@nemesis-oss/ollama-sdk 1.17.0 → 1.18.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
@@ -3,8 +3,8 @@ export { L as ListResponse, x as Logprob, y as LogprobToken, z as ModelDetails,
3
3
  import { H as HttpClient, F as FetchLike, M as Middleware, L as Logger, R as RequestLifecycleHook, 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-CdZP-N7j.cjs';
4
4
  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 NETWORK_ERROR_CODES, r as NOOP_LOGGER, s as NextFunction, t as OllamaAbortError, u as OllamaAgentMaxIterationsError, v as OllamaAgentMaxToolCallsError, w as OllamaAgentToolLoopError, x as OllamaAuthError, y as OllamaBadGatewayError, z as OllamaClientError, J as OllamaClientErrorOptions, K as OllamaErrorRequestContext, Q as OllamaErrorResponseContext, U as OllamaGenericClientError, V as OllamaIncompatibleModelError, W as OllamaMcpError, X as OllamaModelRoutingError, Y as OllamaNetworkError, Z as OllamaNotFoundError, _ as OllamaOverloadedError, $ as OllamaQuotaExceededError, a0 as OllamaRateLimitError, a1 as OllamaRequestTooLargeError, a2 as OllamaRequestValidationError, a3 as OllamaResponseValidationError, a4 as OllamaServerError, a5 as OllamaServerVersionUnknownError, a6 as OllamaSkillInvalidError, a7 as OllamaSkillNotFoundError, a8 as OllamaStreamError, a9 as OllamaTimeoutError, aa as OllamaToolTimeoutError, ab as OllamaToolValidationError, ac as OllamaUnsupportedCapabilityError, ad as RequestContext, ae as RequestLifecycleEvent, af as ResponseContext, ag as SseEvent, ah as ThinkingEvent, ai as TokenEvent, aj as ToolCallEvent, ak as composeMiddleware, al as createConsoleLogger, am as extractUsage, an as isNetworkLevelError, ao as mapError, ap as parseSseStream } from './runtime-CdZP-N7j.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-AKbXnWJU.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 OllamaOpenAIChatContentPart, a4 as OllamaOpenAIChatMessage, a5 as OllamaOpenAICompletionRequest, a6 as OllamaOpenAIEmbeddingRequest, a7 as OllamaOpenAIImageDataUrl, a8 as OllamaOpenAIReasoningEffort, a9 as OllamaOpenAIResponsesRequest, aa as OpenAIChatCompletionChoice, b as OpenAIChatCompletionChunk, ab as OpenAIChatCompletionChunkChoice, ac as OpenAIChatCompletionDelta, O as OpenAIChatCompletionRequest, a as OpenAIChatCompletionResponse, ad as OpenAIChatCompletionStream, ae as OpenAICompletionChoice, e as OpenAICompletionChunk, c as OpenAICompletionRequest, d as OpenAICompletionResponse, af as OpenAICompletionStream, ag as OpenAIContentPart, ah as OpenAIEmbeddingInput, ai as OpenAIEmbeddingItem, f as OpenAIEmbeddingRequest, g as OpenAIEmbeddingResponse, aj as OpenAIFunctionDefinition, ak as OpenAIImageUrlContentPart, h as OpenAIListModelsResponse, al as OpenAIMessage, i as OpenAIModelItem, am as OpenAIReasoningEffort, an as OpenAIResponseFormat, ao as OpenAIResponsesCompletedEvent, ap as OpenAIResponsesContentPartAddedEvent, aq as OpenAIResponsesContentPartDoneEvent, ar as OpenAIResponsesCreatedEvent, as as OpenAIResponsesError, at as OpenAIResponsesEventBase, au as OpenAIResponsesFailedEvent, av as OpenAIResponsesFunctionCallArgumentsDeltaEvent, aw as OpenAIResponsesFunctionCallArgumentsDoneEvent, ax as OpenAIResponsesInProgressEvent, ay as OpenAIResponsesIncompleteDetails, az as OpenAIResponsesIncompleteEvent, aA as OpenAIResponsesOutputContent, aB as OpenAIResponsesOutputFunctionCall, aC as OpenAIResponsesOutputItem, aD as OpenAIResponsesOutputItemAddedEvent, aE as OpenAIResponsesOutputItemDoneEvent, aF as OpenAIResponsesOutputMessage, aG as OpenAIResponsesOutputReasoning, aH as OpenAIResponsesOutputRefusal, aI as OpenAIResponsesOutputTextContent, aJ as OpenAIResponsesOutputTextDeltaEvent, aK as OpenAIResponsesOutputTextDoneEvent, aL as OpenAIResponsesQueuedEvent, aM as OpenAIResponsesReasoningSummaryPartAddedEvent, aN as OpenAIResponsesReasoningSummaryPartDoneEvent, aO as OpenAIResponsesReasoningSummaryTextDeltaEvent, aP as OpenAIResponsesReasoningSummaryTextDoneEvent, aQ as OpenAIResponsesReasoningTextDeltaEvent, aR as OpenAIResponsesReasoningTextDoneEvent, aS as OpenAIResponsesRefusalDeltaEvent, aT as OpenAIResponsesRefusalDoneEvent, j as OpenAIResponsesRequest, k as OpenAIResponsesResponse, aU as OpenAIResponsesStatus, aV as OpenAIResponsesStream, aW as OpenAIResponsesStreamError, l as OpenAIResponsesStreamEvent, aX as OpenAIResponsesUsage, aY as OpenAIStreamOptions, aZ as OpenAITextContentPart, a_ as OpenAITool, a$ as OpenAIToolCall, b0 as OpenAIToolCallDelta, b1 as OpenAIUsage, b2 as SystemOneConfidence, b3 as SystemOneProbabilities } from './anthropic-AKbXnWJU.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-BvHOsidk.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 OllamaOpenAIChatContentPart, a4 as OllamaOpenAIChatMessage, a5 as OllamaOpenAICompletionRequest, a6 as OllamaOpenAIEmbeddingRequest, a7 as OllamaOpenAIImageDataUrl, a8 as OllamaOpenAIReasoningEffort, a9 as OllamaOpenAIResponsesRequest, aa as OpenAIChatCompletionChoice, b as OpenAIChatCompletionChunk, ab as OpenAIChatCompletionChunkChoice, ac as OpenAIChatCompletionDelta, O as OpenAIChatCompletionRequest, a as OpenAIChatCompletionResponse, ad as OpenAIChatCompletionStream, ae as OpenAICompletionChoice, e as OpenAICompletionChunk, c as OpenAICompletionRequest, d as OpenAICompletionResponse, af as OpenAICompletionStream, ag as OpenAIContentPart, ah as OpenAIEmbeddingInput, ai as OpenAIEmbeddingItem, f as OpenAIEmbeddingRequest, g as OpenAIEmbeddingResponse, aj as OpenAIFunctionDefinition, ak as OpenAIImageUrlContentPart, h as OpenAIListModelsResponse, al as OpenAIMessage, i as OpenAIModelItem, am as OpenAIReasoningEffort, an as OpenAIResponseFormat, ao as OpenAIResponsesCompletedEvent, ap as OpenAIResponsesContentPartAddedEvent, aq as OpenAIResponsesContentPartDoneEvent, ar as OpenAIResponsesCreatedEvent, as as OpenAIResponsesError, at as OpenAIResponsesEventBase, au as OpenAIResponsesFailedEvent, av as OpenAIResponsesFunctionCallArgumentsDeltaEvent, aw as OpenAIResponsesFunctionCallArgumentsDoneEvent, ax as OpenAIResponsesInProgressEvent, ay as OpenAIResponsesIncompleteDetails, az as OpenAIResponsesIncompleteEvent, aA as OpenAIResponsesOutputContent, aB as OpenAIResponsesOutputFunctionCall, aC as OpenAIResponsesOutputItem, aD as OpenAIResponsesOutputItemAddedEvent, aE as OpenAIResponsesOutputItemDoneEvent, aF as OpenAIResponsesOutputMessage, aG as OpenAIResponsesOutputReasoning, aH as OpenAIResponsesOutputRefusal, aI as OpenAIResponsesOutputTextContent, aJ as OpenAIResponsesOutputTextDeltaEvent, aK as OpenAIResponsesOutputTextDoneEvent, aL as OpenAIResponsesQueuedEvent, aM as OpenAIResponsesReasoningSummaryPartAddedEvent, aN as OpenAIResponsesReasoningSummaryPartDoneEvent, aO as OpenAIResponsesReasoningSummaryTextDeltaEvent, aP as OpenAIResponsesReasoningSummaryTextDoneEvent, aQ as OpenAIResponsesReasoningTextDeltaEvent, aR as OpenAIResponsesReasoningTextDoneEvent, aS as OpenAIResponsesRefusalDeltaEvent, aT as OpenAIResponsesRefusalDoneEvent, j as OpenAIResponsesRequest, k as OpenAIResponsesResponse, aU as OpenAIResponsesStatus, aV as OpenAIResponsesStream, aW as OpenAIResponsesStreamError, l as OpenAIResponsesStreamEvent, aX as OpenAIResponsesUsage, aY as OpenAIStreamOptions, aZ as OpenAITextContentPart, a_ as OpenAITool, a$ as OpenAIToolCall, b0 as OpenAIToolCallDelta, b1 as OpenAIUsage, b2 as SystemOneConfidence, b3 as SystemOneProbabilities } from './anthropic-BvHOsidk.cjs';
