@foldrun/core 13.1.1 → 14.0.1

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.
@@ -1,5 +1,5 @@
1
1
  import { type WireFormat } from "./providers.ts";
2
- export type SupplyProviderName = "anthropic" | "openai" | "gemini" | "openrouter";
2
+ export type SupplyProviderName = "anthropic" | "openai" | "gemini" | "deepseek" | "moonshot";
3
3
  export interface SupplyProvider {
4
4
  name: SupplyProviderName;
5
5
  /** The preset the step's provider block is built from (providers.ts). */
@@ -19,6 +19,22 @@ export interface SupplyProvider {
19
19
  method: "GET" | "POST";
20
20
  path: string;
21
21
  }[];
22
+ /** How a request is reshaped before it leaves (the gateway applies it,
23
+ * shapeRequest). The agent runtime sends Claude's whole surface —
24
+ * `thinking: {type: adaptive, display}`, `output_config.effort` in five
25
+ * words, `context_management` — and a compatible endpoint documents
26
+ * less: what it does with the rest is not stated, so it is not sent. */
27
+ send?: SendShape;
28
+ }
29
+ export interface SendShape {
30
+ /** Only these top-level fields are sent; any other is dropped. */
31
+ fields?: string[];
32
+ /** These top-level fields are dropped. */
33
+ drop?: string[];
34
+ /** The keys of `thinking` that are sent; null drops `thinking` whole. */
35
+ thinking?: string[] | null;
36
+ /** `output_config.effort`, as this provider spells it. */
37
+ effort?: Record<string, string>;
22
38
  }
23
39
  export declare const SUPPLY_PROVIDERS: Record<SupplyProviderName, SupplyProvider>;
24
40
  export declare const SUPPLY_PROVIDER_NAMES: SupplyProviderName[];
@@ -53,3 +69,10 @@ export declare function supplyProviderOfToken(value: string | null | undefined):
53
69
  * endpoint and format, the operator's tier map, and the key as a
54
70
  * placeholder only. */
55
71
  export declare function supplyProviderBlock(provider: SupplyProviderName, tiers: Partial<Record<"fast" | "default" | "max", string>>): Record<string, unknown>;
72
+ /**
73
+ * Reshape a request body for a provider (its `send`), in place. True when
74
+ * anything changed. What a provider's schema does not list is not sent,
75
+ * rather than trusted to be ignored; an effort word it does not spell is
76
+ * sent as the nearest one it does.
77
+ */
78
+ export declare function shapeRequest(p: SupplyProvider, json: Record<string, unknown>): boolean;
@@ -26,22 +26,16 @@ export const SUPPLY_PROVIDERS = {
26
26
  { method: "GET", path: "/v1/models" },
27
27
  ],
28
28
  },
29
- openrouter: {
30
- name: "openrouter",
31
- preset: "openrouter",
32
- format: "anthropic",
33
- host: "openrouter.ai",
34
- auth: "bearer",
35
- metered: ["/api/v1/messages"],
36
- free: [{ method: "GET", path: "/api/v1/models" }],
37
- },
38
29
  openai: {
39
30
  name: "openai",
40
31
  preset: "openai",
41
- format: "openai",
32
+ // The Responses API, not Chat Completions: GPT-6 Astra and GPT-6.1 Sol
33
+ // call tools on Responses alone, GPT-6 Luna on Chat Completions only
34
+ // with reasoning off (OpenAI's model pages, 3 Nov 2026).
35
+ format: "responses",
42
36
  host: "api.openai.com",
43
37
  auth: "bearer",
44
- metered: ["/v1/chat/completions"],
38
+ metered: ["/v1/responses"],
45
39
  free: [{ method: "GET", path: "/v1/models" }],
46
40
  },
47
41
  gemini: {
@@ -53,6 +47,43 @@ export const SUPPLY_PROVIDERS = {
53
47
  metered: ["/v1beta/openai/chat/completions"],
54
48
  free: [{ method: "GET", path: "/v1beta/openai/models" }],
55
49
  },
50
+ // DeepSeek and Moonshot (owner, 3 Nov 2026: directly, not through
51
+ // OpenRouter, whose price depends on which host it routes a call to).
52
+ // Both speak Anthropic's Messages API at /anthropic/v1/messages and report
53
+ // usage the same way; neither prices a provider-run tool we allow
54
+ // (DeepSeek's web search is a typed tool, refused like Anthropic's).
55
+ deepseek: {
56
+ name: "deepseek",
57
+ preset: "deepseek",
58
+ format: "anthropic",
59
+ host: "api.deepseek.com",
60
+ auth: "x-api-key",
61
+ metered: ["/anthropic/v1/messages"],
62
+ free: [],
63
+ // api-docs.deepseek.com/api/create-message (3 Nov 2026): thinking.type
64
+ // enabled|disabled|adaptive (adaptive = enabled), budget_tokens ignored;
65
+ // effort takes every word ours does (medium and xhigh = high). Context
66
+ // editing and thinking.display are not in its schema.
67
+ send: { drop: ["context_management"], thinking: ["type", "budget_tokens"] },
68
+ },
69
+ moonshot: {
70
+ name: "moonshot",
71
+ preset: "moonshot",
72
+ format: "anthropic",
73
+ host: "api.moonshot.ai",
74
+ auth: "bearer",
75
+ metered: ["/anthropic/v1/messages"],
76
+ free: [],
77
+ // platform.kimi.ai/docs/api/messages (3 Nov 2026): the request schema is
78
+ // these fields alone; `thinking` is K2-only (K3.1 Pro always thinks);
79
+ // effort is low | high | max; temperature and top_p are fixed (any
80
+ // other value is an error).
81
+ send: {
82
+ fields: ["model", "messages", "max_tokens", "system", "stream", "stop_sequences", "tools", "tool_choice", "metadata", "cache_control", "output_config"],
83
+ thinking: null,
84
+ effort: { minimal: "low", low: "low", medium: "high", high: "high", xhigh: "high", max: "max" },
85
+ },
86
+ },
56
87
  };
