apex-code 0.0.1-alpha.5 → 0.0.1-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +10 -1
- package/dist/cli.js.map +1 -1
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +18 -3
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +15 -0
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/sandbox/cli-launch.d.ts +43 -0
- package/dist/core/sandbox/cli-launch.d.ts.map +1 -1
- package/dist/core/sandbox/cli-launch.js +70 -3
- package/dist/core/sandbox/cli-launch.js.map +1 -1
- package/dist/core/sandbox/cli-supervisor.d.ts +2 -0
- package/dist/core/sandbox/cli-supervisor.d.ts.map +1 -1
- package/dist/core/sandbox/cli-supervisor.js +1 -0
- package/dist/core/sandbox/cli-supervisor.js.map +1 -1
- package/dist/core/skills.d.ts +19 -7
- package/dist/core/skills.d.ts.map +1 -1
- package/dist/core/skills.js +77 -19
- package/dist/core/skills.js.map +1 -1
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js +1 -1
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +3 -3
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tools/index.d.ts +5 -1
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js +12 -0
- package/dist/core/tools/index.js.map +1 -1
- package/dist/core/tools/skill-search.d.ts +32 -0
- package/dist/core/tools/skill-search.d.ts.map +1 -0
- package/dist/core/tools/skill-search.js +56 -0
- package/dist/core/tools/skill-search.js.map +1 -0
- package/dist/modes/interactive/components/model-selector.d.ts +19 -6
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/model-selector.js +172 -89
- package/dist/modes/interactive/components/model-selector.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +2 -1
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +2 -1
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/docs/skills.md +54 -4
- package/npm-shrinkwrap.json +5 -5
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0C,iBAAiB,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AACvH,OAAO,EAON,cAAc,EACd,wBAAwB,EACxB,yBAAyB,GACzB,MAAM,WAAW,CAAC;AACnB,OAAO,EACN,kBAAkB,EAClB,4BAA4B,GAG5B,MAAM,eAAe,CAAC;AAWvB,OAAO,EACN,cAAc,EACd,wBAAwB,GAKxB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EACN,cAAc,EACd,wBAAwB,GAKxB,MAAM,WAAW,CAAC;AACnB,OAAO,EACN,cAAc,EACd,wBAAwB,GAKxB,MAAM,WAAW,CAAC;AACnB,OAAO,EACN,YAAY,EACZ,sBAAsB,GAKtB,MAAM,SAAS,CAAC;AACjB,OAAO,EACN,aAAa,EACb,uBAAuB,GAOvB,MAAM,UAAU,CAAC;AAClB,OAAO,EACN,qBAAqB,EACrB,+BAA+B,GAG/B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACN,cAAc,EACd,wBAAwB,GAKxB,MAAM,WAAW,CAAC;AACnB,OAAO,EACN,wBAAwB,EACxB,cAAc,EACd,wBAAwB,GAMxB,MAAM,WAAW,CAAC;AACnB,OAAO,EACN,mBAAmB,EACnB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AAE,OAAO,EAAE,EAAE,CAAC;QAClC,WAAW,EAAE,oBAAoB,CAAC,QAAQ,CAAC;QAC3C,UAAU,EAAE,mBAAmB,CAAC,OAAO,EAAE,UAAU,EAAE,KAAK,IAAI,kBAAkB,CAAC;QACjF,UAAU,EAAE,mBAAmB,CAAC,OAAO,EAAE,UAAU,CAAC;QACpD,SAAS,EAAE,kBAAkB,CAAC,OAAO,EAAE,SAAS,CAAC;QACjD,QAAQ,EAAE,iBAAiB,EAAE;QAC7B,YAAY,EAAE,qBAAqB,EAAE;QACrC,QAAQ,EAAE,kBAAkB,CAAC,OAAO,EAAE,QAAQ,EAAE,OAAO,IAAI,qBAAqB,CAAC;QACjF,IAAI,EAAE,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC;QACxC,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,aAAa,CAAC,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACjE,CAAC;AAAA,CACF","sourcesContent":["export { type AskUserDetails, type AskUserInput, createAskUserTool, createAskUserToolDefinition } from \"./ask-user.ts\";\nexport {\n\ttype BashOperations,\n\ttype BashSpawnContext,\n\ttype BashSpawnHook,\n\ttype BashToolDetails,\n\ttype BashToolInput,\n\ttype BashToolOptions,\n\tcreateBashTool,\n\tcreateBashToolDefinition,\n\tcreateLocalBashOperations,\n} from \"./bash.ts\";\nexport {\n\tcreateDelegateTool,\n\tcreateDelegateToolDefinition,\n\ttype DelegateDetails,\n\ttype DelegateInput,\n} from \"./delegate.ts\";\nexport type {\n\tDiagnostic,\n\tDiagnosticEvidenceRecord,\n\tDiagnosticPosition,\n\tDiagnosticRange,\n\tDiagnosticSeverityCounts,\n\tDiagnosticsOperations,\n\tDiagnosticsOutcome,\n\tDiagnosticUnavailableKind,\n} from \"./diagnostics.ts\";\nexport {\n\tcreateEditTool,\n\tcreateEditToolDefinition,\n\ttype EditOperations,\n\ttype EditToolDetails,\n\ttype EditToolInput,\n\ttype EditToolOptions,\n} from \"./edit.ts\";\nexport { withFileMutationQueue } from \"./file-mutation-queue.ts\";\nexport {\n\tcreateFindTool,\n\tcreateFindToolDefinition,\n\ttype FindOperations,\n\ttype FindToolDetails,\n\ttype FindToolInput,\n\ttype FindToolOptions,\n} from \"./find.ts\";\nexport {\n\tcreateGrepTool,\n\tcreateGrepToolDefinition,\n\ttype GrepOperations,\n\ttype GrepToolDetails,\n\ttype GrepToolInput,\n\ttype GrepToolOptions,\n} from \"./grep.ts\";\nexport {\n\tcreateLsTool,\n\tcreateLsToolDefinition,\n\ttype LsOperations,\n\ttype LsToolDetails,\n\ttype LsToolInput,\n\ttype LsToolOptions,\n} from \"./ls.ts\";\nexport {\n\tcreateLspTool,\n\tcreateLspToolDefinition,\n\ttype LspLocation,\n\ttype LspOperations,\n\ttype LspSymbol,\n\ttype LspToolDetails,\n\ttype LspToolInput,\n\ttype LspToolOptions,\n} from \"./lsp.ts\";\nexport {\n\tcreatePlanPresentTool,\n\tcreatePlanPresentToolDefinition,\n\ttype PlanPresentDetails,\n\ttype PlanPresentInput,\n} from \"./plan-present.ts\";\nexport {\n\tcreateReadTool,\n\tcreateReadToolDefinition,\n\ttype ReadOperations,\n\ttype ReadToolDetails,\n\ttype ReadToolInput,\n\ttype ReadToolOptions,\n} from \"./read.ts\";\nexport {\n\tcreateTestPermissionSpec,\n\tcreateTestTool,\n\tcreateTestToolDefinition,\n\ttype TestOperationResult,\n\ttype TestOperations,\n\ttype TestRunDetails,\n\ttype TestToolInput,\n\ttype TestToolOptions,\n} from \"./test.ts\";\nexport {\n\tcreateTodoWriteTool,\n\tcreateTodoWriteToolDefinition,\n\ttype TodoItem,\n\ttype TodoWriteDetails,\n\ttype TodoWriteInput,\n\ttype TodoWriteStore,\n} from \"./todo-write.ts\";\nexport {\n\tDEFAULT_MAX_BYTES,\n\tDEFAULT_MAX_LINES,\n\tformatSize,\n\ttype TruncationOptions,\n\ttype TruncationResult,\n\ttruncateHead,\n\ttruncateLine,\n\ttruncateTail,\n} from \"./truncate.ts\";\nexport {\n\tcreateWebFetchTool,\n\tcreateWebFetchToolDefinition,\n\ttype WebFetchDetails,\n\ttype WebFetchInput,\n\ttype WebFetchOperations,\n\ttype WebFetchToolOptions,\n} from \"./web-fetch.ts\";\nexport {\n\tcreateWebSearchTool,\n\tcreateWebSearchToolDefinition,\n\ttype WebSearchDetails,\n\ttype WebSearchInput,\n\ttype WebSearchOperations,\n\ttype WebSearchResult,\n\ttype WebSearchToolOptions,\n} from \"./web-search.ts\";\nexport {\n\tcreateWriteTool,\n\tcreateWriteToolDefinition,\n\ttype WriteOperations,\n\ttype WriteToolDetails,\n\ttype WriteToolInput,\n\ttype WriteToolOptions,\n} from \"./write.ts\";\n\nimport type { AgentTool } from \"apex-code-agent-core\";\nimport type { DelegationRuntimeOptions } from \"../delegation/runtime.ts\";\nimport { createAskUserTool, createAskUserToolDefinition } from \"./ask-user.ts\";\nimport { type BashToolOptions, createBashTool, createBashToolDefinition } from \"./bash.ts\";\nimport type { ApexToolDefinition } from \"./contract.ts\";\nimport { createDelegateTool, createDelegateToolDefinition } from \"./delegate.ts\";\nimport { createEditTool, createEditToolDefinition, type EditToolOptions } from \"./edit.ts\";\nimport { createFindTool, createFindToolDefinition, type FindToolOptions } from \"./find.ts\";\nimport { createGrepTool, createGrepToolDefinition, type GrepToolOptions } from \"./grep.ts\";\nimport { createLsTool, createLsToolDefinition, type LsToolOptions } from \"./ls.ts\";\nimport { createLspTool, createLspToolDefinition, type LspToolOptions } from \"./lsp.ts\";\nimport { createPlanPresentTool, createPlanPresentToolDefinition } from \"./plan-present.ts\";\nimport { createReadTool, createReadToolDefinition, type ReadToolOptions } from \"./read.ts\";\nimport { createTestTool, createTestToolDefinition, type TestToolOptions } from \"./test.ts\";\nimport { createTodoWriteTool, createTodoWriteToolDefinition, type TodoWriteStore } from \"./todo-write.ts\";\nimport { createToolSchemaTool, createToolSchemaToolDefinition, type ToolSchemaResolver } from \"./tool-schema.ts\";\nimport { createWebFetchTool, createWebFetchToolDefinition, type WebFetchToolOptions } from \"./web-fetch.ts\";\nimport { createWebSearchTool, createWebSearchToolDefinition, type WebSearchToolOptions } from \"./web-search.ts\";\nimport { createWriteTool, createWriteToolDefinition, type WriteToolOptions } from \"./write.ts\";\n\nexport type Tool = AgentTool<any>;\nexport type ToolDef = ApexToolDefinition<any, any>;\nexport type ToolName =\n\t| \"read\"\n\t| \"bash\"\n\t| \"edit\"\n\t| \"write\"\n\t| \"grep\"\n\t| \"find\"\n\t| \"ls\"\n\t| \"tool_schema\"\n\t| \"todo_write\"\n\t| \"web_search\"\n\t| \"web_fetch\"\n\t| \"ask_user\"\n\t| \"plan_present\"\n\t| \"delegate\"\n\t| \"test\";\nexport const allToolNames: Set<ToolName> = new Set([\n\t\"read\",\n\t\"bash\",\n\t\"edit\",\n\t\"write\",\n\t\"grep\",\n\t\"find\",\n\t\"ls\",\n\t\"tool_schema\",\n\t\"todo_write\",\n\t\"web_search\",\n\t\"web_fetch\",\n\t\"ask_user\",\n\t\"plan_present\",\n\t\"delegate\",\n\t\"test\",\n]);\n\nexport interface ToolsOptions {\n\tread?: ReadToolOptions;\n\tbash?: BashToolOptions;\n\twrite?: WriteToolOptions;\n\tedit?: EditToolOptions;\n\tgrep?: GrepToolOptions;\n\tfind?: FindToolOptions;\n\tls?: LsToolOptions;\n\ttool_schema?: { resolver?: ToolSchemaResolver };\n\ttodo_write?: { store?: TodoWriteStore };\n\tweb_search?: WebSearchToolOptions;\n\tweb_fetch?: WebFetchToolOptions;\n\tdelegate?: { runtime?: DelegationRuntimeOptions };\n\ttest?: TestToolOptions;\n\t/**\n\t * The `lsp` navigation tool (LSP.5). Undefined by default -- the registry-building\n\t * functions below include the `lsp` key only when this is provided, which is what\n\t * keeps an unconfigured session's tool set (and static prompt prefix) unaffected.\n\t */\n\tlsp?: LspToolOptions;\n}\n\n/** Default store when no session/workspace context supplies one (mirrors emptyToolSchemaResolver below). */\nconst noopTodoWriteStore: TodoWriteStore = { write: () => {} };\n\n/**\n * Default runtime when no session supplies one (mirrors noopTodoWriteStore/\n * emptyToolSchemaResolver above): every agent type is unresolvable, so `delegate`\n * stays inert -- callable, but every call fails loudly with \"unknown agent type\"\n * rather than silently spawning a child with no real authority derivation behind\n * it. Real production wiring (a resolved parent capability set, a derived\n * permission store, and a `buildChildSession` that calls `createAgentSession`) is\n * supplied by `sdk.ts`'s `createAgentSession({ delegation })` option.\n */\nconst noopDelegationRuntime: DelegationRuntimeOptions = {\n\tresolveAgent: () => undefined,\n\tgetParentCapabilities: () => new Set(),\n\tgetToolCapabilities: () => undefined,\n\tgetDelegationDepth: () => 0,\n\tmaxDelegationDepth: 2,\n\tbuildChildSession: async () => {\n\t\tthrow new Error(\"delegate has no runtime configured in this context -- no agent types are resolvable.\");\n\t},\n};\n\nexport function createToolDefinition(toolName: ToolName, cwd: string, options?: ToolsOptions): ToolDef {\n\tswitch (toolName) {\n\t\tcase \"read\":\n\t\t\treturn createReadToolDefinition(cwd, options?.read);\n\t\tcase \"bash\":\n\t\t\treturn createBashToolDefinition(cwd, options?.bash);\n\t\tcase \"edit\":\n\t\t\treturn createEditToolDefinition(cwd, options?.edit);\n\t\tcase \"write\":\n\t\t\treturn createWriteToolDefinition(cwd, options?.write);\n\t\tcase \"grep\":\n\t\t\treturn createGrepToolDefinition(cwd, options?.grep);\n\t\tcase \"find\":\n\t\t\treturn createFindToolDefinition(cwd, options?.find);\n\t\tcase \"ls\":\n\t\t\treturn createLsToolDefinition(cwd, options?.ls);\n\t\tcase \"tool_schema\":\n\t\t\treturn createToolSchemaToolDefinition(options?.tool_schema?.resolver ?? emptyToolSchemaResolver);\n\t\tcase \"todo_write\":\n\t\t\treturn createTodoWriteToolDefinition(options?.todo_write?.store ?? noopTodoWriteStore);\n\t\tcase \"web_search\":\n\t\t\treturn createWebSearchToolDefinition(options?.web_search);\n\t\tcase \"web_fetch\":\n\t\t\treturn createWebFetchToolDefinition(options?.web_fetch);\n\t\tcase \"ask_user\":\n\t\t\treturn createAskUserToolDefinition();\n\t\tcase \"plan_present\":\n\t\t\treturn createPlanPresentToolDefinition();\n\t\tcase \"delegate\":\n\t\t\treturn createDelegateToolDefinition(options?.delegate?.runtime ?? noopDelegationRuntime);\n\t\tcase \"test\":\n\t\t\treturn createTestToolDefinition(cwd, options?.test);\n\t\tdefault:\n\t\t\tthrow new Error(`Unknown tool name: ${toolName}`);\n\t}\n}\n\nexport function createTool(toolName: ToolName, cwd: string, options?: ToolsOptions): Tool {\n\tswitch (toolName) {\n\t\tcase \"read\":\n\t\t\treturn createReadTool(cwd, options?.read);\n\t\tcase \"bash\":\n\t\t\treturn createBashTool(cwd, options?.bash);\n\t\tcase \"edit\":\n\t\t\treturn createEditTool(cwd, options?.edit);\n\t\tcase \"write\":\n\t\t\treturn createWriteTool(cwd, options?.write);\n\t\tcase \"grep\":\n\t\t\treturn createGrepTool(cwd, options?.grep);\n\t\tcase \"find\":\n\t\t\treturn createFindTool(cwd, options?.find);\n\t\tcase \"ls\":\n\t\t\treturn createLsTool(cwd, options?.ls);\n\t\tcase \"tool_schema\":\n\t\t\treturn createToolSchemaTool(options?.tool_schema?.resolver ?? emptyToolSchemaResolver);\n\t\tcase \"todo_write\":\n\t\t\treturn createTodoWriteTool(options?.todo_write?.store ?? noopTodoWriteStore);\n\t\tcase \"web_search\":\n\t\t\treturn createWebSearchTool(options?.web_search);\n\t\tcase \"web_fetch\":\n\t\t\treturn createWebFetchTool(options?.web_fetch);\n\t\tcase \"ask_user\":\n\t\t\treturn createAskUserTool();\n\t\tcase \"plan_present\":\n\t\t\treturn createPlanPresentTool();\n\t\tcase \"delegate\":\n\t\t\treturn createDelegateTool(options?.delegate?.runtime ?? noopDelegationRuntime);\n\t\tcase \"test\":\n\t\t\treturn createTestTool(cwd, options?.test);\n\t\tdefault:\n\t\t\tthrow new Error(`Unknown tool name: ${toolName}`);\n\t}\n}\n\nexport function createCodingToolDefinitions(cwd: string, options?: ToolsOptions): ToolDef[] {\n\treturn [\n\t\tcreateReadToolDefinition(cwd, options?.read),\n\t\tcreateBashToolDefinition(cwd, options?.bash),\n\t\tcreateEditToolDefinition(cwd, options?.edit),\n\t\tcreateWriteToolDefinition(cwd, options?.write),\n\t];\n}\n\nexport function createReadOnlyToolDefinitions(cwd: string, options?: ToolsOptions): ToolDef[] {\n\treturn [\n\t\tcreateReadToolDefinition(cwd, options?.read),\n\t\tcreateGrepToolDefinition(cwd, options?.grep),\n\t\tcreateFindToolDefinition(cwd, options?.find),\n\t\tcreateLsToolDefinition(cwd, options?.ls),\n\t];\n}\n\nconst emptyToolSchemaResolver: ToolSchemaResolver = {\n\tgetTool: () => undefined,\n\tmarkLoaded: () => {},\n};\n\nexport function createAllToolDefinitions(\n\tcwd: string,\n\toptions?: ToolsOptions,\n): Record<ToolName, ToolDef> & { lsp?: ToolDef } {\n\tconst definitions = {\n\t\tread: createReadToolDefinition(cwd, options?.read),\n\t\tbash: createBashToolDefinition(cwd, options?.bash),\n\t\tedit: createEditToolDefinition(cwd, options?.edit),\n\t\twrite: createWriteToolDefinition(cwd, options?.write),\n\t\tgrep: createGrepToolDefinition(cwd, options?.grep),\n\t\tfind: createFindToolDefinition(cwd, options?.find),\n\t\tls: createLsToolDefinition(cwd, options?.ls),\n\t};\n\tconst resolver = options?.tool_schema?.resolver ?? {\n\t\tgetTool: (name: string) => definitions[name as keyof typeof definitions],\n\t\tmarkLoaded: () => {},\n\t};\n\treturn {\n\t\t...definitions,\n\t\ttool_schema: createToolSchemaToolDefinition(resolver),\n\t\ttodo_write: createTodoWriteToolDefinition(options?.todo_write?.store ?? noopTodoWriteStore),\n\t\tweb_search: createWebSearchToolDefinition(options?.web_search),\n\t\tweb_fetch: createWebFetchToolDefinition(options?.web_fetch),\n\t\task_user: createAskUserToolDefinition(),\n\t\tplan_present: createPlanPresentToolDefinition(),\n\t\tdelegate: createDelegateToolDefinition(options?.delegate?.runtime ?? noopDelegationRuntime),\n\t\ttest: createTestToolDefinition(cwd, options?.test),\n\t\t// Registered only when configured (LSP.5): an unconfigured session's registry,\n\t\t// and therefore its static prompt prefix, is unaffected by this subsystem.\n\t\t...(options?.lsp ? { lsp: createLspToolDefinition(cwd, options.lsp) } : {}),\n\t};\n}\n\nexport function createCodingTools(cwd: string, options?: ToolsOptions): Tool[] {\n\treturn [\n\t\tcreateReadTool(cwd, options?.read),\n\t\tcreateBashTool(cwd, options?.bash),\n\t\tcreateEditTool(cwd, options?.edit),\n\t\tcreateWriteTool(cwd, options?.write),\n\t];\n}\n\nexport function createReadOnlyTools(cwd: string, options?: ToolsOptions): Tool[] {\n\treturn [\n\t\tcreateReadTool(cwd, options?.read),\n\t\tcreateGrepTool(cwd, options?.grep),\n\t\tcreateFindTool(cwd, options?.find),\n\t\tcreateLsTool(cwd, options?.ls),\n\t];\n}\n\nexport function createAllTools(cwd: string, options?: ToolsOptions): Record<ToolName, Tool> & { lsp?: Tool } {\n\tconst definitions = createAllToolDefinitions(cwd, options);\n\tconst resolver = options?.tool_schema?.resolver ?? {\n\t\tgetTool: (name: string) => definitions[name as ToolName],\n\t\tmarkLoaded: () => {},\n\t};\n\treturn {\n\t\tread: createReadTool(cwd, options?.read),\n\t\tbash: createBashTool(cwd, options?.bash),\n\t\tedit: createEditTool(cwd, options?.edit),\n\t\twrite: createWriteTool(cwd, options?.write),\n\t\tgrep: createGrepTool(cwd, options?.grep),\n\t\tfind: createFindTool(cwd, options?.find),\n\t\tls: createLsTool(cwd, options?.ls),\n\t\ttool_schema: createToolSchemaTool(resolver),\n\t\ttodo_write: createTodoWriteTool(options?.todo_write?.store ?? noopTodoWriteStore),\n\t\tweb_search: createWebSearchTool(options?.web_search),\n\t\tweb_fetch: createWebFetchTool(options?.web_fetch),\n\t\task_user: createAskUserTool(),\n\t\tplan_present: createPlanPresentTool(),\n\t\tdelegate: createDelegateTool(options?.delegate?.runtime ?? noopDelegationRuntime),\n\t\ttest: createTestTool(cwd, options?.test),\n\t\t...(options?.lsp ? { lsp: createLspTool(cwd, options.lsp) } : {}),\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0C,iBAAiB,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AACvH,OAAO,EAON,cAAc,EACd,wBAAwB,EACxB,yBAAyB,GACzB,MAAM,WAAW,CAAC;AACnB,OAAO,EACN,kBAAkB,EAClB,4BAA4B,GAG5B,MAAM,eAAe,CAAC;AAWvB,OAAO,EACN,cAAc,EACd,wBAAwB,GAKxB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EACN,cAAc,EACd,wBAAwB,GAKxB,MAAM,WAAW,CAAC;AACnB,OAAO,EACN,cAAc,EACd,wBAAwB,GAKxB,MAAM,WAAW,CAAC;AACnB,OAAO,EACN,YAAY,EACZ,sBAAsB,GAKtB,MAAM,SAAS,CAAC;AACjB,OAAO,EACN,aAAa,EACb,uBAAuB,GAOvB,MAAM,UAAU,CAAC;AAClB,OAAO,EACN,qBAAqB,EACrB,+BAA+B,GAG/B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACN,cAAc,EACd,wBAAwB,GAKxB,MAAM,WAAW,CAAC;AACnB,OAAO,EACN,wBAAwB,EACxB,cAAc,EACd,wBAAwB,GAMxB,MAAM,WAAW,CAAC;AACnB,OAAO,EACN,mBAAmB,EACnB,6BAA6B,GAK7B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACN,iBAAiB,EACjB,iBAAiB,EACjB,UAAU,EAGV,YAAY,EACZ,YAAY,EACZ,YAAY,GACZ,MAAM,eAAe,CAAC;AACvB,OAAO,EACN,kBAAkB,EAClB,4BAA4B,GAK5B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACN,mBAAmB,EACnB,6BAA6B,GAM7B,MAAM,iBAAi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AAO,EAAE,KAAK,CAAC;QAC3C,IAAI,EAAE,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC;QACxC,IAAI,EAAE,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC;QACxC,EAAE,EAAE,YAAY,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE,CAAC;QAClC,WAAW,EAAE,oBAAoB,CAAC,QAAQ,CAAC;QAC3C,UAAU,EAAE,mBAAmB,CAAC,OAAO,EAAE,UAAU,EAAE,KAAK,IAAI,kBAAkB,CAAC;QACjF,YAAY,EAAE,qBAAqB,CAAC,OAAO,EAAE,YAAY,EAAE,QAAQ,IAAI,wBAAwB,CAAC;QAChG,UAAU,EAAE,mBAAmB,CAAC,OAAO,EAAE,UAAU,CAAC;QACpD,SAAS,EAAE,kBAAkB,CAAC,OAAO,EAAE,SAAS,CAAC;QACjD,QAAQ,EAAE,iBAAiB,EAAE;QAC7B,YAAY,EAAE,qBAAqB,EAAE;QACrC,QAAQ,EAAE,kBAAkB,CAAC,OAAO,EAAE,QAAQ,EAAE,OAAO,IAAI,qBAAqB,CAAC;QACjF,IAAI,EAAE,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC;QACxC,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,aAAa,CAAC,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACjE,CAAC;AAAA,CACF","sourcesContent":["export { type AskUserDetails, type AskUserInput, createAskUserTool, createAskUserToolDefinition } from \"./ask-user.ts\";\nexport {\n\ttype BashOperations,\n\ttype BashSpawnContext,\n\ttype BashSpawnHook,\n\ttype BashToolDetails,\n\ttype BashToolInput,\n\ttype BashToolOptions,\n\tcreateBashTool,\n\tcreateBashToolDefinition,\n\tcreateLocalBashOperations,\n} from \"./bash.ts\";\nexport {\n\tcreateDelegateTool,\n\tcreateDelegateToolDefinition,\n\ttype DelegateDetails,\n\ttype DelegateInput,\n} from \"./delegate.ts\";\nexport type {\n\tDiagnostic,\n\tDiagnosticEvidenceRecord,\n\tDiagnosticPosition,\n\tDiagnosticRange,\n\tDiagnosticSeverityCounts,\n\tDiagnosticsOperations,\n\tDiagnosticsOutcome,\n\tDiagnosticUnavailableKind,\n} from \"./diagnostics.ts\";\nexport {\n\tcreateEditTool,\n\tcreateEditToolDefinition,\n\ttype EditOperations,\n\ttype EditToolDetails,\n\ttype EditToolInput,\n\ttype EditToolOptions,\n} from \"./edit.ts\";\nexport { withFileMutationQueue } from \"./file-mutation-queue.ts\";\nexport {\n\tcreateFindTool,\n\tcreateFindToolDefinition,\n\ttype FindOperations,\n\ttype FindToolDetails,\n\ttype FindToolInput,\n\ttype FindToolOptions,\n} from \"./find.ts\";\nexport {\n\tcreateGrepTool,\n\tcreateGrepToolDefinition,\n\ttype GrepOperations,\n\ttype GrepToolDetails,\n\ttype GrepToolInput,\n\ttype GrepToolOptions,\n} from \"./grep.ts\";\nexport {\n\tcreateLsTool,\n\tcreateLsToolDefinition,\n\ttype LsOperations,\n\ttype LsToolDetails,\n\ttype LsToolInput,\n\ttype LsToolOptions,\n} from \"./ls.ts\";\nexport {\n\tcreateLspTool,\n\tcreateLspToolDefinition,\n\ttype LspLocation,\n\ttype LspOperations,\n\ttype LspSymbol,\n\ttype LspToolDetails,\n\ttype LspToolInput,\n\ttype LspToolOptions,\n} from \"./lsp.ts\";\nexport {\n\tcreatePlanPresentTool,\n\tcreatePlanPresentToolDefinition,\n\ttype PlanPresentDetails,\n\ttype PlanPresentInput,\n} from \"./plan-present.ts\";\nexport {\n\tcreateReadTool,\n\tcreateReadToolDefinition,\n\ttype ReadOperations,\n\ttype ReadToolDetails,\n\ttype ReadToolInput,\n\ttype ReadToolOptions,\n} from \"./read.ts\";\nexport {\n\tcreateTestPermissionSpec,\n\tcreateTestTool,\n\tcreateTestToolDefinition,\n\ttype TestOperationResult,\n\ttype TestOperations,\n\ttype TestRunDetails,\n\ttype TestToolInput,\n\ttype TestToolOptions,\n} from \"./test.ts\";\nexport {\n\tcreateTodoWriteTool,\n\tcreateTodoWriteToolDefinition,\n\ttype TodoItem,\n\ttype TodoWriteDetails,\n\ttype TodoWriteInput,\n\ttype TodoWriteStore,\n} from \"./todo-write.ts\";\nexport {\n\tDEFAULT_MAX_BYTES,\n\tDEFAULT_MAX_LINES,\n\tformatSize,\n\ttype TruncationOptions,\n\ttype TruncationResult,\n\ttruncateHead,\n\ttruncateLine,\n\ttruncateTail,\n} from \"./truncate.ts\";\nexport {\n\tcreateWebFetchTool,\n\tcreateWebFetchToolDefinition,\n\ttype WebFetchDetails,\n\ttype WebFetchInput,\n\ttype WebFetchOperations,\n\ttype WebFetchToolOptions,\n} from \"./web-fetch.ts\";\nexport {\n\tcreateWebSearchTool,\n\tcreateWebSearchToolDefinition,\n\ttype WebSearchDetails,\n\ttype WebSearchInput,\n\ttype WebSearchOperations,\n\ttype WebSearchResult,\n\ttype WebSearchToolOptions,\n} from \"./web-search.ts\";\nexport {\n\tcreateWriteTool,\n\tcreateWriteToolDefinition,\n\ttype WriteOperations,\n\ttype WriteToolDetails,\n\ttype WriteToolInput,\n\ttype WriteToolOptions,\n} from \"./write.ts\";\n\nimport type { AgentTool } from \"apex-code-agent-core\";\nimport type { DelegationRuntimeOptions } from \"../delegation/runtime.ts\";\nimport { createAskUserTool, createAskUserToolDefinition } from \"./ask-user.ts\";\nimport { type BashToolOptions, createBashTool, createBashToolDefinition } from \"./bash.ts\";\nimport type { ApexToolDefinition } from \"./contract.ts\";\nimport { createDelegateTool, createDelegateToolDefinition } from \"./delegate.ts\";\nimport { createEditTool, createEditToolDefinition, type EditToolOptions } from \"./edit.ts\";\nimport { createFindTool, createFindToolDefinition, type FindToolOptions } from \"./find.ts\";\nimport { createGrepTool, createGrepToolDefinition, type GrepToolOptions } from \"./grep.ts\";\nimport { createLsTool, createLsToolDefinition, type LsToolOptions } from \"./ls.ts\";\nimport { createLspTool, createLspToolDefinition, type LspToolOptions } from \"./lsp.ts\";\nimport { createPlanPresentTool, createPlanPresentToolDefinition } from \"./plan-present.ts\";\nimport { createReadTool, createReadToolDefinition, type ReadToolOptions } from \"./read.ts\";\nimport { createSkillSearchTool, createSkillSearchToolDefinition, type SkillSearchResolver } from \"./skill-search.ts\";\nimport { createTestTool, createTestToolDefinition, type TestToolOptions } from \"./test.ts\";\nimport { createTodoWriteTool, createTodoWriteToolDefinition, type TodoWriteStore } from \"./todo-write.ts\";\nimport { createToolSchemaTool, createToolSchemaToolDefinition, type ToolSchemaResolver } from \"./tool-schema.ts\";\nimport { createWebFetchTool, createWebFetchToolDefinition, type WebFetchToolOptions } from \"./web-fetch.ts\";\nimport { createWebSearchTool, createWebSearchToolDefinition, type WebSearchToolOptions } from \"./web-search.ts\";\nimport { createWriteTool, createWriteToolDefinition, type WriteToolOptions } from \"./write.ts\";\n\nexport type Tool = AgentTool<any>;\nexport type ToolDef = ApexToolDefinition<any, any>;\nexport type ToolName =\n\t| \"read\"\n\t| \"bash\"\n\t| \"edit\"\n\t| \"write\"\n\t| \"grep\"\n\t| \"find\"\n\t| \"ls\"\n\t| \"tool_schema\"\n\t| \"todo_write\"\n\t| \"web_search\"\n\t| \"web_fetch\"\n\t| \"ask_user\"\n\t| \"plan_present\"\n\t| \"delegate\"\n\t| \"test\"\n\t| \"skill_search\";\nexport const allToolNames: Set<ToolName> = new Set([\n\t\"read\",\n\t\"bash\",\n\t\"edit\",\n\t\"write\",\n\t\"grep\",\n\t\"find\",\n\t\"ls\",\n\t\"tool_schema\",\n\t\"todo_write\",\n\t\"skill_search\",\n\t\"web_search\",\n\t\"web_fetch\",\n\t\"ask_user\",\n\t\"plan_present\",\n\t\"delegate\",\n\t\"test\",\n]);\n\nexport interface ToolsOptions {\n\tread?: ReadToolOptions;\n\tbash?: BashToolOptions;\n\twrite?: WriteToolOptions;\n\tedit?: EditToolOptions;\n\tgrep?: GrepToolOptions;\n\tfind?: FindToolOptions;\n\tls?: LsToolOptions;\n\ttool_schema?: { resolver?: ToolSchemaResolver };\n\ttodo_write?: { store?: TodoWriteStore };\n\tskill_search?: { resolver?: SkillSearchResolver };\n\tweb_search?: WebSearchToolOptions;\n\tweb_fetch?: WebFetchToolOptions;\n\tdelegate?: { runtime?: DelegationRuntimeOptions };\n\ttest?: TestToolOptions;\n\t/**\n\t * The `lsp` navigation tool (LSP.5). Undefined by default -- the registry-building\n\t * functions below include the `lsp` key only when this is provided, which is what\n\t * keeps an unconfigured session's tool set (and static prompt prefix) unaffected.\n\t */\n\tlsp?: LspToolOptions;\n}\n\n/** Default store when no session/workspace context supplies one (mirrors emptyToolSchemaResolver below). */\nconst noopTodoWriteStore: TodoWriteStore = { write: () => {} };\n\n/**\n * Default runtime when no session supplies one (mirrors noopTodoWriteStore/\n * emptyToolSchemaResolver above): every agent type is unresolvable, so `delegate`\n * stays inert -- callable, but every call fails loudly with \"unknown agent type\"\n * rather than silently spawning a child with no real authority derivation behind\n * it. Real production wiring (a resolved parent capability set, a derived\n * permission store, and a `buildChildSession` that calls `createAgentSession`) is\n * supplied by `sdk.ts`'s `createAgentSession({ delegation })` option.\n */\nconst noopDelegationRuntime: DelegationRuntimeOptions = {\n\tresolveAgent: () => undefined,\n\tgetParentCapabilities: () => new Set(),\n\tgetToolCapabilities: () => undefined,\n\tgetDelegationDepth: () => 0,\n\tmaxDelegationDepth: 2,\n\tbuildChildSession: async () => {\n\t\tthrow new Error(\"delegate has no runtime configured in this context -- no agent types are resolvable.\");\n\t},\n};\n\nexport function createToolDefinition(toolName: ToolName, cwd: string, options?: ToolsOptions): ToolDef {\n\tswitch (toolName) {\n\t\tcase \"read\":\n\t\t\treturn createReadToolDefinition(cwd, options?.read);\n\t\tcase \"bash\":\n\t\t\treturn createBashToolDefinition(cwd, options?.bash);\n\t\tcase \"edit\":\n\t\t\treturn createEditToolDefinition(cwd, options?.edit);\n\t\tcase \"write\":\n\t\t\treturn createWriteToolDefinition(cwd, options?.write);\n\t\tcase \"grep\":\n\t\t\treturn createGrepToolDefinition(cwd, options?.grep);\n\t\tcase \"find\":\n\t\t\treturn createFindToolDefinition(cwd, options?.find);\n\t\tcase \"ls\":\n\t\t\treturn createLsToolDefinition(cwd, options?.ls);\n\t\tcase \"tool_schema\":\n\t\t\treturn createToolSchemaToolDefinition(options?.tool_schema?.resolver ?? emptyToolSchemaResolver);\n\t\tcase \"todo_write\":\n\t\t\treturn createTodoWriteToolDefinition(options?.todo_write?.store ?? noopTodoWriteStore);\n\t\tcase \"skill_search\":\n\t\t\treturn createSkillSearchToolDefinition(options?.skill_search?.resolver ?? emptySkillSearchResolver);\n\t\tcase \"web_search\":\n\t\t\treturn createWebSearchToolDefinition(options?.web_search);\n\t\tcase \"web_fetch\":\n\t\t\treturn createWebFetchToolDefinition(options?.web_fetch);\n\t\tcase \"ask_user\":\n\t\t\treturn createAskUserToolDefinition();\n\t\tcase \"plan_present\":\n\t\t\treturn createPlanPresentToolDefinition();\n\t\tcase \"delegate\":\n\t\t\treturn createDelegateToolDefinition(options?.delegate?.runtime ?? noopDelegationRuntime);\n\t\tcase \"test\":\n\t\t\treturn createTestToolDefinition(cwd, options?.test);\n\t\tdefault:\n\t\t\tthrow new Error(`Unknown tool name: ${toolName}`);\n\t}\n}\n\nexport function createTool(toolName: ToolName, cwd: string, options?: ToolsOptions): Tool {\n\tswitch (toolName) {\n\t\tcase \"read\":\n\t\t\treturn createReadTool(cwd, options?.read);\n\t\tcase \"bash\":\n\t\t\treturn createBashTool(cwd, options?.bash);\n\t\tcase \"edit\":\n\t\t\treturn createEditTool(cwd, options?.edit);\n\t\tcase \"write\":\n\t\t\treturn createWriteTool(cwd, options?.write);\n\t\tcase \"grep\":\n\t\t\treturn createGrepTool(cwd, options?.grep);\n\t\tcase \"find\":\n\t\t\treturn createFindTool(cwd, options?.find);\n\t\tcase \"ls\":\n\t\t\treturn createLsTool(cwd, options?.ls);\n\t\tcase \"tool_schema\":\n\t\t\treturn createToolSchemaTool(options?.tool_schema?.resolver ?? emptyToolSchemaResolver);\n\t\tcase \"todo_write\":\n\t\t\treturn createTodoWriteTool(options?.todo_write?.store ?? noopTodoWriteStore);\n\t\tcase \"skill_search\":\n\t\t\treturn createSkillSearchTool(options?.skill_search?.resolver ?? emptySkillSearchResolver);\n\t\tcase \"web_search\":\n\t\t\treturn createWebSearchTool(options?.web_search);\n\t\tcase \"web_fetch\":\n\t\t\treturn createWebFetchTool(options?.web_fetch);\n\t\tcase \"ask_user\":\n\t\t\treturn createAskUserTool();\n\t\tcase \"plan_present\":\n\t\t\treturn createPlanPresentTool();\n\t\tcase \"delegate\":\n\t\t\treturn createDelegateTool(options?.delegate?.runtime ?? noopDelegationRuntime);\n\t\tcase \"test\":\n\t\t\treturn createTestTool(cwd, options?.test);\n\t\tdefault:\n\t\t\tthrow new Error(`Unknown tool name: ${toolName}`);\n\t}\n}\n\nexport function createCodingToolDefinitions(cwd: string, options?: ToolsOptions): ToolDef[] {\n\treturn [\n\t\tcreateReadToolDefinition(cwd, options?.read),\n\t\tcreateBashToolDefinition(cwd, options?.bash),\n\t\tcreateEditToolDefinition(cwd, options?.edit),\n\t\tcreateWriteToolDefinition(cwd, options?.write),\n\t];\n}\n\nexport function createReadOnlyToolDefinitions(cwd: string, options?: ToolsOptions): ToolDef[] {\n\treturn [\n\t\tcreateReadToolDefinition(cwd, options?.read),\n\t\tcreateGrepToolDefinition(cwd, options?.grep),\n\t\tcreateFindToolDefinition(cwd, options?.find),\n\t\tcreateLsToolDefinition(cwd, options?.ls),\n\t];\n}\n\nconst emptyToolSchemaResolver: ToolSchemaResolver = {\n\tgetTool: () => undefined,\n\tmarkLoaded: () => {},\n};\n\n/** Default when no session supplies one (mirrors emptyToolSchemaResolver above): no skills known, so every search returns empty rather than throwing. */\nconst emptySkillSearchResolver: SkillSearchResolver = {\n\tgetSkills: () => [],\n};\n\nexport function createAllToolDefinitions(\n\tcwd: string,\n\toptions?: ToolsOptions,\n): Record<ToolName, ToolDef> & { lsp?: ToolDef } {\n\tconst definitions = {\n\t\tread: createReadToolDefinition(cwd, options?.read),\n\t\tbash: createBashToolDefinition(cwd, options?.bash),\n\t\tedit: createEditToolDefinition(cwd, options?.edit),\n\t\twrite: createWriteToolDefinition(cwd, options?.write),\n\t\tgrep: createGrepToolDefinition(cwd, options?.grep),\n\t\tfind: createFindToolDefinition(cwd, options?.find),\n\t\tls: createLsToolDefinition(cwd, options?.ls),\n\t};\n\tconst resolver = options?.tool_schema?.resolver ?? {\n\t\tgetTool: (name: string) => definitions[name as keyof typeof definitions],\n\t\tmarkLoaded: () => {},\n\t};\n\treturn {\n\t\t...definitions,\n\t\ttool_schema: createToolSchemaToolDefinition(resolver),\n\t\ttodo_write: createTodoWriteToolDefinition(options?.todo_write?.store ?? noopTodoWriteStore),\n\t\tskill_search: createSkillSearchToolDefinition(options?.skill_search?.resolver ?? emptySkillSearchResolver),\n\t\tweb_search: createWebSearchToolDefinition(options?.web_search),\n\t\tweb_fetch: createWebFetchToolDefinition(options?.web_fetch),\n\t\task_user: createAskUserToolDefinition(),\n\t\tplan_present: createPlanPresentToolDefinition(),\n\t\tdelegate: createDelegateToolDefinition(options?.delegate?.runtime ?? noopDelegationRuntime),\n\t\ttest: createTestToolDefinition(cwd, options?.test),\n\t\t// Registered only when configured (LSP.5): an unconfigured session's registry,\n\t\t// and therefore its static prompt prefix, is unaffected by this subsystem.\n\t\t...(options?.lsp ? { lsp: createLspToolDefinition(cwd, options.lsp) } : {}),\n\t};\n}\n\nexport function createCodingTools(cwd: string, options?: ToolsOptions): Tool[] {\n\treturn [\n\t\tcreateReadTool(cwd, options?.read),\n\t\tcreateBashTool(cwd, options?.bash),\n\t\tcreateEditTool(cwd, options?.edit),\n\t\tcreateWriteTool(cwd, options?.write),\n\t];\n}\n\nexport function createReadOnlyTools(cwd: string, options?: ToolsOptions): Tool[] {\n\treturn [\n\t\tcreateReadTool(cwd, options?.read),\n\t\tcreateGrepTool(cwd, options?.grep),\n\t\tcreateFindTool(cwd, options?.find),\n\t\tcreateLsTool(cwd, options?.ls),\n\t];\n}\n\nexport function createAllTools(cwd: string, options?: ToolsOptions): Record<ToolName, Tool> & { lsp?: Tool } {\n\tconst definitions = createAllToolDefinitions(cwd, options);\n\tconst resolver = options?.tool_schema?.resolver ?? {\n\t\tgetTool: (name: string) => definitions[name as ToolName],\n\t\tmarkLoaded: () => {},\n\t};\n\treturn {\n\t\tread: createReadTool(cwd, options?.read),\n\t\tbash: createBashTool(cwd, options?.bash),\n\t\tedit: createEditTool(cwd, options?.edit),\n\t\twrite: createWriteTool(cwd, options?.write),\n\t\tgrep: createGrepTool(cwd, options?.grep),\n\t\tfind: createFindTool(cwd, options?.find),\n\t\tls: createLsTool(cwd, options?.ls),\n\t\ttool_schema: createToolSchemaTool(resolver),\n\t\ttodo_write: createTodoWriteTool(options?.todo_write?.store ?? noopTodoWriteStore),\n\t\tskill_search: createSkillSearchTool(options?.skill_search?.resolver ?? emptySkillSearchResolver),\n\t\tweb_search: createWebSearchTool(options?.web_search),\n\t\tweb_fetch: createWebFetchTool(options?.web_fetch),\n\t\task_user: createAskUserTool(),\n\t\tplan_present: createPlanPresentTool(),\n\t\tdelegate: createDelegateTool(options?.delegate?.runtime ?? noopDelegationRuntime),\n\t\ttest: createTestTool(cwd, options?.test),\n\t\t...(options?.lsp ? { lsp: createLspTool(cwd, options.lsp) } : {}),\n\t};\n}\n"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Type } from "typebox";
|
|
2
|
+
import type { ApexToolDefinition } from "./contract.ts";
|
|
3
|
+
declare const skillSearchSchema: Type.TObject<{
|
|
4
|
+
query: Type.TOptional<Type.TString>;
|
|
5
|
+
}>;
|
|
6
|
+
export interface SkillSearchEntry {
|
|
7
|
+
name: string;
|
|
8
|
+
description: string;
|
|
9
|
+
}
|
|
10
|
+
export interface SkillSearchResolver {
|
|
11
|
+
getSkills(): SkillSearchEntry[];
|
|
12
|
+
}
|
|
13
|
+
export interface SkillSearchResult {
|
|
14
|
+
name: string;
|
|
15
|
+
/** Present only when a query was given -- a name-only listing carries no description, matching the catalog's own name-only shape (ADR 0021). */
|
|
16
|
+
description?: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Resolve `skill_search`'s answer against the in-memory skill registry (ADR 0021,
|
|
20
|
+
* SKILL.6's catalog is names only; this resolves the description behind a name).
|
|
21
|
+
* Reads only from `resolver`; performs no filesystem or network I/O, which is why
|
|
22
|
+
* the tool's contract holds no capabilities. An unmatched query returns an empty
|
|
23
|
+
* array rather than throwing -- there is no such thing as an invalid search.
|
|
24
|
+
*/
|
|
25
|
+
export declare function searchSkills(resolver: SkillSearchResolver, query: string | undefined): SkillSearchResult[];
|
|
26
|
+
/** Create the model-callable skill discovery tool settled by ADR 0021. */
|
|
27
|
+
export declare function createSkillSearchToolDefinition(resolver: SkillSearchResolver): ApexToolDefinition<typeof skillSearchSchema>;
|
|
28
|
+
export declare function createSkillSearchTool(resolver: SkillSearchResolver): import("apex-code-agent-core").AgentTool<Type.TObject<{
|
|
29
|
+
query: Type.TOptional<Type.TString>;
|
|
30
|
+
}>, unknown>;
|
|
31
|
+
export {};
|
|
32
|
+
//# sourceMappingURL=skill-search.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skill-search.d.ts","sourceRoot":"","sources":["../../../src/core/tools/skill-search.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAGxD,QAAA,MAAM,iBAAiB;;EAOrB,CAAC;AAIH,MAAM,WAAW,gBAAgB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,mBAAmB;IACnC,SAAS,IAAI,gBAAgB,EAAE,CAAC;CAChC;AAED,MAAM,WAAW,iBAAiB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,gJAAgJ;IAChJ,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,mBAAmB,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,iBAAiB,EAAE,CAY1G;AAED,0EAA0E;AAC1E,wBAAgB,+BAA+B,CAC9C,QAAQ,EAAE,mBAAmB,GAC3B,kBAAkB,CAAC,OAAO,iBAAiB,CAAC,CA0B9C;AAED,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,mBAAmB;;aAElE","sourcesContent":["import type { AgentToolResult } from \"apex-code-agent-core\";\nimport { type Static, Type } from \"typebox\";\nimport type { ApexToolDefinition } from \"./contract.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\n\nconst skillSearchSchema = Type.Object({\n\tquery: Type.Optional(\n\t\tType.String({\n\t\t\tdescription:\n\t\t\t\t\"Case-insensitive substring matched against skill names and descriptions. Omit to list every available skill name.\",\n\t\t}),\n\t),\n});\n\ntype SkillSearchInput = Static<typeof skillSearchSchema>;\n\nexport interface SkillSearchEntry {\n\tname: string;\n\tdescription: string;\n}\n\nexport interface SkillSearchResolver {\n\tgetSkills(): SkillSearchEntry[];\n}\n\nexport interface SkillSearchResult {\n\tname: string;\n\t/** Present only when a query was given -- a name-only listing carries no description, matching the catalog's own name-only shape (ADR 0021). */\n\tdescription?: string;\n}\n\n/**\n * Resolve `skill_search`'s answer against the in-memory skill registry (ADR 0021,\n * SKILL.6's catalog is names only; this resolves the description behind a name).\n * Reads only from `resolver`; performs no filesystem or network I/O, which is why\n * the tool's contract holds no capabilities. An unmatched query returns an empty\n * array rather than throwing -- there is no such thing as an invalid search.\n */\nexport function searchSkills(resolver: SkillSearchResolver, query: string | undefined): SkillSearchResult[] {\n\tconst skills = resolver.getSkills();\n\tconst sorted = [...skills].sort((a, b) => a.name.localeCompare(b.name));\n\n\tif (query === undefined || query.trim() === \"\") {\n\t\treturn sorted.map((skill) => ({ name: skill.name }));\n\t}\n\n\tconst needle = query.trim().toLowerCase();\n\treturn sorted\n\t\t.filter((skill) => skill.name.toLowerCase().includes(needle) || skill.description.toLowerCase().includes(needle))\n\t\t.map((skill) => ({ name: skill.name, description: skill.description }));\n}\n\n/** Create the model-callable skill discovery tool settled by ADR 0021. */\nexport function createSkillSearchToolDefinition(\n\tresolver: SkillSearchResolver,\n): ApexToolDefinition<typeof skillSearchSchema> {\n\treturn {\n\t\tname: \"skill_search\",\n\t\tlabel: \"skill_search\",\n\t\tdescription:\n\t\t\t\"List available skill names, or search their names and descriptions by a query. Use to find a skill named in the prompt before reading its file.\",\n\t\tparameters: skillSearchSchema,\n\t\tcontract: {\n\t\t\tcapabilities: new Set(),\n\t\t\tpermission: {\n\t\t\t\tdefaultBehavior: \"allow\",\n\t\t\t\tmatches: () => false,\n\t\t\t\tdescribe: () => \"Searching the skill catalog\",\n\t\t\t\truleForCall: () => null,\n\t\t\t},\n\t\t\tcontext: { resultRecoverable: true, deferSchema: true },\n\t\t\tevidence: { emits: new Set(), capture: () => [] },\n\t\t},\n\t\tasync execute(_toolCallId, { query }: SkillSearchInput): Promise<AgentToolResult<unknown>> {\n\t\t\tconst results = searchSkills(resolver, query);\n\t\t\treturn {\n\t\t\t\tcontent: [{ type: \"text\", text: JSON.stringify({ results }) }],\n\t\t\t\tdetails: { results },\n\t\t\t};\n\t\t},\n\t};\n}\n\nexport function createSkillSearchTool(resolver: SkillSearchResolver) {\n\treturn wrapToolDefinition(createSkillSearchToolDefinition(resolver));\n}\n"]}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Type } from "typebox";
|
|
2
|
+
import { wrapToolDefinition } from "./tool-definition-wrapper.js";
|
|
3
|
+
const skillSearchSchema = Type.Object({
|
|
4
|
+
query: Type.Optional(Type.String({
|
|
5
|
+
description: "Case-insensitive substring matched against skill names and descriptions. Omit to list every available skill name.",
|
|
6
|
+
})),
|
|
7
|
+
});
|
|
8
|
+
/**
|
|
9
|
+
* Resolve `skill_search`'s answer against the in-memory skill registry (ADR 0021,
|
|
10
|
+
* SKILL.6's catalog is names only; this resolves the description behind a name).
|
|
11
|
+
* Reads only from `resolver`; performs no filesystem or network I/O, which is why
|
|
12
|
+
* the tool's contract holds no capabilities. An unmatched query returns an empty
|
|
13
|
+
* array rather than throwing -- there is no such thing as an invalid search.
|
|
14
|
+
*/
|
|
15
|
+
export function searchSkills(resolver, query) {
|
|
16
|
+
const skills = resolver.getSkills();
|
|
17
|
+
const sorted = [...skills].sort((a, b) => a.name.localeCompare(b.name));
|
|
18
|
+
if (query === undefined || query.trim() === "") {
|
|
19
|
+
return sorted.map((skill) => ({ name: skill.name }));
|
|
20
|
+
}
|
|
21
|
+
const needle = query.trim().toLowerCase();
|
|
22
|
+
return sorted
|
|
23
|
+
.filter((skill) => skill.name.toLowerCase().includes(needle) || skill.description.toLowerCase().includes(needle))
|
|
24
|
+
.map((skill) => ({ name: skill.name, description: skill.description }));
|
|
25
|
+
}
|
|
26
|
+
/** Create the model-callable skill discovery tool settled by ADR 0021. */
|
|
27
|
+
export function createSkillSearchToolDefinition(resolver) {
|
|
28
|
+
return {
|
|
29
|
+
name: "skill_search",
|
|
30
|
+
label: "skill_search",
|
|
31
|
+
description: "List available skill names, or search their names and descriptions by a query. Use to find a skill named in the prompt before reading its file.",
|
|
32
|
+
parameters: skillSearchSchema,
|
|
33
|
+
contract: {
|
|
34
|
+
capabilities: new Set(),
|
|
35
|
+
permission: {
|
|
36
|
+
defaultBehavior: "allow",
|
|
37
|
+
matches: () => false,
|
|
38
|
+
describe: () => "Searching the skill catalog",
|
|
39
|
+
ruleForCall: () => null,
|
|
40
|
+
},
|
|
41
|
+
context: { resultRecoverable: true, deferSchema: true },
|
|
42
|
+
evidence: { emits: new Set(), capture: () => [] },
|
|
43
|
+
},
|
|
44
|
+
async execute(_toolCallId, { query }) {
|
|
45
|
+
const results = searchSkills(resolver, query);
|
|
46
|
+
return {
|
|
47
|
+
content: [{ type: "text", text: JSON.stringify({ results }) }],
|
|
48
|
+
details: { results },
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export function createSkillSearchTool(resolver) {
|
|
54
|
+
return wrapToolDefinition(createSkillSearchToolDefinition(resolver));
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=skill-search.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skill-search.js","sourceRoot":"","sources":["../../../src/core/tools/skill-search.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAE5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAElE,MAAM,iBAAiB,GAAG,IAAI,CAAC,MAAM,CAAC;IACrC,KAAK,EAAE,IAAI,CAAC,QAAQ,CACnB,IAAI,CAAC,MAAM,CAAC;QACX,WAAW,EACV,mHAAmH;KACpH,CAAC,CACF;CACD,CAAC,CAAC;AAmBH;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,QAA6B,EAAE,KAAyB,EAAuB;IAC3G,MAAM,MAAM,GAAG,QAAQ,CAAC,SAAS,EAAE,CAAC;IACpC,MAAM,MAAM,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IAExE,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QAChD,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IACtD,CAAC;IAED,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,WAAW,EA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,EAAE,CAAC,EAAE,CAAC;gBAC9D,OAAO,EAAE,EAAE,OAAO,EAAE;aACpB,CAAC;QAAA,CACF;KACD,CAAC;AAAA,CACF;AAED,MAAM,UAAU,qBAAqB,CAAC,QAA6B,EAAE;IACpE,OAAO,kBAAkB,CAAC,+BAA+B,CAAC,QAAQ,CAAC,CAAC,CAAC;AAAA,CACrE","sourcesContent":["import type { AgentToolResult } from \"apex-code-agent-core\";\nimport { type Static, Type } from \"typebox\";\nimport type { ApexToolDefinition } from \"./contract.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\n\nconst skillSearchSchema = Type.Object({\n\tquery: Type.Optional(\n\t\tType.String({\n\t\t\tdescription:\n\t\t\t\t\"Case-insensitive substring matched against skill names and descriptions. Omit to list every available skill name.\",\n\t\t}),\n\t),\n});\n\ntype SkillSearchInput = Static<typeof skillSearchSchema>;\n\nexport interface SkillSearchEntry {\n\tname: string;\n\tdescription: string;\n}\n\nexport interface SkillSearchResolver {\n\tgetSkills(): SkillSearchEntry[];\n}\n\nexport interface SkillSearchResult {\n\tname: string;\n\t/** Present only when a query was given -- a name-only listing carries no description, matching the catalog's own name-only shape (ADR 0021). */\n\tdescription?: string;\n}\n\n/**\n * Resolve `skill_search`'s answer against the in-memory skill registry (ADR 0021,\n * SKILL.6's catalog is names only; this resolves the description behind a name).\n * Reads only from `resolver`; performs no filesystem or network I/O, which is why\n * the tool's contract holds no capabilities. An unmatched query returns an empty\n * array rather than throwing -- there is no such thing as an invalid search.\n */\nexport function searchSkills(resolver: SkillSearchResolver, query: string | undefined): SkillSearchResult[] {\n\tconst skills = resolver.getSkills();\n\tconst sorted = [...skills].sort((a, b) => a.name.localeCompare(b.name));\n\n\tif (query === undefined || query.trim() === \"\") {\n\t\treturn sorted.map((skill) => ({ name: skill.name }));\n\t}\n\n\tconst needle = query.trim().toLowerCase();\n\treturn sorted\n\t\t.filter((skill) => skill.name.toLowerCase().includes(needle) || skill.description.toLowerCase().includes(needle))\n\t\t.map((skill) => ({ name: skill.name, description: skill.description }));\n}\n\n/** Create the model-callable skill discovery tool settled by ADR 0021. */\nexport function createSkillSearchToolDefinition(\n\tresolver: SkillSearchResolver,\n): ApexToolDefinition<typeof skillSearchSchema> {\n\treturn {\n\t\tname: \"skill_search\",\n\t\tlabel: \"skill_search\",\n\t\tdescription:\n\t\t\t\"List available skill names, or search their names and descriptions by a query. Use to find a skill named in the prompt before reading its file.\",\n\t\tparameters: skillSearchSchema,\n\t\tcontract: {\n\t\t\tcapabilities: new Set(),\n\t\t\tpermission: {\n\t\t\t\tdefaultBehavior: \"allow\",\n\t\t\t\tmatches: () => false,\n\t\t\t\tdescribe: () => \"Searching the skill catalog\",\n\t\t\t\truleForCall: () => null,\n\t\t\t},\n\t\t\tcontext: { resultRecoverable: true, deferSchema: true },\n\t\t\tevidence: { emits: new Set(), capture: () => [] },\n\t\t},\n\t\tasync execute(_toolCallId, { query }: SkillSearchInput): Promise<AgentToolResult<unknown>> {\n\t\t\tconst results = searchSkills(resolver, query);\n\t\t\treturn {\n\t\t\t\tcontent: [{ type: \"text\", text: JSON.stringify({ results }) }],\n\t\t\t\tdetails: { results },\n\t\t\t};\n\t\t},\n\t};\n}\n\nexport function createSkillSearchTool(resolver: SkillSearchResolver) {\n\treturn wrapToolDefinition(createSkillSearchToolDefinition(resolver));\n}\n"]}
|
|
@@ -7,18 +7,20 @@ interface ScopedModelItem {
|
|
|
7
7
|
thinkingLevel?: string;
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
|
-
* Component that renders a model selector
|
|
10
|
+
* Component that renders a two-step model selector: provider first, then that provider's models.
|
|
11
11
|
*/
|
|
12
12
|
export declare class ModelSelectorComponent extends Container implements Focusable {
|
|
13
13
|
private searchInput;
|
|
14
14
|
private _focused;
|
|
15
15
|
get focused(): boolean;
|
|
16
16
|
set focused(value: boolean);
|
|
17
|
+
private headerContainer;
|
|
17
18
|
private listContainer;
|
|
18
19
|
private allModels;
|
|
19
20
|
private scopedModelItems;
|
|
20
21
|
private activeModels;
|
|
21
|
-
private
|
|
22
|
+
private rows;
|
|
23
|
+
private filteredRows;
|
|
22
24
|
private selectedIndex;
|
|
23
25
|
private currentModel?;
|
|
24
26
|
private settingsManager;
|
|
@@ -31,22 +33,33 @@ export declare class ModelSelectorComponent extends Container implements Focusab
|
|
|
31
33
|
private tui;
|
|
32
34
|
private scopedModels;
|
|
33
35
|
private scope;
|
|
34
|
-
private
|
|
35
|
-
private scopeHintText?;
|
|
36
|
+
private step;
|
|
36
37
|
private readonly refreshAbortController;
|
|
37
38
|
private refreshTimeout?;
|
|
38
39
|
private closed;
|
|
39
40
|
constructor(tui: TUI, currentModel: Model<any> | undefined, settingsManager: SettingsManager, modelRuntime: ModelRuntime, scopedModels: ReadonlyArray<ScopedModelItem>, onSelect: (model: Model<any>) => void, onCancel: () => void, initialSearchInput?: string);
|
|
41
|
+
private initialStep;
|
|
42
|
+
private activeProviders;
|
|
40
43
|
private loadModelsFromSnapshot;
|
|
41
44
|
private refreshModels;
|
|
42
45
|
dispose(): void;
|
|
43
46
|
private sortModels;
|
|
47
|
+
private rebuildRows;
|
|
48
|
+
private defaultSelectedIndex;
|
|
49
|
+
private setStep;
|
|
50
|
+
private isDrilledIn;
|
|
51
|
+
/** Escape returns to the provider list whenever there is a provider list worth returning to. */
|
|
52
|
+
private canGoBack;
|
|
53
|
+
private renderHeader;
|
|
44
54
|
private getScopeText;
|
|
45
|
-
private
|
|
55
|
+
private getHintText;
|
|
46
56
|
private setScope;
|
|
47
|
-
private
|
|
57
|
+
private rowSearchText;
|
|
58
|
+
private filterRows;
|
|
59
|
+
private renderRow;
|
|
48
60
|
private updateList;
|
|
49
61
|
handleInput(keyData: string): void;
|
|
62
|
+
private confirmSelection;
|
|
50
63
|
private handleSelect;
|
|
51
64
|
getSearchInput(): Input;
|
|
52
65
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-selector.d.ts","sourceRoot":"","sources":["../../../../src/modes/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;IAC7B,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAAyB;IAChE,OAAO,CAAC,cAAc,CAAC,CAAgC;IACvD,OAAO,CAAC,MAAM,CAAS;IAEvB,YACC,GAAG,EAAE,GAAG,EACR,YAAY,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,SAAS,EACpC,eAAe,EAAE,eAAe,EAChC,YAAY,EAAE,YAAY,EAC1B,YAAY,EAAE,aAAa,CAAC,eAAe,CAAC,EAC5C,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,KAAK,IAAI,EACrC,QAAQ,EAAE,MAAM,IAAI,EACpB,kBAAkB,CAAC,EAAE,MAAM,EA2D3B;IAED,OAAO,CAAC,sBAAsB;YAuBhB,aAAa;IAwC3B,OAAO,IAAI,IAAI,CAKd;IAED,OAAO,CAAC,UAAU;IAalB,OAAO,CAAC,YAAY;IAMpB,OAAO,CAAC,gBAAgB;IAIxB,OAAO,CAAC,QAAQ;IAYhB,OAAO,CAAC,YAAY;IAapB,OAAO,CAAC,UAAU;IA+DlB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAyCjC;IAED,OAAO,CAAC,YAAY;IAOpB,cAAc,IAAI,KAAK,CAEtB;CACD","sourcesContent":["import { type Model, modelsAreEqual } from \"@earendil-works/pi-ai\";\nimport {\n\tContainer,\n\ttype Focusable,\n\tfuzzyFilter,\n\tgetKeybindings,\n\tInput,\n\tSpacer,\n\tText,\n\ttype TUI,\n} from \"@earendil-works/pi-tui\";\nimport type { ModelRuntime } from \"../../../core/model-runtime.ts\";\nimport type { SettingsManager } from \"../../../core/settings-manager.ts\";\nimport { getModelSelectorSearchText } from \"../model-search.ts\";\nimport { theme } from \"../theme/theme.ts\";\nimport { DynamicBorder } from \"./dynamic-border.ts\";\nimport { keyHint } from \"./keybinding-hints.ts\";\n\ninterface ModelItem {\n\tprovider: string;\n\tid: string;\n\tmodel: Model<any>;\n}\n\ninterface ScopedModelItem {\n\tmodel: Model<any>;\n\tthinkingLevel?: string;\n}\n\ntype ModelScope = \"all\" | \"scoped\";\n\n/**\n * Component that renders a model selector with search\n */\nexport class ModelSelectorComponent extends Container implements Focusable {\n\tprivate searchInput: Input;\n\n\t// Focusable implementation - propagate to searchInput for IME cursor positioning\n\tprivate _focused = false;\n\tget focused(): boolean {\n\t\treturn this._focused;\n\t}\n\tset focused(value: boolean) {\n\t\tthis._focused = value;\n\t\tthis.searchInput.focused = value;\n\t}\n\tprivate listContainer: Container;\n\tprivate allModels: ModelItem[] = [];\n\tprivate scopedModelItems: ModelItem[] = [];\n\tprivate activeModels: ModelItem[] = [];\n\tprivate filteredModels: ModelItem[] = [];\n\tprivate selectedIndex: number = 0;\n\tprivate currentModel?: Model<any>;\n\tprivate settingsManager: SettingsManager;\n\tprivate modelRuntime: ModelRuntime;\n\tprivate onSelectCallback: (model: Model<any>) => void;\n\tprivate onCancelCallback: () => void;\n\tprivate errorMessage?: string;\n\tprivate refreshStatusMessage = \"Refreshing model catalogs…\";\n\tprivate refreshStatusSuccess = false;\n\tprivate tui: TUI;\n\tprivate scopedModels: ReadonlyArray<ScopedModelItem>;\n\tprivate scope: ModelScope = \"all\";\n\tprivate scopeText?: Text;\n\tprivate scopeHintText?: Text;\n\tprivate readonly refreshAbortController = new AbortController();\n\tprivate refreshTimeout?: ReturnType<typeof setTimeout>;\n\tprivate closed = false;\n\n\tconstructor(\n\t\ttui: TUI,\n\t\tcurrentModel: Model<any> | undefined,\n\t\tsettingsManager: SettingsManager,\n\t\tmodelRuntime: ModelRuntime,\n\t\tscopedModels: ReadonlyArray<ScopedModelItem>,\n\t\tonSelect: (model: Model<any>) => void,\n\t\tonCancel: () => void,\n\t\tinitialSearchInput?: string,\n\t) {\n\t\tsuper();\n\n\t\tthis.tui = tui;\n\t\tthis.currentModel = currentModel;\n\t\tthis.settingsManager = settingsManager;\n\t\tthis.modelRuntime = modelRuntime;\n\t\tthis.scopedModels = scopedModels;\n\t\tthis.scope = scopedModels.length > 0 ? \"scoped\" : \"all\";\n\t\tthis.onSelectCallback = onSelect;\n\t\tthis.onCancelCallback = onCancel;\n\n\t\t// Add top border\n\t\tthis.addChild(new DynamicBorder());\n\t\tthis.addChild(new Spacer(1));\n\n\t\t// Add hint about model filtering\n\t\tif (scopedModels.length > 0) {\n\t\t\tthis.scopeText = new Text(this.getScopeText(), 0, 0);\n\t\t\tthis.addChild(this.scopeText);\n\t\t\tthis.scopeHintText = new Text(this.getScopeHintText(), 0, 0);\n\t\t\tthis.addChild(this.scopeHintText);\n\t\t} else {\n\t\t\tconst hintText = \"Only showing models from configured providers. Use /login to add providers.\";\n\t\t\tthis.addChild(new Text(theme.fg(\"warning\", hintText), 0, 0));\n\t\t}\n\t\tthis.addChild(new Spacer(1));\n\n\t\t// Create search input\n\t\tthis.searchInput = new Input();\n\t\tif (initialSearchInput) {\n\t\t\tthis.searchInput.setValue(initialSearchInput);\n\t\t}\n\t\tthis.searchInput.onSubmit = () => {\n\t\t\t// Enter on search input selects the first filtered item\n\t\t\tif (this.filteredModels[this.selectedIndex]) {\n\t\t\t\tthis.handleSelect(this.filteredModels[this.selectedIndex].model);\n\t\t\t}\n\t\t};\n\t\tthis.addChild(this.searchInput);\n\n\t\tthis.addChild(new Spacer(1));\n\n\t\t// Create list container\n\t\tthis.listContainer = new Container();\n\t\tthis.addChild(this.listContainer);\n\n\t\tthis.addChild(new Spacer(1));\n\n\t\t// Add bottom border\n\t\tthis.addChild(new DynamicBorder());\n\n\t\t// Render the current snapshot immediately, then refresh in the background.\n\t\tthis.loadModelsFromSnapshot();\n\t\tif (initialSearchInput) this.filterModels(initialSearchInput);\n\t\telse this.updateList();\n\t\tthis.tui.requestRender();\n\t\tvoid this.refreshModels();\n\t}\n\n\tprivate loadModelsFromSnapshot(): void {\n\t\tconst models = this.modelRuntime.getAvailableSnapshot().map((model: Model<any>) => ({\n\t\t\tprovider: model.provider,\n\t\t\tid: model.id,\n\t\t\tmodel,\n\t\t}));\n\t\tthis.allModels = this.sortModels(models);\n\t\tthis.scopedModels = this.scopedModels.map((scoped) => {\n\t\t\tconst refreshed = this.modelRuntime.getModel(scoped.model.provider, scoped.model.id);\n\t\t\treturn refreshed ? { ...scoped, model: refreshed } : scoped;\n\t\t});\n\t\tthis.scopedModelItems = this.scopedModels.map((scoped) => ({\n\t\t\tprovider: scoped.model.provider,\n\t\t\tid: scoped.model.id,\n\t\t\tmodel: scoped.model,\n\t\t}));\n\t\tthis.activeModels = this.scope === \"scoped\" ? this.scopedModelItems : this.allModels;\n\t\tthis.filteredModels = this.activeModels;\n\t\tconst currentIndex = this.filteredModels.findIndex((item) => modelsAreEqual(this.currentModel, item.model));\n\t\tthis.selectedIndex =\n\t\t\tcurrentIndex >= 0 ? currentIndex : Math.min(this.selectedIndex, Math.max(0, this.filteredModels.length - 1));\n\t}\n\n\tprivate async refreshModels(): Promise<void> {\n\t\tconst timeoutMs = 15_000;\n\t\tlet timedOut = false;\n\t\tthis.refreshTimeout = setTimeout(() => {\n\t\t\ttimedOut = true;\n\t\t\tthis.refreshAbortController.abort();\n\t\t}, timeoutMs);\n\t\ttry {\n\t\t\tconst result = await this.modelRuntime.refresh({ signal: this.refreshAbortController.signal });\n\t\t\tif (this.closed) return;\n\t\t\tthis.refreshStatusMessage = \"\";\n\t\t\tif (result.aborted && timedOut) {\n\t\t\t\tthis.errorMessage = \"Model refresh timed out; showing cached models.\";\n\t\t\t} else if (result.errors.size === 1) {\n\t\t\t\tthis.errorMessage = `Could not refresh ${result.errors.keys().next().value}; showing cached models.`;\n\t\t\t} else if (result.errors.size > 1) {\n\t\t\t\tthis.errorMessage = `Could not refresh ${result.errors.size} model catalogs (${[...result.errors.keys()].join(\", \")}); showing cached models.`;\n\t\t\t} else {\n\t\t\t\tthis.errorMessage = this.modelRuntime.getError();\n\t\t\t\tif (!this.errorMessage) {\n\t\t\t\t\tthis.refreshStatusMessage = \"Model catalogs refreshed.\";\n\t\t\t\t\tthis.refreshStatusSuccess = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis.loadModelsFromSnapshot();\n\t\t\tthis.filterModels(this.searchInput.getValue());\n\t\t\tthis.tui.requestRender();\n\t\t} catch (error) {\n\t\t\tif (this.closed) return;\n\t\t\tthis.refreshStatusMessage = \"\";\n\t\t\tthis.errorMessage = timedOut\n\t\t\t\t? \"Model refresh timed out; showing cached models.\"\n\t\t\t\t: `Could not refresh model catalogs: ${error instanceof Error ? error.message : String(error)}`;\n\t\t\tthis.updateList();\n\t\t\tthis.tui.requestRender();\n\t\t} finally {\n\t\t\tif (this.refreshTimeout) clearTimeout(this.refreshTimeout);\n\t\t}\n\t}\n\n\tdispose(): void {\n\t\tif (this.closed) return;\n\t\tthis.closed = true;\n\t\tif (this.refreshTimeout) clearTimeout(this.refreshTimeout);\n\t\tthis.refreshAbortController.abort();\n\t}\n\n\tprivate sortModels(models: ModelItem[]): ModelItem[] {\n\t\tconst sorted = [...models];\n\t\t// Sort: current model first, then by provider\n\t\tsorted.sort((a, b) => {\n\t\t\tconst aIsCurrent = modelsAreEqual(this.currentModel, a.model);\n\t\t\tconst bIsCurrent = modelsAreEqual(this.currentModel, b.model);\n\t\t\tif (aIsCurrent && !bIsCurrent) return -1;\n\t\t\tif (!aIsCurrent && bIsCurrent) return 1;\n\t\t\treturn a.provider.localeCompare(b.provider);\n\t\t});\n\t\treturn sorted;\n\t}\n\n\tprivate getScopeText(): string {\n\t\tconst allText = this.scope === \"all\" ? theme.fg(\"accent\", \"all\") : theme.fg(\"muted\", \"all\");\n\t\tconst scopedText = this.scope === \"scoped\" ? theme.fg(\"accent\", \"scoped\") : theme.fg(\"muted\", \"scoped\");\n\t\treturn `${theme.fg(\"muted\", \"Scope: \")}${allText}${theme.fg(\"muted\", \" | \")}${scopedText}`;\n\t}\n\n\tprivate getScopeHintText(): string {\n\t\treturn keyHint(\"tui.input.tab\", \"scope\") + theme.fg(\"muted\", \" (all/scoped)\");\n\t}\n\n\tprivate setScope(scope: ModelScope): void {\n\t\tif (this.scope === scope) return;\n\t\tthis.scope = scope;\n\t\tthis.activeModels = this.scope === \"scoped\" ? this.scopedModelItems : this.allModels;\n\t\tconst currentIndex = this.activeModels.findIndex((item) => modelsAreEqual(this.currentModel, item.model));\n\t\tthis.selectedIndex = currentIndex >= 0 ? currentIndex : 0;\n\t\tthis.filterModels(this.searchInput.getValue());\n\t\tif (this.scopeText) {\n\t\t\tthis.scopeText.setText(this.getScopeText());\n\t\t}\n\t}\n\n\tprivate filterModels(query: string): void {\n\t\tthis.filteredModels = query\n\t\t\t? fuzzyFilter(this.activeModels, query, ({ id, provider, model }) =>\n\t\t\t\t\tgetModelSelectorSearchText({ id, provider, name: model.name }),\n\t\t\t\t)\n\t\t\t: this.activeModels;\n\t\t// When filtering by a query, move the selector to the top row so the best\n\t\t// match is highlighted. When the query is cleared, keep the current position\n\t\t// clamped to the (restored) list length.\n\t\tthis.selectedIndex = query ? 0 : Math.min(this.selectedIndex, Math.max(0, this.filteredModels.length - 1));\n\t\tthis.updateList();\n\t}\n\n\tprivate updateList(): void {\n\t\tthis.listContainer.clear();\n\n\t\tconst maxVisible = 10;\n\t\tconst startIndex = Math.max(\n\t\t\t0,\n\t\t\tMath.min(this.selectedIndex - Math.floor(maxVisible / 2), this.filteredModels.length - maxVisible),\n\t\t);\n\t\tconst endIndex = Math.min(startIndex + maxVisible, this.filteredModels.length);\n\n\t\t// Show visible slice of filtered models\n\t\tfor (let i = startIndex; i < endIndex; i++) {\n\t\t\tconst item = this.filteredModels[i];\n\t\t\tif (!item) continue;\n\n\t\t\tconst isSelected = i === this.selectedIndex;\n\t\t\tconst isCurrent = modelsAreEqual(this.currentModel, item.model);\n\n\t\t\tlet line = \"\";\n\t\t\tif (isSelected) {\n\t\t\t\tconst prefix = theme.fg(\"accent\", \"→ \");\n\t\t\t\tconst modelText = `${item.id}`;\n\t\t\t\tconst providerBadge = theme.fg(\"muted\", `[${item.provider}]`);\n\t\t\t\tconst checkmark = isCurrent ? theme.fg(\"success\", \" ✓\") : \"\";\n\t\t\t\tline = `${prefix + theme.fg(\"accent\", modelText)} ${providerBadge}${checkmark}`;\n\t\t\t} else {\n\t\t\t\tconst modelText = ` ${item.id}`;\n\t\t\t\tconst providerBadge = theme.fg(\"muted\", `[${item.provider}]`);\n\t\t\t\tconst checkmark = isCurrent ? theme.fg(\"success\", \" ✓\") : \"\";\n\t\t\t\tline = `${modelText} ${providerBadge}${checkmark}`;\n\t\t\t}\n\n\t\t\tthis.listContainer.addChild(new Text(line, 0, 0));\n\t\t}\n\n\t\t// Add scroll indicator if needed\n\t\tif (startIndex > 0 || endIndex < this.filteredModels.length) {\n\t\t\tconst scrollInfo = theme.fg(\"muted\", ` (${this.selectedIndex + 1}/${this.filteredModels.length})`);\n\t\t\tthis.listContainer.addChild(new Text(scrollInfo, 0, 0));\n\t\t}\n\n\t\t// Show error message or \"no results\" if empty\n\t\tif (this.errorMessage) {\n\t\t\t// Show error in red\n\t\t\tconst errorLines = this.errorMessage.split(\"\\n\");\n\t\t\tfor (const line of errorLines) {\n\t\t\t\tthis.listContainer.addChild(new Text(theme.fg(\"error\", line), 0, 0));\n\t\t\t}\n\t\t} else if (this.filteredModels.length === 0) {\n\t\t\tthis.listContainer.addChild(new Text(theme.fg(\"muted\", \" No matching models\"), 0, 0));\n\t\t} else {\n\t\t\tconst selected = this.filteredModels[this.selectedIndex];\n\t\t\tthis.listContainer.addChild(new Spacer(1));\n\t\t\tthis.listContainer.addChild(new Text(theme.fg(\"muted\", ` Model Name: ${selected.model.name}`), 0, 0));\n\t\t}\n\t\tif (this.refreshStatusMessage) {\n\t\t\tthis.listContainer.addChild(new Spacer(1));\n\t\t\tthis.listContainer.addChild(\n\t\t\t\tnew Text(theme.fg(this.refreshStatusSuccess ? \"success\" : \"muted\", ` ${this.refreshStatusMessage}`), 0, 0),\n\t\t\t);\n\t\t}\n\t}\n\n\thandleInput(keyData: string): void {\n\t\tconst kb = getKeybindings();\n\t\tif (kb.matches(keyData, \"tui.input.tab\")) {\n\t\t\tif (this.scopedModelItems.length > 0) {\n\t\t\t\tconst nextScope: ModelScope = this.scope === \"all\" ? \"scoped\" : \"all\";\n\t\t\t\tthis.setScope(nextScope);\n\t\t\t\tif (this.scopeHintText) {\n\t\t\t\t\tthis.scopeHintText.setText(this.getScopeHintText());\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\t// Up arrow - wrap to bottom when at top\n\t\tif (kb.matches(keyData, \"tui.select.up\")) {\n\t\t\tif (this.filteredModels.length === 0) return;\n\t\t\tthis.selectedIndex = this.selectedIndex === 0 ? this.filteredModels.length - 1 : this.selectedIndex - 1;\n\t\t\tthis.updateList();\n\t\t}\n\t\t// Down arrow - wrap to top when at bottom\n\t\telse if (kb.matches(keyData, \"tui.select.down\")) {\n\t\t\tif (this.filteredModels.length === 0) return;\n\t\t\tthis.selectedIndex = this.selectedIndex === this.filteredModels.length - 1 ? 0 : this.selectedIndex + 1;\n\t\t\tthis.updateList();\n\t\t}\n\t\t// Enter\n\t\telse if (kb.matches(keyData, \"tui.select.confirm\")) {\n\t\t\tconst selectedModel = this.filteredModels[this.selectedIndex];\n\t\t\tif (selectedModel) {\n\t\t\t\tthis.handleSelect(selectedModel.model);\n\t\t\t}\n\t\t}\n\t\t// Escape or Ctrl+C\n\t\telse if (kb.matches(keyData, \"tui.select.cancel\")) {\n\t\t\tthis.dispose();\n\t\t\tthis.onCancelCallback();\n\t\t}\n\t\t// Pass everything else to search input\n\t\telse {\n\t\t\tthis.searchInput.handleInput(keyData);\n\t\t\tthis.filterModels(this.searchInput.getValue());\n\t\t}\n\t}\n\n\tprivate handleSelect(model: Model<any>): void {\n\t\tthis.dispose();\n\t\t// Save as new default\n\t\tthis.settingsManager.setDefaultModelAndProvider(model.provider, model.id);\n\t\tthis.onSelectCallback(model);\n\t}\n\n\tgetSearchInput(): Input {\n\t\treturn this.searchInput;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"model-selector.d.ts","sourceRoot":"","sources":["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tmatchesKey,\n\tSpacer,\n\tText,\n\ttype TUI,\n} from \"@earendil-works/pi-tui\";\nimport type { ModelRuntime } from \"../../../core/model-runtime.ts\";\nimport type { SettingsManager } from \"../../../core/settings-manager.ts\";\nimport { getModelSelectorSearchText } from \"../model-search.ts\";\nimport { theme } from \"../theme/theme.ts\";\nimport { DynamicBorder } from \"./dynamic-border.ts\";\nimport { keyHint, rawKeyHint } from \"./keybinding-hints.ts\";\n\ninterface ModelItem {\n\tprovider: string;\n\tid: string;\n\tmodel: Model<any>;\n}\n\ninterface ScopedModelItem {\n\tmodel: Model<any>;\n\tthinkingLevel?: string;\n}\n\ntype ModelScope = \"all\" | \"scoped\";\n\n/**\n * Which of the two steps the selector is on. `provider: null` lists every provider's models at once,\n * which is how a `/model <search>` invocation and a single-provider setup both open.\n */\ntype Step = { kind: \"providers\" } | { kind: \"models\"; provider: string | null };\n\ntype Row =\n\t| { kind: \"provider\"; provider: string; count: number; hasCurrent: boolean }\n\t| { kind: \"model\"; item: ModelItem };\n\nconst MAX_VISIBLE_ROWS = 10;\n\n/**\n * Component that renders a two-step model selector: provider first, then that provider's models.\n */\nexport class ModelSelectorComponent extends Container implements Focusable {\n\tprivate searchInput: Input;\n\n\t// Focusable implementation - propagate to searchInput for IME cursor positioning\n\tprivate _focused = false;\n\tget focused(): boolean {\n\t\treturn this._focused;\n\t}\n\tset focused(value: boolean) {\n\t\tthis._focused = value;\n\t\tthis.searchInput.focused = value;\n\t}\n\tprivate headerContainer: Container;\n\tprivate listContainer: Container;\n\tprivate allModels: ModelItem[] = [];\n\tprivate scopedModelItems: ModelItem[] = [];\n\tprivate activeModels: ModelItem[] = [];\n\tprivate rows: Row[] = [];\n\tprivate filteredRows: Row[] = [];\n\tprivate selectedIndex: number = 0;\n\tprivate currentModel?: Model<any>;\n\tprivate settingsManager: SettingsManager;\n\tprivate modelRuntime: ModelRuntime;\n\tprivate onSelectCallback: (model: Model<any>) => void;\n\tprivate onCancelCallback: () => void;\n\tprivate errorMessage?: string;\n\tprivate refreshStatusMessage = \"Refreshing model catalogs…\";\n\tprivate refreshStatusSuccess = false;\n\tprivate tui: TUI;\n\tprivate scopedModels: ReadonlyArray<ScopedModelItem>;\n\tprivate scope: ModelScope = \"all\";\n\tprivate step: Step = { kind: \"providers\" };\n\tprivate readonly refreshAbortController = new AbortController();\n\tprivate refreshTimeout?: ReturnType<typeof setTimeout>;\n\tprivate closed = false;\n\n\tconstructor(\n\t\ttui: TUI,\n\t\tcurrentModel: Model<any> | undefined,\n\t\tsettingsManager: SettingsManager,\n\t\tmodelRuntime: ModelRuntime,\n\t\tscopedModels: ReadonlyArray<ScopedModelItem>,\n\t\tonSelect: (model: Model<any>) => void,\n\t\tonCancel: () => void,\n\t\tinitialSearchInput?: string,\n\t) {\n\t\tsuper();\n\n\t\tthis.tui = tui;\n\t\tthis.currentModel = currentModel;\n\t\tthis.settingsManager = settingsManager;\n\t\tthis.modelRuntime = modelRuntime;\n\t\tthis.scopedModels = scopedModels;\n\t\tthis.scope = scopedModels.length > 0 ? \"scoped\" : \"all\";\n\t\tthis.onSelectCallback = onSelect;\n\t\tthis.onCancelCallback = onCancel;\n\n\t\t// Add top border\n\t\tthis.addChild(new DynamicBorder());\n\t\tthis.addChild(new Spacer(1));\n\n\t\tthis.headerContainer = new Container();\n\t\tthis.addChild(this.headerContainer);\n\t\tthis.addChild(new Spacer(1));\n\n\t\t// Create search input\n\t\tthis.searchInput = new Input();\n\t\tif (initialSearchInput) {\n\t\t\tthis.searchInput.setValue(initialSearchInput);\n\t\t}\n\t\tthis.searchInput.onSubmit = () => this.confirmSelection();\n\t\tthis.addChild(this.searchInput);\n\n\t\tthis.addChild(new Spacer(1));\n\n\t\t// Create list container\n\t\tthis.listContainer = new Container();\n\t\tthis.addChild(this.listContainer);\n\n\t\tthis.addChild(new Spacer(1));\n\n\t\t// Add bottom border\n\t\tthis.addChild(new DynamicBorder());\n\n\t\t// Render the current snapshot immediately, then refresh in the background.\n\t\tthis.loadModelsFromSnapshot();\n\t\tthis.step = this.initialStep(initialSearchInput);\n\t\tthis.rebuildRows();\n\t\tthis.selectedIndex = this.defaultSelectedIndex();\n\t\tthis.renderHeader();\n\t\tthis.filterRows(this.searchInput.getValue());\n\t\tthis.tui.requestRender();\n\t\tvoid this.refreshModels();\n\t}\n\n\tprivate initialStep(initialSearchInput: string | undefined): Step {\n\t\tconst providers = this.activeProviders();\n\t\tif (initialSearchInput) return { kind: \"models\", provider: null };\n\t\tif (providers.length <= 1) return { kind: \"models\", provider: providers[0] ?? null };\n\t\treturn { kind: \"providers\" };\n\t}\n\n\tprivate activeProviders(): string[] {\n\t\treturn [...new Set(this.activeModels.map((item) => item.provider))];\n\t}\n\n\tprivate loadModelsFromSnapshot(): void {\n\t\tconst models = this.modelRuntime.getAvailableSnapshot().map((model: Model<any>) => ({\n\t\t\tprovider: model.provider,\n\t\t\tid: model.id,\n\t\t\tmodel,\n\t\t}));\n\t\tthis.allModels = this.sortModels(models);\n\t\tthis.scopedModels = this.scopedModels.map((scoped) => {\n\t\t\tconst refreshed = this.modelRuntime.getModel(scoped.model.provider, scoped.model.id);\n\t\t\treturn refreshed ? { ...scoped, model: refreshed } : scoped;\n\t\t});\n\t\tthis.scopedModelItems = this.scopedModels.map((scoped) => ({\n\t\t\tprovider: scoped.model.provider,\n\t\t\tid: scoped.model.id,\n\t\t\tmodel: scoped.model,\n\t\t}));\n\t\tthis.activeModels = this.scope === \"scoped\" ? this.scopedModelItems : this.allModels;\n\t}\n\n\tprivate async refreshModels(): Promise<void> {\n\t\tconst timeoutMs = 15_000;\n\t\tlet timedOut = false;\n\t\tthis.refreshTimeout = setTimeout(() => {\n\t\t\ttimedOut = true;\n\t\t\tthis.refreshAbortController.abort();\n\t\t}, timeoutMs);\n\t\ttry {\n\t\t\tconst result = await this.modelRuntime.refresh({ signal: this.refreshAbortController.signal });\n\t\t\tif (this.closed) return;\n\t\t\tthis.refreshStatusMessage = \"\";\n\t\t\tif (result.aborted && timedOut) {\n\t\t\t\tthis.errorMessage = \"Model refresh timed out; showing cached models.\";\n\t\t\t} else if (result.errors.size === 1) {\n\t\t\t\tthis.errorMessage = `Could not refresh ${result.errors.keys().next().value}; showing cached models.`;\n\t\t\t} else if (result.errors.size > 1) {\n\t\t\t\tthis.errorMessage = `Could not refresh ${result.errors.size} model catalogs (${[...result.errors.keys()].join(\", \")}); showing cached models.`;\n\t\t\t} else {\n\t\t\t\tthis.errorMessage = this.modelRuntime.getError();\n\t\t\t\tif (!this.errorMessage) {\n\t\t\t\t\tthis.refreshStatusMessage = \"Model catalogs refreshed.\";\n\t\t\t\t\tthis.refreshStatusSuccess = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis.loadModelsFromSnapshot();\n\t\t\tthis.rebuildRows();\n\t\t\tthis.renderHeader();\n\t\t\tthis.filterRows(this.searchInput.getValue());\n\t\t\tthis.tui.requestRender();\n\t\t} catch (error) {\n\t\t\tif (this.closed) return;\n\t\t\tthis.refreshStatusMessage = \"\";\n\t\t\tthis.errorMessage = timedOut\n\t\t\t\t? \"Model refresh timed out; showing cached models.\"\n\t\t\t\t: `Could not refresh model catalogs: ${error instanceof Error ? error.message : String(error)}`;\n\t\t\tthis.updateList();\n\t\t\tthis.tui.requestRender();\n\t\t} finally {\n\t\t\tif (this.refreshTimeout) clearTimeout(this.refreshTimeout);\n\t\t}\n\t}\n\n\tdispose(): void {\n\t\tif (this.closed) return;\n\t\tthis.closed = true;\n\t\tif (this.refreshTimeout) clearTimeout(this.refreshTimeout);\n\t\tthis.refreshAbortController.abort();\n\t}\n\n\tprivate sortModels(models: ModelItem[]): ModelItem[] {\n\t\tconst sorted = [...models];\n\t\t// Sort: current model first, then by provider\n\t\tsorted.sort((a, b) => {\n\t\t\tconst aIsCurrent = modelsAreEqual(this.currentModel, a.model);\n\t\t\tconst bIsCurrent = modelsAreEqual(this.currentModel, b.model);\n\t\t\tif (aIsCurrent && !bIsCurrent) return -1;\n\t\t\tif (!aIsCurrent && bIsCurrent) return 1;\n\t\t\treturn a.provider.localeCompare(b.provider);\n\t\t});\n\t\treturn sorted;\n\t}\n\n\tprivate rebuildRows(): void {\n\t\tif (this.step.kind === \"providers\") {\n\t\t\tconst byProvider = new Map<string, ModelItem[]>();\n\t\t\tfor (const item of this.activeModels) {\n\t\t\t\tconst existing = byProvider.get(item.provider);\n\t\t\t\tif (existing) existing.push(item);\n\t\t\t\telse byProvider.set(item.provider, [item]);\n\t\t\t}\n\t\t\tconst providerRows: Row[] = [...byProvider].map(([provider, items]) => ({\n\t\t\t\tkind: \"provider\",\n\t\t\t\tprovider,\n\t\t\t\tcount: items.length,\n\t\t\t\thasCurrent: items.some((item) => modelsAreEqual(this.currentModel, item.model)),\n\t\t\t}));\n\t\t\tproviderRows.sort((a, b) => {\n\t\t\t\tif (a.kind !== \"provider\" || b.kind !== \"provider\") return 0;\n\t\t\t\tif (a.hasCurrent !== b.hasCurrent) return a.hasCurrent ? -1 : 1;\n\t\t\t\treturn a.provider.localeCompare(b.provider);\n\t\t\t});\n\t\t\tthis.rows = providerRows;\n\t\t\treturn;\n\t\t}\n\t\tconst provider = this.step.provider;\n\t\tconst models = provider === null ? this.activeModels : this.activeModels.filter((m) => m.provider === provider);\n\t\tthis.rows = models.map((item) => ({ kind: \"model\", item }));\n\t}\n\n\tprivate defaultSelectedIndex(): number {\n\t\tconst index = this.rows.findIndex((row) =>\n\t\t\trow.kind === \"provider\" ? row.hasCurrent : modelsAreEqual(this.currentModel, row.item.model),\n\t\t);\n\t\treturn index >= 0 ? index : 0;\n\t}\n\n\tprivate setStep(step: Step): void {\n\t\tthis.step = step;\n\t\tthis.searchInput.setValue(\"\");\n\t\tthis.rebuildRows();\n\t\tthis.selectedIndex = this.defaultSelectedIndex();\n\t\tthis.renderHeader();\n\t\tthis.filterRows(\"\");\n\t\tthis.tui.requestRender();\n\t}\n\n\tprivate isDrilledIn(): boolean {\n\t\treturn this.step.kind === \"models\" && this.step.provider !== null;\n\t}\n\n\t/** Escape returns to the provider list whenever there is a provider list worth returning to. */\n\tprivate canGoBack(): boolean {\n\t\treturn this.step.kind === \"models\" && this.activeProviders().length > 1;\n\t}\n\n\tprivate renderHeader(): void {\n\t\tthis.headerContainer.clear();\n\n\t\tif (this.step.kind === \"providers\") {\n\t\t\tthis.headerContainer.addChild(new Text(theme.bold(theme.fg(\"accent\", \"Select a provider\")), 0, 0));\n\t\t} else {\n\t\t\tconst label = this.step.provider ?? \"All providers\";\n\t\t\tconst crumb = `${theme.bold(theme.fg(\"accent\", label))}${theme.fg(\"muted\", \" › select a model\")}`;\n\t\t\tthis.headerContainer.addChild(new Text(crumb, 0, 0));\n\t\t}\n\n\t\tif (this.scopedModelItems.length > 0) {\n\t\t\tthis.headerContainer.addChild(new Text(this.getScopeText(), 0, 0));\n\t\t} else if (!this.isDrilledIn()) {\n\t\t\tconst hintText = \"Only showing models from configured providers. Use /login to add providers.\";\n\t\t\tthis.headerContainer.addChild(new Text(theme.fg(\"warning\", hintText), 0, 0));\n\t\t}\n\n\t\tthis.headerContainer.addChild(new Text(this.getHintText(), 0, 0));\n\t}\n\n\tprivate getScopeText(): string {\n\t\tconst allText = this.scope === \"all\" ? theme.fg(\"accent\", \"all\") : theme.fg(\"muted\", \"all\");\n\t\tconst scopedText = this.scope === \"scoped\" ? theme.fg(\"accent\", \"scoped\") : theme.fg(\"muted\", \"scoped\");\n\t\treturn `${theme.fg(\"muted\", \"Scope: \")}${allText}${theme.fg(\"muted\", \" | \")}${scopedText}`;\n\t}\n\n\tprivate getHintText(): string {\n\t\tconst hints: string[] = [];\n\t\tif (this.scopedModelItems.length > 0) {\n\t\t\thints.push(keyHint(\"tui.input.tab\", \"scope\") + theme.fg(\"muted\", \" (all/scoped)\"));\n\t\t}\n\t\tif (this.canGoBack()) hints.push(rawKeyHint(\"escape\", \"providers\"), rawKeyHint(\"ctrl+c\", \"close\"));\n\t\telse hints.push(keyHint(\"tui.select.cancel\", \"close\"));\n\t\treturn hints.join(theme.fg(\"muted\", \" · \"));\n\t}\n\n\tprivate setScope(scope: ModelScope): void {\n\t\tif (this.scope === scope) return;\n\t\tthis.scope = scope;\n\t\tthis.activeModels = this.scope === \"scoped\" ? this.scopedModelItems : this.allModels;\n\t\tthis.rebuildRows();\n\t\tthis.selectedIndex = this.defaultSelectedIndex();\n\t\tthis.renderHeader();\n\t\tthis.filterRows(this.searchInput.getValue());\n\t}\n\n\tprivate rowSearchText(row: Row): string {\n\t\tif (row.kind === \"provider\") return row.provider;\n\t\treturn getModelSelectorSearchText({ id: row.item.id, provider: row.item.provider, name: row.item.model.name });\n\t}\n\n\tprivate filterRows(query: string): void {\n\t\tthis.filteredRows = query ? fuzzyFilter(this.rows, query, (row) => this.rowSearchText(row)) : this.rows;\n\t\t// When filtering by a query, move the selector to the top row so the best\n\t\t// match is highlighted. When the query is cleared, keep the current position\n\t\t// clamped to the (restored) list length.\n\t\tthis.selectedIndex = query ? 0 : Math.min(this.selectedIndex, Math.max(0, this.filteredRows.length - 1));\n\t\tthis.updateList();\n\t}\n\n\tprivate renderRow(row: Row, isSelected: boolean): string {\n\t\tconst prefix = isSelected ? theme.fg(\"accent\", \"→ \") : \" \";\n\t\tif (row.kind === \"provider\") {\n\t\t\tconst label = isSelected ? theme.fg(\"accent\", row.provider) : row.provider;\n\t\t\tconst count = theme.fg(\"muted\", ` (${row.count} model${row.count === 1 ? \"\" : \"s\"})`);\n\t\t\tconst checkmark = row.hasCurrent ? theme.fg(\"success\", \" ✓\") : \"\";\n\t\t\treturn `${prefix}${label}${count}${checkmark}`;\n\t\t}\n\t\tconst label = isSelected ? theme.fg(\"accent\", row.item.id) : row.item.id;\n\t\tconst showProvider = this.step.kind === \"models\" && this.step.provider === null;\n\t\tconst badge = showProvider ? ` ${theme.fg(\"muted\", `[${row.item.provider}]`)}` : \"\";\n\t\tconst checkmark = modelsAreEqual(this.currentModel, row.item.model) ? theme.fg(\"success\", \" ✓\") : \"\";\n\t\treturn `${prefix}${label}${badge}${checkmark}`;\n\t}\n\n\tprivate updateList(): void {\n\t\tthis.listContainer.clear();\n\n\t\tconst startIndex = Math.max(\n\t\t\t0,\n\t\t\tMath.min(this.selectedIndex - Math.floor(MAX_VISIBLE_ROWS / 2), this.filteredRows.length - MAX_VISIBLE_ROWS),\n\t\t);\n\t\tconst endIndex = Math.min(startIndex + MAX_VISIBLE_ROWS, this.filteredRows.length);\n\n\t\tfor (let i = startIndex; i < endIndex; i++) {\n\t\t\tconst row = this.filteredRows[i];\n\t\t\tif (!row) continue;\n\t\t\tthis.listContainer.addChild(new Text(this.renderRow(row, i === this.selectedIndex), 0, 0));\n\t\t}\n\n\t\t// Add scroll indicator if needed\n\t\tif (startIndex > 0 || endIndex < this.filteredRows.length) {\n\t\t\tconst scrollInfo = theme.fg(\"muted\", ` (${this.selectedIndex + 1}/${this.filteredRows.length})`);\n\t\t\tthis.listContainer.addChild(new Text(scrollInfo, 0, 0));\n\t\t}\n\n\t\t// Show error message or \"no results\" if empty\n\t\tif (this.errorMessage) {\n\t\t\t// Show error in red\n\t\t\tconst errorLines = this.errorMessage.split(\"\\n\");\n\t\t\tfor (const line of errorLines) {\n\t\t\t\tthis.listContainer.addChild(new Text(theme.fg(\"error\", line), 0, 0));\n\t\t\t}\n\t\t} else if (this.filteredRows.length === 0) {\n\t\t\tconst empty = this.step.kind === \"providers\" ? \" No matching providers\" : \" No matching models\";\n\t\t\tthis.listContainer.addChild(new Text(theme.fg(\"muted\", empty), 0, 0));\n\t\t} else {\n\t\t\tconst selected = this.filteredRows[this.selectedIndex];\n\t\t\tif (selected?.kind === \"model\") {\n\t\t\t\tthis.listContainer.addChild(new Spacer(1));\n\t\t\t\tthis.listContainer.addChild(new Text(theme.fg(\"muted\", ` Model Name: ${selected.item.model.name}`), 0, 0));\n\t\t\t}\n\t\t}\n\t\tif (this.refreshStatusMessage) {\n\t\t\tthis.listContainer.addChild(new Spacer(1));\n\t\t\tthis.listContainer.addChild(\n\t\t\t\tnew Text(theme.fg(this.refreshStatusSuccess ? \"success\" : \"muted\", ` ${this.refreshStatusMessage}`), 0, 0),\n\t\t\t);\n\t\t}\n\t}\n\n\thandleInput(keyData: string): void {\n\t\tconst kb = getKeybindings();\n\t\tif (kb.matches(keyData, \"tui.input.tab\")) {\n\t\t\tif (this.scopedModelItems.length > 0) {\n\t\t\t\tthis.setScope(this.scope === \"all\" ? \"scoped\" : \"all\");\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\t// Up arrow - wrap to bottom when at top\n\t\tif (kb.matches(keyData, \"tui.select.up\")) {\n\t\t\tif (this.filteredRows.length === 0) return;\n\t\t\tthis.selectedIndex = this.selectedIndex === 0 ? this.filteredRows.length - 1 : this.selectedIndex - 1;\n\t\t\tthis.updateList();\n\t\t}\n\t\t// Down arrow - wrap to top when at bottom\n\t\telse if (kb.matches(keyData, \"tui.select.down\")) {\n\t\t\tif (this.filteredRows.length === 0) return;\n\t\t\tthis.selectedIndex = this.selectedIndex === this.filteredRows.length - 1 ? 0 : this.selectedIndex + 1;\n\t\t\tthis.updateList();\n\t\t}\n\t\t// Enter\n\t\telse if (kb.matches(keyData, \"tui.select.confirm\")) {\n\t\t\tthis.confirmSelection();\n\t\t}\n\t\t// Escape or Ctrl+C\n\t\telse if (kb.matches(keyData, \"tui.select.cancel\")) {\n\t\t\t// Escape steps back through the two levels; Ctrl+C always closes.\n\t\t\tif (matchesKey(keyData, Key.escape) && this.canGoBack()) {\n\t\t\t\tthis.setStep({ kind: \"providers\" });\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthis.dispose();\n\t\t\tthis.onCancelCallback();\n\t\t}\n\t\t// Pass everything else to search input\n\t\telse {\n\t\t\tthis.searchInput.handleInput(keyData);\n\t\t\tthis.filterRows(this.searchInput.getValue());\n\t\t}\n\t}\n\n\tprivate confirmSelection(): void {\n\t\tconst row = this.filteredRows[this.selectedIndex];\n\t\tif (!row) return;\n\t\tif (row.kind === \"provider\") {\n\t\t\tthis.setStep({ kind: \"models\", provider: row.provider });\n\t\t\treturn;\n\t\t}\n\t\tthis.handleSelect(row.item.model);\n\t}\n\n\tprivate handleSelect(model: Model<any>): void {\n\t\tthis.dispose();\n\t\t// Save as new default\n\t\tthis.settingsManager.setDefaultModelAndProvider(model.provider, model.id);\n\t\tthis.onSelectCallback(model);\n\t}\n\n\tgetSearchInput(): Input {\n\t\treturn this.searchInput;\n\t}\n}\n"]}
|