@nemesis-oss/ollama-sdk 1.9.0 → 1.10.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/dist/index.d.cts CHANGED
@@ -1,12 +1,12 @@
1
- import { F as FetchLike, M as Middleware, L as Logger, R as RequestLifecycleHook, H as HttpClient, c as OllamaStreamEvent, A as AbortableAsyncIterable, d as OllamaStreamEventType, P as ProgressStreamResult, B as BinaryBody, O as OllamaRuntime, C as ChatStreamResult, G as GenerateStreamResult, e as RawUsageSource, T as TokenUsage } from './runtime-D2W9TfCJ.cjs';
2
- export { D as DoneEvent, E as ErrorEvent, f as HttpBody, g as HttpClientOptions, h as HttpRequestOptions, i as LifecycleErrorEvent, j as LifecycleRetryEvent, k as LifecycleStartEvent, l as LifecycleSuccessEvent, m as LogFn, n as MessageEvent, o as MiddlewareContext, N as NANOS_PER_MS, p as NANOS_PER_SECOND, q as NOOP_LOGGER, r as NextFunction, s as OllamaAbortError, t as OllamaAgentMaxIterationsError, u as OllamaAgentMaxToolCallsError, v as OllamaAuthError, w as OllamaBadGatewayError, x as OllamaClientError, y as OllamaClientErrorOptions, z as OllamaErrorRequestContext, J as OllamaErrorResponseContext, K as OllamaGenericClientError, Q as OllamaIncompatibleModelError, U as OllamaMcpError, V as OllamaModelRoutingError, W as OllamaNetworkError, X as OllamaNotFoundError, Y as OllamaOverloadedError, Z as OllamaQuotaExceededError, _ as OllamaRateLimitError, $ as OllamaRequestTooLargeError, a0 as OllamaRequestValidationError, a1 as OllamaResponseValidationError, a2 as OllamaServerError, a3 as OllamaServerVersionUnknownError, a4 as OllamaSkillInvalidError, a5 as OllamaSkillNotFoundError, a6 as OllamaStreamError, a7 as OllamaTimeoutError, a8 as OllamaToolTimeoutError, a9 as OllamaToolValidationError, aa as OllamaUnsupportedCapabilityError, ab as RequestContext, ac as RequestLifecycleEvent, ad as ResponseContext, ae as SseEvent, af as ThinkingEvent, ag as TokenEvent, ah as ToolCallEvent, ai as composeMiddleware, aj as createConsoleLogger, ak as extractUsage, al as mapError, am as parseSseStream } from './runtime-D2W9TfCJ.cjs';
3
- import { T as ThinkingMetadata, M as ModelResponse, S as ShowRequestOptions, a as ShowResponse, P as PullRequestOptions, b as ProgressResponse, c as PushRequestOptions, C as CreateRequestOptions, D as DeleteRequestOptions, d as StatusResponse, e as CopyRequestOptions, f as PsResponse, V as VersionResponse, R as RequestCancellationOptions, g as ToolParameters, h as ThinkValue, i as ToolCall, j as ChatRequestOptions, k as ModelOptions, l as ToolDefinition, F as FormatOption, m as ChatResponse, n as Message, G as GenerateRequestOptions, o as GenerateResponse, E as EmbedRequestOptions, p as EmbedResponse, q as EmbeddingsRequestOptions, r as EmbeddingsResponse, W as WebSearchRequestOptions, s as WebSearchResponse, t as WebFetchRequestOptions, u as WebFetchResponse, U as UsageRequestOptions, B as BalanceRequestOptions, v as VisionInput } from './types-DVcX_zMp.cjs';
4
- export { L as ListResponse, w as Logprob, x as LogprobToken, y as ModelDetails, z as Role, A as ToolCallFunction, H as ToolFunctionDefinition, I as ToolProperty, J as UsageRange, K as UsageScope, N as WebSearchResult, O as imageStringNeedsResolution, Q as resolveImageInput } from './types-DVcX_zMp.cjs';
1
+ import { F as FetchLike, M as Middleware, L as Logger, R as RequestLifecycleHook, H as HttpClient, c as OllamaStreamEvent, A as AbortableAsyncIterable, d as OllamaStreamEventType, P as ProgressStreamResult, B as BinaryBody, O as OllamaRuntime, C as ChatStreamResult, G as GenerateStreamResult, e as RawUsageSource, T as TokenUsage } from './runtime-BsdBbuOv.cjs';
2
+ export { D as DoneEvent, E as ErrorEvent, f as HttpBody, g as HttpClientOptions, h as HttpRequestOptions, i as LifecycleErrorEvent, j as LifecycleRetryEvent, k as LifecycleStartEvent, l as LifecycleSuccessEvent, m as LogFn, n as MessageEvent, o as MiddlewareContext, N as NANOS_PER_MS, p as NANOS_PER_SECOND, q as NOOP_LOGGER, r as NextFunction, s as OllamaAbortError, t as OllamaAgentMaxIterationsError, u as OllamaAgentMaxToolCallsError, v as OllamaAuthError, w as OllamaBadGatewayError, x as OllamaClientError, y as OllamaClientErrorOptions, z as OllamaErrorRequestContext, J as OllamaErrorResponseContext, K as OllamaGenericClientError, Q as OllamaIncompatibleModelError, U as OllamaMcpError, V as OllamaModelRoutingError, W as OllamaNetworkError, X as OllamaNotFoundError, Y as OllamaOverloadedError, Z as OllamaQuotaExceededError, _ as OllamaRateLimitError, $ as OllamaRequestTooLargeError, a0 as OllamaRequestValidationError, a1 as OllamaResponseValidationError, a2 as OllamaServerError, a3 as OllamaServerVersionUnknownError, a4 as OllamaSkillInvalidError, a5 as OllamaSkillNotFoundError, a6 as OllamaStreamError, a7 as OllamaTimeoutError, a8 as OllamaToolTimeoutError, a9 as OllamaToolValidationError, aa as OllamaUnsupportedCapabilityError, ab as RequestContext, ac as RequestLifecycleEvent, ad as ResponseContext, ae as SseEvent, af as ThinkingEvent, ag as TokenEvent, ah as ToolCallEvent, ai as composeMiddleware, aj as createConsoleLogger, ak as extractUsage, al as mapError, am as parseSseStream } from './runtime-BsdBbuOv.cjs';
3
+ import { T as ThinkingMetadata, M as ModelResponse, S as ShowRequestOptions, a as ShowResponse, P as PullRequestOptions, b as ProgressResponse, c as PushRequestOptions, C as CreateRequestOptions, D as DeleteRequestOptions, d as StatusResponse, e as CopyRequestOptions, f as PsResponse, V as VersionResponse, R as RequestCancellationOptions, g as ToolParameters, h as ThinkValue, i as ToolCall, j as ChatRequestOptions, k as ModelOptions, l as ToolDefinition, F as FormatOption, m as ChatResponse, n as Message, G as GenerateRequestOptions, o as GenerateResponse, E as EmbedRequestOptions, p as EmbedResponse, q as EmbeddingsRequestOptions, r as EmbeddingsResponse, W as WebSearchRequestOptions, s as WebSearchResponse, t as WebFetchRequestOptions, u as WebFetchResponse, U as UsageRequestOptions, B as BalanceRequestOptions, v as VisionInput } from './types-BtQexFpT.cjs';
4
+ export { L as ListResponse, w as Logprob, x as LogprobToken, y as ModelDetails, z as Role, A as ToolCallFunction, H as ToolFunctionDefinition, I as ToolProperty, J as UsageRange, K as UsageScope, N as WebSearchResult, O as imageStringNeedsResolution, Q as resolveImageInput } from './types-BtQexFpT.cjs';
5
5
  import { z } from 'zod';