57
88
  export const SUPPLY_PROVIDER_NAMES = Object.keys(SUPPLY_PROVIDERS);
58
89
  /** How each reads to a person: on a step's credential line, in Settings. */
@@ -60,7 +91,8 @@ export const SUPPLY_TITLES = {
60
91
  anthropic: "Anthropic",
61
92
  openai: "OpenAI",
62
93
  gemini: "Google Gemini",
63
- openrouter: "OpenRouter",
94
+ deepseek: "DeepSeek",
95
+ moonshot: "Moonshot Kimi",
64
96
  };
65
97
  export function isSupplyProvider(name) {
66
98
  return typeof name === "string" && Object.hasOwn(SUPPLY_PROVIDERS, name);
@@ -95,3 +127,49 @@ export function supplyProviderBlock(provider, tiers) {
95
127
  ...(Object.keys(tiers).length ? { models: tiers } : {}),
96
128
  };
97
129
  }
130
+ /**
131
+ * Reshape a request body for a provider (its `send`), in place. True when
132
+ * anything changed. What a provider's schema does not list is not sent,
133
+ * rather than trusted to be ignored; an effort word it does not spell is
134
+ * sent as the nearest one it does.
135
+ */
136
+ export function shapeRequest(p, json) {
137
+ const shape = p.send;
138
+ if (!shape)
139
+ return false;
140
+ let changed = false;
141
+ if (shape.fields) {
142
+ for (const k of Object.keys(json))
143
+ if (!shape.fields.includes(k))
144
+ (delete json[k], (changed = true));
145
+ }
146
+ for (const k of shape.drop ?? [])
147
+ if (k in json)
148
+ (delete json[k], (changed = true));
149
+ if (shape.thinking !== undefined && "thinking" in json) {
150
+ if (shape.thinking === null) {
151
+ delete json.thinking;
152
+ changed = true;
153
+ }
154
+ else if (json.thinking && typeof json.thinking === "object") {
155
+ const t = json.thinking;
156
+ for (const k of Object.keys(t))
157
+ if (!shape.thinking.includes(k))
158
+ (delete t[k], (changed = true));
159
+ }
160
+ }
161
+ const oc = json.output_config;
162
+ if (shape.effort && oc && typeof oc === "object" && typeof oc.effort === "string") {
163
+ const word = oc.effort;
164
+ const to = shape.effort[word];
165
+ if (to === undefined) {
166
+ delete oc.effort;
167
+ changed = true;
168
+ }
169
+ else if (to !== word) {
170
+ oc.effort = to;
171
+ changed = true;
172
+ }
173
+ }
174
+ return changed;
175
+ }
@@ -221,9 +221,9 @@ export const PROVIDERS = [
221
221
  { name: "vllm", title: "vLLM (yours)", format: "anthropic", auth: "bearer",
222
222
  note: "base_url is your server (default :8000). Start it with --enable-auto-tool-choice and a --tool-call-parser or no tool loop closes." },
223
223
  // ------------------------------------------- Chat-Completions, translated
224
- { name: "openai", title: "OpenAI", format: "openai", baseUrl: "https://api.openai.com/v1", auth: "bearer", verified: true,
224
+ { name: "openai", title: "OpenAI", format: "responses", baseUrl: "https://api.openai.com/v1", auth: "bearer", verified: true,
225
225
  maxTokensParam: "max_completion_tokens", reasoningEffort: true, promptCacheKey: true,
226
- note: "Reached over Chat Completions, which OpenAI keeps supporting; the Responses API is not spoken here, so a reasoning model's reasoning does not carry across tool calls.", search: "openai" },
226
+ note: "Reached over the Responses API (3 Nov 2026): GPT-6 Astra and GPT-6.1 Sol call tools there alone, GPT-6 Luna on Chat Completions only with reasoning off. `format: openai` still says Chat Completions, for an older model or a proxy that speaks only that.", search: "openai" },
227
227
  { name: "gemini", title: "Google Gemini", format: "openai", baseUrl: "https://generativelanguage.googleapis.com/v1beta/openai", auth: "bearer",
228
228
  note: "Google's OpenAI-compatible route. Unknown parameters are ignored silently; reasoning cannot be switched off on the newest models." },
229
229
  { name: "xai", title: "xAI Grok", format: "openai", baseUrl: "https://api.x.ai/v1", auth: "bearer",
@@ -91,6 +91,8 @@ export declare function toChatCompletions(req: Json, opts: {
91
91
  cacheKey?: string;
92
92
  /** Merged in last, so the file wins over the translation. */
93
93
  params?: Record<string, unknown>;
94
+ /** What the provider attached to earlier tool calls, to send back. */
95
+ extras?: ToolCallExtras;
94
96
  }, drop?: Dropped): Json;
95
97
  /**
96
98
  * An Anthropic Messages request as a Responses request. Pure.
@@ -109,7 +111,7 @@ export declare function toResponses(req: Json, opts: {
109
111
  params?: Record<string, unknown>;
110
112
  }, drop?: Dropped): Json;
111
113
  /** A finished Chat Completion as an Anthropic message. Pure. */
112
- export declare function fromChatCompletion(res: Json, requestedModel: string, stopSequences?: unknown): Json;
114
+ export declare function fromChatCompletion(res: Json, requestedModel: string, stopSequences?: unknown, extras?: ToolCallExtras): Json;
113
115
  /**
114
116
  * The streaming half: Chat-Completions chunks in, Anthropic SSE events out.
115
117
  * A state machine because the two streams disagree about structure — one
@@ -117,6 +119,23 @@ export declare function fromChatCompletion(res: Json, requestedModel: string, st
117
119
  * stops — and a tool call's arguments arrive as fragments that the other
118
120
  * side wants as `input_json_delta`s inside one open block.
119
121
  */
122
+ /**
123
+ * What a provider attached to a tool call that must come back with it.
124
+ * Gemini 3 and later put a thought signature on each tool call
125
+ * (`extra_content.google.thought_signature`) and refuse the next turn when
126
+ * it is missing; Claude's transcript has nowhere to keep it, so the
127
+ * translator — one per step, or per host call — remembers it by the call's
128
+ * id and puts it back when that call is sent again. Bounded: a step that
129
+ * makes more calls than this forgets the oldest.
130
+ */
131
+ export declare class ToolCallExtras {
132
+ private byId;
133
+ private readonly max;
134
+ constructor(max?: number);
135
+ keep(id: string, extra: unknown): void;
136
+ get(id: string): Json | undefined;
137
+ get size(): number;
138
+ }
120
139
  export declare class StreamTranslator {
121
140
  private started;
122
141
  private nextIndex;
@@ -129,7 +148,8 @@ export declare class StreamTranslator {
129
148
  private id;
130
149
  private readonly model;
131
150
  private readonly stops;
132
- constructor(model: string, stopSequences?: unknown);
151
+ private readonly extras?;
152
+ constructor(model: string, stopSequences?: unknown, extras?: ToolCallExtras);
133
153
  private event;
134
154
  private start;
135
155
  private closeText;
@@ -137,10 +137,12 @@ export function toChatCompletions(req, opts, drop = dropped()) {
137
137
  const toolCalls = [];
138
138
  for (const b of Array.isArray(content) ? content : []) {
139
139
  if (b.type === "tool_use") {
140
+ const extra = opts.extras?.get(String(b.id));
140
141
  toolCalls.push({
141
142
  id: String(b.id),
142
143
  type: "function",
143
144
  function: { name: String(b.name), arguments: JSON.stringify(b.input ?? {}) },
145
+ ...(extra ? { extra_content: extra } : {}),
144
146
  });
145
147
  }
146
148
  else if (b.type === "thinking" || b.type === "redacted_thinking") {
@@ -474,7 +476,7 @@ function parseArgs(raw) {
474
476
  }
475
477
  }
476
478
  /** A finished Chat Completion as an Anthropic message. Pure. */
477
- export function fromChatCompletion(res, requestedModel, stopSequences) {
479
+ export function fromChatCompletion(res, requestedModel, stopSequences, extras) {
478
480
  const choice = (res.choices ?? [])[0] ?? {};
479
481
  const msg = choice.message ?? {};
480
482
  const content = [];
@@ -483,9 +485,11 @@ export function fromChatCompletion(res, requestedModel, stopSequences) {
483
485
  content.push({ type: "text", text });
484
486
  for (const tc of (Array.isArray(msg.tool_calls) ? msg.tool_calls : [])) {
485
487
  const fn = tc.function ?? {};
488
+ const id = String(tc.id ?? `call_${crypto.randomBytes(6).toString("hex")}`);
489
+ extras?.keep(id, tc.extra_content);
486
490
  content.push({
487
491
  type: "tool_use",
488
- id: String(tc.id ?? `call_${crypto.randomBytes(6).toString("hex")}`),
492
+ id,
489
493
  name: String(fn.name ?? ""),
490
494
  input: parseArgs(fn.arguments),
491
495
  });
@@ -510,6 +514,37 @@ export function fromChatCompletion(res, requestedModel, stopSequences) {
510
514
  * stops — and a tool call's arguments arrive as fragments that the other
511
515
  * side wants as `input_json_delta`s inside one open block.
512
516
  */
517
+ /**
518
+ * What a provider attached to a tool call that must come back with it.
519
+ * Gemini 3 and later put a thought signature on each tool call
520
+ * (`extra_content.google.thought_signature`) and refuse the next turn when
521
+ * it is missing; Claude's transcript has nowhere to keep it, so the
522
+ * translator — one per step, or per host call — remembers it by the call's
523
+ * id and puts it back when that call is sent again. Bounded: a step that
524
+ * makes more calls than this forgets the oldest.
525
+ */
526
+ export class ToolCallExtras {
527
+ byId = new Map();
528
+ max;
529
+ constructor(max = 5000) {
530
+ this.max = max;
531
+ }
532
+ keep(id, extra) {
533
+ if (!id || !extra || typeof extra !== "object" || Array.isArray(extra))
534
+ return;
535
+ const prev = this.byId.get(id);
536
+ this.byId.delete(id);
537
+ this.byId.set(id, prev ? { ...prev, ...extra } : extra);
538
+ while (this.byId.size > this.max)
539
+ this.byId.delete(this.byId.keys().next().value);
540
+ }
541
+ get(id) {
542
+ return this.byId.get(id);
543
+ }
544
+ get size() {
545
+ return this.byId.size;
546
+ }
547
+ }
513
548
  export class StreamTranslator {
514
549
  started = false;
515
550
  nextIndex = 0;
@@ -522,9 +557,11 @@ export class StreamTranslator {
522
557
  id = `msg_${crypto.randomBytes(8).toString("hex")}`;
523
558
  model;
524
559
  stops;
525
- constructor(model, stopSequences) {
560
+ extras;
561
+ constructor(model, stopSequences, extras) {
526
562
  this.model = model;
527
563
  this.stops = stopList(stopSequences);
564
+ this.extras = extras;
528
565
  }
529
566
  event(name, data) {
530
567
  return `event: ${name}\ndata: ${JSON.stringify(data)}\n\n`;
@@ -595,19 +632,20 @@ export class StreamTranslator {
595
632
  // A new call: text stops here (a block is one thing), the tool
596
633
  // block opens with the id and name the first fragment carries.
597
634
  out.push(...this.closeText());
598
- entry = { block: this.nextIndex++, argsSeen: false };
635
+ entry = { block: this.nextIndex++, argsSeen: false, id: String(tc.id ?? `call_${crypto.randomBytes(6).toString("hex")}`) };
599
636
  this.tools.set(idx, entry);
600
637
  out.push(this.event("content_block_start", {
601
638
  type: "content_block_start",
602
639
  index: entry.block,
603
640
  content_block: {
604
641
  type: "tool_use",
605
- id: String(tc.id ?? `call_${crypto.randomBytes(6).toString("hex")}`),
642
+ id: entry.id,
606
643
  name: String(fn.name ?? ""),
607
644
  input: {},
608
645
  },
609
646
  }));
610
647
  }
648
+ this.extras?.keep(entry.id, tc.extra_content);
611
649
  const args = typeof fn.arguments === "string" ? fn.arguments : "";
612
650
  if (args) {
613
651
  entry.argsSeen = true;
@@ -875,6 +913,9 @@ export async function startTranslator(spec) {
875
913
  const log = [];
876
914
  const base = trimSlashes(spec.upstreamBase);
877
915
  const label = spec.label ?? base;
916
+ // One per translator (a step, or one host call): what the provider put on
917
+ // tool calls that must come back with them (Gemini's thought signatures).
918
+ const extras = new ToolCallExtras();
878
919
  const server = http.createServer(async (req, res) => {
879
920
  const started = Date.now();
880
921
  const send = (status, body, type = "application/json") => {
@@ -916,7 +957,7 @@ export async function startTranslator(spec) {
916
957
  const responses = spec.wire === "responses";
917
958
  const outbound = responses
918
959
  ? toResponses(body, { reasoningEffort: spec.reasoningEffort, params: spec.params, cacheKey: spec.cacheKey, stream }, drop)
919
- : toChatCompletions(body, { maxTokensParam: spec.maxTokensParam, reasoningEffort: spec.reasoningEffort, params: spec.params, cacheKey: spec.cacheKey, stream }, drop);
960
+ : toChatCompletions(body, { maxTokensParam: spec.maxTokensParam, reasoningEffort: spec.reasoningEffort, params: spec.params, cacheKey: spec.cacheKey, stream, extras }, drop);
920
961
  for (const line of drop.lines())
921
962
  if (!log.includes(line))
922
963
  log.push(line);
@@ -978,10 +1019,10 @@ export async function startTranslator(spec) {
978
1019
  return send(502, errorBody(502, `translator: ${label} answered with something that is not JSON`));
979
1020
  }
980
1021
  log.push(`POST ${label} → 200 (${Date.now() - started}ms, ${model})`);
981
- return send(200, JSON.stringify(responses ? fromResponses(parsed, model) : fromChatCompletion(parsed, model, body.stop_sequences)));
1022
+ return send(200, JSON.stringify(responses ? fromResponses(parsed, model) : fromChatCompletion(parsed, model, body.stop_sequences, extras)));
982
1023
  }
983
1024
  res.writeHead(200, { "content-type": "text/event-stream", "cache-control": "no-cache", connection: "keep-alive" });
984
- const machine = responses ? new ResponsesStreamTranslator(model) : new StreamTranslator(model, body.stop_sequences);
1025
+ const machine = responses ? new ResponsesStreamTranslator(model) : new StreamTranslator(model, body.stop_sequences, extras);
985
1026
  const reader = upstream.body?.getReader();
986
1027
  if (!reader) {
987
1028
  for (const e of machine.finishStream())
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@foldrun/core",
3
- "version": "13.1.1",
3
+ "version": "14.0.1",
4
4
  "description": "Agents are just folders. The format, the runner, the checks.",
5
5
  "license": "FSL-1.1-ALv2",
6
6
  "type": "module",
@@ -15,7 +15,7 @@
15
15
 
16
16
  import { providerPreset, type WireFormat } from "./providers.ts";
17
17
 
18
- export type SupplyProviderName = "anthropic" | "openai" | "gemini" | "openrouter";
18
+ export type SupplyProviderName = "anthropic" | "openai" | "gemini" | "deepseek" | "moonshot";
19
19
 
20
20
  export interface SupplyProvider {
21
21
  name: SupplyProviderName;
@@ -33,6 +33,23 @@ export interface SupplyProvider {
33
33
  /** Paths that cost nothing and may pass unmetered (GET model lists, a
34
34
  * free token count). Anything not listed in either is refused. */
35
35
  free: { method: "GET" | "POST"; path: string }[];
36
+ /** How a request is reshaped before it leaves (the gateway applies it,
37
+ * shapeRequest). The agent runtime sends Claude's whole surface —
38
+ * `thinking: {type: adaptive, display}`, `output_config.effort` in five
39
+ * words, `context_management` — and a compatible endpoint documents
40
+ * less: what it does with the rest is not stated, so it is not sent. */
41
+ send?: SendShape;
42
+ }
43
+
44
+ export interface SendShape {
45
+ /** Only these top-level fields are sent; any other is dropped. */
46
+ fields?: string[];
47
+ /** These top-level fields are dropped. */
48
+ drop?: string[];
49
+ /** The keys of `thinking` that are sent; null drops `thinking` whole. */
50
+ thinking?: string[] | null;
51
+ /** `output_config.effort`, as this provider spells it. */
52
+ effort?: Record<string, string>;
36
53
  }
37
54
 
38
55
  export const SUPPLY_PROVIDERS: Record<SupplyProviderName, SupplyProvider> = {
@@ -48,22 +65,16 @@ export const SUPPLY_PROVIDERS: Record<SupplyProviderName, SupplyProvider> = {
48
65
  { method: "GET", path: "/v1/models" },
49
66
  ],
50
67
  },
51
- openrouter: {
52
- name: "openrouter",
53
- preset: "openrouter",
54
- format: "anthropic",
55
- host: "openrouter.ai",
56
- auth: "bearer",
57
- metered: ["/api/v1/messages"],
58
- free: [{ method: "GET", path: "/api/v1/models" }],
59
- },
60
68
  openai: {
61
69
  name: "openai",
62
70
  preset: "openai",
63
- format: "openai",
71
+ // The Responses API, not Chat Completions: GPT-6 Astra and GPT-6.1 Sol
72
+ // call tools on Responses alone, GPT-6 Luna on Chat Completions only
73
+ // with reasoning off (OpenAI's model pages, 3 Nov 2026).
74
+ format: "responses",
64
75
  host: "api.openai.com",
65
76
  auth: "bearer",
66
- metered: ["/v1/chat/completions"],
77
+ metered: ["/v1/responses"],
67
78
  free: [{ method: "GET", path: "/v1/models" }],
68
79
  },
69
80
  gemini: {
@@ -75,6 +86,43 @@ export const SUPPLY_PROVIDERS: Record<SupplyProviderName, SupplyProvider> = {
75
86
  metered: ["/v1beta/openai/chat/completions"],
76
87
  free: [{ method: "GET", path: "/v1beta/openai/models" }],
77
88
  },
89
+ // DeepSeek and Moonshot (owner, 3 Nov 2026: directly, not through
90
+ // OpenRouter, whose price depends on which host it routes a call to).
91
+ // Both speak Anthropic's Messages API at /anthropic/v1/messages and report
92
+ // usage the same way; neither prices a provider-run tool we allow
93
+ // (DeepSeek's web search is a typed tool, refused like Anthropic's).
94
+ deepseek: {
95
+ name: "deepseek",
96
+ preset: "deepseek",
97
+ format: "anthropic",
98
+ host: "api.deepseek.com",
99
+ auth: "x-api-key",
100
+ metered: ["/anthropic/v1/messages"],
101
+ free: [],
102
+ // api-docs.deepseek.com/api/create-message (3 Nov 2026): thinking.type
103
+ // enabled|disabled|adaptive (adaptive = enabled), budget_tokens ignored;
104
+ // effort takes every word ours does (medium and xhigh = high). Context
105
+ // editing and thinking.display are not in its schema.
106
+ send: { drop: ["context_management"], thinking: ["type", "budget_tokens"] },
107
+ },
108
+ moonshot: {
109
+ name: "moonshot",
110
+ preset: "moonshot",
111
+ format: "anthropic",
112
+ host: "api.moonshot.ai",
113
+ auth: "bearer",
114
+ metered: ["/anthropic/v1/messages"],
115
+ free: [],
116
+ // platform.kimi.ai/docs/api/messages (3 Nov 2026): the request schema is
117
+ // these fields alone; `thinking` is K2-only (K3.1 Pro always thinks);
118
+ // effort is low | high | max; temperature and top_p are fixed (any
119
+ // other value is an error).
120
+ send: {
121
+ fields: ["model", "messages", "max_tokens", "system", "stream", "stop_sequences", "tools", "tool_choice", "metadata", "cache_control", "output_config"],
122
+ thinking: null,
123
+ effort: { minimal: "low", low: "low", medium: "high", high: "high", xhigh: "high", max: "max" },
124
+ },
125
+ },
78
126
  };
79
127
 
80
128
  export const SUPPLY_PROVIDER_NAMES = Object.keys(SUPPLY_PROVIDERS) as SupplyProviderName[];
@@ -84,7 +132,8 @@ export const SUPPLY_TITLES: Record<SupplyProviderName, string> = {
84
132
  anthropic: "Anthropic",
85
133
  openai: "OpenAI",
86
134
  gemini: "Google Gemini",
87
- openrouter: "OpenRouter",
135
+ deepseek: "DeepSeek",
136
+ moonshot: "Moonshot Kimi",
88
137
  };
89
138
 
90
139
  export function isSupplyProvider(name: unknown): name is SupplyProviderName {
@@ -136,3 +185,41 @@ export function supplyProviderBlock(provider: SupplyProviderName, tiers: Partial
136
185
  ...(Object.keys(tiers).length ? { models: tiers } : {}),
137
186
  };
138
187
  }
188
+
189
+ /**
190
+ * Reshape a request body for a provider (its `send`), in place. True when
191
+ * anything changed. What a provider's schema does not list is not sent,
192
+ * rather than trusted to be ignored; an effort word it does not spell is
193
+ * sent as the nearest one it does.
194
+ */
195
+ export function shapeRequest(p: SupplyProvider, json: Record<string, unknown>): boolean {
196
+ const shape = p.send;
197
+ if (!shape) return false;
198
+ let changed = false;
199
+ if (shape.fields) {
200
+ for (const k of Object.keys(json)) if (!shape.fields.includes(k)) (delete json[k], (changed = true));
201
+ }
202
+ for (const k of shape.drop ?? []) if (k in json) (delete json[k], (changed = true));
203
+ if (shape.thinking !== undefined && "thinking" in json) {
204
+ if (shape.thinking === null) {
205
+ delete json.thinking;
206
+ changed = true;
207
+ } else if (json.thinking && typeof json.thinking === "object") {
208
+ const t = json.thinking as Record<string, unknown>;
209
+ for (const k of Object.keys(t)) if (!shape.thinking.includes(k)) (delete t[k], (changed = true));
210
+ }
211
+ }
212
+ const oc = json.output_config;
213
+ if (shape.effort && oc && typeof oc === "object" && typeof (oc as Record<string, unknown>).effort === "string") {
214
+ const word = (oc as Record<string, unknown>).effort as string;
215
+ const to = shape.effort[word];
216
+ if (to === undefined) {
217
+ delete (oc as Record<string, unknown>).effort;
218
+ changed = true;
219
+ } else if (to !== word) {
220
+ (oc as Record<string, unknown>).effort = to;
221
+ changed = true;
222
+ }
223
+ }
224
+ return changed;
225
+ }
package/src/providers.ts CHANGED
@@ -436,9 +436,9 @@ export const PROVIDERS: readonly ProviderPreset[] = [
436
436
  note: "base_url is your server (default :8000). Start it with --enable-auto-tool-choice and a --tool-call-parser or no tool loop closes." },
437
437
 
438
438
  // ------------------------------------------- Chat-Completions, translated
439
- { name: "openai", title: "OpenAI", format: "openai", baseUrl: "https://api.openai.com/v1", auth: "bearer", verified: true,
439
+ { name: "openai", title: "OpenAI", format: "responses", baseUrl: "https://api.openai.com/v1", auth: "bearer", verified: true,
440
440
  maxTokensParam: "max_completion_tokens", reasoningEffort: true, promptCacheKey: true,
441
- note: "Reached over Chat Completions, which OpenAI keeps supporting; the Responses API is not spoken here, so a reasoning model's reasoning does not carry across tool calls." , search: "openai" },
441
+ note: "Reached over the Responses API (3 Nov 2026): GPT-6 Astra and GPT-6.1 Sol call tools there alone, GPT-6 Luna on Chat Completions only with reasoning off. `format: openai` still says Chat Completions, for an older model or a proxy that speaks only that." , search: "openai" },
442
442
  { name: "gemini", title: "Google Gemini", format: "openai", baseUrl: "https://generativelanguage.googleapis.com/v1beta/openai", auth: "bearer",
443
443
  note: "Google's OpenAI-compatible route. Unknown parameters are ignored silently; reasoning cannot be switched off on the newest models." },
444
444
  { name: "xai", title: "xAI Grok", format: "openai", baseUrl: "https://api.x.ai/v1", auth: "bearer",
package/src/translator.ts CHANGED
@@ -200,6 +200,8 @@ export function toChatCompletions(
200
200
  cacheKey?: string;
201
201
  /** Merged in last, so the file wins over the translation. */
202
202
  params?: Record<string, unknown>;
203
+ /** What the provider attached to earlier tool calls, to send back. */
204
+ extras?: ToolCallExtras;
203
205
  },
204
206
  drop: Dropped = dropped(),
205
207
  ): Json {
@@ -217,10 +219,12 @@ export function toChatCompletions(
217
219
  const toolCalls: Json[] = [];
218
220
  for (const b of Array.isArray(content) ? (content as Json[]) : []) {
219
221
  if (b.type === "tool_use") {
222
+ const extra = opts.extras?.get(String(b.id));
220
223
  toolCalls.push({
221
224
  id: String(b.id),
222
225
  type: "function",
223
226
  function: { name: String(b.name), arguments: JSON.stringify(b.input ?? {}) },
227
+ ...(extra ? { extra_content: extra } : {}),
224
228
  });
225
229
  } else if (b.type === "thinking" || b.type === "redacted_thinking") {
226
230
  drop.add("thinking blocks in the transcript");
@@ -514,7 +518,7 @@ function parseArgs(raw: unknown): unknown {
514
518
  }
515
519
 
516
520
  /** A finished Chat Completion as an Anthropic message. Pure. */
517
- export function fromChatCompletion(res: Json, requestedModel: string, stopSequences?: unknown): Json {
521
+ export function fromChatCompletion(res: Json, requestedModel: string, stopSequences?: unknown, extras?: ToolCallExtras): Json {
518
522
  const choice = ((res.choices as Json[] | undefined) ?? [])[0] ?? {};
519
523
  const msg = (choice.message as Json | undefined) ?? {};
520
524
  const content: Json[] = [];
@@ -522,9 +526,11 @@ export function fromChatCompletion(res: Json, requestedModel: string, stopSequen
522
526
  if (text) content.push({ type: "text", text });
523
527
  for (const tc of (Array.isArray(msg.tool_calls) ? msg.tool_calls : []) as Json[]) {
524
528
  const fn = (tc.function as Json | undefined) ?? {};
529
+ const id = String(tc.id ?? `call_${crypto.randomBytes(6).toString("hex")}`);
530
+ extras?.keep(id, tc.extra_content);
525
531
  content.push({
526
532
  type: "tool_use",
527
- id: String(tc.id ?? `call_${crypto.randomBytes(6).toString("hex")}`),
533
+ id,
528
534
  name: String(fn.name ?? ""),
529
535
  input: parseArgs(fn.arguments),
530
536
  });
@@ -550,21 +556,53 @@ export function fromChatCompletion(res: Json, requestedModel: string, stopSequen
550
556
  * stops — and a tool call's arguments arrive as fragments that the other
551
557
  * side wants as `input_json_delta`s inside one open block.
552
558
  */
559
+ /**
560
+ * What a provider attached to a tool call that must come back with it.
561
+ * Gemini 3 and later put a thought signature on each tool call
562
+ * (`extra_content.google.thought_signature`) and refuse the next turn when
563
+ * it is missing; Claude's transcript has nowhere to keep it, so the
564
+ * translator — one per step, or per host call — remembers it by the call's
565
+ * id and puts it back when that call is sent again. Bounded: a step that
566
+ * makes more calls than this forgets the oldest.
567
+ */
568
+ export class ToolCallExtras {
569
+ private byId = new Map<string, Json>();
570
+ private readonly max: number;
571
+ constructor(max = 5000) {
572
+ this.max = max;
573
+ }
574
+ keep(id: string, extra: unknown): void {
575
+ if (!id || !extra || typeof extra !== "object" || Array.isArray(extra)) return;
576
+ const prev = this.byId.get(id);
577
+ this.byId.delete(id);
578
+ this.byId.set(id, prev ? { ...prev, ...(extra as Json) } : (extra as Json));
579
+ while (this.byId.size > this.max) this.byId.delete(this.byId.keys().next().value as string);
580
+ }
581
+ get(id: string): Json | undefined {
582
+ return this.byId.get(id);
583
+ }
584
+ get size(): number {
585
+ return this.byId.size;
586
+ }
587
+ }
588
+
553
589
  export class StreamTranslator {
554
590
  private started = false;
555
591
  private nextIndex = 0;
556
592
  private textIndex: number | null = null;
557
593
  /** Chat-Completions tool index → Anthropic block index. */
558
- private tools = new Map<number, { block: number; argsSeen: boolean }>();
594
+ private tools = new Map<number, { block: number; argsSeen: boolean; id: string }>();
559
595
  /** The last choice's stop fields: finish_reason and any matched stop. */
560
596
  private finish: Json = {};
561
597
  private usage: { input: number; cached: number; output: number } | null = null;
562
598
  private id = `msg_${crypto.randomBytes(8).toString("hex")}`;
563
599
  private readonly model: string;
564
600
  private readonly stops: string[];
565
- constructor(model: string, stopSequences?: unknown) {
601
+ private readonly extras?: ToolCallExtras;
602
+ constructor(model: string, stopSequences?: unknown, extras?: ToolCallExtras) {
566
603
  this.model = model;
567
604
  this.stops = stopList(stopSequences);
605
+ this.extras = extras;
568
606
  }
569
607
 
570
608
  private event(name: string, data: Json): string {
@@ -640,7 +678,7 @@ export class StreamTranslator {
640
678
  // A new call: text stops here (a block is one thing), the tool
641
679
  // block opens with the id and name the first fragment carries.
642
680
  out.push(...this.closeText());
643
- entry = { block: this.nextIndex++, argsSeen: false };
681
+ entry = { block: this.nextIndex++, argsSeen: false, id: String(tc.id ?? `call_${crypto.randomBytes(6).toString("hex")}`) };
644
682
  this.tools.set(idx, entry);
645
683
  out.push(
646
684
  this.event("content_block_start", {
@@ -648,13 +686,14 @@ export class StreamTranslator {
648
686
  index: entry.block,
649
687
  content_block: {
650
688
  type: "tool_use",
651
- id: String(tc.id ?? `call_${crypto.randomBytes(6).toString("hex")}`),
689
+ id: entry.id,
652
690
  name: String(fn.name ?? ""),
653
691
  input: {},
654
692
  },
655
693
  }),
656
694
  );
657
695
  }
696
+ this.extras?.keep(entry.id, tc.extra_content);
658
697
  const args = typeof fn.arguments === "string" ? fn.arguments : "";
659
698
  if (args) {
660
699
  entry.argsSeen = true;
@@ -929,6 +968,9 @@ export async function startTranslator(spec: TranslatorSpec): Promise<RunningTran
929
968
  const log: string[] = [];
930
969
  const base = trimSlashes(spec.upstreamBase);
931
970
  const label = spec.label ?? base;
971
+ // One per translator (a step, or one host call): what the provider put on
972
+ // tool calls that must come back with them (Gemini's thought signatures).
973
+ const extras = new ToolCallExtras();
932
974
 
933
975
  const server = http.createServer(async (req, res) => {
934
976
  const started = Date.now();
@@ -972,7 +1014,7 @@ export async function startTranslator(spec: TranslatorSpec): Promise<RunningTran
972
1014
  const responses = spec.wire === "responses";
973
1015
  const outbound = responses
974
1016
  ? toResponses(body, { reasoningEffort: spec.reasoningEffort, params: spec.params, cacheKey: spec.cacheKey, stream }, drop)
975
- : toChatCompletions(body, { maxTokensParam: spec.maxTokensParam, reasoningEffort: spec.reasoningEffort, params: spec.params, cacheKey: spec.cacheKey, stream }, drop);
1017
+ : toChatCompletions(body, { maxTokensParam: spec.maxTokensParam, reasoningEffort: spec.reasoningEffort, params: spec.params, cacheKey: spec.cacheKey, stream, extras }, drop);
976
1018
  for (const line of drop.lines()) if (!log.includes(line)) log.push(line);
977
1019
 
978
1020
  let upstream: Response;
@@ -1035,11 +1077,11 @@ export async function startTranslator(spec: TranslatorSpec): Promise<RunningTran
1035
1077
  return send(502, errorBody(502, `translator: ${label} answered with something that is not JSON`));
1036
1078
  }
1037
1079
  log.push(`POST ${label} → 200 (${Date.now() - started}ms, ${model})`);
1038
- return send(200, JSON.stringify(responses ? fromResponses(parsed, model) : fromChatCompletion(parsed, model, body.stop_sequences)));
1080
+ return send(200, JSON.stringify(responses ? fromResponses(parsed, model) : fromChatCompletion(parsed, model, body.stop_sequences, extras)));
1039
1081
  }
1040
1082
 
1041
1083
  res.writeHead(200, { "content-type": "text/event-stream", "cache-control": "no-cache", connection: "keep-alive" });
1042
- const machine = responses ? new ResponsesStreamTranslator(model) : new StreamTranslator(model, body.stop_sequences);
1084
+ const machine = responses ? new ResponsesStreamTranslator(model) : new StreamTranslator(model, body.stop_sequences, extras);
1043
1085
  const reader = upstream.body?.getReader();
1044
1086
  if (!reader) {
1045
1087
  for (const e of machine.finishStream()) res.write(e);