@soiljs/models 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/README.md +47 -1
  2. package/dist/anthropic/index.d.ts +1 -1
  3. package/dist/anthropic/index.js +2 -2
  4. package/dist/chunk-4ONHQ7MX.js +10 -0
  5. package/dist/chunk-4ONHQ7MX.js.map +1 -0
  6. package/dist/chunk-5BTK5EOO.js +8 -0
  7. package/dist/{chunk-FVGWLCYD.js.map → chunk-5BTK5EOO.js.map} +1 -1
  8. package/dist/{chunk-BNO3LXK6.js → chunk-EFJFQCXF.js} +139 -4
  9. package/dist/chunk-EFJFQCXF.js.map +1 -0
  10. package/dist/{chunk-PYIYDQ4B.js → chunk-IBG2ZBNY.js} +3 -3
  11. package/dist/chunk-IBG2ZBNY.js.map +1 -0
  12. package/dist/chunk-LB4ZT5HL.js +10 -0
  13. package/dist/{chunk-TWKCB7MZ.js.map → chunk-LB4ZT5HL.js.map} +1 -1
  14. package/dist/{chunk-QLFAQAYL.js → chunk-OVT5IQM2.js} +13 -11
  15. package/dist/chunk-OVT5IQM2.js.map +1 -0
  16. package/dist/{chunk-ARTPLLDI.js → chunk-P42EM5RH.js} +3 -3
  17. package/dist/{chunk-ARTPLLDI.js.map → chunk-P42EM5RH.js.map} +1 -1
  18. package/dist/{chunk-N6FHK5GY.js → chunk-Q63QXXJS.js} +3 -3
  19. package/dist/{chunk-N6FHK5GY.js.map → chunk-Q63QXXJS.js.map} +1 -1
  20. package/dist/{chunk-QCBXB3MV.js → chunk-RTZJ6MXU.js} +3 -3
  21. package/dist/chunk-RTZJ6MXU.js.map +1 -0
  22. package/dist/chunk-XNDA5XM4.js +10 -0
  23. package/dist/{chunk-2CJ7L6CK.js.map → chunk-XNDA5XM4.js.map} +1 -1
  24. package/dist/{contracts-BHlnsD6v.d.ts → contracts-B5BERDgM.d.ts} +1 -1
  25. package/dist/deepseek/index.d.ts +5 -1
  26. package/dist/deepseek/index.js +2 -2
  27. package/dist/gemini/index.d.ts +3 -1
  28. package/dist/gemini/index.js +2 -2
  29. package/dist/glm/index.d.ts +1 -1
  30. package/dist/glm/index.js +2 -2
  31. package/dist/index.d.ts +7 -5
  32. package/dist/index.js +10 -9
  33. package/dist/kimi/index.d.ts +1 -1
  34. package/dist/kimi/index.js +2 -2
  35. package/dist/openai/index.d.ts +1 -1
  36. package/dist/openai/index.js +2 -2
  37. package/dist/openai-compatible/index.d.ts +21 -0
  38. package/dist/openai-compatible/index.js +4 -0
  39. package/dist/openai-compatible/index.js.map +1 -0
  40. package/dist/openrouter/index.d.ts +5 -1
  41. package/dist/openrouter/index.js +2 -2
  42. package/dist/recording/index.d.ts +1 -1
  43. package/dist/recording/index.js +10 -9
  44. package/dist/recording/index.js.map +1 -1
  45. package/package.json +5 -1
  46. package/dist/chunk-2CJ7L6CK.js +0 -10
  47. package/dist/chunk-BNO3LXK6.js.map +0 -1
  48. package/dist/chunk-FVGWLCYD.js +0 -8
  49. package/dist/chunk-PYIYDQ4B.js.map +0 -1
  50. package/dist/chunk-QCBXB3MV.js.map +0 -1
  51. package/dist/chunk-QLFAQAYL.js.map +0 -1
  52. package/dist/chunk-TWKCB7MZ.js +0 -10
package/README.md CHANGED
@@ -8,12 +8,13 @@
8
8
  pnpm add @soiljs/models