6
- import { R as RequestRunner, S as SystemOneChoiceAnswer, o as SystemOneNoulAnswer, p as SystemOneScoreAnswer, q as SystemOneChoiceQuestion, r as SystemOneNoulQuestion, s as SystemOneScoreQuestion, t as SystemOneRequest$1, u as SystemOneResponse$1, v as SystemOneContent, N as NativeApi, w as OpenAICompatClient, x as AnthropicCompatClient } from './anthropic-BIh45UXj.cjs';
7
- export { y as AnthropicCacheControl, z as AnthropicContentBlock, B as AnthropicImageContentBlock, C as AnthropicMessage, n as AnthropicMessageStreamEvent, A as AnthropicMessagesRequest, m as AnthropicMessagesResponse, D as AnthropicMessagesStream, E as AnthropicMetadata, F as AnthropicOutputConfig, G as AnthropicRedactedThinkingContentBlock, H as AnthropicSystem, I as AnthropicSystemTextBlock, J as AnthropicTextContentBlock, K as AnthropicThinkingConfig, L as AnthropicThinkingContentBlock, M as AnthropicTool, P as AnthropicToolChoice, Q as AnthropicToolResultContentBlock, T as AnthropicToolUseContentBlock, U as AnthropicUnknownStreamEvent, V as OllamaAnthropicContentBlock, W as OllamaAnthropicMessage, X as OllamaAnthropicMessagesRequest, Y as OllamaAnthropicSystem, Z as OllamaAnthropicSystemTextBlock, _ as OllamaAnthropicTextContentBlock, $ as OllamaAnthropicThinkingConfig, a0 as OllamaAnthropicTool, a1 as OllamaAnthropicToolResultContentBlock, a2 as OllamaOpenAIChatCompletionRequest, a3 as OllamaOpenAICompletionRequest, a4 as OllamaOpenAIEmbeddingRequest, a5 as OllamaOpenAIReasoningEffort, a6 as OllamaOpenAIResponsesRequest, a7 as OpenAIChatCompletionChoice, b as OpenAIChatCompletionChunk, a8 as OpenAIChatCompletionChunkChoice, a9 as OpenAIChatCompletionDelta, O as OpenAIChatCompletionRequest, a as OpenAIChatCompletionResponse, aa as OpenAIChatCompletionStream, ab as OpenAICompletionChoice, e as OpenAICompletionChunk, c as OpenAICompletionRequest, d as OpenAICompletionResponse, ac as OpenAICompletionStream, ad as OpenAIContentPart, ae as OpenAIEmbeddingInput, af as OpenAIEmbeddingItem, f as OpenAIEmbeddingRequest, g as OpenAIEmbeddingResponse, ag as OpenAIFunctionDefinition, ah as OpenAIImageUrlContentPart, h as OpenAIListModelsResponse, ai as OpenAIMessage, i as OpenAIModelItem, aj as OpenAIReasoningEffort, ak as OpenAIResponseFormat, al as OpenAIResponsesCompletedEvent, am as OpenAIResponsesContentPartAddedEvent, an as OpenAIResponsesContentPartDoneEvent, ao as OpenAIResponsesCreatedEvent, ap as OpenAIResponsesError, aq as OpenAIResponsesEventBase, ar as OpenAIResponsesFailedEvent, as as OpenAIResponsesFunctionCallArgumentsDeltaEvent, at as OpenAIResponsesFunctionCallArgumentsDoneEvent, au as OpenAIResponsesInProgressEvent, av as OpenAIResponsesIncompleteDetails, aw as OpenAIResponsesIncompleteEvent, ax as OpenAIResponsesOutputContent, ay as OpenAIResponsesOutputFunctionCall, az as OpenAIResponsesOutputItem, aA as OpenAIResponsesOutputItemAddedEvent, aB as OpenAIResponsesOutputItemDoneEvent, aC as OpenAIResponsesOutputMessage, aD as OpenAIResponsesOutputReasoning, aE as OpenAIResponsesOutputRefusal, aF as OpenAIResponsesOutputTextContent, aG as OpenAIResponsesOutputTextDeltaEvent, aH as OpenAIResponsesOutputTextDoneEvent, aI as OpenAIResponsesQueuedEvent, aJ as OpenAIResponsesReasoningSummaryPartAddedEvent, aK as OpenAIResponsesReasoningSummaryPartDoneEvent, aL as OpenAIResponsesReasoningSummaryTextDeltaEvent, aM as OpenAIResponsesReasoningSummaryTextDoneEvent, aN as OpenAIResponsesReasoningTextDeltaEvent, aO as OpenAIResponsesReasoningTextDoneEvent, aP as OpenAIResponsesRefusalDeltaEvent, aQ as OpenAIResponsesRefusalDoneEvent, j as OpenAIResponsesRequest, k as OpenAIResponsesResponse, aR as OpenAIResponsesStatus, aS as OpenAIResponsesStream, aT as OpenAIResponsesStreamError, l as OpenAIResponsesStreamEvent, aU as OpenAIResponsesUsage, aV as OpenAIStreamOptions, aW as OpenAITextContentPart, aX as OpenAITool, aY as OpenAIToolCall, aZ as OpenAIToolCallDelta, a_ as OpenAIUsage, a$ as SystemOneConfidence, b0 as SystemOneProbabilities } from './anthropic-BIh45UXj.cjs';
8
- import { T as ToolHandler, a as Tool, A as AnyTool, b as ToolRegistry, c as ToolExecutionResult } from './compose-Dj6FdF2n.cjs';
9
- export { d as AppliedSkillResult, e as ApplySkillOptions, P as ParsedFrontmatter, S as Skill, f as SkillFrontmatter, g as SkillSummary, h as ToolExecutionContext, i as ToolExecutionFailure, j as ToolExecutionSuccess, k as ToolRegistryOptions, l as applySkill, p as parseFrontmatter } from './compose-Dj6FdF2n.cjs';
6
+ import { R as RequestRunner, S as SystemOneChoiceAnswer, o as SystemOneNoulAnswer, p as SystemOneScoreAnswer, q as SystemOneChoiceQuestion, r as SystemOneNoulQuestion, s as SystemOneScoreQuestion, t as SystemOneRequest$1, u as SystemOneResponse$1, v as SystemOneContent, N as NativeApi, w as OpenAICompatClient, x as AnthropicCompatClient } from './anthropic-DuE8M6Tz.cjs';
7
+ export { y as AnthropicCacheControl, z as AnthropicContentBlock, B as AnthropicImageContentBlock, C as AnthropicMessage, n as AnthropicMessageStreamEvent, A as AnthropicMessagesRequest, m as AnthropicMessagesResponse, D as AnthropicMessagesStream, E as AnthropicMetadata, F as AnthropicOutputConfig, G as AnthropicRedactedThinkingContentBlock, H as AnthropicSystem, I as AnthropicSystemTextBlock, J as AnthropicTextContentBlock, K as AnthropicThinkingConfig, L as AnthropicThinkingContentBlock, M as AnthropicTool, P as AnthropicToolChoice, Q as AnthropicToolResultContentBlock, T as AnthropicToolUseContentBlock, U as AnthropicUnknownStreamEvent, V as OllamaAnthropicContentBlock, W as OllamaAnthropicMessage, X as OllamaAnthropicMessagesRequest, Y as OllamaAnthropicSystem, Z as OllamaAnthropicSystemTextBlock, _ as OllamaAnthropicTextContentBlock, $ as OllamaAnthropicThinkingConfig, a0 as OllamaAnthropicTool, a1 as OllamaAnthropicToolResultContentBlock, a2 as OllamaOpenAIChatCompletionRequest, a3 as OllamaOpenAICompletionRequest, a4 as OllamaOpenAIEmbeddingRequest, a5 as OllamaOpenAIReasoningEffort, a6 as OllamaOpenAIResponsesRequest, a7 as OpenAIChatCompletionChoice, b as OpenAIChatCompletionChunk, a8 as OpenAIChatCompletionChunkChoice, a9 as OpenAIChatCompletionDelta, O as OpenAIChatCompletionRequest, a as OpenAIChatCompletionResponse, aa as OpenAIChatCompletionStream, ab as OpenAICompletionChoice, e as OpenAICompletionChunk, c as OpenAICompletionRequest, d as OpenAICompletionResponse, ac as OpenAICompletionStream, ad as OpenAIContentPart, ae as OpenAIEmbeddingInput, af as OpenAIEmbeddingItem, f as OpenAIEmbeddingRequest, g as OpenAIEmbeddingResponse, ag as OpenAIFunctionDefinition, ah as OpenAIImageUrlContentPart, h as OpenAIListModelsResponse, ai as OpenAIMessage, i as OpenAIModelItem, aj as OpenAIReasoningEffort, ak as OpenAIResponseFormat, al as OpenAIResponsesCompletedEvent, am as OpenAIResponsesContentPartAddedEvent, an as OpenAIResponsesContentPartDoneEvent, ao as OpenAIResponsesCreatedEvent, ap as OpenAIResponsesError, aq as OpenAIResponsesEventBase, ar as OpenAIResponsesFailedEvent, as as OpenAIResponsesFunctionCallArgumentsDeltaEvent, at as OpenAIResponsesFunctionCallArgumentsDoneEvent, au as OpenAIResponsesInProgressEvent, av as OpenAIResponsesIncompleteDetails, aw as OpenAIResponsesIncompleteEvent, ax as OpenAIResponsesOutputContent, ay as OpenAIResponsesOutputFunctionCall, az as OpenAIResponsesOutputItem, aA as OpenAIResponsesOutputItemAddedEvent, aB as OpenAIResponsesOutputItemDoneEvent, aC as OpenAIResponsesOutputMessage, aD as OpenAIResponsesOutputReasoning, aE as OpenAIResponsesOutputRefusal, aF as OpenAIResponsesOutputTextContent, aG as OpenAIResponsesOutputTextDeltaEvent, aH as OpenAIResponsesOutputTextDoneEvent, aI as OpenAIResponsesQueuedEvent, aJ as OpenAIResponsesReasoningSummaryPartAddedEvent, aK as OpenAIResponsesReasoningSummaryPartDoneEvent, aL as OpenAIResponsesReasoningSummaryTextDeltaEvent, aM as OpenAIResponsesReasoningSummaryTextDoneEvent, aN as OpenAIResponsesReasoningTextDeltaEvent, aO as OpenAIResponsesReasoningTextDoneEvent, aP as OpenAIResponsesRefusalDeltaEvent, aQ as OpenAIResponsesRefusalDoneEvent, j as OpenAIResponsesRequest, k as OpenAIResponsesResponse, aR as OpenAIResponsesStatus, aS as OpenAIResponsesStream, aT as OpenAIResponsesStreamError, l as OpenAIResponsesStreamEvent, aU as OpenAIResponsesUsage, aV as OpenAIStreamOptions, aW as OpenAITextContentPart, aX as OpenAITool, aY as OpenAIToolCall, aZ as OpenAIToolCallDelta, a_ as OpenAIUsage, a$ as SystemOneConfidence, b0 as SystemOneProbabilities } from './anthropic-DuE8M6Tz.cjs';
8
+ import { T as ToolHandler, a as Tool, A as AnyTool, b as ToolRegistry, c as ToolExecutionResult } from './compose-lt-Qz3lI.cjs';
9
+ export { d as AppliedSkillResult, e as ApplySkillOptions, P as ParsedFrontmatter, S as Skill, f as SkillFrontmatter, g as SkillSummary, h as ToolExecutionContext, i as ToolExecutionFailure, j as ToolExecutionSuccess, k as ToolRegistryOptions, l as applySkill, p as parseFrontmatter } from './compose-lt-Qz3lI.cjs';
10
10
  import { M as McpClientLike, a as McpToolDescriptor, b as McpTask, c as McpCallToolResult } from './types-CI-gM2u5.cjs';
11
11
  export { d as McpContentBlock, e as McpCreateTaskResult, f as McpElicitationFormRequest, g as McpElicitationHandlers, h as McpElicitationRequest, i as McpElicitationResult, j as McpElicitationUrlRequest, k as McpIcon, l as McpInputRequiredResult, m as McpListToolsParams, n as McpListToolsResult, o as McpRequestOptions, p as McpServerCapabilities, q as McpTaskMethod, r as McpTaskRequest, s as McpTaskStatus, t as McpToolAnnotations, u as McpToolCallResult, v as McpToolExecution } from './types-CI-gM2u5.cjs';
12
12
  import * as Otel from '@opentelemetry/api';
@@ -981,6 +981,131 @@ declare class ConversationSession {
981
981
  reset(): void;
982
982
  }
983
983
 
