@foldrun/core 14.0.1 → 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.
@@ -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.1",
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",
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";