9
9
  ```
10
10
 
11
- 根入口与七个厂商入口使用 Web API,可运行于浏览器、Edge 和 Node.js ≥22.19;只有 `./recording` 导入 Node 文件系统。浏览器生产应用应通过服务端保护供应商密钥。
11
+ 根入口、七个厂商入口及兼容协议入口使用 Web API,可运行于浏览器、Edge 和 Node.js ≥22.19;只有 `./recording` 导入 Node 文件系统。浏览器生产应用应通过服务端保护供应商密钥。
12
12
 
13
13
  | 导出入口 | 公开对象与用途 |
14
14
  | --- | --- |
15
15
  | `@soiljs/models` | JSON/对话/结果/续接类型、`BoundModel`、`ProtocolObject`、`ModelError`、`ALL_PROTOCOLS`、`getProtocol` |
16
16
  | `@soiljs/models/openai` | `openaiResponses`、`openaiChat` |
17
+ | `@soiljs/models/openai-compatible` | `openaiCompatibleChat`、`OpenAICompatibleChatRequest`(根入口也导出) |
17
18
  | `@soiljs/models/anthropic` | `anthropicMessages` |
18
19
  | `@soiljs/models/gemini` | `geminiGenerateContent` |
19
20
  | `@soiljs/models/glm` | `glmChat`、`glmResponses` |
@@ -88,6 +89,51 @@ Node 内置 fetch 默认不会因设置 `HTTP_PROXY` / `HTTPS_PROXY` 就使用
88
89
 
89
90
  Anthropic 使用固定 `anthropic-version: 2026-10-21`,不提供采样或强制工具选择字段;DeepSeek Messages 不发送版本头。Gemini 使用原生 generateContent/streamGenerateContent。GLM Chat 不自动注入 `clearThinking: false`;OpenRouter 独立协议通过 `reasoning.effort` 使用七档 effort,不接受直连厂商的 thinking 配置。OpenRouter Responses 为无状态模式,拒绝调用者提供 `previous_response_id`;GLM Responses 只从自己的存储型 continuation 编码已有 response ID。
90
91
 
92
+ ## OpenAI-compatible v1 与 Vital 参数映射
93
+
94
+ `openaiCompatibleChat` 是第十四个协议,ID 为 `openai-compatible/v1/chat`,已加入 `ALL_PROTOCOLS` / `getProtocol`。它不改变 `openaiChat` 或原有十三个协议的身份、续接约束与未知参数拒绝规则。`baseUrl` 必填,不读取任何环境密钥或地址;任意非空 `model` 都可使用。
95
+
96
+ ```ts
97
+ import { openaiCompatibleChat } from "@soiljs/models/openai-compatible";
98
+
99
+ const model = openaiCompatibleChat.bind({
100
+ model: "my-custom-model",
101
+ baseUrl: "https://gateway.example/v1",
102
+ apiKey: "gateway-key",
103
+ fetch: pinnedFetch, // 调用方提供的 SSRF-safe fetch;所有协议(包括 Google)均直接使用
104
+ temperature: 0.5,
105
+ topP: 0.9,
106
+ maxOutputTokens: 1024,
107
+ maxTokensParam: "max_tokens",
108
+ includeStreamUsage: false,
109
+ responseFormat: { type: "json_object" },
110
+ toolChoice: "auto",
111
+ extraBody: { seed: 42 },
112
+ });
113
+ ```
114
+
115
+ `maxTokensParam` 默认 `max_tokens`,可显式切换为 `max_completion_tokens`;`includeStreamUsage` 默认 `false`,只有显式 `true` 的流请求发送 `stream_options: { include_usage: true }`。兼容协议支持 `temperature`(0–2)、`topP`(0–1)、正整数 `maxOutputTokens`、`responseFormat`(text / JSON object / JSON schema)、七档 `reasoningEffort`、`thinking: { type: "enabled" | "disabled" }`、`toolChoice`(none / auto / required / 指定函数),但不能同时设置 thinking 与 reasoningEffort。这些声明描述请求表面,不保证某个网关或模型支持所有组合;调用方选择明确的能力配置,服务端拒绝不会被重试或忽略。
116
+
117
+ `extraBody` 只接受普通 JSON 对象,限制为 UTF-8 64 KiB、32 层深度、10,000 个节点;拒绝循环、非有限数字、函数、undefined、访问器、隐藏字段、原型键、稀疏数组。顶层保留字段包括 model/messages/tools/stream/stream_options、连接/auth/header 字段、continuation/reasoning 状态及全部类型化选项(含 snake_case / camelCase 别名);即使类型化选项未设置,也必须走类型化入口。任何冲突在网络调用前抛出 `invalid_request`。扩展不会改变 fetch、URL、header 或工具续接。
118
+
119
+ 绑定时固定 fetch 引用,调用级输入无法替换它;注入 fetch 失败后不会回落到 global fetch。Google 原生传输同样适用,不需要 Vital 原来针对 Google 的豁免。兼容协议 JSON 与 SSE 保留 `reasoning_content`、`reasoning` 和有序 `reasoning_details`;下一轮必须携带原始 continuation,不可用展示文本替代。
120
+
121
+ | Vital provider | 推荐入口 | temperature / topP | 输出限制 / JSON | 推理与工具 |
122
+ | --- | --- | --- | --- | --- |
123
+ | openai | `openaiChat` / `openaiResponses` | 维持严格协议,不接受采样 | Chat: max_completion_tokens + responseFormat;Responses: max_output_tokens + textFormat | reasoningEffort + toolChoice;现行旗舰工具限制保持不变 |
124
+ | anthropic | `anthropicMessages` | 维持 2026-10-21 协议,不接受采样(含 thinking 禁用时) | maxOutputTokens 必填;无 JSON 格式选项 | effort + adaptive/disabled/between_tools;不开放强制工具选择 |
125
+ | google | `geminiGenerateContent` | temperature + **新增 topP** | maxOutputTokens + **新增 responseMimeType**(text/plain、application/json) | thinkingLevel;原生函数工具与 thoughtSignature |
126
+ | deepseek | `deepseekChat` | temperature + **新增 topP** | max_tokens + **新增 responseFormat**(text/json_object) | thinking / reasoningEffort;思考开启拒绝 required/指定工具 |
127
+ | moonshot | `kimiChat` | K3 固定采样,继续拒绝自定义 | max_completion_tokens;无 JSON 格式选项 | low/high/max effort;auto/none/required;完整 reasoning_content |
128
+ | openrouter | `openrouterChat` | **新增 temperature + topP** | max_tokens + **新增 responseFormat**(含 JSON schema) | reasoningEffort + **新增 toolChoice**;严格路由显式 requireParameters: true |
129
+ | groq | `openaiCompatibleChat` | temperature + topP | 可选 token 参数名 + responseFormat | 按网关能力显式选择 reasoning/thinking/toolChoice |
130
+ | mistral | `openaiCompatibleChat` | 同上 | 同上 | 同上 |
131
+ | xai | `openaiCompatibleChat` | 同上 | 同上 | 同上 |
132
+ | zhipu | `glmChat` | 维持 0–1 / 0.01–1、两位小数 | max_tokens + text/json_object | thinking + reasoningEffort;toolChoice:auto;保留历史思考需 clearThinking:false |
133
+ | custom / 自托管代理 | `openaiCompatibleChat` | 显式配置 | 显式配置 | 不猜测厂商或模型能力 |
134
+
135
+ 原有 OpenAI / Anthropic / Kimi 限制来自[十三协议基线](../../docs/06-model-definitions.md),不能把 Vital 的任意 native payload hook 直接复制到严格入口。新字段依据 [Google GenerationConfig](https://ai.google.dev/api/generate-content#v1beta.GenerationConfig)、[DeepSeek Chat](https://api-docs.deepseek.com/api/create-chat-completion/) 与 [OpenRouter parameters](https://openrouter.ai/docs/api/reference/parameters)。离线测试覆盖十个 provider、自定义模型、两轮工具调用、参数拒绝、三态用量和所有十四协议的 pinned fetch;不声明 vendor-live 覆盖。
136
+
91
137
  ## 结果、工具与续接状态
92
138
 
93
139
  结果包含 `protocolId`、`model`、`text`、`reasoningText`、`toolCalls`、`usage`、`finishReason`、可选 `continuation` 和 `rawResponse`。六类流事件为 `text.delta`、`reasoning.delta`、`tool_call.start`、`tool_call.delta`、`tool_call.done`、`response.completed`;最后一类携带完整 `response`。SSE 支持注释、拆分 UTF-8 与各厂商结束事件,提前关闭迭代器会释放响应体。
@@ -1,4 +1,4 @@
1
- import { p as ProtocolRequest, P as ProtocolObject, B as BindConfig } from '../contracts-BHlnsD6v.js';
1
+ import { p as ProtocolRequest, P as ProtocolObject, B as BindConfig } from '../contracts-B5BERDgM.js';
2
2
 
3
3
  type AnthropicThinking = {
4
4
  type: "adaptive";
@@ -1,4 +1,4 @@
1
- export { anthropicMessages } from '../chunk-2CJ7L6CK.js';
2
- import '../chunk-BNO3LXK6.js';
1
+ export { anthropicMessages } from '../chunk-XNDA5XM4.js';
2
+ import '../chunk-EFJFQCXF.js';
3
3
  //# sourceMappingURL=index.js.map
4
4
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,10 @@
1
+ import { createProtocol, specs } from './chunk-EFJFQCXF.js';
2
+
3
+ // src/openai-compatible/index.ts
4
+ var openaiCompatibleChat = createProtocol(
5
+ specs["openai-compatible/v1/chat"]
6
+ );
7
+
8
+ export { openaiCompatibleChat };
9
+ //# sourceMappingURL=chunk-4ONHQ7MX.js.map
10
+ //# sourceMappingURL=chunk-4ONHQ7MX.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/openai-compatible/index.ts"],"names":[],"mappings":";;;AAyBO,IAAM,oBAAA,GAAuB,cAAA;AAAA,EAClC,MAAM,2BAA2B;AACnC","file":"chunk-4ONHQ7MX.js","sourcesContent":["import type {\n ChatResponseFormat,\n ChatToolChoice,\n JsonValue,\n ProtocolRequest,\n SevenTierEffort,\n} from \"../contracts.js\";\nimport { createProtocol } from \"../transport/protocol.js\";\nimport { specs } from \"../transport/spec.js\";\n\n/** Explicit gateway contract; model capabilities are selected by the caller. */\nexport interface OpenAICompatibleChatRequest extends ProtocolRequest {\n baseUrl: string;\n temperature?: number;\n topP?: number;\n maxTokensParam?: \"max_tokens\" | \"max_completion_tokens\";\n includeStreamUsage?: boolean;\n responseFormat?: ChatResponseFormat;\n reasoningEffort?: SevenTierEffort;\n thinking?: { type: \"enabled\" | \"disabled\" };\n toolChoice?: ChatToolChoice;\n /** JSON extensions only; transport, continuation and typed fields are reserved. */\n extraBody?: Record<string, JsonValue>;\n}\n\nexport const openaiCompatibleChat = createProtocol<OpenAICompatibleChatRequest>(\n specs[\"openai-compatible/v1/chat\"],\n);\n"]}
@@ -0,0 +1,8 @@
1
+ import { createProtocol, specs } from './chunk-EFJFQCXF.js';
2
+
3
+ // src/kimi/index.ts
4
+ var kimiChat = createProtocol(specs["kimi/chat"]);
5
+
6
+ export { kimiChat };
7
+ //# sourceMappingURL=chunk-5BTK5EOO.js.map
8
+ //# sourceMappingURL=chunk-5BTK5EOO.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/kimi/index.ts"],"names":[],"mappings":";;;AAQO,IAAM,QAAA,GAAW,cAAA,CAAgC,KAAA,CAAM,WAAW,CAAC","file":"chunk-FVGWLCYD.js","sourcesContent":["import type { ProtocolRequest, ThreeTierEffort } from \"../contracts.js\";\nimport { createProtocol } from \"../transport/protocol.js\";\nimport { specs } from \"../transport/spec.js\";\nexport interface KimiChatRequest extends ProtocolRequest {\n reasoningEffort?: ThreeTierEffort;\n toolChoice?: \"auto\" | \"none\" | \"required\";\n cacheTtl?: \"5m\" | \"1h\";\n}\nexport const kimiChat = createProtocol<KimiChatRequest>(specs[\"kimi/chat\"]);\n"]}
1
+ {"version":3,"sources":["../src/kimi/index.ts"],"names":[],"mappings":";;;AAQO,IAAM,QAAA,GAAW,cAAA,CAAgC,KAAA,CAAM,WAAW,CAAC","file":"chunk-5BTK5EOO.js","sourcesContent":["import type { ProtocolRequest, ThreeTierEffort } from \"../contracts.js\";\nimport { createProtocol } from \"../transport/protocol.js\";\nimport { specs } from \"../transport/spec.js\";\nexport interface KimiChatRequest extends ProtocolRequest {\n reasoningEffort?: ThreeTierEffort;\n toolChoice?: \"auto\" | \"none\" | \"required\";\n cacheTtl?: \"5m\" | \"1h\";\n}\nexport const kimiChat = createProtocol<KimiChatRequest>(specs[\"kimi/chat\"]);\n"]}
@@ -377,6 +377,31 @@ var thinking = (values, defaultValue) => field("thinking.type", "thinking", {
377
377
  ...defaultValue ? { serverDefault: defaultValue } : {}
378
378
  });
379
379
  var specs = {
380
+ "openai-compatible/v1/chat": {
381
+ id: "openai-compatible/v1/chat",
382
+ family: "chat",
383
+ base: "",
384
+ path: "/chat/completions",
385
+ apiKeyEnv: [],
386
+ baseUrlEnv: [],
387
+ fields: {
388
+ temperature: field("temperature", "number", { minimum: 0, maximum: 2 }),
389
+ topP: field("top_p", "number", { minimum: 0, maximum: 1 }),
390
+ maxOutputTokens: tokens("max_tokens"),
391
+ maxTokensParam: effort("maxTokensParam", ["max_tokens", "max_completion_tokens"]),
392
+ includeStreamUsage: bool("includeStreamUsage"),
393
+ responseFormat: format("response_format", ["text", "json_object", "json_schema"]),
394
+ reasoningEffort: effort("reasoning_effort", seven),
395
+ thinking: thinking(["enabled", "disabled"]),
396
+ toolChoice: choice(["none", "auto", "required"], true),
397
+ extraBody: field("extraBody", "extraBody")
398
+ },
399
+ notes: [
400
+ "Version 1 explicit gateway profile; baseUrl is required and environment credentials are never inferred.",
401
+ "maxTokensParam defaults to max_tokens; includeStreamUsage defaults to false. These are local encoding controls, not wire fields.",
402
+ "Capabilities belong to the chosen gateway/model; extraBody cannot override typed, transport or continuation fields."
403
+ ]
404
+ },
380
405
  "openai/responses": {
381
406
  id: "openai/responses",
382
407
  family: "responses",
@@ -451,7 +476,12 @@ var specs = {
451
476
  "xhigh"
452
477
  ]),
453
478
  maxOutputTokens: tokens("generationConfig.maxOutputTokens"),
454
- temperature: field("generationConfig.temperature", "number")
479
+ temperature: field("generationConfig.temperature", "number"),
480
+ topP: field("generationConfig.topP", "number", { minimum: 0, maximum: 1 }),
481
+ responseMimeType: effort("generationConfig.responseMimeType", [
482
+ "text/plain",
483
+ "application/json"
484
+ ])
455
485
  },
456
486
  notes: [
457
487
  "Carbon/Argon default medium and reject xhigh; Neon/Hydrogen default high; Flash-Lite defaults minimal.",
@@ -534,6 +564,8 @@ var specs = {
534
564
  thinking: thinking(["enabled", "disabled"]),
535
565
  maxOutputTokens: tokens("max_tokens", 1, 393216),
536
566
  temperature: temp(2),
567
+ topP: field("top_p", "number", { minimum: 0, maximum: 1 }),
568
+ responseFormat: format("response_format", ["text", "json_object"]),
537
569
  toolChoice: choice(["none", "auto", "required"], true)
538
570
  },
539
571
  notes: [
@@ -584,6 +616,10 @@ var specs = {
584
616
  apiKeyEnv: ["OPENROUTER_CHAT_API_KEY", "OPENROUTER_API_KEY"],
585
617
  baseUrlEnv: ["OPENROUTER_CHAT_BASE_URL", "OPENROUTER_BASE_URL"],
586
618
  fields: {
619
+ temperature: field("temperature", "number", { minimum: 0, maximum: 2 }),
620
+ topP: field("top_p", "number", { minimum: 0, maximum: 1 }),
621
+ responseFormat: format("response_format", ["text", "json_object", "json_schema"]),
622
+ toolChoice: choice(["none", "auto", "required"], true),
587
623
  reasoningEffort: effort("reasoning.effort", seven),
588
624
  maxOutputTokens: tokens("max_tokens"),
589
625
  requireParameters: bool("provider.require_parameters", false)
@@ -641,6 +677,7 @@ function resolveBaseUrl(spec, explicit) {
641
677
  function metadata(spec) {
642
678
  const fields = {
643
679
  model: { wireKey: "model", required: true },
680
+ ...spec.id === "openai-compatible/v1/chat" ? { baseUrl: { wireKey: "baseUrl", required: true, type: "string" } } : {},
644
681
  messages: {
645
682
  wireKey: spec.family === "responses" ? "input" : spec.family === "gemini" ? "contents" : "messages",
646
683
  required: true
@@ -748,6 +785,87 @@ async function* readSse(connection) {
748
785
  }
749
786
  }
750
787
 
788
+ // src/transport/extra-body.ts
789
+ var normalized = (key) => key.replace(/[^a-z0-9]/gi, "").toLowerCase();
790
+ var reserved = [
791
+ "model",
792
+ "messages",
793
+ "tools",
794
+ "stream",
795
+ "stream_options",
796
+ "input",
797
+ "contents",
798
+ "headers",
799
+ "authorization",
800
+ "proxy-authorization",
801
+ "apiKey",
802
+ "x-api-key",
803
+ "x-goog-api-key",
804
+ "baseUrl",
805
+ "url",
806
+ "method",
807
+ "body",
808
+ "fetch",
809
+ "signal",
810
+ "timeoutMs",
811
+ "connection",
812
+ "continuation",
813
+ "previous_response_id",
814
+ "conversation",
815
+ "store",
816
+ "include",
817
+ "reasoning",
818
+ "reasoning_content",
819
+ "reasoning_details",
820
+ "encrypted_content",
821
+ "signature",
822
+ "max_tokens",
823
+ "max_completion_tokens",
824
+ "max_output_tokens"
825
+ ];
826
+ function validateExtraBody(value, spec) {
827
+ if (!value || typeof value !== "object" || Array.isArray(value))
828
+ badRequest("extraBody must be a JSON object");
829
+ const forbidden = new Set(
830
+ [
831
+ ...reserved,
832
+ ...Object.keys(spec.fields),
833
+ ...Object.values(spec.fields).map((field2) => field2.wireKey.split(".")[0])
834
+ ].map(normalized)
835
+ );
836
+ const ancestors = /* @__PURE__ */ new Set();
837
+ let nodes = 0;
838
+ const visit = (node, depth) => {
839
+ if (++nodes > 1e4 || depth > 32) badRequest("extraBody exceeds structural limits");
840
+ if (node === null || typeof node === "string" || typeof node === "boolean") return;
841
+ if (typeof node === "number" && Number.isFinite(node)) return;
842
+ if (!node || typeof node !== "object" || ancestors.has(node))
843
+ badRequest("extraBody must contain finite, acyclic JSON");
844
+ if (!Array.isArray(node) && ![Object.prototype, null].includes(Object.getPrototypeOf(node)))
845
+ badRequest("extraBody must contain plain JSON objects");
846
+ ancestors.add(node);
847
+ if (Array.isArray(node) && Object.keys(node).length !== node.length)
848
+ badRequest("extraBody cannot contain sparse or extended arrays");
849
+ for (const key of Reflect.ownKeys(node)) {
850
+ if (Array.isArray(node) && key === "length") continue;
851
+ if (typeof key !== "string" || ["__proto__", "constructor", "prototype"].includes(key))
852
+ badRequest("Invalid extraBody key");
853
+ if (Array.isArray(node) && (!/^(0|[1-9][0-9]*)$/.test(key) || Number(key) >= node.length))
854
+ badRequest("extraBody arrays may only contain indexed elements");
855
+ if (depth === 0 && forbidden.has(normalized(key)))
856
+ badRequest(`Reserved extraBody field: ${key}; use typed options`);
857
+ const property = Object.getOwnPropertyDescriptor(node, key);
858
+ if (!property.enumerable || !("value" in property))
859
+ badRequest("extraBody cannot contain accessors or hidden fields");
860
+ visit(property.value, depth + 1);
861
+ }
862
+ ancestors.delete(node);
863
+ };
864
+ visit(value, 0);
865
+ if (new TextEncoder().encode(JSON.stringify(value)).length > 65536)
866
+ badRequest("extraBody exceeds 64 KiB");
867
+ }
868
+
751
869
  // src/transport/validate.ts
752
870
  function keys(value, allowed, label) {
753
871
  if (!value || typeof value !== "object" || Array.isArray(value))
@@ -772,6 +890,10 @@ function jsonValue(value, ancestors = /* @__PURE__ */ new Set()) {
772
890
  ancestors.delete(value);
773
891
  }
774
892
  function validateField(value, field2, key, spec) {
893
+ if (field2.kind === "extraBody") {
894
+ validateExtraBody(value, spec);
895
+ return;
896
+ }
775
897
  if (field2.kind === "enum") {
776
898
  if (!field2.values?.includes(value)) badRequest(`Invalid ${key}`);
777
899
  } else if (field2.kind === "boolean") {
@@ -844,6 +966,11 @@ function validate(request, spec) {
844
966
  "request"
845
967
  );
846
968
  nonempty(row.model, "model");
969
+ if (spec.id === "openai-compatible/v1/chat") {
970
+ nonempty(row.baseUrl, "baseUrl");
971
+ if (row.thinking !== void 0 && row.reasoningEffort !== void 0)
972
+ badRequest("Choose thinking or reasoningEffort, not both");
973
+ }
847
974
  if (!Array.isArray(request.messages) || request.messages.length === 0)
848
975
  badRequest("messages must be a non-empty array");
849
976
  const resolvedBaseUrl = request.baseUrl !== void 0 ? request.baseUrl : env(spec.baseUrlEnv);
@@ -1186,11 +1313,19 @@ function encode(spec, request, stream = false) {
1186
1313
  }
1187
1314
  for (const [key2, field2] of Object.entries(spec.fields)) {
1188
1315
  if (row[key2] === void 0) continue;
1316
+ if (spec.id === "openai-compatible/v1/chat") {
1317
+ if (["extraBody", "maxTokensParam", "includeStreamUsage"].includes(key2)) continue;
1318
+ if (key2 === "maxOutputTokens") {
1319
+ body[String(row.maxTokensParam ?? "max_tokens")] = row[key2];
1320
+ continue;
1321
+ }
1322
+ }
1189
1323
  setPath(body, field2.kind === "thinking" ? "thinking" : field2.wireKey, row[key2]);
1190
1324
  }
1325
+ if (spec.id === "openai-compatible/v1/chat" && row.extraBody) Object.assign(body, row.extraBody);
1191
1326
  if (stream) {
1192
1327
  if (spec.family !== "gemini") body.stream = true;
1193
- if (spec.family === "chat" && !spec.id.startsWith("openrouter/"))
1328
+ if (spec.family === "chat" && !spec.id.startsWith("openrouter/") && (spec.id !== "openai-compatible/v1/chat" || row.includeStreamUsage === true))
1194
1329
  body.stream_options = spec.id === "glm/chat" ? { chunk_include_usage: true } : { include_usage: true };
1195
1330
  }
1196
1331
  const headers = new Headers(request.headers), key = resolveApiKey(spec, request.apiKey);
@@ -1689,5 +1824,5 @@ function createProtocol(spec) {
1689
1824
  }
1690
1825
 
1691
1826
  export { ModelError, abortError, canonical, createProtocol, emptyUsage, object, specs };
1692
- //# sourceMappingURL=chunk-BNO3LXK6.js.map
1693
- //# sourceMappingURL=chunk-BNO3LXK6.js.map
1827
+ //# sourceMappingURL=chunk-EFJFQCXF.js.map
1828
+ //# sourceMappingURL=chunk-EFJFQCXF.js.map