984
+ /**
985
+ * Batch-constrained embedding generation for high-volume ingestion pipelines.
986
+ *
987
+ * Ollama's `/api/embed` accepts an array of inputs, but two independent limits
988
+ * make naive usage fragile at corpus scale:
989
+ *
990
+ * 1. **Concurrency.** `Promise.all(inputs.map(...))` fires every request at
991
+ * once; against a local Ollama daemon this contends sockets, saturates the
992
+ * request queue (`OLLAMA_MAX_QUEUE`, surfacing as 503 `overloaded`), and —
993
+ * worst case — exhausts GPU VRAM as the model instance serves N prompts
994
+ * simultaneously.
995
+ * 2. **Context window.** Ollama truncates any input string longer than the
996
+ * model's context window (`num_ctx`) *silently* unless `truncate: false` is
997
+ * set — degraded vectors with no error, no warning, nothing on the wire.
998
+ *
999
+ * {@link batchEmbed} addresses the first with a fixed-size worker pool over
1000
+ * `client.embed()` (so every batch still rides the client's full pipeline:
1001
+ * failover, retry, auth, logging, telemetry). The client-level
1002
+ * `embedBatch()` wrapper addresses the second with a pre-flight per-string
1003
+ * token estimate against the resolved `num_ctx` window (see
1004
+ * {@link findOversizedEmbedInputs}).
1005
+ *
1006
+ * Semantics:
1007
+ * - **Order-preserving** — result index `i` is always the embedding of
1008
+ * `input[i]`, regardless of which batch completed first.
1009
+ * - **Fail-fast** — the first batch error aborts every sibling in-flight
1010
+ * batch (surfaces the *original* error, not the derived aborts) and rejects
1011
+ * the whole operation. Vector indexing that half-succeeds is a corrupted
1012
+ * index; callers re-running an ingestion prefer all-or-nothing.
1013
+ * - **Abortable** — the caller's `signal` cancels queued and in-flight batches
1014
+ * alike and rejects with `code: 'aborted'`.
1015
+ */
1016
+
1017
+ /**
1018
+ * Default number of input strings per `/api/embed` request. 32 keeps a single
1019
+ * request's prompt comfortably inside typical embedding-model context windows
1020
+ * (2048+) while amortizing HTTP overhead across the corpus.
1021
+ */
1022
+ declare const DEFAULT_EMBED_BATCH_SIZE = 32;
1023
+ /**
1024
+ * Default number of batches kept in flight concurrently. 3 is deliberately
1025
+ * conservative: a local Ollama daemon serves one model instance per GPU, so
1026
+ * 3 concurrent embedding prompts bound queue depth and VRAM pressure without
1027
+ * leaving the hardware idle between batches. Raise for multi-endpoint
1028
+ * clients or remote daemons; lower (to 1) for constrained devices.
1029
+ */
1030
+ declare const DEFAULT_EMBED_CONCURRENCY = 3;
1031
+ interface EmbedBatchOptions {
1032
+ /** Model to embed with (e.g. `'nomic-embed-text:latest'`). */
1033
+ readonly model: string;
1034
+ /** Input strings, in corpus order. Result index `i` matches `input[i]`. */
1035
+ readonly input: readonly string[];
1036
+ /**
1037
+ * Inputs per `/api/embed` request. Default {@link DEFAULT_EMBED_BATCH_SIZE}
1038
+ * (32). Must be a positive integer.
1039
+ */
1040
+ readonly batchSize?: number | undefined;
1041
+ /**
1042
+ * Batches kept in flight simultaneously. Default
1043
+ * {@link DEFAULT_EMBED_CONCURRENCY} (3). Must be a positive integer.
1044
+ */
1045
+ readonly concurrency?: number | undefined;
1046
+ /** Passed through to each batch request — `false` makes oversized inputs
1047
+ * a server-side error instead of a silent truncation. */
1048
+ readonly truncate?: boolean | undefined;
1049
+ /** Passed through to each batch request (dimensionality truncation). */
1050
+ readonly dimensions?: number | undefined;
1051
+ /** Passed through to each batch request (model unload policy). */
1052
+ readonly keep_alive?: string | number | undefined;
1053
+ /** Ollama model options (`num_ctx`, …) passed through to each batch request. */
1054
+ readonly options?: ModelOptions | undefined;
1055
+ /** Aborts the whole batch operation — queued and in-flight alike. */
1056
+ readonly signal?: AbortSignal | undefined;
1057
+ /** Per-request timeout applied to each individual batch request. */
1058
+ readonly timeoutMs?: number | undefined;
1059
+ /**
1060
+ * Progress callback invoked after each successfully embedded batch as
1061
+ * `onBatchComplete(completedBatches, totalBatches)`. Never called after the
1062
+ * operation rejects.
1063
+ */
1064
+ readonly onBatchComplete?: ((completedBatches: number, totalBatches: number) => void) | undefined;
1065
+ }
1066
+ interface EmbedBatchResult {
1067
+ readonly model: string;
1068
+ /**
1069
+ * Embeddings in input order — `embeddings[i]` corresponds to
1070
+ * `options.input[i]`, independent of batch completion order.
1071
+ */
1072
+ readonly embeddings: readonly (readonly number[])[];
1073
+ /** Number of `/api/embed` requests the corpus was split into. */
1074
+ readonly batchCount: number;
1075
+ }
1076
+ /** An input string whose estimated token count exceeds the context window. */
1077
+ interface OversizedEmbedInput {
1078
+ /** Index into the input array. */
1079
+ readonly index: number;
1080
+ /** Estimated token count for `input[index]`. */
1081
+ readonly estimate: number;
1082
+ }
1083
+ /**
1084
+ * Finds input strings whose heuristic token estimate exceeds `contextLength`
1085
+ * (typically the resolved `num_ctx`). Unlike chat/generate pre-flight there is
1086
+ * no warning margin and no output-token headroom: an embedding request's
1087
+ * prompt IS the whole input, so the exact window is the trip point, and
1088
+ * crossing it means silent truncation (or, with `truncate: false`, a
1089
+ * server-side rejection).
1090
+ */
1091
+ declare function findOversizedEmbedInputs(input: readonly string[], contextLength: number): OversizedEmbedInput[];
1092
+ /**
1093
+ * Builds the warn/throw message for oversized embed inputs (mirrors
1094
+ * `contextWarningMessage` for chat/generate).
1095
+ */
1096
+ declare function embedBatchOverflowMessage(oversized: readonly OversizedEmbedInput[], totalInputs: number, contextLength: number, truncateFalse: boolean): string;
1097
+ /**
1098
+ * Splits `input` into `batchSize` slices and embeds them through `client.embed()`
1099
+ * with at most `concurrency` batches in flight. Order-preserving and fail-fast —
1100
+ * see the module doc for the full semantics.
1101
+ *
1102
+ * Prefer the {@link OllamaClient.embedBatch} wrapper, which additionally
1103
+ * injects `defaultContextLength` as `num_ctx` and enforces the client's
1104
+ * `onContextOverflow` policy against per-string estimates before any request
1105
+ * is sent.
1106
+ */
1107
+ declare function batchEmbed(client: OllamaClient, options: EmbedBatchOptions): Promise<EmbedBatchResult>;
1108
+
984
1109
  /**
985
1110
  * Ergonomic System One types — key-safe generics on top of the generated
986
1111
  * contract models.
@@ -1425,6 +1550,14 @@ declare class OllamaClient {
1425
1550
  private readonly contextWarningThreshold;
1426
1551
  /** Configured overflow policy — `'warn'` (default) or `'throw'`. */
1427
1552
  private readonly onContextOverflow;
1553
+ /**
1554
+ * Controllers for every in-flight request and active stream managed by this
1555
+ * client — see {@link OllamaClient.destroy} and {@link createRequestScope}.
1556
+ * Entries live for exactly as long as the underlying work does: until the
1557
+ * response settles (requests) or the stream's `finalResult` settles
1558
+ * (streams, via `executeWithFailover`'s `holdUntil` release path).
1559
+ */
1560
+ private readonly activeRequests;
1428
1561
  constructor(config?: OllamaClientConfig);
1429
1562
  get modelsClient(): ModelsClient;
1430
1563
  /**
@@ -1523,6 +1656,17 @@ declare class OllamaClient {
1523
1656
  * reference when there's nothing to inject (the common case).
1524
1657
  */
1525
1658
  private injectDefaultContextLength;
1659
+ /**
1660
+ * Creates the per-request abort scope registered with {@link destroy}:
1661
+ * a controller that fires when the caller's `signal` aborts OR when
1662
+ * `destroy()` runs, whichever comes first. `dispose()` removes the
1663
+ * registration when the work it guards settles — for plain requests when
1664
+ * the response settles, for streams when `finalResult` settles (the same
1665
+ * moment `executeWithFailover`'s `holdUntil` releases the endpoint slot),
1666
+ * so a destroy() can tear down a stream mid-consumption but never outlives
1667
+ * one that already finished.
1668
+ */
1669
+ private createRequestScope;
1526
1670
  /**
1527
1671
  * Fail-fast guard for `format` (structured output) requests: throws before any network
1528
1672
  * call if the candidate endpoint is inferred as Ollama Cloud, which does not currently
@@ -1585,6 +1729,36 @@ declare class OllamaClient {
1585
1729
  generateWithSchema<T>(req: Omit<GenerateRequestOptions, 'stream' | 'format'>, schema: z.ZodType<T>): Promise<T>;
1586
1730
  embed(req: EmbedRequestOptions): Promise<EmbedResponse>;
1587
1731
  embedText(model: string, input: string | readonly string[]): Promise<readonly (readonly number[])[]>;
1732
+ /**
1733
+ * Batch-constrained, order-preserving embedding generation for large
1734
+ * corpora — the safe building block for RAG/vector-index ingestion at
1735
+ * scale. Splits `input` into `batchSize` slices and embeds them through
1736
+ * {@link embed} with at most `concurrency` batches in flight (defaults:
1737
+ * 32 × 3), so `Promise.all`-style floods that OOM local daemons and
1738
+ * saturate `OLLAMA_MAX_QUEUE` can't happen by accident. Fail-fast: the
1739
+ * first batch error aborts every sibling in-flight batch and rejects the
1740
+ * whole operation with the original error.
1741
+ *
1742
+ * Before any request is sent, `defaultContextLength` is injected as
1743
+ * `num_ctx` (same as chat/generate) and each input string's token estimate
1744
+ * is checked against the resolved window: Ollama silently truncates
1745
+ * oversized embedding inputs by default, so the client warns (or throws,
1746
+ * under `onContextOverflow: 'throw'`) with the offending indexes — see
1747
+ * `src/embed-batch.ts` for the exact trip point (no margin: an embedding
1748
+ * prompt IS the whole input).
1749
+ *
1750
+ * ```ts
1751
+ * const { embeddings, batchCount } = await client.embedBatch({
1752
+ * model: 'nomic-embed-text:latest',
1753
+ * input: corpus, // e.g. 50k chunks
1754
+ * batchSize: 32, // inputs per /api/embed request
1755
+ * concurrency: 3, // batches in flight
1756
+ * onBatchComplete: (done, total) => progress.log(`${done}/${total}`),
1757
+ * });
1758
+ * // embeddings[i] always corresponds to corpus[i]
1759
+ * ```
1760
+ */
1761
+ embedBatch(options: EmbedBatchOptions): Promise<EmbedBatchResult>;
1588
1762
  /**
1589
1763
  * @deprecated Ollama's `/api/embeddings` endpoint has been superseded by `/api/embed`
1590
1764
  * (exposed here as {@link OllamaClient.embed}), which additionally supports batch
@@ -1710,6 +1884,26 @@ declare class OllamaClient {
1710
1884
  runtimeMode(): RuntimeMode;
1711
1885
  healthCheck(): Promise<EndpointHealthCheckResult[]>;
1712
1886
  endpointStatus(): EndpointHealth[];
1887
+ /**
1888
+ * Immediately aborts every in-flight request and active stream managed by
1889
+ * this client — the clean teardown path for short-lived processes, CLI
1890
+ * runners, and `node:worker_threads` tasks where dangling fetch bodies,
1891
+ * unconsumed stream readers, or queued capacity waiters would otherwise
1892
+ * keep the event loop (and thus the thread/process) alive.
1893
+ *
1894
+ * Every aborted operation rejects with an {@link OllamaAbortError}
1895
+ * (`code: 'aborted'`) carrying `reason` as its message — including requests
1896
+ * still queued behind `maxConcurrentPerEndpoint`, not just dispatched ones.
1897
+ * Streams reject their `finalResult` and release their endpoint slots.
1898
+ *
1899
+ * Idempotent: calling it again (or on a client with nothing in flight)
1900
+ * is a no-op that returns `0`. The client remains usable afterward —
1901
+ * `destroy()` is a drain, not a permanent disable; callers that want a
1902
+ * permanently-dead client should discard the instance.
1903
+ *
1904
+ * @returns the number of in-flight operations that were aborted.
1905
+ */
1906
+ destroy(reason?: string): number;
1713
1907
  get openai(): OpenAICompatClient;
1714
1908
  get anthropic(): AnthropicCompatClient;
1715
1909
  }
@@ -2657,4 +2851,4 @@ declare const OLLAMA_FALLBACK_CONTEXT_LENGTH = 2048;
2657
2851
  */
2658
2852
  declare function contextWarningMessage(check: ContextCheck, kind: 'chat' | 'generate'): string;
2659
2853
 
