@foldrun/core 14.2.0 → 14.2.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.
@@ -35,6 +35,13 @@ export interface SendShape {
35
35
  thinking?: string[] | null;
36
36
  /** `output_config.effort`, as this provider spells it. */
37
37
  effort?: Record<string, string>;
38
+ /** A `system` message inside `messages` (Anthropic's mid-conversation
39
+ * instructions, which the SDK sends) folded into the user turn before
40
+ * it: the endpoint documents user and assistant roles only. */
41
+ mergeSystemMessages?: boolean;
42
+ /** Tools deferred for Anthropic's tool search (`defer_loading`; the SDK
43
+ * always sends a placeholder) dropped: the endpoint cannot load them. */
44
+ dropDeferredTools?: boolean;
38
45
  }
39
46
  export declare const SUPPLY_PROVIDERS: Record<SupplyProviderName, SupplyProvider>;
40
47
  export declare const SUPPLY_PROVIDER_NAMES: SupplyProviderName[];
@@ -65,7 +65,7 @@ export const SUPPLY_PROVIDERS = {
65
65
  // enabled|disabled|adaptive (adaptive = enabled), budget_tokens ignored;
66
66
  // effort takes every word ours does (medium and xhigh = high). Context
67
67
  // editing and thinking.display are not in its schema.
68
- send: { drop: ["context_management"], thinking: ["type", "budget_tokens"] },
68
+ send: { drop: ["context_management"], thinking: ["type", "budget_tokens"], mergeSystemMessages: true, dropDeferredTools: true },
69
69
  },
70
70
  moonshot: {
71
71
  name: "moonshot",
@@ -83,6 +83,8 @@ export const SUPPLY_PROVIDERS = {
83
83
  fields: ["model", "messages", "max_tokens", "system", "stream", "stop_sequences", "tools", "tool_choice", "metadata", "cache_control", "output_config"],
84
84
  thinking: null,
85
85
  effort: { minimal: "low", low: "low", medium: "high", high: "high", xhigh: "high", max: "max" },
86
+ mergeSystemMessages: true,
87
+ dropDeferredTools: true,
86
88
  },
87
89
  },
88
90
  };
@@ -159,6 +161,34 @@ export function shapeRequest(p, json) {
159
161
  (delete t[k], (changed = true));
160
162
  }
161
163
  }
164
+ if (shape.dropDeferredTools && Array.isArray(json.tools)) {
165
+ const kept = json.tools.filter((t) => !(t && typeof t === "object" && t.defer_loading === true));
166
+ if (kept.length !== json.tools.length) {
167
+ json.tools = kept;
168
+ changed = true;
169
+ }
170
+ }
171
+ if (shape.mergeSystemMessages && Array.isArray(json.messages)) {
172
+ const out = [];
173
+ const blocksOf = (c) => typeof c === "string" ? [{ type: "text", text: c }] : Array.isArray(c) ? c : [];
174
+ for (const m of json.messages) {
175
+ if (!m || m.role !== "system") {
176
+ out.push(m);
177
+ continue;
178
+ }
179
+ changed = true;
180
+ // Its words only: an effort-only system message carries none.
181
+ const text = blocksOf(m.content).filter((b) => b && b.type === "text" && typeof b.text === "string" && b.text).map((b) => ({ type: "text", text: b.text }));
182
+ if (!text.length)
183
+ continue;
184
+ const prev = out[out.length - 1];
185
+ if (prev && prev.role === "user")
186
+ prev.content = [...blocksOf(prev.content), ...text];
187
+ else
188
+ out.push({ role: "user", content: text });
189
+ }
190
+ json.messages = out;
191
+ }
162
192
  const oc = json.output_config;
