@nemesis-oss/ollama-sdk 1.12.1 → 1.13.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 +26 -0
- package/README.md +38 -4
- package/dist/{anthropic-CKp5TmAP.d.ts → anthropic-B9AFyzXI.d.ts} +64 -17
- package/dist/{anthropic-Did0lQxP.d.cts → anthropic-CYy_ECam.d.cts} +64 -17
- package/dist/generated-api.cjs +3 -2
- package/dist/generated-api.cjs.map +1 -1
- package/dist/generated-api.d.cts +12 -6
- package/dist/generated-api.d.ts +12 -6
- package/dist/generated-api.js +3 -2
- package/dist/generated-api.js.map +1 -1
- package/dist/generated-models-schemas.cjs +1 -1
- package/dist/generated-models-schemas.cjs.map +1 -1
- package/dist/generated-models-schemas.js +1 -1
- package/dist/generated-models-schemas.js.map +1 -1
- package/dist/generated-runtime.cjs +2 -1
- package/dist/generated-runtime.cjs.map +1 -1
- package/dist/generated-runtime.js +2 -1
- package/dist/generated-runtime.js.map +1 -1
- package/dist/index.cjs +175 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +66 -4
- package/dist/index.d.ts +66 -4
- package/dist/index.js +169 -24
- package/dist/index.js.map +1 -1
- package/dist/mcp/tools.json +4 -4
- package/dist/mcp-generated.cjs +3 -2
- package/dist/mcp-generated.cjs.map +1 -1
- package/dist/mcp-generated.js +3 -2
- package/dist/mcp-generated.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -3,8 +3,8 @@ export { L as ListResponse, x as Logprob, y as LogprobToken, z as ModelDetails,
|
|
|
3
3
|
import { H as HttpClient, F as FetchLike, M as Middleware, L as Logger, R as RequestLifecycleHook, c as OllamaStreamEvent, A as AbortableAsyncIterable, d as OllamaStreamEventType, P as ProgressStreamResult, B as BinaryBody, O as OllamaRuntime, C as ChatStreamResult, G as GenerateStreamResult, e as RawUsageSource, T as TokenUsage } from './runtime-DmI1cOEq.cjs';
|
|
4
4
|
export { D as DoneEvent, E as ErrorEvent, f as HttpBody, g as HttpClientOptions, h as HttpRequestOptions, i as LifecycleErrorEvent, j as LifecycleRetryEvent, k as LifecycleStartEvent, l as LifecycleSuccessEvent, m as LogFn, n as MessageEvent, o as MiddlewareContext, N as NANOS_PER_MS, p as NANOS_PER_SECOND, q as NOOP_LOGGER, r as NextFunction, s as OllamaAbortError, t as OllamaAgentMaxIterationsError, u as OllamaAgentMaxToolCallsError, v as OllamaAgentToolLoopError, w as OllamaAuthError, x as OllamaBadGatewayError, y as OllamaClientError, z as OllamaClientErrorOptions, J as OllamaErrorRequestContext, K as OllamaErrorResponseContext, Q as OllamaGenericClientError, U as OllamaIncompatibleModelError, V as OllamaMcpError, W as OllamaModelRoutingError, X as OllamaNetworkError, Y as OllamaNotFoundError, Z as OllamaOverloadedError, _ as OllamaQuotaExceededError, $ as OllamaRateLimitError, a0 as OllamaRequestTooLargeError, a1 as OllamaRequestValidationError, a2 as OllamaResponseValidationError, a3 as OllamaServerError, a4 as OllamaServerVersionUnknownError, a5 as OllamaSkillInvalidError, a6 as OllamaSkillNotFoundError, a7 as OllamaStreamError, a8 as OllamaTimeoutError, a9 as OllamaToolTimeoutError, aa as OllamaToolValidationError, ab as OllamaUnsupportedCapabilityError, ac as RequestContext, ad as RequestLifecycleEvent, ae as ResponseContext, af as SseEvent, ag as ThinkingEvent, ah as TokenEvent, ai as ToolCallEvent, aj as composeMiddleware, ak as createConsoleLogger, al as extractUsage, am as mapError, an as parseSseStream } from './runtime-DmI1cOEq.cjs';
|
|
5
5
|
import { z } from 'zod';
|
|
6
|
-
import { R as RequestRunner, S as SystemOneChoiceAnswer, o as SystemOneNoulAnswer, p as SystemOneScoreAnswer, q as SystemOneChoiceQuestion, r as SystemOneNoulQuestion, s as SystemOneScoreQuestion, t as SystemOneRequest$1, u as SystemOneResponse$1, v as SystemOneContent, N as NativeApi, w as OpenAICompatClient, x as AnthropicCompatClient } from './anthropic-
|
|
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
|
|
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-CYy_ECam.cjs';
|
|
7
|
+
export { y as AnthropicCacheControl, z as AnthropicContentBlock, B as AnthropicImageContentBlock, C as AnthropicMessage, n as AnthropicMessageStreamEvent, A as AnthropicMessagesRequest, m as AnthropicMessagesResponse, D as AnthropicMessagesStream, E as AnthropicMetadata, F as AnthropicOutputConfig, G as AnthropicRedactedThinkingContentBlock, H as AnthropicSystem, I as AnthropicSystemTextBlock, J as AnthropicTextContentBlock, K as AnthropicThinkingConfig, L as AnthropicThinkingContentBlock, M as AnthropicTool, P as AnthropicToolChoice, Q as AnthropicToolResultContentBlock, T as AnthropicToolUseContentBlock, U as AnthropicUnknownStreamEvent, V as OllamaAnthropicContentBlock, W as OllamaAnthropicMessage, X as OllamaAnthropicMessagesRequest, Y as OllamaAnthropicSystem, Z as OllamaAnthropicSystemTextBlock, _ as OllamaAnthropicTextContentBlock, $ as OllamaAnthropicThinkingConfig, a0 as OllamaAnthropicTool, a1 as OllamaAnthropicToolResultContentBlock, a2 as OllamaOpenAIChatCompletionRequest, a3 as OllamaOpenAIChatContentPart, a4 as OllamaOpenAIChatMessage, a5 as OllamaOpenAICompletionRequest, a6 as OllamaOpenAIEmbeddingRequest, a7 as OllamaOpenAIImageDataUrl, a8 as OllamaOpenAIReasoningEffort, a9 as OllamaOpenAIResponsesRequest, aa as OpenAIChatCompletionChoice, b as OpenAIChatCompletionChunk, ab as OpenAIChatCompletionChunkChoice, ac as OpenAIChatCompletionDelta, O as OpenAIChatCompletionRequest, a as OpenAIChatCompletionResponse, ad as OpenAIChatCompletionStream, ae as OpenAICompletionChoice, e as OpenAICompletionChunk, c as OpenAICompletionRequest, d as OpenAICompletionResponse, af as OpenAICompletionStream, ag as OpenAIContentPart, ah as OpenAIEmbeddingInput, ai as OpenAIEmbeddingItem, f as OpenAIEmbeddingRequest, g as OpenAIEmbeddingResponse, aj as OpenAIFunctionDefinition, ak as OpenAIImageUrlContentPart, h as OpenAIListModelsResponse, al as OpenAIMessage, i as OpenAIModelItem, am as OpenAIReasoningEffort, an as OpenAIResponseFormat, ao as OpenAIResponsesCompletedEvent, ap as OpenAIResponsesContentPartAddedEvent, aq as OpenAIResponsesContentPartDoneEvent, ar as OpenAIResponsesCreatedEvent, as as OpenAIResponsesError, at as OpenAIResponsesEventBase, au as OpenAIResponsesFailedEvent, av as OpenAIResponsesFunctionCallArgumentsDeltaEvent, aw as OpenAIResponsesFunctionCallArgumentsDoneEvent, ax as OpenAIResponsesInProgressEvent, ay as OpenAIResponsesIncompleteDetails, az as OpenAIResponsesIncompleteEvent, aA as OpenAIResponsesOutputContent, aB as OpenAIResponsesOutputFunctionCall, aC as OpenAIResponsesOutputItem, aD as OpenAIResponsesOutputItemAddedEvent, aE as OpenAIResponsesOutputItemDoneEvent, aF as OpenAIResponsesOutputMessage, aG as OpenAIResponsesOutputReasoning, aH as OpenAIResponsesOutputRefusal, aI as OpenAIResponsesOutputTextContent, aJ as OpenAIResponsesOutputTextDeltaEvent, aK as OpenAIResponsesOutputTextDoneEvent, aL as OpenAIResponsesQueuedEvent, aM as OpenAIResponsesReasoningSummaryPartAddedEvent, aN as OpenAIResponsesReasoningSummaryPartDoneEvent, aO as OpenAIResponsesReasoningSummaryTextDeltaEvent, aP as OpenAIResponsesReasoningSummaryTextDoneEvent, aQ as OpenAIResponsesReasoningTextDeltaEvent, aR as OpenAIResponsesReasoningTextDoneEvent, aS as OpenAIResponsesRefusalDeltaEvent, aT as OpenAIResponsesRefusalDoneEvent, j as OpenAIResponsesRequest, k as OpenAIResponsesResponse, aU as OpenAIResponsesStatus, aV as OpenAIResponsesStream, aW as OpenAIResponsesStreamError, l as OpenAIResponsesStreamEvent, aX as OpenAIResponsesUsage, aY as OpenAIStreamOptions, aZ as OpenAITextContentPart, a_ as OpenAITool, a$ as OpenAIToolCall, b0 as OpenAIToolCallDelta, b1 as OpenAIUsage, b2 as SystemOneConfidence, b3 as SystemOneProbabilities } from './anthropic-CYy_ECam.cjs';
|
|
8
8
|
import { T as ToolHandler, a as Tool, A as AnyTool, b as ToolRegistry, c as ToolExecutionResult } from './compose-DhvoUrWa.cjs';
|
|
9
9
|
export { d as AppliedSkillResult, e as ApplySkillOptions, P as ParsedFrontmatter, S as Skill, f as SkillFrontmatter, g as SkillSummary, h as ToolExecutionContext, i as ToolExecutionFailure, j as ToolExecutionSuccess, k as ToolRegistryOptions, l as applySkill, p as parseFrontmatter } from './compose-DhvoUrWa.cjs';
|
|
10
10
|
import { M as McpClientLike, a as McpToolDescriptor, b as McpTask, c as McpCallToolResult } from './types-CI-gM2u5.cjs';
|
|
@@ -110,7 +110,7 @@ interface UsageResponse {
|
|
|
110
110
|
readonly range: '24h' | '7d' | '30d';
|
|
111
111
|
/** Selected usage scope. */
|
|
112
112
|
readonly scope: 'self' | 'team';
|
|
113
|
-
/** Set automatically
|
|
113
|
+
/** Set automatically: hour for 24h, day for 7d and 30d. */
|
|
114
114
|
readonly granularity: 'hour' | 'day';
|
|
115
115
|
/** Start of the range in UTC, inclusive. */
|
|
116
116
|
readonly from: string;
|
|
@@ -3049,6 +3049,68 @@ declare class ToolCallAccumulator {
|
|
|
3049
3049
|
*/
|
|
3050
3050
|
declare function mergeToolCallArrays(earlier: readonly ToolCall[] | undefined, later: readonly ToolCall[] | undefined): readonly ToolCall[];
|
|
3051
3051
|
|
|
3052
|
+
/**
|
|
3053
|
+
* Ollama web search / web fetch exposed as model-callable tools.
|
|
3054
|
+
*
|
|
3055
|
+
* Implements the "Building a search agent" pattern from
|
|
3056
|
+
* https://docs.ollama.com/capabilities/web-search: hand `web_search` and `web_fetch`
|
|
3057
|
+
* to a tool-capable model, execute the calls it emits against Ollama Cloud's hosted
|
|
3058
|
+
* `/api/web_search` and `/api/web_fetch`, and feed bounded results back as
|
|
3059
|
+
* `role: 'tool'` messages. Use with {@link ToolRegistry} / `Agent`.
|
|
3060
|
+
*/
|
|
3061
|
+
|
|
3062
|
+
/** The subset of `OllamaClient` the web tools call. */
|
|
3063
|
+
interface WebToolsClient {
|
|
3064
|
+
webSearch(req: WebSearchRequestOptions): Promise<WebSearchResponse>;
|
|
3065
|
+
webFetch(req: WebFetchRequestOptions): Promise<WebFetchResponse>;
|
|
3066
|
+
}
|
|
3067
|
+
interface WebToolsOptions {
|
|
3068
|
+
/**
|
|
3069
|
+
* Upper bound on the model-visible JSON a single call returns. Web pages and search
|
|
3070
|
+
* snippets can run to thousands of tokens; the docs truncate each result to
|
|
3071
|
+
* `2000 * 4` characters, which is the default here. Content fields are trimmed (not
|
|
3072
|
+
* the serialized JSON), so the output always stays valid JSON.
|
|
3073
|
+
*/
|
|
3074
|
+
readonly maxOutputChars?: number | undefined;
|
|
3075
|
+
/** `max_results` sent when the model omits it. Server default is 5, max 10. */
|
|
3076
|
+
readonly defaultMaxResults?: number | undefined;
|
|
3077
|
+
/** Maximum number of page links `web_fetch` returns to the model. Default 25. */
|
|
3078
|
+
readonly maxLinks?: number | undefined;
|
|
3079
|
+
/** Per-call tool execution timeout in milliseconds (see `ToolRegistryOptions.timeoutMs`). */
|
|
3080
|
+
readonly timeoutMs?: number | undefined;
|
|
3081
|
+
}
|
|
3082
|
+
declare const WEB_SEARCH_TOOL_NAME = "web_search";
|
|
3083
|
+
declare const WEB_FETCH_TOOL_NAME = "web_fetch";
|
|
3084
|
+
declare const webSearchSchema: z.ZodObject<{
|
|
3085
|
+
query: z.ZodString;
|
|
3086
|
+
max_results: z.ZodOptional<z.ZodNumber>;
|
|
3087
|
+
}, z.core.$strip>;
|
|
3088
|
+
declare const webFetchSchema: z.ZodObject<{
|
|
3089
|
+
url: z.ZodString;
|
|
3090
|
+
}, z.core.$strip>;
|
|
3091
|
+
type WebSearchToolParams = z.infer<typeof webSearchSchema>;
|
|
3092
|
+
type WebFetchToolParams = z.infer<typeof webFetchSchema>;
|
|
3093
|
+
/** Serialize a web search response within `maxChars`, trimming each snippet evenly. */
|
|
3094
|
+
declare function formatWebSearchResult(res: WebSearchResponse, maxChars: number): string;
|
|
3095
|
+
/** Serialize a web fetch response within `maxChars`, trimming page content first. */
|
|
3096
|
+
declare function formatWebFetchResult(res: WebFetchResponse, maxChars: number, maxLinks?: number): string;
|
|
3097
|
+
/** `web_search` tool backed by {@link WebToolsClient.webSearch}. */
|
|
3098
|
+
declare function createWebSearchTool(client: WebToolsClient, options?: WebToolsOptions): Tool<WebSearchToolParams, string>;
|
|
3099
|
+
/** `web_fetch` tool backed by {@link WebToolsClient.webFetch}. */
|
|
3100
|
+
declare function createWebFetchTool(client: WebToolsClient, options?: WebToolsOptions): Tool<WebFetchToolParams, string>;
|
|
3101
|
+
/**
|
|
3102
|
+
* Both web tools, ready to register:
|
|
3103
|
+
*
|
|
3104
|
+
* ```ts
|
|
3105
|
+
* const registry = new ToolRegistry(createWebTools(client));
|
|
3106
|
+
* const agent = new Agent(client, { tools: registry });
|
|
3107
|
+
* ```
|
|
3108
|
+
*
|
|
3109
|
+
* Requires an Ollama API key on the client (`apiKey` or `OLLAMA_API_KEY`); calls
|
|
3110
|
+
* always go to `https://ollama.com`, independent of the client's inference endpoints.
|
|
3111
|
+
*/
|
|
3112
|
+
declare function createWebTools(client: WebToolsClient, options?: WebToolsOptions): [Tool<WebSearchToolParams, string>, Tool<WebFetchToolParams, string>];
|
|
3113
|
+
|
|
3052
3114
|
/**
|
|
3053
3115
|
* Converts MCP tools into Ollama-compatible tools.
|
|
3054
3116
|
*/
|
|
@@ -3626,4 +3688,4 @@ declare class ModelAffinityScheduler {
|
|
|
3626
3688
|
/** Convenience factory — `createModelAffinityScheduler(client, opts)` reads better in setups. */
|
|
3627
3689
|
declare function createModelAffinityScheduler(client: ModelAffinityClient | OllamaClient, options?: ModelAffinitySchedulerOptions): ModelAffinityScheduler;
|
|
3628
3690
|
|
|
3629
|
-
export { ATTR_GEN_AI_OPERATION_NAME, ATTR_GEN_AI_REQUEST_MODEL, ATTR_GEN_AI_RESPONSE_MODEL, ATTR_GEN_AI_SYSTEM, ATTR_GEN_AI_TOOL_CALL_ID, ATTR_GEN_AI_TOOL_NAME, ATTR_GEN_AI_USAGE_INPUT_TOKENS, ATTR_GEN_AI_USAGE_OUTPUT_TOKENS, ATTR_HTTP_REQUEST_METHOD, ATTR_HTTP_RESPONSE_STATUS_CODE, ATTR_OLLAMA_AGENT_ITERATION, ATTR_OLLAMA_AGENT_MAX_ITERATIONS, ATTR_OLLAMA_ENDPOINT_ATTEMPT, ATTR_OLLAMA_ENDPOINT_NAME, ATTR_SERVER_ADDRESS, ATTR_SERVER_PORT, ATTR_URL_FULL, AbortableAsyncIterable, type AffinityRunningModel, Agent, type AgentChatClient, type AgentConfig, type AgentHooks, type AgentResult, type AgentRunInput, type AgentTurn, type AnswerFor, AnthropicCompatClient, AnyTool, type BackoffOptions, BalanceRequestOptions, type BalanceResponse, type BlobUploadResult, ChatRequestOptions, ChatResponse, ChatStreamResult, type ChoiceDecision, type CompactionOptions, type ContextCheck, type ContextCheckOptions, type ContextDiscoveryRequestOptions, type ContextLengthSignals, type ContextLengthSource, type ContextWindowSource, type ConversationSendOptions, ConversationSession, type ConversationSessionOptions, CopyRequestOptions, CreateRequestOptions, type CumulativeCacheStats, DEFAULT_BACKOFF, DEFAULT_BASE_URL, DEFAULT_CONTEXT_WARNING_THRESHOLD, DEFAULT_EMBED_BATCH_SIZE, DEFAULT_EMBED_CONCURRENCY, DEFAULT_FAILOVER_CODES, DEFAULT_FETCH_BACKOFF_CONFIG, DEFAULT_RETRY_CONFIG, DEFAULT_TIMEOUT_MS, type Decision, type DefineToolOptions, DeleteRequestOptions, type DiscoveredContextLength, type EmbedBatchOptions, type EmbedBatchResult, EmbedRequestOptions, EmbedResponse, EmbeddingsRequestOptions, EmbeddingsResponse, type EndpointHealth, type EndpointHealthCheckResult, EndpointRegistry, type EndpointRegistryOptions, FetchLike, type FetchWithBackoffConfig, FormatOption, type FormattedTelemetry, GEN_AI_SYSTEM_OLLAMA, GenerateRequestOptions, GenerateResponse, GenerateStreamResult, type HistorySanitizeOptions, HttpClient, IMAGE_TOKEN_ESTIMATE, type IncludedBalance, KEEP_ALIVE_INDEFINITE, KEEP_ALIVE_UNLOAD, KNOWN_DONE_REASONS, type KeepAlive, type KnownDoneReason, type LegacyBalanceLimit, type LegacyIncludedBalance, type LoadMcpToolsOptions, Logger, MAX_SYSTEM_ONE_IMAGES_BYTES, MAX_SYSTEM_ONE_REQUEST_BYTES, MESSAGE_OVERHEAD_TOKENS, McpBridge, type McpBridgeOptions, McpCallToolResult, McpClientLike, McpTask, McpToolDescriptor, Message, Middleware, type ModelAffinityClient, ModelAffinityRouter, type ModelAffinityRoutingOptions, ModelAffinityScheduler, type ModelAffinitySchedulerOptions, type ModelAffinitySnapshot, type ModelAffinityStats, type ModelCapabilities, ModelOptions, ModelResponse, ModelsClient, type NoulDecision, OLLAMA_CLOUD_BASE_URL, OLLAMA_FALLBACK_CONTEXT_LENGTH, OllamaClient, type OllamaClientConfig, type OllamaCloudFreeTierQuotaBudgets, type OllamaCredentialConfig, type OllamaEndpoint, OllamaStream, OllamaStreamEvent, OllamaStreamEventType, OpenAICompatClient, type OversizedEmbedInput, type ParallelToolCallBehavior, PingResult, ProgressResponse, ProgressStreamResult, PsResponse, PullRequestOptions, PushRequestOptions, QuotaManager, type QuotaManagerOptions, type QuotaWindowConfig, type QuotaWindowStatus, RETRYABLE_STATUS_CODES, type RankResult, type RawOllamaMetrics, RawUsageSource, RequestCancellationOptions, RequestLifecycleHook, RequestRunner, type ResponsesCreateRequest, type ResponsesCreateResponse, ResponsesModule, type ResponsesReasoningEffort, type ResponsesStreamEvent, type ResponsesToolDefinition, type ResponsesUsage, type RetryConfig, type RuntimeMode, type ScoreDecision, type SessionCompactionOptions, type SessionCompactionResult, type SessionTurn, ShowRequestOptions, ShowResponse, type SpanAttributeValue, type SpanAttributes, StatusResponse, type SupportedSchema, type SystemOneAnswer, type SystemOneAnswers, SystemOneChoiceAnswer, SystemOneChoiceQuestion, SystemOneContent, SystemOneNoulAnswer, SystemOneNoulQuestion, type SystemOneQuestion, type SystemOneQuestions, type SystemOneRequest, type SystemOneResponse, SystemOneScoreAnswer, SystemOneScoreQuestion, type SystemOneUsage, ThinkValue, ThinkingMetadata, type TimeoutSignal, TokenUsage, Tool, ToolCall, ToolCallAccumulator, ToolDefinition, ToolExecutionResult, ToolHandler, ToolParameters, ToolRegistry, type TurnCacheStats, type UsageBucket, type UsageMetrics, UsageRequestOptions, type UsageResponse, VersionResponse, VisionInput, WebFetchRequestOptions, WebFetchResponse, WebSearchRequestOptions, WebSearchResponse, addSpanEvent, batchEmbed, calculateBackoff, canonicalToolCallSignature, checkChatContext, checkEndpointHealth, checkGenerateContext, compactConversationHistory, contextWarningMessage, createDecision, createModelAffinityScheduler, createOllamaCloudFreeTierQuota, createTimeoutSignal, defineTool, detectModelCapabilities, embedBatchOverflowMessage, encodeImage, estimateChatRequestTokens, estimateGenerateRequestTokens, estimateMessageTokens, estimateSystemOneRequestBytes, estimateTokens, extractContextLength as extractNativeContextLength, extractParameterNumCtx, fetchWithBackoff, findOversizedEmbedInputs, findRunningModelContextLength, formatTelemetry, inferRuntimeMode, isKeepAliveSugar, isKnownDoneReason, isModelResident, isSameToolCall, listAllMcpTools, listAvailableModels, loadMcpTools, mergeToolCall, mergeToolCallArgumentsString, mergeToolCallArrays, normalizeChatStream, normalizeGenerateStream, normalizeKeepAlive, normalizeProgressStream, parseNdjsonStream, parseStructuredOutput, registerMcpTools, resolveContextLength, resolveCredentialEndpoints, sanitizeHistoryForNextTurn, setSpanError, toDataStream, toResponse, toTextStream, withRetry, withSpan, zodToJsonSchema };
|
|
3691
|
+
export { ATTR_GEN_AI_OPERATION_NAME, ATTR_GEN_AI_REQUEST_MODEL, ATTR_GEN_AI_RESPONSE_MODEL, ATTR_GEN_AI_SYSTEM, ATTR_GEN_AI_TOOL_CALL_ID, ATTR_GEN_AI_TOOL_NAME, ATTR_GEN_AI_USAGE_INPUT_TOKENS, ATTR_GEN_AI_USAGE_OUTPUT_TOKENS, ATTR_HTTP_REQUEST_METHOD, ATTR_HTTP_RESPONSE_STATUS_CODE, ATTR_OLLAMA_AGENT_ITERATION, ATTR_OLLAMA_AGENT_MAX_ITERATIONS, ATTR_OLLAMA_ENDPOINT_ATTEMPT, ATTR_OLLAMA_ENDPOINT_NAME, ATTR_SERVER_ADDRESS, ATTR_SERVER_PORT, ATTR_URL_FULL, AbortableAsyncIterable, type AffinityRunningModel, Agent, type AgentChatClient, type AgentConfig, type AgentHooks, type AgentResult, type AgentRunInput, type AgentTurn, type AnswerFor, AnthropicCompatClient, AnyTool, type BackoffOptions, BalanceRequestOptions, type BalanceResponse, type BlobUploadResult, ChatRequestOptions, ChatResponse, ChatStreamResult, type ChoiceDecision, type CompactionOptions, type ContextCheck, type ContextCheckOptions, type ContextDiscoveryRequestOptions, type ContextLengthSignals, type ContextLengthSource, type ContextWindowSource, type ConversationSendOptions, ConversationSession, type ConversationSessionOptions, CopyRequestOptions, CreateRequestOptions, type CumulativeCacheStats, DEFAULT_BACKOFF, DEFAULT_BASE_URL, DEFAULT_CONTEXT_WARNING_THRESHOLD, DEFAULT_EMBED_BATCH_SIZE, DEFAULT_EMBED_CONCURRENCY, DEFAULT_FAILOVER_CODES, DEFAULT_FETCH_BACKOFF_CONFIG, DEFAULT_RETRY_CONFIG, DEFAULT_TIMEOUT_MS, type Decision, type DefineToolOptions, DeleteRequestOptions, type DiscoveredContextLength, type EmbedBatchOptions, type EmbedBatchResult, EmbedRequestOptions, EmbedResponse, EmbeddingsRequestOptions, EmbeddingsResponse, type EndpointHealth, type EndpointHealthCheckResult, EndpointRegistry, type EndpointRegistryOptions, FetchLike, type FetchWithBackoffConfig, FormatOption, type FormattedTelemetry, GEN_AI_SYSTEM_OLLAMA, GenerateRequestOptions, GenerateResponse, GenerateStreamResult, type HistorySanitizeOptions, HttpClient, IMAGE_TOKEN_ESTIMATE, type IncludedBalance, KEEP_ALIVE_INDEFINITE, KEEP_ALIVE_UNLOAD, KNOWN_DONE_REASONS, type KeepAlive, type KnownDoneReason, type LegacyBalanceLimit, type LegacyIncludedBalance, type LoadMcpToolsOptions, Logger, MAX_SYSTEM_ONE_IMAGES_BYTES, MAX_SYSTEM_ONE_REQUEST_BYTES, MESSAGE_OVERHEAD_TOKENS, McpBridge, type McpBridgeOptions, McpCallToolResult, McpClientLike, McpTask, McpToolDescriptor, Message, Middleware, type ModelAffinityClient, ModelAffinityRouter, type ModelAffinityRoutingOptions, ModelAffinityScheduler, type ModelAffinitySchedulerOptions, type ModelAffinitySnapshot, type ModelAffinityStats, type ModelCapabilities, ModelOptions, ModelResponse, ModelsClient, type NoulDecision, OLLAMA_CLOUD_BASE_URL, OLLAMA_FALLBACK_CONTEXT_LENGTH, OllamaClient, type OllamaClientConfig, type OllamaCloudFreeTierQuotaBudgets, type OllamaCredentialConfig, type OllamaEndpoint, OllamaStream, OllamaStreamEvent, OllamaStreamEventType, OpenAICompatClient, type OversizedEmbedInput, type ParallelToolCallBehavior, PingResult, ProgressResponse, ProgressStreamResult, PsResponse, PullRequestOptions, PushRequestOptions, QuotaManager, type QuotaManagerOptions, type QuotaWindowConfig, type QuotaWindowStatus, RETRYABLE_STATUS_CODES, type RankResult, type RawOllamaMetrics, RawUsageSource, RequestCancellationOptions, RequestLifecycleHook, RequestRunner, type ResponsesCreateRequest, type ResponsesCreateResponse, ResponsesModule, type ResponsesReasoningEffort, type ResponsesStreamEvent, type ResponsesToolDefinition, type ResponsesUsage, type RetryConfig, type RuntimeMode, type ScoreDecision, type SessionCompactionOptions, type SessionCompactionResult, type SessionTurn, ShowRequestOptions, ShowResponse, type SpanAttributeValue, type SpanAttributes, StatusResponse, type SupportedSchema, type SystemOneAnswer, type SystemOneAnswers, SystemOneChoiceAnswer, SystemOneChoiceQuestion, SystemOneContent, SystemOneNoulAnswer, SystemOneNoulQuestion, type SystemOneQuestion, type SystemOneQuestions, type SystemOneRequest, type SystemOneResponse, SystemOneScoreAnswer, SystemOneScoreQuestion, type SystemOneUsage, ThinkValue, ThinkingMetadata, type TimeoutSignal, TokenUsage, Tool, ToolCall, ToolCallAccumulator, ToolDefinition, ToolExecutionResult, ToolHandler, ToolParameters, ToolRegistry, type TurnCacheStats, type UsageBucket, type UsageMetrics, UsageRequestOptions, type UsageResponse, VersionResponse, VisionInput, WEB_FETCH_TOOL_NAME, WEB_SEARCH_TOOL_NAME, WebFetchRequestOptions, WebFetchResponse, type WebFetchToolParams, WebSearchRequestOptions, WebSearchResponse, type WebSearchToolParams, type WebToolsClient, type WebToolsOptions, addSpanEvent, batchEmbed, calculateBackoff, canonicalToolCallSignature, checkChatContext, checkEndpointHealth, checkGenerateContext, compactConversationHistory, contextWarningMessage, createDecision, createModelAffinityScheduler, createOllamaCloudFreeTierQuota, createTimeoutSignal, createWebFetchTool, createWebSearchTool, createWebTools, defineTool, detectModelCapabilities, embedBatchOverflowMessage, encodeImage, estimateChatRequestTokens, estimateGenerateRequestTokens, estimateMessageTokens, estimateSystemOneRequestBytes, estimateTokens, extractContextLength as extractNativeContextLength, extractParameterNumCtx, fetchWithBackoff, findOversizedEmbedInputs, findRunningModelContextLength, formatTelemetry, formatWebFetchResult, formatWebSearchResult, inferRuntimeMode, isKeepAliveSugar, isKnownDoneReason, isModelResident, isSameToolCall, listAllMcpTools, listAvailableModels, loadMcpTools, mergeToolCall, mergeToolCallArgumentsString, mergeToolCallArrays, normalizeChatStream, normalizeGenerateStream, normalizeKeepAlive, normalizeProgressStream, parseNdjsonStream, parseStructuredOutput, registerMcpTools, resolveContextLength, resolveCredentialEndpoints, sanitizeHistoryForNextTurn, setSpanError, toDataStream, toResponse, toTextStream, withRetry, withSpan, zodToJsonSchema };
|
package/dist/index.d.ts
CHANGED
|
@@ -3,8 +3,8 @@ export { L as ListResponse, x as Logprob, y as LogprobToken, z as ModelDetails,
|
|
|
3
3
|
import { H as HttpClient, F as FetchLike, M as Middleware, L as Logger, R as RequestLifecycleHook, c as OllamaStreamEvent, A as AbortableAsyncIterable, d as OllamaStreamEventType, P as ProgressStreamResult, B as BinaryBody, O as OllamaRuntime, C as ChatStreamResult, G as GenerateStreamResult, e as RawUsageSource, T as TokenUsage } from './runtime-CIQYCRL3.js';
|
|
4
4
|
export { D as DoneEvent, E as ErrorEvent, f as HttpBody, g as HttpClientOptions, h as HttpRequestOptions, i as LifecycleErrorEvent, j as LifecycleRetryEvent, k as LifecycleStartEvent, l as LifecycleSuccessEvent, m as LogFn, n as MessageEvent, o as MiddlewareContext, N as NANOS_PER_MS, p as NANOS_PER_SECOND, q as NOOP_LOGGER, r as NextFunction, s as OllamaAbortError, t as OllamaAgentMaxIterationsError, u as OllamaAgentMaxToolCallsError, v as OllamaAgentToolLoopError, w as OllamaAuthError, x as OllamaBadGatewayError, y as OllamaClientError, z as OllamaClientErrorOptions, J as OllamaErrorRequestContext, K as OllamaErrorResponseContext, Q as OllamaGenericClientError, U as OllamaIncompatibleModelError, V as OllamaMcpError, W as OllamaModelRoutingError, X as OllamaNetworkError, Y as OllamaNotFoundError, Z as OllamaOverloadedError, _ as OllamaQuotaExceededError, $ as OllamaRateLimitError, a0 as OllamaRequestTooLargeError, a1 as OllamaRequestValidationError, a2 as OllamaResponseValidationError, a3 as OllamaServerError, a4 as OllamaServerVersionUnknownError, a5 as OllamaSkillInvalidError, a6 as OllamaSkillNotFoundError, a7 as OllamaStreamError, a8 as OllamaTimeoutError, a9 as OllamaToolTimeoutError, aa as OllamaToolValidationError, ab as OllamaUnsupportedCapabilityError, ac as RequestContext, ad as RequestLifecycleEvent, ae as ResponseContext, af as SseEvent, ag as ThinkingEvent, ah as TokenEvent, ai as ToolCallEvent, aj as composeMiddleware, ak as createConsoleLogger, al as extractUsage, am as mapError, an as parseSseStream } from './runtime-CIQYCRL3.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
|
|
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-B9AFyzXI.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 OllamaOpenAIChatContentPart, a4 as OllamaOpenAIChatMessage, a5 as OllamaOpenAICompletionRequest, a6 as OllamaOpenAIEmbeddingRequest, a7 as OllamaOpenAIImageDataUrl, a8 as OllamaOpenAIReasoningEffort, a9 as OllamaOpenAIResponsesRequest, aa as OpenAIChatCompletionChoice, b as OpenAIChatCompletionChunk, ab as OpenAIChatCompletionChunkChoice, ac as OpenAIChatCompletionDelta, O as OpenAIChatCompletionRequest, a as OpenAIChatCompletionResponse, ad as OpenAIChatCompletionStream, ae as OpenAICompletionChoice, e as OpenAICompletionChunk, c as OpenAICompletionRequest, d as OpenAICompletionResponse, af as OpenAICompletionStream, ag as OpenAIContentPart, ah as OpenAIEmbeddingInput, ai as OpenAIEmbeddingItem, f as OpenAIEmbeddingRequest, g as OpenAIEmbeddingResponse, aj as OpenAIFunctionDefinition, ak as OpenAIImageUrlContentPart, h as OpenAIListModelsResponse, al as OpenAIMessage, i as OpenAIModelItem, am as OpenAIReasoningEffort, an as OpenAIResponseFormat, ao as OpenAIResponsesCompletedEvent, ap as OpenAIResponsesContentPartAddedEvent, aq as OpenAIResponsesContentPartDoneEvent, ar as OpenAIResponsesCreatedEvent, as as OpenAIResponsesError, at as OpenAIResponsesEventBase, au as OpenAIResponsesFailedEvent, av as OpenAIResponsesFunctionCallArgumentsDeltaEvent, aw as OpenAIResponsesFunctionCallArgumentsDoneEvent, ax as OpenAIResponsesInProgressEvent, ay as OpenAIResponsesIncompleteDetails, az as OpenAIResponsesIncompleteEvent, aA as OpenAIResponsesOutputContent, aB as OpenAIResponsesOutputFunctionCall, aC as OpenAIResponsesOutputItem, aD as OpenAIResponsesOutputItemAddedEvent, aE as OpenAIResponsesOutputItemDoneEvent, aF as OpenAIResponsesOutputMessage, aG as OpenAIResponsesOutputReasoning, aH as OpenAIResponsesOutputRefusal, aI as OpenAIResponsesOutputTextContent, aJ as OpenAIResponsesOutputTextDeltaEvent, aK as OpenAIResponsesOutputTextDoneEvent, aL as OpenAIResponsesQueuedEvent, aM as OpenAIResponsesReasoningSummaryPartAddedEvent, aN as OpenAIResponsesReasoningSummaryPartDoneEvent, aO as OpenAIResponsesReasoningSummaryTextDeltaEvent, aP as OpenAIResponsesReasoningSummaryTextDoneEvent, aQ as OpenAIResponsesReasoningTextDeltaEvent, aR as OpenAIResponsesReasoningTextDoneEvent, aS as OpenAIResponsesRefusalDeltaEvent, aT as OpenAIResponsesRefusalDoneEvent, j as OpenAIResponsesRequest, k as OpenAIResponsesResponse, aU as OpenAIResponsesStatus, aV as OpenAIResponsesStream, aW as OpenAIResponsesStreamError, l as OpenAIResponsesStreamEvent, aX as OpenAIResponsesUsage, aY as OpenAIStreamOptions, aZ as OpenAITextContentPart, a_ as OpenAITool, a$ as OpenAIToolCall, b0 as OpenAIToolCallDelta, b1 as OpenAIUsage, b2 as SystemOneConfidence, b3 as SystemOneProbabilities } from './anthropic-B9AFyzXI.js';
|
|
8
8
|
import { T as ToolHandler, a as Tool, A as AnyTool, b as ToolRegistry, c as ToolExecutionResult } from './compose-6UOPEknN.js';
|
|
9
9
|
export { d as AppliedSkillResult, e as ApplySkillOptions, P as ParsedFrontmatter, S as Skill, f as SkillFrontmatter, g as SkillSummary, h as ToolExecutionContext, i as ToolExecutionFailure, j as ToolExecutionSuccess, k as ToolRegistryOptions, l as applySkill, p as parseFrontmatter } from './compose-6UOPEknN.js';
|
|
10
10
|
import { M as McpClientLike, a as McpToolDescriptor, b as McpTask, c as McpCallToolResult } from './types-CI-gM2u5.js';
|
|
@@ -110,7 +110,7 @@ interface UsageResponse {
|
|
|
110
110
|
readonly range: '24h' | '7d' | '30d';
|
|
111
111
|
/** Selected usage scope. */
|
|
112
112
|
readonly scope: 'self' | 'team';
|
|
113
|
-
/** Set automatically
|
|
113
|
+
/** Set automatically: hour for 24h, day for 7d and 30d. */
|
|
114
114
|
readonly granularity: 'hour' | 'day';
|
|
115
115
|
/** Start of the range in UTC, inclusive. */
|
|
116
116
|
readonly from: string;
|
|
@@ -3049,6 +3049,68 @@ declare class ToolCallAccumulator {
|
|
|
3049
3049
|
*/
|
|
3050
3050
|
declare function mergeToolCallArrays(earlier: readonly ToolCall[] | undefined, later: readonly ToolCall[] | undefined): readonly ToolCall[];
|
|
3051
3051
|
|
|
3052
|
+
/**
|
|
3053
|
+
* Ollama web search / web fetch exposed as model-callable tools.
|
|
3054
|
+
*
|
|
3055
|
+
* Implements the "Building a search agent" pattern from
|
|
3056
|
+
* https://docs.ollama.com/capabilities/web-search: hand `web_search` and `web_fetch`
|
|
3057
|
+
* to a tool-capable model, execute the calls it emits against Ollama Cloud's hosted
|
|
3058
|
+
* `/api/web_search` and `/api/web_fetch`, and feed bounded results back as
|
|
3059
|
+
* `role: 'tool'` messages. Use with {@link ToolRegistry} / `Agent`.
|
|
3060
|
+
*/
|
|
3061
|
+
|
|
3062
|
+
/** The subset of `OllamaClient` the web tools call. */
|
|
3063
|
+
interface WebToolsClient {
|
|
3064
|
+
webSearch(req: WebSearchRequestOptions): Promise<WebSearchResponse>;
|
|
3065
|
+
webFetch(req: WebFetchRequestOptions): Promise<WebFetchResponse>;
|
|
3066
|
+
}
|
|
3067
|
+
interface WebToolsOptions {
|
|
3068
|
+
/**
|
|
3069
|
+
* Upper bound on the model-visible JSON a single call returns. Web pages and search
|
|
3070
|
+
* snippets can run to thousands of tokens; the docs truncate each result to
|
|
3071
|
+
* `2000 * 4` characters, which is the default here. Content fields are trimmed (not
|
|
3072
|
+
* the serialized JSON), so the output always stays valid JSON.
|
|
3073
|
+
*/
|
|
3074
|
+
readonly maxOutputChars?: number | undefined;
|
|
3075
|
+
/** `max_results` sent when the model omits it. Server default is 5, max 10. */
|
|
3076
|
+
readonly defaultMaxResults?: number | undefined;
|
|
3077
|
+
/** Maximum number of page links `web_fetch` returns to the model. Default 25. */
|
|
3078
|
+
readonly maxLinks?: number | undefined;
|
|
3079
|
+
/** Per-call tool execution timeout in milliseconds (see `ToolRegistryOptions.timeoutMs`). */
|
|
3080
|
+
readonly timeoutMs?: number | undefined;
|
|
3081
|
+
}
|
|
3082
|
+
declare const WEB_SEARCH_TOOL_NAME = "web_search";
|
|
3083
|
+
declare const WEB_FETCH_TOOL_NAME = "web_fetch";
|
|
3084
|
+
declare const webSearchSchema: z.ZodObject<{
|
|
3085
|
+
query: z.ZodString;
|
|
3086
|
+
max_results: z.ZodOptional<z.ZodNumber>;
|
|
3087
|
+
}, z.core.$strip>;
|
|
3088
|
+
declare const webFetchSchema: z.ZodObject<{
|
|
3089
|
+
url: z.ZodString;
|
|
3090
|
+
}, z.core.$strip>;
|
|
3091
|
+
type WebSearchToolParams = z.infer<typeof webSearchSchema>;
|
|
3092
|
+
type WebFetchToolParams = z.infer<typeof webFetchSchema>;
|
|
3093
|
+
/** Serialize a web search response within `maxChars`, trimming each snippet evenly. */
|
|
3094
|
+
declare function formatWebSearchResult(res: WebSearchResponse, maxChars: number): string;
|
|
3095
|
+
/** Serialize a web fetch response within `maxChars`, trimming page content first. */
|
|
3096
|
+
declare function formatWebFetchResult(res: WebFetchResponse, maxChars: number, maxLinks?: number): string;
|
|
3097
|
+
/** `web_search` tool backed by {@link WebToolsClient.webSearch}. */
|
|
3098
|
+
declare function createWebSearchTool(client: WebToolsClient, options?: WebToolsOptions): Tool<WebSearchToolParams, string>;
|
|
3099
|
+
/** `web_fetch` tool backed by {@link WebToolsClient.webFetch}. */
|
|
3100
|
+
declare function createWebFetchTool(client: WebToolsClient, options?: WebToolsOptions): Tool<WebFetchToolParams, string>;
|
|
3101
|
+
/**
|
|
3102
|
+
* Both web tools, ready to register:
|
|
3103
|
+
*
|
|
3104
|
+
* ```ts
|
|
3105
|
+
* const registry = new ToolRegistry(createWebTools(client));
|
|
3106
|
+
* const agent = new Agent(client, { tools: registry });
|
|
3107
|
+
* ```
|
|
3108
|
+
*
|
|
3109
|
+
* Requires an Ollama API key on the client (`apiKey` or `OLLAMA_API_KEY`); calls
|
|
3110
|
+
* always go to `https://ollama.com`, independent of the client's inference endpoints.
|
|
3111
|
+
*/
|
|
3112
|
+
declare function createWebTools(client: WebToolsClient, options?: WebToolsOptions): [Tool<WebSearchToolParams, string>, Tool<WebFetchToolParams, string>];
|
|
3113
|
+
|
|
3052
3114
|
/**
|
|
3053
3115
|
* Converts MCP tools into Ollama-compatible tools.
|
|
3054
3116
|
*/
|
|
@@ -3626,4 +3688,4 @@ declare class ModelAffinityScheduler {
|
|
|
3626
3688
|
/** Convenience factory — `createModelAffinityScheduler(client, opts)` reads better in setups. */
|
|
3627
3689
|
declare function createModelAffinityScheduler(client: ModelAffinityClient | OllamaClient, options?: ModelAffinitySchedulerOptions): ModelAffinityScheduler;
|
|
3628
3690
|
|
|
3629
|
-
export { ATTR_GEN_AI_OPERATION_NAME, ATTR_GEN_AI_REQUEST_MODEL, ATTR_GEN_AI_RESPONSE_MODEL, ATTR_GEN_AI_SYSTEM, ATTR_GEN_AI_TOOL_CALL_ID, ATTR_GEN_AI_TOOL_NAME, ATTR_GEN_AI_USAGE_INPUT_TOKENS, ATTR_GEN_AI_USAGE_OUTPUT_TOKENS, ATTR_HTTP_REQUEST_METHOD, ATTR_HTTP_RESPONSE_STATUS_CODE, ATTR_OLLAMA_AGENT_ITERATION, ATTR_OLLAMA_AGENT_MAX_ITERATIONS, ATTR_OLLAMA_ENDPOINT_ATTEMPT, ATTR_OLLAMA_ENDPOINT_NAME, ATTR_SERVER_ADDRESS, ATTR_SERVER_PORT, ATTR_URL_FULL, AbortableAsyncIterable, type AffinityRunningModel, Agent, type AgentChatClient, type AgentConfig, type AgentHooks, type AgentResult, type AgentRunInput, type AgentTurn, type AnswerFor, AnthropicCompatClient, AnyTool, type BackoffOptions, BalanceRequestOptions, type BalanceResponse, type BlobUploadResult, ChatRequestOptions, ChatResponse, ChatStreamResult, type ChoiceDecision, type CompactionOptions, type ContextCheck, type ContextCheckOptions, type ContextDiscoveryRequestOptions, type ContextLengthSignals, type ContextLengthSource, type ContextWindowSource, type ConversationSendOptions, ConversationSession, type ConversationSessionOptions, CopyRequestOptions, CreateRequestOptions, type CumulativeCacheStats, DEFAULT_BACKOFF, DEFAULT_BASE_URL, DEFAULT_CONTEXT_WARNING_THRESHOLD, DEFAULT_EMBED_BATCH_SIZE, DEFAULT_EMBED_CONCURRENCY, DEFAULT_FAILOVER_CODES, DEFAULT_FETCH_BACKOFF_CONFIG, DEFAULT_RETRY_CONFIG, DEFAULT_TIMEOUT_MS, type Decision, type DefineToolOptions, DeleteRequestOptions, type DiscoveredContextLength, type EmbedBatchOptions, type EmbedBatchResult, EmbedRequestOptions, EmbedResponse, EmbeddingsRequestOptions, EmbeddingsResponse, type EndpointHealth, type EndpointHealthCheckResult, EndpointRegistry, type EndpointRegistryOptions, FetchLike, type FetchWithBackoffConfig, FormatOption, type FormattedTelemetry, GEN_AI_SYSTEM_OLLAMA, GenerateRequestOptions, GenerateResponse, GenerateStreamResult, type HistorySanitizeOptions, HttpClient, IMAGE_TOKEN_ESTIMATE, type IncludedBalance, KEEP_ALIVE_INDEFINITE, KEEP_ALIVE_UNLOAD, KNOWN_DONE_REASONS, type KeepAlive, type KnownDoneReason, type LegacyBalanceLimit, type LegacyIncludedBalance, type LoadMcpToolsOptions, Logger, MAX_SYSTEM_ONE_IMAGES_BYTES, MAX_SYSTEM_ONE_REQUEST_BYTES, MESSAGE_OVERHEAD_TOKENS, McpBridge, type McpBridgeOptions, McpCallToolResult, McpClientLike, McpTask, McpToolDescriptor, Message, Middleware, type ModelAffinityClient, ModelAffinityRouter, type ModelAffinityRoutingOptions, ModelAffinityScheduler, type ModelAffinitySchedulerOptions, type ModelAffinitySnapshot, type ModelAffinityStats, type ModelCapabilities, ModelOptions, ModelResponse, ModelsClient, type NoulDecision, OLLAMA_CLOUD_BASE_URL, OLLAMA_FALLBACK_CONTEXT_LENGTH, OllamaClient, type OllamaClientConfig, type OllamaCloudFreeTierQuotaBudgets, type OllamaCredentialConfig, type OllamaEndpoint, OllamaStream, OllamaStreamEvent, OllamaStreamEventType, OpenAICompatClient, type OversizedEmbedInput, type ParallelToolCallBehavior, PingResult, ProgressResponse, ProgressStreamResult, PsResponse, PullRequestOptions, PushRequestOptions, QuotaManager, type QuotaManagerOptions, type QuotaWindowConfig, type QuotaWindowStatus, RETRYABLE_STATUS_CODES, type RankResult, type RawOllamaMetrics, RawUsageSource, RequestCancellationOptions, RequestLifecycleHook, RequestRunner, type ResponsesCreateRequest, type ResponsesCreateResponse, ResponsesModule, type ResponsesReasoningEffort, type ResponsesStreamEvent, type ResponsesToolDefinition, type ResponsesUsage, type RetryConfig, type RuntimeMode, type ScoreDecision, type SessionCompactionOptions, type SessionCompactionResult, type SessionTurn, ShowRequestOptions, ShowResponse, type SpanAttributeValue, type SpanAttributes, StatusResponse, type SupportedSchema, type SystemOneAnswer, type SystemOneAnswers, SystemOneChoiceAnswer, SystemOneChoiceQuestion, SystemOneContent, SystemOneNoulAnswer, SystemOneNoulQuestion, type SystemOneQuestion, type SystemOneQuestions, type SystemOneRequest, type SystemOneResponse, SystemOneScoreAnswer, SystemOneScoreQuestion, type SystemOneUsage, ThinkValue, ThinkingMetadata, type TimeoutSignal, TokenUsage, Tool, ToolCall, ToolCallAccumulator, ToolDefinition, ToolExecutionResult, ToolHandler, ToolParameters, ToolRegistry, type TurnCacheStats, type UsageBucket, type UsageMetrics, UsageRequestOptions, type UsageResponse, VersionResponse, VisionInput, WebFetchRequestOptions, WebFetchResponse, WebSearchRequestOptions, WebSearchResponse, addSpanEvent, batchEmbed, calculateBackoff, canonicalToolCallSignature, checkChatContext, checkEndpointHealth, checkGenerateContext, compactConversationHistory, contextWarningMessage, createDecision, createModelAffinityScheduler, createOllamaCloudFreeTierQuota, createTimeoutSignal, defineTool, detectModelCapabilities, embedBatchOverflowMessage, encodeImage, estimateChatRequestTokens, estimateGenerateRequestTokens, estimateMessageTokens, estimateSystemOneRequestBytes, estimateTokens, extractContextLength as extractNativeContextLength, extractParameterNumCtx, fetchWithBackoff, findOversizedEmbedInputs, findRunningModelContextLength, formatTelemetry, inferRuntimeMode, isKeepAliveSugar, isKnownDoneReason, isModelResident, isSameToolCall, listAllMcpTools, listAvailableModels, loadMcpTools, mergeToolCall, mergeToolCallArgumentsString, mergeToolCallArrays, normalizeChatStream, normalizeGenerateStream, normalizeKeepAlive, normalizeProgressStream, parseNdjsonStream, parseStructuredOutput, registerMcpTools, resolveContextLength, resolveCredentialEndpoints, sanitizeHistoryForNextTurn, setSpanError, toDataStream, toResponse, toTextStream, withRetry, withSpan, zodToJsonSchema };
|
|
3691
|
+
export { ATTR_GEN_AI_OPERATION_NAME, ATTR_GEN_AI_REQUEST_MODEL, ATTR_GEN_AI_RESPONSE_MODEL, ATTR_GEN_AI_SYSTEM, ATTR_GEN_AI_TOOL_CALL_ID, ATTR_GEN_AI_TOOL_NAME, ATTR_GEN_AI_USAGE_INPUT_TOKENS, ATTR_GEN_AI_USAGE_OUTPUT_TOKENS, ATTR_HTTP_REQUEST_METHOD, ATTR_HTTP_RESPONSE_STATUS_CODE, ATTR_OLLAMA_AGENT_ITERATION, ATTR_OLLAMA_AGENT_MAX_ITERATIONS, ATTR_OLLAMA_ENDPOINT_ATTEMPT, ATTR_OLLAMA_ENDPOINT_NAME, ATTR_SERVER_ADDRESS, ATTR_SERVER_PORT, ATTR_URL_FULL, AbortableAsyncIterable, type AffinityRunningModel, Agent, type AgentChatClient, type AgentConfig, type AgentHooks, type AgentResult, type AgentRunInput, type AgentTurn, type AnswerFor, AnthropicCompatClient, AnyTool, type BackoffOptions, BalanceRequestOptions, type BalanceResponse, type BlobUploadResult, ChatRequestOptions, ChatResponse, ChatStreamResult, type ChoiceDecision, type CompactionOptions, type ContextCheck, type ContextCheckOptions, type ContextDiscoveryRequestOptions, type ContextLengthSignals, type ContextLengthSource, type ContextWindowSource, type ConversationSendOptions, ConversationSession, type ConversationSessionOptions, CopyRequestOptions, CreateRequestOptions, type CumulativeCacheStats, DEFAULT_BACKOFF, DEFAULT_BASE_URL, DEFAULT_CONTEXT_WARNING_THRESHOLD, DEFAULT_EMBED_BATCH_SIZE, DEFAULT_EMBED_CONCURRENCY, DEFAULT_FAILOVER_CODES, DEFAULT_FETCH_BACKOFF_CONFIG, DEFAULT_RETRY_CONFIG, DEFAULT_TIMEOUT_MS, type Decision, type DefineToolOptions, DeleteRequestOptions, type DiscoveredContextLength, type EmbedBatchOptions, type EmbedBatchResult, EmbedRequestOptions, EmbedResponse, EmbeddingsRequestOptions, EmbeddingsResponse, type EndpointHealth, type EndpointHealthCheckResult, EndpointRegistry, type EndpointRegistryOptions, FetchLike, type FetchWithBackoffConfig, FormatOption, type FormattedTelemetry, GEN_AI_SYSTEM_OLLAMA, GenerateRequestOptions, GenerateResponse, GenerateStreamResult, type HistorySanitizeOptions, HttpClient, IMAGE_TOKEN_ESTIMATE, type IncludedBalance, KEEP_ALIVE_INDEFINITE, KEEP_ALIVE_UNLOAD, KNOWN_DONE_REASONS, type KeepAlive, type KnownDoneReason, type LegacyBalanceLimit, type LegacyIncludedBalance, type LoadMcpToolsOptions, Logger, MAX_SYSTEM_ONE_IMAGES_BYTES, MAX_SYSTEM_ONE_REQUEST_BYTES, MESSAGE_OVERHEAD_TOKENS, McpBridge, type McpBridgeOptions, McpCallToolResult, McpClientLike, McpTask, McpToolDescriptor, Message, Middleware, type ModelAffinityClient, ModelAffinityRouter, type ModelAffinityRoutingOptions, ModelAffinityScheduler, type ModelAffinitySchedulerOptions, type ModelAffinitySnapshot, type ModelAffinityStats, type ModelCapabilities, ModelOptions, ModelResponse, ModelsClient, type NoulDecision, OLLAMA_CLOUD_BASE_URL, OLLAMA_FALLBACK_CONTEXT_LENGTH, OllamaClient, type OllamaClientConfig, type OllamaCloudFreeTierQuotaBudgets, type OllamaCredentialConfig, type OllamaEndpoint, OllamaStream, OllamaStreamEvent, OllamaStreamEventType, OpenAICompatClient, type OversizedEmbedInput, type ParallelToolCallBehavior, PingResult, ProgressResponse, ProgressStreamResult, PsResponse, PullRequestOptions, PushRequestOptions, QuotaManager, type QuotaManagerOptions, type QuotaWindowConfig, type QuotaWindowStatus, RETRYABLE_STATUS_CODES, type RankResult, type RawOllamaMetrics, RawUsageSource, RequestCancellationOptions, RequestLifecycleHook, RequestRunner, type ResponsesCreateRequest, type ResponsesCreateResponse, ResponsesModule, type ResponsesReasoningEffort, type ResponsesStreamEvent, type ResponsesToolDefinition, type ResponsesUsage, type RetryConfig, type RuntimeMode, type ScoreDecision, type SessionCompactionOptions, type SessionCompactionResult, type SessionTurn, ShowRequestOptions, ShowResponse, type SpanAttributeValue, type SpanAttributes, StatusResponse, type SupportedSchema, type SystemOneAnswer, type SystemOneAnswers, SystemOneChoiceAnswer, SystemOneChoiceQuestion, SystemOneContent, SystemOneNoulAnswer, SystemOneNoulQuestion, type SystemOneQuestion, type SystemOneQuestions, type SystemOneRequest, type SystemOneResponse, SystemOneScoreAnswer, SystemOneScoreQuestion, type SystemOneUsage, ThinkValue, ThinkingMetadata, type TimeoutSignal, TokenUsage, Tool, ToolCall, ToolCallAccumulator, ToolDefinition, ToolExecutionResult, ToolHandler, ToolParameters, ToolRegistry, type TurnCacheStats, type UsageBucket, type UsageMetrics, UsageRequestOptions, type UsageResponse, VersionResponse, VisionInput, WEB_FETCH_TOOL_NAME, WEB_SEARCH_TOOL_NAME, WebFetchRequestOptions, WebFetchResponse, type WebFetchToolParams, WebSearchRequestOptions, WebSearchResponse, type WebSearchToolParams, type WebToolsClient, type WebToolsOptions, addSpanEvent, batchEmbed, calculateBackoff, canonicalToolCallSignature, checkChatContext, checkEndpointHealth, checkGenerateContext, compactConversationHistory, contextWarningMessage, createDecision, createModelAffinityScheduler, createOllamaCloudFreeTierQuota, createTimeoutSignal, createWebFetchTool, createWebSearchTool, createWebTools, defineTool, detectModelCapabilities, embedBatchOverflowMessage, encodeImage, estimateChatRequestTokens, estimateGenerateRequestTokens, estimateMessageTokens, estimateSystemOneRequestBytes, estimateTokens, extractContextLength as extractNativeContextLength, extractParameterNumCtx, fetchWithBackoff, findOversizedEmbedInputs, findRunningModelContextLength, formatTelemetry, formatWebFetchResult, formatWebSearchResult, inferRuntimeMode, isKeepAliveSugar, isKnownDoneReason, isModelResident, isSameToolCall, listAllMcpTools, listAvailableModels, loadMcpTools, mergeToolCall, mergeToolCallArgumentsString, mergeToolCallArrays, normalizeChatStream, normalizeGenerateStream, normalizeKeepAlive, normalizeProgressStream, parseNdjsonStream, parseStructuredOutput, registerMcpTools, resolveContextLength, resolveCredentialEndpoints, sanitizeHistoryForNextTurn, setSpanError, toDataStream, toResponse, toTextStream, withRetry, withSpan, zodToJsonSchema };
|
package/dist/index.js
CHANGED
|
@@ -2849,7 +2849,11 @@ var ModelsClient = class {
|
|
|
2849
2849
|
var OpenAIResponsesStreamError = class extends OllamaClientError {
|
|
2850
2850
|
responsePayload;
|
|
2851
2851
|
constructor(message, responsePayload) {
|
|
2852
|
-
super(message, {
|
|
2852
|
+
super(message, {
|
|
2853
|
+
code: "openai_responses_stream_error",
|
|
2854
|
+
retryable: false,
|
|
2855
|
+
response: { body: responsePayload }
|
|
2856
|
+
});
|
|
2853
2857
|
this.responsePayload = responsePayload;
|
|
2854
2858
|
}
|
|
2855
2859
|
};
|
|
@@ -2991,7 +2995,9 @@ var OpenAIChatCompletionStream = class {
|
|
|
2991
2995
|
} finally {
|
|
2992
2996
|
if (!completed) {
|
|
2993
2997
|
this.source.abort?.();
|
|
2994
|
-
this.rejectFinal(
|
|
2998
|
+
this.rejectFinal(
|
|
2999
|
+
new OllamaAbortError("OpenAI Chat Completion stream ended before completion")
|
|
3000
|
+
);
|
|
2995
3001
|
}
|
|
2996
3002
|
}
|
|
2997
3003
|
}
|
|
@@ -3120,7 +3126,14 @@ var OpenAIResponsesStream = class {
|
|
|
3120
3126
|
existing.kind = kind;
|
|
3121
3127
|
return existing;
|
|
3122
3128
|
}
|
|
3123
|
-
const state = {
|
|
3129
|
+
const state = {
|
|
3130
|
+
itemId,
|
|
3131
|
+
kind,
|
|
3132
|
+
content: /* @__PURE__ */ new Map(),
|
|
3133
|
+
summary: /* @__PURE__ */ new Map(),
|
|
3134
|
+
arguments: "",
|
|
3135
|
+
reasoningText: ""
|
|
3136
|
+
};
|
|
3124
3137
|
outputs.set(outputIndex, state);
|
|
3125
3138
|
return state;
|
|
3126
3139
|
};
|
|
@@ -3151,9 +3164,33 @@ var OpenAIResponsesStream = class {
|
|
|
3151
3164
|
const reconstructedOutput = () => [...outputs.entries()].sort(([a], [b]) => a - b).map(([outputIndex, state]) => {
|
|
3152
3165
|
const canonical = canonicalOutputItems.get(outputIndex);
|
|
3153
3166
|
if (canonical) return canonical;
|
|
3154
|
-
if (state.kind === "message")
|
|
3155
|
-
|
|
3156
|
-
|
|
3167
|
+
if (state.kind === "message")
|
|
3168
|
+
return {
|
|
3169
|
+
type: "message",
|
|
3170
|
+
...state.itemId ? { id: state.itemId } : {},
|
|
3171
|
+
...state.status ? { status: state.status } : {},
|
|
3172
|
+
role: state.role ?? "assistant",
|
|
3173
|
+
...state.phase ? { phase: state.phase } : {},
|
|
3174
|
+
content: [...state.content.entries()].sort(([a], [b]) => a - b).map(([, p]) => p)
|
|
3175
|
+
};
|
|
3176
|
+
if (state.kind === "function_call")
|
|
3177
|
+
return {
|
|
3178
|
+
type: "function_call",
|
|
3179
|
+
...state.itemId ? { id: state.itemId } : {},
|
|
3180
|
+
...state.callId ? { call_id: state.callId } : {},
|
|
3181
|
+
...state.status ? { status: state.status } : {},
|
|
3182
|
+
name: state.name ?? "",
|
|
3183
|
+
arguments: state.arguments
|
|
3184
|
+
};
|
|
3185
|
+
return {
|
|
3186
|
+
type: "reasoning",
|
|
3187
|
+
...state.itemId ? { id: state.itemId } : {},
|
|
3188
|
+
...state.status ? { status: state.status } : {},
|
|
3189
|
+
...state.summary.size ? {
|
|
3190
|
+
summary: [...state.summary.entries()].sort(([a], [b]) => a - b).map(([, text]) => ({ type: "summary_text", text }))
|
|
3191
|
+
} : {},
|
|
3192
|
+
...state.reasoningText ? { text: state.reasoningText } : {}
|
|
3193
|
+
};
|
|
3157
3194
|
});
|
|
3158
3195
|
try {
|
|
3159
3196
|
for await (const event of this.source) {
|
|
@@ -3197,7 +3234,12 @@ var OpenAIResponsesStream = class {
|
|
|
3197
3234
|
case "response.content_part.done": {
|
|
3198
3235
|
const e = payload;
|
|
3199
3236
|
if (e.part.type === "output_text" && "text" in e.part && typeof e.part.text === "string" || e.part.type === "refusal" && "refusal" in e.part && typeof e.part.refusal === "string") {
|
|
3200
|
-
applyContentPart(
|
|
3237
|
+
applyContentPart(
|
|
3238
|
+
e.output_index,
|
|
3239
|
+
e.item_id,
|
|
3240
|
+
e.content_index,
|
|
3241
|
+
e.part
|
|
3242
|
+
);
|
|
3201
3243
|
}
|
|
3202
3244
|
break;
|
|
3203
3245
|
}
|
|
@@ -3205,7 +3247,10 @@ var OpenAIResponsesStream = class {
|
|
|
3205
3247
|
const e = payload;
|
|
3206
3248
|
const s = ensureState(e.output_index, e.item_id, "message");
|
|
3207
3249
|
const p = s.content.get(e.content_index);
|
|
3208
|
-
s.content.set(e.content_index, {
|
|
3250
|
+
s.content.set(e.content_index, {
|
|
3251
|
+
type: "output_text",
|
|
3252
|
+
text: (p?.type === "output_text" ? p.text : "") + e.delta
|
|
3253
|
+
});
|
|
3209
3254
|
break;
|
|
3210
3255
|
}
|
|
3211
3256
|
case "response.output_text.done": {
|
|
@@ -3218,7 +3263,10 @@ var OpenAIResponsesStream = class {
|
|
|
3218
3263
|
const e = payload;
|
|
3219
3264
|
const s = ensureState(e.output_index, e.item_id, "message");
|
|
3220
3265
|
const p = s.content.get(e.content_index);
|
|
3221
|
-
s.content.set(e.content_index, {
|
|
3266
|
+
s.content.set(e.content_index, {
|
|
3267
|
+
type: "refusal",
|
|
3268
|
+
refusal: (p?.type === "refusal" ? p.refusal : "") + e.delta
|
|
3269
|
+
});
|
|
3222
3270
|
break;
|
|
3223
3271
|
}
|
|
3224
3272
|
case "response.refusal.done": {
|
|
@@ -3280,20 +3328,31 @@ var OpenAIResponsesStream = class {
|
|
|
3280
3328
|
const response = terminalFailure ?? terminalIncomplete;
|
|
3281
3329
|
const status = terminalFailure ? "failed" : "incomplete";
|
|
3282
3330
|
const detail = response.error?.message ?? response.incomplete_details?.reason ?? "unknown error";
|
|
3283
|
-
throw new OpenAIResponsesStreamError(
|
|
3331
|
+
throw new OpenAIResponsesStreamError(
|
|
3332
|
+
"OpenAI Responses stream " + status + ": " + detail,
|
|
3333
|
+
response
|
|
3334
|
+
);
|
|
3284
3335
|
}
|
|
3285
3336
|
if (!finalResponse) {
|
|
3286
|
-
if (!responseMeta)
|
|
3337
|
+
if (!responseMeta)
|
|
3338
|
+
throw new Error("OpenAI Responses stream ended without a terminal response payload");
|
|
3287
3339
|
if (responseMeta.status === "failed" || responseMeta.status === "incomplete") {
|
|
3288
3340
|
const detail = responseMeta.error?.message ?? responseMeta.incomplete_details?.reason ?? "unknown error";
|
|
3289
|
-
throw new OpenAIResponsesStreamError(
|
|
3341
|
+
throw new OpenAIResponsesStreamError(
|
|
3342
|
+
"OpenAI Responses stream " + responseMeta.status + ": " + detail,
|
|
3343
|
+
responseMeta
|
|
3344
|
+
);
|
|
3290
3345
|
}
|
|
3291
3346
|
finalResponse = { ...responseMeta, output: reconstructedOutput(), status: "completed" };
|
|
3292
3347
|
} else if (finalResponse.status === "failed" || finalResponse.status === "incomplete") {
|
|
3293
3348
|
const detail = finalResponse.error?.message ?? finalResponse.incomplete_details?.reason ?? "unknown error";
|
|
3294
|
-
throw new OpenAIResponsesStreamError(
|
|
3349
|
+
throw new OpenAIResponsesStreamError(
|
|
3350
|
+
"OpenAI Responses stream " + finalResponse.status + ": " + detail,
|
|
3351
|
+
finalResponse
|
|
3352
|
+
);
|
|
3295
3353
|
}
|
|
3296
|
-
if (finalResponse.output.length === 0 && outputs.size > 0)
|
|
3354
|
+
if (finalResponse.output.length === 0 && outputs.size > 0)
|
|
3355
|
+
finalResponse = { ...finalResponse, output: reconstructedOutput() };
|
|
3297
3356
|
completed = true;
|
|
3298
3357
|
this.removeAbortListener?.();
|
|
3299
3358
|
this.removeAbortListener = void 0;
|
|
@@ -3318,14 +3377,11 @@ var OpenAICompatClient = class {
|
|
|
3318
3377
|
}
|
|
3319
3378
|
request(operation, model, signal, holdUntil) {
|
|
3320
3379
|
if (this.runner) {
|
|
3321
|
-
return this.runner(
|
|
3322
|
-
|
|
3323
|
-
{
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
...holdUntil !== void 0 ? { holdUntil } : {}
|
|
3327
|
-
}
|
|
3328
|
-
);
|
|
3380
|
+
return this.runner((http, runnerSignal) => operation(http, runnerSignal), {
|
|
3381
|
+
...model !== void 0 ? { model } : {},
|
|
3382
|
+
...signal !== void 0 ? { signal } : {},
|
|
3383
|
+
...holdUntil !== void 0 ? { holdUntil } : {}
|
|
3384
|
+
});
|
|
3329
3385
|
}
|
|
3330
3386
|
return operation(this.http, signal);
|
|
3331
3387
|
}
|
|
@@ -3954,7 +4010,7 @@ var SystemOneContentSchema = z.union([
|
|
|
3954
4010
|
var SystemOneChoiceQuestionSchema = z.object({
|
|
3955
4011
|
type: z.enum(["choice"]),
|
|
3956
4012
|
instructions: SystemOneContentSchema,
|
|
3957
|
-
criteria: z.object({}).catchall(z.union([z.string(), z.null()])).refine((v) => Object.keys(v).length >= 2, { message: "must have at least 2 properties" }).refine((v) => Object.keys(v).length <=
|
|
4013
|
+
criteria: z.object({}).catchall(z.union([z.string(), z.null()])).refine((v) => Object.keys(v).length >= 2, { message: "must have at least 2 properties" }).refine((v) => Object.keys(v).length <= 255, { message: "must have at most 255 properties" }).refine((v) => Object.keys(v).every((k) => new RegExp("\\S").test(k)), {
|
|
3958
4014
|
message: 'property names must match pattern "\\S"'
|
|
3959
4015
|
})
|
|
3960
4016
|
});
|
|
@@ -4093,6 +4149,7 @@ var requestSchemas = {
|
|
|
4093
4149
|
var responseSchemas = {
|
|
4094
4150
|
balance: BalanceResponseSchema,
|
|
4095
4151
|
chat: ChatResponseSchema,
|
|
4152
|
+
copy: StatusResponseSchema,
|
|
4096
4153
|
create: StatusResponseSchema,
|
|
4097
4154
|
embed: EmbedResponseSchema,
|
|
4098
4155
|
generate: GenerateResponseSchema,
|
|
@@ -4999,6 +5056,7 @@ var copyOp = {
|
|
|
4999
5056
|
method: "POST",
|
|
5000
5057
|
path: "/api/copy",
|
|
5001
5058
|
request: { $ref: "#/schemas/CopyRequest" },
|
|
5059
|
+
response: { $ref: "#/schemas/StatusResponse" },
|
|
5002
5060
|
environment: { local: true, cloud: false },
|
|
5003
5061
|
transport: { mode: "json", streaming: false },
|
|
5004
5062
|
capabilities: {},
|
|
@@ -6885,6 +6943,93 @@ var ToolRegistry = class {
|
|
|
6885
6943
|
};
|
|
6886
6944
|
}
|
|
6887
6945
|
};
|
|
6946
|
+
var WEB_SEARCH_TOOL_NAME = "web_search";
|
|
6947
|
+
var WEB_FETCH_TOOL_NAME = "web_fetch";
|
|
6948
|
+
var DEFAULT_MAX_OUTPUT_CHARS = 2e3 * 4;
|
|
6949
|
+
var DEFAULT_MAX_LINKS = 25;
|
|
6950
|
+
var TRUNCATION_MARKER = "\u2026[truncated]";
|
|
6951
|
+
var webSearchSchema = z.object({
|
|
6952
|
+
query: z.string().min(1).describe("The search query string"),
|
|
6953
|
+
max_results: z.number().int().min(1).max(10).optional().describe("Maximum results to return (default 5, max 10)")
|
|
6954
|
+
});
|
|
6955
|
+
var webFetchSchema = z.object({
|
|
6956
|
+
url: z.string().min(1).describe("The URL of the web page to fetch")
|
|
6957
|
+
});
|
|
6958
|
+
function positiveInt2(value, fallback, name) {
|
|
6959
|
+
if (value === void 0) return fallback;
|
|
6960
|
+
if (!Number.isInteger(value) || value < 1) {
|
|
6961
|
+
throw new RangeError(`${name} must be a positive integer, received ${String(value)}`);
|
|
6962
|
+
}
|
|
6963
|
+
return value;
|
|
6964
|
+
}
|
|
6965
|
+
function truncate(text, maxChars) {
|
|
6966
|
+
if (text.length <= maxChars) return text;
|
|
6967
|
+
if (maxChars <= TRUNCATION_MARKER.length) return text.slice(0, maxChars);
|
|
6968
|
+
return text.slice(0, maxChars - TRUNCATION_MARKER.length) + TRUNCATION_MARKER;
|
|
6969
|
+
}
|
|
6970
|
+
function formatWebSearchResult(res, maxChars) {
|
|
6971
|
+
const results = res.results.map(({ title, url, content }) => ({ title, url, content }));
|
|
6972
|
+
const full = JSON.stringify({ results });
|
|
6973
|
+
if (full.length <= maxChars || results.length === 0) return truncate(full, maxChars);
|
|
6974
|
+
const overhead = JSON.stringify({
|
|
6975
|
+
results: results.map((r) => ({ ...r, content: "" }))
|
|
6976
|
+
}).length;
|
|
6977
|
+
const perResult = Math.max(0, Math.floor((maxChars - overhead) / results.length));
|
|
6978
|
+
const trimmed = JSON.stringify({
|
|
6979
|
+
results: results.map((r) => ({ ...r, content: truncate(r.content, perResult) }))
|
|
6980
|
+
});
|
|
6981
|
+
return trimmed.length <= maxChars ? trimmed : truncate(trimmed, maxChars);
|
|
6982
|
+
}
|
|
6983
|
+
function formatWebFetchResult(res, maxChars, maxLinks = DEFAULT_MAX_LINKS) {
|
|
6984
|
+
const page = {
|
|
6985
|
+
title: res.title ?? "",
|
|
6986
|
+
content: res.content,
|
|
6987
|
+
links: (res.links ?? []).slice(0, maxLinks)
|
|
6988
|
+
};
|
|
6989
|
+
const full = JSON.stringify(page);
|
|
6990
|
+
if (full.length <= maxChars) return full;
|
|
6991
|
+
const overhead = JSON.stringify({ ...page, content: "" }).length;
|
|
6992
|
+
const trimmed = JSON.stringify({
|
|
6993
|
+
...page,
|
|
6994
|
+
content: truncate(page.content, Math.max(0, maxChars - overhead))
|
|
6995
|
+
});
|
|
6996
|
+
return trimmed.length <= maxChars ? trimmed : truncate(trimmed, maxChars);
|
|
6997
|
+
}
|
|
6998
|
+
function createWebSearchTool(client, options = {}) {
|
|
6999
|
+
const maxChars = positiveInt2(options.maxOutputChars, DEFAULT_MAX_OUTPUT_CHARS, "maxOutputChars");
|
|
7000
|
+
const defaultMaxResults = options.defaultMaxResults === void 0 ? void 0 : Math.min(positiveInt2(options.defaultMaxResults, 5, "defaultMaxResults"), 10);
|
|
7001
|
+
return defineTool({
|
|
7002
|
+
name: WEB_SEARCH_TOOL_NAME,
|
|
7003
|
+
description: "Search the web for current information. Returns a list of results, each with a title, url, and relevant content snippet.",
|
|
7004
|
+
schema: webSearchSchema,
|
|
7005
|
+
timeoutMs: options.timeoutMs,
|
|
7006
|
+
execute: async ({ query, max_results }, { signal }) => {
|
|
7007
|
+
const res = await client.webSearch({
|
|
7008
|
+
query,
|
|
7009
|
+
...(max_results ?? defaultMaxResults) !== void 0 ? { max_results: max_results ?? defaultMaxResults } : {},
|
|
7010
|
+
...signal !== void 0 ? { signal } : {}
|
|
7011
|
+
});
|
|
7012
|
+
return formatWebSearchResult(res, maxChars);
|
|
7013
|
+
}
|
|
7014
|
+
});
|
|
7015
|
+
}
|
|
7016
|
+
function createWebFetchTool(client, options = {}) {
|
|
7017
|
+
const maxChars = positiveInt2(options.maxOutputChars, DEFAULT_MAX_OUTPUT_CHARS, "maxOutputChars");
|
|
7018
|
+
const maxLinks = positiveInt2(options.maxLinks, DEFAULT_MAX_LINKS, "maxLinks");
|
|
7019
|
+
return defineTool({
|
|
7020
|
+
name: WEB_FETCH_TOOL_NAME,
|
|
7021
|
+
description: "Fetch a single web page by URL. Returns the page title, its main content, and links found on the page.",
|
|
7022
|
+
schema: webFetchSchema,
|
|
7023
|
+
timeoutMs: options.timeoutMs,
|
|
7024
|
+
execute: async ({ url }, { signal }) => {
|
|
7025
|
+
const res = await client.webFetch({ url, ...signal !== void 0 ? { signal } : {} });
|
|
7026
|
+
return formatWebFetchResult(res, maxChars, maxLinks);
|
|
7027
|
+
}
|
|
7028
|
+
});
|
|
7029
|
+
}
|
|
7030
|
+
function createWebTools(client, options = {}) {
|
|
7031
|
+
return [createWebSearchTool(client, options), createWebFetchTool(client, options)];
|
|
7032
|
+
}
|
|
6888
7033
|
|
|
6889
7034
|
// src/mcp/json-schema.ts
|
|
6890
7035
|
function label(path) {
|
|
@@ -7732,6 +7877,6 @@ function estimateSystemOneRequestBytes(request) {
|
|
|
7732
7877
|
return new TextEncoder().encode(JSON.stringify(request)).byteLength;
|
|
7733
7878
|
}
|
|
7734
7879
|
|
|
7735
|
-
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, Agent, AnthropicCompatClient, AnthropicMessagesStream, ConversationSession, DEFAULT_BACKOFF, DEFAULT_BASE_URL, DEFAULT_CONTEXT_WARNING_THRESHOLD, DEFAULT_EMBED_BATCH_SIZE, DEFAULT_EMBED_CONCURRENCY, DEFAULT_FAILOVER_CODES, DEFAULT_FETCH_BACKOFF_CONFIG, DEFAULT_RETRY_CONFIG, DEFAULT_TIMEOUT_MS, EndpointRegistry, GEN_AI_SYSTEM_OLLAMA, HttpClient, IMAGE_TOKEN_ESTIMATE, KEEP_ALIVE_INDEFINITE, KEEP_ALIVE_UNLOAD, KNOWN_DONE_REASONS, MAX_SYSTEM_ONE_IMAGES_BYTES, MAX_SYSTEM_ONE_REQUEST_BYTES, MESSAGE_OVERHEAD_TOKENS, McpBridge, ModelAffinityRouter, ModelAffinityScheduler, ModelsClient, NANOS_PER_MS, NANOS_PER_SECOND, NOOP_LOGGER, OLLAMA_CLOUD_BASE_URL, OLLAMA_FALLBACK_CONTEXT_LENGTH, OllamaAbortError, OllamaAgentMaxIterationsError, OllamaAgentMaxToolCallsError, OllamaAgentToolLoopError, OllamaAuthError, OllamaBadGatewayError, OllamaClient, OllamaClientError, OllamaGenericClientError, OllamaIncompatibleModelError, OllamaMcpError, OllamaModelRoutingError, OllamaNetworkError, OllamaNotFoundError, OllamaOverloadedError, OllamaQuotaExceededError, OllamaRateLimitError, OllamaRequestTooLargeError, OllamaRequestValidationError, OllamaResponseValidationError, OllamaServerError, OllamaServerVersionUnknownError, OllamaSkillInvalidError, OllamaSkillNotFoundError, OllamaStream, OllamaStreamError, OllamaTimeoutError, OllamaToolTimeoutError, OllamaToolValidationError, OllamaUnsupportedCapabilityError, OpenAIChatCompletionStream, OpenAICompatClient, OpenAICompletionStream, OpenAIResponsesStream, OpenAIResponsesStreamError, QuotaManager, RETRYABLE_STATUS_CODES, ResponsesModule, ToolCallAccumulator, ToolRegistry, addSpanEvent, applySkill, batchEmbed, calculateBackoff, canonicalToolCallSignature, checkChatContext, checkEndpointHealth, checkGenerateContext, compactConversationHistory, composeMiddleware, contextWarningMessage, createConsoleLogger, createDecision, createModelAffinityScheduler, createOllamaCloudFreeTierQuota, createTimeoutSignal, defineTool, detectModelCapabilities, embedBatchOverflowMessage, encodeImage, estimateChatRequestTokens, estimateGenerateRequestTokens, estimateMessageTokens, estimateSystemOneRequestBytes, estimateTokens, extractContextLength as extractNativeContextLength, extractParameterNumCtx, extractUsage, fetchWithBackoff, findOversizedEmbedInputs, findRunningModelContextLength, formatTelemetry, imageStringNeedsResolution, inferRuntimeMode, isKeepAliveSugar, isKnownDoneReason, isModelResident, isSameToolCall, listAllMcpTools, listAvailableModels, loadMcpTools, mapError, mergeToolCall, mergeToolCallArgumentsString, mergeToolCallArrays, normalizeChatStream, normalizeGenerateStream, normalizeKeepAlive, normalizeProgressStream, parseFrontmatter, parseNdjsonStream, parseSseStream, parseStructuredOutput, registerMcpTools, resolveContextLength, resolveCredentialEndpoints, resolveImageInput, sanitizeHistoryForNextTurn, setSpanError, toDataStream, toResponse, toTextStream, withRetry, withSpan, zodToJsonSchema };
|
|
7880
|
+
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, Agent, AnthropicCompatClient, AnthropicMessagesStream, ConversationSession, DEFAULT_BACKOFF, DEFAULT_BASE_URL, DEFAULT_CONTEXT_WARNING_THRESHOLD, DEFAULT_EMBED_BATCH_SIZE, DEFAULT_EMBED_CONCURRENCY, DEFAULT_FAILOVER_CODES, DEFAULT_FETCH_BACKOFF_CONFIG, DEFAULT_RETRY_CONFIG, DEFAULT_TIMEOUT_MS, EndpointRegistry, GEN_AI_SYSTEM_OLLAMA, HttpClient, IMAGE_TOKEN_ESTIMATE, KEEP_ALIVE_INDEFINITE, KEEP_ALIVE_UNLOAD, KNOWN_DONE_REASONS, MAX_SYSTEM_ONE_IMAGES_BYTES, MAX_SYSTEM_ONE_REQUEST_BYTES, MESSAGE_OVERHEAD_TOKENS, McpBridge, ModelAffinityRouter, ModelAffinityScheduler, ModelsClient, NANOS_PER_MS, NANOS_PER_SECOND, NOOP_LOGGER, OLLAMA_CLOUD_BASE_URL, OLLAMA_FALLBACK_CONTEXT_LENGTH, OllamaAbortError, OllamaAgentMaxIterationsError, OllamaAgentMaxToolCallsError, OllamaAgentToolLoopError, OllamaAuthError, OllamaBadGatewayError, OllamaClient, OllamaClientError, OllamaGenericClientError, OllamaIncompatibleModelError, OllamaMcpError, OllamaModelRoutingError, OllamaNetworkError, OllamaNotFoundError, OllamaOverloadedError, OllamaQuotaExceededError, OllamaRateLimitError, OllamaRequestTooLargeError, OllamaRequestValidationError, OllamaResponseValidationError, OllamaServerError, OllamaServerVersionUnknownError, OllamaSkillInvalidError, OllamaSkillNotFoundError, OllamaStream, OllamaStreamError, OllamaTimeoutError, OllamaToolTimeoutError, OllamaToolValidationError, OllamaUnsupportedCapabilityError, OpenAIChatCompletionStream, OpenAICompatClient, OpenAICompletionStream, OpenAIResponsesStream, OpenAIResponsesStreamError, QuotaManager, RETRYABLE_STATUS_CODES, ResponsesModule, ToolCallAccumulator, ToolRegistry, WEB_FETCH_TOOL_NAME, WEB_SEARCH_TOOL_NAME, addSpanEvent, applySkill, batchEmbed, calculateBackoff, canonicalToolCallSignature, checkChatContext, checkEndpointHealth, checkGenerateContext, compactConversationHistory, composeMiddleware, contextWarningMessage, createConsoleLogger, createDecision, createModelAffinityScheduler, createOllamaCloudFreeTierQuota, createTimeoutSignal, createWebFetchTool, createWebSearchTool, createWebTools, defineTool, detectModelCapabilities, embedBatchOverflowMessage, encodeImage, estimateChatRequestTokens, estimateGenerateRequestTokens, estimateMessageTokens, estimateSystemOneRequestBytes, estimateTokens, extractContextLength as extractNativeContextLength, extractParameterNumCtx, extractUsage, fetchWithBackoff, findOversizedEmbedInputs, findRunningModelContextLength, formatTelemetry, formatWebFetchResult, formatWebSearchResult, imageStringNeedsResolution, inferRuntimeMode, isKeepAliveSugar, isKnownDoneReason, isModelResident, isSameToolCall, listAllMcpTools, listAvailableModels, loadMcpTools, mapError, mergeToolCall, mergeToolCallArgumentsString, mergeToolCallArrays, normalizeChatStream, normalizeGenerateStream, normalizeKeepAlive, normalizeProgressStream, parseFrontmatter, parseNdjsonStream, parseSseStream, parseStructuredOutput, registerMcpTools, resolveContextLength, resolveCredentialEndpoints, resolveImageInput, sanitizeHistoryForNextTurn, setSpanError, toDataStream, toResponse, toTextStream, withRetry, withSpan, zodToJsonSchema };
|
|
7736
7881
|
//# sourceMappingURL=index.js.map
|
|
7737
7882
|
//# sourceMappingURL=index.js.map
|