@openclaw/ai 2026.8.1-beta.3 → 2026.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/dist/{anthropic-B8KwTtlb.mjs → anthropic-Djj7L1rx.mjs} +21 -21
  2. package/dist/{anthropic-compaction-replay-4Zx7-aCr.mjs → anthropic-compaction-replay-CY4tkD4V.mjs} +33 -34
  3. package/dist/{anthropic-payload-policy-CSx7MoKH.d.mts → anthropic-payload-policy-i_5_inWe.d.mts} +3 -2
  4. package/dist/{api-registry-DFxSnFqG.d.mts → api-registry-C9-wZd_W.d.mts} +2 -1
  5. package/dist/{azure-openai-responses-Aa4mVcYG.mjs → azure-openai-responses-Bj3czHNa.mjs} +4 -4
  6. package/dist/{number-coercion-H9qHik3g.mjs → base64-CEFBpSkN.mjs} +73 -1
  7. package/dist/diagnostics.d.mts +2 -3
  8. package/dist/diagnostics.mjs +1 -1
  9. package/dist/{env-api-keys-DrgeBuva.mjs → env-api-keys-bktO00EJ.mjs} +2 -15
  10. package/dist/event-stream-C988TSLe.d.mts +1 -0
  11. package/dist/{event-stream-D91-ohD_.d.mts → event-stream-UhnxHuqt.d.mts} +1 -2
  12. package/dist/event-stream.d.mts +2 -1
  13. package/dist/{google-yDRnipeq.mjs → google-0Ca6TYbw.mjs} +4 -4
  14. package/dist/{google-shared-M1dl64nz.mjs → google-shared-DVfL9COU.mjs} +14 -7
  15. package/dist/{google-vertex-DCJHM_a5.mjs → google-vertex-5dAMxprN.mjs} +4 -4
  16. package/dist/{host-DF_yxOsA.mjs → host-D51fmkH6.mjs} +4 -8
  17. package/dist/{host-DJq_FGcz.d.mts → host-DoPJJ1KD.d.mts} +3 -3
  18. package/dist/index-N3zr6__t.d.mts +105 -0
  19. package/dist/index.d.mts +9 -10
  20. package/dist/index.mjs +2 -3
  21. package/dist/internal/anthropic.d.mts +51 -49
  22. package/dist/internal/anthropic.mjs +5 -5
  23. package/dist/internal/openai-responses-payload-policy.d.mts +3 -3
  24. package/dist/internal/openai-responses-payload-policy.mjs +2 -3
  25. package/dist/internal/openai.d.mts +65 -63
  26. package/dist/internal/openai.mjs +10 -9
  27. package/dist/internal/retry-after.d.mts +2 -3
  28. package/dist/internal/runtime.d.mts +51 -40
  29. package/dist/internal/runtime.mjs +9 -9
  30. package/dist/internal/shared.d.mts +25 -25
  31. package/dist/internal/shared.mjs +3 -3
  32. package/dist/{json-parse-CDnesDM_.mjs → json-parse-BuAJEbdW.mjs} +18 -2
  33. package/dist/{mistral-D6hRXI7A.mjs → mistral-BCnrI-kV.mjs} +22 -25
  34. package/dist/{openai-chatgpt-responses-C339VIfT.mjs → openai-chatgpt-responses-CGBGWSqr.mjs} +31 -14
  35. package/dist/openai-completions-BaTuwID7.mjs +401 -0
  36. package/dist/{openai-completions-compat-B0KTleXp.d.mts → openai-completions-compat-DB7FFq7k.d.mts} +3 -3
  37. package/dist/openai-completions-stream-Bpns6uNc.mjs +1622 -0
  38. package/dist/{openai-responses-BXEcr-Tp.mjs → openai-responses-1GBcQujk.mjs} +8 -6
  39. package/dist/openai-responses-compaction-window-DwydGZI8.mjs +686 -0
  40. package/dist/{openai-responses-contracts-CD75pQ0m.d.mts → openai-responses-contracts-DgaR3t5T.d.mts} +14 -5
  41. package/dist/{openai-responses-payload-policy-CNGFT9zr.d.mts → openai-responses-payload-policy-rLRPsSmB.d.mts} +1 -0
  42. package/dist/{openai-responses-prompt-observer-internal-BG-1AsBI.mjs → openai-responses-prompt-observer-internal-_nhGTn2b.mjs} +3 -2
  43. package/dist/{openai-responses-shared-Cvt5MgEm.mjs → openai-responses-shared-zPmKnhF5.mjs} +315 -1468
  44. package/dist/openai-stop-reason-Drnn_6Qj.mjs +28 -0
  45. package/dist/openai-tool-schema-Dgl4H2MU.mjs +1695 -0
  46. package/dist/{provider-error-C8mBRJDl.mjs → provider-error-jZP5NMTZ.mjs} +3 -77
  47. package/dist/{provider-options-Cc5ZQ6Aa.d.mts → provider-options-HvA_slFa.d.mts} +13 -4
  48. package/dist/{provider-transcript-transform--gtf0ZbR.mjs → provider-transcript-transform-C01bQ5a3.mjs} +1 -1
  49. package/dist/provider-types.d.mts +18 -17
  50. package/dist/providers.d.mts +5 -6
  51. package/dist/providers.mjs +9 -9
  52. package/dist/{reasoning-tag-text-partitioner-5ygO2rZc.mjs → reasoning-tag-text-partitioner-CwzKb0bA.mjs} +1 -1
  53. package/dist/rolldown-runtime-BhDjJH2R.mjs +15 -0
  54. package/dist/{sanitize-unicode-BP7HLLZn.mjs → sanitize-unicode-DCkltN94.mjs} +1 -2
  55. package/dist/simple-options-DKx86yX9.mjs +155 -0
  56. package/dist/{anthropic-BQXQudmA.mjs → src-Bu3FiFAG.mjs} +1 -0
  57. package/dist/{stream-first-event-timeout-MK28puvq.mjs → stream-first-event-timeout-DcNjoFQE.mjs} +1 -1
  58. package/dist/{streaming-byte-guard-BrbkbwUu.mjs → streaming-byte-guard-CC-HMn_u.mjs} +5 -6
  59. package/dist/string-normalization--fwJ4S2q.mjs +16 -0
  60. package/dist/{tool-schema-json-projection-FEr-jOoZ.mjs → tool-schema-json-projection-qvTEs5Am.mjs} +2 -2
  61. package/dist/{simple-options-oqsXB6U3.mjs → transport-stream-shared-CT5ycdzn.mjs} +10 -118
  62. package/dist/transport-stream-shared-NjwWNaRY.d.mts +138 -0
  63. package/dist/{transport-utils-Bv0FHkd0.mjs → transport-utils-BHx9z8Cl.mjs} +9 -9
  64. package/dist/transports.d.mts +127 -189
  65. package/dist/transports.mjs +181 -1214
  66. package/dist/types-DtGu2d3C.d.mts +1 -0
  67. package/dist/{types-DTAP49HF.d.mts → types-h38Azne1.d.mts} +38 -17
  68. package/dist/types.d.mts +5 -4
  69. package/dist/types.mjs +1 -2
  70. package/dist/utf16-slice-qz3nsy87.mjs +84 -0
  71. package/dist/{validation-DYNNrU9u.d.mts → validation-C68lP2uy.d.mts} +1 -2
  72. package/dist/validation.d.mts +1 -1
  73. package/package.json +6 -6
  74. package/dist/anthropic-BECQCNdF.d.mts +0 -98
  75. package/dist/event-stream-BVVgDSdq.d.mts +0 -1
  76. package/dist/headers-B_e4-1J0.mjs +0 -9
  77. package/dist/index-BVVgDSdq.d.mts +0 -1
  78. package/dist/openai-completions-D88orSJ9.mjs +0 -632
  79. package/dist/openai-responses-contracts-DvILoqBk.mjs +0 -247
  80. package/dist/openai-responses-payload-policy-BDo8CQsx.mjs +0 -208
  81. package/dist/openai-stop-reason-9OONKyAm.mjs +0 -579
  82. package/dist/openai-tool-projection-CHGLt03m.mjs +0 -426
  83. package/dist/provider-options-AvldWZt8.mjs +0 -21
  84. package/dist/record-coerce-DdXsgUd_.mjs +0 -23
  85. package/dist/src-D2H6yKkH.mjs +0 -2
  86. package/dist/stream-first-event-timeout-DvDeSucC.d.mts +0 -29
  87. package/dist/string-coerce-fsri9iCu.mjs +0 -34
  88. package/dist/types-BVVgDSdq.d.mts +0 -1
  89. package/dist/utf16-slice-CvGodqok.mjs +0 -29
