@nemesis-oss/ollama-sdk 1.3.0 → 1.4.1
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 +43 -212
- package/README.md +391 -18
- package/dist/compose-BR70yb4W.d.cts +164 -0
- package/dist/compose-DfAqKAFj.d.ts +164 -0
- package/dist/generated-api.cjs +497 -0
- package/dist/generated-api.cjs.map +1 -0
- package/dist/generated-api.d.cts +1651 -0
- package/dist/generated-api.d.ts +1651 -0
- package/dist/generated-api.js +471 -0
- package/dist/generated-api.js.map +1 -0
- package/dist/generated-models-schemas.cjs +328 -0
- package/dist/generated-models-schemas.cjs.map +1 -0
- package/dist/generated-models-schemas.d.cts +463 -0
- package/dist/generated-models-schemas.d.ts +463 -0
- package/dist/generated-models-schemas.js +291 -0
- package/dist/generated-models-schemas.js.map +1 -0
- package/dist/generated-runtime.cjs +205 -0
- package/dist/generated-runtime.cjs.map +1 -0
- package/dist/generated-runtime.d.cts +2 -0
- package/dist/generated-runtime.d.ts +2 -0
- package/dist/generated-runtime.js +203 -0
- package/dist/generated-runtime.js.map +1 -0
- package/dist/index-2RIErNT5.d.cts +583 -0
- package/dist/index-DIQ8NUbU.d.ts +583 -0
- package/dist/index.cjs +2041 -208
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +817 -453
- package/dist/index.d.ts +817 -453
- package/dist/index.js +2032 -209
- package/dist/index.js.map +1 -1
- package/dist/mcp/tools.json +1007 -0
- package/dist/mcp-generated.cjs +429 -0
- package/dist/mcp-generated.cjs.map +1 -0
- package/dist/mcp-generated.d.cts +35 -0
- package/dist/mcp-generated.d.ts +35 -0
- package/dist/mcp-generated.js +424 -0
- package/dist/mcp-generated.js.map +1 -0
- package/dist/mcp-http.cjs +100 -0
- package/dist/mcp-http.cjs.map +1 -0
- package/dist/mcp-http.d.cts +48 -0
- package/dist/mcp-http.d.ts +48 -0
- package/dist/mcp-http.js +96 -0
- package/dist/mcp-http.js.map +1 -0
- package/dist/mcp-stdio.cjs +49 -0
- package/dist/mcp-stdio.cjs.map +1 -0
- package/dist/mcp-stdio.d.cts +34 -0
- package/dist/mcp-stdio.d.ts +34 -0
- package/dist/mcp-stdio.js +47 -0
- package/dist/mcp-stdio.js.map +1 -0
- package/dist/skills.cjs.map +1 -1
- package/dist/skills.d.cts +3 -2
- package/dist/skills.d.ts +3 -2
- package/dist/skills.js.map +1 -1
- package/dist/types-B9_axjum.d.cts +66 -0
- package/dist/types-B9_axjum.d.ts +66 -0
- package/dist/{compose-CDWq8oxJ.d.cts → types-BQhgW-du.d.cts} +68 -171
- package/dist/{compose-CDWq8oxJ.d.ts → types-BQhgW-du.d.ts} +68 -171
- package/package.json +96 -5
package/dist/skills.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/errors.ts","../src/skills/frontmatter.ts","../src/skills/compose.ts","../src/skills/skill-registry.ts"],"names":[],"mappings":";;;;AAwBO,IAAM,iBAAA,GAAN,cAAgC,KAAA,CAAM;AAAA,EAClC,IAAA;AAAA,EACA,MAAA;AAAA,EACA,SAAA;AAAA,EACA,OAAA;AAAA,EACA,QAAA;AAAA,EAET,WAAA,CAAY,SAAiB,OAAA,EAAmC;AAC9D,IAAA,KAAA,CAAM,OAAA,EAAS,EAAE,KAAA,EAAO,OAAA,CAAQ,OAAO,CAAA;AACvC,IAAA,IAAA,CAAK,IAAA,GAAO,KAAK,WAAA,CAAY,IAAA;AAC7B,IAAA,IAAA,CAAK,OAAO,OAAA,CAAQ,IAAA;AACpB,IAAA,IAAA,CAAK,SAAS,OAAA,CAAQ,MAAA;AACtB,IAAA,IAAA,CAAK,SAAA,GAAY,QAAQ,SAAA,IAAa,KAAA;AACtC,IAAA,IAAA,CAAK,UAAU,OAAA,CAAQ,OAAA;AACvB,IAAA,IAAA,CAAK,WAAW,OAAA,CAAQ,QAAA;AAAA,EAC1B;AACF,CAAA;AAsMO,IAAM,wBAAA,GAAN,cAAuC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CAAiB,OAAA,EAAS,SAAS,CAAA;AAClD,QAAA,SAAA,CAAU,IAAA,CAAK;AAAA,UACb,IAAA,EAAM,OAAO,WAAA,CAAY,IAAA;AAAA,UACzB,WAAA,EAAa,OAAO,WAAA,CAAY,WAAA;AAAA,UAChC,IAAA,EAAM;AAAA,SACP,CAAA;AAAA,MACH,CAAA,CAAA,MAAQ;AAAA,MAER;AAAA,IACF;AAEA,IAAA,OAAO,SAAA;AAAA,EACT;AAAA,EAEA,MAAM,KAAK,IAAA,EAA8B;AACvC,IAAA,MAAM,SAAA,GAAY,IAAA,CAAK,IAAA,CAAK,SAAA,EAAW,MAAM,UAAU,CAAA;AACvD,IAAA,IAAI;AACF,MAAA,MAAM,OAAA,GAAU,MAAM,QAAA,CAAS,SAAA,EAAW,OAAO,CAAA;AACjD,MAAA,MAAM,MAAA,GAAS,gBAAA,CAAiB,OAAA,EAAS,SAAS,CAAA;AAClD,MAAA,OAAO;AAAA,QACL,IAAA,EAAM,OAAO,WAAA,CAAY,IAAA;AAAA,QACzB,WAAA,EAAa,OAAO,WAAA,CAAY,WAAA;AAAA,QAChC,IAAA,EAAM,SAAA;AAAA,QACN,aAAa,MAAA,CAAO,WAAA;AAAA,QACpB,MAAM,MAAA,CAAO,IAAA;AAAA,QACb,YAAA,EAAc,MAAA,CAAO,WAAA,CAAY,eAAe;AAAA,OAClD;AAAA,IACF,SAAS,GAAA,EAAK;AACZ,MAAA,MAAM,IAAI,wBAAA,CAAyB,CAAA,OAAA,EAAU,IAAI,CAAA,eAAA,EAAkB,SAAS,CAAA,CAAA,EAAI;AAAA,QAC9E,SAAA,EAAW,IAAA;AAAA,QACX,KAAA,EAAO;AAAA,OACR,CAAA;AAAA,IACH;AAAA,EACF;AACF","file":"skills.js","sourcesContent":["/**\n * Structured, typed error hierarchy for OllamaClient.\n */\n\nexport interface OllamaErrorRequestContext {\n readonly method?: string | undefined;\n readonly url?: string | undefined;\n readonly model?: string | undefined;\n}\n\nexport interface OllamaErrorResponseContext {\n readonly status?: number | undefined;\n readonly headers?: Record<string, string> | undefined;\n readonly body?: unknown;\n}\n\nexport interface OllamaClientErrorOptions extends ErrorOptions {\n readonly code: string;\n readonly status?: number | undefined;\n readonly retryable?: boolean | undefined;\n readonly request?: OllamaErrorRequestContext | undefined;\n readonly response?: OllamaErrorResponseContext | undefined;\n}\n\nexport class OllamaClientError extends Error {\n readonly code: string;\n readonly status?: number | undefined;\n readonly retryable: boolean;\n readonly request?: OllamaErrorRequestContext | undefined;\n readonly response?: OllamaErrorResponseContext | undefined;\n\n constructor(message: string, options: OllamaClientErrorOptions) {\n super(message, { cause: options.cause });\n this.name = this.constructor.name;\n this.code = options.code;\n this.status = options.status;\n this.retryable = options.retryable ?? false;\n this.request = options.request;\n this.response = options.response;\n }\n}\n\nexport class OllamaNetworkError extends OllamaClientError {\n constructor(\n message: string,\n options?: Omit<OllamaClientErrorOptions, 'code' | 'retryable'> | undefined,\n ) {\n super(message, { ...options, code: 'network_error', retryable: true });\n }\n}\n\nexport class OllamaTimeoutError extends OllamaClientError {\n readonly timeoutMs?: number | undefined;\n constructor(\n message: string,\n options?:\n | (Omit<OllamaClientErrorOptions, 'code' | 'retryable'> & { timeoutMs?: number | undefined })\n | undefined,\n ) {\n super(message, { ...options, code: 'timeout', retryable: true });\n this.timeoutMs = options?.timeoutMs;\n }\n}\n\nexport class OllamaAuthError extends OllamaClientError {\n constructor(\n message: string,\n options?: Omit<OllamaClientErrorOptions, 'code' | 'retryable'> | undefined,\n ) {\n super(message, { ...options, code: 'auth_error', retryable: false });\n }\n}\n\nexport class OllamaNotFoundError extends OllamaClientError {\n constructor(\n message: string,\n options?: Omit<OllamaClientErrorOptions, 'code' | 'retryable'> | undefined,\n ) {\n super(message, { ...options, code: 'not_found', retryable: false });\n }\n}\n\nexport class OllamaRateLimitError extends OllamaClientError {\n readonly retryAfterMs?: number | undefined;\n constructor(\n message: string,\n options?:\n | (Omit<OllamaClientErrorOptions, 'code' | 'retryable'> & {\n retryAfterMs?: number | undefined;\n })\n | undefined,\n ) {\n super(message, { ...options, code: 'rate_limited', retryable: true });\n this.retryAfterMs = options?.retryAfterMs;\n }\n}\n\n/**\n * Thrown client-side, before a network request is made, by `QuotaManager.assertCanProceed`\n * (see `src/quota.ts`) when issuing the request would exceed a configured usage budget for\n * one of its rolling windows. This is distinct from `OllamaRateLimitError`, which reflects\n * the server's own 429 response — Ollama Cloud does not expose account-level quota via the\n * API, so `QuotaManager` tracks usage against budgets the caller configures locally and\n * fails fast rather than waiting for the server to reject the request.\n */\nexport class OllamaQuotaExceededError extends OllamaClientError {\n readonly windowId: string;\n readonly resetAt: number;\n constructor(\n message: string,\n options: Omit<OllamaClientErrorOptions, 'code' | 'retryable'> & {\n windowId: string;\n resetAt: number;\n },\n ) {\n super(message, { ...options, code: 'quota_exceeded', retryable: false });\n this.windowId = options.windowId;\n this.resetAt = options.resetAt;\n }\n}\n\nexport class OllamaServerError extends OllamaClientError {\n constructor(\n message: string,\n options?: Omit<OllamaClientErrorOptions, 'code' | 'retryable'> | undefined,\n ) {\n super(message, { ...options, code: 'server_error', retryable: true });\n }\n}\n\nexport class OllamaAbortError extends OllamaClientError {\n constructor(\n message: string,\n options?: Omit<OllamaClientErrorOptions, 'code' | 'retryable'> | undefined,\n ) {\n super(message, { ...options, code: 'aborted', retryable: false });\n }\n}\n\nexport class OllamaToolValidationError extends OllamaClientError {\n readonly toolName: string;\n readonly issues?: unknown;\n constructor(\n message: string,\n options: Omit<OllamaClientErrorOptions, 'code'> & { toolName: string; issues?: unknown },\n ) {\n super(message, { ...options, code: 'tool_validation_error', retryable: false });\n this.toolName = options.toolName;\n this.issues = options.issues;\n }\n}\n\nexport class OllamaToolTimeoutError extends OllamaClientError {\n readonly toolName: string;\n readonly timeoutMs: number;\n constructor(\n message: string,\n options: Omit<OllamaClientErrorOptions, 'code' | 'retryable'> & {\n toolName: string;\n timeoutMs: number;\n },\n ) {\n super(message, { ...options, code: 'tool_timeout', retryable: false });\n this.toolName = options.toolName;\n this.timeoutMs = options.timeoutMs;\n }\n}\n\n/**\n * Thrown client-side, before a network request is made, when a request asks for a\n * capability an endpoint is known not to support (e.g. structured output `format` against\n * an Ollama Cloud endpoint — see `ModelCapabilities.supportsStructuredOutputRequest` in\n * `src/capabilities/capabilities.ts`). Its `code` is included in `DEFAULT_FAILOVER_CODES`\n * by default, so in a multi-endpoint setup it causes failover to the next candidate rather\n * than failing outright — it only surfaces to the caller if every candidate is rejected.\n */\nexport class OllamaUnsupportedCapabilityError extends OllamaClientError {\n readonly capability: string;\n constructor(\n message: string,\n options: Omit<OllamaClientErrorOptions, 'code' | 'retryable'> & { capability: string },\n ) {\n super(message, { ...options, code: 'unsupported_capability', retryable: false });\n this.capability = options.capability;\n }\n}\n\n/**\n * Thrown client-side, before any network call, when `config.endpoints` uses\n * `OllamaEndpoint.models` to scope endpoints/credentials to specific models and the\n * requested `model` isn't in any configured endpoint's allow-list. This is a routing\n * misconfiguration, not a connectivity problem — the SDK deliberately does not \"probe\"\n * unauthorized endpoints to find one that happens to work (that would burn quota on keys\n * that were never entitled to the model and produce non-deterministic startup behavior).\n */\nexport class OllamaModelRoutingError extends OllamaClientError {\n readonly model: string;\n readonly availableModels: readonly string[];\n constructor(\n message: string,\n options: Omit<OllamaClientErrorOptions, 'code' | 'retryable'> & {\n model: string;\n availableModels: readonly string[];\n },\n ) {\n super(message, { ...options, code: 'model_routing_error', retryable: false });\n this.model = options.model;\n this.availableModels = options.availableModels;\n }\n}\n\nexport class OllamaAgentMaxIterationsError extends OllamaClientError {\n readonly maxIterations: number;\n constructor(\n message: string,\n options: Omit<OllamaClientErrorOptions, 'code'> & { maxIterations: number },\n ) {\n super(message, { ...options, code: 'agent_max_iterations_exceeded', retryable: false });\n this.maxIterations = options.maxIterations;\n }\n}\n\nexport class OllamaMcpError extends OllamaClientError {\n readonly mcpMethod: 'listTools' | 'callTool';\n readonly toolName?: string | undefined;\n constructor(\n message: string,\n options: Omit<OllamaClientErrorOptions, 'code'> & {\n mcpMethod: 'listTools' | 'callTool';\n toolName?: string | undefined;\n },\n ) {\n super(message, { ...options, code: 'mcp_error', retryable: options.retryable ?? false });\n this.mcpMethod = options.mcpMethod;\n this.toolName = options.toolName;\n }\n}\n\nexport class OllamaSkillNotFoundError extends OllamaClientError {\n readonly skillName: string;\n constructor(\n message: string,\n options: Omit<OllamaClientErrorOptions, 'code'> & { skillName: string },\n ) {\n super(message, { ...options, code: 'skill_not_found', retryable: false });\n this.skillName = options.skillName;\n }\n}\n\nexport class OllamaSkillInvalidError extends OllamaClientError {\n readonly skillName: string;\n readonly path?: string | undefined;\n constructor(\n message: string,\n options: Omit<OllamaClientErrorOptions, 'code'> & {\n skillName: string;\n path?: string | undefined;\n },\n ) {\n super(message, { ...options, code: 'skill_invalid', retryable: false });\n this.skillName = options.skillName;\n this.path = options.path;\n }\n}\n\nexport class OllamaGenericClientError extends OllamaClientError {\n constructor(message: string, options?: Omit<OllamaClientErrorOptions, 'code'> | undefined) {\n super(message, { ...options, code: 'client_error' });\n }\n}\n\nfunction isDomAbortError(error: unknown): error is DOMException {\n return (\n typeof DOMException !== 'undefined' &&\n error instanceof DOMException &&\n error.name === 'AbortError'\n );\n}\n\nfunction statusToError(\n status: number,\n message: string,\n options: Omit<OllamaClientErrorOptions, 'code' | 'status'>,\n): OllamaClientError {\n if (status === 401 || status === 403) {\n return new OllamaAuthError(message, { ...options, status });\n }\n if (status === 404) {\n return new OllamaNotFoundError(message, { ...options, status });\n }\n if (status === 429) {\n return new OllamaRateLimitError(message, { ...options, status });\n }\n if (status >= 500) {\n return new OllamaServerError(message, { ...options, status });\n }\n return new OllamaGenericClientError(message, { ...options, status });\n}\n\n/**\n * Maps arbitrary thrown exceptions into structured OllamaClientError instances.\n */\nexport function mapError(\n error: unknown,\n context: {\n request?: OllamaErrorRequestContext | undefined;\n response?: OllamaErrorResponseContext | undefined;\n } = {},\n): OllamaClientError {\n if (error instanceof OllamaClientError) {\n return error;\n }\n if (isDomAbortError(error)) {\n return new OllamaAbortError(error.message || 'Request was aborted', {\n cause: error,\n request: context.request,\n });\n }\n if (error instanceof TypeError) {\n return new OllamaNetworkError(error.message || 'Network request failed', {\n cause: error,\n request: context.request,\n });\n }\n if (context.response?.status !== undefined) {\n const message = error instanceof Error ? error.message : String(error);\n return statusToError(context.response.status, message, {\n cause: error,\n request: context.request,\n response: context.response,\n });\n }\n const message = error instanceof Error ? error.message : String(error);\n return new OllamaGenericClientError(message, {\n cause: error,\n request: context.request,\n response: context.response,\n });\n}\n","/**\n * Lightweight frontmatter parser for SKILL.md files.\n */\n\nimport { OllamaSkillInvalidError } from '../errors.js';\nimport type { SkillFrontmatter } from './types.js';\n\nexport interface ParsedFrontmatter {\n readonly frontmatter: SkillFrontmatter;\n readonly body: string;\n}\n\nfunction parseYamlValue(raw: string): unknown {\n const trimmed = raw.trim();\n if (trimmed === 'true') return true;\n if (trimmed === 'false') return false;\n if (!Number.isNaN(Number(trimmed)) && trimmed !== '') return Number(trimmed);\n if (\n (trimmed.startsWith('\"') && trimmed.endsWith('\"')) ||\n (trimmed.startsWith(\"'\") && trimmed.endsWith(\"'\"))\n ) {\n return trimmed.slice(1, -1);\n }\n return trimmed;\n}\n\nfunction parseYamlBlock(yamlText: string): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n const lines = yamlText.split('\\n');\n let currentKey: string | undefined;\n let currentList: unknown[] | undefined;\n\n for (const line of lines) {\n const trimmed = line.trim();\n if (!trimmed || trimmed.startsWith('#')) continue;\n\n if (trimmed.startsWith('- ') && currentKey) {\n if (!currentList) {\n currentList = [];\n result[currentKey] = currentList;\n }\n currentList.push(parseYamlValue(trimmed.slice(2)));\n continue;\n }\n\n currentList = undefined;\n const colonIndex = line.indexOf(':');\n if (colonIndex > 0) {\n const key = line.slice(0, colonIndex).trim();\n const valStr = line.slice(colonIndex + 1).trim();\n currentKey = key;\n if (valStr.length > 0) {\n result[key] = parseYamlValue(valStr);\n }\n }\n }\n\n return result;\n}\n\nexport function parseFrontmatter(source: string, path = ''): ParsedFrontmatter {\n const match = source.match(/^---\\r?\\n([\\s\\S]*?)\\r?\\n---\\r?\\n?([\\s\\S]*)$/);\n if (!match) {\n throw new OllamaSkillInvalidError('Missing YAML frontmatter delimiters (---)', {\n skillName: path || 'unknown',\n path,\n });\n }\n\n const rawYaml = match[1] ?? '';\n const body = match[2]?.trim() ?? '';\n const parsed = parseYamlBlock(rawYaml);\n\n if (!parsed['name'] || typeof parsed['name'] !== 'string') {\n throw new OllamaSkillInvalidError('Frontmatter missing required string \"name\"', {\n skillName: String(parsed['name'] ?? 'unknown'),\n path,\n });\n }\n if (!parsed['description'] || typeof parsed['description'] !== 'string') {\n throw new OllamaSkillInvalidError('Frontmatter missing required string \"description\"', {\n skillName: parsed['name'],\n path,\n });\n }\n\n return {\n frontmatter: parsed as unknown as SkillFrontmatter,\n body,\n };\n}\n","/**\n * Skill composition and context injection.\n */\n\nimport type { Message } from '../types.js';\nimport type { ToolRegistry } from '../tools/registry.js';\nimport type { Skill } from './types.js';\n\nexport interface ApplySkillOptions {\n readonly messages: readonly Message[];\n readonly tools?: ToolRegistry;\n}\n\nexport interface AppliedSkillResult {\n readonly messages: readonly Message[];\n readonly tools?: ToolRegistry;\n}\n\n/**\n * Injects a skill's body into messages as a system prompt and applies allowed tool filters.\n */\nexport function applySkill(skill: Skill, options: ApplySkillOptions): AppliedSkillResult {\n const systemPrompt = `[Skill: ${skill.name}]\\n${skill.description}\\n\\n${skill.body}`;\n const messages = [...options.messages];\n const systemIndex = messages.findIndex((m) => m.role === 'system');\n\n if (systemIndex >= 0) {\n const existing = messages[systemIndex];\n if (existing) {\n messages[systemIndex] = {\n role: 'system',\n content: `${existing.content}\\n\\n${systemPrompt}`,\n };\n }\n } else {\n messages.unshift({ role: 'system', content: systemPrompt });\n }\n\n return {\n messages,\n ...(options.tools !== undefined ? { tools: options.tools } : {}),\n };\n}\n","/**\n * Node.js filesystem skill registry for SKILL.md packages.\n */\n\nimport { readdir, readFile } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { OllamaSkillNotFoundError } from '../errors.js';\nimport { parseFrontmatter } from './frontmatter.js';\nimport type { Skill, SkillSummary } from './types.js';\n\nexport interface SkillRegistryOptions {\n readonly directory: string;\n}\n\nexport class SkillRegistry {\n readonly directory: string;\n\n constructor(options: SkillRegistryOptions) {\n this.directory = options.directory;\n }\n\n async list(): Promise<SkillSummary[]> {\n const entries = await readdir(this.directory, { withFileTypes: true });\n const summaries: SkillSummary[] = [];\n\n for (const entry of entries) {\n if (!entry.isDirectory()) continue;\n const skillPath = join(this.directory, entry.name, 'SKILL.md');\n try {\n const content = await readFile(skillPath, 'utf-8');\n const parsed = parseFrontmatter(content, skillPath);\n summaries.push({\n name: parsed.frontmatter.name,\n description: parsed.frontmatter.description,\n path: skillPath,\n });\n } catch {\n // Skip directories without valid SKILL.md\n }\n }\n\n return summaries;\n }\n\n async load(name: string): Promise<Skill> {\n const skillPath = join(this.directory, name, 'SKILL.md');\n try {\n const content = await readFile(skillPath, 'utf-8');\n const parsed = parseFrontmatter(content, skillPath);\n return {\n name: parsed.frontmatter.name,\n description: parsed.frontmatter.description,\n path: skillPath,\n frontmatter: parsed.frontmatter,\n body: parsed.body,\n allowedTools: parsed.frontmatter['allowed-tools'],\n };\n } catch (err) {\n throw new OllamaSkillNotFoundError(`Skill \"${name}\" not found at ${skillPath}`, {\n skillName: name,\n cause: err,\n });\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/errors.ts","../src/skills/frontmatter.ts","../src/skills/compose.ts","../src/skills/skill-registry.ts"],"names":[],"mappings":";;;;AAwBO,IAAM,iBAAA,GAAN,cAAgC,KAAA,CAAM;AAAA,EAClC,IAAA;AAAA,EACA,MAAA;AAAA,EACA,SAAA;AAAA,EACA,OAAA;AAAA,EACA,QAAA;AAAA,EAET,WAAA,CAAY,SAAiB,OAAA,EAAmC;AAC9D,IAAA,KAAA,CAAM,OAAA,EAAS,EAAE,KAAA,EAAO,OAA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e;AAAA,OAClD;AAAA,IACF,SAAS,GAAA,EAAK;AACZ,MAAA,MAAM,IAAI,wBAAA,CAAyB,CAAA,OAAA,EAAU,IAAI,CAAA,eAAA,EAAkB,SAAS,CAAA,CAAA,EAAI;AAAA,QAC9E,SAAA,EAAW,IAAA;AAAA,QACX,KAAA,EAAO;AAAA,OACR,CAAA;AAAA,IACH;AAAA,EACF;AACF","file":"skills.js","sourcesContent":["/**\n * Structured, typed error hierarchy for OllamaClient.\n */\n\nexport interface OllamaErrorRequestContext {\n readonly method?: string | undefined;\n readonly url?: string | undefined;\n readonly model?: string | undefined;\n}\n\nexport interface OllamaErrorResponseContext {\n readonly status?: number | undefined;\n readonly headers?: Record<string, string> | undefined;\n readonly body?: unknown;\n}\n\nexport interface OllamaClientErrorOptions extends ErrorOptions {\n readonly code: string;\n readonly status?: number | undefined;\n readonly retryable?: boolean | undefined;\n readonly request?: OllamaErrorRequestContext | undefined;\n readonly response?: OllamaErrorResponseContext | undefined;\n}\n\nexport class OllamaClientError extends Error {\n readonly code: string;\n readonly status?: number | undefined;\n readonly retryable: boolean;\n readonly request?: OllamaErrorRequestContext | undefined;\n readonly response?: OllamaErrorResponseContext | undefined;\n\n constructor(message: string, options: OllamaClientErrorOptions) {\n super(message, { cause: options.cause });\n this.name = this.constructor.name;\n this.code = options.code;\n this.status = options.status;\n this.retryable = options.retryable ?? false;\n this.request = options.request;\n this.response = options.response;\n }\n}\n\nexport class OllamaNetworkError extends OllamaClientError {\n constructor(\n message: string,\n options?: Omit<OllamaClientErrorOptions, 'code' | 'retryable'> | undefined,\n ) {\n super(message, { ...options, code: 'network_error', retryable: true });\n }\n}\n\nexport class OllamaTimeoutError extends OllamaClientError {\n readonly timeoutMs?: number | undefined;\n constructor(\n message: string,\n options?:\n | (Omit<OllamaClientErrorOptions, 'code' | 'retryable'> & { timeoutMs?: number | undefined })\n | undefined,\n ) {\n super(message, { ...options, code: 'timeout', retryable: true });\n this.timeoutMs = options?.timeoutMs;\n }\n}\n\nexport class OllamaAuthError extends OllamaClientError {\n constructor(\n message: string,\n options?: Omit<OllamaClientErrorOptions, 'code' | 'retryable'> | undefined,\n ) {\n super(message, { ...options, code: 'auth_error', retryable: false });\n }\n}\n\nexport class OllamaNotFoundError extends OllamaClientError {\n constructor(\n message: string,\n options?: Omit<OllamaClientErrorOptions, 'code' | 'retryable'> | undefined,\n ) {\n super(message, { ...options, code: 'not_found', retryable: false });\n }\n}\n\nexport class OllamaRateLimitError extends OllamaClientError {\n readonly retryAfterMs?: number | undefined;\n constructor(\n message: string,\n options?:\n | (Omit<OllamaClientErrorOptions, 'code' | 'retryable'> & {\n retryAfterMs?: number | undefined;\n })\n | undefined,\n ) {\n super(message, { ...options, code: 'rate_limited', retryable: true });\n this.retryAfterMs = options?.retryAfterMs;\n }\n}\n\n/**\n * Thrown client-side, before a network request is made, by `QuotaManager.assertCanProceed`\n * (see `src/quota.ts`) when issuing the request would exceed a configured usage budget for\n * one of its rolling windows. This is distinct from `OllamaRateLimitError`, which reflects\n * the server's own 429 response — Ollama Cloud does not expose account-level quota via the\n * API, so `QuotaManager` tracks usage against budgets the caller configures locally and\n * fails fast rather than waiting for the server to reject the request.\n */\nexport class OllamaQuotaExceededError extends OllamaClientError {\n readonly windowId: string;\n readonly resetAt: number;\n constructor(\n message: string,\n options: Omit<OllamaClientErrorOptions, 'code' | 'retryable'> & {\n windowId: string;\n resetAt: number;\n },\n ) {\n super(message, { ...options, code: 'quota_exceeded', retryable: false });\n this.windowId = options.windowId;\n this.resetAt = options.resetAt;\n }\n}\n\nexport class OllamaServerError extends OllamaClientError {\n constructor(\n message: string,\n options?: Omit<OllamaClientErrorOptions, 'code' | 'retryable'> | undefined,\n ) {\n super(message, { ...options, code: 'server_error', retryable: true });\n }\n}\n\nexport class OllamaAbortError extends OllamaClientError {\n constructor(\n message: string,\n options?: Omit<OllamaClientErrorOptions, 'code' | 'retryable'> | undefined,\n ) {\n super(message, { ...options, code: 'aborted', retryable: false });\n }\n}\n\nexport class OllamaToolValidationError extends OllamaClientError {\n readonly toolName: string;\n readonly issues?: unknown;\n constructor(\n message: string,\n options: Omit<OllamaClientErrorOptions, 'code'> & { toolName: string; issues?: unknown },\n ) {\n super(message, { ...options, code: 'tool_validation_error', retryable: false });\n this.toolName = options.toolName;\n this.issues = options.issues;\n }\n}\n\nexport class OllamaToolTimeoutError extends OllamaClientError {\n readonly toolName: string;\n readonly timeoutMs: number;\n constructor(\n message: string,\n options: Omit<OllamaClientErrorOptions, 'code' | 'retryable'> & {\n toolName: string;\n timeoutMs: number;\n },\n ) {\n super(message, { ...options, code: 'tool_timeout', retryable: false });\n this.toolName = options.toolName;\n this.timeoutMs = options.timeoutMs;\n }\n}\n\n/**\n * Thrown client-side, before a network request is made, when a request asks for a\n * capability an endpoint is known not to support (e.g. structured output `format` against\n * an Ollama Cloud endpoint — see `ModelCapabilities.supportsStructuredOutputRequest` in\n * `src/capabilities/capabilities.ts`). Its `code` is included in `DEFAULT_FAILOVER_CODES`\n * by default, so in a multi-endpoint setup it causes failover to the next candidate rather\n * than failing outright — it only surfaces to the caller if every candidate is rejected.\n */\nexport class OllamaUnsupportedCapabilityError extends OllamaClientError {\n readonly capability: string;\n constructor(\n message: string,\n options: Omit<OllamaClientErrorOptions, 'code' | 'retryable'> & { capability: string },\n ) {\n super(message, { ...options, code: 'unsupported_capability', retryable: false });\n this.capability = options.capability;\n }\n}\n\n/**\n * Thrown client-side, before any network call, when `config.endpoints` uses\n * `OllamaEndpoint.models` to scope endpoints/credentials to specific models and the\n * requested `model` isn't in any configured endpoint's allow-list. This is a routing\n * misconfiguration, not a connectivity problem — the SDK deliberately does not \"probe\"\n * unauthorized endpoints to find one that happens to work (that would burn quota on keys\n * that were never entitled to the model and produce non-deterministic startup behavior).\n */\nexport class OllamaModelRoutingError extends OllamaClientError {\n readonly model: string;\n readonly availableModels: readonly string[];\n constructor(\n message: string,\n options: Omit<OllamaClientErrorOptions, 'code' | 'retryable'> & {\n model: string;\n availableModels: readonly string[];\n },\n ) {\n super(message, { ...options, code: 'model_routing_error', retryable: false });\n this.model = options.model;\n this.availableModels = options.availableModels;\n }\n}\n\n/**\n * Thrown before an agent tool loop starts when the selected model's /api/show metadata\n * does not advertise a capability required by the loop.\n */\nexport class OllamaIncompatibleModelError extends OllamaClientError {\n readonly model: string;\n readonly capability: string;\n readonly reportedCapabilities: readonly string[];\n\n constructor(\n message: string,\n options: Omit<OllamaClientErrorOptions, 'code' | 'retryable'> & {\n model: string;\n capability: string;\n reportedCapabilities: readonly string[];\n },\n ) {\n super(message, { ...options, code: 'incompatible_model', retryable: false });\n this.model = options.model;\n this.capability = options.capability;\n this.reportedCapabilities = options.reportedCapabilities;\n }\n}\nexport class OllamaAgentMaxToolCallsError extends OllamaClientError {\n readonly maxToolCalls: number;\n readonly toolCallsExecuted: number;\n\n constructor(\n message: string,\n options: Omit<OllamaClientErrorOptions, 'code'> & {\n maxToolCalls: number;\n toolCallsExecuted: number;\n },\n ) {\n super(message, { ...options, code: 'agent_max_tool_calls_exceeded', retryable: false });\n this.maxToolCalls = options.maxToolCalls;\n this.toolCallsExecuted = options.toolCallsExecuted;\n }\n}\n\nexport class OllamaAgentMaxIterationsError extends OllamaClientError {\n readonly maxIterations: number;\n constructor(\n message: string,\n options: Omit<OllamaClientErrorOptions, 'code'> & { maxIterations: number },\n ) {\n super(message, { ...options, code: 'agent_max_iterations_exceeded', retryable: false });\n this.maxIterations = options.maxIterations;\n }\n}\n\nexport class OllamaMcpError extends OllamaClientError {\n readonly mcpMethod: 'listTools' | 'callTool';\n readonly toolName?: string | undefined;\n constructor(\n message: string,\n options: Omit<OllamaClientErrorOptions, 'code'> & {\n mcpMethod: 'listTools' | 'callTool';\n toolName?: string | undefined;\n },\n ) {\n super(message, { ...options, code: 'mcp_error', retryable: options.retryable ?? false });\n this.mcpMethod = options.mcpMethod;\n this.toolName = options.toolName;\n }\n}\n\nexport class OllamaSkillNotFoundError extends OllamaClientError {\n readonly skillName: string;\n constructor(\n message: string,\n options: Omit<OllamaClientErrorOptions, 'code'> & { skillName: string },\n ) {\n super(message, { ...options, code: 'skill_not_found', retryable: false });\n this.skillName = options.skillName;\n }\n}\n\nexport class OllamaSkillInvalidError extends OllamaClientError {\n readonly skillName: string;\n readonly path?: string | undefined;\n constructor(\n message: string,\n options: Omit<OllamaClientErrorOptions, 'code'> & {\n skillName: string;\n path?: string | undefined;\n },\n ) {\n super(message, { ...options, code: 'skill_invalid', retryable: false });\n this.skillName = options.skillName;\n this.path = options.path;\n }\n}\n\nexport class OllamaGenericClientError extends OllamaClientError {\n constructor(message: string, options?: Omit<OllamaClientErrorOptions, 'code'> | undefined) {\n super(message, { ...options, code: 'client_error' });\n }\n}\n\nfunction isDomAbortError(error: unknown): error is DOMException {\n return (\n typeof DOMException !== 'undefined' &&\n error instanceof DOMException &&\n error.name === 'AbortError'\n );\n}\n\nfunction statusToError(\n status: number,\n message: string,\n options: Omit<OllamaClientErrorOptions, 'code' | 'status'>,\n): OllamaClientError {\n if (status === 401 || status === 403) {\n return new OllamaAuthError(message, { ...options, status });\n }\n if (status === 404) {\n return new OllamaNotFoundError(message, { ...options, status });\n }\n if (status === 429) {\n return new OllamaRateLimitError(message, { ...options, status });\n }\n if (status >= 500) {\n return new OllamaServerError(message, { ...options, status });\n }\n return new OllamaGenericClientError(message, { ...options, status });\n}\n\n/**\n * Maps arbitrary thrown exceptions into structured OllamaClientError instances.\n */\nexport function mapError(\n error: unknown,\n context: {\n request?: OllamaErrorRequestContext | undefined;\n response?: OllamaErrorResponseContext | undefined;\n } = {},\n): OllamaClientError {\n if (error instanceof OllamaClientError) {\n return error;\n }\n if (isDomAbortError(error)) {\n return new OllamaAbortError(error.message || 'Request was aborted', {\n cause: error,\n request: context.request,\n });\n }\n if (error instanceof TypeError) {\n return new OllamaNetworkError(error.message || 'Network request failed', {\n cause: error,\n request: context.request,\n });\n }\n if (context.response?.status !== undefined) {\n const message = error instanceof Error ? error.message : String(error);\n return statusToError(context.response.status, message, {\n cause: error,\n request: context.request,\n response: context.response,\n });\n }\n const message = error instanceof Error ? error.message : String(error);\n return new OllamaGenericClientError(message, {\n cause: error,\n request: context.request,\n response: context.response,\n });\n}\n","/**\n * Lightweight frontmatter parser for SKILL.md files.\n */\n\nimport { OllamaSkillInvalidError } from '../errors.js';\nimport type { SkillFrontmatter } from './types.js';\n\nexport interface ParsedFrontmatter {\n readonly frontmatter: SkillFrontmatter;\n readonly body: string;\n}\n\nfunction parseYamlValue(raw: string): unknown {\n const trimmed = raw.trim();\n if (trimmed === 'true') return true;\n if (trimmed === 'false') return false;\n if (!Number.isNaN(Number(trimmed)) && trimmed !== '') return Number(trimmed);\n if (\n (trimmed.startsWith('\"') && trimmed.endsWith('\"')) ||\n (trimmed.startsWith(\"'\") && trimmed.endsWith(\"'\"))\n ) {\n return trimmed.slice(1, -1);\n }\n return trimmed;\n}\n\nfunction parseYamlBlock(yamlText: string): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n const lines = yamlText.split('\\n');\n let currentKey: string | undefined;\n let currentList: unknown[] | undefined;\n\n for (const line of lines) {\n const trimmed = line.trim();\n if (!trimmed || trimmed.startsWith('#')) continue;\n\n if (trimmed.startsWith('- ') && currentKey) {\n if (!currentList) {\n currentList = [];\n result[currentKey] = currentList;\n }\n currentList.push(parseYamlValue(trimmed.slice(2)));\n continue;\n }\n\n currentList = undefined;\n const colonIndex = line.indexOf(':');\n if (colonIndex > 0) {\n const key = line.slice(0, colonIndex).trim();\n const valStr = line.slice(colonIndex + 1).trim();\n currentKey = key;\n if (valStr.length > 0) {\n result[key] = parseYamlValue(valStr);\n }\n }\n }\n\n return result;\n}\n\nexport function parseFrontmatter(source: string, path = ''): ParsedFrontmatter {\n const match = source.match(/^---\\r?\\n([\\s\\S]*?)\\r?\\n---\\r?\\n?([\\s\\S]*)$/);\n if (!match) {\n throw new OllamaSkillInvalidError('Missing YAML frontmatter delimiters (---)', {\n skillName: path || 'unknown',\n path,\n });\n }\n\n const rawYaml = match[1] ?? '';\n const body = match[2]?.trim() ?? '';\n const parsed = parseYamlBlock(rawYaml);\n\n if (!parsed['name'] || typeof parsed['name'] !== 'string') {\n throw new OllamaSkillInvalidError('Frontmatter missing required string \"name\"', {\n skillName: String(parsed['name'] ?? 'unknown'),\n path,\n });\n }\n if (!parsed['description'] || typeof parsed['description'] !== 'string') {\n throw new OllamaSkillInvalidError('Frontmatter missing required string \"description\"', {\n skillName: parsed['name'],\n path,\n });\n }\n\n return {\n frontmatter: parsed as unknown as SkillFrontmatter,\n body,\n };\n}\n","/**\n * Skill composition and context injection.\n */\n\nimport type { Message } from '../types.js';\nimport type { ToolRegistry } from '../tools/registry.js';\nimport type { Skill } from './types.js';\n\nexport interface ApplySkillOptions {\n readonly messages: readonly Message[];\n readonly tools?: ToolRegistry;\n}\n\nexport interface AppliedSkillResult {\n readonly messages: readonly Message[];\n readonly tools?: ToolRegistry;\n}\n\n/**\n * Injects a skill's body into messages as a system prompt and applies allowed tool filters.\n */\nexport function applySkill(skill: Skill, options: ApplySkillOptions): AppliedSkillResult {\n const systemPrompt = `[Skill: ${skill.name}]\\n${skill.description}\\n\\n${skill.body}`;\n const messages = [...options.messages];\n const systemIndex = messages.findIndex((m) => m.role === 'system');\n\n if (systemIndex >= 0) {\n const existing = messages[systemIndex];\n if (existing) {\n messages[systemIndex] = {\n role: 'system',\n content: `${existing.content}\\n\\n${systemPrompt}`,\n };\n }\n } else {\n messages.unshift({ role: 'system', content: systemPrompt });\n }\n\n return {\n messages,\n ...(options.tools !== undefined ? { tools: options.tools } : {}),\n };\n}\n","/**\n * Node.js filesystem skill registry for SKILL.md packages.\n */\n\nimport { readdir, readFile } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { OllamaSkillNotFoundError } from '../errors.js';\nimport { parseFrontmatter } from './frontmatter.js';\nimport type { Skill, SkillSummary } from './types.js';\n\nexport interface SkillRegistryOptions {\n readonly directory: string;\n}\n\nexport class SkillRegistry {\n readonly directory: string;\n\n constructor(options: SkillRegistryOptions) {\n this.directory = options.directory;\n }\n\n async list(): Promise<SkillSummary[]> {\n const entries = await readdir(this.directory, { withFileTypes: true });\n const summaries: SkillSummary[] = [];\n\n for (const entry of entries) {\n if (!entry.isDirectory()) continue;\n const skillPath = join(this.directory, entry.name, 'SKILL.md');\n try {\n const content = await readFile(skillPath, 'utf-8');\n const parsed = parseFrontmatter(content, skillPath);\n summaries.push({\n name: parsed.frontmatter.name,\n description: parsed.frontmatter.description,\n path: skillPath,\n });\n } catch {\n // Skip directories without valid SKILL.md\n }\n }\n\n return summaries;\n }\n\n async load(name: string): Promise<Skill> {\n const skillPath = join(this.directory, name, 'SKILL.md');\n try {\n const content = await readFile(skillPath, 'utf-8');\n const parsed = parseFrontmatter(content, skillPath);\n return {\n name: parsed.frontmatter.name,\n description: parsed.frontmatter.description,\n path: skillPath,\n frontmatter: parsed.frontmatter,\n body: parsed.body,\n allowedTools: parsed.frontmatter['allowed-tools'],\n };\n } catch (err) {\n throw new OllamaSkillNotFoundError(`Skill \"${name}\" not found at ${skillPath}`, {\n skillName: name,\n cause: err,\n });\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Duck-typed MCP (Model Context Protocol) client interfaces.
|
|
3
|
+
* Decoupled from any specific MCP SDK.
|
|
4
|
+
*/
|
|
5
|
+
interface McpToolAnnotations {
|
|
6
|
+
readonly title?: string | undefined;
|
|
7
|
+
readonly readOnlyHint?: boolean | undefined;
|
|
8
|
+
readonly destructiveHint?: boolean | undefined;
|
|
9
|
+
readonly idempotentHint?: boolean | undefined;
|
|
10
|
+
readonly openWorldHint?: boolean | undefined;
|
|
11
|
+
readonly [key: string]: unknown;
|
|
12
|
+
}
|
|
13
|
+
interface McpToolExecution {
|
|
14
|
+
readonly taskSupport?: 'forbidden' | 'optional' | 'required' | undefined;
|
|
15
|
+
readonly [key: string]: unknown;
|
|
16
|
+
}
|
|
17
|
+
interface McpIcon {
|
|
18
|
+
readonly src: string;
|
|
19
|
+
readonly mimeType?: string | undefined;
|
|
20
|
+
readonly sizes?: readonly string[] | undefined;
|
|
21
|
+
readonly theme?: 'light' | 'dark' | undefined;
|
|
22
|
+
readonly [key: string]: unknown;
|
|
23
|
+
}
|
|
24
|
+
interface McpRequestOptions {
|
|
25
|
+
readonly signal?: AbortSignal | undefined;
|
|
26
|
+
}
|
|
27
|
+
interface McpToolDescriptor {
|
|
28
|
+
readonly name: string;
|
|
29
|
+
readonly title?: string | undefined;
|
|
30
|
+
readonly description?: string | undefined;
|
|
31
|
+
readonly inputSchema?: Record<string, unknown> | undefined;
|
|
32
|
+
readonly outputSchema?: Record<string, unknown> | undefined;
|
|
33
|
+
readonly annotations?: McpToolAnnotations | undefined;
|
|
34
|
+
readonly execution?: McpToolExecution | undefined;
|
|
35
|
+
readonly icons?: readonly McpIcon[] | undefined;
|
|
36
|
+
readonly _meta?: Record<string, unknown> | undefined;
|
|
37
|
+
}
|
|
38
|
+
interface McpListToolsResult {
|
|
39
|
+
readonly tools: readonly McpToolDescriptor[];
|
|
40
|
+
readonly nextCursor?: string | undefined;
|
|
41
|
+
}
|
|
42
|
+
interface McpListToolsParams {
|
|
43
|
+
readonly cursor?: string | undefined;
|
|
44
|
+
}
|
|
45
|
+
interface McpContentBlock {
|
|
46
|
+
readonly type: string;
|
|
47
|
+
readonly text?: string | undefined;
|
|
48
|
+
readonly annotations?: Record<string, unknown> | undefined;
|
|
49
|
+
readonly _meta?: Record<string, unknown> | undefined;
|
|
50
|
+
readonly [key: string]: unknown;
|
|
51
|
+
}
|
|
52
|
+
interface McpCallToolResult {
|
|
53
|
+
readonly content: readonly McpContentBlock[];
|
|
54
|
+
readonly structuredContent?: unknown;
|
|
55
|
+
readonly isError?: boolean | undefined;
|
|
56
|
+
readonly _meta?: Record<string, unknown> | undefined;
|
|
57
|
+
}
|
|
58
|
+
interface McpClientLike {
|
|
59
|
+
listTools: (params?: McpListToolsParams, options?: McpRequestOptions) => Promise<McpListToolsResult>;
|
|
60
|
+
callTool: (params: {
|
|
61
|
+
readonly name: string;
|
|
62
|
+
readonly arguments?: Record<string, unknown>;
|
|
63
|
+
}, options?: McpRequestOptions) => Promise<McpCallToolResult>;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export type { McpToolDescriptor as M, McpClientLike as a, McpCallToolResult as b, McpContentBlock as c, McpIcon as d, McpListToolsParams as e, McpListToolsResult as f, McpRequestOptions as g, McpToolAnnotations as h, McpToolExecution as i };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Duck-typed MCP (Model Context Protocol) client interfaces.
|
|
3
|
+
* Decoupled from any specific MCP SDK.
|
|
4
|
+
*/
|
|
5
|
+
interface McpToolAnnotations {
|
|
6
|
+
readonly title?: string | undefined;
|
|
7
|
+
readonly readOnlyHint?: boolean | undefined;
|
|
8
|
+
readonly destructiveHint?: boolean | undefined;
|
|
9
|
+
readonly idempotentHint?: boolean | undefined;
|
|
10
|
+
readonly openWorldHint?: boolean | undefined;
|
|
11
|
+
readonly [key: string]: unknown;
|
|
12
|
+
}
|
|
13
|
+
interface McpToolExecution {
|
|
14
|
+
readonly taskSupport?: 'forbidden' | 'optional' | 'required' | undefined;
|
|
15
|
+
readonly [key: string]: unknown;
|
|
16
|
+
}
|
|
17
|
+
interface McpIcon {
|
|
18
|
+
readonly src: string;
|
|
19
|
+
readonly mimeType?: string | undefined;
|
|
20
|
+
readonly sizes?: readonly string[] | undefined;
|
|
21
|
+
readonly theme?: 'light' | 'dark' | undefined;
|
|
22
|
+
readonly [key: string]: unknown;
|
|
23
|
+
}
|
|
24
|
+
interface McpRequestOptions {
|
|
25
|
+
readonly signal?: AbortSignal | undefined;
|
|
26
|
+
}
|
|
27
|
+
interface McpToolDescriptor {
|
|
28
|
+
readonly name: string;
|
|
29
|
+
readonly title?: string | undefined;
|
|
30
|
+
readonly description?: string | undefined;
|
|
31
|
+
readonly inputSchema?: Record<string, unknown> | undefined;
|
|
32
|
+
readonly outputSchema?: Record<string, unknown> | undefined;
|
|
33
|
+
readonly annotations?: McpToolAnnotations | undefined;
|
|
34
|
+
readonly execution?: McpToolExecution | undefined;
|
|
35
|
+
readonly icons?: readonly McpIcon[] | undefined;
|
|
36
|
+
readonly _meta?: Record<string, unknown> | undefined;
|
|
37
|
+
}
|
|
38
|
+
interface McpListToolsResult {
|
|
39
|
+
readonly tools: readonly McpToolDescriptor[];
|
|
40
|
+
readonly nextCursor?: string | undefined;
|
|
41
|
+
}
|
|
42
|
+
interface McpListToolsParams {
|
|
43
|
+
readonly cursor?: string | undefined;
|
|
44
|
+
}
|
|
45
|
+
interface McpContentBlock {
|
|
46
|
+
readonly type: string;
|
|
47
|
+
readonly text?: string | undefined;
|
|
48
|
+
readonly annotations?: Record<string, unknown> | undefined;
|
|
49
|
+
readonly _meta?: Record<string, unknown> | undefined;
|
|
50
|
+
readonly [key: string]: unknown;
|
|
51
|
+
}
|
|
52
|
+
interface McpCallToolResult {
|
|
53
|
+
readonly content: readonly McpContentBlock[];
|
|
54
|
+
readonly structuredContent?: unknown;
|
|
55
|
+
readonly isError?: boolean | undefined;
|
|
56
|
+
readonly _meta?: Record<string, unknown> | undefined;
|
|
57
|
+
}
|
|
58
|
+
interface McpClientLike {
|
|
59
|
+
listTools: (params?: McpListToolsParams, options?: McpRequestOptions) => Promise<McpListToolsResult>;
|
|
60
|
+
callTool: (params: {
|
|
61
|
+
readonly name: string;
|
|
62
|
+
readonly arguments?: Record<string, unknown>;
|
|
63
|
+
}, options?: McpRequestOptions) => Promise<McpCallToolResult>;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export type { McpToolDescriptor as M, McpClientLike as a, McpCallToolResult as b, McpContentBlock as c, McpIcon as d, McpListToolsParams as e, McpListToolsResult as f, McpRequestOptions as g, McpToolAnnotations as h, McpToolExecution as i };
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* Core protocol and message types for the Ollama REST API.
|
|
5
3
|
*/
|
|
6
4
|
type Role = 'system' | 'user' | 'assistant' | 'tool' | 'thought';
|
|
5
|
+
/** Ollama native thinking control: booleans, null for model default, or model-defined levels. */
|
|
6
|
+
type ThinkValue = boolean | string | null;
|
|
7
|
+
/** Thinking capability metadata returned by `/api/show`. */
|
|
8
|
+
interface ThinkingMetadata {
|
|
9
|
+
readonly values: readonly (boolean | string)[];
|
|
10
|
+
readonly default?: boolean | string | null | undefined;
|
|
11
|
+
}
|
|
7
12
|
interface ToolCallFunction {
|
|
8
13
|
readonly name: string;
|
|
9
14
|
readonly arguments: Record<string, unknown>;
|
|
@@ -35,7 +40,16 @@ interface Message {
|
|
|
35
40
|
*/
|
|
36
41
|
readonly images?: readonly (string | Uint8Array)[] | undefined;
|
|
37
42
|
readonly tool_calls?: readonly ToolCall[] | undefined;
|
|
38
|
-
/**
|
|
43
|
+
/**
|
|
44
|
+
* Ollama's native `/api/chat` field identifying which tool produced this result.
|
|
45
|
+
* For `role: 'tool'` messages this should be the registered tool's name.
|
|
46
|
+
*/
|
|
47
|
+
readonly tool_name?: string | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* @deprecated SDK-local correlation metadata only. Ollama's native `/api/chat` protocol
|
|
50
|
+
* does not use `tool_call_id`; native requests strip this field before transmission.
|
|
51
|
+
* OpenAI compatibility uses its own `OpenAIMessage.tool_call_id` type.
|
|
52
|
+
*/
|
|
39
53
|
readonly tool_call_id?: string | undefined;
|
|
40
54
|
readonly thinking?: string | undefined;
|
|
41
55
|
}
|
|
@@ -46,15 +60,20 @@ interface ToolProperty {
|
|
|
46
60
|
readonly items?: Record<string, unknown> | undefined;
|
|
47
61
|
readonly properties?: Record<string, unknown> | undefined;
|
|
48
62
|
readonly required?: readonly string[] | undefined;
|
|
63
|
+
/** Additional JSON Schema keywords are preserved for MCP/provider interoperability. */
|
|
64
|
+
readonly [keyword: string]: unknown;
|
|
65
|
+
}
|
|
66
|
+
interface ToolParameters {
|
|
67
|
+
readonly type: 'object';
|
|
68
|
+
readonly properties: Record<string, ToolProperty>;
|
|
69
|
+
readonly required?: readonly string[] | undefined;
|
|
70
|
+
/** Additional JSON Schema keywords such as $defs, anyOf, allOf, and additionalProperties. */
|
|
71
|
+
readonly [keyword: string]: unknown;
|
|
49
72
|
}
|
|
50
73
|
interface ToolFunctionDefinition {
|
|
51
74
|
readonly name: string;
|
|
52
75
|
readonly description: string;
|
|
53
|
-
readonly parameters:
|
|
54
|
-
readonly type: 'object';
|
|
55
|
-
readonly properties: Record<string, ToolProperty>;
|
|
56
|
-
readonly required?: readonly string[] | undefined;
|
|
57
|
-
};
|
|
76
|
+
readonly parameters: ToolParameters;
|
|
58
77
|
}
|
|
59
78
|
interface ToolDefinition {
|
|
60
79
|
readonly type: 'function';
|
|
@@ -80,6 +99,8 @@ interface ModelOptions {
|
|
|
80
99
|
readonly num_keep?: number | undefined;
|
|
81
100
|
readonly seed?: number | undefined;
|
|
82
101
|
readonly num_predict?: number | undefined;
|
|
102
|
+
/** Number of tokens to predict with a draft/speculative model, when supported. */
|
|
103
|
+
readonly draft_num_predict?: number | undefined;
|
|
83
104
|
readonly top_k?: number | undefined;
|
|
84
105
|
readonly top_p?: number | undefined;
|
|
85
106
|
readonly min_p?: number | undefined;
|
|
@@ -118,7 +139,17 @@ interface ChatRequestOptions extends RequestCancellationOptions {
|
|
|
118
139
|
readonly options?: ModelOptions | undefined;
|
|
119
140
|
readonly stream?: boolean | undefined;
|
|
120
141
|
readonly keep_alive?: string | number | undefined;
|
|
121
|
-
|
|
142
|
+
/**
|
|
143
|
+
* Controls thinking output. Use `client.capabilities(model).thinking` to discover
|
|
144
|
+
* model-defined string levels and the model default.
|
|
145
|
+
*/
|
|
146
|
+
readonly think?: ThinkValue | undefined;
|
|
147
|
+
/** Experimental image-generation width in pixels. */
|
|
148
|
+
readonly width?: number | undefined;
|
|
149
|
+
/** Experimental image-generation height in pixels. */
|
|
150
|
+
readonly height?: number | undefined;
|
|
151
|
+
/** Experimental image-generation diffusion steps. */
|
|
152
|
+
readonly steps?: number | undefined;
|
|
122
153
|
/** Whether to return log probabilities of the output tokens. See {@link ChatResponse.logprobs}. */
|
|
123
154
|
readonly logprobs?: boolean | undefined;
|
|
124
155
|
/** Number of most likely alternative tokens to return at each position. Requires `logprobs: true`. */
|
|
@@ -133,6 +164,8 @@ interface ChatResponse {
|
|
|
133
164
|
readonly total_duration?: number | undefined;
|
|
134
165
|
readonly load_duration?: number | undefined;
|
|
135
166
|
readonly prompt_eval_count?: number | undefined;
|
|
167
|
+
/** Number of prompt tokens read from the KV cache. */
|
|
168
|
+
readonly prompt_eval_cached_count?: number | undefined;
|
|
136
169
|
readonly prompt_eval_duration?: number | undefined;
|
|
137
170
|
readonly eval_count?: number | undefined;
|
|
138
171
|
readonly eval_duration?: number | undefined;
|
|
@@ -157,11 +190,17 @@ interface GenerateRequestOptions extends RequestCancellationOptions {
|
|
|
157
190
|
readonly images?: readonly (string | Uint8Array)[] | undefined;
|
|
158
191
|
readonly options?: ModelOptions | undefined;
|
|
159
192
|
readonly keep_alive?: string | number | undefined;
|
|
160
|
-
readonly think?:
|
|
193
|
+
readonly think?: ThinkValue | undefined;
|
|
161
194
|
/** Whether to return log probabilities of the output tokens. See {@link GenerateResponse.logprobs}. */
|
|
162
195
|
readonly logprobs?: boolean | undefined;
|
|
163
196
|
/** Number of most likely alternative tokens to return at each position. Requires `logprobs: true`. */
|
|
164
197
|
readonly top_logprobs?: number | undefined;
|
|
198
|
+
/** Experimental image-generation width in pixels. */
|
|
199
|
+
readonly width?: number | undefined;
|
|
200
|
+
/** Experimental image-generation height in pixels. */
|
|
201
|
+
readonly height?: number | undefined;
|
|
202
|
+
/** Experimental image-generation diffusion steps. */
|
|
203
|
+
readonly steps?: number | undefined;
|
|
165
204
|
}
|
|
166
205
|
interface GenerateResponse {
|
|
167
206
|
readonly model: string;
|
|
@@ -173,12 +212,20 @@ interface GenerateResponse {
|
|
|
173
212
|
readonly total_duration?: number | undefined;
|
|
174
213
|
readonly load_duration?: number | undefined;
|
|
175
214
|
readonly prompt_eval_count?: number | undefined;
|
|
215
|
+
/** Number of prompt tokens read from the KV cache. */
|
|
216
|
+
readonly prompt_eval_cached_count?: number | undefined;
|
|
176
217
|
readonly prompt_eval_duration?: number | undefined;
|
|
177
218
|
readonly eval_count?: number | undefined;
|
|
178
219
|
readonly eval_duration?: number | undefined;
|
|
179
220
|
readonly thinking?: string | undefined;
|
|
180
221
|
/** Present when the request set `logprobs: true`. */
|
|
181
222
|
readonly logprobs?: readonly Logprob[] | undefined;
|
|
223
|
+
/** Base64-encoded generated image data for image-generation models. */
|
|
224
|
+
readonly image?: string | undefined;
|
|
225
|
+
/** Number of completed image-generation steps. */
|
|
226
|
+
readonly completed?: number | undefined;
|
|
227
|
+
/** Total image-generation steps. */
|
|
228
|
+
readonly total?: number | undefined;
|
|
182
229
|
}
|
|
183
230
|
interface EmbedRequestOptions extends RequestCancellationOptions {
|
|
184
231
|
readonly model: string;
|
|
@@ -222,6 +269,8 @@ interface ModelResponse {
|
|
|
222
269
|
readonly details: ModelDetails;
|
|
223
270
|
readonly expires_at?: string | undefined;
|
|
224
271
|
readonly size_vram?: number | undefined;
|
|
272
|
+
/** Context window length reported for currently running models by /api/ps. */
|
|
273
|
+
readonly context_length?: number | undefined;
|
|
225
274
|
}
|
|
226
275
|
interface ListResponse {
|
|
227
276
|
readonly models: readonly ModelResponse[];
|
|
@@ -242,6 +291,8 @@ interface ShowResponse {
|
|
|
242
291
|
readonly messages?: readonly Message[] | undefined;
|
|
243
292
|
readonly model_info?: Record<string, unknown> | undefined;
|
|
244
293
|
readonly capabilities?: readonly string[] | undefined;
|
|
294
|
+
/** Model-defined thinking levels and default, when reported by Ollama. */
|
|
295
|
+
readonly thinking?: ThinkingMetadata | undefined;
|
|
245
296
|
readonly modified_at?: string | undefined;
|
|
246
297
|
}
|
|
247
298
|
interface ProgressResponse {
|
|
@@ -274,8 +325,12 @@ interface CreateRequestOptions extends RequestCancellationOptions {
|
|
|
274
325
|
readonly modelfile?: string | undefined;
|
|
275
326
|
readonly stream?: boolean | undefined;
|
|
276
327
|
readonly quantize?: string | undefined;
|
|
328
|
+
/** Quantization level to apply to draft weights during import. */
|
|
329
|
+
readonly draft_quantize?: string | undefined;
|
|
277
330
|
readonly from?: string | undefined;
|
|
278
331
|
readonly files?: Record<string, string> | undefined;
|
|
332
|
+
/** Draft source file names mapped to their SHA-256 digests. */
|
|
333
|
+
readonly draft_files?: Record<string, string> | undefined;
|
|
279
334
|
readonly adapters?: Record<string, string> | undefined;
|
|
280
335
|
readonly template?: string | undefined;
|
|
281
336
|
readonly renderer?: string | undefined;
|
|
@@ -285,6 +340,8 @@ interface CreateRequestOptions extends RequestCancellationOptions {
|
|
|
285
340
|
/** Modelfile `PARAMETER` instructions, e.g. `{ temperature: 0.7, stop: ['\n'] }`. */
|
|
286
341
|
readonly parameters?: Record<string, unknown> | undefined;
|
|
287
342
|
readonly messages?: readonly Message[] | undefined;
|
|
343
|
+
/** Minimum Ollama version required by the model. */
|
|
344
|
+
readonly requires?: string | undefined;
|
|
288
345
|
}
|
|
289
346
|
interface DeleteRequestOptions extends RequestCancellationOptions {
|
|
290
347
|
readonly model: string;
|
|
@@ -343,164 +400,4 @@ interface WebFetchResponse {
|
|
|
343
400
|
readonly links?: readonly string[] | undefined;
|
|
344
401
|
}
|
|
345
402
|
|
|
346
|
-
|
|
347
|
-
* Tool definition, handler, and execution types.
|
|
348
|
-
*/
|
|
349
|
-
|
|
350
|
-
interface ToolExecutionContext {
|
|
351
|
-
readonly signal?: AbortSignal | undefined;
|
|
352
|
-
}
|
|
353
|
-
type ToolHandler<TParams, TResult> = (params: TParams, context: ToolExecutionContext) => Promise<TResult> | TResult;
|
|
354
|
-
interface Tool<TParams = Record<string, unknown>, TResult = unknown> {
|
|
355
|
-
readonly name: string;
|
|
356
|
-
readonly description: string;
|
|
357
|
-
readonly schema: z.ZodType<TParams>;
|
|
358
|
-
readonly execute: ToolHandler<TParams, TResult>;
|
|
359
|
-
readonly definition: ToolDefinition;
|
|
360
|
-
/**
|
|
361
|
-
* Per-tool execution timeout in milliseconds, overriding the registry's default.
|
|
362
|
-
* Pass `0` to explicitly disable timeout enforcement for this tool.
|
|
363
|
-
*/
|
|
364
|
-
readonly timeoutMs?: number | undefined;
|
|
365
|
-
}
|
|
366
|
-
/**
|
|
367
|
-
* A `Tool` of *any* parameter shape, for heterogeneous collections — i.e. what
|
|
368
|
-
* `ToolRegistry` stores and accepts.
|
|
369
|
-
*
|
|
370
|
-
* `Tool<TParams>` is **invariant** in `TParams`, because `TParams` appears both
|
|
371
|
-
* covariantly (`schema: z.ZodType<TParams>`) and contravariantly
|
|
372
|
-
* (`execute: ToolHandler<TParams, …>`). That makes `Tool<never, unknown>` — the obvious-
|
|
373
|
-
* looking "bottom" type for a mixed collection — assignable from *nothing*: a perfectly
|
|
374
|
-
* ordinary `Tool<{ city: string }, string>` from `defineTool` is rejected by it. `any` is
|
|
375
|
-
* the standard escape hatch for exactly this case, and it is confined to this one alias:
|
|
376
|
-
* `defineTool` still infers `TParams` from the Zod schema and still type-checks `execute`
|
|
377
|
-
* against it, so tool authoring keeps full type safety. Only the registry's *storage*
|
|
378
|
-
* type is widened, and the registry never does anything with a tool's params beyond
|
|
379
|
-
* handing `schema.safeParse`'s validated output straight back to that same tool's
|
|
380
|
-
* `execute`.
|
|
381
|
-
*/
|
|
382
|
-
type AnyTool = Tool<any, unknown>;
|
|
383
|
-
interface ToolExecutionSuccess {
|
|
384
|
-
readonly toolName: string;
|
|
385
|
-
/** Echoes the originating {@link ToolCall.id}, if the call had one. */
|
|
386
|
-
readonly toolCallId?: string | undefined;
|
|
387
|
-
readonly success: true;
|
|
388
|
-
readonly result: unknown;
|
|
389
|
-
readonly outputString: string;
|
|
390
|
-
}
|
|
391
|
-
interface ToolExecutionFailure {
|
|
392
|
-
readonly toolName: string;
|
|
393
|
-
/** Echoes the originating {@link ToolCall.id}, if the call had one. */
|
|
394
|
-
readonly toolCallId?: string | undefined;
|
|
395
|
-
readonly success: false;
|
|
396
|
-
readonly error: Error;
|
|
397
|
-
readonly outputString: string;
|
|
398
|
-
}
|
|
399
|
-
type ToolExecutionResult = ToolExecutionSuccess | ToolExecutionFailure;
|
|
400
|
-
|
|
401
|
-
/**
|
|
402
|
-
* Tool registry for managing definitions and executing model tool calls.
|
|
403
|
-
*/
|
|
404
|
-
|
|
405
|
-
interface ToolRegistryOptions {
|
|
406
|
-
readonly tools?: readonly AnyTool[] | undefined;
|
|
407
|
-
readonly onError?: ((error: Error, toolCall: ToolCall) => string) | undefined;
|
|
408
|
-
/**
|
|
409
|
-
* Default per-call execution timeout in milliseconds, applied to any tool that
|
|
410
|
-
* doesn't declare its own `timeoutMs`. Undefined (the default) means no timeout is
|
|
411
|
-
* enforced, matching prior behavior. Recommended whenever tool arguments or
|
|
412
|
-
* implementations are influenced by model output you don't fully control, since an
|
|
413
|
-
* unbounded tool call can otherwise stall the entire agent loop indefinitely.
|
|
414
|
-
*
|
|
415
|
-
* Enforcement is cooperative: it races the tool's promise against a timer and
|
|
416
|
-
* reports a timeout failure, but cannot forcibly halt synchronous or non-abort-aware
|
|
417
|
-
* asynchronous work already in flight on the same thread. Tools that perform I/O
|
|
418
|
-
* should honor `ToolExecutionContext.signal` to stop promptly on timeout.
|
|
419
|
-
*/
|
|
420
|
-
readonly timeoutMs?: number | undefined;
|
|
421
|
-
/**
|
|
422
|
-
* Maximum number of tool calls executed concurrently by `executeToolCalls`.
|
|
423
|
-
* Undefined (the default) runs all calls in parallel, matching prior behavior.
|
|
424
|
-
*/
|
|
425
|
-
readonly maxConcurrency?: number | undefined;
|
|
426
|
-
/**
|
|
427
|
-
* Maximum length of a tool's `outputString` before it is truncated. Guards against a
|
|
428
|
-
* single tool call flooding the conversation history / model context (and process
|
|
429
|
-
* memory) with unbounded output. Undefined (the default) applies no limit.
|
|
430
|
-
*/
|
|
431
|
-
readonly maxOutputChars?: number | undefined;
|
|
432
|
-
}
|
|
433
|
-
declare class ToolRegistry {
|
|
434
|
-
private readonly tools;
|
|
435
|
-
private readonly onError?;
|
|
436
|
-
private readonly defaultTimeoutMs?;
|
|
437
|
-
private readonly maxConcurrency?;
|
|
438
|
-
private readonly maxOutputChars?;
|
|
439
|
-
constructor(toolsOrOptions?: readonly AnyTool[] | ToolRegistryOptions | undefined);
|
|
440
|
-
register(tool: AnyTool): this;
|
|
441
|
-
registerMany(tools: readonly AnyTool[]): this;
|
|
442
|
-
get(name: string): AnyTool | undefined;
|
|
443
|
-
definitions(): ToolDefinition[];
|
|
444
|
-
executeToolCall(toolCall: ToolCall, ctx?: ToolExecutionContext): Promise<ToolExecutionResult>;
|
|
445
|
-
private executeToolCallUninstrumented;
|
|
446
|
-
/**
|
|
447
|
-
* Executes every call in `toolCalls` and returns results in the same order, so results
|
|
448
|
-
* are always correlatable by array position regardless of `id`. Each result also echoes
|
|
449
|
-
* its call's `toolCallId` for callers who'd rather match by ID — see the {@link ToolCall}
|
|
450
|
-
* docs for how that id is produced. Runs fully in parallel (`Promise.all`) unless
|
|
451
|
-
* `maxConcurrency` was configured, in which case a bounded worker pool is used instead.
|
|
452
|
-
*/
|
|
453
|
-
executeToolCalls(toolCalls: readonly ToolCall[], ctx?: ToolExecutionContext): Promise<ToolExecutionResult[]>;
|
|
454
|
-
private runWithTimeout;
|
|
455
|
-
private truncateOutput;
|
|
456
|
-
private handleExecutionError;
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
/**
|
|
460
|
-
* SKILL.md frontmatter and skill registry types.
|
|
461
|
-
*/
|
|
462
|
-
interface SkillFrontmatter {
|
|
463
|
-
readonly name: string;
|
|
464
|
-
readonly description: string;
|
|
465
|
-
readonly 'allowed-tools'?: readonly string[] | undefined;
|
|
466
|
-
readonly [key: string]: unknown;
|
|
467
|
-
}
|
|
468
|
-
interface SkillSummary {
|
|
469
|
-
readonly name: string;
|
|
470
|
-
readonly description: string;
|
|
471
|
-
readonly path: string;
|
|
472
|
-
}
|
|
473
|
-
interface Skill extends SkillSummary {
|
|
474
|
-
readonly frontmatter: SkillFrontmatter;
|
|
475
|
-
readonly body: string;
|
|
476
|
-
readonly allowedTools?: readonly string[] | undefined;
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
/**
|
|
480
|
-
* Lightweight frontmatter parser for SKILL.md files.
|
|
481
|
-
*/
|
|
482
|
-
|
|
483
|
-
interface ParsedFrontmatter {
|
|
484
|
-
readonly frontmatter: SkillFrontmatter;
|
|
485
|
-
readonly body: string;
|
|
486
|
-
}
|
|
487
|
-
declare function parseFrontmatter(source: string, path?: string): ParsedFrontmatter;
|
|
488
|
-
|
|
489
|
-
/**
|
|
490
|
-
* Skill composition and context injection.
|
|
491
|
-
*/
|
|
492
|
-
|
|
493
|
-
interface ApplySkillOptions {
|
|
494
|
-
readonly messages: readonly Message[];
|
|
495
|
-
readonly tools?: ToolRegistry;
|
|
496
|
-
}
|
|
497
|
-
interface AppliedSkillResult {
|
|
498
|
-
readonly messages: readonly Message[];
|
|
499
|
-
readonly tools?: ToolRegistry;
|
|
500
|
-
}
|
|
501
|
-
/**
|
|
502
|
-
* Injects a skill's body into messages as a system prompt and applies allowed tool filters.
|
|
503
|
-
*/
|
|
504
|
-
declare function applySkill(skill: Skill, options: ApplySkillOptions): AppliedSkillResult;
|
|
505
|
-
|
|
506
|
-
export { type WebSearchResult as $, type AnyTool as A, type ModelDetails as B, type ChatResponse as C, type DeleteRequestOptions as D, type EmbedRequestOptions as E, type FormatOption as F, type GenerateResponse as G, type ParsedFrontmatter as H, type Role as I, type Skill as J, type SkillFrontmatter as K, type ListResponse as L, type Message as M, type SkillSummary as N, type ToolCallFunction as O, type ProgressResponse as P, type ToolExecutionContext as Q, type RequestCancellationOptions as R, type ShowRequestOptions as S, type ToolCall as T, type ToolExecutionFailure as U, type VersionResponse as V, type WebSearchRequestOptions as W, type ToolExecutionSuccess as X, type ToolFunctionDefinition as Y, type ToolProperty as Z, type ToolRegistryOptions as _, type ModelResponse as a, applySkill as a0, parseFrontmatter as a1, type ShowResponse as b, type PullRequestOptions as c, type PushRequestOptions as d, type CreateRequestOptions as e, type StatusResponse as f, type CopyRequestOptions as g, type PsResponse as h, type ChatRequestOptions as i, type GenerateRequestOptions as j, type EmbedResponse as k, type EmbeddingsRequestOptions as l, type EmbeddingsResponse as m, type WebSearchResponse as n, type WebFetchRequestOptions as o, type WebFetchResponse as p, type ToolHandler as q, type Tool as r, ToolRegistry as s, type ToolExecutionResult as t, type ModelOptions as u, type ToolDefinition as v, type AppliedSkillResult as w, type ApplySkillOptions as x, type Logprob as y, type LogprobToken as z };
|
|
403
|
+
export type { ToolParameters as A, ToolProperty as B, CreateRequestOptions as C, DeleteRequestOptions as D, EmbedRequestOptions as E, FormatOption as F, GenerateRequestOptions as G, WebSearchResult as H, ListResponse as L, Message as M, PullRequestOptions as P, RequestCancellationOptions as R, ShowRequestOptions as S, ToolDefinition as T, VersionResponse as V, WebSearchRequestOptions as W, ToolCall as a, ThinkingMetadata as b, ModelResponse as c, ShowResponse as d, ProgressResponse as e, PushRequestOptions as f, StatusResponse as g, CopyRequestOptions as h, PsResponse as i, ChatRequestOptions as j, ChatResponse as k, GenerateResponse as l, EmbedResponse as m, EmbeddingsRequestOptions as n, EmbeddingsResponse as o, WebSearchResponse as p, WebFetchRequestOptions as q, WebFetchResponse as r, ModelOptions as s, ThinkValue as t, Logprob as u, LogprobToken as v, ModelDetails as w, Role as x, ToolCallFunction as y, ToolFunctionDefinition as z };
|