2660
- export { ATTR_GEN_AI_OPERATION_NAME, ATTR_GEN_AI_REQUEST_MODEL, ATTR_GEN_AI_RESPONSE_MODEL, ATTR_GEN_AI_SYSTEM, ATTR_GEN_AI_TOOL_CALL_ID, ATTR_GEN_AI_TOOL_NAME, ATTR_GEN_AI_USAGE_INPUT_TOKENS, ATTR_GEN_AI_USAGE_OUTPUT_TOKENS, ATTR_HTTP_REQUEST_METHOD, ATTR_HTTP_RESPONSE_STATUS_CODE, ATTR_OLLAMA_AGENT_ITERATION, ATTR_OLLAMA_AGENT_MAX_ITERATIONS, ATTR_OLLAMA_ENDPOINT_ATTEMPT, ATTR_OLLAMA_ENDPOINT_NAME, ATTR_SERVER_ADDRESS, ATTR_SERVER_PORT, ATTR_URL_FULL, AbortableAsyncIterable, Agent, type AgentChatClient, type AgentConfig, type AgentHooks, type AgentResult, type AgentRunInput, type AgentTurn, type AnswerFor, AnthropicCompatClient, AnyTool, type BackoffOptions, BalanceRequestOptions, type BalanceResponse, type BlobUploadResult, ChatRequestOptions, ChatResponse, ChatStreamResult, type ChoiceDecision, type ContextCheck, type ContextCheckOptions, type ContextWindowSource, type ConversationSendOptions, ConversationSession, type ConversationSessionOptions, CopyRequestOptions, CreateRequestOptions, type CumulativeCacheStats, DEFAULT_BACKOFF, DEFAULT_BASE_URL, DEFAULT_CONTEXT_WARNING_THRESHOLD, DEFAULT_FAILOVER_CODES, DEFAULT_FETCH_BACKOFF_CONFIG, DEFAULT_RETRY_CONFIG, DEFAULT_TIMEOUT_MS, type Decision, type DefineToolOptions, DeleteRequestOptions, EmbedRequestOptions, EmbedResponse, EmbeddingsRequestOptions, EmbeddingsResponse, type EndpointHealth, type EndpointHealthCheckResult, EndpointRegistry, type EndpointRegistryOptions, FetchLike, type FetchWithBackoffConfig, FormatOption, GEN_AI_SYSTEM_OLLAMA, GenerateRequestOptions, GenerateResponse, GenerateStreamResult, HttpClient, IMAGE_TOKEN_ESTIMATE, type IncludedBalance, KEEP_ALIVE_INDEFINITE, KEEP_ALIVE_UNLOAD, KNOWN_DONE_REASONS, type KeepAlive, type KnownDoneReason, type LegacyBalanceLimit, type LegacyIncludedBalance, type LoadMcpToolsOptions, Logger, MAX_SYSTEM_ONE_IMAGES_BYTES, MAX_SYSTEM_ONE_REQUEST_BYTES, McpBridge, type McpBridgeOptions, McpCallToolResult, McpClientLike, McpTask, McpToolDescriptor, Message, Middleware, type ModelCapabilities, ModelOptions, ModelResponse, ModelsClient, type NoulDecision, OLLAMA_CLOUD_BASE_URL, OLLAMA_FALLBACK_CONTEXT_LENGTH, OllamaClient, type OllamaClientConfig, type OllamaCloudFreeTierQuotaBudgets, type OllamaCredentialConfig, type OllamaEndpoint, OllamaStream, OllamaStreamEvent, OllamaStreamEventType, OpenAICompatClient, type ParallelToolCallBehavior, ProgressResponse, ProgressStreamResult, PsResponse, PullRequestOptions, PushRequestOptions, QuotaManager, type QuotaManagerOptions, type QuotaWindowConfig, type QuotaWindowStatus, RETRYABLE_STATUS_CODES, type RankResult, RawUsageSource, RequestCancellationOptions, RequestLifecycleHook, RequestRunner, type ResponsesCreateRequest, type ResponsesCreateResponse, ResponsesModule, type ResponsesReasoningEffort, type ResponsesStreamEvent, type ResponsesToolDefinition, type ResponsesUsage, type RetryConfig, type RuntimeMode, type ScoreDecision, type SessionTurn, ShowRequestOptions, ShowResponse, type SpanAttributeValue, type SpanAttributes, StatusResponse, type SupportedSchema, type SystemOneAnswer, type SystemOneAnswers, SystemOneChoiceAnswer, SystemOneChoiceQuestion, SystemOneContent, SystemOneNoulAnswer, SystemOneNoulQuestion, type SystemOneQuestion, type SystemOneQuestions, type SystemOneRequest, type SystemOneResponse, SystemOneScoreAnswer, SystemOneScoreQuestion, type SystemOneUsage, ThinkValue, ThinkingMetadata, type TimeoutSignal, TokenUsage, Tool, ToolCall, ToolCallAccumulator, ToolDefinition, ToolExecutionResult, ToolHandler, ToolParameters, ToolRegistry, type TurnCacheStats, type UsageBucket, type UsageMetrics, UsageRequestOptions, type UsageResponse, VersionResponse, VisionInput, WebFetchRequestOptions, WebFetchResponse, WebSearchRequestOptions, WebSearchResponse, addSpanEvent, calculateBackoff, checkChatContext, checkEndpointHealth, checkGenerateContext, contextWarningMessage, createDecision, createOllamaCloudFreeTierQuota, createTimeoutSignal, defineTool, detectModelCapabilities, encodeImage, estimateChatRequestTokens, estimateGenerateRequestTokens, estimateSystemOneRequestBytes, estimateTokens, fetchWithBackoff, inferRuntimeMode, isKeepAliveSugar, isKnownDoneReason, isSameToolCall, listAllMcpTools, listAvailableModels, loadMcpTools, mergeToolCall, mergeToolCallArgumentsString, mergeToolCallArrays, normalizeChatStream, normalizeGenerateStream, normalizeKeepAlive, normalizeProgressStream, parseNdjsonStream, parseStructuredOutput, registerMcpTools, resolveCredentialEndpoints, setSpanError, toDataStream, toResponse, toTextStream, withRetry, withSpan, zodToJsonSchema };
2854
+ export { ATTR_GEN_AI_OPERATION_NAME, ATTR_GEN_AI_REQUEST_MODEL, ATTR_GEN_AI_RESPONSE_MODEL, ATTR_GEN_AI_SYSTEM, ATTR_GEN_AI_TOOL_CALL_ID, ATTR_GEN_AI_TOOL_NAME, ATTR_GEN_AI_USAGE_INPUT_TOKENS, ATTR_GEN_AI_USAGE_OUTPUT_TOKENS, ATTR_HTTP_REQUEST_METHOD, ATTR_HTTP_RESPONSE_STATUS_CODE, ATTR_OLLAMA_AGENT_ITERATION, ATTR_OLLAMA_AGENT_MAX_ITERATIONS, ATTR_OLLAMA_ENDPOINT_ATTEMPT, ATTR_OLLAMA_ENDPOINT_NAME, ATTR_SERVER_ADDRESS, ATTR_SERVER_PORT, ATTR_URL_FULL, AbortableAsyncIterable, Agent, type AgentChatClient, type AgentConfig, type AgentHooks, type AgentResult, type AgentRunInput, type AgentTurn, type AnswerFor, AnthropicCompatClient, AnyTool, type BackoffOptions, BalanceRequestOptions, type BalanceResponse, type BlobUploadResult, ChatRequestOptions, ChatResponse, ChatStreamResult, type ChoiceDecision, type ContextCheck, type ContextCheckOptions, type ContextWindowSource, type ConversationSendOptions, ConversationSession, type ConversationSessionOptions, CopyRequestOptions, CreateRequestOptions, type CumulativeCacheStats, DEFAULT_BACKOFF, DEFAULT_BASE_URL, DEFAULT_CONTEXT_WARNING_THRESHOLD, DEFAULT_EMBED_BATCH_SIZE, DEFAULT_EMBED_CONCURRENCY, DEFAULT_FAILOVER_CODES, DEFAULT_FETCH_BACKOFF_CONFIG, DEFAULT_RETRY_CONFIG, DEFAULT_TIMEOUT_MS, type Decision, type DefineToolOptions, DeleteRequestOptions, type EmbedBatchOptions, type EmbedBatchResult, EmbedRequestOptions, EmbedResponse, EmbeddingsRequestOptions, EmbeddingsResponse, type EndpointHealth, type EndpointHealthCheckResult, EndpointRegistry, type EndpointRegistryOptions, FetchLike, type FetchWithBackoffConfig, FormatOption, GEN_AI_SYSTEM_OLLAMA, GenerateRequestOptions, GenerateResponse, GenerateStreamResult, HttpClient, IMAGE_TOKEN_ESTIMATE, type IncludedBalance, KEEP_ALIVE_INDEFINITE, KEEP_ALIVE_UNLOAD, KNOWN_DONE_REASONS, type KeepAlive, type KnownDoneReason, type LegacyBalanceLimit, type LegacyIncludedBalance, type LoadMcpToolsOptions, Logger, MAX_SYSTEM_ONE_IMAGES_BYTES, MAX_SYSTEM_ONE_REQUEST_BYTES, McpBridge, type McpBridgeOptions, McpCallToolResult, McpClientLike, McpTask, McpToolDescriptor, Message, Middleware, type ModelCapabilities, ModelOptions, ModelResponse, ModelsClient, type NoulDecision, OLLAMA_CLOUD_BASE_URL, OLLAMA_FALLBACK_CONTEXT_LENGTH, OllamaClient, type OllamaClientConfig, type OllamaCloudFreeTierQuotaBudgets, type OllamaCredentialConfig, type OllamaEndpoint, OllamaStream, OllamaStreamEvent, OllamaStreamEventType, OpenAICompatClient, type OversizedEmbedInput, type ParallelToolCallBehavior, ProgressResponse, ProgressStreamResult, PsResponse, PullRequestOptions, PushRequestOptions, QuotaManager, type QuotaManagerOptions, type QuotaWindowConfig, type QuotaWindowStatus, RETRYABLE_STATUS_CODES, type RankResult, RawUsageSource, RequestCancellationOptions, RequestLifecycleHook, RequestRunner, type ResponsesCreateRequest, type ResponsesCreateResponse, ResponsesModule, type ResponsesReasoningEffort, type ResponsesStreamEvent, type ResponsesToolDefinition, type ResponsesUsage, type RetryConfig, type RuntimeMode, type ScoreDecision, type SessionTurn, ShowRequestOptions, ShowResponse, type SpanAttributeValue, type SpanAttributes, StatusResponse, type SupportedSchema, type SystemOneAnswer, type SystemOneAnswers, SystemOneChoiceAnswer, SystemOneChoiceQuestion, SystemOneContent, SystemOneNoulAnswer, SystemOneNoulQuestion, type SystemOneQuestion, type SystemOneQuestions, type SystemOneRequest, type SystemOneResponse, SystemOneScoreAnswer, SystemOneScoreQuestion, type SystemOneUsage, ThinkValue, ThinkingMetadata, type TimeoutSignal, TokenUsage, Tool, ToolCall, ToolCallAccumulator, ToolDefinition, ToolExecutionResult, ToolHandler, ToolParameters, ToolRegistry, type TurnCacheStats, type UsageBucket, type UsageMetrics, UsageRequestOptions, type UsageResponse, VersionResponse, VisionInput, WebFetchRequestOptions, WebFetchResponse, WebSearchRequestOptions, WebSearchResponse, addSpanEvent, batchEmbed, calculateBackoff, checkChatContext, checkEndpointHealth, checkGenerateContext, contextWarningMessage, createDecision, createOllamaCloudFreeTierQuota, createTimeoutSignal, defineTool, detectModelCapabilities, embedBatchOverflowMessage, encodeImage, estimateChatRequestTokens, estimateGenerateRequestTokens, estimateSystemOneRequestBytes, estimateTokens, fetchWithBackoff, findOversizedEmbedInputs, inferRuntimeMode, isKeepAliveSugar, isKnownDoneReason, isSameToolCall, listAllMcpTools, listAvailableModels, loadMcpTools, mergeToolCall, mergeToolCallArgumentsString, mergeToolCallArrays, normalizeChatStream, normalizeGenerateStream, normalizeKeepAlive, normalizeProgressStream, parseNdjsonStream, parseStructuredOutput, registerMcpTools, resolveCredentialEndpoints, setSpanError, toDataStream, toResponse, toTextStream, withRetry, withSpan, zodToJsonSchema };
package/dist/index.d.ts CHANGED
@@ -1,12 +1,12 @@
1
- import { F as FetchLike, M as Middleware, L as Logger, R as RequestLifecycleHook, H as HttpClient, c as OllamaStreamEvent, A as AbortableAsyncIterable, d as OllamaStreamEventType, P as ProgressStreamResult, B as BinaryBody, O as OllamaRuntime, C as ChatStreamResult, G as GenerateStreamResult, e as RawUsageSource, T as TokenUsage } from './runtime-C3rfpkZw.js';
2
- export { D as DoneEvent, E as ErrorEvent, f as HttpBody, g as HttpClientOptions, h as HttpRequestOptions, i as LifecycleErrorEvent, j as LifecycleRetryEvent, k as LifecycleStartEvent, l as LifecycleSuccessEvent, m as LogFn, n as MessageEvent, o as MiddlewareContext, N as NANOS_PER_MS, p as NANOS_PER_SECOND, q as NOOP_LOGGER, r as NextFunction, s as OllamaAbortError, t as OllamaAgentMaxIterationsError, u as OllamaAgentMaxToolCallsError, v as OllamaAuthError, w as OllamaBadGatewayError, x as OllamaClientError, y as OllamaClientErrorOptions, z as OllamaErrorRequestContext, J as OllamaErrorResponseContext, K as OllamaGenericClientError, Q as OllamaIncompatibleModelError, U as OllamaMcpError, V as OllamaModelRoutingError, W as OllamaNetworkError, X as OllamaNotFoundError, Y as OllamaOverloadedError, Z as OllamaQuotaExceededError, _ as OllamaRateLimitError, $ as OllamaRequestTooLargeError, a0 as OllamaRequestValidationError, a1 as OllamaResponseValidationError, a2 as OllamaServerError, a3 as OllamaServerVersionUnknownError, a4 as OllamaSkillInvalidError, a5 as OllamaSkillNotFoundError, a6 as OllamaStreamError, a7 as OllamaTimeoutError, a8 as OllamaToolTimeoutError, a9 as OllamaToolValidationError, aa as OllamaUnsupportedCapabilityError, ab as RequestContext, ac as RequestLifecycleEvent, ad as ResponseContext, ae as SseEvent, af as ThinkingEvent, ag as TokenEvent, ah as ToolCallEvent, ai as composeMiddleware, aj as createConsoleLogger, ak as extractUsage, al as mapError, am as parseSseStream } from './runtime-C3rfpkZw.js';
3
- import { T as ThinkingMetadata, M as ModelResponse, S as ShowRequestOptions, a as ShowResponse, P as PullRequestOptions, b as ProgressResponse, c as PushRequestOptions, C as CreateRequestOptions, D as DeleteRequestOptions, d as StatusResponse, e as CopyRequestOptions, f as PsResponse, V as VersionResponse, R as RequestCancellationOptions, g as ToolParameters, h as ThinkValue, i as ToolCall, j as ChatRequestOptions, k as ModelOptions, l as ToolDefinition, F as FormatOption, m as ChatResponse, n as Message, G as GenerateRequestOptions, o as GenerateResponse, E as EmbedRequestOptions, p as EmbedResponse, q as EmbeddingsRequestOptions, r as EmbeddingsResponse, W as WebSearchRequestOptions, s as WebSearchResponse, t as WebFetchRequestOptions, u as WebFetchResponse, U as UsageRequestOptions, B as BalanceRequestOptions, v as VisionInput } from './types-DVcX_zMp.js';
4
- export { L as ListResponse, w as Logprob, x as LogprobToken, y as ModelDetails, z as Role, A as ToolCallFunction, H as ToolFunctionDefinition, I as ToolProperty, J as UsageRange, K as UsageScope, N as WebSearchResult, O as imageStringNeedsResolution, Q as resolveImageInput } from './types-DVcX_zMp.js';
1
+ import { F as FetchLike, M as Middleware, L as Logger, R as RequestLifecycleHook, H as HttpClient, c as OllamaStreamEvent, A as AbortableAsyncIterable, d as OllamaStreamEventType, P as ProgressStreamResult, B as BinaryBody, O as OllamaRuntime, C as ChatStreamResult, G as GenerateStreamResult, e as RawUsageSource, T as TokenUsage } from './runtime-BV9SK_cf.js';
2
+ export { D as DoneEvent, E as ErrorEvent, f as HttpBody, g as HttpClientOptions, h as HttpRequestOptions, i as LifecycleErrorEvent, j as LifecycleRetryEvent, k as LifecycleStartEvent, l as LifecycleSuccessEvent, m as LogFn, n as MessageEvent, o as MiddlewareContext, N as NANOS_PER_MS, p as NANOS_PER_SECOND, q as NOOP_LOGGER, r as NextFunction, s as OllamaAbortError, t as OllamaAgentMaxIterationsError, u as OllamaAgentMaxToolCallsError, v as OllamaAuthError, w as OllamaBadGatewayError, x as OllamaClientError, y as OllamaClientErrorOptions, z as OllamaErrorRequestContext, J as OllamaErrorResponseContext, K as OllamaGenericClientError, Q as OllamaIncompatibleModelError, U as OllamaMcpError, V as OllamaModelRoutingError, W as OllamaNetworkError, X as OllamaNotFoundError, Y as OllamaOverloadedError, Z as OllamaQuotaExceededError, _ as OllamaRateLimitError, $ as OllamaRequestTooLargeError, a0 as OllamaRequestValidationError, a1 as OllamaResponseValidationError, a2 as OllamaServerError, a3 as OllamaServerVersionUnknownError, a4 as OllamaSkillInvalidError, a5 as OllamaSkillNotFoundError, a6 as OllamaStreamError, a7 as OllamaTimeoutError, a8 as OllamaToolTimeoutError, a9 as OllamaToolValidationError, aa as OllamaUnsupportedCapabilityError, ab as RequestContext, ac as RequestLifecycleEvent, ad as ResponseContext, ae as SseEvent, af as ThinkingEvent, ag as TokenEvent, ah as ToolCallEvent, ai as composeMiddleware, aj as createConsoleLogger, ak as extractUsage, al as mapError, am as parseSseStream } from './runtime-BV9SK_cf.js';
3
+ import { T as ThinkingMetadata, M as ModelResponse, S as ShowRequestOptions, a as ShowResponse, P as PullRequestOptions, b as ProgressResponse, c as PushRequestOptions, C as CreateRequestOptions, D as DeleteRequestOptions, d as StatusResponse, e as CopyRequestOptions, f as PsResponse, V as VersionResponse, R as RequestCancellationOptions, g as ToolParameters, h as ThinkValue, i as ToolCall, j as ChatRequestOptions, k as ModelOptions, l as ToolDefinition, F as FormatOption, m as ChatResponse, n as Message, G as GenerateRequestOptions, o as GenerateResponse, E as EmbedRequestOptions, p as EmbedResponse, q as EmbeddingsRequestOptions, r as EmbeddingsResponse, W as WebSearchRequestOptions, s as WebSearchResponse, t as WebFetchRequestOptions, u as WebFetchResponse, U as UsageRequestOptions, B as BalanceRequestOptions, v as VisionInput } from './types-BtQexFpT.js';
4
+ export { L as ListResponse, w as Logprob, x as LogprobToken, y as ModelDetails, z as Role, A as ToolCallFunction, H as ToolFunctionDefinition, I as ToolProperty, J as UsageRange, K as UsageScope, N as WebSearchResult, O as imageStringNeedsResolution, Q as resolveImageInput } from './types-BtQexFpT.js';
5
5
  import { z } from 'zod';
