@openclaw/ai 2026.8.1-beta.2 → 2026.9.1-beta.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-SrGtwsJu.d.mts → anthropic-BECQCNdF.d.mts} +0 -2
- package/dist/{anthropic-B6dLpq5L.mjs → anthropic-DI4PZKKB.mjs} +46 -34
- package/dist/{anthropic-compaction-replay-8lJNKXOE.mjs → anthropic-compaction-replay-nhKaCXu6.mjs} +17 -22
- package/dist/{anthropic-payload-policy-CiEuQS72.d.mts → anthropic-payload-policy-B_0n0enE.d.mts} +3 -1
- package/dist/{api-registry-k3zTz0cV.d.mts → api-registry-CTd8NzcD.d.mts} +2 -1
- package/dist/{azure-openai-responses-mxIOtUnn.mjs → azure-openai-responses-D8dI0ekg.mjs} +3 -3
- package/dist/diagnostics.d.mts +0 -1
- package/dist/diagnostics.mjs +1 -1
- package/dist/event-stream-BKp4fOt_.d.mts +1 -0
- package/dist/{event-stream-BP6AWT8j.d.mts → event-stream-LiXePESD.d.mts} +1 -2
- package/dist/event-stream.d.mts +2 -1
- package/dist/{google-C7h2QzDX.mjs → google-Od-LLdVK.mjs} +3 -3
- package/dist/{google-shared-B0Qr9OR7.mjs → google-shared-Bgr9lFPw.mjs} +22 -8
- package/dist/{google-vertex-Bhc3TjDl.mjs → google-vertex-aerRSXc4.mjs} +4 -4
- package/dist/{host-DTqNc7ad.mjs → host-D51fmkH6.mjs} +40 -33
- package/dist/{host-vWgMMhiJ.d.mts → host-DsbPMFU6.d.mts} +7 -7
- package/dist/index-Qbej8io0.d.mts +3 -0
- package/dist/index.d.mts +8 -8
- package/dist/index.mjs +2 -3
- package/dist/internal/anthropic.d.mts +13 -6
- package/dist/internal/anthropic.mjs +4 -4
- package/dist/internal/openai-responses-payload-policy.d.mts +2 -2
- package/dist/internal/openai-responses-payload-policy.mjs +2 -2
- package/dist/internal/openai.d.mts +6 -6
- package/dist/internal/openai.mjs +10 -8
- package/dist/internal/runtime.d.mts +18 -5
- package/dist/internal/runtime.mjs +8 -7
- package/dist/internal/shared.d.mts +18 -4
- 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-EiHdymeb.mjs} +59 -49
- package/dist/{openai-chatgpt-responses-CrPmqERt.mjs → openai-chatgpt-responses-DHpF9o1e.mjs} +42 -17
- package/dist/{openai-completions-BPnt4Sml.mjs → openai-completions-EFPiUGfS.mjs} +60 -257
- package/dist/{openai-completions-compat-Dt3dcawL.d.mts → openai-completions-compat-BefmHT26.d.mts} +3 -3
- package/dist/openai-completions-stream-DUlGwRMz.mjs +1621 -0
- package/dist/{openai-responses-DhIKtOup.mjs → openai-responses-BogP8OjX.mjs} +6 -5
- package/dist/{openai-responses-contracts-XpZJxrRG.d.mts → openai-responses-contracts-Dvj_UtPy.d.mts} +3 -3
- package/dist/{openai-responses-contracts-CyfIkQi5.mjs → openai-responses-contracts-QUY12X0B.mjs} +6 -26
- package/dist/{openai-responses-payload-policy-BSs371VM.d.mts → openai-responses-payload-policy-CNGFT9zr.d.mts} +1 -0
- package/dist/{openai-responses-payload-policy-BDxV-W0c.mjs → openai-responses-payload-policy-D8EdimYe.mjs} +6 -8
- package/dist/{openai-responses-prompt-observer-internal-DgNTYnRY.mjs → openai-responses-prompt-observer-internal-Cd4hJG-S.mjs} +3 -3
- package/dist/{openai-responses-shared-DXIt3iY5.mjs → openai-responses-shared-DJThc6jW.mjs} +205 -1472
- package/dist/openai-stop-reason-Drnn_6Qj.mjs +28 -0
- package/dist/openai-tool-schema-ho-hIkQf.mjs +1695 -0
- package/dist/{provider-error-BUwEnjXq.mjs → provider-error-DDOs_Bz0.mjs} +20 -27
- package/dist/provider-options-AvldWZt8.mjs +21 -0
- package/dist/{provider-options-B96RdNpH.d.mts → provider-options-MdMBLzlU.d.mts} +15 -4
- package/dist/provider-transcript-transform-C01bQ5a3.mjs +32 -0
- package/dist/provider-types.d.mts +7 -5
- package/dist/providers.d.mts +1 -2
- package/dist/providers.mjs +9 -9
- package/dist/{reasoning-tag-text-partitioner-rnPwX2pg.mjs → reasoning-tag-text-partitioner-5ygO2rZc.mjs} +3 -0
- package/dist/{sanitize-unicode-BYqrYtC_.mjs → sanitize-unicode-DCkltN94.mjs} +1 -2
- package/dist/{simple-options-D58D5Kvw.mjs → simple-options-CFj7x3J4.mjs} +5 -4
- package/dist/{anthropic-JsNA5KCu.mjs → src-Bu3FiFAG.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-ljShVIZB.mjs +342 -0
- package/dist/transport-stream-shared-rvaCyFYt.d.mts +138 -0
- package/dist/{transport-utils-DJqkxbhC.mjs → transport-utils-LJ1_rbi-.mjs} +8 -5
- package/dist/transports.d.mts +45 -106
- package/dist/transports.mjs +134 -1089
- package/dist/{types-BHNrPS1l.d.mts → types-DhLoJbFm.d.mts} +49 -17
- package/dist/types-GiAjXatj.d.mts +1 -0
- 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-Dk7q7NMN.d.mts} +1 -2
- package/dist/validation.d.mts +1 -1
- package/package.json +5 -5
- package/dist/index-BVVgDSdq.d.mts +0 -1
- 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,18 +1,15 @@
|
|
|
1
1
|
import { n as getEnvApiKey, r as __exportAll } from "./env-api-keys-DrgeBuva.mjs";
|
|
2
2
|
import { t as AssistantMessageEventStream } from "./event-stream-uSMZJ3FA.mjs";
|
|
3
|
-
import { i as clampThinkingLevel } from "./sanitize-unicode-
|
|
4
|
-
import { n as getAiTransportHost } from "./host-
|
|
5
|
-
import { n as projectProviderError } from "./provider-error-
|
|
3
|
+
import { i as clampThinkingLevel } from "./sanitize-unicode-DCkltN94.mjs";
|
|
4
|
+
import { n as getAiTransportHost } from "./host-D51fmkH6.mjs";
|
|
5
|
+
import { n as projectProviderError } from "./provider-error-DDOs_Bz0.mjs";
|
|
6
6
|
import { n as clampOpenAIPromptCacheKey } from "./openai-prompt-cache-mZTCdRPo.mjs";
|
|
7
7
|
import { t as resolveCacheRetention } from "./cache-retention-0x979a5V.mjs";
|
|
8
|
-
import { c as splitSystemPromptCacheBoundary, f as sortPromptCacheToolsByName, n as buildBaseOptions } from "./simple-options-
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
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";
|
|
8
|
+
import { c as splitSystemPromptCacheBoundary, f as sortPromptCacheToolsByName, n as buildBaseOptions } from "./simple-options-CFj7x3J4.mjs";
|
|
9
|
+
import { _ as transportAbortError, y as withProviderResponseHook } from "./transport-stream-shared-ljShVIZB.mjs";
|
|
10
|
+
import { E as tagUnresolvedTextAsCommentary, S as shouldOmitOllamaCompatResponseFormat, _ as hasToolCallHistory, b as resolveOpenAICompletionsCompat, g as convertMessages, h as resolveOpenAIReasoningEffortMap, t as processCompletionsStream, v as finalizeOpenAICompletionsToolCalls, w as clearPendingCommentaryText, x as resolveOpenAICompletionsResponseFormat } from "./openai-completions-stream-DUlGwRMz.mjs";
|
|
11
|
+
import { C as createOpenAIProviderAcceptanceHook, T as isOpenAICompletionsThinkingEnabled, j as resolveOpenAIClientBaseUrl, v as projectOpenAITools, y as reconcileOpenAICompletionsToolChoice } from "./openai-tool-schema-ho-hIkQf.mjs";
|
|
12
|
+
import { i as getFirstStreamEventTimeoutMs, r as getFirstStreamEventTimeoutHandler, t as createFirstStreamEventAbortController } from "./stream-first-event-timeout-MK28puvq.mjs";
|
|
16
13
|
import { i as resolveCloudflareBaseUrl, n as hasCopilotVisionInput, r as isCloudflareProvider, t as buildCopilotDynamicHeaders } from "./github-copilot-headers-NCJtz9i0.mjs";
|
|
17
14
|
import OpenAI from "openai";
|
|
18
15
|
//#region packages/ai/src/providers/openai-completions.ts
|
|
@@ -21,11 +18,6 @@ var openai_completions_exports = /* @__PURE__ */ __exportAll({
|
|
|
21
18
|
streamOpenAICompletions: () => streamOpenAICompletions,
|
|
22
19
|
streamSimpleOpenAICompletions: () => streamSimpleOpenAICompletions
|
|
23
20
|
});
|
|
24
|
-
function isEncryptedReasoningDetail(detail) {
|
|
25
|
-
if (typeof detail !== "object" || detail === null) return false;
|
|
26
|
-
const candidate = detail;
|
|
27
|
-
return candidate.type === "reasoning.encrypted" && typeof candidate.id === "string" && candidate.id.length > 0 && typeof candidate.data === "string" && candidate.data.length > 0;
|
|
28
|
-
}
|
|
29
21
|
const streamOpenAICompletions = (model, context, options) => {
|
|
30
22
|
const stream = new AssistantMessageEventStream();
|
|
31
23
|
(async () => {
|
|
@@ -57,6 +49,7 @@ const streamOpenAICompletions = (model, context, options) => {
|
|
|
57
49
|
try {
|
|
58
50
|
const apiKey = options?.apiKey || getEnvApiKey(model.provider) || "";
|
|
59
51
|
const compat = resolveOpenAICompletionsCompat(model);
|
|
52
|
+
const shouldEmitReasoning = Boolean(model.reasoning && options?.reasoningEffort && isOpenAICompletionsThinkingEnabled(options.reasoningEffort));
|
|
60
53
|
const cacheRetention = resolveCacheRetention(options?.cacheRetention);
|
|
61
54
|
const cacheSessionId = cacheRetention === "none" ? void 0 : options?.sessionId;
|
|
62
55
|
const client = createClient(model, context, apiKey, options?.headers, cacheSessionId, compat);
|
|
@@ -74,267 +67,75 @@ const streamOpenAICompletions = (model, context, options) => {
|
|
|
74
67
|
stream: openaiStream,
|
|
75
68
|
signal: firstEventAbort.signal,
|
|
76
69
|
abort: firstEventAbort.abort,
|
|
77
|
-
hook:
|
|
70
|
+
hook: createOpenAIProviderAcceptanceHook(options, response, model),
|
|
78
71
|
onReady: () => stream.push({
|
|
79
72
|
type: "start",
|
|
80
73
|
partial: output
|
|
81
74
|
})
|
|
82
75
|
});
|
|
83
|
-
let textBlock = null;
|
|
84
|
-
let thinkingBlock = null;
|
|
85
|
-
let hasFinishReason = false;
|
|
86
|
-
const toolCallBlocksByIndex = /* @__PURE__ */ new Map();
|
|
87
|
-
const toolCallBlocksById = /* @__PURE__ */ new Map();
|
|
88
|
-
const toolCallBlocksByFirstId = /* @__PURE__ */ new Map();
|
|
89
|
-
const normalizeToolCallDeltas = createOpenAICompletionsToolCallDeltaNormalizer();
|
|
90
|
-
const pendingReasoningDetailsByToolCallId = /* @__PURE__ */ new Map();
|
|
91
|
-
const blocks = output.content;
|
|
92
76
|
const finishedBlocks = /* @__PURE__ */ new Set();
|
|
93
77
|
const contentIndices = /* @__PURE__ */ new WeakMap();
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
blocks.push(block);
|
|
97
|
-
};
|
|
98
|
-
const getContentIndex = (block) => contentIndices.get(block) ?? -1;
|
|
99
|
-
const rememberFirstToolCallById = (id, block) => {
|
|
100
|
-
if (toolCallBlocksByFirstId.has(id)) return;
|
|
101
|
-
toolCallBlocksByFirstId.set(id, block);
|
|
102
|
-
const pendingDetail = pendingReasoningDetailsByToolCallId.get(id);
|
|
103
|
-
if (pendingDetail) {
|
|
104
|
-
block.thoughtSignature = pendingDetail;
|
|
105
|
-
pendingReasoningDetailsByToolCallId.delete(id);
|
|
106
|
-
}
|
|
107
|
-
};
|
|
78
|
+
let openTextBlock;
|
|
79
|
+
let openThinkingBlock;
|
|
108
80
|
const finishBlock = (block) => {
|
|
109
|
-
const contentIndex =
|
|
110
|
-
if (contentIndex ===
|
|
81
|
+
const contentIndex = contentIndices.get(block);
|
|
82
|
+
if (contentIndex === void 0 || finishedBlocks.has(block)) return;
|
|
111
83
|
finishedBlocks.add(block);
|
|
112
|
-
if (block.type === "text")
|
|
113
|
-
|
|
114
|
-
contentIndex,
|
|
115
|
-
content: block.text,
|
|
116
|
-
partial: output
|
|
117
|
-
});
|
|
118
|
-
else if (block.type === "thinking") stream.push({
|
|
119
|
-
type: "thinking_end",
|
|
120
|
-
contentIndex,
|
|
121
|
-
content: block.thinking,
|
|
122
|
-
partial: output
|
|
123
|
-
});
|
|
124
|
-
else if (block.type === "toolCall") stream.push({
|
|
125
|
-
type: "toolcall_end",
|
|
126
|
-
contentIndex,
|
|
127
|
-
toolCall: block,
|
|
128
|
-
partial: output
|
|
129
|
-
});
|
|
130
|
-
};
|
|
131
|
-
const ensureTextBlock = () => {
|
|
132
|
-
if (!textBlock) {
|
|
133
|
-
textBlock = {
|
|
134
|
-
type: "text",
|
|
135
|
-
text: ""
|
|
136
|
-
};
|
|
137
|
-
appendBlock(textBlock);
|
|
84
|
+
if (block.type === "text") {
|
|
85
|
+
openTextBlock = void 0;
|
|
138
86
|
stream.push({
|
|
139
|
-
type: "
|
|
140
|
-
contentIndex
|
|
87
|
+
type: "text_end",
|
|
88
|
+
contentIndex,
|
|
89
|
+
content: block.text,
|
|
141
90
|
partial: output
|
|
142
91
|
});
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
};
|
|
146
|
-
const ensureThinkingBlock = (thinkingSignature) => {
|
|
147
|
-
if (!thinkingBlock) {
|
|
148
|
-
thinkingBlock = {
|
|
149
|
-
type: "thinking",
|
|
150
|
-
thinking: "",
|
|
151
|
-
...thinkingSignature ? { thinkingSignature } : {}
|
|
152
|
-
};
|
|
153
|
-
appendBlock(thinkingBlock);
|
|
92
|
+
} else if (block.type === "thinking") {
|
|
93
|
+
openThinkingBlock = void 0;
|
|
154
94
|
stream.push({
|
|
155
|
-
type: "
|
|
156
|
-
contentIndex
|
|
95
|
+
type: "thinking_end",
|
|
96
|
+
contentIndex,
|
|
97
|
+
content: block.thinking,
|
|
157
98
|
partial: output
|
|
158
99
|
});
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
if (thinkingBlock && !reasoningTagTextPartitioner.isInsideReasoning()) {
|
|
164
|
-
finishBlock(thinkingBlock);
|
|
165
|
-
thinkingBlock = null;
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
|
-
const appendTextDelta = (delta) => {
|
|
169
|
-
sealNativeReasoningBeforeText();
|
|
170
|
-
const block = ensureTextBlock();
|
|
171
|
-
block.text += delta;
|
|
172
|
-
stream.push({
|
|
173
|
-
type: "text_delta",
|
|
174
|
-
contentIndex: getContentIndex(block),
|
|
175
|
-
delta,
|
|
176
|
-
partial: output
|
|
177
|
-
});
|
|
178
|
-
};
|
|
179
|
-
const appendThinkingDelta = (thinkingSignature, delta) => {
|
|
180
|
-
const block = ensureThinkingBlock(thinkingSignature);
|
|
181
|
-
block.thinking += delta;
|
|
182
|
-
stream.push({
|
|
183
|
-
type: "thinking_delta",
|
|
184
|
-
contentIndex: getContentIndex(block),
|
|
185
|
-
delta,
|
|
100
|
+
} else if (block.type === "toolCall") stream.push({
|
|
101
|
+
type: "toolcall_end",
|
|
102
|
+
contentIndex,
|
|
103
|
+
toolCall: block,
|
|
186
104
|
partial: output
|
|
187
105
|
});
|
|
188
106
|
};
|
|
189
|
-
const
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
type
|
|
196
|
-
id: toolCall.id || "",
|
|
197
|
-
name: toolCall.function?.name || "",
|
|
198
|
-
arguments: {},
|
|
199
|
-
partialArgs: "",
|
|
200
|
-
streamIndex
|
|
201
|
-
};
|
|
202
|
-
if (streamIndex !== void 0) toolCallBlocksByIndex.set(streamIndex, block);
|
|
203
|
-
if (toolCall.id) {
|
|
204
|
-
toolCallBlocksById.set(toolCall.id, block);
|
|
205
|
-
rememberFirstToolCallById(toolCall.id, block);
|
|
107
|
+
const directEventStream = { push(event) {
|
|
108
|
+
if (event.type === "text_start" || event.type === "thinking_start" || event.type === "toolcall_start") {
|
|
109
|
+
const block = output.content[event.contentIndex];
|
|
110
|
+
if (block) {
|
|
111
|
+
contentIndices.set(block, event.contentIndex);
|
|
112
|
+
if (block.type === "text") openTextBlock = block;
|
|
113
|
+
else if (block.type === "thinking") openThinkingBlock = block;
|
|
206
114
|
}
|
|
207
|
-
appendBlock(block);
|
|
208
|
-
stream.push({
|
|
209
|
-
type: "toolcall_start",
|
|
210
|
-
contentIndex: getContentIndex(block),
|
|
211
|
-
partial: output
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
if (streamIndex !== void 0 && block.streamIndex === void 0) {
|
|
215
|
-
block.streamIndex = streamIndex;
|
|
216
|
-
toolCallBlocksByIndex.set(streamIndex, block);
|
|
217
115
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
for await (const chunk of guardedOpenaiStream) {
|
|
240
|
-
if (!chunk || typeof chunk !== "object") continue;
|
|
241
|
-
notifyLlmRequestActivity(options?.signal);
|
|
242
|
-
output.responseId ||= chunk.id;
|
|
243
|
-
if (typeof chunk.model === "string" && chunk.model.length > 0 && chunk.model !== model.id) output.responseModel ||= chunk.model;
|
|
244
|
-
if (chunk.usage) output.usage = parseOpenAICompletionsUsage(chunk.usage, model, { includeReasoningTokens: false });
|
|
245
|
-
const choice = Array.isArray(chunk.choices) ? chunk.choices[0] : void 0;
|
|
246
|
-
if (!choice) continue;
|
|
247
|
-
const choiceUsage = choice.usage;
|
|
248
|
-
if (!chunk.usage && choiceUsage) output.usage = parseOpenAICompletionsUsage(choiceUsage, model, { includeReasoningTokens: false });
|
|
249
|
-
if (choice.finish_reason) {
|
|
250
|
-
const finishReasonResult = mapOpenAIStopReason(choice.finish_reason);
|
|
251
|
-
output.stopReason = finishReasonResult.stopReason;
|
|
252
|
-
if (finishReasonResult.errorMessage) output.errorMessage = finishReasonResult.errorMessage;
|
|
253
|
-
hasFinishReason = true;
|
|
254
|
-
}
|
|
255
|
-
const rawChoiceDelta = choice.delta ?? choice.message;
|
|
256
|
-
if (rawChoiceDelta) for (const normalizedDelta of normalizeToolCallDeltas(rawChoiceDelta, choice.finish_reason)) {
|
|
257
|
-
const choiceDelta = normalizedDelta.delta;
|
|
258
|
-
const reasoningFields = [
|
|
259
|
-
"reasoning_content",
|
|
260
|
-
"reasoning",
|
|
261
|
-
"reasoning_text"
|
|
262
|
-
];
|
|
263
|
-
const deltaFields = choiceDelta;
|
|
264
|
-
const shouldEmitReasoning = Boolean(model.reasoning && options?.reasoningEffort && isOpenAICompletionsThinkingEnabled(options.reasoningEffort));
|
|
265
|
-
let foundReasoningField = null;
|
|
266
|
-
for (const field of reasoningFields) {
|
|
267
|
-
const value = deltaFields[field];
|
|
268
|
-
if (typeof value === "string" && value.length > 0) {
|
|
269
|
-
foundReasoningField = field;
|
|
270
|
-
break;
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
if (foundReasoningField) reasoningTagTextPartitioner.markStrict();
|
|
274
|
-
if (shouldEmitReasoning && foundReasoningField) {
|
|
275
|
-
const delta = deltaFields[foundReasoningField];
|
|
276
|
-
if (typeof delta === "string" && delta.length > 0) appendThinkingDelta(model.provider === "opencode-go" && foundReasoningField === "reasoning" ? "reasoning_content" : foundReasoningField, delta);
|
|
277
|
-
}
|
|
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) {
|
|
284
|
-
flushPartitionedContent();
|
|
285
|
-
sealNativeReasoningBeforeText();
|
|
286
|
-
rememberPendingCommentaryTags(provisionalCommentaryTags, tagPendingCommentaryText(output.content));
|
|
287
|
-
for (const toolCall of toolCallDeltas) {
|
|
288
|
-
const block = ensureToolCallBlock(toolCall);
|
|
289
|
-
if (!block.id && toolCall.id) {
|
|
290
|
-
block.id = toolCall.id;
|
|
291
|
-
toolCallBlocksById.set(toolCall.id, block);
|
|
292
|
-
rememberFirstToolCallById(toolCall.id, block);
|
|
293
|
-
}
|
|
294
|
-
if (!block.name && toolCall.function?.name) block.name = toolCall.function.name;
|
|
295
|
-
let delta = "";
|
|
296
|
-
if (toolCall.function?.arguments) {
|
|
297
|
-
delta = toolCall.function.arguments;
|
|
298
|
-
block.partialArgs = (block.partialArgs ?? "") + toolCall.function.arguments;
|
|
299
|
-
block.arguments = parseStreamingJson(block.partialArgs);
|
|
300
|
-
}
|
|
301
|
-
stream.push({
|
|
302
|
-
type: "toolcall_delta",
|
|
303
|
-
contentIndex: getContentIndex(block),
|
|
304
|
-
delta,
|
|
305
|
-
partial: output
|
|
306
|
-
});
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
const reasoningDetails = choiceDelta.reasoning_details;
|
|
310
|
-
if (Array.isArray(reasoningDetails)) {
|
|
311
|
-
for (const detail of reasoningDetails) if (isEncryptedReasoningDetail(detail)) {
|
|
312
|
-
const serializedDetail = JSON.stringify(detail);
|
|
313
|
-
const matchingToolCall = toolCallBlocksByFirstId.get(detail.id);
|
|
314
|
-
if (matchingToolCall) matchingToolCall.thoughtSignature = serializedDetail;
|
|
315
|
-
else pendingReasoningDetailsByToolCallId.set(detail.id, serializedDetail);
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
flushPartitionedContent();
|
|
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"));
|
|
116
|
+
stream.push(event);
|
|
117
|
+
} };
|
|
118
|
+
try {
|
|
119
|
+
await processCompletionsStream(hookedOpenAIStream, output, model, directEventStream, {
|
|
120
|
+
mode: "direct",
|
|
121
|
+
beforeContentBlock(nextType) {
|
|
122
|
+
if (openThinkingBlock) finishBlock(openThinkingBlock);
|
|
123
|
+
if (openTextBlock && nextType !== "toolCall") finishBlock(openTextBlock);
|
|
124
|
+
},
|
|
125
|
+
provisionalCommentaryTags,
|
|
126
|
+
signal: options?.signal,
|
|
127
|
+
emitReasoning: shouldEmitReasoning,
|
|
128
|
+
firstEventTimeoutMs: getFirstStreamEventTimeoutMs(options),
|
|
129
|
+
abortFirstEventStream: firstEventAbort.abort,
|
|
130
|
+
onFirstEventTimeout: getFirstStreamEventTimeoutHandler(options)
|
|
131
|
+
});
|
|
132
|
+
if (options?.signal?.aborted) throw transportAbortError(options.signal);
|
|
133
|
+
if (output.stopReason === "aborted" || output.stopReason === "error") throw new Error(output.errorMessage || (output.stopReason === "aborted" ? "Request was aborted" : "Provider returned an invalid tool call"));
|
|
134
|
+
} catch (error) {
|
|
135
|
+
for (const block of output.content) if (block.type !== "toolCall") finishBlock(block);
|
|
136
|
+
throw error;
|
|
334
137
|
}
|
|
335
|
-
for (const block of
|
|
336
|
-
if (output.stopReason !== "toolUse") clearPendingCommentaryText(provisionalCommentaryTags);
|
|
337
|
-
if (output.stopReason === "toolUse") tagPendingCommentaryText(output.content);
|
|
138
|
+
for (const block of output.content) if (block.type !== "toolCall" || output.stopReason === "toolUse") finishBlock(block);
|
|
338
139
|
stream.push({
|
|
339
140
|
type: "done",
|
|
340
141
|
reason: output.stopReason,
|
|
@@ -345,6 +146,8 @@ const streamOpenAICompletions = (model, context, options) => {
|
|
|
345
146
|
const terminal = projectProviderError(error, options?.signal);
|
|
346
147
|
Object.assign(output, terminal);
|
|
347
148
|
finalizeOpenAICompletionsToolCalls(output, { allowSilentToolCallPromotion: false });
|
|
149
|
+
clearPendingCommentaryText(provisionalCommentaryTags);
|
|
150
|
+
tagUnresolvedTextAsCommentary(output);
|
|
348
151
|
for (const block of output.content) {
|
|
349
152
|
delete block.index;
|
|
350
153
|
delete block.partialArgs;
|
|
@@ -400,7 +203,7 @@ function createClient(model, context, apiKey, optionsHeaders, sessionId, compat
|
|
|
400
203
|
} : headers;
|
|
401
204
|
return new OpenAI({
|
|
402
205
|
apiKey,
|
|
403
|
-
baseURL: isCloudflareProvider(model.provider) ? resolveCloudflareBaseUrl(model) : model.baseUrl,
|
|
206
|
+
baseURL: resolveOpenAIClientBaseUrl(model, isCloudflareProvider(model.provider) ? resolveCloudflareBaseUrl(model) : model.baseUrl),
|
|
404
207
|
dangerouslyAllowBrowser: true,
|
|
405
208
|
defaultHeaders,
|
|
406
209
|
fetch: getAiTransportHost().buildModelFetch(model)
|
package/dist/{openai-completions-compat-Dt3dcawL.d.mts → openai-completions-compat-BefmHT26.d.mts}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
|
|
1
|
+
import { D as Model, k as OpenAICompletionsCompat } from "./types-DhLoJbFm.mjs";
|
|
2
|
+
import "./index-Qbej8io0.mjs";
|
|
3
|
+
import { a as AiProviderRequestPolicyInput, i as AiProviderRequestCapabilities } from "./host-DsbPMFU6.mjs";
|
|
4
4
|
//#region packages/ai/src/transports/openai-completions-compat.d.ts
|
|
5
5
|
type ProviderRequestCapabilities = AiProviderRequestCapabilities;
|
|
6
6
|
type OpenAICompletionsSessionAffinity = "none" | "openai" | "openrouter";
|