8
8
  import { T as ToolHandler, a as Tool, A as AnyTool, b as ToolRegistry, c as ToolExecutionResult } from './compose-DFkmtUOP.cjs';
9
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-DFkmtUOP.cjs';
10
10
  import { M as McpClientLike, a as McpToolDescriptor, b as McpTask, c as McpCallToolResult } from './types-CI-gM2u5.cjs';
@@ -1817,6 +1817,14 @@ interface ChoiceDecision {
1817
1817
  readonly probabilities: Record<string, number>;
1818
1818
  /** Distribution concentration (0–1). NOT a guarantee of correctness. */
1819
1819
  readonly confidence: number;
1820
+ /**
1821
+ * Present only when `minConfidence` was configured: `true` when
1822
+ * `confidence >= minConfidence`. Autonomous flows should treat `false` as
1823
+ * "do not act on this decision" — the official System One docs warn that a
1824
+ * high confidence does not guarantee correctness, and a barely-majority
1825
+ * choice (e.g. 0.51) is rarely safe to act on unattended.
1826
+ */
1827
+ readonly isConfident?: boolean;
1820
1828
  /** Token usage for the call. */
1821
1829
  readonly usage: {
1822
1830
  readonly input_tokens: number;
@@ -1830,7 +1838,11 @@ interface ChoiceDecision {
1830
1838
  interface NoulDecision {
1831
1839
  /** Probability of true (0–1). */
1832
1840
  readonly noul: number;
1833
- /** Boolean decision: true if noul >= 0.5, false otherwise. */
1841
+ /**
1842
+ * Boolean decision: `true` if `noul >= minProbability` (default 0.5).
1843
+ * Raise the bar for safety gates with `minProbability` — e.g. 0.8 for
1844
+ * irreversible actions.
1845
+ */
1834
1846
  readonly bool: boolean;
1835
1847
  /** Token usage for the call. */
1836
1848
  readonly usage: {
@@ -1852,6 +1864,8 @@ interface ScoreDecision {
1852
1864
  readonly probabilities: Record<string, number>;
1853
1865
  /** Distribution concentration (0–1). NOT a guarantee of correctness. */
1854
1866
  readonly confidence: number;
1867
+ /** Present only when `minConfidence` was configured: `confidence >= minConfidence`. */
1868
+ readonly isConfident?: boolean;
1855
1869
  /** Token usage for the call. */
1856
1870
  readonly usage: {
1857
1871
  readonly input_tokens: number;
@@ -1866,6 +1880,8 @@ interface RankResult<T extends string> {
1866
1880
  readonly candidate: T;
1867
1881
  readonly score: number;
1868
1882
  readonly confidence: number;
1883
+ /** Present only when `minConfidence` was configured: `confidence >= minConfidence`. */
1884
+ readonly isConfident?: boolean;
1869
1885
  }
1870
1886
  /**
1871
1887
  * Higher-level System One decision helpers.
@@ -1906,6 +1922,12 @@ interface Decision {
1906
1922
  criteria: Record<string, string | null>;
1907
1923
  images?: string[];
1908
1924
  keepAlive?: string | number;
1925
+ /**
1926
+ * Opt-in confidence gate in (0, 1]. When set, the result carries
1927
+ * `isConfident: confidence >= minConfidence` so autonomous flows can
1928
+ * refuse to act on barely-majority decisions. Off by default.
1929
+ */
1930
+ minConfidence?: number;
1909
1931
  }): Promise<ChoiceDecision>;
1910
1932
  /**
1911
1933
  * Ask a single yes/no (noul) question. Returns the probability of
@@ -1920,6 +1942,12 @@ interface Decision {
1920
1942
  instructions: SystemOneContent;
1921
1943
  images?: string[];
1922
1944
  keepAlive?: string | number;
1945
+ /**
1946
+ * Inclusive lower bound in (0, 1] the probability of `true` must meet
1947
+ * for `bool` to be `true`. Default 0.5 (a coin-flip majority). Raise it
1948
+ * (e.g. 0.8) for safety gates and irreversible actions.
1949
+ */
1950
+ minProbability?: number;
1923
1951
  }): Promise<NoulDecision>;
1924
1952
  /**
1925
1953
  * Ask a single score question. Returns the probability-weighted
@@ -1932,10 +1960,12 @@ interface Decision {
1932
1960
  model: string;
1933
1961
  state: SystemOneContent;
1934
1962
  instructions: SystemOneContent;
1935
- /** Ordered criteria from lowest (index 0) to highest. 2–26 items. */
1963
+ /** Ordered criteria from lowest (index 0) to highest. 2–10 items. */
1936
1964
  criteria: string[];
1937
1965
  images?: string[];
1938
1966
  keepAlive?: string | number;
1967
+ /** Opt-in confidence gate in (0, 1] — see {@link Decision.choice}. */
1968
+ minConfidence?: number;
1939
1969
  }): Promise<ScoreDecision>;
1940
1970
  /**
1941
1971
  * Route a request to one of N named options. Convenience wrapper
@@ -1951,9 +1981,12 @@ interface Decision {
1951
1981
  criteria: Record<T, string | null>;
1952
1982
  images?: string[];
1953
1983
  keepAlive?: string | number;
1984
+ /** Opt-in confidence gate in (0, 1] — see {@link Decision.choice}. */
1985
+ minConfidence?: number;
1954
1986
  }): Promise<{
1955
1987
  readonly route: T;
1956
1988
  readonly confidence: number;
1989
+ readonly isConfident?: boolean;
1957
1990
  }>;