163
193
  if (shape.effort && oc && typeof oc === "object" && typeof oc.effort === "string") {
164
194
  const word = oc.effort;
@@ -225,6 +225,7 @@ export const PROVIDERS = [
225
225
  maxTokensParam: "max_completion_tokens", reasoningEffort: true, promptCacheKey: true,
226
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
+ reasoningEffort: true,
228
229
  note: "Google's OpenAI-compatible route. Unknown parameters are ignored silently; reasoning cannot be switched off on the newest models." },
229
230
  { name: "xai", title: "xAI Grok", format: "openai", baseUrl: "https://api.x.ai/v1", auth: "bearer",
230
231
  maxTokensParam: "max_completion_tokens", reasoningEffort: true },
@@ -3954,6 +3954,11 @@ const MAX_BACKOFF_MS = 30_000;
3954
3954
  export function isTransientOverload(text) {
3955
3955
  if (/credits?\b|quota|billing|insufficient|payment|401|402|403/i.test(text))
3956
3956
  return false;
3957
+ // The platform's own answer on foldrun's models (no price, the day's cap,
3958
+ // the provider withdrawn) is a decision, not load: a retry cannot change
3959
+ // it (e2e check, 3 Nov 2026 — a cap refusal retried for minutes).
3960
+ if (/foldrun's models/i.test(text))
3961
+ return false;
3957
3962
  return /\b(429|503|529)\b|overloaded|rate.?limit|too many requests|try again/i.test(text);
3958
3963
  }
3959
3964
  /**
@@ -207,6 +207,10 @@ export function toChatCompletions(req, opts, drop = dropped()) {
207
207
  out.messages = messages;
208
208
  const tools = [];
209
209
  for (const t of (Array.isArray(req.tools) ? req.tools : [])) {
210
+ // A tool deferred for Anthropic's tool search (the SDK always sends a
211
+ // placeholder) is not a tool this endpoint can call.
212
+ if (t.defer_loading === true)
213
+ continue;
210
214
  if (t.type && t.type !== "custom") {
211
215
  drop.add(`server-side tool ${String(t.type)}`);
212
216
  continue;
@@ -381,6 +385,10 @@ export function toResponses(req, opts, drop = dropped()) {
381
385
  out.input = input;
382
386
  const tools = [];
383
387
  for (const t of (Array.isArray(req.tools) ? req.tools : [])) {
388
+ // A tool deferred for Anthropic's tool search (the SDK always sends a
389
+ // placeholder) is not a tool this endpoint can call.
390
+ if (t.defer_loading === true)
391
+ continue;
384
392
  if (t.type && t.type !== "custom") {
385
393
  drop.add(`server-side tool ${String(t.type)}`);
386
394
  continue;
@@ -1029,6 +1037,13 @@ export async function startTranslator(spec) {
1029
1037
  }
1030
1038
  // The status crosses unchanged, so a 401 or 429 from the provider
1031
1039
  // reads as one to the SDK — and to the fallback decision upstream.
1040
+ // A refusal that says not to retry (the platform's gateway does)
1041
+ // says so to the SDK too, or it retries a decision for minutes.
1042
+ const noRetry = upstream.headers.get("x-should-retry");
1043
+ if (noRetry) {
1044
+ res.writeHead(upstream.status, { "content-type": "application/json", "x-should-retry": noRetry });
1045
+ return void res.end(errorBody(upstream.status, message));
1046
+ }
1032
1047
  return send(upstream.status, errorBody(upstream.status, message));
1033
1048
  }
1034
1049
  const model = String(body.model ?? "");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@foldrun/core",
3
- "version": "14.2.0",
3
+ "version": "14.2.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",
@@ -51,6 +51,13 @@ export interface SendShape {
51
51
  thinking?: string[] | null;
52
52
  /** `output_config.effort`, as this provider spells it. */
53
53
  effort?: Record<string, string>;
54
+ /** A `system` message inside `messages` (Anthropic's mid-conversation
55
+ * instructions, which the SDK sends) folded into the user turn before
56
+ * it: the endpoint documents user and assistant roles only. */
57
+ mergeSystemMessages?: boolean;
58
+ /** Tools deferred for Anthropic's tool search (`defer_loading`; the SDK
59
+ * always sends a placeholder) dropped: the endpoint cannot load them. */
60
+ dropDeferredTools?: boolean;
54
61
  }
55
62
 
56
63
  export const SUPPLY_PROVIDERS: Record<SupplyProviderName, SupplyProvider> = {
@@ -104,7 +111,7 @@ export const SUPPLY_PROVIDERS: Record<SupplyProviderName, SupplyProvider> = {
104
111
  // enabled|disabled|adaptive (adaptive = enabled), budget_tokens ignored;
105
112
  // effort takes every word ours does (medium and xhigh = high). Context
106
113
  // editing and thinking.display are not in its schema.
107
- send: { drop: ["context_management"], thinking: ["type", "budget_tokens"] },
114
+ send: { drop: ["context_management"], thinking: ["type", "budget_tokens"], mergeSystemMessages: true, dropDeferredTools: true },
108
115
  },
109
116
  moonshot: {
110
117
  name: "moonshot",
@@ -122,6 +129,8 @@ export const SUPPLY_PROVIDERS: Record<SupplyProviderName, SupplyProvider> = {
122
129
  fields: ["model", "messages", "max_tokens", "system", "stream", "stop_sequences", "tools", "tool_choice", "metadata", "cache_control", "output_config"],
123
130
  thinking: null,
124
131
  effort: { minimal: "low", low: "low", medium: "high", high: "high", xhigh: "high", max: "max" },
132
+ mergeSystemMessages: true,
133
+ dropDeferredTools: true,
125
134
  },
126
135
  },
127
136
  };
@@ -210,6 +219,32 @@ export function shapeRequest(p: SupplyProvider, json: Record<string, unknown>):
210
219
  for (const k of Object.keys(t)) if (!shape.thinking.includes(k)) (delete t[k], (changed = true));
211
220
  }
212
221
  }
