@openclaw/ai 2026.7.2-beta.7 → 2026.8.1-beta.2
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-CH4UUnZr.mjs → anthropic-B6dLpq5L.mjs} +55 -203
- package/dist/{src-QkygScBs.mjs → anthropic-JsNA5KCu.mjs} +0 -1
- package/dist/anthropic-compaction-replay-8lJNKXOE.mjs +840 -0
- package/dist/anthropic-payload-policy-CiEuQS72.d.mts +49 -0
- package/dist/{api-registry-DlMgPR39.d.mts → api-registry-k3zTz0cV.d.mts} +1 -1
- package/dist/{azure-openai-responses-CImcwB83.mjs → azure-openai-responses-mxIOtUnn.mjs} +23 -29
- package/dist/diagnostics.d.mts +24 -1
- package/dist/diagnostics.mjs +2 -1
- package/dist/{event-stream-YjaPW20U.d.mts → event-stream-BP6AWT8j.d.mts} +4 -1
- package/dist/{event-stream-D8n2uFee.mjs → event-stream-uSMZJ3FA.mjs} +26 -5
- package/dist/event-stream.d.mts +1 -1
- package/dist/event-stream.mjs +1 -1
- package/dist/{google-CtSg0iTS.mjs → google-C7h2QzDX.mjs} +5 -5
- package/dist/{google-shared-DNBz5rcD.mjs → google-shared-B0Qr9OR7.mjs} +146 -89
- package/dist/google-thinking-level-C-V3tecN.mjs +9 -0
- package/dist/{google-vertex-31f1uS9L.mjs → google-vertex-Bhc3TjDl.mjs} +11 -7
- package/dist/{llm-request-activity-BjtkplhG.mjs → headers-DdOQtGuU.mjs} +9 -1
- package/dist/host-DTqNc7ad.mjs +466 -0
- package/dist/{host-B9GUmcra.d.mts → host-vWgMMhiJ.d.mts} +9 -4
- package/dist/index.d.mts +6 -6
- package/dist/index.mjs +7 -5
- package/dist/internal/anthropic.d.mts +29 -5
- package/dist/internal/anthropic.mjs +5 -5
- package/dist/internal/openai-responses-payload-policy.d.mts +3 -0
- package/dist/internal/openai-responses-payload-policy.mjs +3 -0
- package/dist/internal/openai.d.mts +6 -6
- package/dist/internal/openai.mjs +8 -7
- package/dist/internal/runtime.d.mts +17 -5
- package/dist/internal/runtime.mjs +85 -73
- package/dist/internal/shared.d.mts +1 -6
- package/dist/internal/shared.mjs +3 -5
- package/dist/{json-parse-BvXNt1-7.mjs → json-parse-CDnesDM_.mjs} +4 -6
- package/dist/{mistral-CWmpvWYh.mjs → mistral-CEWoQI_g.mjs} +45 -48
- package/dist/number-coercion-H9qHik3g.mjs +71 -0
- package/dist/openai-chatgpt-jwt-KWcgd0d_.mjs +19 -0
- package/dist/{openai-chatgpt-responses-B84Ibtrd.mjs → openai-chatgpt-responses-CrPmqERt.mjs} +284 -240
- package/dist/{openai-completions-DsOxhOD1.mjs → openai-completions-BPnt4Sml.mjs} +65 -99
- package/dist/{openai-completions-compat-DBWjXoMZ.d.mts → openai-completions-compat-Dt3dcawL.d.mts} +2 -2
- package/dist/{openai-responses-BT7A3sLu.mjs → openai-responses-DhIKtOup.mjs} +18 -41
- package/dist/openai-responses-contracts-CyfIkQi5.mjs +253 -0
- package/dist/openai-responses-contracts-XpZJxrRG.d.mts +68 -0
- package/dist/openai-responses-payload-policy-BDxV-W0c.mjs +206 -0
- package/dist/openai-responses-payload-policy-BSs371VM.d.mts +40 -0
- package/dist/openai-responses-prompt-observer-internal-DgNTYnRY.mjs +46 -0
- package/dist/{openai-responses-stream-internal-Cw5txaGW.mjs → openai-responses-shared-DXIt3iY5.mjs} +1406 -940
- package/dist/{openai-reasoning-compat-YgeLncHw.mjs → openai-stop-reason-BkFkqqK0.mjs} +204 -37
- package/dist/openai-tool-projection-CY04OcvQ.mjs +338 -0
- package/dist/provider-error-BUwEnjXq.mjs +429 -0
- package/dist/provider-error-CzNw4BWX.d.mts +12 -0
- package/dist/{provider-options-D8bB3z9b.d.mts → provider-options-B96RdNpH.d.mts} +9 -3
- package/dist/provider-transcript-transform-ePx-Bbfr.mjs +155 -0
- package/dist/provider-types.d.mts +31 -0
- package/dist/provider-types.mjs +8 -0
- package/dist/providers.d.mts +1 -1
- package/dist/providers.mjs +17 -19
- package/dist/{reasoning-tag-text-partitioner-CGDyLWUR.mjs → reasoning-tag-text-partitioner-rnPwX2pg.mjs} +14 -8
- package/dist/record-coerce-DdXsgUd_.mjs +23 -0
- package/dist/sanitize-unicode-BYqrYtC_.mjs +90 -0
- package/dist/session-resources-CkR4WWy1.mjs +21 -0
- package/dist/simple-options-D58D5Kvw.mjs +117 -0
- package/dist/src-D2H6yKkH.mjs +2 -0
- package/dist/{stream-first-event-timeout-BBys9hSb.mjs → stream-first-event-timeout-MK28puvq.mjs} +2 -2
- package/dist/string-coerce-fsri9iCu.mjs +34 -0
- package/dist/{tool-schema-json-projection-BwNu3nDi.mjs → tool-schema-json-projection-q5d7QX5c.mjs} +32 -7
- package/dist/transport-utils-DJqkxbhC.mjs +138 -0
- package/dist/transports.d.mts +166 -241
- package/dist/transports.mjs +1979 -1825
- package/dist/types-BDdaOVi2.mjs +6 -0
- package/dist/{types-bzp5k29J.d.mts → types-BHNrPS1l.d.mts} +23 -1
- package/dist/types.d.mts +4 -4
- package/dist/types.mjs +6 -4
- package/dist/utf16-slice-CvGodqok.mjs +29 -0
- package/dist/{validation-DAa_yFOM.mjs → validation-B61OhAio.mjs} +6 -6
- package/dist/{validation-B-j7cOYp.d.mts → validation-DT9SrFn3.d.mts} +1 -1
- package/dist/validation.d.mts +1 -1
- package/dist/validation.mjs +1 -1
- package/package.json +15 -1
- package/dist/anthropic-usage-DWU-x8MI.mjs +0 -459
- package/dist/error-coercion-DgxlWC0n.mjs +0 -15
- package/dist/headers-B_e4-1J0.mjs +0 -9
- package/dist/host-Dog2WQiR.mjs +0 -369
- package/dist/number-coercion-DvG7SNMg.mjs +0 -129
- package/dist/openai-chatgpt-jwt-DhAAzLkj.mjs +0 -39
- package/dist/openai-responses-shared-pXl6Wd8S.mjs +0 -392
- package/dist/openai-tool-projection-OhX64DoP.mjs +0 -215
- package/dist/provider-error-CAEvRjry.mjs +0 -47
- package/dist/sanitize-unicode-DT5o51ur.mjs +0 -26
- package/dist/simple-options-9lhRrN73.mjs +0 -50
- 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
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
import { n as getEnvApiKey, r as __exportAll } from "./env-api-keys-DrgeBuva.mjs";
|
|
2
|
-
import { t as AssistantMessageEventStream } from "./event-stream-
|
|
3
|
-
import {
|
|
2
|
+
import { t as AssistantMessageEventStream } from "./event-stream-uSMZJ3FA.mjs";
|
|
3
|
+
import { i as clampThinkingLevel } from "./sanitize-unicode-BYqrYtC_.mjs";
|
|
4
|
+
import { n as getAiTransportHost } from "./host-DTqNc7ad.mjs";
|
|
5
|
+
import { n as projectProviderError } from "./provider-error-BUwEnjXq.mjs";
|
|
4
6
|
import { n as clampOpenAIPromptCacheKey } from "./openai-prompt-cache-mZTCdRPo.mjs";
|
|
5
7
|
import { t as resolveCacheRetention } from "./cache-retention-0x979a5V.mjs";
|
|
6
|
-
import {
|
|
7
|
-
import { n as
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import { t as
|
|
12
|
-
import {
|
|
13
|
-
import { t as createReasoningTagTextPartitioner } from "./reasoning-tag-text-partitioner-
|
|
14
|
-
import { a as withFirstStreamEventTimeout, i as getFirstStreamEventTimeoutMs, r as getFirstStreamEventTimeoutHandler, t as createFirstStreamEventAbortController } from "./stream-first-event-timeout-BBys9hSb.mjs";
|
|
15
|
-
import { t as headersToRecord } from "./headers-B_e4-1J0.mjs";
|
|
16
|
-
import { t as formatProviderError } from "./provider-error-CAEvRjry.mjs";
|
|
8
|
+
import { c as splitSystemPromptCacheBoundary, f as sortPromptCacheToolsByName, n as buildBaseOptions } from "./simple-options-D58D5Kvw.mjs";
|
|
9
|
+
import { a as createOpenAICompletionsToolCallDeltaNormalizer, c as resolveOpenAICompletionsCompat, d as clearPendingCommentaryText, f as rememberPendingCommentaryTags, i as hasToolCallHistory, l as resolveOpenAICompletionsResponseFormat, n as resolveOpenAIReasoningEffortMap, o as finalizeOpenAICompletionsToolCalls, p as tagPendingCommentaryText, r as convertMessages, t as mapOpenAIStopReason, u as shouldOmitOllamaCompatResponseFormat } from "./openai-stop-reason-BkFkqqK0.mjs";
|
|
10
|
+
import { n as parseStreamingJson } from "./json-parse-CDnesDM_.mjs";
|
|
11
|
+
import { n as notifyLlmRequestActivity } from "./headers-DdOQtGuU.mjs";
|
|
12
|
+
import { f as transportAbortError, p as withProviderResponseHook } from "./provider-transcript-transform-ePx-Bbfr.mjs";
|
|
13
|
+
import { d as readOpenAICompletionsContentDeltas, n as reconcileOpenAICompletionsToolChoice, o as createOpenAIResponseHook, s as isOpenAICompletionsThinkingEnabled, t as projectOpenAITools, u as parseOpenAICompletionsUsage } from "./openai-tool-projection-CY04OcvQ.mjs";
|
|
14
|
+
import { a as withFirstStreamEventTimeout, i as getFirstStreamEventTimeoutMs, r as getFirstStreamEventTimeoutHandler, t as createFirstStreamEventAbortController } from "./stream-first-event-timeout-MK28puvq.mjs";
|
|
15
|
+
import { t as createReasoningTagTextPartitioner } from "./reasoning-tag-text-partitioner-rnPwX2pg.mjs";
|
|
17
16
|
import { i as resolveCloudflareBaseUrl, n as hasCopilotVisionInput, r as isCloudflareProvider, t as buildCopilotDynamicHeaders } from "./github-copilot-headers-NCJtz9i0.mjs";
|
|
18
|
-
import { n as buildBaseOptions } from "./simple-options-9lhRrN73.mjs";
|
|
19
17
|
import OpenAI from "openai";
|
|
20
18
|
//#region packages/ai/src/providers/openai-completions.ts
|
|
21
19
|
var openai_completions_exports = /* @__PURE__ */ __exportAll({
|
|
@@ -23,20 +21,6 @@ var openai_completions_exports = /* @__PURE__ */ __exportAll({
|
|
|
23
21
|
streamOpenAICompletions: () => streamOpenAICompletions,
|
|
24
22
|
streamSimpleOpenAICompletions: () => streamSimpleOpenAICompletions
|
|
25
23
|
});
|
|
26
|
-
/**
|
|
27
|
-
* Check if conversation messages contain tool calls or tool results.
|
|
28
|
-
* This is needed because Anthropic (via proxy) requires the tools param
|
|
29
|
-
* to be present when messages include tool_calls or tool role messages.
|
|
30
|
-
*/
|
|
31
|
-
function hasToolHistory(messages) {
|
|
32
|
-
for (const msg of messages) {
|
|
33
|
-
if (msg.role === "toolResult") return true;
|
|
34
|
-
if (msg.role === "assistant") {
|
|
35
|
-
if (Array.isArray(msg.content) && msg.content.some((block) => block.type === "toolCall")) return true;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
24
|
function isEncryptedReasoningDetail(detail) {
|
|
41
25
|
if (typeof detail !== "object" || detail === null) return false;
|
|
42
26
|
const candidate = detail;
|
|
@@ -86,13 +70,15 @@ const streamOpenAICompletions = (model, context, options) => {
|
|
|
86
70
|
maxRetries: options?.maxRetries ?? 0
|
|
87
71
|
};
|
|
88
72
|
const { data: openaiStream, response } = await client.chat.completions.create(params, requestOptions).withResponse();
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
73
|
+
const hookedOpenAIStream = withProviderResponseHook({
|
|
74
|
+
stream: openaiStream,
|
|
75
|
+
signal: firstEventAbort.signal,
|
|
76
|
+
abort: firstEventAbort.abort,
|
|
77
|
+
hook: createOpenAIResponseHook(options?.onResponse, response, model),
|
|
78
|
+
onReady: () => stream.push({
|
|
79
|
+
type: "start",
|
|
80
|
+
partial: output
|
|
81
|
+
})
|
|
96
82
|
});
|
|
97
83
|
let textBlock = null;
|
|
98
84
|
let thinkingBlock = null;
|
|
@@ -100,6 +86,7 @@ const streamOpenAICompletions = (model, context, options) => {
|
|
|
100
86
|
const toolCallBlocksByIndex = /* @__PURE__ */ new Map();
|
|
101
87
|
const toolCallBlocksById = /* @__PURE__ */ new Map();
|
|
102
88
|
const toolCallBlocksByFirstId = /* @__PURE__ */ new Map();
|
|
89
|
+
const normalizeToolCallDeltas = createOpenAICompletionsToolCallDeltaNormalizer();
|
|
103
90
|
const pendingReasoningDetailsByToolCallId = /* @__PURE__ */ new Map();
|
|
104
91
|
const blocks = output.content;
|
|
105
92
|
const finishedBlocks = /* @__PURE__ */ new Set();
|
|
@@ -134,16 +121,12 @@ const streamOpenAICompletions = (model, context, options) => {
|
|
|
134
121
|
content: block.thinking,
|
|
135
122
|
partial: output
|
|
136
123
|
});
|
|
137
|
-
else if (block.type === "toolCall") {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
toolCall: block,
|
|
144
|
-
partial: output
|
|
145
|
-
});
|
|
146
|
-
}
|
|
124
|
+
else if (block.type === "toolCall") stream.push({
|
|
125
|
+
type: "toolcall_end",
|
|
126
|
+
contentIndex,
|
|
127
|
+
toolCall: block,
|
|
128
|
+
partial: output
|
|
129
|
+
});
|
|
147
130
|
};
|
|
148
131
|
const ensureTextBlock = () => {
|
|
149
132
|
if (!textBlock) {
|
|
@@ -165,7 +148,7 @@ const streamOpenAICompletions = (model, context, options) => {
|
|
|
165
148
|
thinkingBlock = {
|
|
166
149
|
type: "thinking",
|
|
167
150
|
thinking: "",
|
|
168
|
-
thinkingSignature
|
|
151
|
+
...thinkingSignature ? { thinkingSignature } : {}
|
|
169
152
|
};
|
|
170
153
|
appendBlock(thinkingBlock);
|
|
171
154
|
stream.push({
|
|
@@ -243,7 +226,7 @@ const streamOpenAICompletions = (model, context, options) => {
|
|
|
243
226
|
const flushPartitionedContent = () => {
|
|
244
227
|
for (const delta of reasoningTagTextPartitioner.flush()) if (delta.kind === "text") appendTextDelta(delta.text);
|
|
245
228
|
};
|
|
246
|
-
const guardedOpenaiStream = withFirstStreamEventTimeout(
|
|
229
|
+
const guardedOpenaiStream = withFirstStreamEventTimeout(hookedOpenAIStream, {
|
|
247
230
|
provider: model.provider,
|
|
248
231
|
api: model.api,
|
|
249
232
|
model: model.id,
|
|
@@ -258,26 +241,27 @@ const streamOpenAICompletions = (model, context, options) => {
|
|
|
258
241
|
notifyLlmRequestActivity(options?.signal);
|
|
259
242
|
output.responseId ||= chunk.id;
|
|
260
243
|
if (typeof chunk.model === "string" && chunk.model.length > 0 && chunk.model !== model.id) output.responseModel ||= chunk.model;
|
|
261
|
-
if (chunk.usage) output.usage =
|
|
244
|
+
if (chunk.usage) output.usage = parseOpenAICompletionsUsage(chunk.usage, model, { includeReasoningTokens: false });
|
|
262
245
|
const choice = Array.isArray(chunk.choices) ? chunk.choices[0] : void 0;
|
|
263
246
|
if (!choice) continue;
|
|
264
247
|
const choiceUsage = choice.usage;
|
|
265
|
-
if (!chunk.usage && choiceUsage) output.usage =
|
|
248
|
+
if (!chunk.usage && choiceUsage) output.usage = parseOpenAICompletionsUsage(choiceUsage, model, { includeReasoningTokens: false });
|
|
266
249
|
if (choice.finish_reason) {
|
|
267
250
|
const finishReasonResult = mapOpenAIStopReason(choice.finish_reason);
|
|
268
251
|
output.stopReason = finishReasonResult.stopReason;
|
|
269
252
|
if (finishReasonResult.errorMessage) output.errorMessage = finishReasonResult.errorMessage;
|
|
270
253
|
hasFinishReason = true;
|
|
271
254
|
}
|
|
272
|
-
const
|
|
273
|
-
if (
|
|
255
|
+
const rawChoiceDelta = choice.delta ?? choice.message;
|
|
256
|
+
if (rawChoiceDelta) for (const normalizedDelta of normalizeToolCallDeltas(rawChoiceDelta, choice.finish_reason)) {
|
|
257
|
+
const choiceDelta = normalizedDelta.delta;
|
|
274
258
|
const reasoningFields = [
|
|
275
259
|
"reasoning_content",
|
|
276
260
|
"reasoning",
|
|
277
261
|
"reasoning_text"
|
|
278
262
|
];
|
|
279
263
|
const deltaFields = choiceDelta;
|
|
280
|
-
const shouldEmitReasoning = Boolean(model.reasoning && options?.reasoningEffort);
|
|
264
|
+
const shouldEmitReasoning = Boolean(model.reasoning && options?.reasoningEffort && isOpenAICompletionsThinkingEnabled(options.reasoningEffort));
|
|
281
265
|
let foundReasoningField = null;
|
|
282
266
|
for (const field of reasoningFields) {
|
|
283
267
|
const value = deltaFields[field];
|
|
@@ -291,14 +275,16 @@ const streamOpenAICompletions = (model, context, options) => {
|
|
|
291
275
|
const delta = deltaFields[foundReasoningField];
|
|
292
276
|
if (typeof delta === "string" && delta.length > 0) appendThinkingDelta(model.provider === "opencode-go" && foundReasoningField === "reasoning" ? "reasoning_content" : foundReasoningField, delta);
|
|
293
277
|
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
278
|
+
for (const contentDelta of readOpenAICompletionsContentDeltas(choiceDelta.content, choiceDelta.refusal, foundReasoningField ? [deltaFields[foundReasoningField]] : [])) if (contentDelta.kind === "thinking") {
|
|
279
|
+
if (reasoningTagTextPartitioner.hasPending()) reasoningTagTextPartitioner.markStrict();
|
|
280
|
+
if (shouldEmitReasoning) appendThinkingDelta(contentDelta.signature, contentDelta.text);
|
|
281
|
+
} else appendPartitionedContent(contentDelta.text, Boolean(foundReasoningField));
|
|
282
|
+
const toolCallDeltas = normalizedDelta.toolCalls;
|
|
283
|
+
if (toolCallDeltas.length > 0) {
|
|
298
284
|
flushPartitionedContent();
|
|
299
285
|
sealNativeReasoningBeforeText();
|
|
300
286
|
rememberPendingCommentaryTags(provisionalCommentaryTags, tagPendingCommentaryText(output.content));
|
|
301
|
-
for (const toolCall of
|
|
287
|
+
for (const toolCall of toolCallDeltas) {
|
|
302
288
|
const block = ensureToolCallBlock(toolCall);
|
|
303
289
|
if (!block.id && toolCall.id) {
|
|
304
290
|
block.id = toolCall.id;
|
|
@@ -332,16 +318,21 @@ const streamOpenAICompletions = (model, context, options) => {
|
|
|
332
318
|
}
|
|
333
319
|
}
|
|
334
320
|
flushPartitionedContent();
|
|
335
|
-
|
|
336
|
-
if (options?.signal?.aborted)
|
|
337
|
-
if (output.stopReason === "aborted")
|
|
338
|
-
if (output.stopReason === "error")
|
|
339
|
-
if (!hasFinishReason)
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
321
|
+
let terminalError;
|
|
322
|
+
if (options?.signal?.aborted) terminalError = transportAbortError(options.signal);
|
|
323
|
+
else if (output.stopReason === "aborted") terminalError = /* @__PURE__ */ new Error("Request was aborted");
|
|
324
|
+
else if (output.stopReason === "error") terminalError = new Error(output.errorMessage || "Provider returned an error stop reason");
|
|
325
|
+
else if (!hasFinishReason) terminalError = /* @__PURE__ */ new Error("Stream ended without finish_reason");
|
|
326
|
+
if (terminalError) {
|
|
327
|
+
for (const block of blocks) if (block.type !== "toolCall") finishBlock(block);
|
|
328
|
+
throw terminalError;
|
|
329
|
+
}
|
|
330
|
+
finalizeOpenAICompletionsToolCalls(output);
|
|
331
|
+
if (output.stopReason === "aborted" || output.stopReason === "error") {
|
|
332
|
+
for (const block of blocks) if (block.type !== "toolCall") finishBlock(block);
|
|
333
|
+
throw new Error(output.errorMessage || (output.stopReason === "aborted" ? "Request was aborted" : "Provider returned an invalid tool call"));
|
|
334
|
+
}
|
|
335
|
+
for (const block of blocks) if (block.type !== "toolCall" || output.stopReason === "toolUse") finishBlock(block);
|
|
345
336
|
if (output.stopReason !== "toolUse") clearPendingCommentaryText(provisionalCommentaryTags);
|
|
346
337
|
if (output.stopReason === "toolUse") tagPendingCommentaryText(output.content);
|
|
347
338
|
stream.push({
|
|
@@ -351,18 +342,17 @@ const streamOpenAICompletions = (model, context, options) => {
|
|
|
351
342
|
});
|
|
352
343
|
stream.end();
|
|
353
344
|
} catch (error) {
|
|
345
|
+
const terminal = projectProviderError(error, options?.signal);
|
|
346
|
+
Object.assign(output, terminal);
|
|
347
|
+
finalizeOpenAICompletionsToolCalls(output, { allowSilentToolCallPromotion: false });
|
|
354
348
|
for (const block of output.content) {
|
|
355
349
|
delete block.index;
|
|
356
350
|
delete block.partialArgs;
|
|
357
351
|
delete block.streamIndex;
|
|
358
352
|
}
|
|
359
|
-
output.stopReason = options?.signal?.aborted ? "aborted" : "error";
|
|
360
|
-
output.errorMessage = formatProviderError(error);
|
|
361
|
-
const rawMetadata = error?.error?.metadata?.raw;
|
|
362
|
-
if (rawMetadata && !output.errorMessage.includes(rawMetadata)) output.errorMessage += `\n${rawMetadata}`;
|
|
363
353
|
stream.push({
|
|
364
354
|
type: "error",
|
|
365
|
-
reason:
|
|
355
|
+
reason: terminal.stopReason,
|
|
366
356
|
error: output
|
|
367
357
|
});
|
|
368
358
|
stream.end();
|
|
@@ -453,9 +443,9 @@ function buildParams(model, context, options, compat = resolveOpenAICompletionsC
|
|
|
453
443
|
const converted = convertTools(context.tools, compat);
|
|
454
444
|
toolProjection = converted.projection;
|
|
455
445
|
if (converted.tools.length > 0) params.tools = converted.tools;
|
|
456
|
-
else if (
|
|
446
|
+
else if (hasToolCallHistory(context.messages)) params.tools = [];
|
|
457
447
|
if (compat.zaiToolStream && converted.tools.length > 0) params.tool_stream = true;
|
|
458
|
-
} else if (
|
|
448
|
+
} else if (hasToolCallHistory(context.messages)) params.tools = [];
|
|
459
449
|
if (cacheControl) applyAnthropicCacheControl(messages, params.tools, cacheControl, cacheOptOutIndexes);
|
|
460
450
|
if (options?.toolChoice) {
|
|
461
451
|
const toolChoice = reconcileOpenAICompletionsToolChoice(options.toolChoice, toolProjection ?? projectOpenAITools([]));
|
|
@@ -591,7 +581,7 @@ function convertTools(tools, compat) {
|
|
|
591
581
|
const projection = projectOpenAITools(tools);
|
|
592
582
|
return {
|
|
593
583
|
projection,
|
|
594
|
-
tools: projection.tools.map((tool) => ({
|
|
584
|
+
tools: sortPromptCacheToolsByName(projection.tools).map((tool) => ({
|
|
595
585
|
type: "function",
|
|
596
586
|
function: {
|
|
597
587
|
name: tool.name,
|
|
@@ -602,29 +592,5 @@ function convertTools(tools, compat) {
|
|
|
602
592
|
}))
|
|
603
593
|
};
|
|
604
594
|
}
|
|
605
|
-
function parseChunkUsage(rawUsage, model) {
|
|
606
|
-
const promptTokens = rawUsage.prompt_tokens || 0;
|
|
607
|
-
const cacheReadTokens = rawUsage.prompt_tokens_details?.cached_tokens ?? rawUsage.prompt_cache_hit_tokens ?? 0;
|
|
608
|
-
const cacheWriteTokens = rawUsage.prompt_tokens_details?.cache_write_tokens || 0;
|
|
609
|
-
const input = Math.max(0, promptTokens - cacheReadTokens - cacheWriteTokens);
|
|
610
|
-
const outputTokens = rawUsage.completion_tokens || 0;
|
|
611
|
-
const usage = {
|
|
612
|
-
input,
|
|
613
|
-
output: outputTokens,
|
|
614
|
-
cacheRead: cacheReadTokens,
|
|
615
|
-
cacheWrite: cacheWriteTokens,
|
|
616
|
-
totalTokens: input + outputTokens + cacheReadTokens + cacheWriteTokens,
|
|
617
|
-
cost: {
|
|
618
|
-
input: 0,
|
|
619
|
-
output: 0,
|
|
620
|
-
cacheRead: 0,
|
|
621
|
-
cacheWrite: 0,
|
|
622
|
-
total: 0
|
|
623
|
-
}
|
|
624
|
-
};
|
|
625
|
-
calculateCost(model, usage);
|
|
626
|
-
applyProviderReportedUsageCost(usage, rawUsage.cost);
|
|
627
|
-
return usage;
|
|
628
|
-
}
|
|
629
595
|
//#endregion
|
|
630
596
|
export { streamOpenAICompletions as n, streamSimpleOpenAICompletions as r, openai_completions_exports as t };
|
package/dist/{openai-completions-compat-DBWjXoMZ.d.mts → openai-completions-compat-Dt3dcawL.d.mts}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { E as Model, O as OpenAICompletionsCompat } from "./types-
|
|
2
|
-
import { a as AiProviderRequestPolicyInput, i as AiProviderRequestCapabilities } from "./host-
|
|
1
|
+
import { E as Model, O as OpenAICompletionsCompat } from "./types-BHNrPS1l.mjs";
|
|
2
|
+
import { a as AiProviderRequestPolicyInput, i as AiProviderRequestCapabilities } from "./host-vWgMMhiJ.mjs";
|
|
3
3
|
|
|
4
4
|
//#region packages/ai/src/transports/openai-completions-compat.d.ts
|
|
5
5
|
type ProviderRequestCapabilities = AiProviderRequestCapabilities;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { n as getEnvApiKey, r as __exportAll } from "./env-api-keys-DrgeBuva.mjs";
|
|
2
|
-
import { t as AssistantMessageEventStream } from "./event-stream-
|
|
3
|
-
import { n as getAiTransportHost } from "./host-
|
|
2
|
+
import { t as AssistantMessageEventStream } from "./event-stream-uSMZJ3FA.mjs";
|
|
3
|
+
import { n as getAiTransportHost } from "./host-DTqNc7ad.mjs";
|
|
4
|
+
import { S as supportsOpenAITemperature } from "./openai-responses-contracts-CyfIkQi5.mjs";
|
|
4
5
|
import { n as clampOpenAIPromptCacheKey } from "./openai-prompt-cache-mZTCdRPo.mjs";
|
|
5
6
|
import { t as resolveCacheRetention } from "./cache-retention-0x979a5V.mjs";
|
|
6
|
-
import {
|
|
7
|
+
import { n as buildBaseOptions } from "./simple-options-D58D5Kvw.mjs";
|
|
8
|
+
import { a as resolveResponsesReasoningEffort, i as createResponsesAssistantOutput, n as applyResponsesServiceTierPricing, o as runResponsesStreamLifecycle, r as convertResponsesMessages, t as applyCommonResponsesParams } from "./openai-responses-shared-DXIt3iY5.mjs";
|
|
7
9
|
import { i as resolveCloudflareBaseUrl, n as hasCopilotVisionInput, r as isCloudflareProvider, t as buildCopilotDynamicHeaders } from "./github-copilot-headers-NCJtz9i0.mjs";
|
|
8
|
-
import { n as buildBaseOptions } from "./simple-options-9lhRrN73.mjs";
|
|
9
|
-
import { a as runResponsesStreamLifecycle, i as resolveResponsesReasoningEffort, n as convertResponsesMessages, r as createResponsesAssistantOutput, t as applyCommonResponsesParams } from "./openai-responses-shared-pXl6Wd8S.mjs";
|
|
10
10
|
import OpenAI from "openai";
|
|
11
11
|
//#region packages/ai/src/providers/openai-responses.ts
|
|
12
12
|
var openai_responses_exports = /* @__PURE__ */ __exportAll({
|
|
@@ -23,19 +23,6 @@ function getCompat(model) {
|
|
|
23
23
|
function getPromptCacheRetention(compat, cacheRetention) {
|
|
24
24
|
return cacheRetention === "long" && compat.supportsLongCacheRetention ? "24h" : void 0;
|
|
25
25
|
}
|
|
26
|
-
function formatOpenAIResponsesError(error) {
|
|
27
|
-
if (error instanceof Error) {
|
|
28
|
-
const status = error.status;
|
|
29
|
-
const statusCode = typeof status === "number" ? status : void 0;
|
|
30
|
-
if (statusCode !== void 0) return `OpenAI API error (${statusCode}): ${error.message}`;
|
|
31
|
-
return error.message;
|
|
32
|
-
}
|
|
33
|
-
try {
|
|
34
|
-
return JSON.stringify(error);
|
|
35
|
-
} catch {
|
|
36
|
-
return String(error);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
26
|
/**
|
|
40
27
|
* Generate function for OpenAI Responses API
|
|
41
28
|
*/
|
|
@@ -51,12 +38,11 @@ const streamOpenAIResponses = (model, context, options) => {
|
|
|
51
38
|
const cacheSessionId = resolveCacheRetention(options?.cacheRetention) === "none" ? void 0 : options?.sessionId;
|
|
52
39
|
return createClient(model, context, apiKey, options?.headers, cacheSessionId);
|
|
53
40
|
},
|
|
54
|
-
buildParams: () => buildParams(model, context, options),
|
|
41
|
+
buildParams: (_requestModel, replayMode) => buildParams(model, context, options, replayMode),
|
|
55
42
|
processStreamOptions: {
|
|
56
43
|
serviceTier: options?.serviceTier,
|
|
57
|
-
applyServiceTierPricing: (usage, serviceTier) =>
|
|
58
|
-
}
|
|
59
|
-
formatError: formatOpenAIResponsesError
|
|
44
|
+
applyServiceTierPricing: (usage, serviceTier) => applyResponsesServiceTierPricing(usage, serviceTier, model)
|
|
45
|
+
}
|
|
60
46
|
});
|
|
61
47
|
return stream;
|
|
62
48
|
};
|
|
@@ -64,10 +50,12 @@ const streamSimpleOpenAIResponses = (model, context, options) => {
|
|
|
64
50
|
const apiKey = options?.apiKey || getEnvApiKey(model.provider);
|
|
65
51
|
if (!apiKey) throw new Error(`No API key for provider: ${model.provider}`);
|
|
66
52
|
const base = buildBaseOptions(model, options, apiKey);
|
|
53
|
+
const replayOptions = options;
|
|
67
54
|
return streamOpenAIResponses(model, context, {
|
|
68
55
|
...base,
|
|
56
|
+
authProfileId: replayOptions?.authProfileId,
|
|
69
57
|
reasoningEffort: resolveResponsesReasoningEffort(model, options?.reasoning),
|
|
70
|
-
replayResponsesItemIds:
|
|
58
|
+
replayResponsesItemIds: replayOptions?.replayResponsesItemIds
|
|
71
59
|
});
|
|
72
60
|
};
|
|
73
61
|
function createClient(model, context, apiKey, optionsHeaders, sessionId) {
|
|
@@ -100,8 +88,13 @@ function createClient(model, context, apiKey, optionsHeaders, sessionId) {
|
|
|
100
88
|
fetch: getAiTransportHost().buildModelFetch(model)
|
|
101
89
|
});
|
|
102
90
|
}
|
|
103
|
-
function buildParams(model, context, options) {
|
|
104
|
-
const messages = convertResponsesMessages(model, context, OPENAI_TOOL_CALL_PROVIDERS, {
|
|
91
|
+
function buildParams(model, context, options, replayMode = "checkpoint") {
|
|
92
|
+
const messages = convertResponsesMessages(model, context, OPENAI_TOOL_CALL_PROVIDERS, {
|
|
93
|
+
replayResponsesItemIds: options?.replayResponsesItemIds ?? false,
|
|
94
|
+
sessionId: options?.sessionId,
|
|
95
|
+
authProfileId: options?.authProfileId,
|
|
96
|
+
replayMode
|
|
97
|
+
});
|
|
105
98
|
const cacheRetention = resolveCacheRetention(options?.cacheRetention);
|
|
106
99
|
const compat = getCompat(model);
|
|
107
100
|
const params = {
|
|
@@ -118,21 +111,5 @@ function buildParams(model, context, options) {
|
|
|
118
111
|
applyCommonResponsesParams(params, model, context, options, { setDefaultReasoningOff: model.provider !== "github-copilot" });
|
|
119
112
|
return params;
|
|
120
113
|
}
|
|
121
|
-
function getServiceTierCostMultiplier(model, serviceTier) {
|
|
122
|
-
switch (serviceTier) {
|
|
123
|
-
case "flex": return .5;
|
|
124
|
-
case "priority": return model.id === "gpt-5.5" ? 2.5 : 2;
|
|
125
|
-
default: return 1;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
function applyServiceTierPricing(usage, serviceTier, model) {
|
|
129
|
-
const multiplier = getServiceTierCostMultiplier(model, serviceTier);
|
|
130
|
-
if (multiplier === 1) return;
|
|
131
|
-
usage.cost.input *= multiplier;
|
|
132
|
-
usage.cost.output *= multiplier;
|
|
133
|
-
usage.cost.cacheRead *= multiplier;
|
|
134
|
-
usage.cost.cacheWrite *= multiplier;
|
|
135
|
-
usage.cost.total = usage.cost.input + usage.cost.output + usage.cost.cacheRead + usage.cost.cacheWrite;
|
|
136
|
-
}
|
|
137
114
|
//#endregion
|
|
138
115
|
export { streamOpenAIResponses as n, streamSimpleOpenAIResponses as r, openai_responses_exports as t };
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import { n as PROVIDER_POST_DISPATCH_AMBIGUITY_ERROR_CODE, t as PROVIDER_FAILURE_WITH_OUTPUT_ERROR_CODE } from "./types-BDdaOVi2.mjs";
|
|
2
|
+
import "./src-D2H6yKkH.mjs";
|
|
3
|
+
import { a as normalizeOptionalString, n as normalizeLowercaseStringOrEmpty } from "./string-coerce-fsri9iCu.mjs";
|
|
4
|
+
import { a as isRecord } from "./record-coerce-DdXsgUd_.mjs";
|
|
5
|
+
//#region packages/normalization-core/src/string-normalization.ts
|
|
6
|
+
/** Coerces entries to strings, trims them, and drops empty results. */
|
|
7
|
+
function normalizeStringEntries(list) {
|
|
8
|
+
return (list ?? []).map((entry) => normalizeOptionalString(String(entry)) ?? "").filter(Boolean);
|
|
9
|
+
}
|
|
10
|
+
/** Returns first-seen unique values while preserving insertion order. */
|
|
11
|
+
function uniqueValues(values) {
|
|
12
|
+
return [...new Set(values)];
|
|
13
|
+
}
|
|
14
|
+
/** Returns first-seen unique strings while preserving insertion order. */
|
|
15
|
+
function uniqueStrings(values) {
|
|
16
|
+
return uniqueValues(values);
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region packages/ai/src/providers/openai-reasoning-effort.ts
|
|
20
|
+
/**
|
|
21
|
+
* OpenAI-compatible reasoning-effort normalization. Different GPT families
|
|
22
|
+
* expose different accepted effort enums, so callers map requested values here
|
|
23
|
+
* before constructing provider payloads.
|
|
24
|
+
*/
|
|
25
|
+
const GPT_5_REASONING_EFFORTS = [
|
|
26
|
+
"minimal",
|
|
27
|
+
"low",
|
|
28
|
+
"medium",
|
|
29
|
+
"high"
|
|
30
|
+
];
|
|
31
|
+
const GPT_51_REASONING_EFFORTS = [
|
|
32
|
+
"none",
|
|
33
|
+
"low",
|
|
34
|
+
"medium",
|
|
35
|
+
"high"
|
|
36
|
+
];
|
|
37
|
+
const GPT_52_REASONING_EFFORTS = [
|
|
38
|
+
"none",
|
|
39
|
+
"low",
|
|
40
|
+
"medium",
|
|
41
|
+
"high",
|
|
42
|
+
"xhigh"
|
|
43
|
+
];
|
|
44
|
+
const GPT_56_REASONING_EFFORTS = [
|
|
45
|
+
"none",
|
|
46
|
+
"low",
|
|
47
|
+
"medium",
|
|
48
|
+
"high",
|
|
49
|
+
"xhigh",
|
|
50
|
+
"max"
|
|
51
|
+
];
|
|
52
|
+
const GPT_CODEX_REASONING_EFFORTS = [
|
|
53
|
+
"low",
|
|
54
|
+
"medium",
|
|
55
|
+
"high",
|
|
56
|
+
"xhigh"
|
|
57
|
+
];
|
|
58
|
+
const GPT_PRO_REASONING_EFFORTS = [
|
|
59
|
+
"medium",
|
|
60
|
+
"high",
|
|
61
|
+
"xhigh"
|
|
62
|
+
];
|
|
63
|
+
const GPT_5_PRO_REASONING_EFFORTS = ["high"];
|
|
64
|
+
const GPT_51_CODEX_MAX_REASONING_EFFORTS = [
|
|
65
|
+
"none",
|
|
66
|
+
"medium",
|
|
67
|
+
"high",
|
|
68
|
+
"xhigh"
|
|
69
|
+
];
|
|
70
|
+
const GPT_51_CODEX_MINI_REASONING_EFFORTS = ["medium"];
|
|
71
|
+
const GENERIC_REASONING_EFFORTS = [
|
|
72
|
+
"low",
|
|
73
|
+
"medium",
|
|
74
|
+
"high"
|
|
75
|
+
];
|
|
76
|
+
const CANONICAL_REASONING_EFFORTS = /* @__PURE__ */ new Set([
|
|
77
|
+
"none",
|
|
78
|
+
"minimal",
|
|
79
|
+
"low",
|
|
80
|
+
"medium",
|
|
81
|
+
"high",
|
|
82
|
+
"xhigh",
|
|
83
|
+
"max",
|
|
84
|
+
"off"
|
|
85
|
+
]);
|
|
86
|
+
function normalizeModelId(id) {
|
|
87
|
+
return normalizeLowercaseStringOrEmpty(id ?? "").replace(/-\d{4}-\d{2}-\d{2}$/u, "");
|
|
88
|
+
}
|
|
89
|
+
/** Return whether a model is the GPT-5.4 mini family. */
|
|
90
|
+
function isOpenAIGpt54MiniModel(model) {
|
|
91
|
+
const id = normalizeModelId(typeof model.id === "string" ? model.id : void 0);
|
|
92
|
+
return /^gpt-5\.4-mini(?:-|$)/u.test(id);
|
|
93
|
+
}
|
|
94
|
+
/** Return whether a model is the GPT-5.5 family. */
|
|
95
|
+
function isOpenAIGpt55Model(model) {
|
|
96
|
+
const id = normalizeModelId(typeof model.id === "string" ? model.id : void 0);
|
|
97
|
+
const name = normalizeModelId(typeof model.name === "string" ? model.name : void 0);
|
|
98
|
+
return /^gpt-5\.5(?:-|$)/u.test(id) || /^gpt-5\.5(?:\s|\(|-|$)/u.test(name);
|
|
99
|
+
}
|
|
100
|
+
/** Return whether a model is the GPT-5.6 family. */
|
|
101
|
+
function isOpenAIGpt56Model(model) {
|
|
102
|
+
const id = normalizeModelId(typeof model.id === "string" ? model.id : void 0);
|
|
103
|
+
const name = normalizeModelId(typeof model.name === "string" ? model.name : void 0);
|
|
104
|
+
return /^gpt-5\.6(?:-|$)/u.test(id) || /^gpt-5\.6(?:\s|\(|-|$)/u.test(name);
|
|
105
|
+
}
|
|
106
|
+
/** Normalize user-facing reasoning effort names to API effort names. */
|
|
107
|
+
function normalizeOpenAIReasoningEffort(effort) {
|
|
108
|
+
const trimmed = effort.trim();
|
|
109
|
+
const folded = trimmed.toLowerCase();
|
|
110
|
+
return CANONICAL_REASONING_EFFORTS.has(folded) ? folded : trimmed;
|
|
111
|
+
}
|
|
112
|
+
function readCompatReasoningEfforts(compat) {
|
|
113
|
+
if (!compat || typeof compat !== "object") return;
|
|
114
|
+
if (compat.supportsReasoningEffort === false) return [];
|
|
115
|
+
const raw = compat.supportedReasoningEfforts;
|
|
116
|
+
if (!Array.isArray(raw)) return;
|
|
117
|
+
const supported = uniqueStrings(normalizeStringEntries(raw.filter((value) => typeof value === "string")));
|
|
118
|
+
return supported.length > 0 ? supported : void 0;
|
|
119
|
+
}
|
|
120
|
+
function isDisabledReasoningEffort(effort) {
|
|
121
|
+
return effort === "none" || effort === "off";
|
|
122
|
+
}
|
|
123
|
+
/** Resolve the reasoning efforts accepted by a specific OpenAI-compatible model. */
|
|
124
|
+
function resolveOpenAISupportedReasoningEfforts(model) {
|
|
125
|
+
const compatEfforts = readCompatReasoningEfforts(model.compat);
|
|
126
|
+
if (compatEfforts) return compatEfforts;
|
|
127
|
+
const id = normalizeModelId(typeof model.id === "string" ? model.id : void 0);
|
|
128
|
+
if (/^gpt-5\.6(?:-|$)/u.test(id)) return GPT_56_REASONING_EFFORTS;
|
|
129
|
+
if (id === "gpt-5.1-codex-mini") return GPT_51_CODEX_MINI_REASONING_EFFORTS;
|
|
130
|
+
if (id === "gpt-5.1-codex-max") return GPT_51_CODEX_MAX_REASONING_EFFORTS;
|
|
131
|
+
if (/^gpt-5(?:\.\d+)?-codex(?:-|$)/u.test(id)) return GPT_CODEX_REASONING_EFFORTS;
|
|
132
|
+
if (id === "gpt-5-pro") return GPT_5_PRO_REASONING_EFFORTS;
|
|
133
|
+
if (/^gpt-5\.[2-9](?:\.\d+)?-pro(?:-|$)/u.test(id)) return GPT_PRO_REASONING_EFFORTS;
|
|
134
|
+
if (/^gpt-5\.[2-9](?:\.\d+)?(?:-|$)/u.test(id)) return GPT_52_REASONING_EFFORTS;
|
|
135
|
+
if (/^gpt-5\.1(?:-|$)/u.test(id)) return GPT_51_REASONING_EFFORTS;
|
|
136
|
+
if (/^gpt-5(?:-|$)/u.test(id)) return GPT_5_REASONING_EFFORTS;
|
|
137
|
+
return GENERIC_REASONING_EFFORTS;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Return whether a model accepts the temperature parameter. The GPT-5.6
|
|
141
|
+
* family rejects it with a 400; catalog compat can override per model.
|
|
142
|
+
*/
|
|
143
|
+
function supportsOpenAITemperature(model) {
|
|
144
|
+
const compat = model.compat;
|
|
145
|
+
if (compat && typeof compat === "object") {
|
|
146
|
+
const declared = compat.supportsTemperature;
|
|
147
|
+
if (typeof declared === "boolean") return declared;
|
|
148
|
+
}
|
|
149
|
+
const id = normalizeModelId(typeof model.id === "string" ? model.id : void 0);
|
|
150
|
+
return !/^gpt-5\.6(?:-|$)/u.test(id);
|
|
151
|
+
}
|
|
152
|
+
/** Return whether a model accepts a requested reasoning effort. */
|
|
153
|
+
function supportsOpenAIReasoningEffort(model, effort) {
|
|
154
|
+
return resolveOpenAISupportedReasoningEfforts(model).includes(normalizeOpenAIReasoningEffort(effort));
|
|
155
|
+
}
|
|
156
|
+
/** Resolve a requested reasoning effort to the closest value supported by the model. */
|
|
157
|
+
function resolveOpenAIReasoningEffortForModel(params) {
|
|
158
|
+
const requested = normalizeOpenAIReasoningEffort(params.effort);
|
|
159
|
+
const mapped = params.fallbackMap?.[requested] ?? (params.fallbackMap && CANONICAL_REASONING_EFFORTS.has(requested) ? Object.entries(params.fallbackMap).find(([effort]) => normalizeOpenAIReasoningEffort(effort) === requested)?.[1] : void 0);
|
|
160
|
+
const normalized = mapped === void 0 ? requested : mapped.trim();
|
|
161
|
+
const supported = resolveOpenAISupportedReasoningEfforts(params.model);
|
|
162
|
+
if (supported.includes(normalized)) return normalized;
|
|
163
|
+
if (requested === "off" && supported.includes("none")) return "none";
|
|
164
|
+
if (isDisabledReasoningEffort(requested) || isDisabledReasoningEffort(normalized)) return;
|
|
165
|
+
if (requested === "minimal" && supported.includes("low")) return "low";
|
|
166
|
+
if ((requested === "minimal" || requested === "low") && supported.includes("medium")) return "medium";
|
|
167
|
+
if (requested === "xhigh" && supported.includes("high")) return "high";
|
|
168
|
+
if (requested === "max" && supported.includes("xhigh")) return "xhigh";
|
|
169
|
+
return supported.find((effort) => !isDisabledReasoningEffort(normalizeOpenAIReasoningEffort(effort)));
|
|
170
|
+
}
|
|
171
|
+
//#endregion
|
|
172
|
+
//#region packages/ai/src/transports/openai-responses-contracts.ts
|
|
173
|
+
const DEFAULT_AZURE_OPENAI_API_VERSION = "preview";
|
|
174
|
+
const OPENAI_CODEX_RESPONSES_DEFAULT_INSTRUCTIONS = "Follow the user request.";
|
|
175
|
+
const AZURE_RESPONSES_FIRST_EVENT_TIMEOUT_MS = 3e4;
|
|
176
|
+
const RESPONSE_FAILED_NO_DETAILS_MESSAGE = "Unknown error (no error details in response)";
|
|
177
|
+
const OPENAI_RESPONSES_REASONING_REPLAY_META_KEY = "__openclaw_replay";
|
|
178
|
+
const OPENAI_RESPONSES_REASONING_REPLAY_BLOCK_META_KEY = "openclawReasoningReplay";
|
|
179
|
+
const OPENAI_RESPONSES_COMPACTION_REPLAY_TYPE = "openai-responses-compaction";
|
|
180
|
+
const OPENAI_RESPONSES_APIS = /* @__PURE__ */ new Set([
|
|
181
|
+
"openai-responses",
|
|
182
|
+
"azure-openai-responses",
|
|
183
|
+
"openai-chatgpt-responses",
|
|
184
|
+
"openclaw-openai-responses-transport",
|
|
185
|
+
"openclaw-openai-chatgpt-responses-transport",
|
|
186
|
+
"openclaw-azure-openai-responses-transport"
|
|
187
|
+
]);
|
|
188
|
+
var OpenAIResponsesWebSocketResponseFailedError = class extends Error {
|
|
189
|
+
constructor(hasOutput) {
|
|
190
|
+
super("OpenAI Responses WebSocket returned response.failed");
|
|
191
|
+
this.name = "OpenAIResponsesWebSocketResponseFailedError";
|
|
192
|
+
this.code = hasOutput ? PROVIDER_FAILURE_WITH_OUTPUT_ERROR_CODE : PROVIDER_POST_DISPATCH_AMBIGUITY_ERROR_CODE;
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
var OpenAIResponsesWebSocketPreDispatchError = class extends Error {
|
|
196
|
+
constructor(cause) {
|
|
197
|
+
super("OpenAI Responses WebSocket failed before request dispatch", { cause });
|
|
198
|
+
this.name = "OpenAIResponsesWebSocketPreDispatchError";
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
var OpenAIResponsesWebSocketPostDispatchError = class extends Error {
|
|
202
|
+
constructor(cause) {
|
|
203
|
+
super("OpenAI Responses WebSocket failed after request dispatch; outcome is unknown", { cause });
|
|
204
|
+
this.code = PROVIDER_POST_DISPATCH_AMBIGUITY_ERROR_CODE;
|
|
205
|
+
this.name = "OpenAIResponsesWebSocketPostDispatchError";
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
var OpenAIResponsesWebSocketServerError = class extends Error {
|
|
209
|
+
constructor(code, status, param, message, cause) {
|
|
210
|
+
super(message, { cause });
|
|
211
|
+
this.code = code;
|
|
212
|
+
this.status = status;
|
|
213
|
+
this.param = param;
|
|
214
|
+
this.name = "OpenAIResponsesWebSocketServerError";
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
var OpenAIResponsesWebSocketSafeRetryError = class extends OpenAIResponsesWebSocketServerError {};
|
|
218
|
+
function readWebSocketServerError(value) {
|
|
219
|
+
if (!isRecord(value) || value.type !== "error") return;
|
|
220
|
+
const details = isRecord(value.error) ? value.error : value;
|
|
221
|
+
if (typeof details.code !== "string" || typeof details.message !== "string") return;
|
|
222
|
+
const rawStatus = value.status ?? value.status_code;
|
|
223
|
+
return {
|
|
224
|
+
code: details.code,
|
|
225
|
+
message: details.message,
|
|
226
|
+
param: typeof details.param === "string" ? details.param : null,
|
|
227
|
+
status: typeof rawStatus === "number" ? rawStatus : void 0
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
function parseOpenAIResponsesWebSocketServerError(cause) {
|
|
231
|
+
if (!isRecord(cause)) return;
|
|
232
|
+
let details = readWebSocketServerError(cause.error) ?? readWebSocketServerError(cause);
|
|
233
|
+
if (!details && typeof cause.message === "string") try {
|
|
234
|
+
details = readWebSocketServerError(JSON.parse(cause.message));
|
|
235
|
+
} catch {}
|
|
236
|
+
if (!details) return;
|
|
237
|
+
return new (details.code === "previous_response_not_found" || details.code === "websocket_connection_limit_reached" || details.code === "invalid_encrypted_content" || details.code === "thinking_signature_invalid" ? OpenAIResponsesWebSocketSafeRetryError : OpenAIResponsesWebSocketServerError)(details.code, details.status, details.param, details.message, cause);
|
|
238
|
+
}
|
|
239
|
+
const PROMPT_OBSERVER = Symbol("openaiResponsesPromptObserver");
|
|
240
|
+
const responsesPromptObserver = {
|
|
241
|
+
set(options, observer) {
|
|
242
|
+
Reflect.set(options, PROMPT_OBSERVER, observer);
|
|
243
|
+
},
|
|
244
|
+
get(options) {
|
|
245
|
+
return Reflect.get(options, PROMPT_OBSERVER);
|
|
246
|
+
},
|
|
247
|
+
copy(source, target) {
|
|
248
|
+
const observer = source && responsesPromptObserver.get(source);
|
|
249
|
+
if (observer) responsesPromptObserver.set(target, observer);
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
//#endregion
|
|
253
|
+
export { normalizeStringEntries as C, supportsOpenAITemperature as S, uniqueValues as T, isOpenAIGpt56Model as _, OPENAI_RESPONSES_COMPACTION_REPLAY_TYPE as a, resolveOpenAISupportedReasoningEfforts as b, OpenAIResponsesWebSocketPostDispatchError as c, OpenAIResponsesWebSocketSafeRetryError as d, RESPONSE_FAILED_NO_DETAILS_MESSAGE as f, isOpenAIGpt55Model as g, isOpenAIGpt54MiniModel as h, OPENAI_RESPONSES_APIS as i, OpenAIResponsesWebSocketPreDispatchError as l, responsesPromptObserver as m, DEFAULT_AZURE_OPENAI_API_VERSION as n, OPENAI_RESPONSES_REASONING_REPLAY_BLOCK_META_KEY as o, parseOpenAIResponsesWebSocketServerError as p, OPENAI_CODEX_RESPONSES_DEFAULT_INSTRUCTIONS as r, OPENAI_RESPONSES_REASONING_REPLAY_META_KEY as s, AZURE_RESPONSES_FIRST_EVENT_TIMEOUT_MS as t, OpenAIResponsesWebSocketResponseFailedError as u, normalizeOpenAIReasoningEffort as v, uniqueStrings as w, supportsOpenAIReasoningEffort as x, resolveOpenAIReasoningEffortForModel as y };
|