6
- import { R as RequestRunner, S as SystemOneChoiceAnswer, o as SystemOneNoulAnswer, p as SystemOneScoreAnswer, q as SystemOneChoiceQuestion, r as SystemOneNoulQuestion, s as SystemOneScoreQuestion, t as SystemOneRequest$1, u as SystemOneResponse$1, v as SystemOneContent, N as NativeApi, w as OpenAICompatClient, x as AnthropicCompatClient } from './anthropic-5oYIRS6D.js';
7
- export { y as AnthropicCacheControl, z as AnthropicContentBlock, B as AnthropicImageContentBlock, C as AnthropicMessage, n as AnthropicMessageStreamEvent, A as AnthropicMessagesRequest, m as AnthropicMessagesResponse, D as AnthropicMessagesStream, E as AnthropicMetadata, F as AnthropicOutputConfig, G as AnthropicRedactedThinkingContentBlock, H as AnthropicSystem, I as AnthropicSystemTextBlock, J as AnthropicTextContentBlock, K as AnthropicThinkingConfig, L as AnthropicThinkingContentBlock, M as AnthropicTool, P as AnthropicToolChoice, Q as AnthropicToolResultContentBlock, T as AnthropicToolUseContentBlock, U as AnthropicUnknownStreamEvent, V as OllamaAnthropicContentBlock, W as OllamaAnthropicMessage, X as OllamaAnthropicMessagesRequest, Y as OllamaAnthropicSystem, Z as OllamaAnthropicSystemTextBlock, _ as OllamaAnthropicTextContentBlock, $ as OllamaAnthropicThinkingConfig, a0 as OllamaAnthropicTool, a1 as OllamaAnthropicToolResultContentBlock, a2 as OllamaOpenAIChatCompletionRequest, a3 as OllamaOpenAICompletionRequest, a4 as OllamaOpenAIEmbeddingRequest, a5 as OllamaOpenAIReasoningEffort, a6 as OllamaOpenAIResponsesRequest, a7 as OpenAIChatCompletionChoice, b as OpenAIChatCompletionChunk, a8 as OpenAIChatCompletionChunkChoice, a9 as OpenAIChatCompletionDelta, O as OpenAIChatCompletionRequest, a as OpenAIChatCompletionResponse, aa as OpenAIChatCompletionStream, ab as OpenAICompletionChoice, e as OpenAICompletionChunk, c as OpenAICompletionRequest, d as OpenAICompletionResponse, ac as OpenAICompletionStream, ad as OpenAIContentPart, ae as OpenAIEmbeddingInput, af as OpenAIEmbeddingItem, f as OpenAIEmbeddingRequest, g as OpenAIEmbeddingResponse, ag as OpenAIFunctionDefinition, ah as OpenAIImageUrlContentPart, h as OpenAIListModelsResponse, ai as OpenAIMessage, i as OpenAIModelItem, aj as OpenAIReasoningEffort, ak as OpenAIResponseFormat, al as OpenAIResponsesCompletedEvent, am as OpenAIResponsesContentPartAddedEvent, an as OpenAIResponsesContentPartDoneEvent, ao as OpenAIResponsesCreatedEvent, ap as OpenAIResponsesError, aq as OpenAIResponsesEventBase, ar as OpenAIResponsesFailedEvent, as as OpenAIResponsesFunctionCallArgumentsDeltaEvent, at as OpenAIResponsesFunctionCallArgumentsDoneEvent, au as OpenAIResponsesInProgressEvent, av as OpenAIResponsesIncompleteDetails, aw as OpenAIResponsesIncompleteEvent, ax as OpenAIResponsesOutputContent, ay as OpenAIResponsesOutputFunctionCall, az as OpenAIResponsesOutputItem, aA as OpenAIResponsesOutputItemAddedEvent, aB as OpenAIResponsesOutputItemDoneEvent, aC as OpenAIResponsesOutputMessage, aD as OpenAIResponsesOutputReasoning, aE as OpenAIResponsesOutputRefusal, aF as OpenAIResponsesOutputTextContent, aG as OpenAIResponsesOutputTextDeltaEvent, aH as OpenAIResponsesOutputTextDoneEvent, aI as OpenAIResponsesQueuedEvent, aJ as OpenAIResponsesReasoningSummaryPartAddedEvent, aK as OpenAIResponsesReasoningSummaryPartDoneEvent, aL as OpenAIResponsesReasoningSummaryTextDeltaEvent, aM as OpenAIResponsesReasoningSummaryTextDoneEvent, aN as OpenAIResponsesReasoningTextDeltaEvent, aO as OpenAIResponsesReasoningTextDoneEvent, aP as OpenAIResponsesRefusalDeltaEvent, aQ as OpenAIResponsesRefusalDoneEvent, j as OpenAIResponsesRequest, k as OpenAIResponsesResponse, aR as OpenAIResponsesStatus, aS as OpenAIResponsesStream, aT as OpenAIResponsesStreamError, l as OpenAIResponsesStreamEvent, aU as OpenAIResponsesUsage, aV as OpenAIStreamOptions, aW as OpenAITextContentPart, aX as OpenAITool, aY as OpenAIToolCall, aZ as OpenAIToolCallDelta, a_ as OpenAIUsage, a$ as SystemOneConfidence, b0 as SystemOneProbabilities } from './anthropic-5oYIRS6D.js';
8
- import { T as ToolHandler, a as Tool, A as AnyTool, b as ToolRegistry, c as ToolExecutionResult } from './compose-DCVYMvOL.js';
9
- export { d as AppliedSkillResult, e as ApplySkillOptions, P as ParsedFrontmatter, S as Skill, f as SkillFrontmatter, g as SkillSummary, h as ToolExecutionContext, i as ToolExecutionFailure, j as ToolExecutionSuccess, k as ToolRegistryOptions, l as applySkill, p as parseFrontmatter } from './compose-DCVYMvOL.js';
6
+ import { R as RequestRunner, S as SystemOneChoiceAnswer, o as SystemOneNoulAnswer, p as SystemOneScoreAnswer, q as SystemOneChoiceQuestion, r as SystemOneNoulQuestion, s as SystemOneScoreQuestion, t as SystemOneRequest$1, u as SystemOneResponse$1, v as SystemOneContent, N as NativeApi, w as OpenAICompatClient, x as AnthropicCompatClient } from './anthropic-CPaoxeLX.js';
7
+ export { y as AnthropicCacheControl, z as AnthropicContentBlock, B as AnthropicImageContentBlock, C as AnthropicMessage, n as AnthropicMessageStreamEvent, A as AnthropicMessagesRequest, m as AnthropicMessagesResponse, D as AnthropicMessagesStream, E as AnthropicMetadata, F as AnthropicOutputConfig, G as AnthropicRedactedThinkingContentBlock, H as AnthropicSystem, I as AnthropicSystemTextBlock, J as AnthropicTextContentBlock, K as AnthropicThinkingConfig, L as AnthropicThinkingContentBlock, M as AnthropicTool, P as AnthropicToolChoice, Q as AnthropicToolResultContentBlock, T as AnthropicToolUseContentBlock, U as AnthropicUnknownStreamEvent, V as OllamaAnthropicContentBlock, W as OllamaAnthropicMessage, X as OllamaAnthropicMessagesRequest, Y as OllamaAnthropicSystem, Z as OllamaAnthropicSystemTextBlock, _ as OllamaAnthropicTextContentBlock, $ as OllamaAnthropicThinkingConfig, a0 as OllamaAnthropicTool, a1 as OllamaAnthropicToolResultContentBlock, a2 as OllamaOpenAIChatCompletionRequest, a3 as OllamaOpenAICompletionRequest, a4 as OllamaOpenAIEmbeddingRequest, a5 as OllamaOpenAIReasoningEffort, a6 as OllamaOpenAIResponsesRequest, a7 as OpenAIChatCompletionChoice, b as OpenAIChatCompletionChunk, a8 as OpenAIChatCompletionChunkChoice, a9 as OpenAIChatCompletionDelta, O as OpenAIChatCompletionRequest, a as OpenAIChatCompletionResponse, aa as OpenAIChatCompletionStream, ab as OpenAICompletionChoice, e as OpenAICompletionChunk, c as OpenAICompletionRequest, d as OpenAICompletionResponse, ac as OpenAICompletionStream, ad as OpenAIContentPart, ae as OpenAIEmbeddingInput, af as OpenAIEmbeddingItem, f as OpenAIEmbeddingRequest, g as OpenAIEmbeddingResponse, ag as OpenAIFunctionDefinition, ah as OpenAIImageUrlContentPart, h as OpenAIListModelsResponse, ai as OpenAIMessage, i as OpenAIModelItem, aj as OpenAIReasoningEffort, ak as OpenAIResponseFormat, al as OpenAIResponsesCompletedEvent, am as OpenAIResponsesContentPartAddedEvent, an as OpenAIResponsesContentPartDoneEvent, ao as OpenAIResponsesCreatedEvent, ap as OpenAIResponsesError, aq as OpenAIResponsesEventBase, ar as OpenAIResponsesFailedEvent, as as OpenAIResponsesFunctionCallArgumentsDeltaEvent, at as OpenAIResponsesFunctionCallArgumentsDoneEvent, au as OpenAIResponsesInProgressEvent, av as OpenAIResponsesIncompleteDetails, aw as OpenAIResponsesIncompleteEvent, ax as OpenAIResponsesOutputContent, ay as OpenAIResponsesOutputFunctionCall, az as OpenAIResponsesOutputItem, aA as OpenAIResponsesOutputItemAddedEvent, aB as OpenAIResponsesOutputItemDoneEvent, aC as OpenAIResponsesOutputMessage, aD as OpenAIResponsesOutputReasoning, aE as OpenAIResponsesOutputRefusal, aF as OpenAIResponsesOutputTextContent, aG as OpenAIResponsesOutputTextDeltaEvent, aH as OpenAIResponsesOutputTextDoneEvent, aI as OpenAIResponsesQueuedEvent, aJ as OpenAIResponsesReasoningSummaryPartAddedEvent, aK as OpenAIResponsesReasoningSummaryPartDoneEvent, aL as OpenAIResponsesReasoningSummaryTextDeltaEvent, aM as OpenAIResponsesReasoningSummaryTextDoneEvent, aN as OpenAIResponsesReasoningTextDeltaEvent, aO as OpenAIResponsesReasoningTextDoneEvent, aP as OpenAIResponsesRefusalDeltaEvent, aQ as OpenAIResponsesRefusalDoneEvent, j as OpenAIResponsesRequest, k as OpenAIResponsesResponse, aR as OpenAIResponsesStatus, aS as OpenAIResponsesStream, aT as OpenAIResponsesStreamError, l as OpenAIResponsesStreamEvent, aU as OpenAIResponsesUsage, aV as OpenAIStreamOptions, aW as OpenAITextContentPart, aX as OpenAITool, aY as OpenAIToolCall, aZ as OpenAIToolCallDelta, a_ as OpenAIUsage, a$ as SystemOneConfidence, b0 as SystemOneProbabilities } from './anthropic-CPaoxeLX.js';
8
+ import { T as ToolHandler, a as Tool, A as AnyTool, b as ToolRegistry, c as ToolExecutionResult } from './compose-BQYXdpar.js';
9
+ export { d as AppliedSkillResult, e as ApplySkillOptions, P as ParsedFrontmatter, S as Skill, f as SkillFrontmatter, g as SkillSummary, h as ToolExecutionContext, i as ToolExecutionFailure, j as ToolExecutionSuccess, k as ToolRegistryOptions, l as applySkill, p as parseFrontmatter } from './compose-BQYXdpar.js';
10
10
  import { M as McpClientLike, a as McpToolDescriptor, b as McpTask, c as McpCallToolResult } from './types-CI-gM2u5.js';