222
+ if (shape.dropDeferredTools && Array.isArray(json.tools)) {
223
+ const kept = (json.tools as unknown[]).filter((t) => !(t && typeof t === "object" && (t as Record<string, unknown>).defer_loading === true));
224
+ if (kept.length !== json.tools.length) {
225
+ json.tools = kept;
226
+ changed = true;
227
+ }
228
+ }
229
+ if (shape.mergeSystemMessages && Array.isArray(json.messages)) {
230
+ const out: Record<string, unknown>[] = [];
231
+ const blocksOf = (c: unknown): Record<string, unknown>[] =>
232
+ typeof c === "string" ? [{ type: "text", text: c }] : Array.isArray(c) ? (c as Record<string, unknown>[]) : [];
233
+ for (const m of json.messages as Record<string, unknown>[]) {
234
+ if (!m || m.role !== "system") {
235
+ out.push(m);
236
+ continue;
237
+ }
238
+ changed = true;
239
+ // Its words only: an effort-only system message carries none.
240
+ const text = blocksOf(m.content).filter((b) => b && b.type === "text" && typeof b.text === "string" && b.text).map((b) => ({ type: "text", text: b.text }));
241
+ if (!text.length) continue;
242
+ const prev = out[out.length - 1];
243
+ if (prev && prev.role === "user") prev.content = [...blocksOf(prev.content), ...text];
244
+ else out.push({ role: "user", content: text });
245
+ }
246
+ json.messages = out;
247
+ }
213
248
  const oc = json.output_config;
214
249
  if (shape.effort && oc && typeof oc === "object" && typeof (oc as Record<string, unknown>).effort === "string") {
215
250
  const word = (oc as Record<string, unknown>).effort as string;
package/src/providers.ts CHANGED
@@ -440,6 +440,7 @@ export const PROVIDERS: readonly ProviderPreset[] = [
440
440
  maxTokensParam: "max_completion_tokens", reasoningEffort: true, promptCacheKey: true,
441
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
+ reasoningEffort: true,
443
444
  note: "Google's OpenAI-compatible route. Unknown parameters are ignored silently; reasoning cannot be switched off on the newest models." },
444
445
  { name: "xai", title: "xAI Grok", format: "openai", baseUrl: "https://api.x.ai/v1", auth: "bearer",
445
446
  maxTokensParam: "max_completion_tokens", reasoningEffort: true },
package/src/runner.ts CHANGED
@@ -4168,6 +4168,10 @@ const MAX_BACKOFF_MS = 30_000;
4168
4168
  */
4169
4169
  export function isTransientOverload(text: string): boolean {
4170
4170
  if (/credits?\b|quota|billing|insufficient|payment|401|402|403/i.test(text)) return false;
4171
+ // The platform's own answer on foldrun's models (no price, the day's cap,
4172
+ // the provider withdrawn) is a decision, not load: a retry cannot change
4173
+ // it (e2e check, 3 Nov 2026 — a cap refusal retried for minutes).
4174
+ if (/foldrun's models/i.test(text)) return false;
4171
4175
  return /\b(429|503|529)\b|overloaded|rate.?limit|too many requests|try again/i.test(text);
4172
4176
  }
4173
4177
 
package/src/translator.ts CHANGED
@@ -284,6 +284,9 @@ export function toChatCompletions(
284
284
 
285
285
  const tools: Json[] = [];
286
286
  for (const t of (Array.isArray(req.tools) ? req.tools : []) as Json[]) {
287
+ // A tool deferred for Anthropic's tool search (the SDK always sends a
288
+ // placeholder) is not a tool this endpoint can call.
289
+ if (t.defer_loading === true) continue;
287
290
  if (t.type && t.type !== "custom") {
288
291
  drop.add(`server-side tool ${String(t.type)}`);
289
292
  continue;
@@ -441,6 +444,9 @@ export function toResponses(
441
444
 
442
445
  const tools: Json[] = [];
443
446
  for (const t of (Array.isArray(req.tools) ? req.tools : []) as Json[]) {
447
+ // A tool deferred for Anthropic's tool search (the SDK always sends a
448
+ // placeholder) is not a tool this endpoint can call.
449
+ if (t.defer_loading === true) continue;
444
450
  if (t.type && t.type !== "custom") {
445
451
  drop.add(`server-side tool ${String(t.type)}`);
446
452
  continue;
@@ -1089,6 +1095,13 @@ export async function startTranslator(spec: TranslatorSpec): Promise<RunningTran
1089
1095
  }
1090
1096
  // The status crosses unchanged, so a 401 or 429 from the provider
1091
1097
  // reads as one to the SDK — and to the fallback decision upstream.
1098
+ // A refusal that says not to retry (the platform's gateway does)
1099
+ // says so to the SDK too, or it retries a decision for minutes.
1100
+ const noRetry = upstream.headers.get("x-should-retry");
1101
+ if (noRetry) {
1102
+ res.writeHead(upstream.status, { "content-type": "application/json", "x-should-retry": noRetry });
1103
+ return void res.end(errorBody(upstream.status, message));
1104
+ }
1092
1105
  return send(upstream.status, errorBody(upstream.status, message));
1093
1106
  }
1094
1107