@foldrun/core 14.0.0 → 14.1.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.
@@ -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;
@@ -29,10 +29,13 @@ export const SUPPLY_PROVIDERS = {
29
29
  openai: {
30
30
  name: "openai",
31
31
  preset: "openai",
32
- 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",
33
36
  host: "api.openai.com",
34
37
  auth: "bearer",
35
- metered: ["/v1/chat/completions"],
38
+ metered: ["/v1/responses"],
36
39
  free: [{ method: "GET", path: "/v1/models" }],
37
40
  },
38
41
  gemini: {
@@ -57,6 +60,11 @@ export const SUPPLY_PROVIDERS = {
57
60
  auth: "x-api-key",
58
61
  metered: ["/anthropic/v1/messages"],
59
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"] },
60
68
  },
61
69
  moonshot: {
62
70
  name: "moonshot",
@@ -66,6 +74,15 @@ export const SUPPLY_PROVIDERS = {
66
74
  auth: "bearer",
67
75
  metered: ["/anthropic/v1/messages"],
68
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
+ },
69
86
  },
70
87
  };
71
88
  export const SUPPLY_PROVIDER_NAMES = Object.keys(SUPPLY_PROVIDERS);
@@ -110,3 +127,49 @@ export function supplyProviderBlock(provider, tiers) {
110
127
  ...(Object.keys(tiers).length ? { models: tiers } : {}),
111
128
  };
112
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",
@@ -64,17 +64,32 @@ export interface RunningTranslator {
64
64
  }
65
65
  interface Dropped {
66
66
  add(what: string): void;
67
+ /** Something sent differently, not dropped: said as written. */
68
+ note(what: string): void;
67
69
  lines(): string[];
68
70
  }
69
71
  /**
70
- * Whether a model is one OpenAI's own endpoint refuses a reasoning-effort
71
- * parameter for ("Unsupported parameter: 'reasoning.effort'" on gpt-4o-mini).
72
- * A gateway in front of it ignored the field, which is how the preset's
73
- * reasoningEffort shipped untested against the origin. The families that do
74
- * not reason are the ones named — anything else (o-series, gpt-5, grok,
75
- * gemini, deepseek-r, qwen thinking) keeps getting the knob, because on a
76
- * gateway the id alone cannot say and an ignored field costs nothing.
72
+ * The reasoning-effort words each model takes on an OpenAI-shaped endpoint
73
+ * (Chat Completions' reasoning_effort, Responses' reasoning.effort), from
74
+ * the providers' own pages; the first match wins. A model not listed gets
75
+ * low | medium | high, which every reasoning model there has taken — a
76
+ * word it might not know is never sent on a guess. Add a row when a model
77
+ * documents more (or fewer).
77
78
  */
79
+ export declare const MODEL_EFFORTS: readonly {
80
+ match: RegExp;
81
+ levels: readonly string[];
82
+ source: string;
83
+ }[];
84
+ /** The levels a model takes, by its id (a provider prefix ignored). */
85
+ export declare function effortsOf(model: string): readonly string[];
86
+ /**
87
+ * A foldrun effort word as this model takes it: the word itself when the
88
+ * model has it, else the nearest level below that it has (xhigh on a model
89
+ * that stops at high runs as high), else its lowest. Null for a word that
90
+ * is not one of ours.
91
+ */
92
+ export declare function fitEffort(model: string, word: string): string | null;
78
93
  export declare function modelRejectsReasoning(model: string): boolean;
79
94
  /**
80
95
  * An Anthropic Messages request as a Chat Completions request. Pure.
@@ -63,9 +63,11 @@ function usageBlock(u) {
63
63
  }
64
64
  function dropped() {
65
65
  const seen = new Set();
66
+ const notes = new Set();
66
67
  return {
67
68
  add: (w) => void seen.add(w),
68
- lines: () => [...seen].map((w) => `translator: dropped ${w} — the endpoint has no equivalent`),
69
+ note: (w) => void notes.add(w),
70
+ lines: () => [...[...seen].map((w) => `translator: dropped ${w} — the endpoint has no equivalent`), ...[...notes].map((w) => `translator: ${w}`)],
69
71
  };
70
72
  }
71
73
  // ------------------------------------------------------- request mapping
@@ -89,6 +91,54 @@ function stableId(id) {
89
91
  * gemini, deepseek-r, qwen thinking) keeps getting the knob, because on a
90
92
  * gateway the id alone cannot say and an ignored field costs nothing.
91
93
  */
94
+ /** foldrun's effort words, low to high (frontmatter-fields EFFORT_LEVELS). */
95
+ const EFFORT_ORDER = ["low", "medium", "high", "xhigh", "max"];
96
+ /**
97
+ * The reasoning-effort words each model takes on an OpenAI-shaped endpoint
98
+ * (Chat Completions' reasoning_effort, Responses' reasoning.effort), from
99
+ * the providers' own pages; the first match wins. A model not listed gets
100
+ * low | medium | high, which every reasoning model there has taken — a
101
+ * word it might not know is never sent on a guess. Add a row when a model
102
+ * documents more (or fewer).
103
+ */
104
+ export const MODEL_EFFORTS = [
105
+ {
106
+ // "reasoning.effort supports low, medium (default), high, xhigh, and max"
107
+ // (Luna also none, which no foldrun word asks for).
108
+ match: /^gpt-6(?:\.\d+)?-(?:astra|sol|luna)(?:$|-)/,
109
+ levels: ["low", "medium", "high", "xhigh", "max"],
110
+ source: "developers.openai.com/api/docs/models, 3 Nov 2026",
111
+ },
112
+ {
113
+ // reasoning_effort minimal | low | medium | high; thinking cannot be
114
+ // turned off on Gemini 3 and later.
115
+ match: /^gemini-/,
116
+ levels: ["low", "medium", "high"],
117
+ source: "ai.google.dev/gemini-api/docs/openai, 3 Nov 2026",
118
+ },
119
+ ];
120
+ const DEFAULT_EFFORTS = ["low", "medium", "high"];
121
+ /** The levels a model takes, by its id (a provider prefix ignored). */
122
+ export function effortsOf(model) {
123
+ const id = String(model).split("/").pop()?.toLowerCase() ?? "";
124
+ return MODEL_EFFORTS.find((m) => m.match.test(id))?.levels ?? DEFAULT_EFFORTS;
125
+ }
126
+ /**
127
+ * A foldrun effort word as this model takes it: the word itself when the
128
+ * model has it, else the nearest level below that it has (xhigh on a model
129
+ * that stops at high runs as high), else its lowest. Null for a word that
130
+ * is not one of ours.
131
+ */
132
+ export function fitEffort(model, word) {
133
+ const want = EFFORT_ORDER.indexOf(word);
134
+ if (want < 0)
135
+ return null;
136
+ const levels = effortsOf(model);
137
+ for (let i = want; i >= 0; i--)
138
+ if (levels.includes(EFFORT_ORDER[i]))
139
+ return EFFORT_ORDER[i];
140
+ return EFFORT_ORDER.find((l) => levels.includes(l)) ?? null;
141
+ }
92
142
  export function modelRejectsReasoning(model) {
93
143
  const id = String(model).split("/").pop()?.toLowerCase() ?? "";
94
144
  return /^(gpt-3|gpt-4|chatgpt|gpt-5-chat|davinci|babbage)/.test(id);
@@ -249,8 +299,11 @@ export function toChatCompletions(req, opts, drop = dropped()) {
249
299
  const thinking = req.thinking;
250
300
  const effortWord = typeof req.effort === "string" ? req.effort : req.output_config?.effort;
251
301
  let effort = null;
252
- if (typeof effortWord === "string")
253
- effort = { low: "low", medium: "medium", high: "high", xhigh: "high", max: "high" }[effortWord] ?? null;
302
+ if (typeof effortWord === "string") {
303
+ effort = fitEffort(String(req.model), effortWord);
304
+ if (effort && effort !== effortWord)
305
+ drop.note(`effort ${effortWord} runs as ${effort} on ${String(req.model)} — the nearest level it takes`);
306
+ }
254
307
  else if (thinking && thinking.type === "enabled") {
255
308
  const b = Number(thinking.budget_tokens) || 0;
256
309
  effort = b <= 2048 ? "low" : b <= 8192 ? "medium" : "high";
@@ -321,9 +374,20 @@ export function toResponses(req, opts, drop = dropped()) {
321
374
  if (b.type === "tool_result") {
322
375
  const inner = b.content;
323
376
  const text = typeof inner === "string" ? inner : textOf(inner);
324
- input.push({ type: "function_call_output", call_id: String(b.tool_use_id), output: text || (b.is_error ? "error" : "ok") });
325
- if (Array.isArray(inner) && inner.some((x) => x.type === "image"))
326
- drop.add("images inside tool results");
377
+ // A tool result that holds images (a picture the agent opened) is
378
+ // sent as a list of parts, which Responses takes in a tool output.
379
+ const images = Array.isArray(inner)
380
+ ? inner.flatMap((x) => {
381
+ const src = x.type === "image" ? x.source : undefined;
382
+ if (src?.type === "base64" && typeof src.data === "string")
383
+ return [{ type: "input_image", image_url: `data:${String(src.media_type ?? "image/png")};base64,${src.data}`, detail: "auto" }];
384
+ if (src?.type === "url" && typeof src.url === "string")
385
+ return [{ type: "input_image", image_url: src.url, detail: "auto" }];
386
+ return [];
387
+ })
388
+ : [];
389
+ const output = images.length ? [...(text ? [{ type: "input_text", text }] : []), ...images] : text || (b.is_error ? "error" : "ok");
390
+ input.push({ type: "function_call_output", call_id: String(b.tool_use_id), output });
327
391
  }
328
392
  else if (b.type === "text") {
329
393
  parts.push({ type: "input_text", text: String(b.text ?? "") });
@@ -404,8 +468,11 @@ export function toResponses(req, opts, drop = dropped()) {
404
468
  const thinking = req.thinking;
405
469
  const effortWord = typeof req.effort === "string" ? req.effort : req.output_config?.effort;
406
470
  let effort = null;
407
- if (typeof effortWord === "string")
408
- effort = { low: "low", medium: "medium", high: "high", xhigh: "high", max: "high" }[effortWord] ?? null;
471
+ if (typeof effortWord === "string") {
472
+ effort = fitEffort(String(req.model), effortWord);
473
+ if (effort && effort !== effortWord)
474
+ drop.note(`effort ${effortWord} runs as ${effort} on ${String(req.model)} — the nearest level it takes`);
475
+ }
409
476
  else if (thinking && thinking.type === "enabled") {
410
477
  const b = Number(thinking.budget_tokens) || 0;
411
478
  effort = b <= 2048 ? "low" : b <= 8192 ? "medium" : "high";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@foldrun/core",
3
- "version": "14.0.0",
3
+ "version": "14.1.0",
4
4
  "description": "Agents are just folders. The format, the runner, the checks.",
5
5
  "license": "FSL-1.1-ALv2",
6
6
  "type": "module",
@@ -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> = {
@@ -51,10 +68,13 @@ export const SUPPLY_PROVIDERS: Record<SupplyProviderName, SupplyProvider> = {
51
68
  openai: {
52
69
  name: "openai",
53
70
  preset: "openai",
54
- 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",
55
75
  host: "api.openai.com",
56
76
  auth: "bearer",
57
- metered: ["/v1/chat/completions"],
77
+ metered: ["/v1/responses"],
58
78
  free: [{ method: "GET", path: "/v1/models" }],
59
79
  },
60
80
  gemini: {
@@ -79,6 +99,11 @@ export const SUPPLY_PROVIDERS: Record<SupplyProviderName, SupplyProvider> = {
79
99
  auth: "x-api-key",
80
100
  metered: ["/anthropic/v1/messages"],
81
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"] },
82
107
  },
83
108
  moonshot: {
84
109
  name: "moonshot",
@@ -88,6 +113,15 @@ export const SUPPLY_PROVIDERS: Record<SupplyProviderName, SupplyProvider> = {
88
113
  auth: "bearer",
89
114
  metered: ["/anthropic/v1/messages"],
90
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
+ },
91
125
  },
92
126
  };
93
127
 
@@ -151,3 +185,41 @@ export function supplyProviderBlock(provider: SupplyProviderName, tiers: Partial
151
185
  ...(Object.keys(tiers).length ? { models: tiers } : {}),
152
186
  };
153
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
@@ -125,14 +125,18 @@ export interface RunningTranslator {
125
125
 
126
126
  interface Dropped {
127
127
  add(what: string): void;
128
+ /** Something sent differently, not dropped: said as written. */
129
+ note(what: string): void;
128
130
  lines(): string[];
129
131
  }
130
132
 
131
133
  function dropped(): Dropped {
132
134
  const seen = new Set<string>();
135
+ const notes = new Set<string>();
133
136
  return {
134
137
  add: (w) => void seen.add(w),
135
- lines: () => [...seen].map((w) => `translator: dropped ${w} — the endpoint has no equivalent`),
138
+ note: (w) => void notes.add(w),
139
+ lines: () => [...[...seen].map((w) => `translator: dropped ${w} — the endpoint has no equivalent`), ...[...notes].map((w) => `translator: ${w}`)],
136
140
  };
137
141
  }
138
142
 
@@ -159,6 +163,55 @@ function stableId(id: string): string {
159
163
  * gemini, deepseek-r, qwen thinking) keeps getting the knob, because on a
160
164
  * gateway the id alone cannot say and an ignored field costs nothing.
161
165
  */
166
+ /** foldrun's effort words, low to high (frontmatter-fields EFFORT_LEVELS). */
167
+ const EFFORT_ORDER = ["low", "medium", "high", "xhigh", "max"] as const;
168
+
169
+ /**
170
+ * The reasoning-effort words each model takes on an OpenAI-shaped endpoint
171
+ * (Chat Completions' reasoning_effort, Responses' reasoning.effort), from
172
+ * the providers' own pages; the first match wins. A model not listed gets
173
+ * low | medium | high, which every reasoning model there has taken — a
174
+ * word it might not know is never sent on a guess. Add a row when a model
175
+ * documents more (or fewer).
176
+ */
177
+ export const MODEL_EFFORTS: readonly { match: RegExp; levels: readonly string[]; source: string }[] = [
178
+ {
179
+ // "reasoning.effort supports low, medium (default), high, xhigh, and max"
180
+ // (Luna also none, which no foldrun word asks for).
181
+ match: /^gpt-6(?:\.\d+)?-(?:astra|sol|luna)(?:$|-)/,
182
+ levels: ["low", "medium", "high", "xhigh", "max"],
183
+ source: "developers.openai.com/api/docs/models, 3 Nov 2026",
184
+ },
185
+ {
186
+ // reasoning_effort minimal | low | medium | high; thinking cannot be
187
+ // turned off on Gemini 3 and later.
188
+ match: /^gemini-/,
189
+ levels: ["low", "medium", "high"],
190
+ source: "ai.google.dev/gemini-api/docs/openai, 3 Nov 2026",
191
+ },
192
+ ];
193
+ const DEFAULT_EFFORTS = ["low", "medium", "high"] as const;
194
+
195
+ /** The levels a model takes, by its id (a provider prefix ignored). */
196
+ export function effortsOf(model: string): readonly string[] {
197
+ const id = String(model).split("/").pop()?.toLowerCase() ?? "";
198
+ return MODEL_EFFORTS.find((m) => m.match.test(id))?.levels ?? DEFAULT_EFFORTS;
199
+ }
200
+
201
+ /**
202
+ * A foldrun effort word as this model takes it: the word itself when the
203
+ * model has it, else the nearest level below that it has (xhigh on a model
204
+ * that stops at high runs as high), else its lowest. Null for a word that
205
+ * is not one of ours.
206
+ */
207
+ export function fitEffort(model: string, word: string): string | null {
208
+ const want = (EFFORT_ORDER as readonly string[]).indexOf(word);
209
+ if (want < 0) return null;
210
+ const levels = effortsOf(model);
211
+ for (let i = want; i >= 0; i--) if (levels.includes(EFFORT_ORDER[i]!)) return EFFORT_ORDER[i]!;
212
+ return EFFORT_ORDER.find((l) => levels.includes(l)) ?? null;
213
+ }
214
+
162
215
  export function modelRejectsReasoning(model: string): boolean {
163
216
  const id = String(model).split("/").pop()?.toLowerCase() ?? "";
164
217
  return /^(gpt-3|gpt-4|chatgpt|gpt-5-chat|davinci|babbage)/.test(id);
@@ -314,7 +367,10 @@ export function toChatCompletions(
314
367
  const effortWord =
315
368
  typeof req.effort === "string" ? req.effort : (req.output_config as Json | undefined)?.effort;
316
369
  let effort: string | null = null;
317
- if (typeof effortWord === "string") effort = { low: "low", medium: "medium", high: "high", xhigh: "high", max: "high" }[effortWord] ?? null;
370
+ if (typeof effortWord === "string") {
371
+ effort = fitEffort(String(req.model), effortWord);
372
+ if (effort && effort !== effortWord) drop.note(`effort ${effortWord} runs as ${effort} on ${String(req.model)} — the nearest level it takes`);
373
+ }
318
374
  else if (thinking && thinking.type === "enabled") {
319
375
  const b = Number(thinking.budget_tokens) || 0;
320
376
  effort = b <= 2048 ? "low" : b <= 8192 ? "medium" : "high";
@@ -387,8 +443,18 @@ export function toResponses(
387
443
  if (b.type === "tool_result") {
388
444
  const inner = b.content;
389
445
  const text = typeof inner === "string" ? inner : textOf(inner);
390
- input.push({ type: "function_call_output", call_id: String(b.tool_use_id), output: text || (b.is_error ? "error" : "ok") });
391
- if (Array.isArray(inner) && (inner as Json[]).some((x) => x.type === "image")) drop.add("images inside tool results");
446
+ // A tool result that holds images (a picture the agent opened) is
447
+ // sent as a list of parts, which Responses takes in a tool output.
448
+ const images = Array.isArray(inner)
449
+ ? (inner as Json[]).flatMap((x) => {
450
+ const src = x.type === "image" ? (x.source as Json | undefined) : undefined;
451
+ if (src?.type === "base64" && typeof src.data === "string") return [{ type: "input_image", image_url: `data:${String(src.media_type ?? "image/png")};base64,${src.data}`, detail: "auto" }];
452
+ if (src?.type === "url" && typeof src.url === "string") return [{ type: "input_image", image_url: src.url, detail: "auto" }];
453
+ return [];
454
+ })
455
+ : [];
456
+ const output = images.length ? [...(text ? [{ type: "input_text", text }] : []), ...images] : text || (b.is_error ? "error" : "ok");
457
+ input.push({ type: "function_call_output", call_id: String(b.tool_use_id), output });
392
458
  } else if (b.type === "text") {
393
459
  parts.push({ type: "input_text", text: String(b.text ?? "") });
394
460
  } else if (b.type === "image") {
@@ -454,7 +520,10 @@ export function toResponses(
454
520
  const effortWord =
455
521
  typeof req.effort === "string" ? req.effort : (req.output_config as Json | undefined)?.effort;
456
522
  let effort: string | null = null;
457
- if (typeof effortWord === "string") effort = { low: "low", medium: "medium", high: "high", xhigh: "high", max: "high" }[effortWord] ?? null;
523
+ if (typeof effortWord === "string") {
524
+ effort = fitEffort(String(req.model), effortWord);
525
+ if (effort && effort !== effortWord) drop.note(`effort ${effortWord} runs as ${effort} on ${String(req.model)} — the nearest level it takes`);
526
+ }
458
527
  else if (thinking && thinking.type === "enabled") {
459
528
  const b = Number(thinking.budget_tokens) || 0;
460
529
  effort = b <= 2048 ? "low" : b <= 8192 ? "medium" : "high";