@openclaw/ai 2026.8.1-beta.2 → 2026.8.1
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-B6dLpq5L.mjs → anthropic-Djj7L1rx.mjs} +49 -39
- package/dist/{anthropic-compaction-replay-8lJNKXOE.mjs → anthropic-compaction-replay-CY4tkD4V.mjs} +42 -44
- package/dist/{anthropic-payload-policy-CiEuQS72.d.mts → anthropic-payload-policy-i_5_inWe.d.mts} +4 -2
- package/dist/{api-registry-k3zTz0cV.d.mts → api-registry-C9-wZd_W.d.mts} +2 -1
- package/dist/{azure-openai-responses-mxIOtUnn.mjs → azure-openai-responses-Bj3czHNa.mjs} +4 -4
- package/dist/{number-coercion-H9qHik3g.mjs → base64-CEFBpSkN.mjs} +73 -1
- package/dist/diagnostics.d.mts +2 -3
- package/dist/diagnostics.mjs +1 -1
- package/dist/{env-api-keys-DrgeBuva.mjs → env-api-keys-bktO00EJ.mjs} +2 -15
- package/dist/event-stream-C988TSLe.d.mts +1 -0
- package/dist/{event-stream-BP6AWT8j.d.mts → event-stream-UhnxHuqt.d.mts} +1 -2
- package/dist/event-stream.d.mts +2 -1
- package/dist/{google-C7h2QzDX.mjs → google-0Ca6TYbw.mjs} +4 -4
- package/dist/{google-shared-B0Qr9OR7.mjs → google-shared-DVfL9COU.mjs} +22 -8
- package/dist/{google-vertex-Bhc3TjDl.mjs → google-vertex-5dAMxprN.mjs} +4 -4
- package/dist/{host-DTqNc7ad.mjs → host-D51fmkH6.mjs} +40 -33
- package/dist/{host-vWgMMhiJ.d.mts → host-DoPJJ1KD.d.mts} +7 -7
- package/dist/index-N3zr6__t.d.mts +105 -0
- package/dist/index.d.mts +9 -10
- package/dist/index.mjs +2 -3
- package/dist/internal/anthropic.d.mts +57 -49
- package/dist/internal/anthropic.mjs +5 -5
- package/dist/internal/openai-responses-payload-policy.d.mts +3 -3
- package/dist/internal/openai-responses-payload-policy.mjs +2 -3
- package/dist/internal/openai.d.mts +65 -63
- package/dist/internal/openai.mjs +10 -8
- package/dist/internal/retry-after.d.mts +2 -3
- package/dist/internal/runtime.d.mts +53 -40
- package/dist/internal/runtime.mjs +10 -9
- package/dist/internal/shared.d.mts +37 -23
- package/dist/internal/shared.mjs +4 -4
- package/dist/{json-parse-CDnesDM_.mjs → json-parse-BuAJEbdW.mjs} +18 -2
- package/dist/{headers-DdOQtGuU.mjs → llm-request-activity-BjtkplhG.mjs} +1 -9
- package/dist/{mistral-CEWoQI_g.mjs → mistral-BCnrI-kV.mjs} +64 -53
- package/dist/{openai-chatgpt-responses-CrPmqERt.mjs → openai-chatgpt-responses-CGBGWSqr.mjs} +45 -20
- package/dist/{openai-completions-BPnt4Sml.mjs → openai-completions-BaTuwID7.mjs} +63 -258
- package/dist/{openai-completions-compat-Dt3dcawL.d.mts → openai-completions-compat-DB7FFq7k.d.mts} +3 -3
- package/dist/openai-completions-stream-Bpns6uNc.mjs +1622 -0
- package/dist/{openai-responses-DhIKtOup.mjs → openai-responses-1GBcQujk.mjs} +8 -6
- package/dist/openai-responses-compaction-window-DwydGZI8.mjs +686 -0
- package/dist/{openai-responses-contracts-XpZJxrRG.d.mts → openai-responses-contracts-DgaR3t5T.d.mts} +14 -5
- package/dist/{openai-responses-payload-policy-BSs371VM.d.mts → openai-responses-payload-policy-rLRPsSmB.d.mts} +2 -0
- package/dist/{openai-responses-prompt-observer-internal-DgNTYnRY.mjs → openai-responses-prompt-observer-internal-_nhGTn2b.mjs} +3 -3
- package/dist/{openai-responses-shared-DXIt3iY5.mjs → openai-responses-shared-zPmKnhF5.mjs} +345 -1553
- package/dist/openai-stop-reason-Drnn_6Qj.mjs +28 -0
- package/dist/openai-tool-schema-Dgl4H2MU.mjs +1695 -0
- package/dist/{provider-error-BUwEnjXq.mjs → provider-error-jZP5NMTZ.mjs} +3 -82
- package/dist/{provider-options-B96RdNpH.d.mts → provider-options-HvA_slFa.d.mts} +23 -4
- package/dist/provider-transcript-transform-C01bQ5a3.mjs +32 -0
- package/dist/provider-types.d.mts +18 -17
- package/dist/providers.d.mts +5 -6
- package/dist/providers.mjs +9 -9
- package/dist/{reasoning-tag-text-partitioner-rnPwX2pg.mjs → reasoning-tag-text-partitioner-CwzKb0bA.mjs} +4 -1
- package/dist/rolldown-runtime-BhDjJH2R.mjs +15 -0
- package/dist/{sanitize-unicode-BYqrYtC_.mjs → sanitize-unicode-DCkltN94.mjs} +1 -2
- package/dist/{simple-options-D58D5Kvw.mjs → simple-options-DKx86yX9.mjs} +42 -4
- package/dist/{anthropic-JsNA5KCu.mjs → src-Bu3FiFAG.mjs} +1 -1
- package/dist/{stream-first-event-timeout-MK28puvq.mjs → stream-first-event-timeout-DcNjoFQE.mjs} +1 -1
- package/dist/{streaming-byte-guard-BrbkbwUu.mjs → streaming-byte-guard-CC-HMn_u.mjs} +5 -6
- package/dist/string-normalization--fwJ4S2q.mjs +16 -0
- package/dist/{tool-schema-json-projection-q5d7QX5c.mjs → tool-schema-json-projection-qvTEs5Am.mjs} +17 -8
- package/dist/transport-stream-shared-CT5ycdzn.mjs +342 -0
- package/dist/transport-stream-shared-NjwWNaRY.d.mts +138 -0
- package/dist/{transport-utils-DJqkxbhC.mjs → transport-utils-BHx9z8Cl.mjs} +9 -9
- package/dist/transports.d.mts +140 -169
- package/dist/transports.mjs +269 -1262
- package/dist/types-DtGu2d3C.d.mts +1 -0
- package/dist/{types-BHNrPS1l.d.mts → types-h38Azne1.d.mts} +53 -17
- package/dist/types.d.mts +6 -5
- package/dist/types.mjs +1 -2
- package/dist/utf16-slice-qz3nsy87.mjs +84 -0
- package/dist/{validation-DT9SrFn3.d.mts → validation-C68lP2uy.d.mts} +1 -2
- package/dist/validation.d.mts +1 -1
- package/package.json +6 -6
- package/dist/anthropic-SrGtwsJu.d.mts +0 -100
- package/dist/index-BVVgDSdq.d.mts +0 -1
- package/dist/openai-responses-contracts-CyfIkQi5.mjs +0 -253
- package/dist/openai-responses-payload-policy-BDxV-W0c.mjs +0 -206
- package/dist/openai-stop-reason-BkFkqqK0.mjs +0 -563
- package/dist/openai-tool-projection-CY04OcvQ.mjs +0 -338
- package/dist/provider-transcript-transform-ePx-Bbfr.mjs +0 -155
- package/dist/record-coerce-DdXsgUd_.mjs +0 -23
- package/dist/src-D2H6yKkH.mjs +0 -2
- package/dist/stream-first-event-timeout-DvDeSucC.d.mts +0 -29
- package/dist/string-coerce-fsri9iCu.mjs +0 -34
- package/dist/types-BVVgDSdq.d.mts +0 -1
- package/dist/utf16-slice-CvGodqok.mjs +0 -29
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import { n as getEnvApiKey } from "./env-api-keys-DrgeBuva.mjs";
|
|
2
1
|
import { t as AssistantMessageEventStream } from "./event-stream-uSMZJ3FA.mjs";
|
|
3
|
-
import { i as clampThinkingLevel, r as calculateCost, t as sanitizeSurrogates } from "./sanitize-unicode-
|
|
4
|
-
import { a as describeToolResultMediaPlaceholder,
|
|
5
|
-
import {
|
|
6
|
-
import { n as
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
2
|
+
import { i as clampThinkingLevel, r as calculateCost, t as sanitizeSurrogates } from "./sanitize-unicode-DCkltN94.mjs";
|
|
3
|
+
import { a as describeToolResultMediaPlaceholder, c as extractToolResultText, d as isImageWithMediaPayload, l as formatToolResultText, n as getAiTransportHost } from "./host-D51fmkH6.mjs";
|
|
4
|
+
import { n as projectProviderError } from "./provider-error-jZP5NMTZ.mjs";
|
|
5
|
+
import { d as stripSystemPromptCacheBoundary, m as sortPromptCacheToolsByName, n as buildBaseOptions, r as clampMaxTokensToModel } from "./simple-options-DKx86yX9.mjs";
|
|
6
|
+
import { n as getEnvApiKey } from "./env-api-keys-bktO00EJ.mjs";
|
|
7
|
+
import { _ as transportAbortError, f as notifyProviderHttpResponse, s as finalizeTerminalToolCallArguments } from "./transport-stream-shared-CT5ycdzn.mjs";
|
|
8
|
+
import { r as parseStreamingJson, t as createToolArgumentPreviewSchedule } from "./json-parse-BuAJEbdW.mjs";
|
|
9
9
|
import { t as shortHash } from "./hash-CHgqbJmD.mjs";
|
|
10
|
-
import {
|
|
11
|
-
import { t as
|
|
10
|
+
import { t as transformProviderMessages } from "./provider-transcript-transform-C01bQ5a3.mjs";
|
|
11
|
+
import { t as mapOpenAIStopReason } from "./openai-stop-reason-Drnn_6Qj.mjs";
|
|
12
|
+
import { t as createSseByteGuard } from "./streaming-byte-guard-CC-HMn_u.mjs";
|
|
12
13
|
import { randomUUID } from "node:crypto";
|
|
13
|
-
import { HTTPClient
|
|
14
|
+
import { HTTPClient } from "@mistralai/mistralai/lib/http";
|
|
15
|
+
import { Chat } from "@mistralai/mistralai/sdk/chat";
|
|
14
16
|
//#region packages/ai/src/providers/mistral.ts
|
|
15
17
|
const MISTRAL_TOOL_CALL_ID_LENGTH = 9;
|
|
16
18
|
const MISTRAL_STREAM_BODY_MAX_BYTES = 16 * 1024 * 1024;
|
|
@@ -63,10 +65,25 @@ const streamMistral = (model, context, options) => {
|
|
|
63
65
|
try {
|
|
64
66
|
const apiKey = options?.apiKey || getEnvApiKey(model.provider);
|
|
65
67
|
if (!apiKey) throw new Error(`No API key for provider: ${model.provider}`);
|
|
66
|
-
const
|
|
68
|
+
const boundedFetcher = createBoundedMistralFetcher(MISTRAL_STREAM_BODY_MAX_BYTES, getAiTransportHost().buildModelFetch(model) ?? fetch);
|
|
69
|
+
let mistralResponse;
|
|
70
|
+
let reportedResponse;
|
|
71
|
+
const httpClient = new HTTPClient({ fetcher: boundedFetcher });
|
|
72
|
+
httpClient.addHook("response", async (response) => {
|
|
73
|
+
mistralResponse = response;
|
|
74
|
+
if (!response.ok) {
|
|
75
|
+
await notifyProviderHttpResponse({
|
|
76
|
+
options,
|
|
77
|
+
response,
|
|
78
|
+
model
|
|
79
|
+
});
|
|
80
|
+
reportedResponse = response;
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
const chat = new Chat({
|
|
67
84
|
apiKey,
|
|
68
85
|
serverURL: model.baseUrl,
|
|
69
|
-
httpClient
|
|
86
|
+
httpClient
|
|
70
87
|
});
|
|
71
88
|
const normalizeMistralToolCallId = createMistralToolCallIdNormalizer();
|
|
72
89
|
let payload = buildChatPayload(model, context, transformProviderMessages(context.messages, model, (id) => normalizeMistralToolCallId(id)), options);
|
|
@@ -77,17 +94,23 @@ const streamMistral = (model, context, options) => {
|
|
|
77
94
|
...options?.headers
|
|
78
95
|
};
|
|
79
96
|
if (resolveMistralPromptCacheKey(options) && options?.sessionId) headers["x-affinity"] ||= options.sessionId;
|
|
80
|
-
const mistralStream = await
|
|
97
|
+
const mistralStream = await chat.stream(payload, {
|
|
81
98
|
headers,
|
|
82
99
|
signal: options?.signal
|
|
83
100
|
});
|
|
101
|
+
if (mistralResponse && mistralResponse !== reportedResponse) await notifyProviderHttpResponse({
|
|
102
|
+
options,
|
|
103
|
+
response: mistralResponse,
|
|
104
|
+
model,
|
|
105
|
+
cancelStream: (reason) => mistralStream.cancel(reason)
|
|
106
|
+
});
|
|
84
107
|
stream.push({
|
|
85
108
|
type: "start",
|
|
86
109
|
partial: output
|
|
87
110
|
});
|
|
88
111
|
await consumeChatStream(model, output, stream, mistralStream);
|
|
89
112
|
if (options?.signal?.aborted) throw transportAbortError(options.signal);
|
|
90
|
-
if (output.stopReason === "aborted" || output.stopReason === "error") throw new Error("An unknown error occurred");
|
|
113
|
+
if (output.stopReason === "aborted" || output.stopReason === "error") throw new Error(output.errorMessage ?? "An unknown error occurred");
|
|
91
114
|
stream.push({
|
|
92
115
|
type: "done",
|
|
93
116
|
reason: output.stopReason,
|
|
@@ -221,6 +244,7 @@ async function consumeChatStream(model, output, stream, mistralStream) {
|
|
|
221
244
|
const blocks = output.content;
|
|
222
245
|
const blockIndex = () => blocks.length - 1;
|
|
223
246
|
const toolBlockIdentities = /* @__PURE__ */ new Map();
|
|
247
|
+
const toolArgumentPreviewSchedules = /* @__PURE__ */ new WeakMap();
|
|
224
248
|
const normalizeMissingToolCallId = createMistralToolCallIdNormalizer();
|
|
225
249
|
const missingToolCallIdScope = randomUUID();
|
|
226
250
|
const createMissingToolCallId = (contentIndex) => normalizeMissingToolCallId(`${missingToolCallIdScope}:toolcall:${contentIndex}`);
|
|
@@ -300,6 +324,7 @@ async function consumeChatStream(model, output, stream, mistralStream) {
|
|
|
300
324
|
for await (const event of mistralStream) {
|
|
301
325
|
const chunk = event.data;
|
|
302
326
|
output.responseId ||= chunk.id;
|
|
327
|
+
if (typeof chunk.model === "string" && chunk.model.length > 0 && chunk.model !== model.id) output.responseModel ||= chunk.model;
|
|
303
328
|
if (chunk.usage) {
|
|
304
329
|
const promptTokens = chunk.usage.promptTokens || 0;
|
|
305
330
|
const cachedPromptTokens = readMistralCachedPromptTokens(chunk.usage, promptTokens);
|
|
@@ -314,7 +339,9 @@ async function consumeChatStream(model, output, stream, mistralStream) {
|
|
|
314
339
|
if (!choice) continue;
|
|
315
340
|
if (choice.finishReason) {
|
|
316
341
|
terminalFinishReason = choice.finishReason;
|
|
317
|
-
|
|
342
|
+
const { stopReason, errorMessage } = mapOpenAIStopReason(choice.finishReason === "model_length" ? "length" : choice.finishReason);
|
|
343
|
+
output.stopReason = stopReason;
|
|
344
|
+
if (errorMessage) output.errorMessage = errorMessage;
|
|
318
345
|
}
|
|
319
346
|
const delta = choice.delta;
|
|
320
347
|
if (delta.content !== null && delta.content !== void 0) {
|
|
@@ -425,6 +452,7 @@ async function consumeChatStream(model, output, stream, mistralStream) {
|
|
|
425
452
|
partialArgs: ""
|
|
426
453
|
};
|
|
427
454
|
output.content.push(block);
|
|
455
|
+
toolArgumentPreviewSchedules.set(block, createToolArgumentPreviewSchedule());
|
|
428
456
|
toolBlockIdentities.set(contentIndex, {
|
|
429
457
|
explicitIds: new Set(providedCallId ? [providedCallId] : []),
|
|
430
458
|
functionNames: new Set(functionName ? [functionName] : []),
|
|
@@ -452,7 +480,7 @@ async function consumeChatStream(model, output, stream, mistralStream) {
|
|
|
452
480
|
if (toolCallIndex !== void 0) identity.indexes.add(toolCallIndex);
|
|
453
481
|
const argsDelta = typeof toolCall.function.arguments === "string" ? toolCall.function.arguments : JSON.stringify(toolCall.function.arguments || {});
|
|
454
482
|
block.partialArgs = (block.partialArgs || "") + argsDelta;
|
|
455
|
-
block.arguments = parseStreamingJson(block.partialArgs);
|
|
483
|
+
if (toolArgumentPreviewSchedules.get(block)?.(block.partialArgs.length)) block.arguments = parseStreamingJson(block.partialArgs);
|
|
456
484
|
stream.push({
|
|
457
485
|
type: "toolcall_delta",
|
|
458
486
|
contentIndex,
|
|
@@ -467,23 +495,20 @@ async function consumeChatStream(model, output, stream, mistralStream) {
|
|
|
467
495
|
if (!terminalFinishReason) throw new Error("Mistral stream ended without a terminal finish reason");
|
|
468
496
|
return;
|
|
469
497
|
}
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
}
|
|
478
|
-
for (const
|
|
479
|
-
|
|
480
|
-
if (block?.type !== "toolCall") continue;
|
|
481
|
-
const toolBlock = block;
|
|
482
|
-
delete toolBlock.partialArgs;
|
|
498
|
+
const completedToolCalls = [...toolBlockIdentities.keys()].flatMap((contentIndex) => {
|
|
499
|
+
const block = blocks[contentIndex];
|
|
500
|
+
return block?.type === "toolCall" ? [{
|
|
501
|
+
block,
|
|
502
|
+
contentIndex
|
|
503
|
+
}] : [];
|
|
504
|
+
});
|
|
505
|
+
finalizeTerminalToolCallArguments(completedToolCalls.map(({ block }) => block), (block) => block.partialArgs ?? "", "Mistral completed tool call has invalid JSON arguments");
|
|
506
|
+
for (const { block, contentIndex } of completedToolCalls) {
|
|
507
|
+
delete block.partialArgs;
|
|
483
508
|
stream.push({
|
|
484
509
|
type: "toolcall_end",
|
|
485
|
-
contentIndex
|
|
486
|
-
toolCall:
|
|
510
|
+
contentIndex,
|
|
511
|
+
toolCall: block,
|
|
487
512
|
partial: output
|
|
488
513
|
});
|
|
489
514
|
}
|
|
@@ -592,7 +617,14 @@ function toChatMessages(messages, supportsImages) {
|
|
|
592
617
|
continue;
|
|
593
618
|
}
|
|
594
619
|
const toolContent = [];
|
|
595
|
-
const
|
|
620
|
+
const textResult = extractToolResultText(msg.content);
|
|
621
|
+
const mediaPlaceholder = describeToolResultMediaPlaceholder(msg.content);
|
|
622
|
+
const toolText = formatToolResultText({
|
|
623
|
+
text: textResult,
|
|
624
|
+
mediaPlaceholder,
|
|
625
|
+
omittedMediaPlaceholder: msg.content.some(isImageWithMediaPayload) && !supportsImages ? textResult.trim() ? "[tool image omitted: model does not support images]" : mediaPlaceholder === "(see attached media)" ? "(media omitted: model does not support images)" : "(image omitted: model does not support images)" : void 0,
|
|
626
|
+
isError: msg.isError
|
|
627
|
+
});
|
|
596
628
|
toolContent.push({
|
|
597
629
|
type: "text",
|
|
598
630
|
text: toolText
|
|
@@ -614,16 +646,6 @@ function toChatMessages(messages, supportsImages) {
|
|
|
614
646
|
}
|
|
615
647
|
return result;
|
|
616
648
|
}
|
|
617
|
-
function buildToolResultText(text, mediaPlaceholder, hasImages, supportsImages, isError) {
|
|
618
|
-
const trimmed = text.trim();
|
|
619
|
-
const errorPrefix = isError ? "[tool error] " : "";
|
|
620
|
-
if (trimmed.length > 0) return `${errorPrefix}${trimmed}${hasImages && !supportsImages ? "\n[tool image omitted: model does not support images]" : ""}`;
|
|
621
|
-
if (mediaPlaceholder) {
|
|
622
|
-
if (!hasImages || supportsImages) return `${errorPrefix}${mediaPlaceholder}`;
|
|
623
|
-
return `${errorPrefix}${mediaPlaceholder === "(see attached media)" ? "(media omitted: model does not support images)" : "(image omitted: model does not support images)"}`;
|
|
624
|
-
}
|
|
625
|
-
return isError ? "[tool error] (no tool output)" : "(no tool output)";
|
|
626
|
-
}
|
|
627
649
|
function usesReasoningEffort(model) {
|
|
628
650
|
return model.id === "mistral-small-2603" || model.id === "mistral-small-latest" || model.id === "mistral-medium-3-5";
|
|
629
651
|
}
|
|
@@ -647,16 +669,5 @@ function mapToolChoice(choice, convertedToolNames) {
|
|
|
647
669
|
function: { name: toolName }
|
|
648
670
|
};
|
|
649
671
|
}
|
|
650
|
-
function mapChatStopReason(reason) {
|
|
651
|
-
if (reason === null) return "stop";
|
|
652
|
-
switch (reason) {
|
|
653
|
-
case "stop": return "stop";
|
|
654
|
-
case "length":
|
|
655
|
-
case "model_length": return "length";
|
|
656
|
-
case "tool_calls": return "toolUse";
|
|
657
|
-
case "error": return "error";
|
|
658
|
-
default: return "stop";
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
672
|
//#endregion
|
|
662
673
|
export { createBoundedMistralFetcher, streamMistral, streamSimpleMistral };
|
package/dist/{openai-chatgpt-responses-CrPmqERt.mjs → openai-chatgpt-responses-CGBGWSqr.mjs}
RENAMED
|
@@ -1,24 +1,23 @@
|
|
|
1
|
-
import { n as getEnvApiKey } from "./env-api-keys-DrgeBuva.mjs";
|
|
2
1
|
import { i as formatThrownValue, n as createAssistantMessageDiagnostic, t as appendAssistantMessageDiagnostic } from "./diagnostics-COpOtRwq.mjs";
|
|
3
2
|
import { t as AssistantMessageEventStream } from "./event-stream-uSMZJ3FA.mjs";
|
|
4
|
-
import { n as getAiTransportHost, r as resolveAiTransportHeaderSentinels } from "./host-
|
|
5
|
-
import { n as projectProviderError } from "./provider-error-
|
|
6
|
-
import { n as toErrorObject, t as createResponsesPromptEgressObserver } from "./openai-responses-prompt-observer-internal-
|
|
7
|
-
import {
|
|
8
|
-
import { S as supportsOpenAITemperature, m as responsesPromptObserver } from "./openai-responses-contracts-CyfIkQi5.mjs";
|
|
3
|
+
import { n as getAiTransportHost, r as resolveAiTransportHeaderSentinels } from "./host-D51fmkH6.mjs";
|
|
4
|
+
import { n as projectProviderError } from "./provider-error-jZP5NMTZ.mjs";
|
|
5
|
+
import { n as toErrorObject, t as createResponsesPromptEgressObserver } from "./openai-responses-prompt-observer-internal-_nhGTn2b.mjs";
|
|
6
|
+
import { o as clampTimerTimeoutMs, u as resolveTimerTimeoutMs } from "./base64-CEFBpSkN.mjs";
|
|
9
7
|
import { n as clampOpenAIPromptCacheKey } from "./openai-prompt-cache-mZTCdRPo.mjs";
|
|
10
|
-
import {
|
|
11
|
-
import { t as headersToRecord } from "./headers-DdOQtGuU.mjs";
|
|
12
|
-
import { F as commitResponsesEncryptedContentAttempt, G as suppressOpenAIResponsesCompaction, L as isInvalidEncryptedContentError, U as buildOpenAIResponsesReasoningReplayMetadata, a as resolveResponsesReasoningEffort, c as processResponsesStream, i as createResponsesAssistantOutput, n as applyResponsesServiceTierPricing, p as ResponsesStreamFailure, r as convertResponsesMessages, s as convertResponsesToolPayload, z as resolveNextResponsesEncryptedContentAttempt } from "./openai-responses-shared-DXIt3iY5.mjs";
|
|
13
|
-
import { f as transportAbortError, p as withProviderResponseHook } from "./provider-transcript-transform-ePx-Bbfr.mjs";
|
|
8
|
+
import { d as stripSystemPromptCacheBoundary, n as buildBaseOptions } from "./simple-options-DKx86yX9.mjs";
|
|
14
9
|
import { parseRetryAfterHttpDateMs } from "./internal/retry-after.mjs";
|
|
15
|
-
import { t as MALFORMED_STREAMING_FRAGMENT_ERROR_MESSAGE } from "./transport-utils-
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
10
|
+
import { t as MALFORMED_STREAMING_FRAGMENT_ERROR_MESSAGE } from "./transport-utils-BHx9z8Cl.mjs";
|
|
11
|
+
import { n as getEnvApiKey } from "./env-api-keys-bktO00EJ.mjs";
|
|
12
|
+
import { C as headersToRecord, _ as transportAbortError, p as notifyProviderStreamOpened, y as withProviderResponseHook } from "./transport-stream-shared-CT5ycdzn.mjs";
|
|
13
|
+
import { F as commitResponsesEncryptedContentAttempt, L as isInvalidEncryptedContentError, W as buildOpenAIResponsesReasoningReplayMetadata, a as resolveResponsesReasoningEffort, c as processResponsesStream, i as createResponsesAssistantOutput, n as applyResponsesServiceTierPricing, p as ResponsesStreamFailure, q as suppressOpenAIResponsesCompaction, r as convertResponsesMessages, s as convertResponsesToolPayload, z as resolveNextResponsesEncryptedContentAttempt } from "./openai-responses-shared-zPmKnhF5.mjs";
|
|
14
|
+
import { C as createOpenAIProviderAcceptanceHook, w as createOpenAIResponseHook } from "./openai-tool-schema-Dgl4H2MU.mjs";
|
|
15
|
+
import { a as withFirstStreamEventTimeout, i as getFirstStreamEventTimeoutMs, r as getFirstStreamEventTimeoutHandler, t as createFirstStreamEventAbortController } from "./stream-first-event-timeout-DcNjoFQE.mjs";
|
|
16
|
+
import { A as supportsOpenAITemperature, S as responsesPromptObserver } from "./openai-responses-compaction-window-DwydGZI8.mjs";
|
|
17
|
+
import { t as createSseByteGuard } from "./streaming-byte-guard-CC-HMn_u.mjs";
|
|
18
18
|
import { n as registerSessionResourceCleanup } from "./session-resources-CkR4WWy1.mjs";
|
|
19
19
|
import "./diagnostics.mjs";
|
|
20
20
|
import { n as resolveOpenAICodexAccountId } from "./openai-chatgpt-jwt-KWcgd0d_.mjs";
|
|
21
|
-
import { t as createSseByteGuard } from "./streaming-byte-guard-BrbkbwUu.mjs";
|
|
22
21
|
import { t as inspectTlsCertificateError } from "./tls-certificate-errors-DXSpluKI.mjs";
|
|
23
22
|
//#region packages/ai/src/internal/retry-sleep.ts
|
|
24
23
|
function sleepWithAbort(ms, signal) {
|
|
@@ -155,6 +154,12 @@ function isRequestTimeoutError(error, callerSignal, requestSignal, timeoutMs) {
|
|
|
155
154
|
if (!(error instanceof Error)) return false;
|
|
156
155
|
return error.name === "AbortError" || error.name === "TimeoutError" || error.message === "Request was aborted";
|
|
157
156
|
}
|
|
157
|
+
/** Local-only failure category for transport diagnostics; never provider text. */
|
|
158
|
+
function classifyStreamFailure(error, signal, requestTimedOut) {
|
|
159
|
+
if (requestTimedOut) return "timeout";
|
|
160
|
+
if (signal?.aborted) return "caller-abort";
|
|
161
|
+
return error instanceof ResponsesStreamFailure || error instanceof CodexApiError ? "provider-failure" : "transport";
|
|
162
|
+
}
|
|
158
163
|
function formatRequestTimeoutError(timeoutMs, cause) {
|
|
159
164
|
return new Error(`Request timed out after ${timeoutMs}ms`, { cause: cause instanceof Error ? cause : void 0 });
|
|
160
165
|
}
|
|
@@ -172,6 +177,7 @@ function compressRequestBodyZstd(bodyJson) {
|
|
|
172
177
|
const streamOpenAICodexResponses = (model, context, options) => {
|
|
173
178
|
const stream = new AssistantMessageEventStream();
|
|
174
179
|
(async () => {
|
|
180
|
+
const startedAt = Date.now();
|
|
175
181
|
let requestTimeoutMs;
|
|
176
182
|
let requestTimeoutSignal;
|
|
177
183
|
let activeSignal;
|
|
@@ -218,8 +224,9 @@ const streamOpenAICodexResponses = (model, context, options) => {
|
|
|
218
224
|
websocketRequestSent = false;
|
|
219
225
|
try {
|
|
220
226
|
await processWebSocketStream(resolveCodexWebSocketUrl(model.baseUrl), activeAttempt.request, websocketHeaders, output, stream, model, () => {
|
|
221
|
-
commitSemanticAttempt(activeAttempt);
|
|
222
227
|
websocketStarted = true;
|
|
228
|
+
}, () => {
|
|
229
|
+
commitSemanticAttempt(activeAttempt);
|
|
223
230
|
}, requestOptions, firstEventAbort.abort, observePromptEgress, activeAttempt.kind, () => {
|
|
224
231
|
websocketRequestSent = true;
|
|
225
232
|
});
|
|
@@ -337,7 +344,7 @@ const streamOpenAICodexResponses = (model, context, options) => {
|
|
|
337
344
|
stream: mapCodexEvents(parseOpenAIChatGptResponsesSse(response)),
|
|
338
345
|
signal: firstEventAbort.signal,
|
|
339
346
|
abort: firstEventAbort.abort,
|
|
340
|
-
hook:
|
|
347
|
+
hook: createOpenAIProviderAcceptanceHook(options, response, model),
|
|
341
348
|
onReady: () => stream.push({
|
|
342
349
|
type: "start",
|
|
343
350
|
partial: output
|
|
@@ -364,9 +371,19 @@ const streamOpenAICodexResponses = (model, context, options) => {
|
|
|
364
371
|
});
|
|
365
372
|
stream.end();
|
|
366
373
|
} catch (error) {
|
|
367
|
-
const
|
|
374
|
+
const requestTimedOut = isRequestTimeoutError(error, options?.signal, requestTimeoutSignal, requestTimeoutMs) && requestTimeoutMs !== void 0;
|
|
375
|
+
const normalizedError = requestTimedOut && requestTimeoutMs !== void 0 ? formatRequestTimeoutError(requestTimeoutMs, error) : error;
|
|
368
376
|
for (const block of output.content) delete block.partialJson;
|
|
369
377
|
const terminal = projectProviderError(normalizedError, options?.signal);
|
|
378
|
+
getAiTransportHost().logWarn("openai-transport", "ChatGPT Responses stream terminated", {
|
|
379
|
+
provider: model.provider,
|
|
380
|
+
api: model.api,
|
|
381
|
+
model: model.id,
|
|
382
|
+
transport: options?.transport || "auto",
|
|
383
|
+
elapsedMs: Math.max(0, Date.now() - startedAt),
|
|
384
|
+
stopReason: terminal.stopReason,
|
|
385
|
+
failureKind: classifyStreamFailure(error, options?.signal, requestTimedOut)
|
|
386
|
+
});
|
|
370
387
|
Object.assign(output, terminal);
|
|
371
388
|
stream.push({
|
|
372
389
|
type: "error",
|
|
@@ -872,12 +889,14 @@ function buildCachedWebSocketRequestBody(entry, body) {
|
|
|
872
889
|
input: delta
|
|
873
890
|
};
|
|
874
891
|
}
|
|
875
|
-
async function* startWebSocketOutputOnFirstEvent(events, output, stream, onStart) {
|
|
892
|
+
async function* startWebSocketOutputOnFirstEvent(events, output, stream, onFirstProviderEvent, reportStreamOpened, onStart) {
|
|
876
893
|
let started = false;
|
|
877
894
|
for await (const event of events) {
|
|
878
895
|
if (!started) {
|
|
879
896
|
started = true;
|
|
897
|
+
onFirstProviderEvent();
|
|
880
898
|
onStart();
|
|
899
|
+
await reportStreamOpened();
|
|
881
900
|
stream.push({
|
|
882
901
|
type: "start",
|
|
883
902
|
partial: output
|
|
@@ -886,7 +905,7 @@ async function* startWebSocketOutputOnFirstEvent(events, output, stream, onStart
|
|
|
886
905
|
yield event;
|
|
887
906
|
}
|
|
888
907
|
}
|
|
889
|
-
async function processWebSocketStream(url, body, headers, output, stream, model, onStart, options, abortFirstEventStream, observePromptEgress, payloadVariant = "initial", onRequestSent) {
|
|
908
|
+
async function processWebSocketStream(url, body, headers, output, stream, model, onFirstProviderEvent, onStart, options, abortFirstEventStream, observePromptEgress, payloadVariant = "initial", onRequestSent) {
|
|
890
909
|
const { socket, entry, release } = await acquireWebSocket(url, headers, options?.sessionId, options?.signal);
|
|
891
910
|
let keepConnection = true;
|
|
892
911
|
const useCachedContext = options?.transport === "websocket-cached" || options?.transport === "auto";
|
|
@@ -903,7 +922,13 @@ async function processWebSocketStream(url, body, headers, output, stream, model,
|
|
|
903
922
|
...requestBody
|
|
904
923
|
}));
|
|
905
924
|
onRequestSent?.();
|
|
906
|
-
await processResponsesStream(startWebSocketOutputOnFirstEvent(mapCodexEvents(parseWebSocket(socket, options?.signal)), output, stream,
|
|
925
|
+
await processResponsesStream(startWebSocketOutputOnFirstEvent(mapCodexEvents(parseWebSocket(socket, options?.signal)), output, stream, onFirstProviderEvent, () => notifyProviderStreamOpened({
|
|
926
|
+
options,
|
|
927
|
+
cancelStream: () => {
|
|
928
|
+
keepConnection = false;
|
|
929
|
+
closeWebSocketSilently(socket);
|
|
930
|
+
}
|
|
931
|
+
}), onStart), output, stream, model, {
|
|
907
932
|
serviceTier: options?.serviceTier,
|
|
908
933
|
firstEventTimeoutMs: getFirstStreamEventTimeoutMs(options),
|
|
909
934
|
abortFirstEventStream,
|