@nemesis-oss/ollama-sdk 1.8.0 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +158 -0
- package/README.md +181 -10
- package/dist/{anthropic-B_UXplNF.d.ts → anthropic-5oYIRS6D.d.ts} +4 -2
- package/dist/{anthropic-CVDFy_a0.d.cts → anthropic-BIh45UXj.d.cts} +4 -2
- package/dist/{compose-DLStUfaF.d.ts → compose-DCVYMvOL.d.ts} +1 -1
- package/dist/{compose-DS-UWFx8.d.cts → compose-Dj6FdF2n.d.cts} +1 -1
- package/dist/generated-api.cjs +42 -3
- package/dist/generated-api.cjs.map +1 -1
- package/dist/generated-api.d.cts +96 -6
- package/dist/generated-api.d.ts +96 -6
- package/dist/generated-api.js +41 -4
- package/dist/generated-api.js.map +1 -1
- package/dist/generated-models-schemas.cjs +62 -2
- package/dist/generated-models-schemas.cjs.map +1 -1
- package/dist/generated-models-schemas.d.cts +108 -3
- package/dist/generated-models-schemas.d.ts +108 -3
- package/dist/generated-models-schemas.js +56 -3
- package/dist/generated-models-schemas.js.map +1 -1
- package/dist/generated-runtime.cjs +105 -5
- package/dist/generated-runtime.cjs.map +1 -1
- package/dist/generated-runtime.d.cts +2 -2
- package/dist/generated-runtime.d.ts +2 -2
- package/dist/generated-runtime.js +105 -5
- package/dist/generated-runtime.js.map +1 -1
- package/dist/index.cjs +1384 -51
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1312 -14
- package/dist/index.d.ts +1312 -14
- package/dist/index.js +1352 -52
- package/dist/index.js.map +1 -1
- package/dist/mcp/tools.json +43 -24
- package/dist/mcp-generated.cjs +43 -1
- package/dist/mcp-generated.cjs.map +1 -1
- package/dist/mcp-generated.d.cts +2 -2
- package/dist/mcp-generated.d.ts +2 -2
- package/dist/mcp-generated.js +43 -1
- package/dist/mcp-generated.js.map +1 -1
- package/dist/{runtime-C6UYtBRB.d.ts → runtime-C3rfpkZw.d.ts} +69 -2
- package/dist/{runtime-DTmUeU6K.d.cts → runtime-D2W9TfCJ.d.cts} +69 -2
- package/dist/skills.cjs.map +1 -1
- package/dist/skills.d.cts +3 -3
- package/dist/skills.d.ts +3 -3
- package/dist/skills.js.map +1 -1
- package/dist/{types-5PAjLoCp.d.cts → types-DVcX_zMp.d.cts} +110 -10
- package/dist/{types-5PAjLoCp.d.ts → types-DVcX_zMp.d.ts} +110 -10
- package/package.json +8 -5
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,127 @@
|
|
|
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-
|
|
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
|
|
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,
|
|
4
|
-
export {
|
|
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';
|
|
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-
|
|
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-
|
|
8
|
-
import { T as ToolHandler, a as Tool, A as AnyTool, b as ToolRegistry, c as ToolExecutionResult } from './compose-
|
|
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-
|
|
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';
|
|
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';
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* AUTO-GENERATED by `npm run contract:generate`. DO NOT EDIT.
|
|
16
|
+
* Source: contracts/ir/ollama.ir.json (canonical Ollama IR).
|
|
17
|
+
* See ADR 0013 and ADR 0014 for the contract-first architecture.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
interface BalanceResponse {
|
|
21
|
+
readonly included: IncludedBalance | LegacyIncludedBalance;
|
|
22
|
+
readonly purchased: {
|
|
23
|
+
/** Remaining unexpired purchased credits in USD. */
|
|
24
|
+
readonly balance_usd: number;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* AUTO-GENERATED by `npm run contract:generate`. DO NOT EDIT.
|
|
30
|
+
* Source: contracts/ir/ollama.ir.json (canonical Ollama IR).
|
|
31
|
+
* See ADR 0013 and ADR 0014 for the contract-first architecture.
|
|
32
|
+
*/
|
|
33
|
+
interface IncludedBalance {
|
|
34
|
+
/** Remaining included credits in USD. */
|
|
35
|
+
readonly balance_usd: number;
|
|
36
|
+
/** Included credits available for the full period in USD. */
|
|
37
|
+
readonly allowance_usd: number;
|
|
38
|
+
readonly period: {
|
|
39
|
+
/** Start of the included period in UTC, inclusive. */
|
|
40
|
+
readonly from: string;
|
|
41
|
+
/** End of the included period in UTC, exclusive. */
|
|
42
|
+
readonly until: string;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* AUTO-GENERATED by `npm run contract:generate`. DO NOT EDIT.
|
|
48
|
+
* Source: contracts/ir/ollama.ir.json (canonical Ollama IR).
|
|
49
|
+
* See ADR 0013 and ADR 0014 for the contract-first architecture.
|
|
50
|
+
*/
|
|
51
|
+
interface LegacyBalanceLimit {
|
|
52
|
+
/** Percentage of the limit remaining. */
|
|
53
|
+
readonly remaining_percent: number;
|
|
54
|
+
/** Next reset time in UTC. */
|
|
55
|
+
readonly resets_at: string;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* AUTO-GENERATED by `npm run contract:generate`. DO NOT EDIT.
|
|
60
|
+
* Source: contracts/ir/ollama.ir.json (canonical Ollama IR).
|
|
61
|
+
* See ADR 0013 and ADR 0014 for the contract-first architecture.
|
|
62
|
+
*/
|
|
63
|
+
|
|
64
|
+
interface LegacyIncludedBalance {
|
|
65
|
+
readonly session: LegacyBalanceLimit;
|
|
66
|
+
readonly weekly: LegacyBalanceLimit;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* AUTO-GENERATED by `npm run contract:generate`. DO NOT EDIT.
|
|
71
|
+
* Source: contracts/ir/ollama.ir.json (canonical Ollama IR).
|
|
72
|
+
* See ADR 0013 and ADR 0014 for the contract-first architecture.
|
|
73
|
+
*/
|
|
74
|
+
|
|
75
|
+
type UsageBucket = UsageMetrics & {
|
|
76
|
+
/** Start of the bucket in UTC, inclusive. */
|
|
77
|
+
readonly from: string;
|
|
78
|
+
/** End of the bucket in UTC, exclusive. */
|
|
79
|
+
readonly until: string;
|
|
80
|
+
/** Present and true for the current hour or day, which is still in progress. */
|
|
81
|
+
readonly partial?: boolean | undefined;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* AUTO-GENERATED by `npm run contract:generate`. DO NOT EDIT.
|
|
86
|
+
* Source: contracts/ir/ollama.ir.json (canonical Ollama IR).
|
|
87
|
+
* See ADR 0013 and ADR 0014 for the contract-first architecture.
|
|
88
|
+
*/
|
|
89
|
+
interface UsageMetrics {
|
|
90
|
+
/** Number of recorded requests. */
|
|
91
|
+
readonly request_count: number;
|
|
92
|
+
/** Total value of the requests in USD, including usage covered by your plan and usage paid from purchased credits. */
|
|
93
|
+
readonly usage_usd?: number | undefined;
|
|
94
|
+
/** Recorded input tokens, including cached input tokens. */
|
|
95
|
+
readonly input_tokens?: number | undefined;
|
|
96
|
+
/** Recorded input tokens read from cache, already included in input_tokens. */
|
|
97
|
+
readonly cached_input_tokens?: number | undefined;
|
|
98
|
+
/** Recorded output tokens. */
|
|
99
|
+
readonly output_tokens?: number | undefined;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* AUTO-GENERATED by `npm run contract:generate`. DO NOT EDIT.
|
|
104
|
+
* Source: contracts/ir/ollama.ir.json (canonical Ollama IR).
|
|
105
|
+
* See ADR 0013 and ADR 0014 for the contract-first architecture.
|
|
106
|
+
*/
|
|
107
|
+
|
|
108
|
+
interface UsageResponse {
|
|
109
|
+
/** Selected time range. */
|
|
110
|
+
readonly range: '24h' | '7d' | '30d';
|
|
111
|
+
/** Selected usage scope. */
|
|
112
|
+
readonly scope: 'self' | 'team';
|
|
113
|
+
/** Set automatically - hour for 24h, day for 7d and 30d. */
|
|
114
|
+
readonly granularity: 'hour' | 'day';
|
|
115
|
+
/** Start of the range in UTC, inclusive. */
|
|
116
|
+
readonly from: string;
|
|
117
|
+
/** End of the range in UTC, exclusive. */
|
|
118
|
+
readonly until: string;
|
|
119
|
+
/** Usage across the entire range. */
|
|
120
|
+
readonly totals: UsageMetrics;
|
|
121
|
+
/** Usage in chronological order, including buckets with no recorded requests. */
|
|
122
|
+
readonly buckets: readonly UsageBucket[];
|
|
123
|
+
}
|
|
124
|
+
|
|
14
125
|
/**
|
|
15
126
|
* Exponential backoff with full jitter calculation.
|
|
16
127
|
*/
|
|
@@ -291,6 +402,31 @@ interface OllamaClientConfig {
|
|
|
291
402
|
readonly logger?: Logger;
|
|
292
403
|
/** Enables console debug logger if true. */
|
|
293
404
|
readonly debug?: boolean;
|
|
405
|
+
/**
|
|
406
|
+
* Default context window (`num_ctx`) applied to every `chat`/`generate`
|
|
407
|
+
* request that doesn't set `options.num_ctx` itself. Injected as
|
|
408
|
+
* `options.num_ctx` on the wire, making the effective window explicit
|
|
409
|
+
* instead of leaving it to Ollama's server default (commonly 2048–4096,
|
|
410
|
+
* model-dependent) — which **silently truncates** prompts that don't fit,
|
|
411
|
+
* with no error and no warning. See `src/context-safety.ts`.
|
|
412
|
+
*/
|
|
413
|
+
readonly defaultContextLength?: number;
|
|
414
|
+
/**
|
|
415
|
+
* Fraction of the effective context window at which the client warns that
|
|
416
|
+
* a request's estimated prompt size is approaching truncation (default
|
|
417
|
+
* `0.9` — see `DEFAULT_CONTEXT_WARNING_THRESHOLD`).
|
|
418
|
+
*/
|
|
419
|
+
readonly contextWarningThreshold?: number;
|
|
420
|
+
/**
|
|
421
|
+
* What happens when the pre-flight context check (see
|
|
422
|
+
* `src/context-safety.ts`) concludes a request will likely be truncated:
|
|
423
|
+
* `'warn'` (default) logs a warning through the configured logger and sends
|
|
424
|
+
* the request anyway; `'throw'` rejects the request client-side with
|
|
425
|
+
* `OllamaClientError` before anything hits the wire. `'throw'` is the
|
|
426
|
+
* safety-critical choice — use it when silent history truncation would
|
|
427
|
+
* corrupt application behavior (e.g. long-context RAG, agents).
|
|
428
|
+
*/
|
|
429
|
+
readonly onContextOverflow?: 'warn' | 'throw';
|
|
294
430
|
/** Request lifecycle hook for telemetry/metrics. */
|
|
295
431
|
readonly onLifecycleEvent?: RequestLifecycleHook;
|
|
296
432
|
}
|
|
@@ -314,6 +450,20 @@ declare function checkEndpointHealth(endpoint: OllamaEndpoint, fetchImpl?: Fetch
|
|
|
314
450
|
*/
|
|
315
451
|
|
|
316
452
|
type RuntimeMode = 'local' | 'cloud' | 'unknown';
|
|
453
|
+
/**
|
|
454
|
+
* Best-effort classification of a model's parallel tool-call emission
|
|
455
|
+
* behavior. Used by agent loops that need to know whether the model
|
|
456
|
+
* is likely to emit multiple `tool_calls` in a single assistant
|
|
457
|
+
* message (parallel) or one-at-a-time (sequential).
|
|
458
|
+
*
|
|
459
|
+
* This is a **heuristic** derived from runtime mode + model family
|
|
460
|
+
* pattern matching against `/api/show`'s reported model_info. The
|
|
461
|
+
* SDK does NOT normalize between cloud and local — it reports the
|
|
462
|
+
* best assessment it can and lets the caller decide how to act.
|
|
463
|
+
*
|
|
464
|
+
* See ADR 0023 for the rationale and the recommended caller pattern.
|
|
465
|
+
*/
|
|
466
|
+
type ParallelToolCallBehavior = 'yes' | 'no' | 'unknown';
|
|
317
467
|
interface ModelCapabilities {
|
|
318
468
|
readonly model: string;
|
|
319
469
|
readonly reported: readonly string[];
|
|
@@ -338,6 +488,44 @@ interface ModelCapabilities {
|
|
|
338
488
|
* making a network call that Ollama Cloud is known to reject.
|
|
339
489
|
*/
|
|
340
490
|
readonly supportsStructuredOutputRequest: boolean;
|
|
491
|
+
/**
|
|
492
|
+
* Best-effort inference of whether the model is likely to emit
|
|
493
|
+
* **multiple `tool_calls` in a single assistant message** (parallel)
|
|
494
|
+
* vs **one tool call per assistant turn** (sequential).
|
|
495
|
+
*
|
|
496
|
+
* The SDK does NOT normalize between cloud and local — it reports
|
|
497
|
+
* the best assessment it can and lets the caller decide. Agent
|
|
498
|
+
* authors who need hard sequential execution should set
|
|
499
|
+
* `ToolRegistry`'s `maxConcurrency: 1` regardless of this field's
|
|
500
|
+
* value, since the model's behavior is not deterministic across
|
|
501
|
+
* prompts.
|
|
502
|
+
*
|
|
503
|
+
* Inference matrix (see ADR 0023):
|
|
504
|
+
*
|
|
505
|
+
* - **`'yes'`** — the model is known to emit parallel tool calls:
|
|
506
|
+
* - Cloud-mode endpoints (the OpenAI/Anthropic compat bridges
|
|
507
|
+
* proxy to proprietary models like GPT-4o, Claude, which
|
|
508
|
+
* freely emit parallel tool calls).
|
|
509
|
+
* - Local models from families that ship with parallel-tool-call
|
|
510
|
+
* training (Qwen 2.5+, Llama 3.1+ tool-use variants, Mistral
|
|
511
|
+
* function-calling fine-tunes, Hermes 2/3, Command R+).
|
|
512
|
+
*
|
|
513
|
+
* - **`'no'`** — the model is known to emit at most one tool call
|
|
514
|
+
* per assistant turn. Currently no model family is classified
|
|
515
|
+
* as `'no'` by default; the field is reserved for future
|
|
516
|
+
* narrowing as more is learned about specific models.
|
|
517
|
+
*
|
|
518
|
+
* - **`'unknown'`** — the model family is not in the known-yes or
|
|
519
|
+
* known-no list, OR `/api/show` didn't return enough
|
|
520
|
+
* information to make an assessment. Callers should treat
|
|
521
|
+
* `'unknown'` as "ask the model and see what it does" — the
|
|
522
|
+
* `ToolRegistry` will execute whatever calls the model emits,
|
|
523
|
+
* in parallel via `Promise.all` by default.
|
|
524
|
+
*
|
|
525
|
+
* See: `src/tools/registry.ts` for `maxConcurrency` enforcement,
|
|
526
|
+
* and ADR 0023 for the full design rationale.
|
|
527
|
+
*/
|
|
528
|
+
readonly parallelToolCalls: ParallelToolCallBehavior;
|
|
341
529
|
}
|
|
342
530
|
declare function inferRuntimeMode(baseUrl: string): RuntimeMode;
|
|
343
531
|
declare function detectModelCapabilities(http: HttpClient, model: string, signal?: AbortSignal): Promise<ModelCapabilities>;
|
|
@@ -375,6 +563,13 @@ declare class OllamaStream<TChunk, TFinal> implements AsyncIterable<OllamaStream
|
|
|
375
563
|
* Model and blob management operations.
|
|
376
564
|
*/
|
|
377
565
|
|
|
566
|
+
/** Result of a convenience blob upload ({@link ModelsClient.createBlobFromData}). */
|
|
567
|
+
interface BlobUploadResult {
|
|
568
|
+
/** Content digest (`sha256:<hex>`) of the uploaded payload. */
|
|
569
|
+
readonly digest: string;
|
|
570
|
+
/** True when the server already had this blob (HTTP 200) and skipped writing. */
|
|
571
|
+
readonly alreadyExisted: boolean;
|
|
572
|
+
}
|
|
378
573
|
/**
|
|
379
574
|
* Every operation here targets one specific Ollama server's local model catalog or blob
|
|
380
575
|
* store — unlike `chat`/`generate`/`embed`, a different endpoint isn't an interchangeable
|
|
@@ -413,8 +608,377 @@ declare class ModelsClient {
|
|
|
413
608
|
copy(request: CopyRequestOptions): Promise<StatusResponse>;
|
|
414
609
|
ps(): Promise<PsResponse>;
|
|
415
610
|
version(): Promise<VersionResponse>;
|
|
611
|
+
/**
|
|
612
|
+
* Immediately unloads `model` from VRAM/RAM by issuing an empty
|
|
613
|
+
* `/api/generate` request with `keep_alive: 0`. The server
|
|
614
|
+
* finalizes any in-flight generation, releases the model's
|
|
615
|
+
* weights from GPU memory, and frees the slot for subsequent
|
|
616
|
+
* pipelines (e.g. swap a vision encoder out before loading an
|
|
617
|
+
* LLM).
|
|
618
|
+
*
|
|
619
|
+
* This is the ergonomic equivalent of:
|
|
620
|
+
*
|
|
621
|
+
* ```ts
|
|
622
|
+
* client.generate({ model, prompt: '', keep_alive: 0 });
|
|
623
|
+
* ```
|
|
624
|
+
*
|
|
625
|
+
* Use {@link pin} for the opposite lifecycle — pinning a model
|
|
626
|
+
* indefinitely in VRAM for hot-loop inference.
|
|
627
|
+
*
|
|
628
|
+
* Resolves once the server acknowledges the unload. The promise
|
|
629
|
+
* rejects on transport errors, model-not-found (404), or auth
|
|
630
|
+
* failures — callers handling transient issues can retry via the
|
|
631
|
+
* standard {@link withRetry} policy.
|
|
632
|
+
*
|
|
633
|
+
* See: https://github.com/ollama/ollama/blob/main/docs/faq.md
|
|
634
|
+
* #how-do-i-keep-a-model-loaded-in-memory-or-make-it-unload-immediately
|
|
635
|
+
*/
|
|
636
|
+
unload(model: string): Promise<void>;
|
|
637
|
+
/**
|
|
638
|
+
* Pre-loads and pins `model` into VRAM indefinitely by issuing an
|
|
639
|
+
* empty `/api/generate` request with `keep_alive: -1`. The server
|
|
640
|
+
* loads the model into GPU memory (paying the cold-load latency
|
|
641
|
+
* once) and keeps it resident until either:
|
|
642
|
+
*
|
|
643
|
+
* - an explicit {@link unload} call is made,
|
|
644
|
+
* - the server process is restarted, or
|
|
645
|
+
* - the host runs out of VRAM and the server's own eviction
|
|
646
|
+
* policy kicks in.
|
|
647
|
+
*
|
|
648
|
+
* This is the ergonomic equivalent of:
|
|
649
|
+
*
|
|
650
|
+
* ```ts
|
|
651
|
+
* client.generate({ model, prompt: '', keep_alive: -1 });
|
|
652
|
+
* ```
|
|
653
|
+
*
|
|
654
|
+
* Use {@link unload} to release the pinned slot when the hot loop
|
|
655
|
+
* is done — leaving models pinned indefinitely exhausts VRAM and
|
|
656
|
+
* starves subsequent pipelines.
|
|
657
|
+
*
|
|
658
|
+
* Resolves once the server acknowledges the pin (i.e. the model
|
|
659
|
+
* is fully loaded). The promise rejects on transport errors,
|
|
660
|
+
* model-not-found (404), or VRAM-exhaustion failures.
|
|
661
|
+
*/
|
|
662
|
+
pin(model: string): Promise<void>;
|
|
416
663
|
createBlob(digest: string, data: BinaryBody): Promise<void>;
|
|
417
664
|
checkBlob(digest: string): Promise<boolean>;
|
|
665
|
+
/**
|
|
666
|
+
* Computes a blob digest the way Ollama's content-addressed store expects:
|
|
667
|
+
* SHA-256 over the raw bytes, formatted as `sha256:<64 lowercase hex>`.
|
|
668
|
+
*
|
|
669
|
+
* Uses the Web Crypto API (`crypto.subtle.digest`), which exists in every
|
|
670
|
+
* supported runtime — Node.js ≥ 19 exposes it as a global (this SDK
|
|
671
|
+
* requires Node ≥ 20), and browsers/edge runtimes have always had it.
|
|
672
|
+
*/
|
|
673
|
+
computeBlobDigest(data: Uint8Array): Promise<string>;
|
|
674
|
+
/**
|
|
675
|
+
* Computes the SHA-256 digest of `data` and pushes it as a blob in one
|
|
676
|
+
* step — the content-addressed upload Ollama's own tooling performs
|
|
677
|
+
* (`curl -T file http://…/api/blobs/sha256:…`). Returns the digest, which
|
|
678
|
+
* `/api/create`'s `files` field references.
|
|
679
|
+
*
|
|
680
|
+
* Pass `digest` to skip recomputation when the caller already knows it —
|
|
681
|
+
* the server verifies the content against the digest and rejects mismatches.
|
|
682
|
+
*/
|
|
683
|
+
createBlobFromData(data: Uint8Array, opts?: {
|
|
684
|
+
readonly digest?: string | undefined;
|
|
685
|
+
readonly signal?: AbortSignal | undefined;
|
|
686
|
+
}): Promise<BlobUploadResult>;
|
|
687
|
+
/**
|
|
688
|
+
* Reads a local file and uploads it as a blob (Node.js only — dynamic
|
|
689
|
+
* `node:fs` import, so browser bundles never pull it in). The file name
|
|
690
|
+
* (basename) is what `/api/create`'s `files` map expects as the key, so
|
|
691
|
+
* this returns it alongside the digest.
|
|
692
|
+
*/
|
|
693
|
+
createBlobFromFile(path: string, opts?: {
|
|
694
|
+
readonly signal?: AbortSignal | undefined;
|
|
695
|
+
}): Promise<BlobUploadResult & {
|
|
696
|
+
readonly fileName: string;
|
|
697
|
+
}>;
|
|
698
|
+
/**
|
|
699
|
+
* One-shot custom-model publishing from raw GGUF weights, following the
|
|
700
|
+
* protocol Ollama's API reference documents: push a blob for the GGUF
|
|
701
|
+
* bytes, then `POST /api/create` with `files: { <fileName>: <digest> }`.
|
|
702
|
+
* Split GGUFs are supported via `files` — pass every shard's path.
|
|
703
|
+
*
|
|
704
|
+
* ```ts
|
|
705
|
+
* await client.models.createModelFromGguf('my-model', '/path/to/model.gguf', {
|
|
706
|
+
* template: '{{ .Prompt }}',
|
|
707
|
+
* });
|
|
708
|
+
* ```
|
|
709
|
+
*
|
|
710
|
+
* @param model Name for the new model (e.g. `'my-model:latest'`).
|
|
711
|
+
* @param gguf Path(s) to GGUF file(s) on the local filesystem.
|
|
712
|
+
* @param opts Everything else `/api/create` accepts (`template`, `system`,
|
|
713
|
+
* `parameters`, `license`, `quantize`, …) except `files` and `from`.
|
|
714
|
+
*/
|
|
715
|
+
createModelFromGguf(model: string, gguf: string | readonly string[], opts?: Omit<CreateRequestOptions, 'model' | 'files' | 'from' | 'stream'>): Promise<ProgressResponse>;
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
/**
|
|
719
|
+
* Ergonomic OpenAI Responses API bridge — `client.responses.create()`.
|
|
720
|
+
*
|
|
721
|
+
* Ollama (v0.13.3+) exposes OpenAI's Responses API at `POST /v1/responses` as
|
|
722
|
+
* a **stateless** compatibility endpoint: it accepts `model`, `input`,
|
|
723
|
+
* `instructions`, `tools`, `stream`, `temperature`, `top_p`,
|
|
724
|
+
* `max_output_tokens`, `reasoning.effort`, `truncation`, and the Ollama
|
|
725
|
+
* extension `think` — and rejects OpenAI's stateful `previous_response_id` /
|
|
726
|
+
* `conversation` fields, because every call is independent. Responses deliver
|
|
727
|
+
* text inside `output[] → message → content[] → output_text` blocks rather
|
|
728
|
+
* than chat-completion `choices`.
|
|
729
|
+
*
|
|
730
|
+
* This module wraps that endpoint with a small, OpenAI-SDK-shaped surface for
|
|
731
|
+
* teams migrating from `openai.responses.create()` — and adds a safety net the
|
|
732
|
+
* raw compat layer doesn't have: **dual-mode transport**.
|
|
733
|
+
*
|
|
734
|
+
* 1. **Native** — POST `/v1/responses` directly. Used when the server
|
|
735
|
+
* supports it (Ollama ≥ v0.13.3, or Ollama Cloud).
|
|
736
|
+
* 2. **Chat adapter** — on `404 Not Found` (older Ollama builds without the
|
|
737
|
+
* endpoint), the same request is transparently re-issued against
|
|
738
|
+
* `/api/chat` with `instructions` mapped to a system message,
|
|
739
|
+
* `max_output_tokens` to `options.num_predict`, and tools mapped to the
|
|
740
|
+
* native tool-definition shape. The response is normalized back into the
|
|
741
|
+
* Responses form (`output_text`, `usage.input_tokens`/`output_tokens`),
|
|
742
|
+
* so migrating code works unchanged against old servers.
|
|
743
|
+
*
|
|
744
|
+
* The `transport` field on the result records which path served the request.
|
|
745
|
+
*
|
|
746
|
+
* For the full OpenAI-shaped surface (stateful fields accepted-but-ignored,
|
|
747
|
+
* raw `output` items, SSE event objects), use `client.openai.responses()`
|
|
748
|
+
* instead — this module is the ergonomic subset.
|
|
749
|
+
*/
|
|
750
|
+
|
|
751
|
+
/** Flat tool definition, matching the `openai` npm SDK's `tools[]` shape. */
|
|
752
|
+
interface ResponsesToolDefinition {
|
|
753
|
+
readonly name: string;
|
|
754
|
+
readonly description?: string | undefined;
|
|
755
|
+
readonly parameters?: ToolParameters | undefined;
|
|
756
|
+
}
|
|
757
|
+
/** Reasoning effort levels Ollama's `/v1/responses` accepts under `reasoning.effort`. */
|
|
758
|
+
type ResponsesReasoningEffort = 'low' | 'medium' | 'high';
|
|
759
|
+
/**
|
|
760
|
+
* Ergonomic request for {@link ResponsesModule.create} — the subset of
|
|
761
|
+
* OpenAI's Responses API that Ollama supports, minus the stateful fields
|
|
762
|
+
* (`previous_response_id`, `conversation`) Ollama rejects.
|
|
763
|
+
*/
|
|
764
|
+
interface ResponsesCreateRequest extends RequestCancellationOptions {
|
|
765
|
+
readonly model: string;
|
|
766
|
+
/** The user prompt. Send the full conversation here — Ollama is stateless. */
|
|
767
|
+
readonly input: string;
|
|
768
|
+
/** System/developer instructions, mapped to a system message. */
|
|
769
|
+
readonly instructions?: string | undefined;
|
|
770
|
+
readonly tools?: readonly ResponsesToolDefinition[] | undefined;
|
|
771
|
+
readonly temperature?: number | undefined;
|
|
772
|
+
readonly top_p?: number | undefined;
|
|
773
|
+
readonly max_output_tokens?: number | undefined;
|
|
774
|
+
/** Maps to `reasoning.effort` on the native endpoint; ignored by the chat adapter. */
|
|
775
|
+
readonly reasoning_effort?: ResponsesReasoningEffort | undefined;
|
|
776
|
+
/** Ollama-specific extension: thinking output control (boolean or model-defined level). */
|
|
777
|
+
readonly think?: ThinkValue | undefined;
|
|
778
|
+
}
|
|
779
|
+
/** Token usage in OpenAI Responses naming. */
|
|
780
|
+
interface ResponsesUsage {
|
|
781
|
+
readonly input_tokens: number;
|
|
782
|
+
readonly output_tokens: number;
|
|
783
|
+
readonly total_tokens: number;
|
|
784
|
+
}
|
|
785
|
+
/**
|
|
786
|
+
* Normalized, non-stateful Responses result — `output_text` is the joined
|
|
787
|
+
* text of all `output_text` content blocks, so consumers never touch the
|
|
788
|
+
* nested `output[]` structure.
|
|
789
|
+
*/
|
|
790
|
+
interface ResponsesCreateResponse {
|
|
791
|
+
readonly id: string;
|
|
792
|
+
readonly model: string;
|
|
793
|
+
readonly created_at: string;
|
|
794
|
+
readonly output_text: string;
|
|
795
|
+
/** Reasoning-model thinking trace, when produced with `think` enabled. */
|
|
796
|
+
readonly thinking?: string | undefined;
|
|
797
|
+
/** Parsed function calls the model requested, when `tools` were provided. */
|
|
798
|
+
readonly tool_calls?: readonly ToolCall[] | undefined;
|
|
799
|
+
readonly usage?: ResponsesUsage | undefined;
|
|
800
|
+
/** Which transport served the request — see the module doc on dual-mode. */
|
|
801
|
+
readonly transport: 'native' | 'chat-adapter';
|
|
802
|
+
}
|
|
803
|
+
/** Simplified streaming events from {@link ResponsesModule.stream}. */
|
|
804
|
+
type ResponsesStreamEvent = {
|
|
805
|
+
readonly type: 'text_delta';
|
|
806
|
+
readonly delta: string;
|
|
807
|
+
} | {
|
|
808
|
+
readonly type: 'thinking_delta';
|
|
809
|
+
readonly delta: string;
|
|
810
|
+
} | {
|
|
811
|
+
readonly type: 'done';
|
|
812
|
+
readonly response: ResponsesCreateResponse;
|
|
813
|
+
};
|
|
814
|
+
/**
|
|
815
|
+
* Dual-mode Responses API bridge. Access via `client.responses` — see the
|
|
816
|
+
* module doc for the transport selection rules.
|
|
817
|
+
*/
|
|
818
|
+
declare class ResponsesModule {
|
|
819
|
+
private readonly runner;
|
|
820
|
+
constructor(runner: RequestRunner);
|
|
821
|
+
/** The request body sent to the native endpoint (also reused for streaming). */
|
|
822
|
+
private nativeBody;
|
|
823
|
+
/**
|
|
824
|
+
* Runs one Responses request, preferring the native `POST /v1/responses`
|
|
825
|
+
* endpoint and transparently re-issuing via `/api/chat` when the server
|
|
826
|
+
* answers `404` (pre-v0.13.3 Ollama without the compatibility endpoint).
|
|
827
|
+
*/
|
|
828
|
+
create(req: ResponsesCreateRequest): Promise<ResponsesCreateResponse>;
|
|
829
|
+
/** Convenience: `create()` returning only the `output_text` string. */
|
|
830
|
+
createText(req: ResponsesCreateRequest): Promise<string>;
|
|
831
|
+
private createViaChatAdapter;
|
|
832
|
+
/**
|
|
833
|
+
* Streams a Responses request as simplified
|
|
834
|
+
* `{type: 'text_delta' | 'thinking_delta' | 'done'}` events. Dual-mode like
|
|
835
|
+
* {@link create}: native SSE from `/v1/responses` when available, otherwise
|
|
836
|
+
* the normalized `/api/chat` token stream. Tool calls are not delta'd —
|
|
837
|
+
* collect them from the final `done` event's `response.tool_calls`.
|
|
838
|
+
*
|
|
839
|
+
* This is a lazy async generator: nothing is sent until the first
|
|
840
|
+
* iteration, matching `for await (... of client.responses.stream(req))`
|
|
841
|
+
* intuition. The generator is also cancellable through `req.signal`.
|
|
842
|
+
*/
|
|
843
|
+
stream(req: ResponsesCreateRequest): AsyncGenerator<ResponsesStreamEvent, void, void>;
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
/**
|
|
847
|
+
* KV-prefix-preserving conversation sessions.
|
|
848
|
+
*
|
|
849
|
+
* Ollama reuses the model's KV cache across turns of a conversation by
|
|
850
|
+
* **prompt prefix matching**: if the new prompt's leading tokens are
|
|
851
|
+
* byte-identical to the previous turn's, the cached prefix is reused and
|
|
852
|
+
* only the new suffix is evaluated — surfaced by the server as
|
|
853
|
+
* `prompt_eval_cached_count`. Anything that mutates the prefix invalidates
|
|
854
|
+
* the whole cache and forces a full re-evaluation (`prompt_eval_count`
|
|
855
|
+
* spikes, latency jumps): changing the system prompt, prepending dynamic
|
|
856
|
+
* timestamps or request IDs to the conversation, or reordering past turns.
|
|
857
|
+
*
|
|
858
|
+
* `ConversationSession` makes the cache-friendly structure the default:
|
|
859
|
+
*
|
|
860
|
+
* - The system prompt (if any) is fixed at construction and always the
|
|
861
|
+
* first message. There is deliberately **no API to mutate it later** —
|
|
862
|
+
* a mutable system prompt is the #1 silent KV-cache killer.
|
|
863
|
+
* - History is append-only. Messages are never reordered, rewritten, or
|
|
864
|
+
* re-serialized between turns — `getMessages()` copies, so external
|
|
865
|
+
* mutation can't leak in either.
|
|
866
|
+
* - Per-turn options (`options`, `think`, `tools`, …) ride on the request,
|
|
867
|
+
* not the history, so changing them never disturbs the prefix.
|
|
868
|
+
*
|
|
869
|
+
* Each turn records what the server reported about the cache, so degrading
|
|
870
|
+
* hit rates (a symptom of prefix churn somewhere upstream, or a context
|
|
871
|
+
* window that no longer holds the whole history) are visible in
|
|
872
|
+
* {@link ConversationSession.cacheStats} instead of hiding in raw responses.
|
|
873
|
+
*/
|
|
874
|
+
|
|
875
|
+
/** What one turn's response reported about KV-cache reuse and evaluation. */
|
|
876
|
+
interface TurnCacheStats {
|
|
877
|
+
/** Prompt tokens served from the KV cache this turn. */
|
|
878
|
+
readonly cachedTokens: number;
|
|
879
|
+
/** Prompt tokens freshly evaluated this turn. */
|
|
880
|
+
readonly evaluatedTokens: number;
|
|
881
|
+
/**
|
|
882
|
+
* Cache hit rate for this turn: `cached / (cached + evaluated)`.
|
|
883
|
+
*
|
|
884
|
+
* Note the denominator adds both counters — when the *entire* prompt hits
|
|
885
|
+
* the cache, Ollama reports `prompt_eval_count: 0`, so dividing by
|
|
886
|
+
* `prompt_eval_count` alone would falsely yield a 0% hit rate on the
|
|
887
|
+
* best-case turn.
|
|
888
|
+
*/
|
|
889
|
+
readonly hitRate: number;
|
|
890
|
+
}
|
|
891
|
+
/** Cumulative cache statistics across every completed turn so far. */
|
|
892
|
+
interface CumulativeCacheStats extends TurnCacheStats {
|
|
893
|
+
/** Number of completed turns (user+assistant pairs). */
|
|
894
|
+
readonly turns: number;
|
|
895
|
+
/** Total prompt tokens across turns, cached + evaluated. */
|
|
896
|
+
readonly totalPromptTokens: number;
|
|
897
|
+
}
|
|
898
|
+
/** Everything one {@link ConversationSession.sendTurn} call knows. */
|
|
899
|
+
interface SessionTurn {
|
|
900
|
+
/** The assistant's text reply (same value `send()` returns). */
|
|
901
|
+
readonly content: string;
|
|
902
|
+
/** What the server reported about KV-cache reuse for this turn. */
|
|
903
|
+
readonly cache: TurnCacheStats;
|
|
904
|
+
/** The full underlying `/api/chat` response (usage, durations, thinking, …). */
|
|
905
|
+
readonly response: ChatResponse;
|
|
906
|
+
}
|
|
907
|
+
/** Per-turn overrides — none of these touch the history prefix, so they are KV-safe. */
|
|
908
|
+
interface ConversationSendOptions extends Pick<ChatRequestOptions, 'signal' | 'timeoutMs'> {
|
|
909
|
+
readonly options?: ModelOptions | undefined;
|
|
910
|
+
readonly think?: ThinkValue | undefined;
|
|
911
|
+
readonly keep_alive?: string | number | undefined;
|
|
912
|
+
readonly tools?: readonly ToolDefinition[] | undefined;
|
|
913
|
+
readonly format?: FormatOption | undefined;
|
|
914
|
+
}
|
|
915
|
+
/** Static configuration for a session, fixed at construction (KV-prefix safety). */
|
|
916
|
+
interface ConversationSessionOptions {
|
|
917
|
+
readonly model: string;
|
|
918
|
+
/**
|
|
919
|
+
* System prompt, pinned as the first history message for the session's
|
|
920
|
+
* whole lifetime. Avoid dynamic content here (timestamps, request IDs) —
|
|
921
|
+
* a per-call system prompt defeats prefix caching entirely.
|
|
922
|
+
*/
|
|
923
|
+
readonly systemPrompt?: string | undefined;
|
|
924
|
+
/** Default `options` (sampler settings, `num_ctx`, …) applied to every turn. */
|
|
925
|
+
readonly options?: ModelOptions | undefined;
|
|
926
|
+
/** Default `think` control applied to every turn. */
|
|
927
|
+
readonly think?: ThinkValue | undefined;
|
|
928
|
+
/** Default `keep_alive` applied to every turn. */
|
|
929
|
+
readonly keep_alive?: string | number | undefined;
|
|
930
|
+
/** Default `tools` applied to every turn. */
|
|
931
|
+
readonly tools?: readonly ToolDefinition[] | undefined;
|
|
932
|
+
/** Default `format` (structured output) applied to every turn. */
|
|
933
|
+
readonly format?: FormatOption | undefined;
|
|
934
|
+
}
|
|
935
|
+
/**
|
|
936
|
+
* A multi-turn chat session with an immutable, cache-friendly message
|
|
937
|
+
* history. Create via `client.session(...)` or construct directly:
|
|
938
|
+
*
|
|
939
|
+
* ```ts
|
|
940
|
+
* const session = client.session('llama3.1', 'You are a concise assistant.');
|
|
941
|
+
* await session.send('Hi!'); // turn 1 — cold cache
|
|
942
|
+
* await session.send('Why is the sky blue?'); // turn 2 — prefix reused
|
|
943
|
+
* session.cacheStats; // cumulative hit rate
|
|
944
|
+
* ```
|
|
945
|
+
*/
|
|
946
|
+
declare class ConversationSession {
|
|
947
|
+
private readonly client;
|
|
948
|
+
private readonly config;
|
|
949
|
+
/** Ordered, append-only history. Message objects are frozen on push. */
|
|
950
|
+
private readonly history;
|
|
951
|
+
/** Mutable tallies behind the read-only {@link cacheStats} view. */
|
|
952
|
+
private readonly tallies;
|
|
953
|
+
constructor(client: OllamaClient, config: ConversationSessionOptions);
|
|
954
|
+
/** The model name this session talks to. */
|
|
955
|
+
get model(): string;
|
|
956
|
+
/** Number of completed turns. */
|
|
957
|
+
get turnCount(): number;
|
|
958
|
+
/** Cumulative KV-cache statistics across completed turns. */
|
|
959
|
+
get cacheStats(): CumulativeCacheStats;
|
|
960
|
+
/**
|
|
961
|
+
* Sends the user's message and returns the assistant's reply text —
|
|
962
|
+
* the ergonomic path. Use {@link sendTurn} when you also need the
|
|
963
|
+
* per-turn cache statistics or the raw response.
|
|
964
|
+
*/
|
|
965
|
+
send(content: string, overrides?: ConversationSendOptions): Promise<string>;
|
|
966
|
+
/**
|
|
967
|
+
* Sends the user's message and returns the full turn record: reply text,
|
|
968
|
+
* per-turn KV-cache statistics, and the raw `/api/chat` response.
|
|
969
|
+
*/
|
|
970
|
+
sendTurn(content: string, overrides?: ConversationSendOptions): Promise<SessionTurn>;
|
|
971
|
+
/**
|
|
972
|
+
* A defensive copy of the session history — mutating the returned array or
|
|
973
|
+
* its frozen messages has no effect on the session.
|
|
974
|
+
*/
|
|
975
|
+
getMessages(): readonly Message[];
|
|
976
|
+
/**
|
|
977
|
+
* Clears the conversation back to its initial state (system prompt, zero
|
|
978
|
+
* turns, zeroed cache statistics). The next turn starts with a cold cache
|
|
979
|
+
* by definition — there is nothing upstream of it to reuse.
|
|
980
|
+
*/
|
|
981
|
+
reset(): void;
|
|
418
982
|
}
|
|
419
983
|
|
|
420
984
|
/**
|
|
@@ -453,6 +1017,28 @@ declare class ModelsClient {
|
|
|
453
1017
|
* Wave 13.
|
|
454
1018
|
*/
|
|
455
1019
|
|
|
1020
|
+
/**
|
|
1021
|
+
* Maximum total request size, in bytes, accepted by `/v1/systemone`
|
|
1022
|
+
* when the request body carries a non-empty `images` array.
|
|
1023
|
+
*
|
|
1024
|
+
* The Ollama server enforces this limit server-side and rejects
|
|
1025
|
+
* oversized payloads with HTTP 413. The SDK's runtime also enforces
|
|
1026
|
+
* it client-side (see `OllamaRuntime`'s `maxRequestBytesWithImages`
|
|
1027
|
+
* handling) so the round-trip is avoided.
|
|
1028
|
+
*
|
|
1029
|
+
* Without images, the limit is the much smaller
|
|
1030
|
+
* {@link MAX_SYSTEM_ONE_REQUEST_BYTES} (64 KiB) — the bumped
|
|
1031
|
+
* images-cap exists specifically to accommodate base64-encoded image
|
|
1032
|
+
* bytes shared across all questions in a single System One call.
|
|
1033
|
+
*/
|
|
1034
|
+
declare const MAX_SYSTEM_ONE_IMAGES_BYTES: number;
|
|
1035
|
+
/**
|
|
1036
|
+
* Maximum total request size, in bytes, for `/v1/systemone` when no
|
|
1037
|
+
* images are attached. The Ollama server caps the JSON-only payload
|
|
1038
|
+
* at 64 KiB; the runtime enforces this client-side (see
|
|
1039
|
+
* `OllamaRuntime`'s `maxRequestBytes`).
|
|
1040
|
+
*/
|
|
1041
|
+
declare const MAX_SYSTEM_ONE_REQUEST_BYTES: number;
|
|
456
1042
|
/**
|
|
457
1043
|
* Discriminated union of the three question kinds. The upstream OpenAPI
|
|
458
1044
|
* defines this inline as `oneOf` within SystemOneRequest.questions; we
|
|
@@ -513,6 +1099,23 @@ type SystemOneAnswers<Q extends SystemOneQuestions = SystemOneQuestions> = {
|
|
|
513
1099
|
*
|
|
514
1100
|
* The `model`, `state`, `images`, and `keep_alive` fields are inherited
|
|
515
1101
|
* from the generated base type unchanged.
|
|
1102
|
+
*
|
|
1103
|
+
* ## Image support
|
|
1104
|
+
*
|
|
1105
|
+
* The `images` field accepts up to N base64-encoded images shared by
|
|
1106
|
+
* all questions in the request. Total request payload (JSON + images)
|
|
1107
|
+
* must remain within {@link MAX_SYSTEM_ONE_IMAGES_BYTES} (32 MiB);
|
|
1108
|
+
* requests without images are capped at
|
|
1109
|
+
* {@link MAX_SYSTEM_ONE_REQUEST_BYTES} (64 KiB).
|
|
1110
|
+
*
|
|
1111
|
+
* Use {@link estimateSystemOneRequestBytes} for a client-side pre-flight
|
|
1112
|
+
* check before sending a large multi-image batch — the runtime also
|
|
1113
|
+
* enforces the limit, but the early check avoids the round-trip when
|
|
1114
|
+
* the caller already knows the payload is too large.
|
|
1115
|
+
*
|
|
1116
|
+
* Requires Clef or Clef Flash with vision weights. URLs and data URLs
|
|
1117
|
+
* are NOT supported — pre-encode the bytes to base64 before adding to
|
|
1118
|
+
* the array.
|
|
516
1119
|
*/
|
|
517
1120
|
interface SystemOneRequest<Q extends SystemOneQuestions = SystemOneQuestions> extends Omit<SystemOneRequest$1, 'questions'> {
|
|
518
1121
|
readonly questions: Q;
|
|
@@ -526,6 +1129,27 @@ interface SystemOneResponse<Q extends SystemOneQuestions = SystemOneQuestions> e
|
|
|
526
1129
|
readonly answers: SystemOneAnswers<Q>;
|
|
527
1130
|
readonly usage: SystemOneUsage;
|
|
528
1131
|
}
|
|
1132
|
+
/**
|
|
1133
|
+
* Estimate the on-the-wire byte size of a System One request body, for
|
|
1134
|
+
* pre-flight size validation against {@link MAX_SYSTEM_ONE_REQUEST_BYTES}
|
|
1135
|
+
* (no images) or {@link MAX_SYSTEM_ONE_IMAGES_BYTES} (with images).
|
|
1136
|
+
*
|
|
1137
|
+
* The estimate is conservative: it uses `JSON.stringify` length and
|
|
1138
|
+
* assumes UTF-8 encoding. The actual wire size may differ slightly due
|
|
1139
|
+
* to server-side JSON normalization (key ordering, whitespace), but the
|
|
1140
|
+
* estimate is always within a few percent of the real payload size and
|
|
1141
|
+
* is suitable for "fail fast before sending" checks.
|
|
1142
|
+
*
|
|
1143
|
+
* @example
|
|
1144
|
+
* ```ts
|
|
1145
|
+
* const request: SystemOneRequest = { ... };
|
|
1146
|
+
* const bytes = estimateSystemOneRequestBytes(request);
|
|
1147
|
+
* const cap = request.images?.length ? MAX_SYSTEM_ONE_IMAGES_BYTES : MAX_SYSTEM_ONE_REQUEST_BYTES;
|
|
1148
|
+
* if (bytes > cap) throw new Error(`payload ${bytes}B exceeds cap ${cap}B`);
|
|
1149
|
+
* await client.systemOne(request);
|
|
1150
|
+
* ```
|
|
1151
|
+
*/
|
|
1152
|
+
declare function estimateSystemOneRequestBytes(request: SystemOneRequest | SystemOneRequest$1): number;
|
|
529
1153
|
|
|
530
1154
|
/**
|
|
531
1155
|
* Higher-level System One decision helpers.
|
|
@@ -795,6 +1419,12 @@ declare class OllamaClient {
|
|
|
795
1419
|
* `OLLAMA_API_KEY`), independent of whether `config.endpoints` was used instead.
|
|
796
1420
|
*/
|
|
797
1421
|
private readonly cloudApiKey;
|
|
1422
|
+
/** Configured `defaultContextLength` — injected as `num_ctx` when a request omits it. */
|
|
1423
|
+
private readonly defaultContextLength;
|
|
1424
|
+
/** Configured `contextWarningThreshold` (default 0.9). */
|
|
1425
|
+
private readonly contextWarningThreshold;
|
|
1426
|
+
/** Configured overflow policy — `'warn'` (default) or `'throw'`. */
|
|
1427
|
+
private readonly onContextOverflow;
|
|
798
1428
|
constructor(config?: OllamaClientConfig);
|
|
799
1429
|
get modelsClient(): ModelsClient;
|
|
800
1430
|
/**
|
|
@@ -851,6 +1481,48 @@ declare class OllamaClient {
|
|
|
851
1481
|
*/
|
|
852
1482
|
get decision(): Decision;
|
|
853
1483
|
private _decision;
|
|
1484
|
+
/**
|
|
1485
|
+
* Ergonomic OpenAI Responses API bridge (`client.responses.create()` /
|
|
1486
|
+
* `.stream()`). Dual-mode transport: prefers the native `POST
|
|
1487
|
+
* /v1/responses` endpoint (Ollama ≥ v0.13.3) and transparently re-issues via
|
|
1488
|
+
* `/api/chat` when the server answers 404, so migrating OpenAI code works
|
|
1489
|
+
* unchanged against older servers. See `src/responses.ts`.
|
|
1490
|
+
*/
|
|
1491
|
+
get responses(): ResponsesModule;
|
|
1492
|
+
private _responses;
|
|
1493
|
+
/**
|
|
1494
|
+
* Starts a KV-prefix-preserving multi-turn conversation session.
|
|
1495
|
+
*
|
|
1496
|
+
* ```ts
|
|
1497
|
+
* const session = client.session('llama3.1', 'You are a concise assistant.');
|
|
1498
|
+
* const reply = await session.send('Hi!');
|
|
1499
|
+
* const detail = await session.sendTurn('Why is the sky blue?');
|
|
1500
|
+
* detail.cache.hitRate; // per-turn KV-cache hit rate
|
|
1501
|
+
* session.cacheStats; // cumulative stats across turns
|
|
1502
|
+
* ```
|
|
1503
|
+
*
|
|
1504
|
+
* Accepts either `(model, systemPrompt?)` or a full options object
|
|
1505
|
+
* (`{ model, systemPrompt, options, think, keep_alive, tools }`). See
|
|
1506
|
+
* `src/conversation.ts` for why the system prompt is pinned for the
|
|
1507
|
+
* session's lifetime.
|
|
1508
|
+
*/
|
|
1509
|
+
session(model: string, systemPrompt?: string): ConversationSession;
|
|
1510
|
+
session(options: ConversationSessionOptions): ConversationSession;
|
|
1511
|
+
/**
|
|
1512
|
+
* Context-window pre-flight enforcement — see `src/context-safety.ts` and
|
|
1513
|
+
* the `defaultContextLength` / `onContextOverflow` config docs. Logs a
|
|
1514
|
+
* warning (default) or throws client-side when the estimated prompt size
|
|
1515
|
+
* is close to / beyond the effective context window.
|
|
1516
|
+
*/
|
|
1517
|
+
private enforceContextSafety;
|
|
1518
|
+
/**
|
|
1519
|
+
* Returns `options` with `num_ctx` injected from the client's
|
|
1520
|
+
* `defaultContextLength` when the request didn't set one — making the
|
|
1521
|
+
* effective context window explicit on the wire instead of relying on
|
|
1522
|
+
* Ollama's silently-truncating server default. Returns the original
|
|
1523
|
+
* reference when there's nothing to inject (the common case).
|
|
1524
|
+
*/
|
|
1525
|
+
private injectDefaultContextLength;
|
|
854
1526
|
/**
|
|
855
1527
|
* Fail-fast guard for `format` (structured output) requests: throws before any network
|
|
856
1528
|
* call if the candidate endpoint is inferred as Ollama Cloud, which does not currently
|
|
@@ -930,6 +1602,18 @@ declare class OllamaClient {
|
|
|
930
1602
|
readonly version: () => Promise<VersionResponse>;
|
|
931
1603
|
readonly createBlob: (digest: string, data: BinaryBody) => Promise<void>;
|
|
932
1604
|
readonly checkBlob: (digest: string) => Promise<boolean>;
|
|
1605
|
+
/**
|
|
1606
|
+
* Immediately unloads `model` from VRAM. Convenience alias for
|
|
1607
|
+
* {@link ModelsClient.unload} — see that method for the full
|
|
1608
|
+
* lifecycle contract.
|
|
1609
|
+
*/
|
|
1610
|
+
readonly unloadModel: (model: string) => Promise<void>;
|
|
1611
|
+
/**
|
|
1612
|
+
* Pre-loads and pins `model` into VRAM indefinitely. Convenience
|
|
1613
|
+
* alias for {@link ModelsClient.pin} — see that method for the
|
|
1614
|
+
* full lifecycle contract.
|
|
1615
|
+
*/
|
|
1616
|
+
readonly pinModel: (model: string) => Promise<void>;
|
|
933
1617
|
/**
|
|
934
1618
|
* Ollama's System One decision layer (`POST /v1/systemone`) — evaluates
|
|
935
1619
|
* 1–64 typed questions (choice, noul, or score) against a provided state
|
|
@@ -977,6 +1661,45 @@ declare class OllamaClient {
|
|
|
977
1661
|
* which applies identically here.
|
|
978
1662
|
*/
|
|
979
1663
|
webFetch(req: WebFetchRequestOptions): Promise<WebFetchResponse>;
|
|
1664
|
+
/**
|
|
1665
|
+
* Ollama Cloud usage statistics (`GET https://ollama.com/api/usage`) — request counts,
|
|
1666
|
+
* USD spend, and token totals (including cached input tokens) for cloud inference,
|
|
1667
|
+
* web search, and web fetch, bucketed by hour (`range: '24h'`) or day (`'7d'`/`'30d'`).
|
|
1668
|
+
*
|
|
1669
|
+
* See {@link OllamaClient.webSearch} for the cloud-endpoint/auth/timeout/retry
|
|
1670
|
+
* behavior, which applies identically here. Query parameters mirror the official
|
|
1671
|
+
* endpoint: `range` (`'24h' | '7d' | '30d'`, server default `'7d'`) and `scope`
|
|
1672
|
+
* (`'self' | 'team'`, server default `'self'`; team scope requires a team admin).
|
|
1673
|
+
* Omitted options are left unset so the server applies its own defaults.
|
|
1674
|
+
*
|
|
1675
|
+
* ```ts
|
|
1676
|
+
* const usage = await client.usage({ range: '24h' });
|
|
1677
|
+
* console.log(usage.totals.request_count, usage.totals.usage_usd);
|
|
1678
|
+
* for (const bucket of usage.buckets) {
|
|
1679
|
+
* if (bucket.partial) continue; // current hour, still in progress
|
|
1680
|
+
* // ...
|
|
1681
|
+
* }
|
|
1682
|
+
* ```
|
|
1683
|
+
*/
|
|
1684
|
+
usage(req?: UsageRequestOptions): Promise<UsageResponse>;
|
|
1685
|
+
/**
|
|
1686
|
+
* Ollama Cloud balance (`GET https://ollama.com/api/balance`) — remaining included
|
|
1687
|
+
* and purchased usage credits. The included balance is either a plan-period credit
|
|
1688
|
+
* object (`balance_usd`/`allowance_usd`/`period`) or, on legacy plans, session/weekly
|
|
1689
|
+
* percentage limits; the shape is discriminated at runtime by the server response.
|
|
1690
|
+
* See {@link OllamaClient.webSearch} for the cloud-endpoint/auth/timeout/retry
|
|
1691
|
+
* behavior, which applies identically here.
|
|
1692
|
+
*
|
|
1693
|
+
* ```ts
|
|
1694
|
+
* const balance = await client.balance();
|
|
1695
|
+
* if ('balance_usd' in balance.included) {
|
|
1696
|
+
* console.log(balance.included.balance_usd, balance.purchased.balance_usd);
|
|
1697
|
+
* } else {
|
|
1698
|
+
* console.log(balance.included.session.remaining_percent, '% of session limit left');
|
|
1699
|
+
* }
|
|
1700
|
+
* ```
|
|
1701
|
+
*/
|
|
1702
|
+
balance(req?: BalanceRequestOptions): Promise<BalanceResponse>;
|
|
980
1703
|
/**
|
|
981
1704
|
* Runs `operation` against the fixed Ollama Cloud host with this client's default
|
|
982
1705
|
* timeout and retry policy — the same primitives `executeWithFailover` uses, minus the
|
|
@@ -1003,6 +1726,269 @@ interface TimeoutSignal {
|
|
|
1003
1726
|
*/
|
|
1004
1727
|
declare function createTimeoutSignal(timeoutMs?: number, userSignal?: AbortSignal): TimeoutSignal;
|
|
1005
1728
|
|
|
1729
|
+
/**
|
|
1730
|
+
* Standalone fetch-with-backoff helper.
|
|
1731
|
+
*
|
|
1732
|
+
* Ollama's server caps in-flight work via `OLLAMA_MAX_QUEUE` (default
|
|
1733
|
+
* 512); when the queue saturates, excess requests are rejected with
|
|
1734
|
+
* HTTP **503 Service Unavailable**. The same retry discipline applies
|
|
1735
|
+
* to **429 Too Many Requests** for rate-limited cloud endpoints.
|
|
1736
|
+
*
|
|
1737
|
+
* Callers running parallel agentic swarms (multi-turn tool loops,
|
|
1738
|
+
* fan-out embed batches, speculative-decoding pipelines) can't always
|
|
1739
|
+
* predict saturation ahead of time, so the SDK exposes this helper —
|
|
1740
|
+
* a thin wrapper around `fetch` that retries 503/429 responses with
|
|
1741
|
+
* the same jittered exponential backoff used by the SDK's internal
|
|
1742
|
+
* transport (see `./backoff.ts` and `./retry.ts`).
|
|
1743
|
+
*
|
|
1744
|
+
* The helper is intentionally standalone: it works with any
|
|
1745
|
+
* `fetch`-shaped function (browser `globalThis.fetch`, `undici`, an
|
|
1746
|
+
* Edge runtime polyfill, or a `vi.fn()` mock) and does not depend on
|
|
1747
|
+
* the wider `OllamaClient` / `HttpClient` machinery. Use it when you
|
|
1748
|
+
* want the SDK's retry ergonomics on raw HTTP traffic that doesn't go
|
|
1749
|
+
* through `OllamaClient` — for example, when calling the OpenAI / Anthropic
|
|
1750
|
+
* compatibility bridges directly, or when talking to a sibling Ollama
|
|
1751
|
+
* instance outside the configured endpoint registry.
|
|
1752
|
+
*
|
|
1753
|
+
* For SDK-routed traffic (`client.chat`, `client.generate`, …),
|
|
1754
|
+
* retry/backoff is already applied automatically by the transport
|
|
1755
|
+
* layer; you do NOT need to wrap those calls in `fetchWithBackoff`.
|
|
1756
|
+
*/
|
|
1757
|
+
|
|
1758
|
+
/**
|
|
1759
|
+
* Configuration for {@link fetchWithBackoff}.
|
|
1760
|
+
*
|
|
1761
|
+
* All fields optional; sensible defaults are provided.
|
|
1762
|
+
*/
|
|
1763
|
+
interface FetchWithBackoffConfig {
|
|
1764
|
+
/**
|
|
1765
|
+
* Maximum number of retry attempts after the initial request.
|
|
1766
|
+
* Defaults to `3` (i.e. up to 4 total HTTP requests).
|
|
1767
|
+
*/
|
|
1768
|
+
readonly maxRetries?: number | undefined;
|
|
1769
|
+
/**
|
|
1770
|
+
* Backoff tuning. Defaults to {@link DEFAULT_BACKOFF}
|
|
1771
|
+
* (`initialDelayMs: 500`, `maxDelayMs: 30_000`, `backoffFactor: 2`).
|
|
1772
|
+
*/
|
|
1773
|
+
readonly backoff?: BackoffOptions | undefined;
|
|
1774
|
+
/**
|
|
1775
|
+
* Optional callback fired before each retry sleep. Useful for
|
|
1776
|
+
* logging, OpenTelemetry span events, or surfacing the
|
|
1777
|
+
* backoff in observability dashboards.
|
|
1778
|
+
*
|
|
1779
|
+
* Receives the attempt index (0-based for the original request,
|
|
1780
|
+
* 1+ for retries), the HTTP status that triggered the retry
|
|
1781
|
+
* (or `0` for network-level failures), and the calculated delay
|
|
1782
|
+
* in milliseconds (already jittered).
|
|
1783
|
+
*/
|
|
1784
|
+
readonly onRetry?: ((attempt: number, status: number, delayMs: number) => void) | undefined;
|
|
1785
|
+
/**
|
|
1786
|
+
* Optional `AbortSignal` forwarded to the underlying `fetch`.
|
|
1787
|
+
* Aborting mid-backoff cancels the sleep and rejects with an
|
|
1788
|
+
* `AbortError`-shaped error (the same shape `fetch` itself
|
|
1789
|
+
* rejects with on abort).
|
|
1790
|
+
*/
|
|
1791
|
+
readonly signal?: AbortSignal | undefined;
|
|
1792
|
+
/**
|
|
1793
|
+
* Optional `fetch` implementation to use. Defaults to
|
|
1794
|
+
* `globalThis.fetch`. Pass an explicit implementation when
|
|
1795
|
+
* running in environments without a global `fetch` (legacy
|
|
1796
|
+
* Node.js, custom sandboxes), or to inject a mock for testing.
|
|
1797
|
+
*/
|
|
1798
|
+
readonly fetch?: typeof globalThis.fetch | undefined;
|
|
1799
|
+
}
|
|
1800
|
+
/**
|
|
1801
|
+
* HTTP statuses that trigger a retry by default. Both indicate
|
|
1802
|
+
* transient, server-side saturation — the queue is full and the
|
|
1803
|
+
* request is rejected without consuming inference resources.
|
|
1804
|
+
*
|
|
1805
|
+
* - `503 Service Unavailable` — Ollama queue saturated
|
|
1806
|
+
* (`OLLAMA_MAX_QUEUE` exceeded).
|
|
1807
|
+
* - `429 Too Many Requests` — rate limit hit (typically Ollama
|
|
1808
|
+
* Cloud endpoints).
|
|
1809
|
+
*/
|
|
1810
|
+
declare const RETRYABLE_STATUS_CODES: ReadonlySet<number>;
|
|
1811
|
+
/**
|
|
1812
|
+
* Default retry configuration used when {@link FetchWithBackoffConfig}
|
|
1813
|
+
* is omitted entirely. Matches the SDK's internal transport defaults
|
|
1814
|
+
* so consumers see identical retry behavior whether they go through
|
|
1815
|
+
* `OllamaClient` or call `fetchWithBackoff` directly.
|
|
1816
|
+
*/
|
|
1817
|
+
declare const DEFAULT_FETCH_BACKOFF_CONFIG: {
|
|
1818
|
+
readonly maxRetries: 3;
|
|
1819
|
+
};
|
|
1820
|
+
/**
|
|
1821
|
+
* Wrapper around any `fetch`-shaped function that retries HTTP 429 / 503
|
|
1822
|
+
* responses with jittered exponential backoff (full-jitter strategy —
|
|
1823
|
+
* see `./backoff.ts` for the rationale and AWS Architecture Blog
|
|
1824
|
+
* citation).
|
|
1825
|
+
*
|
|
1826
|
+
* The wrapper:
|
|
1827
|
+
* - forwards `input`/`init` unchanged to every attempt,
|
|
1828
|
+
* - sleeps before each retry using the configured backoff,
|
|
1829
|
+
* - retries up to `maxRetries` times (default 3), then returns the
|
|
1830
|
+
* final `Response` (whatever its status) so the caller can
|
|
1831
|
+
* branch on it,
|
|
1832
|
+
* - rethrows network errors (TypeError under WHATWG fetch) only
|
|
1833
|
+
* after exhausting retries — intermediate attempts also sleep,
|
|
1834
|
+
* - honors `AbortSignal` for both the underlying `fetch` and the
|
|
1835
|
+
* sleep between retries.
|
|
1836
|
+
*
|
|
1837
|
+
* @example
|
|
1838
|
+
* ```ts
|
|
1839
|
+
* const res = await fetchWithBackoff(
|
|
1840
|
+
* 'http://localhost:11434/api/chat',
|
|
1841
|
+
* { method: 'POST', body: JSON.stringify(payload) },
|
|
1842
|
+
* {
|
|
1843
|
+
* maxRetries: 5,
|
|
1844
|
+
* onRetry: (attempt, status, delayMs) =>
|
|
1845
|
+
* console.warn(`retry ${attempt} (HTTP ${status}) in ${delayMs}ms`),
|
|
1846
|
+
* },
|
|
1847
|
+
* );
|
|
1848
|
+
* if (!res.ok) throw new Error(`chat failed: HTTP ${res.status}`);
|
|
1849
|
+
* ```
|
|
1850
|
+
*/
|
|
1851
|
+
declare function fetchWithBackoff(input: string | URL | Request, init?: RequestInit | undefined, config?: FetchWithBackoffConfig): Promise<Response>;
|
|
1852
|
+
|
|
1853
|
+
/**
|
|
1854
|
+
* VRAM lifecycle helpers — ergonomic `keep_alive` primitives.
|
|
1855
|
+
*
|
|
1856
|
+
* Ollama's `keep_alive` parameter (accepted by `/api/generate`,
|
|
1857
|
+
* `/api/chat`, `/api/embed`, `/api/embeddings`, and `/v1/systemone`)
|
|
1858
|
+
* controls how long a model remains resident in VRAM after a request
|
|
1859
|
+
* completes. The upstream spec defines four operational semantics:
|
|
1860
|
+
*
|
|
1861
|
+
* - **Duration string** (`"5m"`, `"10s"`, `"24h"`) — explicit window.
|
|
1862
|
+
* - **Integer seconds** (`3600`, `300`) — explicit window in seconds.
|
|
1863
|
+
* - **Indefinite pinning** (`-1` or `"-1m"`) — keep the model
|
|
1864
|
+
* permanently resident in VRAM until the server is restarted or
|
|
1865
|
+
* an explicit `0` request is made. Useful for hot-loop inference
|
|
1866
|
+
* where load latency dominates.
|
|
1867
|
+
* - **Immediate eviction** (`0` or `"0s"`) — unload the model from
|
|
1868
|
+
* VRAM as soon as the response is finalized. Frees GPU memory
|
|
1869
|
+
* for the next pipeline (e.g. swap a vision model out before
|
|
1870
|
+
* loading an LLM).
|
|
1871
|
+
*
|
|
1872
|
+
* These primitives let callers express VRAM-lifecycle intent with
|
|
1873
|
+
* readable names instead of magic integers, while preserving full
|
|
1874
|
+
* backward compatibility with raw `string | number` values.
|
|
1875
|
+
*
|
|
1876
|
+
* See: https://github.com/ollama/ollama/blob/main/docs/faq.md
|
|
1877
|
+
* #how-do-i-keep-a-model-loaded-in-memory-or-make-it-unload-immediately
|
|
1878
|
+
*/
|
|
1879
|
+
/**
|
|
1880
|
+
* Sentinel value that, when passed as `keep_alive`, instructs the
|
|
1881
|
+
* server to evict the model from VRAM as soon as the in-flight
|
|
1882
|
+
* request finalizes its response. Equivalent to passing `0` or
|
|
1883
|
+
* `"0s"`.
|
|
1884
|
+
*/
|
|
1885
|
+
declare const KEEP_ALIVE_UNLOAD: 0;
|
|
1886
|
+
/**
|
|
1887
|
+
* Sentinel value that, when passed as `keep_alive`, instructs the
|
|
1888
|
+
* server to keep the model resident in VRAM indefinitely (until
|
|
1889
|
+
* the server is restarted or an explicit `0` request arrives).
|
|
1890
|
+
* Equivalent to passing `-1` or `"-1m"`.
|
|
1891
|
+
*/
|
|
1892
|
+
declare const KEEP_ALIVE_INDEFINITE: -1;
|
|
1893
|
+
/**
|
|
1894
|
+
* Ergonomic union for the `keep_alive` field on chat/generate/embed/
|
|
1895
|
+
* embeddings/System One requests.
|
|
1896
|
+
*
|
|
1897
|
+
* Accepts every upstream-supported shape plus two SDK-level sugar
|
|
1898
|
+
* literals:
|
|
1899
|
+
*
|
|
1900
|
+
* - `'unload'` — same as `0`; frees GPU VRAM after this request.
|
|
1901
|
+
* - `'indefinite'` — same as `-1`; pins the model in VRAM until
|
|
1902
|
+
* an explicit unload.
|
|
1903
|
+
*
|
|
1904
|
+
* Use {@link normalizeKeepAlive} to convert this into the raw
|
|
1905
|
+
* `string | number` shape the wire expects.
|
|
1906
|
+
*/
|
|
1907
|
+
type KeepAlive = string | number | 'unload' | 'indefinite';
|
|
1908
|
+
/**
|
|
1909
|
+
* Convert a {@link KeepAlive} value into the raw `string | number`
|
|
1910
|
+
* shape Ollama's REST API expects.
|
|
1911
|
+
*
|
|
1912
|
+
* - `'unload'` → `0` (immediate eviction)
|
|
1913
|
+
* - `'indefinite'` → `-1` (perpetual pinning)
|
|
1914
|
+
* - everything else is passed through unchanged
|
|
1915
|
+
*
|
|
1916
|
+
* Returns `undefined` for `undefined` input so callers can pipe
|
|
1917
|
+
* optional fields straight through without conditional spreads.
|
|
1918
|
+
*
|
|
1919
|
+
* @example
|
|
1920
|
+
* normalizeKeepAlive('unload') // → 0
|
|
1921
|
+
* normalizeKeepAlive('indefinite') // → -1
|
|
1922
|
+
* normalizeKeepAlive('5m') // → '5m'
|
|
1923
|
+
* normalizeKeepAlive(3600) // → 3600
|
|
1924
|
+
* normalizeKeepAlive(undefined) // → undefined
|
|
1925
|
+
*/
|
|
1926
|
+
declare function normalizeKeepAlive(keepAlive: KeepAlive | undefined): string | number | undefined;
|
|
1927
|
+
/**
|
|
1928
|
+
* Type guard: `true` when the value is one of the SDK-level sugar
|
|
1929
|
+
* literals (`'unload'` or `'indefinite'`). Useful for callers that
|
|
1930
|
+
* want to branch on intent rather than magic integers.
|
|
1931
|
+
*/
|
|
1932
|
+
declare function isKeepAliveSugar(value: KeepAlive | unknown): value is 'unload' | 'indefinite';
|
|
1933
|
+
|
|
1934
|
+
/**
|
|
1935
|
+
* `done_reason` decoder helpers — graceful handling of upstream
|
|
1936
|
+
* variance in the `done_reason` field returned by `/api/chat` and
|
|
1937
|
+
* `/api/generate`.
|
|
1938
|
+
*
|
|
1939
|
+
* The Ollama OpenAPI documents `done_reason` as a free-form string,
|
|
1940
|
+
* but the values actually observed on the wire fall into a small,
|
|
1941
|
+
* stable set:
|
|
1942
|
+
*
|
|
1943
|
+
* - `"stop"` — natural stop token hit or end-of-text.
|
|
1944
|
+
* - `"length"` — `num_predict` ceiling reached mid-generation.
|
|
1945
|
+
* - `"load"` — model load event (seen in streaming chunks
|
|
1946
|
+
* before the first token is generated; the
|
|
1947
|
+
* server reports `done: true` with `done_reason:
|
|
1948
|
+
* 'load'` to indicate the load phase completed).
|
|
1949
|
+
* - `"unload"` — model unloaded (seen after a `keep_alive: 0`
|
|
1950
|
+
* request finalizes the unload).
|
|
1951
|
+
*
|
|
1952
|
+
* The SDK accepts any string for `done_reason` (so unknown values
|
|
1953
|
+
* don't cause runtime errors — the conformance-test failure mode
|
|
1954
|
+
* the Wave 13 CI run flagged). These helpers give callers who want
|
|
1955
|
+
* to narrow on the known set a type-safe way to do so.
|
|
1956
|
+
*
|
|
1957
|
+
* See: https://github.com/ollama/ollama/blob/main/docs/api.md
|
|
1958
|
+
*/
|
|
1959
|
+
/**
|
|
1960
|
+
* The set of `done_reason` values Ollama documents and emits in
|
|
1961
|
+
* practice. Unknown upstream additions pass through as plain
|
|
1962
|
+
* strings — use {@link isKnownDoneReason} to narrow.
|
|
1963
|
+
*/
|
|
1964
|
+
type KnownDoneReason = 'stop' | 'length' | 'load' | 'unload';
|
|
1965
|
+
/**
|
|
1966
|
+
* Set of known `done_reason` literals, exposed for callers building
|
|
1967
|
+
* exhaustive `switch` statements or runtime validation tables.
|
|
1968
|
+
*/
|
|
1969
|
+
declare const KNOWN_DONE_REASONS: ReadonlySet<KnownDoneReason>;
|
|
1970
|
+
/**
|
|
1971
|
+
* Type guard: `true` when `value` is one of the documented
|
|
1972
|
+
* `done_reason` literals. Use this to safely narrow from
|
|
1973
|
+
* `string | undefined` to {@link KnownDoneReason} before a
|
|
1974
|
+
* `switch` block.
|
|
1975
|
+
*
|
|
1976
|
+
* @example
|
|
1977
|
+
* ```ts
|
|
1978
|
+
* if (isKnownDoneReason(res.done_reason)) {
|
|
1979
|
+
* switch (res.done_reason) {
|
|
1980
|
+
* case 'stop': // …
|
|
1981
|
+
* case 'length': // …
|
|
1982
|
+
* case 'load': // …
|
|
1983
|
+
* case 'unload': // …
|
|
1984
|
+
* }
|
|
1985
|
+
* } else {
|
|
1986
|
+
* // forward-compat: an unknown reason we didn't list
|
|
1987
|
+
* }
|
|
1988
|
+
* ```
|
|
1989
|
+
*/
|
|
1990
|
+
declare function isKnownDoneReason(value: string | undefined | null): value is KnownDoneReason;
|
|
1991
|
+
|
|
1006
1992
|
/**
|
|
1007
1993
|
* Normalization mappers and aggregators for Ollama streaming responses.
|
|
1008
1994
|
*/
|
|
@@ -1013,9 +1999,27 @@ declare function normalizeProgressStream(source: AbortableAsyncIterable<Progress
|
|
|
1013
1999
|
|
|
1014
2000
|
/**
|
|
1015
2001
|
* NDJSON (newline-delimited JSON) stream reader for native fetch Response bodies.
|
|
2002
|
+
*
|
|
2003
|
+
* Ollama's streaming endpoints (chat / generate / pull / push / create)
|
|
2004
|
+
* emit newline-delimited JSON objects. Each line is a complete JSON
|
|
2005
|
+
* document. The transport is chunked HTTP with status 200 OK — meaning
|
|
2006
|
+
* the HTTP status never changes mid-stream even when the server
|
|
2007
|
+
* encounters an error after generation has started.
|
|
2008
|
+
*
|
|
2009
|
+
* Instead, Ollama emits a final JSON frame of the form
|
|
2010
|
+
* `{"error": "..."}` and closes the stream. This reader detects such
|
|
2011
|
+
* in-band error frames and throws {@link OllamaStreamError} immediately,
|
|
2012
|
+
* so callers don't see the error message bleed into the assistant's
|
|
2013
|
+
* content stream as garbage tokens.
|
|
1016
2014
|
*/
|
|
1017
2015
|
/**
|
|
1018
2016
|
* Parses a byte stream from fetch body into an async generator of typed JSON chunks.
|
|
2017
|
+
*
|
|
2018
|
+
* Throws {@link OllamaStreamError} immediately upon encountering an
|
|
2019
|
+
* in-band `{"error": "..."}` frame. The thrown error carries an empty
|
|
2020
|
+
* `partialContent` (this low-level parser does not accumulate content;
|
|
2021
|
+
* the higher-level aggregator in `streaming/normalize.ts` is the
|
|
2022
|
+
* right place to surface partial content if needed).
|
|
1019
2023
|
*/
|
|
1020
2024
|
declare function parseNdjsonStream<T>(stream: ReadableStream<Uint8Array>): AsyncGenerator<T, void, undefined>;
|
|
1021
2025
|
|
|
@@ -1157,6 +2161,184 @@ interface DefineToolOptions<TParams, TResult> {
|
|
|
1157
2161
|
*/
|
|
1158
2162
|
declare function defineTool<TParams, TResult>(options: DefineToolOptions<TParams, TResult>): Tool<TParams, TResult>;
|
|
1159
2163
|
|
|
2164
|
+
/**
|
|
2165
|
+
* Tool-call streaming accumulator — defensive merge logic for
|
|
2166
|
+
* `message.tool_calls` arrays that arrive across multiple NDJSON
|
|
2167
|
+
* chunks.
|
|
2168
|
+
*
|
|
2169
|
+
* ## When this matters
|
|
2170
|
+
*
|
|
2171
|
+
* Ollama's **native `/api/chat`** streaming protocol emits
|
|
2172
|
+
* `message.tool_calls` as a complete JSON array (with parsed-object
|
|
2173
|
+
* `arguments`, not stringified deltas) in a single `done: true` chunk.
|
|
2174
|
+
* For native streaming, the accumulator here is mostly a no-op —
|
|
2175
|
+
* one chunk carries the full array, the next chunk has nothing.
|
|
2176
|
+
*
|
|
2177
|
+
* The accumulator becomes load-bearing in three scenarios:
|
|
2178
|
+
*
|
|
2179
|
+
* 1. **OpenAI-compat streaming** (`/v1/chat/completions` with
|
|
2180
|
+
* `stream: true`): tool call arguments come as string deltas
|
|
2181
|
+
* spread across multiple chunks, identified by `index`. The
|
|
2182
|
+
* compat layer at `src/integrations/openai.ts` already does
|
|
2183
|
+
* its own per-index accumulation; this utility exists for
|
|
2184
|
+
* callers who want the same logic on raw NDJSON chunks.
|
|
2185
|
+
*
|
|
2186
|
+
* 2. **Defensive native streaming**: although the documented
|
|
2187
|
+
* Ollama behavior is "tool_calls arrive in the final chunk",
|
|
2188
|
+
* a future server version could legitimately stream them
|
|
2189
|
+
* incrementally. The SDK shouldn't crash or produce
|
|
2190
|
+
* duplicates if that happens.
|
|
2191
|
+
*
|
|
2192
|
+
* 3. **Caller-side buffering**: agent loops that consume
|
|
2193
|
+
* `OllamaStream` events directly may want to buffer tool-call
|
|
2194
|
+
* deltas themselves rather than trust the SDK's aggregator —
|
|
2195
|
+
* this utility gives them a typed, tested building block.
|
|
2196
|
+
*
|
|
2197
|
+
* ## Merge semantics
|
|
2198
|
+
*
|
|
2199
|
+
* Two `ToolCall` entries are considered "the same call" when they
|
|
2200
|
+
* share the same `id` (the SDK-synthesized stable identifier — see
|
|
2201
|
+
* `src/tools/tool-call-id.ts`), OR when they're at the same array
|
|
2202
|
+
* position and neither has an `id`. When two same-call entries are
|
|
2203
|
+
* merged:
|
|
2204
|
+
*
|
|
2205
|
+
* - `function.name` — the later chunk's name wins (the model may
|
|
2206
|
+
* emit the name in a later chunk after an initial empty one).
|
|
2207
|
+
* - `function.arguments` — the two objects are merged with
|
|
2208
|
+
* spread semantics: `{...earlier, ...later}`. This handles
|
|
2209
|
+
* the case where the model emits arguments incrementally as
|
|
2210
|
+
* partial JSON objects (which is non-standard but seen in some
|
|
2211
|
+
* open-weights fine-tunes).
|
|
2212
|
+
*
|
|
2213
|
+
* For arguments-as-string deltas (the OpenAI-compat case), the
|
|
2214
|
+
* accumulator concatenates the strings rather than merging — see
|
|
2215
|
+
* {@link mergeToolCallArgumentsString}.
|
|
2216
|
+
*/
|
|
2217
|
+
|
|
2218
|
+
/**
|
|
2219
|
+
* Determine whether two `ToolCall` entries refer to the same logical
|
|
2220
|
+
* call (and should therefore be merged rather than appended).
|
|
2221
|
+
*
|
|
2222
|
+
* Returns `true` when:
|
|
2223
|
+
* - both have an `id` and the ids match, OR
|
|
2224
|
+
* - neither has an `id` and they're at the same array index
|
|
2225
|
+
* (caller is responsible for the index check — this helper
|
|
2226
|
+
* only handles the id case).
|
|
2227
|
+
*/
|
|
2228
|
+
declare function isSameToolCall(a: ToolCall, b: ToolCall, aIndex?: number, bIndex?: number): boolean;
|
|
2229
|
+
/**
|
|
2230
|
+
* Merge two `ToolCall` entries that refer to the same logical call.
|
|
2231
|
+
*
|
|
2232
|
+
* The later chunk's `function.name` wins when present; otherwise the
|
|
2233
|
+
* earlier one's name is preserved. The two `arguments` objects are
|
|
2234
|
+
* merged with spread semantics (`{...earlier, ...later}`), which
|
|
2235
|
+
* handles the (non-standard but observed) case where the model
|
|
2236
|
+
* emits arguments as partial JSON objects across chunks.
|
|
2237
|
+
*
|
|
2238
|
+
* For arguments-as-string deltas (OpenAI-compat streaming), use
|
|
2239
|
+
* {@link mergeToolCallArgumentsString} instead.
|
|
2240
|
+
*/
|
|
2241
|
+
declare function mergeToolCall(earlier: ToolCall, later: ToolCall): ToolCall;
|
|
2242
|
+
/**
|
|
2243
|
+
* Merge two `ToolCall` entries where `function.arguments` is a JSON
|
|
2244
|
+
* string (the OpenAI-compat streaming format), concatenating the
|
|
2245
|
+
* string deltas rather than spreading objects.
|
|
2246
|
+
*
|
|
2247
|
+
* Returns a `ToolCall` whose `function.arguments` is the
|
|
2248
|
+
* concatenated string. The caller is responsible for JSON-parsing
|
|
2249
|
+
* the final string when the stream completes.
|
|
2250
|
+
*/
|
|
2251
|
+
declare function mergeToolCallArgumentsString(earlier: ToolCall, later: ToolCall): ToolCall;
|
|
2252
|
+
/**
|
|
2253
|
+
* Defensive accumulator for `message.tool_calls` arrays that arrive
|
|
2254
|
+
* across multiple NDJSON chunks. Used internally by
|
|
2255
|
+
* `aggregateChat` in `src/streaming/normalize.ts` so the SDK doesn't
|
|
2256
|
+
* produce duplicate tool_call entries if a future server version
|
|
2257
|
+
* starts streaming them incrementally.
|
|
2258
|
+
*
|
|
2259
|
+
* The merge strategy is:
|
|
2260
|
+
*
|
|
2261
|
+
* - For each tool call in the new chunk, check whether an existing
|
|
2262
|
+
* entry matches (by `id` if both have one, by array position
|
|
2263
|
+
* otherwise).
|
|
2264
|
+
* - If a match is found, merge the two entries via
|
|
2265
|
+
* {@link mergeToolCall}.
|
|
2266
|
+
* - If no match is found, append the new entry.
|
|
2267
|
+
*
|
|
2268
|
+
* This preserves the documented native Ollama behavior (tool_calls
|
|
2269
|
+
* arrive complete in one chunk → no merge happens, just one append)
|
|
2270
|
+
* while being defensive against incremental streaming.
|
|
2271
|
+
*
|
|
2272
|
+
* @example
|
|
2273
|
+
* ```ts
|
|
2274
|
+
* const acc = new ToolCallAccumulator();
|
|
2275
|
+
* acc.process([
|
|
2276
|
+
* { function: { name: 'get_weather', arguments: { city: 'Tokyo' } } },
|
|
2277
|
+
* ]);
|
|
2278
|
+
* acc.process([
|
|
2279
|
+
* { function: { name: 'get_weather', arguments: { unit: 'celsius' } } },
|
|
2280
|
+
* ]);
|
|
2281
|
+
* const result = acc.finalize();
|
|
2282
|
+
* // → [{ function: { name: 'get_weather', arguments: { city: 'Tokyo', unit: 'celsius' } } }]
|
|
2283
|
+
* ```
|
|
2284
|
+
*/
|
|
2285
|
+
declare class ToolCallAccumulator {
|
|
2286
|
+
private readonly entries;
|
|
2287
|
+
/**
|
|
2288
|
+
* Process a chunk's `tool_calls` array. Entries that match an
|
|
2289
|
+
* existing accumulated entry (by id or array position) are merged;
|
|
2290
|
+
* new entries are appended.
|
|
2291
|
+
*
|
|
2292
|
+
* Returns the current accumulated state (a shallow copy — entries
|
|
2293
|
+
* themselves are NOT deep-cloned, so callers that mutate
|
|
2294
|
+
* `function.arguments` on a returned entry will mutate the
|
|
2295
|
+
* accumulator's internal state. Use {@link snapshot} for an
|
|
2296
|
+
* explicitly read-only view, or deep-clone the result if you need
|
|
2297
|
+
* full isolation).
|
|
2298
|
+
*/
|
|
2299
|
+
process(toolCalls: readonly ToolCall[] | undefined): readonly ToolCall[];
|
|
2300
|
+
/**
|
|
2301
|
+
* Returns the final accumulated tool calls. Identical to calling
|
|
2302
|
+
* `process(undefined)` — included for ergonomics so callers can
|
|
2303
|
+
* express "I'm done, give me the result" without a no-op call.
|
|
2304
|
+
*
|
|
2305
|
+
* The returned array is a shallow copy; entries themselves are
|
|
2306
|
+
* the same object references the accumulator holds internally.
|
|
2307
|
+
*/
|
|
2308
|
+
finalize(): readonly ToolCall[];
|
|
2309
|
+
/**
|
|
2310
|
+
* Returns the current accumulated state without modifying the
|
|
2311
|
+
* accumulator. Useful for mid-stream inspection.
|
|
2312
|
+
*
|
|
2313
|
+
* The returned array is a shallow copy; mutating it (e.g.
|
|
2314
|
+
* `result.push(...)`) does not affect the accumulator, but
|
|
2315
|
+
* mutating an entry's `function.arguments` object DOES affect
|
|
2316
|
+
* the accumulator's internal state because the entry reference
|
|
2317
|
+
* is shared. Deep-clone the result if you need full isolation.
|
|
2318
|
+
*/
|
|
2319
|
+
snapshot(): readonly ToolCall[];
|
|
2320
|
+
/**
|
|
2321
|
+
* Returns the number of accumulated tool calls so far.
|
|
2322
|
+
*/
|
|
2323
|
+
get length(): number;
|
|
2324
|
+
}
|
|
2325
|
+
/**
|
|
2326
|
+
* Convenience function: merge two `tool_calls` arrays using the
|
|
2327
|
+
* default accumulator semantics, returning the merged array.
|
|
2328
|
+
*
|
|
2329
|
+
* Stateless equivalent of:
|
|
2330
|
+
*
|
|
2331
|
+
* ```ts
|
|
2332
|
+
* const acc = new ToolCallAccumulator();
|
|
2333
|
+
* acc.process(earlier);
|
|
2334
|
+
* acc.process(later);
|
|
2335
|
+
* return acc.finalize();
|
|
2336
|
+
* ```
|
|
2337
|
+
*
|
|
2338
|
+
* Useful for one-off merges without instantiating an accumulator.
|
|
2339
|
+
*/
|
|
2340
|
+
declare function mergeToolCallArrays(earlier: readonly ToolCall[] | undefined, later: readonly ToolCall[] | undefined): readonly ToolCall[];
|
|
2341
|
+
|
|
1160
2342
|
/**
|
|
1161
2343
|
* Converts MCP tools into Ollama-compatible tools.
|
|
1162
2344
|
*/
|
|
@@ -1348,15 +2530,131 @@ declare const GEN_AI_SYSTEM_OLLAMA = "ollama";
|
|
|
1348
2530
|
* Cross-runtime helpers with no Node.js API dependency, so they stay safe to import from
|
|
1349
2531
|
* the core client bundle (see ADR 0006 — Edge Runtime CI).
|
|
1350
2532
|
*/
|
|
2533
|
+
|
|
1351
2534
|
/**
|
|
1352
2535
|
* Encodes an image to a base64 string, matching the wire format Ollama's `/api/chat` and
|
|
1353
2536
|
* `/api/generate` `images` arrays expect.
|
|
1354
2537
|
*
|
|
1355
|
-
* - A `string` is assumed to already be base64-encoded and is returned unchanged.
|
|
1356
|
-
*
|
|
1357
|
-
*
|
|
1358
|
-
*
|
|
2538
|
+
* - A `string` is assumed to already be base64-encoded and is returned unchanged. For
|
|
2539
|
+
* data URIs, URLs, and local file paths use {@link resolveImageInput}, which this SDK's
|
|
2540
|
+
* request pipeline applies automatically (see {@link withEncodedImages}).
|
|
2541
|
+
* - A `Uint8Array` (or Node `Buffer`) is base64-encoded using whichever universal primitive
|
|
2542
|
+
* the runtime exposes: `Buffer` on Node.js, `btoa` on browsers/Edge runtimes. Chunked so it
|
|
2543
|
+
* doesn't blow the engine's max call-stack/argument-count limits on large images.
|
|
2544
|
+
*/
|
|
2545
|
+
declare function encodeImage(image: VisionInput): Promise<string>;
|
|
2546
|
+
|
|
2547
|
+
/**
|
|
2548
|
+
* Context-window safety: client-side token estimation and pre-flight overflow
|
|
2549
|
+
* warnings for `/api/chat` and `/api/generate`.
|
|
2550
|
+
*
|
|
2551
|
+
* Why this exists: when `options.num_ctx` is left unset, Ollama loads the
|
|
2552
|
+
* model with a conservative default context window (commonly 2048–4096
|
|
2553
|
+
* tokens, model-dependent) and **silently truncates** any prompt that doesn't
|
|
2554
|
+
* fit — the model just loses the top of the conversation with no error, no
|
|
2555
|
+
* warning, and often no visible symptom beyond degraded answers. This module
|
|
2556
|
+
* estimates the prompt size client-side (a fast heuristic — no tokenizer
|
|
2557
|
+
* download, no model dependency) and surfaces a warning *before* the request
|
|
2558
|
+
* is sent, when the estimate approaches the effective context window.
|
|
2559
|
+
*
|
|
2560
|
+
* The estimator is deliberately simple and documented as approximate
|
|
2561
|
+
* (±20–30% vs a real BPE tokenizer):
|
|
2562
|
+
*
|
|
2563
|
+
* - CJK code points (Chinese/Japanese/Korean) count as ~1 token each —
|
|
2564
|
+
* modern tokenizers emit roughly one token per CJK character.
|
|
2565
|
+
* - Everything else estimates at ~4 characters per token, the classic
|
|
2566
|
+
* English GPT-style average.
|
|
2567
|
+
* - Each attached image adds a fixed {@link IMAGE_TOKEN_ESTIMATE} —
|
|
2568
|
+
* vision encoders consume a roughly predictable tile budget per image
|
|
2569
|
+
* (e.g. LLaVA-family encoders emit a few hundred tokens per image).
|
|
2570
|
+
*
|
|
2571
|
+
* It is used in three places:
|
|
2572
|
+
*
|
|
2573
|
+
* 1. `OllamaClient.chat()`/`generate()` pre-flight — logs a warning (or
|
|
2574
|
+
* throws, per `onContextOverflow`) when the estimate crosses
|
|
2575
|
+
* {@link DEFAULT_CONTEXT_WARNING_THRESHOLD} of the effective window.
|
|
2576
|
+
* 2. The `defaultContextLength` client config — injects `num_ctx` when the
|
|
2577
|
+
* caller didn't set one, making the effective window explicit instead
|
|
2578
|
+
* of server-default guesswork.
|
|
2579
|
+
* 3. `ConversationSession` — sessions grow monotonically, so they surface
|
|
2580
|
+
* cache and context stats per turn.
|
|
2581
|
+
*/
|
|
2582
|
+
|
|
2583
|
+
/**
|
|
2584
|
+
* Fraction of the effective context window at which a pre-flight warning
|
|
2585
|
+
* fires. 0.9 = warn when the estimated prompt reaches 90% of `num_ctx`.
|
|
2586
|
+
* Above this, the response has little room left and the next turn's history
|
|
2587
|
+
* will almost certainly overflow.
|
|
2588
|
+
*/
|
|
2589
|
+
declare const DEFAULT_CONTEXT_WARNING_THRESHOLD = 0.9;
|
|
2590
|
+
/**
|
|
2591
|
+
* Rough token budget consumed per attached image. Vision encoders emit a few
|
|
2592
|
+
* hundred embedding tokens per image tile; 300 sits between LLaVA-1.5's ~258
|
|
2593
|
+
* and qwen-vl's higher tile counts. This is an estimate for warning purposes
|
|
2594
|
+
* only — it never gates a request on its own unless images push the total
|
|
2595
|
+
* past the threshold.
|
|
2596
|
+
*/
|
|
2597
|
+
declare const IMAGE_TOKEN_ESTIMATE = 300;
|
|
2598
|
+
/**
|
|
2599
|
+
* Heuristic token estimate for a single text string: ~1 token per CJK
|
|
2600
|
+
* character + ~1 token per 4 non-CJK characters. Approximate by design —
|
|
2601
|
+
* accurate enough to warn against silent truncation without shipping a
|
|
2602
|
+
* model-specific tokenizer.
|
|
2603
|
+
*/
|
|
2604
|
+
declare function estimateTokens(text: string): number;
|
|
2605
|
+
/**
|
|
2606
|
+
* Estimated prompt tokens for a `/api/chat` request: every message plus
|
|
2607
|
+
* tool-schema overhead (each tool definition's JSON schema serializes into
|
|
2608
|
+
* the prompt on Ollama's side).
|
|
2609
|
+
*/
|
|
2610
|
+
declare function estimateChatRequestTokens(req: ChatRequestOptions): number;
|
|
2611
|
+
/** Estimated prompt tokens for a `/api/generate` request (prompt + system + images). */
|
|
2612
|
+
declare function estimateGenerateRequestTokens(req: GenerateRequestOptions): number;
|
|
2613
|
+
/** Where the context window used by a pre-flight check came from. */
|
|
2614
|
+
type ContextWindowSource =
|
|
2615
|
+
/** Explicit `options.num_ctx` on the request — exact, server-enforced. */
|
|
2616
|
+
'request'
|
|
2617
|
+
/** Client `defaultContextLength` config — injected as `num_ctx` by the pipeline. */
|
|
2618
|
+
| 'client-default'
|
|
2619
|
+
/** Neither set; Ollama's server default applies (2048–4096, model-dependent). */
|
|
2620
|
+
| 'server-fallback';
|
|
2621
|
+
/** What the pre-flight check concluded about one request. */
|
|
2622
|
+
interface ContextCheck {
|
|
2623
|
+
/** Estimated prompt tokens (heuristic — see {@link estimateTokens}). */
|
|
2624
|
+
readonly estimatedPromptTokens: number;
|
|
2625
|
+
/** The context window the estimate was compared against. */
|
|
2626
|
+
readonly effectiveContextLength: number;
|
|
2627
|
+
/** Where that window came from. */
|
|
2628
|
+
readonly windowSource: ContextWindowSource;
|
|
2629
|
+
/** True when the estimate crossed the warning threshold of the effective window. */
|
|
2630
|
+
readonly exceedsThreshold: boolean;
|
|
2631
|
+
}
|
|
2632
|
+
interface ContextCheckOptions {
|
|
2633
|
+
/** Client `defaultContextLength`, applied when the request doesn't set `num_ctx`. */
|
|
2634
|
+
readonly defaultContextLength?: number | undefined;
|
|
2635
|
+
/** Warning threshold; defaults to {@link DEFAULT_CONTEXT_WARNING_THRESHOLD}. */
|
|
2636
|
+
readonly threshold?: number | undefined;
|
|
2637
|
+
}
|
|
2638
|
+
/**
|
|
2639
|
+
* Runs the pre-flight context check for a chat request. Pure — callers decide
|
|
2640
|
+
* what to do with the result (log, throw, ignore).
|
|
2641
|
+
*/
|
|
2642
|
+
declare function checkChatContext(req: ChatRequestOptions, options?: ContextCheckOptions): ContextCheck;
|
|
2643
|
+
/**
|
|
2644
|
+
* Runs the pre-flight context check for a generate request. Pure — callers
|
|
2645
|
+
* decide what to do with the result (log, throw, ignore).
|
|
2646
|
+
*/
|
|
2647
|
+
declare function checkGenerateContext(req: GenerateRequestOptions, options?: ContextCheckOptions): ContextCheck;
|
|
2648
|
+
/**
|
|
2649
|
+
* The conservative server-side default (2048) Ollama most commonly applies
|
|
2650
|
+
* when `num_ctx` is unset — used to warn about *likely* truncation even when
|
|
2651
|
+
* no effective window is known client-side.
|
|
2652
|
+
*/
|
|
2653
|
+
declare const OLLAMA_FALLBACK_CONTEXT_LENGTH = 2048;
|
|
2654
|
+
/**
|
|
2655
|
+
* Builds the human-readable warning text for a failed pre-flight check.
|
|
2656
|
+
* Exported for reuse by `ConversationSession` and for tests.
|
|
1359
2657
|
*/
|
|
1360
|
-
declare function
|
|
2658
|
+
declare function contextWarningMessage(check: ContextCheck, kind: 'chat' | 'generate'): string;
|
|
1361
2659
|
|
|
1362
|
-
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, ChatRequestOptions, ChatResponse, ChatStreamResult, type ChoiceDecision, CopyRequestOptions, CreateRequestOptions, DEFAULT_BACKOFF, DEFAULT_BASE_URL, DEFAULT_FAILOVER_CODES, DEFAULT_RETRY_CONFIG, DEFAULT_TIMEOUT_MS, type Decision, type DefineToolOptions, DeleteRequestOptions, EmbedRequestOptions, EmbedResponse, EmbeddingsRequestOptions, EmbeddingsResponse, type EndpointHealth, type EndpointHealthCheckResult, EndpointRegistry, type EndpointRegistryOptions, FetchLike, GEN_AI_SYSTEM_OLLAMA, GenerateRequestOptions, GenerateResponse, GenerateStreamResult, HttpClient, type LoadMcpToolsOptions, Logger, McpBridge, type McpBridgeOptions, McpCallToolResult, McpClientLike, McpTask, McpToolDescriptor, Message, Middleware, type ModelCapabilities, ModelOptions, ModelResponse, ModelsClient, type NoulDecision, OLLAMA_CLOUD_BASE_URL, OllamaClient, type OllamaClientConfig, type OllamaCloudFreeTierQuotaBudgets, type OllamaCredentialConfig, type OllamaEndpoint, OllamaStream, OllamaStreamEvent, OllamaStreamEventType, OpenAICompatClient, ProgressResponse, ProgressStreamResult, PsResponse, PullRequestOptions, PushRequestOptions, QuotaManager, type QuotaManagerOptions, type QuotaWindowConfig, type QuotaWindowStatus, type RankResult, RawUsageSource, RequestLifecycleHook, RequestRunner, type RetryConfig, type RuntimeMode, type ScoreDecision, 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, ToolDefinition, ToolExecutionResult, ToolHandler, ToolRegistry, VersionResponse, WebFetchRequestOptions, WebFetchResponse, WebSearchRequestOptions, WebSearchResponse, addSpanEvent, calculateBackoff, checkEndpointHealth, createDecision, createOllamaCloudFreeTierQuota, createTimeoutSignal, defineTool, detectModelCapabilities, encodeImage, inferRuntimeMode, listAllMcpTools, listAvailableModels, loadMcpTools, normalizeChatStream, normalizeGenerateStream, normalizeProgressStream, parseNdjsonStream, parseStructuredOutput, registerMcpTools, resolveCredentialEndpoints, setSpanError, toDataStream, toResponse, toTextStream, withRetry, withSpan, zodToJsonSchema };
|
|
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 };
|