@@ -0,0 +1,401 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-BhDjJH2R.mjs";
2
+ import { t as AssistantMessageEventStream } from "./event-stream-uSMZJ3FA.mjs";
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-jZP5NMTZ.mjs";
6
+ import { n as clampOpenAIPromptCacheKey } from "./openai-prompt-cache-mZTCdRPo.mjs";
7
+ import { t as resolveCacheRetention } from "./cache-retention-0x979a5V.mjs";
8
+ import { m as sortPromptCacheToolsByName, n as buildBaseOptions, o as reasoningTagTextPolicy, u as splitSystemPromptCacheBoundary } from "./simple-options-DKx86yX9.mjs";
9
+ import { n as getEnvApiKey } from "./env-api-keys-bktO00EJ.mjs";
10
+ import { _ as transportAbortError, y as withProviderResponseHook } from "./transport-stream-shared-CT5ycdzn.mjs";
11
+ 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-Bpns6uNc.mjs";
12
+ import { C as createOpenAIProviderAcceptanceHook, T as isOpenAICompletionsThinkingEnabled, j as resolveOpenAIClientBaseUrl, v as projectOpenAITools, y as reconcileOpenAICompletionsToolChoice } from "./openai-tool-schema-Dgl4H2MU.mjs";
13
+ import { i as getFirstStreamEventTimeoutMs, r as getFirstStreamEventTimeoutHandler, t as createFirstStreamEventAbortController } from "./stream-first-event-timeout-DcNjoFQE.mjs";
14
+ import { i as resolveCloudflareBaseUrl, n as hasCopilotVisionInput, r as isCloudflareProvider, t as buildCopilotDynamicHeaders } from "./github-copilot-headers-NCJtz9i0.mjs";
15
+ import OpenAI from "openai";
16
+ //#region packages/ai/src/providers/openai-completions.ts
17
+ var openai_completions_exports = /* @__PURE__ */ __exportAll({
18
+ convertMessages: () => convertMessages,
19
+ streamOpenAICompletions: () => streamOpenAICompletions,
20
+ streamSimpleOpenAICompletions: () => streamSimpleOpenAICompletions
21
+ });
22
+ const streamOpenAICompletions = (model, context, options) => {
23
+ const stream = new AssistantMessageEventStream();
24
+ (async () => {
25
+ const output = {
26
+ role: "assistant",
27
+ content: [],
28
+ api: model.api,
29
+ provider: model.provider,
30
+ model: model.id,
31
+ usage: {
32
+ input: 0,
33
+ output: 0,
34
+ cacheRead: 0,
35
+ cacheWrite: 0,
36
+ totalTokens: 0,
37
+ cost: {
38
+ input: 0,
39
+ output: 0,
40
+ cacheRead: 0,
41
+ cacheWrite: 0,
42
+ total: 0
43
+ }
44
+ },
45
+ stopReason: "stop",
46
+ timestamp: Date.now()
47
+ };
48
+ const provisionalCommentaryTags = /* @__PURE__ */ new Map();
49
+ let firstEventAbort;
50
+ try {
51
+ const apiKey = options?.apiKey || getEnvApiKey(model.provider) || "";
52
+ const compat = resolveOpenAICompletionsCompat(model);
53
+ const shouldEmitReasoning = Boolean(model.reasoning && options?.reasoningEffort && isOpenAICompletionsThinkingEnabled(options.reasoningEffort));
54
+ const cacheRetention = resolveCacheRetention(options?.cacheRetention);
55
+ const cacheSessionId = cacheRetention === "none" ? void 0 : options?.sessionId;
56
+ const client = createClient(model, context, apiKey, options?.headers, cacheSessionId, compat);
57
+ let params = buildParams(model, context, options, compat, cacheRetention);
58
+ const nextParams = await options?.onPayload?.(params, model);
59
+ if (nextParams !== void 0) params = nextParams;
60
+ firstEventAbort = createFirstStreamEventAbortController(options?.signal);
61
+ const requestOptions = {
62
+ signal: firstEventAbort.signal,
63
+ ...options?.timeoutMs !== void 0 ? { timeout: options.timeoutMs } : {},
64
+ maxRetries: options?.maxRetries ?? 0
65
+ };
66
+ const { data: openaiStream, response } = await client.chat.completions.create(params, requestOptions).withResponse();
67
+ const hookedOpenAIStream = withProviderResponseHook({
68
+ stream: openaiStream,
69
+ signal: firstEventAbort.signal,
70
+ abort: firstEventAbort.abort,
71
+ hook: createOpenAIProviderAcceptanceHook(options, response, model),
72
+ onReady: () => stream.push({
73
+ type: "start",
74
+ partial: output
75
+ })
76
+ });
77
+ const finishedBlocks = /* @__PURE__ */ new Set();
78
+ const contentIndices = /* @__PURE__ */ new WeakMap();
79
+ let openTextBlock;
80
+ let openThinkingBlock;
81
+ const finishBlock = (block) => {
82
+ const contentIndex = contentIndices.get(block);
83
+ if (contentIndex === void 0 || finishedBlocks.has(block)) return;
84
+ finishedBlocks.add(block);
85
+ if (block.type === "text") {
86
+ openTextBlock = void 0;
87
+ stream.push({
88
+ type: "text_end",
89
+ contentIndex,
90
+ content: block.text,
91
+ partial: output
92
+ });
93
+ } else if (block.type === "thinking") {
94
+ openThinkingBlock = void 0;
95
+ stream.push({
96
+ type: "thinking_end",
97
+ contentIndex,
98
+ content: block.thinking,
99
+ partial: output
100
+ });
101
+ } else if (block.type === "toolCall") stream.push({
102
+ type: "toolcall_end",
103
+ contentIndex,
104
+ toolCall: block,
105
+ partial: output
106
+ });
107
+ };
108
+ const directEventStream = { push(event) {
109
+ if (event.type === "text_start" || event.type === "thinking_start" || event.type === "toolcall_start") {
110
+ const block = output.content[event.contentIndex];
111
+ if (block) {
112
+ contentIndices.set(block, event.contentIndex);
113
+ if (block.type === "text") openTextBlock = block;
114
+ else if (block.type === "thinking") openThinkingBlock = block;
115
+ }
116
+ }
117
+ stream.push(event);
118
+ } };
119
+ try {
120
+ await processCompletionsStream(hookedOpenAIStream, output, model, directEventStream, {
121
+ mode: "direct",
122
+ beforeContentBlock(nextType) {
123
+ if (openThinkingBlock) finishBlock(openThinkingBlock);
124
+ if (openTextBlock && nextType !== "toolCall") finishBlock(openTextBlock);
125
+ },
126
+ provisionalCommentaryTags,
127
+ signal: options?.signal,
128
+ emitReasoning: shouldEmitReasoning,
129
+ strictReasoningTags: reasoningTagTextPolicy.isStrict(options),
130
+ firstEventTimeoutMs: getFirstStreamEventTimeoutMs(options),
131
+ abortFirstEventStream: firstEventAbort.abort,
132
+ onFirstEventTimeout: getFirstStreamEventTimeoutHandler(options)
133
+ });
134
+ if (options?.signal?.aborted) throw transportAbortError(options.signal);
135
+ if (output.stopReason === "aborted" || output.stopReason === "error") throw new Error(output.errorMessage || (output.stopReason === "aborted" ? "Request was aborted" : "Provider returned an invalid tool call"));
136
+ } catch (error) {
137
+ for (const block of output.content) if (block.type !== "toolCall") finishBlock(block);
138
+ throw error;
139
+ }
140
+ for (const block of output.content) if (block.type !== "toolCall" || output.stopReason === "toolUse") finishBlock(block);
141
+ stream.push({
142
+ type: "done",
143
+ reason: output.stopReason,
144
+ message: output
145
+ });
146
+ stream.end();
147
+ } catch (error) {
148
+ const terminal = projectProviderError(error, options?.signal);
149
+ Object.assign(output, terminal);
150
+ finalizeOpenAICompletionsToolCalls(output, { allowSilentToolCallPromotion: false });
151
+ clearPendingCommentaryText(provisionalCommentaryTags);
152
+ tagUnresolvedTextAsCommentary(output);
153
+ for (const block of output.content) {
154
+ delete block.index;
155
+ delete block.partialArgs;
156
+ delete block.streamIndex;
157
+ }
158
+ stream.push({
159
+ type: "error",
160
+ reason: terminal.stopReason,
161
+ error: output
162
+ });
163
+ stream.end();
164
+ } finally {
165
+ firstEventAbort?.dispose();
166
+ }
167
+ })();
168
+ return stream;
169
+ };
170
+ const streamSimpleOpenAICompletions = (model, context, options) => {
171
+ const apiKey = options?.apiKey || getEnvApiKey(model.provider);
172
+ if (!apiKey) throw new Error(`No API key for provider: ${model.provider}`);
173
+ const base = buildBaseOptions(model, options, apiKey);
174
+ const clampedReasoning = options?.reasoning ? clampThinkingLevel(model, options.reasoning) : void 0;
175
+ const reasoningEffort = clampedReasoning === "off" ? void 0 : clampedReasoning === "max" ? "xhigh" : clampedReasoning;
176
+ const toolChoice = options?.toolChoice;
177
+ return streamOpenAICompletions(model, context, {
178
+ ...base,
179
+ reasoningEffort,
180
+ toolChoice
181
+ });
182
+ };
183
+ function createClient(model, context, apiKey, optionsHeaders, sessionId, compat = resolveOpenAICompletionsCompat(model)) {
184
+ if (!apiKey) throw new Error(`No API key for provider: ${model.provider}`);
185
+ const headers = { ...model.headers };
186
+ if (model.provider === "github-copilot") {
187
+ const hasImages = hasCopilotVisionInput(context.messages);
188
+ const copilotHeaders = buildCopilotDynamicHeaders({
189
+ messages: context.messages,
190
+ hasImages
191
+ });
192
+ Object.assign(headers, copilotHeaders);
193
+ }
194
+ if (sessionId && compat.sessionAffinity !== "none") if (compat.sessionAffinity === "openrouter") headers["x-session-id"] = sessionId;
195
+ else {
196
+ headers.session_id = sessionId;
197
+ headers["x-client-request-id"] = sessionId;
198
+ headers["x-session-affinity"] = sessionId;
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
+ return new OpenAI({
207
+ apiKey,
208
+ baseURL: resolveOpenAIClientBaseUrl(model, isCloudflareProvider(model.provider) ? resolveCloudflareBaseUrl(model) : model.baseUrl),
209
+ dangerouslyAllowBrowser: true,
210
+ defaultHeaders,
211
+ fetch: getAiTransportHost().buildModelFetch(model)
212
+ });
213
+ }
214
+ function buildParams(model, context, options, compat = resolveOpenAICompletionsCompat(model), cacheRetention = resolveCacheRetention(options?.cacheRetention)) {
215
+ const cacheControl = getCompatCacheControl(compat, cacheRetention);
216
+ const cacheOptOutIndexes = /* @__PURE__ */ new Set();
217
+ const messages = convertMessages(model, context, compat, {
218
+ cacheOptOutIndexes,
219
+ preserveSystemPromptCacheBoundary: cacheControl !== void 0
220
+ });
221
+ const supportsPromptCacheKey = model.baseUrl.includes("api.openai.com") || compat.supportsPromptCacheKey;
222
+ const promptCacheKey = supportsPromptCacheKey && cacheRetention !== "none" ? clampOpenAIPromptCacheKey(options?.promptCacheKey ?? options?.sessionId) : void 0;
223
+ const params = {
224
+ model: model.id,
225
+ messages,
226
+ stream: true,
227
+ prompt_cache_key: promptCacheKey,
228
+ prompt_cache_retention: supportsPromptCacheKey && cacheRetention === "long" && compat.supportsLongCacheRetention ? "24h" : void 0
229
+ };
230
+ if (compat.supportsUsageInStreaming) params.stream_options = { include_usage: true };
231
+ if (compat.supportsStore) params.store = false;
232
+ if (options?.maxTokens) {
233
+ const maxTokens = clampOpenAICompletionsMaxTokens(model, options.maxTokens);
234
+ if (compat.maxTokensField === "max_tokens") params.max_tokens = maxTokens;
235
+ else params.max_completion_tokens = maxTokens;
236
+ }
237
+ if (options?.temperature !== void 0) params.temperature = options.temperature;
238
+ if (options?.stop !== void 0 && options.stop.length > 0) params.stop = options.stop;
239
+ const requestedResponseFormat = options?.responseFormat;
240
+ const responseFormat = requestedResponseFormat === void 0 ? void 0 : resolveOpenAICompletionsResponseFormat(shouldOmitOllamaCompatResponseFormat({
241
+ provider: model.provider,
242
+ baseUrl: model.baseUrl,
243
+ hasTools: () => Boolean(context.tools?.length)
244
+ }) ? void 0 : requestedResponseFormat, compat.supportsJsonSchemaResponseFormat);
245
+ if (responseFormat !== void 0) params.response_format = responseFormat;
246
+ let toolProjection;
247
+ if (context.tools) {
248
+ const converted = convertTools(context.tools, compat);
249
+ toolProjection = converted.projection;
250
+ if (converted.tools.length > 0) params.tools = converted.tools;
251
+ else if (hasToolCallHistory(context.messages)) params.tools = [];
252
+ if (compat.zaiToolStream && converted.tools.length > 0) params.tool_stream = true;
253
+ } else if (hasToolCallHistory(context.messages)) params.tools = [];
254
+ if (cacheControl) applyAnthropicCacheControl(messages, params.tools, cacheControl, cacheOptOutIndexes);
255
+ if (options?.toolChoice) {
256
+ const toolChoice = reconcileOpenAICompletionsToolChoice(options.toolChoice, toolProjection ?? projectOpenAITools([]));
257
+ if (toolChoice !== void 0) params.tool_choice = toolChoice;
258
+ }
259
+ const reasoningEffortMap = resolveOpenAIReasoningEffortMap(model);
260
+ const thinkingLevelMap = model.thinkingLevelMap;
261
+ const reasoningEffort = options?.reasoningEffort === void 0 ? void 0 : reasoningEffortMap[options.reasoningEffort] ?? thinkingLevelMap?.[options.reasoningEffort] ?? options.reasoningEffort;
262
+ const reasoningEnabled = reasoningEffort !== void 0 && reasoningEffort !== "none";
263
+ const offReasoningEffort = reasoningEffortMap.off ?? model.thinkingLevelMap?.off;
264
+ if (compat.thinkingFormat === "zai" && model.reasoning) params.thinking = reasoningEnabled ? {
265
+ type: "enabled",
266
+ clear_thinking: false
267
+ } : { type: "disabled" };
268
+ else if (compat.thinkingFormat === "qwen" && model.reasoning) params.enable_thinking = reasoningEnabled;
269
+ else if (compat.thinkingFormat === "qwen-chat-template" && model.reasoning) params.chat_template_kwargs = {
270
+ enable_thinking: reasoningEnabled,
271
+ preserve_thinking: true
272
+ };
273
+ else if (compat.thinkingFormat === "deepseek" && model.reasoning) {
274
+ params.thinking = { type: reasoningEnabled ? "enabled" : "disabled" };
275
+ if (reasoningEnabled && compat.supportsReasoningEffort) params.reasoning_effort = reasoningEffort;
276
+ } else if (compat.thinkingFormat === "openrouter" && model.reasoning) {
277
+ const openRouterParams = params;
278
+ if (reasoningEnabled) openRouterParams.reasoning = { effort: reasoningEffort };
279
+ else if (offReasoningEffort !== null) openRouterParams.reasoning = { effort: offReasoningEffort ?? "none" };
280
+ } else if (compat.thinkingFormat === "together" && model.reasoning) {
281
+ const togetherParams = params;
282
+ togetherParams.reasoning = { enabled: reasoningEnabled };
283
+ if (reasoningEnabled && compat.supportsReasoningEffort) togetherParams.reasoning_effort = reasoningEffort;
284
+ } else if (reasoningEnabled && model.reasoning && compat.supportsReasoningEffort) params.reasoning_effort = reasoningEffort;
285
+ else if (model.reasoning && compat.supportsReasoningEffort) {
286
+ if (typeof offReasoningEffort === "string") params.reasoning_effort = offReasoningEffort;
287
+ }
288
+ if (compat.openRouterRouting) params.provider = compat.openRouterRouting;
289
+ if (model.baseUrl.includes("ai-gateway.vercel.sh") && model.compat?.vercelGatewayRouting) {
290
+ const routing = model.compat.vercelGatewayRouting;
291
+ if (routing.only || routing.order) {
292
+ const gatewayOptions = {};
293
+ if (routing.only) gatewayOptions.only = routing.only;
294
+ if (routing.order) gatewayOptions.order = routing.order;
295
+ params.providerOptions = { gateway: gatewayOptions };
296
+ }
297
+ }
298
+ return params;
299
+ }
300
+ function clampOpenAICompletionsMaxTokens(model, requestedMaxTokens) {
301
+ const modelMaxTokens = typeof model.maxTokens === "number" && Number.isFinite(model.maxTokens) && model.maxTokens > 0 ? Math.floor(model.maxTokens) : void 0;
302
+ return modelMaxTokens === void 0 || requestedMaxTokens <= modelMaxTokens ? requestedMaxTokens : modelMaxTokens;
303
+ }
304
+ function getCompatCacheControl(compat, cacheRetention) {
305
+ if (compat.cacheControlFormat !== "anthropic" || cacheRetention === "none") return;
306
+ const ttl = cacheRetention === "long" && compat.supportsLongCacheRetention ? "1h" : void 0;
307
+ return {
308
+ type: "ephemeral",
309
+ ...ttl ? { ttl } : {}
310
+ };
311
+ }
312
+ function applyAnthropicCacheControl(messages, tools, cacheControl, cacheOptOutIndexes) {
313
+ addCacheControlToSystemPrompt(messages, cacheControl);
314
+ addCacheControlToLastTool(tools, cacheControl);
315
+ addCacheControlToLastConversationMessage(messages, cacheControl, cacheOptOutIndexes);
316
+ }
317
+ function addCacheControlToSystemPrompt(messages, cacheControl) {
318
+ for (const message of messages) if (message.role === "system" || message.role === "developer") {
319
+ addCacheControlToInstructionMessage(message, cacheControl);
320
+ return;
321
+ }
322
+ }
323
+ function addCacheControlToLastConversationMessage(messages, cacheControl, cacheOptOutIndexes) {
324
+ for (let i = messages.length - 1; i >= 0; i--) {
325
+ const message = messages[i];
326
+ if (!message || cacheOptOutIndexes.has(i)) continue;
327
+ if (message.role === "user" || message.role === "assistant") {
328
+ if (addCacheControlToMessage(message, cacheControl)) return;
329
+ }
330
+ }
331
+ }
332
+ function addCacheControlToLastTool(tools, cacheControl) {
333
+ if (!tools || tools.length === 0) return;
334
+ const lastTool = tools.at(-1);
335
+ if (!lastTool) return;
336
+ lastTool.cache_control = cacheControl;
337
+ }
338
+ function addCacheControlToInstructionMessage(message, cacheControl) {
339
+ return addCacheControlToTextContent(message, cacheControl);
340
+ }
341
+ function addCacheControlToMessage(message, cacheControl) {
342
+ if (message.role === "user" || message.role === "assistant") return addCacheControlToTextContent(message, cacheControl);
343
+ return false;
344
+ }
345
+ function addCacheControlToTextContent(message, cacheControl) {
346
+ const content = message.content;
347
+ if (typeof content === "string") {
348
+ if (content.length === 0) return false;
349
+ message.content = buildCacheControlledTextParts(content, cacheControl);
350
+ return true;
351
+ }
352
+ if (!Array.isArray(content)) return false;
353
+ for (let i = content.length - 1; i >= 0; i--) {
354
+ const part = content[i];
355
+ if (part?.type === "text") {
356
+ const text = part.text;
357
+ content.splice(i, 1, ...buildCacheControlledTextParts(text, cacheControl));
358
+ return true;
359
+ }
360
+ }
361
+ return false;
362
+ }
363
+ function buildCacheControlledTextParts(text, cacheControl) {
364
+ const split = splitSystemPromptCacheBoundary(text);
365
+ if (!split) return [{
366
+ type: "text",
367
+ text,
368
+ cache_control: cacheControl
369
+ }];
370
+ const parts = [];
371
+ if (split.stablePrefix) parts.push({
372
+ type: "text",
373
+ text: split.stablePrefix,
374
+ cache_control: cacheControl
375
+ });
376
+ if (split.dynamicSuffix) parts.push({
377
+ type: "text",
378
+ text: split.dynamicSuffix
379
+ });
380
+ return parts.length > 0 ? parts : [{
381
+ type: "text",
382
+ text: ""
383
+ }];
384
+ }
385
+ function convertTools(tools, compat) {
386
+ const projection = projectOpenAITools(tools);
387
+ return {
388
+ projection,
389
+ tools: sortPromptCacheToolsByName(projection.tools).map((tool) => ({
390
+ type: "function",
391
+ function: {
392
+ name: tool.name,
393
+ description: tool.description,
394
+ parameters: tool.parameters,
395
+ ...compat.supportsStrictMode && { strict: false }
396
+ }
397
+ }))
398
+ };
399
+ }
400
+ //#endregion
401
+ export { streamOpenAICompletions as n, streamSimpleOpenAICompletions as r, openai_completions_exports as t };
@@ -1,6 +1,6 @@
1
- import { D as Model, k as OpenAICompletionsCompat } from "./types-DTAP49HF.mjs";
2
- import { a as AiProviderRequestPolicyInput, i as AiProviderRequestCapabilities } from "./host-DJq_FGcz.mjs";
3
-
1
+ import "./index-N3zr6__t.mjs";
2
+ import { D as Model, k as OpenAICompletionsCompat } from "./types-h38Azne1.mjs";
3
+ import { a as AiProviderRequestPolicyInput, i as AiProviderRequestCapabilities } from "./host-DoPJJ1KD.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";