@comma-agents/core 2.0.0-rc.0

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.
Files changed (216) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +18 -0
  3. package/dist/abortable/abortable.d.ts +5 -0
  4. package/dist/abortable/abortable.types.d.ts +10 -0
  5. package/dist/abortable/index.d.ts +2 -0
  6. package/dist/agents/agent/agent.constants.d.ts +5 -0
  7. package/dist/agents/agent/agent.d.ts +24 -0
  8. package/dist/agents/agent/agent.types.d.ts +408 -0
  9. package/dist/agents/agent/agent.utils.d.ts +107 -0
  10. package/dist/agents/built-in/user/user-agent.d.ts +32 -0
  11. package/dist/agents/built-in/user/user-agent.types.d.ts +53 -0
  12. package/dist/agents/built-in/user/user-agent.utils.d.ts +2 -0
  13. package/dist/agents/hook-into-agent/hook-into-agent.d.ts +29 -0
  14. package/dist/agents/hooks/hooks.types.d.ts +64 -0
  15. package/dist/agents/hooks/hooks.utils.d.ts +9 -0
  16. package/dist/agents/hooks/index.d.ts +2 -0
  17. package/dist/agents/loader/index.d.ts +4 -0
  18. package/dist/agents/loader/loader.d.ts +49 -0
  19. package/dist/agents/loader/loader.schema.d.ts +270 -0
  20. package/dist/agents/loader/loader.types.d.ts +15 -0
  21. package/dist/conversation-context/conversation-context.d.ts +78 -0
  22. package/dist/conversation-context/conversation-context.types.d.ts +111 -0
  23. package/dist/conversation-context/conversation-context.utils.d.ts +6 -0
  24. package/dist/conversation-context/index.d.ts +3 -0
  25. package/dist/conversation-context/retention/compaction/compaction.constants.d.ts +3 -0
  26. package/dist/conversation-context/retention/compaction/compaction.d.ts +21 -0
  27. package/dist/conversation-context/retention/compaction/compaction.types.d.ts +26 -0
  28. package/dist/conversation-context/retention/compaction/index.d.ts +2 -0
  29. package/dist/conversation-context/retention/index.d.ts +4 -0
  30. package/dist/conversation-context/retention/retention.d.ts +9 -0
  31. package/dist/conversation-context/retention/retention.types.d.ts +90 -0
  32. package/dist/conversation-context/retention/retention.utils.d.ts +3 -0
  33. package/dist/conversation-context/retention/rolling-window/index.d.ts +2 -0
  34. package/dist/conversation-context/retention/rolling-window/rolling-window.d.ts +13 -0
  35. package/dist/conversation-context/retention/rolling-window/rolling-window.types.d.ts +5 -0
  36. package/dist/credentials/backends/json-file.d.ts +21 -0
  37. package/dist/credentials/credentials.constants.d.ts +9 -0
  38. package/dist/credentials/credentials.d.ts +18 -0
  39. package/dist/credentials/credentials.schema.d.ts +102 -0
  40. package/dist/credentials/credentials.types.d.ts +118 -0
  41. package/dist/credentials/credentials.utils.d.ts +30 -0
  42. package/dist/credentials/index.d.ts +6 -0
  43. package/dist/defaults/defaults.d.ts +108 -0
  44. package/dist/defaults/defaults.types.d.ts +51 -0
  45. package/dist/defaults/index.d.ts +2 -0
  46. package/dist/errors/index.d.ts +70 -0
  47. package/dist/flows/built-in/broadcast/broadcast-flow.constants.d.ts +2 -0
  48. package/dist/flows/built-in/broadcast/broadcast-flow.d.ts +30 -0
  49. package/dist/flows/built-in/cycle/cycle-flow.d.ts +53 -0
  50. package/dist/flows/built-in/sequential/sequential-flow.d.ts +25 -0
  51. package/dist/flows/flow/flow.d.ts +79 -0
  52. package/dist/flows/flow/flow.types.d.ts +179 -0
  53. package/dist/flows/flow/flow.utils.d.ts +18 -0
  54. package/dist/flows/hook-into-flow/hook-into-flow.d.ts +30 -0
  55. package/dist/flows/index.d.ts +6 -0
  56. package/dist/flows/loader/index.d.ts +4 -0
  57. package/dist/flows/loader/loader.d.ts +55 -0
  58. package/dist/flows/loader/loader.schema.d.ts +195 -0
  59. package/dist/flows/loader/loader.types.d.ts +27 -0
  60. package/dist/guard/guard.d.ts +17 -0
  61. package/dist/guard/guard.types.d.ts +112 -0
  62. package/dist/guard/index.d.ts +3 -0
  63. package/dist/guard/policies.d.ts +28 -0
  64. package/dist/hooks/built-in/token-tracking/index.d.ts +2 -0
  65. package/dist/hooks/built-in/token-tracking/token-tracking.constants.d.ts +14 -0
  66. package/dist/hooks/built-in/token-tracking/token-tracking.d.ts +87 -0
  67. package/dist/hooks/built-in/token-tracking/token-tracking.types.d.ts +136 -0
  68. package/dist/hooks/hooks.d.ts +10 -0
  69. package/dist/hooks/hooks.types.d.ts +11 -0
  70. package/dist/hooks/index.d.ts +2 -0
  71. package/dist/index.d.ts +50 -0
  72. package/dist/index.js +8961 -0
  73. package/dist/language/index.d.ts +1 -0
  74. package/dist/language/language.types.d.ts +60 -0
  75. package/dist/model/index.d.ts +5 -0
  76. package/dist/model/model.d.ts +63 -0
  77. package/dist/model/model.types.d.ts +85 -0
  78. package/dist/model/model.utils.d.ts +151 -0
  79. package/dist/model/providers/catalog/catalog.d.ts +57 -0
  80. package/dist/model/providers/catalog/catalog.types.d.ts +50 -0
  81. package/dist/model/providers/catalog/catalog.utils.d.ts +15 -0
  82. package/dist/model/providers/catalog/index.d.ts +3 -0
  83. package/dist/model/providers/index.d.ts +7 -0
  84. package/dist/model/providers/listers/copilot.d.ts +10 -0
  85. package/dist/model/providers/listers/index.d.ts +2 -0
  86. package/dist/model/providers/listers/ollama.d.ts +9 -0
  87. package/dist/model/providers/providers.d.ts +69 -0
  88. package/dist/model/providers/providers.types.d.ts +157 -0
  89. package/dist/model/providers/providers.utils.d.ts +16 -0
  90. package/dist/prompts/index.d.ts +4 -0
  91. package/dist/prompts/message-builder.d.ts +89 -0
  92. package/dist/prompts/prompts.types.d.ts +86 -0
  93. package/dist/prompts/template/prompt-template.d.ts +22 -0
  94. package/dist/sandbox/in-sandbox.d.ts +31 -0
  95. package/dist/sandbox/index.d.ts +4 -0
  96. package/dist/sandbox/sandbox.constants.d.ts +31 -0
  97. package/dist/sandbox/sandbox.d.ts +11 -0
  98. package/dist/sandbox/sandbox.types.d.ts +105 -0
  99. package/dist/skills/index.d.ts +4 -0
  100. package/dist/skills/skills.constants.d.ts +10 -0
  101. package/dist/skills/skills.loader.d.ts +46 -0
  102. package/dist/skills/skills.registry.d.ts +18 -0
  103. package/dist/skills/skills.types.d.ts +66 -0
  104. package/dist/skills/skills.utils.d.ts +37 -0
  105. package/dist/strategy/discover/discover.d.ts +16 -0
  106. package/dist/strategy/discover/discover.types.d.ts +70 -0
  107. package/dist/strategy/discover/discover.utils.d.ts +95 -0
  108. package/dist/strategy/discover/index.d.ts +3 -0
  109. package/dist/strategy/exporter/exporter.d.ts +27 -0
  110. package/dist/strategy/exporter/exporter.types.d.ts +6 -0
  111. package/dist/strategy/index.d.ts +10 -0
  112. package/dist/strategy/loader/loader.d.ts +39 -0
  113. package/dist/strategy/loader/loader.types.d.ts +106 -0
  114. package/dist/strategy/loader/loader.utils.d.ts +20 -0
  115. package/dist/strategy/loader/project-loader.d.ts +9 -0
  116. package/dist/strategy/schema.d.ts +1032 -0
  117. package/dist/timeline/index.d.ts +4 -0
  118. package/dist/timeline/projections/conversation-context.d.ts +19 -0
  119. package/dist/timeline/projections/file-state.d.ts +8 -0
  120. package/dist/timeline/projections/index.d.ts +3 -0
  121. package/dist/timeline/timeline.d.ts +11 -0
  122. package/dist/timeline/timeline.types.d.ts +97 -0
  123. package/dist/tools/build-tool-system-prompt.d.ts +41 -0
  124. package/dist/tools/built-in/ask-question/ask-question.d.ts +21 -0
  125. package/dist/tools/built-in/ask-question/index.d.ts +2 -0
  126. package/dist/tools/built-in/create-file/create-file.d.ts +18 -0
  127. package/dist/tools/built-in/create-file/create-file.types.d.ts +11 -0
  128. package/dist/tools/built-in/create-file/index.d.ts +2 -0
  129. package/dist/tools/built-in/delete-file/delete-file.constants.d.ts +14 -0
  130. package/dist/tools/built-in/delete-file/delete-file.d.ts +5 -0
  131. package/dist/tools/built-in/delete-file/delete-file.types.d.ts +26 -0
  132. package/dist/tools/built-in/delete-file/index.d.ts +2 -0
  133. package/dist/tools/built-in/describe-tool.d.ts +61 -0
  134. package/dist/tools/built-in/edit-file/edit-file.d.ts +46 -0
  135. package/dist/tools/built-in/edit-file/edit-file.replacers.d.ts +81 -0
  136. package/dist/tools/built-in/edit-file/edit-file.types.d.ts +59 -0
  137. package/dist/tools/built-in/edit-file/edit-file.utils.d.ts +70 -0
  138. package/dist/tools/built-in/edit-file/index.d.ts +2 -0
  139. package/dist/tools/built-in/glob/glob.constants.d.ts +3 -0
  140. package/dist/tools/built-in/glob/glob.d.ts +25 -0
  141. package/dist/tools/built-in/glob/glob.types.d.ts +31 -0
  142. package/dist/tools/built-in/glob/glob.utils.d.ts +4 -0
  143. package/dist/tools/built-in/glob/index.d.ts +2 -0
  144. package/dist/tools/built-in/launch-strategy/index.d.ts +2 -0
  145. package/dist/tools/built-in/launch-strategy/launch-strategy.d.ts +26 -0
  146. package/dist/tools/built-in/launch-strategy/launch-strategy.types.d.ts +14 -0
  147. package/dist/tools/built-in/list-directory/index.d.ts +2 -0
  148. package/dist/tools/built-in/list-directory/list-directory.constants.d.ts +3 -0
  149. package/dist/tools/built-in/list-directory/list-directory.d.ts +20 -0
  150. package/dist/tools/built-in/list-directory/list-directory.types.d.ts +41 -0
  151. package/dist/tools/built-in/list-directory/list-directory.utils.d.ts +4 -0
  152. package/dist/tools/built-in/list-skills/index.d.ts +2 -0
  153. package/dist/tools/built-in/list-skills/list-skills.d.ts +5 -0
  154. package/dist/tools/built-in/list-skills/list-skills.types.d.ts +10 -0
  155. package/dist/tools/built-in/list-strategy/index.d.ts +2 -0
  156. package/dist/tools/built-in/list-strategy/list-strategy.d.ts +14 -0
  157. package/dist/tools/built-in/list-strategy/list-strategy.types.d.ts +33 -0
  158. package/dist/tools/built-in/load-skill/index.d.ts +2 -0
  159. package/dist/tools/built-in/load-skill/load-skill.d.ts +24 -0
  160. package/dist/tools/built-in/load-skill/load-skill.types.d.ts +15 -0
  161. package/dist/tools/built-in/lsp-request/index.d.ts +2 -0
  162. package/dist/tools/built-in/lsp-request/lsp-request.d.ts +4 -0
  163. package/dist/tools/built-in/lsp-request/lsp-request.schema.d.ts +23 -0
  164. package/dist/tools/built-in/lsp-request/lsp-request.types.d.ts +4 -0
  165. package/dist/tools/built-in/move-file/index.d.ts +2 -0
  166. package/dist/tools/built-in/move-file/move-file.d.ts +21 -0
  167. package/dist/tools/built-in/move-file/move-file.types.d.ts +12 -0
  168. package/dist/tools/built-in/read-file/index.d.ts +2 -0
  169. package/dist/tools/built-in/read-file/read-file.constants.d.ts +1 -0
  170. package/dist/tools/built-in/read-file/read-file.d.ts +32 -0
  171. package/dist/tools/built-in/read-file/read-file.types.d.ts +34 -0
  172. package/dist/tools/built-in/read-file/read-file.utils.d.ts +14 -0
  173. package/dist/tools/built-in/restore-file/index.d.ts +2 -0
  174. package/dist/tools/built-in/restore-file/restore-file.d.ts +16 -0
  175. package/dist/tools/built-in/restore-file/restore-file.types.d.ts +11 -0
  176. package/dist/tools/built-in/run-command/index.d.ts +2 -0
  177. package/dist/tools/built-in/run-command/run-command.constants.d.ts +23 -0
  178. package/dist/tools/built-in/run-command/run-command.d.ts +21 -0
  179. package/dist/tools/built-in/run-command/run-command.types.d.ts +81 -0
  180. package/dist/tools/built-in/run-command/run-command.utils.d.ts +37 -0
  181. package/dist/tools/built-in/search-files/index.d.ts +2 -0
  182. package/dist/tools/built-in/search-files/search-files.constants.d.ts +5 -0
  183. package/dist/tools/built-in/search-files/search-files.d.ts +30 -0
  184. package/dist/tools/built-in/search-files/search-files.types.d.ts +19 -0
  185. package/dist/tools/built-in/search-files/search-files.utils.d.ts +11 -0
  186. package/dist/tools/built-in/todo/todo.d.ts +62 -0
  187. package/dist/tools/built-in/todo/todo.types.d.ts +7 -0
  188. package/dist/tools/built-in/webfetch/webfetch.constants.d.ts +3 -0
  189. package/dist/tools/built-in/webfetch/webfetch.d.ts +33 -0
  190. package/dist/tools/built-in/webfetch/webfetch.types.d.ts +8 -0
  191. package/dist/tools/built-in/webfetch/webfetch.utils.d.ts +19 -0
  192. package/dist/tools/built-in/write-file/index.d.ts +2 -0
  193. package/dist/tools/built-in/write-file/write-file.d.ts +18 -0
  194. package/dist/tools/built-in/write-file/write-file.types.d.ts +11 -0
  195. package/dist/tools/define/define-tool.d.ts +15 -0
  196. package/dist/tools/io/atomic-write.d.ts +37 -0
  197. package/dist/tools/io/audit-sink.d.ts +29 -0
  198. package/dist/tools/io/audit.types.d.ts +115 -0
  199. package/dist/tools/io/audit.utils.d.ts +48 -0
  200. package/dist/tools/io/binary.d.ts +16 -0
  201. package/dist/tools/io/bom.d.ts +15 -0
  202. package/dist/tools/io/diff.d.ts +27 -0
  203. package/dist/tools/io/hash.d.ts +25 -0
  204. package/dist/tools/io/index.d.ts +19 -0
  205. package/dist/tools/io/newline.d.ts +34 -0
  206. package/dist/tools/io/sandbox-error.d.ts +13 -0
  207. package/dist/tools/io/session-file-state.d.ts +68 -0
  208. package/dist/tools/io/stale-file.d.ts +9 -0
  209. package/dist/tools/io/trash.d.ts +57 -0
  210. package/dist/tools/launch-strategy.types.d.ts +38 -0
  211. package/dist/tools/result/index.d.ts +1 -0
  212. package/dist/tools/result/result.d.ts +47 -0
  213. package/dist/tools/tool.constants.d.ts +7 -0
  214. package/dist/tools/tool.registry.d.ts +54 -0
  215. package/dist/tools/tool.types.d.ts +191 -0
  216. package/package.json +48 -0
