@nemesis-oss/ollama-sdk 1.6.0 → 1.8.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 +14 -2
- package/README.md +31 -0
- package/dist/anthropic-B_UXplNF.d.ts +1647 -0
- package/dist/anthropic-CVDFy_a0.d.cts +1647 -0
- package/dist/generated-api.cjs +74 -6
- package/dist/generated-api.cjs.map +1 -1
- package/dist/generated-api.d.cts +230 -629
- package/dist/generated-api.d.ts +230 -629
- package/dist/generated-api.js +72 -7
- package/dist/generated-api.js.map +1 -1
- package/dist/generated-models-schemas.cjs +89 -1
- package/dist/generated-models-schemas.cjs.map +1 -1
- package/dist/generated-models-schemas.d.cts +121 -1
- package/dist/generated-models-schemas.d.ts +121 -1
- package/dist/generated-models-schemas.js +79 -2
- package/dist/generated-models-schemas.js.map +1 -1
- package/dist/generated-runtime.cjs +576 -57
- package/dist/generated-runtime.cjs.map +1 -1
- package/dist/generated-runtime.d.cts +21 -23
- package/dist/generated-runtime.d.ts +21 -23
- package/dist/generated-runtime.js +575 -58
- package/dist/generated-runtime.js.map +1 -1
- package/dist/index.cjs +1210 -81
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +395 -876
- package/dist/index.d.ts +395 -876
- package/dist/index.js +1207 -82
- package/dist/index.js.map +1 -1
- package/dist/mcp/tools.json +287 -73
- package/dist/mcp-generated.cjs +96 -7
- package/dist/mcp-generated.cjs.map +1 -1
- package/dist/mcp-generated.d.cts +3 -3
- package/dist/mcp-generated.d.ts +3 -3
- package/dist/mcp-generated.js +96 -7
- package/dist/mcp-generated.js.map +1 -1
- 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-CVQkbYgF.d.ts → runtime-C6UYtBRB.d.ts} +222 -6
- package/dist/{runtime-IxRpUBjN.d.cts → runtime-DTmUeU6K.d.cts} +222 -6
- 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 +4 -2
- package/dist/types-MOsWXEE7.d.cts +0 -66
- package/dist/types-MOsWXEE7.d.ts +0 -66
|
@@ -195,6 +195,61 @@ declare class OllamaRequestValidationError extends OllamaClientError {
|
|
|
195
195
|
issues: readonly z.ZodIssue[];
|
|
196
196
|
});
|
|
197
197
|
}
|
|
198
|
+
/**
|
|
199
|
+
* Thrown by `OllamaRuntime.invoke` BEFORE any HTTP request is made when the
|
|
200
|
+
* serialized request body exceeds the operation's declared
|
|
201
|
+
* `constraints.maxRequestBytes`. The Ollama server returns 413 for such
|
|
202
|
+
* payloads; this client-side check fails fast so the round-trip is avoided.
|
|
203
|
+
*
|
|
204
|
+
* Wave 12 (P0 #5): the IR has carried `maxRequestBytes` for System One
|
|
205
|
+
* (64 KiB) since v1.7.0, but the runtime never enforced it. This closes
|
|
206
|
+
* that contract/runtime gap.
|
|
207
|
+
*/
|
|
208
|
+
declare class OllamaRequestTooLargeError extends OllamaClientError {
|
|
209
|
+
readonly operationId: string;
|
|
210
|
+
readonly actualBytes: number;
|
|
211
|
+
readonly maxBytes: number;
|
|
212
|
+
constructor(message: string, options: Omit<OllamaClientErrorOptions, 'code' | 'retryable' | 'status'> & {
|
|
213
|
+
operationId: string;
|
|
214
|
+
actualBytes: number;
|
|
215
|
+
maxBytes: number;
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Thrown by `OllamaRuntime.invoke` AFTER the HTTP response is received
|
|
220
|
+
* when `validateResponses: true` is set and the response body fails Zod
|
|
221
|
+
* validation against the operation's registered response schema.
|
|
222
|
+
*
|
|
223
|
+
* Wave 13: the runtime previously never validated responses (see ADR
|
|
224
|
+
* 0020). This opt-in error gives callers a way to detect wire-format
|
|
225
|
+
* mismatches for operations where typed response semantics are critical
|
|
226
|
+
* (e.g. System One). The error carries the original Zod issues so
|
|
227
|
+
* callers can inspect which fields failed.
|
|
228
|
+
*/
|
|
229
|
+
declare class OllamaResponseValidationError extends OllamaClientError {
|
|
230
|
+
readonly operationId: string;
|
|
231
|
+
readonly issues: readonly z.ZodIssue[];
|
|
232
|
+
constructor(message: string, options: Omit<OllamaClientErrorOptions, 'code' | 'retryable'> & {
|
|
233
|
+
operationId: string;
|
|
234
|
+
issues: readonly z.ZodIssue[];
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Thrown by `OllamaRuntime.invoke` BEFORE any HTTP request is made when the
|
|
239
|
+
* operation declares `constraints.minOllamaVersion` and the runtime could
|
|
240
|
+
* not obtain a server version to compare against (e.g. `enforceVersion:
|
|
241
|
+
* 'strict'` was set and `/api/version` was unreachable). Distinct from
|
|
242
|
+
* {@link OllamaGenericClientError} so callers can branch on the failure
|
|
243
|
+
* mode rather than parsing the message.
|
|
244
|
+
*/
|
|
245
|
+
declare class OllamaServerVersionUnknownError extends OllamaClientError {
|
|
246
|
+
readonly operationId: string;
|
|
247
|
+
readonly minRequiredVersion: string;
|
|
248
|
+
constructor(message: string, options: Omit<OllamaClientErrorOptions, 'code' | 'retryable'> & {
|
|
249
|
+
operationId: string;
|
|
250
|
+
minRequiredVersion: string;
|
|
251
|
+
});
|
|
252
|
+
}
|
|
198
253
|
declare class OllamaToolTimeoutError extends OllamaClientError {
|
|
199
254
|
readonly toolName: string;
|
|
200
255
|
readonly timeoutMs: number;
|
|
@@ -262,11 +317,13 @@ declare class OllamaAgentMaxIterationsError extends OllamaClientError {
|
|
|
262
317
|
});
|
|
263
318
|
}
|
|
264
319
|
declare class OllamaMcpError extends OllamaClientError {
|
|
265
|
-
readonly mcpMethod: 'listTools' | 'callTool';
|
|
320
|
+
readonly mcpMethod: 'listTools' | 'callTool' | 'tools/call' | 'tasks/get' | 'tasks/result' | 'tasks/cancel';
|
|
266
321
|
readonly toolName?: string | undefined;
|
|
322
|
+
readonly issues?: unknown;
|
|
267
323
|
constructor(message: string, options: Omit<OllamaClientErrorOptions, 'code'> & {
|
|
268
|
-
mcpMethod: 'listTools' | 'callTool';
|
|
324
|
+
mcpMethod: 'listTools' | 'callTool' | 'tools/call' | 'tasks/get' | 'tasks/result' | 'tasks/cancel';
|
|
269
325
|
toolName?: string | undefined;
|
|
326
|
+
issues?: unknown;
|
|
270
327
|
});
|
|
271
328
|
}
|
|
272
329
|
declare class OllamaSkillNotFoundError extends OllamaClientError {
|
|
@@ -492,6 +549,21 @@ type CapabilitySupport = 'supported' | 'unsupported' | 'model-dependent' | 'vers
|
|
|
492
549
|
interface SchemaRef {
|
|
493
550
|
readonly $ref: string;
|
|
494
551
|
}
|
|
552
|
+
/**
|
|
553
|
+
* Wave 15 (P0): structural parameter on an operation. Mirrors
|
|
554
|
+
* {@link OperationParameter} from the canonical IR. Path parameters
|
|
555
|
+
* are substituted into the operation's path template at runtime;
|
|
556
|
+
* query and header parameters are attached to the HTTP request.
|
|
557
|
+
*/
|
|
558
|
+
interface OperationParameter {
|
|
559
|
+
readonly name: string;
|
|
560
|
+
readonly in: 'path' | 'query' | 'header';
|
|
561
|
+
readonly required: boolean;
|
|
562
|
+
readonly schema?: {
|
|
563
|
+
readonly type?: string;
|
|
564
|
+
};
|
|
565
|
+
readonly description?: string;
|
|
566
|
+
}
|
|
495
567
|
/** Behavioral contract a generated operation carries into the runtime. */
|
|
496
568
|
interface OperationDefinition {
|
|
497
569
|
readonly operationId: string;
|
|
@@ -503,6 +575,25 @@ interface OperationDefinition {
|
|
|
503
575
|
readonly local: boolean;
|
|
504
576
|
readonly cloud: boolean;
|
|
505
577
|
};
|
|
578
|
+
/**
|
|
579
|
+
* Wave 12 (P1 #7): host this operation targets, when different from
|
|
580
|
+
* the runtime's default HttpClient base URL. Cloud-hosted capability
|
|
581
|
+
* endpoints (web search, web fetch) live at `https://ollama.com/api/...`
|
|
582
|
+
* rather than the local Ollama server. The runtime rejects operations
|
|
583
|
+
* with a non-default host when the runtime's HttpClient isn't
|
|
584
|
+
* configured for that host — callers must use OllamaClient.webSearch /
|
|
585
|
+
* OllamaClient.webFetch (which spin up a dedicated cloud HttpClient)
|
|
586
|
+
* for these operations.
|
|
587
|
+
*/
|
|
588
|
+
readonly host?: string;
|
|
589
|
+
/**
|
|
590
|
+
* Wave 15 (P0): structural parameters derived from the path template
|
|
591
|
+
* and OpenAPI declarations. Path parameters are substituted into the
|
|
592
|
+
* URL at runtime; query and header parameters are attached to the
|
|
593
|
+
* HTTP request. The runtime uses this to URI-encode and substitute
|
|
594
|
+
* `{name}` segments in the path.
|
|
595
|
+
*/
|
|
596
|
+
readonly parameters?: readonly OperationParameter[];
|
|
506
597
|
readonly transport: {
|
|
507
598
|
readonly mode: TransportMode;
|
|
508
599
|
readonly streaming: boolean;
|
|
@@ -519,6 +610,8 @@ interface OperationDefinition {
|
|
|
519
610
|
readonly constraints?: {
|
|
520
611
|
readonly minOllamaVersion?: string;
|
|
521
612
|
readonly maxRequestBytes?: number;
|
|
613
|
+
/** Wave 13: limit when body contains images (e.g. System One: 32 MiB). */
|
|
614
|
+
readonly maxRequestBytesWithImages?: number;
|
|
522
615
|
};
|
|
523
616
|
readonly status: {
|
|
524
617
|
readonly documented: boolean;
|
|
@@ -542,6 +635,28 @@ interface InvokeRequest {
|
|
|
542
635
|
* doesn't explicitly set `stream`.
|
|
543
636
|
*/
|
|
544
637
|
readonly streamingDefault?: boolean;
|
|
638
|
+
/**
|
|
639
|
+
* Wave 15 (P0): path parameter values keyed by parameter name. The
|
|
640
|
+
* runtime substitutes these into the operation's path template
|
|
641
|
+
* (e.g. `{model}` → `gpt-4`) with URI encoding.
|
|
642
|
+
*/
|
|
643
|
+
readonly pathParams?: Readonly<Record<string, string>>;
|
|
644
|
+
/**
|
|
645
|
+
* Wave 15 (P0): query parameter values keyed by parameter name.
|
|
646
|
+
* The runtime attaches these to the HTTP request URL.
|
|
647
|
+
*/
|
|
648
|
+
readonly queryParams?: Readonly<Record<string, string>>;
|
|
649
|
+
/**
|
|
650
|
+
* Wave 15 (P0): header parameter values keyed by header name.
|
|
651
|
+
* The runtime attaches these to the HTTP request headers.
|
|
652
|
+
*/
|
|
653
|
+
readonly headerParams?: Readonly<Record<string, string>>;
|
|
654
|
+
/**
|
|
655
|
+
* Wave 15 (P1): model name for routing. Extracted from the request
|
|
656
|
+
* body when possible; used by the failover layer to filter endpoints
|
|
657
|
+
* by `OllamaEndpoint.models` (credential-scoped routing).
|
|
658
|
+
*/
|
|
659
|
+
readonly model?: string;
|
|
545
660
|
}
|
|
546
661
|
|
|
547
662
|
/**
|
|
@@ -568,9 +683,30 @@ interface InvokeRequest {
|
|
|
568
683
|
* existing HttpClient.
|
|
569
684
|
*/
|
|
570
685
|
|
|
686
|
+
/**
|
|
687
|
+
* Minimal HTTP client surface the runtime consumes. Either a full
|
|
688
|
+
* {@link HttpClient} or a {@link FailoverHttpClient} — the runtime only
|
|
689
|
+
* calls `request()`.
|
|
690
|
+
*
|
|
691
|
+
* Wave 14: widened from `HttpClient` to allow the failover-aware wrapper
|
|
692
|
+
* without breaking existing callers that pass a plain HttpClient.
|
|
693
|
+
*/
|
|
694
|
+
type RuntimeHttpBackend = Pick<HttpClient, 'baseUrl' | 'request'>;
|
|
571
695
|
/** Constructor options for {@link OllamaRuntime}. */
|
|
572
696
|
interface OllamaRuntimeOptions {
|
|
573
|
-
readonly http:
|
|
697
|
+
readonly http: RuntimeHttpBackend;
|
|
698
|
+
/**
|
|
699
|
+
* Wave 15 (P0): HTTP backend for operations that declare a non-default
|
|
700
|
+
* `host` (e.g. web search/fetch at `https://ollama.com`). When an
|
|
701
|
+
* operation has `host: 'https://ollama.com'` and `cloudHttp` is
|
|
702
|
+
* configured, the runtime routes the request through this backend
|
|
703
|
+
* instead of the default `http`. When `cloudHttp` is not configured
|
|
704
|
+
* and a host-bearing operation is invoked, the runtime throws.
|
|
705
|
+
*
|
|
706
|
+
* OllamaClient.runtime sets this to a dedicated cloud HttpClient
|
|
707
|
+
* pointed at `https://ollama.com` with the configured API key.
|
|
708
|
+
*/
|
|
709
|
+
readonly cloudHttp?: RuntimeHttpBackend;
|
|
574
710
|
/**
|
|
575
711
|
* Whether this runtime is targeting a local Ollama instance. Defaults to
|
|
576
712
|
* `true`. When `false`, operations marked `environment.cloud === false`
|
|
@@ -581,6 +717,10 @@ interface OllamaRuntimeOptions {
|
|
|
581
717
|
* Server version, if known (typically from a prior `/api/version` call).
|
|
582
718
|
* When set, operations with `constraints.minOllamaVersion` are checked
|
|
583
719
|
* against this value at request time.
|
|
720
|
+
*
|
|
721
|
+
* Wave 12 (P0 #5): when unset, the runtime will lazily fetch and cache
|
|
722
|
+
* the server version the first time a version-gated operation is
|
|
723
|
+
* invoked. The fetch policy is controlled by {@link enforceVersion}.
|
|
584
724
|
*/
|
|
585
725
|
readonly serverVersion?: string;
|
|
586
726
|
/**
|
|
@@ -599,15 +739,75 @@ interface OllamaRuntimeOptions {
|
|
|
599
739
|
* `/v1/systemone`, OpenAI/Anthropic compat surfaces), validation is
|
|
600
740
|
* skipped silently.
|
|
601
741
|
*
|
|
602
|
-
* Response validation is intentionally NOT enabled — see
|
|
603
|
-
* the rationale (forward-compat with wire-format
|
|
742
|
+
* Response validation is intentionally NOT enabled by default — see
|
|
743
|
+
* ADR 0020 for the rationale (forward-compat with wire-format
|
|
744
|
+
* extensions).
|
|
745
|
+
*
|
|
746
|
+
* Wave 13: an opt-in `validateResponses` option is now available for
|
|
747
|
+
* operations where typed response semantics are the entire point
|
|
748
|
+
* (e.g. System One). When enabled, the runtime validates the HTTP
|
|
749
|
+
* response body against the operation's registered response schema
|
|
750
|
+
* before returning it to the caller. On failure, throws
|
|
751
|
+
* {@link OllamaResponseValidationError}.
|
|
604
752
|
*/
|
|
605
753
|
readonly validateRequests?: boolean;
|
|
754
|
+
/**
|
|
755
|
+
* Wave 13: when `true`, the runtime validates every response body
|
|
756
|
+
* against the operation's registered response schema before returning
|
|
757
|
+
* it. Defaults to `false` — opt-in. Only operations with a registered
|
|
758
|
+
* response schema are validated; others pass through unchanged.
|
|
759
|
+
*
|
|
760
|
+
* On validation failure, throws {@link OllamaResponseValidationError}
|
|
761
|
+
* with the Zod issues attached. The HTTP response is still consumed.
|
|
762
|
+
*
|
|
763
|
+
* Use this for operations where typed response semantics are critical
|
|
764
|
+
* (System One, structured output). Don't enable globally — legitimate
|
|
765
|
+
* forward-compat wire-format extensions would cause false rejections.
|
|
766
|
+
*/
|
|
767
|
+
readonly validateResponses?: boolean;
|
|
768
|
+
/**
|
|
769
|
+
* Policy for enforcing `constraints.minOllamaVersion` when
|
|
770
|
+
* {@link serverVersion} is not explicitly supplied.
|
|
771
|
+
*
|
|
772
|
+
* - `'auto'` (default): lazily fetch `/api/version` once and cache the
|
|
773
|
+
* result; subsequent version-gated invocations reuse the cached
|
|
774
|
+
* value. If the fetch fails, the operation is allowed through
|
|
775
|
+
* (fail-open) — the server will reject it if it truly doesn't
|
|
776
|
+
* support it.
|
|
777
|
+
* - `'strict'`: same as `'auto'`, but if the version fetch fails the
|
|
778
|
+
* invocation throws {@link OllamaServerVersionUnknownError} rather
|
|
779
|
+
* than fail-open. Use this when the caller wants hard guarantees
|
|
780
|
+
* that a version-gated operation will not be sent to a server that
|
|
781
|
+
* can't handle it.
|
|
782
|
+
* - `'off'`: never fetch `/api/version` automatically. The runtime
|
|
783
|
+
* only enforces the version constraint when {@link serverVersion}
|
|
784
|
+
* was explicitly supplied. Useful in tests that mock fetch and want
|
|
785
|
+
* to avoid spurious version probes.
|
|
786
|
+
*/
|
|
787
|
+
readonly enforceVersion?: 'auto' | 'strict' | 'off';
|
|
606
788
|
}
|
|
607
789
|
/** The runtime seam. */
|
|
608
790
|
declare class OllamaRuntime {
|
|
609
791
|
private readonly options;
|
|
792
|
+
/**
|
|
793
|
+
* Cached promise of the Ollama server version, populated lazily the first
|
|
794
|
+
* time a version-gated operation is invoked. `undefined` until then.
|
|
795
|
+
*
|
|
796
|
+
* Wave 12 (P0 #5): see {@link OllamaRuntimeOptions.enforceVersion}.
|
|
797
|
+
*/
|
|
798
|
+
private serverVersionCache;
|
|
610
799
|
constructor(options: OllamaRuntimeOptions);
|
|
800
|
+
/**
|
|
801
|
+
* Wave 15 (P0): resolve the HTTP backend for a given operation.
|
|
802
|
+
*
|
|
803
|
+
* Operations with a declared `host` (e.g. web search/fetch at
|
|
804
|
+
* https://ollama.com) must route to a HttpClient pointed at that host,
|
|
805
|
+
* not the default one. The runtime accepts an optional `cloudHttp`
|
|
806
|
+
* backend for this purpose — if the operation declares a host and no
|
|
807
|
+
* cloud backend is configured, the runtime throws rather than silently
|
|
808
|
+
* sending the request to the wrong server.
|
|
809
|
+
*/
|
|
810
|
+
private resolveHttpBackend;
|
|
611
811
|
/**
|
|
612
812
|
* Invoke an operation. Called by every generated API method.
|
|
613
813
|
*
|
|
@@ -616,6 +816,22 @@ declare class OllamaRuntime {
|
|
|
616
816
|
* class's overloads pick the right return type at compile time.
|
|
617
817
|
*/
|
|
618
818
|
invoke<T = unknown>(req: InvokeRequest): Promise<T>;
|
|
819
|
+
/**
|
|
820
|
+
* Apply environment + version guards before delegating to HttpClient.
|
|
821
|
+
*
|
|
822
|
+
* Throws {@link OllamaGenericClientError} when:
|
|
823
|
+
* - The operation is local-only and the runtime is in cloud mode.
|
|
824
|
+
* - The operation has `constraints.minOllamaVersion` and the server is older.
|
|
825
|
+
*
|
|
826
|
+
* Wave 12 (P0 #5): when `minOllamaVersion` is declared but the runtime's
|
|
827
|
+
* `serverVersion` is unknown AND `enforceVersion` is `'auto'` or
|
|
828
|
+
* `'strict'`, the runtime lazily fetches `/api/version` (cached on the
|
|
829
|
+
* runtime instance) so the constraint is actually enforced even when the
|
|
830
|
+
* caller didn't supply it. Previously the constraint was only enforced
|
|
831
|
+
* when `serverVersion` was manually supplied — meaning in practice it was
|
|
832
|
+
* almost never enforced.
|
|
833
|
+
*/
|
|
834
|
+
private assertOperationAllowed;
|
|
619
835
|
}
|
|
620
836
|
|
|
621
|
-
export {
|
|
837
|
+
export { OllamaResponseValidationError as $, type AbortableAsyncIterable as A, type BinaryBody as B, type ChatStreamResult as C, type DoneEvent as D, type ErrorEvent as E, type FetchLike as F, type GenerateStreamResult as G, HttpClient as H, type InvokeRequest as I, OllamaGenericClientError as J, OllamaIncompatibleModelError as K, type Logger as L, type Middleware as M, NANOS_PER_MS as N, OllamaRuntime as O, type ProgressStreamResult as P, OllamaMcpError as Q, type RequestLifecycleHook as R, type SchemaRef as S, type TokenUsage as T, OllamaModelRoutingError as U, OllamaNetworkError as V, OllamaNotFoundError as W, OllamaQuotaExceededError as X, OllamaRateLimitError as Y, OllamaRequestTooLargeError as Z, OllamaRequestValidationError as _, type OperationDefinition as a, OllamaServerError as a0, OllamaServerVersionUnknownError as a1, OllamaSkillInvalidError as a2, OllamaSkillNotFoundError as a3, OllamaTimeoutError as a4, OllamaToolTimeoutError as a5, OllamaToolValidationError as a6, OllamaUnsupportedCapabilityError as a7, type RequestContext as a8, type RequestLifecycleEvent as a9, type ResponseContext as aa, type SseEvent as ab, type ThinkingEvent as ac, type TokenEvent as ad, type ToolCallEvent as ae, composeMiddleware as af, createConsoleLogger as ag, extractUsage as ah, mapError as ai, parseSseStream as aj, type OllamaRuntimeOptions as b, type OllamaStreamEvent as c, type OllamaStreamEventType as d, type RawUsageSource as e, type HttpBody as f, type HttpClientOptions as g, type HttpRequestOptions as h, type LifecycleErrorEvent as i, type LifecycleRetryEvent as j, type LifecycleStartEvent as k, type LifecycleSuccessEvent as l, type LogFn as m, type MessageEvent as n, type MiddlewareContext as o, NANOS_PER_SECOND as p, NOOP_LOGGER as q, type NextFunction as r, OllamaAbortError as s, OllamaAgentMaxIterationsError as t, OllamaAgentMaxToolCallsError as u, OllamaAuthError as v, OllamaClientError as w, type OllamaClientErrorOptions as x, type OllamaErrorRequestContext as y, type OllamaErrorResponseContext as z };
|
|
@@ -195,6 +195,61 @@ declare class OllamaRequestValidationError extends OllamaClientError {
|
|
|
195
195
|
issues: readonly z.ZodIssue[];
|
|
196
196
|
});
|
|
197
197
|
}
|
|
198
|
+
/**
|
|
199
|
+
* Thrown by `OllamaRuntime.invoke` BEFORE any HTTP request is made when the
|
|
200
|
+
* serialized request body exceeds the operation's declared
|
|
201
|
+
* `constraints.maxRequestBytes`. The Ollama server returns 413 for such
|
|
202
|
+
* payloads; this client-side check fails fast so the round-trip is avoided.
|
|
203
|
+
*
|
|
204
|
+
* Wave 12 (P0 #5): the IR has carried `maxRequestBytes` for System One
|
|
205
|
+
* (64 KiB) since v1.7.0, but the runtime never enforced it. This closes
|
|
206
|
+
* that contract/runtime gap.
|
|
207
|
+
*/
|
|
208
|
+
declare class OllamaRequestTooLargeError extends OllamaClientError {
|
|
209
|
+
readonly operationId: string;
|
|
210
|
+
readonly actualBytes: number;
|
|
211
|
+
readonly maxBytes: number;
|
|
212
|
+
constructor(message: string, options: Omit<OllamaClientErrorOptions, 'code' | 'retryable' | 'status'> & {
|
|
213
|
+
operationId: string;
|
|
214
|
+
actualBytes: number;
|
|
215
|
+
maxBytes: number;
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Thrown by `OllamaRuntime.invoke` AFTER the HTTP response is received
|
|
220
|
+
* when `validateResponses: true` is set and the response body fails Zod
|
|
221
|
+
* validation against the operation's registered response schema.
|
|
222
|
+
*
|
|
223
|
+
* Wave 13: the runtime previously never validated responses (see ADR
|
|
224
|
+
* 0020). This opt-in error gives callers a way to detect wire-format
|
|
225
|
+
* mismatches for operations where typed response semantics are critical
|
|
226
|
+
* (e.g. System One). The error carries the original Zod issues so
|
|
227
|
+
* callers can inspect which fields failed.
|
|
228
|
+
*/
|
|
229
|
+
declare class OllamaResponseValidationError extends OllamaClientError {
|
|
230
|
+
readonly operationId: string;
|
|
231
|
+
readonly issues: readonly z.ZodIssue[];
|
|
232
|
+
constructor(message: string, options: Omit<OllamaClientErrorOptions, 'code' | 'retryable'> & {
|
|
233
|
+
operationId: string;
|
|
234
|
+
issues: readonly z.ZodIssue[];
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Thrown by `OllamaRuntime.invoke` BEFORE any HTTP request is made when the
|
|
239
|
+
* operation declares `constraints.minOllamaVersion` and the runtime could
|
|
240
|
+
* not obtain a server version to compare against (e.g. `enforceVersion:
|
|
241
|
+
* 'strict'` was set and `/api/version` was unreachable). Distinct from
|
|
242
|
+
* {@link OllamaGenericClientError} so callers can branch on the failure
|
|
243
|
+
* mode rather than parsing the message.
|
|
244
|
+
*/
|
|
245
|
+
declare class OllamaServerVersionUnknownError extends OllamaClientError {
|
|
246
|
+
readonly operationId: string;
|
|
247
|
+
readonly minRequiredVersion: string;
|
|
248
|
+
constructor(message: string, options: Omit<OllamaClientErrorOptions, 'code' | 'retryable'> & {
|
|
249
|
+
operationId: string;
|
|
250
|
+
minRequiredVersion: string;
|
|
251
|
+
});
|
|
252
|
+
}
|
|
198
253
|
declare class OllamaToolTimeoutError extends OllamaClientError {
|
|
199
254
|
readonly toolName: string;
|
|
200
255
|
readonly timeoutMs: number;
|
|
@@ -262,11 +317,13 @@ declare class OllamaAgentMaxIterationsError extends OllamaClientError {
|
|
|
262
317
|
});
|
|
263
318
|
}
|
|
264
319
|
declare class OllamaMcpError extends OllamaClientError {
|
|
265
|
-
readonly mcpMethod: 'listTools' | 'callTool';
|
|
320
|
+
readonly mcpMethod: 'listTools' | 'callTool' | 'tools/call' | 'tasks/get' | 'tasks/result' | 'tasks/cancel';
|
|
266
321
|
readonly toolName?: string | undefined;
|
|
322
|
+
readonly issues?: unknown;
|
|
267
323
|
constructor(message: string, options: Omit<OllamaClientErrorOptions, 'code'> & {
|
|
268
|
-
mcpMethod: 'listTools' | 'callTool';
|
|
324
|
+
mcpMethod: 'listTools' | 'callTool' | 'tools/call' | 'tasks/get' | 'tasks/result' | 'tasks/cancel';
|
|
269
325
|
toolName?: string | undefined;
|
|
326
|
+
issues?: unknown;
|
|
270
327
|
});
|
|
271
328
|
}
|
|
272
329
|
declare class OllamaSkillNotFoundError extends OllamaClientError {
|
|
@@ -492,6 +549,21 @@ type CapabilitySupport = 'supported' | 'unsupported' | 'model-dependent' | 'vers
|
|
|
492
549
|
interface SchemaRef {
|
|
493
550
|
readonly $ref: string;
|
|
494
551
|
}
|
|
552
|
+
/**
|
|
553
|
+
* Wave 15 (P0): structural parameter on an operation. Mirrors
|
|
554
|
+
* {@link OperationParameter} from the canonical IR. Path parameters
|
|
555
|
+
* are substituted into the operation's path template at runtime;
|
|
556
|
+
* query and header parameters are attached to the HTTP request.
|
|
557
|
+
*/
|
|
558
|
+
interface OperationParameter {
|
|
559
|
+
readonly name: string;
|
|
560
|
+
readonly in: 'path' | 'query' | 'header';
|
|
561
|
+
readonly required: boolean;
|
|
562
|
+
readonly schema?: {
|
|
563
|
+
readonly type?: string;
|
|
564
|
+
};
|
|
565
|
+
readonly description?: string;
|
|
566
|
+
}
|
|
495
567
|
/** Behavioral contract a generated operation carries into the runtime. */
|
|
496
568
|
interface OperationDefinition {
|
|
497
569
|
readonly operationId: string;
|
|
@@ -503,6 +575,25 @@ interface OperationDefinition {
|
|
|
503
575
|
readonly local: boolean;
|
|
504
576
|
readonly cloud: boolean;
|
|
505
577
|
};
|
|
578
|
+
/**
|
|
579
|
+
* Wave 12 (P1 #7): host this operation targets, when different from
|
|
580
|
+
* the runtime's default HttpClient base URL. Cloud-hosted capability
|
|
581
|
+
* endpoints (web search, web fetch) live at `https://ollama.com/api/...`
|
|
582
|
+
* rather than the local Ollama server. The runtime rejects operations
|
|
583
|
+
* with a non-default host when the runtime's HttpClient isn't
|
|
584
|
+
* configured for that host — callers must use OllamaClient.webSearch /
|
|
585
|
+
* OllamaClient.webFetch (which spin up a dedicated cloud HttpClient)
|
|
586
|
+
* for these operations.
|
|
587
|
+
*/
|
|
588
|
+
readonly host?: string;
|
|
589
|
+
/**
|
|
590
|
+
* Wave 15 (P0): structural parameters derived from the path template
|
|
591
|
+
* and OpenAPI declarations. Path parameters are substituted into the
|
|
592
|
+
* URL at runtime; query and header parameters are attached to the
|
|
593
|
+
* HTTP request. The runtime uses this to URI-encode and substitute
|
|
594
|
+
* `{name}` segments in the path.
|
|
595
|
+
*/
|
|
596
|
+
readonly parameters?: readonly OperationParameter[];
|
|
506
597
|
readonly transport: {
|
|
507
598
|
readonly mode: TransportMode;
|
|
508
599
|
readonly streaming: boolean;
|
|
@@ -519,6 +610,8 @@ interface OperationDefinition {
|
|
|
519
610
|
readonly constraints?: {
|
|
520
611
|
readonly minOllamaVersion?: string;
|
|
521
612
|
readonly maxRequestBytes?: number;
|
|
613
|
+
/** Wave 13: limit when body contains images (e.g. System One: 32 MiB). */
|
|
614
|
+
readonly maxRequestBytesWithImages?: number;
|
|
522
615
|
};
|
|
523
616
|
readonly status: {
|
|
524
617
|
readonly documented: boolean;
|
|
@@ -542,6 +635,28 @@ interface InvokeRequest {
|
|
|
542
635
|
* doesn't explicitly set `stream`.
|
|
543
636
|
*/
|
|
544
637
|
readonly streamingDefault?: boolean;
|
|
638
|
+
/**
|
|
639
|
+
* Wave 15 (P0): path parameter values keyed by parameter name. The
|
|
640
|
+
* runtime substitutes these into the operation's path template
|
|
641
|
+
* (e.g. `{model}` → `gpt-4`) with URI encoding.
|
|
642
|
+
*/
|
|
643
|
+
readonly pathParams?: Readonly<Record<string, string>>;
|
|
644
|
+
/**
|
|
645
|
+
* Wave 15 (P0): query parameter values keyed by parameter name.
|
|
646
|
+
* The runtime attaches these to the HTTP request URL.
|
|
647
|
+
*/
|
|
648
|
+
readonly queryParams?: Readonly<Record<string, string>>;
|
|
649
|
+
/**
|
|
650
|
+
* Wave 15 (P0): header parameter values keyed by header name.
|
|
651
|
+
* The runtime attaches these to the HTTP request headers.
|
|
652
|
+
*/
|
|
653
|
+
readonly headerParams?: Readonly<Record<string, string>>;
|
|
654
|
+
/**
|
|
655
|
+
* Wave 15 (P1): model name for routing. Extracted from the request
|
|
656
|
+
* body when possible; used by the failover layer to filter endpoints
|
|
657
|
+
* by `OllamaEndpoint.models` (credential-scoped routing).
|
|
658
|
+
*/
|
|
659
|
+
readonly model?: string;
|
|
545
660
|
}
|
|
546
661
|
|
|
547
662
|
/**
|
|
@@ -568,9 +683,30 @@ interface InvokeRequest {
|
|
|
568
683
|
* existing HttpClient.
|
|
569
684
|
*/
|
|
570
685
|
|
|
686
|
+
/**
|
|
687
|
+
* Minimal HTTP client surface the runtime consumes. Either a full
|
|
688
|
+
* {@link HttpClient} or a {@link FailoverHttpClient} — the runtime only
|
|
689
|
+
* calls `request()`.
|
|
690
|
+
*
|
|
691
|
+
* Wave 14: widened from `HttpClient` to allow the failover-aware wrapper
|
|
692
|
+
* without breaking existing callers that pass a plain HttpClient.
|
|
693
|
+
*/
|
|
694
|
+
type RuntimeHttpBackend = Pick<HttpClient, 'baseUrl' | 'request'>;
|
|
571
695
|
/** Constructor options for {@link OllamaRuntime}. */
|
|
572
696
|
interface OllamaRuntimeOptions {
|
|
573
|
-
readonly http:
|
|
697
|
+
readonly http: RuntimeHttpBackend;
|
|
698
|
+
/**
|
|
699
|
+
* Wave 15 (P0): HTTP backend for operations that declare a non-default
|
|
700
|
+
* `host` (e.g. web search/fetch at `https://ollama.com`). When an
|
|
701
|
+
* operation has `host: 'https://ollama.com'` and `cloudHttp` is
|
|
702
|
+
* configured, the runtime routes the request through this backend
|
|
703
|
+
* instead of the default `http`. When `cloudHttp` is not configured
|
|
704
|
+
* and a host-bearing operation is invoked, the runtime throws.
|
|
705
|
+
*
|
|
706
|
+
* OllamaClient.runtime sets this to a dedicated cloud HttpClient
|
|
707
|
+
* pointed at `https://ollama.com` with the configured API key.
|
|
708
|
+
*/
|
|
709
|
+
readonly cloudHttp?: RuntimeHttpBackend;
|
|
574
710
|
/**
|
|
575
711
|
* Whether this runtime is targeting a local Ollama instance. Defaults to
|
|
576
712
|
* `true`. When `false`, operations marked `environment.cloud === false`
|
|
@@ -581,6 +717,10 @@ interface OllamaRuntimeOptions {
|
|
|
581
717
|
* Server version, if known (typically from a prior `/api/version` call).
|
|
582
718
|
* When set, operations with `constraints.minOllamaVersion` are checked
|
|
583
719
|
* against this value at request time.
|
|
720
|
+
*
|
|
721
|
+
* Wave 12 (P0 #5): when unset, the runtime will lazily fetch and cache
|
|
722
|
+
* the server version the first time a version-gated operation is
|
|
723
|
+
* invoked. The fetch policy is controlled by {@link enforceVersion}.
|
|
584
724
|
*/
|
|
585
725
|
readonly serverVersion?: string;
|
|
586
726
|
/**
|
|
@@ -599,15 +739,75 @@ interface OllamaRuntimeOptions {
|
|
|
599
739
|
* `/v1/systemone`, OpenAI/Anthropic compat surfaces), validation is
|
|
600
740
|
* skipped silently.
|
|
601
741
|
*
|
|
602
|
-
* Response validation is intentionally NOT enabled — see
|
|
603
|
-
* the rationale (forward-compat with wire-format
|
|
742
|
+
* Response validation is intentionally NOT enabled by default — see
|
|
743
|
+
* ADR 0020 for the rationale (forward-compat with wire-format
|
|
744
|
+
* extensions).
|
|
745
|
+
*
|
|
746
|
+
* Wave 13: an opt-in `validateResponses` option is now available for
|
|
747
|
+
* operations where typed response semantics are the entire point
|
|
748
|
+
* (e.g. System One). When enabled, the runtime validates the HTTP
|
|
749
|
+
* response body against the operation's registered response schema
|
|
750
|
+
* before returning it to the caller. On failure, throws
|
|
751
|
+
* {@link OllamaResponseValidationError}.
|
|
604
752
|
*/
|
|
605
753
|
readonly validateRequests?: boolean;
|
|
754
|
+
/**
|
|
755
|
+
* Wave 13: when `true`, the runtime validates every response body
|
|
756
|
+
* against the operation's registered response schema before returning
|
|
757
|
+
* it. Defaults to `false` — opt-in. Only operations with a registered
|
|
758
|
+
* response schema are validated; others pass through unchanged.
|
|
759
|
+
*
|
|
760
|
+
* On validation failure, throws {@link OllamaResponseValidationError}
|
|
761
|
+
* with the Zod issues attached. The HTTP response is still consumed.
|
|
762
|
+
*
|
|
763
|
+
* Use this for operations where typed response semantics are critical
|
|
764
|
+
* (System One, structured output). Don't enable globally — legitimate
|
|
765
|
+
* forward-compat wire-format extensions would cause false rejections.
|
|
766
|
+
*/
|
|
767
|
+
readonly validateResponses?: boolean;
|
|
768
|
+
/**
|
|
769
|
+
* Policy for enforcing `constraints.minOllamaVersion` when
|
|
770
|
+
* {@link serverVersion} is not explicitly supplied.
|
|
771
|
+
*
|
|
772
|
+
* - `'auto'` (default): lazily fetch `/api/version` once and cache the
|
|
773
|
+
* result; subsequent version-gated invocations reuse the cached
|
|
774
|
+
* value. If the fetch fails, the operation is allowed through
|
|
775
|
+
* (fail-open) — the server will reject it if it truly doesn't
|
|
776
|
+
* support it.
|
|
777
|
+
* - `'strict'`: same as `'auto'`, but if the version fetch fails the
|
|
778
|
+
* invocation throws {@link OllamaServerVersionUnknownError} rather
|
|
779
|
+
* than fail-open. Use this when the caller wants hard guarantees
|
|
780
|
+
* that a version-gated operation will not be sent to a server that
|
|
781
|
+
* can't handle it.
|
|
782
|
+
* - `'off'`: never fetch `/api/version` automatically. The runtime
|
|
783
|
+
* only enforces the version constraint when {@link serverVersion}
|
|
784
|
+
* was explicitly supplied. Useful in tests that mock fetch and want
|
|
785
|
+
* to avoid spurious version probes.
|
|
786
|
+
*/
|
|
787
|
+
readonly enforceVersion?: 'auto' | 'strict' | 'off';
|
|
606
788
|
}
|
|
607
789
|
/** The runtime seam. */
|
|
608
790
|
declare class OllamaRuntime {
|
|
609
791
|
private readonly options;
|
|
792
|
+
/**
|
|
793
|
+
* Cached promise of the Ollama server version, populated lazily the first
|
|
794
|
+
* time a version-gated operation is invoked. `undefined` until then.
|
|
795
|
+
*
|
|
796
|
+
* Wave 12 (P0 #5): see {@link OllamaRuntimeOptions.enforceVersion}.
|
|
797
|
+
*/
|
|
798
|
+
private serverVersionCache;
|
|
610
799
|
constructor(options: OllamaRuntimeOptions);
|
|
800
|
+
/**
|
|
801
|
+
* Wave 15 (P0): resolve the HTTP backend for a given operation.
|
|
802
|
+
*
|
|
803
|
+
* Operations with a declared `host` (e.g. web search/fetch at
|
|
804
|
+
* https://ollama.com) must route to a HttpClient pointed at that host,
|
|
805
|
+
* not the default one. The runtime accepts an optional `cloudHttp`
|
|
806
|
+
* backend for this purpose — if the operation declares a host and no
|
|
807
|
+
* cloud backend is configured, the runtime throws rather than silently
|
|
808
|
+
* sending the request to the wrong server.
|
|
809
|
+
*/
|
|
810
|
+
private resolveHttpBackend;
|
|
611
811
|
/**
|
|
612
812
|
* Invoke an operation. Called by every generated API method.
|
|
613
813
|
*
|
|
@@ -616,6 +816,22 @@ declare class OllamaRuntime {
|
|
|
616
816
|
* class's overloads pick the right return type at compile time.
|
|
617
817
|
*/
|
|
618
818
|
invoke<T = unknown>(req: InvokeRequest): Promise<T>;
|
|
819
|
+
/**
|
|
820
|
+
* Apply environment + version guards before delegating to HttpClient.
|
|
821
|
+
*
|
|
822
|
+
* Throws {@link OllamaGenericClientError} when:
|
|
823
|
+
* - The operation is local-only and the runtime is in cloud mode.
|
|
824
|
+
* - The operation has `constraints.minOllamaVersion` and the server is older.
|
|
825
|
+
*
|
|
826
|
+
* Wave 12 (P0 #5): when `minOllamaVersion` is declared but the runtime's
|
|
827
|
+
* `serverVersion` is unknown AND `enforceVersion` is `'auto'` or
|
|
828
|
+
* `'strict'`, the runtime lazily fetches `/api/version` (cached on the
|
|
829
|
+
* runtime instance) so the constraint is actually enforced even when the
|
|
830
|
+
* caller didn't supply it. Previously the constraint was only enforced
|
|
831
|
+
* when `serverVersion` was manually supplied — meaning in practice it was
|
|
832
|
+
* almost never enforced.
|
|
833
|
+
*/
|
|
834
|
+
private assertOperationAllowed;
|
|
619
835
|
}
|
|
620
836
|
|
|
621
|
-
export {
|
|
837
|
+
export { OllamaResponseValidationError as $, type AbortableAsyncIterable as A, type BinaryBody as B, type ChatStreamResult as C, type DoneEvent as D, type ErrorEvent as E, type FetchLike as F, type GenerateStreamResult as G, HttpClient as H, type InvokeRequest as I, OllamaGenericClientError as J, OllamaIncompatibleModelError as K, type Logger as L, type Middleware as M, NANOS_PER_MS as N, OllamaRuntime as O, type ProgressStreamResult as P, OllamaMcpError as Q, type RequestLifecycleHook as R, type SchemaRef as S, type TokenUsage as T, OllamaModelRoutingError as U, OllamaNetworkError as V, OllamaNotFoundError as W, OllamaQuotaExceededError as X, OllamaRateLimitError as Y, OllamaRequestTooLargeError as Z, OllamaRequestValidationError as _, type OperationDefinition as a, OllamaServerError as a0, OllamaServerVersionUnknownError as a1, OllamaSkillInvalidError as a2, OllamaSkillNotFoundError as a3, OllamaTimeoutError as a4, OllamaToolTimeoutError as a5, OllamaToolValidationError as a6, OllamaUnsupportedCapabilityError as a7, type RequestContext as a8, type RequestLifecycleEvent as a9, type ResponseContext as aa, type SseEvent as ab, type ThinkingEvent as ac, type TokenEvent as ad, type ToolCallEvent as ae, composeMiddleware as af, createConsoleLogger as ag, extractUsage as ah, mapError as ai, parseSseStream as aj, type OllamaRuntimeOptions as b, type OllamaStreamEvent as c, type OllamaStreamEventType as d, type RawUsageSource as e, type HttpBody as f, type HttpClientOptions as g, type HttpRequestOptions as h, type LifecycleErrorEvent as i, type LifecycleRetryEvent as j, type LifecycleStartEvent as k, type LifecycleSuccessEvent as l, type LogFn as m, type MessageEvent as n, type MiddlewareContext as o, NANOS_PER_SECOND as p, NOOP_LOGGER as q, type NextFunction as r, OllamaAbortError as s, OllamaAgentMaxIterationsError as t, OllamaAgentMaxToolCallsError as u, OllamaAuthError as v, OllamaClientError as w, type OllamaClientErrorOptions as x, type OllamaErrorRequestContext as y, type OllamaErrorResponseContext as z };
|