@nemesis-oss/ollama-sdk 1.6.0 → 1.7.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.
- package/CHANGELOG.md +4 -1
- package/README.md +31 -0
- package/dist/generated-api.d.cts +2 -2
- package/dist/generated-api.d.ts +2 -2
- package/dist/generated-runtime.cjs.map +1 -1
- package/dist/generated-runtime.d.cts +1 -1
- package/dist/generated-runtime.d.ts +1 -1
- package/dist/generated-runtime.js.map +1 -1
- package/dist/index.cjs +132 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +20 -5
- package/dist/index.d.ts +20 -5
- package/dist/index.js +132 -6
- package/dist/index.js.map +1 -1
- package/dist/mcp-generated.d.cts +3 -3
- package/dist/mcp-generated.d.ts +3 -3
- package/dist/mcp-http.cjs +43 -4
- package/dist/mcp-http.cjs.map +1 -1
- package/dist/mcp-http.d.cts +5 -1
- package/dist/mcp-http.d.ts +5 -1
- package/dist/mcp-http.js +43 -4
- package/dist/mcp-http.js.map +1 -1
- package/dist/mcp-stdio.cjs +43 -4
- package/dist/mcp-stdio.cjs.map +1 -1
- package/dist/mcp-stdio.d.cts +5 -1
- package/dist/mcp-stdio.d.ts +5 -1
- package/dist/mcp-stdio.js +43 -4
- package/dist/mcp-stdio.js.map +1 -1
- package/dist/{runtime-IxRpUBjN.d.cts → runtime-bQ48I-RC.d.cts} +4 -2
- package/dist/{runtime-CVQkbYgF.d.ts → runtime-qwD72cpn.d.ts} +4 -2
- package/dist/skills.cjs.map +1 -1
- package/dist/skills.js.map +1 -1
- package/dist/types-CI-gM2u5.d.cts +139 -0
- package/dist/types-CI-gM2u5.d.ts +139 -0
- package/package.json +2 -1
- package/dist/types-MOsWXEE7.d.cts +0 -66
- package/dist/types-MOsWXEE7.d.ts +0 -66
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/errors.ts","../src/utils.ts","../src/streaming/ndjson.ts","../src/generated/models/ToolCall.schema.ts","../src/generated/models/ChatMessage.schema.ts","../src/generated/models/ModelOptions.schema.ts","../src/generated/models/ThinkValue.schema.ts","../src/generated/models/ToolDefinition.schema.ts","../src/generated/models/ChatRequest.schema.ts","../src/generated/models/GenerateRequest.schema.ts","../src/generated/models/EmbedRequest.schema.ts","../src/generated/models/CreateRequest.schema.ts","../src/generated/models/CopyRequest.schema.ts","../src/generated/models/DeleteRequest.schema.ts","../src/generated/models/PullRequest.schema.ts","../src/generated/models/PushRequest.schema.ts","../src/generated/models/ShowRequest.schema.ts","../src/generated/runtime/schema-registry.ts","../src/generated/runtime/runtime.ts"],"names":["z"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BO,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;AAwHO,IAAM,4BAAA,GAAN,cAA2C,iBAAA,CAAkB;AAAA,EACzD,WAAA;AAAA,EACA,MAAA;AAAA,EACT,WAAA,CACE,SACA,OAAA,EAIA;AACA,IAAA,KAAA,CAAM,OAAA,EAAS,EAAE,GAAG,OAAA,EAAS,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,EAAa,GAAA,CAAI,SAAA,CAAU,WAAW,CAAA,iCAAA;AAAA,OACxC;AAAA,IACF;AACA,IAAA,OAAO,iBAAA,CAAqB,SAAS,IAAI,CAAA;AAAA,EAC3C;AACF","file":"generated-runtime.js","sourcesContent":["/**\n * Structured, typed error hierarchy for OllamaClient.\n */\n\nimport type { z } from 'zod';\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\n/**\n * Thrown by `OllamaRuntime.invoke` when `validateRequests: true` is set and\n * the request body fails Zod validation against the operation's registered\n * schema. See ADR 0020 (runtime Zod validation).\n *\n * The error carries the original Zod issues so callers can inspect which\n * fields failed. No HTTP request is made when this error is thrown.\n */\nexport class OllamaRequestValidationError extends OllamaClientError {\n readonly operationId: string;\n readonly issues: readonly z.ZodIssue[];\n constructor(\n message: string,\n options: Omit<OllamaClientErrorOptions, 'code'> & {\n operationId: string;\n issues: readonly z.ZodIssue[];\n },\n ) {\n super(message, { ...options, code: 'request_validation_error', retryable: false });\n this.operationId = options.operationId;\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 * Cross-runtime helpers with no Node.js API dependency, so they stay safe to import from\n * the core client bundle (see ADR 0006 — Edge Runtime CI).\n */\n\n/**\n * Encodes an image to a base64 string, matching the wire format Ollama's `/api/chat` and\n * `/api/generate` `images` arrays expect.\n *\n * - A `string` is assumed to already be base64-encoded and is returned unchanged.\n * - A `Uint8Array` is base64-encoded using whichever universal primitive the runtime\n * exposes: `Buffer` on Node.js, `btoa` on browsers/Edge runtimes. Chunked so it doesn't\n * blow the engine's max call-stack/argument-count limits on large images.\n */\nexport async function encodeImage(image: Uint8Array | string): Promise<string> {\n if (typeof image === 'string') return image;\n\n const bufferCtor = (\n globalThis as { Buffer?: { from(data: Uint8Array): { toString(encoding: string): string } } }\n ).Buffer;\n if (bufferCtor !== undefined) return bufferCtor.from(image).toString('base64');\n\n const CHUNK_SIZE = 0x8000;\n let binary = '';\n for (let i = 0; i < image.length; i += CHUNK_SIZE) {\n binary += String.fromCharCode(...image.subarray(i, i + CHUNK_SIZE));\n }\n return btoa(binary);\n}\n\nasync function encodeImages(\n images: readonly (string | Uint8Array)[] | undefined,\n): Promise<readonly string[] | undefined> {\n if (images === undefined) return undefined;\n return Promise.all(images.map((image) => encodeImage(image)));\n}\n\n/**\n * Returns `req` unchanged if `req.images` has no `Uint8Array` entries (the common case),\n * otherwise a shallow copy with `images` base64-encoded. Keeps `chat`/`generate` request\n * bodies wire-compatible without requiring callers to pre-encode raw image bytes.\n */\nexport async function withEncodedImages<\n T extends { images?: readonly (string | Uint8Array)[] | undefined },\n>(req: T): Promise<T> {\n if (!req.images?.some((image) => image instanceof Uint8Array)) return req;\n return { ...req, images: await encodeImages(req.images) };\n}\n\n/**\n * Applies {@link withEncodedImages} to each message's `images` array. Returns `messages`\n * unchanged (same reference) if no message carries a `Uint8Array` image.\n */\nexport async function withEncodedMessageImages<\n T extends { images?: readonly (string | Uint8Array)[] | undefined },\n>(messages: readonly T[]): Promise<readonly T[]> {\n if (!messages.some((message) => message.images?.some((image) => image instanceof Uint8Array)))\n return messages;\n return Promise.all(messages.map((message) => withEncodedImages(message)));\n}\n\n// ─── Disposable helpers (TS 5.2+ `using` declarations) ──────────────────\n//\n// These wrappers turn cleanup operations into `Disposable` / `AsyncDisposable`\n// values so callers can use `using` / `await using` declarations instead of\n// try/finally blocks. This eliminates the \"forgot to clean up in the finally\n// block\" bug class for timer, reader, and span lifecycles.\n\n/** Wraps a `setTimeout` handle so `clearTimeout` runs at scope exit. */\nexport function disposableTimer(timer: ReturnType<typeof setTimeout>): Disposable {\n return {\n [Symbol.dispose]() {\n clearTimeout(timer);\n },\n };\n}\n\n/** Wraps a `ReadableStreamDefaultReader` so `cancel()` + `releaseLock()` run at scope exit. */\nexport function disposableReader<T>(reader: ReadableStreamDefaultReader<T>): AsyncDisposable {\n return {\n async [Symbol.asyncDispose]() {\n try {\n await reader.cancel();\n } catch {\n /* stream may already be closed */\n }\n reader.releaseLock();\n },\n };\n}\n\n/** Wraps an OpenTelemetry span so `span.end()` runs at scope exit. */\nexport function disposableSpan(span: { end(): void }): Disposable {\n return {\n [Symbol.dispose]() {\n span.end();\n },\n };\n}\n","/**\n * NDJSON (newline-delimited JSON) stream reader for native fetch Response bodies.\n */\n\nimport { OllamaGenericClientError } from '../errors.js';\nimport { disposableReader } from '../utils.js';\n\n/**\n * Parses a byte stream from fetch body into an async generator of typed JSON chunks.\n */\nexport async function* parseNdjsonStream<T>(\n stream: ReadableStream<Uint8Array>,\n): AsyncGenerator<T, void, undefined> {\n const reader = stream.getReader();\n const decoder = new TextDecoder();\n let buffer = '';\n await using _reader = disposableReader(reader);\n\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n\n buffer += decoder.decode(value, { stream: true });\n const lines = buffer.split('\\n');\n // Keep the last partial line in buffer\n buffer = lines.pop() ?? '';\n\n for (const line of lines) {\n const trimmed = line.trim();\n if (!trimmed) continue;\n try {\n yield JSON.parse(trimmed) as T;\n } catch (err) {\n throw new OllamaGenericClientError(`Failed to parse stream JSON chunk: ${trimmed}`, {\n cause: err,\n });\n }\n }\n }\n\n if (buffer.trim()) {\n yield JSON.parse(buffer.trim()) as T;\n }\n // reader.cancel() + reader.releaseLock() called automatically via `await using _reader`\n}\n","// AUTO-GENERATED by `npm run contract:generate`. DO NOT EDIT.\n// Source: contracts/ir/ollama.ir.json (canonical Ollama IR).\n// Pairs with ./<name>.ts (the TypeScript interface).\n\nimport { z } from 'zod';\n\nexport const ToolCallSchema = z.object({\n function: z\n .object({\n name: z.string(),\n description: z.string().optional(),\n arguments: z.object({}).optional(),\n })\n .optional(),\n});\n","// AUTO-GENERATED by `npm run contract:generate`. DO NOT EDIT.\n// Source: contracts/ir/ollama.ir.json (canonical Ollama IR).\n// Pairs with ./<name>.ts (the TypeScript interface).\n\nimport { z } from 'zod';\nimport { ToolCallSchema } from './ToolCall.schema.js';\n\nexport const ChatMessageSchema = z.object({\n role: z.enum(['system', 'user', 'assistant', 'tool']),\n content: z.string(),\n images: z.array(z.string()).optional(),\n tool_calls: z.array(ToolCallSchema).optional(),\n});\n","// AUTO-GENERATED by `npm run contract:generate`. DO NOT EDIT.\n// Source: contracts/ir/ollama.ir.json (canonical Ollama IR).\n// Pairs with ./<name>.ts (the TypeScript interface).\n\nimport { z } from 'zod';\n\n/** Runtime options that control text generation */\nexport const ModelOptionsSchema = z\n .object({\n seed: z.number().optional(),\n temperature: z.number().optional(),\n top_k: z.number().optional(),\n top_p: z.number().optional(),\n min_p: z.number().optional(),\n stop: z.union([z.string(), z.array(z.string())]).optional(),\n num_ctx: z.number().optional(),\n num_predict: z.number().optional(),\n })\n .catchall(z.unknown());\n","// AUTO-GENERATED by `npm run contract:generate`. DO NOT EDIT.\n// Source: contracts/ir/ollama.ir.json (canonical Ollama IR).\n// Pairs with ./<name>.ts (the TypeScript interface).\n\nimport { z } from 'zod';\n\n/** Controls a model's thinking output. Use `/api/show` to discover the supported values and default for the selected model. `true` requests thinking, `false` requests no thinking output, and `null` uses the model default. String values are model-defined; supported names must match `/api/show` exactly. Numbers are not supported. */\nexport const ThinkValueSchema = z.union([z.boolean(), z.string(), z.null()]);\n","// AUTO-GENERATED by `npm run contract:generate`. DO NOT EDIT.\n// Source: contracts/ir/ollama.ir.json (canonical Ollama IR).\n// Pairs with ./<name>.ts (the TypeScript interface).\n\nimport { z } from 'zod';\n\nexport const ToolDefinitionSchema = z.object({\n type: z.enum(['function']),\n function: z.object({\n name: z.string(),\n description: z.string().optional(),\n parameters: z.object({}),\n }),\n});\n","// AUTO-GENERATED by `npm run contract:generate`. DO NOT EDIT.\n// Source: contracts/ir/ollama.ir.json (canonical Ollama IR).\n// Pairs with ./<name>.ts (the TypeScript interface).\n\nimport { z } from 'zod';\nimport { ChatMessageSchema } from './ChatMessage.schema.js';\nimport { ModelOptionsSchema } from './ModelOptions.schema.js';\nimport { ThinkValueSchema } from './ThinkValue.schema.js';\nimport { ToolDefinitionSchema } from './ToolDefinition.schema.js';\n\nexport const ChatRequestSchema = z.object({\n model: z.string(),\n messages: z.array(ChatMessageSchema),\n tools: z.array(ToolDefinitionSchema).optional(),\n format: z.union([z.enum(['json']), z.object({})]).optional(),\n options: ModelOptionsSchema.optional(),\n stream: z.boolean().optional(),\n think: ThinkValueSchema.optional(),\n keep_alive: z.union([z.string(), z.number()]).optional(),\n logprobs: z.boolean().optional(),\n top_logprobs: z.number().optional(),\n});\n","// AUTO-GENERATED by `npm run contract:generate`. DO NOT EDIT.\n// Source: contracts/ir/ollama.ir.json (canonical Ollama IR).\n// Pairs with ./<name>.ts (the TypeScript interface).\n\nimport { z } from 'zod';\nimport { ModelOptionsSchema } from './ModelOptions.schema.js';\nimport { ThinkValueSchema } from './ThinkValue.schema.js';\n\nexport const GenerateRequestSchema = z.object({\n model: z.string(),\n prompt: z.string().optional(),\n suffix: z.string().optional(),\n images: z.array(z.string()).optional(),\n format: z.union([z.string(), z.object({})]).optional(),\n system: z.string().optional(),\n stream: z.boolean().optional(),\n think: ThinkValueSchema.optional(),\n raw: z.boolean().optional(),\n keep_alive: z.union([z.string(), z.number()]).optional(),\n options: ModelOptionsSchema.optional(),\n logprobs: z.boolean().optional(),\n top_logprobs: z.number().optional(),\n});\n","// AUTO-GENERATED by `npm run contract:generate`. DO NOT EDIT.\n// Source: contracts/ir/ollama.ir.json (canonical Ollama IR).\n// Pairs with ./<name>.ts (the TypeScript interface).\n\nimport { z } from 'zod';\nimport { ModelOptionsSchema } from './ModelOptions.schema.js';\n\nexport const EmbedRequestSchema = z.object({\n model: z.string(),\n input: z.union([z.string(), z.array(z.string())]),\n truncate: z.boolean().optional(),\n dimensions: z.number().optional(),\n keep_alive: z.string().optional(),\n options: ModelOptionsSchema.optional(),\n});\n","// AUTO-GENERATED by `npm run contract:generate`. DO NOT EDIT.\n// Source: contracts/ir/ollama.ir.json (canonical Ollama IR).\n// Pairs with ./<name>.ts (the TypeScript interface).\n\nimport { z } from 'zod';\nimport { ChatMessageSchema } from './ChatMessage.schema.js';\n\nexport const CreateRequestSchema = z.object({\n model: z.string(),\n from: z.string().optional(),\n template: z.string().optional(),\n renderer: z.string().optional(),\n parser: z.string().optional(),\n files: z.object({}).catchall(z.string()).optional(),\n draft_files: z.object({}).catchall(z.string()).optional(),\n license: z.union([z.string(), z.array(z.string())]).optional(),\n system: z.string().optional(),\n parameters: z.object({}).optional(),\n messages: z.array(ChatMessageSchema).optional(),\n quantize: z.string().optional(),\n draft_quantize: z.string().optional(),\n requires: z.string().optional(),\n stream: z.boolean().optional(),\n});\n","// AUTO-GENERATED by `npm run contract:generate`. DO NOT EDIT.\n// Source: contracts/ir/ollama.ir.json (canonical Ollama IR).\n// Pairs with ./<name>.ts (the TypeScript interface).\n\nimport { z } from 'zod';\n\nexport const CopyRequestSchema = z.object({\n source: z.string(),\n destination: z.string(),\n});\n","// AUTO-GENERATED by `npm run contract:generate`. DO NOT EDIT.\n// Source: contracts/ir/ollama.ir.json (canonical Ollama IR).\n// Pairs with ./<name>.ts (the TypeScript interface).\n\nimport { z } from 'zod';\n\nexport const DeleteRequestSchema = z.object({\n model: z.string(),\n});\n","// AUTO-GENERATED by `npm run contract:generate`. DO NOT EDIT.\n// Source: contracts/ir/ollama.ir.json (canonical Ollama IR).\n// Pairs with ./<name>.ts (the TypeScript interface).\n\nimport { z } from 'zod';\n\nexport const PullRequestSchema = z.object({\n model: z.string(),\n insecure: z.boolean().optional(),\n stream: z.boolean().optional(),\n});\n","// AUTO-GENERATED by `npm run contract:generate`. DO NOT EDIT.\n// Source: contracts/ir/ollama.ir.json (canonical Ollama IR).\n// Pairs with ./<name>.ts (the TypeScript interface).\n\nimport { z } from 'zod';\n\nexport const PushRequestSchema = z.object({\n model: z.string(),\n insecure: z.boolean().optional(),\n stream: z.boolean().optional(),\n});\n","// AUTO-GENERATED by `npm run contract:generate`. DO NOT EDIT.\n// Source: contracts/ir/ollama.ir.json (canonical Ollama IR).\n// Pairs with ./<name>.ts (the TypeScript interface).\n\nimport { z } from 'zod';\n\nexport const ShowRequestSchema = z.object({\n model: z.string(),\n verbose: z.boolean().optional(),\n});\n","/**\n * Schema registry — maps operationId → request/response Zod schemas.\n *\n * The runtime consults this registry to validate request bodies before\n * sending and response payloads after receiving. This is the runtime\n * enforcement layer described in ADR 0019 (Zod schema generation) and\n * ADR 0020 (runtime validation wiring).\n *\n * The registry is hand-written (not generated) because:\n * 1. Not every operation has a request schema (GET/HEAD have no body).\n * 2. Not every operation has a response schema (DELETE returns 204).\n * 3. The map is small (21 operations) and changes only when overlays\n * add new operations — at which point the generator should remind\n * the maintainer to update this file via the contract validator.\n *\n * When `validateRequests: true` is set on `OllamaRuntime` and an\n * operation has no registered request schema, the runtime skips\n * validation (it doesn't fail — the contract just doesn't have a\n * schema for that operation yet).\n */\nimport type { z } from 'zod';\nimport { ChatRequestSchema } from '../models/ChatRequest.schema.js';\nimport { GenerateRequestSchema } from '../models/GenerateRequest.schema.js';\nimport { EmbedRequestSchema } from '../models/EmbedRequest.schema.js';\nimport { CreateRequestSchema } from '../models/CreateRequest.schema.js';\nimport { CopyRequestSchema } from '../models/CopyRequest.schema.js';\nimport { DeleteRequestSchema } from '../models/DeleteRequest.schema.js';\nimport { PullRequestSchema } from '../models/PullRequest.schema.js';\nimport { PushRequestSchema } from '../models/PushRequest.schema.js';\nimport { ShowRequestSchema } from '../models/ShowRequest.schema.js';\n\n/**\n * Map from operationId → request schema. Response schemas are intentionally\n * NOT registered here — see ADR 0020 for the rationale (response validation\n * would break on legitimate forward-compat extensions to the wire format).\n */\nexport const requestSchemas: Readonly<Record<string, z.ZodType>> = {\n chat: ChatRequestSchema,\n generate: GenerateRequestSchema,\n embed: EmbedRequestSchema,\n create: CreateRequestSchema,\n copy: CopyRequestSchema,\n delete: DeleteRequestSchema,\n pull: PullRequestSchema,\n push: PushRequestSchema,\n show: ShowRequestSchema,\n // Operations without a registered request schema (blobs, ps, tags,\n // version, systemOne, openai*, anthropic*) skip validation. This is\n // deliberate — the OpenAPI spec doesn't define request bodies for\n // GET/HEAD operations, and the compat-surface request schemas (OpenAI,\n // Anthropic) are richer than what the IR currently models.\n};\n\n/** Look up a request schema by operationId. Returns `undefined` if no schema exists. */\nexport function getRequestSchema(operationId: string): z.ZodType | undefined {\n return requestSchemas[operationId];\n}\n","/**\n * OllamaRuntime — the runtime seam generated API classes delegate to.\n *\n * This is the only hand-written file in `src/generated/runtime/`. Every\n * generated method in `src/generated/api/*-api.ts` ends with:\n *\n * ```ts\n * return this.runtime.invoke({ operation: chatOp, body: request });\n * ```\n *\n * The runtime is responsible for:\n * - Method/path resolution (from {@link OperationDefinition})\n * - Streaming default application (when the request doesn't set `stream`)\n * - Environment guard (rejecting cloud calls for local-only operations)\n * - Version constraint guard (failing fast when the server is too old)\n * - Delegating to the existing {@link HttpClient} for transport, retry,\n * telemetry, NDJSON/SSE parsing\n *\n * It is intentionally a thin adapter — the existing transport, streaming,\n * middleware, and error-mapping layers are preserved verbatim. This file\n * only adds the contract-aware glue between generated API classes and the\n * existing HttpClient.\n */\nimport { HttpClient, type HttpRequestOptions } from '../../transport/http.js';\nimport { parseNdjsonStream } from '../../streaming/ndjson.js';\nimport { OllamaGenericClientError, OllamaRequestValidationError } from '../../errors.js';\nimport type { OperationDefinition, InvokeRequest } from './operation-definition.js';\nimport { getRequestSchema } from './schema-registry.js';\n\n/** Constructor options for {@link OllamaRuntime}. */\nexport interface OllamaRuntimeOptions {\n readonly http: HttpClient;\n /**\n * Whether this runtime is targeting a local Ollama instance. Defaults to\n * `true`. When `false`, operations marked `environment.cloud === false`\n * (i.e. local-only like `/v1/systemone`) are rejected at request time.\n */\n readonly localMode?: boolean;\n /**\n * Server version, if known (typically from a prior `/api/version` call).\n * When set, operations with `constraints.minOllamaVersion` are checked\n * against this value at request time.\n */\n readonly serverVersion?: string;\n /**\n * When `true`, the runtime validates every request body against the\n * generated Zod schema before sending it. Defaults to `false` — opt-in.\n *\n * Validation behavior:\n * - If the operation has a registered request schema (see\n * {@link schema-registry.ts}), the body is parsed via `safeParse`.\n * - On parse failure, throws `OllamaRequestValidationError` with the\n * Zod issues attached. No HTTP request is made.\n * - On parse success, the parsed (and stripped of unknown fields) body\n * is sent — this means callers can't accidentally send extra fields\n * that the contract doesn't allow.\n * - If the operation has NO registered schema (e.g. GET endpoints,\n * `/v1/systemone`, OpenAI/Anthropic compat surfaces), validation is\n * skipped silently.\n *\n * Response validation is intentionally NOT enabled — see ADR 0020 for\n * the rationale (forward-compat with wire-format extensions).\n */\n readonly validateRequests?: boolean;\n}\n\nfunction compareVersions(a: string, b: string): number {\n const pa = a.split('.').map((s) => Number.parseInt(s, 10) ?? 0);\n const pb = b.split('.').map((s) => Number.parseInt(s, 10) ?? 0);\n for (let i = 0; i < Math.max(pa.length, pb.length); i += 1) {\n const va = pa[i] ?? 0;\n const vb = pb[i] ?? 0;\n if (va !== vb) return va - vb;\n }\n return 0;\n}\n\n/**\n * Apply environment + version guards before delegating to HttpClient.\n *\n * Throws {@link OllamaGenericClientError} when:\n * - The operation is local-only and the runtime is in cloud mode.\n * - The operation has `constraints.minOllamaVersion` and the server is older.\n */\nfunction assertOperationAllowed(\n operation: OperationDefinition,\n options: OllamaRuntimeOptions,\n): void {\n const localMode = options.localMode ?? true;\n if (!localMode && !operation.environment.cloud) {\n throw new OllamaGenericClientError(\n `Operation ${operation.operationId} (${operation.method} ${operation.path}) ` +\n `is local-only and not supported in cloud mode.`,\n );\n }\n if (\n operation.constraints?.minOllamaVersion &&\n options.serverVersion &&\n compareVersions(options.serverVersion, operation.constraints.minOllamaVersion) < 0\n ) {\n throw new OllamaGenericClientError(\n `Operation ${operation.operationId} (${operation.method} ${operation.path}) ` +\n `requires Ollama >= ${operation.constraints.minOllamaVersion} ` +\n `(server reports ${options.serverVersion}).`,\n );\n }\n}\n\n/**\n * Decide whether the request should stream. If the request body explicitly\n * sets `stream`, that wins. Otherwise the operation's `streamingDefault`\n * from the contract is used.\n */\nfunction shouldStream(req: InvokeRequest): boolean {\n if (req.body && typeof req.body === 'object' && 'stream' in req.body) {\n const explicit = (req.body as { stream?: unknown }).stream;\n if (typeof explicit === 'boolean') return explicit;\n }\n return Boolean(req.streamingDefault ?? req.operation.transport.streamingDefault);\n}\n\n/**\n * Apply the streaming default to the request body if needed.\n *\n * If the operation streams by default and the body doesn't set `stream`,\n * add `stream: true`. The user can always override by setting `stream`\n * explicitly on the request.\n */\nfunction buildBody(req: InvokeRequest): unknown {\n if (req.body === undefined) return undefined;\n if (typeof req.body !== 'object' || req.body === null) return req.body;\n const body = req.body as Record<string, unknown>;\n if (\n req.operation.transport.streaming &&\n req.operation.transport.streamingDefault &&\n body.stream === undefined\n ) {\n return { ...body, stream: true };\n }\n return body;\n}\n\n/** The runtime seam. */\nexport class OllamaRuntime {\n constructor(private readonly options: OllamaRuntimeOptions) {}\n\n /**\n * Invoke an operation. Called by every generated API method.\n *\n * Returns a `Promise<T>` for non-streaming operations, or an\n * `AsyncGenerator<T>` for streaming operations. The generated API\n * class's overloads pick the right return type at compile time.\n */\n async invoke<T = unknown>(req: InvokeRequest): Promise<T> {\n assertOperationAllowed(req.operation, this.options);\n let body = buildBody(req);\n\n // Wave 10 (ADR 0020): runtime Zod validation. Opt-in via\n // `validateRequests: true` on the runtime constructor. Throws\n // `OllamaRequestValidationError` BEFORE any HTTP request is made\n // when the body fails validation. The validated (and stripped)\n // body replaces the original so unknown fields can't leak through.\n if (this.options.validateRequests === true && body !== undefined) {\n const schema = getRequestSchema(req.operation.operationId);\n if (schema) {\n const result = schema.safeParse(body);\n if (!result.success) {\n throw new OllamaRequestValidationError(\n `Request validation failed for operation \"${req.operation.operationId}\" ` +\n `(${req.operation.method} ${req.operation.path}): ` +\n result.error.issues\n .map((i) => `${i.path.join('.') || '<root>'}: ${i.message}`)\n .join('; '),\n {\n operationId: req.operation.operationId,\n issues: result.error.issues,\n request: { method: req.operation.method, url: req.operation.path },\n },\n );\n }\n body = result.data;\n }\n }\n\n const streaming = shouldStream(req);\n\n // The HttpClient expects the narrow method union 'GET' | 'POST' |\n // 'DELETE' | 'HEAD' | undefined — cast through `as` because our\n // OperationDefinition.method is the wider HttpMethod type.\n const httpReq: HttpRequestOptions = {\n path: req.operation.path,\n method: req.operation.method as 'GET' | 'POST' | 'DELETE' | 'HEAD',\n ...(body !== undefined ? { body } : {}),\n ...(req.signal !== undefined ? { signal: req.signal } : {}),\n // For streaming calls, request the raw Response so we can pipe it\n // through parseNdjsonStream directly. This inherits middleware,\n // retry, telemetry, and error-mapping from HttpClient — the\n // previous Wave 3 implementation bypassed them with a direct\n // `fetch()` call.\n ...(streaming ? { raw: true } : {}),\n };\n\n if (!streaming) {\n return (await this.options.http.request<T>(httpReq)) as T;\n }\n\n // Streaming: HttpClient returns the raw Response (via the `raw: true`\n // option) so we can read its body as an NDJSON stream.\n const response = await this.options.http.request<Response>(httpReq);\n if (!response.body) {\n throw new OllamaGenericClientError(\n `Operation ${req.operation.operationId}: streaming response had no body.`,\n );\n }\n return parseNdjsonStream<T>(response.body) as unknown as T;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/errors.ts","../src/utils.ts","../src/streaming/ndjson.ts","../src/generated/models/ToolCall.schema.ts","../src/generated/models/ChatMessage.schema.ts","../src/generated/models/ModelOptions.schema.ts","../src/generated/models/ThinkValue.schema.ts","../src/generated/models/ToolDefinition.schema.ts","../src/generated/models/ChatRequest.schema.ts","../src/generated/models/GenerateRequest.schema.ts","../src/generated/models/EmbedRequest.schema.ts","../src/generated/models/CreateRequest.schema.ts","../src/generated/models/CopyRequest.schema.ts","../src/generated/models/DeleteRequest.schema.ts","../src/generated/models/PullRequest.schema.ts","../src/generated/models/PushRequest.schema.ts","../src/generated/models/ShowRequest.schema.ts","../src/generated/runtime/schema-registry.ts","../src/generated/runtime/runtime.ts"],"names":["z"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BO,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,IAA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AE,MAAA,EAAQ,GAAA,CAAI,MAAA,EAAO,GAAI,EAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAMzD,GAAI,SAAA,GAAY,EAAE,GAAA,EAAK,IAAA,KAAS;AAAC,KACnC;AAEA,IAAA,IAAI,CAAC,SAAA,EAAW;AACd,MAAA,OAAQ,MAAM,IAAA,CAAK,OAAA,CAAQ,IAAA,CAAK,QAAW,OAAO,CAAA;AAAA,IACpD;AAIA,IAAA,MAAM,WAAW,MAAM,IAAA,CAAK,OAAA,CAAQ,IAAA,CAAK,QAAkB,OAAO,CAAA;AAClE,IAAA,IAAI,CAAC,SAAS,IAAA,EAAM;AAClB,MAAA,MAAM,IAAI,wBAAA;AAAA,QACR,CAAA,UAAA,EAAa,GAAA,CAAI,SAAA,CAAU,WAAW,CAAA,iCAAA;AAAA,OACxC;AAAA,IACF;AACA,IAAA,OAAO,iBAAA,CAAqB,SAAS,IAAI,CAAA;AAAA,EAC3C;AACF","file":"generated-runtime.js","sourcesContent":["/**\n * Structured, typed error hierarchy for OllamaClient.\n */\n\nimport type { z } from 'zod';\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\n/**\n * Thrown by `OllamaRuntime.invoke` when `validateRequests: true` is set and\n * the request body fails Zod validation against the operation's registered\n * schema. See ADR 0020 (runtime Zod validation).\n *\n * The error carries the original Zod issues so callers can inspect which\n * fields failed. No HTTP request is made when this error is thrown.\n */\nexport class OllamaRequestValidationError extends OllamaClientError {\n readonly operationId: string;\n readonly issues: readonly z.ZodIssue[];\n constructor(\n message: string,\n options: Omit<OllamaClientErrorOptions, 'code'> & {\n operationId: string;\n issues: readonly z.ZodIssue[];\n },\n ) {\n super(message, { ...options, code: 'request_validation_error', retryable: false });\n this.operationId = options.operationId;\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:\n | 'listTools'\n | 'callTool'\n | 'tools/call'\n | 'tasks/get'\n | 'tasks/result'\n | 'tasks/cancel';\n readonly toolName?: string | undefined;\n readonly issues?: unknown;\n constructor(\n message: string,\n options: Omit<OllamaClientErrorOptions, 'code'> & {\n mcpMethod:\n | 'listTools'\n | 'callTool'\n | 'tools/call'\n | 'tasks/get'\n | 'tasks/result'\n | 'tasks/cancel';\n toolName?: string | undefined;\n issues?: unknown;\n },\n ) {\n super(message, { ...options, code: 'mcp_error', retryable: options.retryable ?? false });\n this.mcpMethod = options.mcpMethod;\n this.toolName = options.toolName;\n this.issues = options.issues;\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 * Cross-runtime helpers with no Node.js API dependency, so they stay safe to import from\n * the core client bundle (see ADR 0006 — Edge Runtime CI).\n */\n\n/**\n * Encodes an image to a base64 string, matching the wire format Ollama's `/api/chat` and\n * `/api/generate` `images` arrays expect.\n *\n * - A `string` is assumed to already be base64-encoded and is returned unchanged.\n * - A `Uint8Array` is base64-encoded using whichever universal primitive the runtime\n * exposes: `Buffer` on Node.js, `btoa` on browsers/Edge runtimes. Chunked so it doesn't\n * blow the engine's max call-stack/argument-count limits on large images.\n */\nexport async function encodeImage(image: Uint8Array | string): Promise<string> {\n if (typeof image === 'string') return image;\n\n const bufferCtor = (\n globalThis as { Buffer?: { from(data: Uint8Array): { toString(encoding: string): string } } }\n ).Buffer;\n if (bufferCtor !== undefined) return bufferCtor.from(image).toString('base64');\n\n const CHUNK_SIZE = 0x8000;\n let binary = '';\n for (let i = 0; i < image.length; i += CHUNK_SIZE) {\n binary += String.fromCharCode(...image.subarray(i, i + CHUNK_SIZE));\n }\n return btoa(binary);\n}\n\nasync function encodeImages(\n images: readonly (string | Uint8Array)[] | undefined,\n): Promise<readonly string[] | undefined> {\n if (images === undefined) return undefined;\n return Promise.all(images.map((image) => encodeImage(image)));\n}\n\n/**\n * Returns `req` unchanged if `req.images` has no `Uint8Array` entries (the common case),\n * otherwise a shallow copy with `images` base64-encoded. Keeps `chat`/`generate` request\n * bodies wire-compatible without requiring callers to pre-encode raw image bytes.\n */\nexport async function withEncodedImages<\n T extends { images?: readonly (string | Uint8Array)[] | undefined },\n>(req: T): Promise<T> {\n if (!req.images?.some((image) => image instanceof Uint8Array)) return req;\n return { ...req, images: await encodeImages(req.images) };\n}\n\n/**\n * Applies {@link withEncodedImages} to each message's `images` array. Returns `messages`\n * unchanged (same reference) if no message carries a `Uint8Array` image.\n */\nexport async function withEncodedMessageImages<\n T extends { images?: readonly (string | Uint8Array)[] | undefined },\n>(messages: readonly T[]): Promise<readonly T[]> {\n if (!messages.some((message) => message.images?.some((image) => image instanceof Uint8Array)))\n return messages;\n return Promise.all(messages.map((message) => withEncodedImages(message)));\n}\n\n// ─── Disposable helpers (TS 5.2+ `using` declarations) ──────────────────\n//\n// These wrappers turn cleanup operations into `Disposable` / `AsyncDisposable`\n// values so callers can use `using` / `await using` declarations instead of\n// try/finally blocks. This eliminates the \"forgot to clean up in the finally\n// block\" bug class for timer, reader, and span lifecycles.\n\n/** Wraps a `setTimeout` handle so `clearTimeout` runs at scope exit. */\nexport function disposableTimer(timer: ReturnType<typeof setTimeout>): Disposable {\n return {\n [Symbol.dispose]() {\n clearTimeout(timer);\n },\n };\n}\n\n/** Wraps a `ReadableStreamDefaultReader` so `cancel()` + `releaseLock()` run at scope exit. */\nexport function disposableReader<T>(reader: ReadableStreamDefaultReader<T>): AsyncDisposable {\n return {\n async [Symbol.asyncDispose]() {\n try {\n await reader.cancel();\n } catch {\n /* stream may already be closed */\n }\n reader.releaseLock();\n },\n };\n}\n\n/** Wraps an OpenTelemetry span so `span.end()` runs at scope exit. */\nexport function disposableSpan(span: { end(): void }): Disposable {\n return {\n [Symbol.dispose]() {\n span.end();\n },\n };\n}\n","/**\n * NDJSON (newline-delimited JSON) stream reader for native fetch Response bodies.\n */\n\nimport { OllamaGenericClientError } from '../errors.js';\nimport { disposableReader } from '../utils.js';\n\n/**\n * Parses a byte stream from fetch body into an async generator of typed JSON chunks.\n */\nexport async function* parseNdjsonStream<T>(\n stream: ReadableStream<Uint8Array>,\n): AsyncGenerator<T, void, undefined> {\n const reader = stream.getReader();\n const decoder = new TextDecoder();\n let buffer = '';\n await using _reader = disposableReader(reader);\n\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n\n buffer += decoder.decode(value, { stream: true });\n const lines = buffer.split('\\n');\n // Keep the last partial line in buffer\n buffer = lines.pop() ?? '';\n\n for (const line of lines) {\n const trimmed = line.trim();\n if (!trimmed) continue;\n try {\n yield JSON.parse(trimmed) as T;\n } catch (err) {\n throw new OllamaGenericClientError(`Failed to parse stream JSON chunk: ${trimmed}`, {\n cause: err,\n });\n }\n }\n }\n\n if (buffer.trim()) {\n yield JSON.parse(buffer.trim()) as T;\n }\n // reader.cancel() + reader.releaseLock() called automatically via `await using _reader`\n}\n","// AUTO-GENERATED by `npm run contract:generate`. DO NOT EDIT.\n// Source: contracts/ir/ollama.ir.json (canonical Ollama IR).\n// Pairs with ./<name>.ts (the TypeScript interface).\n\nimport { z } from 'zod';\n\nexport const ToolCallSchema = z.object({\n function: z\n .object({\n name: z.string(),\n description: z.string().optional(),\n arguments: z.object({}).optional(),\n })\n .optional(),\n});\n","// AUTO-GENERATED by `npm run contract:generate`. DO NOT EDIT.\n// Source: contracts/ir/ollama.ir.json (canonical Ollama IR).\n// Pairs with ./<name>.ts (the TypeScript interface).\n\nimport { z } from 'zod';\nimport { ToolCallSchema } from './ToolCall.schema.js';\n\nexport const ChatMessageSchema = z.object({\n role: z.enum(['system', 'user', 'assistant', 'tool']),\n content: z.string(),\n images: z.array(z.string()).optional(),\n tool_calls: z.array(ToolCallSchema).optional(),\n});\n","// AUTO-GENERATED by `npm run contract:generate`. DO NOT EDIT.\n// Source: contracts/ir/ollama.ir.json (canonical Ollama IR).\n// Pairs with ./<name>.ts (the TypeScript interface).\n\nimport { z } from 'zod';\n\n/** Runtime options that control text generation */\nexport const ModelOptionsSchema = z\n .object({\n seed: z.number().optional(),\n temperature: z.number().optional(),\n top_k: z.number().optional(),\n top_p: z.number().optional(),\n min_p: z.number().optional(),\n stop: z.union([z.string(), z.array(z.string())]).optional(),\n num_ctx: z.number().optional(),\n num_predict: z.number().optional(),\n })\n .catchall(z.unknown());\n","// AUTO-GENERATED by `npm run contract:generate`. DO NOT EDIT.\n// Source: contracts/ir/ollama.ir.json (canonical Ollama IR).\n// Pairs with ./<name>.ts (the TypeScript interface).\n\nimport { z } from 'zod';\n\n/** Controls a model's thinking output. Use `/api/show` to discover the supported values and default for the selected model. `true` requests thinking, `false` requests no thinking output, and `null` uses the model default. String values are model-defined; supported names must match `/api/show` exactly. Numbers are not supported. */\nexport const ThinkValueSchema = z.union([z.boolean(), z.string(), z.null()]);\n","// AUTO-GENERATED by `npm run contract:generate`. DO NOT EDIT.\n// Source: contracts/ir/ollama.ir.json (canonical Ollama IR).\n// Pairs with ./<name>.ts (the TypeScript interface).\n\nimport { z } from 'zod';\n\nexport const ToolDefinitionSchema = z.object({\n type: z.enum(['function']),\n function: z.object({\n name: z.string(),\n description: z.string().optional(),\n parameters: z.object({}),\n }),\n});\n","// AUTO-GENERATED by `npm run contract:generate`. DO NOT EDIT.\n// Source: contracts/ir/ollama.ir.json (canonical Ollama IR).\n// Pairs with ./<name>.ts (the TypeScript interface).\n\nimport { z } from 'zod';\nimport { ChatMessageSchema } from './ChatMessage.schema.js';\nimport { ModelOptionsSchema } from './ModelOptions.schema.js';\nimport { ThinkValueSchema } from './ThinkValue.schema.js';\nimport { ToolDefinitionSchema } from './ToolDefinition.schema.js';\n\nexport const ChatRequestSchema = z.object({\n model: z.string(),\n messages: z.array(ChatMessageSchema),\n tools: z.array(ToolDefinitionSchema).optional(),\n format: z.union([z.enum(['json']), z.object({})]).optional(),\n options: ModelOptionsSchema.optional(),\n stream: z.boolean().optional(),\n think: ThinkValueSchema.optional(),\n keep_alive: z.union([z.string(), z.number()]).optional(),\n logprobs: z.boolean().optional(),\n top_logprobs: z.number().optional(),\n});\n","// AUTO-GENERATED by `npm run contract:generate`. DO NOT EDIT.\n// Source: contracts/ir/ollama.ir.json (canonical Ollama IR).\n// Pairs with ./<name>.ts (the TypeScript interface).\n\nimport { z } from 'zod';\nimport { ModelOptionsSchema } from './ModelOptions.schema.js';\nimport { ThinkValueSchema } from './ThinkValue.schema.js';\n\nexport const GenerateRequestSchema = z.object({\n model: z.string(),\n prompt: z.string().optional(),\n suffix: z.string().optional(),\n images: z.array(z.string()).optional(),\n format: z.union([z.string(), z.object({})]).optional(),\n system: z.string().optional(),\n stream: z.boolean().optional(),\n think: ThinkValueSchema.optional(),\n raw: z.boolean().optional(),\n keep_alive: z.union([z.string(), z.number()]).optional(),\n options: ModelOptionsSchema.optional(),\n logprobs: z.boolean().optional(),\n top_logprobs: z.number().optional(),\n});\n","// AUTO-GENERATED by `npm run contract:generate`. DO NOT EDIT.\n// Source: contracts/ir/ollama.ir.json (canonical Ollama IR).\n// Pairs with ./<name>.ts (the TypeScript interface).\n\nimport { z } from 'zod';\nimport { ModelOptionsSchema } from './ModelOptions.schema.js';\n\nexport const EmbedRequestSchema = z.object({\n model: z.string(),\n input: z.union([z.string(), z.array(z.string())]),\n truncate: z.boolean().optional(),\n dimensions: z.number().optional(),\n keep_alive: z.string().optional(),\n options: ModelOptionsSchema.optional(),\n});\n","// AUTO-GENERATED by `npm run contract:generate`. DO NOT EDIT.\n// Source: contracts/ir/ollama.ir.json (canonical Ollama IR).\n// Pairs with ./<name>.ts (the TypeScript interface).\n\nimport { z } from 'zod';\nimport { ChatMessageSchema } from './ChatMessage.schema.js';\n\nexport const CreateRequestSchema = z.object({\n model: z.string(),\n from: z.string().optional(),\n template: z.string().optional(),\n renderer: z.string().optional(),\n parser: z.string().optional(),\n files: z.object({}).catchall(z.string()).optional(),\n draft_files: z.object({}).catchall(z.string()).optional(),\n license: z.union([z.string(), z.array(z.string())]).optional(),\n system: z.string().optional(),\n parameters: z.object({}).optional(),\n messages: z.array(ChatMessageSchema).optional(),\n quantize: z.string().optional(),\n draft_quantize: z.string().optional(),\n requires: z.string().optional(),\n stream: z.boolean().optional(),\n});\n","// AUTO-GENERATED by `npm run contract:generate`. DO NOT EDIT.\n// Source: contracts/ir/ollama.ir.json (canonical Ollama IR).\n// Pairs with ./<name>.ts (the TypeScript interface).\n\nimport { z } from 'zod';\n\nexport const CopyRequestSchema = z.object({\n source: z.string(),\n destination: z.string(),\n});\n","// AUTO-GENERATED by `npm run contract:generate`. DO NOT EDIT.\n// Source: contracts/ir/ollama.ir.json (canonical Ollama IR).\n// Pairs with ./<name>.ts (the TypeScript interface).\n\nimport { z } from 'zod';\n\nexport const DeleteRequestSchema = z.object({\n model: z.string(),\n});\n","// AUTO-GENERATED by `npm run contract:generate`. DO NOT EDIT.\n// Source: contracts/ir/ollama.ir.json (canonical Ollama IR).\n// Pairs with ./<name>.ts (the TypeScript interface).\n\nimport { z } from 'zod';\n\nexport const PullRequestSchema = z.object({\n model: z.string(),\n insecure: z.boolean().optional(),\n stream: z.boolean().optional(),\n});\n","// AUTO-GENERATED by `npm run contract:generate`. DO NOT EDIT.\n// Source: contracts/ir/ollama.ir.json (canonical Ollama IR).\n// Pairs with ./<name>.ts (the TypeScript interface).\n\nimport { z } from 'zod';\n\nexport const PushRequestSchema = z.object({\n model: z.string(),\n insecure: z.boolean().optional(),\n stream: z.boolean().optional(),\n});\n","// AUTO-GENERATED by `npm run contract:generate`. DO NOT EDIT.\n// Source: contracts/ir/ollama.ir.json (canonical Ollama IR).\n// Pairs with ./<name>.ts (the TypeScript interface).\n\nimport { z } from 'zod';\n\nexport const ShowRequestSchema = z.object({\n model: z.string(),\n verbose: z.boolean().optional(),\n});\n","/**\n * Schema registry — maps operationId → request/response Zod schemas.\n *\n * The runtime consults this registry to validate request bodies before\n * sending and response payloads after receiving. This is the runtime\n * enforcement layer described in ADR 0019 (Zod schema generation) and\n * ADR 0020 (runtime validation wiring).\n *\n * The registry is hand-written (not generated) because:\n * 1. Not every operation has a request schema (GET/HEAD have no body).\n * 2. Not every operation has a response schema (DELETE returns 204).\n * 3. The map is small (21 operations) and changes only when overlays\n * add new operations — at which point the generator should remind\n * the maintainer to update this file via the contract validator.\n *\n * When `validateRequests: true` is set on `OllamaRuntime` and an\n * operation has no registered request schema, the runtime skips\n * validation (it doesn't fail — the contract just doesn't have a\n * schema for that operation yet).\n */\nimport type { z } from 'zod';\nimport { ChatRequestSchema } from '../models/ChatRequest.schema.js';\nimport { GenerateRequestSchema } from '../models/GenerateRequest.schema.js';\nimport { EmbedRequestSchema } from '../models/EmbedRequest.schema.js';\nimport { CreateRequestSchema } from '../models/CreateRequest.schema.js';\nimport { CopyRequestSchema } from '../models/CopyRequest.schema.js';\nimport { DeleteRequestSchema } from '../models/DeleteRequest.schema.js';\nimport { PullRequestSchema } from '../models/PullRequest.schema.js';\nimport { PushRequestSchema } from '../models/PushRequest.schema.js';\nimport { ShowRequestSchema } from '../models/ShowRequest.schema.js';\n\n/**\n * Map from operationId → request schema. Response schemas are intentionally\n * NOT registered here — see ADR 0020 for the rationale (response validation\n * would break on legitimate forward-compat extensions to the wire format).\n */\nexport const requestSchemas: Readonly<Record<string, z.ZodType>> = {\n chat: ChatRequestSchema,\n generate: GenerateRequestSchema,\n embed: EmbedRequestSchema,\n create: CreateRequestSchema,\n copy: CopyRequestSchema,\n delete: DeleteRequestSchema,\n pull: PullRequestSchema,\n push: PushRequestSchema,\n show: ShowRequestSchema,\n // Operations without a registered request schema (blobs, ps, tags,\n // version, systemOne, openai*, anthropic*) skip validation. This is\n // deliberate — the OpenAPI spec doesn't define request bodies for\n // GET/HEAD operations, and the compat-surface request schemas (OpenAI,\n // Anthropic) are richer than what the IR currently models.\n};\n\n/** Look up a request schema by operationId. Returns `undefined` if no schema exists. */\nexport function getRequestSchema(operationId: string): z.ZodType | undefined {\n return requestSchemas[operationId];\n}\n","/**\n * OllamaRuntime — the runtime seam generated API classes delegate to.\n *\n * This is the only hand-written file in `src/generated/runtime/`. Every\n * generated method in `src/generated/api/*-api.ts` ends with:\n *\n * ```ts\n * return this.runtime.invoke({ operation: chatOp, body: request });\n * ```\n *\n * The runtime is responsible for:\n * - Method/path resolution (from {@link OperationDefinition})\n * - Streaming default application (when the request doesn't set `stream`)\n * - Environment guard (rejecting cloud calls for local-only operations)\n * - Version constraint guard (failing fast when the server is too old)\n * - Delegating to the existing {@link HttpClient} for transport, retry,\n * telemetry, NDJSON/SSE parsing\n *\n * It is intentionally a thin adapter — the existing transport, streaming,\n * middleware, and error-mapping layers are preserved verbatim. This file\n * only adds the contract-aware glue between generated API classes and the\n * existing HttpClient.\n */\nimport { HttpClient, type HttpRequestOptions } from '../../transport/http.js';\nimport { parseNdjsonStream } from '../../streaming/ndjson.js';\nimport { OllamaGenericClientError, OllamaRequestValidationError } from '../../errors.js';\nimport type { OperationDefinition, InvokeRequest } from './operation-definition.js';\nimport { getRequestSchema } from './schema-registry.js';\n\n/** Constructor options for {@link OllamaRuntime}. */\nexport interface OllamaRuntimeOptions {\n readonly http: HttpClient;\n /**\n * Whether this runtime is targeting a local Ollama instance. Defaults to\n * `true`. When `false`, operations marked `environment.cloud === false`\n * (i.e. local-only like `/v1/systemone`) are rejected at request time.\n */\n readonly localMode?: boolean;\n /**\n * Server version, if known (typically from a prior `/api/version` call).\n * When set, operations with `constraints.minOllamaVersion` are checked\n * against this value at request time.\n */\n readonly serverVersion?: string;\n /**\n * When `true`, the runtime validates every request body against the\n * generated Zod schema before sending it. Defaults to `false` — opt-in.\n *\n * Validation behavior:\n * - If the operation has a registered request schema (see\n * {@link schema-registry.ts}), the body is parsed via `safeParse`.\n * - On parse failure, throws `OllamaRequestValidationError` with the\n * Zod issues attached. No HTTP request is made.\n * - On parse success, the parsed (and stripped of unknown fields) body\n * is sent — this means callers can't accidentally send extra fields\n * that the contract doesn't allow.\n * - If the operation has NO registered schema (e.g. GET endpoints,\n * `/v1/systemone`, OpenAI/Anthropic compat surfaces), validation is\n * skipped silently.\n *\n * Response validation is intentionally NOT enabled — see ADR 0020 for\n * the rationale (forward-compat with wire-format extensions).\n */\n readonly validateRequests?: boolean;\n}\n\nfunction compareVersions(a: string, b: string): number {\n const pa = a.split('.').map((s) => Number.parseInt(s, 10) ?? 0);\n const pb = b.split('.').map((s) => Number.parseInt(s, 10) ?? 0);\n for (let i = 0; i < Math.max(pa.length, pb.length); i += 1) {\n const va = pa[i] ?? 0;\n const vb = pb[i] ?? 0;\n if (va !== vb) return va - vb;\n }\n return 0;\n}\n\n/**\n * Apply environment + version guards before delegating to HttpClient.\n *\n * Throws {@link OllamaGenericClientError} when:\n * - The operation is local-only and the runtime is in cloud mode.\n * - The operation has `constraints.minOllamaVersion` and the server is older.\n */\nfunction assertOperationAllowed(\n operation: OperationDefinition,\n options: OllamaRuntimeOptions,\n): void {\n const localMode = options.localMode ?? true;\n if (!localMode && !operation.environment.cloud) {\n throw new OllamaGenericClientError(\n `Operation ${operation.operationId} (${operation.method} ${operation.path}) ` +\n `is local-only and not supported in cloud mode.`,\n );\n }\n if (\n operation.constraints?.minOllamaVersion &&\n options.serverVersion &&\n compareVersions(options.serverVersion, operation.constraints.minOllamaVersion) < 0\n ) {\n throw new OllamaGenericClientError(\n `Operation ${operation.operationId} (${operation.method} ${operation.path}) ` +\n `requires Ollama >= ${operation.constraints.minOllamaVersion} ` +\n `(server reports ${options.serverVersion}).`,\n );\n }\n}\n\n/**\n * Decide whether the request should stream. If the request body explicitly\n * sets `stream`, that wins. Otherwise the operation's `streamingDefault`\n * from the contract is used.\n */\nfunction shouldStream(req: InvokeRequest): boolean {\n if (req.body && typeof req.body === 'object' && 'stream' in req.body) {\n const explicit = (req.body as { stream?: unknown }).stream;\n if (typeof explicit === 'boolean') return explicit;\n }\n return Boolean(req.streamingDefault ?? req.operation.transport.streamingDefault);\n}\n\n/**\n * Apply the streaming default to the request body if needed.\n *\n * If the operation streams by default and the body doesn't set `stream`,\n * add `stream: true`. The user can always override by setting `stream`\n * explicitly on the request.\n */\nfunction buildBody(req: InvokeRequest): unknown {\n if (req.body === undefined) return undefined;\n if (typeof req.body !== 'object' || req.body === null) return req.body;\n const body = req.body as Record<string, unknown>;\n if (\n req.operation.transport.streaming &&\n req.operation.transport.streamingDefault &&\n body.stream === undefined\n ) {\n return { ...body, stream: true };\n }\n return body;\n}\n\n/** The runtime seam. */\nexport class OllamaRuntime {\n constructor(private readonly options: OllamaRuntimeOptions) {}\n\n /**\n * Invoke an operation. Called by every generated API method.\n *\n * Returns a `Promise<T>` for non-streaming operations, or an\n * `AsyncGenerator<T>` for streaming operations. The generated API\n * class's overloads pick the right return type at compile time.\n */\n async invoke<T = unknown>(req: InvokeRequest): Promise<T> {\n assertOperationAllowed(req.operation, this.options);\n let body = buildBody(req);\n\n // Wave 10 (ADR 0020): runtime Zod validation. Opt-in via\n // `validateRequests: true` on the runtime constructor. Throws\n // `OllamaRequestValidationError` BEFORE any HTTP request is made\n // when the body fails validation. The validated (and stripped)\n // body replaces the original so unknown fields can't leak through.\n if (this.options.validateRequests === true && body !== undefined) {\n const schema = getRequestSchema(req.operation.operationId);\n if (schema) {\n const result = schema.safeParse(body);\n if (!result.success) {\n throw new OllamaRequestValidationError(\n `Request validation failed for operation \"${req.operation.operationId}\" ` +\n `(${req.operation.method} ${req.operation.path}): ` +\n result.error.issues\n .map((i) => `${i.path.join('.') || '<root>'}: ${i.message}`)\n .join('; '),\n {\n operationId: req.operation.operationId,\n issues: result.error.issues,\n request: { method: req.operation.method, url: req.operation.path },\n },\n );\n }\n body = result.data;\n }\n }\n\n const streaming = shouldStream(req);\n\n // The HttpClient expects the narrow method union 'GET' | 'POST' |\n // 'DELETE' | 'HEAD' | undefined — cast through `as` because our\n // OperationDefinition.method is the wider HttpMethod type.\n const httpReq: HttpRequestOptions = {\n path: req.operation.path,\n method: req.operation.method as 'GET' | 'POST' | 'DELETE' | 'HEAD',\n ...(body !== undefined ? { body } : {}),\n ...(req.signal !== undefined ? { signal: req.signal } : {}),\n // For streaming calls, request the raw Response so we can pipe it\n // through parseNdjsonStream directly. This inherits middleware,\n // retry, telemetry, and error-mapping from HttpClient — the\n // previous Wave 3 implementation bypassed them with a direct\n // `fetch()` call.\n ...(streaming ? { raw: true } : {}),\n };\n\n if (!streaming) {\n return (await this.options.http.request<T>(httpReq)) as T;\n }\n\n // Streaming: HttpClient returns the raw Response (via the `raw: true`\n // option) so we can read its body as an NDJSON stream.\n const response = await this.options.http.request<Response>(httpReq);\n if (!response.body) {\n throw new OllamaGenericClientError(\n `Operation ${req.operation.operationId}: streaming response had no body.`,\n );\n }\n return parseNdjsonStream<T>(response.body) as unknown as T;\n }\n}\n"]}
|
package/dist/index.cjs
CHANGED
|
@@ -239,10 +239,12 @@ var OllamaAgentMaxIterationsError = class extends OllamaClientError {
|
|
|
239
239
|
var OllamaMcpError = class extends OllamaClientError {
|
|
240
240
|
mcpMethod;
|
|
241
241
|
toolName;
|
|
242
|
+
issues;
|
|
242
243
|
constructor(message, options) {
|
|
243
244
|
super(message, { ...options, code: "mcp_error", retryable: options.retryable ?? false });
|
|
244
245
|
this.mcpMethod = options.mcpMethod;
|
|
245
246
|
this.toolName = options.toolName;
|
|
247
|
+
this.issues = options.issues;
|
|
246
248
|
}
|
|
247
249
|
};
|
|
248
250
|
var OllamaSkillNotFoundError = class extends OllamaClientError {
|
|
@@ -4006,6 +4008,22 @@ async function listAllMcpTools(mcpClient, options = {}, signal) {
|
|
|
4006
4008
|
const params = cursor !== void 0 ? { cursor } : void 0;
|
|
4007
4009
|
const requestOptions = signal !== void 0 ? { signal } : void 0;
|
|
4008
4010
|
const page = await mcpClient.listTools(params, requestOptions);
|
|
4011
|
+
const pageNames = /* @__PURE__ */ new Set();
|
|
4012
|
+
for (const tool of page.tools) {
|
|
4013
|
+
if (pageNames.has(tool.name)) {
|
|
4014
|
+
throw new OllamaMcpError(
|
|
4015
|
+
`MCP tools/list returned duplicate tool name "${tool.name}"`,
|
|
4016
|
+
{ mcpMethod: "listTools", toolName: tool.name }
|
|
4017
|
+
);
|
|
4018
|
+
}
|
|
4019
|
+
pageNames.add(tool.name);
|
|
4020
|
+
if (tools.some((existing) => existing.name === tool.name)) {
|
|
4021
|
+
throw new OllamaMcpError(
|
|
4022
|
+
`MCP tools/list returned duplicate tool name "${tool.name}" across pages`,
|
|
4023
|
+
{ mcpMethod: "listTools", toolName: tool.name }
|
|
4024
|
+
);
|
|
4025
|
+
}
|
|
4026
|
+
}
|
|
4009
4027
|
tools.push(...page.tools);
|
|
4010
4028
|
if (page.nextCursor === void 0) {
|
|
4011
4029
|
return tools;
|
|
@@ -4019,6 +4037,9 @@ async function listAllMcpTools(mcpClient, options = {}, signal) {
|
|
|
4019
4037
|
throw new Error("MCP tools/list exceeded maxPages (" + maxPages + ")");
|
|
4020
4038
|
}
|
|
4021
4039
|
function formatMcpToolResult(result) {
|
|
4040
|
+
if ("resultType" in result || "task" in result) {
|
|
4041
|
+
return JSON.stringify(result) ?? String(result);
|
|
4042
|
+
}
|
|
4022
4043
|
const parts = result.content.map((block) => {
|
|
4023
4044
|
if (block.type === "text" && typeof block.text === "string") {
|
|
4024
4045
|
return block.text;
|
|
@@ -4040,6 +4061,20 @@ function formatMcpToolResult(result) {
|
|
|
4040
4061
|
}
|
|
4041
4062
|
return parts.join("\n");
|
|
4042
4063
|
}
|
|
4064
|
+
function supportsTaskCalls(mcpClient) {
|
|
4065
|
+
return mcpClient.getServerCapabilities?.()?.tasks?.requests?.tools?.call !== void 0;
|
|
4066
|
+
}
|
|
4067
|
+
function shouldCallAsTask(descriptor, options, serverSupportsTasks) {
|
|
4068
|
+
const support = descriptor.execution?.taskSupport;
|
|
4069
|
+
if (support === "required" && !serverSupportsTasks) {
|
|
4070
|
+
throw new OllamaMcpError(
|
|
4071
|
+
`MCP tool "${descriptor.name}" requires task execution, but the server does not advertise tasks.requests.tools.call`,
|
|
4072
|
+
{ mcpMethod: "callTool", toolName: descriptor.name }
|
|
4073
|
+
);
|
|
4074
|
+
}
|
|
4075
|
+
if (!serverSupportsTasks || support === void 0 || support === "forbidden") return false;
|
|
4076
|
+
return support === "required" || options.taskMode === "all-supported";
|
|
4077
|
+
}
|
|
4043
4078
|
function createInputValidator(inputSchema) {
|
|
4044
4079
|
return zod.z.custom().superRefine((value, ctx) => {
|
|
4045
4080
|
const issues = validateJsonSchema(value, inputSchema);
|
|
@@ -4052,7 +4087,7 @@ function createInputValidator(inputSchema) {
|
|
|
4052
4087
|
}
|
|
4053
4088
|
});
|
|
4054
4089
|
}
|
|
4055
|
-
function convertMcpDescriptorToTool(descriptor, mcpClient, namePrefix = "", resultMode = "text") {
|
|
4090
|
+
function convertMcpDescriptorToTool(descriptor, mcpClient, namePrefix = "", resultMode = "text", validateOutputSchema = true, executeAsTask = false, taskTtlMs) {
|
|
4056
4091
|
const toolName = `${namePrefix}${descriptor.name}`;
|
|
4057
4092
|
const inputSchema = descriptor.inputSchema ?? { type: "object", properties: {} };
|
|
4058
4093
|
const properties = inputSchema["properties"] ?? {};
|
|
@@ -4072,10 +4107,27 @@ function convertMcpDescriptorToTool(descriptor, mcpClient, namePrefix = "", resu
|
|
|
4072
4107
|
const result = await mcpClient.callTool(
|
|
4073
4108
|
{
|
|
4074
4109
|
name: descriptor.name,
|
|
4075
|
-
arguments: args
|
|
4110
|
+
arguments: args,
|
|
4111
|
+
...executeAsTask ? { task: taskTtlMs !== void 0 ? { ttl: taskTtlMs } : {} } : {}
|
|
4076
4112
|
},
|
|
4077
|
-
|
|
4113
|
+
{
|
|
4114
|
+
...context.signal !== void 0 ? { signal: context.signal } : {},
|
|
4115
|
+
allowInputRequired: true
|
|
4116
|
+
}
|
|
4078
4117
|
);
|
|
4118
|
+
if (!("resultType" in result) && !("task" in result) && validateOutputSchema && descriptor.outputSchema !== void 0 && result.structuredContent !== void 0) {
|
|
4119
|
+
const issues = validateJsonSchema(result.structuredContent, descriptor.outputSchema);
|
|
4120
|
+
if (issues.length > 0) {
|
|
4121
|
+
throw new OllamaMcpError(
|
|
4122
|
+
`MCP tool "${descriptor.name}" returned structuredContent that violates outputSchema`,
|
|
4123
|
+
{
|
|
4124
|
+
mcpMethod: "tools/call",
|
|
4125
|
+
toolName: descriptor.name,
|
|
4126
|
+
issues
|
|
4127
|
+
}
|
|
4128
|
+
);
|
|
4129
|
+
}
|
|
4130
|
+
}
|
|
4079
4131
|
return resultMode === "structured" ? result : formatMcpToolResult(result);
|
|
4080
4132
|
} catch (err) {
|
|
4081
4133
|
if (err instanceof OllamaMcpError) throw err;
|
|
@@ -4098,9 +4150,29 @@ function convertMcpDescriptorToTool(descriptor, mcpClient, namePrefix = "", resu
|
|
|
4098
4150
|
}
|
|
4099
4151
|
async function loadMcpTools(mcpClient, options = {}, signal) {
|
|
4100
4152
|
try {
|
|
4153
|
+
if (options.taskTtlMs !== void 0 && (!Number.isFinite(options.taskTtlMs) || options.taskTtlMs <= 0)) {
|
|
4154
|
+
throw new RangeError("MCP taskTtlMs must be a positive finite number");
|
|
4155
|
+
}
|
|
4101
4156
|
const tools = await listAllMcpTools(mcpClient, options, signal);
|
|
4102
|
-
|
|
4157
|
+
const serverSupportsTasks = supportsTaskCalls(mcpClient);
|
|
4158
|
+
return tools.map((tool) => {
|
|
4159
|
+
const taskCall = shouldCallAsTask(
|
|
4160
|
+
tool,
|
|
4161
|
+
options,
|
|
4162
|
+
serverSupportsTasks
|
|
4163
|
+
);
|
|
4164
|
+
return convertMcpDescriptorToTool(
|
|
4165
|
+
tool,
|
|
4166
|
+
mcpClient,
|
|
4167
|
+
options.namePrefix,
|
|
4168
|
+
options.resultMode,
|
|
4169
|
+
options.validateOutputSchema ?? true,
|
|
4170
|
+
taskCall,
|
|
4171
|
+
options.taskTtlMs
|
|
4172
|
+
);
|
|
4173
|
+
});
|
|
4103
4174
|
} catch (err) {
|
|
4175
|
+
if (err instanceof OllamaMcpError) throw err;
|
|
4104
4176
|
throw new OllamaMcpError("Failed listing MCP tools from client", {
|
|
4105
4177
|
mcpMethod: "listTools",
|
|
4106
4178
|
cause: err
|
|
@@ -4111,8 +4183,18 @@ async function registerMcpTools(registry, mcpClient, options = {}, signal) {
|
|
|
4111
4183
|
const tools = await loadMcpTools(mcpClient, options, signal);
|
|
4112
4184
|
registry.registerMany(tools);
|
|
4113
4185
|
}
|
|
4114
|
-
|
|
4115
|
-
|
|
4186
|
+
var taskSchema = zod.z.object({
|
|
4187
|
+
taskId: zod.z.string(),
|
|
4188
|
+
status: zod.z.enum(["working", "input_required", "completed", "failed", "cancelled"]),
|
|
4189
|
+
statusMessage: zod.z.string().optional(),
|
|
4190
|
+
createdAt: zod.z.string(),
|
|
4191
|
+
lastUpdatedAt: zod.z.string(),
|
|
4192
|
+
ttl: zod.z.number().optional(),
|
|
4193
|
+
pollInterval: zod.z.number().optional()
|
|
4194
|
+
}).passthrough();
|
|
4195
|
+
var callToolResultSchema = zod.z.custom(
|
|
4196
|
+
(value) => typeof value === "object" && value !== null && "content" in value && Array.isArray(value.content)
|
|
4197
|
+
);
|
|
4116
4198
|
var McpBridge = class _McpBridge {
|
|
4117
4199
|
constructor(client, options = {}) {
|
|
4118
4200
|
this.client = client;
|
|
@@ -4147,6 +4229,50 @@ var McpBridge = class _McpBridge {
|
|
|
4147
4229
|
async register(registry, signal) {
|
|
4148
4230
|
await registry.registerMany(await this.loadTools(signal));
|
|
4149
4231
|
}
|
|
4232
|
+
/** Refreshes the current MCP tool catalog into an existing registry without clearing local tools. */
|
|
4233
|
+
async refresh(registry, signal) {
|
|
4234
|
+
await registry.registerMany(await this.loadTools(signal));
|
|
4235
|
+
}
|
|
4236
|
+
/** Fetches one legacy MCP task's current status without starting a polling loop. */
|
|
4237
|
+
async getTaskStatus(taskId, signal) {
|
|
4238
|
+
return this.requestTask(
|
|
4239
|
+
"tasks/get",
|
|
4240
|
+
taskId,
|
|
4241
|
+
taskSchema,
|
|
4242
|
+
signal
|
|
4243
|
+
);
|
|
4244
|
+
}
|
|
4245
|
+
/** Retrieves a completed legacy MCP task's result. */
|
|
4246
|
+
async getTaskResult(taskId, signal) {
|
|
4247
|
+
return this.requestTask(
|
|
4248
|
+
"tasks/result",
|
|
4249
|
+
taskId,
|
|
4250
|
+
callToolResultSchema,
|
|
4251
|
+
signal
|
|
4252
|
+
);
|
|
4253
|
+
}
|
|
4254
|
+
/** Cancels one legacy MCP task. */
|
|
4255
|
+
async cancelTask(taskId, signal) {
|
|
4256
|
+
return this.requestTask(
|
|
4257
|
+
"tasks/cancel",
|
|
4258
|
+
taskId,
|
|
4259
|
+
taskSchema,
|
|
4260
|
+
signal
|
|
4261
|
+
);
|
|
4262
|
+
}
|
|
4263
|
+
requestTask(method, taskId, resultSchema, signal) {
|
|
4264
|
+
if (this.client.request === void 0) {
|
|
4265
|
+
throw new OllamaMcpError(
|
|
4266
|
+
`MCP client does not support ${method} requests`,
|
|
4267
|
+
{ mcpMethod: method }
|
|
4268
|
+
);
|
|
4269
|
+
}
|
|
4270
|
+
return this.client.request(
|
|
4271
|
+
{ method, params: { taskId } },
|
|
4272
|
+
resultSchema,
|
|
4273
|
+
signal !== void 0 ? { signal } : void 0
|
|
4274
|
+
);
|
|
4275
|
+
}
|
|
4150
4276
|
};
|
|
4151
4277
|
|
|
4152
4278
|
// src/skills/frontmatter.ts
|