@openclaw/ai 2026.9.2 → 2026.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- package/dist/anthropic-CZy5U0NY.mjs +376 -0
- package/dist/{anthropic-payload-policy-d46X2pR0.d.mts → anthropic-payload-policy-wuRCb6MH.d.mts} +16 -6
- package/dist/{anthropic-compaction-replay-DB2FGLQc.mjs → anthropic-stream-reducer-B_yo_7pf.mjs} +923 -181
- package/dist/{api-registry-DWtPjzyn.d.mts → api-registry-CB1-1oQ2.d.mts} +2 -2
- package/dist/assistant-output-iqnlJCV2.mjs +16 -0
- package/dist/assistant-text-phase-C20rxWwP.mjs +55 -0
- package/dist/{azure-openai-responses-C5bZRfAP.mjs → azure-openai-responses-Crpa40QR.mjs} +5 -5
- package/dist/{base64-CEFBpSkN.mjs → base64-D-su8YVo.mjs} +1 -27
- package/dist/{diagnostics-DfFyKeX_.mjs → diagnostics-dV98PqIy.mjs} +96 -21
- package/dist/diagnostics.d.mts +3 -1
- package/dist/diagnostics.mjs +3 -3
- package/dist/{event-stream-BhT5T1Ay.d.mts → event-stream-C1Z2piyk.d.mts} +11 -3
- package/dist/{event-stream-BgDvQeum.mjs → event-stream-D8PARQfL.mjs} +45 -1
- package/dist/event-stream-I_GlBsuZ.d.mts +1 -0
- package/dist/event-stream.d.mts +2 -2
- package/dist/event-stream.mjs +1 -1
- package/dist/{github-copilot-headers-NCJtz9i0.mjs → github-copilot-headers-B37TB3rB.mjs} +3 -10
- package/dist/github-copilot-request-facts-BTEBMeOv.mjs +16 -0
- package/dist/{google-4qeuE8iX.mjs → google-BDPriaVe.mjs} +10 -10
- package/dist/google-messages-CVn9eFpF.mjs +449 -0
- package/dist/google-shared-BedY23XS.mjs +185 -0
- package/dist/{google-vertex-O9BcnB6X.mjs → google-vertex-DMz8XQCn.mjs} +7 -6
- package/dist/{host-CEvLw30U.mjs → host-CWuF-sS3.mjs} +44 -39
- package/dist/{host-DjzGmdZ2.d.mts → host-DK3wmS3e.d.mts} +3 -3
- package/dist/host-policy-CAopLRKA.mjs +37 -0
- package/dist/{index-FnHM2FcI.d.mts → index-CQ6LTHw8.d.mts} +3 -3
- package/dist/index.d.mts +6 -6
- package/dist/index.mjs +4 -4
- package/dist/internal/anthropic.d.mts +7 -7
- package/dist/internal/anthropic.mjs +4 -4
- package/dist/internal/google-model-family.d.mts +5 -0
- package/dist/internal/google-model-family.mjs +15 -0
- package/dist/internal/openai-responses-payload-policy.d.mts +1 -1
- package/dist/internal/openai-responses-payload-policy.mjs +1 -1
- package/dist/internal/openai.d.mts +8 -103
- package/dist/internal/openai.mjs +10 -10
- package/dist/internal/retry-after.d.mts +2 -4
- package/dist/internal/retry-after.mjs +57 -8
- package/dist/internal/runtime.d.mts +7 -6
- package/dist/internal/runtime.mjs +8 -7
- package/dist/internal/shared.d.mts +14 -3
- package/dist/internal/shared.mjs +6 -4
- package/dist/internal/tool-schema.d.mts +63 -0
- package/dist/internal/tool-schema.mjs +3 -0
- package/dist/{json-parse-BuAJEbdW.mjs → json-parse-Dw_hnxsA.mjs} +1 -1
- package/dist/{mistral-Tb6oalqH.mjs → mistral--m-Jm6VZ.mjs} +13 -37
- package/dist/model-transport-url-DKocrEsb.d.mts +28 -0
- package/dist/{openai-chatgpt-responses-yUXjPNfu.mjs → openai-chatgpt-responses-nDZccFW-.mjs} +48 -38
- package/dist/openai-completions-KuoZyx0d.mjs +187 -0
- package/dist/{openai-completions-compat-CpjYUArk.d.mts → openai-completions-compat-CXn3T1we.d.mts} +26 -4
- package/dist/{openai-completions-stream-BsrBe3Gg.mjs → openai-completions-stream-BQk3SkLD.mjs} +622 -452
- package/dist/openai-prompt-cache-BI0rkM-5.mjs +220 -0
- package/dist/openai-prompt-cache-rrutvqxq.d.mts +16 -0
- package/dist/openai-provider-client-ha_WxTyj.mjs +24 -0
- package/dist/openai-reasoning-effort-BK7FbcLT.mjs +167 -0
- package/dist/{openai-responses-CCL41ALM.mjs → openai-responses-D99dOzKI.mjs} +14 -29
- package/dist/{openai-responses-compaction-window-BMVHFOtq.mjs → openai-responses-compaction-window-D5jbzCi3.mjs} +7 -170
- package/dist/{openai-responses-contracts-rF5DDRNS.d.mts → openai-responses-contracts-B55afwRo.d.mts} +3 -3
- package/dist/{openai-responses-prompt-observer-internal-D0bhBfgL.mjs → openai-responses-prompt-observer-internal-tApyTLVu.mjs} +3 -3
- package/dist/{openai-responses-shared-Bmma_3Qc.mjs → openai-responses-shared-ZyQEzS5i.mjs} +44 -115
- package/dist/openai-tool-projection-793cE3QX.d.mts +37 -0
- package/dist/{openai-tool-schema-_pTAJqKF.mjs → openai-tool-schema-CzjyYXun.mjs} +38 -556
- package/dist/openai-tool-schema-ynZBgqW-.d.mts +38 -0
- package/dist/openai-transport-params-DNasp2fU.mjs +674 -0
- package/dist/{provider-error-9TraxGvt.mjs → provider-error-C6TbKiey.mjs} +23 -6
- package/dist/{provider-options-Bcc_p-TU.d.mts → provider-options-BXr9Ec83.d.mts} +4 -39
- package/dist/{provider-transcript-transform-BaMbI1hr.mjs → provider-transcript-transform-pPmUIwKt.mjs} +1 -1
- package/dist/provider-types-CAV0Og3m.d.mts +29 -0
- package/dist/provider-types.d.mts +6 -31
- package/dist/providers.d.mts +2 -2
- package/dist/providers.mjs +11 -11
- package/dist/{reasoning-tag-text-partitioner-DLCNXki6.mjs → reasoning-tag-text-partitioner-BQBi4B9d.mjs} +19 -12
- package/dist/record-coerce-DwRYMj3t.mjs +32 -0
- package/dist/retry-after-CdCURCVg.d.mts +15 -0
- package/dist/{sanitize-unicode-D6xUvZaS.mjs → sanitize-unicode-Bb-v9meu.mjs} +1 -1
- package/dist/session-affinity-CCH7eYdB.mjs +20 -0
- package/dist/{simple-options-BjHCCh4v.mjs → simple-options-tcKOqnpF.mjs} +3 -3
- package/dist/{src-2qBGKg8O.mjs → src-B2Q_6G8V.mjs} +1 -1
- package/dist/{stream-first-event-timeout-DcNjoFQE.mjs → stream-first-event-timeout-2hfrquuz.mjs} +1 -1
- package/dist/string-coerce-fsri9iCu.mjs +34 -0
- package/dist/{string-normalization--fwJ4S2q.mjs → string-normalization-CmLIasuf.mjs} +1 -1
- package/dist/{tool-schema-json-projection-mJhXDcyz.mjs → tool-schema-json-projection-ClptDdAO.mjs} +2 -38
- package/dist/{transport-stream-shared-CZqMhfIw.mjs → transport-stream-shared-Cu3ZPhNW.mjs} +5 -5
- package/dist/{transport-stream-shared-xnaqxmbP.d.mts → transport-stream-shared-DOxpGJ-H.d.mts} +4 -4
- package/dist/transport-utils-CCooe-cr.mjs +121 -0
- package/dist/transports.d.mts +113 -41
- package/dist/transports.mjs +162 -1276
- package/dist/types-BADKjDBI.d.mts +1 -0
- package/dist/{types-CJ1-Ht7A.d.mts → types-Dy1q0CSu.d.mts} +72 -57
- package/dist/types.d.mts +5 -5
- package/dist/types.mjs +3 -3
- package/dist/utf16-slice-CvGodqok.mjs +29 -0
- package/dist/{validation-CJZtym2g.mjs → validation-BDzVDnTs.mjs} +9 -1
- package/dist/{validation-AKZBDGQd.d.mts → validation-CaFUZN9B.d.mts} +1 -1
- package/dist/validation.d.mts +1 -1
- package/dist/validation.mjs +1 -1
- package/package.json +13 -3
- package/dist/anthropic-BDdqdVLK.mjs +0 -886
- package/dist/event-stream-zctLx0yr.d.mts +0 -1
- package/dist/google-shared-CWeG8RIl.mjs +0 -636
- package/dist/google-thinking-level-C-V3tecN.mjs +0 -9
- package/dist/openai-completions-BIUV3RDT.mjs +0 -403
- package/dist/openai-prompt-cache-CGnVB74a.mjs +0 -21
- package/dist/openai-prompt-cache-CNoIfHYC.d.mts +0 -16
- package/dist/transport-utils-7il795_9.mjs +0 -138
- package/dist/types-3Lnm-QSJ.d.mts +0 -1
- package/dist/utf16-slice-qz3nsy87.mjs +0 -84
|
@@ -1,403 +0,0 @@
|
|
|
1
|
-
import { t as __exportAll } from "./rolldown-runtime-BhDjJH2R.mjs";
|
|
2
|
-
import { t as AssistantMessageEventStream } from "./event-stream-BgDvQeum.mjs";
|
|
3
|
-
import { i as clampThinkingLevel } from "./sanitize-unicode-D6xUvZaS.mjs";
|
|
4
|
-
import { n as getAiTransportHost } from "./host-CEvLw30U.mjs";
|
|
5
|
-
import { n as clampOpenAIPromptCacheKey } from "./openai-prompt-cache-CGnVB74a.mjs";
|
|
6
|
-
import { t as resolveCacheRetention } from "./cache-retention-0x979a5V.mjs";
|
|
7
|
-
import { m as sortPromptCacheToolsByName, n as buildBaseOptions, o as reasoningTagTextPolicy, u as splitSystemPromptCacheBoundary } from "./simple-options-BjHCCh4v.mjs";
|
|
8
|
-
import { n as getEnvApiKey } from "./env-api-keys-bktO00EJ.mjs";
|
|
9
|
-
import { _ as transportAbortError, t as assignTransportErrorDetails, y as withProviderResponseHook } from "./transport-stream-shared-CZqMhfIw.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-BsrBe3Gg.mjs";
|
|
11
|
-
import { C as createOpenAIProviderAcceptanceHook, T as isOpenAICompletionsThinkingEnabled, j as resolveOpenAIClientBaseUrl, v as projectOpenAITools, y as reconcileOpenAICompletionsToolChoice } from "./openai-tool-schema-_pTAJqKF.mjs";
|
|
12
|
-
import { i as getFirstStreamEventTimeoutMs, r as getFirstStreamEventTimeoutHandler, t as createFirstStreamEventAbortController } from "./stream-first-event-timeout-DcNjoFQE.mjs";
|
|
13
|
-
import { i as resolveCloudflareBaseUrl, n as hasCopilotVisionInput, r as isCloudflareProvider, t as buildCopilotDynamicHeaders } from "./github-copilot-headers-NCJtz9i0.mjs";
|
|
14
|
-
import OpenAI from "openai";
|
|
15
|
-
//#region packages/ai/src/providers/openai-completions.ts
|
|
16
|
-
var openai_completions_exports = /* @__PURE__ */ __exportAll({
|
|
17
|
-
convertMessages: () => convertMessages,
|
|
18
|
-
streamOpenAICompletions: () => streamOpenAICompletions,
|
|
19
|
-
streamSimpleOpenAICompletions: () => streamSimpleOpenAICompletions
|
|
20
|
-
});
|
|
21
|
-
const streamOpenAICompletions = (model, context, options) => {
|
|
22
|
-
const stream = new AssistantMessageEventStream();
|
|
23
|
-
(async () => {
|
|
24
|
-
const output = {
|
|
25
|
-
role: "assistant",
|
|
26
|
-
content: [],
|
|
27
|
-
api: model.api,
|
|
28
|
-
provider: model.provider,
|
|
29
|
-
model: model.id,
|
|
30
|
-
usage: {
|
|
31
|
-
input: 0,
|
|
32
|
-
output: 0,
|
|
33
|
-
cacheRead: 0,
|
|
34
|
-
cacheWrite: 0,
|
|
35
|
-
totalTokens: 0,
|
|
36
|
-
cost: {
|
|
37
|
-
input: 0,
|
|
38
|
-
output: 0,
|
|
39
|
-
cacheRead: 0,
|
|
40
|
-
cacheWrite: 0,
|
|
41
|
-
total: 0
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
stopReason: "stop",
|
|
45
|
-
timestamp: Date.now()
|
|
46
|
-
};
|
|
47
|
-
const provisionalCommentaryTags = /* @__PURE__ */ new Map();
|
|
48
|
-
let firstEventAbort;
|
|
49
|
-
try {
|
|
50
|
-
const apiKey = options?.apiKey || getEnvApiKey(model.provider) || "";
|
|
51
|
-
const compat = resolveOpenAICompletionsCompat(model);
|
|
52
|
-
const shouldEmitReasoning = Boolean(model.reasoning && options?.reasoningEffort && isOpenAICompletionsThinkingEnabled(options.reasoningEffort));
|
|
53
|
-
const cacheRetention = resolveCacheRetention(options?.cacheRetention);
|
|
54
|
-
const cacheSessionId = cacheRetention === "none" ? void 0 : options?.sessionId;
|
|
55
|
-
const client = createClient(model, context, apiKey, options?.headers, cacheSessionId, compat);
|
|
56
|
-
let params = buildParams(model, context, options, compat, cacheRetention);
|
|
57
|
-
const nextParams = await options?.onPayload?.(params, model);
|
|
58
|
-
if (nextParams !== void 0) params = nextParams;
|
|
59
|
-
firstEventAbort = createFirstStreamEventAbortController(options?.signal);
|
|
60
|
-
const requestOptions = {
|
|
61
|
-
signal: firstEventAbort.signal,
|
|
62
|
-
...options?.timeoutMs !== void 0 ? { timeout: options.timeoutMs } : {},
|
|
63
|
-
maxRetries: 0
|
|
64
|
-
};
|
|
65
|
-
const { data: openaiStream, response } = await client.chat.completions.create(params, requestOptions).withResponse();
|
|
66
|
-
const hookedOpenAIStream = withProviderResponseHook({
|
|
67
|
-
stream: openaiStream,
|
|
68
|
-
signal: firstEventAbort.signal,
|
|
69
|
-
abort: firstEventAbort.abort,
|
|
70
|
-
hook: createOpenAIProviderAcceptanceHook(options, response, model),
|
|
71
|
-
onReady: () => stream.push({
|
|
72
|
-
type: "start",
|
|
73
|
-
partial: output
|
|
74
|
-
})
|
|
75
|
-
});
|
|
76
|
-
const finishedBlocks = /* @__PURE__ */ new Set();
|
|
77
|
-
const contentIndices = /* @__PURE__ */ new WeakMap();
|
|
78
|
-
let openTextBlock;
|
|
79
|
-
let openThinkingBlock;
|
|
80
|
-
const finishBlock = (block) => {
|
|
81
|
-
const contentIndex = contentIndices.get(block);
|
|
82
|
-
if (contentIndex === void 0 || finishedBlocks.has(block)) return;
|
|
83
|
-
finishedBlocks.add(block);
|
|
84
|
-
if (block.type === "text") {
|
|
85
|
-
openTextBlock = void 0;
|
|
86
|
-
stream.push({
|
|
87
|
-
type: "text_end",
|
|
88
|
-
contentIndex,
|
|
89
|
-
content: block.text,
|
|
90
|
-
partial: output
|
|
91
|
-
});
|
|
92
|
-
} else if (block.type === "thinking") {
|
|
93
|
-
openThinkingBlock = void 0;
|
|
94
|
-
stream.push({
|
|
95
|
-
type: "thinking_end",
|
|
96
|
-
contentIndex,
|
|
97
|
-
content: block.thinking,
|
|
98
|
-
partial: output
|
|
99
|
-
});
|
|
100
|
-
} else if (block.type === "toolCall") stream.push({
|
|
101
|
-
type: "toolcall_end",
|
|
102
|
-
contentIndex,
|
|
103
|
-
toolCall: block,
|
|
104
|
-
partial: output
|
|
105
|
-
});
|
|
106
|
-
};
|
|
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;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
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
|
-
strictReasoningTags: reasoningTagTextPolicy.isStrict(options),
|
|
129
|
-
firstEventTimeoutMs: getFirstStreamEventTimeoutMs(options),
|
|
130
|
-
abortFirstEventStream: firstEventAbort.abort,
|
|
131
|
-
onFirstEventTimeout: getFirstStreamEventTimeoutHandler(options)
|
|
132
|
-
});
|
|
133
|
-
if (options?.signal?.aborted) throw transportAbortError(options.signal);
|
|
134
|
-
if (output.stopReason === "aborted" || output.stopReason === "error") throw new Error(output.errorMessage || (output.stopReason === "aborted" ? "Request was aborted" : "Provider returned an invalid tool call"));
|
|
135
|
-
} catch (error) {
|
|
136
|
-
for (const block of output.content) if (block.type !== "toolCall") finishBlock(block);
|
|
137
|
-
throw error;
|
|
138
|
-
}
|
|
139
|
-
for (const block of output.content) if (block.type !== "toolCall" || output.stopReason === "toolUse") finishBlock(block);
|
|
140
|
-
stream.push({
|
|
141
|
-
type: "done",
|
|
142
|
-
reason: output.stopReason,
|
|
143
|
-
message: output
|
|
144
|
-
});
|
|
145
|
-
stream.end();
|
|
146
|
-
} catch (error) {
|
|
147
|
-
const terminal = assignTransportErrorDetails(output, error, options?.signal);
|
|
148
|
-
finalizeOpenAICompletionsToolCalls(output, { allowSilentToolCallPromotion: false });
|
|
149
|
-
clearPendingCommentaryText(provisionalCommentaryTags);
|
|
150
|
-
tagUnresolvedTextAsCommentary(output);
|
|
151
|
-
for (const block of output.content) {
|
|
152
|
-
delete block.index;
|
|
153
|
-
delete block.partialArgs;
|
|
154
|
-
delete block.streamIndex;
|
|
155
|
-
}
|
|
156
|
-
stream.push({
|
|
157
|
-
type: "error",
|
|
158
|
-
reason: terminal.stopReason,
|
|
159
|
-
error: output
|
|
160
|
-
});
|
|
161
|
-
stream.end();
|
|
162
|
-
} finally {
|
|
163
|
-
firstEventAbort?.dispose();
|
|
164
|
-
}
|
|
165
|
-
})();
|
|
166
|
-
return stream;
|
|
167
|
-
};
|
|
168
|
-
const streamSimpleOpenAICompletions = (model, context, options) => {
|
|
169
|
-
const apiKey = options?.apiKey || getEnvApiKey(model.provider);
|
|
170
|
-
if (!apiKey) throw new Error(`No API key for provider: ${model.provider}`);
|
|
171
|
-
const base = buildBaseOptions(model, options, apiKey);
|
|
172
|
-
const clampedReasoning = options?.reasoning ? clampThinkingLevel(model, options.reasoning) : void 0;
|
|
173
|
-
const reasoningEffort = clampedReasoning === "off" ? void 0 : clampedReasoning === "max" ? "xhigh" : clampedReasoning;
|
|
174
|
-
const toolChoice = options?.toolChoice;
|
|
175
|
-
return streamOpenAICompletions(model, context, {
|
|
176
|
-
...base,
|
|
177
|
-
reasoningEffort,
|
|
178
|
-
toolChoice
|
|
179
|
-
});
|
|
180
|
-
};
|
|
181
|
-
function createClient(model, context, apiKey, optionsHeaders, sessionId, compat = resolveOpenAICompletionsCompat(model)) {
|
|
182
|
-
if (!apiKey) throw new Error(`No API key for provider: ${model.provider}`);
|
|
183
|
-
const headers = { ...model.headers };
|
|
184
|
-
if (model.provider === "github-copilot") {
|
|
185
|
-
const hasImages = hasCopilotVisionInput(context.messages);
|
|
186
|
-
const copilotHeaders = buildCopilotDynamicHeaders({
|
|
187
|
-
messages: context.messages,
|
|
188
|
-
hasImages
|
|
189
|
-
});
|
|
190
|
-
Object.assign(headers, copilotHeaders);
|
|
191
|
-
}
|
|
192
|
-
if (sessionId && compat.sessionAffinity !== "none") {
|
|
193
|
-
if (compat.sessionAffinity === "openrouter") headers["x-session-id"] = sessionId;
|
|
194
|
-
else {
|
|
195
|
-
headers.session_id = sessionId;
|
|
196
|
-
headers["x-client-request-id"] = sessionId;
|
|
197
|
-
headers["x-session-affinity"] = sessionId;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
if (optionsHeaders) Object.assign(headers, optionsHeaders);
|
|
201
|
-
const defaultHeaders = model.provider === "cloudflare-ai-gateway" ? {
|
|
202
|
-
...headers,
|
|
203
|
-
Authorization: headers.Authorization ?? null,
|
|
204
|
-
"cf-aig-authorization": `Bearer ${apiKey}`
|
|
205
|
-
} : headers;
|
|
206
|
-
const baseUrl = isCloudflareProvider(model.provider) ? resolveCloudflareBaseUrl(model) : model.baseUrl;
|
|
207
|
-
return new OpenAI({
|
|
208
|
-
apiKey,
|
|
209
|
-
baseURL: resolveOpenAIClientBaseUrl(model, baseUrl),
|
|
210
|
-
dangerouslyAllowBrowser: true,
|
|
211
|
-
defaultHeaders,
|
|
212
|
-
maxRetries: 0,
|
|
213
|
-
fetch: getAiTransportHost().buildModelFetch(model)
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
function buildParams(model, context, options, compat = resolveOpenAICompletionsCompat(model), cacheRetention = resolveCacheRetention(options?.cacheRetention)) {
|
|
217
|
-
const cacheControl = getCompatCacheControl(compat, cacheRetention);
|
|
218
|
-
const cacheOptOutIndexes = /* @__PURE__ */ new Set();
|
|
219
|
-
const messages = convertMessages(model, context, compat, {
|
|
220
|
-
cacheOptOutIndexes,
|
|
221
|
-
preserveSystemPromptCacheBoundary: cacheControl !== void 0
|
|
222
|
-
});
|
|
223
|
-
const supportsPromptCacheKey = model.baseUrl.includes("api.openai.com") || compat.supportsPromptCacheKey;
|
|
224
|
-
const promptCacheKey = supportsPromptCacheKey && cacheRetention !== "none" ? clampOpenAIPromptCacheKey(options?.promptCacheKey ?? options?.sessionId) : void 0;
|
|
225
|
-
const params = {
|
|
226
|
-
model: model.id,
|
|
227
|
-
messages,
|
|
228
|
-
stream: true,
|
|
229
|
-
prompt_cache_key: promptCacheKey,
|
|
230
|
-
prompt_cache_retention: supportsPromptCacheKey && cacheRetention === "long" && compat.supportsLongCacheRetention ? "24h" : void 0
|
|
231
|
-
};
|
|
232
|
-
if (compat.supportsUsageInStreaming) params.stream_options = { include_usage: true };
|
|
233
|
-
if (compat.supportsStore) params.store = false;
|
|
234
|
-
if (options?.maxTokens) {
|
|
235
|
-
const maxTokens = clampOpenAICompletionsMaxTokens(model, options.maxTokens);
|
|
236
|
-
if (compat.maxTokensField === "max_tokens") params.max_tokens = maxTokens;
|
|
237
|
-
else params.max_completion_tokens = maxTokens;
|
|
238
|
-
}
|
|
239
|
-
if (options?.temperature !== void 0) params.temperature = options.temperature;
|
|
240
|
-
if (options?.stop !== void 0 && options.stop.length > 0) params.stop = options.stop;
|
|
241
|
-
const requestedResponseFormat = options?.responseFormat;
|
|
242
|
-
const responseFormat = requestedResponseFormat === void 0 ? void 0 : resolveOpenAICompletionsResponseFormat(shouldOmitOllamaCompatResponseFormat({
|
|
243
|
-
provider: model.provider,
|
|
244
|
-
baseUrl: model.baseUrl,
|
|
245
|
-
hasTools: () => Boolean(context.tools?.length)
|
|
246
|
-
}) ? void 0 : requestedResponseFormat, compat.supportsJsonSchemaResponseFormat);
|
|
247
|
-
if (responseFormat !== void 0) params.response_format = responseFormat;
|
|
248
|
-
let toolProjection;
|
|
249
|
-
if (context.tools) {
|
|
250
|
-
const converted = convertTools(context.tools, compat);
|
|
251
|
-
toolProjection = converted.projection;
|
|
252
|
-
if (converted.tools.length > 0) params.tools = converted.tools;
|
|
253
|
-
else if (hasToolCallHistory(context.messages)) params.tools = [];
|
|
254
|
-
if (compat.zaiToolStream && converted.tools.length > 0) params.tool_stream = true;
|
|
255
|
-
} else if (hasToolCallHistory(context.messages)) params.tools = [];
|
|
256
|
-
if (cacheControl) applyAnthropicCacheControl(messages, params.tools, cacheControl, cacheOptOutIndexes);
|
|
257
|
-
if (options?.toolChoice) {
|
|
258
|
-
const toolChoice = reconcileOpenAICompletionsToolChoice(options.toolChoice, toolProjection ?? projectOpenAITools([]));
|
|
259
|
-
if (toolChoice !== void 0) params.tool_choice = toolChoice;
|
|
260
|
-
}
|
|
261
|
-
const reasoningEffortMap = resolveOpenAIReasoningEffortMap(model);
|
|
262
|
-
const thinkingLevelMap = model.thinkingLevelMap;
|
|
263
|
-
const offReasoningEffort = reasoningEffortMap.off ?? model.thinkingLevelMap?.off;
|
|
264
|
-
const reasoningEffort = options?.reasoningEffort === void 0 ? offReasoningEffort ?? void 0 : reasoningEffortMap[options.reasoningEffort] ?? thinkingLevelMap?.[options.reasoningEffort] ?? options.reasoningEffort;
|
|
265
|
-
const reasoningEnabled = reasoningEffort !== void 0 && reasoningEffort !== "none";
|
|
266
|
-
if (compat.thinkingFormat === "zai" && model.reasoning) params.thinking = reasoningEnabled ? {
|
|
267
|
-
type: "enabled",
|
|
268
|
-
clear_thinking: false
|
|
269
|
-
} : { type: "disabled" };
|
|
270
|
-
else if (compat.thinkingFormat === "qwen" && model.reasoning) params.enable_thinking = reasoningEnabled;
|
|
271
|
-
else if (compat.thinkingFormat === "qwen-chat-template" && model.reasoning) params.chat_template_kwargs = {
|
|
272
|
-
enable_thinking: reasoningEnabled,
|
|
273
|
-
preserve_thinking: true
|
|
274
|
-
};
|
|
275
|
-
else if (compat.thinkingFormat === "deepseek" && model.reasoning) {
|
|
276
|
-
params.thinking = { type: reasoningEnabled ? "enabled" : "disabled" };
|
|
277
|
-
if (reasoningEnabled && compat.supportsReasoningEffort) params.reasoning_effort = reasoningEffort;
|
|
278
|
-
} else if (compat.thinkingFormat === "openrouter" && model.reasoning) {
|
|
279
|
-
const openRouterParams = params;
|
|
280
|
-
if (reasoningEnabled) openRouterParams.reasoning = { effort: reasoningEffort };
|
|
281
|
-
else if (offReasoningEffort !== null) openRouterParams.reasoning = { effort: offReasoningEffort ?? "none" };
|
|
282
|
-
} else if (compat.thinkingFormat === "together" && model.reasoning) {
|
|
283
|
-
const togetherParams = params;
|
|
284
|
-
togetherParams.reasoning = { enabled: reasoningEnabled };
|
|
285
|
-
if (reasoningEnabled && compat.supportsReasoningEffort) togetherParams.reasoning_effort = reasoningEffort;
|
|
286
|
-
} else if (reasoningEnabled && model.reasoning && compat.supportsReasoningEffort) params.reasoning_effort = reasoningEffort;
|
|
287
|
-
else if (model.reasoning && compat.supportsReasoningEffort) {
|
|
288
|
-
if (typeof offReasoningEffort === "string") params.reasoning_effort = offReasoningEffort;
|
|
289
|
-
}
|
|
290
|
-
if (compat.openRouterRouting) params.provider = compat.openRouterRouting;
|
|
291
|
-
if (model.baseUrl.includes("ai-gateway.vercel.sh") && model.compat?.vercelGatewayRouting) {
|
|
292
|
-
const routing = model.compat.vercelGatewayRouting;
|
|
293
|
-
if (routing.only || routing.order) {
|
|
294
|
-
const gatewayOptions = {};
|
|
295
|
-
if (routing.only) gatewayOptions.only = routing.only;
|
|
296
|
-
if (routing.order) gatewayOptions.order = routing.order;
|
|
297
|
-
params.providerOptions = { gateway: gatewayOptions };
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
return params;
|
|
301
|
-
}
|
|
302
|
-
function clampOpenAICompletionsMaxTokens(model, requestedMaxTokens) {
|
|
303
|
-
const modelMaxTokens = typeof model.maxTokens === "number" && Number.isFinite(model.maxTokens) && model.maxTokens > 0 ? Math.floor(model.maxTokens) : void 0;
|
|
304
|
-
return modelMaxTokens === void 0 || requestedMaxTokens <= modelMaxTokens ? requestedMaxTokens : modelMaxTokens;
|
|
305
|
-
}
|
|
306
|
-
function getCompatCacheControl(compat, cacheRetention) {
|
|
307
|
-
if (compat.cacheControlFormat !== "anthropic" || cacheRetention === "none") return;
|
|
308
|
-
const ttl = cacheRetention === "long" && compat.supportsLongCacheRetention ? "1h" : void 0;
|
|
309
|
-
return {
|
|
310
|
-
type: "ephemeral",
|
|
311
|
-
...ttl ? { ttl } : {}
|
|
312
|
-
};
|
|
313
|
-
}
|
|
314
|
-
function applyAnthropicCacheControl(messages, tools, cacheControl, cacheOptOutIndexes) {
|
|
315
|
-
addCacheControlToSystemPrompt(messages, cacheControl);
|
|
316
|
-
addCacheControlToLastTool(tools, cacheControl);
|
|
317
|
-
addCacheControlToLastConversationMessage(messages, cacheControl, cacheOptOutIndexes);
|
|
318
|
-
}
|
|
319
|
-
function addCacheControlToSystemPrompt(messages, cacheControl) {
|
|
320
|
-
for (const message of messages) if (message.role === "system" || message.role === "developer") {
|
|
321
|
-
addCacheControlToInstructionMessage(message, cacheControl);
|
|
322
|
-
return;
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
function addCacheControlToLastConversationMessage(messages, cacheControl, cacheOptOutIndexes) {
|
|
326
|
-
for (let i = messages.length - 1; i >= 0; i--) {
|
|
327
|
-
const message = messages[i];
|
|
328
|
-
if (!message || cacheOptOutIndexes.has(i)) continue;
|
|
329
|
-
if (message.role === "user" || message.role === "assistant") {
|
|
330
|
-
if (addCacheControlToMessage(message, cacheControl)) return;
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
function addCacheControlToLastTool(tools, cacheControl) {
|
|
335
|
-
if (!tools || tools.length === 0) return;
|
|
336
|
-
const lastTool = tools.at(-1);
|
|
337
|
-
if (!lastTool) return;
|
|
338
|
-
lastTool.cache_control = cacheControl;
|
|
339
|
-
}
|
|
340
|
-
function addCacheControlToInstructionMessage(message, cacheControl) {
|
|
341
|
-
return addCacheControlToTextContent(message, cacheControl);
|
|
342
|
-
}
|
|
343
|
-
function addCacheControlToMessage(message, cacheControl) {
|
|
344
|
-
if (message.role === "user" || message.role === "assistant") return addCacheControlToTextContent(message, cacheControl);
|
|
345
|
-
return false;
|
|
346
|
-
}
|
|
347
|
-
function addCacheControlToTextContent(message, cacheControl) {
|
|
348
|
-
const content = message.content;
|
|
349
|
-
if (typeof content === "string") {
|
|
350
|
-
if (content.length === 0) return false;
|
|
351
|
-
message.content = buildCacheControlledTextParts(content, cacheControl);
|
|
352
|
-
return true;
|
|
353
|
-
}
|
|
354
|
-
if (!Array.isArray(content)) return false;
|
|
355
|
-
for (let i = content.length - 1; i >= 0; i--) {
|
|
356
|
-
const part = content[i];
|
|
357
|
-
if (part?.type === "text") {
|
|
358
|
-
const text = part.text;
|
|
359
|
-
content.splice(i, 1, ...buildCacheControlledTextParts(text, cacheControl));
|
|
360
|
-
return true;
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
return false;
|
|
364
|
-
}
|
|
365
|
-
function buildCacheControlledTextParts(text, cacheControl) {
|
|
366
|
-
const split = splitSystemPromptCacheBoundary(text);
|
|
367
|
-
if (!split) return [{
|
|
368
|
-
type: "text",
|
|
369
|
-
text,
|
|
370
|
-
cache_control: cacheControl
|
|
371
|
-
}];
|
|
372
|
-
const parts = [];
|
|
373
|
-
if (split.stablePrefix) parts.push({
|
|
374
|
-
type: "text",
|
|
375
|
-
text: split.stablePrefix,
|
|
376
|
-
cache_control: cacheControl
|
|
377
|
-
});
|
|
378
|
-
if (split.dynamicSuffix) parts.push({
|
|
379
|
-
type: "text",
|
|
380
|
-
text: split.dynamicSuffix
|
|
381
|
-
});
|
|
382
|
-
return parts.length > 0 ? parts : [{
|
|
383
|
-
type: "text",
|
|
384
|
-
text: ""
|
|
385
|
-
}];
|
|
386
|
-
}
|
|
387
|
-
function convertTools(tools, compat) {
|
|
388
|
-
const projection = projectOpenAITools(tools);
|
|
389
|
-
return {
|
|
390
|
-
projection,
|
|
391
|
-
tools: sortPromptCacheToolsByName(projection.tools).map((tool) => ({
|
|
392
|
-
type: "function",
|
|
393
|
-
function: {
|
|
394
|
-
name: tool.name,
|
|
395
|
-
description: tool.description,
|
|
396
|
-
parameters: tool.parameters,
|
|
397
|
-
...compat.supportsStrictMode && { strict: false }
|
|
398
|
-
}
|
|
399
|
-
}))
|
|
400
|
-
};
|
|
401
|
-
}
|
|
402
|
-
//#endregion
|
|
403
|
-
export { streamOpenAICompletions as n, streamSimpleOpenAICompletions as r, openai_completions_exports as t };
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
//#region packages/ai/src/providers/openai-prompt-cache.ts
|
|
2
|
-
/** Selects the documented cache lifetime fields for a Responses request. */
|
|
3
|
-
function resolveOpenAIResponsesCacheParams(model, cacheRetention, supportsLongCacheRetention) {
|
|
4
|
-
if (cacheRetention === "none") return {};
|
|
5
|
-
if (model.id === "gpt-6-astra" && model.api === "openai-responses") {
|
|
6
|
-
const endpoint = URL.parse(model.baseUrl ?? "https://api.openai.com/v1");
|
|
7
|
-
if (endpoint?.protocol === "https:" && (endpoint.hostname === "api.openai.com" || endpoint.hostname.endsWith(".api.openai.com"))) return { prompt_cache_options: { ttl: "30m" } };
|
|
8
|
-
}
|
|
9
|
-
return cacheRetention === "long" && supportsLongCacheRetention ? { prompt_cache_retention: "24h" } : {};
|
|
10
|
-
}
|
|
11
|
-
/** Maximum prompt cache key length accepted by OpenAI-compatible request metadata. */
|
|
12
|
-
const OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH = 64;
|
|
13
|
-
/** Truncates a prompt cache key by Unicode code point count. */
|
|
14
|
-
function clampOpenAIPromptCacheKey(key) {
|
|
15
|
-
if (key === void 0) return;
|
|
16
|
-
const chars = Array.from(key);
|
|
17
|
-
if (chars.length <= 64) return key;
|
|
18
|
-
return chars.slice(0, 64).join("");
|
|
19
|
-
}
|
|
20
|
-
//#endregion
|
|
21
|
-
export { clampOpenAIPromptCacheKey as n, resolveOpenAIResponsesCacheParams as r, OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH as t };
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { D as Model, l as CacheRetention } from "./types-CJ1-Ht7A.mjs";
|
|
2
|
-
import "./types-3Lnm-QSJ.mjs";
|
|
3
|
-
//#region packages/ai/src/providers/openai-prompt-cache.d.ts
|
|
4
|
-
/** Selects the documented cache lifetime fields for a Responses request. */
|
|
5
|
-
declare function resolveOpenAIResponsesCacheParams(model: Pick<Model, "id" | "api" | "baseUrl">, cacheRetention: CacheRetention, supportsLongCacheRetention: boolean): {
|
|
6
|
-
prompt_cache_retention?: "24h";
|
|
7
|
-
prompt_cache_options?: {
|
|
8
|
-
ttl: "30m";
|
|
9
|
-
};
|
|
10
|
-
};
|
|
11
|
-
/** Maximum prompt cache key length accepted by OpenAI-compatible request metadata. */
|
|
12
|
-
declare const OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH = 64;
|
|
13
|
-
/** Truncates a prompt cache key by Unicode code point count. */
|
|
14
|
-
declare function clampOpenAIPromptCacheKey(key: string | undefined): string | undefined;
|
|
15
|
-
//#endregion
|
|
16
|
-
export { clampOpenAIPromptCacheKey as n, resolveOpenAIResponsesCacheParams as r, OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH as t };
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import { d as normalizeOptionalString, t as truncateUtf16Safe } from "./utf16-slice-qz3nsy87.mjs";
|
|
2
|
-
import { n as getAiTransportHost } from "./host-CEvLw30U.mjs";
|
|
3
|
-
import { c as parseStrictNonNegativeInteger, i as asFiniteNumberInRange, l as parseStrictPositiveInteger, s as parseStrictFiniteNumber } from "./base64-CEFBpSkN.mjs";
|
|
4
|
-
import { parseRetryAfterHttpDateMs } from "./internal/retry-after.mjs";
|
|
5
|
-
import { createHash } from "node:crypto";
|
|
6
|
-
//#region packages/ai/src/transports/transport-utils.ts
|
|
7
|
-
const MALFORMED_STREAMING_FRAGMENT_ERROR_MESSAGE = "OpenClaw transport error: malformed_streaming_fragment";
|
|
8
|
-
const NON_LATIN_RE = /[\u2E80-\u9FFF\uA000-\uA4FF\uAC00-\uD7AF\uF900-\uFAFF\uFF01-\uFF60\uFFE0-\uFFE6\u{20000}-\u{2FA1F}]/gu;
|
|
9
|
-
const CJK_SURROGATE_HIGH_RE = /[\uD840-\uD87E][\uDC00-\uDFFF]/g;
|
|
10
|
-
function parsePositiveInteger(value) {
|
|
11
|
-
if (typeof value === "number" && Number.isFinite(value) && value > 0) return Math.floor(value);
|
|
12
|
-
return typeof value === "string" ? parseStrictPositiveInteger(value) : void 0;
|
|
13
|
-
}
|
|
14
|
-
function sha256Hex(value) {
|
|
15
|
-
return createHash("sha256").update(value).digest("hex");
|
|
16
|
-
}
|
|
17
|
-
function sha256HexPrefix(value, length) {
|
|
18
|
-
return sha256Hex(value).slice(0, length);
|
|
19
|
-
}
|
|
20
|
-
function redactIdentifier(value, opts) {
|
|
21
|
-
const trimmed = normalizeOptionalString(value);
|
|
22
|
-
if (!trimmed) return "-";
|
|
23
|
-
return `sha256:${sha256HexPrefix(trimmed, Number.isFinite(opts?.len) ? Math.max(1, Math.floor(opts?.len ?? 12)) : 12)}`;
|
|
24
|
-
}
|
|
25
|
-
function redactSensitiveText(text, _options) {
|
|
26
|
-
return getAiTransportHost().redactToolPayloadText(text);
|
|
27
|
-
}
|
|
28
|
-
function resolveModelHeaderSentinels(model) {
|
|
29
|
-
if (!model.headers) return model;
|
|
30
|
-
let headers;
|
|
31
|
-
for (const [name, value] of Object.entries(model.headers)) {
|
|
32
|
-
const resolved = getAiTransportHost().resolveSecretSentinel(value);
|
|
33
|
-
if (resolved !== value) {
|
|
34
|
-
headers ??= { ...model.headers };
|
|
35
|
-
headers[name] = resolved;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return headers ? {
|
|
39
|
-
...model,
|
|
40
|
-
headers
|
|
41
|
-
} : model;
|
|
42
|
-
}
|
|
43
|
-
function createAbortError(message, options) {
|
|
44
|
-
const error = new Error(message, options);
|
|
45
|
-
error.name = "AbortError";
|
|
46
|
-
return error;
|
|
47
|
-
}
|
|
48
|
-
function estimateStringChars(text) {
|
|
49
|
-
if (!text) return 0;
|
|
50
|
-
const nonLatinCount = (text.match(NON_LATIN_RE) ?? []).length;
|
|
51
|
-
return (nonLatinCount === 0 ? text.length : text.length - (text.match(CJK_SURROGATE_HIGH_RE) ?? []).length) + nonLatinCount * 3;
|
|
52
|
-
}
|
|
53
|
-
function supportsModelTools(model) {
|
|
54
|
-
return (model.compat && typeof model.compat === "object" ? model.compat : void 0)?.supportsTools !== false;
|
|
55
|
-
}
|
|
56
|
-
function isCodeModeModelVisibleToolName(name, visibleToolNames) {
|
|
57
|
-
return visibleToolNames.has(name);
|
|
58
|
-
}
|
|
59
|
-
function isGoogleGemini3Model(modelId, family) {
|
|
60
|
-
const normalized = modelId.trim().toLowerCase();
|
|
61
|
-
const suffix = family === "pro" ? "pro" : "flash";
|
|
62
|
-
return new RegExp(`(?:^|/)gemini-(?:3(?:\\.\\d+)?-${suffix}|${suffix}${family === "flash" ? "(?:-lite)?" : ""}-latest)(?:-|$)`).test(normalized);
|
|
63
|
-
}
|
|
64
|
-
function isGoogleGemini3ProModel(modelId) {
|
|
65
|
-
return isGoogleGemini3Model(modelId, "pro");
|
|
66
|
-
}
|
|
67
|
-
function isGoogleGemini3FlashModel(modelId) {
|
|
68
|
-
return isGoogleGemini3Model(modelId, "flash");
|
|
69
|
-
}
|
|
70
|
-
function parseRetryAfterSeconds(headers) {
|
|
71
|
-
const retryAfterMs = headers.get("retry-after-ms");
|
|
72
|
-
if (retryAfterMs) {
|
|
73
|
-
const trimmed = retryAfterMs.trim();
|
|
74
|
-
if (/^\d+(?:\.\d+)?$/.test(trimmed)) {
|
|
75
|
-
const milliseconds = asFiniteNumberInRange(parseStrictFiniteNumber(trimmed), {
|
|
76
|
-
min: 0,
|
|
77
|
-
max: Number.MAX_SAFE_INTEGER
|
|
78
|
-
});
|
|
79
|
-
return milliseconds === void 0 ? Number.POSITIVE_INFINITY : milliseconds / 1e3;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
const retryAfter = headers.get("retry-after")?.trim();
|
|
83
|
-
if (!retryAfter) return;
|
|
84
|
-
if (/^\d+$/.test(retryAfter)) return parseStrictNonNegativeInteger(retryAfter) ?? Number.POSITIVE_INFINITY;
|
|
85
|
-
const retryAt = parseRetryAfterHttpDateMs(retryAfter);
|
|
86
|
-
return retryAt === void 0 ? void 0 : Math.max(0, (retryAt - Date.now()) / 1e3);
|
|
87
|
-
}
|
|
88
|
-
async function readChunkWithIdleTimeout(reader, timeoutMs, onIdleTimeout) {
|
|
89
|
-
let timer;
|
|
90
|
-
try {
|
|
91
|
-
return await Promise.race([reader.read(), new Promise((_resolve, reject) => {
|
|
92
|
-
timer = setTimeout(() => reject(onIdleTimeout?.({ chunkTimeoutMs: timeoutMs }) ?? /* @__PURE__ */ new Error("Read timed out")), timeoutMs);
|
|
93
|
-
})]);
|
|
94
|
-
} finally {
|
|
95
|
-
if (timer) clearTimeout(timer);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
async function readResponseTextSnippet(response, options) {
|
|
99
|
-
const maxBytes = options?.maxBytes ?? 8192;
|
|
100
|
-
const maxChars = options?.maxChars ?? 200;
|
|
101
|
-
const reader = response.body?.getReader();
|
|
102
|
-
if (!reader) return;
|
|
103
|
-
const chunks = [];
|
|
104
|
-
let bytes = 0;
|
|
105
|
-
let truncated = false;
|
|
106
|
-
try {
|
|
107
|
-
while (bytes < maxBytes) {
|
|
108
|
-
const result = options?.chunkTimeoutMs ? await readChunkWithIdleTimeout(reader, options.chunkTimeoutMs, options.onIdleTimeout) : await reader.read();
|
|
109
|
-
if (result.done) break;
|
|
110
|
-
if (!result.value?.length) continue;
|
|
111
|
-
const remaining = maxBytes - bytes;
|
|
112
|
-
chunks.push(result.value.subarray(0, remaining));
|
|
113
|
-
bytes += Math.min(result.value.length, remaining);
|
|
114
|
-
if (result.value.length >= remaining) {
|
|
115
|
-
truncated = true;
|
|
116
|
-
await reader.cancel().catch(() => void 0);
|
|
117
|
-
break;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
} catch (error) {
|
|
121
|
-
await reader.cancel(error).catch(() => void 0);
|
|
122
|
-
throw error;
|
|
123
|
-
} finally {
|
|
124
|
-
reader.releaseLock();
|
|
125
|
-
}
|
|
126
|
-
const merged = new Uint8Array(bytes);
|
|
127
|
-
let offset = 0;
|
|
128
|
-
for (const chunk of chunks) {
|
|
129
|
-
merged.set(chunk, offset);
|
|
130
|
-
offset += chunk.length;
|
|
131
|
-
}
|
|
132
|
-
const collapsed = new TextDecoder().decode(merged).replace(/\s+/g, " ").trim();
|
|
133
|
-
if (!collapsed) return;
|
|
134
|
-
if (collapsed.length > maxChars) return `${truncateUtf16Safe(collapsed, maxChars)}…`;
|
|
135
|
-
return truncated ? `${collapsed}…` : collapsed;
|
|
136
|
-
}
|
|
137
|
-
//#endregion
|
|
138
|
-
export { isGoogleGemini3FlashModel as a, parseRetryAfterSeconds as c, redactSensitiveText as d, resolveModelHeaderSentinels as f, isCodeModeModelVisibleToolName as i, readResponseTextSnippet as l, supportsModelTools as m, createAbortError as n, isGoogleGemini3ProModel as o, sha256Hex as p, estimateStringChars as r, parsePositiveInteger as s, MALFORMED_STREAMING_FRAGMENT_ERROR_MESSAGE as t, redactIdentifier as u };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import "./index-FnHM2FcI.mjs";
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
//#region packages/normalization-core/src/string-coerce.ts
|
|
2
|
-
/** Reads a value only when it is already a string, preserving whitespace. */
|
|
3
|
-
function readStringValue(value) {
|
|
4
|
-
return typeof value === "string" ? value : void 0;
|
|
5
|
-
}
|
|
6
|
-
/** Trims string input and returns null for non-strings or empty strings. */
|
|
7
|
-
function normalizeNullableString(value) {
|
|
8
|
-
if (typeof value !== "string") return null;
|
|
9
|
-
const trimmed = value.trim();
|
|
10
|
-
return trimmed ? trimmed : null;
|
|
11
|
-
}
|
|
12
|
-
/** Trims string input and returns undefined for non-strings or empty strings. */
|
|
13
|
-
function normalizeOptionalString(value) {
|
|
14
|
-
return normalizeNullableString(value) ?? void 0;
|
|
15
|
-
}
|
|
16
|
-
/** Stringifies primitive ids/flags before applying optional string normalization. */
|
|
17
|
-
function normalizeStringifiedOptionalString(value) {
|
|
18
|
-
if (typeof value === "string") return normalizeOptionalString(value);
|
|
19
|
-
if (typeof value === "number" || typeof value === "boolean" || typeof value === "bigint") return normalizeOptionalString(String(value));
|
|
20
|
-
}
|
|
21
|
-
/** Lowercases a normalized optional string. */
|
|
22
|
-
function normalizeOptionalLowercaseString(value) {
|
|
23
|
-
return normalizeOptionalString(value)?.toLowerCase();
|
|
24
|
-
}
|
|
25
|
-
/** Lowercases a normalized string or returns an empty string when absent. */
|
|
26
|
-
function normalizeLowercaseStringOrEmpty(value) {
|
|
27
|
-
return normalizeOptionalLowercaseString(value) ?? "";
|
|
28
|
-
}
|
|
29
|
-
/** Type guard for strings that remain non-empty after trimming. */
|
|
30
|
-
function hasNonEmptyString(value) {
|
|
31
|
-
return normalizeOptionalString(value) !== void 0;
|
|
32
|
-
}
|
|
33
|
-
//#endregion
|
|
34
|
-
//#region packages/normalization-core/src/record-coerce.ts
|
|
35
|
-
/** Type guard for non-array object records at browser-safe boundaries. */
|
|
36
|
-
function isRecord(value) {
|
|
37
|
-
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
38
|
-
}
|
|
39
|
-
/** Returns a non-array record or undefined. */
|
|
40
|
-
function asOptionalRecord(value) {
|
|
41
|
-
return isRecord(value) ? value : void 0;
|
|
42
|
-
}
|
|
43
|
-
/** Returns a non-array record or a fresh ordinary empty record. */
|
|
44
|
-
function asNonArrayRecord(value) {
|
|
45
|
-
return asOptionalRecord(value) ?? {};
|
|
46
|
-
}
|
|
47
|
-
/** Returns a non-array record or null. */
|
|
48
|
-
function asNullableRecord(value) {
|
|
49
|
-
return isRecord(value) ? value : null;
|
|
50
|
-
}
|
|
51
|
-
/** Returns any object-backed record, including arrays, or undefined. */
|
|
52
|
-
function asOptionalObjectRecord(value) {
|
|
53
|
-
return value && typeof value === "object" ? value : void 0;
|
|
54
|
-
}
|
|
55
|
-
//#endregion
|
|
56
|
-
//#region packages/normalization-core/src/utf16-slice.ts
|
|
57
|
-
function isHighSurrogate(codeUnit) {
|
|
58
|
-
return codeUnit >= 55296 && codeUnit <= 56319;
|
|
59
|
-
}
|
|
60
|
-
function isLowSurrogate(codeUnit) {
|
|
61
|
-
return codeUnit >= 56320 && codeUnit <= 57343;
|
|
62
|
-
}
|
|
63
|
-
/** Slices a UTF-16 string without returning dangling surrogate halves at either edge. */
|
|
64
|
-
function sliceUtf16Safe(input, start, end) {
|
|
65
|
-
const len = input.length;
|
|
66
|
-
let from = start < 0 ? Math.max(len + start, 0) : Math.min(start, len);
|
|
67
|
-
let to = end === void 0 ? len : end < 0 ? Math.max(len + end, 0) : Math.min(end, len);
|
|
68
|
-
if (to <= from) return "";
|
|
69
|
-
if (from > 0 && from < len) {
|
|
70
|
-
if (isLowSurrogate(input.charCodeAt(from)) && isHighSurrogate(input.charCodeAt(from - 1))) from += 1;
|
|
71
|
-
}
|
|
72
|
-
if (to > 0 && to < len) {
|
|
73
|
-
if (isHighSurrogate(input.charCodeAt(to - 1)) && isLowSurrogate(input.charCodeAt(to))) to -= 1;
|
|
74
|
-
}
|
|
75
|
-
return input.slice(from, to);
|
|
76
|
-
}
|
|
77
|
-
/** Truncates a UTF-16 string without cutting a surrogate pair in half. */
|
|
78
|
-
function truncateUtf16Safe(input, maxLen) {
|
|
79
|
-
const limit = Math.max(0, Math.floor(maxLen));
|
|
80
|
-
if (input.length <= limit) return input;
|
|
81
|
-
return sliceUtf16Safe(input, 0, limit);
|
|
82
|
-
}
|
|
83
|
-
//#endregion
|
|
84
|
-
export { asOptionalRecord as a, normalizeLowercaseStringOrEmpty as c, normalizeOptionalString as d, normalizeStringifiedOptionalString as f, asOptionalObjectRecord as i, normalizeNullableString as l, asNonArrayRecord as n, isRecord as o, readStringValue as p, asNullableRecord as r, hasNonEmptyString as s, truncateUtf16Safe as t, normalizeOptionalLowercaseString as u };
|