1958
1991
  /**
1959
1992
  * Verify whether a claim is supported by evidence. Convenience
@@ -1972,6 +2005,11 @@ interface Decision {
1972
2005
  instructions?: SystemOneContent;
1973
2006
  images?: string[];
1974
2007
  keepAlive?: string | number;
2008
+ /**
2009
+ * Inclusive lower bound in (0, 1] the probability of `true` must meet
2010
+ * for `verified`. Default 0.5. See {@link Decision.noul}.
2011
+ */
2012
+ minProbability?: number;
1975
2013
  }): Promise<{
1976
2014
  readonly verified: boolean;
1977
2015
  readonly probability: number;
@@ -1991,7 +2029,7 @@ interface Decision {
1991
2029
  rank<T extends string>(params: {
1992
2030
  model: string;
1993
2031
  instructions: SystemOneContent;
1994
- /** Ordered criteria from lowest (index 0) to highest. 2–26 items. */
2032
+ /** Ordered criteria from lowest (index 0) to highest. 2–10 items. */
1995
2033
  criteria: string[];
1996
2034
  candidates: ReadonlyArray<{
1997
2035
  readonly id: T;
@@ -1999,6 +2037,8 @@ interface Decision {
1999
2037
  }>;
2000
2038
  images?: string[];
2001
2039
  keepAlive?: string | number;
2040
+ /** Opt-in confidence gate in (0, 1] — flags each result with `isConfident`. */
2041
+ minConfidence?: number;
2002
2042
  }): Promise<ReadonlyArray<RankResult<T>>>;
2003
2043
  }
2004
2044
  /** Create a Decision helper bound to an OllamaClient. */
@@ -2807,6 +2847,180 @@ declare function toDataStream<TChunk, TFinal>(stream: OllamaStream<TChunk, TFina
2807
2847
  */
2808
2848
  declare function toResponse<TChunk, TFinal>(stream: OllamaStream<TChunk, TFinal>, init?: ResponseInit): Response;
2809
2849
 
2850
+ /**
2851
+ * Typed progress callback helpers for `/api/pull` and `/api/push` streams.
2852
+ *
2853
+ * Ollama emits newline-delimited progress frames of the shape:
2854
+ *
2855
+ * ```json
2856
+ * {"status":"pulling manifest"}
2857
+ * {"status":"downloading","digest":"sha256:...","total":1234567,"completed":123}
2858
+ * {"status":"verifying sha256 digest"}
2859
+ * {"status":"writing manifest","digest":"sha256:...","total":42,"completed":42}
2860
+ * {"status":"success"}
2861
+ * ```
2862
+ *
2863
+ * The SDK already exposes these as a typed {@link OllamaStream} via
2864
+ * {@link ModelsClient.pull} / {@link ModelsClient.push} when called
2865
+ * with `{ stream: true }`. This file adds a higher-level helper that
2866
+ * invokes a typed callback on every progress event with a pre-computed
2867
+ * `percent` field — for callers who want a fire-and-forget pull/push
2868
+ * without manually iterating the stream.
2869
+ *
2870
+ * ## When to use this vs. the raw `OllamaStream`
2871
+ *
2872
+ * - **`onProgress(stream, cb)`** — best for download/upload UIs that
2873
+ * just need to render a progress bar. Resolves on `success`,
2874
+ * rejects on stream error.
2875
+ * - **Raw `for await ... of stream`** — best for callers who want
2876
+ * every chunk as a typed event (e.g. for structured logging, or
2877
+ * to react to specific `status` values like `"downloading"` vs
2878
+ * `"verifying sha256 digest"`).
2879
+ */
2880
+
2881
+ /**
2882
+ * A single progress event delivered to {@link onProgress}'s callback.
2883
+ *
2884
+ * `percent` is `undefined` when the server hasn't reported byte
2885
+ * totals (e.g. for `pulling manifest`, `verifying sha256 digest`,
2886
+ * `success` — these status lines carry no `total`/`completed`).
2887
+ * For `downloading` / `writing manifest` / `writing layer` style
2888
+ * events, `percent` is the ratio of `completed / total`, clamped
2889
+ * to `[0, 100]` and rounded to two decimals.
2890
+ *
2891
+ * `bytesPerSecond` and `etaSeconds` are populated by {@link onProgress}
2892
+ * (via {@link createProgressSpeedTracker}) once at least two
2893
+ * byte-bearing frames for the same layer have arrived. Callers using
2894
+ * {@link toPullProgressEvent} directly get them from their own tracker
2895
+ * — the pure wrapper never measures time.
2896
+ */
2897
+ interface PullProgressEvent {
2898
+ /** Ollama's status string (`"pulling manifest"`, `"downloading"`, `"success"`, …). */
2899
+ readonly status: string;
2900
+ /** SHA-256 digest of the layer being transferred, when applicable. */
2901
+ readonly digest?: string | undefined;
2902
+ /** Total bytes for this transfer, when the server has reported it. */
2903
+ readonly total?: number | undefined;
2904
+ /** Bytes transferred so far, when the server has reported it. */
2905
+ readonly completed?: number | undefined;
2906
+ /** Completion percentage in `[0, 100]`, or `undefined` when no byte total. */
2907
+ readonly percent?: number | undefined;
2908
+ /**
2909
+ * Cumulative-average transfer speed for the current layer, in bytes per
2910
+ * second (measured since the layer's first byte-bearing frame). `undefined`
2911
+ * until a second byte-bearing frame of the same layer arrives.
2912
+ */
2913
+ readonly bytesPerSecond?: number | undefined;
2914
+ /**
2915
+ * Estimated seconds remaining for the current layer at the observed
2916
+ * speed: `(total - completed) / bytesPerSecond`. `undefined` while the
2917
+ * speed is unknown or the server hasn't reported a total; `0` once
2918
+ * `completed >= total`.
2919
+ */
2920
+ readonly etaSeconds?: number | undefined;
2921
+ /** The raw upstream frame, for callers who need fields this helper skips. */
2922
+ readonly raw: ProgressResponse;
2923
+ }
2924
+ /**
2925
+ * Callback shape accepted by {@link onProgress}.
2926
+ */
2927
+ type ProgressCallback = (event: PullProgressEvent) => void;
2928
+ /**
2929
+ * Compute the completion percentage from a progress chunk.
2930
+ *
2931
+ * Returns `undefined` when either `total` or `completed` is missing
2932
+ * or zero (the server emits byte totals only for `downloading` /
2933
+ * `writing manifest` / `writing layer` style events; for
2934
+ * `pulling manifest`, `verifying sha256 digest`, `success`, etc. the
2935
+ * totals are absent and percent is undefined).
2936
+ *
2937
+ * When both are present, returns `Math.round((completed / total) * 10000) / 100`
2938
+ * — i.e. percent with two decimal places (e.g. `42.37`), clamped to
2939
+ * `[0, 100]` to guard against upstream reporting inconsistencies
2940
+ * (sometimes the server briefly reports `completed > total` during
2941
+ * dedup / verification phases).
2942
+ */
2943
+ declare function computeProgressPercent(chunk: ProgressResponse): number | undefined;
2944
+ /**
2945
+ * Wrap a {@link ProgressResponse} into a {@link PullProgressEvent}
2946
+ * with a pre-computed `percent` field.
2947
+ */
2948
+ declare function toPullProgressEvent(chunk: ProgressResponse): PullProgressEvent;
2949
+ /**
2950
+ * Speed/ETA readings produced by {@link createProgressSpeedTracker}.
2951
+ */
2952
+ interface ProgressSpeed {
2953
+ /** Cumulative-average bytes/second for the current layer, once measurable. */
2954
+ readonly bytesPerSecond?: number | undefined;
2955
+ /** Estimated seconds remaining for the current layer; `0` once complete. */
2956
+ readonly etaSeconds?: number | undefined;
2957
+ }
2958
+ /**
2959
+ * A stateful per-layer transfer-speed measurer. Feed it every raw
2960
+ * `ProgressResponse` chunk, in arrival order; it returns the current
2961
+ * speed/ETA readings for that chunk's layer.
2962
+ *
2963
+ * This is the building block {@link onProgress} uses internally, exported
2964
+ * for consumers who iterate the raw `OllamaStream` themselves (structured
2965
+ * logging, custom dashboards) and would otherwise have to hand-roll a
2966
+ * stateful byte counter.
2967
+ *
2968
+ * Semantics:
2969
+ * - **Per-layer epochs.** A pull/push transfers several layers; each has
2970
+ * its own `digest` and byte range, and `completed` restarts from a low
2971
+ * value when the next layer begins. The tracker starts a fresh epoch
2972
+ * whenever the digest changes or `completed` regresses, so the speed
2973
+ * never averages across layers.
2974
+ * - **Cumulative average.** Speed is measured from the layer's first
2975
+ * byte-bearing frame — `(completed - firstCompleted) / elapsed` — which
2976
+ * is stable for progress bars (instantaneous frame-to-frame rates jitter
2977
+ * wildly).
2978
+ * - **Monotonic clock.** `performance.now()`, immune to wall-clock
2979
+ * adjustments.
2980
+ *
2981
+ * @example
2982
+ * ```ts
2983
+ * const speed = createProgressSpeedTracker();
2984
+ * const stream = await client.models.pull({ model: 'llama3.2', stream: true });
2985
+ * for await (const event of stream) {
2986
+ * if (event.type === 'message') {
2987
+ * const { bytesPerSecond, etaSeconds } = speed(event.data.chunk);
2988
+ * // render: 42.37% at 8.1 MiB/s, ETA 3s
2989
+ * }
2990
+ * }
2991
+ * ```
2992
+ */
2993
+ declare function createProgressSpeedTracker(): (chunk: ProgressResponse) => ProgressSpeed;
2994
+ /**
2995
+ * Subscribe to a pull/push stream with a typed progress callback.
2996
+ *
2997
+ * Iterates the stream, invokes `callback` on every progress event
2998
+ * with a pre-computed `percent` field, and resolves when the stream
2999
+ * completes (`success` status). Rejects with {@link OllamaStreamError}
3000
+ * if the stream emits an in-band `{"error": "..."}` frame, or with
3001
+ * whatever error the underlying transport surfaces for HTTP-level
3002
+ * failures.
3003
+ *
3004
+ * @example
3005
+ * ```ts
3006
+ * const stream = await client.models.pull({ model: 'llama3.2', stream: true });
3007
+ * await onProgress(stream, (event) => {
3008
+ * if (event.percent !== undefined) {
3009
+ * console.log(`${event.status}: ${event.percent}% (${event.digest?.slice(0, 12) ?? '-'})`);
3010
+ * } else {
3011
+ * console.log(event.status);
3012
+ * }
3013
+ * });
3014
+ * console.log('pull complete');
3015
+ * ```
3016
+ *
3017
+ * @param stream The `OllamaStream` returned by `models.pull({ stream: true })`.
3018
+ * @param callback Invoked on every progress event.
3019
+ * @returns A promise that resolves to the final {@link ProgressStreamResult}
3020
+ * (carrying `status: 'success'`) when the stream completes.
3021
+ */
3022
+ declare function onProgress(stream: OllamaStream<ProgressResponse, ProgressStreamResult>, callback: ProgressCallback): Promise<ProgressStreamResult>;
3023
+
2810
3024
  /**
2811
3025
  * Zero-copy stream observation — the safe alternative to `ReadableStream.tee()`
2812
3026
  * for multi-sink consumption (audit logging, token counting, telemetry taps).
@@ -4049,4 +4263,4 @@ declare class ModelAffinityScheduler {
4049
4263
  /** Convenience factory — `createModelAffinityScheduler(client, opts)` reads better in setups. */
4050
4264
  declare function createModelAffinityScheduler(client: ModelAffinityClient | OllamaClient, options?: ModelAffinitySchedulerOptions): ModelAffinityScheduler;
4051
4265
 
4052
- 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, type AffinityRunningModel, 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 CompactionOptions, type CompareDraftPerformanceOptions, type ContextCheck, type ContextCheckOptions, type ContextDiscoveryRequestOptions, type ContextLengthSignals, type ContextLengthSource, type ContextWindowSource, type ConversationSendOptions, ConversationSession, type ConversationSessionOptions, CopyRequestOptions, type CreateModelFromGgufOptions, 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 DiscoveredContextLength, type DraftBenchmarkClient, type DraftPerformanceComparison, type DraftRunStats, type EmbedBatchOptions, type EmbedBatchResult, EmbedRequestOptions, EmbedResponse, EmbeddingsRequestOptions, EmbeddingsResponse, type EndpointHealth, type EndpointHealthCheckResult, EndpointRegistry, type EndpointRegistryOptions, FetchLike, type FetchWithBackoffConfig, FormatOption, type FormattedTelemetry, GEN_AI_SYSTEM_OLLAMA, GenerateRequestOptions, GenerateResponse, GenerateStreamResult, type HistorySanitizeOptions, 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, MESSAGE_OVERHEAD_TOKENS, McpBridge, type McpBridgeOptions, McpCallToolResult, McpClientLike, McpTask, McpToolDescriptor, Message, Middleware, type ModelAffinityClient, ModelAffinityRouter, type ModelAffinityRoutingOptions, ModelAffinityScheduler, type ModelAffinitySchedulerOptions, type ModelAffinitySnapshot, type ModelAffinityStats, 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, PingResult, ProgressResponse, ProgressStreamResult, PsResponse, PullRequestOptions, PushRequestOptions, QuotaManager, type QuotaManagerOptions, type QuotaWindowConfig, type QuotaWindowStatus, RETRYABLE_STATUS_CODES, type RankResult, type RawOllamaMetrics, RawUsageSource, RequestCancellationOptions, RequestLifecycleHook, RequestRunner, type ResponsesCreateRequest, type ResponsesCreateResponse, ResponsesModule, type ResponsesReasoningEffort, type ResponsesStreamEvent, type ResponsesToolDefinition, type ResponsesUsage, type RetryConfig, type RuntimeMode, type ScoreDecision, type SessionCompactionOptions, type SessionCompactionResult, type SessionTurn, ShowRequestOptions, ShowResponse, type SpanAttributeValue, type SpanAttributes, StatusResponse, type StreamObserverCallbacks, type StreamObserverPhase, 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, WEB_FETCH_TOOL_NAME, WEB_SEARCH_TOOL_NAME, WebFetchRequestOptions, WebFetchResponse, type WebFetchToolParams, WebSearchRequestOptions, WebSearchResponse, type WebSearchToolParams, type WebToolsClient, type WebToolsOptions, addSpanEvent, batchEmbed, calculateBackoff, canonicalToolCallSignature, checkChatContext, checkEndpointHealth, checkGenerateContext, compactConversationHistory, compareDraftPerformance, contextWarningMessage, createDecision, createModelAffinityScheduler, createOllamaCloudFreeTierQuota, createTimeoutSignal, createWebFetchTool, createWebSearchTool, createWebTools, defineTool, detectModelCapabilities, embedBatchOverflowMessage, encodeImage, estimateChatRequestTokens, estimateGenerateRequestTokens, estimateMessageTokens, estimateSystemOneRequestBytes, estimateTokens, extractContextLength as extractNativeContextLength, extractParameterNumCtx, fetchWithBackoff, findOversizedEmbedInputs, findRunningModelContextLength, formatTelemetry, formatWebFetchResult, formatWebSearchResult, inferRuntimeMode, isKeepAliveSugar, isKnownDoneReason, isModelResident, isSameToolCall, listAllMcpTools, listAvailableModels, loadMcpTools, mergeToolCall, mergeToolCallArgumentsString, mergeToolCallArrays, normalizeChatStream, normalizeGenerateStream, normalizeKeepAlive, normalizeProgressStream, observeStream, parseNdjsonStream, parseStructuredOutput, recommendContextWindow, registerMcpTools, resolveContextLength, resolveCredentialEndpoints, sanitizeHistoryForNextTurn, setSpanError, toDataStream, toResponse, toTextStream, withRetry, withSpan, zodToJsonSchema };
4266
+ 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, type AffinityRunningModel, 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 CompactionOptions, type CompareDraftPerformanceOptions, type ContextCheck, type ContextCheckOptions, type ContextDiscoveryRequestOptions, type ContextLengthSignals, type ContextLengthSource, type ContextWindowSource, type ConversationSendOptions, ConversationSession, type ConversationSessionOptions, CopyRequestOptions, type CreateModelFromGgufOptions, 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 DiscoveredContextLength, type DraftBenchmarkClient, type DraftPerformanceComparison, type DraftRunStats, type EmbedBatchOptions, type EmbedBatchResult, EmbedRequestOptions, EmbedResponse, EmbeddingsRequestOptions, EmbeddingsResponse, type EndpointHealth, type EndpointHealthCheckResult, EndpointRegistry, type EndpointRegistryOptions, FetchLike, type FetchWithBackoffConfig, FormatOption, type FormattedTelemetry, GEN_AI_SYSTEM_OLLAMA, GenerateRequestOptions, GenerateResponse, GenerateStreamResult, type HistorySanitizeOptions, 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, MESSAGE_OVERHEAD_TOKENS, McpBridge, type McpBridgeOptions, McpCallToolResult, McpClientLike, McpTask, McpToolDescriptor, Message, Middleware, type ModelAffinityClient, ModelAffinityRouter, type ModelAffinityRoutingOptions, ModelAffinityScheduler, type ModelAffinitySchedulerOptions, type ModelAffinitySnapshot, type ModelAffinityStats, 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, PingResult, type ProgressCallback, ProgressResponse, type ProgressSpeed, ProgressStreamResult, PsResponse, type PullProgressEvent, PullRequestOptions, PushRequestOptions, QuotaManager, type QuotaManagerOptions, type QuotaWindowConfig, type QuotaWindowStatus, RETRYABLE_STATUS_CODES, type RankResult, type RawOllamaMetrics, RawUsageSource, RequestCancellationOptions, RequestLifecycleHook, RequestRunner, type ResponsesCreateRequest, type ResponsesCreateResponse, ResponsesModule, type ResponsesReasoningEffort, type ResponsesStreamEvent, type ResponsesToolDefinition, type ResponsesUsage, type RetryConfig, type RuntimeMode, type ScoreDecision, type SessionCompactionOptions, type SessionCompactionResult, type SessionTurn, ShowRequestOptions, ShowResponse, type SpanAttributeValue, type SpanAttributes, StatusResponse, type StreamObserverCallbacks, type StreamObserverPhase, 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, WEB_FETCH_TOOL_NAME, WEB_SEARCH_TOOL_NAME, WebFetchRequestOptions, WebFetchResponse, type WebFetchToolParams, WebSearchRequestOptions, WebSearchResponse, type WebSearchToolParams, type WebToolsClient, type WebToolsOptions, addSpanEvent, batchEmbed, calculateBackoff, canonicalToolCallSignature, checkChatContext, checkEndpointHealth, checkGenerateContext, compactConversationHistory, compareDraftPerformance, computeProgressPercent, contextWarningMessage, createDecision, createModelAffinityScheduler, createOllamaCloudFreeTierQuota, createProgressSpeedTracker, createTimeoutSignal, createWebFetchTool, createWebSearchTool, createWebTools, defineTool, detectModelCapabilities, embedBatchOverflowMessage, encodeImage, estimateChatRequestTokens, estimateGenerateRequestTokens, estimateMessageTokens, estimateSystemOneRequestBytes, estimateTokens, extractContextLength as extractNativeContextLength, extractParameterNumCtx, fetchWithBackoff, findOversizedEmbedInputs, findRunningModelContextLength, formatTelemetry, formatWebFetchResult, formatWebSearchResult, inferRuntimeMode, isKeepAliveSugar, isKnownDoneReason, isModelResident, isSameToolCall, listAllMcpTools, listAvailableModels, loadMcpTools, mergeToolCall, mergeToolCallArgumentsString, mergeToolCallArrays, normalizeChatStream, normalizeGenerateStream, normalizeKeepAlive, normalizeProgressStream, observeStream, onProgress, parseNdjsonStream, parseStructuredOutput, recommendContextWindow, registerMcpTools, resolveContextLength, resolveCredentialEndpoints, sanitizeHistoryForNextTurn, setSpanError, toDataStream, toPullProgressEvent, toResponse, toTextStream, withRetry, withSpan, zodToJsonSchema };