@openclaw/ai 2026.7.2-beta.5 → 2026.7.2-beta.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{anthropic-CQVj3le6.mjs → anthropic-CH4UUnZr.mjs} +14 -463
- package/dist/anthropic-usage-DWU-x8MI.mjs +459 -0
- package/dist/{azure-openai-responses-DIYgsqFM.mjs → azure-openai-responses-CImcwB83.mjs} +4 -3
- package/dist/azure-openai-responses-client-compat-C7K7QfUE.mjs +62 -0
- package/dist/cache-retention-0x979a5V.mjs +12 -0
- package/dist/deferred-event-buffer-DAvyP7qA.mjs +19 -0
- package/dist/github-copilot-headers-NCJtz9i0.mjs +37 -0
- package/dist/{google-f-A8xrae.mjs → google-CtSg0iTS.mjs} +3 -3
- package/dist/{google-shared-J6qvYINH.mjs → google-shared-DNBz5rcD.mjs} +5 -3
- package/dist/{google-vertex-D3yMVXIY.mjs → google-vertex-31f1uS9L.mjs} +3 -3
- package/dist/host-Dog2WQiR.mjs +369 -0
- package/dist/index.mjs +1 -1
- package/dist/internal/anthropic.d.mts +3 -53
- package/dist/internal/anthropic.mjs +3 -2
- package/dist/internal/openai.d.mts +259 -2
- package/dist/internal/openai.mjs +8 -4
- package/dist/internal/runtime.mjs +6 -4
- package/dist/internal/shared.d.mts +1 -1
- package/dist/internal/shared.mjs +5 -1
- package/dist/{llm-request-activity-CehVkZP-.mjs → llm-request-activity-BjtkplhG.mjs} +1 -19
- package/dist/{mistral-CKV-TOQj.mjs → mistral-CWmpvWYh.mjs} +5 -3
- package/dist/{openai-chatgpt-responses-CedIj0hk.mjs → openai-chatgpt-responses-B84Ibtrd.mjs} +18 -13
- package/dist/openai-completions-DsOxhOD1.mjs +630 -0
- package/dist/openai-completions-compat-DBWjXoMZ.d.mts +43 -0
- package/dist/openai-reasoning-compat-YgeLncHw.mjs +396 -0
- package/dist/openai-responses-BT7A3sLu.mjs +138 -0
- package/dist/openai-responses-shared-pXl6Wd8S.mjs +392 -0
- package/dist/{openai-D3PD6PE-.mjs → openai-responses-stream-internal-Cw5txaGW.mjs} +1409 -1863
- package/dist/openai-tool-projection-OhX64DoP.mjs +215 -0
- package/dist/{provider-error-apVOZI6G.mjs → provider-error-CAEvRjry.mjs} +1 -1
- package/dist/provider-options-D8bB3z9b.d.mts +144 -0
- package/dist/providers.mjs +8 -8
- package/dist/{stream-first-event-timeout-C3OgBjIk.mjs → reasoning-tag-text-partitioner-CGDyLWUR.mjs} +1 -86
- package/dist/simple-options-9lhRrN73.mjs +50 -0
- package/dist/stream-first-event-timeout-BBys9hSb.mjs +86 -0
- package/dist/tls-certificate-errors-DXSpluKI.mjs +93 -0
- package/dist/tool-result-text-CTpIRbYd.mjs +225 -0
- package/dist/{github-copilot-headers-BCoBNmL7.mjs → tool-schema-json-projection-BwNu3nDi.mjs} +1 -48
- package/dist/transform-messages-C8mBqZxF.mjs +2 -0
- package/dist/{transport-stream-shared-BbMELSI4.mjs → transport-stream-shared-D81p90xq.mjs} +4 -4
- package/dist/transports.d.mts +13 -33
- package/dist/transports.mjs +75 -34
- package/package.json +4 -4
- package/dist/host-XYGZcgO8.mjs +0 -98
- package/dist/openai-BPor_3WI.d.mts +0 -358
- package/dist/openai-completions-CiSutyu0.mjs +0 -1223
- package/dist/shared-CdjNZd35.mjs +0 -634
|
@@ -1,3 +1,260 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { E as Model, F as SimpleStreamOptions, I as StopReason, R as StreamFunction, X as Usage, u as Context, z as StreamOptions } from "../types-bzp5k29J.mjs";
|
|
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";
|
|
2
4
|
import { n as clampOpenAIPromptCacheKey, t as OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH } from "../openai-prompt-cache-2uo_1OR1.mjs";
|
|
3
|
-
|
|
5
|
+
import OpenAI from "openai";
|
|
6
|
+
import { TSchema } from "typebox";
|
|
7
|
+
import { ResponseCreateParamsStreaming } from "openai/resources/responses/responses.js";
|
|
8
|
+
import { ChatCompletionMessageParam } from "openai/resources/chat/completions.js";
|
|
9
|
+
|
|
10
|
+
//#region packages/ai/src/providers/agent-tools-parameter-schema.d.ts
|
|
11
|
+
/**
|
|
12
|
+
* Narrow structural view of the host's model compat config. packages/ai must stay
|
|
13
|
+
* config-agnostic, so only tool-schema-relevant fields are modeled here; the host's
|
|
14
|
+
* ModelCompatConfig remains structurally assignable.
|
|
15
|
+
*/
|
|
16
|
+
type ToolSchemaModelCompat = {
|
|
17
|
+
toolSchemaProfile?: string;
|
|
18
|
+
unsupportedToolSchemaKeywords?: string[];
|
|
19
|
+
omitEmptyArrayItems?: boolean;
|
|
20
|
+
};
|
|
21
|
+
/** Extracts the compat record whether callers pass a model (`{ compat }`) or the compat itself. */
|
|
22
|
+
declare function extractToolSchemaModelCompat(modelOrCompat: {
|
|
23
|
+
compat?: unknown;
|
|
24
|
+
} | ToolSchemaModelCompat | undefined): ToolSchemaModelCompat | undefined;
|
|
25
|
+
/** JSON Schema keywords this model/provider rejects in tool schemas. */
|
|
26
|
+
declare function resolveUnsupportedToolSchemaKeywords(modelOrCompat: {
|
|
27
|
+
compat?: unknown;
|
|
28
|
+
} | ToolSchemaModelCompat | undefined): ReadonlySet<string>;
|
|
29
|
+
/** Whether empty `items: {}` on array schemas must be omitted for this model/provider. */
|
|
30
|
+
declare function shouldOmitEmptyArrayItems(modelOrCompat: {
|
|
31
|
+
compat?: unknown;
|
|
32
|
+
} | ToolSchemaModelCompat | undefined): boolean;
|
|
33
|
+
type ToolParameterSchemaOptions = {
|
|
34
|
+
modelProvider?: string;
|
|
35
|
+
modelId?: string;
|
|
36
|
+
modelCompat?: ToolSchemaModelCompat;
|
|
37
|
+
};
|
|
38
|
+
/** Return a provider-compatible JSON schema for a model-facing tool. */
|
|
39
|
+
declare function normalizeToolParameterSchema(schema: unknown, options?: ToolParameterSchemaOptions): TSchema;
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region packages/ai/src/providers/azure-deployment-map.d.ts
|
|
42
|
+
/** Parses AZURE_OPENAI_DEPLOYMENT_MAP-style model=deployment entries. */
|
|
43
|
+
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
|
+
*/
|
|
51
|
+
declare function resolveAzureDeploymentNameFromMap(params: {
|
|
52
|
+
modelId: string;
|
|
53
|
+
deploymentMap?: string;
|
|
54
|
+
}): string;
|
|
55
|
+
//#endregion
|
|
56
|
+
//#region packages/ai/src/providers/azure-openai-responses-client-compat.d.ts
|
|
57
|
+
declare function isTraditionalAzureOpenAIHost(hostname: string): boolean;
|
|
58
|
+
declare function isOpenAICompatibleAzureResponsesBaseUrl(baseUrl: string): boolean;
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region packages/ai/src/providers/clean-for-gemini.d.ts
|
|
61
|
+
declare const GEMINI_UNSUPPORTED_SCHEMA_KEYWORDS: Set<string>;
|
|
62
|
+
declare function cleanSchemaForGemini(schema: unknown): TSchema;
|
|
63
|
+
//#endregion
|
|
64
|
+
//#region packages/ai/src/providers/clean-for-llamacpp-gbnf.d.ts
|
|
65
|
+
/** llama.cpp rejects grammar repetitions whose expanded rule count reaches 2000. */
|
|
66
|
+
declare const LLAMACPP_GBNF_MAX_REPETITION_THRESHOLD = 2000;
|
|
67
|
+
/** Removes JSON Schema constraints that llama.cpp cannot compile into GBNF. */
|
|
68
|
+
declare function cleanSchemaForLlamacppGbnf(schema: unknown): unknown;
|
|
69
|
+
/** Reports schema paths that llama.cpp cannot compile into GBNF. */
|
|
70
|
+
declare function findLlamacppGbnfSchemaViolations(schema: unknown, path: string): string[];
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region packages/ai/src/openai-completions-messages.d.ts
|
|
73
|
+
/** Convert a normalized transcript to OpenAI Chat Completions messages. */
|
|
74
|
+
declare function convertMessages(model: Model<"openai-completions">, context: Context, compat: ResolvedOpenAICompletionsCompat, options?: {
|
|
75
|
+
cacheOptOutIndexes?: Set<number>;
|
|
76
|
+
preserveSystemPromptCacheBoundary?: boolean;
|
|
77
|
+
}): ChatCompletionMessageParam[];
|
|
78
|
+
//#endregion
|
|
79
|
+
//#region packages/ai/src/providers/openai-completions.d.ts
|
|
80
|
+
declare const streamOpenAICompletions: StreamFunction<"openai-completions", OpenAICompletionsOptions>;
|
|
81
|
+
declare const streamSimpleOpenAICompletions: StreamFunction<"openai-completions", SimpleStreamOptions>;
|
|
82
|
+
//#endregion
|
|
83
|
+
//#region packages/ai/src/providers/openai-responses.d.ts
|
|
84
|
+
interface OpenAIResponsesOptions extends StreamOptions {
|
|
85
|
+
reasoningEffort?: "minimal" | "low" | "medium" | "high" | "xhigh" | "max";
|
|
86
|
+
reasoningSummary?: "auto" | "detailed" | "concise" | null;
|
|
87
|
+
replayResponsesItemIds?: boolean;
|
|
88
|
+
serviceTier?: ResponseCreateParamsStreaming["service_tier"];
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Generate function for OpenAI Responses API
|
|
92
|
+
*/
|
|
93
|
+
declare const streamOpenAIResponses: StreamFunction<"openai-responses", OpenAIResponsesOptions>;
|
|
94
|
+
declare const streamSimpleOpenAIResponses: StreamFunction<"openai-responses", SimpleStreamOptions>;
|
|
95
|
+
//#endregion
|
|
96
|
+
//#region packages/ai/src/providers/openai-responses-stream-compat.d.ts
|
|
97
|
+
declare const OPENAI_RESPONSES_OUTPUT_TEXT_CONTENT_PART_TYPE = "output_text";
|
|
98
|
+
declare const AZURE_RESPONSES_TEXT_CONTENT_PART_TYPE = "text";
|
|
99
|
+
declare const OPENAI_RESPONSES_OUTPUT_TEXT_DELTA_EVENT_TYPE = "response.output_text.delta";
|
|
100
|
+
declare const AZURE_RESPONSES_TEXT_DELTA_EVENT_TYPE = "response.text.delta";
|
|
101
|
+
type ResponsesTextContentPartType = typeof OPENAI_RESPONSES_OUTPUT_TEXT_CONTENT_PART_TYPE | typeof AZURE_RESPONSES_TEXT_CONTENT_PART_TYPE;
|
|
102
|
+
type ResponsesTextDeltaEventType = typeof OPENAI_RESPONSES_OUTPUT_TEXT_DELTA_EVENT_TYPE | typeof AZURE_RESPONSES_TEXT_DELTA_EVENT_TYPE;
|
|
103
|
+
type AzureResponsesTextContentPart = {
|
|
104
|
+
type: typeof AZURE_RESPONSES_TEXT_CONTENT_PART_TYPE;
|
|
105
|
+
text: string;
|
|
106
|
+
};
|
|
107
|
+
type AzureResponsesTextDeltaEvent = {
|
|
108
|
+
type: typeof AZURE_RESPONSES_TEXT_DELTA_EVENT_TYPE;
|
|
109
|
+
delta: string;
|
|
110
|
+
};
|
|
111
|
+
declare function isResponsesTextContentPartType(type: unknown): type is ResponsesTextContentPartType;
|
|
112
|
+
declare function isResponsesTextDeltaEventType(type: unknown): type is ResponsesTextDeltaEventType;
|
|
113
|
+
declare function isAzureResponsesTextDeltaEventType(type: unknown): type is typeof AZURE_RESPONSES_TEXT_DELTA_EVENT_TYPE;
|
|
114
|
+
declare function isAzureResponsesTextDeltaEvent(event: {
|
|
115
|
+
type?: unknown;
|
|
116
|
+
delta?: unknown;
|
|
117
|
+
}): event is AzureResponsesTextDeltaEvent;
|
|
118
|
+
type ResponsesMessageSnapshotCollapse = {
|
|
119
|
+
kind: "extend";
|
|
120
|
+
text: string;
|
|
121
|
+
} | {
|
|
122
|
+
kind: "keep";
|
|
123
|
+
};
|
|
124
|
+
declare function resolveResponsesMessageSnapshotCollapse(params: {
|
|
125
|
+
prior: {
|
|
126
|
+
text: string;
|
|
127
|
+
phase: string | undefined;
|
|
128
|
+
} | null;
|
|
129
|
+
nextText: string;
|
|
130
|
+
nextPhase: string | undefined;
|
|
131
|
+
}): ResponsesMessageSnapshotCollapse;
|
|
132
|
+
//#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
|
+
//#region packages/ai/src/providers/openai-stop-reason.d.ts
|
|
199
|
+
type OpenAIStopReasonResult = {
|
|
200
|
+
stopReason: StopReason;
|
|
201
|
+
errorMessage?: string;
|
|
202
|
+
};
|
|
203
|
+
declare function mapOpenAIStopReason(reason: string | null, options?: {
|
|
204
|
+
allowSingularToolCall?: boolean;
|
|
205
|
+
}): OpenAIStopReasonResult;
|
|
206
|
+
//#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
|
+
//#region packages/ai/src/providers/openai-tool-schema.d.ts
|
|
216
|
+
/**
|
|
217
|
+
* OpenAI strict-tool-schema normalization and diagnostics.
|
|
218
|
+
*
|
|
219
|
+
* Strict schemas need all object properties required and `additionalProperties: false`; model
|
|
220
|
+
* compatibility settings can also remove unsupported schema constructs before strict checks run.
|
|
221
|
+
*/
|
|
222
|
+
type ToolSchemaCompatInput = {
|
|
223
|
+
unsupportedToolSchemaKeywords?: unknown;
|
|
224
|
+
omitEmptyArrayItems?: unknown;
|
|
225
|
+
};
|
|
226
|
+
declare function clearOpenAIToolSchemaCacheForTest(): void;
|
|
227
|
+
/** Normalizes a tool parameter schema into the OpenAI strict JSON-schema subset. */
|
|
228
|
+
declare function normalizeStrictOpenAIJsonSchema(schema: unknown, modelCompat?: ToolSchemaCompatInput | null): unknown;
|
|
229
|
+
/** Normalizes tool parameters using strict OpenAI rules only when strict mode is active. */
|
|
230
|
+
declare function normalizeOpenAIStrictToolParameters<T>(schema: T, strict: boolean, modelCompat?: ToolSchemaCompatInput | null): T;
|
|
231
|
+
/** Returns whether a schema already satisfies OpenAI strict tool-schema constraints. */
|
|
232
|
+
declare function isStrictOpenAIJsonSchemaCompatible(schema: unknown): boolean;
|
|
233
|
+
type OpenAIStrictToolSchemaDiagnostic = {
|
|
234
|
+
toolIndex: number;
|
|
235
|
+
toolName?: string;
|
|
236
|
+
violations: string[];
|
|
237
|
+
};
|
|
238
|
+
/** Returns strict-schema diagnostics for an already materialized OpenAI tool projection. */
|
|
239
|
+
declare function findOpenAIStrictToolProjectionDiagnostics(projection: OpenAIToolProjection): OpenAIStrictToolSchemaDiagnostic[];
|
|
240
|
+
/** Resolves strict mode for the projected tools that will be emitted in the request payload. */
|
|
241
|
+
declare function resolveOpenAIProjectedToolsStrictToolFlag(projection: OpenAIToolProjection, strict: boolean | null | undefined): boolean | undefined;
|
|
242
|
+
//#endregion
|
|
243
|
+
//#region packages/ai/src/providers/schema-keyword-strip.d.ts
|
|
244
|
+
/** Recursively remove schema keywords unsupported by a target provider/tool surface. */
|
|
245
|
+
declare function stripUnsupportedSchemaKeywords(schema: unknown, unsupportedKeywords: ReadonlySet<string>): unknown;
|
|
246
|
+
//#endregion
|
|
247
|
+
//#region packages/ai/src/providers/tool-schema-json-projection.d.ts
|
|
248
|
+
/** JSON-safe schema value used when projecting runtime tool parameters. */
|
|
249
|
+
type RuntimeToolInputSchemaJson = null | boolean | number | string | RuntimeToolInputSchemaJson[] | {
|
|
250
|
+
[key: string]: RuntimeToolInputSchemaJson;
|
|
251
|
+
};
|
|
252
|
+
/** Projected runtime tool schema plus validation violations. */
|
|
253
|
+
type RuntimeToolInputSchemaProjection = {
|
|
254
|
+
readonly schema: RuntimeToolInputSchemaJson;
|
|
255
|
+
readonly violations: readonly string[];
|
|
256
|
+
};
|
|
257
|
+
/** Projects one runtime tool input schema to JSON and reports runtime incompatibilities. */
|
|
258
|
+
declare function projectRuntimeToolInputSchema(schema: unknown, path?: string): RuntimeToolInputSchemaProjection;
|
|
259
|
+
//#endregion
|
|
260
|
+
export { AZURE_RESPONSES_TEXT_CONTENT_PART_TYPE, AZURE_RESPONSES_TEXT_DELTA_EVENT_TYPE, AzureResponsesTextContentPart, AzureResponsesTextDeltaEvent, GEMINI_UNSUPPORTED_SCHEMA_KEYWORDS, LLAMACPP_GBNF_MAX_REPETITION_THRESHOLD, OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH, OPENAI_RESPONSES_OUTPUT_TEXT_CONTENT_PART_TYPE, OPENAI_RESPONSES_OUTPUT_TEXT_DELTA_EVENT_TYPE, OpenAIApiReasoningEffort, type OpenAICompletionsOptions, OpenAICompletionsToolChoice, OpenAIReasoningEffort, OpenAIResponsesOptions, OpenAIStopReasonResult, OpenAIToolProjection, ResponsesMessageSnapshotCollapse, ResponsesTerminalUsagePayload, ResponsesTextContentPartType, ResponsesTextDeltaEventType, ResponsesToolCallIdentity, ResponsesToolCallState, RuntimeToolInputSchemaJson, RuntimeToolInputSchemaProjection, ToolParameterSchemaOptions, ToolSchemaModelCompat, clampOpenAIPromptCacheKey, cleanSchemaForGemini, cleanSchemaForLlamacppGbnf, clearOpenAIToolSchemaCacheForTest, convertMessages, createResponsesToolCallTracker, extractToolSchemaModelCompat, findLlamacppGbnfSchemaViolations, findOpenAIStrictSchemaViolations, findOpenAIStrictToolProjectionDiagnostics, isAzureResponsesTextDeltaEvent, isAzureResponsesTextDeltaEventType, isOpenAICompatibleAzureResponsesBaseUrl, isOpenAIGpt54MiniModel, isOpenAIGpt55Model, isOpenAIGpt56Model, isResponsesTextContentPartType, isResponsesTextDeltaEventType, isStrictOpenAIJsonSchemaCompatible, isTraditionalAzureOpenAIHost, mapOpenAIStopReason, mapResponsesTerminalUsage, normalizeOpenAIReasoningEffort, normalizeOpenAIStrictCompatSchema, normalizeOpenAIStrictToolParameters, normalizeStrictOpenAIJsonSchema, normalizeToolParameterSchema, parseAzureDeploymentNameMap, projectOpenAITools, projectRuntimeToolInputSchema, readResponsesReasoningTokens, readResponsesToolCallItemIdentity, reconcileOpenAICompletionsToolChoice, reconcileOpenAIResponsesToolChoice, resolveAzureDeploymentNameFromMap, resolveOpenAIProjectedToolsStrictToolFlag, resolveOpenAIReasoningEffortForModel, resolveOpenAISupportedReasoningEfforts, resolveResponsesMessageSnapshotCollapse, resolveResponsesTerminalStopReason, resolveUnsupportedToolSchemaKeywords, shouldOmitEmptyArrayItems, streamOpenAICompletions, streamOpenAIResponses, streamSimpleOpenAICompletions, streamSimpleOpenAIResponses, stripUnsupportedSchemaKeywords, supportsOpenAIReasoningEffort, supportsOpenAITemperature };
|
package/dist/internal/openai.mjs
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { n as clampOpenAIPromptCacheKey, t as OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH } from "../openai-prompt-cache-mZTCdRPo.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
2
|
+
import { n as reconcileOpenAICompletionsToolChoice, r as reconcileOpenAIResponsesToolChoice, t as projectOpenAITools } from "../openai-tool-projection-OhX64DoP.mjs";
|
|
3
|
+
import { t as projectRuntimeToolInputSchema } from "../tool-schema-json-projection-BwNu3nDi.mjs";
|
|
4
|
+
import { n as mapOpenAIStopReason, r as convertMessages } from "../openai-reasoning-compat-YgeLncHw.mjs";
|
|
5
|
+
import { $ as normalizeOpenAIStrictCompatSchema, J as isStrictOpenAIJsonSchemaCompatible, K as clearOpenAIToolSchemaCacheForTest, Q as findOpenAIStrictSchemaViolations, X as normalizeStrictOpenAIJsonSchema, Y as normalizeOpenAIStrictToolParameters, Z as resolveOpenAIProjectedToolsStrictToolFlag, _ as resolveResponsesMessageSnapshotCollapse, _t as supportsOpenAITemperature, a as resolveResponsesTerminalStopReason, at as LLAMACPP_GBNF_MAX_REPETITION_THRESHOLD, c as readResponsesToolCallItemIdentity, ct as GEMINI_UNSUPPORTED_SCHEMA_KEYWORDS, d as OPENAI_RESPONSES_OUTPUT_TEXT_CONTENT_PART_TYPE, dt as isOpenAIGpt55Model, et as extractToolSchemaModelCompat, f as OPENAI_RESPONSES_OUTPUT_TEXT_DELTA_EVENT_TYPE, ft as isOpenAIGpt56Model, g as isResponsesTextDeltaEventType, gt as supportsOpenAIReasoningEffort, h as isResponsesTextContentPartType, ht as resolveOpenAISupportedReasoningEfforts, i as readResponsesReasoningTokens, it as stripUnsupportedSchemaKeywords, l as AZURE_RESPONSES_TEXT_CONTENT_PART_TYPE, lt as cleanSchemaForGemini, m as isAzureResponsesTextDeltaEventType, mt as resolveOpenAIReasoningEffortForModel, nt as resolveUnsupportedToolSchemaKeywords, ot as cleanSchemaForLlamacppGbnf, p as isAzureResponsesTextDeltaEvent, pt as normalizeOpenAIReasoningEffort, q as findOpenAIStrictToolProjectionDiagnostics, r as mapResponsesTerminalUsage, rt as shouldOmitEmptyArrayItems, s as createResponsesToolCallTracker, st as findLlamacppGbnfSchemaViolations, tt as normalizeToolParameterSchema, u as AZURE_RESPONSES_TEXT_DELTA_EVENT_TYPE, ut as isOpenAIGpt54MiniModel } from "../openai-responses-stream-internal-Cw5txaGW.mjs";
|
|
6
|
+
import { i as resolveAzureDeploymentNameFromMap, n as isTraditionalAzureOpenAIHost, r as parseAzureDeploymentNameMap, t as isOpenAICompatibleAzureResponsesBaseUrl } from "../azure-openai-responses-client-compat-C7K7QfUE.mjs";
|
|
7
|
+
import { n as streamOpenAICompletions, r as streamSimpleOpenAICompletions } from "../openai-completions-DsOxhOD1.mjs";
|
|
8
|
+
import { n as streamOpenAIResponses, r as streamSimpleOpenAIResponses } from "../openai-responses-BT7A3sLu.mjs";
|
|
9
|
+
export { AZURE_RESPONSES_TEXT_CONTENT_PART_TYPE, AZURE_RESPONSES_TEXT_DELTA_EVENT_TYPE, GEMINI_UNSUPPORTED_SCHEMA_KEYWORDS, LLAMACPP_GBNF_MAX_REPETITION_THRESHOLD, OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH, OPENAI_RESPONSES_OUTPUT_TEXT_CONTENT_PART_TYPE, OPENAI_RESPONSES_OUTPUT_TEXT_DELTA_EVENT_TYPE, clampOpenAIPromptCacheKey, cleanSchemaForGemini, cleanSchemaForLlamacppGbnf, clearOpenAIToolSchemaCacheForTest, convertMessages, createResponsesToolCallTracker, extractToolSchemaModelCompat, findLlamacppGbnfSchemaViolations, findOpenAIStrictSchemaViolations, findOpenAIStrictToolProjectionDiagnostics, isAzureResponsesTextDeltaEvent, isAzureResponsesTextDeltaEventType, isOpenAICompatibleAzureResponsesBaseUrl, isOpenAIGpt54MiniModel, isOpenAIGpt55Model, isOpenAIGpt56Model, isResponsesTextContentPartType, isResponsesTextDeltaEventType, isStrictOpenAIJsonSchemaCompatible, isTraditionalAzureOpenAIHost, mapOpenAIStopReason, mapResponsesTerminalUsage, normalizeOpenAIReasoningEffort, normalizeOpenAIStrictCompatSchema, normalizeOpenAIStrictToolParameters, normalizeStrictOpenAIJsonSchema, normalizeToolParameterSchema, parseAzureDeploymentNameMap, projectOpenAITools, projectRuntimeToolInputSchema, readResponsesReasoningTokens, readResponsesToolCallItemIdentity, reconcileOpenAICompletionsToolChoice, reconcileOpenAIResponsesToolChoice, resolveAzureDeploymentNameFromMap, resolveOpenAIProjectedToolsStrictToolFlag, resolveOpenAIReasoningEffortForModel, resolveOpenAISupportedReasoningEfforts, resolveResponsesMessageSnapshotCollapse, resolveResponsesTerminalStopReason, resolveUnsupportedToolSchemaKeywords, shouldOmitEmptyArrayItems, streamOpenAICompletions, streamOpenAIResponses, streamSimpleOpenAICompletions, streamSimpleOpenAIResponses, stripUnsupportedSchemaKeywords, supportsOpenAIReasoningEffort, supportsOpenAITemperature };
|
|
@@ -2,12 +2,14 @@ import { n as getEnvApiKey, t as findEnvKeys } from "../env-api-keys-DrgeBuva.mj
|
|
|
2
2
|
import { n as createApiRegistry, t as createLlmRuntime } from "../stream-CREqxHgU.mjs";
|
|
3
3
|
import { t as sanitizeSurrogates } from "../sanitize-unicode-DT5o51ur.mjs";
|
|
4
4
|
import { c as calculateCost, d as modelsAreEqual, l as clampThinkingLevel, s as applyProviderReportedUsageCost, u as getSupportedThinkingLevels } from "../number-coercion-DvG7SNMg.mjs";
|
|
5
|
-
import {
|
|
6
|
-
import { t as headersToRecord } from "../headers-B_e4-1J0.mjs";
|
|
5
|
+
import { t as createDeferredEventBuffer } from "../deferred-event-buffer-DAvyP7qA.mjs";
|
|
7
6
|
import { n as parseStreamingJson, r as repairJson, t as parseJsonWithRepair } from "../json-parse-BvXNt1-7.mjs";
|
|
8
|
-
import {
|
|
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";
|
|
9
10
|
import { t as shortHash } from "../hash-CHgqbJmD.mjs";
|
|
10
|
-
import {
|
|
11
|
+
import { t as headersToRecord } from "../headers-B_e4-1J0.mjs";
|
|
12
|
+
import { i as registerSessionResourceCleanup, n as resolveOpenAICodexAccountId, r as cleanupSessionResources, t as decodeOpenAICodexJwtPayload } from "../openai-chatgpt-jwt-DhAAzLkj.mjs";
|
|
11
13
|
import { t as createSseByteGuard } from "../streaming-byte-guard-BrbkbwUu.mjs";
|
|
12
14
|
//#region packages/ai/src/internal/default-runtime.ts
|
|
13
15
|
const DEFAULT_RUNTIME_KEY = Symbol.for("openclaw.ai.defaultRuntime");
|
|
@@ -31,7 +31,7 @@ declare function describeToolResultMediaPlaceholder(blocks: readonly unknown[]):
|
|
|
31
31
|
declare function extractToolResultBlockText(block: unknown): string | undefined;
|
|
32
32
|
declare function extractToolResultText(blocks: readonly unknown[]): string;
|
|
33
33
|
//#endregion
|
|
34
|
-
//#region packages/ai/src/
|
|
34
|
+
//#region packages/ai/src/transcript-transform.d.ts
|
|
35
35
|
/**
|
|
36
36
|
* Normalize tool call ID for cross-provider compatibility.
|
|
37
37
|
* OpenAI Responses API generates IDs that are 450+ chars with special characters like `|`.
|
package/dist/internal/shared.mjs
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { i as transformMessages } from "../host-Dog2WQiR.mjs";
|
|
2
2
|
import { t as sanitizeSurrogates } from "../sanitize-unicode-DT5o51ur.mjs";
|
|
3
|
+
import { a as isImageWithMediaPayload, c as ensureSystemPromptCacheBoundary, d as stripSystemPromptCacheBoundary, f as normalizePromptCapabilityIds, i as hasMediaPayload, l as prependSystemPromptAdditionAfterCacheBoundary, m as sortPromptCacheToolsByName, n as extractToolResultBlockText, p as normalizeStructuredPromptSection, r as extractToolResultText, s as SYSTEM_PROMPT_CACHE_BOUNDARY, t as describeToolResultMediaPlaceholder, u as splitSystemPromptCacheBoundary } from "../tool-result-text-CTpIRbYd.mjs";
|
|
4
|
+
import { i as clampReasoning, n as buildBaseOptions, r as clampMaxTokensToModel, t as adjustMaxTokensForThinking } from "../simple-options-9lhRrN73.mjs";
|
|
5
|
+
import "../transform-messages-C8mBqZxF.mjs";
|
|
6
|
+
import { t as inspectTlsCertificateError } from "../tls-certificate-errors-DXSpluKI.mjs";
|
|
3
7
|
export { SYSTEM_PROMPT_CACHE_BOUNDARY, adjustMaxTokensForThinking, buildBaseOptions, clampMaxTokensToModel, clampReasoning, describeToolResultMediaPlaceholder, ensureSystemPromptCacheBoundary, extractToolResultBlockText, extractToolResultText, hasMediaPayload, inspectTlsCertificateError, isImageWithMediaPayload, normalizePromptCapabilityIds, normalizeStructuredPromptSection, prependSystemPromptAdditionAfterCacheBoundary, sanitizeSurrogates, sortPromptCacheToolsByName, splitSystemPromptCacheBoundary, stripSystemPromptCacheBoundary, transformMessages };
|
|
@@ -1,21 +1,3 @@
|
|
|
1
|
-
//#region packages/ai/src/utils/deferred-event-buffer.ts
|
|
2
|
-
function createDeferredEventBuffer(sink, onBufferedEvent) {
|
|
3
|
-
let events = [];
|
|
4
|
-
return {
|
|
5
|
-
push(event) {
|
|
6
|
-
events.push(event);
|
|
7
|
-
onBufferedEvent?.();
|
|
8
|
-
},
|
|
9
|
-
flush() {
|
|
10
|
-
for (const event of events) sink.push(event);
|
|
11
|
-
events = [];
|
|
12
|
-
},
|
|
13
|
-
discard() {
|
|
14
|
-
events = [];
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
//#endregion
|
|
19
1
|
//#region packages/ai/src/utils/llm-request-activity.ts
|
|
20
2
|
const requestActivityListeners = /* @__PURE__ */ new WeakMap();
|
|
21
3
|
function notifyLlmRequestActivity(signal) {
|
|
@@ -32,4 +14,4 @@ function onLlmRequestActivity(signal, listener) {
|
|
|
32
14
|
};
|
|
33
15
|
}
|
|
34
16
|
//#endregion
|
|
35
|
-
export { onLlmRequestActivity as n,
|
|
17
|
+
export { onLlmRequestActivity as n, notifyLlmRequestActivity as t };
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { n as getEnvApiKey } from "./env-api-keys-DrgeBuva.mjs";
|
|
2
2
|
import { t as AssistantMessageEventStream } from "./event-stream-D8n2uFee.mjs";
|
|
3
|
-
import { n as getAiTransportHost } from "./host-
|
|
4
|
-
import { A as buildBaseOptions, D as truncateUtf16Safe, E as isImageWithMediaPayload, S as describeToolResultMediaPlaceholder, j as clampMaxTokensToModel, o as stripSystemPromptCacheBoundary, u as transformMessages, w as extractToolResultText } from "./shared-CdjNZd35.mjs";
|
|
3
|
+
import { i as transformMessages, n as getAiTransportHost } from "./host-Dog2WQiR.mjs";
|
|
5
4
|
import { t as sanitizeSurrogates } from "./sanitize-unicode-DT5o51ur.mjs";
|
|
5
|
+
import { a as isImageWithMediaPayload, d as stripSystemPromptCacheBoundary, o as truncateUtf16Safe, r as extractToolResultText, t as describeToolResultMediaPlaceholder } from "./tool-result-text-CTpIRbYd.mjs";
|
|
6
6
|
import { c as calculateCost, l as clampThinkingLevel } from "./number-coercion-DvG7SNMg.mjs";
|
|
7
|
-
import { d as transportAbortError } from "./transport-stream-shared-BbMELSI4.mjs";
|
|
8
7
|
import { n as parseStreamingJson } from "./json-parse-BvXNt1-7.mjs";
|
|
8
|
+
import { d as transportAbortError } from "./transport-stream-shared-D81p90xq.mjs";
|
|
9
9
|
import { t as shortHash } from "./hash-CHgqbJmD.mjs";
|
|
10
|
+
import { n as buildBaseOptions, r as clampMaxTokensToModel } from "./simple-options-9lhRrN73.mjs";
|
|
11
|
+
import "./transform-messages-C8mBqZxF.mjs";
|
|
10
12
|
import { t as createSseByteGuard } from "./streaming-byte-guard-BrbkbwUu.mjs";
|
|
11
13
|
import { randomUUID } from "node:crypto";
|
|
12
14
|
import { HTTPClient, Mistral } from "@mistralai/mistralai";
|
package/dist/{openai-chatgpt-responses-CedIj0hk.mjs → openai-chatgpt-responses-B84Ibtrd.mjs}
RENAMED
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
import { n as getEnvApiKey } from "./env-api-keys-DrgeBuva.mjs";
|
|
2
2
|
import { i as formatThrownValue, n as createAssistantMessageDiagnostic, t as appendAssistantMessageDiagnostic } from "./diagnostics-COpOtRwq.mjs";
|
|
3
3
|
import { t as AssistantMessageEventStream } from "./event-stream-D8n2uFee.mjs";
|
|
4
|
-
import { n as getAiTransportHost, r as resolveAiTransportHeaderSentinels } from "./host-
|
|
4
|
+
import { n as getAiTransportHost, r as resolveAiTransportHeaderSentinels } from "./host-Dog2WQiR.mjs";
|
|
5
5
|
import { n as clampOpenAIPromptCacheKey } from "./openai-prompt-cache-mZTCdRPo.mjs";
|
|
6
|
-
import {
|
|
6
|
+
import { d as stripSystemPromptCacheBoundary } from "./tool-result-text-CTpIRbYd.mjs";
|
|
7
7
|
import { t as toErrorObject } from "./error-coercion-DgxlWC0n.mjs";
|
|
8
8
|
import { n as clampTimerTimeoutMs, o as resolveTimerTimeoutMs } from "./number-coercion-DvG7SNMg.mjs";
|
|
9
9
|
import { parseRetryAfterHttpDateMs } from "./internal/retry-after.mjs";
|
|
10
|
-
import { d as transportAbortError } from "./transport-stream-shared-
|
|
10
|
+
import { d as transportAbortError } from "./transport-stream-shared-D81p90xq.mjs";
|
|
11
|
+
import { _t as supportsOpenAITemperature, n as processResponsesStream } from "./openai-responses-stream-internal-Cw5txaGW.mjs";
|
|
12
|
+
import { i as getFirstStreamEventTimeoutMs, r as getFirstStreamEventTimeoutHandler, t as createFirstStreamEventAbortController } from "./stream-first-event-timeout-BBys9hSb.mjs";
|
|
11
13
|
import { t as headersToRecord } from "./headers-B_e4-1J0.mjs";
|
|
14
|
+
import { n as buildBaseOptions } from "./simple-options-9lhRrN73.mjs";
|
|
15
|
+
import { i as resolveResponsesReasoningEffort, n as convertResponsesMessages, o as convertResponsesToolPayload } from "./openai-responses-shared-pXl6Wd8S.mjs";
|
|
12
16
|
import { i as registerSessionResourceCleanup, n as resolveOpenAICodexAccountId } from "./openai-chatgpt-jwt-DhAAzLkj.mjs";
|
|
13
|
-
import { i as getFirstStreamEventTimeoutMs, r as getFirstStreamEventTimeoutHandler, t as createFirstStreamEventAbortController } from "./stream-first-event-timeout-C3OgBjIk.mjs";
|
|
14
17
|
import { t as createSseByteGuard } from "./streaming-byte-guard-BrbkbwUu.mjs";
|
|
15
|
-
import {
|
|
18
|
+
import { t as inspectTlsCertificateError } from "./tls-certificate-errors-DXSpluKI.mjs";
|
|
16
19
|
//#region packages/ai/src/internal/retry-sleep.ts
|
|
17
20
|
function sleepWithAbort(ms, signal) {
|
|
18
21
|
return new Promise((resolve, reject) => {
|
|
@@ -147,10 +150,6 @@ const streamOpenAICodexResponses = (model, context, options) => {
|
|
|
147
150
|
const nextBody = await options?.onPayload?.(body, model);
|
|
148
151
|
if (nextBody !== void 0) body = nextBody;
|
|
149
152
|
const sessionId = clampOpenAIPromptCacheKey(options?.sessionId);
|
|
150
|
-
const websocketRequestId = sessionId || createCodexRequestId();
|
|
151
|
-
const sseHeaders = buildSSEHeaders(modelHeaders, optionHeaders, accountId, apiKey, sessionId);
|
|
152
|
-
const websocketHeaders = buildWebSocketHeaders(modelHeaders, optionHeaders, accountId, apiKey, websocketRequestId);
|
|
153
|
-
const bodyJson = JSON.stringify(body);
|
|
154
153
|
requestTimeoutMs = resolveRequestTimeoutMs(options);
|
|
155
154
|
requestTimeoutSignal = buildRequestSignal(options?.signal, requestTimeoutMs);
|
|
156
155
|
firstEventAbort = createFirstStreamEventAbortController(requestTimeoutSignal);
|
|
@@ -162,6 +161,7 @@ const streamOpenAICodexResponses = (model, context, options) => {
|
|
|
162
161
|
const transport = options?.transport || "auto";
|
|
163
162
|
const websocketDisabledForSession = transport === "auto" && isWebSocketSseFallbackActive(options?.sessionId);
|
|
164
163
|
if (transport !== "sse" && !websocketDisabledForSession) {
|
|
164
|
+
const websocketHeaders = buildWebSocketHeaders(modelHeaders, optionHeaders, accountId, apiKey, sessionId || createCodexRequestId());
|
|
165
165
|
let websocketStarted = false;
|
|
166
166
|
let retriedWebSocketConnectionLimit = false;
|
|
167
167
|
while (true) {
|
|
@@ -191,7 +191,7 @@ const streamOpenAICodexResponses = (model, context, options) => {
|
|
|
191
191
|
fallbackTransport: transport === "auto" && !websocketStarted ? "sse" : void 0,
|
|
192
192
|
eventsEmitted: websocketStarted,
|
|
193
193
|
phase: websocketStarted ? "after_message_stream_start" : "before_message_stream_start",
|
|
194
|
-
requestBytes: new TextEncoder().encode(
|
|
194
|
+
requestBytes: new TextEncoder().encode(JSON.stringify(body)).byteLength
|
|
195
195
|
}));
|
|
196
196
|
if (transport === "auto" && options?.sessionId) websocketSseFallbackSessions.add(options.sessionId);
|
|
197
197
|
if (websocketStarted || transport !== "auto") throw error;
|
|
@@ -199,6 +199,8 @@ const streamOpenAICodexResponses = (model, context, options) => {
|
|
|
199
199
|
}
|
|
200
200
|
}
|
|
201
201
|
}
|
|
202
|
+
const sseHeaders = buildSSEHeaders(modelHeaders, optionHeaders, accountId, apiKey, sessionId);
|
|
203
|
+
const bodyJson = JSON.stringify(body);
|
|
202
204
|
const compressedBody = model.provider === "openai" && !sseHeaders.has("content-encoding") ? compressRequestBodyZstd(bodyJson) : null;
|
|
203
205
|
if (compressedBody) sseHeaders.set("content-encoding", "zstd");
|
|
204
206
|
const sseBody = compressedBody ?? bodyJson;
|
|
@@ -554,12 +556,15 @@ function closeWebSocketSilently(socket, code = 1e3, reason = "done") {
|
|
|
554
556
|
socket.close(code, reason);
|
|
555
557
|
} catch {}
|
|
556
558
|
}
|
|
559
|
+
function deleteOwnedWebSocketSession(sessionId, entry) {
|
|
560
|
+
if (websocketSessionCache.get(sessionId) === entry) websocketSessionCache.delete(sessionId);
|
|
561
|
+
}
|
|
557
562
|
function scheduleSessionWebSocketExpiry(sessionId, entry) {
|
|
558
563
|
if (entry.idleTimer) clearTimeout(entry.idleTimer);
|
|
559
564
|
entry.idleTimer = setTimeout(() => {
|
|
560
565
|
if (entry.busy) return;
|
|
561
566
|
closeWebSocketSilently(entry.socket, 1e3, "idle_timeout");
|
|
562
|
-
|
|
567
|
+
deleteOwnedWebSocketSession(sessionId, entry);
|
|
563
568
|
}, SESSION_WEBSOCKET_CACHE_TTL_MS);
|
|
564
569
|
}
|
|
565
570
|
async function connectWebSocket(url, headers, signal) {
|
|
@@ -650,7 +655,7 @@ async function acquireWebSocket(url, headers, sessionId, signal) {
|
|
|
650
655
|
release: ({ keep } = {}) => {
|
|
651
656
|
if (!keep || !isWebSocketReusable(cached.socket)) {
|
|
652
657
|
closeWebSocketSilently(cached.socket);
|
|
653
|
-
|
|
658
|
+
deleteOwnedWebSocketSession(sessionId, cached);
|
|
654
659
|
return;
|
|
655
660
|
}
|
|
656
661
|
cached.busy = false;
|
|
@@ -686,7 +691,7 @@ async function acquireWebSocket(url, headers, sessionId, signal) {
|
|
|
686
691
|
if (!keep || !isWebSocketReusable(entry.socket)) {
|
|
687
692
|
closeWebSocketSilently(entry.socket);
|
|
688
693
|
if (entry.idleTimer) clearTimeout(entry.idleTimer);
|
|
689
|
-
|
|
694
|
+
deleteOwnedWebSocketSession(sessionId, entry);
|
|
690
695
|
return;
|
|
691
696
|
}
|
|
692
697
|
entry.busy = false;
|