omnigateway 0.4.12 → 0.4.13

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 (25) hide show
  1. package/README.md +86 -238
  2. package/bin/omni.js +868 -377
  3. package/gateway.js +864 -348
  4. package/package.json +1 -1
  5. package/public/assets/{CopyValue-By5BAgv7.js → CopyValue-C2DkO9Yz.js} +1 -1
  6. package/public/assets/{Rack-fDZClWZL.js → Rack-HM36SprU.js} +1 -1
  7. package/public/assets/{Toggle-ClEeOh0F.js → Toggle-CRrH9nDt.js} +1 -1
  8. package/public/assets/{TokenBreakdown-D70VeZ2N.js → TokenBreakdown-C2NsJnqO.js} +1 -1
  9. package/public/assets/{_app-CDPKnQ72.js → _app-DVpIsUid.js} +1 -1
  10. package/public/assets/{_app.accounts-Dz0ox4Br.js → _app.accounts-64d_cxir.js} +2 -2
  11. package/public/assets/{_app.console-hPUmmYjp.js → _app.console-BBuBmLRI.js} +1 -1
  12. package/public/assets/{_app.database-DGtP4NdG.js → _app.database-J9Ujio8l.js} +1 -1
  13. package/public/assets/{_app.index-COcCAmbH.js → _app.index-BX4yKEXO.js} +1 -1
  14. package/public/assets/{_app.keys-yTXTbKTA.js → _app.keys-2sKwhZJc.js} +1 -1
  15. package/public/assets/{_app.logs-BhMvO_Fx.js → _app.logs-DuHXYrZU.js} +1 -1
  16. package/public/assets/{_app.models-0S3rurIl.js → _app.models-B0kTfPtn.js} +1 -1
  17. package/public/assets/{_app.plugins._pluginId-B-ZDQNPU.js → _app.plugins._pluginId-BOXRBToU.js} +1 -1
  18. package/public/assets/{_app.settings-DTnFwTeA.js → _app.settings-DoaOUmc1.js} +1 -1
  19. package/public/assets/{_app.usage-C2-VLiq9.js → _app.usage-B5sxB40E.js} +1 -1
  20. package/public/assets/{index-COwhxKU7.js → index-iCfSaRSG.js} +2 -2
  21. package/public/assets/{login-DjfMomJJ.js → login-B9CJqU--.js} +1 -1
  22. package/public/assets/plus-DKapAGoR.js +1 -0
  23. package/public/assets/{trash-2-U2ViYZum.js → trash-2-DwMK-JrZ.js} +1 -1
  24. package/public/index.html +1 -1
  25. package/public/assets/plus-UDQ_BTEr.js +0 -1
package/bin/omni.js CHANGED
@@ -2140,13 +2140,31 @@ var anthropicAdapter = {
2140
2140
  };
2141
2141
  }
2142
2142
  };