@@ -0,0 +1 @@
1
+ export type { LanguageDiagnostic, LanguageDiagnosticSeverity, LanguageHoverResult, LanguageLocation, LanguagePosition, LanguageRange, LanguageService, LanguageSymbol, LspMethod, LspRequest, LspResponse, } from "./language.types";
@@ -0,0 +1,60 @@
1
+ export type LspMethod = "textDocument/diagnostic" | "textDocument/hover" | "textDocument/definition" | "textDocument/typeDefinition" | "textDocument/implementation" | "textDocument/references" | "textDocument/documentSymbol" | "workspace/symbol";
2
+ export interface LanguagePosition {
3
+ readonly path: string;
4
+ /** 1-indexed line number. */
5
+ readonly line: number;
6
+ /** 1-indexed character number. */
7
+ readonly character: number;
8
+ readonly absolutePath?: string;
9
+ }
10
+ export interface LspRequest {
11
+ readonly method: LspMethod;
12
+ readonly languageId?: string;
13
+ readonly path?: string;
14
+ readonly absolutePath?: string;
15
+ readonly position?: {
16
+ readonly line: number;
17
+ readonly character: number;
18
+ };
19
+ readonly query?: string;
20
+ }
21
+ export interface LanguageRange {
22
+ readonly startLine: number;
23
+ readonly startCharacter: number;
24
+ readonly endLine: number;
25
+ readonly endCharacter: number;
26
+ }
27
+ export interface LanguageLocation {
28
+ readonly path: string;
29
+ readonly range: LanguageRange;
30
+ }
31
+ export type LanguageDiagnosticSeverity = "error" | "warning" | "information" | "hint";
32
+ export interface LanguageDiagnostic {
33
+ readonly path: string;
34
+ readonly range: LanguageRange;
35
+ readonly severity: LanguageDiagnosticSeverity;
36
+ readonly message: string;
37
+ readonly code?: string | number;
38
+ readonly source?: string;
39
+ }
40
+ export interface LanguageHoverResult {
41
+ readonly contents: string;
42
+ readonly range?: LanguageRange;
43
+ }
44
+ export interface LanguageSymbol {
45
+ readonly name: string;
46
+ readonly kind: string;
47
+ readonly path: string;
48
+ readonly range: LanguageRange;
49
+ readonly containerName?: string;
50
+ }
51
+ export interface LspResponse {
52
+ readonly diagnostics?: readonly LanguageDiagnostic[];
53
+ readonly hover?: LanguageHoverResult | null;
54
+ readonly locations?: readonly LanguageLocation[];
55
+ readonly symbols?: readonly LanguageSymbol[];
56
+ }
57
+ export interface LanguageService {
58
+ readonly languageIds: readonly string[];
59
+ request(request: LspRequest, signal?: AbortSignal): Promise<LspResponse>;
60
+ }
@@ -0,0 +1,5 @@
1
+ export { registerModel, resetModelRegistry, resolveModel, unregisterModel, } from "./model";
2
+ export type { ParsedModel, ProviderFactory, ProviderInfo, ProviderResolver, } from "./model.types";
3
+ export { extractProviderIds, formatProviderName, getModelCapabilities, getModelMetadata, getProviderInfo, getProviderPackage, getQualifiedModelMetadata, isKnownProvider, listProviders, parseModel, } from "./model.utils";
4
+ export type { CatalogData, CatalogModel, CatalogProvider, ListModelsContext, ListModelsFn, ListModelsResult, Modality, ModelCapabilities, ModelCost, ModelInfo, ModelModalities, ModelStatus, ModelsSource, ProviderDefinition, ProviderWithModels, } from "./providers/index";
5
+ export { getCatalogModels, getCatalogProvider, getCatalogProviderSync, getCatalogSnapshot, getProviderDefinition, getProviderPackageNameSync, getProvidersForModel, getRegisteredProviderIds, getReverseModelIndex, isKnownProviderSync, listAllProviderModels, listCatalogProviders, listProviderDefinitions, listProviderModels, loadCatalog, mergeCatalogWithLive, mergeModelInfo, refreshCatalog, registerProviderDefinition, resetCatalog, resetProviderRegistry, resolveCatalogCachePath, resolveCredentialForProvider, sortModels, toModelInfo, unregisterProviderDefinition, } from "./providers/index";
@@ -0,0 +1,63 @@
1
+ import type { LanguageModel } from "ai";
2
+ /**
3
+ * Register a LanguageModel instance for a specific model string.
4
+ *
5
+ * Registered models take precedence over provider-based resolution.
6
+ * This is the simplest way to provide mock models for tests.
7
+ *
8
+ * @param modelString - The full "providerID/modelID" string to register under.
9
+ * @param model - The LanguageModel instance to associate with the string.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * import { registerModel } from "@comma-agents/core";
14
+ *
15
+ * const mockModel = createSimpleMockModel(["Hello!"]);
16
+ * registerModel("mock/test", mockModel);
17
+ *
18
+ * const agent = createAgent({ name: "test", model: "mock/test" });
19
+ * ```
20
+ */
21
+ export declare function registerModel(modelString: string, model: LanguageModel): void;
22
+ /**
23
+ * Remove a previously registered model.
24
+ *
25
+ * @param modelString - The string originally passed to `registerModel`.
26
+ * @returns `true` if the model was registered and removed.
27
+ */
28
+ export declare function unregisterModel(modelString: string): boolean;
29
+ /** Reset the global model registry to empty state. Primarily for tests. */
30
+ export declare function resetModelRegistry(): void;
31
+ /**
32
+ * Resolve a model string into a live LanguageModel instance.
33
+ *
34
+ * Supports two formats:
35
+ * 1. `"providerID/modelID"` — explicit provider selection (e.g. `"openai/gpt-4o"`).
36
+ * 2. Bare model ID — auto-resolves the provider from the models.dev catalog
37
+ * by finding providers that list the model and have configured credentials.
38
+ *
39
+ * Resolution order:
40
+ * 1. Direct model registry (via `registerModel()`) — exact match on the full string.
41
+ * 2. If the string contains `/`: parse as `providerID/modelID`, resolve credential
42
+ * for that provider, and instantiate the model.
43
+ * 3. If the string has no `/`: query the reverse model index for candidate providers.
44
+ * For each candidate (alphabetically sorted), check if a credential is configured.
45
+ * The first provider with a credential wins. If none have credentials, throw
46
+ * with a list of candidate providers that support the model.
47
+ *
48
+ * @param modelString - `"providerID/modelID"` or a bare model ID like `"gpt-4o"`.
49
+ * @throws {ModelResolutionError} If the model string cannot be resolved.
50
+ *
51
+ * @example
52
+ * ```ts
53
+ * // Explicit provider
54
+ * const model = await resolveModel("openai/gpt-4o");
55
+ *
56
+ * // Auto-resolved — finds the first provider with credentials for this model
57
+ * const model = await resolveModel("gpt-4o");
58
+ *
59
+ * // With a pre-registered model (e.g., in tests)
60
+ * registerModel("mock/simple", mockLanguageModel);
61
+ * ```
62
+ */
63
+ export declare function resolveModel(modelString: string): Promise<LanguageModel>;
@@ -0,0 +1,85 @@
1
+ import type { LanguageModel } from "ai";
2
+ import type { Credential } from "../credentials/credentials.types";
3
+ import type { CredentialType, ModelInfo, ModelsSource } from "./providers/providers.types";
4
+ /** Result of parsing a model string like "openai/gpt-4o". */
5
+ export interface ParsedModel {
6
+ /** The provider identifier (e.g., "openai", "anthropic"). */
7
+ readonly providerId: string;
8
+ /** The model identifier (e.g., "gpt-4o", "claude-sonnet-4-5"). */
9
+ readonly modelId: string;
10
+ /** The npm package for the provider, if known. Undefined for custom providers. */
11
+ readonly packageName: string | undefined;
12
+ }
13
+ /**
14
+ * A function that creates a LanguageModel from a model ID.
15
+ * Each provider (openai, anthropic, etc.) supplies one of these.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * import { createOpenAI } from "@ai-sdk/openai";
20
+ * const providers = { openai: (id) => createOpenAI({ apiKey: "...", model: id }) };
21
+ * ```
22
+ */
23
+ export type ProviderFactory = (modelId: string) => LanguageModel;
24
+ /**
25
+ * A function that translates a (providerId, credential) pair into a
26
+ * ProviderFactory. Allows the strategy loader to auto-resolve credentials
27
+ * from a CredentialStore and create provider instances on demand.
28
+ *
29
+ * Implementations are supplied by the consuming layer (daemon, CLI, examples)
30
+ * so that core remains provider-agnostic.
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * const resolver: ProviderResolver = async (providerId, credential) => {
35
+ * if (credential.type !== "api") throw new Error("Only API keys supported");
36
+ * const { createOpenAI } = await import("@ai-sdk/openai");
37
+ * return (modelId) => createOpenAI({ apiKey: credential.key })(modelId);
38
+ * };
39
+ * ```
40
+ */
41
+ export type ProviderResolver = (providerId: string, credential: Credential) => ProviderFactory | Promise<ProviderFactory>;
42
+ /**
43
+ * Aggregate metadata for a single provider.
44
+ *
45
+ * Emitted by `listProviders()` and the daemon's `list_providers` protocol
46
+ * message. Consumers (like the TUI) use this to present provider/model
47
+ * pickers and auth status indicators.
48
+ *
49
+ * Models are returned as rich `ModelInfo[]` entries with cost, context
50
+ * window, capabilities, and modality metadata merged from the models.dev
51
+ * catalog and (optionally) the provider's live API.
52
+ */
53
+ export interface ProviderInfo {
54
+ /** Canonical provider id (matches models.dev keys, e.g., `"github-copilot"`). */
55
+ readonly id: string;
56
+ /** Human-friendly display name (catalog `name` when available). */
57
+ readonly name: string;
58
+ /**
59
+ * Expected credential type for this provider.
60
+ * Defaults to `"api"` for catalog-derived providers.
61
+ */
62
+ readonly credentialType: CredentialType;
63
+ /**
64
+ * Configuration-level auth status. `"configured"` means a credential
65
+ * was found via env var, strategy scope, or global scope. Not validated
66
+ * against the provider's API.
67
+ */
68
+ readonly authStatus: "none" | "configured";
69
+ /**
70
+ * Normalized model metadata. Combines the catalog baseline with live
71
+ * data (when `live === true` and credentials are available).
72
+ */
73
+ readonly models: readonly ModelInfo[];
74
+ /** Provenance of the model list for this provider. */
75
+ readonly modelsSource: ModelsSource;
76
+ /** ISO timestamp when live data was fetched, if any. */
77
+ readonly fetchedAt?: string;
78
+ /** Error message when live discovery failed and we fell back to catalog. */
79
+ readonly error?: string;
80
+ /**
81
+ * `true` if this provider was added via `registerProvider()` rather
82
+ * than being derived from the models.dev catalog or built-in overrides.
83
+ */
84
+ readonly isCustom: boolean;
85
+ }
@@ -0,0 +1,151 @@
1
+ import type { CredentialStore } from "../credentials/credentials.types";
2
+ import type { ParsedModel, ProviderInfo } from "./model.types";
3
+ import type { ModelCapabilities, ModelInfo } from "./providers/providers.types";
4
+ /**
5
+ * Parse a model string in the format `providerID/modelID`.
6
+ *
7
+ * The model ID may contain slashes (e.g., `"ollama/meta-llama/llama-3"`),
8
+ * so only the first slash is used as the separator.
9
+ *
10
+ * @param modelString - Raw model string to parse.
11
+ * @throws {ModelResolutionError} If the string is empty or has no slash separator.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * parseModel("openai/gpt-4o")
16
+ * // => { providerId: "openai", modelId: "gpt-4o", packageName: "@ai-sdk/openai" }
17
+ *
18
+ * parseModel("ollama/meta-llama/llama-3")
19
+ * // => { providerId: "ollama", modelId: "meta-llama/llama-3", packageName: "ollama-ai-provider" }
20
+ * ```
21
+ */
22
+ export declare function parseModel(modelString: string): ParsedModel;
23
+ /**
24
+ * Check whether a provider is known to the runtime (catalog entry or
25
+ * built-in override).
26
+ */
27
+ export declare function isKnownProvider(providerId: string): boolean;
28
+ /**
29
+ * Get the npm package name for a known provider.
30
+ *
31
+ * Returns `undefined` for providers that have no catalog entry and no
32
+ * built-in override; callers may fall back to guessing `@ai-sdk/<id>`.
33
+ */
34
+ export declare function getProviderPackage(providerId: string): string | undefined;
35
+ /**
36
+ * Extract unique provider IDs from a raw (already-parsed) strategy object.
37
+ *
38
+ * Scans each agent's `model` field for "providerID/modelID" strings.
39
+ * Returns the set of unique provider IDs. Works on pre-validation data —
40
+ * silently skips invalid model strings so callers can discover required
41
+ * providers before the full Zod validation pass.
42
+ *
43
+ * @param raw - Parsed but unvalidated strategy object.
44
+ *
45
+ * @example
46
+ * ```ts
47
+ * const raw = JSON.parse(strategyJson);
48
+ * const providerIds = extractProviderIds(raw);
49
+ * // => Set { "openai", "anthropic" }
50
+ * ```
51
+ */
52
+ export declare function extractProviderIds(raw: Record<string, unknown>): Set<string>;
53
+ /**
54
+ * Aggregate metadata for a single provider.
55
+ *
56
+ * Resolves the provider's models from the models.dev catalog (and,
57
+ * when `live === true` and credentials are present, the provider's
58
+ * live API). Auth status is a configuration-level check only.
59
+ *
60
+ * @param providerId - The provider ID to inspect.
61
+ * @param credentialStore - The credential store used to check auth status.
62
+ * @param options - `scope` for scoped credential resolution; `live` to enable live discovery.
63
+ *
64
+ * @example
65
+ * ```ts
66
+ * const info = await getProviderInfo("openai", credentialStore, { live: true });
67
+ * // => { id: "openai", name: "OpenAI", authStatus: "configured", models: [...], modelsSource: "merged", isCustom: false }
68
+ * ```
69
+ */
70
+ export declare function getProviderInfo(providerId: string, credentialStore: CredentialStore, options?: {
71
+ readonly scope?: string;
72
+ readonly live?: boolean;
73
+ }): Promise<ProviderInfo>;
74
+ /**
75
+ * List all known providers along with their auth status and model metadata.
76
+ *
77
+ * Returns every provider derived from the models.dev catalog, plus any
78
+ * built-in overrides (Ollama, DeepSeek) and user-registered custom
79
+ * providers. Auth status is a configuration-level check (env var /
80
+ * credential store presence) and never performs network calls unless
81
+ * `live === true` is passed.
82
+ *
83
+ * @param credentialStore - The credential store used to check auth status.
84
+ * @param options - `scope` for scoped credential resolution; `live` to enable live model discovery.
85
+ *
86
+ * @example
87
+ * ```ts
88
+ * const providers = await listProviders(credentialStore, { live: true });
89
+ * for (const provider of providers) {
90
+ * console.log(`${provider.name}: ${provider.authStatus} (${provider.models.length} models, ${provider.modelsSource})`);
91
+ * }
92
+ * ```
93
+ */
94
+ export declare function listProviders(credentialStore: CredentialStore, options?: {
95
+ readonly scope?: string;
96
+ readonly live?: boolean;
97
+ }): Promise<readonly ProviderInfo[]>;
98
+ /**
99
+ * Look up normalized metadata for a bare model ID from the catalog.
100
+ *
101
+ * Scans the reverse model index for the first provider that lists the
102
+ * model, then returns the full `ModelInfo` (including capabilities,
103
+ * modalities, cost, context window, etc.). Returns `undefined` if the
104
+ * model is not found in any provider catalog.
105
+ *
106
+ * @example
107
+ * ```ts
108
+ * const info = getModelMetadata("gpt-4o");
109
+ * console.log(info?.capabilities?.reasoning); // true
110
+ * console.log(info?.contextWindow); // 128000
111
+ * ```
112
+ */
113
+ export declare function getModelMetadata(modelId: string): ModelInfo | undefined;
114
+ /**
115
+ * Look up normalized metadata for a provider-qualified model string.
116
+ *
117
+ * @param model - Model identifier in "providerID/modelID" format.
118
+ * @example
119
+ * ```ts
120
+ * const info = getQualifiedModelMetadata("openai/gpt-4o");
121
+ * console.log(info?.contextWindow);
122
+ * ```
123
+ */
124
+ export declare function getQualifiedModelMetadata(model: string): ModelInfo | undefined;
125
+ /**
126
+ * Look up capability flags for a bare model ID.
127
+ *
128
+ * Returns the model's `ModelCapabilities` (tools, reasoning, vision,
129
+ * attachment, structuredOutput) from the catalog. Returns `undefined` if
130
+ * the model is not found in any provider catalog.
131
+ *
132
+ * This is a convenience wrapper around `getModelMetadata()` for the common
133
+ * case of checking what features a model supports at runtime.
134
+ *
135
+ * @example
136
+ * ```ts
137
+ * const caps = getModelCapabilities("gpt-4o");
138
+ * if (caps?.reasoning) {
139
+ * // use reasoning-related options
140
+ * }
141
+ * ```
142
+ */
143
+ export declare function getModelCapabilities(modelId: string): ModelCapabilities | undefined;
144
+ /**
145
+ * Convert a provider ID to a human-friendly display name.
146
+ *
147
+ * Hyphen-separated tokens are capitalized (e.g., `github-copilot` ->
148
+ * `Github Copilot`). This is a best-effort default; consumers that want
149
+ * brand-accurate names should rely on the catalog-provided `name`.
150
+ */
151
+ export declare function formatProviderName(providerId: string): string;
@@ -0,0 +1,57 @@
1
+ import type { ModelInfo } from "../providers.types";
2
+ import type { CatalogData, CatalogProvider } from "./catalog.types";
3
+ /** Source URL for the live catalog. */
4
+ export declare const CATALOG_SOURCE_URL = "https://models.dev/api.json";
5
+ /** Default cache TTL — 24 hours. */
6
+ export declare const CATALOG_CACHE_TTL_MS: number;
7
+ /** Force re-evaluation on next `loadCatalog()` call. Used by tests. */
8
+ export declare function resetCatalog(): void;
9
+ /**
10
+ * Synchronous snapshot access. Returns whatever is currently loaded in
11
+ * memory, falling back to the bundled snapshot without touching disk or
12
+ * network. Use this in sync paths (e.g., the provider resolver) where
13
+ * awaiting is not practical.
14
+ */
15
+ export declare function getCatalogSnapshot(): CatalogData;
16
+ /** Sync counterpart to `getCatalogProvider`. */
17
+ export declare function getCatalogProviderSync(providerId: string): CatalogProvider | undefined;
18
+ /**
19
+ * Load the models.dev catalog, preferring (fresh cache) → (network refresh) →
20
+ * (bundled snapshot). The first successful source wins; subsequent calls
21
+ * return the memoized result until `resetCatalog()` is invoked.
22
+ */
23
+ export declare function loadCatalog(options?: {
24
+ readonly forceRefresh?: boolean;
25
+ }): Promise<CatalogData>;
26
+ /**
27
+ * Force a network refresh of the catalog. Updates the disk cache on success;
28
+ * falls back to the existing cache or bundled snapshot on failure.
29
+ */
30
+ export declare function refreshCatalog(): Promise<CatalogData>;
31
+ /** Look up a single provider entry from the catalog. */
32
+ export declare function getCatalogProvider(providerId: string): Promise<CatalogProvider | undefined>;
33
+ /** Return every provider entry from the catalog. */
34
+ export declare function listCatalogProviders(): Promise<readonly CatalogProvider[]>;
35
+ /** Return the normalized `ModelInfo[]` for a provider, or an empty array if unknown. */
36
+ export declare function getCatalogModels(providerId: string): Promise<readonly ModelInfo[]>;
37
+ /**
38
+ * Return a lazy-built reverse model index.
39
+ *
40
+ * The index maps each model ID (e.g. `"gpt-4o"`) to an alphabetically-sorted
41
+ * array of provider IDs that list that model in the models.dev catalog.
42
+ * Providers are sorted alphabetically for deterministic resolution order.
43
+ *
44
+ * Built once from `getCatalogSnapshot()` and invalidated via `resetCatalog()`.
45
+ */
46
+ export declare function getReverseModelIndex(): Map<string, string[]>;
47
+ /**
48
+ * Return the list of provider IDs known to offer a given model ID.
49
+ *
50
+ * Only includes providers registered in the models.dev catalog. Live-only
51
+ * providers (ollama, GitHub Copilot models fetched at runtime) are NOT
52
+ * included here.
53
+ *
54
+ * @param modelId - The bare model ID to look up (e.g. `"gpt-4o"`).
55
+ * @returns Sorted array of provider IDs, or empty array if unknown.
56
+ */
57
+ export declare function getProvidersForModel(modelId: string): string[];
@@ -0,0 +1,50 @@
1
+ import type { ModelStatus } from "../providers.types";
2
+ /** Raw model entry shape used by `https://models.dev/api.json`. */
3
+ export interface CatalogModel {
4
+ readonly id: string;
5
+ readonly name: string;
6
+ readonly family?: string;
7
+ readonly attachment: boolean;
8
+ readonly reasoning: boolean;
9
+ readonly tool_call: boolean;
10
+ readonly temperature?: boolean;
11
+ readonly structured_output?: boolean;
12
+ readonly open_weights: boolean;
13
+ readonly interleaved?: boolean | {
14
+ readonly field?: string;
15
+ };
16
+ readonly knowledge?: string;
17
+ readonly release_date: string;
18
+ readonly last_updated: string;
19
+ readonly status?: ModelStatus | string;
20
+ readonly modalities: {
21
+ readonly input: readonly string[];
22
+ readonly output: readonly string[];
23
+ };
24
+ readonly limit: {
25
+ readonly context: number;
26
+ readonly input?: number;
27
+ readonly output: number;
28
+ };
29
+ readonly cost?: {
30
+ readonly input?: number;
31
+ readonly output?: number;
32
+ readonly reasoning?: number;
33
+ readonly cache_read?: number;
34
+ readonly cache_write?: number;
35
+ readonly input_audio?: number;
36
+ readonly output_audio?: number;
37
+ };
38
+ }
39
+ /** Raw provider entry shape used by `https://models.dev/api.json`. */
40
+ export interface CatalogProvider {
41
+ readonly id: string;
42
+ readonly name: string;
43
+ readonly npm: string;
44
+ readonly env: readonly string[];
45
+ readonly doc: string;
46
+ readonly api?: string;
47
+ readonly models: Readonly<Record<string, CatalogModel>>;
48
+ }
49
+ /** Top-level shape: provider-id → provider entry. */
50
+ export type CatalogData = Readonly<Record<string, CatalogProvider>>;
@@ -0,0 +1,15 @@
1
+ import type { ModelInfo } from "../providers.types";
2
+ import type { CatalogModel } from "./catalog.types";
3
+ /** Map a raw catalog model entry to our normalized `ModelInfo` shape. */
4
+ export declare function toModelInfo(catalogModel: CatalogModel): ModelInfo;
5
+ /** Filename used for the on-disk catalog snapshot. */
6
+ export declare const CATALOG_CACHE_FILENAME = "models-catalog.json";
7
+ /**
8
+ * Resolve the platform-aware cache directory for comma-agents.
9
+ *
10
+ * Mirrors the conventions used by `resolveDataDir` but targets cache storage:
11
+ * - macOS: ~/Library/Caches/comma-agents/
12
+ * - Windows: %LOCALAPPDATA%/comma-agents/Cache/ (fallback ~/AppData/Local)
13
+ * - Linux: $XDG_CACHE_HOME/comma-agents/ (fallback ~/.cache)
14
+ */
15
+ export declare function resolveCatalogCachePath(env?: Readonly<Record<string, string | undefined>>, platform?: NodeJS.Platform): string;
@@ -0,0 +1,3 @@
1
+ export { CATALOG_CACHE_TTL_MS, CATALOG_SOURCE_URL, getCatalogModels, getCatalogProvider, getCatalogProviderSync, getCatalogSnapshot, getProvidersForModel, getReverseModelIndex, listCatalogProviders, loadCatalog, refreshCatalog, resetCatalog, } from "./catalog";
2
+ export type { CatalogData, CatalogModel, CatalogProvider, } from "./catalog.types";
3
+ export { resolveCatalogCachePath, toModelInfo, } from "./catalog.utils";
@@ -0,0 +1,7 @@
1
+ export type { CatalogData, CatalogModel, CatalogProvider, } from "./catalog/index";
2
+ export { CATALOG_CACHE_TTL_MS, CATALOG_SOURCE_URL, getCatalogModels, getCatalogProvider, getCatalogProviderSync, getCatalogSnapshot, getProvidersForModel, getReverseModelIndex, listCatalogProviders, loadCatalog, refreshCatalog, resetCatalog, resolveCatalogCachePath, toModelInfo, } from "./catalog/index";
3
+ export { listCopilotModels, listOllamaModels } from "./listers/index";
4
+ export type { ProviderWithModels } from "./providers";
5
+ export { getProviderDefinition, getProviderPackageNameSync, getRegisteredProviderIds, isKnownProviderSync, listAllProviderModels, listProviderDefinitions, listProviderModels, registerProviderDefinition, resetProviderRegistry, resolveCredentialForProvider, unregisterProviderDefinition, } from "./providers";
6
+ export type { ListModelsContext, ListModelsFn, ListModelsResult, Modality, ModelCapabilities, ModelCost, ModelInfo, ModelModalities, ModelStatus, ModelsSource, ProviderDefinition, } from "./providers.types";
7
+ export { mergeCatalogWithLive, mergeModelInfo, sortModels, } from "./providers.utils";
@@ -0,0 +1,10 @@
1
+ import type { ListModelsFn } from "../providers.types";
2
+ /**
3
+ * List GitHub Copilot models via `GET {base}/models`.
4
+ *
5
+ * Requires an OAuth credential (GitHub access token). Filters out models
6
+ * where `model_picker_enabled` is false or `policy.state === "disabled"`.
7
+ * Populates capabilities/limits from the response and leaves pricing blank
8
+ * (Copilot is subscription-based, not per-token).
9
+ */
10
+ export declare const listCopilotModels: ListModelsFn;
@@ -0,0 +1,2 @@
1
+ export { listCopilotModels } from "./copilot";
2
+ export { listOllamaModels } from "./ollama";
@@ -0,0 +1,9 @@
1
+ import type { ListModelsFn } from "../providers.types";
2
+ /**
3
+ * List locally installed Ollama models via `GET {baseURL}/api/tags`.
4
+ *
5
+ * Ollama is absent from the models.dev catalog because the set of installed
6
+ * models is user-specific. This lister returns whatever the local daemon
7
+ * reports; capabilities and context windows are unknown from the tags endpoint.
8
+ */
9
+ export declare const listOllamaModels: ListModelsFn;
@@ -0,0 +1,69 @@
1
+ import type { Credential, CredentialStore } from "../../credentials/credentials.types";
2
+ import type { ListModelsResult, ProviderDefinition } from "./providers.types";
3
+ /**
4
+ * Register (or override) a provider definition. Custom registrations take
5
+ * precedence over catalog-derived defaults and persist across catalog reloads.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * registerProviderDefinition({
10
+ * id: "acme",
11
+ * name: "Acme Labs",
12
+ * packageName: "@acme/ai-sdk",
13
+ * listModels: async () => [{ id: "acme-1" }],
14
+ * });
15
+ * ```
16
+ */
17
+ export declare function registerProviderDefinition(definition: ProviderDefinition): void;
18
+ /** Remove a previously registered provider. Catalog-derived entries return on next init. */
19
+ export declare function unregisterProviderDefinition(providerId: string): boolean;
20
+ /** Reset all provider registrations. Primarily for tests. */
21
+ export declare function resetProviderRegistry(): void;
22
+ /** Look up a single provider definition by id. */
23
+ export declare function getProviderDefinition(providerId: string): Promise<ProviderDefinition | undefined>;
24
+ /** Every registered provider definition, alphabetically by id. */
25
+ export declare function listProviderDefinitions(): Promise<readonly ProviderDefinition[]>;
26
+ /**
27
+ * Resolve the model list for a single provider.
28
+ *
29
+ * When `options.live` is false, only catalog data is returned. When `live`
30
+ * is true and the provider defines `listModels`, the live response is
31
+ * merged with the catalog baseline. Live errors fall back to catalog
32
+ * (if any) and are reported via `result.error`.
33
+ */
34
+ export declare function listProviderModels(providerId: string, credential: Credential | undefined, options?: {
35
+ readonly live?: boolean;
36
+ readonly signal?: AbortSignal;
37
+ }): Promise<ListModelsResult>;
38
+ /**
39
+ * Resolve a credential for a provider via its credential store. Swallows
40
+ * `undefined` (not found) cases so callers can treat missing credentials
41
+ * as "skip live listing".
42
+ */
43
+ export declare function resolveCredentialForProvider(credentialStore: CredentialStore, providerId: string, scope?: string): Promise<Credential | undefined>;
44
+ /** Convenience re-export: every provider definition paired with its models. */
45
+ export interface ProviderWithModels {
46
+ readonly definition: ProviderDefinition;
47
+ readonly result: ListModelsResult;
48
+ }
49
+ /** Resolve models for every registered provider in parallel. */
50
+ export declare function listAllProviderModels(credentialStore: CredentialStore, options?: {
51
+ readonly live?: boolean;
52
+ readonly scope?: string;
53
+ }): Promise<readonly ProviderWithModels[]>;
54
+ /** Expose a snapshot of the current registry for inspection (test helper). */
55
+ export declare function getRegisteredProviderIds(): readonly string[];
56
+ /**
57
+ * Synchronously resolve the npm package name for a provider.
58
+ *
59
+ * Checks built-in overrides first (ollama, deepseek), then falls back to
60
+ * the bundled catalog snapshot. Returns `undefined` for providers that have
61
+ * no known package (the resolver may guess `@ai-sdk/<id>` in that case).
62
+ *
63
+ * Designed for sync paths like the provider resolver; async callers should
64
+ * prefer `getProviderDefinition()` which reflects the live registry.
65
+ */
66
+ export declare function getProviderPackageNameSync(providerId: string): string | undefined;
67
+ /** Check whether a provider is known to the runtime (catalog or built-in). */
68
+ export declare function isKnownProviderSync(providerId: string): boolean;
69
+ export type { ModelInfo } from "./providers.types";