linkque-cli-v2 1.0.5 → 1.0.6

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 (50) hide show
  1. package/README.md +1 -1
  2. package/linkquejs.js +27 -2212
  3. package/package.json +4 -1
  4. package/vendor/linkque-agent-appwrite-integrate/dist/esm/anthropic-messages-B5T6TFD2.js +7172 -0
  5. package/vendor/linkque-agent-appwrite-integrate/dist/esm/azure-openai-responses-S7HNQOSE.js +229 -0
  6. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-2NGJGNYB.js +1765 -0
  7. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-3S3TOEBZ.js +608 -0
  8. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-46SEH6ER.js +78 -0
  9. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-52BVDZQ2.js +60299 -0
  10. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-6MHDOBWO.js +12 -0
  11. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-6WHNFJT4.js +31278 -0
  12. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-7BQRUS4C.js +671 -0
  13. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-7QWAKKTY.js +7054 -0
  14. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-CT4G24PS.js +8 -0
  15. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-DYEQRE6N.js +343 -0
  16. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-E2P6TIFG.js +31 -0
  17. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-FHNQ6DPF.js +14 -0
  18. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-HTG7JBF2.js +38 -0
  19. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-I64V3ICJ.js +11166 -0
  20. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-IKZ25GJD.js +497 -0
  21. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-MKS245OU.js +3570 -0
  22. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-NKEOCGYU.js +76 -0
  23. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-NQM5ZCTR.js +12015 -0
  24. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-OXGCUIKV.js +33 -0
  25. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-RYONFGPP.js +317 -0
  26. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-UEVQXSKG.js +4765 -0
  27. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-UFVAKOTZ.js +17 -0
  28. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-VS2QQHAK.js +46 -0
  29. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-XMVFOHGJ.js +31 -0
  30. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-XUFLSZM4.js +5319 -0
  31. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-Y6UTJIT4.js +23 -0
  32. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-YDKZZ6EH.js +3584 -0
  33. package/vendor/linkque-agent-appwrite-integrate/dist/esm/dist-QD3CV4KC.js +1224 -0
  34. package/vendor/linkque-agent-appwrite-integrate/dist/esm/google-generative-ai-IOXNKFEV.js +412 -0
  35. package/vendor/linkque-agent-appwrite-integrate/dist/esm/google-vertex-U4ZV5IXZ.js +461 -0
  36. package/vendor/linkque-agent-appwrite-integrate/dist/esm/mistral-conversations-G3K7SSWR.js +30344 -0
  37. package/vendor/linkque-agent-appwrite-integrate/dist/esm/multipart-parser-2VJ7LVQD.js +170 -0
  38. package/vendor/linkque-agent-appwrite-integrate/dist/esm/multipart-parser-AJMV6U6H.js +178 -0
  39. package/vendor/linkque-agent-appwrite-integrate/dist/esm/multipart-parser-PULXGNYO.js +368 -0
  40. package/vendor/linkque-agent-appwrite-integrate/dist/esm/openai-codex-responses-4JJLPTCS.js +1308 -0
  41. package/vendor/linkque-agent-appwrite-integrate/dist/esm/openai-completions-PH4WW6E7.js +977 -0
  42. package/vendor/linkque-agent-appwrite-integrate/dist/esm/openai-responses-KGWAX6HR.js +264 -0
  43. package/vendor/linkque-agent-appwrite-integrate/dist/esm/openrouter-images-LMBZZQ76.js +138 -0
  44. package/vendor/linkque-agent-appwrite-integrate/dist/esm/otel-7GSG7QQO.js +6657 -0
  45. package/vendor/linkque-agent-appwrite-integrate/dist/esm/pi-messages-ZX3KUWSZ.js +309 -0
  46. package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/handler/chat.js +2354 -0
  47. package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/handler/clientCapability.js +16 -0
  48. package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/protocol.js +17 -0
  49. package/vendor/linkque-agent-appwrite-integrate/dist/esm/src-NGZW4JXI.js +1396 -0
  50. package/vendor/linkque-agent-appwrite-integrate/package.json +1 -0