11
11
  export { d as McpContentBlock, e as McpCreateTaskResult, f as McpElicitationFormRequest, g as McpElicitationHandlers, h as McpElicitationRequest, i as McpElicitationResult, j as McpElicitationUrlRequest, k as McpIcon, l as McpInputRequiredResult, m as McpListToolsParams, n as McpListToolsResult, o as McpRequestOptions, p as McpServerCapabilities, q as McpTaskMethod, r as McpTaskRequest, s as McpTaskStatus, t as McpToolAnnotations, u as McpToolCallResult, v as McpToolExecution } from './types-CI-gM2u5.js';
12
12
  import * as Otel from '@opentelemetry/api';
@@ -981,6 +981,131 @@ declare class ConversationSession {
981
981
  reset(): void;
982
982
  }
983
983
 
984
+ /**
985
+ * Batch-constrained embedding generation for high-volume ingestion pipelines.
986
+ *
987
+ * Ollama's `/api/embed` accepts an array of inputs, but two independent limits
988
+ * make naive usage fragile at corpus scale:
989
+ *
990
+ * 1. **Concurrency.** `Promise.all(inputs.map(...))` fires every request at
991
+ * once; against a local Ollama daemon this contends sockets, saturates the
992
+ * request queue (`OLLAMA_MAX_QUEUE`, surfacing as 503 `overloaded`), and —
993
+ * worst case — exhausts GPU VRAM as the model instance serves N prompts
994
+ * simultaneously.
995
+ * 2. **Context window.** Ollama truncates any input string longer than the
996
+ * model's context window (`num_ctx`) *silently* unless `truncate: false` is
997
+ * set — degraded vectors with no error, no warning, nothing on the wire.
998
+ *
999
+ * {@link batchEmbed} addresses the first with a fixed-size worker pool over
1000
+ * `client.embed()` (so every batch still rides the client's full pipeline:
1001
+ * failover, retry, auth, logging, telemetry). The client-level
1002
+ * `embedBatch()` wrapper addresses the second with a pre-flight per-string
1003
+ * token estimate against the resolved `num_ctx` window (see
1004
+ * {@link findOversizedEmbedInputs}).
1005
+ *
1006
+ * Semantics:
1007
+ * - **Order-preserving** — result index `i` is always the embedding of
1008
+ * `input[i]`, regardless of which batch completed first.
1009
+ * - **Fail-fast** — the first batch error aborts every sibling in-flight
1010
+ * batch (surfaces the *original* error, not the derived aborts) and rejects
1011
+ * the whole operation. Vector indexing that half-succeeds is a corrupted
1012
+ * index; callers re-running an ingestion prefer all-or-nothing.
1013
+ * - **Abortable** — the caller's `signal` cancels queued and in-flight batches
1014
+ * alike and rejects with `code: 'aborted'`.
1015
+ */
1016
+
1017
+ /**
1018
+ * Default number of input strings per `/api/embed` request. 32 keeps a single
1019
+ * request's prompt comfortably inside typical embedding-model context windows
1020
+ * (2048+) while amortizing HTTP overhead across the corpus.
1021
+ */
1022
+ declare const DEFAULT_EMBED_BATCH_SIZE = 32;
1023
+ /**
1024
+ * Default number of batches kept in flight concurrently. 3 is deliberately
1025
+ * conservative: a local Ollama daemon serves one model instance per GPU, so
1026
+ * 3 concurrent embedding prompts bound queue depth and VRAM pressure without
1027
+ * leaving the hardware idle between batches. Raise for multi-endpoint
1028
+ * clients or remote daemons; lower (to 1) for constrained devices.
1029
+ */
1030
+ declare const DEFAULT_EMBED_CONCURRENCY = 3;
1031
+ interface EmbedBatchOptions {
1032
+ /** Model to embed with (e.g. `'nomic-embed-text:latest'`). */
1033
+ readonly model: string;
1034
+ /** Input strings, in corpus order. Result index `i` matches `input[i]`. */
1035
+ readonly input: readonly string[];
1036
+ /**
1037
+ * Inputs per `/api/embed` request. Default {@link DEFAULT_EMBED_BATCH_SIZE}
1038
+ * (32). Must be a positive integer.
1039
+ */
1040
+ readonly batchSize?: number | undefined;
1041
+ /**
1042
+ * Batches kept in flight simultaneously. Default
1043
+ * {@link DEFAULT_EMBED_CONCURRENCY} (3). Must be a positive integer.
1044
+ */
1045
+ readonly concurrency?: number | undefined;
1046
+ /** Passed through to each batch request — `false` makes oversized inputs
1047
+ * a server-side error instead of a silent truncation. */
1048
+ readonly truncate?: boolean | undefined;
1049
+ /** Passed through to each batch request (dimensionality truncation). */
1050
+ readonly dimensions?: number | undefined;
1051
+ /** Passed through to each batch request (model unload policy). */
1052
+ readonly keep_alive?: string | number | undefined;
1053
+ /** Ollama model options (`num_ctx`, …) passed through to each batch request. */
1054
+ readonly options?: ModelOptions | undefined;
1055
+ /** Aborts the whole batch operation — queued and in-flight alike. */
1056
+ readonly signal?: AbortSignal | undefined;
1057
+ /** Per-request timeout applied to each individual batch request. */
1058
+ readonly timeoutMs?: number | undefined;
1059
+ /**
1060
+ * Progress callback invoked after each successfully embedded batch as
1061
+ * `onBatchComplete(completedBatches, totalBatches)`. Never called after the
1062
+ * operation rejects.
1063
+ */
1064
+ readonly onBatchComplete?: ((completedBatches: number, totalBatches: number) => void) | undefined;
1065
+ }
1066
+ interface EmbedBatchResult {
1067
+ readonly model: string;
1068
+ /**
1069
+ * Embeddings in input order — `embeddings[i]` corresponds to
1070
+ * `options.input[i]`, independent of batch completion order.
1071
+ */
1072
+ readonly embeddings: readonly (readonly number[])[];
1073
+ /** Number of `/api/embed` requests the corpus was split into. */
1074
+ readonly batchCount: number;
1075
+ }
1076
+ /** An input string whose estimated token count exceeds the context window. */
1077
+ interface OversizedEmbedInput {
1078
+ /** Index into the input array. */
1079
+ readonly index: number;
1080
+ /** Estimated token count for `input[index]`. */
1081
+ readonly estimate: number;
1082
+ }
1083
+ /**
1084
+ * Finds input strings whose heuristic token estimate exceeds `contextLength`
1085
+ * (typically the resolved `num_ctx`). Unlike chat/generate pre-flight there is
1086
+ * no warning margin and no output-token headroom: an embedding request's
1087
+ * prompt IS the whole input, so the exact window is the trip point, and
1088
+ * crossing it means silent truncation (or, with `truncate: false`, a
1089
+ * server-side rejection).
1090
+ */
1091
+ declare function findOversizedEmbedInputs(input: readonly string[], contextLength: number): OversizedEmbedInput[];
1092
+ /**
1093
+ * Builds the warn/throw message for oversized embed inputs (mirrors
1094
+ * `contextWarningMessage` for chat/generate).
1095
+ */
1096
+ declare function embedBatchOverflowMessage(oversized: readonly OversizedEmbedInput[], totalInputs: number, contextLength: number, truncateFalse: boolean): string;
1097
+ /**
1098
+ * Splits `input` into `batchSize` slices and embeds them through `client.embed()`
1099
+ * with at most `concurrency` batches in flight. Order-preserving and fail-fast —
1100
+ * see the module doc for the full semantics.
1101
+ *
1102
+ * Prefer the {@link OllamaClient.embedBatch} wrapper, which additionally
1103
+ * injects `defaultContextLength` as `num_ctx` and enforces the client's
1104
+ * `onContextOverflow` policy against per-string estimates before any request
1105
+ * is sent.
1106
+ */
1107
+ declare function batchEmbed(client: OllamaClient, options: EmbedBatchOptions): Promise<EmbedBatchResult>;
1108
+
984
1109
  /**
985
1110
  * Ergonomic System One types — key-safe generics on top of the generated
986
1111
  * contract models.
@@ -1425,6 +1550,14 @@ declare class OllamaClient {
1425
1550
  private readonly contextWarningThreshold;
1426
1551
  /** Configured overflow policy — `'warn'` (default) or `'throw'`. */
