@openclaw/ai 2026.7.2-beta.6 → 2026.7.33
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/README.md +5 -6
- package/dist/{anthropic-CH4UUnZr.mjs → anthropic-BML72tLz.mjs} +468 -101
- package/dist/{api-registry-DlMgPR39.d.mts → api-registry-BXYnCOIR.d.mts} +2 -1
- package/dist/{azure-openai-responses-client-compat-C7K7QfUE.mjs → azure-openai-responses-client-compat-a_O_GVQV.mjs} +2 -23
- package/dist/{azure-openai-responses-CImcwB83.mjs → azure-openai-responses-kEN8II8I.mjs} +13 -11
- package/dist/{env-api-keys-DrgeBuva.mjs → env-api-keys-CtMlqaQ4.mjs} +4 -5
- package/dist/{event-stream-YjaPW20U.d.mts → event-stream-0nZeBKl2.d.mts} +1 -1
- package/dist/{event-stream-D8n2uFee.mjs → event-stream-ReMmOTzX.mjs} +6 -14
- package/dist/event-stream.d.mts +1 -1
- package/dist/event-stream.mjs +1 -1
- package/dist/{github-copilot-headers-NCJtz9i0.mjs → github-copilot-headers-BsH5cqGj.mjs} +12 -1
- package/dist/{google-CtSg0iTS.mjs → google-DTM4O3e9.mjs} +5 -5
- package/dist/{google-shared-DNBz5rcD.mjs → google-shared-BAP0BQVi.mjs} +22 -34
- package/dist/{google-vertex-31f1uS9L.mjs → google-vertex-D58MZHCQ.mjs} +19 -6
- package/dist/host-4t713IeR.mjs +37 -0
- package/dist/{anthropic-SrGtwsJu.d.mts → index-BoTnz8cv.d.mts} +1 -27
- package/dist/index.d.mts +50 -7
- package/dist/index.mjs +5 -5
- package/dist/internal/anthropic.d.mts +62 -22
- package/dist/internal/anthropic.mjs +4 -5
- package/dist/internal/openai.d.mts +82 -98
- package/dist/internal/openai.mjs +6 -8
- package/dist/internal/runtime.d.mts +34 -13
- package/dist/internal/runtime.mjs +14 -26
- package/dist/internal/shared.d.mts +9 -26
- package/dist/internal/shared.mjs +2 -6
- package/dist/{json-parse-BvXNt1-7.mjs → json-parse-DzNSIQBq.mjs} +6 -4
- package/dist/{llm-request-activity-BjtkplhG.mjs → llm-request-activity-CehVkZP-.mjs} +19 -1
- package/dist/{mistral-CWmpvWYh.mjs → mistral-CePVNdws.mjs} +39 -141
- package/dist/model-utils-DgmOla96.mjs +69 -0
- package/dist/{openai-chatgpt-responses-B84Ibtrd.mjs → openai-chatgpt-responses-BHqbcipc.mjs} +154 -101
- package/dist/{openai-completions-DsOxhOD1.mjs → openai-completions-9qYFVS7H.mjs} +295 -81
- package/dist/{openai-responses-BT7A3sLu.mjs → openai-responses-D6l9URyV.mjs} +8 -10
- package/dist/openai-responses-shared-L3PWZvkm.mjs +1949 -0
- package/dist/{openai-tool-projection-OhX64DoP.mjs → openai-tool-projection-BPlyXt8H.mjs} +12 -32
- package/dist/providers.d.mts +2 -3
- package/dist/providers.mjs +10 -11
- package/dist/reasoning-tag-text-partitioner-axhAdUwg.mjs +394 -0
- package/dist/{src-QkygScBs.mjs → src-CZ503MYJ.mjs} +5 -24
- package/dist/{stream-first-event-timeout-BBys9hSb.mjs → stream-first-event-timeout-RjWszj8c.mjs} +22 -2
- package/dist/transform-messages-BhGF_fF4.mjs +507 -0
- package/dist/{types-bzp5k29J.d.mts → types-DRgdPqaZ.d.mts} +0 -19
- package/dist/types.d.mts +5 -5
- package/dist/types.mjs +4 -4
- package/dist/{validation-B-j7cOYp.d.mts → validation-BDMWOr8d.d.mts} +1 -1
- package/dist/{validation-DAa_yFOM.mjs → validation-FrchoOlv.mjs} +7 -2
- package/dist/validation.d.mts +1 -1
- package/dist/validation.mjs +1 -1
- package/npm-shrinkwrap.json +645 -0
- package/package.json +11 -36
- package/dist/anthropic-usage-DWU-x8MI.mjs +0 -459
- package/dist/cache-retention-0x979a5V.mjs +0 -12
- package/dist/deferred-event-buffer-DAvyP7qA.mjs +0 -19
- package/dist/error-coercion-DgxlWC0n.mjs +0 -15
- package/dist/host-B9GUmcra.d.mts +0 -173
- package/dist/host-Dog2WQiR.mjs +0 -369
- package/dist/index-BVVgDSdq.d.mts +0 -1
- package/dist/internal/retry-after.d.mts +0 -5
- package/dist/internal/retry-after.mjs +0 -101
- package/dist/number-coercion-DvG7SNMg.mjs +0 -129
- package/dist/openai-completions-compat-DBWjXoMZ.d.mts +0 -43
- package/dist/openai-prompt-cache-2uo_1OR1.d.mts +0 -7
- package/dist/openai-prompt-cache-mZTCdRPo.mjs +0 -12
- package/dist/openai-reasoning-compat-YgeLncHw.mjs +0 -396
- package/dist/openai-responses-shared-pXl6Wd8S.mjs +0 -392
- package/dist/openai-responses-stream-internal-Cw5txaGW.mjs +0 -2964
- package/dist/prompt-cache-stability-Cwcjv_fx.d.mts +0 -13
- package/dist/provider-error-CAEvRjry.mjs +0 -47
- package/dist/provider-options-D8bB3z9b.d.mts +0 -144
- package/dist/reasoning-tag-text-partitioner-CGDyLWUR.mjs +0 -12209
- package/dist/simple-options-9lhRrN73.mjs +0 -50
- package/dist/stream-first-event-timeout-DvDeSucC.d.mts +0 -29
- package/dist/tls-certificate-errors-DXSpluKI.mjs +0 -93
- package/dist/tool-result-text-CTpIRbYd.mjs +0 -225
- package/dist/transform-messages-C8mBqZxF.mjs +0 -2
- package/dist/transport-stream-shared-D81p90xq.mjs +0 -297
- package/dist/transports.d.mts +0 -573
- package/dist/transports.mjs +0 -4110
|
@@ -1,8 +1,58 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as resolveClaudeFable5ModelIdentity, c as resolveClaudeNativeThinkingLevelMap, d as supportsClaudeNativeMaxEffort, f as supportsClaudeNativeXhighEffort, i as requiresClaudeMandatoryAdaptiveThinking, l as resolveClaudeSonnet5ModelIdentity, o as resolveClaudeModelIdentity, r as requiresClaudeDefaultSampling, s as resolveClaudeMythos5ModelIdentity, u as supportsClaudeAdaptiveThinking } from "../index-BoTnz8cv.mjs";
|
|
2
2
|
import { t as AssistantMessageDiagnostic } from "../diagnostics-BaTA9eVl.mjs";
|
|
3
|
-
import { E as Model, F as SimpleStreamOptions, R as StreamFunction, u as Context } from "../types-
|
|
4
|
-
import
|
|
3
|
+
import { E as Model, F as SimpleStreamOptions, R as StreamFunction, u as Context, z as StreamOptions } from "../types-DRgdPqaZ.mjs";
|
|
4
|
+
import Anthropic from "@anthropic-ai/sdk";
|
|
5
|
+
|
|
5
6
|
//#region packages/ai/src/providers/anthropic.d.ts
|
|
7
|
+
type AnthropicEffort = "low" | "medium" | "high" | "xhigh" | "max";
|
|
8
|
+
type AnthropicThinkingDisplay = "summarized" | "omitted";
|
|
9
|
+
interface AnthropicOptions extends StreamOptions {
|
|
10
|
+
/**
|
|
11
|
+
* Enable extended thinking.
|
|
12
|
+
* For Opus 4.6+ and Sonnet 4.6: uses adaptive thinking (model decides when/how much to think).
|
|
13
|
+
* For older models: uses budget-based thinking with thinkingBudgetTokens.
|
|
14
|
+
*/
|
|
15
|
+
thinkingEnabled?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Token budget for extended thinking (older models only).
|
|
18
|
+
* Ignored for Opus 4.6+ and Sonnet 4.6, which use adaptive thinking.
|
|
19
|
+
*/
|
|
20
|
+
thinkingBudgetTokens?: number;
|
|
21
|
+
/**
|
|
22
|
+
* Effort level for adaptive thinking (Opus 4.6+ and Sonnet 4.6).
|
|
23
|
+
* Controls how much thinking Claude allocates:
|
|
24
|
+
* - "max": Always thinks with no constraints (Opus 4.6 only)
|
|
25
|
+
* - "xhigh": Highest reasoning level (Opus 4.7+)
|
|
26
|
+
* - "high": Always thinks, deep reasoning (default)
|
|
27
|
+
* - "medium": Moderate thinking, may skip for simple queries
|
|
28
|
+
* - "low": Minimal thinking, skips for simple tasks
|
|
29
|
+
* Ignored for older models.
|
|
30
|
+
*/
|
|
31
|
+
effort?: AnthropicEffort;
|
|
32
|
+
/**
|
|
33
|
+
* Controls how thinking content is returned in API responses.
|
|
34
|
+
* - "summarized": Thinking blocks contain summarized thinking text (default here).
|
|
35
|
+
* - "omitted": Thinking blocks return an empty thinking field; the encrypted
|
|
36
|
+
* signature still travels back for multi-turn continuity. Use for faster
|
|
37
|
+
* time-to-first-text-token when your UI does not surface thinking.
|
|
38
|
+
*
|
|
39
|
+
* Note: Anthropic's API default for Claude Opus 4.7+ and Claude Mythos Preview
|
|
40
|
+
* is "omitted". We default to "summarized" here to keep behavior consistent
|
|
41
|
+
* with older Claude 4 models. Set this explicitly to "omitted" to opt in.
|
|
42
|
+
*/
|
|
43
|
+
thinkingDisplay?: AnthropicThinkingDisplay;
|
|
44
|
+
interleavedThinking?: boolean;
|
|
45
|
+
toolChoice?: "auto" | "any" | "none" | {
|
|
46
|
+
type: "tool";
|
|
47
|
+
name: string;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Pre-built Anthropic client instance. When provided, skips internal client
|
|
51
|
+
* construction entirely. Use this to inject alternative SDK clients such as
|
|
52
|
+
* `AnthropicVertex` that shares the same messaging API.
|
|
53
|
+
*/
|
|
54
|
+
client?: Anthropic;
|
|
55
|
+
}
|
|
6
56
|
declare const streamAnthropic: StreamFunction<"anthropic-messages", AnthropicOptions>;
|
|
7
57
|
type AnthropicSimpleStreamOptions = SimpleStreamOptions & {
|
|
8
58
|
toolChoice?: AnthropicOptions["toolChoice"];
|
|
@@ -48,8 +98,8 @@ declare function defaultsClaudeAdaptiveThinking(model: {
|
|
|
48
98
|
params?: Record<string, unknown>;
|
|
49
99
|
api?: string;
|
|
50
100
|
}): boolean;
|
|
51
|
-
/** Remove
|
|
52
|
-
declare function
|
|
101
|
+
/** Remove Sonnet 5 assistant prefills while preserving completed tool-use turns. */
|
|
102
|
+
declare function prepareClaudeSonnet5RequestContext(model: Model, context: Context): Context;
|
|
53
103
|
declare function applyClaudeRequestContract(params: Record<string, unknown>, model: {
|
|
54
104
|
id?: string;
|
|
55
105
|
params?: Record<string, unknown>;
|
|
@@ -70,25 +120,21 @@ declare function applyAnthropicRefusal(output: AnthropicRefusalOutput, stopDetai
|
|
|
70
120
|
//#endregion
|
|
71
121
|
//#region packages/ai/src/providers/anthropic-server-fallback.d.ts
|
|
72
122
|
/** Anthropic beta that re-serves safety refusals on an allowed fallback model. */
|
|
73
|
-
declare const ANTHROPIC_SERVER_SIDE_FALLBACK_BETA = "server-side-fallback-2026-
|
|
74
|
-
|
|
75
|
-
declare const
|
|
76
|
-
declare const CLAUDE_OPUS_FALLBACK_MODEL_COST: {
|
|
123
|
+
declare const ANTHROPIC_SERVER_SIDE_FALLBACK_BETA = "server-side-fallback-2026-06-01";
|
|
124
|
+
declare const CLAUDE_FABLE_5_FALLBACK_MODEL = "claude-opus-4-8";
|
|
125
|
+
declare const CLAUDE_FABLE_5_FALLBACK_MODEL_COST: {
|
|
77
126
|
readonly input: 5;
|
|
78
127
|
readonly output: 25;
|
|
79
128
|
readonly cacheRead: 0.5;
|
|
80
129
|
readonly cacheWrite: 6.25;
|
|
81
130
|
};
|
|
131
|
+
declare function buildAnthropicServerSideFallbacks(): Array<{
|
|
132
|
+
model: string;
|
|
133
|
+
}>;
|
|
82
134
|
type AnthropicFallbackBoundary = {
|
|
83
135
|
fromModel: string | null;
|
|
84
136
|
toModel: string | null;
|
|
85
137
|
};
|
|
86
|
-
/** Resolve billed rates from the serving model reported by Anthropic's fallback stream. */
|
|
87
|
-
declare function resolveAnthropicFallbackServingModelCost(params: {
|
|
88
|
-
requestedModelId: string;
|
|
89
|
-
servingModelId: string | null;
|
|
90
|
-
requestedCost: Model["cost"];
|
|
91
|
-
}): Model["cost"];
|
|
92
138
|
/** Reads a `fallback` content block marking where one model's output gives way to the next. */
|
|
93
139
|
declare function readAnthropicFallbackBoundary(block: unknown): AnthropicFallbackBoundary | null;
|
|
94
140
|
/**
|
|
@@ -162,13 +208,8 @@ type AnthropicUsagePayload = {
|
|
|
162
208
|
output_tokens?: unknown;
|
|
163
209
|
cache_read_input_tokens?: unknown;
|
|
164
210
|
cache_creation_input_tokens?: unknown;
|
|
165
|
-
cache_creation?: unknown;
|
|
166
211
|
iterations?: unknown;
|
|
167
212
|
};
|
|
168
|
-
type AnthropicCacheWriteUsage = {
|
|
169
|
-
cacheWrite5m?: number;
|
|
170
|
-
cacheWrite1h?: number;
|
|
171
|
-
};
|
|
172
213
|
type AnthropicPromptUsageSnapshot = {
|
|
173
214
|
input: number;
|
|
174
215
|
cacheRead: number;
|
|
@@ -187,8 +228,7 @@ type AnthropicIterationUsageResult = {
|
|
|
187
228
|
usage: AnthropicIterationUsageSnapshot;
|
|
188
229
|
};
|
|
189
230
|
declare function readAnthropicUsageTokenCount(value: unknown): number | undefined;
|
|
190
|
-
declare function readAnthropicCacheWriteUsage(usage: AnthropicUsagePayload): AnthropicCacheWriteUsage;
|
|
191
231
|
declare function readAnthropicPromptUsageSnapshot(usage: AnthropicUsagePayload): AnthropicPromptUsageSnapshot | undefined;
|
|
192
232
|
declare function readLastAnthropicIterationUsage(usage: AnthropicUsagePayload): AnthropicIterationUsageResult;
|
|
193
233
|
//#endregion
|
|
194
|
-
export { ANTHROPIC_OMITTED_REASONING_TEXT,
|
|
234
|
+
export { ANTHROPIC_OMITTED_REASONING_TEXT, ANTHROPIC_SERVER_SIDE_FALLBACK_BETA, AnthropicEffort, AnthropicFallbackBoundary, AnthropicIterationUsageResult, AnthropicIterationUsageSnapshot, AnthropicOptions, AnthropicProjectedToolChoice, AnthropicPromptUsageSnapshot, AnthropicThinkingDisplay, AnthropicToolProjection, CLAUDE_FABLE_5_FALLBACK_MODEL, CLAUDE_FABLE_5_FALLBACK_MODEL_COST, applyAnthropicFallbackBoundary, applyAnthropicRefusal, applyClaudeRequestContract, buildAnthropicServerSideFallbacks, defaultsClaudeAdaptiveThinking, findActiveAnthropicToolTurnAssistantIndex, omitFoundryBearerCredentialHeaders, prepareClaudeSonnet5RequestContext, projectAnthropicTools, readAnthropicFallbackBoundary, readAnthropicPromptUsageSnapshot, readAnthropicUsageTokenCount, readLastAnthropicIterationUsage, reconcileAnthropicToolChoice, requiresClaudeAdaptiveThinking, requiresClaudeDefaultSampling, requiresClaudeMandatoryAdaptiveThinking, resolveClaudeFable5ModelIdentity, resolveClaudeModelIdentity, resolveClaudeMythos5ModelIdentity, resolveClaudeNativeThinkingLevelMap, resolveClaudeSonnet5ModelIdentity, resolveModelBoundThinkingReplayMode, resolveOriginalAnthropicToolName, streamAnthropic, streamSimpleAnthropic, supportsClaudeAdaptiveThinking, supportsClaudeNativeMaxEffort, supportsClaudeNativeXhighEffort, usesClaudeFable5MessagesContract, usesClaudeStreamingRefusalContract, usesFoundryBearerAuth };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
import {
|
|
3
|
-
import { _ as
|
|
4
|
-
|
|
5
|
-
export { ANTHROPIC_OMITTED_REASONING_TEXT, ANTHROPIC_SERVER_SIDE_FALLBACKS, ANTHROPIC_SERVER_SIDE_FALLBACK_BETA, CLAUDE_OPUS_FALLBACK_MODEL_COST, applyAnthropicFallbackBoundary, applyAnthropicRefusal, applyClaudeRequestContract, defaultsClaudeAdaptiveThinking, findActiveAnthropicToolTurnAssistantIndex, omitFoundryBearerCredentialHeaders, prepareClaudeNoPrefillRequestContext, projectAnthropicTools, readAnthropicCacheWriteUsage, readAnthropicFallbackBoundary, readAnthropicPromptUsageSnapshot, readAnthropicUsageTokenCount, readLastAnthropicIterationUsage, reconcileAnthropicToolChoice, requiresClaudeAdaptiveThinking, requiresClaudeDefaultSampling, requiresClaudeMandatoryAdaptiveThinking, resolveAnthropicFallbackServingModelCost, resolveClaudeFable5ModelIdentity, resolveClaudeModelIdentity, resolveClaudeMythos5ModelIdentity, resolveClaudeNativeThinkingLevelMap, resolveClaudeOpus5ModelIdentity, resolveClaudeSonnet5ModelIdentity, resolveModelBoundThinkingReplayMode, resolveOriginalAnthropicToolName, streamAnthropic, streamSimpleAnthropic, supportsClaudeAdaptiveThinking, supportsClaudeNativeMaxEffort, supportsClaudeNativeXhighEffort, usesClaudeFable5MessagesContract, usesClaudeStreamingRefusalContract, usesFoundryBearerAuth };
|
|
1
|
+
import { a as resolveClaudeFable5ModelIdentity, c as resolveClaudeNativeThinkingLevelMap, d as supportsClaudeNativeMaxEffort, f as supportsClaudeNativeXhighEffort, i as requiresClaudeMandatoryAdaptiveThinking, l as resolveClaudeSonnet5ModelIdentity, o as resolveClaudeModelIdentity, r as requiresClaudeDefaultSampling, s as resolveClaudeMythos5ModelIdentity, u as supportsClaudeAdaptiveThinking } from "../src-CZ503MYJ.mjs";
|
|
2
|
+
import { d as prepareClaudeSonnet5RequestContext, f as requiresClaudeAdaptiveThinking, h as usesClaudeStreamingRefusalContract, l as applyClaudeRequestContract, m as usesClaudeFable5MessagesContract, p as resolveModelBoundThinkingReplayMode, u as defaultsClaudeAdaptiveThinking } from "../transform-messages-BhGF_fF4.mjs";
|
|
3
|
+
import { _ as readAnthropicFallbackBoundary, a as readAnthropicUsageTokenCount, b as usesFoundryBearerAuth, c as reconcileAnthropicToolChoice, d as findActiveAnthropicToolTurnAssistantIndex, f as ANTHROPIC_SERVER_SIDE_FALLBACK_BETA, g as buildAnthropicServerSideFallbacks, h as applyAnthropicFallbackBoundary, i as readAnthropicPromptUsageSnapshot, l as resolveOriginalAnthropicToolName, m as CLAUDE_FABLE_5_FALLBACK_MODEL_COST, n as streamAnthropic, o as readLastAnthropicIterationUsage, p as CLAUDE_FABLE_5_FALLBACK_MODEL, r as streamSimpleAnthropic, s as projectAnthropicTools, u as ANTHROPIC_OMITTED_REASONING_TEXT, v as applyAnthropicRefusal, y as omitFoundryBearerCredentialHeaders } from "../anthropic-BML72tLz.mjs";
|
|
4
|
+
export { ANTHROPIC_OMITTED_REASONING_TEXT, ANTHROPIC_SERVER_SIDE_FALLBACK_BETA, CLAUDE_FABLE_5_FALLBACK_MODEL, CLAUDE_FABLE_5_FALLBACK_MODEL_COST, applyAnthropicFallbackBoundary, applyAnthropicRefusal, applyClaudeRequestContract, buildAnthropicServerSideFallbacks, defaultsClaudeAdaptiveThinking, findActiveAnthropicToolTurnAssistantIndex, omitFoundryBearerCredentialHeaders, prepareClaudeSonnet5RequestContext, projectAnthropicTools, readAnthropicFallbackBoundary, readAnthropicPromptUsageSnapshot, readAnthropicUsageTokenCount, readLastAnthropicIterationUsage, reconcileAnthropicToolChoice, requiresClaudeAdaptiveThinking, requiresClaudeDefaultSampling, requiresClaudeMandatoryAdaptiveThinking, resolveClaudeFable5ModelIdentity, resolveClaudeModelIdentity, resolveClaudeMythos5ModelIdentity, resolveClaudeNativeThinkingLevelMap, resolveClaudeSonnet5ModelIdentity, resolveModelBoundThinkingReplayMode, resolveOriginalAnthropicToolName, streamAnthropic, streamSimpleAnthropic, supportsClaudeAdaptiveThinking, supportsClaudeNativeMaxEffort, supportsClaudeNativeXhighEffort, usesClaudeFable5MessagesContract, usesClaudeStreamingRefusalContract, usesFoundryBearerAuth };
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import { E as Model, F as SimpleStreamOptions, I as StopReason,
|
|
2
|
-
import { _ as resolveOpenAIReasoningEffortForModel, a as OpenAICompletionsOptions, b as supportsOpenAITemperature, c as projectOpenAITools, d as OpenAIApiReasoningEffort, f as OpenAIReasoningEffort, g as normalizeOpenAIReasoningEffort, h as isOpenAIGpt56Model, l as reconcileOpenAICompletionsToolChoice, m as isOpenAIGpt55Model, o as OpenAICompletionsToolChoice, p as isOpenAIGpt54MiniModel, s as OpenAIToolProjection, u as reconcileOpenAIResponsesToolChoice, v as resolveOpenAISupportedReasoningEfforts, y as supportsOpenAIReasoningEffort } from "../provider-options-D8bB3z9b.mjs";
|
|
3
|
-
import { t as ResolvedOpenAICompletionsCompat } from "../openai-completions-compat-DBWjXoMZ.mjs";
|
|
4
|
-
import { n as clampOpenAIPromptCacheKey, t as OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH } from "../openai-prompt-cache-2uo_1OR1.mjs";
|
|
1
|
+
import { E as Model, F as SimpleStreamOptions, I as StopReason, O as OpenAICompletionsCompat, R as StreamFunction, u as Context, z as StreamOptions } from "../types-DRgdPqaZ.mjs";
|
|
5
2
|
import OpenAI from "openai";
|
|
6
3
|
import { TSchema } from "typebox";
|
|
7
|
-
import { ResponseCreateParamsStreaming } from "openai/resources/responses/responses.js";
|
|
8
4
|
import { ChatCompletionMessageParam } from "openai/resources/chat/completions.js";
|
|
5
|
+
import { ResponseCreateParamsStreaming } from "openai/resources/responses/responses.js";
|
|
9
6
|
|
|
10
7
|
//#region packages/ai/src/providers/agent-tools-parameter-schema.d.ts
|
|
11
8
|
/**
|
|
@@ -41,13 +38,7 @@ declare function normalizeToolParameterSchema(schema: unknown, options?: ToolPar
|
|
|
41
38
|
//#region packages/ai/src/providers/azure-deployment-map.d.ts
|
|
42
39
|
/** Parses AZURE_OPENAI_DEPLOYMENT_MAP-style model=deployment entries. */
|
|
43
40
|
declare function parseAzureDeploymentNameMap(value: string | undefined): Map<string, string>;
|
|
44
|
-
/**
|
|
45
|
-
* Resolves the Azure deployment name for a model id, falling back to the model id.
|
|
46
|
-
*
|
|
47
|
-
* An exact-case match always wins, so configs that intentionally distinguish keys by
|
|
48
|
-
* case keep their exact mappings; a case-insensitive match is only used as a fallback
|
|
49
|
-
* (e.g. `GPT-4o` against a `gpt-4o=...` map) to avoid 404s from casing differences.
|
|
50
|
-
*/
|
|
41
|
+
/** Resolves the Azure deployment name for a model id, falling back to the model id. */
|
|
51
42
|
declare function resolveAzureDeploymentNameFromMap(params: {
|
|
52
43
|
modelId: string;
|
|
53
44
|
deploymentMap?: string;
|
|
@@ -61,24 +52,90 @@ declare function isOpenAICompatibleAzureResponsesBaseUrl(baseUrl: string): boole
|
|
|
61
52
|
declare const GEMINI_UNSUPPORTED_SCHEMA_KEYWORDS: Set<string>;
|
|
62
53
|
declare function cleanSchemaForGemini(schema: unknown): TSchema;
|
|
63
54
|
//#endregion
|
|
64
|
-
//#region packages/ai/src/providers/
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
55
|
+
//#region packages/ai/src/providers/openai-tool-projection.d.ts
|
|
56
|
+
type OpenAIToolDescriptor = {
|
|
57
|
+
readonly name?: unknown;
|
|
58
|
+
readonly description?: unknown;
|
|
59
|
+
readonly parameters: unknown;
|
|
60
|
+
};
|
|
61
|
+
type OpenAIProjectedTool = {
|
|
62
|
+
readonly toolIndex: number;
|
|
63
|
+
readonly name: string;
|
|
64
|
+
readonly description?: string;
|
|
65
|
+
readonly parameters: Record<string, unknown>;
|
|
66
|
+
};
|
|
67
|
+
type OpenAIToolProjectionDiagnostic = {
|
|
68
|
+
readonly toolIndex: number;
|
|
69
|
+
readonly toolName?: string;
|
|
70
|
+
readonly violations: readonly string[];
|
|
71
|
+
};
|
|
72
|
+
type OpenAIToolProjection = {
|
|
73
|
+
readonly inputToolCount: number;
|
|
74
|
+
readonly tools: readonly OpenAIProjectedTool[];
|
|
75
|
+
readonly diagnostics: readonly OpenAIToolProjectionDiagnostic[];
|
|
76
|
+
};
|
|
77
|
+
type OpenAIResponsesToolChoice = ResponseCreateParamsStreaming["tool_choice"];
|
|
78
|
+
type OpenAICompletionsSdkToolChoice = OpenAI.Chat.Completions.ChatCompletionCreateParamsStreaming["tool_choice"];
|
|
79
|
+
type OpenAICompletionsToolChoice = Exclude<OpenAICompletionsSdkToolChoice, {
|
|
80
|
+
type: "custom";
|
|
81
|
+
}>;
|
|
82
|
+
/** Snapshots direct/custom tool descriptors before OpenAI payload construction. */
|
|
83
|
+
declare function projectOpenAITools(tools: readonly OpenAIToolDescriptor[]): OpenAIToolProjection;
|
|
84
|
+
/** Keeps Responses tool choices aligned with surviving function schemas. */
|
|
85
|
+
declare function reconcileOpenAIResponsesToolChoice(choice: OpenAIResponsesToolChoice, projection: OpenAIToolProjection): OpenAIResponsesToolChoice | undefined;
|
|
86
|
+
/** Keeps Chat Completions tool choices aligned with surviving function schemas. */
|
|
87
|
+
declare function reconcileOpenAICompletionsToolChoice(choice: OpenAICompletionsSdkToolChoice, projection: OpenAIToolProjection): OpenAICompletionsSdkToolChoice | undefined;
|
|
71
88
|
//#endregion
|
|
72
|
-
//#region packages/ai/src/openai-completions
|
|
73
|
-
|
|
89
|
+
//#region packages/ai/src/providers/openai-completions.d.ts
|
|
90
|
+
interface OpenAICompletionsOptions extends StreamOptions {
|
|
91
|
+
toolChoice?: OpenAICompletionsToolChoice;
|
|
92
|
+
reasoningEffort?: "minimal" | "low" | "medium" | "high" | "xhigh";
|
|
93
|
+
}
|
|
94
|
+
type ResolvedOpenAICompletionsCompat = Omit<Required<OpenAICompletionsCompat>, "cacheControlFormat"> & {
|
|
95
|
+
cacheControlFormat?: OpenAICompletionsCompat["cacheControlFormat"];
|
|
96
|
+
};
|
|
97
|
+
declare const streamOpenAICompletions: StreamFunction<"openai-completions", OpenAICompletionsOptions>;
|
|
98
|
+
declare const streamSimpleOpenAICompletions: StreamFunction<"openai-completions", SimpleStreamOptions>;
|
|
74
99
|
declare function convertMessages(model: Model<"openai-completions">, context: Context, compat: ResolvedOpenAICompletionsCompat, options?: {
|
|
75
100
|
cacheOptOutIndexes?: Set<number>;
|
|
76
101
|
preserveSystemPromptCacheBoundary?: boolean;
|
|
77
102
|
}): ChatCompletionMessageParam[];
|
|
78
103
|
//#endregion
|
|
79
|
-
//#region packages/ai/src/providers/openai-
|
|
80
|
-
|
|
81
|
-
declare const
|
|
104
|
+
//#region packages/ai/src/providers/openai-prompt-cache.d.ts
|
|
105
|
+
/** Maximum prompt cache key length accepted by OpenAI-compatible request metadata. */
|
|
106
|
+
declare const OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH = 64;
|
|
107
|
+
/** Truncates a prompt cache key by Unicode code point count. */
|
|
108
|
+
declare function clampOpenAIPromptCacheKey(key: string | undefined): string | undefined;
|
|
109
|
+
//#endregion
|
|
110
|
+
//#region packages/ai/src/providers/openai-reasoning-effort.d.ts
|
|
111
|
+
type OpenAIReasoningEffort = "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max";
|
|
112
|
+
type OpenAIApiReasoningEffort = OpenAIReasoningEffort | (string & {});
|
|
113
|
+
type OpenAIReasoningModel = {
|
|
114
|
+
provider?: unknown;
|
|
115
|
+
id?: unknown;
|
|
116
|
+
name?: unknown;
|
|
117
|
+
api?: unknown;
|
|
118
|
+
baseUrl?: unknown;
|
|
119
|
+
compat?: unknown;
|
|
120
|
+
};
|
|
121
|
+
/** Return whether a model is the GPT-5.4 mini family. */
|
|
122
|
+
declare function isOpenAIGpt54MiniModel(model: OpenAIReasoningModel): boolean;
|
|
123
|
+
/** Return whether a model is the GPT-5.5 family. */
|
|
124
|
+
declare function isOpenAIGpt55Model(model: OpenAIReasoningModel): boolean;
|
|
125
|
+
/** Return whether a model is the GPT-5.6 family. */
|
|
126
|
+
declare function isOpenAIGpt56Model(model: OpenAIReasoningModel): boolean;
|
|
127
|
+
/** Normalize user-facing reasoning effort names to API effort names. */
|
|
128
|
+
declare function normalizeOpenAIReasoningEffort(effort: string): string;
|
|
129
|
+
/** Resolve the reasoning efforts accepted by a specific OpenAI-compatible model. */
|
|
130
|
+
declare function resolveOpenAISupportedReasoningEfforts(model: OpenAIReasoningModel): readonly OpenAIApiReasoningEffort[];
|
|
131
|
+
/** Return whether a model accepts a requested reasoning effort. */
|
|
132
|
+
declare function supportsOpenAIReasoningEffort(model: OpenAIReasoningModel, effort: string): boolean;
|
|
133
|
+
/** Resolve a requested reasoning effort to the closest value supported by the model. */
|
|
134
|
+
declare function resolveOpenAIReasoningEffortForModel(params: {
|
|
135
|
+
model: OpenAIReasoningModel;
|
|
136
|
+
effort: string;
|
|
137
|
+
fallbackMap?: Record<string, string>;
|
|
138
|
+
}): OpenAIApiReasoningEffort | undefined;
|
|
82
139
|
//#endregion
|
|
83
140
|
//#region packages/ai/src/providers/openai-responses.d.ts
|
|
84
141
|
interface OpenAIResponsesOptions extends StreamOptions {
|
|
@@ -130,71 +187,6 @@ declare function resolveResponsesMessageSnapshotCollapse(params: {
|
|
|
130
187
|
nextPhase: string | undefined;
|
|
131
188
|
}): ResponsesMessageSnapshotCollapse;
|
|
132
189
|
//#endregion
|
|
133
|
-
//#region packages/ai/src/providers/openai-responses-terminal-usage.d.ts
|
|
134
|
-
/** Terminal usage payload, modeled structurally so untyped callers can pass raw records. */
|
|
135
|
-
type ResponsesTerminalUsagePayload = {
|
|
136
|
-
input_tokens?: number | null;
|
|
137
|
-
output_tokens?: number | null;
|
|
138
|
-
total_tokens?: number | null;
|
|
139
|
-
input_tokens_details?: {
|
|
140
|
-
cached_tokens?: number | null;
|
|
141
|
-
cache_write_tokens?: number | null;
|
|
142
|
-
} | null;
|
|
143
|
-
output_tokens_details?: {
|
|
144
|
-
reasoning_tokens?: number | null;
|
|
145
|
-
} | null;
|
|
146
|
-
};
|
|
147
|
-
/**
|
|
148
|
-
* Split a terminal usage payload into the priced buckets.
|
|
149
|
-
*
|
|
150
|
-
* OpenAI includes cache reads and writes in `input_tokens`, so both are subtracted out of the
|
|
151
|
-
* billable input bucket. `total_tokens` comes from the payload, but never below the sum of the
|
|
152
|
-
* split buckets: proxies routinely omit it (reporting 0 would understate the turn), and a payload
|
|
153
|
-
* whose `cached_tokens` exceeds `input_tokens` clamps the input bucket, leaving the reported total
|
|
154
|
-
* short of what the buckets actually price.
|
|
155
|
-
*/
|
|
156
|
-
declare function mapResponsesTerminalUsage(usage: ResponsesTerminalUsagePayload | undefined | null): Pick<Usage, "input" | "output" | "cacheRead" | "cacheWrite" | "totalTokens"> | undefined;
|
|
157
|
-
/** Reasoning tokens are reported by the agent path only; the package path does not track them. */
|
|
158
|
-
declare function readResponsesReasoningTokens(usage: ResponsesTerminalUsagePayload | undefined | null): number | undefined;
|
|
159
|
-
/**
|
|
160
|
-
* Resolve the terminal stop reason, including the two overrides every Responses path shares: a
|
|
161
|
-
* content-filtered turn is a provider error rather than a truncated answer, and a turn that
|
|
162
|
-
* produced tool calls reports `toolUse` instead of a plain stop.
|
|
163
|
-
*/
|
|
164
|
-
declare function resolveResponsesTerminalStopReason(params: {
|
|
165
|
-
status: OpenAI.Responses.ResponseStatus | undefined;
|
|
166
|
-
terminalEventType?: "response.completed" | "response.incomplete";
|
|
167
|
-
incompleteReason?: string;
|
|
168
|
-
hasToolCall: boolean;
|
|
169
|
-
}): {
|
|
170
|
-
stopReason: StopReason;
|
|
171
|
-
errorMessage?: string;
|
|
172
|
-
};
|
|
173
|
-
//#endregion
|
|
174
|
-
//#region packages/ai/src/providers/openai-responses-tool-call-tracker.d.ts
|
|
175
|
-
type ResponsesToolCallIdentity = {
|
|
176
|
-
itemId?: string;
|
|
177
|
-
callId?: string;
|
|
178
|
-
};
|
|
179
|
-
type ResponsesToolCallState = ResponsesToolCallIdentity & {
|
|
180
|
-
argumentStreamReliable: boolean;
|
|
181
|
-
};
|
|
182
|
-
type ResponsesToolCallEvent = {
|
|
183
|
-
output_index?: unknown;
|
|
184
|
-
item_id?: unknown;
|
|
185
|
-
};
|
|
186
|
-
declare function readResponsesToolCallItemIdentity(item: {
|
|
187
|
-
id?: unknown;
|
|
188
|
-
call_id?: unknown;
|
|
189
|
-
}): ResponsesToolCallIdentity;
|
|
190
|
-
declare function createResponsesToolCallTracker<TState extends ResponsesToolCallState>(): {
|
|
191
|
-
register(event: ResponsesToolCallEvent, state: TState): void;
|
|
192
|
-
resolve(event: ResponsesToolCallEvent, identity?: ResponsesToolCallIdentity): TState | undefined;
|
|
193
|
-
forget(toolCall: TState): void;
|
|
194
|
-
markArgumentsUnreliable(): void;
|
|
195
|
-
hasActive(): boolean;
|
|
196
|
-
};
|
|
197
|
-
//#endregion
|
|
198
190
|
//#region packages/ai/src/providers/openai-stop-reason.d.ts
|
|
199
191
|
type OpenAIStopReasonResult = {
|
|
200
192
|
stopReason: StopReason;
|
|
@@ -204,14 +196,6 @@ declare function mapOpenAIStopReason(reason: string | null, options?: {
|
|
|
204
196
|
allowSingularToolCall?: boolean;
|
|
205
197
|
}): OpenAIStopReasonResult;
|
|
206
198
|
//#endregion
|
|
207
|
-
//#region packages/ai/src/providers/openai-tool-schema-compat.d.ts
|
|
208
|
-
/** Repairs recoverable OpenAI tool-schema shapes before canonical normalization. */
|
|
209
|
-
declare function normalizeOpenAIStrictCompatSchema(schema: unknown): TSchema;
|
|
210
|
-
/** Finds schema paths that violate OpenAI strict tool-schema requirements. */
|
|
211
|
-
declare function findOpenAIStrictSchemaViolations(schema: unknown, path: string, options?: {
|
|
212
|
-
requireObjectRoot?: boolean;
|
|
213
|
-
}): string[];
|
|
214
|
-
//#endregion
|
|
215
199
|
//#region packages/ai/src/providers/openai-tool-schema.d.ts
|
|
216
200
|
/**
|
|
217
201
|
* OpenAI strict-tool-schema normalization and diagnostics.
|
|
@@ -257,4 +241,4 @@ type RuntimeToolInputSchemaProjection = {
|
|
|
257
241
|
/** Projects one runtime tool input schema to JSON and reports runtime incompatibilities. */
|
|
258
242
|
declare function projectRuntimeToolInputSchema(schema: unknown, path?: string): RuntimeToolInputSchemaProjection;
|
|
259
243
|
//#endregion
|
|
260
|
-
export { AZURE_RESPONSES_TEXT_CONTENT_PART_TYPE, AZURE_RESPONSES_TEXT_DELTA_EVENT_TYPE, AzureResponsesTextContentPart, AzureResponsesTextDeltaEvent, GEMINI_UNSUPPORTED_SCHEMA_KEYWORDS,
|
|
244
|
+
export { AZURE_RESPONSES_TEXT_CONTENT_PART_TYPE, AZURE_RESPONSES_TEXT_DELTA_EVENT_TYPE, AzureResponsesTextContentPart, AzureResponsesTextDeltaEvent, GEMINI_UNSUPPORTED_SCHEMA_KEYWORDS, OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH, OPENAI_RESPONSES_OUTPUT_TEXT_CONTENT_PART_TYPE, OPENAI_RESPONSES_OUTPUT_TEXT_DELTA_EVENT_TYPE, OpenAIApiReasoningEffort, OpenAICompletionsOptions, OpenAICompletionsToolChoice, OpenAIReasoningEffort, OpenAIResponsesOptions, OpenAIStopReasonResult, OpenAIToolProjection, ResponsesMessageSnapshotCollapse, ResponsesTextContentPartType, ResponsesTextDeltaEventType, RuntimeToolInputSchemaJson, RuntimeToolInputSchemaProjection, ToolParameterSchemaOptions, ToolSchemaModelCompat, clampOpenAIPromptCacheKey, cleanSchemaForGemini, clearOpenAIToolSchemaCacheForTest, convertMessages, extractToolSchemaModelCompat, findOpenAIStrictToolProjectionDiagnostics, isAzureResponsesTextDeltaEvent, isAzureResponsesTextDeltaEventType, isOpenAICompatibleAzureResponsesBaseUrl, isOpenAIGpt54MiniModel, isOpenAIGpt55Model, isOpenAIGpt56Model, isResponsesTextContentPartType, isResponsesTextDeltaEventType, isStrictOpenAIJsonSchemaCompatible, isTraditionalAzureOpenAIHost, mapOpenAIStopReason, normalizeOpenAIReasoningEffort, normalizeOpenAIStrictToolParameters, normalizeStrictOpenAIJsonSchema, normalizeToolParameterSchema, parseAzureDeploymentNameMap, projectOpenAITools, projectRuntimeToolInputSchema, reconcileOpenAICompletionsToolChoice, reconcileOpenAIResponsesToolChoice, resolveAzureDeploymentNameFromMap, resolveOpenAIProjectedToolsStrictToolFlag, resolveOpenAIReasoningEffortForModel, resolveOpenAISupportedReasoningEfforts, resolveResponsesMessageSnapshotCollapse, resolveUnsupportedToolSchemaKeywords, shouldOmitEmptyArrayItems, streamOpenAICompletions, streamOpenAIResponses, streamSimpleOpenAICompletions, streamSimpleOpenAIResponses, stripUnsupportedSchemaKeywords, supportsOpenAIReasoningEffort };
|
package/dist/internal/openai.mjs
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { n as clampOpenAIPromptCacheKey, t as OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH } from "../openai-prompt-cache-mZTCdRPo.mjs";
|
|
2
|
-
import { n as reconcileOpenAICompletionsToolChoice, r as reconcileOpenAIResponsesToolChoice, t as projectOpenAITools } from "../openai-tool-projection-OhX64DoP.mjs";
|
|
3
1
|
import { t as projectRuntimeToolInputSchema } from "../tool-schema-json-projection-BwNu3nDi.mjs";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { i as
|
|
7
|
-
import {
|
|
8
|
-
import { n as streamOpenAIResponses, r as streamSimpleOpenAIResponses } from "../openai-responses-
|
|
9
|
-
export { AZURE_RESPONSES_TEXT_CONTENT_PART_TYPE, AZURE_RESPONSES_TEXT_DELTA_EVENT_TYPE, GEMINI_UNSUPPORTED_SCHEMA_KEYWORDS,
|
|
2
|
+
import { A as extractToolSchemaModelCompat, C as isOpenAIGpt54MiniModel, D as resolveOpenAIReasoningEffortForModel, E as normalizeOpenAIReasoningEffort, F as GEMINI_UNSUPPORTED_SCHEMA_KEYWORDS, I as cleanSchemaForGemini, M as resolveUnsupportedToolSchemaKeywords, N as shouldOmitEmptyArrayItems, O as resolveOpenAISupportedReasoningEfforts, P as stripUnsupportedSchemaKeywords, S as resolveResponsesMessageSnapshotCollapse, T as isOpenAIGpt56Model, _ as OPENAI_RESPONSES_OUTPUT_TEXT_DELTA_EVENT_TYPE, b as isResponsesTextContentPartType, c as clearOpenAIToolSchemaCacheForTest, d as normalizeOpenAIStrictToolParameters, f as normalizeStrictOpenAIJsonSchema, g as OPENAI_RESPONSES_OUTPUT_TEXT_CONTENT_PART_TYPE, h as AZURE_RESPONSES_TEXT_DELTA_EVENT_TYPE, j as normalizeToolParameterSchema, k as supportsOpenAIReasoningEffort, l as findOpenAIStrictToolProjectionDiagnostics, m as AZURE_RESPONSES_TEXT_CONTENT_PART_TYPE, p as resolveOpenAIProjectedToolsStrictToolFlag, u as isStrictOpenAIJsonSchemaCompatible, v as isAzureResponsesTextDeltaEvent, w as isOpenAIGpt55Model, x as isResponsesTextDeltaEventType, y as isAzureResponsesTextDeltaEventType } from "../openai-responses-shared-L3PWZvkm.mjs";
|
|
3
|
+
import { i as resolveAzureDeploymentNameFromMap, n as isTraditionalAzureOpenAIHost, r as parseAzureDeploymentNameMap, t as isOpenAICompatibleAzureResponsesBaseUrl } from "../azure-openai-responses-client-compat-a_O_GVQV.mjs";
|
|
4
|
+
import { a as clampOpenAIPromptCacheKey, i as OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH, n as reconcileOpenAICompletionsToolChoice, r as reconcileOpenAIResponsesToolChoice, t as projectOpenAITools } from "../openai-tool-projection-BPlyXt8H.mjs";
|
|
5
|
+
import { a as mapOpenAIStopReason, i as streamSimpleOpenAICompletions, r as streamOpenAICompletions, t as convertMessages } from "../openai-completions-9qYFVS7H.mjs";
|
|
6
|
+
import { n as streamOpenAIResponses, r as streamSimpleOpenAIResponses } from "../openai-responses-D6l9URyV.mjs";
|
|
7
|
+
export { AZURE_RESPONSES_TEXT_CONTENT_PART_TYPE, AZURE_RESPONSES_TEXT_DELTA_EVENT_TYPE, GEMINI_UNSUPPORTED_SCHEMA_KEYWORDS, OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH, OPENAI_RESPONSES_OUTPUT_TEXT_CONTENT_PART_TYPE, OPENAI_RESPONSES_OUTPUT_TEXT_DELTA_EVENT_TYPE, clampOpenAIPromptCacheKey, cleanSchemaForGemini, clearOpenAIToolSchemaCacheForTest, convertMessages, extractToolSchemaModelCompat, findOpenAIStrictToolProjectionDiagnostics, isAzureResponsesTextDeltaEvent, isAzureResponsesTextDeltaEventType, isOpenAICompatibleAzureResponsesBaseUrl, isOpenAIGpt54MiniModel, isOpenAIGpt55Model, isOpenAIGpt56Model, isResponsesTextContentPartType, isResponsesTextDeltaEventType, isStrictOpenAIJsonSchemaCompatible, isTraditionalAzureOpenAIHost, mapOpenAIStopReason, normalizeOpenAIReasoningEffort, normalizeOpenAIStrictToolParameters, normalizeStrictOpenAIJsonSchema, normalizeToolParameterSchema, parseAzureDeploymentNameMap, projectOpenAITools, projectRuntimeToolInputSchema, reconcileOpenAICompletionsToolChoice, reconcileOpenAIResponsesToolChoice, resolveAzureDeploymentNameFromMap, resolveOpenAIProjectedToolsStrictToolFlag, resolveOpenAIReasoningEffortForModel, resolveOpenAISupportedReasoningEfforts, resolveResponsesMessageSnapshotCollapse, resolveUnsupportedToolSchemaKeywords, shouldOmitEmptyArrayItems, streamOpenAICompletions, streamOpenAIResponses, streamSimpleOpenAICompletions, streamSimpleOpenAIResponses, stripUnsupportedSchemaKeywords, supportsOpenAIReasoningEffort };
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { D as ModelThinkingLevel, E as Model, F as SimpleStreamOptions, P as ProviderStreamOptions, X as Usage, i as AssistantMessage, n as Api, o as AssistantMessageEventStreamContract, u as Context, z as StreamOptions } from "../types-
|
|
2
|
-
import { a as RegisteredApiProvider, t as ApiProvider } from "../api-registry-
|
|
1
|
+
import { D as ModelThinkingLevel, E as Model, F as SimpleStreamOptions, P as ProviderStreamOptions, X as Usage, i as AssistantMessage, n as Api, o as AssistantMessageEventStreamContract, u as Context, z as StreamOptions } from "../types-DRgdPqaZ.mjs";
|
|
2
|
+
import { a as RegisteredApiProvider, t as ApiProvider } from "../api-registry-BXYnCOIR.mjs";
|
|
3
3
|
import { t as sanitizeSurrogates } from "../sanitize-unicode-BZiVbGwK.mjs";
|
|
4
|
-
import { a as createFirstStreamEventTimeoutError, c as withFirstStreamEventTimeout, i as createFirstStreamEventAbortController, n as FirstStreamEventInternalOptions, o as getFirstStreamEventTimeoutHandler, r as FirstStreamEventTimeoutContext, s as getFirstStreamEventTimeoutMs, t as FirstStreamEventAbortController } from "../stream-first-event-timeout-DvDeSucC.mjs";
|
|
5
4
|
|
|
6
5
|
//#region packages/ai/src/internal/default-runtime.d.ts
|
|
7
6
|
declare const defaultApiRegistry: {
|
|
@@ -24,8 +23,7 @@ declare const defaultLlmRuntime: {
|
|
|
24
23
|
streamSimple: <TApi extends Api>(model: Model<TApi>, context: Context, options?: SimpleStreamOptions) => AssistantMessageEventStreamContract;
|
|
25
24
|
completeSimple: <TApi extends Api>(model: Model<TApi>, context: Context, options?: SimpleStreamOptions) => Promise<AssistantMessage>;
|
|
26
25
|
};
|
|
27
|
-
declare const getApiProvider: (api: Api) => RegisteredApiProvider | undefined, getApiProviders: () => RegisteredApiProvider[];
|
|
28
|
-
declare function clearApiProviders(): void;
|
|
26
|
+
declare const registerApiProvider: <TApi extends Api, TOptions extends StreamOptions>(provider: ApiProvider<TApi, TOptions>, sourceId?: string) => void, getApiProvider: (api: Api) => RegisteredApiProvider | undefined, getApiProviders: () => RegisteredApiProvider[], unregisterApiProviders: (sourceId: string) => void, clearApiProviders: () => void;
|
|
29
27
|
declare const stream: <TApi extends Api>(model: Model<TApi>, context: Context, options?: ProviderStreamOptions) => AssistantMessageEventStreamContract, complete: <TApi extends Api>(model: Model<TApi>, context: Context, options?: ProviderStreamOptions) => Promise<AssistantMessage>, streamSimple: <TApi extends Api>(model: Model<TApi>, context: Context, options?: SimpleStreamOptions) => AssistantMessageEventStreamContract, completeSimple: <TApi extends Api>(model: Model<TApi>, context: Context, options?: SimpleStreamOptions) => Promise<AssistantMessage>;
|
|
30
28
|
//#endregion
|
|
31
29
|
//#region packages/ai/src/env-api-keys.d.ts
|
|
@@ -141,12 +139,10 @@ declare function isConfiguredContextSizeOverflowError(errorMessage: string): boo
|
|
|
141
139
|
* - llama.cpp: "exceeds the available context size"
|
|
142
140
|
* - LM Studio: "greater than the context length"
|
|
143
141
|
* - Kimi For Coding: "exceeded model token limit: X (requested: Y)"
|
|
144
|
-
* - z.ai: "tokens in request more than max tokens allowed" or "Prompt exceeds max length"
|
|
145
142
|
*
|
|
146
143
|
* **Unreliable detection:**
|
|
147
144
|
* - z.ai: Sometimes accepts overflow silently (detectable via usage.input > contextWindow),
|
|
148
|
-
* sometimes returns rate limit errors
|
|
149
|
-
* contextWindow param to detect silent overflow.
|
|
145
|
+
* sometimes returns rate limit errors. Pass contextWindow param to detect silent overflow.
|
|
150
146
|
* - Xiaomi MiMo: Truncates input to fit contextWindow then returns stopReason "length" with
|
|
151
147
|
* output=0. Pass contextWindow param to detect via the "filled context + zero output" signal.
|
|
152
148
|
* - Ollama: May truncate input silently for some setups, but may also return explicit
|
|
@@ -170,7 +166,7 @@ declare function isConfiguredContextSizeOverflowError(errorMessage: string): boo
|
|
|
170
166
|
*/
|
|
171
167
|
declare function isContextOverflow(message: AssistantMessage, contextWindow?: number): boolean;
|
|
172
168
|
//#endregion
|
|
173
|
-
//#region packages/
|
|
169
|
+
//#region packages/ai/src/utils/reasoning-tag-text-partitioner.d.ts
|
|
174
170
|
type ReasoningTagTextDelta = {
|
|
175
171
|
kind: "text";
|
|
176
172
|
text: string;
|
|
@@ -178,8 +174,6 @@ type ReasoningTagTextDelta = {
|
|
|
178
174
|
kind: "thinking";
|
|
179
175
|
text: string;
|
|
180
176
|
};
|
|
181
|
-
//#endregion
|
|
182
|
-
//#region packages/markdown-core/src/reasoning-tags.d.ts
|
|
183
177
|
interface ReasoningTagTextPartitioner {
|
|
184
178
|
markStrict(): void;
|
|
185
179
|
push(chunk: string): ReasoningTagTextDelta[];
|
|
@@ -188,9 +182,36 @@ interface ReasoningTagTextPartitioner {
|
|
|
188
182
|
hasPending(): boolean;
|
|
189
183
|
isInsideReasoning(): boolean;
|
|
190
184
|
}
|
|
191
|
-
/** Creates a block-incremental parser that emits only Markdown-stable text. */
|
|
192
185
|
declare function createReasoningTagTextPartitioner(): ReasoningTagTextPartitioner;
|
|
193
186
|
//#endregion
|
|
187
|
+
//#region packages/ai/src/utils/stream-first-event-timeout.d.ts
|
|
188
|
+
type StreamStage = "responses" | "completions";
|
|
189
|
+
type FirstStreamEventTimeoutContext = {
|
|
190
|
+
provider?: string;
|
|
191
|
+
api?: string;
|
|
192
|
+
model?: string;
|
|
193
|
+
timeoutMs: number;
|
|
194
|
+
stage?: StreamStage;
|
|
195
|
+
hint?: string;
|
|
196
|
+
abort?: (reason: Error) => void;
|
|
197
|
+
onTimeout?: (reason: Error) => void;
|
|
198
|
+
};
|
|
199
|
+
type FirstStreamEventInternalOptions = {
|
|
200
|
+
firstEventTimeoutMs?: number;
|
|
201
|
+
abortFirstEventStream?: (reason: Error) => void;
|
|
202
|
+
onFirstEventTimeout?: (reason: Error) => void;
|
|
203
|
+
};
|
|
204
|
+
type FirstStreamEventAbortController = {
|
|
205
|
+
signal: AbortSignal;
|
|
206
|
+
abort: (reason: Error) => void;
|
|
207
|
+
dispose: () => void;
|
|
208
|
+
};
|
|
209
|
+
declare function getFirstStreamEventTimeoutMs(options: unknown): number | undefined;
|
|
210
|
+
declare function getFirstStreamEventTimeoutHandler(options: unknown): ((reason: Error) => void) | undefined;
|
|
211
|
+
declare function createFirstStreamEventTimeoutError(context: FirstStreamEventTimeoutContext): Error;
|
|
212
|
+
declare function createFirstStreamEventAbortController(parentSignal?: AbortSignal): FirstStreamEventAbortController;
|
|
213
|
+
declare function withFirstStreamEventTimeout<T>(stream: AsyncIterable<T>, context: FirstStreamEventTimeoutContext): AsyncIterable<T>;
|
|
214
|
+
//#endregion
|
|
194
215
|
//#region packages/ai/src/utils/streaming-byte-guard.d.ts
|
|
195
216
|
/**
|
|
196
217
|
* Bounded SSE / NDJSON stream reader guard.
|
|
@@ -221,4 +242,4 @@ type SseByteGuard = {
|
|
|
221
242
|
};
|
|
222
243
|
declare function createSseByteGuard(reader: ReadableStreamDefaultReader<Uint8Array>, opts: ReadSseStreamWithLimitOptions): SseByteGuard;
|
|
223
244
|
//#endregion
|
|
224
|
-
export { FirstStreamEventAbortController, FirstStreamEventInternalOptions, FirstStreamEventTimeoutContext, OpenAICodexJwtPayload, ReadSseStreamWithLimitOptions,
|
|
245
|
+
export { FirstStreamEventAbortController, FirstStreamEventInternalOptions, FirstStreamEventTimeoutContext, OpenAICodexJwtPayload, ReadSseStreamWithLimitOptions, ReasoningTagTextDelta, ReasoningTagTextPartitioner, SessionResourceCleanup, SseByteGuard, SseStreamOverflow, applyProviderReportedUsageCost, calculateCost, clampThinkingLevel, cleanupSessionResources, clearApiProviders, complete, completeSimple, createDeferredEventBuffer, createFirstStreamEventAbortController, createFirstStreamEventTimeoutError, createReasoningTagTextPartitioner, createSseByteGuard, decodeOpenAICodexJwtPayload, defaultApiRegistry, defaultLlmRuntime, findEnvKeys, getApiProvider, getApiProviders, getEnvApiKey, getFirstStreamEventTimeoutHandler, getFirstStreamEventTimeoutMs, getSupportedThinkingLevels, headersToRecord, isConfiguredContextSizeOverflowError, isContextOverflow, modelsAreEqual, notifyLlmRequestActivity, onLlmRequestActivity, parseJsonWithRepair, parseStreamingJson, registerApiProvider, registerSessionResourceCleanup, repairJson, resolveOpenAICodexAccountId, sanitizeSurrogates, shortHash, stream, streamSimple, unregisterApiProviders, withFirstStreamEventTimeout };
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import { n as getEnvApiKey, t as findEnvKeys } from "../env-api-keys-
|
|
1
|
+
import { n as getEnvApiKey, t as findEnvKeys } from "../env-api-keys-CtMlqaQ4.mjs";
|
|
2
2
|
import { n as createApiRegistry, t as createLlmRuntime } from "../stream-CREqxHgU.mjs";
|
|
3
|
+
import { a as modelsAreEqual, i as getSupportedThinkingLevels, n as calculateCost, r as clampThinkingLevel, t as applyProviderReportedUsageCost } from "../model-utils-DgmOla96.mjs";
|
|
4
|
+
import { n as onLlmRequestActivity, r as createDeferredEventBuffer, t as notifyLlmRequestActivity } from "../llm-request-activity-CehVkZP-.mjs";
|
|
5
|
+
import { t as headersToRecord } from "../headers-B_e4-1J0.mjs";
|
|
6
|
+
import { n as parseStreamingJson, r as repairJson, t as parseJsonWithRepair } from "../json-parse-DzNSIQBq.mjs";
|
|
3
7
|
import { t as sanitizeSurrogates } from "../sanitize-unicode-DT5o51ur.mjs";
|
|
4
|
-
import {
|
|
5
|
-
import { t as
|
|
6
|
-
import { n as parseStreamingJson, r as repairJson, t as parseJsonWithRepair } from "../json-parse-BvXNt1-7.mjs";
|
|
7
|
-
import { n as onLlmRequestActivity, t as notifyLlmRequestActivity } from "../llm-request-activity-BjtkplhG.mjs";
|
|
8
|
-
import { t as createReasoningTagTextPartitioner } from "../reasoning-tag-text-partitioner-CGDyLWUR.mjs";
|
|
9
|
-
import { a as withFirstStreamEventTimeout, i as getFirstStreamEventTimeoutMs, n as createFirstStreamEventTimeoutError, r as getFirstStreamEventTimeoutHandler, t as createFirstStreamEventAbortController } from "../stream-first-event-timeout-BBys9hSb.mjs";
|
|
8
|
+
import { t as createReasoningTagTextPartitioner } from "../reasoning-tag-text-partitioner-axhAdUwg.mjs";
|
|
9
|
+
import { a as withFirstStreamEventTimeout, i as getFirstStreamEventTimeoutMs, n as createFirstStreamEventTimeoutError, r as getFirstStreamEventTimeoutHandler, t as createFirstStreamEventAbortController } from "../stream-first-event-timeout-RjWszj8c.mjs";
|
|
10
10
|
import { t as shortHash } from "../hash-CHgqbJmD.mjs";
|
|
11
|
-
import { t as headersToRecord } from "../headers-B_e4-1J0.mjs";
|
|
12
11
|
import { i as registerSessionResourceCleanup, n as resolveOpenAICodexAccountId, r as cleanupSessionResources, t as decodeOpenAICodexJwtPayload } from "../openai-chatgpt-jwt-DhAAzLkj.mjs";
|
|
13
12
|
import { t as createSseByteGuard } from "../streaming-byte-guard-BrbkbwUu.mjs";
|
|
14
13
|
//#region packages/ai/src/internal/default-runtime.ts
|
|
@@ -27,10 +26,7 @@ function resolveDefaultRuntime() {
|
|
|
27
26
|
const defaultRuntime = resolveDefaultRuntime();
|
|
28
27
|
const defaultApiRegistry = defaultRuntime.registry;
|
|
29
28
|
const defaultLlmRuntime = defaultRuntime.runtime;
|
|
30
|
-
const { getApiProvider, getApiProviders } = defaultApiRegistry;
|
|
31
|
-
function clearApiProviders() {
|
|
32
|
-
defaultApiRegistry.clearApiProviders();
|
|
33
|
-
}
|
|
29
|
+
const { registerApiProvider, getApiProvider, getApiProviders, unregisterApiProviders, clearApiProviders } = defaultApiRegistry;
|
|
34
30
|
const { stream, complete, streamSimple, completeSimple } = defaultLlmRuntime;
|
|
35
31
|
//#endregion
|
|
36
32
|
//#region packages/ai/src/utils/overflow.ts
|
|
@@ -63,9 +59,7 @@ function isConfiguredContextSizeOverflowError(errorMessage) {
|
|
|
63
59
|
* - Kimi For Coding: "Your request exceeded model token limit: X (requested: Y)"
|
|
64
60
|
* - Cerebras: "400/413 status code (no body)"
|
|
65
61
|
* - Mistral: "Prompt contains X tokens ... too large for model with Y maximum context length"
|
|
66
|
-
* - z.ai:
|
|
67
|
-
* "Prompt exceeds max length" (code 1261), or accept overflow silently; handled via the
|
|
68
|
-
* error patterns or usage.input > contextWindow
|
|
62
|
+
* - z.ai: Does NOT error, accepts overflow silently - handled via usage.input > contextWindow
|
|
69
63
|
* - Xiaomi MiMo: Truncates input to fill contextWindow exactly, then returns finish_reason "length"
|
|
70
64
|
* with output=0 (no room left to generate). Detected via stopReason "length" + zero output +
|
|
71
65
|
* input filling the context window.
|
|
@@ -76,20 +70,17 @@ const OVERFLOW_PATTERNS = [
|
|
|
76
70
|
/request_too_large/i,
|
|
77
71
|
/input is too long for requested model/i,
|
|
78
72
|
/exceeds the context window/i,
|
|
79
|
-
/exceeds (?:the )?(?:model'?s )?maximum context length
|
|
73
|
+
/exceeds (?:the )?(?:model'?s )?maximum context length of [\d,]+ tokens?/i,
|
|
80
74
|
/input token count.*exceeds the maximum/i,
|
|
81
75
|
/maximum prompt length is \d+/i,
|
|
82
76
|
/reduce the length of the messages/i,
|
|
83
77
|
/maximum context length is \d+ tokens/i,
|
|
84
|
-
/exceeds (?:the )?maximum allowed input length of [\d,]+ tokens?/i,
|
|
85
78
|
/input \(\d+ tokens\) is longer than the model'?s context length \(\d+ tokens\)/i,
|
|
86
79
|
/exceeds the limit of \d+/i,
|
|
87
80
|
/exceeds the available context size/i,
|
|
88
81
|
/greater than the context length/i,
|
|
89
82
|
/context window exceeds limit/i,
|
|
90
83
|
/exceeded model token limit/i,
|
|
91
|
-
/tokens? in request more than max tokens? allowed/i,
|
|
92
|
-
/prompt exceeds max(?:imum)? length/i,
|
|
93
84
|
/too large for model with \d+ maximum context length/i,
|
|
94
85
|
CONFIGURED_CONTEXT_SIZE_OVERFLOW_RE,
|
|
95
86
|
/model_context_window_exceeded/i,
|
|
@@ -116,7 +107,7 @@ const NON_OVERFLOW_PATTERNS = [
|
|
|
116
107
|
function resolveContextInputTokens(message) {
|
|
117
108
|
if (message.usage.contextUsage?.state === "available") return message.usage.contextUsage.promptTokens;
|
|
118
109
|
if (message.usage.contextUsage?.state === "unavailable") return;
|
|
119
|
-
return message.usage.input + message.usage.cacheRead
|
|
110
|
+
return message.usage.input + message.usage.cacheRead;
|
|
120
111
|
}
|
|
121
112
|
/**
|
|
122
113
|
* Check if an assistant message represents a context overflow error.
|
|
@@ -142,12 +133,10 @@ function resolveContextInputTokens(message) {
|
|
|
142
133
|
* - llama.cpp: "exceeds the available context size"
|
|
143
134
|
* - LM Studio: "greater than the context length"
|
|
144
135
|
* - Kimi For Coding: "exceeded model token limit: X (requested: Y)"
|
|
145
|
-
* - z.ai: "tokens in request more than max tokens allowed" or "Prompt exceeds max length"
|
|
146
136
|
*
|
|
147
137
|
* **Unreliable detection:**
|
|
148
138
|
* - z.ai: Sometimes accepts overflow silently (detectable via usage.input > contextWindow),
|
|
149
|
-
* sometimes returns rate limit errors
|
|
150
|
-
* contextWindow param to detect silent overflow.
|
|
139
|
+
* sometimes returns rate limit errors. Pass contextWindow param to detect silent overflow.
|
|
151
140
|
* - Xiaomi MiMo: Truncates input to fit contextWindow then returns stopReason "length" with
|
|
152
141
|
* output=0. Pass contextWindow param to detect via the "filled context + zero output" signal.
|
|
153
142
|
* - Ollama: May truncate input silently for some setups, but may also return explicit
|
|
@@ -171,8 +160,7 @@ function resolveContextInputTokens(message) {
|
|
|
171
160
|
*/
|
|
172
161
|
function isContextOverflow(message, contextWindow) {
|
|
173
162
|
if (message.stopReason === "error" && message.errorMessage) {
|
|
174
|
-
|
|
175
|
-
if (!NON_OVERFLOW_PATTERNS.some((p) => p.test(errorMessage)) && OVERFLOW_PATTERNS.some((p) => p.test(errorMessage))) return true;
|
|
163
|
+
if (!NON_OVERFLOW_PATTERNS.some((p) => p.test(message.errorMessage)) && OVERFLOW_PATTERNS.some((p) => p.test(message.errorMessage))) return true;
|
|
176
164
|
}
|
|
177
165
|
if (contextWindow && message.stopReason === "stop") {
|
|
178
166
|
const inputTokens = resolveContextInputTokens(message);
|
|
@@ -185,4 +173,4 @@ function isContextOverflow(message, contextWindow) {
|
|
|
185
173
|
return false;
|
|
186
174
|
}
|
|
187
175
|
//#endregion
|
|
188
|
-
export { applyProviderReportedUsageCost, calculateCost, clampThinkingLevel, cleanupSessionResources, clearApiProviders, complete, completeSimple, createDeferredEventBuffer, createFirstStreamEventAbortController, createFirstStreamEventTimeoutError, createReasoningTagTextPartitioner, createSseByteGuard, decodeOpenAICodexJwtPayload, defaultApiRegistry, defaultLlmRuntime, findEnvKeys, getApiProvider, getApiProviders, getEnvApiKey, getFirstStreamEventTimeoutHandler, getFirstStreamEventTimeoutMs, getSupportedThinkingLevels, headersToRecord, isConfiguredContextSizeOverflowError, isContextOverflow, modelsAreEqual, notifyLlmRequestActivity, onLlmRequestActivity, parseJsonWithRepair, parseStreamingJson, registerSessionResourceCleanup, repairJson, resolveOpenAICodexAccountId, sanitizeSurrogates, shortHash, stream, streamSimple, withFirstStreamEventTimeout };
|
|
176
|
+
export { applyProviderReportedUsageCost, calculateCost, clampThinkingLevel, cleanupSessionResources, clearApiProviders, complete, completeSimple, createDeferredEventBuffer, createFirstStreamEventAbortController, createFirstStreamEventTimeoutError, createReasoningTagTextPartitioner, createSseByteGuard, decodeOpenAICodexJwtPayload, defaultApiRegistry, defaultLlmRuntime, findEnvKeys, getApiProvider, getApiProviders, getEnvApiKey, getFirstStreamEventTimeoutHandler, getFirstStreamEventTimeoutMs, getSupportedThinkingLevels, headersToRecord, isConfiguredContextSizeOverflowError, isContextOverflow, modelsAreEqual, notifyLlmRequestActivity, onLlmRequestActivity, parseJsonWithRepair, parseStreamingJson, registerApiProvider, registerSessionResourceCleanup, repairJson, resolveOpenAICodexAccountId, sanitizeSurrogates, shortHash, stream, streamSimple, unregisterApiProviders, withFirstStreamEventTimeout };
|