@@ -0,0 +1,977 @@
1
+ import {
2
+ buildCopilotDynamicHeaders,
3
+ hasCopilotVisionInput
4
+ } from "./chunk-XMVFOHGJ.js";
5
+ import {
6
+ OpenAI
7
+ } from "./chunk-7QWAKKTY.js";
8
+ import {
9
+ clampOpenAIPromptCacheKey
10
+ } from "./chunk-FHNQ6DPF.js";
11
+ import {
12
+ formatProviderError,
13
+ normalizeProviderError
14
+ } from "./chunk-NKEOCGYU.js";
15
+ import {
16
+ buildBaseOptions,
17
+ transformMessages
18
+ } from "./chunk-RYONFGPP.js";
19
+ import {
20
+ sanitizeSurrogates
21
+ } from "./chunk-CT4G24PS.js";
22
+ import {
23
+ headersToRecord
24
+ } from "./chunk-Y6UTJIT4.js";
25
+ import {
26
+ calculateCost,
27
+ clampThinkingLevel
28
+ } from "./chunk-3S3TOEBZ.js";
29
+ import {
30
+ getProviderEnvValue
31
+ } from "./chunk-OXGCUIKV.js";
32
+ import {
33
+ parseStreamingJson
34
+ } from "./chunk-DYEQRE6N.js";
35
+ import {
36
+ AssistantMessageEventStream
37
+ } from "./chunk-46SEH6ER.js";
38
+ import "./chunk-VS2QQHAK.js";
39
+
40
+ // ../../node_modules/@earendil-works/pi-ai/dist/api/openai-completions.js
41
+ function hasHeader(headers, name) {
42
+ if (!headers)
43
+ return false;
44
+ const expected = name.toLowerCase();
45
+ for (const [key, value] of Object.entries(headers)) {
46
+ if (key.toLowerCase() === expected && value !== null && value.trim().length > 0)
47
+ return true;
48
+ }
49
+ return false;
50
+ }
51
+ function getClientApiKey(provider, apiKey, headers) {
52
+ if (apiKey)
53
+ return apiKey;
54
+ if (hasHeader(headers, "authorization") || hasHeader(headers, "cf-aig-authorization"))
55
+ return "unused";
56
+ throw new Error(`No API key for provider: ${provider}`);
57
+ }
58
+ function hasToolHistory(messages) {
59
+ for (const msg of messages) {
60
+ if (msg.role === "toolResult") {
61
+ return true;
62
+ }
63
+ if (msg.role === "assistant") {
64
+ if (msg.content.some((block) => block.type === "toolCall")) {
65
+ return true;
66
+ }
67
+ }
68
+ }
69
+ return false;
70
+ }
71
+ function getDeferredToolNames(messages) {
72
+ const names = /* @__PURE__ */ new Set();
73
+ for (const message of messages) {
74
+ if (message.role === "toolResult") {
75
+ for (const name of message.addedToolNames ?? []) {
76
+ names.add(name);
77
+ }
78
+ }
79
+ }
80
+ return names;
81
+ }
82
+ function getToolsByName(tools, names) {
83
+ if (!tools)
84
+ return [];
85
+ const toolsByName = new Map(tools.map((tool) => [tool.name, tool]));
86
+ return Array.from(names).map((name) => toolsByName.get(name)).filter((tool) => tool !== void 0);
87
+ }
88
+ function isTextContentBlock(block) {
89
+ return block.type === "text";
90
+ }
91
+ function isThinkingContentBlock(block) {
92
+ return block.type === "thinking";
93
+ }
94
+ function isToolCallBlock(block) {
95
+ return block.type === "toolCall";
96
+ }
97
+ function isImageContentBlock(block) {
98
+ return block.type === "image";
99
+ }
100
+ function isEncryptedReasoningDetail(detail) {
101
+ if (typeof detail !== "object" || detail === null) {
102
+ return false;
103
+ }
104
+ const candidate = detail;
105
+ return candidate.type === "reasoning.encrypted" && typeof candidate.id === "string" && candidate.id.length > 0 && typeof candidate.data === "string" && candidate.data.length > 0;
106
+ }
107
+ function resolveCacheRetention(cacheRetention, env) {
108
+ if (cacheRetention) {
109
+ return cacheRetention;
110
+ }
111
+ if (getProviderEnvValue("PI_CACHE_RETENTION", env) === "long") {
112
+ return "long";
113
+ }
114
+ return "short";
115
+ }
116
+ var stream = (model, context, options) => {
117
+ const stream2 = new AssistantMessageEventStream();
118
+ (async () => {
119
+ const output = {
120
+ role: "assistant",
121
+ content: [],
122
+ api: model.api,
123
+ provider: model.provider,
124
+ model: model.id,
125
+ usage: {
126
+ input: 0,
127
+ output: 0,
128
+ cacheRead: 0,
129
+ cacheWrite: 0,
130
+ totalTokens: 0,
131
+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 }
132
+ },
133
+ stopReason: "stop",
134
+ timestamp: Date.now()
135
+ };
136
+ try {
137
+ const apiKey = getClientApiKey(model.provider, options?.apiKey, options?.headers);
138
+ const compat = getCompat(model);
139
+ const cacheRetention = resolveCacheRetention(options?.cacheRetention, options?.env);
140
+ const cacheSessionId = cacheRetention === "none" ? void 0 : options?.sessionId;
141
+ const client = createClient(model, context, apiKey, options?.headers, cacheSessionId, compat);
142
+ let params = buildParams(model, context, options, compat, cacheRetention);
143
+ const nextParams = await options?.onPayload?.(params, model);
144
+ if (nextParams !== void 0) {
145
+ params = nextParams;
146
+ }
147
+ const requestOptions = {
148
+ ...options?.signal ? { signal: options.signal } : {},
149
+ ...options?.timeoutMs !== void 0 ? { timeout: options.timeoutMs } : {},
150
+ maxRetries: options?.maxRetries ?? 0
151
+ };
152
+ const { data: openaiStream, response } = await client.chat.completions.create(params, requestOptions).withResponse();
153
+ await options?.onResponse?.({ status: response.status, headers: headersToRecord(response.headers) }, model);
154
+ stream2.push({ type: "start", partial: output });
155
+ let textBlock = null;
156
+ let thinkingBlock = null;
157
+ let hasFinishReason = false;
158
+ const toolCallBlocksByIndex = /* @__PURE__ */ new Map();
159
+ const toolCallBlocksById = /* @__PURE__ */ new Map();
160
+ const pendingReasoningDetailsByToolCallId = /* @__PURE__ */ new Map();
161
+ const blocks = output.content;
162
+ const getContentIndex = (block) => blocks.indexOf(block);
163
+ const finishBlock = (block) => {
164
+ const contentIndex = getContentIndex(block);
165
+ if (contentIndex === -1) {
166
+ return;
167
+ }
168
+ if (block.type === "text") {
169
+ stream2.push({
170
+ type: "text_end",
171
+ contentIndex,
172
+ content: block.text,
173
+ partial: output
174
+ });
175
+ } else if (block.type === "thinking") {
176
+ stream2.push({
177
+ type: "thinking_end",
178
+ contentIndex,
179
+ content: block.thinking,
180
+ partial: output
181
+ });
182
+ } else if (block.type === "toolCall") {
183
+ block.arguments = parseStreamingJson(block.partialArgs);
184
+ delete block.partialArgs;
185
+ delete block.streamIndex;
186
+ stream2.push({
187
+ type: "toolcall_end",
188
+ contentIndex,
189
+ toolCall: block,
190
+ partial: output
191
+ });
192
+ }
193
+ };
194
+ const ensureTextBlock = () => {
195
+ if (!textBlock) {
196
+ textBlock = { type: "text", text: "" };
197
+ blocks.push(textBlock);
198
+ stream2.push({ type: "text_start", contentIndex: getContentIndex(textBlock), partial: output });
199
+ }
200
+ return textBlock;
201
+ };
202
+ const ensureThinkingBlock = (thinkingSignature) => {
203
+ if (!thinkingBlock) {
204
+ thinkingBlock = {
205
+ type: "thinking",
206
+ thinking: "",
207
+ thinkingSignature
208
+ };
209
+ blocks.push(thinkingBlock);
210
+ stream2.push({ type: "thinking_start", contentIndex: getContentIndex(thinkingBlock), partial: output });
211
+ }
212
+ return thinkingBlock;
213
+ };
214
+ const applyPendingReasoningDetail = (block) => {
215
+ if (!block.id) {
216
+ return;
217
+ }
218
+ const pendingReasoningDetail = pendingReasoningDetailsByToolCallId.get(block.id);
219
+ if (pendingReasoningDetail) {
220
+ block.thoughtSignature = pendingReasoningDetail;
221
+ pendingReasoningDetailsByToolCallId.delete(block.id);
222
+ }
223
+ };
224
+ const ensureToolCallBlock = (toolCall) => {
225
+ const streamIndex = typeof toolCall.index === "number" ? toolCall.index : void 0;
226
+ let block = streamIndex !== void 0 ? toolCallBlocksByIndex.get(streamIndex) : void 0;
227
+ if (!block && toolCall.id) {
228
+ block = toolCallBlocksById.get(toolCall.id);
229
+ }
230
+ if (!block) {
231
+ block = {
232
+ type: "toolCall",
233
+ id: toolCall.id || "",
234
+ name: toolCall.function?.name || "",
235
+ arguments: {},
236
+ partialArgs: "",
237
+ streamIndex
238
+ };
239
+ if (streamIndex !== void 0) {
240
+ toolCallBlocksByIndex.set(streamIndex, block);
241
+ }
242
+ if (toolCall.id) {
243
+ toolCallBlocksById.set(toolCall.id, block);
244
+ }
245
+ blocks.push(block);
246
+ stream2.push({
247
+ type: "toolcall_start",
248
+ contentIndex: getContentIndex(block),
249
+ partial: output
250
+ });
251
+ }
252
+ if (streamIndex !== void 0 && block.streamIndex === void 0) {
253
+ block.streamIndex = streamIndex;
254
+ toolCallBlocksByIndex.set(streamIndex, block);
255
+ }
256
+ if (toolCall.id) {
257
+ toolCallBlocksById.set(toolCall.id, block);
258
+ }
259
+ applyPendingReasoningDetail(block);
260
+ return block;
261
+ };
262
+ for await (const chunk of openaiStream) {
263
+ if (!chunk || typeof chunk !== "object")
264
+ continue;
265
+ output.responseId ||= chunk.id;
266
+ if (typeof chunk.model === "string" && chunk.model.length > 0 && chunk.model !== model.id) {
267
+ output.responseModel ||= chunk.model;
268
+ }
269
+ if (chunk.usage) {
270
+ output.usage = parseChunkUsage(chunk.usage, model);
271
+ }
272
+ const choice = Array.isArray(chunk.choices) ? chunk.choices[0] : void 0;
273
+ if (!choice)
274
+ continue;
275
+ if (!chunk.usage && choice.usage) {
276
+ output.usage = parseChunkUsage(choice.usage, model);
277
+ }
278
+ if (choice.finish_reason) {
279
+ const finishReasonResult = mapStopReason(choice.finish_reason);
280
+ output.stopReason = finishReasonResult.stopReason;
281
+ if (finishReasonResult.errorMessage) {
282
+ output.errorMessage = finishReasonResult.errorMessage;
283
+ }
284
+ hasFinishReason = true;
285
+ }
286
+ if (choice.delta) {
287
+ if (choice.delta.content !== null && choice.delta.content !== void 0 && choice.delta.content.length > 0) {
288
+ const block = ensureTextBlock();
289
+ block.text += choice.delta.content;
290
+ stream2.push({
291
+ type: "text_delta",
292
+ contentIndex: getContentIndex(block),
293
+ delta: choice.delta.content,
294
+ partial: output
295
+ });
296
+ }
297
+ const reasoningFields = ["reasoning_content", "reasoning", "reasoning_text"];
298
+ const deltaFields = choice.delta;
299
+ let foundReasoningField = null;
300
+ for (const field of reasoningFields) {
301
+ const value = deltaFields[field];
302
+ if (typeof value === "string" && value.length > 0) {
303
+ foundReasoningField = field;
304
+ break;
305
+ }
306
+ }
307
+ if (foundReasoningField) {
308
+ const delta = deltaFields[foundReasoningField];
309
+ if (typeof delta === "string" && delta.length > 0) {
310
+ const thinkingSignature = model.provider === "opencode-go" && foundReasoningField === "reasoning" ? "reasoning_content" : foundReasoningField;
311
+ const block = ensureThinkingBlock(thinkingSignature);
312
+ block.thinking += delta;
313
+ stream2.push({
314
+ type: "thinking_delta",
315
+ contentIndex: getContentIndex(block),
316
+ delta,
317
+ partial: output
318
+ });
319
+ }
320
+ }
321
+ if (choice?.delta?.tool_calls) {
322
+ for (const toolCall of choice.delta.tool_calls) {
323
+ const block = ensureToolCallBlock(toolCall);
324
+ if (!block.id && toolCall.id) {
325
+ block.id = toolCall.id;
326
+ toolCallBlocksById.set(toolCall.id, block);
327
+ }
328
+ if (!block.name && toolCall.function?.name) {
329
+ block.name = toolCall.function.name;
330
+ }
331
+ let delta = "";
332
+ if (toolCall.function?.arguments) {
333
+ delta = toolCall.function.arguments;
334
+ block.partialArgs = (block.partialArgs ?? "") + toolCall.function.arguments;
335
+ block.arguments = parseStreamingJson(block.partialArgs);
336
+ }
337
+ stream2.push({
338
+ type: "toolcall_delta",
339
+ contentIndex: getContentIndex(block),
340
+ delta,
341
+ partial: output
342
+ });
343
+ }
344
+ }
345
+ const reasoningDetails = choice.delta.reasoning_details;
346
+ if (Array.isArray(reasoningDetails)) {
347
+ for (const detail of reasoningDetails) {
348
+ if (isEncryptedReasoningDetail(detail)) {
349
+ const serializedDetail = JSON.stringify(detail);
350
+ const matchingToolCall = toolCallBlocksById.get(detail.id);
351
+ if (matchingToolCall) {
352
+ matchingToolCall.thoughtSignature = serializedDetail;
353
+ } else {
354
+ pendingReasoningDetailsByToolCallId.set(detail.id, serializedDetail);
355
+ }
356
+ }
357
+ }
358
+ }
359
+ }
360
+ }
361
+ for (const block of blocks) {
362
+ finishBlock(block);
363
+ }
364
+ if (options?.signal?.aborted) {
365
+ throw new Error("Request was aborted");
366
+ }
367
+ if (output.stopReason === "aborted") {
368
+ throw new Error("Request was aborted");
369
+ }
370
+ if (output.stopReason === "error") {
371
+ throw new Error(output.errorMessage || "Provider returned an error stop reason");
372
+ }
373
+ if (!hasFinishReason) {
374
+ throw new Error("Stream ended without finish_reason");
375
+ }
376
+ stream2.push({ type: "done", reason: output.stopReason, message: output });
377
+ stream2.end();
378
+ } catch (error) {
379
+ for (const block of output.content) {
380
+ delete block.index;
381
+ delete block.partialArgs;
382
+ delete block.streamIndex;
383
+ }
384
+ output.stopReason = options?.signal?.aborted ? "aborted" : "error";
385
+ output.errorMessage = formatProviderError(normalizeProviderError(error));
386
+ const rawMetadata = error?.error?.metadata?.raw;
387
+ if (rawMetadata && !output.errorMessage.includes(String(rawMetadata))) {
388
+ output.errorMessage += `
389
+ ${rawMetadata}`;
390
+ }
391
+ stream2.push({ type: "error", reason: output.stopReason, error: output });
392
+ stream2.end();
393
+ }
394
+ })();
395
+ return stream2;
396
+ };
397
+ var streamSimple = (model, context, options) => {
398
+ getClientApiKey(model.provider, options?.apiKey, options?.headers);
399
+ const base = buildBaseOptions(model, context, options, options?.apiKey);
400
+ const clampedReasoning = options?.reasoning ? clampThinkingLevel(model, options.reasoning) : void 0;
401
+ const reasoningEffort = clampedReasoning === "off" ? void 0 : clampedReasoning;
402
+ const toolChoice = options?.toolChoice;
403
+ return stream(model, context, {
404
+ ...base,
405
+ reasoningEffort,
406
+ toolChoice
407
+ });
408
+ };
409
+ function createClient(model, context, apiKey, optionsHeaders, sessionId, compat = getCompat(model)) {
410
+ const headers = { ...model.headers };
411
+ if (model.provider === "github-copilot") {
412
+ const hasImages = hasCopilotVisionInput(context.messages);
413
+ const copilotHeaders = buildCopilotDynamicHeaders({
414
+ messages: context.messages,
415
+ hasImages
416
+ });
417
+ Object.assign(headers, copilotHeaders);
418
+ }
419
+ if (sessionId && compat.sendSessionAffinityHeaders) {
420
+ if (compat.sessionAffinityFormat === "openrouter") {
421
+ headers["x-session-id"] = sessionId;
422
+ } else {
423
+ if (compat.sessionAffinityFormat === "openai") {
424
+ headers.session_id = sessionId;
425
+ }
426
+ headers["x-client-request-id"] = sessionId;
427
+ headers["x-session-affinity"] = sessionId;
428
+ }
429
+ }
430
+ if (optionsHeaders) {
431
+ Object.assign(headers, optionsHeaders);
432
+ }
433
+ return new OpenAI({
434
+ apiKey,
435
+ baseURL: model.baseUrl,
436
+ dangerouslyAllowBrowser: true,
437
+ defaultHeaders: headers
438
+ });
439
+ }
440
+ function buildParams(model, context, options, compat = getCompat(model), cacheRetention = resolveCacheRetention(options?.cacheRetention, options?.env)) {
441
+ const messages = convertMessages(model, context, compat);
442
+ const cacheControl = getCompatCacheControl(compat, cacheRetention);
443
+ const params = {
444
+ model: model.id,
445
+ messages,
446
+ stream: true,
447
+ prompt_cache_key: model.baseUrl.includes("api.openai.com") && cacheRetention !== "none" || cacheRetention === "long" && compat.supportsLongCacheRetention ? clampOpenAIPromptCacheKey(options?.sessionId) : void 0,
448
+ prompt_cache_retention: cacheRetention === "long" && compat.supportsLongCacheRetention ? "24h" : void 0
449
+ };
450
+ if (compat.supportsUsageInStreaming !== false) {
451
+ params.stream_options = { include_usage: true };
452
+ }
453
+ if (compat.supportsStore) {
454
+ params.store = false;
455
+ }
456
+ if (options?.maxTokens) {
457
+ if (compat.maxTokensField === "max_tokens") {
458
+ params.max_tokens = options.maxTokens;
459
+ } else {
460
+ params.max_completion_tokens = options.maxTokens;
461
+ }
462
+ }
463
+ if (options?.temperature !== void 0) {
464
+ params.temperature = options.temperature;
465
+ }
466
+ const deferredToolNames = compat.deferredToolsMode === "kimi" ? getDeferredToolNames(context.messages) : /* @__PURE__ */ new Set();
467
+ const activeTools = context.tools?.filter((tool) => !deferredToolNames.has(tool.name));
468
+ if (activeTools && activeTools.length > 0) {
469
+ params.tools = convertTools(activeTools, compat);
470
+ if (compat.zaiToolStream) {
471
+ params.tool_stream = true;
472
+ }
473
+ } else if (hasToolHistory(context.messages)) {
474
+ params.tools = [];
475
+ }
476
+ if (cacheControl) {
477
+ applyAnthropicCacheControl(messages, params.tools, cacheControl);
478
+ }
479
+ if (options?.toolChoice) {
480
+ params.tool_choice = options.toolChoice;
481
+ }
482
+ if (compat.thinkingFormat === "zai" && model.reasoning) {
483
+ const zaiParams = params;
484
+ zaiParams.thinking = options?.reasoningEffort ? { type: "enabled", clear_thinking: false } : { type: "disabled" };
485
+ if (options?.reasoningEffort && compat.supportsReasoningEffort) {
486
+ const mappedEffort = model.thinkingLevelMap?.[options.reasoningEffort];
487
+ const effort = mappedEffort === void 0 ? options.reasoningEffort : mappedEffort;
488
+ if (typeof effort === "string") {
489
+ zaiParams.reasoning_effort = effort;
490
+ }
491
+ }
492
+ } else if (compat.thinkingFormat === "qwen" && model.reasoning) {
493
+ params.enable_thinking = !!options?.reasoningEffort;
494
+ } else if (compat.thinkingFormat === "qwen-chat-template" && model.reasoning) {
495
+ params.chat_template_kwargs = {
496
+ enable_thinking: !!options?.reasoningEffort,
497
+ preserve_thinking: true
498
+ };
499
+ } else if (compat.thinkingFormat === "chat-template" && model.reasoning) {
500
+ const chatTemplateKwargs = buildChatTemplateKwargs(model, options, compat);
501
+ if (chatTemplateKwargs) {
502
+ params.chat_template_kwargs = chatTemplateKwargs;
503
+ }
504
+ } else if (compat.thinkingFormat === "deepseek" && model.reasoning) {
505
+ if (options?.reasoningEffort) {
506
+ params.thinking = { type: "enabled" };
507
+ } else if (model.thinkingLevelMap?.off !== null) {
508
+ params.thinking = { type: "disabled" };
509
+ }
510
+ if (options?.reasoningEffort && compat.supportsReasoningEffort) {
511
+ params.reasoning_effort = model.thinkingLevelMap?.[options.reasoningEffort] ?? options.reasoningEffort;
512
+ }
513
+ } else if (compat.thinkingFormat === "openrouter" && model.reasoning) {
514
+ const openRouterParams = params;
515
+ if (options?.reasoningEffort) {
516
+ openRouterParams.reasoning = {
517
+ effort: model.thinkingLevelMap?.[options.reasoningEffort] ?? options.reasoningEffort
518
+ };
519
+ } else if (model.thinkingLevelMap?.off !== null) {
520
+ openRouterParams.reasoning = { effort: model.thinkingLevelMap?.off ?? "none" };
521
+ }
522
+ } else if (compat.thinkingFormat === "ant-ling" && model.reasoning && options?.reasoningEffort) {
523
+ const effort = model.thinkingLevelMap?.[options.reasoningEffort];
524
+ if (typeof effort === "string") {
525
+ params.reasoning = { effort };
526
+ }
527
+ } else if (compat.thinkingFormat === "together" && model.reasoning) {
528
+ const togetherParams = params;
529
+ togetherParams.reasoning = { enabled: !!options?.reasoningEffort };
530
+ if (options?.reasoningEffort && compat.supportsReasoningEffort) {
531
+ togetherParams.reasoning_effort = model.thinkingLevelMap?.[options.reasoningEffort] ?? options.reasoningEffort;
532
+ }
533
+ } else if (compat.thinkingFormat === "string-thinking" && model.reasoning) {
534
+ const stringThinkingParams = params;
535
+ if (options?.reasoningEffort) {
536
+ stringThinkingParams.thinking = model.thinkingLevelMap?.[options.reasoningEffort] ?? options.reasoningEffort;
537
+ } else if (model.thinkingLevelMap?.off !== null) {
538
+ stringThinkingParams.thinking = model.thinkingLevelMap?.off ?? "none";
539
+ }
540
+ } else if (options?.reasoningEffort && model.reasoning && compat.supportsReasoningEffort) {
541
+ params.reasoning_effort = model.thinkingLevelMap?.[options.reasoningEffort] ?? options.reasoningEffort;
542
+ } else if (!options?.reasoningEffort && model.reasoning && compat.supportsReasoningEffort) {
543
+ const offValue = model.thinkingLevelMap?.off;
544
+ if (typeof offValue === "string") {
545
+ params.reasoning_effort = offValue;
546
+ }
547
+ }
548
+ if (model.compat?.openRouterRouting) {
549
+ params.provider = model.compat.openRouterRouting;
550
+ }
551
+ if (model.compat?.vercelGatewayRouting) {
552
+ const routing = model.compat.vercelGatewayRouting;
553
+ if (routing.only || routing.order) {
554
+ const gatewayOptions = {};
555
+ if (routing.only)
556
+ gatewayOptions.only = routing.only;
557
+ if (routing.order)
558
+ gatewayOptions.order = routing.order;
559
+ params.providerOptions = { gateway: gatewayOptions };
560
+ }
561
+ }
562
+ return params;
563
+ }
564
+ function buildChatTemplateKwargs(model, options, compat) {
565
+ const kwargs = {};
566
+ for (const [key, value] of Object.entries(compat.chatTemplateKwargs)) {
567
+ const resolved = resolveChatTemplateKwargValue(model, options, value);
568
+ if (resolved !== void 0) {
569
+ kwargs[key] = resolved;
570
+ }
571
+ }
572
+ return Object.keys(kwargs).length > 0 ? kwargs : void 0;
573
+ }
574
+ function resolveChatTemplateKwargValue(model, options, value) {
575
+ if (typeof value !== "object" || value === null) {
576
+ return value;
577
+ }
578
+ const reasoningEffort = options?.reasoningEffort;
579
+ if (!reasoningEffort && value.omitWhenOff) {
580
+ return void 0;
581
+ }
582
+ if (value.$var === "thinking.enabled") {
583
+ return !!reasoningEffort;
584
+ }
585
+ const mappedValue = reasoningEffort ? model.thinkingLevelMap?.[reasoningEffort] : model.thinkingLevelMap?.off;
586
+ return mappedValue === void 0 ? reasoningEffort : typeof mappedValue === "string" ? mappedValue : void 0;
587
+ }
588
+ function getCompatCacheControl(compat, cacheRetention) {
589
+ if (compat.cacheControlFormat !== "anthropic" || cacheRetention === "none") {
590
+ return void 0;
591
+ }
592
+ const ttl = cacheRetention === "long" && compat.supportsLongCacheRetention ? "1h" : void 0;
593
+ return { type: "ephemeral", ...ttl ? { ttl } : {} };
594
+ }
595
+ function applyAnthropicCacheControl(messages, tools, cacheControl) {
596
+ addCacheControlToSystemPrompt(messages, cacheControl);
597
+ addCacheControlToLastTool(tools, cacheControl);
598
+ addCacheControlToLastConversationMessage(messages, cacheControl);
599
+ }
600
+ function addCacheControlToSystemPrompt(messages, cacheControl) {
601
+ for (const message of messages) {
602
+ if (message.role === "system" || message.role === "developer") {
603
+ addCacheControlToInstructionMessage(message, cacheControl);
604
+ return;
605
+ }
606
+ }
607
+ }
608
+ function addCacheControlToLastConversationMessage(messages, cacheControl) {
609
+ for (let i = messages.length - 1; i >= 0; i--) {
610
+ const message = messages[i];
611
+ if (message.role === "user" || message.role === "assistant") {
612
+ if (addCacheControlToMessage(message, cacheControl)) {
613
+ return;
614
+ }
615
+ }
616
+ }
617
+ }
618
+ function addCacheControlToLastTool(tools, cacheControl) {
619
+ if (!tools || tools.length === 0) {
620
+ return;
621
+ }
622
+ const lastTool = tools[tools.length - 1];
623
+ lastTool.cache_control = cacheControl;
624
+ }
625
+ function addCacheControlToInstructionMessage(message, cacheControl) {
626
+ return addCacheControlToTextContent(message, cacheControl);
627
+ }
628
+ function addCacheControlToMessage(message, cacheControl) {
629
+ if (message.role === "user" || message.role === "assistant") {
630
+ return addCacheControlToTextContent(message, cacheControl);
631
+ }
632
+ return false;
633
+ }
634
+ function addCacheControlToTextContent(message, cacheControl) {
635
+ const content = message.content;
636
+ if (typeof content === "string") {
637
+ if (content.length === 0) {
638
+ return false;
639
+ }
640
+ message.content = [
641
+ {
642
+ type: "text",
643
+ text: content,
644
+ cache_control: cacheControl
645
+ }
646
+ ];
647
+ return true;
648
+ }
649
+ if (!Array.isArray(content)) {
650
+ return false;
651
+ }
652
+ for (let i = content.length - 1; i >= 0; i--) {
653
+ const part = content[i];
654
+ if (part?.type === "text") {
655
+ const textPart = part;
656
+ textPart.cache_control = cacheControl;
657
+ return true;
658
+ }
659
+ }
660
+ return false;
661
+ }
662
+ function convertMessages(model, context, compat) {
663
+ const params = [];
664
+ const normalizeToolCallId = (id) => {
665
+ if (id.includes("|")) {
666
+ const [callId] = id.split("|");
667
+ return callId.replace(/[^a-zA-Z0-9_-]/g, "_").slice(0, 40);
668
+ }
669
+ if (model.provider === "openai")
670
+ return id.length > 40 ? id.slice(0, 40) : id;
671
+ return id;
672
+ };
673
+ const transformedMessages = transformMessages(context.messages, model, (id) => normalizeToolCallId(id));
674
+ if (context.systemPrompt) {
675
+ const useDeveloperRole = model.reasoning && compat.supportsDeveloperRole;
676
+ const role = useDeveloperRole ? "developer" : "system";
677
+ params.push({ role, content: sanitizeSurrogates(context.systemPrompt) });
678
+ }
679
+ let lastRole = null;
680
+ for (let i = 0; i < transformedMessages.length; i++) {
681
+ const msg = transformedMessages[i];
682
+ if (compat.requiresAssistantAfterToolResult && lastRole === "toolResult" && msg.role === "user") {
683
+ params.push({
684
+ role: "assistant",
685
+ content: "I have processed the tool results."
686
+ });
687
+ }
688
+ if (msg.role === "user") {
689
+ if (typeof msg.content === "string") {
690
+ params.push({
691
+ role: "user",
692
+ content: sanitizeSurrogates(msg.content)
693
+ });
694
+ } else {
695
+ const content = msg.content.map((item) => {
696
+ if (item.type === "text") {
697
+ return {
698
+ type: "text",
699
+ text: sanitizeSurrogates(item.text)
700
+ };
701
+ } else {
702
+ return {
703
+ type: "image_url",
704
+ image_url: {
705
+ url: `data:${item.mimeType};base64,${item.data}`
706
+ }
707
+ };
708
+ }
709
+ });
710
+ if (content.length === 0)
711
+ continue;
712
+ params.push({
713
+ role: "user",
714
+ content
715
+ });
716
+ }
717
+ } else if (msg.role === "assistant") {
718
+ const assistantMsg = {
719
+ role: "assistant",
720
+ content: compat.requiresAssistantAfterToolResult ? "" : null
721
+ };
722
+ const assistantTextParts = msg.content.filter(isTextContentBlock).filter((block) => block.text.trim().length > 0).map((block) => ({
723
+ type: "text",
724
+ text: sanitizeSurrogates(block.text)
725
+ }));
726
+ const assistantText = assistantTextParts.map((part) => part.text).join("");
727
+ const nonEmptyThinkingBlocks = msg.content.filter(isThinkingContentBlock).filter((block) => block.thinking.trim().length > 0);
728
+ if (nonEmptyThinkingBlocks.length > 0) {
729
+ if (compat.requiresThinkingAsText) {
730
+ const thinkingText = nonEmptyThinkingBlocks.map((block) => sanitizeSurrogates(block.thinking)).join("\n\n");
731
+ assistantMsg.content = [{ type: "text", text: thinkingText }, ...assistantTextParts];
732
+ } else {
733
+ if (assistantText.length > 0) {
734
+ assistantMsg.content = assistantText;
735
+ }
736
+ let signature = nonEmptyThinkingBlocks[0].thinkingSignature;
737
+ if (model.provider === "opencode-go" && signature === "reasoning") {
738
+ signature = "reasoning_content";
739
+ }
740
+ if (signature && signature.length > 0) {
741
+ assistantMsg[signature] = nonEmptyThinkingBlocks.map((block) => block.thinking).join("\n");
742
+ }
743
+ }
744
+ } else if (assistantText.length > 0) {
745
+ assistantMsg.content = assistantText;
746
+ }
747
+ const toolCalls = msg.content.filter(isToolCallBlock);
748
+ if (toolCalls.length > 0) {
749
+ assistantMsg.tool_calls = toolCalls.map((tc) => ({
750
+ id: tc.id,
751
+ type: "function",
752
+ function: {
753
+ name: tc.name,
754
+ arguments: JSON.stringify(tc.arguments)
755
+ }
756
+ }));
757
+ const reasoningDetails = toolCalls.filter((tc) => tc.thoughtSignature).map((tc) => {
758
+ try {
759
+ return JSON.parse(tc.thoughtSignature);
760
+ } catch {
761
+ return null;
762
+ }
763
+ }).filter(Boolean);
764
+ if (reasoningDetails.length > 0) {
765
+ assistantMsg.reasoning_details = reasoningDetails;
766
+ }
767
+ }
768
+ if (compat.requiresReasoningContentOnAssistantMessages && model.reasoning && assistantMsg.reasoning_content === void 0) {
769
+ assistantMsg.reasoning_content = "";
770
+ }
771
+ const content = assistantMsg.content;
772
+ const hasContent = content !== null && content !== void 0 && (typeof content === "string" ? content.length > 0 : content.length > 0);
773
+ if (!hasContent && !assistantMsg.tool_calls) {
774
+ continue;
775
+ }
776
+ params.push(assistantMsg);
777
+ } else if (msg.role === "toolResult") {
778
+ const imageBlocks = [];
779
+ const deferredToolNames = /* @__PURE__ */ new Set();
780
+ let j = i;
781
+ for (; j < transformedMessages.length && transformedMessages[j].role === "toolResult"; j++) {
782
+ const toolMsg = transformedMessages[j];
783
+ const textResult = toolMsg.content.filter(isTextContentBlock).map((block) => block.text).join("\n");
784
+ const hasImages = toolMsg.content.some((c) => c.type === "image");
785
+ const hasText = textResult.length > 0;
786
+ const toolResultText = hasText ? textResult : hasImages ? "(see attached image)" : "(no tool output)";
787
+ const toolResultMsg = {
788
+ role: "tool",
789
+ content: sanitizeSurrogates(toolResultText),
790
+ tool_call_id: toolMsg.toolCallId
791
+ };
792
+ if (compat.requiresToolResultName && toolMsg.toolName) {
793
+ toolResultMsg.name = toolMsg.toolName;
794
+ }
795
+ params.push(toolResultMsg);
796
+ if (compat.deferredToolsMode === "kimi") {
797
+ for (const name of toolMsg.addedToolNames ?? []) {
798
+ deferredToolNames.add(name);
799
+ }
800
+ }
801
+ if (hasImages && model.input.includes("image")) {
802
+ for (const block of toolMsg.content) {
803
+ if (isImageContentBlock(block)) {
804
+ imageBlocks.push({
805
+ type: "image_url",
806
+ image_url: {
807
+ url: `data:${block.mimeType};base64,${block.data}`
808
+ }
809
+ });
810
+ }
811
+ }
812
+ }
813
+ }
814
+ i = j - 1;
815
+ if (imageBlocks.length > 0) {
816
+ if (compat.requiresAssistantAfterToolResult) {
817
+ params.push({
818
+ role: "assistant",
819
+ content: "I have processed the tool results."
820
+ });
821
+ }
822
+ params.push({
823
+ role: "user",
824
+ content: [
825
+ {
826
+ type: "text",
827
+ text: "Attached image(s) from tool result:"
828
+ },
829
+ ...imageBlocks
830
+ ]
831
+ });
832
+ lastRole = "user";
833
+ } else {
834
+ lastRole = "toolResult";
835
+ }
836
+ if (deferredToolNames.size > 0) {
837
+ const deferredTools = getToolsByName(context.tools, deferredToolNames);
838
+ if (deferredTools.length > 0) {
839
+ const kimiToolMessage = {
840
+ role: "system",
841
+ tools: convertTools(deferredTools, compat)
842
+ };
843
+ params.push(kimiToolMessage);
844
+ }
845
+ }
846
+ continue;
847
+ }
848
+ lastRole = msg.role;
849
+ }
850
+ return params;
851
+ }
852
+ function convertTools(tools, compat) {
853
+ return tools.map((tool) => ({
854
+ type: "function",
855
+ function: {
856
+ name: tool.name,
857
+ description: tool.description,
858
+ parameters: tool.parameters,
859
+ // TypeBox already generates JSON Schema
860
+ // Only include strict if provider supports it. Some reject unknown fields.
861
+ ...compat.supportsStrictMode !== false && { strict: false }
862
+ }
863
+ }));
864
+ }
865
+ function parseChunkUsage(rawUsage, model) {
866
+ const promptTokens = rawUsage.prompt_tokens || 0;
867
+ const cacheReadTokens = rawUsage.prompt_tokens_details?.cached_tokens ?? rawUsage.prompt_cache_hit_tokens ?? 0;
868
+ const cacheWriteTokens = rawUsage.prompt_tokens_details?.cache_write_tokens || 0;
869
+ const input = Math.max(0, promptTokens - cacheReadTokens - cacheWriteTokens);
870
+ const outputTokens = rawUsage.completion_tokens || 0;
871
+ const usage = {
872
+ input,
873
+ output: outputTokens,
874
+ cacheRead: cacheReadTokens,
875
+ cacheWrite: cacheWriteTokens,
876
+ reasoning: rawUsage.completion_tokens_details?.reasoning_tokens || 0,
877
+ totalTokens: input + outputTokens + cacheReadTokens + cacheWriteTokens,
878
+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 }
879
+ };
880
+ calculateCost(model, usage);
881
+ return usage;
882
+ }
883
+ function mapStopReason(reason) {
884
+ if (reason === null)
885
+ return { stopReason: "stop" };
886
+ switch (reason) {
887
+ case "stop":
888
+ case "end":
889
+ return { stopReason: "stop" };
890
+ case "length":
891
+ return { stopReason: "length" };
892
+ case "function_call":
893
+ case "tool_calls":
894
+ return { stopReason: "toolUse" };
895
+ case "content_filter":
896
+ return { stopReason: "error", errorMessage: "Provider finish_reason: content_filter" };
897
+ case "network_error":
898
+ return { stopReason: "error", errorMessage: "Provider finish_reason: network_error" };
899
+ default:
900
+ return {
901
+ stopReason: "error",
902
+ errorMessage: `Provider finish_reason: ${reason}`
903
+ };
904
+ }
905
+ }
906
+ function detectCompat(model) {
907
+ const provider = model.provider;
908
+ const baseUrl = model.baseUrl;
909
+ const isZai = provider === "zai" || provider === "zai-coding-cn" || baseUrl.includes("api.z.ai") || baseUrl.includes("open.bigmodel.cn");
910
+ const isTogether = provider === "together" || baseUrl.includes("api.together.ai") || baseUrl.includes("api.together.xyz");
911
+ const isMoonshot = provider === "moonshotai" || provider === "moonshotai-cn" || baseUrl.includes("api.moonshot.");
912
+ const isOpenRouter = provider === "openrouter" || baseUrl.includes("openrouter.ai");
913
+ const isCloudflareWorkersAI = provider === "cloudflare-workers-ai" || baseUrl.includes("api.cloudflare.com");
914
+ const isCloudflareAiGateway = provider === "cloudflare-ai-gateway" || baseUrl.includes("gateway.ai.cloudflare.com");
915
+ const isNvidia = provider === "nvidia" || baseUrl.includes("integrate.api.nvidia.com");
916
+ const isAntLing = provider === "ant-ling" || baseUrl.includes("api.ant-ling.com");
917
+ const isNonStandard = isNvidia || provider === "cerebras" || baseUrl.includes("cerebras.ai") || provider === "xai" || baseUrl.includes("api.x.ai") || isTogether || baseUrl.includes("chutes.ai") || baseUrl.includes("deepseek.com") || isZai || isMoonshot || provider === "opencode" || baseUrl.includes("opencode.ai") || isCloudflareWorkersAI || isCloudflareAiGateway || isAntLing;
918
+ const useMaxTokens = baseUrl.includes("chutes.ai") || isMoonshot || isCloudflareAiGateway || isTogether || isNvidia || isAntLing;
919
+ const isGrok = provider === "xai" || baseUrl.includes("api.x.ai");
920
+ const isDeepSeek = provider === "deepseek" || baseUrl.includes("deepseek.com");
921
+ const isOpenRouterDeveloperRoleModel = isOpenRouter && (model.id.startsWith("anthropic/") || model.id.startsWith("openai/"));
922
+ const cacheControlFormat = provider === "openrouter" && model.id.startsWith("anthropic/") ? "anthropic" : void 0;
923
+ return {
924
+ supportsStore: !isNonStandard,
925
+ supportsDeveloperRole: isOpenRouterDeveloperRoleModel || !isNonStandard && !isOpenRouter,
926
+ supportsReasoningEffort: !isGrok && !isZai && !isMoonshot && !isTogether && !isCloudflareAiGateway && !isNvidia && !isAntLing,
927
+ supportsUsageInStreaming: true,
928
+ maxTokensField: useMaxTokens ? "max_tokens" : "max_completion_tokens",
929
+ requiresToolResultName: false,
930
+ requiresAssistantAfterToolResult: false,
931
+ requiresThinkingAsText: false,
932
+ requiresReasoningContentOnAssistantMessages: isDeepSeek,
933
+ thinkingFormat: isDeepSeek ? "deepseek" : isZai ? "zai" : isTogether ? "together" : isAntLing ? "ant-ling" : isOpenRouter ? "openrouter" : "openai",
934
+ openRouterRouting: {},
935
+ vercelGatewayRouting: {},
936
+ chatTemplateKwargs: {},
937
+ zaiToolStream: false,
938
+ supportsStrictMode: !isMoonshot && !isTogether && !isCloudflareAiGateway && !isNvidia,
939
+ cacheControlFormat,
940
+ sendSessionAffinityHeaders: false,
941
+ deferredToolsMode: void 0,
942
+ sessionAffinityFormat: isOpenRouter ? "openrouter" : "openai",
943
+ supportsLongCacheRetention: !(isTogether || isCloudflareWorkersAI || isCloudflareAiGateway || isNvidia || isAntLing)
944
+ };
945
+ }
946
+ function getCompat(model) {
947
+ const detected = detectCompat(model);
948
+ if (!model.compat)
949
+ return detected;
950
+ return {
951
+ supportsStore: model.compat.supportsStore ?? detected.supportsStore,
952
+ supportsDeveloperRole: model.compat.supportsDeveloperRole ?? detected.supportsDeveloperRole,
953
+ supportsReasoningEffort: model.compat.supportsReasoningEffort ?? detected.supportsReasoningEffort,
954
+ supportsUsageInStreaming: model.compat.supportsUsageInStreaming ?? detected.supportsUsageInStreaming,
955
+ maxTokensField: model.compat.maxTokensField ?? detected.maxTokensField,
956
+ requiresToolResultName: model.compat.requiresToolResultName ?? detected.requiresToolResultName,
957
+ requiresAssistantAfterToolResult: model.compat.requiresAssistantAfterToolResult ?? detected.requiresAssistantAfterToolResult,
958
+ requiresThinkingAsText: model.compat.requiresThinkingAsText ?? detected.requiresThinkingAsText,
959
+ requiresReasoningContentOnAssistantMessages: model.compat.requiresReasoningContentOnAssistantMessages ?? detected.requiresReasoningContentOnAssistantMessages,
960
+ thinkingFormat: model.compat.thinkingFormat ?? detected.thinkingFormat,
961
+ openRouterRouting: model.compat.openRouterRouting ?? {},
962
+ vercelGatewayRouting: model.compat.vercelGatewayRouting ?? detected.vercelGatewayRouting,
963
+ chatTemplateKwargs: model.compat.chatTemplateKwargs ?? detected.chatTemplateKwargs,
964
+ zaiToolStream: model.compat.zaiToolStream ?? detected.zaiToolStream,
965
+ supportsStrictMode: model.compat.supportsStrictMode ?? detected.supportsStrictMode,
966
+ cacheControlFormat: model.compat.cacheControlFormat ?? detected.cacheControlFormat,
967
+ sendSessionAffinityHeaders: model.compat.sendSessionAffinityHeaders ?? detected.sendSessionAffinityHeaders,
968
+ deferredToolsMode: model.compat.deferredToolsMode ?? detected.deferredToolsMode,
969
+ sessionAffinityFormat: model.compat.sessionAffinityFormat ?? detected.sessionAffinityFormat,
970
+ supportsLongCacheRetention: model.compat.supportsLongCacheRetention ?? detected.supportsLongCacheRetention
971
+ };
972
+ }
973
+ export {
974
+ convertMessages,
975
+ stream,
976
+ streamSimple
977
+ };