1427
1552
  private readonly onContextOverflow;
1553
+ /**
1554
+ * Controllers for every in-flight request and active stream managed by this
1555
+ * client — see {@link OllamaClient.destroy} and {@link createRequestScope}.
1556
+ * Entries live for exactly as long as the underlying work does: until the
1557
+ * response settles (requests) or the stream's `finalResult` settles
1558
+ * (streams, via `executeWithFailover`'s `holdUntil` release path).
1559
+ */
1560
+ private readonly activeRequests;
1428
1561
  constructor(config?: OllamaClientConfig);
1429
1562
  get modelsClient(): ModelsClient;
1430
1563
  /**
@@ -1523,6 +1656,17 @@ declare class OllamaClient {
1523
1656
  * reference when there's nothing to inject (the common case).
1524
1657
  */
1525
1658
  private injectDefaultContextLength;
1659
+ /**
1660
+ * Creates the per-request abort scope registered with {@link destroy}:
1661
+ * a controller that fires when the caller's `signal` aborts OR when
1662
+ * `destroy()` runs, whichever comes first. `dispose()` removes the
1663
+ * registration when the work it guards settles — for plain requests when
1664
+ * the response settles, for streams when `finalResult` settles (the same
1665
+ * moment `executeWithFailover`'s `holdUntil` releases the endpoint slot),
1666
+ * so a destroy() can tear down a stream mid-consumption but never outlives
1667
+ * one that already finished.
1668
+ */
1669
+ private createRequestScope;
1526
1670
  /**
1527
1671
  * Fail-fast guard for `format` (structured output) requests: throws before any network
1528
1672
  * call if the candidate endpoint is inferred as Ollama Cloud, which does not currently
@@ -1585,6 +1729,36 @@ declare class OllamaClient {
1585
1729
  generateWithSchema<T>(req: Omit<GenerateRequestOptions, 'stream' | 'format'>, schema: z.ZodType<T>): Promise<T>;
1586
1730
  embed(req: EmbedRequestOptions): Promise<EmbedResponse>;
1587
1731
  embedText(model: string, input: string | readonly string[]): Promise<readonly (readonly number[])[]>;
1732
+ /**
1733
+ * Batch-constrained, order-preserving embedding generation for large
1734
+ * corpora — the safe building block for RAG/vector-index ingestion at
1735
+ * scale. Splits `input` into `batchSize` slices and embeds them through
1736
+ * {@link embed} with at most `concurrency` batches in flight (defaults:
1737
+ * 32 × 3), so `Promise.all`-style floods that OOM local daemons and
1738
+ * saturate `OLLAMA_MAX_QUEUE` can't happen by accident. Fail-fast: the
1739
+ * first batch error aborts every sibling in-flight batch and rejects the
1740
+ * whole operation with the original error.
1741
+ *
1742
+ * Before any request is sent, `defaultContextLength` is injected as
1743
+ * `num_ctx` (same as chat/generate) and each input string's token estimate
1744
+ * is checked against the resolved window: Ollama silently truncates
1745
+ * oversized embedding inputs by default, so the client warns (or throws,
1746
+ * under `onContextOverflow: 'throw'`) with the offending indexes — see
1747
+ * `src/embed-batch.ts` for the exact trip point (no margin: an embedding
1748
+ * prompt IS the whole input).
1749
+ *
1750
+ * ```ts
1751
+ * const { embeddings, batchCount } = await client.embedBatch({
1752
+ * model: 'nomic-embed-text:latest',
1753
+ * input: corpus, // e.g. 50k chunks
1754
+ * batchSize: 32, // inputs per /api/embed request
1755
+ * concurrency: 3, // batches in flight
1756
+ * onBatchComplete: (done, total) => progress.log(`${done}/${total}`),
1757
+ * });
1758
+ * // embeddings[i] always corresponds to corpus[i]
1759
+ * ```
1760
+ */
1761
+ embedBatch(options: EmbedBatchOptions): Promise<EmbedBatchResult>;
1588
1762
  /**
1589
1763
  * @deprecated Ollama's `/api/embeddings` endpoint has been superseded by `/api/embed`
1590
1764
  * (exposed here as {@link OllamaClient.embed}), which additionally supports batch
@@ -1710,6 +1884,26 @@ declare class OllamaClient {
1710
1884
  runtimeMode(): RuntimeMode;
1711
1885
  healthCheck(): Promise<EndpointHealthCheckResult[]>;
1712
1886
  endpointStatus(): EndpointHealth[];
1887
+ /**
1888
+ * Immediately aborts every in-flight request and active stream managed by
1889
+ * this client — the clean teardown path for short-lived processes, CLI
1890
+ * runners, and `node:worker_threads` tasks where dangling fetch bodies,
1891
+ * unconsumed stream readers, or queued capacity waiters would otherwise
1892
+ * keep the event loop (and thus the thread/process) alive.
1893
+ *
1894
+ * Every aborted operation rejects with an {@link OllamaAbortError}
1895
+ * (`code: 'aborted'`) carrying `reason` as its message — including requests
1896
+ * still queued behind `maxConcurrentPerEndpoint`, not just dispatched ones.
1897
+ * Streams reject their `finalResult` and release their endpoint slots.
1898
+ *
1899
+ * Idempotent: calling it again (or on a client with nothing in flight)
1900
+ * is a no-op that returns `0`. The client remains usable afterward —
1901
+ * `destroy()` is a drain, not a permanent disable; callers that want a
1902
+ * permanently-dead client should discard the instance.
1903
+ *
1904
+ * @returns the number of in-flight operations that were aborted.
1905
+ */
1906
+ destroy(reason?: string): number;
1713
1907
  get openai(): OpenAICompatClient;
1714
1908
  get anthropic(): AnthropicCompatClient;
1715
1909
  }
@@ -2657,4 +2851,4 @@ declare const OLLAMA_FALLBACK_CONTEXT_LENGTH = 2048;
2657
2851
  */
2658
2852
  declare function contextWarningMessage(check: ContextCheck, kind: 'chat' | 'generate'): string;
2659
2853
 
