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.
- package/README.md +86 -238
- package/bin/omni.js +910 -384
- package/gateway.js +906 -355
- package/package.json +1 -1
- package/public/assets/{CopyValue-By5BAgv7.js → CopyValue-C2DkO9Yz.js} +1 -1
- package/public/assets/{Rack-fDZClWZL.js → Rack-HM36SprU.js} +1 -1
- package/public/assets/{Toggle-ClEeOh0F.js → Toggle-CRrH9nDt.js} +1 -1
- package/public/assets/{TokenBreakdown-D70VeZ2N.js → TokenBreakdown-C2NsJnqO.js} +1 -1
- package/public/assets/{_app-CDPKnQ72.js → _app-DVpIsUid.js} +1 -1
- package/public/assets/{_app.accounts-Dz0ox4Br.js → _app.accounts-64d_cxir.js} +2 -2
- package/public/assets/{_app.console-hPUmmYjp.js → _app.console-BBuBmLRI.js} +1 -1
- package/public/assets/{_app.database-DGtP4NdG.js → _app.database-J9Ujio8l.js} +1 -1
- package/public/assets/{_app.index-COcCAmbH.js → _app.index-BX4yKEXO.js} +1 -1
- package/public/assets/{_app.keys-yTXTbKTA.js → _app.keys-2sKwhZJc.js} +1 -1
- package/public/assets/{_app.logs-BhMvO_Fx.js → _app.logs-DuHXYrZU.js} +1 -1
- package/public/assets/{_app.models-0S3rurIl.js → _app.models-B0kTfPtn.js} +1 -1
- package/public/assets/{_app.plugins._pluginId-B-ZDQNPU.js → _app.plugins._pluginId-BOXRBToU.js} +1 -1
- package/public/assets/{_app.settings-DTnFwTeA.js → _app.settings-DoaOUmc1.js} +1 -1
- package/public/assets/{_app.usage-C2-VLiq9.js → _app.usage-B5sxB40E.js} +1 -1
- package/public/assets/{index-COwhxKU7.js → index-iCfSaRSG.js} +2 -2
- package/public/assets/{login-DjfMomJJ.js → login-B9CJqU--.js} +1 -1
- package/public/assets/plus-DKapAGoR.js +1 -0
- package/public/assets/{trash-2-U2ViYZum.js → trash-2-DwMK-JrZ.js} +1 -1
- package/public/index.html +1 -1
- package/public/assets/plus-UDQ_BTEr.js +0 -1
package/gateway.js
CHANGED
|
@@ -4683,8 +4683,8 @@ class FileTypeParser {
|
|
|
4683
4683
|
if (jsonSize > 12 && this.buffer.length >= jsonSize + 16) {
|
|
4684
4684
|
try {
|
|
4685
4685
|
const header = new TextDecoder().decode(this.buffer.subarray(16, jsonSize + 16));
|
|
4686
|
-
const
|
|
4687
|
-
if (
|
|
4686
|
+
const json8 = JSON.parse(header);
|
|
4687
|
+
if (json8.files) {
|
|
4688
4688
|
return {
|
|
4689
4689
|
ext: "asar",
|
|
4690
4690
|
mime: "application/x-asar"
|
|
@@ -5523,6 +5523,15 @@ function parseLogLevel(value) {
|
|
|
5523
5523
|
function cacheControlOf(block) {
|
|
5524
5524
|
return block.type === "thinking" ? undefined : block.cacheControl;
|
|
5525
5525
|
}
|
|
5526
|
+
var REASONING_EFFORTS = [
|
|
5527
|
+
"none",
|
|
5528
|
+
"minimal",
|
|
5529
|
+
"low",
|
|
5530
|
+
"medium",
|
|
5531
|
+
"high",
|
|
5532
|
+
"xhigh",
|
|
5533
|
+
"max"
|
|
5534
|
+
];
|
|
5526
5535
|
// packages/ir/src/stream.ts
|
|
5527
5536
|
function usageFromPromptTotal(promptTokens, outputTokens, cacheReadTokens, cacheWriteTokens = 0) {
|
|
5528
5537
|
return {
|
|
@@ -7293,16 +7302,51 @@ function hasVendorCacheControl(req) {
|
|
|
7293
7302
|
const anthropic2 = req.vendor?.anthropic;
|
|
7294
7303
|
return typeof anthropic2 === "object" && anthropic2 !== null && "cache_control" in anthropic2;
|
|
7295
7304
|
}
|
|
7296
|
-
|
|
7305
|
+
var CACHEABLE_WIRE_BLOCKS = new Set(["text", "image", "tool_use", "tool_result", "document"]);
|
|
7306
|
+
function lastCacheableHistoryBlock(messages) {
|
|
7307
|
+
for (let m = messages.length - 1;m >= 0; m--) {
|
|
7308
|
+
const message = messages[m];
|
|
7309
|
+
if (!isRecord(message) || !Array.isArray(message.content))
|
|
7310
|
+
continue;
|
|
7311
|
+
for (let b = message.content.length - 1;b >= 0; b--) {
|
|
7312
|
+
const block = message.content[b];
|
|
7313
|
+
if (!isRecord(block))
|
|
7314
|
+
continue;
|
|
7315
|
+
if (typeof block.type === "string" && CACHEABLE_WIRE_BLOCKS.has(block.type))
|
|
7316
|
+
return block;
|
|
7317
|
+
}
|
|
7318
|
+
}
|
|
7319
|
+
return;
|
|
7320
|
+
}
|
|
7321
|
+
function addAutoCacheBreakpoints(body, req, note) {
|
|
7297
7322
|
if (estimateCachedInputTokens(req) !== 0 || hasVendorCacheControl(req))
|
|
7298
7323
|
return;
|
|
7299
|
-
|
|
7324
|
+
let markedPrefix = 0;
|
|
7325
|
+
const worthAMarker = (prefix) => prefix - markedPrefix >= AUTO_CACHE_MIN_TOKENS;
|
|
7326
|
+
let stablePrefixMarked = false;
|
|
7327
|
+
const toolsPrefix = estimateInputTokens({ ...req, messages: [], system: [] });
|
|
7328
|
+
const lastTool = body.tools?.at(-1);
|
|
7329
|
+
if (lastTool !== undefined && worthAMarker(toolsPrefix)) {
|
|
7330
|
+
lastTool.cache_control = { type: "ephemeral" };
|
|
7331
|
+
markedPrefix = toolsPrefix;
|
|
7332
|
+
stablePrefixMarked = true;
|
|
7333
|
+
}
|
|
7334
|
+
const systemPrefix = estimateInputTokens({ ...req, messages: [] });
|
|
7335
|
+
const lastSystem = body.system?.at(-1);
|
|
7336
|
+
if (lastSystem !== undefined && worthAMarker(systemPrefix)) {
|
|
7337
|
+
lastSystem.cache_control = { type: "ephemeral" };
|
|
7338
|
+
markedPrefix = systemPrefix;
|
|
7339
|
+
stablePrefixMarked = true;
|
|
7340
|
+
}
|
|
7341
|
+
if (stablePrefixMarked)
|
|
7342
|
+
note("anthropic:cache-breakpoint-added");
|
|
7343
|
+
if (!worthAMarker(estimateInputTokens(req)))
|
|
7300
7344
|
return;
|
|
7301
|
-
const
|
|
7302
|
-
if (
|
|
7345
|
+
const lastHistory = lastCacheableHistoryBlock(body.messages);
|
|
7346
|
+
if (lastHistory === undefined)
|
|
7303
7347
|
return;
|
|
7304
|
-
|
|
7305
|
-
note("anthropic:cache-breakpoint-added");
|
|
7348
|
+
lastHistory.cache_control = { type: "ephemeral" };
|
|
7349
|
+
note("anthropic:history-cache-breakpoint-added");
|
|
7306
7350
|
}
|
|
7307
7351
|
function toWire(req, model, opts) {
|
|
7308
7352
|
const cloak = opts.cloak ?? null;
|
|
@@ -7354,7 +7398,7 @@ function toWire(req, model, opts) {
|
|
|
7354
7398
|
if (req.toolChoice !== undefined)
|
|
7355
7399
|
body.tool_choice = encodeToolChoice(req.toolChoice, cloak);
|
|
7356
7400
|
if (opts.autoCache === true)
|
|
7357
|
-
|
|
7401
|
+
addAutoCacheBreakpoints(body, req, note);
|
|
7358
7402
|
if (req.reasoning !== undefined) {
|
|
7359
7403
|
switch (req.reasoning.mode) {
|
|
7360
7404
|
case "adaptive":
|
|
@@ -7467,13 +7511,31 @@ var anthropicAdapter = {
|
|
|
7467
7511
|
};
|
|
7468
7512
|
}
|
|
7469
7513
|
};
|
|
7470
|
-
// packages/providers/src/
|
|
7471
|
-
var
|
|
7514
|
+
// packages/providers/src/custom/decode.ts
|
|
7515
|
+
var CHAT_FINISH = {
|
|
7472
7516
|
stop: "endTurn",
|
|
7473
7517
|
length: "maxTokens",
|
|
7474
7518
|
tool_calls: "toolUse",
|
|
7475
7519
|
content_filter: "contentFilter"
|
|
7476
7520
|
};
|
|
7521
|
+
function reasoningText(delta) {
|
|
7522
|
+
if (typeof delta.reasoning === "string" && delta.reasoning.length > 0)
|
|
7523
|
+
return delta.reasoning;
|
|
7524
|
+
if (typeof delta.reasoning_content === "string" && delta.reasoning_content.length > 0) {
|
|
7525
|
+
return delta.reasoning_content;
|
|
7526
|
+
}
|
|
7527
|
+
if (!Array.isArray(delta.reasoning_details))
|
|
7528
|
+
return "";
|
|
7529
|
+
return delta.reasoning_details.flatMap((entry) => {
|
|
7530
|
+
if (entry === null || typeof entry !== "object")
|
|
7531
|
+
return [];
|
|
7532
|
+
if (typeof entry.text === "string" && entry.text.length > 0)
|
|
7533
|
+
return [entry.text];
|
|
7534
|
+
if (typeof entry.summary === "string" && entry.summary.length > 0)
|
|
7535
|
+
return [entry.summary];
|
|
7536
|
+
return [];
|
|
7537
|
+
}).join("");
|
|
7538
|
+
}
|
|
7477
7539
|
function json2(data) {
|
|
7478
7540
|
try {
|
|
7479
7541
|
const v = JSON.parse(data);
|
|
@@ -7482,7 +7544,7 @@ function json2(data) {
|
|
|
7482
7544
|
return null;
|
|
7483
7545
|
}
|
|
7484
7546
|
}
|
|
7485
|
-
async function*
|
|
7547
|
+
async function* decodeCustomChat(messages) {
|
|
7486
7548
|
let started = false;
|
|
7487
7549
|
let done = false;
|
|
7488
7550
|
let stopReason = "endTurn";
|
|
@@ -7511,6 +7573,21 @@ async function* decodeChat(messages) {
|
|
|
7511
7573
|
if (!choice)
|
|
7512
7574
|
continue;
|
|
7513
7575
|
const delta = choice.delta ?? {};
|
|
7576
|
+
const reasoning = reasoningText(delta);
|
|
7577
|
+
if (reasoning.length > 0) {
|
|
7578
|
+
if (openKind !== "thinking") {
|
|
7579
|
+
if (openKind !== undefined)
|
|
7580
|
+
yield { type: "blockEnd", index: openIndex };
|
|
7581
|
+
openKind = "thinking";
|
|
7582
|
+
openIndex = nextIndex++;
|
|
7583
|
+
yield { type: "blockStart", index: openIndex, block: { type: "thinking" } };
|
|
7584
|
+
}
|
|
7585
|
+
yield {
|
|
7586
|
+
type: "blockDelta",
|
|
7587
|
+
index: openIndex,
|
|
7588
|
+
delta: { type: "thinking", text: reasoning }
|
|
7589
|
+
};
|
|
7590
|
+
}
|
|
7514
7591
|
if (typeof delta.content === "string" && delta.content.length > 0) {
|
|
7515
7592
|
if (openKind !== "text") {
|
|
7516
7593
|
if (openKind !== undefined)
|
|
@@ -7551,7 +7628,7 @@ async function* decodeChat(messages) {
|
|
|
7551
7628
|
}
|
|
7552
7629
|
}
|
|
7553
7630
|
if (typeof choice.finish_reason === "string") {
|
|
7554
|
-
stopReason =
|
|
7631
|
+
stopReason = CHAT_FINISH[choice.finish_reason] ?? "endTurn";
|
|
7555
7632
|
}
|
|
7556
7633
|
}
|
|
7557
7634
|
if (done) {
|
|
@@ -7567,110 +7644,7 @@ async function* decodeChat(messages) {
|
|
|
7567
7644
|
};
|
|
7568
7645
|
}
|
|
7569
7646
|
}
|
|
7570
|
-
|
|
7571
|
-
// packages/providers/src/kimi/wire.ts
|
|
7572
|
-
function encodeToolChoice2(c) {
|
|
7573
|
-
switch (c.type) {
|
|
7574
|
-
case "auto":
|
|
7575
|
-
return "auto";
|
|
7576
|
-
case "any":
|
|
7577
|
-
return "required";
|
|
7578
|
-
case "none":
|
|
7579
|
-
return "none";
|
|
7580
|
-
case "tool":
|
|
7581
|
-
return { type: "function", function: { name: c.name } };
|
|
7582
|
-
}
|
|
7583
|
-
}
|
|
7584
|
-
function toChatWire(req, model, vendor = "kimi") {
|
|
7585
|
-
const degradations = [];
|
|
7586
|
-
const note = (d) => {
|
|
7587
|
-
if (!degradations.includes(d))
|
|
7588
|
-
degradations.push(d);
|
|
7589
|
-
};
|
|
7590
|
-
if (req.betas?.includes(CONTEXT_1M_BETA))
|
|
7591
|
-
note("kimi:context-1m-dropped");
|
|
7592
|
-
const messages = [];
|
|
7593
|
-
const system = req.system?.flatMap((b) => b.type === "text" ? [b.text] : []).join(`
|
|
7594
|
-
|
|
7595
|
-
`);
|
|
7596
|
-
if (system !== undefined && system.length > 0)
|
|
7597
|
-
messages.push({ role: "system", content: system });
|
|
7598
|
-
for (const message of req.messages) {
|
|
7599
|
-
const text = [];
|
|
7600
|
-
const toolCalls = [];
|
|
7601
|
-
for (const block of message.content) {
|
|
7602
|
-
switch (block.type) {
|
|
7603
|
-
case "text":
|
|
7604
|
-
text.push(block.text);
|
|
7605
|
-
break;
|
|
7606
|
-
case "image":
|
|
7607
|
-
note("kimi:images-dropped");
|
|
7608
|
-
break;
|
|
7609
|
-
case "thinking":
|
|
7610
|
-
note("kimi:thinking-dropped");
|
|
7611
|
-
break;
|
|
7612
|
-
case "toolUse":
|
|
7613
|
-
toolCalls.push({
|
|
7614
|
-
id: block.id,
|
|
7615
|
-
type: "function",
|
|
7616
|
-
function: { name: block.name, arguments: JSON.stringify(block.input) }
|
|
7617
|
-
});
|
|
7618
|
-
break;
|
|
7619
|
-
case "toolResult":
|
|
7620
|
-
messages.push({
|
|
7621
|
-
role: "tool",
|
|
7622
|
-
tool_call_id: block.toolUseId,
|
|
7623
|
-
content: block.content
|
|
7624
|
-
});
|
|
7625
|
-
break;
|
|
7626
|
-
case "anthropicNative":
|
|
7627
|
-
note("kimi:anthropic-native-block-dropped");
|
|
7628
|
-
break;
|
|
7629
|
-
}
|
|
7630
|
-
}
|
|
7631
|
-
if (toolCalls.length > 0) {
|
|
7632
|
-
messages.push({
|
|
7633
|
-
role: message.role,
|
|
7634
|
-
content: text.length > 0 ? text.join(`
|
|
7635
|
-
`) : null,
|
|
7636
|
-
tool_calls: toolCalls
|
|
7637
|
-
});
|
|
7638
|
-
} else if (text.length > 0) {
|
|
7639
|
-
messages.push({ role: message.role, content: text.join(`
|
|
7640
|
-
`) });
|
|
7641
|
-
}
|
|
7642
|
-
}
|
|
7643
|
-
const body = {
|
|
7644
|
-
model,
|
|
7645
|
-
messages,
|
|
7646
|
-
stream: req.stream,
|
|
7647
|
-
stream_options: { include_usage: true }
|
|
7648
|
-
};
|
|
7649
|
-
if (req.maxTokens !== undefined)
|
|
7650
|
-
body.max_tokens = req.maxTokens;
|
|
7651
|
-
if (req.temperature !== undefined)
|
|
7652
|
-
body.temperature = req.temperature;
|
|
7653
|
-
if (req.stopSequences !== undefined)
|
|
7654
|
-
body.stop = req.stopSequences;
|
|
7655
|
-
if (req.tools !== undefined) {
|
|
7656
|
-
const custom = req.tools.filter((t) => t.provider === "custom");
|
|
7657
|
-
if (custom.length !== req.tools.length)
|
|
7658
|
-
note("kimi:anthropic-tool-dropped");
|
|
7659
|
-
body.tools = custom.map((t) => ({
|
|
7660
|
-
type: "function",
|
|
7661
|
-
function: { name: t.name, description: t.description, parameters: t.inputSchema }
|
|
7662
|
-
}));
|
|
7663
|
-
}
|
|
7664
|
-
if (req.toolChoice !== undefined)
|
|
7665
|
-
body.tool_choice = encodeToolChoice2(req.toolChoice);
|
|
7666
|
-
if (req.reasoning !== undefined)
|
|
7667
|
-
note("kimi:reasoning-dropped");
|
|
7668
|
-
Object.assign(body, req.vendor?.[vendor] ?? {});
|
|
7669
|
-
return { body, degradations };
|
|
7670
|
-
}
|
|
7671
|
-
|
|
7672
|
-
// packages/providers/src/openai/decode.ts
|
|
7673
|
-
var ERROR_CODE = {
|
|
7647
|
+
var RESPONSES_ERROR_CODE = {
|
|
7674
7648
|
rate_limit_exceeded: "RATE_LIMIT",
|
|
7675
7649
|
insufficient_quota: "QUOTA_EXHAUSTED",
|
|
7676
7650
|
invalid_api_key: "AUTH",
|
|
@@ -7678,15 +7652,7 @@ var ERROR_CODE = {
|
|
|
7678
7652
|
context_length_exceeded: "BAD_REQUEST",
|
|
7679
7653
|
content_policy_violation: "CONTENT_FILTER"
|
|
7680
7654
|
};
|
|
7681
|
-
function
|
|
7682
|
-
try {
|
|
7683
|
-
const v = JSON.parse(data);
|
|
7684
|
-
return typeof v === "object" && v !== null ? v : null;
|
|
7685
|
-
} catch {
|
|
7686
|
-
return null;
|
|
7687
|
-
}
|
|
7688
|
-
}
|
|
7689
|
-
async function* decodeResponses(messages) {
|
|
7655
|
+
async function* decodeCustomResponses(messages) {
|
|
7690
7656
|
const indices = new Map;
|
|
7691
7657
|
let next = 0;
|
|
7692
7658
|
const irIndex = (outputIndex, contentIndex = 0) => {
|
|
@@ -7702,7 +7668,7 @@ async function* decodeResponses(messages) {
|
|
|
7702
7668
|
let terminal = false;
|
|
7703
7669
|
const ownsBlock = new Set;
|
|
7704
7670
|
for await (const msg of messages) {
|
|
7705
|
-
const d =
|
|
7671
|
+
const d = json2(msg.data);
|
|
7706
7672
|
if (d === null)
|
|
7707
7673
|
continue;
|
|
7708
7674
|
switch (msg.event) {
|
|
@@ -7794,7 +7760,7 @@ async function* decodeResponses(messages) {
|
|
|
7794
7760
|
case "error": {
|
|
7795
7761
|
terminal = true;
|
|
7796
7762
|
const err = d.response?.error ?? d.error ?? {};
|
|
7797
|
-
const code =
|
|
7763
|
+
const code = RESPONSES_ERROR_CODE[String(err.code ?? err.type)] ?? "UPSTREAM";
|
|
7798
7764
|
yield {
|
|
7799
7765
|
type: "error",
|
|
7800
7766
|
code,
|
|
@@ -7817,8 +7783,20 @@ async function* decodeResponses(messages) {
|
|
|
7817
7783
|
}
|
|
7818
7784
|
}
|
|
7819
7785
|
|
|
7820
|
-
// packages/providers/src/
|
|
7821
|
-
function
|
|
7786
|
+
// packages/providers/src/custom/wire.ts
|
|
7787
|
+
function encodeChatToolChoice(c) {
|
|
7788
|
+
switch (c.type) {
|
|
7789
|
+
case "auto":
|
|
7790
|
+
return "auto";
|
|
7791
|
+
case "any":
|
|
7792
|
+
return "required";
|
|
7793
|
+
case "none":
|
|
7794
|
+
return "none";
|
|
7795
|
+
case "tool":
|
|
7796
|
+
return { type: "function", function: { name: c.name } };
|
|
7797
|
+
}
|
|
7798
|
+
}
|
|
7799
|
+
function encodeResponsesToolChoice(c) {
|
|
7822
7800
|
switch (c.type) {
|
|
7823
7801
|
case "auto":
|
|
7824
7802
|
return "auto";
|
|
@@ -7830,20 +7808,115 @@ function encodeToolChoice3(c) {
|
|
|
7830
7808
|
return { type: "function", name: c.name };
|
|
7831
7809
|
}
|
|
7832
7810
|
}
|
|
7833
|
-
function
|
|
7811
|
+
function customEffort(reasoning) {
|
|
7812
|
+
if (reasoning === undefined || reasoning.mode !== "adaptive")
|
|
7813
|
+
return;
|
|
7814
|
+
return reasoning.effort ?? "medium";
|
|
7815
|
+
}
|
|
7816
|
+
function toCustomChatWire(req, model) {
|
|
7834
7817
|
const degradations = [];
|
|
7835
|
-
const input = [];
|
|
7836
7818
|
const note = (d) => {
|
|
7837
7819
|
if (!degradations.includes(d))
|
|
7838
7820
|
degradations.push(d);
|
|
7839
7821
|
};
|
|
7840
7822
|
if (req.betas?.includes(CONTEXT_1M_BETA))
|
|
7841
|
-
note("
|
|
7823
|
+
note("custom:context-1m-dropped");
|
|
7824
|
+
const messages = [];
|
|
7825
|
+
const system = req.system?.flatMap((b) => b.type === "text" ? [b.text] : []).join(`
|
|
7826
|
+
|
|
7827
|
+
`);
|
|
7828
|
+
if (system !== undefined && system.length > 0)
|
|
7829
|
+
messages.push({ role: "system", content: system });
|
|
7830
|
+
for (const message of req.messages) {
|
|
7831
|
+
const text = [];
|
|
7832
|
+
const toolCalls = [];
|
|
7833
|
+
for (const block of message.content) {
|
|
7834
|
+
switch (block.type) {
|
|
7835
|
+
case "text":
|
|
7836
|
+
text.push(block.text);
|
|
7837
|
+
break;
|
|
7838
|
+
case "image":
|
|
7839
|
+
note("custom:images-dropped");
|
|
7840
|
+
break;
|
|
7841
|
+
case "thinking":
|
|
7842
|
+
note("custom:thinking-dropped");
|
|
7843
|
+
break;
|
|
7844
|
+
case "toolUse":
|
|
7845
|
+
toolCalls.push({
|
|
7846
|
+
id: block.id,
|
|
7847
|
+
type: "function",
|
|
7848
|
+
function: { name: block.name, arguments: JSON.stringify(block.input) }
|
|
7849
|
+
});
|
|
7850
|
+
break;
|
|
7851
|
+
case "toolResult":
|
|
7852
|
+
messages.push({
|
|
7853
|
+
role: "tool",
|
|
7854
|
+
tool_call_id: block.toolUseId,
|
|
7855
|
+
content: block.content
|
|
7856
|
+
});
|
|
7857
|
+
break;
|
|
7858
|
+
case "anthropicNative":
|
|
7859
|
+
note("custom:anthropic-native-block-dropped");
|
|
7860
|
+
break;
|
|
7861
|
+
}
|
|
7862
|
+
}
|
|
7863
|
+
if (toolCalls.length > 0) {
|
|
7864
|
+
messages.push({
|
|
7865
|
+
role: message.role,
|
|
7866
|
+
content: text.length > 0 ? text.join(`
|
|
7867
|
+
`) : null,
|
|
7868
|
+
tool_calls: toolCalls
|
|
7869
|
+
});
|
|
7870
|
+
} else if (text.length > 0) {
|
|
7871
|
+
messages.push({ role: message.role, content: text.join(`
|
|
7872
|
+
`) });
|
|
7873
|
+
}
|
|
7874
|
+
}
|
|
7875
|
+
const body = {
|
|
7876
|
+
model,
|
|
7877
|
+
messages,
|
|
7878
|
+
stream: req.stream,
|
|
7879
|
+
stream_options: { include_usage: true }
|
|
7880
|
+
};
|
|
7881
|
+
if (req.maxTokens !== undefined)
|
|
7882
|
+
body.max_tokens = req.maxTokens;
|
|
7883
|
+
if (req.temperature !== undefined)
|
|
7884
|
+
body.temperature = req.temperature;
|
|
7885
|
+
if (req.stopSequences !== undefined)
|
|
7886
|
+
body.stop = req.stopSequences;
|
|
7887
|
+
if (req.tools !== undefined) {
|
|
7888
|
+
const portable = req.tools.filter((t) => t.provider === "custom");
|
|
7889
|
+
if (portable.length !== req.tools.length)
|
|
7890
|
+
note("custom:anthropic-tool-dropped");
|
|
7891
|
+
body.tools = portable.map((t) => ({
|
|
7892
|
+
type: "function",
|
|
7893
|
+
function: { name: t.name, description: t.description, parameters: t.inputSchema }
|
|
7894
|
+
}));
|
|
7895
|
+
}
|
|
7896
|
+
if (req.toolChoice !== undefined)
|
|
7897
|
+
body.tool_choice = encodeChatToolChoice(req.toolChoice);
|
|
7898
|
+
const effort = customEffort(req.reasoning);
|
|
7899
|
+
if (effort !== undefined)
|
|
7900
|
+
body.reasoning_effort = effort;
|
|
7901
|
+
else if (req.reasoning?.mode === "budget")
|
|
7902
|
+
note("custom:reasoning-budget-dropped");
|
|
7903
|
+
Object.assign(body, req.vendor?.openai ?? {});
|
|
7904
|
+
return { body, degradations };
|
|
7905
|
+
}
|
|
7906
|
+
function toCustomResponsesWire(req, model) {
|
|
7907
|
+
const degradations = [];
|
|
7908
|
+
const note = (d) => {
|
|
7909
|
+
if (!degradations.includes(d))
|
|
7910
|
+
degradations.push(d);
|
|
7911
|
+
};
|
|
7912
|
+
const input = [];
|
|
7913
|
+
if (req.betas?.includes(CONTEXT_1M_BETA))
|
|
7914
|
+
note("custom:context-1m-dropped");
|
|
7842
7915
|
for (const message of req.messages) {
|
|
7843
7916
|
const parts = [];
|
|
7844
7917
|
const inlined = message.role === "system";
|
|
7845
7918
|
if (inlined)
|
|
7846
|
-
note("
|
|
7919
|
+
note("custom:system-turn-inlined");
|
|
7847
7920
|
const role = inlined ? "user" : message.role;
|
|
7848
7921
|
const flush = () => {
|
|
7849
7922
|
if (parts.length === 0)
|
|
@@ -7868,9 +7941,7 @@ ${block.text}
|
|
|
7868
7941
|
});
|
|
7869
7942
|
break;
|
|
7870
7943
|
case "thinking":
|
|
7871
|
-
|
|
7872
|
-
note("openai:thinking-dropped");
|
|
7873
|
-
}
|
|
7944
|
+
note("custom:thinking-dropped");
|
|
7874
7945
|
break;
|
|
7875
7946
|
case "toolUse":
|
|
7876
7947
|
flush();
|
|
@@ -7890,7 +7961,7 @@ ${block.text}
|
|
|
7890
7961
|
});
|
|
7891
7962
|
break;
|
|
7892
7963
|
case "anthropicNative":
|
|
7893
|
-
note("
|
|
7964
|
+
note("custom:anthropic-native-block-dropped");
|
|
7894
7965
|
break;
|
|
7895
7966
|
}
|
|
7896
7967
|
}
|
|
@@ -7902,23 +7973,15 @@ ${block.text}
|
|
|
7902
7973
|
`);
|
|
7903
7974
|
if (instructions !== undefined && instructions.length > 0)
|
|
7904
7975
|
body.instructions = instructions;
|
|
7905
|
-
if (req.maxTokens !== undefined)
|
|
7906
|
-
|
|
7907
|
-
|
|
7908
|
-
|
|
7909
|
-
body.max_output_tokens = req.maxTokens;
|
|
7910
|
-
}
|
|
7911
|
-
if (req.temperature !== undefined) {
|
|
7912
|
-
if (opts.oauth)
|
|
7913
|
-
note("openai:temperature-dropped");
|
|
7914
|
-
else
|
|
7915
|
-
body.temperature = req.temperature;
|
|
7916
|
-
}
|
|
7976
|
+
if (req.maxTokens !== undefined)
|
|
7977
|
+
body.max_output_tokens = req.maxTokens;
|
|
7978
|
+
if (req.temperature !== undefined)
|
|
7979
|
+
body.temperature = req.temperature;
|
|
7917
7980
|
if (req.tools !== undefined) {
|
|
7918
|
-
const
|
|
7919
|
-
if (
|
|
7920
|
-
note("
|
|
7921
|
-
body.tools =
|
|
7981
|
+
const portable = req.tools.filter((t) => t.provider === "custom");
|
|
7982
|
+
if (portable.length !== req.tools.length)
|
|
7983
|
+
note("custom:anthropic-tool-dropped");
|
|
7984
|
+
body.tools = portable.map((t) => ({
|
|
7922
7985
|
type: "function",
|
|
7923
7986
|
name: t.name,
|
|
7924
7987
|
description: t.description,
|
|
@@ -7926,20 +7989,12 @@ ${block.text}
|
|
|
7926
7989
|
}));
|
|
7927
7990
|
}
|
|
7928
7991
|
if (req.toolChoice !== undefined)
|
|
7929
|
-
body.tool_choice =
|
|
7930
|
-
|
|
7931
|
-
|
|
7932
|
-
|
|
7933
|
-
|
|
7934
|
-
|
|
7935
|
-
body.reasoning = {
|
|
7936
|
-
effort: effort === "xhigh" || effort === "max" ? "high" : effort,
|
|
7937
|
-
summary: "auto"
|
|
7938
|
-
};
|
|
7939
|
-
if (req.reasoning.mode === "budget") {
|
|
7940
|
-
degradations.push("openai:reasoning-budget-dropped");
|
|
7941
|
-
}
|
|
7942
|
-
}
|
|
7992
|
+
body.tool_choice = encodeResponsesToolChoice(req.toolChoice);
|
|
7993
|
+
const effort = customEffort(req.reasoning);
|
|
7994
|
+
if (effort !== undefined)
|
|
7995
|
+
body.reasoning = { effort, summary: "auto" };
|
|
7996
|
+
else if (req.reasoning?.mode === "budget")
|
|
7997
|
+
note("custom:reasoning-budget-dropped");
|
|
7943
7998
|
Object.assign(body, req.vendor?.openai ?? {});
|
|
7944
7999
|
return { body, degradations };
|
|
7945
8000
|
}
|
|
@@ -7950,7 +8005,13 @@ function metadata(data) {
|
|
|
7950
8005
|
if (typeof origin !== "string" || protocol !== "chat_completions" && protocol !== "responses") {
|
|
7951
8006
|
throw new GatewayError("BAD_REQUEST", "custom credential has invalid endpoint metadata");
|
|
7952
8007
|
}
|
|
7953
|
-
|
|
8008
|
+
const basePath = typeof data.basePath === "string" ? data.basePath : "";
|
|
8009
|
+
return { origin, basePath, protocol };
|
|
8010
|
+
}
|
|
8011
|
+
function endpointUrl(origin, basePath, protocol) {
|
|
8012
|
+
const suffix = protocol === "chat_completions" ? "chat/completions" : "responses";
|
|
8013
|
+
const base = `${origin}${basePath}`.replace(/\/+$/, "");
|
|
8014
|
+
return base.endsWith("/v1") ? `${base}/${suffix}` : `${base}/v1/${suffix}`;
|
|
7954
8015
|
}
|
|
7955
8016
|
var customAdapter = {
|
|
7956
8017
|
id: "custom",
|
|
@@ -7960,15 +8021,15 @@ var customAdapter = {
|
|
|
7960
8021
|
if (apiKey === null) {
|
|
7961
8022
|
throw new GatewayError("AUTH", "custom credential has no API key", { provider: "custom" });
|
|
7962
8023
|
}
|
|
7963
|
-
const { origin, protocol } = metadata(req.credentials.providerData);
|
|
7964
|
-
const encoded = protocol === "chat_completions" ?
|
|
8024
|
+
const { origin, basePath, protocol } = metadata(req.credentials.providerData);
|
|
8025
|
+
const encoded = protocol === "chat_completions" ? toCustomChatWire(req.request, req.model) : toCustomResponsesWire(req.request, req.model);
|
|
7965
8026
|
const headers = [
|
|
7966
8027
|
["Content-Type", "application/json"],
|
|
7967
8028
|
["Authorization", `Bearer ${apiKey}`]
|
|
7968
8029
|
];
|
|
7969
8030
|
const res = await req.http({
|
|
7970
8031
|
provider: "custom",
|
|
7971
|
-
url:
|
|
8032
|
+
url: endpointUrl(origin, basePath, protocol),
|
|
7972
8033
|
method: "POST",
|
|
7973
8034
|
headers,
|
|
7974
8035
|
body: JSON.stringify({ ...encoded.body, stream: true }),
|
|
@@ -7980,8 +8041,8 @@ var customAdapter = {
|
|
|
7980
8041
|
throw new GatewayError("UPSTREAM", "empty response body", { provider: "custom" });
|
|
7981
8042
|
}
|
|
7982
8043
|
return {
|
|
7983
|
-
events: protocol === "chat_completions" ?
|
|
7984
|
-
degradations: encoded.degradations
|
|
8044
|
+
events: protocol === "chat_completions" ? decodeCustomChat(parseSse(res.body)) : decodeCustomResponses(parseSse(res.body)),
|
|
8045
|
+
degradations: encoded.degradations
|
|
7985
8046
|
};
|
|
7986
8047
|
}
|
|
7987
8048
|
};
|
|
@@ -8000,7 +8061,7 @@ function grokDeviceHeaders(providerData) {
|
|
|
8000
8061
|
import { createHash as createHash2 } from "crypto";
|
|
8001
8062
|
|
|
8002
8063
|
// packages/providers/src/grok/decode.ts
|
|
8003
|
-
var
|
|
8064
|
+
var ERROR_CODE = {
|
|
8004
8065
|
rate_limit_exceeded: "RATE_LIMIT",
|
|
8005
8066
|
insufficient_quota: "QUOTA_EXHAUSTED",
|
|
8006
8067
|
invalid_api_key: "AUTH",
|
|
@@ -8034,7 +8095,7 @@ var KNOWN_EVENTS2 = new Set([
|
|
|
8034
8095
|
"response.failed",
|
|
8035
8096
|
"error"
|
|
8036
8097
|
]);
|
|
8037
|
-
function
|
|
8098
|
+
function json3(data) {
|
|
8038
8099
|
try {
|
|
8039
8100
|
const v = JSON.parse(data);
|
|
8040
8101
|
return typeof v === "object" && v !== null ? v : null;
|
|
@@ -8069,7 +8130,7 @@ async function* decodeGrokResponses(messages) {
|
|
|
8069
8130
|
};
|
|
8070
8131
|
return;
|
|
8071
8132
|
}
|
|
8072
|
-
const d =
|
|
8133
|
+
const d = json3(msg.data);
|
|
8073
8134
|
if (d === null)
|
|
8074
8135
|
continue;
|
|
8075
8136
|
switch (msg.event) {
|
|
@@ -8162,7 +8223,7 @@ async function* decodeGrokResponses(messages) {
|
|
|
8162
8223
|
case "error": {
|
|
8163
8224
|
terminal = true;
|
|
8164
8225
|
const err = d.response?.error ?? d.error ?? {};
|
|
8165
|
-
const code =
|
|
8226
|
+
const code = ERROR_CODE[String(err.code ?? err.type)] ?? "UPSTREAM";
|
|
8166
8227
|
yield {
|
|
8167
8228
|
type: "error",
|
|
8168
8229
|
code,
|
|
@@ -8188,7 +8249,7 @@ async function* decodeGrokResponses(messages) {
|
|
|
8188
8249
|
// packages/providers/src/grok/wire.ts
|
|
8189
8250
|
import { createHash } from "crypto";
|
|
8190
8251
|
var MAX_TOOLS = 200;
|
|
8191
|
-
function
|
|
8252
|
+
function encodeToolChoice2(c) {
|
|
8192
8253
|
switch (c.type) {
|
|
8193
8254
|
case "auto":
|
|
8194
8255
|
return "auto";
|
|
@@ -8299,12 +8360,14 @@ ${block.text}
|
|
|
8299
8360
|
}));
|
|
8300
8361
|
}
|
|
8301
8362
|
if (req.toolChoice !== undefined)
|
|
8302
|
-
body.tool_choice =
|
|
8363
|
+
body.tool_choice = encodeToolChoice2(req.toolChoice);
|
|
8303
8364
|
if (req.reasoning !== undefined && req.reasoning.mode !== "off") {
|
|
8304
|
-
|
|
8305
|
-
body.reasoning = { effort, summary: "concise" };
|
|
8306
|
-
if (req.reasoning.mode === "budget")
|
|
8365
|
+
if (req.reasoning.mode === "budget") {
|
|
8307
8366
|
note("grok:reasoning-budget-dropped");
|
|
8367
|
+
} else {
|
|
8368
|
+
const effort = req.reasoning.effort ?? "medium";
|
|
8369
|
+
body.reasoning = { effort, summary: "concise" };
|
|
8370
|
+
}
|
|
8308
8371
|
}
|
|
8309
8372
|
Object.assign(body, req.vendor?.grok ?? {});
|
|
8310
8373
|
return { body, degradations };
|
|
@@ -8462,13 +8525,13 @@ function hasHeader(req, lowerName) {
|
|
|
8462
8525
|
return req.headers.some(([name]) => name.toLowerCase() === lowerName);
|
|
8463
8526
|
}
|
|
8464
8527
|
// packages/providers/src/kilo/decode.ts
|
|
8465
|
-
var
|
|
8528
|
+
var FINISH = {
|
|
8466
8529
|
stop: "endTurn",
|
|
8467
8530
|
length: "maxTokens",
|
|
8468
8531
|
tool_calls: "toolUse",
|
|
8469
8532
|
content_filter: "contentFilter"
|
|
8470
8533
|
};
|
|
8471
|
-
function
|
|
8534
|
+
function reasoningText2(delta) {
|
|
8472
8535
|
if (typeof delta.reasoning === "string" && delta.reasoning.length > 0)
|
|
8473
8536
|
return delta.reasoning;
|
|
8474
8537
|
if (typeof delta.reasoning_content === "string" && delta.reasoning_content.length > 0) {
|
|
@@ -8486,7 +8549,7 @@ function reasoningText(delta) {
|
|
|
8486
8549
|
return [];
|
|
8487
8550
|
}).join("");
|
|
8488
8551
|
}
|
|
8489
|
-
function
|
|
8552
|
+
function json4(data) {
|
|
8490
8553
|
try {
|
|
8491
8554
|
const v = JSON.parse(data);
|
|
8492
8555
|
return typeof v === "object" && v !== null ? v : null;
|
|
@@ -8508,7 +8571,7 @@ async function* decodeKiloChat(messages) {
|
|
|
8508
8571
|
done = true;
|
|
8509
8572
|
break;
|
|
8510
8573
|
}
|
|
8511
|
-
const d =
|
|
8574
|
+
const d = json4(msg.data);
|
|
8512
8575
|
if (d === null)
|
|
8513
8576
|
continue;
|
|
8514
8577
|
if (!started && (d.id !== undefined || d.model !== undefined)) {
|
|
@@ -8523,7 +8586,7 @@ async function* decodeKiloChat(messages) {
|
|
|
8523
8586
|
if (!choice)
|
|
8524
8587
|
continue;
|
|
8525
8588
|
const delta = choice.delta ?? {};
|
|
8526
|
-
const reasoning =
|
|
8589
|
+
const reasoning = reasoningText2(delta);
|
|
8527
8590
|
if (reasoning.length > 0) {
|
|
8528
8591
|
if (openKind !== "thinking") {
|
|
8529
8592
|
if (openKind !== undefined)
|
|
@@ -8579,7 +8642,7 @@ async function* decodeKiloChat(messages) {
|
|
|
8579
8642
|
}
|
|
8580
8643
|
}
|
|
8581
8644
|
if (typeof choice.finish_reason === "string") {
|
|
8582
|
-
stopReason =
|
|
8645
|
+
stopReason = FINISH[choice.finish_reason] ?? "endTurn";
|
|
8583
8646
|
}
|
|
8584
8647
|
}
|
|
8585
8648
|
if (done) {
|
|
@@ -8597,7 +8660,7 @@ async function* decodeKiloChat(messages) {
|
|
|
8597
8660
|
}
|
|
8598
8661
|
|
|
8599
8662
|
// packages/providers/src/kilo/wire.ts
|
|
8600
|
-
function
|
|
8663
|
+
function encodeToolChoice3(c) {
|
|
8601
8664
|
switch (c.type) {
|
|
8602
8665
|
case "auto":
|
|
8603
8666
|
return "auto";
|
|
@@ -8710,15 +8773,12 @@ function toKiloWire(req, model) {
|
|
|
8710
8773
|
}));
|
|
8711
8774
|
}
|
|
8712
8775
|
if (req.toolChoice !== undefined)
|
|
8713
|
-
body.tool_choice =
|
|
8776
|
+
body.tool_choice = encodeToolChoice3(req.toolChoice);
|
|
8714
8777
|
if (req.reasoning !== undefined && req.reasoning.mode !== "off") {
|
|
8715
8778
|
if (req.reasoning.mode === "budget") {
|
|
8716
8779
|
body.reasoning = { max_tokens: req.reasoning.budgetTokens };
|
|
8717
8780
|
} else {
|
|
8718
|
-
|
|
8719
|
-
if (effort === "xhigh" || effort === "max")
|
|
8720
|
-
note("kilo:reasoning-effort-clamped");
|
|
8721
|
-
body.reasoning = { effort: effort === "xhigh" || effort === "max" ? "high" : effort };
|
|
8781
|
+
body.reasoning = { effort: req.reasoning.effort ?? "medium" };
|
|
8722
8782
|
}
|
|
8723
8783
|
}
|
|
8724
8784
|
Object.assign(body, req.vendor?.kilo ?? {});
|
|
@@ -8788,6 +8848,208 @@ function kimiDeviceHeaders(providerData) {
|
|
|
8788
8848
|
["X-Msh-Os-Version", str(providerData.osVersion)]
|
|
8789
8849
|
];
|
|
8790
8850
|
}
|
|
8851
|
+
// packages/providers/src/kimi/decode.ts
|
|
8852
|
+
var FINISH2 = {
|
|
8853
|
+
stop: "endTurn",
|
|
8854
|
+
length: "maxTokens",
|
|
8855
|
+
tool_calls: "toolUse",
|
|
8856
|
+
content_filter: "contentFilter"
|
|
8857
|
+
};
|
|
8858
|
+
function json5(data) {
|
|
8859
|
+
try {
|
|
8860
|
+
const v = JSON.parse(data);
|
|
8861
|
+
return typeof v === "object" && v !== null ? v : null;
|
|
8862
|
+
} catch {
|
|
8863
|
+
return null;
|
|
8864
|
+
}
|
|
8865
|
+
}
|
|
8866
|
+
async function* decodeChat(messages) {
|
|
8867
|
+
let started = false;
|
|
8868
|
+
let done = false;
|
|
8869
|
+
let stopReason = "endTurn";
|
|
8870
|
+
let usage = { inputTokens: 0, outputTokens: 0, cacheReadTokens: 0, cacheWriteTokens: 0 };
|
|
8871
|
+
const toolIndex = new Map;
|
|
8872
|
+
let nextIndex = 0;
|
|
8873
|
+
let openKind;
|
|
8874
|
+
let openIndex = 0;
|
|
8875
|
+
for await (const msg of messages) {
|
|
8876
|
+
if (msg.data === "[DONE]") {
|
|
8877
|
+
done = true;
|
|
8878
|
+
break;
|
|
8879
|
+
}
|
|
8880
|
+
const d = json5(msg.data);
|
|
8881
|
+
if (d === null)
|
|
8882
|
+
continue;
|
|
8883
|
+
if (!started && (d.id !== undefined || d.model !== undefined)) {
|
|
8884
|
+
started = true;
|
|
8885
|
+
yield { type: "start", id: String(d.id ?? ""), model: String(d.model ?? "") };
|
|
8886
|
+
}
|
|
8887
|
+
if (d.usage) {
|
|
8888
|
+
const details = d.usage.prompt_tokens_details;
|
|
8889
|
+
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);
|
|
8890
|
+
}
|
|
8891
|
+
const choice = d.choices?.[0];
|
|
8892
|
+
if (!choice)
|
|
8893
|
+
continue;
|
|
8894
|
+
const delta = choice.delta ?? {};
|
|
8895
|
+
if (typeof delta.content === "string" && delta.content.length > 0) {
|
|
8896
|
+
if (openKind !== "text") {
|
|
8897
|
+
if (openKind !== undefined)
|
|
8898
|
+
yield { type: "blockEnd", index: openIndex };
|
|
8899
|
+
openKind = "text";
|
|
8900
|
+
openIndex = nextIndex++;
|
|
8901
|
+
yield { type: "blockStart", index: openIndex, block: { type: "text" } };
|
|
8902
|
+
}
|
|
8903
|
+
yield {
|
|
8904
|
+
type: "blockDelta",
|
|
8905
|
+
index: openIndex,
|
|
8906
|
+
delta: { type: "text", text: delta.content }
|
|
8907
|
+
};
|
|
8908
|
+
}
|
|
8909
|
+
for (const call of delta.tool_calls ?? []) {
|
|
8910
|
+
const wireIndex = call.index ?? 0;
|
|
8911
|
+
let index = toolIndex.get(wireIndex);
|
|
8912
|
+
if (index === undefined) {
|
|
8913
|
+
if (openKind !== undefined)
|
|
8914
|
+
yield { type: "blockEnd", index: openIndex };
|
|
8915
|
+
index = nextIndex++;
|
|
8916
|
+
toolIndex.set(wireIndex, index);
|
|
8917
|
+
openKind = "tool";
|
|
8918
|
+
openIndex = index;
|
|
8919
|
+
yield {
|
|
8920
|
+
type: "blockStart",
|
|
8921
|
+
index,
|
|
8922
|
+
block: {
|
|
8923
|
+
type: "toolUse",
|
|
8924
|
+
id: String(call.id ?? `call_${wireIndex}`),
|
|
8925
|
+
name: String(call.function?.name ?? "")
|
|
8926
|
+
}
|
|
8927
|
+
};
|
|
8928
|
+
}
|
|
8929
|
+
const args = call.function?.arguments;
|
|
8930
|
+
if (typeof args === "string" && args.length > 0) {
|
|
8931
|
+
yield { type: "blockDelta", index, delta: { type: "toolJson", partial: args } };
|
|
8932
|
+
}
|
|
8933
|
+
}
|
|
8934
|
+
if (typeof choice.finish_reason === "string") {
|
|
8935
|
+
stopReason = FINISH2[choice.finish_reason] ?? "endTurn";
|
|
8936
|
+
}
|
|
8937
|
+
}
|
|
8938
|
+
if (done) {
|
|
8939
|
+
if (openKind !== undefined)
|
|
8940
|
+
yield { type: "blockEnd", index: openIndex };
|
|
8941
|
+
yield { type: "end", stopReason, usage };
|
|
8942
|
+
} else {
|
|
8943
|
+
yield {
|
|
8944
|
+
type: "error",
|
|
8945
|
+
code: "UPSTREAM",
|
|
8946
|
+
message: "upstream stream ended before [DONE]",
|
|
8947
|
+
retryable: RETRYABLE.UPSTREAM
|
|
8948
|
+
};
|
|
8949
|
+
}
|
|
8950
|
+
}
|
|
8951
|
+
|
|
8952
|
+
// packages/providers/src/kimi/wire.ts
|
|
8953
|
+
function encodeToolChoice4(c) {
|
|
8954
|
+
switch (c.type) {
|
|
8955
|
+
case "auto":
|
|
8956
|
+
return "auto";
|
|
8957
|
+
case "any":
|
|
8958
|
+
return "required";
|
|
8959
|
+
case "none":
|
|
8960
|
+
return "none";
|
|
8961
|
+
case "tool":
|
|
8962
|
+
return { type: "function", function: { name: c.name } };
|
|
8963
|
+
}
|
|
8964
|
+
}
|
|
8965
|
+
function toChatWire(req, model, vendor = "kimi") {
|
|
8966
|
+
const degradations = [];
|
|
8967
|
+
const note = (d) => {
|
|
8968
|
+
if (!degradations.includes(d))
|
|
8969
|
+
degradations.push(d);
|
|
8970
|
+
};
|
|
8971
|
+
if (req.betas?.includes(CONTEXT_1M_BETA))
|
|
8972
|
+
note("kimi:context-1m-dropped");
|
|
8973
|
+
const messages = [];
|
|
8974
|
+
const system = req.system?.flatMap((b) => b.type === "text" ? [b.text] : []).join(`
|
|
8975
|
+
|
|
8976
|
+
`);
|
|
8977
|
+
if (system !== undefined && system.length > 0)
|
|
8978
|
+
messages.push({ role: "system", content: system });
|
|
8979
|
+
for (const message of req.messages) {
|
|
8980
|
+
const text = [];
|
|
8981
|
+
const toolCalls = [];
|
|
8982
|
+
for (const block of message.content) {
|
|
8983
|
+
switch (block.type) {
|
|
8984
|
+
case "text":
|
|
8985
|
+
text.push(block.text);
|
|
8986
|
+
break;
|
|
8987
|
+
case "image":
|
|
8988
|
+
note("kimi:images-dropped");
|
|
8989
|
+
break;
|
|
8990
|
+
case "thinking":
|
|
8991
|
+
note("kimi:thinking-dropped");
|
|
8992
|
+
break;
|
|
8993
|
+
case "toolUse":
|
|
8994
|
+
toolCalls.push({
|
|
8995
|
+
id: block.id,
|
|
8996
|
+
type: "function",
|
|
8997
|
+
function: { name: block.name, arguments: JSON.stringify(block.input) }
|
|
8998
|
+
});
|
|
8999
|
+
break;
|
|
9000
|
+
case "toolResult":
|
|
9001
|
+
messages.push({
|
|
9002
|
+
role: "tool",
|
|
9003
|
+
tool_call_id: block.toolUseId,
|
|
9004
|
+
content: block.content
|
|
9005
|
+
});
|
|
9006
|
+
break;
|
|
9007
|
+
case "anthropicNative":
|
|
9008
|
+
note("kimi:anthropic-native-block-dropped");
|
|
9009
|
+
break;
|
|
9010
|
+
}
|
|
9011
|
+
}
|
|
9012
|
+
if (toolCalls.length > 0) {
|
|
9013
|
+
messages.push({
|
|
9014
|
+
role: message.role,
|
|
9015
|
+
content: text.length > 0 ? text.join(`
|
|
9016
|
+
`) : null,
|
|
9017
|
+
tool_calls: toolCalls
|
|
9018
|
+
});
|
|
9019
|
+
} else if (text.length > 0) {
|
|
9020
|
+
messages.push({ role: message.role, content: text.join(`
|
|
9021
|
+
`) });
|
|
9022
|
+
}
|
|
9023
|
+
}
|
|
9024
|
+
const body = {
|
|
9025
|
+
model,
|
|
9026
|
+
messages,
|
|
9027
|
+
stream: req.stream,
|
|
9028
|
+
stream_options: { include_usage: true }
|
|
9029
|
+
};
|
|
9030
|
+
if (req.maxTokens !== undefined)
|
|
9031
|
+
body.max_tokens = req.maxTokens;
|
|
9032
|
+
if (req.temperature !== undefined)
|
|
9033
|
+
body.temperature = req.temperature;
|
|
9034
|
+
if (req.stopSequences !== undefined)
|
|
9035
|
+
body.stop = req.stopSequences;
|
|
9036
|
+
if (req.tools !== undefined) {
|
|
9037
|
+
const custom = req.tools.filter((t) => t.provider === "custom");
|
|
9038
|
+
if (custom.length !== req.tools.length)
|
|
9039
|
+
note("kimi:anthropic-tool-dropped");
|
|
9040
|
+
body.tools = custom.map((t) => ({
|
|
9041
|
+
type: "function",
|
|
9042
|
+
function: { name: t.name, description: t.description, parameters: t.inputSchema }
|
|
9043
|
+
}));
|
|
9044
|
+
}
|
|
9045
|
+
if (req.toolChoice !== undefined)
|
|
9046
|
+
body.tool_choice = encodeToolChoice4(req.toolChoice);
|
|
9047
|
+
if (req.reasoning !== undefined)
|
|
9048
|
+
note("kimi:reasoning-dropped");
|
|
9049
|
+
Object.assign(body, req.vendor?.[vendor] ?? {});
|
|
9050
|
+
return { body, degradations };
|
|
9051
|
+
}
|
|
9052
|
+
|
|
8791
9053
|
// packages/providers/src/kimi/index.ts
|
|
8792
9054
|
var BASE_URL2 = "https://api.kimi.com/coding/v1/chat/completions";
|
|
8793
9055
|
var kimiAdapter = {
|
|
@@ -8822,6 +9084,276 @@ var kimiAdapter = {
|
|
|
8822
9084
|
return { events: decodeChat(parseSse(res.body)), degradations };
|
|
8823
9085
|
}
|
|
8824
9086
|
};
|
|
9087
|
+
// packages/providers/src/openai/decode.ts
|
|
9088
|
+
var ERROR_CODE2 = {
|
|
9089
|
+
rate_limit_exceeded: "RATE_LIMIT",
|
|
9090
|
+
insufficient_quota: "QUOTA_EXHAUSTED",
|
|
9091
|
+
invalid_api_key: "AUTH",
|
|
9092
|
+
server_error: "UPSTREAM",
|
|
9093
|
+
context_length_exceeded: "BAD_REQUEST",
|
|
9094
|
+
content_policy_violation: "CONTENT_FILTER"
|
|
9095
|
+
};
|
|
9096
|
+
function json6(data) {
|
|
9097
|
+
try {
|
|
9098
|
+
const v = JSON.parse(data);
|
|
9099
|
+
return typeof v === "object" && v !== null ? v : null;
|
|
9100
|
+
} catch {
|
|
9101
|
+
return null;
|
|
9102
|
+
}
|
|
9103
|
+
}
|
|
9104
|
+
async function* decodeResponses(messages) {
|
|
9105
|
+
const indices = new Map;
|
|
9106
|
+
let next = 0;
|
|
9107
|
+
const irIndex = (outputIndex, contentIndex = 0) => {
|
|
9108
|
+
const key = `${outputIndex}:${contentIndex}`;
|
|
9109
|
+
const existing = indices.get(key);
|
|
9110
|
+
if (existing !== undefined)
|
|
9111
|
+
return existing;
|
|
9112
|
+
const assigned = next++;
|
|
9113
|
+
indices.set(key, assigned);
|
|
9114
|
+
return assigned;
|
|
9115
|
+
};
|
|
9116
|
+
let sawToolCall = false;
|
|
9117
|
+
let terminal = false;
|
|
9118
|
+
const ownsBlock = new Set;
|
|
9119
|
+
for await (const msg of messages) {
|
|
9120
|
+
const d = json6(msg.data);
|
|
9121
|
+
if (d === null)
|
|
9122
|
+
continue;
|
|
9123
|
+
switch (msg.event) {
|
|
9124
|
+
case "response.created":
|
|
9125
|
+
yield {
|
|
9126
|
+
type: "start",
|
|
9127
|
+
id: String(d.response?.id ?? ""),
|
|
9128
|
+
model: String(d.response?.model ?? "")
|
|
9129
|
+
};
|
|
9130
|
+
break;
|
|
9131
|
+
case "response.output_item.added": {
|
|
9132
|
+
const item = d.item ?? {};
|
|
9133
|
+
if (item.type === "reasoning") {
|
|
9134
|
+
ownsBlock.add(d.output_index ?? 0);
|
|
9135
|
+
yield {
|
|
9136
|
+
type: "blockStart",
|
|
9137
|
+
index: irIndex(d.output_index ?? 0),
|
|
9138
|
+
block: { type: "thinking" }
|
|
9139
|
+
};
|
|
9140
|
+
} else if (item.type === "function_call") {
|
|
9141
|
+
sawToolCall = true;
|
|
9142
|
+
ownsBlock.add(d.output_index ?? 0);
|
|
9143
|
+
yield {
|
|
9144
|
+
type: "blockStart",
|
|
9145
|
+
index: irIndex(d.output_index ?? 0),
|
|
9146
|
+
block: { type: "toolUse", id: String(item.call_id), name: String(item.name) }
|
|
9147
|
+
};
|
|
9148
|
+
}
|
|
9149
|
+
break;
|
|
9150
|
+
}
|
|
9151
|
+
case "response.content_part.added":
|
|
9152
|
+
if (d.part?.type === "output_text") {
|
|
9153
|
+
yield {
|
|
9154
|
+
type: "blockStart",
|
|
9155
|
+
index: irIndex(d.output_index ?? 0, d.content_index ?? 0),
|
|
9156
|
+
block: { type: "text" }
|
|
9157
|
+
};
|
|
9158
|
+
}
|
|
9159
|
+
break;
|
|
9160
|
+
case "response.output_text.delta":
|
|
9161
|
+
yield {
|
|
9162
|
+
type: "blockDelta",
|
|
9163
|
+
index: irIndex(d.output_index ?? 0, d.content_index ?? 0),
|
|
9164
|
+
delta: { type: "text", text: String(d.delta ?? "") }
|
|
9165
|
+
};
|
|
9166
|
+
break;
|
|
9167
|
+
case "response.reasoning_summary_text.delta":
|
|
9168
|
+
yield {
|
|
9169
|
+
type: "blockDelta",
|
|
9170
|
+
index: irIndex(d.output_index ?? 0),
|
|
9171
|
+
delta: { type: "thinking", text: String(d.delta ?? "") }
|
|
9172
|
+
};
|
|
9173
|
+
break;
|
|
9174
|
+
case "response.function_call_arguments.delta":
|
|
9175
|
+
yield {
|
|
9176
|
+
type: "blockDelta",
|
|
9177
|
+
index: irIndex(d.output_index ?? 0),
|
|
9178
|
+
delta: { type: "toolJson", partial: String(d.delta ?? "") }
|
|
9179
|
+
};
|
|
9180
|
+
break;
|
|
9181
|
+
case "response.content_part.done":
|
|
9182
|
+
yield { type: "blockEnd", index: irIndex(d.output_index ?? 0, d.content_index ?? 0) };
|
|
9183
|
+
break;
|
|
9184
|
+
case "response.output_item.done": {
|
|
9185
|
+
const outputIndex = d.output_index ?? 0;
|
|
9186
|
+
if (ownsBlock.delete(outputIndex)) {
|
|
9187
|
+
yield { type: "blockEnd", index: irIndex(outputIndex) };
|
|
9188
|
+
}
|
|
9189
|
+
break;
|
|
9190
|
+
}
|
|
9191
|
+
case "response.completed":
|
|
9192
|
+
case "response.incomplete": {
|
|
9193
|
+
terminal = true;
|
|
9194
|
+
const r = d.response ?? {};
|
|
9195
|
+
const reason = r.incomplete_details?.reason;
|
|
9196
|
+
let stopReason = sawToolCall ? "toolUse" : "endTurn";
|
|
9197
|
+
if (reason === "max_output_tokens")
|
|
9198
|
+
stopReason = "maxTokens";
|
|
9199
|
+
else if (reason === "content_filter")
|
|
9200
|
+
stopReason = "contentFilter";
|
|
9201
|
+
yield {
|
|
9202
|
+
type: "end",
|
|
9203
|
+
stopReason,
|
|
9204
|
+
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)
|
|
9205
|
+
};
|
|
9206
|
+
break;
|
|
9207
|
+
}
|
|
9208
|
+
case "response.failed":
|
|
9209
|
+
case "error": {
|
|
9210
|
+
terminal = true;
|
|
9211
|
+
const err = d.response?.error ?? d.error ?? {};
|
|
9212
|
+
const code = ERROR_CODE2[String(err.code ?? err.type)] ?? "UPSTREAM";
|
|
9213
|
+
yield {
|
|
9214
|
+
type: "error",
|
|
9215
|
+
code,
|
|
9216
|
+
message: String(err.message ?? "upstream error"),
|
|
9217
|
+
retryable: RETRYABLE[code]
|
|
9218
|
+
};
|
|
9219
|
+
break;
|
|
9220
|
+
}
|
|
9221
|
+
default:
|
|
9222
|
+
break;
|
|
9223
|
+
}
|
|
9224
|
+
}
|
|
9225
|
+
if (!terminal) {
|
|
9226
|
+
yield {
|
|
9227
|
+
type: "error",
|
|
9228
|
+
code: "UPSTREAM",
|
|
9229
|
+
message: "upstream stream ended before response completion",
|
|
9230
|
+
retryable: RETRYABLE.UPSTREAM
|
|
9231
|
+
};
|
|
9232
|
+
}
|
|
9233
|
+
}
|
|
9234
|
+
|
|
9235
|
+
// packages/providers/src/openai/wire.ts
|
|
9236
|
+
function encodeToolChoice5(c) {
|
|
9237
|
+
switch (c.type) {
|
|
9238
|
+
case "auto":
|
|
9239
|
+
return "auto";
|
|
9240
|
+
case "any":
|
|
9241
|
+
return "required";
|
|
9242
|
+
case "none":
|
|
9243
|
+
return "none";
|
|
9244
|
+
case "tool":
|
|
9245
|
+
return { type: "function", name: c.name };
|
|
9246
|
+
}
|
|
9247
|
+
}
|
|
9248
|
+
function toResponsesWire(req, model, opts = { oauth: false }) {
|
|
9249
|
+
const degradations = [];
|
|
9250
|
+
const input = [];
|
|
9251
|
+
const note = (d) => {
|
|
9252
|
+
if (!degradations.includes(d))
|
|
9253
|
+
degradations.push(d);
|
|
9254
|
+
};
|
|
9255
|
+
if (req.betas?.includes(CONTEXT_1M_BETA))
|
|
9256
|
+
note("openai:context-1m-dropped");
|
|
9257
|
+
for (const message of req.messages) {
|
|
9258
|
+
const parts = [];
|
|
9259
|
+
const inlined = message.role === "system";
|
|
9260
|
+
if (inlined)
|
|
9261
|
+
note("openai:system-turn-inlined");
|
|
9262
|
+
const role = inlined ? "user" : message.role;
|
|
9263
|
+
const flush = () => {
|
|
9264
|
+
if (parts.length === 0)
|
|
9265
|
+
return;
|
|
9266
|
+
input.push({ type: "message", role, content: [...parts] });
|
|
9267
|
+
parts.length = 0;
|
|
9268
|
+
};
|
|
9269
|
+
for (const block of message.content) {
|
|
9270
|
+
switch (block.type) {
|
|
9271
|
+
case "text":
|
|
9272
|
+
parts.push({
|
|
9273
|
+
type: role === "assistant" ? "output_text" : "input_text",
|
|
9274
|
+
text: inlined ? `<system-reminder>
|
|
9275
|
+
${block.text}
|
|
9276
|
+
</system-reminder>` : block.text
|
|
9277
|
+
});
|
|
9278
|
+
break;
|
|
9279
|
+
case "image":
|
|
9280
|
+
parts.push({
|
|
9281
|
+
type: "input_image",
|
|
9282
|
+
image_url: `data:${block.mediaType};base64,${block.data}`
|
|
9283
|
+
});
|
|
9284
|
+
break;
|
|
9285
|
+
case "thinking":
|
|
9286
|
+
if (!degradations.includes("openai:thinking-dropped")) {
|
|
9287
|
+
note("openai:thinking-dropped");
|
|
9288
|
+
}
|
|
9289
|
+
break;
|
|
9290
|
+
case "toolUse":
|
|
9291
|
+
flush();
|
|
9292
|
+
input.push({
|
|
9293
|
+
type: "function_call",
|
|
9294
|
+
call_id: block.id,
|
|
9295
|
+
name: block.name,
|
|
9296
|
+
arguments: JSON.stringify(block.input)
|
|
9297
|
+
});
|
|
9298
|
+
break;
|
|
9299
|
+
case "toolResult":
|
|
9300
|
+
flush();
|
|
9301
|
+
input.push({
|
|
9302
|
+
type: "function_call_output",
|
|
9303
|
+
call_id: block.toolUseId,
|
|
9304
|
+
output: block.content
|
|
9305
|
+
});
|
|
9306
|
+
break;
|
|
9307
|
+
case "anthropicNative":
|
|
9308
|
+
note("openai:anthropic-native-block-dropped");
|
|
9309
|
+
break;
|
|
9310
|
+
}
|
|
9311
|
+
}
|
|
9312
|
+
flush();
|
|
9313
|
+
}
|
|
9314
|
+
const body = { model, input, stream: req.stream, store: false };
|
|
9315
|
+
const instructions = req.system?.flatMap((b) => b.type === "text" ? [b.text] : []).join(`
|
|
9316
|
+
|
|
9317
|
+
`);
|
|
9318
|
+
if (instructions !== undefined && instructions.length > 0)
|
|
9319
|
+
body.instructions = instructions;
|
|
9320
|
+
if (req.maxTokens !== undefined) {
|
|
9321
|
+
if (opts.oauth)
|
|
9322
|
+
note("openai:max-tokens-dropped");
|
|
9323
|
+
else
|
|
9324
|
+
body.max_output_tokens = req.maxTokens;
|
|
9325
|
+
}
|
|
9326
|
+
if (req.temperature !== undefined) {
|
|
9327
|
+
if (opts.oauth)
|
|
9328
|
+
note("openai:temperature-dropped");
|
|
9329
|
+
else
|
|
9330
|
+
body.temperature = req.temperature;
|
|
9331
|
+
}
|
|
9332
|
+
if (req.tools !== undefined) {
|
|
9333
|
+
const custom = req.tools.filter((t) => t.provider === "custom");
|
|
9334
|
+
if (custom.length !== req.tools.length)
|
|
9335
|
+
note("openai:anthropic-tool-dropped");
|
|
9336
|
+
body.tools = custom.map((t) => ({
|
|
9337
|
+
type: "function",
|
|
9338
|
+
name: t.name,
|
|
9339
|
+
description: t.description,
|
|
9340
|
+
parameters: t.inputSchema
|
|
9341
|
+
}));
|
|
9342
|
+
}
|
|
9343
|
+
if (req.toolChoice !== undefined)
|
|
9344
|
+
body.tool_choice = encodeToolChoice5(req.toolChoice);
|
|
9345
|
+
if (req.reasoning !== undefined && req.reasoning.mode !== "off") {
|
|
9346
|
+
if (req.reasoning.mode === "budget") {
|
|
9347
|
+
degradations.push("openai:reasoning-budget-dropped");
|
|
9348
|
+
} else {
|
|
9349
|
+
const effort = req.reasoning.effort ?? "medium";
|
|
9350
|
+
body.reasoning = { effort, summary: "auto" };
|
|
9351
|
+
}
|
|
9352
|
+
}
|
|
9353
|
+
Object.assign(body, req.vendor?.openai ?? {});
|
|
9354
|
+
return { body, degradations };
|
|
9355
|
+
}
|
|
9356
|
+
|
|
8825
9357
|
// packages/providers/src/openai/index.ts
|
|
8826
9358
|
var OAUTH_URL2 = "https://chatgpt.com/backend-api/codex/responses";
|
|
8827
9359
|
var API_URL3 = "https://api.openai.com/v1/responses";
|
|
@@ -9233,7 +9765,7 @@ __export(exports_external, {
|
|
|
9233
9765
|
ipv4: () => ipv42,
|
|
9234
9766
|
ipv6: () => ipv62,
|
|
9235
9767
|
iso: () => exports_iso,
|
|
9236
|
-
json: () =>
|
|
9768
|
+
json: () => json7,
|
|
9237
9769
|
jwt: () => jwt,
|
|
9238
9770
|
keyof: () => keyof,
|
|
9239
9771
|
ksuid: () => ksuid2,
|
|
@@ -20674,29 +21206,29 @@ var formatMap = {
|
|
|
20674
21206
|
regex: ""
|
|
20675
21207
|
};
|
|
20676
21208
|
var stringProcessor = (schema, ctx, _json, _params) => {
|
|
20677
|
-
const
|
|
20678
|
-
|
|
21209
|
+
const json7 = _json;
|
|
21210
|
+
json7.type = "string";
|
|
20679
21211
|
const { minimum, maximum, format, patterns, contentEncoding } = schema._zod.bag;
|
|
20680
21212
|
if (typeof minimum === "number")
|
|
20681
|
-
|
|
21213
|
+
json7.minLength = minimum;
|
|
20682
21214
|
if (typeof maximum === "number")
|
|
20683
|
-
|
|
21215
|
+
json7.maxLength = maximum;
|
|
20684
21216
|
if (format) {
|
|
20685
|
-
|
|
20686
|
-
if (
|
|
20687
|
-
delete
|
|
21217
|
+
json7.format = formatMap[format] ?? format;
|
|
21218
|
+
if (json7.format === "")
|
|
21219
|
+
delete json7.format;
|
|
20688
21220
|
if (format === "time") {
|
|
20689
|
-
delete
|
|
21221
|
+
delete json7.format;
|
|
20690
21222
|
}
|
|
20691
21223
|
}
|
|
20692
21224
|
if (contentEncoding)
|
|
20693
|
-
|
|
21225
|
+
json7.contentEncoding = contentEncoding;
|
|
20694
21226
|
if (patterns && patterns.size > 0) {
|
|
20695
21227
|
const regexes = [...patterns];
|
|
20696
21228
|
if (regexes.length === 1)
|
|
20697
|
-
|
|
21229
|
+
json7.pattern = regexes[0].source;
|
|
20698
21230
|
else if (regexes.length > 1) {
|
|
20699
|
-
|
|
21231
|
+
json7.allOf = [
|
|
20700
21232
|
...regexes.map((regex) => ({
|
|
20701
21233
|
...ctx.target === "draft-07" || ctx.target === "draft-04" || ctx.target === "openapi-3.0" ? { type: "string" } : {},
|
|
20702
21234
|
pattern: regex.source
|
|
@@ -20706,40 +21238,40 @@ var stringProcessor = (schema, ctx, _json, _params) => {
|
|
|
20706
21238
|
}
|
|
20707
21239
|
};
|
|
20708
21240
|
var numberProcessor = (schema, ctx, _json, _params) => {
|
|
20709
|
-
const
|
|
21241
|
+
const json7 = _json;
|
|
20710
21242
|
const { minimum, maximum, format, multipleOf, exclusiveMaximum, exclusiveMinimum } = schema._zod.bag;
|
|
20711
21243
|
if (typeof format === "string" && format.includes("int"))
|
|
20712
|
-
|
|
21244
|
+
json7.type = "integer";
|
|
20713
21245
|
else
|
|
20714
|
-
|
|
21246
|
+
json7.type = "number";
|
|
20715
21247
|
const exMin = typeof exclusiveMinimum === "number" && exclusiveMinimum >= (minimum ?? Number.NEGATIVE_INFINITY);
|
|
20716
21248
|
const exMax = typeof exclusiveMaximum === "number" && exclusiveMaximum <= (maximum ?? Number.POSITIVE_INFINITY);
|
|
20717
21249
|
const legacy = ctx.target === "draft-04" || ctx.target === "openapi-3.0";
|
|
20718
21250
|
if (exMin) {
|
|
20719
21251
|
if (legacy) {
|
|
20720
|
-
|
|
20721
|
-
|
|
21252
|
+
json7.minimum = exclusiveMinimum;
|
|
21253
|
+
json7.exclusiveMinimum = true;
|
|
20722
21254
|
} else {
|
|
20723
|
-
|
|
21255
|
+
json7.exclusiveMinimum = exclusiveMinimum;
|
|
20724
21256
|
}
|
|
20725
21257
|
} else if (typeof minimum === "number") {
|
|
20726
|
-
|
|
21258
|
+
json7.minimum = minimum;
|
|
20727
21259
|
}
|
|
20728
21260
|
if (exMax) {
|
|
20729
21261
|
if (legacy) {
|
|
20730
|
-
|
|
20731
|
-
|
|
21262
|
+
json7.maximum = exclusiveMaximum;
|
|
21263
|
+
json7.exclusiveMaximum = true;
|
|
20732
21264
|
} else {
|
|
20733
|
-
|
|
21265
|
+
json7.exclusiveMaximum = exclusiveMaximum;
|
|
20734
21266
|
}
|
|
20735
21267
|
} else if (typeof maximum === "number") {
|
|
20736
|
-
|
|
21268
|
+
json7.maximum = maximum;
|
|
20737
21269
|
}
|
|
20738
21270
|
if (typeof multipleOf === "number")
|
|
20739
|
-
|
|
21271
|
+
json7.multipleOf = multipleOf;
|
|
20740
21272
|
};
|
|
20741
|
-
var booleanProcessor = (_schema, _ctx,
|
|
20742
|
-
|
|
21273
|
+
var booleanProcessor = (_schema, _ctx, json7, _params) => {
|
|
21274
|
+
json7.type = "boolean";
|
|
20743
21275
|
};
|
|
20744
21276
|
var bigintProcessor = (_schema, ctx, _json, _params) => {
|
|
20745
21277
|
if (ctx.unrepresentable === "throw") {
|
|
@@ -20751,13 +21283,13 @@ var symbolProcessor = (_schema, ctx, _json, _params) => {
|
|
|
20751
21283
|
throw new Error("Symbols cannot be represented in JSON Schema");
|
|
20752
21284
|
}
|
|
20753
21285
|
};
|
|
20754
|
-
var nullProcessor = (_schema, ctx,
|
|
21286
|
+
var nullProcessor = (_schema, ctx, json7, _params) => {
|
|
20755
21287
|
if (ctx.target === "openapi-3.0") {
|
|
20756
|
-
|
|
20757
|
-
|
|
20758
|
-
|
|
21288
|
+
json7.type = "string";
|
|
21289
|
+
json7.nullable = true;
|
|
21290
|
+
json7.enum = [null];
|
|
20759
21291
|
} else {
|
|
20760
|
-
|
|
21292
|
+
json7.type = "null";
|
|
20761
21293
|
}
|
|
20762
21294
|
};
|
|
20763
21295
|
var undefinedProcessor = (_schema, ctx, _json, _params) => {
|
|
@@ -20770,8 +21302,8 @@ var voidProcessor = (_schema, ctx, _json, _params) => {
|
|
|
20770
21302
|
throw new Error("Void cannot be represented in JSON Schema");
|
|
20771
21303
|
}
|
|
20772
21304
|
};
|
|
20773
|
-
var neverProcessor = (_schema, _ctx,
|
|
20774
|
-
|
|
21305
|
+
var neverProcessor = (_schema, _ctx, json7, _params) => {
|
|
21306
|
+
json7.not = {};
|
|
20775
21307
|
};
|
|
20776
21308
|
var anyProcessor = (_schema, _ctx, _json, _params) => {};
|
|
20777
21309
|
var unknownProcessor = (_schema, _ctx, _json, _params) => {};
|
|
@@ -20780,16 +21312,16 @@ var dateProcessor = (_schema, ctx, _json, _params) => {
|
|
|
20780
21312
|
throw new Error("Date cannot be represented in JSON Schema");
|
|
20781
21313
|
}
|
|
20782
21314
|
};
|
|
20783
|
-
var enumProcessor = (schema, _ctx,
|
|
21315
|
+
var enumProcessor = (schema, _ctx, json7, _params) => {
|
|
20784
21316
|
const def = schema._zod.def;
|
|
20785
21317
|
const values = getEnumValues(def.entries);
|
|
20786
21318
|
if (values.every((v) => typeof v === "number"))
|
|
20787
|
-
|
|
21319
|
+
json7.type = "number";
|
|
20788
21320
|
if (values.every((v) => typeof v === "string"))
|
|
20789
|
-
|
|
20790
|
-
|
|
21321
|
+
json7.type = "string";
|
|
21322
|
+
json7.enum = values;
|
|
20791
21323
|
};
|
|
20792
|
-
var literalProcessor = (schema, ctx,
|
|
21324
|
+
var literalProcessor = (schema, ctx, json7, _params) => {
|
|
20793
21325
|
const def = schema._zod.def;
|
|
20794
21326
|
const vals = [];
|
|
20795
21327
|
for (const val of def.values) {
|
|
@@ -20809,22 +21341,22 @@ var literalProcessor = (schema, ctx, json6, _params) => {
|
|
|
20809
21341
|
}
|
|
20810
21342
|
if (vals.length === 0) {} else if (vals.length === 1) {
|
|
20811
21343
|
const val = vals[0];
|
|
20812
|
-
|
|
21344
|
+
json7.type = val === null ? "null" : typeof val;
|
|
20813
21345
|
if (ctx.target === "draft-04" || ctx.target === "openapi-3.0") {
|
|
20814
|
-
|
|
21346
|
+
json7.enum = [val];
|
|
20815
21347
|
} else {
|
|
20816
|
-
|
|
21348
|
+
json7.const = val;
|
|
20817
21349
|
}
|
|
20818
21350
|
} else {
|
|
20819
21351
|
if (vals.every((v) => typeof v === "number"))
|
|
20820
|
-
|
|
21352
|
+
json7.type = "number";
|
|
20821
21353
|
if (vals.every((v) => typeof v === "string"))
|
|
20822
|
-
|
|
21354
|
+
json7.type = "string";
|
|
20823
21355
|
if (vals.every((v) => typeof v === "boolean"))
|
|
20824
|
-
|
|
21356
|
+
json7.type = "boolean";
|
|
20825
21357
|
if (vals.every((v) => v === null))
|
|
20826
|
-
|
|
20827
|
-
|
|
21358
|
+
json7.type = "null";
|
|
21359
|
+
json7.enum = vals;
|
|
20828
21360
|
}
|
|
20829
21361
|
};
|
|
20830
21362
|
var nanProcessor = (_schema, ctx, _json, _params) => {
|
|
@@ -20832,16 +21364,16 @@ var nanProcessor = (_schema, ctx, _json, _params) => {
|
|
|
20832
21364
|
throw new Error("NaN cannot be represented in JSON Schema");
|
|
20833
21365
|
}
|
|
20834
21366
|
};
|
|
20835
|
-
var templateLiteralProcessor = (schema, _ctx,
|
|
20836
|
-
const _json =
|
|
21367
|
+
var templateLiteralProcessor = (schema, _ctx, json7, _params) => {
|
|
21368
|
+
const _json = json7;
|
|
20837
21369
|
const pattern = schema._zod.pattern;
|
|
20838
21370
|
if (!pattern)
|
|
20839
21371
|
throw new Error("Pattern not found in template literal");
|
|
20840
21372
|
_json.type = "string";
|
|
20841
21373
|
_json.pattern = pattern.source;
|
|
20842
21374
|
};
|
|
20843
|
-
var fileProcessor = (schema, _ctx,
|
|
20844
|
-
const _json =
|
|
21375
|
+
var fileProcessor = (schema, _ctx, json7, _params) => {
|
|
21376
|
+
const _json = json7;
|
|
20845
21377
|
const file = {
|
|
20846
21378
|
type: "string",
|
|
20847
21379
|
format: "binary",
|
|
@@ -20864,8 +21396,8 @@ var fileProcessor = (schema, _ctx, json6, _params) => {
|
|
|
20864
21396
|
Object.assign(_json, file);
|
|
20865
21397
|
}
|
|
20866
21398
|
};
|
|
20867
|
-
var successProcessor = (_schema, _ctx,
|
|
20868
|
-
|
|
21399
|
+
var successProcessor = (_schema, _ctx, json7, _params) => {
|
|
21400
|
+
json7.type = "boolean";
|
|
20869
21401
|
};
|
|
20870
21402
|
var customProcessor = (_schema, ctx, _json, _params) => {
|
|
20871
21403
|
if (ctx.unrepresentable === "throw") {
|
|
@@ -20893,27 +21425,27 @@ var setProcessor = (_schema, ctx, _json, _params) => {
|
|
|
20893
21425
|
}
|
|
20894
21426
|
};
|
|
20895
21427
|
var arrayProcessor = (schema, ctx, _json, params) => {
|
|
20896
|
-
const
|
|
21428
|
+
const json7 = _json;
|
|
20897
21429
|
const def = schema._zod.def;
|
|
20898
21430
|
const { minimum, maximum } = schema._zod.bag;
|
|
20899
21431
|
if (typeof minimum === "number")
|
|
20900
|
-
|
|
21432
|
+
json7.minItems = minimum;
|
|
20901
21433
|
if (typeof maximum === "number")
|
|
20902
|
-
|
|
20903
|
-
|
|
20904
|
-
|
|
21434
|
+
json7.maxItems = maximum;
|
|
21435
|
+
json7.type = "array";
|
|
21436
|
+
json7.items = process2(def.element, ctx, {
|
|
20905
21437
|
...params,
|
|
20906
21438
|
path: [...params.path, "items"]
|
|
20907
21439
|
});
|
|
20908
21440
|
};
|
|
20909
21441
|
var objectProcessor = (schema, ctx, _json, params) => {
|
|
20910
|
-
const
|
|
21442
|
+
const json7 = _json;
|
|
20911
21443
|
const def = schema._zod.def;
|
|
20912
|
-
|
|
20913
|
-
|
|
21444
|
+
json7.type = "object";
|
|
21445
|
+
json7.properties = {};
|
|
20914
21446
|
const shape = def.shape;
|
|
20915
21447
|
for (const key in shape) {
|
|
20916
|
-
|
|
21448
|
+
json7.properties[key] = process2(shape[key], ctx, {
|
|
20917
21449
|
...params,
|
|
20918
21450
|
path: [...params.path, "properties", key]
|
|
20919
21451
|
});
|
|
@@ -20928,21 +21460,21 @@ var objectProcessor = (schema, ctx, _json, params) => {
|
|
|
20928
21460
|
}
|
|
20929
21461
|
}));
|
|
20930
21462
|
if (requiredKeys.size > 0) {
|
|
20931
|
-
|
|
21463
|
+
json7.required = Array.from(requiredKeys);
|
|
20932
21464
|
}
|
|
20933
21465
|
if (def.catchall?._zod.def.type === "never") {
|
|
20934
|
-
|
|
21466
|
+
json7.additionalProperties = false;
|
|
20935
21467
|
} else if (!def.catchall) {
|
|
20936
21468
|
if (ctx.io === "output")
|
|
20937
|
-
|
|
21469
|
+
json7.additionalProperties = false;
|
|
20938
21470
|
} else if (def.catchall) {
|
|
20939
|
-
|
|
21471
|
+
json7.additionalProperties = process2(def.catchall, ctx, {
|
|
20940
21472
|
...params,
|
|
20941
21473
|
path: [...params.path, "additionalProperties"]
|
|
20942
21474
|
});
|
|
20943
21475
|
}
|
|
20944
21476
|
};
|
|
20945
|
-
var unionProcessor = (schema, ctx,
|
|
21477
|
+
var unionProcessor = (schema, ctx, json7, params) => {
|
|
20946
21478
|
const def = schema._zod.def;
|
|
20947
21479
|
const isExclusive = def.inclusive === false;
|
|
20948
21480
|
const options = def.options.map((x, i) => process2(x, ctx, {
|
|
@@ -20950,12 +21482,12 @@ var unionProcessor = (schema, ctx, json6, params) => {
|
|
|
20950
21482
|
path: [...params.path, isExclusive ? "oneOf" : "anyOf", i]
|
|
20951
21483
|
}));
|
|
20952
21484
|
if (isExclusive) {
|
|
20953
|
-
|
|
21485
|
+
json7.oneOf = options;
|
|
20954
21486
|
} else {
|
|
20955
|
-
|
|
21487
|
+
json7.anyOf = options;
|
|
20956
21488
|
}
|
|
20957
21489
|
};
|
|
20958
|
-
var intersectionProcessor = (schema, ctx,
|
|
21490
|
+
var intersectionProcessor = (schema, ctx, json7, params) => {
|
|
20959
21491
|
const def = schema._zod.def;
|
|
20960
21492
|
const a = process2(def.left, ctx, {
|
|
20961
21493
|
...params,
|
|
@@ -20970,12 +21502,12 @@ var intersectionProcessor = (schema, ctx, json6, params) => {
|
|
|
20970
21502
|
...isSimpleIntersection(a) ? a.allOf : [a],
|
|
20971
21503
|
...isSimpleIntersection(b) ? b.allOf : [b]
|
|
20972
21504
|
];
|
|
20973
|
-
|
|
21505
|
+
json7.allOf = allOf;
|
|
20974
21506
|
};
|
|
20975
21507
|
var tupleProcessor = (schema, ctx, _json, params) => {
|
|
20976
|
-
const
|
|
21508
|
+
const json7 = _json;
|
|
20977
21509
|
const def = schema._zod.def;
|
|
20978
|
-
|
|
21510
|
+
json7.type = "array";
|
|
20979
21511
|
const prefixPath = ctx.target === "draft-2020-12" ? "prefixItems" : "items";
|
|
20980
21512
|
const restPath = ctx.target === "draft-2020-12" ? "items" : ctx.target === "openapi-3.0" ? "items" : "additionalItems";
|
|
20981
21513
|
const prefixItems = def.items.map((x, i) => process2(x, ctx, {
|
|
@@ -20987,37 +21519,37 @@ var tupleProcessor = (schema, ctx, _json, params) => {
|
|
|
20987
21519
|
path: [...params.path, restPath, ...ctx.target === "openapi-3.0" ? [def.items.length] : []]
|
|
20988
21520
|
}) : null;
|
|
20989
21521
|
if (ctx.target === "draft-2020-12") {
|
|
20990
|
-
|
|
21522
|
+
json7.prefixItems = prefixItems;
|
|
20991
21523
|
if (rest) {
|
|
20992
|
-
|
|
21524
|
+
json7.items = rest;
|
|
20993
21525
|
}
|
|
20994
21526
|
} else if (ctx.target === "openapi-3.0") {
|
|
20995
|
-
|
|
21527
|
+
json7.items = {
|
|
20996
21528
|
anyOf: prefixItems
|
|
20997
21529
|
};
|
|
20998
21530
|
if (rest) {
|
|
20999
|
-
|
|
21531
|
+
json7.items.anyOf.push(rest);
|
|
21000
21532
|
}
|
|
21001
|
-
|
|
21533
|
+
json7.minItems = prefixItems.length;
|
|
21002
21534
|
if (!rest) {
|
|
21003
|
-
|
|
21535
|
+
json7.maxItems = prefixItems.length;
|
|
21004
21536
|
}
|
|
21005
21537
|
} else {
|
|
21006
|
-
|
|
21538
|
+
json7.items = prefixItems;
|
|
21007
21539
|
if (rest) {
|
|
21008
|
-
|
|
21540
|
+
json7.additionalItems = rest;
|
|
21009
21541
|
}
|
|
21010
21542
|
}
|
|
21011
21543
|
const { minimum, maximum } = schema._zod.bag;
|
|
21012
21544
|
if (typeof minimum === "number")
|
|
21013
|
-
|
|
21545
|
+
json7.minItems = minimum;
|
|
21014
21546
|
if (typeof maximum === "number")
|
|
21015
|
-
|
|
21547
|
+
json7.maxItems = maximum;
|
|
21016
21548
|
};
|
|
21017
21549
|
var recordProcessor = (schema, ctx, _json, params) => {
|
|
21018
|
-
const
|
|
21550
|
+
const json7 = _json;
|
|
21019
21551
|
const def = schema._zod.def;
|
|
21020
|
-
|
|
21552
|
+
json7.type = "object";
|
|
21021
21553
|
const keyType = def.keyType;
|
|
21022
21554
|
const keyBag = keyType._zod.bag;
|
|
21023
21555
|
const patterns = keyBag?.patterns;
|
|
@@ -21026,18 +21558,18 @@ var recordProcessor = (schema, ctx, _json, params) => {
|
|
|
21026
21558
|
...params,
|
|
21027
21559
|
path: [...params.path, "patternProperties", "*"]
|
|
21028
21560
|
});
|
|
21029
|
-
|
|
21561
|
+
json7.patternProperties = {};
|
|
21030
21562
|
for (const pattern of patterns) {
|
|
21031
|
-
|
|
21563
|
+
json7.patternProperties[pattern.source] = valueSchema;
|
|
21032
21564
|
}
|
|
21033
21565
|
} else {
|
|
21034
21566
|
if (ctx.target === "draft-07" || ctx.target === "draft-2020-12") {
|
|
21035
|
-
|
|
21567
|
+
json7.propertyNames = process2(def.keyType, ctx, {
|
|
21036
21568
|
...params,
|
|
21037
21569
|
path: [...params.path, "propertyNames"]
|
|
21038
21570
|
});
|
|
21039
21571
|
}
|
|
21040
|
-
|
|
21572
|
+
json7.additionalProperties = process2(def.valueType, ctx, {
|
|
21041
21573
|
...params,
|
|
21042
21574
|
path: [...params.path, "additionalProperties"]
|
|
21043
21575
|
});
|
|
@@ -21046,19 +21578,19 @@ var recordProcessor = (schema, ctx, _json, params) => {
|
|
|
21046
21578
|
if (keyValues) {
|
|
21047
21579
|
const validKeyValues = [...keyValues].filter((v) => typeof v === "string" || typeof v === "number");
|
|
21048
21580
|
if (validKeyValues.length > 0) {
|
|
21049
|
-
|
|
21581
|
+
json7.required = validKeyValues;
|
|
21050
21582
|
}
|
|
21051
21583
|
}
|
|
21052
21584
|
};
|
|
21053
|
-
var nullableProcessor = (schema, ctx,
|
|
21585
|
+
var nullableProcessor = (schema, ctx, json7, params) => {
|
|
21054
21586
|
const def = schema._zod.def;
|
|
21055
21587
|
const inner = process2(def.innerType, ctx, params);
|
|
21056
21588
|
const seen = ctx.seen.get(schema);
|
|
21057
21589
|
if (ctx.target === "openapi-3.0") {
|
|
21058
21590
|
seen.ref = def.innerType;
|
|
21059
|
-
|
|
21591
|
+
json7.nullable = true;
|
|
21060
21592
|
} else {
|
|
21061
|
-
|
|
21593
|
+
json7.anyOf = [inner, { type: "null" }];
|
|
21062
21594
|
}
|
|
21063
21595
|
};
|
|
21064
21596
|
var nonoptionalProcessor = (schema, ctx, _json, params) => {
|
|
@@ -21067,22 +21599,22 @@ var nonoptionalProcessor = (schema, ctx, _json, params) => {
|
|
|
21067
21599
|
const seen = ctx.seen.get(schema);
|
|
21068
21600
|
seen.ref = def.innerType;
|
|
21069
21601
|
};
|
|
21070
|
-
var defaultProcessor = (schema, ctx,
|
|
21602
|
+
var defaultProcessor = (schema, ctx, json7, params) => {
|
|
21071
21603
|
const def = schema._zod.def;
|
|
21072
21604
|
process2(def.innerType, ctx, params);
|
|
21073
21605
|
const seen = ctx.seen.get(schema);
|
|
21074
21606
|
seen.ref = def.innerType;
|
|
21075
|
-
|
|
21607
|
+
json7.default = JSON.parse(JSON.stringify(def.defaultValue));
|
|
21076
21608
|
};
|
|
21077
|
-
var prefaultProcessor = (schema, ctx,
|
|
21609
|
+
var prefaultProcessor = (schema, ctx, json7, params) => {
|
|
21078
21610
|
const def = schema._zod.def;
|
|
21079
21611
|
process2(def.innerType, ctx, params);
|
|
21080
21612
|
const seen = ctx.seen.get(schema);
|
|
21081
21613
|
seen.ref = def.innerType;
|
|
21082
21614
|
if (ctx.io === "input")
|
|
21083
|
-
|
|
21615
|
+
json7._prefault = JSON.parse(JSON.stringify(def.defaultValue));
|
|
21084
21616
|
};
|
|
21085
|
-
var catchProcessor = (schema, ctx,
|
|
21617
|
+
var catchProcessor = (schema, ctx, json7, params) => {
|
|
21086
21618
|
const def = schema._zod.def;
|
|
21087
21619
|
process2(def.innerType, ctx, params);
|
|
21088
21620
|
const seen = ctx.seen.get(schema);
|
|
@@ -21093,7 +21625,7 @@ var catchProcessor = (schema, ctx, json6, params) => {
|
|
|
21093
21625
|
} catch {
|
|
21094
21626
|
throw new Error("Dynamic catch values are not supported in JSON Schema");
|
|
21095
21627
|
}
|
|
21096
|
-
|
|
21628
|
+
json7.default = catchValue;
|
|
21097
21629
|
};
|
|
21098
21630
|
var pipeProcessor = (schema, ctx, _json, params) => {
|
|
21099
21631
|
const def = schema._zod.def;
|
|
@@ -21103,12 +21635,12 @@ var pipeProcessor = (schema, ctx, _json, params) => {
|
|
|
21103
21635
|
const seen = ctx.seen.get(schema);
|
|
21104
21636
|
seen.ref = innerType;
|
|
21105
21637
|
};
|
|
21106
|
-
var readonlyProcessor = (schema, ctx,
|
|
21638
|
+
var readonlyProcessor = (schema, ctx, json7, params) => {
|
|
21107
21639
|
const def = schema._zod.def;
|
|
21108
21640
|
process2(def.innerType, ctx, params);
|
|
21109
21641
|
const seen = ctx.seen.get(schema);
|
|
21110
21642
|
seen.ref = def.innerType;
|
|
21111
|
-
|
|
21643
|
+
json7.readOnly = true;
|
|
21112
21644
|
};
|
|
21113
21645
|
var promiseProcessor = (schema, ctx, _json, params) => {
|
|
21114
21646
|
const def = schema._zod.def;
|
|
@@ -21378,7 +21910,7 @@ __export(exports_schemas2, {
|
|
|
21378
21910
|
invertCodec: () => invertCodec,
|
|
21379
21911
|
ipv4: () => ipv42,
|
|
21380
21912
|
ipv6: () => ipv62,
|
|
21381
|
-
json: () =>
|
|
21913
|
+
json: () => json7,
|
|
21382
21914
|
jwt: () => jwt,
|
|
21383
21915
|
keyof: () => keyof,
|
|
21384
21916
|
ksuid: () => ksuid2,
|
|
@@ -21729,7 +22261,7 @@ var ZodType = /* @__PURE__ */ $constructor("ZodType", (inst, def) => {
|
|
|
21729
22261
|
var _ZodString = /* @__PURE__ */ $constructor("_ZodString", (inst, def) => {
|
|
21730
22262
|
$ZodString.init(inst, def);
|
|
21731
22263
|
ZodType.init(inst, def);
|
|
21732
|
-
inst._zod.processJSONSchema = (ctx,
|
|
22264
|
+
inst._zod.processJSONSchema = (ctx, json7, params) => stringProcessor(inst, ctx, json7, params);
|
|
21733
22265
|
const bag = inst._zod.bag;
|
|
21734
22266
|
inst.format = bag.format ?? null;
|
|
21735
22267
|
inst.minLength = bag.minimum ?? null;
|
|
@@ -22000,7 +22532,7 @@ function hash2(alg, params) {
|
|
|
22000
22532
|
var ZodNumber = /* @__PURE__ */ $constructor("ZodNumber", (inst, def) => {
|
|
22001
22533
|
$ZodNumber.init(inst, def);
|
|
22002
22534
|
ZodType.init(inst, def);
|
|
22003
|
-
inst._zod.processJSONSchema = (ctx,
|
|
22535
|
+
inst._zod.processJSONSchema = (ctx, json7, params) => numberProcessor(inst, ctx, json7, params);
|
|
22004
22536
|
_installLazyMethods(inst, "ZodNumber", {
|
|
22005
22537
|
gt(value, params) {
|
|
22006
22538
|
return this.check(_gt(value, params));
|
|
@@ -22080,7 +22612,7 @@ function uint32(params) {
|
|
|
22080
22612
|
var ZodBoolean = /* @__PURE__ */ $constructor("ZodBoolean", (inst, def) => {
|
|
22081
22613
|
$ZodBoolean.init(inst, def);
|
|
22082
22614
|
ZodType.init(inst, def);
|
|
22083
|
-
inst._zod.processJSONSchema = (ctx,
|
|
22615
|
+
inst._zod.processJSONSchema = (ctx, json7, params) => booleanProcessor(inst, ctx, json7, params);
|
|
22084
22616
|
});
|
|
22085
22617
|
function boolean2(params) {
|
|
22086
22618
|
return _boolean(ZodBoolean, params);
|
|
@@ -22088,7 +22620,7 @@ function boolean2(params) {
|
|
|
22088
22620
|
var ZodBigInt = /* @__PURE__ */ $constructor("ZodBigInt", (inst, def) => {
|
|
22089
22621
|
$ZodBigInt.init(inst, def);
|
|
22090
22622
|
ZodType.init(inst, def);
|
|
22091
|
-
inst._zod.processJSONSchema = (ctx,
|
|
22623
|
+
inst._zod.processJSONSchema = (ctx, json7, params) => bigintProcessor(inst, ctx, json7, params);
|
|
22092
22624
|
inst.gte = (value, params) => inst.check(_gte(value, params));
|
|
22093
22625
|
inst.min = (value, params) => inst.check(_gte(value, params));
|
|
22094
22626
|
inst.gt = (value, params) => inst.check(_gt(value, params));
|
|
@@ -22123,7 +22655,7 @@ function uint64(params) {
|
|
|
22123
22655
|
var ZodSymbol = /* @__PURE__ */ $constructor("ZodSymbol", (inst, def) => {
|
|
22124
22656
|
$ZodSymbol.init(inst, def);
|
|
22125
22657
|
ZodType.init(inst, def);
|
|
22126
|
-
inst._zod.processJSONSchema = (ctx,
|
|
22658
|
+
inst._zod.processJSONSchema = (ctx, json7, params) => symbolProcessor(inst, ctx, json7, params);
|
|
22127
22659
|
});
|
|
22128
22660
|
function symbol(params) {
|
|
22129
22661
|
return _symbol(ZodSymbol, params);
|
|
@@ -22131,7 +22663,7 @@ function symbol(params) {
|
|
|
22131
22663
|
var ZodUndefined = /* @__PURE__ */ $constructor("ZodUndefined", (inst, def) => {
|
|
22132
22664
|
$ZodUndefined.init(inst, def);
|
|
22133
22665
|
ZodType.init(inst, def);
|
|
22134
|
-
inst._zod.processJSONSchema = (ctx,
|
|
22666
|
+
inst._zod.processJSONSchema = (ctx, json7, params) => undefinedProcessor(inst, ctx, json7, params);
|
|
22135
22667
|
});
|
|
22136
22668
|
function _undefined3(params) {
|
|
22137
22669
|
return _undefined2(ZodUndefined, params);
|
|
@@ -22139,7 +22671,7 @@ function _undefined3(params) {
|
|
|
22139
22671
|
var ZodNull = /* @__PURE__ */ $constructor("ZodNull", (inst, def) => {
|
|
22140
22672
|
$ZodNull.init(inst, def);
|
|
22141
22673
|
ZodType.init(inst, def);
|
|
22142
|
-
inst._zod.processJSONSchema = (ctx,
|
|
22674
|
+
inst._zod.processJSONSchema = (ctx, json7, params) => nullProcessor(inst, ctx, json7, params);
|
|
22143
22675
|
});
|
|
22144
22676
|
function _null3(params) {
|
|
22145
22677
|
return _null2(ZodNull, params);
|
|
@@ -22147,7 +22679,7 @@ function _null3(params) {
|
|
|
22147
22679
|
var ZodAny = /* @__PURE__ */ $constructor("ZodAny", (inst, def) => {
|
|
22148
22680
|
$ZodAny.init(inst, def);
|
|
22149
22681
|
ZodType.init(inst, def);
|
|
22150
|
-
inst._zod.processJSONSchema = (ctx,
|
|
22682
|
+
inst._zod.processJSONSchema = (ctx, json7, params) => anyProcessor(inst, ctx, json7, params);
|
|
22151
22683
|
});
|
|
22152
22684
|
function any() {
|
|
22153
22685
|
return _any(ZodAny);
|
|
@@ -22155,7 +22687,7 @@ function any() {
|
|
|
22155
22687
|
var ZodUnknown = /* @__PURE__ */ $constructor("ZodUnknown", (inst, def) => {
|
|
22156
22688
|
$ZodUnknown.init(inst, def);
|
|
22157
22689
|
ZodType.init(inst, def);
|
|
22158
|
-
inst._zod.processJSONSchema = (ctx,
|
|
22690
|
+
inst._zod.processJSONSchema = (ctx, json7, params) => unknownProcessor(inst, ctx, json7, params);
|
|
22159
22691
|
});
|
|
22160
22692
|
function unknown() {
|
|
22161
22693
|
return _unknown(ZodUnknown);
|
|
@@ -22163,7 +22695,7 @@ function unknown() {
|
|
|
22163
22695
|
var ZodNever = /* @__PURE__ */ $constructor("ZodNever", (inst, def) => {
|
|
22164
22696
|
$ZodNever.init(inst, def);
|
|
22165
22697
|
ZodType.init(inst, def);
|
|
22166
|
-
inst._zod.processJSONSchema = (ctx,
|
|
22698
|
+
inst._zod.processJSONSchema = (ctx, json7, params) => neverProcessor(inst, ctx, json7, params);
|
|
22167
22699
|
});
|
|
22168
22700
|
function never(params) {
|
|
22169
22701
|
return _never(ZodNever, params);
|
|
@@ -22171,7 +22703,7 @@ function never(params) {
|
|
|
22171
22703
|
var ZodVoid = /* @__PURE__ */ $constructor("ZodVoid", (inst, def) => {
|
|
22172
22704
|
$ZodVoid.init(inst, def);
|
|
22173
22705
|
ZodType.init(inst, def);
|
|
22174
|
-
inst._zod.processJSONSchema = (ctx,
|
|
22706
|
+
inst._zod.processJSONSchema = (ctx, json7, params) => voidProcessor(inst, ctx, json7, params);
|
|
22175
22707
|
});
|
|
22176
22708
|
function _void2(params) {
|
|
22177
22709
|
return _void(ZodVoid, params);
|
|
@@ -22179,7 +22711,7 @@ function _void2(params) {
|
|
|
22179
22711
|
var ZodDate = /* @__PURE__ */ $constructor("ZodDate", (inst, def) => {
|
|
22180
22712
|
$ZodDate.init(inst, def);
|
|
22181
22713
|
ZodType.init(inst, def);
|
|
22182
|
-
inst._zod.processJSONSchema = (ctx,
|
|
22714
|
+
inst._zod.processJSONSchema = (ctx, json7, params) => dateProcessor(inst, ctx, json7, params);
|
|
22183
22715
|
inst.min = (value, params) => inst.check(_gte(value, params));
|
|
22184
22716
|
inst.max = (value, params) => inst.check(_lte(value, params));
|
|
22185
22717
|
const c = inst._zod.bag;
|
|
@@ -22192,7 +22724,7 @@ function date3(params) {
|
|
|
22192
22724
|
var ZodArray = /* @__PURE__ */ $constructor("ZodArray", (inst, def) => {
|
|
22193
22725
|
$ZodArray.init(inst, def);
|
|
22194
22726
|
ZodType.init(inst, def);
|
|
22195
|
-
inst._zod.processJSONSchema = (ctx,
|
|
22727
|
+
inst._zod.processJSONSchema = (ctx, json7, params) => arrayProcessor(inst, ctx, json7, params);
|
|
22196
22728
|
inst.element = def.element;
|
|
22197
22729
|
_installLazyMethods(inst, "ZodArray", {
|
|
22198
22730
|
min(n, params) {
|
|
@@ -22222,7 +22754,7 @@ function keyof(schema) {
|
|
|
22222
22754
|
var ZodObject = /* @__PURE__ */ $constructor("ZodObject", (inst, def) => {
|
|
22223
22755
|
$ZodObjectJIT.init(inst, def);
|
|
22224
22756
|
ZodType.init(inst, def);
|
|
22225
|
-
inst._zod.processJSONSchema = (ctx,
|
|
22757
|
+
inst._zod.processJSONSchema = (ctx, json7, params) => objectProcessor(inst, ctx, json7, params);
|
|
22226
22758
|
exports_util.defineLazy(inst, "shape", () => {
|
|
22227
22759
|
return def.shape;
|
|
22228
22760
|
});
|
|
@@ -22295,7 +22827,7 @@ function looseObject(shape, params) {
|
|
|
22295
22827
|
var ZodUnion = /* @__PURE__ */ $constructor("ZodUnion", (inst, def) => {
|
|
22296
22828
|
$ZodUnion.init(inst, def);
|
|
22297
22829
|
ZodType.init(inst, def);
|
|
22298
|
-
inst._zod.processJSONSchema = (ctx,
|
|
22830
|
+
inst._zod.processJSONSchema = (ctx, json7, params) => unionProcessor(inst, ctx, json7, params);
|
|
22299
22831
|
inst.options = def.options;
|
|
22300
22832
|
});
|
|
22301
22833
|
function union(options, params) {
|
|
@@ -22308,7 +22840,7 @@ function union(options, params) {
|
|
|
22308
22840
|
var ZodXor = /* @__PURE__ */ $constructor("ZodXor", (inst, def) => {
|
|
22309
22841
|
ZodUnion.init(inst, def);
|
|
22310
22842
|
$ZodXor.init(inst, def);
|
|
22311
|
-
inst._zod.processJSONSchema = (ctx,
|
|
22843
|
+
inst._zod.processJSONSchema = (ctx, json7, params) => unionProcessor(inst, ctx, json7, params);
|
|
22312
22844
|
inst.options = def.options;
|
|
22313
22845
|
});
|
|
22314
22846
|
function xor(options, params) {
|
|
@@ -22334,7 +22866,7 @@ function discriminatedUnion(discriminator, options, params) {
|
|
|
22334
22866
|
var ZodIntersection = /* @__PURE__ */ $constructor("ZodIntersection", (inst, def) => {
|
|
22335
22867
|
$ZodIntersection.init(inst, def);
|
|
22336
22868
|
ZodType.init(inst, def);
|
|
22337
|
-
inst._zod.processJSONSchema = (ctx,
|
|
22869
|
+
inst._zod.processJSONSchema = (ctx, json7, params) => intersectionProcessor(inst, ctx, json7, params);
|
|
22338
22870
|
});
|
|
22339
22871
|
function intersection(left, right) {
|
|
22340
22872
|
return new ZodIntersection({
|
|
@@ -22346,7 +22878,7 @@ function intersection(left, right) {
|
|
|
22346
22878
|
var ZodTuple = /* @__PURE__ */ $constructor("ZodTuple", (inst, def) => {
|
|
22347
22879
|
$ZodTuple.init(inst, def);
|
|
22348
22880
|
ZodType.init(inst, def);
|
|
22349
|
-
inst._zod.processJSONSchema = (ctx,
|
|
22881
|
+
inst._zod.processJSONSchema = (ctx, json7, params) => tupleProcessor(inst, ctx, json7, params);
|
|
22350
22882
|
inst.rest = (rest) => inst.clone({
|
|
22351
22883
|
...inst._zod.def,
|
|
22352
22884
|
rest
|
|
@@ -22366,7 +22898,7 @@ function tuple(items, _paramsOrRest, _params) {
|
|
|
22366
22898
|
var ZodRecord = /* @__PURE__ */ $constructor("ZodRecord", (inst, def) => {
|
|
22367
22899
|
$ZodRecord.init(inst, def);
|
|
22368
22900
|
ZodType.init(inst, def);
|
|
22369
|
-
inst._zod.processJSONSchema = (ctx,
|
|
22901
|
+
inst._zod.processJSONSchema = (ctx, json7, params) => recordProcessor(inst, ctx, json7, params);
|
|
22370
22902
|
inst.keyType = def.keyType;
|
|
22371
22903
|
inst.valueType = def.valueType;
|
|
22372
22904
|
});
|
|
@@ -22408,7 +22940,7 @@ function looseRecord(keyType, valueType, params) {
|
|
|
22408
22940
|
var ZodMap = /* @__PURE__ */ $constructor("ZodMap", (inst, def) => {
|
|
22409
22941
|
$ZodMap.init(inst, def);
|
|
22410
22942
|
ZodType.init(inst, def);
|
|
22411
|
-
inst._zod.processJSONSchema = (ctx,
|
|
22943
|
+
inst._zod.processJSONSchema = (ctx, json7, params) => mapProcessor(inst, ctx, json7, params);
|
|
22412
22944
|
inst.keyType = def.keyType;
|
|
22413
22945
|
inst.valueType = def.valueType;
|
|
22414
22946
|
inst.min = (...args) => inst.check(_minSize(...args));
|
|
@@ -22427,7 +22959,7 @@ function map(keyType, valueType, params) {
|
|
|
22427
22959
|
var ZodSet = /* @__PURE__ */ $constructor("ZodSet", (inst, def) => {
|
|
22428
22960
|
$ZodSet.init(inst, def);
|
|
22429
22961
|
ZodType.init(inst, def);
|
|
22430
|
-
inst._zod.processJSONSchema = (ctx,
|
|
22962
|
+
inst._zod.processJSONSchema = (ctx, json7, params) => setProcessor(inst, ctx, json7, params);
|
|
22431
22963
|
inst.min = (...args) => inst.check(_minSize(...args));
|
|
22432
22964
|
inst.nonempty = (params) => inst.check(_minSize(1, params));
|
|
22433
22965
|
inst.max = (...args) => inst.check(_maxSize(...args));
|
|
@@ -22443,7 +22975,7 @@ function set(valueType, params) {
|
|
|
22443
22975
|
var ZodEnum = /* @__PURE__ */ $constructor("ZodEnum", (inst, def) => {
|
|
22444
22976
|
$ZodEnum.init(inst, def);
|
|
22445
22977
|
ZodType.init(inst, def);
|
|
22446
|
-
inst._zod.processJSONSchema = (ctx,
|
|
22978
|
+
inst._zod.processJSONSchema = (ctx, json7, params) => enumProcessor(inst, ctx, json7, params);
|
|
22447
22979
|
inst.enum = def.entries;
|
|
22448
22980
|
inst.options = Object.values(def.entries);
|
|
22449
22981
|
const keys = new Set(Object.keys(def.entries));
|
|
@@ -22496,7 +23028,7 @@ function nativeEnum(entries, params) {
|
|
|
22496
23028
|
var ZodLiteral = /* @__PURE__ */ $constructor("ZodLiteral", (inst, def) => {
|
|
22497
23029
|
$ZodLiteral.init(inst, def);
|
|
22498
23030
|
ZodType.init(inst, def);
|
|
22499
|
-
inst._zod.processJSONSchema = (ctx,
|
|
23031
|
+
inst._zod.processJSONSchema = (ctx, json7, params) => literalProcessor(inst, ctx, json7, params);
|
|
22500
23032
|
inst.values = new Set(def.values);
|
|
22501
23033
|
Object.defineProperty(inst, "value", {
|
|
22502
23034
|
get() {
|
|
@@ -22517,7 +23049,7 @@ function literal(value, params) {
|
|
|
22517
23049
|
var ZodFile = /* @__PURE__ */ $constructor("ZodFile", (inst, def) => {
|
|
22518
23050
|
$ZodFile.init(inst, def);
|
|
22519
23051
|
ZodType.init(inst, def);
|
|
22520
|
-
inst._zod.processJSONSchema = (ctx,
|
|
23052
|
+
inst._zod.processJSONSchema = (ctx, json7, params) => fileProcessor(inst, ctx, json7, params);
|
|
22521
23053
|
inst.min = (size, params) => inst.check(_minSize(size, params));
|
|
22522
23054
|
inst.max = (size, params) => inst.check(_maxSize(size, params));
|
|
22523
23055
|
inst.mime = (types2, params) => inst.check(_mime(Array.isArray(types2) ? types2 : [types2], params));
|
|
@@ -22528,7 +23060,7 @@ function file(params) {
|
|
|
22528
23060
|
var ZodTransform = /* @__PURE__ */ $constructor("ZodTransform", (inst, def) => {
|
|
22529
23061
|
$ZodTransform.init(inst, def);
|
|
22530
23062
|
ZodType.init(inst, def);
|
|
22531
|
-
inst._zod.processJSONSchema = (ctx,
|
|
23063
|
+
inst._zod.processJSONSchema = (ctx, json7, params) => transformProcessor(inst, ctx, json7, params);
|
|
22532
23064
|
inst._zod.parse = (payload, _ctx) => {
|
|
22533
23065
|
if (_ctx.direction === "backward") {
|
|
22534
23066
|
throw new $ZodEncodeError(inst.constructor.name);
|
|
@@ -22568,7 +23100,7 @@ function transform(fn) {
|
|
|
22568
23100
|
var ZodOptional = /* @__PURE__ */ $constructor("ZodOptional", (inst, def) => {
|
|
22569
23101
|
$ZodOptional.init(inst, def);
|
|
22570
23102
|
ZodType.init(inst, def);
|
|
22571
|
-
inst._zod.processJSONSchema = (ctx,
|
|
23103
|
+
inst._zod.processJSONSchema = (ctx, json7, params) => optionalProcessor(inst, ctx, json7, params);
|
|
22572
23104
|
inst.unwrap = () => inst._zod.def.innerType;
|
|
22573
23105
|
});
|
|
22574
23106
|
function optional(innerType) {
|
|
@@ -22580,7 +23112,7 @@ function optional(innerType) {
|
|
|
22580
23112
|
var ZodExactOptional = /* @__PURE__ */ $constructor("ZodExactOptional", (inst, def) => {
|
|
22581
23113
|
$ZodExactOptional.init(inst, def);
|
|
22582
23114
|
ZodType.init(inst, def);
|
|
22583
|
-
inst._zod.processJSONSchema = (ctx,
|
|
23115
|
+
inst._zod.processJSONSchema = (ctx, json7, params) => optionalProcessor(inst, ctx, json7, params);
|
|
22584
23116
|
inst.unwrap = () => inst._zod.def.innerType;
|
|
22585
23117
|
});
|
|
22586
23118
|
function exactOptional(innerType) {
|
|
@@ -22592,7 +23124,7 @@ function exactOptional(innerType) {
|
|
|
22592
23124
|
var ZodNullable = /* @__PURE__ */ $constructor("ZodNullable", (inst, def) => {
|
|
22593
23125
|
$ZodNullable.init(inst, def);
|
|
22594
23126
|
ZodType.init(inst, def);
|
|
22595
|
-
inst._zod.processJSONSchema = (ctx,
|
|
23127
|
+
inst._zod.processJSONSchema = (ctx, json7, params) => nullableProcessor(inst, ctx, json7, params);
|
|
22596
23128
|
inst.unwrap = () => inst._zod.def.innerType;
|
|
22597
23129
|
});
|
|
22598
23130
|
function nullable(innerType) {
|
|
@@ -22607,7 +23139,7 @@ function nullish2(innerType) {
|
|
|
22607
23139
|
var ZodDefault = /* @__PURE__ */ $constructor("ZodDefault", (inst, def) => {
|
|
22608
23140
|
$ZodDefault.init(inst, def);
|
|
22609
23141
|
ZodType.init(inst, def);
|
|
22610
|
-
inst._zod.processJSONSchema = (ctx,
|
|
23142
|
+
inst._zod.processJSONSchema = (ctx, json7, params) => defaultProcessor(inst, ctx, json7, params);
|
|
22611
23143
|
inst.unwrap = () => inst._zod.def.innerType;
|
|
22612
23144
|
inst.removeDefault = inst.unwrap;
|
|
22613
23145
|
});
|
|
@@ -22623,7 +23155,7 @@ function _default2(innerType, defaultValue) {
|
|
|
22623
23155
|
var ZodPrefault = /* @__PURE__ */ $constructor("ZodPrefault", (inst, def) => {
|
|
22624
23156
|
$ZodPrefault.init(inst, def);
|
|
22625
23157
|
ZodType.init(inst, def);
|
|
22626
|
-
inst._zod.processJSONSchema = (ctx,
|
|
23158
|
+
inst._zod.processJSONSchema = (ctx, json7, params) => prefaultProcessor(inst, ctx, json7, params);
|
|
22627
23159
|
inst.unwrap = () => inst._zod.def.innerType;
|
|
22628
23160
|
});
|
|
22629
23161
|
function prefault(innerType, defaultValue) {
|
|
@@ -22638,7 +23170,7 @@ function prefault(innerType, defaultValue) {
|
|
|
22638
23170
|
var ZodNonOptional = /* @__PURE__ */ $constructor("ZodNonOptional", (inst, def) => {
|
|
22639
23171
|
$ZodNonOptional.init(inst, def);
|
|
22640
23172
|
ZodType.init(inst, def);
|
|
22641
|
-
inst._zod.processJSONSchema = (ctx,
|
|
23173
|
+
inst._zod.processJSONSchema = (ctx, json7, params) => nonoptionalProcessor(inst, ctx, json7, params);
|
|
22642
23174
|
inst.unwrap = () => inst._zod.def.innerType;
|
|
22643
23175
|
});
|
|
22644
23176
|
function nonoptional(innerType, params) {
|
|
@@ -22651,7 +23183,7 @@ function nonoptional(innerType, params) {
|
|
|
22651
23183
|
var ZodSuccess = /* @__PURE__ */ $constructor("ZodSuccess", (inst, def) => {
|
|
22652
23184
|
$ZodSuccess.init(inst, def);
|
|
22653
23185
|
ZodType.init(inst, def);
|
|
22654
|
-
inst._zod.processJSONSchema = (ctx,
|
|
23186
|
+
inst._zod.processJSONSchema = (ctx, json7, params) => successProcessor(inst, ctx, json7, params);
|
|
22655
23187
|
inst.unwrap = () => inst._zod.def.innerType;
|
|
22656
23188
|
});
|
|
22657
23189
|
function success(innerType) {
|
|
@@ -22663,7 +23195,7 @@ function success(innerType) {
|
|
|
22663
23195
|
var ZodCatch = /* @__PURE__ */ $constructor("ZodCatch", (inst, def) => {
|
|
22664
23196
|
$ZodCatch.init(inst, def);
|
|
22665
23197
|
ZodType.init(inst, def);
|
|
22666
|
-
inst._zod.processJSONSchema = (ctx,
|
|
23198
|
+
inst._zod.processJSONSchema = (ctx, json7, params) => catchProcessor(inst, ctx, json7, params);
|
|
22667
23199
|
inst.unwrap = () => inst._zod.def.innerType;
|
|
22668
23200
|
inst.removeCatch = inst.unwrap;
|
|
22669
23201
|
});
|
|
@@ -22677,7 +23209,7 @@ function _catch2(innerType, catchValue) {
|
|
|
22677
23209
|
var ZodNaN = /* @__PURE__ */ $constructor("ZodNaN", (inst, def) => {
|
|
22678
23210
|
$ZodNaN.init(inst, def);
|
|
22679
23211
|
ZodType.init(inst, def);
|
|
22680
|
-
inst._zod.processJSONSchema = (ctx,
|
|
23212
|
+
inst._zod.processJSONSchema = (ctx, json7, params) => nanProcessor(inst, ctx, json7, params);
|
|
22681
23213
|
});
|
|
22682
23214
|
function nan(params) {
|
|
22683
23215
|
return _nan(ZodNaN, params);
|
|
@@ -22685,7 +23217,7 @@ function nan(params) {
|
|
|
22685
23217
|
var ZodPipe = /* @__PURE__ */ $constructor("ZodPipe", (inst, def) => {
|
|
22686
23218
|
$ZodPipe.init(inst, def);
|
|
22687
23219
|
ZodType.init(inst, def);
|
|
22688
|
-
inst._zod.processJSONSchema = (ctx,
|
|
23220
|
+
inst._zod.processJSONSchema = (ctx, json7, params) => pipeProcessor(inst, ctx, json7, params);
|
|
22689
23221
|
inst.in = def.in;
|
|
22690
23222
|
inst.out = def.out;
|
|
22691
23223
|
});
|
|
@@ -22726,7 +23258,7 @@ var ZodPreprocess = /* @__PURE__ */ $constructor("ZodPreprocess", (inst, def) =>
|
|
|
22726
23258
|
var ZodReadonly = /* @__PURE__ */ $constructor("ZodReadonly", (inst, def) => {
|
|
22727
23259
|
$ZodReadonly.init(inst, def);
|
|
22728
23260
|
ZodType.init(inst, def);
|
|
22729
|
-
inst._zod.processJSONSchema = (ctx,
|
|
23261
|
+
inst._zod.processJSONSchema = (ctx, json7, params) => readonlyProcessor(inst, ctx, json7, params);
|
|
22730
23262
|
inst.unwrap = () => inst._zod.def.innerType;
|
|
22731
23263
|
});
|
|
22732
23264
|
function readonly(innerType) {
|
|
@@ -22738,7 +23270,7 @@ function readonly(innerType) {
|
|
|
22738
23270
|
var ZodTemplateLiteral = /* @__PURE__ */ $constructor("ZodTemplateLiteral", (inst, def) => {
|
|
22739
23271
|
$ZodTemplateLiteral.init(inst, def);
|
|
22740
23272
|
ZodType.init(inst, def);
|
|
22741
|
-
inst._zod.processJSONSchema = (ctx,
|
|
23273
|
+
inst._zod.processJSONSchema = (ctx, json7, params) => templateLiteralProcessor(inst, ctx, json7, params);
|
|
22742
23274
|
});
|
|
22743
23275
|
function templateLiteral(parts, params) {
|
|
22744
23276
|
return new ZodTemplateLiteral({
|
|
@@ -22750,7 +23282,7 @@ function templateLiteral(parts, params) {
|
|
|
22750
23282
|
var ZodLazy = /* @__PURE__ */ $constructor("ZodLazy", (inst, def) => {
|
|
22751
23283
|
$ZodLazy.init(inst, def);
|
|
22752
23284
|
ZodType.init(inst, def);
|
|
22753
|
-
inst._zod.processJSONSchema = (ctx,
|
|
23285
|
+
inst._zod.processJSONSchema = (ctx, json7, params) => lazyProcessor(inst, ctx, json7, params);
|
|
22754
23286
|
inst.unwrap = () => inst._zod.def.getter();
|
|
22755
23287
|
});
|
|
22756
23288
|
function lazy(getter) {
|
|
@@ -22762,7 +23294,7 @@ function lazy(getter) {
|
|
|
22762
23294
|
var ZodPromise = /* @__PURE__ */ $constructor("ZodPromise", (inst, def) => {
|
|
22763
23295
|
$ZodPromise.init(inst, def);
|
|
22764
23296
|
ZodType.init(inst, def);
|
|
22765
|
-
inst._zod.processJSONSchema = (ctx,
|
|
23297
|
+
inst._zod.processJSONSchema = (ctx, json7, params) => promiseProcessor(inst, ctx, json7, params);
|
|
22766
23298
|
inst.unwrap = () => inst._zod.def.innerType;
|
|
22767
23299
|
});
|
|
22768
23300
|
function promise(innerType) {
|
|
@@ -22774,7 +23306,7 @@ function promise(innerType) {
|
|
|
22774
23306
|
var ZodFunction = /* @__PURE__ */ $constructor("ZodFunction", (inst, def) => {
|
|
22775
23307
|
$ZodFunction.init(inst, def);
|
|
22776
23308
|
ZodType.init(inst, def);
|
|
22777
|
-
inst._zod.processJSONSchema = (ctx,
|
|
23309
|
+
inst._zod.processJSONSchema = (ctx, json7, params) => functionProcessor(inst, ctx, json7, params);
|
|
22778
23310
|
});
|
|
22779
23311
|
function _function(params) {
|
|
22780
23312
|
return new ZodFunction({
|
|
@@ -22786,7 +23318,7 @@ function _function(params) {
|
|
|
22786
23318
|
var ZodCustom = /* @__PURE__ */ $constructor("ZodCustom", (inst, def) => {
|
|
22787
23319
|
$ZodCustom.init(inst, def);
|
|
22788
23320
|
ZodType.init(inst, def);
|
|
22789
|
-
inst._zod.processJSONSchema = (ctx,
|
|
23321
|
+
inst._zod.processJSONSchema = (ctx, json7, params) => customProcessor(inst, ctx, json7, params);
|
|
22790
23322
|
});
|
|
22791
23323
|
function check(fn) {
|
|
22792
23324
|
const ch = new $ZodCheck({
|
|
@@ -22833,7 +23365,7 @@ var stringbool = (...args) => _stringbool({
|
|
|
22833
23365
|
Boolean: ZodBoolean,
|
|
22834
23366
|
String: ZodString
|
|
22835
23367
|
}, ...args);
|
|
22836
|
-
function
|
|
23368
|
+
function json7(params) {
|
|
22837
23369
|
const jsonSchema = lazy(() => {
|
|
22838
23370
|
return union([string2(params), number2(), boolean2(), _null3(), array(jsonSchema), record(string2(), jsonSchema)]);
|
|
22839
23371
|
});
|
|
@@ -24190,10 +24722,10 @@ function prepareArtifact(input) {
|
|
|
24190
24722
|
attempts,
|
|
24191
24723
|
error: error51.value
|
|
24192
24724
|
};
|
|
24193
|
-
const
|
|
24194
|
-
const size = encoder2.encode(
|
|
24725
|
+
const json8 = JSON.stringify(bounded);
|
|
24726
|
+
const size = encoder2.encode(json8).length;
|
|
24195
24727
|
if (size <= MAX_ARTIFACT_BYTES)
|
|
24196
|
-
return { artifact: bounded, json:
|
|
24728
|
+
return { artifact: bounded, json: json8 };
|
|
24197
24729
|
const marker = omission(size);
|
|
24198
24730
|
const omitted = omitBodies(bounded, marker);
|
|
24199
24731
|
const omittedJson = JSON.stringify(omitted);
|
|
@@ -24203,8 +24735,8 @@ function prepareArtifact(input) {
|
|
|
24203
24735
|
const stripped = { ...omitted, error: marker };
|
|
24204
24736
|
return { artifact: stripped, json: JSON.stringify(stripped) };
|
|
24205
24737
|
}
|
|
24206
|
-
async function sealArtifact(key,
|
|
24207
|
-
const bytes = encoder2.encode(await encrypt(key,
|
|
24738
|
+
async function sealArtifact(key, json8) {
|
|
24739
|
+
const bytes = encoder2.encode(await encrypt(key, json8));
|
|
24208
24740
|
return { bytes, sha256: await sha256Hex(bytes) };
|
|
24209
24741
|
}
|
|
24210
24742
|
async function readArtifact(key, dir, relPath, expectedSha256) {
|
|
@@ -26294,13 +26826,15 @@ function customProviderData(input) {
|
|
|
26294
26826
|
} catch {
|
|
26295
26827
|
throw new GatewayError("BAD_REQUEST", "origin: must be a valid URL");
|
|
26296
26828
|
}
|
|
26297
|
-
if (url2.protocol !== "http:" && url2.protocol !== "https:" || url2.hostname.length === 0 || url2.username.length > 0 || url2.password.length > 0 || url2.
|
|
26829
|
+
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) {
|
|
26298
26830
|
throw new GatewayError("BAD_REQUEST", "origin: must be an HTTP(S) server origin");
|
|
26299
26831
|
}
|
|
26300
|
-
|
|
26832
|
+
const basePath = url2.pathname.replace(/\/+$/, "");
|
|
26833
|
+
return { endpointId, endpointLabel, origin: url2.origin, basePath, protocol: input.protocol };
|
|
26301
26834
|
}
|
|
26302
26835
|
function sameCustomEndpoint(a, b) {
|
|
26303
|
-
|
|
26836
|
+
const basePath = typeof a.basePath === "string" ? a.basePath : "";
|
|
26837
|
+
return a.endpointId === b.endpointId && a.endpointLabel === b.endpointLabel && a.origin === b.origin && basePath === b.basePath && a.protocol === b.protocol;
|
|
26304
26838
|
}
|
|
26305
26839
|
async function createApiKeyCredential(store, input, logger2 = noopLogger) {
|
|
26306
26840
|
const provider = parseOrThrow(providerIdSchema, input.provider);
|
|
@@ -27430,10 +27964,10 @@ function emailFromIdToken(idToken) {
|
|
|
27430
27964
|
if (parts.length !== 3 || payload === undefined || payload.length === 0)
|
|
27431
27965
|
return null;
|
|
27432
27966
|
try {
|
|
27433
|
-
const
|
|
27434
|
-
if (!isRecord2(
|
|
27967
|
+
const json8 = JSON.parse(Buffer.from(payload, "base64url").toString("utf8"));
|
|
27968
|
+
if (!isRecord2(json8))
|
|
27435
27969
|
return null;
|
|
27436
|
-
return typeof
|
|
27970
|
+
return typeof json8.email === "string" && json8.email.trim().length > 0 ? json8.email : null;
|
|
27437
27971
|
} catch {
|
|
27438
27972
|
return null;
|
|
27439
27973
|
}
|
|
@@ -27836,12 +28370,12 @@ function decodeClaims(idToken) {
|
|
|
27836
28370
|
return { email: null, accountId: null };
|
|
27837
28371
|
}
|
|
27838
28372
|
try {
|
|
27839
|
-
const
|
|
27840
|
-
if (!isRecord5(
|
|
28373
|
+
const json8 = JSON.parse(Buffer.from(payload, "base64url").toString("utf8"));
|
|
28374
|
+
if (!isRecord5(json8))
|
|
27841
28375
|
return { email: null, accountId: null };
|
|
27842
|
-
const auth =
|
|
28376
|
+
const auth = json8["https://api.openai.com/auth"];
|
|
27843
28377
|
return {
|
|
27844
|
-
email: typeof
|
|
28378
|
+
email: typeof json8.email === "string" ? json8.email : null,
|
|
27845
28379
|
accountId: isRecord5(auth) ? nonBlankStringOrNull(auth.chatgpt_account_id) : null
|
|
27846
28380
|
};
|
|
27847
28381
|
} catch {
|
|
@@ -43444,6 +43978,15 @@ async function* openaiStream(events, requestId, created) {
|
|
|
43444
43978
|
finish_reason: null
|
|
43445
43979
|
}));
|
|
43446
43980
|
}
|
|
43981
|
+
} else if (event.block.type === "thinking") {
|
|
43982
|
+
if (!roleSent) {
|
|
43983
|
+
roleSent = true;
|
|
43984
|
+
yield emit(chunk(requestId, created, model, {
|
|
43985
|
+
index: 0,
|
|
43986
|
+
delta: { role: "assistant" },
|
|
43987
|
+
finish_reason: null
|
|
43988
|
+
}));
|
|
43989
|
+
}
|
|
43447
43990
|
} else if (event.block.type === "toolUse") {
|
|
43448
43991
|
const index = toolIndex.size;
|
|
43449
43992
|
toolIndex.set(event.index, index);
|
|
@@ -43475,6 +44018,12 @@ async function* openaiStream(events, requestId, created) {
|
|
|
43475
44018
|
delta: { content: d.text },
|
|
43476
44019
|
finish_reason: null
|
|
43477
44020
|
}));
|
|
44021
|
+
} else if (d.type === "thinking") {
|
|
44022
|
+
yield emit(chunk(requestId, created, model, {
|
|
44023
|
+
index: 0,
|
|
44024
|
+
delta: { reasoning_content: d.text },
|
|
44025
|
+
finish_reason: null
|
|
44026
|
+
}));
|
|
43478
44027
|
} else if (d.type === "toolJson") {
|
|
43479
44028
|
const index = toolIndex.get(event.index) ?? 0;
|
|
43480
44029
|
yield emit(chunk(requestId, created, model, {
|
|
@@ -43503,6 +44052,7 @@ async function* openaiStream(events, requestId, created) {
|
|
|
43503
44052
|
}
|
|
43504
44053
|
function openaiResponse(collected, requestId, created) {
|
|
43505
44054
|
const text = collected.content.flatMap((b) => b.type === "text" ? [b.text] : []).join("");
|
|
44055
|
+
const reasoning = collected.content.flatMap((b) => b.type === "thinking" ? [b.text] : []).join("");
|
|
43506
44056
|
const toolCalls = collected.content.flatMap((b) => b.type === "toolUse" ? [
|
|
43507
44057
|
{
|
|
43508
44058
|
id: b.id,
|
|
@@ -43521,6 +44071,7 @@ function openaiResponse(collected, requestId, created) {
|
|
|
43521
44071
|
message: {
|
|
43522
44072
|
role: "assistant",
|
|
43523
44073
|
content: toolCalls.length > 0 && text.length === 0 ? null : text,
|
|
44074
|
+
...reasoning.length > 0 ? { reasoning_content: reasoning } : {},
|
|
43524
44075
|
...toolCalls.length > 0 ? { tool_calls: toolCalls } : {}
|
|
43525
44076
|
},
|
|
43526
44077
|
finish_reason: FINISH3[collected.stopReason]
|
|
@@ -47435,7 +47986,7 @@ function readBlock(raw, role, path) {
|
|
|
47435
47986
|
function toIrToolChoice(c) {
|
|
47436
47987
|
return c.type === "tool" ? { type: "tool", name: c.name } : { type: c.type };
|
|
47437
47988
|
}
|
|
47438
|
-
var EFFORTS =
|
|
47989
|
+
var EFFORTS = REASONING_EFFORTS;
|
|
47439
47990
|
function readEffort(body2) {
|
|
47440
47991
|
if (!isRecord6(body2))
|
|
47441
47992
|
return;
|
|
@@ -47592,7 +48143,7 @@ var schema2 = exports_external.object({
|
|
|
47592
48143
|
exports_external.enum(["auto", "none", "required"]),
|
|
47593
48144
|
exports_external.object({ type: exports_external.literal("function"), function: exports_external.object({ name: exports_external.string() }) })
|
|
47594
48145
|
]).optional(),
|
|
47595
|
-
reasoning_effort: exports_external.enum(
|
|
48146
|
+
reasoning_effort: exports_external.enum(REASONING_EFFORTS).optional()
|
|
47596
48147
|
});
|
|
47597
48148
|
var KNOWN2 = [
|
|
47598
48149
|
"model",
|