2143
- // packages/providers/src/kimi/decode.ts
2144
- var FINISH = {
2143
+ // packages/providers/src/custom/decode.ts
2144
+ var CHAT_FINISH = {
2145
2145
  stop: "endTurn",
2146
2146
  length: "maxTokens",
2147
2147
  tool_calls: "toolUse",
2148
2148
  content_filter: "contentFilter"
2149
2149
  };
2150
+ function reasoningText(delta) {
2151
+ if (typeof delta.reasoning === "string" && delta.reasoning.length > 0)
2152
+ return delta.reasoning;
2153
+ if (typeof delta.reasoning_content === "string" && delta.reasoning_content.length > 0) {
2154
+ return delta.reasoning_content;
2155
+ }
2156
+ if (!Array.isArray(delta.reasoning_details))
2157
+ return "";
2158
+ return delta.reasoning_details.flatMap((entry) => {
2159
+ if (entry === null || typeof entry !== "object")
2160
+ return [];
2161
+ if (typeof entry.text === "string" && entry.text.length > 0)
2162
+ return [entry.text];
2163
+ if (typeof entry.summary === "string" && entry.summary.length > 0)
2164
+ return [entry.summary];
2165
+ return [];
2166
+ }).join("");
2167
+ }
2150
2168
  function json2(data) {
2151
2169
  try {
2152
2170
  const v = JSON.parse(data);
@@ -2155,7 +2173,7 @@ function json2(data) {
2155
2173
  return null;
2156
2174
  }
2157
2175
  }
2158
- async function* decodeChat(messages) {
2176
+ async function* decodeCustomChat(messages) {
2159
2177
  let started = false;
2160
2178
  let done = false;
2161
2179
  let stopReason = "endTurn";
@@ -2184,6 +2202,21 @@ async function* decodeChat(messages) {
2184
2202
  if (!choice)
2185
2203
  continue;
2186
2204
  const delta = choice.delta ?? {};
2205
+ const reasoning = reasoningText(delta);
2206
+ if (reasoning.length > 0) {
2207
+ if (openKind !== "thinking") {
2208
+ if (openKind !== undefined)
2209
+ yield { type: "blockEnd", index: openIndex };
2210
+ openKind = "thinking";
2211
+ openIndex = nextIndex++;
2212
+ yield { type: "blockStart", index: openIndex, block: { type: "thinking" } };
2213
+ }
2214
+ yield {
2215
+ type: "blockDelta",
2216
+ index: openIndex,
2217
+ delta: { type: "thinking", text: reasoning }
2218
+ };
2219
+ }
2187
2220
  if (typeof delta.content === "string" && delta.content.length > 0) {
2188
2221
  if (openKind !== "text") {
2189
2222
  if (openKind !== undefined)
@@ -2224,7 +2257,7 @@ async function* decodeChat(messages) {
2224
2257
  }
2225
2258
  }
2226
2259
  if (typeof choice.finish_reason === "string") {
2227
- stopReason = FINISH[choice.finish_reason] ?? "endTurn";
2260
+ stopReason = CHAT_FINISH[choice.finish_reason] ?? "endTurn";
2228
2261
  }
2229
2262
  }
2230
2263
  if (done) {
@@ -2240,110 +2273,7 @@ async function* decodeChat(messages) {
2240
2273
  };
2241
2274
  }
2242
2275
  }
2243
-
2244
- // packages/providers/src/kimi/wire.ts
2245
- function encodeToolChoice2(c) {
2246
- switch (c.type) {
2247
- case "auto":
2248
- return "auto";
2249
- case "any":
2250
- return "required";
2251
- case "none":
2252
- return "none";
2253
- case "tool":
2254
- return { type: "function", function: { name: c.name } };
2255
- }
2256
- }
2257
- function toChatWire(req, model, vendor = "kimi") {
2258
- const degradations = [];
2259
- const note2 = (d) => {
2260
- if (!degradations.includes(d))
2261
- degradations.push(d);
2262
- };
2263
- if (req.betas?.includes(CONTEXT_1M_BETA))
2264
- note2("kimi:context-1m-dropped");
2265
- const messages = [];
2266
- const system = req.system?.flatMap((b) => b.type === "text" ? [b.text] : []).join(`
2267
-
2268
- `);
2269
- if (system !== undefined && system.length > 0)
2270
- messages.push({ role: "system", content: system });
2271
- for (const message of req.messages) {
2272
- const text = [];
2273
- const toolCalls = [];
2274
- for (const block of message.content) {
2275
- switch (block.type) {
2276
- case "text":
2277
- text.push(block.text);
2278
- break;
2279
- case "image":
2280
- note2("kimi:images-dropped");
2281
- break;
2282
- case "thinking":
2283
- note2("kimi:thinking-dropped");
2284
- break;
2285
- case "toolUse":
2286
- toolCalls.push({
2287
- id: block.id,
2288
- type: "function",
2289
- function: { name: block.name, arguments: JSON.stringify(block.input) }
2290
- });
2291
- break;
2292
- case "toolResult":
2293
- messages.push({
2294
- role: "tool",
2295
- tool_call_id: block.toolUseId,
2296
- content: block.content
2297
- });
2298
- break;
2299
- case "anthropicNative":
2300
- note2("kimi:anthropic-native-block-dropped");
2301
- break;
2302
- }
2303
- }
2304
- if (toolCalls.length > 0) {
2305
- messages.push({
2306
- role: message.role,
2307
- content: text.length > 0 ? text.join(`
2308
- `) : null,
2309
- tool_calls: toolCalls
2310
- });
2311
- } else if (text.length > 0) {
2312
- messages.push({ role: message.role, content: text.join(`
2313
- `) });
2314
- }
2315
- }
2316
- const body = {
2317
- model,
2318
- messages,
2319
- stream: req.stream,
2320
- stream_options: { include_usage: true }
2321
- };
2322
- if (req.maxTokens !== undefined)
2323
- body.max_tokens = req.maxTokens;
2324
- if (req.temperature !== undefined)
2325
- body.temperature = req.temperature;
2326
- if (req.stopSequences !== undefined)
2327
- body.stop = req.stopSequences;
2328
- if (req.tools !== undefined) {
2329
- const custom = req.tools.filter((t) => t.provider === "custom");
2330
- if (custom.length !== req.tools.length)
2331
- note2("kimi:anthropic-tool-dropped");
2332
- body.tools = custom.map((t) => ({
2333
- type: "function",
2334
- function: { name: t.name, description: t.description, parameters: t.inputSchema }
2335
- }));
2336
- }
2337
- if (req.toolChoice !== undefined)
2338
- body.tool_choice = encodeToolChoice2(req.toolChoice);
2339
- if (req.reasoning !== undefined)
2340
- note2("kimi:reasoning-dropped");
2341
- Object.assign(body, req.vendor?.[vendor] ?? {});
2342
- return { body, degradations };
2343
- }
2344
-
2345
- // packages/providers/src/openai/decode.ts
2346
- var ERROR_CODE = {
2276
+ var RESPONSES_ERROR_CODE = {
2347
2277
  rate_limit_exceeded: "RATE_LIMIT",
2348
2278
  insufficient_quota: "QUOTA_EXHAUSTED",
2349
2279
  invalid_api_key: "AUTH",
@@ -2351,15 +2281,7 @@ var ERROR_CODE = {
2351
2281
  context_length_exceeded: "BAD_REQUEST",
2352
2282
  content_policy_violation: "CONTENT_FILTER"
2353
2283
  };
2354
- function json3(data) {
2355
- try {
2356
- const v = JSON.parse(data);
2357
- return typeof v === "object" && v !== null ? v : null;
2358
- } catch {
2359
- return null;
2360
- }
2361
- }
2362
- async function* decodeResponses(messages) {
2284
+ async function* decodeCustomResponses(messages) {
2363
2285
  const indices = new Map;
2364
2286
  let next = 0;
2365
2287
  const irIndex = (outputIndex, contentIndex = 0) => {
@@ -2375,7 +2297,7 @@ async function* decodeResponses(messages) {
2375
2297
  let terminal = false;
2376
2298
  const ownsBlock = new Set;
2377
2299
  for await (const msg of messages) {
2378
- const d = json3(msg.data);
2300
+ const d = json2(msg.data);
2379
2301
  if (d === null)
2380
2302
  continue;
2381
2303
  switch (msg.event) {
@@ -2467,7 +2389,7 @@ async function* decodeResponses(messages) {
2467
2389
  case "error": {
2468
2390
  terminal = true;
2469
2391
  const err = d.response?.error ?? d.error ?? {};
2470
- const code = ERROR_CODE[String(err.code ?? err.type)] ?? "UPSTREAM";
2392
+ const code = RESPONSES_ERROR_CODE[String(err.code ?? err.type)] ?? "UPSTREAM";
2471
2393
  yield {
2472
2394
  type: "error",
2473
2395
  code,
@@ -2490,8 +2412,20 @@ async function* decodeResponses(messages) {
2490
2412
  }
2491
2413
  }
2492
2414
 
2493
- // packages/providers/src/openai/wire.ts
2494
- function encodeToolChoice3(c) {
2415
+ // packages/providers/src/custom/wire.ts
2416
+ function encodeChatToolChoice(c) {
2417
+ switch (c.type) {
2418
+ case "auto":
2419
+ return "auto";
2420
+ case "any":
2421
+ return "required";
2422
+ case "none":
2423
+ return "none";
2424
+ case "tool":
2425
+ return { type: "function", function: { name: c.name } };
2426
+ }
2427
+ }
2428
+ function encodeResponsesToolChoice(c) {
2495
2429
  switch (c.type) {
2496
2430
  case "auto":
2497
2431
  return "auto";
@@ -2503,20 +2437,115 @@ function encodeToolChoice3(c) {
2503
2437
  return { type: "function", name: c.name };
2504
2438
  }
2505
2439
  }
2506
- function toResponsesWire(req, model, opts = { oauth: false }) {
2440
+ function customEffort(reasoning) {
2441
+ if (reasoning === undefined || reasoning.mode !== "adaptive")
2442
+ return;
2443
+ return reasoning.effort ?? "medium";
2444
+ }
2445
+ function toCustomChatWire(req, model) {
2507
2446
  const degradations = [];
2508
- const input = [];
2509
2447
  const note2 = (d) => {
2510
2448
  if (!degradations.includes(d))
2511
2449
  degradations.push(d);
2512
2450
  };
2513
2451
  if (req.betas?.includes(CONTEXT_1M_BETA))
2514
- note2("openai:context-1m-dropped");
2452
+ note2("custom:context-1m-dropped");
2453
+ const messages = [];
2454
+ const system = req.system?.flatMap((b) => b.type === "text" ? [b.text] : []).join(`
2455
+
2456
+ `);
2457
+ if (system !== undefined && system.length > 0)
2458
+ messages.push({ role: "system", content: system });
2459
+ for (const message of req.messages) {
2460
+ const text = [];
2461
+ const toolCalls = [];
2462
+ for (const block of message.content) {
2463
+ switch (block.type) {
2464
+ case "text":
2465
+ text.push(block.text);
2466
+ break;
2467
+ case "image":
2468
+ note2("custom:images-dropped");
2469
+ break;
2470
+ case "thinking":
2471
+ note2("custom:thinking-dropped");
2472
+ break;
2473
+ case "toolUse":
2474
+ toolCalls.push({
2475
+ id: block.id,
2476
+ type: "function",
2477
+ function: { name: block.name, arguments: JSON.stringify(block.input) }
2478
+ });
2479
+ break;
2480
+ case "toolResult":
2481
+ messages.push({
2482
+ role: "tool",
2483
+ tool_call_id: block.toolUseId,
2484
+ content: block.content
2485
+ });
2486
+ break;
2487
+ case "anthropicNative":
2488
+ note2("custom:anthropic-native-block-dropped");
2489
+ break;
2490
+ }
2491
+ }
2492
+ if (toolCalls.length > 0) {
2493
+ messages.push({
2494
+ role: message.role,
2495
+ content: text.length > 0 ? text.join(`
2496
+ `) : null,
2497
+ tool_calls: toolCalls
2498
+ });
2499
+ } else if (text.length > 0) {
2500
+ messages.push({ role: message.role, content: text.join(`
2501
+ `) });
2502
+ }
2503
+ }
2504
+ const body = {
2505
+ model,
2506
+ messages,
2507
+ stream: req.stream,
2508
+ stream_options: { include_usage: true }
2509
+ };
2510
+ if (req.maxTokens !== undefined)
2511
+ body.max_tokens = req.maxTokens;
2512
+ if (req.temperature !== undefined)
2513
+ body.temperature = req.temperature;
2514
+ if (req.stopSequences !== undefined)
2515
+ body.stop = req.stopSequences;
2516
+ if (req.tools !== undefined) {
2517
+ const portable = req.tools.filter((t) => t.provider === "custom");
2518
+ if (portable.length !== req.tools.length)
2519
+ note2("custom:anthropic-tool-dropped");
2520
+ body.tools = portable.map((t) => ({
2521
+ type: "function",
2522
+ function: { name: t.name, description: t.description, parameters: t.inputSchema }
2523
+ }));
2524
+ }
2525
+ if (req.toolChoice !== undefined)
2526
+ body.tool_choice = encodeChatToolChoice(req.toolChoice);
2527
+ const effort = customEffort(req.reasoning);
2528
+ if (effort !== undefined)
2529
+ body.reasoning_effort = effort;
2530
+ else if (req.reasoning?.mode === "budget")
2531
+ note2("custom:reasoning-budget-dropped");
2532
+ Object.assign(body, req.vendor?.openai ?? {});
2533
+ return { body, degradations };
2534
+ }
2535
+ function toCustomResponsesWire(req, model) {
2536
+ const degradations = [];
2537
+ const note2 = (d) => {
2538
+ if (!degradations.includes(d))
2539
+ degradations.push(d);
2540
+ };
2541
+ const input = [];
2542
+ if (req.betas?.includes(CONTEXT_1M_BETA))
2543
+ note2("custom:context-1m-dropped");
2515
2544
  for (const message of req.messages) {
2516
2545
  const parts = [];
2517
2546
  const inlined = message.role === "system";
2518
2547
  if (inlined)
2519
- note2("openai:system-turn-inlined");
2548
+ note2("custom:system-turn-inlined");
2520
2549
  const role = inlined ? "user" : message.role;
2521
2550
  const flush = () => {
2522
2551
  if (parts.length === 0)
@@ -2541,9 +2570,7 @@ ${block.text}
2541
2570
  });
2542
2571
  break;
2543
2572
  case "thinking":
2544
- if (!degradations.includes("openai:thinking-dropped")) {
2545
- note2("openai:thinking-dropped");
2546
- }
2573
+ note2("custom:thinking-dropped");
2547
2574
  break;
2548
2575
  case "toolUse":
2549
2576
  flush();
@@ -2563,7 +2590,7 @@ ${block.text}
2563
2590
  });
2564
2591
  break;
2565
2592
  case "anthropicNative":
2566
- note2("openai:anthropic-native-block-dropped");
2593
+ note2("custom:anthropic-native-block-dropped");
2567
2594
  break;
2568
2595
  }
2569
2596
  }
@@ -2575,23 +2602,15 @@ ${block.text}
2575
2602
  `);
2576
2603
  if (instructions !== undefined && instructions.length > 0)
2577
2604
  body.instructions = instructions;
2578
- if (req.maxTokens !== undefined) {
2579
- if (opts.oauth)
2580
- note2("openai:max-tokens-dropped");
2581
- else
2582
- body.max_output_tokens = req.maxTokens;
2583
- }
2584
- if (req.temperature !== undefined) {
2585
- if (opts.oauth)
2586
- note2("openai:temperature-dropped");
2587
- else
2588
- body.temperature = req.temperature;
2589
- }
2605
+ if (req.maxTokens !== undefined)
2606
+ body.max_output_tokens = req.maxTokens;
2607
+ if (req.temperature !== undefined)
2608
+ body.temperature = req.temperature;
2590
2609
  if (req.tools !== undefined) {
2591
- const custom = req.tools.filter((t) => t.provider === "custom");
2592
- if (custom.length !== req.tools.length)
2593
- note2("openai:anthropic-tool-dropped");
2594
- body.tools = custom.map((t) => ({
2610
+ const portable = req.tools.filter((t) => t.provider === "custom");
2611
+ if (portable.length !== req.tools.length)
2612
+ note2("custom:anthropic-tool-dropped");
2613
+ body.tools = portable.map((t) => ({
2595
2614
  type: "function",
2596
2615
  name: t.name,
2597
2616
  description: t.description,
@@ -2599,20 +2618,12 @@ ${block.text}
2599
2618
  }));
2600
2619
  }
2601
2620
  if (req.toolChoice !== undefined)
2602
- body.tool_choice = encodeToolChoice3(req.toolChoice);
2603
- if (req.reasoning !== undefined && req.reasoning.mode !== "off") {
2604
- const effort = req.reasoning.mode === "adaptive" ? req.reasoning.effort ?? "medium" : "medium";
2605
- if (effort === "xhigh" || effort === "max") {
2606
- degradations.push("openai:reasoning-effort-clamped");
2607
- }
2608
- body.reasoning = {
2609
- effort: effort === "xhigh" || effort === "max" ? "high" : effort,
2610
- summary: "auto"
2611
- };
2612
- if (req.reasoning.mode === "budget") {
2613
- degradations.push("openai:reasoning-budget-dropped");
2614
- }
2615
- }
2621
+ body.tool_choice = encodeResponsesToolChoice(req.toolChoice);
2622
+ const effort = customEffort(req.reasoning);
2623
+ if (effort !== undefined)
2624
+ body.reasoning = { effort, summary: "auto" };
2625
+ else if (req.reasoning?.mode === "budget")
2626
+ note2("custom:reasoning-budget-dropped");
2616
2627
  Object.assign(body, req.vendor?.openai ?? {});
2617
2628
  return { body, degradations };
2618
2629
  }
@@ -2623,7 +2634,13 @@ function metadata(data) {
2623
2634
  if (typeof origin !== "string" || protocol !== "chat_completions" && protocol !== "responses") {
2624
2635
  throw new GatewayError("BAD_REQUEST", "custom credential has invalid endpoint metadata");
2625
2636
  }
2626
- return { origin, protocol };
2637
+ const basePath = typeof data.basePath === "string" ? data.basePath : "";
2638
+ return { origin, basePath, protocol };
2639
+ }
2640
+ function endpointUrl(origin, basePath, protocol) {
2641
+ const suffix = protocol === "chat_completions" ? "chat/completions" : "responses";
2642
+ const base = `${origin}${basePath}`.replace(/\/+$/, "");
2643
+ return base.endsWith("/v1") ? `${base}/${suffix}` : `${base}/v1/${suffix}`;
2627
2644
  }
2628
2645
  var customAdapter = {
2629
2646
  id: "custom",
@@ -2633,15 +2650,15 @@ var customAdapter = {
2633
2650
  if (apiKey === null) {
2634
2651
  throw new GatewayError("AUTH", "custom credential has no API key", { provider: "custom" });
2635
2652
  }
2636
- const { origin, protocol } = metadata(req.credentials.providerData);
2637
- const encoded = protocol === "chat_completions" ? toChatWire(req.request, req.model, "openai") : toResponsesWire(req.request, req.model);
2653
+ const { origin, basePath, protocol } = metadata(req.credentials.providerData);
2654
+ const encoded = protocol === "chat_completions" ? toCustomChatWire(req.request, req.model) : toCustomResponsesWire(req.request, req.model);
2638
2655
  const headers = [
2639
2656
  ["Content-Type", "application/json"],
2640
2657
  ["Authorization", `Bearer ${apiKey}`]
2641
2658
  ];
2642
2659
  const res = await req.http({
2643
2660
  provider: "custom",
2644
- url: `${origin}/v1/${protocol === "chat_completions" ? "chat/completions" : "responses"}`,
2661
+ url: endpointUrl(origin, basePath, protocol),
2645
2662
  method: "POST",
2646
2663
  headers,
2647
2664
  body: JSON.stringify({ ...encoded.body, stream: true }),
@@ -2653,8 +2670,8 @@ var customAdapter = {
2653
2670
  throw new GatewayError("UPSTREAM", "empty response body", { provider: "custom" });
2654
2671
  }
2655
2672
  return {
2656
- events: protocol === "chat_completions" ? decodeChat(parseSse(res.body)) : decodeResponses(parseSse(res.body)),
2657
- degradations: encoded.degradations.map((value) => value.replace(protocol === "chat_completions" ? /^kimi:/ : /^openai:/, "custom:"))
2673
+ events: protocol === "chat_completions" ? decodeCustomChat(parseSse(res.body)) : decodeCustomResponses(parseSse(res.body)),
2674
+ degradations: encoded.degradations
2658
2675
  };
2659
2676
  }
2660
2677
  };
@@ -2673,7 +2690,7 @@ function grokDeviceHeaders(providerData) {
2673
2690
  import { createHash as createHash2 } from "crypto";
2674
2691
 
2675
2692
  // packages/providers/src/grok/decode.ts
2676
- var ERROR_CODE2 = {
2693
+ var ERROR_CODE = {
2677
2694
  rate_limit_exceeded: "RATE_LIMIT",
2678
2695
  insufficient_quota: "QUOTA_EXHAUSTED",
2679
2696
  invalid_api_key: "AUTH",
@@ -2707,7 +2724,7 @@ var KNOWN_EVENTS2 = new Set([
2707
2724
  "response.failed",
2708
2725
  "error"
2709
2726
  ]);
2710
- function json4(data) {
2727
+ function json3(data) {
2711
2728
  try {
2712
2729
  const v = JSON.parse(data);
2713
2730
  return typeof v === "object" && v !== null ? v : null;
@@ -2742,7 +2759,7 @@ async function* decodeGrokResponses(messages) {
2742
2759
  };
2743
2760
  return;
2744
2761
  }
2745
- const d = json4(msg.data);
2762
+ const d = json3(msg.data);
2746
2763
  if (d === null)
2747
2764
  continue;
2748
2765
  switch (msg.event) {
@@ -2835,7 +2852,7 @@ async function* decodeGrokResponses(messages) {
2835
2852
  case "error": {
2836
2853
  terminal = true;
2837
2854
  const err = d.response?.error ?? d.error ?? {};
2838
- const code = ERROR_CODE2[String(err.code ?? err.type)] ?? "UPSTREAM";
2855
+ const code = ERROR_CODE[String(err.code ?? err.type)] ?? "UPSTREAM";
2839
2856
  yield {
2840
2857
  type: "error",
2841
2858
  code,
@@ -2861,7 +2878,7 @@ async function* decodeGrokResponses(messages) {
2861
2878
  // packages/providers/src/grok/wire.ts
2862
2879
  import { createHash } from "crypto";
2863
2880
  var MAX_TOOLS = 200;
2864
- function encodeToolChoice4(c) {
2881
+ function encodeToolChoice2(c) {
2865
2882
  switch (c.type) {
2866
2883
  case "auto":
2867
2884
  return "auto";
@@ -2972,12 +2989,14 @@ ${block.text}
2972
2989
  }));
2973
2990
  }
2974
2991
  if (req.toolChoice !== undefined)
2975
- body.tool_choice = encodeToolChoice4(req.toolChoice);
2992
+ body.tool_choice = encodeToolChoice2(req.toolChoice);
2976
2993
  if (req.reasoning !== undefined && req.reasoning.mode !== "off") {
2977
- const effort = req.reasoning.mode === "adaptive" ? req.reasoning.effort ?? "medium" : "medium";
2978
- body.reasoning = { effort, summary: "concise" };
2979
- if (req.reasoning.mode === "budget")
2994
+ if (req.reasoning.mode === "budget") {
2980
2995
  note2("grok:reasoning-budget-dropped");
2996
+ } else {
2997
+ const effort = req.reasoning.effort ?? "medium";
2998
+ body.reasoning = { effort, summary: "concise" };
2999
+ }
2981
3000
  }
2982
3001
  Object.assign(body, req.vendor?.grok ?? {});
2983
3002
  return { body, degradations };
@@ -3135,13 +3154,13 @@ function hasHeader(req, lowerName) {
3135
3154
  return req.headers.some(([name]) => name.toLowerCase() === lowerName);
3136
3155
  }
3137
3156
  // packages/providers/src/kilo/decode.ts
3138
- var FINISH2 = {
3157
+ var FINISH = {
3139
3158
  stop: "endTurn",
3140
3159
  length: "maxTokens",
3141
3160
  tool_calls: "toolUse",
3142
3161
  content_filter: "contentFilter"
3143
3162
  };
3144
- function reasoningText(delta) {
3163
+ function reasoningText2(delta) {
3145
3164
  if (typeof delta.reasoning === "string" && delta.reasoning.length > 0)
3146
3165
  return delta.reasoning;
3147
3166
  if (typeof delta.reasoning_content === "string" && delta.reasoning_content.length > 0) {
@@ -3159,7 +3178,7 @@ function reasoningText(delta) {
3159
3178
  return [];
3160
3179
  }).join("");
3161
3180
  }
3162
- function json5(data) {
3181
+ function json4(data) {
3163
3182
  try {
3164
3183
  const v = JSON.parse(data);
3165
3184
  return typeof v === "object" && v !== null ? v : null;
@@ -3181,7 +3200,7 @@ async function* decodeKiloChat(messages) {
3181
3200
  done = true;
3182
3201
  break;
3183
3202
  }
3184
- const d = json5(msg.data);
3203
+ const d = json4(msg.data);
3185
3204
  if (d === null)
3186
3205
  continue;
3187
3206
  if (!started && (d.id !== undefined || d.model !== undefined)) {
@@ -3196,7 +3215,7 @@ async function* decodeKiloChat(messages) {
3196
3215
  if (!choice)
3197
3216
  continue;
3198
3217
  const delta = choice.delta ?? {};
3199
- const reasoning = reasoningText(delta);
3218
+ const reasoning = reasoningText2(delta);
3200
3219
  if (reasoning.length > 0) {
3201
3220
  if (openKind !== "thinking") {
3202
3221
  if (openKind !== undefined)
@@ -3252,7 +3271,7 @@ async function* decodeKiloChat(messages) {
3252
3271
  }
3253
3272
  }
3254
3273
  if (typeof choice.finish_reason === "string") {
3255
- stopReason = FINISH2[choice.finish_reason] ?? "endTurn";
3274
+ stopReason = FINISH[choice.finish_reason] ?? "endTurn";
3256
3275
  }
3257
3276
  }
3258
3277
  if (done) {
@@ -3270,7 +3289,7 @@ async function* decodeKiloChat(messages) {
3270
3289
  }
3271
3290
 
3272
3291
  // packages/providers/src/kilo/wire.ts
3273
- function encodeToolChoice5(c) {
3292
+ function encodeToolChoice3(c) {
3274
3293
  switch (c.type) {
3275
3294
  case "auto":
3276
3295
  return "auto";
@@ -3383,15 +3402,12 @@ function toKiloWire(req, model) {
3383
3402
  }));
3384
3403
  }
3385
3404
  if (req.toolChoice !== undefined)
3386
- body.tool_choice = encodeToolChoice5(req.toolChoice);
3405
+ body.tool_choice = encodeToolChoice3(req.toolChoice);
3387
3406
  if (req.reasoning !== undefined && req.reasoning.mode !== "off") {
3388
3407
  if (req.reasoning.mode === "budget") {
3389
3408
  body.reasoning = { max_tokens: req.reasoning.budgetTokens };
3390
3409
  } else {
3391
- const effort = req.reasoning.effort ?? "medium";
3392
- if (effort === "xhigh" || effort === "max")
3393
- note2("kilo:reasoning-effort-clamped");
3394
- body.reasoning = { effort: effort === "xhigh" || effort === "max" ? "high" : effort };
3410
+ body.reasoning = { effort: req.reasoning.effort ?? "medium" };
3395
3411
  }
3396
3412
  }
3397
3413
  Object.assign(body, req.vendor?.kilo ?? {});
@@ -3461,40 +3477,512 @@ function kimiDeviceHeaders(providerData) {
3461
3477
  ["X-Msh-Os-Version", str(providerData.osVersion)]
3462
3478
  ];
3463
3479
  }
3464
- // packages/providers/src/kimi/index.ts
3465
- var BASE_URL2 = "https://api.kimi.com/coding/v1/chat/completions";
3466
- var kimiAdapter = {
3467
- id: "kimi",
3468
- capabilities: PROVIDER_CAPABILITIES.kimi,
3469
- async send(req) {
3470
- const { body, degradations } = toChatWire(req.request, req.model);
3471
- const token = req.credentials.accessToken ?? req.credentials.apiKey;
3472
- if (token === null) {
3473
- throw new GatewayError("AUTH", "kimi credential has no token", { provider: "kimi" });
3480
+ // packages/providers/src/kimi/decode.ts
3481
+ var FINISH2 = {
3482
+ stop: "endTurn",
3483
+ length: "maxTokens",
3484
+ tool_calls: "toolUse",
3485
+ content_filter: "contentFilter"
3486
+ };
3487
+ function json5(data) {
3488
+ try {
3489
+ const v = JSON.parse(data);
3490
+ return typeof v === "object" && v !== null ? v : null;
3491
+ } catch {
3492
+ return null;
3493
+ }
3494
+ }
3495
+ async function* decodeChat(messages) {
3496
+ let started = false;
3497
+ let done = false;
3498
+ let stopReason = "endTurn";
3499
+ let usage = { inputTokens: 0, outputTokens: 0, cacheReadTokens: 0, cacheWriteTokens: 0 };
3500
+ const toolIndex = new Map;
3501
+ let nextIndex = 0;
3502
+ let openKind;
3503
+ let openIndex = 0;
3504
+ for await (const msg of messages) {
3505
+ if (msg.data === "[DONE]") {
3506
+ done = true;
3507
+ break;
3508
+ }
3509
+ const d = json5(msg.data);
3510
+ if (d === null)
3511
+ continue;
3512
+ if (!started && (d.id !== undefined || d.model !== undefined)) {
3513
+ started = true;
3514
+ yield { type: "start", id: String(d.id ?? ""), model: String(d.model ?? "") };
3515
+ }
3516
+ if (d.usage) {
3517
+ const details = d.usage.prompt_tokens_details;
3518
+ usage = usageFromPromptTotal(d.usage.prompt_tokens ?? 0, d.usage.completion_tokens ?? 0, details?.cached_tokens ?? d.usage.prompt_cache_hit_tokens ?? 0, details?.cache_creation_tokens ?? details?.cache_write_tokens ?? 0);
3519
+ }
3520
+ const choice = d.choices?.[0];
3521
+ if (!choice)
3522
+ continue;
3523
+ const delta = choice.delta ?? {};
3524
+ if (typeof delta.content === "string" && delta.content.length > 0) {
3525
+ if (openKind !== "text") {
3526
+ if (openKind !== undefined)
3527
+ yield { type: "blockEnd", index: openIndex };
3528
+ openKind = "text";
3529
+ openIndex = nextIndex++;
3530
+ yield { type: "blockStart", index: openIndex, block: { type: "text" } };
3531
+ }
3532
+ yield {
3533
+ type: "blockDelta",
3534
+ index: openIndex,
3535
+ delta: { type: "text", text: delta.content }
3536
+ };
3537
+ }
3538
+ for (const call of delta.tool_calls ?? []) {
3539
+ const wireIndex = call.index ?? 0;
3540
+ let index = toolIndex.get(wireIndex);
3541
+ if (index === undefined) {
3542
+ if (openKind !== undefined)
3543
+ yield { type: "blockEnd", index: openIndex };
3544
+ index = nextIndex++;
3545
+ toolIndex.set(wireIndex, index);
3546
+ openKind = "tool";
3547
+ openIndex = index;
3548
+ yield {
3549
+ type: "blockStart",
3550
+ index,
3551
+ block: {
3552
+ type: "toolUse",
3553
+ id: String(call.id ?? `call_${wireIndex}`),
3554
+ name: String(call.function?.name ?? "")
3555
+ }
3556
+ };
3557
+ }
3558
+ const args = call.function?.arguments;
3559
+ if (typeof args === "string" && args.length > 0) {
3560
+ yield { type: "blockDelta", index, delta: { type: "toolJson", partial: args } };
3561
+ }
3562
+ }
3563
+ if (typeof choice.finish_reason === "string") {
3564
+ stopReason = FINISH2[choice.finish_reason] ?? "endTurn";
3474
3565
  }
3475
- const protocol = [
3476
- ["Content-Type", "application/json"],
3477
- ["Accept", "text/event-stream"],
3478
- ["Authorization", `Bearer ${token}`],
3479
- ...kimiDeviceHeaders(req.credentials.providerData)
3480
- ];
3481
- const profile = PROFILES.kimi;
3482
- const headers = orderHeaders(mergeHeaders(profile.headers, protocol), profile.order);
3483
- const res = await req.http({
3484
- provider: "kimi",
3485
- url: BASE_URL2,
3486
- method: "POST",
3487
- headers,
3488
- body: JSON.stringify(orderFields({ ...body, stream: true }, BODY_ORDER.kimi)),
3489
- signal: req.signal
3490
- });
3491
- if (res.status < 200 || res.status >= 300)
3492
- throw await httpError(res, "kimi");
3493
- if (res.body === null)
3494
- throw new GatewayError("UPSTREAM", "empty response body", { provider: "kimi" });
3495
- return { events: decodeChat(parseSse(res.body)), degradations };
3496
3566
  }
3497
- };
3567
+ if (done) {
3568
+ if (openKind !== undefined)
3569
+ yield { type: "blockEnd", index: openIndex };
3570
+ yield { type: "end", stopReason, usage };
3571
+ } else {
3572
+ yield {
3573
+ type: "error",
3574
+ code: "UPSTREAM",
3575
+ message: "upstream stream ended before [DONE]",
3576
+ retryable: RETRYABLE.UPSTREAM
3577
+ };
3578
+ }
3579
+ }
3580
+
3581
+ // packages/providers/src/kimi/wire.ts
3582
+ function encodeToolChoice4(c) {
3583
+ switch (c.type) {
3584
+ case "auto":
3585
+ return "auto";
3586
+ case "any":
3587
+ return "required";
3588
+ case "none":
3589
+ return "none";
3590
+ case "tool":
3591
+ return { type: "function", function: { name: c.name } };
3592
+ }
3593
+ }
3594
+ function toChatWire(req, model, vendor = "kimi") {
3595
+ const degradations = [];
3596
+ const note2 = (d) => {
3597
+ if (!degradations.includes(d))
3598
+ degradations.push(d);
3599
+ };
3600
+ if (req.betas?.includes(CONTEXT_1M_BETA))
3601
+ note2("kimi:context-1m-dropped");
3602
+ const messages = [];
3603
+ const system = req.system?.flatMap((b) => b.type === "text" ? [b.text] : []).join(`
3604
+
3605
+ `);
3606
+ if (system !== undefined && system.length > 0)
3607
+ messages.push({ role: "system", content: system });
3608
+ for (const message of req.messages) {
3609
+ const text = [];
3610
+ const toolCalls = [];
3611
+ for (const block of message.content) {
3612
+ switch (block.type) {
3613
+ case "text":
3614
+ text.push(block.text);
3615
+ break;
3616
+ case "image":
3617
+ note2("kimi:images-dropped");
3618
+ break;
3619
+ case "thinking":
3620
+ note2("kimi:thinking-dropped");
3621
+ break;
3622
+ case "toolUse":
3623
+ toolCalls.push({
3624
+ id: block.id,
3625
+ type: "function",
3626
+ function: { name: block.name, arguments: JSON.stringify(block.input) }
3627
+ });
3628
+ break;
3629
+ case "toolResult":
3630
+ messages.push({
3631
+ role: "tool",
3632
+ tool_call_id: block.toolUseId,
3633
+ content: block.content
3634
+ });
3635
+ break;
3636
+ case "anthropicNative":
3637
+ note2("kimi:anthropic-native-block-dropped");
3638
+ break;
3639
+ }
3640
+ }
3641
+ if (toolCalls.length > 0) {
3642
+ messages.push({
3643
+ role: message.role,
3644
+ content: text.length > 0 ? text.join(`
3645
+ `) : null,
3646
+ tool_calls: toolCalls
3647
+ });
3648
+ } else if (text.length > 0) {
3649
+ messages.push({ role: message.role, content: text.join(`
3650
+ `) });
3651
+ }
3652
+ }
3653
+ const body = {
3654
+ model,
3655
+ messages,
3656
+ stream: req.stream,
3657
+ stream_options: { include_usage: true }
3658
+ };
3659
+ if (req.maxTokens !== undefined)
3660
+ body.max_tokens = req.maxTokens;
3661
+ if (req.temperature !== undefined)
3662
+ body.temperature = req.temperature;
3663
+ if (req.stopSequences !== undefined)
3664
+ body.stop = req.stopSequences;
3665
+ if (req.tools !== undefined) {
3666
+ const custom = req.tools.filter((t) => t.provider === "custom");
3667
+ if (custom.length !== req.tools.length)
3668
+ note2("kimi:anthropic-tool-dropped");
3669
+ body.tools = custom.map((t) => ({
3670
+ type: "function",
3671
+ function: { name: t.name, description: t.description, parameters: t.inputSchema }
3672
+ }));
3673
+ }
3674
+ if (req.toolChoice !== undefined)
3675
+ body.tool_choice = encodeToolChoice4(req.toolChoice);
3676
+ if (req.reasoning !== undefined)
3677
+ note2("kimi:reasoning-dropped");
3678
+ Object.assign(body, req.vendor?.[vendor] ?? {});
3679
+ return { body, degradations };
3680
+ }
3681
+
3682
+ // packages/providers/src/kimi/index.ts
3683
+ var BASE_URL2 = "https://api.kimi.com/coding/v1/chat/completions";
3684
+ var kimiAdapter = {
3685
+ id: "kimi",
3686
+ capabilities: PROVIDER_CAPABILITIES.kimi,
3687
+ async send(req) {
3688
+ const { body, degradations } = toChatWire(req.request, req.model);
3689
+ const token = req.credentials.accessToken ?? req.credentials.apiKey;
3690
+ if (token === null) {
3691
+ throw new GatewayError("AUTH", "kimi credential has no token", { provider: "kimi" });
3692
+ }
3693
+ const protocol = [
3694
+ ["Content-Type", "application/json"],
3695
+ ["Accept", "text/event-stream"],
3696
+ ["Authorization", `Bearer ${token}`],
3697
+ ...kimiDeviceHeaders(req.credentials.providerData)
3698
+ ];
3699
+ const profile = PROFILES.kimi;
3700
+ const headers = orderHeaders(mergeHeaders(profile.headers, protocol), profile.order);
3701
+ const res = await req.http({
3702
+ provider: "kimi",
3703
+ url: BASE_URL2,
3704
+ method: "POST",
3705
+ headers,
3706
+ body: JSON.stringify(orderFields({ ...body, stream: true }, BODY_ORDER.kimi)),
3707
+ signal: req.signal
3708
+ });
3709
+ if (res.status < 200 || res.status >= 300)
3710
+ throw await httpError(res, "kimi");
3711
+ if (res.body === null)
3712
+ throw new GatewayError("UPSTREAM", "empty response body", { provider: "kimi" });
3713
+ return { events: decodeChat(parseSse(res.body)), degradations };
3714
+ }
3715
+ };
3716
+ // packages/providers/src/openai/decode.ts
3717
+ var ERROR_CODE2 = {
3718
+ rate_limit_exceeded: "RATE_LIMIT",
3719
+ insufficient_quota: "QUOTA_EXHAUSTED",
3720
+ invalid_api_key: "AUTH",
3721
+ server_error: "UPSTREAM",
3722
+ context_length_exceeded: "BAD_REQUEST",
3723
+ content_policy_violation: "CONTENT_FILTER"
3724
+ };
3725
+ function json6(data) {
3726
+ try {
3727
+ const v = JSON.parse(data);
3728
+ return typeof v === "object" && v !== null ? v : null;
3729
+ } catch {
3730
+ return null;
3731
+ }
3732
+ }
3733
+ async function* decodeResponses(messages) {
3734
+ const indices = new Map;
3735
+ let next = 0;
3736
+ const irIndex = (outputIndex, contentIndex = 0) => {
3737
+ const key = `${outputIndex}:${contentIndex}`;
3738
+ const existing = indices.get(key);
3739
+ if (existing !== undefined)
3740
+ return existing;
3741
+ const assigned = next++;
3742
+ indices.set(key, assigned);
3743
+ return assigned;
3744
+ };
3745
+ let sawToolCall = false;
3746
+ let terminal = false;
3747
+ const ownsBlock = new Set;
3748
+ for await (const msg of messages) {
3749
+ const d = json6(msg.data);
3750
+ if (d === null)
3751
+ continue;
3752
+ switch (msg.event) {
3753
+ case "response.created":
3754
+ yield {
3755
+ type: "start",
3756
+ id: String(d.response?.id ?? ""),
3757
+ model: String(d.response?.model ?? "")
3758
+ };
3759
+ break;
3760
+ case "response.output_item.added": {
3761
+ const item = d.item ?? {};
3762
+ if (item.type === "reasoning") {
3763
+ ownsBlock.add(d.output_index ?? 0);
3764
+ yield {
3765
+ type: "blockStart",
3766
+ index: irIndex(d.output_index ?? 0),
3767
+ block: { type: "thinking" }
3768
+ };
3769
+ } else if (item.type === "function_call") {
3770
+ sawToolCall = true;
3771
+ ownsBlock.add(d.output_index ?? 0);
3772
+ yield {
3773
+ type: "blockStart",
3774
+ index: irIndex(d.output_index ?? 0),
3775
+ block: { type: "toolUse", id: String(item.call_id), name: String(item.name) }
3776
+ };
3777
+ }
3778
+ break;
3779
+ }
3780
+ case "response.content_part.added":
3781
+ if (d.part?.type === "output_text") {
3782
+ yield {
3783
+ type: "blockStart",
3784
+ index: irIndex(d.output_index ?? 0, d.content_index ?? 0),
3785
+ block: { type: "text" }
3786
+ };
3787
+ }
3788
+ break;
3789
+ case "response.output_text.delta":
3790
+ yield {
3791
+ type: "blockDelta",
3792
+ index: irIndex(d.output_index ?? 0, d.content_index ?? 0),
3793
+ delta: { type: "text", text: String(d.delta ?? "") }
3794
+ };
3795
+ break;
3796
+ case "response.reasoning_summary_text.delta":
3797
+ yield {
3798
+ type: "blockDelta",
3799
+ index: irIndex(d.output_index ?? 0),
3800
+ delta: { type: "thinking", text: String(d.delta ?? "") }
3801
+ };
3802
+ break;
3803
+ case "response.function_call_arguments.delta":
3804
+ yield {
3805
+ type: "blockDelta",
3806
+ index: irIndex(d.output_index ?? 0),
3807
+ delta: { type: "toolJson", partial: String(d.delta ?? "") }
3808
+ };
3809
+ break;
3810
+ case "response.content_part.done":
3811
+ yield { type: "blockEnd", index: irIndex(d.output_index ?? 0, d.content_index ?? 0) };
3812
+ break;
3813
+ case "response.output_item.done": {
3814
+ const outputIndex = d.output_index ?? 0;
3815
+ if (ownsBlock.delete(outputIndex)) {
3816
+ yield { type: "blockEnd", index: irIndex(outputIndex) };
3817
+ }
3818
+ break;
3819
+ }
3820
+ case "response.completed":
3821
+ case "response.incomplete": {
3822
+ terminal = true;
3823
+ const r = d.response ?? {};
3824
+ const reason = r.incomplete_details?.reason;
3825
+ let stopReason = sawToolCall ? "toolUse" : "endTurn";
3826
+ if (reason === "max_output_tokens")
3827
+ stopReason = "maxTokens";
3828
+ else if (reason === "content_filter")
3829
+ stopReason = "contentFilter";
3830
+ yield {
3831
+ type: "end",
3832
+ stopReason,
3833
+ usage: usageFromPromptTotal(r.usage?.input_tokens ?? 0, r.usage?.output_tokens ?? 0, r.usage?.input_tokens_details?.cached_tokens ?? r.usage?.prompt_tokens_details?.cached_tokens ?? 0)
3834
+ };
3835
+ break;
3836
+ }
3837
+ case "response.failed":
3838
+ case "error": {
3839
+ terminal = true;
3840
+ const err = d.response?.error ?? d.error ?? {};
3841
+ const code = ERROR_CODE2[String(err.code ?? err.type)] ?? "UPSTREAM";
3842
+ yield {
3843
+ type: "error",
3844
+ code,
3845
+ message: String(err.message ?? "upstream error"),
3846
+ retryable: RETRYABLE[code]
3847
+ };
3848
+ break;
3849
+ }
3850
+ default:
3851
+ break;
3852
+ }
3853
+ }
3854
+ if (!terminal) {
3855
+ yield {
3856
+ type: "error",
3857
+ code: "UPSTREAM",
3858
+ message: "upstream stream ended before response completion",
3859
+ retryable: RETRYABLE.UPSTREAM
3860
+ };
3861
+ }
3862
+ }
3863
+
3864
+ // packages/providers/src/openai/wire.ts
3865
+ function encodeToolChoice5(c) {
3866
+ switch (c.type) {
3867
+ case "auto":
3868
+ return "auto";
3869
+ case "any":
3870
+ return "required";
3871
+ case "none":
3872
+ return "none";
3873
+ case "tool":
3874
+ return { type: "function", name: c.name };
3875
+ }
3876
+ }
3877
+ function toResponsesWire(req, model, opts = { oauth: false }) {
3878
+ const degradations = [];
3879
+ const input = [];
3880
+ const note2 = (d) => {
3881
+ if (!degradations.includes(d))
3882
+ degradations.push(d);
3883
+ };
3884
+ if (req.betas?.includes(CONTEXT_1M_BETA))
3885
+ note2("openai:context-1m-dropped");
3886
+ for (const message of req.messages) {
3887
+ const parts = [];
3888
+ const inlined = message.role === "system";
3889
+ if (inlined)
3890
+ note2("openai:system-turn-inlined");
3891
+ const role = inlined ? "user" : message.role;
3892
+ const flush = () => {
3893
+ if (parts.length === 0)
3894
+ return;
3895
+ input.push({ type: "message", role, content: [...parts] });
3896
+ parts.length = 0;
3897
+ };
3898
+ for (const block of message.content) {
3899
+ switch (block.type) {
3900
+ case "text":
3901
+ parts.push({
3902
+ type: role === "assistant" ? "output_text" : "input_text",
3903
+ text: inlined ? `<system-reminder>
3904
+ ${block.text}
3905
+ </system-reminder>` : block.text
3906
+ });
3907
+ break;
3908
+ case "image":
3909
+ parts.push({
3910
+ type: "input_image",
3911
+ image_url: `data:${block.mediaType};base64,${block.data}`
3912
+ });
3913
+ break;
3914
+ case "thinking":
3915
+ if (!degradations.includes("openai:thinking-dropped")) {
3916
+ note2("openai:thinking-dropped");
3917
+ }
3918
+ break;
3919
+ case "toolUse":
3920
+ flush();
3921
+ input.push({
3922
+ type: "function_call",
3923
+ call_id: block.id,
3924
+ name: block.name,
3925
+ arguments: JSON.stringify(block.input)
3926
+ });
3927
+ break;
3928
+ case "toolResult":
3929
+ flush();
3930
+ input.push({
3931
+ type: "function_call_output",
3932
+ call_id: block.toolUseId,
3933
+ output: block.content
3934
+ });
3935
+ break;
3936
+ case "anthropicNative":
3937
+ note2("openai:anthropic-native-block-dropped");
3938
+ break;
3939
+ }
3940
+ }
3941
+ flush();
3942
+ }
3943
+ const body = { model, input, stream: req.stream, store: false };
3944
+ const instructions = req.system?.flatMap((b) => b.type === "text" ? [b.text] : []).join(`
3945
+
3946
+ `);
3947
+ if (instructions !== undefined && instructions.length > 0)
3948
+ body.instructions = instructions;
3949
+ if (req.maxTokens !== undefined) {
3950
+ if (opts.oauth)
3951
+ note2("openai:max-tokens-dropped");
3952
+ else
3953
+ body.max_output_tokens = req.maxTokens;
3954
+ }
3955
+ if (req.temperature !== undefined) {
3956
+ if (opts.oauth)
3957
+ note2("openai:temperature-dropped");
3958
+ else
3959
+ body.temperature = req.temperature;
3960
+ }
3961
+ if (req.tools !== undefined) {
3962
+ const custom = req.tools.filter((t) => t.provider === "custom");
3963
+ if (custom.length !== req.tools.length)
3964
+ note2("openai:anthropic-tool-dropped");
3965
+ body.tools = custom.map((t) => ({
3966
+ type: "function",
3967
+ name: t.name,
3968
+ description: t.description,
3969
+ parameters: t.inputSchema
3970
+ }));
3971
+ }
3972
+ if (req.toolChoice !== undefined)
3973
+ body.tool_choice = encodeToolChoice5(req.toolChoice);
3974
+ if (req.reasoning !== undefined && req.reasoning.mode !== "off") {
3975
+ if (req.reasoning.mode === "budget") {
3976
+ degradations.push("openai:reasoning-budget-dropped");
3977
+ } else {
3978
+ const effort = req.reasoning.effort ?? "medium";
3979
+ body.reasoning = { effort, summary: "auto" };
3980
+ }
3981
+ }
3982
+ Object.assign(body, req.vendor?.openai ?? {});
3983
+ return { body, degradations };
3984
+ }
3985
+
3498
3986
  // packages/providers/src/openai/index.ts
3499
3987
  var OAUTH_URL2 = "https://chatgpt.com/backend-api/codex/responses";
3500
3988
  var API_URL3 = "https://api.openai.com/v1/responses";
@@ -3897,7 +4385,7 @@ __export(exports_external, {
3897
4385
  ipv4: () => ipv42,
3898
4386
  ipv6: () => ipv62,
3899
4387
  iso: () => exports_iso,
3900
- json: () => json6,
4388
+ json: () => json7,
3901
4389
  jwt: () => jwt,
3902
4390
  keyof: () => keyof,
3903
4391
  ksuid: () => ksuid2,
@@ -15338,29 +15826,29 @@ var formatMap = {
15338
15826
  regex: ""
15339
15827
  };
15340
15828
  var stringProcessor = (schema, ctx, _json, _params) => {
15341
- const json6 = _json;
15342
- json6.type = "string";
15829
+ const json7 = _json;
15830
+ json7.type = "string";
15343
15831
  const { minimum, maximum, format, patterns, contentEncoding } = schema._zod.bag;
15344
15832
  if (typeof minimum === "number")
15345
- json6.minLength = minimum;
15833
+ json7.minLength = minimum;
15346
15834
  if (typeof maximum === "number")
15347
- json6.maxLength = maximum;
15835
+ json7.maxLength = maximum;
15348
15836
  if (format) {
15349
- json6.format = formatMap[format] ?? format;
15350
- if (json6.format === "")
15351
- delete json6.format;
15837
+ json7.format = formatMap[format] ?? format;
15838
+ if (json7.format === "")
15839
+ delete json7.format;
15352
15840
  if (format === "time") {
15353
- delete json6.format;
15841
+ delete json7.format;
15354
15842
  }
15355
15843
  }
15356
15844
  if (contentEncoding)
15357
- json6.contentEncoding = contentEncoding;
15845
+ json7.contentEncoding = contentEncoding;
15358
15846
  if (patterns && patterns.size > 0) {
15359
15847
  const regexes = [...patterns];
15360
15848
  if (regexes.length === 1)
15361
- json6.pattern = regexes[0].source;
15849
+ json7.pattern = regexes[0].source;
15362
15850
  else if (regexes.length > 1) {
15363
- json6.allOf = [
15851
+ json7.allOf = [
15364
15852
  ...regexes.map((regex) => ({
15365
15853
  ...ctx.target === "draft-07" || ctx.target === "draft-04" || ctx.target === "openapi-3.0" ? { type: "string" } : {},
15366
15854
  pattern: regex.source
@@ -15370,40 +15858,40 @@ var stringProcessor = (schema, ctx, _json, _params) => {
15370
15858
  }
15371
15859
  };
15372
15860
  var numberProcessor = (schema, ctx, _json, _params) => {
15373
- const json6 = _json;
15861
+ const json7 = _json;
15374
15862
  const { minimum, maximum, format, multipleOf, exclusiveMaximum, exclusiveMinimum } = schema._zod.bag;
15375
15863
  if (typeof format === "string" && format.includes("int"))
15376
- json6.type = "integer";
15864
+ json7.type = "integer";
15377
15865
  else
15378
- json6.type = "number";
15866
+ json7.type = "number";
15379
15867
  const exMin = typeof exclusiveMinimum === "number" && exclusiveMinimum >= (minimum ?? Number.NEGATIVE_INFINITY);
15380
15868
  const exMax = typeof exclusiveMaximum === "number" && exclusiveMaximum <= (maximum ?? Number.POSITIVE_INFINITY);
15381
15869
  const legacy = ctx.target === "draft-04" || ctx.target === "openapi-3.0";
15382
15870
  if (exMin) {
15383
15871
  if (legacy) {
15384
- json6.minimum = exclusiveMinimum;
15385
- json6.exclusiveMinimum = true;
15872
+ json7.minimum = exclusiveMinimum;
15873
+ json7.exclusiveMinimum = true;
15386
15874
  } else {
15387
- json6.exclusiveMinimum = exclusiveMinimum;
15875
+ json7.exclusiveMinimum = exclusiveMinimum;
15388
15876
  }
15389
15877
  } else if (typeof minimum === "number") {
15390
- json6.minimum = minimum;
15878
+ json7.minimum = minimum;
15391
15879
  }
15392
15880
  if (exMax) {
15393
15881
  if (legacy) {
15394
- json6.maximum = exclusiveMaximum;
15395
- json6.exclusiveMaximum = true;
15882
+ json7.maximum = exclusiveMaximum;
15883
+ json7.exclusiveMaximum = true;
15396
15884
  } else {
15397
- json6.exclusiveMaximum = exclusiveMaximum;
15885
+ json7.exclusiveMaximum = exclusiveMaximum;
15398
15886
  }
15399
15887
  } else if (typeof maximum === "number") {
15400
- json6.maximum = maximum;
15888
+ json7.maximum = maximum;
15401
15889
  }
15402
15890
  if (typeof multipleOf === "number")
15403
- json6.multipleOf = multipleOf;
15891
+ json7.multipleOf = multipleOf;
15404
15892
  };
15405
- var booleanProcessor = (_schema, _ctx, json6, _params) => {
15406
- json6.type = "boolean";
15893
+ var booleanProcessor = (_schema, _ctx, json7, _params) => {
15894
+ json7.type = "boolean";
15407
15895
  };
15408
15896
  var bigintProcessor = (_schema, ctx, _json, _params) => {
15409
15897
  if (ctx.unrepresentable === "throw") {
@@ -15415,13 +15903,13 @@ var symbolProcessor = (_schema, ctx, _json, _params) => {
15415
15903
  throw new Error("Symbols cannot be represented in JSON Schema");
15416
15904
  }
15417
15905
  };
15418
- var nullProcessor = (_schema, ctx, json6, _params) => {
15906
+ var nullProcessor = (_schema, ctx, json7, _params) => {
15419
15907
  if (ctx.target === "openapi-3.0") {
15420
- json6.type = "string";
15421
- json6.nullable = true;
15422
- json6.enum = [null];
15908
+ json7.type = "string";
15909
+ json7.nullable = true;
15910
+ json7.enum = [null];
15423
15911
  } else {
15424
- json6.type = "null";
15912
+ json7.type = "null";
15425
15913
  }
15426
15914
  };
15427
15915
  var undefinedProcessor = (_schema, ctx, _json, _params) => {
@@ -15434,8 +15922,8 @@ var voidProcessor = (_schema, ctx, _json, _params) => {
15434
15922
  throw new Error("Void cannot be represented in JSON Schema");
15435
15923
  }
15436
15924
  };
15437
- var neverProcessor = (_schema, _ctx, json6, _params) => {
15438
- json6.not = {};
15925
+ var neverProcessor = (_schema, _ctx, json7, _params) => {
15926
+ json7.not = {};
15439
15927
  };
15440
15928
  var anyProcessor = (_schema, _ctx, _json, _params) => {};
15441
15929
  var unknownProcessor = (_schema, _ctx, _json, _params) => {};
@@ -15444,16 +15932,16 @@ var dateProcessor = (_schema, ctx, _json, _params) => {
15444
15932
  throw new Error("Date cannot be represented in JSON Schema");
15445
15933
  }
15446
15934
  };
15447
- var enumProcessor = (schema, _ctx, json6, _params) => {
15935
+ var enumProcessor = (schema, _ctx, json7, _params) => {
15448
15936
  const def = schema._zod.def;
15449
15937
  const values = getEnumValues(def.entries);
15450
15938
  if (values.every((v) => typeof v === "number"))
15451
- json6.type = "number";
15939
+ json7.type = "number";
15452
15940
  if (values.every((v) => typeof v === "string"))
15453
- json6.type = "string";
15454
- json6.enum = values;
15941
+ json7.type = "string";
15942
+ json7.enum = values;
15455
15943
  };
15456
- var literalProcessor = (schema, ctx, json6, _params) => {
15944
+ var literalProcessor = (schema, ctx, json7, _params) => {
15457
15945
  const def = schema._zod.def;
15458
15946
  const vals = [];
15459
15947
  for (const val of def.values) {
@@ -15473,22 +15961,22 @@ var literalProcessor = (schema, ctx, json6, _params) => {
15473
15961
  }
15474
15962
  if (vals.length === 0) {} else if (vals.length === 1) {
15475
15963
  const val = vals[0];
15476
- json6.type = val === null ? "null" : typeof val;
15964
+ json7.type = val === null ? "null" : typeof val;
15477
15965
  if (ctx.target === "draft-04" || ctx.target === "openapi-3.0") {
15478
- json6.enum = [val];
15966
+ json7.enum = [val];
15479
15967
  } else {
15480
- json6.const = val;
15968
+ json7.const = val;
15481
15969
  }
15482
15970
  } else {
15483
15971
  if (vals.every((v) => typeof v === "number"))
15484
- json6.type = "number";
15972
+ json7.type = "number";
15485
15973
  if (vals.every((v) => typeof v === "string"))
15486
- json6.type = "string";
15974
+ json7.type = "string";
15487
15975
  if (vals.every((v) => typeof v === "boolean"))
15488
- json6.type = "boolean";
15976
+ json7.type = "boolean";
15489
15977
  if (vals.every((v) => v === null))
15490
- json6.type = "null";
15491
- json6.enum = vals;
15978
+ json7.type = "null";
15979
+ json7.enum = vals;
15492
15980
  }
15493
15981
  };
15494
15982
  var nanProcessor = (_schema, ctx, _json, _params) => {
@@ -15496,16 +15984,16 @@ var nanProcessor = (_schema, ctx, _json, _params) => {
15496
15984
  throw new Error("NaN cannot be represented in JSON Schema");
15497
15985
  }
15498
15986
  };
15499
- var templateLiteralProcessor = (schema, _ctx, json6, _params) => {
15500
- const _json = json6;
15987
+ var templateLiteralProcessor = (schema, _ctx, json7, _params) => {
15988
+ const _json = json7;
15501
15989
  const pattern = schema._zod.pattern;
15502
15990
  if (!pattern)
15503
15991
  throw new Error("Pattern not found in template literal");
15504
15992
  _json.type = "string";
15505
15993
  _json.pattern = pattern.source;
15506
15994
  };
15507
- var fileProcessor = (schema, _ctx, json6, _params) => {
15508
- const _json = json6;
15995
+ var fileProcessor = (schema, _ctx, json7, _params) => {
15996
+ const _json = json7;
15509
15997
  const file = {
15510
15998
  type: "string",
15511
15999
  format: "binary",
@@ -15528,8 +16016,8 @@ var fileProcessor = (schema, _ctx, json6, _params) => {
15528
16016
  Object.assign(_json, file);
15529
16017
  }
15530
16018
  };
15531
- var successProcessor = (_schema, _ctx, json6, _params) => {
15532
- json6.type = "boolean";
16019
+ var successProcessor = (_schema, _ctx, json7, _params) => {
16020
+ json7.type = "boolean";
15533
16021
  };
15534
16022
  var customProcessor = (_schema, ctx, _json, _params) => {
15535
16023
  if (ctx.unrepresentable === "throw") {
@@ -15557,27 +16045,27 @@ var setProcessor = (_schema, ctx, _json, _params) => {
15557
16045
  }
15558
16046
  };
15559
16047
  var arrayProcessor = (schema, ctx, _json, params) => {
15560
- const json6 = _json;
16048
+ const json7 = _json;
15561
16049
  const def = schema._zod.def;
15562
16050
  const { minimum, maximum } = schema._zod.bag;
15563
16051
  if (typeof minimum === "number")
15564
- json6.minItems = minimum;
16052
+ json7.minItems = minimum;
15565
16053
  if (typeof maximum === "number")
15566
- json6.maxItems = maximum;
15567
- json6.type = "array";
15568
- json6.items = process2(def.element, ctx, {
16054
+ json7.maxItems = maximum;
16055
+ json7.type = "array";
16056
+ json7.items = process2(def.element, ctx, {
15569
16057
  ...params,
15570
16058
  path: [...params.path, "items"]
15571
16059
  });
15572
16060
  };
15573
16061
  var objectProcessor = (schema, ctx, _json, params) => {
15574
- const json6 = _json;
16062
+ const json7 = _json;
15575
16063
  const def = schema._zod.def;
15576
- json6.type = "object";
15577
- json6.properties = {};
16064
+ json7.type = "object";
16065
+ json7.properties = {};
15578
16066
  const shape = def.shape;
15579
16067
  for (const key in shape) {
15580
- json6.properties[key] = process2(shape[key], ctx, {
16068
+ json7.properties[key] = process2(shape[key], ctx, {
15581
16069
  ...params,
15582
16070
  path: [...params.path, "properties", key]
15583
16071
  });
@@ -15592,21 +16080,21 @@ var objectProcessor = (schema, ctx, _json, params) => {
15592
16080
  }
15593
16081
  }));
15594
16082
  if (requiredKeys.size > 0) {
15595
- json6.required = Array.from(requiredKeys);
16083
+ json7.required = Array.from(requiredKeys);
15596
16084
  }
15597
16085
  if (def.catchall?._zod.def.type === "never") {
15598
- json6.additionalProperties = false;
16086
+ json7.additionalProperties = false;
15599
16087
  } else if (!def.catchall) {
15600
16088
  if (ctx.io === "output")
15601
- json6.additionalProperties = false;
16089
+ json7.additionalProperties = false;
15602
16090
  } else if (def.catchall) {
15603
- json6.additionalProperties = process2(def.catchall, ctx, {
16091
+ json7.additionalProperties = process2(def.catchall, ctx, {
15604
16092
  ...params,
15605
16093
  path: [...params.path, "additionalProperties"]
15606
16094
  });
15607
16095
  }
15608
16096
  };
15609
- var unionProcessor = (schema, ctx, json6, params) => {
16097
+ var unionProcessor = (schema, ctx, json7, params) => {
15610
16098
  const def = schema._zod.def;
15611
16099
  const isExclusive = def.inclusive === false;
15612
16100
  const options = def.options.map((x, i) => process2(x, ctx, {
@@ -15614,12 +16102,12 @@ var unionProcessor = (schema, ctx, json6, params) => {
15614
16102
  path: [...params.path, isExclusive ? "oneOf" : "anyOf", i]
15615
16103
  }));
15616
16104
  if (isExclusive) {
15617
- json6.oneOf = options;
16105
+ json7.oneOf = options;
15618
16106
  } else {
15619
- json6.anyOf = options;
16107
+ json7.anyOf = options;
15620
16108
  }
15621
16109
  };
15622
- var intersectionProcessor = (schema, ctx, json6, params) => {
16110
+ var intersectionProcessor = (schema, ctx, json7, params) => {
15623
16111
  const def = schema._zod.def;
15624
16112
  const a = process2(def.left, ctx, {
15625
16113
  ...params,
@@ -15634,12 +16122,12 @@ var intersectionProcessor = (schema, ctx, json6, params) => {
15634
16122
  ...isSimpleIntersection(a) ? a.allOf : [a],
15635
16123
  ...isSimpleIntersection(b) ? b.allOf : [b]
15636
16124
  ];
15637
- json6.allOf = allOf;
16125
+ json7.allOf = allOf;
15638
16126
  };
15639
16127
  var tupleProcessor = (schema, ctx, _json, params) => {
15640
- const json6 = _json;
16128
+ const json7 = _json;
15641
16129
  const def = schema._zod.def;
15642
- json6.type = "array";
16130
+ json7.type = "array";
15643
16131
  const prefixPath = ctx.target === "draft-2020-12" ? "prefixItems" : "items";
15644
16132
  const restPath = ctx.target === "draft-2020-12" ? "items" : ctx.target === "openapi-3.0" ? "items" : "additionalItems";
15645
16133
  const prefixItems = def.items.map((x, i) => process2(x, ctx, {
@@ -15651,37 +16139,37 @@ var tupleProcessor = (schema, ctx, _json, params) => {
15651
16139
  path: [...params.path, restPath, ...ctx.target === "openapi-3.0" ? [def.items.length] : []]
15652
16140
  }) : null;
15653
16141
  if (ctx.target === "draft-2020-12") {
15654
- json6.prefixItems = prefixItems;
16142
+ json7.prefixItems = prefixItems;
15655
16143
  if (rest) {
15656
- json6.items = rest;
16144
+ json7.items = rest;
15657
16145
  }
15658
16146
  } else if (ctx.target === "openapi-3.0") {
15659
- json6.items = {
16147
+ json7.items = {
15660
16148
  anyOf: prefixItems
15661
16149
  };
15662
16150
  if (rest) {
15663
- json6.items.anyOf.push(rest);
16151
+ json7.items.anyOf.push(rest);
15664
16152
  }
15665
- json6.minItems = prefixItems.length;
16153
+ json7.minItems = prefixItems.length;
15666
16154
  if (!rest) {
15667
- json6.maxItems = prefixItems.length;
16155
+ json7.maxItems = prefixItems.length;
15668
16156
  }
15669
16157
  } else {
15670
- json6.items = prefixItems;
16158
+ json7.items = prefixItems;
15671
16159
  if (rest) {
15672
- json6.additionalItems = rest;
16160
+ json7.additionalItems = rest;
15673
16161
  }
15674
16162
  }
15675
16163
  const { minimum, maximum } = schema._zod.bag;
15676
16164
  if (typeof minimum === "number")
15677
- json6.minItems = minimum;
16165
+ json7.minItems = minimum;
15678
16166
  if (typeof maximum === "number")
15679
- json6.maxItems = maximum;
16167
+ json7.maxItems = maximum;
15680
16168
  };
15681
16169
  var recordProcessor = (schema, ctx, _json, params) => {
15682
- const json6 = _json;
16170
+ const json7 = _json;
15683
16171
  const def = schema._zod.def;
15684
- json6.type = "object";
16172
+ json7.type = "object";
15685
16173
  const keyType = def.keyType;
15686
16174
  const keyBag = keyType._zod.bag;
15687
16175
  const patterns = keyBag?.patterns;
@@ -15690,18 +16178,18 @@ var recordProcessor = (schema, ctx, _json, params) => {
15690
16178
  ...params,
15691
16179
  path: [...params.path, "patternProperties", "*"]
15692
16180
  });
15693
- json6.patternProperties = {};
16181
+ json7.patternProperties = {};
15694
16182
  for (const pattern of patterns) {
15695
- json6.patternProperties[pattern.source] = valueSchema;
16183
+ json7.patternProperties[pattern.source] = valueSchema;
15696
16184
  }
15697
16185
  } else {
15698
16186
  if (ctx.target === "draft-07" || ctx.target === "draft-2020-12") {
15699
- json6.propertyNames = process2(def.keyType, ctx, {
16187
+ json7.propertyNames = process2(def.keyType, ctx, {
15700
16188
  ...params,
15701
16189
  path: [...params.path, "propertyNames"]
15702
16190
  });
15703
16191
  }
15704
- json6.additionalProperties = process2(def.valueType, ctx, {
16192
+ json7.additionalProperties = process2(def.valueType, ctx, {
15705
16193
  ...params,
15706
16194
  path: [...params.path, "additionalProperties"]
15707
16195
  });
@@ -15710,19 +16198,19 @@ var recordProcessor = (schema, ctx, _json, params) => {
15710
16198
  if (keyValues) {
15711
16199
  const validKeyValues = [...keyValues].filter((v) => typeof v === "string" || typeof v === "number");
15712
16200
  if (validKeyValues.length > 0) {
15713
- json6.required = validKeyValues;
16201
+ json7.required = validKeyValues;
15714
16202
  }
15715
16203
  }
15716
16204
  };
15717
- var nullableProcessor = (schema, ctx, json6, params) => {
16205
+ var nullableProcessor = (schema, ctx, json7, params) => {
15718
16206
  const def = schema._zod.def;
15719
16207
  const inner = process2(def.innerType, ctx, params);
15720
16208
  const seen = ctx.seen.get(schema);
15721
16209
  if (ctx.target === "openapi-3.0") {
15722
16210
  seen.ref = def.innerType;
15723
- json6.nullable = true;
16211
+ json7.nullable = true;
15724
16212
  } else {
15725
- json6.anyOf = [inner, { type: "null" }];
16213
+ json7.anyOf = [inner, { type: "null" }];
15726
16214
  }
15727
16215
  };
15728
16216
  var nonoptionalProcessor = (schema, ctx, _json, params) => {
@@ -15731,22 +16219,22 @@ var nonoptionalProcessor = (schema, ctx, _json, params) => {
15731
16219
  const seen = ctx.seen.get(schema);
15732
16220
  seen.ref = def.innerType;
15733
16221
  };
15734
- var defaultProcessor = (schema, ctx, json6, params) => {
16222
+ var defaultProcessor = (schema, ctx, json7, params) => {
15735
16223
  const def = schema._zod.def;
15736
16224
  process2(def.innerType, ctx, params);
15737
16225
  const seen = ctx.seen.get(schema);
15738
16226
  seen.ref = def.innerType;
15739
- json6.default = JSON.parse(JSON.stringify(def.defaultValue));
16227
+ json7.default = JSON.parse(JSON.stringify(def.defaultValue));
15740
16228
  };
15741
- var prefaultProcessor = (schema, ctx, json6, params) => {
16229
+ var prefaultProcessor = (schema, ctx, json7, params) => {
15742
16230
  const def = schema._zod.def;
15743
16231
  process2(def.innerType, ctx, params);
15744
16232
  const seen = ctx.seen.get(schema);
15745
16233
  seen.ref = def.innerType;
15746
16234
  if (ctx.io === "input")
15747
- json6._prefault = JSON.parse(JSON.stringify(def.defaultValue));
16235
+ json7._prefault = JSON.parse(JSON.stringify(def.defaultValue));
15748
16236
  };
15749
- var catchProcessor = (schema, ctx, json6, params) => {
16237
+ var catchProcessor = (schema, ctx, json7, params) => {
15750
16238
  const def = schema._zod.def;
15751
16239
  process2(def.innerType, ctx, params);
15752
16240
  const seen = ctx.seen.get(schema);
@@ -15757,7 +16245,7 @@ var catchProcessor = (schema, ctx, json6, params) => {
15757
16245
  } catch {
15758
16246
  throw new Error("Dynamic catch values are not supported in JSON Schema");
15759
16247
  }
15760
- json6.default = catchValue;
16248
+ json7.default = catchValue;
15761
16249
  };
15762
16250
  var pipeProcessor = (schema, ctx, _json, params) => {
15763
16251
  const def = schema._zod.def;
@@ -15767,12 +16255,12 @@ var pipeProcessor = (schema, ctx, _json, params) => {
15767
16255
  const seen = ctx.seen.get(schema);
15768
16256
  seen.ref = innerType;
15769
16257
  };
15770
- var readonlyProcessor = (schema, ctx, json6, params) => {
16258
+ var readonlyProcessor = (schema, ctx, json7, params) => {
15771
16259
  const def = schema._zod.def;
15772
16260
  process2(def.innerType, ctx, params);
15773
16261
  const seen = ctx.seen.get(schema);
15774
16262
  seen.ref = def.innerType;
15775
- json6.readOnly = true;
16263
+ json7.readOnly = true;
15776
16264
  };
15777
16265
  var promiseProcessor = (schema, ctx, _json, params) => {
15778
16266
  const def = schema._zod.def;
@@ -16042,7 +16530,7 @@ __export(exports_schemas2, {
16042
16530
  invertCodec: () => invertCodec,
16043
16531
  ipv4: () => ipv42,
16044
16532
  ipv6: () => ipv62,
16045
- json: () => json6,
16533
+ json: () => json7,
16046
16534
  jwt: () => jwt,
16047
16535
  keyof: () => keyof,
16048
16536
  ksuid: () => ksuid2,
@@ -16393,7 +16881,7 @@ var ZodType = /* @__PURE__ */ $constructor("ZodType", (inst, def) => {
16393
16881
  var _ZodString = /* @__PURE__ */ $constructor("_ZodString", (inst, def) => {
16394
16882
  $ZodString.init(inst, def);
16395
16883
  ZodType.init(inst, def);
16396
- inst._zod.processJSONSchema = (ctx, json6, params) => stringProcessor(inst, ctx, json6, params);
16884
+ inst._zod.processJSONSchema = (ctx, json7, params) => stringProcessor(inst, ctx, json7, params);
16397
16885
  const bag = inst._zod.bag;
16398
16886
  inst.format = bag.format ?? null;
16399
16887
  inst.minLength = bag.minimum ?? null;
@@ -16664,7 +17152,7 @@ function hash2(alg, params) {
16664
17152
  var ZodNumber = /* @__PURE__ */ $constructor("ZodNumber", (inst, def) => {
16665
17153
  $ZodNumber.init(inst, def);
16666
17154
  ZodType.init(inst, def);
16667
- inst._zod.processJSONSchema = (ctx, json6, params) => numberProcessor(inst, ctx, json6, params);
17155
+ inst._zod.processJSONSchema = (ctx, json7, params) => numberProcessor(inst, ctx, json7, params);
16668
17156
  _installLazyMethods(inst, "ZodNumber", {
16669
17157
  gt(value, params) {
16670
17158
  return this.check(_gt(value, params));
@@ -16744,7 +17232,7 @@ function uint32(params) {
16744
17232
  var ZodBoolean = /* @__PURE__ */ $constructor("ZodBoolean", (inst, def) => {
16745
17233
  $ZodBoolean.init(inst, def);
16746
17234
  ZodType.init(inst, def);
16747
- inst._zod.processJSONSchema = (ctx, json6, params) => booleanProcessor(inst, ctx, json6, params);
17235
+ inst._zod.processJSONSchema = (ctx, json7, params) => booleanProcessor(inst, ctx, json7, params);
16748
17236
  });
16749
17237
  function boolean2(params) {
16750
17238
  return _boolean(ZodBoolean, params);
@@ -16752,7 +17240,7 @@ function boolean2(params) {
16752
17240
  var ZodBigInt = /* @__PURE__ */ $constructor("ZodBigInt", (inst, def) => {
16753
17241
  $ZodBigInt.init(inst, def);
16754
17242
  ZodType.init(inst, def);
16755
- inst._zod.processJSONSchema = (ctx, json6, params) => bigintProcessor(inst, ctx, json6, params);
17243
+ inst._zod.processJSONSchema = (ctx, json7, params) => bigintProcessor(inst, ctx, json7, params);
16756
17244
  inst.gte = (value, params) => inst.check(_gte(value, params));
16757
17245
  inst.min = (value, params) => inst.check(_gte(value, params));
16758
17246
  inst.gt = (value, params) => inst.check(_gt(value, params));
@@ -16787,7 +17275,7 @@ function uint64(params) {
16787
17275
  var ZodSymbol = /* @__PURE__ */ $constructor("ZodSymbol", (inst, def) => {
16788
17276
  $ZodSymbol.init(inst, def);
16789
17277
  ZodType.init(inst, def);
16790
- inst._zod.processJSONSchema = (ctx, json6, params) => symbolProcessor(inst, ctx, json6, params);
17278
+ inst._zod.processJSONSchema = (ctx, json7, params) => symbolProcessor(inst, ctx, json7, params);
16791
17279
  });
16792
17280
  function symbol(params) {
16793
17281
  return _symbol(ZodSymbol, params);
@@ -16795,7 +17283,7 @@ function symbol(params) {
16795
17283
  var ZodUndefined = /* @__PURE__ */ $constructor("ZodUndefined", (inst, def) => {
16796
17284
  $ZodUndefined.init(inst, def);
16797
17285
  ZodType.init(inst, def);
16798
- inst._zod.processJSONSchema = (ctx, json6, params) => undefinedProcessor(inst, ctx, json6, params);
17286
+ inst._zod.processJSONSchema = (ctx, json7, params) => undefinedProcessor(inst, ctx, json7, params);
16799
17287
  });
16800
17288
  function _undefined3(params) {
16801
17289
  return _undefined2(ZodUndefined, params);
@@ -16803,7 +17291,7 @@ function _undefined3(params) {
16803
17291
  var ZodNull = /* @__PURE__ */ $constructor("ZodNull", (inst, def) => {
16804
17292
  $ZodNull.init(inst, def);
16805
17293
  ZodType.init(inst, def);
16806
- inst._zod.processJSONSchema = (ctx, json6, params) => nullProcessor(inst, ctx, json6, params);
17294
+ inst._zod.processJSONSchema = (ctx, json7, params) => nullProcessor(inst, ctx, json7, params);
16807
17295
  });
16808
17296
  function _null3(params) {
16809
17297
  return _null2(ZodNull, params);
@@ -16811,7 +17299,7 @@ function _null3(params) {
16811
17299
  var ZodAny = /* @__PURE__ */ $constructor("ZodAny", (inst, def) => {
16812
17300
  $ZodAny.init(inst, def);
16813
17301
  ZodType.init(inst, def);
16814
- inst._zod.processJSONSchema = (ctx, json6, params) => anyProcessor(inst, ctx, json6, params);
17302
+ inst._zod.processJSONSchema = (ctx, json7, params) => anyProcessor(inst, ctx, json7, params);
16815
17303
  });
16816
17304
  function any() {
16817
17305
  return _any(ZodAny);
@@ -16819,7 +17307,7 @@ function any() {
16819
17307
  var ZodUnknown = /* @__PURE__ */ $constructor("ZodUnknown", (inst, def) => {
16820
17308
  $ZodUnknown.init(inst, def);
16821
17309
  ZodType.init(inst, def);
16822
- inst._zod.processJSONSchema = (ctx, json6, params) => unknownProcessor(inst, ctx, json6, params);
17310
+ inst._zod.processJSONSchema = (ctx, json7, params) => unknownProcessor(inst, ctx, json7, params);
16823
17311
  });
16824
17312
  function unknown() {
16825
17313
  return _unknown(ZodUnknown);
@@ -16827,7 +17315,7 @@ function unknown() {
16827
17315
  var ZodNever = /* @__PURE__ */ $constructor("ZodNever", (inst, def) => {
16828
17316
  $ZodNever.init(inst, def);
16829
17317
  ZodType.init(inst, def);
16830
- inst._zod.processJSONSchema = (ctx, json6, params) => neverProcessor(inst, ctx, json6, params);
17318
+ inst._zod.processJSONSchema = (ctx, json7, params) => neverProcessor(inst, ctx, json7, params);
16831
17319
  });
16832
17320
  function never(params) {
16833
17321
  return _never(ZodNever, params);
@@ -16835,7 +17323,7 @@ function never(params) {
16835
17323
  var ZodVoid = /* @__PURE__ */ $constructor("ZodVoid", (inst, def) => {
16836
17324
  $ZodVoid.init(inst, def);
16837
17325
  ZodType.init(inst, def);
16838
- inst._zod.processJSONSchema = (ctx, json6, params) => voidProcessor(inst, ctx, json6, params);
17326
+ inst._zod.processJSONSchema = (ctx, json7, params) => voidProcessor(inst, ctx, json7, params);
16839
17327
  });
16840
17328
  function _void2(params) {
16841
17329
  return _void(ZodVoid, params);
@@ -16843,7 +17331,7 @@ function _void2(params) {
16843
17331
  var ZodDate = /* @__PURE__ */ $constructor("ZodDate", (inst, def) => {
16844
17332
  $ZodDate.init(inst, def);
16845
17333
  ZodType.init(inst, def);
16846
- inst._zod.processJSONSchema = (ctx, json6, params) => dateProcessor(inst, ctx, json6, params);
17334
+ inst._zod.processJSONSchema = (ctx, json7, params) => dateProcessor(inst, ctx, json7, params);
16847
17335
  inst.min = (value, params) => inst.check(_gte(value, params));
16848
17336
  inst.max = (value, params) => inst.check(_lte(value, params));
16849
17337
  const c = inst._zod.bag;
@@ -16856,7 +17344,7 @@ function date3(params) {
16856
17344
  var ZodArray = /* @__PURE__ */ $constructor("ZodArray", (inst, def) => {
16857
17345
  $ZodArray.init(inst, def);
16858
17346
  ZodType.init(inst, def);
16859
- inst._zod.processJSONSchema = (ctx, json6, params) => arrayProcessor(inst, ctx, json6, params);
17347
+ inst._zod.processJSONSchema = (ctx, json7, params) => arrayProcessor(inst, ctx, json7, params);
16860
17348
  inst.element = def.element;
16861
17349
  _installLazyMethods(inst, "ZodArray", {
16862
17350
  min(n, params) {
@@ -16886,7 +17374,7 @@ function keyof(schema) {
16886
17374
  var ZodObject = /* @__PURE__ */ $constructor("ZodObject", (inst, def) => {
16887
17375
  $ZodObjectJIT.init(inst, def);
16888
17376
  ZodType.init(inst, def);
16889
- inst._zod.processJSONSchema = (ctx, json6, params) => objectProcessor(inst, ctx, json6, params);
17377
+ inst._zod.processJSONSchema = (ctx, json7, params) => objectProcessor(inst, ctx, json7, params);
16890
17378
  exports_util.defineLazy(inst, "shape", () => {
16891
17379
  return def.shape;
16892
17380
  });
@@ -16959,7 +17447,7 @@ function looseObject(shape, params) {
16959
17447
  var ZodUnion = /* @__PURE__ */ $constructor("ZodUnion", (inst, def) => {
16960
17448
  $ZodUnion.init(inst, def);
16961
17449
  ZodType.init(inst, def);
16962
- inst._zod.processJSONSchema = (ctx, json6, params) => unionProcessor(inst, ctx, json6, params);
17450
+ inst._zod.processJSONSchema = (ctx, json7, params) => unionProcessor(inst, ctx, json7, params);
16963
17451
  inst.options = def.options;
16964
17452
  });
16965
17453
  function union(options, params) {
@@ -16972,7 +17460,7 @@ function union(options, params) {
16972
17460
  var ZodXor = /* @__PURE__ */ $constructor("ZodXor", (inst, def) => {
16973
17461
  ZodUnion.init(inst, def);
16974
17462
  $ZodXor.init(inst, def);
16975
- inst._zod.processJSONSchema = (ctx, json6, params) => unionProcessor(inst, ctx, json6, params);
17463
+ inst._zod.processJSONSchema = (ctx, json7, params) => unionProcessor(inst, ctx, json7, params);
16976
17464
  inst.options = def.options;
16977
17465
  });
16978
17466
  function xor(options, params) {
@@ -16998,7 +17486,7 @@ function discriminatedUnion(discriminator, options, params) {
16998
17486
  var ZodIntersection = /* @__PURE__ */ $constructor("ZodIntersection", (inst, def) => {
16999
17487
  $ZodIntersection.init(inst, def);
17000
17488
  ZodType.init(inst, def);
17001
- inst._zod.processJSONSchema = (ctx, json6, params) => intersectionProcessor(inst, ctx, json6, params);
17489
+ inst._zod.processJSONSchema = (ctx, json7, params) => intersectionProcessor(inst, ctx, json7, params);
17002
17490
  });
17003
17491
  function intersection(left, right) {
17004
17492
  return new ZodIntersection({
@@ -17010,7 +17498,7 @@ function intersection(left, right) {
17010
17498
  var ZodTuple = /* @__PURE__ */ $constructor("ZodTuple", (inst, def) => {
17011
17499
  $ZodTuple.init(inst, def);
17012
17500
  ZodType.init(inst, def);
17013
- inst._zod.processJSONSchema = (ctx, json6, params) => tupleProcessor(inst, ctx, json6, params);
17501
+ inst._zod.processJSONSchema = (ctx, json7, params) => tupleProcessor(inst, ctx, json7, params);
17014
17502
  inst.rest = (rest) => inst.clone({
17015
17503
  ...inst._zod.def,
17016
17504
  rest
@@ -17030,7 +17518,7 @@ function tuple(items, _paramsOrRest, _params) {
17030
17518
  var ZodRecord = /* @__PURE__ */ $constructor("ZodRecord", (inst, def) => {
17031
17519
  $ZodRecord.init(inst, def);
17032
17520
  ZodType.init(inst, def);
17033
- inst._zod.processJSONSchema = (ctx, json6, params) => recordProcessor(inst, ctx, json6, params);
17521
+ inst._zod.processJSONSchema = (ctx, json7, params) => recordProcessor(inst, ctx, json7, params);
17034
17522
  inst.keyType = def.keyType;
17035
17523
  inst.valueType = def.valueType;
17036
17524
  });
@@ -17072,7 +17560,7 @@ function looseRecord(keyType, valueType, params) {
17072
17560
  var ZodMap = /* @__PURE__ */ $constructor("ZodMap", (inst, def) => {
17073
17561
  $ZodMap.init(inst, def);
17074
17562
  ZodType.init(inst, def);
17075
- inst._zod.processJSONSchema = (ctx, json6, params) => mapProcessor(inst, ctx, json6, params);
17563
+ inst._zod.processJSONSchema = (ctx, json7, params) => mapProcessor(inst, ctx, json7, params);
17076
17564
  inst.keyType = def.keyType;
17077
17565
  inst.valueType = def.valueType;
17078
17566
  inst.min = (...args) => inst.check(_minSize(...args));
@@ -17091,7 +17579,7 @@ function map(keyType, valueType, params) {
17091
17579
  var ZodSet = /* @__PURE__ */ $constructor("ZodSet", (inst, def) => {
17092
17580
  $ZodSet.init(inst, def);
17093
17581
  ZodType.init(inst, def);
17094
- inst._zod.processJSONSchema = (ctx, json6, params) => setProcessor(inst, ctx, json6, params);
17582
+ inst._zod.processJSONSchema = (ctx, json7, params) => setProcessor(inst, ctx, json7, params);
17095
17583
  inst.min = (...args) => inst.check(_minSize(...args));
17096
17584
  inst.nonempty = (params) => inst.check(_minSize(1, params));
17097
17585
  inst.max = (...args) => inst.check(_maxSize(...args));
@@ -17107,7 +17595,7 @@ function set(valueType, params) {
17107
17595
  var ZodEnum = /* @__PURE__ */ $constructor("ZodEnum", (inst, def) => {
17108
17596
  $ZodEnum.init(inst, def);
17109
17597
  ZodType.init(inst, def);
17110
- inst._zod.processJSONSchema = (ctx, json6, params) => enumProcessor(inst, ctx, json6, params);
17598
+ inst._zod.processJSONSchema = (ctx, json7, params) => enumProcessor(inst, ctx, json7, params);
17111
17599
  inst.enum = def.entries;
17112
17600
  inst.options = Object.values(def.entries);
17113
17601
  const keys = new Set(Object.keys(def.entries));
@@ -17160,7 +17648,7 @@ function nativeEnum(entries, params) {
17160
17648
  var ZodLiteral = /* @__PURE__ */ $constructor("ZodLiteral", (inst, def) => {
17161
17649
  $ZodLiteral.init(inst, def);
17162
17650
  ZodType.init(inst, def);
17163
- inst._zod.processJSONSchema = (ctx, json6, params) => literalProcessor(inst, ctx, json6, params);
17651
+ inst._zod.processJSONSchema = (ctx, json7, params) => literalProcessor(inst, ctx, json7, params);
17164
17652
  inst.values = new Set(def.values);
17165
17653
  Object.defineProperty(inst, "value", {
17166
17654
  get() {
@@ -17181,7 +17669,7 @@ function literal(value, params) {
17181
17669
  var ZodFile = /* @__PURE__ */ $constructor("ZodFile", (inst, def) => {
17182
17670
  $ZodFile.init(inst, def);
17183
17671
  ZodType.init(inst, def);
17184
- inst._zod.processJSONSchema = (ctx, json6, params) => fileProcessor(inst, ctx, json6, params);
17672
+ inst._zod.processJSONSchema = (ctx, json7, params) => fileProcessor(inst, ctx, json7, params);
17185
17673
  inst.min = (size, params) => inst.check(_minSize(size, params));
17186
17674
  inst.max = (size, params) => inst.check(_maxSize(size, params));
17187
17675
  inst.mime = (types2, params) => inst.check(_mime(Array.isArray(types2) ? types2 : [types2], params));
@@ -17192,7 +17680,7 @@ function file(params) {
17192
17680
  var ZodTransform = /* @__PURE__ */ $constructor("ZodTransform", (inst, def) => {
17193
17681
  $ZodTransform.init(inst, def);
17194
17682
  ZodType.init(inst, def);
17195
- inst._zod.processJSONSchema = (ctx, json6, params) => transformProcessor(inst, ctx, json6, params);
17683
+ inst._zod.processJSONSchema = (ctx, json7, params) => transformProcessor(inst, ctx, json7, params);
17196
17684
  inst._zod.parse = (payload, _ctx) => {
17197
17685
  if (_ctx.direction === "backward") {
17198
17686
  throw new $ZodEncodeError(inst.constructor.name);
@@ -17232,7 +17720,7 @@ function transform(fn) {
17232
17720
  var ZodOptional = /* @__PURE__ */ $constructor("ZodOptional", (inst, def) => {
17233
17721
  $ZodOptional.init(inst, def);
17234
17722
  ZodType.init(inst, def);
17235
- inst._zod.processJSONSchema = (ctx, json6, params) => optionalProcessor(inst, ctx, json6, params);
17723
+ inst._zod.processJSONSchema = (ctx, json7, params) => optionalProcessor(inst, ctx, json7, params);
17236
17724
  inst.unwrap = () => inst._zod.def.innerType;
17237
17725
  });
17238
17726
  function optional(innerType) {
@@ -17244,7 +17732,7 @@ function optional(innerType) {
17244
17732
  var ZodExactOptional = /* @__PURE__ */ $constructor("ZodExactOptional", (inst, def) => {
17245
17733
  $ZodExactOptional.init(inst, def);
17246
17734
  ZodType.init(inst, def);
17247
- inst._zod.processJSONSchema = (ctx, json6, params) => optionalProcessor(inst, ctx, json6, params);
17735
+ inst._zod.processJSONSchema = (ctx, json7, params) => optionalProcessor(inst, ctx, json7, params);
17248
17736
  inst.unwrap = () => inst._zod.def.innerType;
17249
17737
  });
17250
17738
  function exactOptional(innerType) {
@@ -17256,7 +17744,7 @@ function exactOptional(innerType) {
17256
17744
  var ZodNullable = /* @__PURE__ */ $constructor("ZodNullable", (inst, def) => {
17257
17745
  $ZodNullable.init(inst, def);
17258
17746
  ZodType.init(inst, def);
17259
- inst._zod.processJSONSchema = (ctx, json6, params) => nullableProcessor(inst, ctx, json6, params);
17747
+ inst._zod.processJSONSchema = (ctx, json7, params) => nullableProcessor(inst, ctx, json7, params);
17260
17748
  inst.unwrap = () => inst._zod.def.innerType;
17261
17749
  });
17262
17750
  function nullable(innerType) {
@@ -17271,7 +17759,7 @@ function nullish2(innerType) {
17271
17759
  var ZodDefault = /* @__PURE__ */ $constructor("ZodDefault", (inst, def) => {
17272
17760
  $ZodDefault.init(inst, def);
17273
17761
  ZodType.init(inst, def);
17274
- inst._zod.processJSONSchema = (ctx, json6, params) => defaultProcessor(inst, ctx, json6, params);
17762
+ inst._zod.processJSONSchema = (ctx, json7, params) => defaultProcessor(inst, ctx, json7, params);
17275
17763
  inst.unwrap = () => inst._zod.def.innerType;
17276
17764
  inst.removeDefault = inst.unwrap;
17277
17765
  });
@@ -17287,7 +17775,7 @@ function _default2(innerType, defaultValue) {
17287
17775
  var ZodPrefault = /* @__PURE__ */ $constructor("ZodPrefault", (inst, def) => {
17288
17776
  $ZodPrefault.init(inst, def);
17289
17777
  ZodType.init(inst, def);
17290
- inst._zod.processJSONSchema = (ctx, json6, params) => prefaultProcessor(inst, ctx, json6, params);
17778
+ inst._zod.processJSONSchema = (ctx, json7, params) => prefaultProcessor(inst, ctx, json7, params);
17291
17779
  inst.unwrap = () => inst._zod.def.innerType;
17292
17780
  });
17293
17781
  function prefault(innerType, defaultValue) {
@@ -17302,7 +17790,7 @@ function prefault(innerType, defaultValue) {
17302
17790
  var ZodNonOptional = /* @__PURE__ */ $constructor("ZodNonOptional", (inst, def) => {
17303
17791
  $ZodNonOptional.init(inst, def);
17304
17792
  ZodType.init(inst, def);
17305
- inst._zod.processJSONSchema = (ctx, json6, params) => nonoptionalProcessor(inst, ctx, json6, params);
17793
+ inst._zod.processJSONSchema = (ctx, json7, params) => nonoptionalProcessor(inst, ctx, json7, params);
17306
17794
  inst.unwrap = () => inst._zod.def.innerType;
17307
17795
  });
17308
17796
  function nonoptional(innerType, params) {
@@ -17315,7 +17803,7 @@ function nonoptional(innerType, params) {
17315
17803
  var ZodSuccess = /* @__PURE__ */ $constructor("ZodSuccess", (inst, def) => {
17316
17804
  $ZodSuccess.init(inst, def);
17317
17805
  ZodType.init(inst, def);
17318
- inst._zod.processJSONSchema = (ctx, json6, params) => successProcessor(inst, ctx, json6, params);
17806
+ inst._zod.processJSONSchema = (ctx, json7, params) => successProcessor(inst, ctx, json7, params);
17319
17807
  inst.unwrap = () => inst._zod.def.innerType;
17320
17808
  });
17321
17809
  function success(innerType) {
@@ -17327,7 +17815,7 @@ function success(innerType) {
17327
17815
  var ZodCatch = /* @__PURE__ */ $constructor("ZodCatch", (inst, def) => {
17328
17816
  $ZodCatch.init(inst, def);
17329
17817
  ZodType.init(inst, def);
17330
- inst._zod.processJSONSchema = (ctx, json6, params) => catchProcessor(inst, ctx, json6, params);
17818
+ inst._zod.processJSONSchema = (ctx, json7, params) => catchProcessor(inst, ctx, json7, params);
17331
17819
  inst.unwrap = () => inst._zod.def.innerType;
17332
17820
  inst.removeCatch = inst.unwrap;
17333
17821
  });
@@ -17341,7 +17829,7 @@ function _catch2(innerType, catchValue) {
17341
17829
  var ZodNaN = /* @__PURE__ */ $constructor("ZodNaN", (inst, def) => {
17342
17830
  $ZodNaN.init(inst, def);
17343
17831
  ZodType.init(inst, def);
17344
- inst._zod.processJSONSchema = (ctx, json6, params) => nanProcessor(inst, ctx, json6, params);
17832
+ inst._zod.processJSONSchema = (ctx, json7, params) => nanProcessor(inst, ctx, json7, params);
17345
17833
  });
17346
17834
  function nan(params) {
17347
17835
  return _nan(ZodNaN, params);
@@ -17349,7 +17837,7 @@ function nan(params) {
17349
17837
  var ZodPipe = /* @__PURE__ */ $constructor("ZodPipe", (inst, def) => {
17350
17838
  $ZodPipe.init(inst, def);
17351
17839
  ZodType.init(inst, def);
17352
- inst._zod.processJSONSchema = (ctx, json6, params) => pipeProcessor(inst, ctx, json6, params);
17840
+ inst._zod.processJSONSchema = (ctx, json7, params) => pipeProcessor(inst, ctx, json7, params);
17353
17841
  inst.in = def.in;
17354
17842
  inst.out = def.out;
17355
17843
  });
@@ -17390,7 +17878,7 @@ var ZodPreprocess = /* @__PURE__ */ $constructor("ZodPreprocess", (inst, def) =>
17390
17878
  var ZodReadonly = /* @__PURE__ */ $constructor("ZodReadonly", (inst, def) => {
17391
17879
  $ZodReadonly.init(inst, def);
17392
17880
  ZodType.init(inst, def);
17393
- inst._zod.processJSONSchema = (ctx, json6, params) => readonlyProcessor(inst, ctx, json6, params);
17881
+ inst._zod.processJSONSchema = (ctx, json7, params) => readonlyProcessor(inst, ctx, json7, params);
17394
17882
  inst.unwrap = () => inst._zod.def.innerType;
17395
17883
  });
17396
17884
  function readonly(innerType) {
@@ -17402,7 +17890,7 @@ function readonly(innerType) {
17402
17890
  var ZodTemplateLiteral = /* @__PURE__ */ $constructor("ZodTemplateLiteral", (inst, def) => {
17403
17891
  $ZodTemplateLiteral.init(inst, def);
17404
17892
  ZodType.init(inst, def);
17405
- inst._zod.processJSONSchema = (ctx, json6, params) => templateLiteralProcessor(inst, ctx, json6, params);
17893
+ inst._zod.processJSONSchema = (ctx, json7, params) => templateLiteralProcessor(inst, ctx, json7, params);
17406
17894
  });
17407
17895
  function templateLiteral(parts, params) {
17408
17896
  return new ZodTemplateLiteral({
@@ -17414,7 +17902,7 @@ function templateLiteral(parts, params) {
17414
17902
  var ZodLazy = /* @__PURE__ */ $constructor("ZodLazy", (inst, def) => {
17415
17903
  $ZodLazy.init(inst, def);
17416
17904
  ZodType.init(inst, def);
17417
- inst._zod.processJSONSchema = (ctx, json6, params) => lazyProcessor(inst, ctx, json6, params);
17905
+ inst._zod.processJSONSchema = (ctx, json7, params) => lazyProcessor(inst, ctx, json7, params);
17418
17906
  inst.unwrap = () => inst._zod.def.getter();
17419
17907
  });
17420
17908
  function lazy(getter) {
@@ -17426,7 +17914,7 @@ function lazy(getter) {
17426
17914
  var ZodPromise = /* @__PURE__ */ $constructor("ZodPromise", (inst, def) => {
17427
17915
  $ZodPromise.init(inst, def);
17428
17916
  ZodType.init(inst, def);
17429
- inst._zod.processJSONSchema = (ctx, json6, params) => promiseProcessor(inst, ctx, json6, params);
17917
+ inst._zod.processJSONSchema = (ctx, json7, params) => promiseProcessor(inst, ctx, json7, params);
17430
17918
  inst.unwrap = () => inst._zod.def.innerType;
17431
17919
  });
17432
17920
  function promise(innerType) {
@@ -17438,7 +17926,7 @@ function promise(innerType) {
17438
17926
  var ZodFunction = /* @__PURE__ */ $constructor("ZodFunction", (inst, def) => {
17439
17927
  $ZodFunction.init(inst, def);
17440
17928
  ZodType.init(inst, def);
17441
- inst._zod.processJSONSchema = (ctx, json6, params) => functionProcessor(inst, ctx, json6, params);
17929
+ inst._zod.processJSONSchema = (ctx, json7, params) => functionProcessor(inst, ctx, json7, params);
17442
17930
  });
17443
17931
  function _function(params) {
17444
17932
  return new ZodFunction({
@@ -17450,7 +17938,7 @@ function _function(params) {
17450
17938
  var ZodCustom = /* @__PURE__ */ $constructor("ZodCustom", (inst, def) => {
17451
17939
  $ZodCustom.init(inst, def);
17452
17940
  ZodType.init(inst, def);
17453
- inst._zod.processJSONSchema = (ctx, json6, params) => customProcessor(inst, ctx, json6, params);
17941
+ inst._zod.processJSONSchema = (ctx, json7, params) => customProcessor(inst, ctx, json7, params);
17454
17942
  });
17455
17943
  function check(fn) {
17456
17944
  const ch = new $ZodCheck({
@@ -17497,7 +17985,7 @@ var stringbool = (...args) => _stringbool({
17497
17985
  Boolean: ZodBoolean,
17498
17986
  String: ZodString
17499
17987
  }, ...args);
17500
- function json6(params) {
17988
+ function json7(params) {
17501
17989
  const jsonSchema = lazy(() => {
17502
17990
  return union([string2(params), number2(), boolean2(), _null3(), array(jsonSchema), record(string2(), jsonSchema)]);
17503
17991
  });
@@ -18749,10 +19237,10 @@ function prepareArtifact(input) {
18749
19237
  attempts,
18750
19238
  error: error51.value
18751
19239
  };
18752
- const json7 = JSON.stringify(bounded);
18753
- const size = encoder2.encode(json7).length;
19240
+ const json8 = JSON.stringify(bounded);
19241
+ const size = encoder2.encode(json8).length;
18754
19242
  if (size <= MAX_ARTIFACT_BYTES)
18755
- return { artifact: bounded, json: json7 };
19243
+ return { artifact: bounded, json: json8 };
18756
19244
  const marker = omission(size);
18757
19245
  const omitted = omitBodies(bounded, marker);
18758
19246
  const omittedJson = JSON.stringify(omitted);
@@ -18762,8 +19250,8 @@ function prepareArtifact(input) {
18762
19250
  const stripped = { ...omitted, error: marker };
18763
19251
  return { artifact: stripped, json: JSON.stringify(stripped) };
18764
19252
  }
18765
- async function sealArtifact(key, json7) {
18766
- const bytes = encoder2.encode(await encrypt(key, json7));
19253
+ async function sealArtifact(key, json8) {
19254
+ const bytes = encoder2.encode(await encrypt(key, json8));
18767
19255
  return { bytes, sha256: await sha256Hex(bytes) };
18768
19256
  }
18769
19257
  async function readArtifact(key, dir, relPath, expectedSha256) {
@@ -20859,13 +21347,15 @@ function customProviderData(input) {
20859
21347
  } catch {
20860
21348
  throw new GatewayError("BAD_REQUEST", "origin: must be a valid URL");
20861
21349
  }
20862
- if (url2.protocol !== "http:" && url2.protocol !== "https:" || url2.hostname.length === 0 || url2.username.length > 0 || url2.password.length > 0 || url2.pathname !== "" && url2.pathname !== "/" || url2.search.length > 0 || url2.hash.length > 0) {
21350
+ if (url2.protocol !== "http:" && url2.protocol !== "https:" || url2.hostname.length === 0 || url2.username.length > 0 || url2.password.length > 0 || url2.search.length > 0 || url2.hash.length > 0) {
20863
21351
  throw new GatewayError("BAD_REQUEST", "origin: must be an HTTP(S) server origin");
20864
21352
  }
20865
- return { endpointId, endpointLabel, origin: url2.origin, protocol: input.protocol };
21353
+ const basePath = url2.pathname.replace(/\/+$/, "");
21354
+ return { endpointId, endpointLabel, origin: url2.origin, basePath, protocol: input.protocol };
20866
21355
  }
20867
21356
  function sameCustomEndpoint(a, b) {
20868
- return a.endpointId === b.endpointId && a.endpointLabel === b.endpointLabel && a.origin === b.origin && a.protocol === b.protocol;
21357
+ const basePath = typeof a.basePath === "string" ? a.basePath : "";
21358
+ return a.endpointId === b.endpointId && a.endpointLabel === b.endpointLabel && a.origin === b.origin && basePath === b.basePath && a.protocol === b.protocol;
20869
21359
  }
20870
21360
  async function createApiKeyCredential(store, input, logger2 = noopLogger) {
20871
21361
  const provider = parseOrThrow(providerIdSchema, input.provider);
@@ -22506,10 +22996,10 @@ function emailFromIdToken(idToken) {
22506
22996
  if (parts.length !== 3 || payload === undefined || payload.length === 0)
22507
22997
  return null;
22508
22998
  try {
22509
- const json7 = JSON.parse(Buffer.from(payload, "base64url").toString("utf8"));
22510
- if (!isRecord2(json7))
22999
+ const json8 = JSON.parse(Buffer.from(payload, "base64url").toString("utf8"));
23000
+ if (!isRecord2(json8))
22511
23001
  return null;
22512
- return typeof json7.email === "string" && json7.email.trim().length > 0 ? json7.email : null;
23002
+ return typeof json8.email === "string" && json8.email.trim().length > 0 ? json8.email : null;
22513
23003
  } catch {
22514
23004
  return null;
22515
23005
  }
@@ -22912,12 +23402,12 @@ function decodeClaims(idToken) {
22912
23402
  return { email: null, accountId: null };
22913
23403
  }
22914
23404
  try {
22915
- const json7 = JSON.parse(Buffer.from(payload, "base64url").toString("utf8"));
22916
- if (!isRecord5(json7))
23405
+ const json8 = JSON.parse(Buffer.from(payload, "base64url").toString("utf8"));
23406
+ if (!isRecord5(json8))
22917
23407
  return { email: null, accountId: null };
22918
- const auth = json7["https://api.openai.com/auth"];
23408
+ const auth = json8["https://api.openai.com/auth"];
22919
23409
  return {
22920
- email: typeof json7.email === "string" ? json7.email : null,
23410
+ email: typeof json8.email === "string" ? json8.email : null,
22921
23411
  accountId: isRecord5(auth) ? nonBlankStringOrNull(auth.chatgpt_account_id) : null
22922
23412
  };
22923
23413
  } catch {
@@ -24161,13 +24651,14 @@ var credentialsAddKey = {
24161
24651
  const store = await ctx.store();
24162
24652
  const endpointId = stringFlag(args.values, "endpoint-id");
24163
24653
  const existingEndpoint = providerId === "custom" && endpointId !== undefined ? (await listCredentials(store)).find((credential) => credential.provider === "custom" && credential.providerData.endpointId === endpointId.trim()) : undefined;
24654
+ const existingOrigin = existingEndpoint === undefined ? undefined : `${String(existingEndpoint.providerData.origin)}${typeof existingEndpoint.providerData.basePath === "string" ? existingEndpoint.providerData.basePath : ""}`;
24164
24655
  const created = await createApiKeyCredential(store, {
24165
24656
  provider: providerId,
24166
24657
  apiKey: key,
24167
24658
  label: stringFlag(args.values, "label"),
24168
24659
  endpointId,
24169
24660
  endpointLabel: stringFlag(args.values, "endpoint-label") ?? existingEndpoint?.providerData.endpointLabel,
24170
- origin: stringFlag(args.values, "origin") ?? existingEndpoint?.providerData.origin,
24661
+ origin: stringFlag(args.values, "origin") ?? existingOrigin,
24171
24662
  protocol: protocol ?? existingEndpoint?.providerData.protocol
24172
24663
  });
24173
24664
  emit(ctx, writer, { id: created.id, provider: created.provider }, () => `stored ${created.provider} api key as ${created.id}`);