2660
- export { ATTR_GEN_AI_OPERATION_NAME, ATTR_GEN_AI_REQUEST_MODEL, ATTR_GEN_AI_RESPONSE_MODEL, ATTR_GEN_AI_SYSTEM, ATTR_GEN_AI_TOOL_CALL_ID, ATTR_GEN_AI_TOOL_NAME, ATTR_GEN_AI_USAGE_INPUT_TOKENS, ATTR_GEN_AI_USAGE_OUTPUT_TOKENS, ATTR_HTTP_REQUEST_METHOD, ATTR_HTTP_RESPONSE_STATUS_CODE, ATTR_OLLAMA_AGENT_ITERATION, ATTR_OLLAMA_AGENT_MAX_ITERATIONS, ATTR_OLLAMA_ENDPOINT_ATTEMPT, ATTR_OLLAMA_ENDPOINT_NAME, ATTR_SERVER_ADDRESS, ATTR_SERVER_PORT, ATTR_URL_FULL, AbortableAsyncIterable, Agent, type AgentChatClient, type AgentConfig, type AgentHooks, type AgentResult, type AgentRunInput, type AgentTurn, type AnswerFor, AnthropicCompatClient, AnyTool, type BackoffOptions, BalanceRequestOptions, type BalanceResponse, type BlobUploadResult, ChatRequestOptions, ChatResponse, ChatStreamResult, type ChoiceDecision, type ContextCheck, type ContextCheckOptions, type ContextWindowSource, type ConversationSendOptions, ConversationSession, type ConversationSessionOptions, CopyRequestOptions, CreateRequestOptions, type CumulativeCacheStats, DEFAULT_BACKOFF, DEFAULT_BASE_URL, DEFAULT_CONTEXT_WARNING_THRESHOLD, DEFAULT_FAILOVER_CODES, DEFAULT_FETCH_BACKOFF_CONFIG, DEFAULT_RETRY_CONFIG, DEFAULT_TIMEOUT_MS, type Decision, type DefineToolOptions, DeleteRequestOptions, EmbedRequestOptions, EmbedResponse, EmbeddingsRequestOptions, EmbeddingsResponse, type EndpointHealth, type EndpointHealthCheckResult, EndpointRegistry, type EndpointRegistryOptions, FetchLike, type FetchWithBackoffConfig, FormatOption, GEN_AI_SYSTEM_OLLAMA, GenerateRequestOptions, GenerateResponse, GenerateStreamResult, HttpClient, IMAGE_TOKEN_ESTIMATE, type IncludedBalance, KEEP_ALIVE_INDEFINITE, KEEP_ALIVE_UNLOAD, KNOWN_DONE_REASONS, type KeepAlive, type KnownDoneReason, type LegacyBalanceLimit, type LegacyIncludedBalance, type LoadMcpToolsOptions, Logger, MAX_SYSTEM_ONE_IMAGES_BYTES, MAX_SYSTEM_ONE_REQUEST_BYTES, McpBridge, type McpBridgeOptions, McpCallToolResult, McpClientLike, McpTask, McpToolDescriptor, Message, Middleware, type ModelCapabilities, ModelOptions, ModelResponse, ModelsClient, type NoulDecision, OLLAMA_CLOUD_BASE_URL, OLLAMA_FALLBACK_CONTEXT_LENGTH, OllamaClient, type OllamaClientConfig, type OllamaCloudFreeTierQuotaBudgets, type OllamaCredentialConfig, type OllamaEndpoint, OllamaStream, OllamaStreamEvent, OllamaStreamEventType, OpenAICompatClient, type ParallelToolCallBehavior, ProgressResponse, ProgressStreamResult, PsResponse, PullRequestOptions, PushRequestOptions, QuotaManager, type QuotaManagerOptions, type QuotaWindowConfig, type QuotaWindowStatus, RETRYABLE_STATUS_CODES, type RankResult, RawUsageSource, RequestCancellationOptions, RequestLifecycleHook, RequestRunner, type ResponsesCreateRequest, type ResponsesCreateResponse, ResponsesModule, type ResponsesReasoningEffort, type ResponsesStreamEvent, type ResponsesToolDefinition, type ResponsesUsage, type RetryConfig, type RuntimeMode, type ScoreDecision, type SessionTurn, ShowRequestOptions, ShowResponse, type SpanAttributeValue, type SpanAttributes, StatusResponse, type SupportedSchema, type SystemOneAnswer, type SystemOneAnswers, SystemOneChoiceAnswer, SystemOneChoiceQuestion, SystemOneContent, SystemOneNoulAnswer, SystemOneNoulQuestion, type SystemOneQuestion, type SystemOneQuestions, type SystemOneRequest, type SystemOneResponse, SystemOneScoreAnswer, SystemOneScoreQuestion, type SystemOneUsage, ThinkValue, ThinkingMetadata, type TimeoutSignal, TokenUsage, Tool, ToolCall, ToolCallAccumulator, ToolDefinition, ToolExecutionResult, ToolHandler, ToolParameters, ToolRegistry, type TurnCacheStats, type UsageBucket, type UsageMetrics, UsageRequestOptions, type UsageResponse, VersionResponse, VisionInput, WebFetchRequestOptions, WebFetchResponse, WebSearchRequestOptions, WebSearchResponse, addSpanEvent, calculateBackoff, checkChatContext, checkEndpointHealth, checkGenerateContext, contextWarningMessage, createDecision, createOllamaCloudFreeTierQuota, createTimeoutSignal, defineTool, detectModelCapabilities, encodeImage, estimateChatRequestTokens, estimateGenerateRequestTokens, estimateSystemOneRequestBytes, estimateTokens, fetchWithBackoff, inferRuntimeMode, isKeepAliveSugar, isKnownDoneReason, isSameToolCall, listAllMcpTools, listAvailableModels, loadMcpTools, mergeToolCall, mergeToolCallArgumentsString, mergeToolCallArrays, normalizeChatStream, normalizeGenerateStream, normalizeKeepAlive, normalizeProgressStream, parseNdjsonStream, parseStructuredOutput, registerMcpTools, resolveCredentialEndpoints, setSpanError, toDataStream, toResponse, toTextStream, withRetry, withSpan, zodToJsonSchema };
2854
+ export { ATTR_GEN_AI_OPERATION_NAME, ATTR_GEN_AI_REQUEST_MODEL, ATTR_GEN_AI_RESPONSE_MODEL, ATTR_GEN_AI_SYSTEM, ATTR_GEN_AI_TOOL_CALL_ID, ATTR_GEN_AI_TOOL_NAME, ATTR_GEN_AI_USAGE_INPUT_TOKENS, ATTR_GEN_AI_USAGE_OUTPUT_TOKENS, ATTR_HTTP_REQUEST_METHOD, ATTR_HTTP_RESPONSE_STATUS_CODE, ATTR_OLLAMA_AGENT_ITERATION, ATTR_OLLAMA_AGENT_MAX_ITERATIONS, ATTR_OLLAMA_ENDPOINT_ATTEMPT, ATTR_OLLAMA_ENDPOINT_NAME, ATTR_SERVER_ADDRESS, ATTR_SERVER_PORT, ATTR_URL_FULL, AbortableAsyncIterable, Agent, type AgentChatClient, type AgentConfig, type AgentHooks, type AgentResult, type AgentRunInput, type AgentTurn, type AnswerFor, AnthropicCompatClient, AnyTool, type BackoffOptions, BalanceRequestOptions, type BalanceResponse, type BlobUploadResult, ChatRequestOptions, ChatResponse, ChatStreamResult, type ChoiceDecision, type ContextCheck, type ContextCheckOptions, type ContextWindowSource, type ConversationSendOptions, ConversationSession, type ConversationSessionOptions, CopyRequestOptions, CreateRequestOptions, type CumulativeCacheStats, DEFAULT_BACKOFF, DEFAULT_BASE_URL, DEFAULT_CONTEXT_WARNING_THRESHOLD, DEFAULT_EMBED_BATCH_SIZE, DEFAULT_EMBED_CONCURRENCY, DEFAULT_FAILOVER_CODES, DEFAULT_FETCH_BACKOFF_CONFIG, DEFAULT_RETRY_CONFIG, DEFAULT_TIMEOUT_MS, type Decision, type DefineToolOptions, DeleteRequestOptions, type EmbedBatchOptions, type EmbedBatchResult, EmbedRequestOptions, EmbedResponse, EmbeddingsRequestOptions, EmbeddingsResponse, type EndpointHealth, type EndpointHealthCheckResult, EndpointRegistry, type EndpointRegistryOptions, FetchLike, type FetchWithBackoffConfig, FormatOption, GEN_AI_SYSTEM_OLLAMA, GenerateRequestOptions, GenerateResponse, GenerateStreamResult, HttpClient, IMAGE_TOKEN_ESTIMATE, type IncludedBalance, KEEP_ALIVE_INDEFINITE, KEEP_ALIVE_UNLOAD, KNOWN_DONE_REASONS, type KeepAlive, type KnownDoneReason, type LegacyBalanceLimit, type LegacyIncludedBalance, type LoadMcpToolsOptions, Logger, MAX_SYSTEM_ONE_IMAGES_BYTES, MAX_SYSTEM_ONE_REQUEST_BYTES, McpBridge, type McpBridgeOptions, McpCallToolResult, McpClientLike, McpTask, McpToolDescriptor, Message, Middleware, type ModelCapabilities, ModelOptions, ModelResponse, ModelsClient, type NoulDecision, OLLAMA_CLOUD_BASE_URL, OLLAMA_FALLBACK_CONTEXT_LENGTH, OllamaClient, type OllamaClientConfig, type OllamaCloudFreeTierQuotaBudgets, type OllamaCredentialConfig, type OllamaEndpoint, OllamaStream, OllamaStreamEvent, OllamaStreamEventType, OpenAICompatClient, type OversizedEmbedInput, type ParallelToolCallBehavior, ProgressResponse, ProgressStreamResult, PsResponse, PullRequestOptions, PushRequestOptions, QuotaManager, type QuotaManagerOptions, type QuotaWindowConfig, type QuotaWindowStatus, RETRYABLE_STATUS_CODES, type RankResult, RawUsageSource, RequestCancellationOptions, RequestLifecycleHook, RequestRunner, type ResponsesCreateRequest, type ResponsesCreateResponse, ResponsesModule, type ResponsesReasoningEffort, type ResponsesStreamEvent, type ResponsesToolDefinition, type ResponsesUsage, type RetryConfig, type RuntimeMode, type ScoreDecision, type SessionTurn, ShowRequestOptions, ShowResponse, type SpanAttributeValue, type SpanAttributes, StatusResponse, type SupportedSchema, type SystemOneAnswer, type SystemOneAnswers, SystemOneChoiceAnswer, SystemOneChoiceQuestion, SystemOneContent, SystemOneNoulAnswer, SystemOneNoulQuestion, type SystemOneQuestion, type SystemOneQuestions, type SystemOneRequest, type SystemOneResponse, SystemOneScoreAnswer, SystemOneScoreQuestion, type SystemOneUsage, ThinkValue, ThinkingMetadata, type TimeoutSignal, TokenUsage, Tool, ToolCall, ToolCallAccumulator, ToolDefinition, ToolExecutionResult, ToolHandler, ToolParameters, ToolRegistry, type TurnCacheStats, type UsageBucket, type UsageMetrics, UsageRequestOptions, type UsageResponse, VersionResponse, VisionInput, WebFetchRequestOptions, WebFetchResponse, WebSearchRequestOptions, WebSearchResponse, addSpanEvent, batchEmbed, calculateBackoff, checkChatContext, checkEndpointHealth, checkGenerateContext, contextWarningMessage, createDecision, createOllamaCloudFreeTierQuota, createTimeoutSignal, defineTool, detectModelCapabilities, embedBatchOverflowMessage, encodeImage, estimateChatRequestTokens, estimateGenerateRequestTokens, estimateSystemOneRequestBytes, estimateTokens, fetchWithBackoff, findOversizedEmbedInputs, inferRuntimeMode, isKeepAliveSugar, isKnownDoneReason, isSameToolCall, listAllMcpTools, listAvailableModels, loadMcpTools, mergeToolCall, mergeToolCallArgumentsString, mergeToolCallArrays, normalizeChatStream, normalizeGenerateStream, normalizeKeepAlive, normalizeProgressStream, parseNdjsonStream, parseStructuredOutput, registerMcpTools, resolveCredentialEndpoints, setSpanError, toDataStream, toResponse, toTextStream, withRetry, withSpan, zodToJsonSchema };