omnigateway 0.4.11 → 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 +910 -384
  3. package/gateway.js +906 -355
  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
@@ -1931,16 +1931,51 @@ function hasVendorCacheControl(req) {
1931
1931
  const anthropic2 = req.vendor?.anthropic;
1932
1932
  return typeof anthropic2 === "object" && anthropic2 !== null && "cache_control" in anthropic2;
1933
1933
  }
1934
- function addAutoCacheBreakpoint(body, req, note2) {
1934
+ var CACHEABLE_WIRE_BLOCKS = new Set(["text", "image", "tool_use", "tool_result", "document"]);
1935
+ function lastCacheableHistoryBlock(messages) {
1936
+ for (let m = messages.length - 1;m >= 0; m--) {
1937
+ const message = messages[m];
1938
+ if (!isRecord(message) || !Array.isArray(message.content))
1939
+ continue;
1940
+ for (let b = message.content.length - 1;b >= 0; b--) {
1941
+ const block = message.content[b];
1942
+ if (!isRecord(block))
1943
+ continue;
1944
+ if (typeof block.type === "string" && CACHEABLE_WIRE_BLOCKS.has(block.type))
1945
+ return block;
1946
+ }
1947
+ }
1948
+ return;
1949
+ }
1950
+ function addAutoCacheBreakpoints(body, req, note2) {
1935
1951
  if (estimateCachedInputTokens(req) !== 0 || hasVendorCacheControl(req))
1936
1952
  return;
1937
- if (estimateInputTokens({ ...req, messages: [] }) < AUTO_CACHE_MIN_TOKENS)
1953
+ let markedPrefix = 0;
1954
+ const worthAMarker = (prefix) => prefix - markedPrefix >= AUTO_CACHE_MIN_TOKENS;
1955
+ let stablePrefixMarked = false;
1956
+ const toolsPrefix = estimateInputTokens({ ...req, messages: [], system: [] });
1957
+ const lastTool = body.tools?.at(-1);
1958
+ if (lastTool !== undefined && worthAMarker(toolsPrefix)) {
1959
+ lastTool.cache_control = { type: "ephemeral" };
1960
+ markedPrefix = toolsPrefix;
1961
+ stablePrefixMarked = true;
1962
+ }
1963
+ const systemPrefix = estimateInputTokens({ ...req, messages: [] });
1964
+ const lastSystem = body.system?.at(-1);
1965
+ if (lastSystem !== undefined && worthAMarker(systemPrefix)) {
1966
+ lastSystem.cache_control = { type: "ephemeral" };
1967
+ markedPrefix = systemPrefix;
1968
+ stablePrefixMarked = true;
1969
+ }
1970
+ if (stablePrefixMarked)
1971
+ note2("anthropic:cache-breakpoint-added");
1972
+ if (!worthAMarker(estimateInputTokens(req)))
1938
1973
  return;
1939
- const target = body.system?.at(-1) ?? body.tools?.at(-1);
1940
- if (target === undefined)
1974
+ const lastHistory = lastCacheableHistoryBlock(body.messages);
1975
+ if (lastHistory === undefined)
1941
1976
  return;
1942
- target.cache_control = { type: "ephemeral" };
1943
- note2("anthropic:cache-breakpoint-added");
1977
+ lastHistory.cache_control = { type: "ephemeral" };
1978
+ note2("anthropic:history-cache-breakpoint-added");
1944
1979
  }
1945
1980
  function toWire(req, model, opts) {
1946
1981
  const cloak = opts.cloak ?? null;
@@ -1992,7 +2027,7 @@ function toWire(req, model, opts) {
1992
2027
  if (req.toolChoice !== undefined)
1993
2028
  body.tool_choice = encodeToolChoice(req.toolChoice, cloak);
1994
2029
  if (opts.autoCache === true)
1995
- addAutoCacheBreakpoint(body, req, note2);
2030
+ addAutoCacheBreakpoints(body, req, note2);
1996
2031
  if (req.reasoning !== undefined) {
1997
2032
  switch (req.reasoning.mode) {
1998
2033
  case "adaptive":
@@ -2105,13 +2140,31 @@ var anthropicAdapter = {
2105
2140
  };
2106
2141
  }
2107
2142
  };
2108
- // packages/providers/src/kimi/decode.ts
2109
- var FINISH = {
2143
+ // packages/providers/src/custom/decode.ts
2144
+ var CHAT_FINISH = {
2110
2145
  stop: "endTurn",
2111
2146
  length: "maxTokens",
2112
2147
  tool_calls: "toolUse",
2113
2148
  content_filter: "contentFilter"
2114
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
+ }
2115
2168
  function json2(data) {
2116
2169
  try {
2117
2170
  const v = JSON.parse(data);
@@ -2120,7 +2173,7 @@ function json2(data) {
2120
2173
  return null;
2121
2174
  }
2122
2175
  }
2123
- async function* decodeChat(messages) {
2176
+ async function* decodeCustomChat(messages) {
2124
2177
  let started = false;
2125
2178
  let done = false;
2126
2179
  let stopReason = "endTurn";
@@ -2149,6 +2202,21 @@ async function* decodeChat(messages) {
2149
2202
  if (!choice)
2150
2203
  continue;
2151
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
+ }
2152
2220
  if (typeof delta.content === "string" && delta.content.length > 0) {
2153
2221
  if (openKind !== "text") {
2154
2222
  if (openKind !== undefined)
@@ -2189,7 +2257,7 @@ async function* decodeChat(messages) {
2189
2257
  }
2190
2258
  }
2191
2259
  if (typeof choice.finish_reason === "string") {
2192
- stopReason = FINISH[choice.finish_reason] ?? "endTurn";
2260
+ stopReason = CHAT_FINISH[choice.finish_reason] ?? "endTurn";
2193
2261
  }
2194
2262
  }
2195
2263
  if (done) {
@@ -2205,110 +2273,7 @@ async function* decodeChat(messages) {
2205
2273
  };
2206
2274
  }
2207
2275
  }
2208
-
2209
- // packages/providers/src/kimi/wire.ts
2210
- function encodeToolChoice2(c) {
2211
- switch (c.type) {
2212
- case "auto":
2213
- return "auto";
2214
- case "any":
2215
- return "required";
2216
- case "none":
2217
- return "none";
2218
- case "tool":
2219
- return { type: "function", function: { name: c.name } };
2220
- }
2221
- }
2222
- function toChatWire(req, model, vendor = "kimi") {
2223
- const degradations = [];
2224
- const note2 = (d) => {
2225
- if (!degradations.includes(d))
2226
- degradations.push(d);
2227
- };
2228
- if (req.betas?.includes(CONTEXT_1M_BETA))
2229
- note2("kimi:context-1m-dropped");
2230
- const messages = [];
2231
- const system = req.system?.flatMap((b) => b.type === "text" ? [b.text] : []).join(`
2232
-
2233
- `);
2234
- if (system !== undefined && system.length > 0)
2235
- messages.push({ role: "system", content: system });
2236
- for (const message of req.messages) {
2237
- const text = [];
2238
- const toolCalls = [];
2239
- for (const block of message.content) {
2240
- switch (block.type) {
2241
- case "text":
2242
- text.push(block.text);
2243
- break;
2244
- case "image":
2245
- note2("kimi:images-dropped");
2246
- break;
2247
- case "thinking":
2248
- note2("kimi:thinking-dropped");
2249
- break;
2250
- case "toolUse":
2251
- toolCalls.push({
2252
- id: block.id,
2253
- type: "function",
2254
- function: { name: block.name, arguments: JSON.stringify(block.input) }
2255
- });
2256
- break;
2257
- case "toolResult":
2258
- messages.push({
2259
- role: "tool",
2260
- tool_call_id: block.toolUseId,
2261
- content: block.content
2262
- });
2263
- break;
2264
- case "anthropicNative":
2265
- note2("kimi:anthropic-native-block-dropped");
2266
- break;
2267
- }
2268
- }
2269
- if (toolCalls.length > 0) {
2270
- messages.push({
2271
- role: message.role,
2272
- content: text.length > 0 ? text.join(`
2273
- `) : null,
2274
- tool_calls: toolCalls
2275
- });
2276
- } else if (text.length > 0) {
2277
- messages.push({ role: message.role, content: text.join(`
2278
- `) });
2279
- }
2280
- }
2281
- const body = {
2282
- model,
2283
- messages,
2284
- stream: req.stream,
2285
- stream_options: { include_usage: true }
2286
- };
2287
- if (req.maxTokens !== undefined)
2288
- body.max_tokens = req.maxTokens;
2289
- if (req.temperature !== undefined)
2290
- body.temperature = req.temperature;
2291
- if (req.stopSequences !== undefined)
2292
- body.stop = req.stopSequences;
2293
- if (req.tools !== undefined) {
2294
- const custom = req.tools.filter((t) => t.provider === "custom");
2295
- if (custom.length !== req.tools.length)
2296
- note2("kimi:anthropic-tool-dropped");
2297
- body.tools = custom.map((t) => ({
2298
- type: "function",
2299
- function: { name: t.name, description: t.description, parameters: t.inputSchema }
2300
- }));
2301
- }
2302
- if (req.toolChoice !== undefined)
2303
- body.tool_choice = encodeToolChoice2(req.toolChoice);
2304
- if (req.reasoning !== undefined)
2305
- note2("kimi:reasoning-dropped");
2306
- Object.assign(body, req.vendor?.[vendor] ?? {});
2307
- return { body, degradations };
2308
- }
2309
-
2310
- // packages/providers/src/openai/decode.ts
2311
- var ERROR_CODE = {
2276
+ var RESPONSES_ERROR_CODE = {
2312
2277
  rate_limit_exceeded: "RATE_LIMIT",
2313
2278
  insufficient_quota: "QUOTA_EXHAUSTED",
2314
2279
  invalid_api_key: "AUTH",
@@ -2316,15 +2281,7 @@ var ERROR_CODE = {
2316
2281
  context_length_exceeded: "BAD_REQUEST",
2317
2282
  content_policy_violation: "CONTENT_FILTER"
2318
2283
  };
2319
- function json3(data) {
2320
- try {
2321
- const v = JSON.parse(data);
2322
- return typeof v === "object" && v !== null ? v : null;
2323
- } catch {
2324
- return null;
2325
- }
2326
- }
2327
- async function* decodeResponses(messages) {
2284
+ async function* decodeCustomResponses(messages) {
2328
2285
  const indices = new Map;
2329
2286
  let next = 0;
2330
2287
  const irIndex = (outputIndex, contentIndex = 0) => {
@@ -2340,7 +2297,7 @@ async function* decodeResponses(messages) {
2340
2297
  let terminal = false;
2341
2298
  const ownsBlock = new Set;
2342
2299
  for await (const msg of messages) {
2343
- const d = json3(msg.data);
2300
+ const d = json2(msg.data);
2344
2301
  if (d === null)
2345
2302
  continue;
2346
2303
  switch (msg.event) {
@@ -2432,7 +2389,7 @@ async function* decodeResponses(messages) {
2432
2389
  case "error": {
2433
2390
  terminal = true;
2434
2391
  const err = d.response?.error ?? d.error ?? {};
2435
- const code = ERROR_CODE[String(err.code ?? err.type)] ?? "UPSTREAM";
2392
+ const code = RESPONSES_ERROR_CODE[String(err.code ?? err.type)] ?? "UPSTREAM";
2436
2393
  yield {
2437
2394
  type: "error",
2438
2395
  code,
@@ -2455,8 +2412,20 @@ async function* decodeResponses(messages) {
2455
2412
  }
2456
2413
  }
2457
2414
 
2458
- // packages/providers/src/openai/wire.ts
2459
- 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) {
2460
2429
  switch (c.type) {
2461
2430
  case "auto":
2462
2431
  return "auto";
@@ -2468,20 +2437,115 @@ function encodeToolChoice3(c) {
2468
2437
  return { type: "function", name: c.name };
2469
2438
  }
2470
2439
  }
2471
- 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) {
2472
2446
  const degradations = [];
2473
- const input = [];
2474
2447
  const note2 = (d) => {
2475
2448
  if (!degradations.includes(d))
2476
2449
  degradations.push(d);
2477
2450
  };
2478
2451
  if (req.betas?.includes(CONTEXT_1M_BETA))
2479
- 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");
2480
2544
  for (const message of req.messages) {
2481
2545
  const parts = [];
2482
2546
  const inlined = message.role === "system";
2483
2547
  if (inlined)
2484
- note2("openai:system-turn-inlined");
2548
+ note2("custom:system-turn-inlined");
2485
2549
  const role = inlined ? "user" : message.role;
2486
2550
  const flush = () => {
2487
2551
  if (parts.length === 0)
@@ -2506,9 +2570,7 @@ ${block.text}
2506
2570
  });
2507
2571
  break;
2508
2572
  case "thinking":
2509
- if (!degradations.includes("openai:thinking-dropped")) {
2510
- note2("openai:thinking-dropped");
2511
- }
2573
+ note2("custom:thinking-dropped");
2512
2574
  break;
2513
2575
  case "toolUse":
2514
2576
  flush();
@@ -2528,7 +2590,7 @@ ${block.text}
2528
2590
  });
2529
2591
  break;
2530
2592
  case "anthropicNative":
2531
- note2("openai:anthropic-native-block-dropped");
2593
+ note2("custom:anthropic-native-block-dropped");
2532
2594
  break;
2533
2595
  }
2534
2596
  }
@@ -2540,23 +2602,15 @@ ${block.text}
2540
2602
  `);
2541
2603
  if (instructions !== undefined && instructions.length > 0)
2542
2604
  body.instructions = instructions;
2543
- if (req.maxTokens !== undefined) {
2544
- if (opts.oauth)
2545
- note2("openai:max-tokens-dropped");
2546
- else
2547
- body.max_output_tokens = req.maxTokens;
2548
- }
2549
- if (req.temperature !== undefined) {
2550
- if (opts.oauth)
2551
- note2("openai:temperature-dropped");
2552
- else
2553
- body.temperature = req.temperature;
2554
- }
2605
+ if (req.maxTokens !== undefined)
2606
+ body.max_output_tokens = req.maxTokens;
2607
+ if (req.temperature !== undefined)
2608
+ body.temperature = req.temperature;
2555
2609
  if (req.tools !== undefined) {
2556
- const custom = req.tools.filter((t) => t.provider === "custom");
2557
- if (custom.length !== req.tools.length)
2558
- note2("openai:anthropic-tool-dropped");
2559
- 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) => ({
2560
2614
  type: "function",
2561
2615
  name: t.name,
2562
2616
  description: t.description,
@@ -2564,20 +2618,12 @@ ${block.text}
2564
2618
  }));
2565
2619
  }
2566
2620
  if (req.toolChoice !== undefined)
2567
- body.tool_choice = encodeToolChoice3(req.toolChoice);
2568
- if (req.reasoning !== undefined && req.reasoning.mode !== "off") {
2569
- const effort = req.reasoning.mode === "adaptive" ? req.reasoning.effort ?? "medium" : "medium";
2570
- if (effort === "xhigh" || effort === "max") {
2571
- degradations.push("openai:reasoning-effort-clamped");
2572
- }
2573
- body.reasoning = {
2574
- effort: effort === "xhigh" || effort === "max" ? "high" : effort,
2575
- summary: "auto"
2576
- };
2577
- if (req.reasoning.mode === "budget") {
2578
- degradations.push("openai:reasoning-budget-dropped");
2579
- }
2580
- }
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");
2581
2627
  Object.assign(body, req.vendor?.openai ?? {});
2582
2628
  return { body, degradations };
2583
2629
  }
@@ -2588,7 +2634,13 @@ function metadata(data) {
2588
2634
  if (typeof origin !== "string" || protocol !== "chat_completions" && protocol !== "responses") {
2589
2635
  throw new GatewayError("BAD_REQUEST", "custom credential has invalid endpoint metadata");
2590
2636
  }
2591
- 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}`;
2592
2644
  }
2593
2645
  var customAdapter = {
2594
2646
  id: "custom",
@@ -2598,15 +2650,15 @@ var customAdapter = {
2598
2650
  if (apiKey === null) {
2599
2651
  throw new GatewayError("AUTH", "custom credential has no API key", { provider: "custom" });
2600
2652
  }
2601
- const { origin, protocol } = metadata(req.credentials.providerData);
2602
- 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);
2603
2655
  const headers = [
2604
2656
  ["Content-Type", "application/json"],
2605
2657
  ["Authorization", `Bearer ${apiKey}`]
2606
2658
  ];
2607
2659
  const res = await req.http({
2608
2660
  provider: "custom",
2609
- url: `${origin}/v1/${protocol === "chat_completions" ? "chat/completions" : "responses"}`,
2661
+ url: endpointUrl(origin, basePath, protocol),
2610
2662
  method: "POST",
2611
2663
  headers,
2612
2664
  body: JSON.stringify({ ...encoded.body, stream: true }),
@@ -2618,8 +2670,8 @@ var customAdapter = {
2618
2670
  throw new GatewayError("UPSTREAM", "empty response body", { provider: "custom" });
2619
2671
  }
2620
2672
  return {
2621
- events: protocol === "chat_completions" ? decodeChat(parseSse(res.body)) : decodeResponses(parseSse(res.body)),
2622
- 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
2623
2675
  };
2624
2676
  }
2625
2677
  };
@@ -2638,7 +2690,7 @@ function grokDeviceHeaders(providerData) {
2638
2690
  import { createHash as createHash2 } from "crypto";
2639
2691
 
2640
2692
  // packages/providers/src/grok/decode.ts
2641
- var ERROR_CODE2 = {
2693
+ var ERROR_CODE = {
2642
2694
  rate_limit_exceeded: "RATE_LIMIT",
2643
2695
  insufficient_quota: "QUOTA_EXHAUSTED",
2644
2696
  invalid_api_key: "AUTH",
@@ -2672,7 +2724,7 @@ var KNOWN_EVENTS2 = new Set([
2672
2724
  "response.failed",
2673
2725
  "error"
2674
2726
  ]);
2675
- function json4(data) {
2727
+ function json3(data) {
2676
2728
  try {
2677
2729
  const v = JSON.parse(data);
2678
2730
  return typeof v === "object" && v !== null ? v : null;
@@ -2707,7 +2759,7 @@ async function* decodeGrokResponses(messages) {
2707
2759
  };
2708
2760
  return;
2709
2761
  }
2710
- const d = json4(msg.data);
2762
+ const d = json3(msg.data);
2711
2763
  if (d === null)
2712
2764
  continue;
2713
2765
  switch (msg.event) {
@@ -2800,7 +2852,7 @@ async function* decodeGrokResponses(messages) {
2800
2852
  case "error": {
2801
2853
  terminal = true;
2802
2854
  const err = d.response?.error ?? d.error ?? {};
2803
- const code = ERROR_CODE2[String(err.code ?? err.type)] ?? "UPSTREAM";
2855
+ const code = ERROR_CODE[String(err.code ?? err.type)] ?? "UPSTREAM";
2804
2856
  yield {
2805
2857
  type: "error",
2806
2858
  code,
@@ -2826,7 +2878,7 @@ async function* decodeGrokResponses(messages) {
2826
2878
  // packages/providers/src/grok/wire.ts
2827
2879
  import { createHash } from "crypto";
2828
2880
  var MAX_TOOLS = 200;
2829
- function encodeToolChoice4(c) {
2881
+ function encodeToolChoice2(c) {
2830
2882
  switch (c.type) {
2831
2883
  case "auto":
2832
2884
  return "auto";
@@ -2937,12 +2989,14 @@ ${block.text}
2937
2989
  }));
2938
2990
  }
2939
2991
  if (req.toolChoice !== undefined)
2940
- body.tool_choice = encodeToolChoice4(req.toolChoice);
2992
+ body.tool_choice = encodeToolChoice2(req.toolChoice);
2941
2993
  if (req.reasoning !== undefined && req.reasoning.mode !== "off") {
2942
- const effort = req.reasoning.mode === "adaptive" ? req.reasoning.effort ?? "medium" : "medium";
2943
- body.reasoning = { effort, summary: "concise" };
2944
- if (req.reasoning.mode === "budget")
2994
+ if (req.reasoning.mode === "budget") {
2945
2995
  note2("grok:reasoning-budget-dropped");
2996
+ } else {
2997
+ const effort = req.reasoning.effort ?? "medium";
2998
+ body.reasoning = { effort, summary: "concise" };
2999
+ }
2946
3000
  }
2947
3001
  Object.assign(body, req.vendor?.grok ?? {});
2948
3002
  return { body, degradations };
@@ -3100,13 +3154,13 @@ function hasHeader(req, lowerName) {
3100
3154
  return req.headers.some(([name]) => name.toLowerCase() === lowerName);
3101
3155
  }
3102
3156
  // packages/providers/src/kilo/decode.ts
3103
- var FINISH2 = {
3157
+ var FINISH = {
3104
3158
  stop: "endTurn",
3105
3159
  length: "maxTokens",
3106
3160
  tool_calls: "toolUse",
3107
3161
  content_filter: "contentFilter"
3108
3162
  };
3109
- function reasoningText(delta) {
3163
+ function reasoningText2(delta) {
3110
3164
  if (typeof delta.reasoning === "string" && delta.reasoning.length > 0)
3111
3165
  return delta.reasoning;
3112
3166
  if (typeof delta.reasoning_content === "string" && delta.reasoning_content.length > 0) {
@@ -3124,7 +3178,7 @@ function reasoningText(delta) {
3124
3178
  return [];
3125
3179
  }).join("");
3126
3180
  }
3127
- function json5(data) {
3181
+ function json4(data) {
3128
3182
  try {
3129
3183
  const v = JSON.parse(data);
3130
3184
  return typeof v === "object" && v !== null ? v : null;
@@ -3146,7 +3200,7 @@ async function* decodeKiloChat(messages) {
3146
3200
  done = true;
3147
3201
  break;
3148
3202
  }
3149
- const d = json5(msg.data);
3203
+ const d = json4(msg.data);
3150
3204
  if (d === null)
3151
3205
  continue;
3152
3206
  if (!started && (d.id !== undefined || d.model !== undefined)) {
@@ -3161,7 +3215,7 @@ async function* decodeKiloChat(messages) {
3161
3215
  if (!choice)
3162
3216
  continue;
3163
3217
  const delta = choice.delta ?? {};
3164
- const reasoning = reasoningText(delta);
3218
+ const reasoning = reasoningText2(delta);
3165
3219
  if (reasoning.length > 0) {
3166
3220
  if (openKind !== "thinking") {
3167
3221
  if (openKind !== undefined)
@@ -3217,7 +3271,7 @@ async function* decodeKiloChat(messages) {
3217
3271
  }
3218
3272
  }
3219
3273
  if (typeof choice.finish_reason === "string") {
3220
- stopReason = FINISH2[choice.finish_reason] ?? "endTurn";
3274
+ stopReason = FINISH[choice.finish_reason] ?? "endTurn";
3221
3275
  }
3222
3276
  }
3223
3277
  if (done) {
@@ -3235,7 +3289,7 @@ async function* decodeKiloChat(messages) {
3235
3289
  }
3236
3290
 
3237
3291
  // packages/providers/src/kilo/wire.ts
3238
- function encodeToolChoice5(c) {
3292
+ function encodeToolChoice3(c) {
3239
3293
  switch (c.type) {
3240
3294
  case "auto":
3241
3295
  return "auto";
@@ -3348,15 +3402,12 @@ function toKiloWire(req, model) {
3348
3402
  }));
3349
3403
  }
3350
3404
  if (req.toolChoice !== undefined)
3351
- body.tool_choice = encodeToolChoice5(req.toolChoice);
3405
+ body.tool_choice = encodeToolChoice3(req.toolChoice);
3352
3406
  if (req.reasoning !== undefined && req.reasoning.mode !== "off") {
3353
3407
  if (req.reasoning.mode === "budget") {
3354
3408
  body.reasoning = { max_tokens: req.reasoning.budgetTokens };
3355
3409
  } else {
3356
- const effort = req.reasoning.effort ?? "medium";
3357
- if (effort === "xhigh" || effort === "max")
3358
- note2("kilo:reasoning-effort-clamped");
3359
- body.reasoning = { effort: effort === "xhigh" || effort === "max" ? "high" : effort };
3410
+ body.reasoning = { effort: req.reasoning.effort ?? "medium" };
3360
3411
  }
3361
3412
  }
3362
3413
  Object.assign(body, req.vendor?.kilo ?? {});
@@ -3426,40 +3477,512 @@ function kimiDeviceHeaders(providerData) {
3426
3477
  ["X-Msh-Os-Version", str(providerData.osVersion)]
3427
3478
  ];
3428
3479
  }
3429
- // packages/providers/src/kimi/index.ts
3430
- var BASE_URL2 = "https://api.kimi.com/coding/v1/chat/completions";
3431
- var kimiAdapter = {
3432
- id: "kimi",
3433
- capabilities: PROVIDER_CAPABILITIES.kimi,
3434
- async send(req) {
3435
- const { body, degradations } = toChatWire(req.request, req.model);
3436
- const token = req.credentials.accessToken ?? req.credentials.apiKey;
3437
- if (token === null) {
3438
- 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";
3439
3565
  }
3440
- const protocol = [
3441
- ["Content-Type", "application/json"],
3442
- ["Accept", "text/event-stream"],
3443
- ["Authorization", `Bearer ${token}`],
3444
- ...kimiDeviceHeaders(req.credentials.providerData)
3445
- ];
3446
- const profile = PROFILES.kimi;
3447
- const headers = orderHeaders(mergeHeaders(profile.headers, protocol), profile.order);
3448
- const res = await req.http({
3449
- provider: "kimi",
3450
- url: BASE_URL2,
3451
- method: "POST",
3452
- headers,
3453
- body: JSON.stringify(orderFields({ ...body, stream: true }, BODY_ORDER.kimi)),
3454
- signal: req.signal
3455
- });
3456
- if (res.status < 200 || res.status >= 300)
3457
- throw await httpError(res, "kimi");
3458
- if (res.body === null)
3459
- throw new GatewayError("UPSTREAM", "empty response body", { provider: "kimi" });
3460
- return { events: decodeChat(parseSse(res.body)), degradations };
3461
3566
  }
3462
- };
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
+
3463
3986
  // packages/providers/src/openai/index.ts
3464
3987
  var OAUTH_URL2 = "https://chatgpt.com/backend-api/codex/responses";
3465
3988
  var API_URL3 = "https://api.openai.com/v1/responses";
@@ -3862,7 +4385,7 @@ __export(exports_external, {
3862
4385
  ipv4: () => ipv42,
3863
4386
  ipv6: () => ipv62,
3864
4387
  iso: () => exports_iso,
3865
- json: () => json6,
4388
+ json: () => json7,
3866
4389
  jwt: () => jwt,
3867
4390
  keyof: () => keyof,
3868
4391
  ksuid: () => ksuid2,
@@ -15303,29 +15826,29 @@ var formatMap = {
15303
15826
  regex: ""
15304
15827
  };
15305
15828
  var stringProcessor = (schema, ctx, _json, _params) => {
15306
- const json6 = _json;
15307
- json6.type = "string";
15829
+ const json7 = _json;
15830
+ json7.type = "string";
15308
15831
  const { minimum, maximum, format, patterns, contentEncoding } = schema._zod.bag;
15309
15832
  if (typeof minimum === "number")
15310
- json6.minLength = minimum;
15833
+ json7.minLength = minimum;
15311
15834
  if (typeof maximum === "number")
15312
- json6.maxLength = maximum;
15835
+ json7.maxLength = maximum;
15313
15836
  if (format) {
15314
- json6.format = formatMap[format] ?? format;
15315
- if (json6.format === "")
15316
- delete json6.format;
15837
+ json7.format = formatMap[format] ?? format;
15838
+ if (json7.format === "")
15839
+ delete json7.format;
15317
15840
  if (format === "time") {
15318
- delete json6.format;
15841
+ delete json7.format;
15319
15842
  }
15320
15843
  }
15321
15844
  if (contentEncoding)
15322
- json6.contentEncoding = contentEncoding;
15845
+ json7.contentEncoding = contentEncoding;
15323
15846
  if (patterns && patterns.size > 0) {
15324
15847
  const regexes = [...patterns];
15325
15848
  if (regexes.length === 1)
15326
- json6.pattern = regexes[0].source;
15849
+ json7.pattern = regexes[0].source;
15327
15850
  else if (regexes.length > 1) {
15328
- json6.allOf = [
15851
+ json7.allOf = [
15329
15852
  ...regexes.map((regex) => ({
15330
15853
  ...ctx.target === "draft-07" || ctx.target === "draft-04" || ctx.target === "openapi-3.0" ? { type: "string" } : {},
15331
15854
  pattern: regex.source
@@ -15335,40 +15858,40 @@ var stringProcessor = (schema, ctx, _json, _params) => {
15335
15858
  }
15336
15859
  };
15337
15860
  var numberProcessor = (schema, ctx, _json, _params) => {
15338
- const json6 = _json;
15861
+ const json7 = _json;
15339
15862
  const { minimum, maximum, format, multipleOf, exclusiveMaximum, exclusiveMinimum } = schema._zod.bag;
15340
15863
  if (typeof format === "string" && format.includes("int"))
15341
- json6.type = "integer";
15864
+ json7.type = "integer";
15342
15865
  else
15343
- json6.type = "number";
15866
+ json7.type = "number";
15344
15867
  const exMin = typeof exclusiveMinimum === "number" && exclusiveMinimum >= (minimum ?? Number.NEGATIVE_INFINITY);
15345
15868
  const exMax = typeof exclusiveMaximum === "number" && exclusiveMaximum <= (maximum ?? Number.POSITIVE_INFINITY);
15346
15869
  const legacy = ctx.target === "draft-04" || ctx.target === "openapi-3.0";
15347
15870
  if (exMin) {
15348
15871
  if (legacy) {
15349
- json6.minimum = exclusiveMinimum;
15350
- json6.exclusiveMinimum = true;
15872
+ json7.minimum = exclusiveMinimum;
15873
+ json7.exclusiveMinimum = true;
15351
15874
  } else {
15352
- json6.exclusiveMinimum = exclusiveMinimum;
15875
+ json7.exclusiveMinimum = exclusiveMinimum;
15353
15876
  }
15354
15877
  } else if (typeof minimum === "number") {
15355
- json6.minimum = minimum;
15878
+ json7.minimum = minimum;
15356
15879
  }
15357
15880
  if (exMax) {
15358
15881
  if (legacy) {
15359
- json6.maximum = exclusiveMaximum;
15360
- json6.exclusiveMaximum = true;
15882
+ json7.maximum = exclusiveMaximum;
15883
+ json7.exclusiveMaximum = true;
15361
15884
  } else {
15362
- json6.exclusiveMaximum = exclusiveMaximum;
15885
+ json7.exclusiveMaximum = exclusiveMaximum;
15363
15886
  }
15364
15887
  } else if (typeof maximum === "number") {
15365
- json6.maximum = maximum;
15888
+ json7.maximum = maximum;
15366
15889
  }
15367
15890
  if (typeof multipleOf === "number")
15368
- json6.multipleOf = multipleOf;
15891
+ json7.multipleOf = multipleOf;
15369
15892
  };
15370
- var booleanProcessor = (_schema, _ctx, json6, _params) => {
15371
- json6.type = "boolean";
15893
+ var booleanProcessor = (_schema, _ctx, json7, _params) => {
15894
+ json7.type = "boolean";
15372
15895
  };
15373
15896
  var bigintProcessor = (_schema, ctx, _json, _params) => {
15374
15897
  if (ctx.unrepresentable === "throw") {
@@ -15380,13 +15903,13 @@ var symbolProcessor = (_schema, ctx, _json, _params) => {
15380
15903
  throw new Error("Symbols cannot be represented in JSON Schema");
15381
15904
  }
15382
15905
  };
15383
- var nullProcessor = (_schema, ctx, json6, _params) => {
15906
+ var nullProcessor = (_schema, ctx, json7, _params) => {
15384
15907
  if (ctx.target === "openapi-3.0") {
15385
- json6.type = "string";
15386
- json6.nullable = true;
15387
- json6.enum = [null];
15908
+ json7.type = "string";
15909
+ json7.nullable = true;
15910
+ json7.enum = [null];
15388
15911
  } else {
15389
- json6.type = "null";
15912
+ json7.type = "null";
15390
15913
  }
15391
15914
  };
15392
15915
  var undefinedProcessor = (_schema, ctx, _json, _params) => {
@@ -15399,8 +15922,8 @@ var voidProcessor = (_schema, ctx, _json, _params) => {
15399
15922
  throw new Error("Void cannot be represented in JSON Schema");
15400
15923
  }
15401
15924
  };
15402
- var neverProcessor = (_schema, _ctx, json6, _params) => {
15403
- json6.not = {};
15925
+ var neverProcessor = (_schema, _ctx, json7, _params) => {
15926
+ json7.not = {};
15404
15927
  };
15405
15928
  var anyProcessor = (_schema, _ctx, _json, _params) => {};
15406
15929
  var unknownProcessor = (_schema, _ctx, _json, _params) => {};
@@ -15409,16 +15932,16 @@ var dateProcessor = (_schema, ctx, _json, _params) => {
15409
15932
  throw new Error("Date cannot be represented in JSON Schema");
15410
15933
  }
15411
15934
  };
15412
- var enumProcessor = (schema, _ctx, json6, _params) => {
15935
+ var enumProcessor = (schema, _ctx, json7, _params) => {
15413
15936
  const def = schema._zod.def;
15414
15937
  const values = getEnumValues(def.entries);
15415
15938
  if (values.every((v) => typeof v === "number"))
15416
- json6.type = "number";
15939
+ json7.type = "number";
15417
15940
  if (values.every((v) => typeof v === "string"))
15418
- json6.type = "string";
15419
- json6.enum = values;
15941
+ json7.type = "string";
15942
+ json7.enum = values;
15420
15943
  };
15421
- var literalProcessor = (schema, ctx, json6, _params) => {
15944
+ var literalProcessor = (schema, ctx, json7, _params) => {
15422
15945
  const def = schema._zod.def;
15423
15946
  const vals = [];
15424
15947
  for (const val of def.values) {
@@ -15438,22 +15961,22 @@ var literalProcessor = (schema, ctx, json6, _params) => {
15438
15961
  }
15439
15962
  if (vals.length === 0) {} else if (vals.length === 1) {
15440
15963
  const val = vals[0];
15441
- json6.type = val === null ? "null" : typeof val;
15964
+ json7.type = val === null ? "null" : typeof val;
15442
15965
  if (ctx.target === "draft-04" || ctx.target === "openapi-3.0") {
15443
- json6.enum = [val];
15966
+ json7.enum = [val];
15444
15967
  } else {
15445
- json6.const = val;
15968
+ json7.const = val;
15446
15969
  }
15447
15970
  } else {
15448
15971
  if (vals.every((v) => typeof v === "number"))
15449
- json6.type = "number";
15972
+ json7.type = "number";
15450
15973
  if (vals.every((v) => typeof v === "string"))
15451
- json6.type = "string";
15974
+ json7.type = "string";
15452
15975
  if (vals.every((v) => typeof v === "boolean"))
15453
- json6.type = "boolean";
15976
+ json7.type = "boolean";
15454
15977
  if (vals.every((v) => v === null))
15455
- json6.type = "null";
15456
- json6.enum = vals;
15978
+ json7.type = "null";
15979
+ json7.enum = vals;
15457
15980
  }
15458
15981
  };
15459
15982
  var nanProcessor = (_schema, ctx, _json, _params) => {
@@ -15461,16 +15984,16 @@ var nanProcessor = (_schema, ctx, _json, _params) => {
15461
15984
  throw new Error("NaN cannot be represented in JSON Schema");
15462
15985
  }
15463
15986
  };
15464
- var templateLiteralProcessor = (schema, _ctx, json6, _params) => {
15465
- const _json = json6;
15987
+ var templateLiteralProcessor = (schema, _ctx, json7, _params) => {
15988
+ const _json = json7;
15466
15989
  const pattern = schema._zod.pattern;
15467
15990
  if (!pattern)
15468
15991
  throw new Error("Pattern not found in template literal");
15469
15992
  _json.type = "string";
15470
15993
  _json.pattern = pattern.source;
15471
15994
  };
15472
- var fileProcessor = (schema, _ctx, json6, _params) => {
15473
- const _json = json6;
15995
+ var fileProcessor = (schema, _ctx, json7, _params) => {
15996
+ const _json = json7;
15474
15997
  const file = {
15475
15998
  type: "string",
15476
15999
  format: "binary",
@@ -15493,8 +16016,8 @@ var fileProcessor = (schema, _ctx, json6, _params) => {
15493
16016
  Object.assign(_json, file);
15494
16017
  }
15495
16018
  };
15496
- var successProcessor = (_schema, _ctx, json6, _params) => {
15497
- json6.type = "boolean";
16019
+ var successProcessor = (_schema, _ctx, json7, _params) => {
16020
+ json7.type = "boolean";
15498
16021
  };
15499
16022
  var customProcessor = (_schema, ctx, _json, _params) => {
15500
16023
  if (ctx.unrepresentable === "throw") {
@@ -15522,27 +16045,27 @@ var setProcessor = (_schema, ctx, _json, _params) => {
15522
16045
  }
15523
16046
  };
15524
16047
  var arrayProcessor = (schema, ctx, _json, params) => {
15525
- const json6 = _json;
16048
+ const json7 = _json;
15526
16049
  const def = schema._zod.def;
15527
16050
  const { minimum, maximum } = schema._zod.bag;
15528
16051
  if (typeof minimum === "number")
15529
- json6.minItems = minimum;
16052
+ json7.minItems = minimum;
15530
16053
  if (typeof maximum === "number")
15531
- json6.maxItems = maximum;
15532
- json6.type = "array";
15533
- json6.items = process2(def.element, ctx, {
16054
+ json7.maxItems = maximum;
16055
+ json7.type = "array";
16056
+ json7.items = process2(def.element, ctx, {
15534
16057
  ...params,
15535
16058
  path: [...params.path, "items"]
15536
16059
  });
15537
16060
  };
15538
16061
  var objectProcessor = (schema, ctx, _json, params) => {
15539
- const json6 = _json;
16062
+ const json7 = _json;
15540
16063
  const def = schema._zod.def;
15541
- json6.type = "object";
15542
- json6.properties = {};
16064
+ json7.type = "object";
16065
+ json7.properties = {};
15543
16066
  const shape = def.shape;
15544
16067
  for (const key in shape) {
15545
- json6.properties[key] = process2(shape[key], ctx, {
16068
+ json7.properties[key] = process2(shape[key], ctx, {
15546
16069
  ...params,
15547
16070
  path: [...params.path, "properties", key]
15548
16071
  });
@@ -15557,21 +16080,21 @@ var objectProcessor = (schema, ctx, _json, params) => {
15557
16080
  }
15558
16081
  }));
15559
16082
  if (requiredKeys.size > 0) {
15560
- json6.required = Array.from(requiredKeys);
16083
+ json7.required = Array.from(requiredKeys);
15561
16084
  }
15562
16085
  if (def.catchall?._zod.def.type === "never") {
15563
- json6.additionalProperties = false;
16086
+ json7.additionalProperties = false;
15564
16087
  } else if (!def.catchall) {
15565
16088
  if (ctx.io === "output")
15566
- json6.additionalProperties = false;
16089
+ json7.additionalProperties = false;
15567
16090
  } else if (def.catchall) {
15568
- json6.additionalProperties = process2(def.catchall, ctx, {
16091
+ json7.additionalProperties = process2(def.catchall, ctx, {
15569
16092
  ...params,
15570
16093
  path: [...params.path, "additionalProperties"]
15571
16094
  });
15572
16095
  }
15573
16096
  };
15574
- var unionProcessor = (schema, ctx, json6, params) => {
16097
+ var unionProcessor = (schema, ctx, json7, params) => {
15575
16098
  const def = schema._zod.def;
15576
16099
  const isExclusive = def.inclusive === false;
15577
16100
  const options = def.options.map((x, i) => process2(x, ctx, {
@@ -15579,12 +16102,12 @@ var unionProcessor = (schema, ctx, json6, params) => {
15579
16102
  path: [...params.path, isExclusive ? "oneOf" : "anyOf", i]
15580
16103
  }));
15581
16104
  if (isExclusive) {
15582
- json6.oneOf = options;
16105
+ json7.oneOf = options;
15583
16106
  } else {
15584
- json6.anyOf = options;
16107
+ json7.anyOf = options;
15585
16108
  }
15586
16109
  };
15587
- var intersectionProcessor = (schema, ctx, json6, params) => {
16110
+ var intersectionProcessor = (schema, ctx, json7, params) => {
15588
16111
  const def = schema._zod.def;
15589
16112
  const a = process2(def.left, ctx, {
15590
16113
  ...params,
@@ -15599,12 +16122,12 @@ var intersectionProcessor = (schema, ctx, json6, params) => {
15599
16122
  ...isSimpleIntersection(a) ? a.allOf : [a],
15600
16123
  ...isSimpleIntersection(b) ? b.allOf : [b]
15601
16124
  ];
15602
- json6.allOf = allOf;
16125
+ json7.allOf = allOf;
15603
16126
  };
15604
16127
  var tupleProcessor = (schema, ctx, _json, params) => {
15605
- const json6 = _json;
16128
+ const json7 = _json;
15606
16129
  const def = schema._zod.def;
15607
- json6.type = "array";
16130
+ json7.type = "array";
15608
16131
  const prefixPath = ctx.target === "draft-2020-12" ? "prefixItems" : "items";
15609
16132
  const restPath = ctx.target === "draft-2020-12" ? "items" : ctx.target === "openapi-3.0" ? "items" : "additionalItems";
15610
16133
  const prefixItems = def.items.map((x, i) => process2(x, ctx, {
@@ -15616,37 +16139,37 @@ var tupleProcessor = (schema, ctx, _json, params) => {
15616
16139
  path: [...params.path, restPath, ...ctx.target === "openapi-3.0" ? [def.items.length] : []]
15617
16140
  }) : null;
15618
16141
  if (ctx.target === "draft-2020-12") {
15619
- json6.prefixItems = prefixItems;
16142
+ json7.prefixItems = prefixItems;
15620
16143
  if (rest) {
15621
- json6.items = rest;
16144
+ json7.items = rest;
15622
16145
  }
15623
16146
  } else if (ctx.target === "openapi-3.0") {
15624
- json6.items = {
16147
+ json7.items = {
15625
16148
  anyOf: prefixItems
15626
16149
  };
15627
16150
  if (rest) {
15628
- json6.items.anyOf.push(rest);
16151
+ json7.items.anyOf.push(rest);
15629
16152
  }
15630
- json6.minItems = prefixItems.length;
16153
+ json7.minItems = prefixItems.length;
15631
16154
  if (!rest) {
15632
- json6.maxItems = prefixItems.length;
16155
+ json7.maxItems = prefixItems.length;
15633
16156
  }
15634
16157
  } else {
15635
- json6.items = prefixItems;
16158
+ json7.items = prefixItems;
15636
16159
  if (rest) {
15637
- json6.additionalItems = rest;
16160
+ json7.additionalItems = rest;
15638
16161
  }
15639
16162
  }
15640
16163
  const { minimum, maximum } = schema._zod.bag;
15641
16164
  if (typeof minimum === "number")
15642
- json6.minItems = minimum;
16165
+ json7.minItems = minimum;
15643
16166
  if (typeof maximum === "number")
15644
- json6.maxItems = maximum;
16167
+ json7.maxItems = maximum;
15645
16168
  };
15646
16169
  var recordProcessor = (schema, ctx, _json, params) => {
15647
- const json6 = _json;
16170
+ const json7 = _json;
15648
16171
  const def = schema._zod.def;
15649
- json6.type = "object";
16172
+ json7.type = "object";
15650
16173
  const keyType = def.keyType;
15651
16174
  const keyBag = keyType._zod.bag;
15652
16175
  const patterns = keyBag?.patterns;
@@ -15655,18 +16178,18 @@ var recordProcessor = (schema, ctx, _json, params) => {
15655
16178
  ...params,
15656
16179
  path: [...params.path, "patternProperties", "*"]
15657
16180
  });
15658
- json6.patternProperties = {};
16181
+ json7.patternProperties = {};
15659
16182
  for (const pattern of patterns) {
15660
- json6.patternProperties[pattern.source] = valueSchema;
16183
+ json7.patternProperties[pattern.source] = valueSchema;
15661
16184
  }
15662
16185
  } else {
15663
16186
  if (ctx.target === "draft-07" || ctx.target === "draft-2020-12") {
15664
- json6.propertyNames = process2(def.keyType, ctx, {
16187
+ json7.propertyNames = process2(def.keyType, ctx, {
15665
16188
  ...params,
15666
16189
  path: [...params.path, "propertyNames"]
15667
16190
  });
15668
16191
  }
15669
- json6.additionalProperties = process2(def.valueType, ctx, {
16192
+ json7.additionalProperties = process2(def.valueType, ctx, {
15670
16193
  ...params,
15671
16194
  path: [...params.path, "additionalProperties"]
15672
16195
  });
@@ -15675,19 +16198,19 @@ var recordProcessor = (schema, ctx, _json, params) => {
15675
16198
  if (keyValues) {
15676
16199
  const validKeyValues = [...keyValues].filter((v) => typeof v === "string" || typeof v === "number");
15677
16200
  if (validKeyValues.length > 0) {
15678
- json6.required = validKeyValues;
16201
+ json7.required = validKeyValues;
15679
16202
  }
15680
16203
  }
15681
16204
  };
15682
- var nullableProcessor = (schema, ctx, json6, params) => {
16205
+ var nullableProcessor = (schema, ctx, json7, params) => {
15683
16206
  const def = schema._zod.def;
15684
16207
  const inner = process2(def.innerType, ctx, params);
15685
16208
  const seen = ctx.seen.get(schema);
15686
16209
  if (ctx.target === "openapi-3.0") {
15687
16210
  seen.ref = def.innerType;
15688
- json6.nullable = true;
16211
+ json7.nullable = true;
15689
16212
  } else {
15690
- json6.anyOf = [inner, { type: "null" }];
16213
+ json7.anyOf = [inner, { type: "null" }];
15691
16214
  }
15692
16215
  };
15693
16216
  var nonoptionalProcessor = (schema, ctx, _json, params) => {
@@ -15696,22 +16219,22 @@ var nonoptionalProcessor = (schema, ctx, _json, params) => {
15696
16219
  const seen = ctx.seen.get(schema);
15697
16220
  seen.ref = def.innerType;
15698
16221
  };
15699
- var defaultProcessor = (schema, ctx, json6, params) => {
16222
+ var defaultProcessor = (schema, ctx, json7, params) => {
15700
16223
  const def = schema._zod.def;
15701
16224
  process2(def.innerType, ctx, params);
15702
16225
  const seen = ctx.seen.get(schema);
15703
16226
  seen.ref = def.innerType;
15704
- json6.default = JSON.parse(JSON.stringify(def.defaultValue));
16227
+ json7.default = JSON.parse(JSON.stringify(def.defaultValue));
15705
16228
  };
15706
- var prefaultProcessor = (schema, ctx, json6, params) => {
16229
+ var prefaultProcessor = (schema, ctx, json7, params) => {
15707
16230
  const def = schema._zod.def;
15708
16231
  process2(def.innerType, ctx, params);
15709
16232
  const seen = ctx.seen.get(schema);
15710
16233
  seen.ref = def.innerType;
15711
16234
  if (ctx.io === "input")
15712
- json6._prefault = JSON.parse(JSON.stringify(def.defaultValue));
16235
+ json7._prefault = JSON.parse(JSON.stringify(def.defaultValue));
15713
16236
  };
15714
- var catchProcessor = (schema, ctx, json6, params) => {
16237
+ var catchProcessor = (schema, ctx, json7, params) => {
15715
16238
  const def = schema._zod.def;
15716
16239
  process2(def.innerType, ctx, params);
15717
16240
  const seen = ctx.seen.get(schema);
@@ -15722,7 +16245,7 @@ var catchProcessor = (schema, ctx, json6, params) => {
15722
16245
  } catch {
15723
16246
  throw new Error("Dynamic catch values are not supported in JSON Schema");
15724
16247
  }
15725
- json6.default = catchValue;
16248
+ json7.default = catchValue;
15726
16249
  };
15727
16250
  var pipeProcessor = (schema, ctx, _json, params) => {
15728
16251
  const def = schema._zod.def;
@@ -15732,12 +16255,12 @@ var pipeProcessor = (schema, ctx, _json, params) => {
15732
16255
  const seen = ctx.seen.get(schema);
15733
16256
  seen.ref = innerType;
15734
16257
  };
15735
- var readonlyProcessor = (schema, ctx, json6, params) => {
16258
+ var readonlyProcessor = (schema, ctx, json7, params) => {
15736
16259
  const def = schema._zod.def;
15737
16260
  process2(def.innerType, ctx, params);
15738
16261
  const seen = ctx.seen.get(schema);
15739
16262
  seen.ref = def.innerType;
15740
- json6.readOnly = true;
16263
+ json7.readOnly = true;
15741
16264
  };
15742
16265
  var promiseProcessor = (schema, ctx, _json, params) => {
15743
16266
  const def = schema._zod.def;
@@ -16007,7 +16530,7 @@ __export(exports_schemas2, {
16007
16530
  invertCodec: () => invertCodec,
16008
16531
  ipv4: () => ipv42,
16009
16532
  ipv6: () => ipv62,
16010
- json: () => json6,
16533
+ json: () => json7,
16011
16534
  jwt: () => jwt,
16012
16535
  keyof: () => keyof,
16013
16536
  ksuid: () => ksuid2,
@@ -16358,7 +16881,7 @@ var ZodType = /* @__PURE__ */ $constructor("ZodType", (inst, def) => {
16358
16881
  var _ZodString = /* @__PURE__ */ $constructor("_ZodString", (inst, def) => {
16359
16882
  $ZodString.init(inst, def);
16360
16883
  ZodType.init(inst, def);
16361
- inst._zod.processJSONSchema = (ctx, json6, params) => stringProcessor(inst, ctx, json6, params);
16884
+ inst._zod.processJSONSchema = (ctx, json7, params) => stringProcessor(inst, ctx, json7, params);
16362
16885
  const bag = inst._zod.bag;
16363
16886
  inst.format = bag.format ?? null;
16364
16887
  inst.minLength = bag.minimum ?? null;
@@ -16629,7 +17152,7 @@ function hash2(alg, params) {
16629
17152
  var ZodNumber = /* @__PURE__ */ $constructor("ZodNumber", (inst, def) => {
16630
17153
  $ZodNumber.init(inst, def);
16631
17154
  ZodType.init(inst, def);
16632
- inst._zod.processJSONSchema = (ctx, json6, params) => numberProcessor(inst, ctx, json6, params);
17155
+ inst._zod.processJSONSchema = (ctx, json7, params) => numberProcessor(inst, ctx, json7, params);
16633
17156
  _installLazyMethods(inst, "ZodNumber", {
16634
17157
  gt(value, params) {
16635
17158
  return this.check(_gt(value, params));
@@ -16709,7 +17232,7 @@ function uint32(params) {
16709
17232
  var ZodBoolean = /* @__PURE__ */ $constructor("ZodBoolean", (inst, def) => {
16710
17233
  $ZodBoolean.init(inst, def);
16711
17234
  ZodType.init(inst, def);
16712
- inst._zod.processJSONSchema = (ctx, json6, params) => booleanProcessor(inst, ctx, json6, params);
17235
+ inst._zod.processJSONSchema = (ctx, json7, params) => booleanProcessor(inst, ctx, json7, params);
16713
17236
  });
16714
17237
  function boolean2(params) {
16715
17238
  return _boolean(ZodBoolean, params);
@@ -16717,7 +17240,7 @@ function boolean2(params) {
16717
17240
  var ZodBigInt = /* @__PURE__ */ $constructor("ZodBigInt", (inst, def) => {
16718
17241
  $ZodBigInt.init(inst, def);
16719
17242
  ZodType.init(inst, def);
16720
- inst._zod.processJSONSchema = (ctx, json6, params) => bigintProcessor(inst, ctx, json6, params);
17243
+ inst._zod.processJSONSchema = (ctx, json7, params) => bigintProcessor(inst, ctx, json7, params);
16721
17244
  inst.gte = (value, params) => inst.check(_gte(value, params));
16722
17245
  inst.min = (value, params) => inst.check(_gte(value, params));
16723
17246
  inst.gt = (value, params) => inst.check(_gt(value, params));
@@ -16752,7 +17275,7 @@ function uint64(params) {
16752
17275
  var ZodSymbol = /* @__PURE__ */ $constructor("ZodSymbol", (inst, def) => {
16753
17276
  $ZodSymbol.init(inst, def);
16754
17277
  ZodType.init(inst, def);
16755
- inst._zod.processJSONSchema = (ctx, json6, params) => symbolProcessor(inst, ctx, json6, params);
17278
+ inst._zod.processJSONSchema = (ctx, json7, params) => symbolProcessor(inst, ctx, json7, params);
16756
17279
  });
16757
17280
  function symbol(params) {
16758
17281
  return _symbol(ZodSymbol, params);
@@ -16760,7 +17283,7 @@ function symbol(params) {
16760
17283
  var ZodUndefined = /* @__PURE__ */ $constructor("ZodUndefined", (inst, def) => {
16761
17284
  $ZodUndefined.init(inst, def);
16762
17285
  ZodType.init(inst, def);
16763
- inst._zod.processJSONSchema = (ctx, json6, params) => undefinedProcessor(inst, ctx, json6, params);
17286
+ inst._zod.processJSONSchema = (ctx, json7, params) => undefinedProcessor(inst, ctx, json7, params);
16764
17287
  });
16765
17288
  function _undefined3(params) {
16766
17289
  return _undefined2(ZodUndefined, params);
@@ -16768,7 +17291,7 @@ function _undefined3(params) {
16768
17291
  var ZodNull = /* @__PURE__ */ $constructor("ZodNull", (inst, def) => {
16769
17292
  $ZodNull.init(inst, def);
16770
17293
  ZodType.init(inst, def);
16771
- inst._zod.processJSONSchema = (ctx, json6, params) => nullProcessor(inst, ctx, json6, params);
17294
+ inst._zod.processJSONSchema = (ctx, json7, params) => nullProcessor(inst, ctx, json7, params);
16772
17295
  });
16773
17296
  function _null3(params) {
16774
17297
  return _null2(ZodNull, params);
@@ -16776,7 +17299,7 @@ function _null3(params) {
16776
17299
  var ZodAny = /* @__PURE__ */ $constructor("ZodAny", (inst, def) => {
16777
17300
  $ZodAny.init(inst, def);
16778
17301
  ZodType.init(inst, def);
16779
- inst._zod.processJSONSchema = (ctx, json6, params) => anyProcessor(inst, ctx, json6, params);
17302
+ inst._zod.processJSONSchema = (ctx, json7, params) => anyProcessor(inst, ctx, json7, params);
16780
17303
  });
16781
17304
  function any() {
16782
17305
  return _any(ZodAny);
@@ -16784,7 +17307,7 @@ function any() {
16784
17307
  var ZodUnknown = /* @__PURE__ */ $constructor("ZodUnknown", (inst, def) => {
16785
17308
  $ZodUnknown.init(inst, def);
16786
17309
  ZodType.init(inst, def);
16787
- inst._zod.processJSONSchema = (ctx, json6, params) => unknownProcessor(inst, ctx, json6, params);
17310
+ inst._zod.processJSONSchema = (ctx, json7, params) => unknownProcessor(inst, ctx, json7, params);
16788
17311
  });
16789
17312
  function unknown() {
16790
17313
  return _unknown(ZodUnknown);
@@ -16792,7 +17315,7 @@ function unknown() {
16792
17315
  var ZodNever = /* @__PURE__ */ $constructor("ZodNever", (inst, def) => {
16793
17316
  $ZodNever.init(inst, def);
16794
17317
  ZodType.init(inst, def);
16795
- inst._zod.processJSONSchema = (ctx, json6, params) => neverProcessor(inst, ctx, json6, params);
17318
+ inst._zod.processJSONSchema = (ctx, json7, params) => neverProcessor(inst, ctx, json7, params);
16796
17319
  });
16797
17320
  function never(params) {
16798
17321
  return _never(ZodNever, params);
@@ -16800,7 +17323,7 @@ function never(params) {
16800
17323
  var ZodVoid = /* @__PURE__ */ $constructor("ZodVoid", (inst, def) => {
16801
17324
  $ZodVoid.init(inst, def);
16802
17325
  ZodType.init(inst, def);
16803
- inst._zod.processJSONSchema = (ctx, json6, params) => voidProcessor(inst, ctx, json6, params);
17326
+ inst._zod.processJSONSchema = (ctx, json7, params) => voidProcessor(inst, ctx, json7, params);
16804
17327
  });
16805
17328
  function _void2(params) {
16806
17329
  return _void(ZodVoid, params);
@@ -16808,7 +17331,7 @@ function _void2(params) {
16808
17331
  var ZodDate = /* @__PURE__ */ $constructor("ZodDate", (inst, def) => {
16809
17332
  $ZodDate.init(inst, def);
16810
17333
  ZodType.init(inst, def);
16811
- inst._zod.processJSONSchema = (ctx, json6, params) => dateProcessor(inst, ctx, json6, params);
17334
+ inst._zod.processJSONSchema = (ctx, json7, params) => dateProcessor(inst, ctx, json7, params);
16812
17335
  inst.min = (value, params) => inst.check(_gte(value, params));
16813
17336
  inst.max = (value, params) => inst.check(_lte(value, params));
16814
17337
  const c = inst._zod.bag;
@@ -16821,7 +17344,7 @@ function date3(params) {
16821
17344
  var ZodArray = /* @__PURE__ */ $constructor("ZodArray", (inst, def) => {
16822
17345
  $ZodArray.init(inst, def);
16823
17346
  ZodType.init(inst, def);
16824
- inst._zod.processJSONSchema = (ctx, json6, params) => arrayProcessor(inst, ctx, json6, params);
17347
+ inst._zod.processJSONSchema = (ctx, json7, params) => arrayProcessor(inst, ctx, json7, params);
16825
17348
  inst.element = def.element;
16826
17349
  _installLazyMethods(inst, "ZodArray", {
16827
17350
  min(n, params) {
@@ -16851,7 +17374,7 @@ function keyof(schema) {
16851
17374
  var ZodObject = /* @__PURE__ */ $constructor("ZodObject", (inst, def) => {
16852
17375
  $ZodObjectJIT.init(inst, def);
16853
17376
  ZodType.init(inst, def);
16854
- inst._zod.processJSONSchema = (ctx, json6, params) => objectProcessor(inst, ctx, json6, params);
17377
+ inst._zod.processJSONSchema = (ctx, json7, params) => objectProcessor(inst, ctx, json7, params);
16855
17378
  exports_util.defineLazy(inst, "shape", () => {
16856
17379
  return def.shape;
16857
17380
  });
@@ -16924,7 +17447,7 @@ function looseObject(shape, params) {
16924
17447
  var ZodUnion = /* @__PURE__ */ $constructor("ZodUnion", (inst, def) => {
16925
17448
  $ZodUnion.init(inst, def);
16926
17449
  ZodType.init(inst, def);
16927
- inst._zod.processJSONSchema = (ctx, json6, params) => unionProcessor(inst, ctx, json6, params);
17450
+ inst._zod.processJSONSchema = (ctx, json7, params) => unionProcessor(inst, ctx, json7, params);
16928
17451
  inst.options = def.options;
16929
17452
  });
16930
17453
  function union(options, params) {
@@ -16937,7 +17460,7 @@ function union(options, params) {
16937
17460
  var ZodXor = /* @__PURE__ */ $constructor("ZodXor", (inst, def) => {
16938
17461
  ZodUnion.init(inst, def);
16939
17462
  $ZodXor.init(inst, def);
16940
- inst._zod.processJSONSchema = (ctx, json6, params) => unionProcessor(inst, ctx, json6, params);
17463
+ inst._zod.processJSONSchema = (ctx, json7, params) => unionProcessor(inst, ctx, json7, params);
16941
17464
  inst.options = def.options;
16942
17465
  });
16943
17466
  function xor(options, params) {
@@ -16963,7 +17486,7 @@ function discriminatedUnion(discriminator, options, params) {
16963
17486
  var ZodIntersection = /* @__PURE__ */ $constructor("ZodIntersection", (inst, def) => {
16964
17487
  $ZodIntersection.init(inst, def);
16965
17488
  ZodType.init(inst, def);
16966
- inst._zod.processJSONSchema = (ctx, json6, params) => intersectionProcessor(inst, ctx, json6, params);
17489
+ inst._zod.processJSONSchema = (ctx, json7, params) => intersectionProcessor(inst, ctx, json7, params);
16967
17490
  });
16968
17491
  function intersection(left, right) {
16969
17492
  return new ZodIntersection({
@@ -16975,7 +17498,7 @@ function intersection(left, right) {
16975
17498
  var ZodTuple = /* @__PURE__ */ $constructor("ZodTuple", (inst, def) => {
16976
17499
  $ZodTuple.init(inst, def);
16977
17500
  ZodType.init(inst, def);
16978
- inst._zod.processJSONSchema = (ctx, json6, params) => tupleProcessor(inst, ctx, json6, params);
17501
+ inst._zod.processJSONSchema = (ctx, json7, params) => tupleProcessor(inst, ctx, json7, params);
16979
17502
  inst.rest = (rest) => inst.clone({
16980
17503
  ...inst._zod.def,
16981
17504
  rest
@@ -16995,7 +17518,7 @@ function tuple(items, _paramsOrRest, _params) {
16995
17518
  var ZodRecord = /* @__PURE__ */ $constructor("ZodRecord", (inst, def) => {
16996
17519
  $ZodRecord.init(inst, def);
16997
17520
  ZodType.init(inst, def);
16998
- inst._zod.processJSONSchema = (ctx, json6, params) => recordProcessor(inst, ctx, json6, params);
17521
+ inst._zod.processJSONSchema = (ctx, json7, params) => recordProcessor(inst, ctx, json7, params);
16999
17522
  inst.keyType = def.keyType;
17000
17523
  inst.valueType = def.valueType;
17001
17524
  });
@@ -17037,7 +17560,7 @@ function looseRecord(keyType, valueType, params) {
17037
17560
  var ZodMap = /* @__PURE__ */ $constructor("ZodMap", (inst, def) => {
17038
17561
  $ZodMap.init(inst, def);
17039
17562
  ZodType.init(inst, def);
17040
- inst._zod.processJSONSchema = (ctx, json6, params) => mapProcessor(inst, ctx, json6, params);
17563
+ inst._zod.processJSONSchema = (ctx, json7, params) => mapProcessor(inst, ctx, json7, params);
17041
17564
  inst.keyType = def.keyType;
17042
17565
  inst.valueType = def.valueType;
17043
17566
  inst.min = (...args) => inst.check(_minSize(...args));
@@ -17056,7 +17579,7 @@ function map(keyType, valueType, params) {
17056
17579
  var ZodSet = /* @__PURE__ */ $constructor("ZodSet", (inst, def) => {
17057
17580
  $ZodSet.init(inst, def);
17058
17581
  ZodType.init(inst, def);
17059
- inst._zod.processJSONSchema = (ctx, json6, params) => setProcessor(inst, ctx, json6, params);
17582
+ inst._zod.processJSONSchema = (ctx, json7, params) => setProcessor(inst, ctx, json7, params);
17060
17583
  inst.min = (...args) => inst.check(_minSize(...args));
17061
17584
  inst.nonempty = (params) => inst.check(_minSize(1, params));
17062
17585
  inst.max = (...args) => inst.check(_maxSize(...args));
@@ -17072,7 +17595,7 @@ function set(valueType, params) {
17072
17595
  var ZodEnum = /* @__PURE__ */ $constructor("ZodEnum", (inst, def) => {
17073
17596
  $ZodEnum.init(inst, def);
17074
17597
  ZodType.init(inst, def);
17075
- inst._zod.processJSONSchema = (ctx, json6, params) => enumProcessor(inst, ctx, json6, params);
17598
+ inst._zod.processJSONSchema = (ctx, json7, params) => enumProcessor(inst, ctx, json7, params);
17076
17599
  inst.enum = def.entries;
17077
17600
  inst.options = Object.values(def.entries);
17078
17601
  const keys = new Set(Object.keys(def.entries));
@@ -17125,7 +17648,7 @@ function nativeEnum(entries, params) {
17125
17648
  var ZodLiteral = /* @__PURE__ */ $constructor("ZodLiteral", (inst, def) => {
17126
17649
  $ZodLiteral.init(inst, def);
17127
17650
  ZodType.init(inst, def);
17128
- inst._zod.processJSONSchema = (ctx, json6, params) => literalProcessor(inst, ctx, json6, params);
17651
+ inst._zod.processJSONSchema = (ctx, json7, params) => literalProcessor(inst, ctx, json7, params);
17129
17652
  inst.values = new Set(def.values);
17130
17653
  Object.defineProperty(inst, "value", {
17131
17654
  get() {
@@ -17146,7 +17669,7 @@ function literal(value, params) {
17146
17669
  var ZodFile = /* @__PURE__ */ $constructor("ZodFile", (inst, def) => {
17147
17670
  $ZodFile.init(inst, def);
17148
17671
  ZodType.init(inst, def);
17149
- inst._zod.processJSONSchema = (ctx, json6, params) => fileProcessor(inst, ctx, json6, params);
17672
+ inst._zod.processJSONSchema = (ctx, json7, params) => fileProcessor(inst, ctx, json7, params);
17150
17673
  inst.min = (size, params) => inst.check(_minSize(size, params));
17151
17674
  inst.max = (size, params) => inst.check(_maxSize(size, params));
17152
17675
  inst.mime = (types2, params) => inst.check(_mime(Array.isArray(types2) ? types2 : [types2], params));
@@ -17157,7 +17680,7 @@ function file(params) {
17157
17680
  var ZodTransform = /* @__PURE__ */ $constructor("ZodTransform", (inst, def) => {
17158
17681
  $ZodTransform.init(inst, def);
17159
17682
  ZodType.init(inst, def);
17160
- inst._zod.processJSONSchema = (ctx, json6, params) => transformProcessor(inst, ctx, json6, params);
17683
+ inst._zod.processJSONSchema = (ctx, json7, params) => transformProcessor(inst, ctx, json7, params);
17161
17684
  inst._zod.parse = (payload, _ctx) => {
17162
17685
  if (_ctx.direction === "backward") {
17163
17686
  throw new $ZodEncodeError(inst.constructor.name);
@@ -17197,7 +17720,7 @@ function transform(fn) {
17197
17720
  var ZodOptional = /* @__PURE__ */ $constructor("ZodOptional", (inst, def) => {
17198
17721
  $ZodOptional.init(inst, def);
17199
17722
  ZodType.init(inst, def);
17200
- inst._zod.processJSONSchema = (ctx, json6, params) => optionalProcessor(inst, ctx, json6, params);
17723
+ inst._zod.processJSONSchema = (ctx, json7, params) => optionalProcessor(inst, ctx, json7, params);
17201
17724
  inst.unwrap = () => inst._zod.def.innerType;
17202
17725
  });
17203
17726
  function optional(innerType) {
@@ -17209,7 +17732,7 @@ function optional(innerType) {
17209
17732
  var ZodExactOptional = /* @__PURE__ */ $constructor("ZodExactOptional", (inst, def) => {
17210
17733
  $ZodExactOptional.init(inst, def);
17211
17734
  ZodType.init(inst, def);
17212
- inst._zod.processJSONSchema = (ctx, json6, params) => optionalProcessor(inst, ctx, json6, params);
17735
+ inst._zod.processJSONSchema = (ctx, json7, params) => optionalProcessor(inst, ctx, json7, params);
17213
17736
  inst.unwrap = () => inst._zod.def.innerType;
17214
17737
  });
17215
17738
  function exactOptional(innerType) {
@@ -17221,7 +17744,7 @@ function exactOptional(innerType) {
17221
17744
  var ZodNullable = /* @__PURE__ */ $constructor("ZodNullable", (inst, def) => {
17222
17745
  $ZodNullable.init(inst, def);
17223
17746
  ZodType.init(inst, def);
17224
- inst._zod.processJSONSchema = (ctx, json6, params) => nullableProcessor(inst, ctx, json6, params);
17747
+ inst._zod.processJSONSchema = (ctx, json7, params) => nullableProcessor(inst, ctx, json7, params);
17225
17748
  inst.unwrap = () => inst._zod.def.innerType;
17226
17749
  });
17227
17750
  function nullable(innerType) {
@@ -17236,7 +17759,7 @@ function nullish2(innerType) {
17236
17759
  var ZodDefault = /* @__PURE__ */ $constructor("ZodDefault", (inst, def) => {
17237
17760
  $ZodDefault.init(inst, def);
17238
17761
  ZodType.init(inst, def);
17239
- inst._zod.processJSONSchema = (ctx, json6, params) => defaultProcessor(inst, ctx, json6, params);
17762
+ inst._zod.processJSONSchema = (ctx, json7, params) => defaultProcessor(inst, ctx, json7, params);
17240
17763
  inst.unwrap = () => inst._zod.def.innerType;
17241
17764
  inst.removeDefault = inst.unwrap;
17242
17765
  });
@@ -17252,7 +17775,7 @@ function _default2(innerType, defaultValue) {
17252
17775
  var ZodPrefault = /* @__PURE__ */ $constructor("ZodPrefault", (inst, def) => {
17253
17776
  $ZodPrefault.init(inst, def);
17254
17777
  ZodType.init(inst, def);
17255
- inst._zod.processJSONSchema = (ctx, json6, params) => prefaultProcessor(inst, ctx, json6, params);
17778
+ inst._zod.processJSONSchema = (ctx, json7, params) => prefaultProcessor(inst, ctx, json7, params);
17256
17779
  inst.unwrap = () => inst._zod.def.innerType;
17257
17780
  });
17258
17781
  function prefault(innerType, defaultValue) {
@@ -17267,7 +17790,7 @@ function prefault(innerType, defaultValue) {
17267
17790
  var ZodNonOptional = /* @__PURE__ */ $constructor("ZodNonOptional", (inst, def) => {
17268
17791
  $ZodNonOptional.init(inst, def);
17269
17792
  ZodType.init(inst, def);
17270
- inst._zod.processJSONSchema = (ctx, json6, params) => nonoptionalProcessor(inst, ctx, json6, params);
17793
+ inst._zod.processJSONSchema = (ctx, json7, params) => nonoptionalProcessor(inst, ctx, json7, params);
17271
17794
  inst.unwrap = () => inst._zod.def.innerType;
17272
17795
  });
17273
17796
  function nonoptional(innerType, params) {
@@ -17280,7 +17803,7 @@ function nonoptional(innerType, params) {
17280
17803
  var ZodSuccess = /* @__PURE__ */ $constructor("ZodSuccess", (inst, def) => {
17281
17804
  $ZodSuccess.init(inst, def);
17282
17805
  ZodType.init(inst, def);
17283
- inst._zod.processJSONSchema = (ctx, json6, params) => successProcessor(inst, ctx, json6, params);
17806
+ inst._zod.processJSONSchema = (ctx, json7, params) => successProcessor(inst, ctx, json7, params);
17284
17807
  inst.unwrap = () => inst._zod.def.innerType;
17285
17808
  });
17286
17809
  function success(innerType) {
@@ -17292,7 +17815,7 @@ function success(innerType) {
17292
17815
  var ZodCatch = /* @__PURE__ */ $constructor("ZodCatch", (inst, def) => {
17293
17816
  $ZodCatch.init(inst, def);
17294
17817
  ZodType.init(inst, def);
17295
- inst._zod.processJSONSchema = (ctx, json6, params) => catchProcessor(inst, ctx, json6, params);
17818
+ inst._zod.processJSONSchema = (ctx, json7, params) => catchProcessor(inst, ctx, json7, params);
17296
17819
  inst.unwrap = () => inst._zod.def.innerType;
17297
17820
  inst.removeCatch = inst.unwrap;
17298
17821
  });
@@ -17306,7 +17829,7 @@ function _catch2(innerType, catchValue) {
17306
17829
  var ZodNaN = /* @__PURE__ */ $constructor("ZodNaN", (inst, def) => {
17307
17830
  $ZodNaN.init(inst, def);
17308
17831
  ZodType.init(inst, def);
17309
- inst._zod.processJSONSchema = (ctx, json6, params) => nanProcessor(inst, ctx, json6, params);
17832
+ inst._zod.processJSONSchema = (ctx, json7, params) => nanProcessor(inst, ctx, json7, params);
17310
17833
  });
17311
17834
  function nan(params) {
17312
17835
  return _nan(ZodNaN, params);
@@ -17314,7 +17837,7 @@ function nan(params) {
17314
17837
  var ZodPipe = /* @__PURE__ */ $constructor("ZodPipe", (inst, def) => {
17315
17838
  $ZodPipe.init(inst, def);
17316
17839
  ZodType.init(inst, def);
17317
- inst._zod.processJSONSchema = (ctx, json6, params) => pipeProcessor(inst, ctx, json6, params);
17840
+ inst._zod.processJSONSchema = (ctx, json7, params) => pipeProcessor(inst, ctx, json7, params);
17318
17841
  inst.in = def.in;
17319
17842
  inst.out = def.out;
17320
17843
  });
@@ -17355,7 +17878,7 @@ var ZodPreprocess = /* @__PURE__ */ $constructor("ZodPreprocess", (inst, def) =>
17355
17878
  var ZodReadonly = /* @__PURE__ */ $constructor("ZodReadonly", (inst, def) => {
17356
17879
  $ZodReadonly.init(inst, def);
17357
17880
  ZodType.init(inst, def);
17358
- inst._zod.processJSONSchema = (ctx, json6, params) => readonlyProcessor(inst, ctx, json6, params);
17881
+ inst._zod.processJSONSchema = (ctx, json7, params) => readonlyProcessor(inst, ctx, json7, params);
17359
17882
  inst.unwrap = () => inst._zod.def.innerType;
17360
17883
  });
17361
17884
  function readonly(innerType) {
@@ -17367,7 +17890,7 @@ function readonly(innerType) {
17367
17890
  var ZodTemplateLiteral = /* @__PURE__ */ $constructor("ZodTemplateLiteral", (inst, def) => {
17368
17891
  $ZodTemplateLiteral.init(inst, def);
17369
17892
  ZodType.init(inst, def);
17370
- inst._zod.processJSONSchema = (ctx, json6, params) => templateLiteralProcessor(inst, ctx, json6, params);
17893
+ inst._zod.processJSONSchema = (ctx, json7, params) => templateLiteralProcessor(inst, ctx, json7, params);
17371
17894
  });
17372
17895
  function templateLiteral(parts, params) {
17373
17896
  return new ZodTemplateLiteral({
@@ -17379,7 +17902,7 @@ function templateLiteral(parts, params) {
17379
17902
  var ZodLazy = /* @__PURE__ */ $constructor("ZodLazy", (inst, def) => {
17380
17903
  $ZodLazy.init(inst, def);
17381
17904
  ZodType.init(inst, def);
17382
- inst._zod.processJSONSchema = (ctx, json6, params) => lazyProcessor(inst, ctx, json6, params);
17905
+ inst._zod.processJSONSchema = (ctx, json7, params) => lazyProcessor(inst, ctx, json7, params);
17383
17906
  inst.unwrap = () => inst._zod.def.getter();
17384
17907
  });
17385
17908
  function lazy(getter) {
@@ -17391,7 +17914,7 @@ function lazy(getter) {
17391
17914
  var ZodPromise = /* @__PURE__ */ $constructor("ZodPromise", (inst, def) => {
17392
17915
  $ZodPromise.init(inst, def);
17393
17916
  ZodType.init(inst, def);
17394
- inst._zod.processJSONSchema = (ctx, json6, params) => promiseProcessor(inst, ctx, json6, params);
17917
+ inst._zod.processJSONSchema = (ctx, json7, params) => promiseProcessor(inst, ctx, json7, params);
17395
17918
  inst.unwrap = () => inst._zod.def.innerType;
17396
17919
  });
17397
17920
  function promise(innerType) {
@@ -17403,7 +17926,7 @@ function promise(innerType) {
17403
17926
  var ZodFunction = /* @__PURE__ */ $constructor("ZodFunction", (inst, def) => {
17404
17927
  $ZodFunction.init(inst, def);
17405
17928
  ZodType.init(inst, def);
17406
- inst._zod.processJSONSchema = (ctx, json6, params) => functionProcessor(inst, ctx, json6, params);
17929
+ inst._zod.processJSONSchema = (ctx, json7, params) => functionProcessor(inst, ctx, json7, params);
17407
17930
  });
17408
17931
  function _function(params) {
17409
17932
  return new ZodFunction({
@@ -17415,7 +17938,7 @@ function _function(params) {
17415
17938
  var ZodCustom = /* @__PURE__ */ $constructor("ZodCustom", (inst, def) => {
17416
17939
  $ZodCustom.init(inst, def);
17417
17940
  ZodType.init(inst, def);
17418
- inst._zod.processJSONSchema = (ctx, json6, params) => customProcessor(inst, ctx, json6, params);
17941
+ inst._zod.processJSONSchema = (ctx, json7, params) => customProcessor(inst, ctx, json7, params);
17419
17942
  });
17420
17943
  function check(fn) {
17421
17944
  const ch = new $ZodCheck({
@@ -17462,7 +17985,7 @@ var stringbool = (...args) => _stringbool({
17462
17985
  Boolean: ZodBoolean,
17463
17986
  String: ZodString
17464
17987
  }, ...args);
17465
- function json6(params) {
17988
+ function json7(params) {
17466
17989
  const jsonSchema = lazy(() => {
17467
17990
  return union([string2(params), number2(), boolean2(), _null3(), array(jsonSchema), record(string2(), jsonSchema)]);
17468
17991
  });
@@ -18714,10 +19237,10 @@ function prepareArtifact(input) {
18714
19237
  attempts,
18715
19238
  error: error51.value
18716
19239
  };
18717
- const json7 = JSON.stringify(bounded);
18718
- const size = encoder2.encode(json7).length;
19240
+ const json8 = JSON.stringify(bounded);
19241
+ const size = encoder2.encode(json8).length;
18719
19242
  if (size <= MAX_ARTIFACT_BYTES)
18720
- return { artifact: bounded, json: json7 };
19243
+ return { artifact: bounded, json: json8 };
18721
19244
  const marker = omission(size);
18722
19245
  const omitted = omitBodies(bounded, marker);
18723
19246
  const omittedJson = JSON.stringify(omitted);
@@ -18727,8 +19250,8 @@ function prepareArtifact(input) {
18727
19250
  const stripped = { ...omitted, error: marker };
18728
19251
  return { artifact: stripped, json: JSON.stringify(stripped) };
18729
19252
  }
18730
- async function sealArtifact(key, json7) {
18731
- const bytes = encoder2.encode(await encrypt(key, json7));
19253
+ async function sealArtifact(key, json8) {
19254
+ const bytes = encoder2.encode(await encrypt(key, json8));
18732
19255
  return { bytes, sha256: await sha256Hex(bytes) };
18733
19256
  }
18734
19257
  async function readArtifact(key, dir, relPath, expectedSha256) {
@@ -20824,13 +21347,15 @@ function customProviderData(input) {
20824
21347
  } catch {
20825
21348
  throw new GatewayError("BAD_REQUEST", "origin: must be a valid URL");
20826
21349
  }
20827
- 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) {
20828
21351
  throw new GatewayError("BAD_REQUEST", "origin: must be an HTTP(S) server origin");
20829
21352
  }
20830
- 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 };
20831
21355
  }
20832
21356
  function sameCustomEndpoint(a, b) {
20833
- 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;
20834
21359
  }
20835
21360
  async function createApiKeyCredential(store, input, logger2 = noopLogger) {
20836
21361
  const provider = parseOrThrow(providerIdSchema, input.provider);
@@ -22471,10 +22996,10 @@ function emailFromIdToken(idToken) {
22471
22996
  if (parts.length !== 3 || payload === undefined || payload.length === 0)
22472
22997
  return null;
22473
22998
  try {
22474
- const json7 = JSON.parse(Buffer.from(payload, "base64url").toString("utf8"));
22475
- if (!isRecord2(json7))
22999
+ const json8 = JSON.parse(Buffer.from(payload, "base64url").toString("utf8"));
23000
+ if (!isRecord2(json8))
22476
23001
  return null;
22477
- 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;
22478
23003
  } catch {
22479
23004
  return null;
22480
23005
  }
@@ -22877,12 +23402,12 @@ function decodeClaims(idToken) {
22877
23402
  return { email: null, accountId: null };
22878
23403
  }
22879
23404
  try {
22880
- const json7 = JSON.parse(Buffer.from(payload, "base64url").toString("utf8"));
22881
- if (!isRecord5(json7))
23405
+ const json8 = JSON.parse(Buffer.from(payload, "base64url").toString("utf8"));
23406
+ if (!isRecord5(json8))
22882
23407
  return { email: null, accountId: null };
22883
- const auth = json7["https://api.openai.com/auth"];
23408
+ const auth = json8["https://api.openai.com/auth"];
22884
23409
  return {
22885
- email: typeof json7.email === "string" ? json7.email : null,
23410
+ email: typeof json8.email === "string" ? json8.email : null,
22886
23411
  accountId: isRecord5(auth) ? nonBlankStringOrNull(auth.chatgpt_account_id) : null
22887
23412
  };
22888
23413
  } catch {
@@ -24126,13 +24651,14 @@ var credentialsAddKey = {
24126
24651
  const store = await ctx.store();
24127
24652
  const endpointId = stringFlag(args.values, "endpoint-id");
24128
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 : ""}`;
24129
24655
  const created = await createApiKeyCredential(store, {
24130
24656
  provider: providerId,
24131
24657
  apiKey: key,
24132
24658
  label: stringFlag(args.values, "label"),
24133
24659
  endpointId,
24134
24660
  endpointLabel: stringFlag(args.values, "endpoint-label") ?? existingEndpoint?.providerData.endpointLabel,
24135
- origin: stringFlag(args.values, "origin") ?? existingEndpoint?.providerData.origin,
24661
+ origin: stringFlag(args.values, "origin") ?? existingOrigin,
24136
24662
  protocol: protocol ?? existingEndpoint?.providerData.protocol
24137
24663
  });
24138
24664
  emit(ctx, writer, { id: created.id, provider: created.provider }, () => `stored ${created.provider} api key as ${created.id}`);