import { IEmbedder } from "../../embeddings/dist/index.js";
import { IGraphStore, IKnowledgeStore } from "../../store/dist/index.js";
import { Client } from "@modelcontextprotocol/sdk/client/index.js";

//#region packages/aikit-client/src/types.d.ts
/**
 * IAikitClient — Unified data access interface for AI Kit consumers.
 *
 * Implemented by:
 * - DirectAikitClient (in-process, used by TUI)
 * - McpAikitClient (over MCP transport, used by Dashboard)
 */
interface AikitStatus {
  totalRecords: number;
  totalFiles: number;
  lastIndexedAt: string | null;
  onboarded: boolean;
}
interface AikitSearchResult {
  sourcePath: string;
  contentType: string;
  score: number;
  content: string;
  headingPath?: string;
  startLine?: number;
  endLine?: number;
}
interface AikitKnowledgeEntry {
  path: string;
  title: string;
  category: string;
  tags: string[];
  content: string;
}
interface AikitGraphData {
  nodes: Array<{
    id: string;
    name: string;
    type: string;
    sourcePath?: string;
  }>;
  edges: Array<{
    fromId: string;
    toId: string;
    type: string;
  }>;
}
interface IAikitClient {
  /** Get AI Kit status. */
  getStatus(): Promise<AikitStatus>;
  /** Search AI Kit. */
  search(query: string, options?: {
    limit?: number;
    mode?: 'hybrid' | 'semantic' | 'keyword';
  }): Promise<AikitSearchResult[]>;
  /** List curated knowledge entries. */
  listKnowledge(): Promise<AikitKnowledgeEntry[]>;
  /** Read a specific curated entry. */
  readKnowledge(path: string): Promise<AikitKnowledgeEntry | null>;
  /** Get knowledge graph data. */
  getGraph(query?: string): Promise<AikitGraphData>;
  /** Get file tree of indexed sources. */
  getFileTree(): Promise<string[]>;
}
//#endregion
//#region packages/aikit-client/src/direct-client.d.ts
interface CuratedEntry {
  path: string;
  title: string;
  category: string;
  tags: string[];
  content: string;
}
interface DirectClientDeps {
  store: IKnowledgeStore;
  embedder: IEmbedder;
  graphStore?: IGraphStore;
  /** Function to list curated entries */
  listCurated?: () => Promise<CuratedEntry[]>;
  /** Function to read a single curated entry */
  readCurated?: (path: string) => Promise<CuratedEntry | null>;
}
declare class DirectAikitClient implements IAikitClient {
  private readonly deps;
  constructor(deps: DirectClientDeps);
  getStatus(): Promise<AikitStatus>;
  search(query: string, options?: {
    limit?: number;
    mode?: 'hybrid' | 'semantic' | 'keyword';
  }): Promise<AikitSearchResult[]>;
  listKnowledge(): Promise<AikitKnowledgeEntry[]>;
  readKnowledge(path: string): Promise<AikitKnowledgeEntry | null>;
  getGraph(query?: string): Promise<AikitGraphData>;
  getFileTree(): Promise<string[]>;
  private getEdgesForNodes;
}
//#endregion
//#region packages/aikit-client/src/mcp-client.d.ts
declare class McpAikitClient implements IAikitClient {
  private readonly client;
  constructor(client: Client);
  getStatus(): Promise<AikitStatus>;
  search(query: string, options?: {
    limit?: number;
    mode?: 'hybrid' | 'semantic' | 'keyword';
  }): Promise<AikitSearchResult[]>;
  listKnowledge(): Promise<AikitKnowledgeEntry[]>;
  readKnowledge(path: string): Promise<AikitKnowledgeEntry | null>;
  getGraph(query?: string): Promise<AikitGraphData>;
  getFileTree(): Promise<string[]>;
}
//#endregion
//#region packages/aikit-client/src/parsers.d.ts
/**
 * Content parsers for MCP tool responses.
 * Used by McpAikitClient to parse structuredContent from tool calls.
 */
interface ParsedContent<T = unknown> {
  text: string;
  structured?: T;
}
/**
 * Extract text content from an MCP tool result.
 */
declare function extractText(result: {
  content?: unknown;
} | null | undefined): string;
/**
 * Extract structured content from an MCP tool result.
 */
declare function extractStructured<T>(result: {
  structuredContent?: unknown;
} | null | undefined): T | undefined;
/**
 * Parse a tool result, returning both text and structured content.
 */
declare function parseToolResult<T = unknown>(result: {
  content?: unknown;
  structuredContent?: unknown;
} | null | undefined): ParsedContent<T>;
/**
 * Try to parse JSON from a text tool result.
 * Returns undefined if parsing fails.
 */
declare function tryParseJson<T = unknown>(text: string): T | undefined;
//#endregion
export { type AikitGraphData, type AikitKnowledgeEntry, type AikitSearchResult, type AikitStatus, DirectAikitClient, type DirectClientDeps, type IAikitClient, McpAikitClient, type ParsedContent, extractStructured, extractText, parseToolResult, tryParseJson };