@foldrun/core 14.2.0 → 14.3.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.
- package/dist/src/completions.js +3 -0
- package/dist/src/flow-lint.js +1 -1
- package/dist/src/frontmatter-fields.js +2 -0
- package/dist/src/frontmatter-schema.js +7 -1
- package/dist/src/model-supply.d.ts +10 -0
- package/dist/src/model-supply.js +31 -1
- package/dist/src/providers.js +1 -0
- package/dist/src/runner.js +49 -2
- package/dist/src/scan.d.ts +8 -0
- package/dist/src/scan.js +75 -2
- package/dist/src/starter.js +1 -0
- package/dist/src/store.d.ts +22 -1
- package/dist/src/store.js +42 -1
- package/dist/src/translator.js +15 -0
- package/dist/src/workspace-check.js +6 -0
- package/package.json +1 -1
- package/src/completions.ts +3 -0
- package/src/flow-lint.ts +1 -1
- package/src/frontmatter-fields.ts +2 -0
- package/src/frontmatter-schema.ts +8 -1
- package/src/model-supply.ts +44 -2
- package/src/providers.ts +1 -0
- package/src/runner.ts +48 -1
- package/src/scan.ts +77 -2
- package/src/starter.ts +1 -0
- package/src/store.ts +55 -2
- package/src/translator.ts +13 -0
- package/src/workspace-check.ts +7 -1
package/dist/src/completions.js
CHANGED
|
@@ -89,6 +89,7 @@ const FIELDS = {
|
|
|
89
89
|
{ label: "description", insert: "description: ", hint: "required — what it does, and when" },
|
|
90
90
|
{ label: "model", insert: "model: default" },
|
|
91
91
|
{ label: "effort", insert: "effort: high", hint: "how hard it thinks" },
|
|
92
|
+
{ label: "max_output_tokens", insert: "max_output_tokens: 16000", hint: "the longest one reply may be, in tokens" },
|
|
92
93
|
{ label: "tools", insert: "tools:\n - write", hint: "what the runtime gives it" },
|
|
93
94
|
{ label: "secrets", insert: "secrets:\n - ", hint: "credentials it may spend" },
|
|
94
95
|
{ label: "skills", insert: "skills:\n - ", hint: "allowlist; omit to inherit all" },
|
|
@@ -162,6 +163,7 @@ const FIELDS = {
|
|
|
162
163
|
{ label: "timezone", insert: "timezone: Australia/Sydney" },
|
|
163
164
|
{ label: "model", insert: "model: fast", hint: "every step, unless the step says" },
|
|
164
165
|
{ label: "effort", insert: "effort: high", hint: "every step, unless the step says" },
|
|
166
|
+
{ label: "max_output_tokens", insert: "max_output_tokens: 16000", hint: "every step's longest reply, unless the step says" },
|
|
165
167
|
],
|
|
166
168
|
evalFile: [
|
|
167
169
|
{ label: "name", insert: "name: " },
|
|
@@ -271,6 +273,7 @@ const STEP_OPTIONS = [
|
|
|
271
273
|
{ label: "each", insert: "each: items", hint: "fan out: lines | items | rows of <csv>" },
|
|
272
274
|
{ label: "model", insert: "model: fast" },
|
|
273
275
|
{ label: "effort", insert: "effort: high", hint: "this step only" },
|
|
276
|
+
{ label: "max_output_tokens", insert: "max_output_tokens: 16000", hint: "the longest one reply may be, this step only" },
|
|
274
277
|
{ label: "approve", insert: "approve: true", hint: "pause for a human" },
|
|
275
278
|
];
|
|
276
279
|
// Header and query-parameter names, for the indented lines under `headers:`
|
package/dist/src/flow-lint.js
CHANGED
|
@@ -21,7 +21,7 @@ const SUBFLOW_DROPPED = [
|
|
|
21
21
|
["effort", "effort:"], ["onFail", "on-fail:"], ["waitSecs", "wait:"], ["waitFor", "wait:"],
|
|
22
22
|
["ask", "ask:"], ["preview", "preview:"], ["delegate", "delegate:"], ["loop", "loop:"],
|
|
23
23
|
["until", "until:"], ["each", "each:"], ["max", "max:"], ["output", "output:"],
|
|
24
|
-
["schema", "schema:"], ["parallel", "parallel:"], ["maxTurns", "max_turns:"], ["limits", "limits:"],
|
|
24
|
+
["schema", "schema:"], ["parallel", "parallel:"], ["maxTurns", "max_turns:"], ["maxOutputTokens", "max_output_tokens:"], ["limits", "limits:"],
|
|
25
25
|
];
|
|
26
26
|
// Anaphora: phrases that only mean something if earlier output exists.
|
|
27
27
|
// Deliberately conservative — a false warning is worse than a missed one,
|
|
@@ -33,6 +33,7 @@ const AGENT = [
|
|
|
33
33
|
{ key: "owner", type: "string", help: "the person accountable for it — an email or a name; else the workspace's, else the account's" },
|
|
34
34
|
{ key: "model", type: "string", help: "fast | default | max, an alias, or a full model id" },
|
|
35
35
|
{ key: "effort", type: "string", values: EFFORT_LEVELS, help: "how long it thinks" },
|
|
36
|
+
{ key: "max_output_tokens", type: ["number", "string"], help: "the most tokens one model reply may have, 1 to 1048576; on foldrun's models the price list's ceiling applies too" },
|
|
36
37
|
{ key: "size", type: "string", values: ["small", "large", "heavy"], help: "the sandbox it rents; anything else becomes large" },
|
|
37
38
|
{ key: "resources", type: "object", help: "{cpu, memory, disk} in numbers, over the size class's figures key by key — cpu 0.5–8, memory 256Mi–16Gi, disk 1–40Gi" },
|
|
38
39
|
{ key: "permissionMode", type: "string", values: ["plan"], help: "plan = read-only; no other mode changes anything here" },
|
|
@@ -104,6 +105,7 @@ const FLOW = [
|
|
|
104
105
|
{ key: "timezone", type: "string", validated: true, help: "the zone its schedule reads in" },
|
|
105
106
|
{ key: "model", type: "string", help: "every step's model unless the step says" },
|
|
106
107
|
{ key: "effort", type: "string", values: EFFORT_LEVELS, help: "every step's effort unless the step says" },
|
|
108
|
+
{ key: "max_output_tokens", type: ["number", "string"], help: "every step's longest reply, in tokens, unless the step or its agent says" },
|
|
107
109
|
{ key: "overlap", type: "string", validated: true, help: "skip | queue" },
|
|
108
110
|
{ key: "issues", type: "string", values: ["stay-open", "auto-close"], help: "what a good run does to this flow's open issues: stay-open (the default — a person resolves them) or auto-close" },
|
|
109
111
|
{ key: "priority", type: "string", validated: true, help: "high | normal | low" },
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// field list alone from frontmatter-fields.ts.
|
|
4
4
|
import { FRONTMATTER, JOBS } from "./frontmatter-fields.js";
|
|
5
5
|
import { jobFold } from "./matter.js";
|
|
6
|
-
import { resolveEffort, parseDuration, parseInstant, parseRate, STEP_OPTION_KEYS } from "./store.js";
|
|
6
|
+
import { resolveEffort, parseDuration, parseInstant, parseRate, STEP_OPTION_KEYS, parseMaxOutputTokens, MAX_OUTPUT_TOKENS_CAP } from "./store.js";
|
|
7
7
|
import { budgetProblem } from "./budget.js";
|
|
8
8
|
import { cronProblem, parseCron, cronCanFire } from "./cron.js";
|
|
9
9
|
import { SECRET_NAME } from "./secrets.js";
|
|
@@ -27,11 +27,16 @@ const DURATION = (min, max, unit = "") => (v) => {
|
|
|
27
27
|
return `"${String(v)}" is outside ${unit || `${min}s to ${max}s`}`;
|
|
28
28
|
return null;
|
|
29
29
|
};
|
|
30
|
+
/** `max_output_tokens:` — a whole number of tokens the runtime can be told. */
|
|
31
|
+
function maxOutputProblem(v) {
|
|
32
|
+
return parseMaxOutputTokens(v) === undefined ? `${shown(v)} is not a number of tokens, 1 to ${MAX_OUTPUT_TOKENS_CAP}; the model's own limit applies` : null;
|
|
33
|
+
}
|
|
30
34
|
/** Why a value is wrong, or null — per kind, per field: the rules a list of
|
|
31
35
|
* values cannot say (aliases, durations, cron, budgets). */
|
|
32
36
|
const CHECKS = {
|
|
33
37
|
"agent": {
|
|
34
38
|
effort: (v) => (resolveEffort(v) ? null : `"${String(v)}" is not an effort — low, medium, high, xhigh or max; the step runs at the model's default`),
|
|
39
|
+
max_output_tokens: maxOutputProblem,
|
|
35
40
|
apis: apisProblem,
|
|
36
41
|
remotes: remotesProblem,
|
|
37
42
|
budget: (v) => budgetProblem(v, ["run"]),
|
|
@@ -47,6 +52,7 @@ const CHECKS = {
|
|
|
47
52
|
"flow": {
|
|
48
53
|
schedule: cronProblem,
|
|
49
54
|
effort: (v) => (resolveEffort(v) ? null : `"${String(v)}" is not an effort — low, medium, high, xhigh or max`),
|
|
55
|
+
max_output_tokens: maxOutputProblem,
|
|
50
56
|
at: (v) => (parseInstant(v) ? null : `"${String(v)}" is not an ISO 8601 instant — a once flow with it never fires`),
|
|
51
57
|
url: (v) => (/^https?:\/\//i.test(String(v)) ? null : `"${String(v)}" is not an http(s) URL`),
|
|
52
58
|
every: DURATION(1, 30 * 86400, "1s to 30 days"),
|
|
@@ -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[];
|
|
@@ -59,6 +66,9 @@ export type SupplyAnswer = {
|
|
|
59
66
|
kind: "foldrun";
|
|
60
67
|
provider: SupplyProviderName;
|
|
61
68
|
tiers: Partial<Record<"fast" | "default" | "max", string>>;
|
|
69
|
+
/** The price list's output ceiling per model id: the most one reply
|
|
70
|
+
* may be on the platform's key, told to the runtime up front. */
|
|
71
|
+
ceilings?: Record<string, number>;
|
|
62
72
|
} | {
|
|
63
73
|
kind: "refused";
|
|
64
74
|
reason: string;
|
package/dist/src/model-supply.js
CHANGED
|
@@ -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;
|
package/dist/src/providers.js
CHANGED
|
@@ -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 },
|
package/dist/src/runner.js
CHANGED
|
@@ -42,7 +42,7 @@ import { ASK_TOOL, PEER_TOOLS, applyOperatorEvent, askPromptLine, askTimeoutSec,
|
|
|
42
42
|
import { sendPlainNotification } from "./notify.js";
|
|
43
43
|
import { TOOL_MAP, BUILTIN_TOOLS, ownToolNames, toolRefs, legacyUseNames, legacyUseError, retiredToolNames, retiredToolError } from "./tool-names.js";
|
|
44
44
|
import { refNames } from "./refs.js";
|
|
45
|
-
import { accountDir, workspaceDir, buildMemoryIndex, workspaceMemoryIndex, knowledgeIndex, workspaceKnowledgeIndex, workspaceTools, brokenToolReport, listWorkspaces, listTenants, listRuns, liveRuns, syncBundleFor, parseToolDef, readFlow, markerPresent, whenRowsPath, parseApis, resolveModel, parseProvider, providerEnvFor, resolveEffort, isEffortWord, EFFORT_LEVELS, checkFormatVersion, readRun, writeRun, isSplicedRecord, runSummary, verdictOf, sumAttempts, tokensOf, parseSchemaText, STORAGE_DIR, adoptLegacyVersionKey, listAgents, isOneSegment, stoppedByText, } from "./store.js";
|
|
45
|
+
import { accountDir, workspaceDir, buildMemoryIndex, workspaceMemoryIndex, knowledgeIndex, workspaceKnowledgeIndex, workspaceTools, brokenToolReport, listWorkspaces, listTenants, listRuns, liveRuns, syncBundleFor, parseToolDef, readFlow, markerPresent, whenRowsPath, parseApis, resolveModel, parseProvider, providerEnvFor, resolveEffort, parseMaxOutputTokens, isEffortWord, EFFORT_LEVELS, checkFormatVersion, readRun, writeRun, isSplicedRecord, runSummary, verdictOf, sumAttempts, tokensOf, parseSchemaText, STORAGE_DIR, adoptLegacyVersionKey, listAgents, isOneSegment, stoppedByText, } from "./store.js";
|
|
46
46
|
import { canReadBack } from "./tool-output.js";
|
|
47
47
|
import { PromptLayers, promptCacheKey } from "./prompt-layers.js";
|
|
48
48
|
import { loadCatalog, checkModel, clampEffort, catalogCost, findModel, tokenPriceOf } from "./catalog.js";
|
|
@@ -2470,6 +2470,20 @@ mayDefer) {
|
|
|
2470
2470
|
// this the in-pod meter priced haiku and sonnet at Opus rates and a
|
|
2471
2471
|
// step was stopped at up to fifteen times what it had spent.
|
|
2472
2472
|
tokenPrice ??= knownPrice(wireModel);
|
|
2473
|
+
// `max_output_tokens:` — the step's own (or its flow's, snapshotted on
|
|
2474
|
+
// the run), else the agent's; on foldrun's models never above the price
|
|
2475
|
+
// list's ceiling for the model it runs, so the runtime knows its real
|
|
2476
|
+
// limit up front instead of the gateway cutting it short (3 Nov 2026).
|
|
2477
|
+
const askedOut = step.maxOutputTokens ?? parseMaxOutputTokens(front.max_output_tokens);
|
|
2478
|
+
const outCeiling = onSupply && supply.kind === "foldrun" ? supply.ceilings?.[wireModel] : undefined;
|
|
2479
|
+
const maxOut = askedOut && outCeiling ? Math.min(askedOut, outCeiling) : (askedOut ?? outCeiling);
|
|
2480
|
+
if (askedOut && outCeiling && askedOut > outCeiling) {
|
|
2481
|
+
push("info", `max_output_tokens: ${askedOut} runs as ${outCeiling} — the price list's ceiling for ${wireModel} on foldrun's models`);
|
|
2482
|
+
}
|
|
2483
|
+
const outputEnv = maxOut ? { CLAUDE_CODE_MAX_OUTPUT_TOKENS: String(maxOut) } : {};
|
|
2484
|
+
if (maxOut && !(askedOut && outCeiling && askedOut > outCeiling)) {
|
|
2485
|
+
push("info", `max_output_tokens: ${maxOut}${askedOut ? "" : " — the price list's ceiling on foldrun's models"}`);
|
|
2486
|
+
}
|
|
2473
2487
|
fs.mkdirSync(path.join(agentDir, "outputs"), { recursive: true });
|
|
2474
2488
|
fs.mkdirSync(path.join(agentDir, "memory"), { recursive: true });
|
|
2475
2489
|
// Expose the workspace's shared scripts/ as ./shared so every agent reaches
|
|
@@ -3065,6 +3079,7 @@ mayDefer) {
|
|
|
3065
3079
|
// A provider: block still wins, because providerEnv is spread
|
|
3066
3080
|
// after and carries the agent's chosen endpoint + token.
|
|
3067
3081
|
...proxied(Object.keys(providerEnv).length === 0 ? modelEnv : providerEnv, keyName),
|
|
3082
|
+
...outputEnv,
|
|
3068
3083
|
...(lease ? { [EGRESS_ENV]: lease.url } : {}),
|
|
3069
3084
|
// Every program's HTTP(S) through the proxy's forward door, and
|
|
3070
3085
|
// the CA it signs bound sites with, for the sandbox to trust.
|
|
@@ -3533,7 +3548,7 @@ mayDefer) {
|
|
|
3533
3548
|
// the allowlisted host environment, not process.env: the SDK's
|
|
3534
3549
|
// Bash tool runs with this, and on a platform process.env holds
|
|
3535
3550
|
// every tenant's root key and the datastore credentials.
|
|
3536
|
-
env: { ...hostSafeEnv(), ...clockEnv, ...(testRun ? testModeEnv() : {}), ...mat.env, ...installEnv, ...modelEnv },
|
|
3551
|
+
env: { ...hostSafeEnv(), ...clockEnv, ...(testRun ? testModeEnv() : {}), ...mat.env, ...installEnv, ...modelEnv, ...outputEnv },
|
|
3537
3552
|
timeoutSec: step.timeout,
|
|
3538
3553
|
budgetUsd: stepBudgetUsd,
|
|
3539
3554
|
budgetNote: stepBudgetNote,
|
|
@@ -3954,6 +3969,11 @@ const MAX_BACKOFF_MS = 30_000;
|
|
|
3954
3969
|
export function isTransientOverload(text) {
|
|
3955
3970
|
if (/credits?\b|quota|billing|insufficient|payment|401|402|403/i.test(text))
|
|
3956
3971
|
return false;
|
|
3972
|
+
// The platform's own answer on foldrun's models (no price, the day's cap,
|
|
3973
|
+
// the provider withdrawn) is a decision, not load: a retry cannot change
|
|
3974
|
+
// it (e2e check, 3 Nov 2026 — a cap refusal retried for minutes).
|
|
3975
|
+
if (/foldrun's models/i.test(text))
|
|
3976
|
+
return false;
|
|
3957
3977
|
return /\b(429|503|529)\b|overloaded|rate.?limit|too many requests|try again/i.test(text);
|
|
3958
3978
|
}
|
|
3959
3979
|
/**
|
|
@@ -4180,6 +4200,13 @@ export function createFlowRun(tenant, workspace, steps, flowName, status, tags =
|
|
|
4180
4200
|
/** An A2A task's correlation (foldrun-platform flow-admission.ts) — its
|
|
4181
4201
|
* own trailing argument, so the signature only widened. */
|
|
4182
4202
|
a2a) {
|
|
4203
|
+
let flowMaxOut;
|
|
4204
|
+
try {
|
|
4205
|
+
flowMaxOut = readFlow(tenant, workspace, flowName)?.maxOutputTokens;
|
|
4206
|
+
}
|
|
4207
|
+
catch {
|
|
4208
|
+
flowMaxOut = undefined;
|
|
4209
|
+
}
|
|
4183
4210
|
const run = {
|
|
4184
4211
|
id: `run-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 6)}`,
|
|
4185
4212
|
flow: flowName,
|
|
@@ -4198,6 +4225,11 @@ a2a) {
|
|
|
4198
4225
|
optional: s.optional ?? false,
|
|
4199
4226
|
model: s.model,
|
|
4200
4227
|
effort: s.effort,
|
|
4228
|
+
// The flow's default snapshotted here, as a step's own options are:
|
|
4229
|
+
// what the run started with is what it runs with. A step from a
|
|
4230
|
+
// nested flow carries that flow's own (expandSubflows).
|
|
4231
|
+
...((s.maxOutputTokens ?? s.flowMaxOutputTokens ?? flowMaxOut) ? { maxOutputTokens: s.maxOutputTokens ?? s.flowMaxOutputTokens ?? flowMaxOut } : {}),
|
|
4232
|
+
...((s.flowMaxOutputTokens ?? flowMaxOut) ? { flowMaxOutputTokens: s.flowMaxOutputTokens ?? flowMaxOut } : {}),
|
|
4201
4233
|
approve: s.approve,
|
|
4202
4234
|
when: s.when,
|
|
4203
4235
|
case: s.case,
|
|
@@ -5147,6 +5179,8 @@ function driveRunInner(tenant, workspace, run, modelOverride, tags, opts) {
|
|
|
5147
5179
|
delegation: id,
|
|
5148
5180
|
instruction: job,
|
|
5149
5181
|
group: parent.group,
|
|
5182
|
+
// A job done for a step is held to that step's output limit.
|
|
5183
|
+
...(parent.maxOutputTokens ? { maxOutputTokens: parent.maxOutputTokens } : {}),
|
|
5150
5184
|
optional: true,
|
|
5151
5185
|
timeout: parent.timeout,
|
|
5152
5186
|
attempts: 1,
|
|
@@ -5636,6 +5670,9 @@ function driveRunInner(tenant, workspace, run, modelOverride, tags, opts) {
|
|
|
5636
5670
|
optional: false,
|
|
5637
5671
|
model: step.model,
|
|
5638
5672
|
effort: step.effort,
|
|
5673
|
+
// The step's output limit (its own, or the flow's snapshotted
|
|
5674
|
+
// on it) holds for whoever takes the step over (Codex review).
|
|
5675
|
+
...(step.maxOutputTokens ? { maxOutputTokens: step.maxOutputTokens } : {}),
|
|
5639
5676
|
timeout: step.timeout,
|
|
5640
5677
|
// The rescuer inherits the contract, not just the job: a step
|
|
5641
5678
|
// that promised data still owes data when someone else does it,
|
|
@@ -5729,6 +5766,10 @@ function driveRunInner(tenant, workspace, run, modelOverride, tags, opts) {
|
|
|
5729
5766
|
instruction: m[2].trim(),
|
|
5730
5767
|
group: chooser.group,
|
|
5731
5768
|
optional: false,
|
|
5769
|
+
// The output limit of the flow the chooser was written in, as a
|
|
5770
|
+
// step of that file would have it (Codex review); the chooser's
|
|
5771
|
+
// own options are its own.
|
|
5772
|
+
...(chooser.flowMaxOutputTokens ? { maxOutputTokens: chooser.flowMaxOutputTokens, flowMaxOutputTokens: chooser.flowMaxOutputTokens } : {}),
|
|
5732
5773
|
attempts: 0,
|
|
5733
5774
|
status: "pending",
|
|
5734
5775
|
events: [],
|
|
@@ -5928,11 +5969,17 @@ function expandSubflows(tenant, workspace, steps, seen = [], depth = 0) {
|
|
|
5928
5969
|
for (const ns of nestedSteps) {
|
|
5929
5970
|
const g = base + ns.group;
|
|
5930
5971
|
maxGroup = Math.max(maxGroup, g);
|
|
5972
|
+
// The nested flow's own output limit holds for its steps (a step's
|
|
5973
|
+
// own still wins), as its file says (Codex review).
|
|
5974
|
+
const flowMax = ns.flowMaxOutputTokens ?? nested.maxOutputTokens;
|
|
5975
|
+
const maxOut = ns.maxOutputTokens ?? flowMax;
|
|
5931
5976
|
out.push({
|
|
5932
5977
|
...ns,
|
|
5933
5978
|
group: g,
|
|
5934
5979
|
optional: ns.optional || step.optional,
|
|
5935
5980
|
instruction: ns.instruction || step.instruction,
|
|
5981
|
+
...(maxOut ? { maxOutputTokens: maxOut } : {}),
|
|
5982
|
+
...(flowMax ? { flowMaxOutputTokens: flowMax } : {}),
|
|
5936
5983
|
});
|
|
5937
5984
|
}
|
|
5938
5985
|
group = maxGroup;
|
package/dist/src/scan.d.ts
CHANGED
|
@@ -48,6 +48,14 @@ export interface ScanOptions {
|
|
|
48
48
|
model: string;
|
|
49
49
|
on: string;
|
|
50
50
|
} | null;
|
|
51
|
+
/** The most one reply may be on the model this account's steps run on
|
|
52
|
+
* (a `model:` word or id) — the price list's ceiling on foldrun's
|
|
53
|
+
* models — or null when that is not known here. */
|
|
54
|
+
outputCeiling?: (model: string) => {
|
|
55
|
+
ceiling: number;
|
|
56
|
+
model: string;
|
|
57
|
+
on: string;
|
|
58
|
+
} | null;
|
|
51
59
|
}
|
|
52
60
|
export declare const OWASP_URL = "https://genai.owasp.org/resource/owasp-top-10-for-agentic-applications-for-2026";
|
|
53
61
|
export declare const SCAN_RULES: readonly ScanRule[];
|
package/dist/src/scan.js
CHANGED
|
@@ -32,7 +32,7 @@ import { resolveNetwork } from "./network.js";
|
|
|
32
32
|
import { frontmatterProblems, schemaKindOf } from "./frontmatter-schema.js";
|
|
33
33
|
import { parseRemotes } from "./a2a-remotes.js";
|
|
34
34
|
import { isA2aPublished } from "./a2a-publish.js";
|
|
35
|
-
import { parseFlow, resolveEffort } from "./store.js";
|
|
35
|
+
import { parseFlow, resolveEffort, parseMaxOutputTokens } from "./store.js";
|
|
36
36
|
export const OWASP_URL = "https://genai.owasp.org/resource/owasp-top-10-for-agentic-applications-for-2026";
|
|
37
37
|
export const SCAN_RULES = [
|
|
38
38
|
{
|
|
@@ -239,6 +239,15 @@ export const SCAN_RULES = [
|
|
|
239
239
|
"The step still runs, at the nearest level the model has, and the step's log says so. Write the level it has, or choose " +
|
|
240
240
|
"a provider whose model has the one you want (Settings → Model provider).",
|
|
241
241
|
},
|
|
242
|
+
{
|
|
243
|
+
id: "config/output-fitted",
|
|
244
|
+
category: "config",
|
|
245
|
+
level: "warn",
|
|
246
|
+
title: "A max_output_tokens above what the account's model allows",
|
|
247
|
+
help: "On foldrun's models one reply may be at most the price list's ceiling for its model. The step still runs, with " +
|
|
248
|
+
"the ceiling as its limit, and the step's log says so. Write a number at or under the ceiling, or run the agent " +
|
|
249
|
+
"on your own key.",
|
|
250
|
+
},
|
|
242
251
|
{
|
|
243
252
|
id: "config/cron-never-fires",
|
|
244
253
|
category: "config",
|
|
@@ -956,6 +965,67 @@ function scanEfforts(agents, flows, runsAs, push) {
|
|
|
956
965
|
});
|
|
957
966
|
}
|
|
958
967
|
}
|
|
968
|
+
/**
|
|
969
|
+
* A `max_output_tokens:` above the ceiling of the model a step will run on:
|
|
970
|
+
* warned, not refused (the step runs at the ceiling). Resolved step → flow
|
|
971
|
+
* → agent, the written value first, as scanEfforts does.
|
|
972
|
+
*/
|
|
973
|
+
function scanOutputs(agents, flows, ceilingOf, push) {
|
|
974
|
+
const say = (file, line, asked, model, whence) => {
|
|
975
|
+
const c = ceilingOf(model);
|
|
976
|
+
if (!c || asked <= c.ceiling)
|
|
977
|
+
return;
|
|
978
|
+
push("config/output-fitted", file, line, `config/output-fitted ${file} ${whence} ${asked} ${c.model}`, `max_output_tokens: ${asked}${whence} runs as ${c.ceiling} on ${c.on} (${c.model}) — the price list's ceiling for that model.`);
|
|
979
|
+
};
|
|
980
|
+
const byName = new Map();
|
|
981
|
+
const ownProvider = new Set();
|
|
982
|
+
for (const a of agents) {
|
|
983
|
+
const model = typeof a.data.model === "string" && a.data.model.trim() ? a.data.model.trim() : "default";
|
|
984
|
+
byName.set(a.name, { model, raw: a.data.max_output_tokens });
|
|
985
|
+
if (a.data.provider) {
|
|
986
|
+
ownProvider.add(a.name);
|
|
987
|
+
continue;
|
|
988
|
+
}
|
|
989
|
+
const n = parseMaxOutputTokens(a.data.max_output_tokens);
|
|
990
|
+
if (n)
|
|
991
|
+
say(a.file, keyLine(a.lines, "max_output_tokens"), n, model, "");
|
|
992
|
+
}
|
|
993
|
+
for (const fl of flows) {
|
|
994
|
+
let info;
|
|
995
|
+
try {
|
|
996
|
+
info = parseFlow(fl.file, fl.content);
|
|
997
|
+
}
|
|
998
|
+
catch {
|
|
999
|
+
continue;
|
|
1000
|
+
}
|
|
1001
|
+
const steps = [...(info.steps ?? [])].sort((x, y) => (x.line ?? 0) - (y.line ?? 0));
|
|
1002
|
+
const flowLine = keyLine(fl.lines, "max_output_tokens");
|
|
1003
|
+
steps.forEach((st, i) => {
|
|
1004
|
+
if (st.subflow || ownProvider.has(st.agent))
|
|
1005
|
+
return;
|
|
1006
|
+
const agent = byName.get(st.agent);
|
|
1007
|
+
const from = st.maxOutputTokens != null ? "step" : info.maxOutputTokens != null ? "flow" : "agent";
|
|
1008
|
+
const n = from === "step" ? st.maxOutputTokens : from === "flow" ? info.maxOutputTokens : parseMaxOutputTokens(agent?.raw);
|
|
1009
|
+
if (!n)
|
|
1010
|
+
return;
|
|
1011
|
+
const model = st.model ?? info.model ?? agent?.model ?? "default";
|
|
1012
|
+
if (from === "step") {
|
|
1013
|
+
const to = steps[i + 1]?.line ?? fl.lines.length + 1;
|
|
1014
|
+
let at;
|
|
1015
|
+
for (let k = st.line ?? 1; k < to; k++)
|
|
1016
|
+
if (/^\s+max_output_tokens\s*:/.test(fl.lines[k - 1] ?? ""))
|
|
1017
|
+
at = k;
|
|
1018
|
+
say(fl.file, at ?? st.line, n, model, ` (step ${st.agent})`);
|
|
1019
|
+
}
|
|
1020
|
+
else if (from === "flow") {
|
|
1021
|
+
say(fl.file, flowLine, n, model, ` (the flow's, on step ${st.agent})`);
|
|
1022
|
+
}
|
|
1023
|
+
else if (st.model || info.model) {
|
|
1024
|
+
say(fl.file, st.line, n, model, ` (${st.agent}'s own, on this step's model)`);
|
|
1025
|
+
}
|
|
1026
|
+
});
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
959
1029
|
export function scanFiles(files, options = {}) {
|
|
960
1030
|
const want = options.only?.length ? new Set(options.only) : null;
|
|
961
1031
|
const enabled = (rule) => !want || want.has(rule) || want.has(scanRule(rule)?.category ?? "") || rule === "check/ignore-needs-reason";
|
|
@@ -1066,8 +1136,11 @@ export function scanFiles(files, options = {}) {
|
|
|
1066
1136
|
scanPublishedFlows(flows, legs, push);
|
|
1067
1137
|
// A workspace that names its own provider: does not run on the account's
|
|
1068
1138
|
// choice, so the account's models say nothing about its efforts.
|
|
1069
|
-
|
|
1139
|
+
const ownWorkspaceProvider = Boolean(workspaceMd && frontOf(workspaceMd.content, "AGENTS.md")?.provider);
|
|
1140
|
+
if (options.effortRunsAs && !ownWorkspaceProvider)
|
|
1070
1141
|
scanEfforts(agents, flows, options.effortRunsAs, push);
|
|
1142
|
+
if (options.outputCeiling && !ownWorkspaceProvider)
|
|
1143
|
+
scanOutputs(agents, flows, options.outputCeiling, push);
|
|
1071
1144
|
for (const m of more.values()) {
|
|
1072
1145
|
findings.push({ rule: m.rule, level: m.level ?? scanRule(m.rule)?.level ?? "warn", file: m.file, message: `and ${m.n} more like this in this file, not listed`, fingerprint: m.hash.digest("hex").slice(0, 16), truncated: true });
|
|
1073
1146
|
}
|
package/dist/src/starter.js
CHANGED
|
@@ -451,6 +451,7 @@ Indented under a step, any of:
|
|
|
451
451
|
| \`verify: judge: <claim>\` | a model grades the claim against the output |
|
|
452
452
|
| \`verify: contains:\` / \`not-contains:\` / \`matches:\` / \`file:\` | the cheap checks, no shell |
|
|
453
453
|
| \`model:\` / \`effort:\` | override the flow's default for this step |
|
|
454
|
+
| \`max_output_tokens:\` | the longest one reply may be, in tokens, for this step |
|
|
454
455
|
| \`loop: 3\` / \`until: <condition>\` | repeat until it holds, at most 5 |
|
|
455
456
|
| \`each: lines\` | run once per line of the previous result |
|
|
456
457
|
| \`each: rows of <path>\` | run once per CSV row |
|
package/dist/src/store.d.ts
CHANGED
|
@@ -306,6 +306,8 @@ export interface AgentInfo {
|
|
|
306
306
|
* the interface did not say so, so every consumer had to re-read the file
|
|
307
307
|
* to show it. */
|
|
308
308
|
effort: string | null;
|
|
309
|
+
/** `max_output_tokens:` — the longest one reply may be, when it says. */
|
|
310
|
+
maxOutputTokens?: number;
|
|
309
311
|
tools: string[];
|
|
310
312
|
apis: ApiSpec[];
|
|
311
313
|
/** `remotes:` — the outside A2A agents it may call, the entries that read
|
|
@@ -511,6 +513,14 @@ export interface FlowStep {
|
|
|
511
513
|
parallel?: number;
|
|
512
514
|
/** `max_turns:` — the most model turns this step may take before it is
|
|
513
515
|
* stopped, beside `budget:` (money) and `timeout:` (time). */
|
|
516
|
+
/** `max_output_tokens:` — the longest one model reply may be, in tokens.
|
|
517
|
+
* On a run's step: the step's own, else the flow's, snapshotted when the
|
|
518
|
+
* run was created (createFlowRun); the agent's is read at the step. */
|
|
519
|
+
maxOutputTokens?: number;
|
|
520
|
+
/** The `max_output_tokens:` default of the flow this step was written in
|
|
521
|
+
* (a nested flow's own, when it came from one): what a `delegate:`
|
|
522
|
+
* chooser's picks are held to. Set by expansion and createFlowRun. */
|
|
523
|
+
flowMaxOutputTokens?: number;
|
|
514
524
|
maxTurns?: number;
|
|
515
525
|
/** `limits: {web.search: 10}` — this step's call limits, over the agent's
|
|
516
526
|
* (nearest wins per key). See limits.ts. */
|
|
@@ -536,6 +546,8 @@ export interface FlowInfo {
|
|
|
536
546
|
model: string | null;
|
|
537
547
|
/** Same, for effort. */
|
|
538
548
|
effort: string | null;
|
|
549
|
+
/** `max_output_tokens:` — every step's longest reply unless it says. */
|
|
550
|
+
maxOutputTokens?: number;
|
|
539
551
|
/** What a new fire does while a run of this flow is still live:
|
|
540
552
|
* "skip" doesn't start one, "queue" starts it but the worker holds it
|
|
541
553
|
* until the live run finishes. Unset keeps today's behaviour (runs may
|
|
@@ -688,6 +700,12 @@ export declare const STEP_OPTION_KEYS: ReadonlySet<string>;
|
|
|
688
700
|
/** The most fan-out instances `parallel:` may run at once — the fan-out's
|
|
689
701
|
* own hard cap, since more slots than items is no cap. */
|
|
690
702
|
export declare const PARALLEL_CAP = 20;
|
|
703
|
+
/** The most `max_output_tokens:` may say — 2^20, above any model's own
|
|
704
|
+
* limit today (Kimi's 1,048,576): a ceiling on typos, not on models. */
|
|
705
|
+
export declare const MAX_OUTPUT_TOKENS_CAP = 1048576;
|
|
706
|
+
/** `max_output_tokens:` as a whole number of tokens, or undefined when it
|
|
707
|
+
* is not one in range (YAML may hand over a number or a string). */
|
|
708
|
+
export declare function parseMaxOutputTokens(v: unknown): number | undefined;
|
|
691
709
|
/** The most turns `max_turns:` may allow. A turn is one model reply, tool
|
|
692
710
|
* calls included; a step that needs more than this is not one step. */
|
|
693
711
|
export declare const MAX_TURNS_CAP = 500;
|
|
@@ -792,7 +810,7 @@ declare function setFlowTriggerLF(raw: string, opts: {
|
|
|
792
810
|
schedule?: string;
|
|
793
811
|
timezone?: string;
|
|
794
812
|
}): string;
|
|
795
|
-
declare function updateFlowStepLF(raw: string, index: number, options: Partial<Record<"model" | "effort" | "retry" | "timeout" | "verify" | "when" | "case" | "else" | "loop" | "until" | "each" | "max" | "limits", string | number | null>>): string;
|
|
813
|
+
declare function updateFlowStepLF(raw: string, index: number, options: Partial<Record<"model" | "effort" | "max_output_tokens" | "retry" | "timeout" | "verify" | "when" | "case" | "else" | "loop" | "until" | "each" | "max" | "limits", string | number | null>>): string;
|
|
796
814
|
/** Append a step as its own group at the end of the flow. */
|
|
797
815
|
declare function addFlowStepLF(raw: string, step: {
|
|
798
816
|
target: string;
|
|
@@ -1258,6 +1276,9 @@ export interface StepRecord {
|
|
|
1258
1276
|
schema?: Record<string, unknown> | boolean;
|
|
1259
1277
|
schemaPath?: string;
|
|
1260
1278
|
parallel?: number;
|
|
1279
|
+
maxOutputTokens?: number;
|
|
1280
|
+
/** See FlowStep: the default of the flow this step was written in. */
|
|
1281
|
+
flowMaxOutputTokens?: number;
|
|
1261
1282
|
maxTurns?: number;
|
|
1262
1283
|
limits?: Record<string, number>;
|
|
1263
1284
|
/** The parsed JSON an `output: json` step returned. Kept beside the prose
|
package/dist/src/store.js
CHANGED
|
@@ -1186,6 +1186,7 @@ export function listAgents(tenant, workspace) {
|
|
|
1186
1186
|
...resolveOwner(data.owner, workspaceFront.owner, accountFront.owner),
|
|
1187
1187
|
model: data.model ?? "default",
|
|
1188
1188
|
effort: data.effort ?? null,
|
|
1189
|
+
...(parseMaxOutputTokens(data.max_output_tokens) ? { maxOutputTokens: parseMaxOutputTokens(data.max_output_tokens) } : {}),
|
|
1189
1190
|
tools,
|
|
1190
1191
|
apis: parseApis(data.apis),
|
|
1191
1192
|
remotes: parseRemotes(data.remotes),
|
|
@@ -1239,7 +1240,7 @@ const OPTION_RE = /^(\s+)([a-z_-]+):(.*)$/;
|
|
|
1239
1240
|
* swallowed as an unknown option, silently, along with any typo of a real
|
|
1240
1241
|
* key. The consistency suite reads this list against the docs. */
|
|
1241
1242
|
export const STEP_OPTION_KEYS = new Set([
|
|
1242
|
-
"approve", "ask", "case", "delegate", "each", "effort", "else", "limits", "loop", "max", "max_turns", "model",
|
|
1243
|
+
"approve", "ask", "case", "delegate", "each", "effort", "else", "limits", "loop", "max", "max_output_tokens", "max_turns", "model",
|
|
1243
1244
|
"on-fail", "onfail", "output", "parallel", "preview", "retry", "schema", "timeout", "until", "verify", "wait", "when",
|
|
1244
1245
|
]);
|
|
1245
1246
|
/** A line that opens a markdown block rather than continuing a sentence:
|
|
@@ -1250,6 +1251,15 @@ const MARKDOWN_BLOCK_RE = /^(?:#{1,6}\s|[-*+]\s|>\s|\d+[.)]\s|\*\*|__|---|\|)/;
|
|
|
1250
1251
|
/** The most fan-out instances `parallel:` may run at once — the fan-out's
|
|
1251
1252
|
* own hard cap, since more slots than items is no cap. */
|
|
1252
1253
|
export const PARALLEL_CAP = 20;
|
|
1254
|
+
/** The most `max_output_tokens:` may say — 2^20, above any model's own
|
|
1255
|
+
* limit today (Kimi's 1,048,576): a ceiling on typos, not on models. */
|
|
1256
|
+
export const MAX_OUTPUT_TOKENS_CAP = 1_048_576;
|
|
1257
|
+
/** `max_output_tokens:` as a whole number of tokens, or undefined when it
|
|
1258
|
+
* is not one in range (YAML may hand over a number or a string). */
|
|
1259
|
+
export function parseMaxOutputTokens(v) {
|
|
1260
|
+
const n = typeof v === "number" ? v : typeof v === "string" && /^\s*\d+\s*$/.test(v) ? Number(v) : NaN;
|
|
1261
|
+
return Number.isInteger(n) && n >= 1 && n <= MAX_OUTPUT_TOKENS_CAP ? n : undefined;
|
|
1262
|
+
}
|
|
1253
1263
|
/** The most turns `max_turns:` may allow. A turn is one model reply, tool
|
|
1254
1264
|
* calls included; a step that needs more than this is not one step. */
|
|
1255
1265
|
export const MAX_TURNS_CAP = 500;
|
|
@@ -1601,6 +1611,13 @@ export function parseFlow(file, raw) {
|
|
|
1601
1611
|
else
|
|
1602
1612
|
step.parallel = n;
|
|
1603
1613
|
}
|
|
1614
|
+
else if (key === "max_output_tokens") {
|
|
1615
|
+
const n = parseMaxOutputTokens(value);
|
|
1616
|
+
if (n === undefined)
|
|
1617
|
+
problem(`a whole number of tokens, 1 to ${MAX_OUTPUT_TOKENS_CAP}`);
|
|
1618
|
+
else
|
|
1619
|
+
step.maxOutputTokens = n;
|
|
1620
|
+
}
|
|
1604
1621
|
else if (key === "max_turns") {
|
|
1605
1622
|
const n = parseCount(value, 1, MAX_TURNS_CAP);
|
|
1606
1623
|
if (n === undefined)
|
|
@@ -1659,6 +1676,7 @@ export function parseFlow(file, raw) {
|
|
|
1659
1676
|
timezone: data.timezone ?? null,
|
|
1660
1677
|
model: data.model ?? null,
|
|
1661
1678
|
effort: data.effort ?? null,
|
|
1679
|
+
...(parseMaxOutputTokens(data.max_output_tokens) ? { maxOutputTokens: parseMaxOutputTokens(data.max_output_tokens) } : {}),
|
|
1662
1680
|
overlap: data.overlap === "skip" || data.overlap === "queue" ? data.overlap : null,
|
|
1663
1681
|
...(data.issues === "auto-close" || data.issues === "stay-open" ? { issues: data.issues } : {}),
|
|
1664
1682
|
live: data.live === true,
|
|
@@ -1919,6 +1937,14 @@ function updateFlowStepLF(raw, index, options) {
|
|
|
1919
1937
|
const clamp = {
|
|
1920
1938
|
model: (v) => v || null,
|
|
1921
1939
|
effort: (v) => resolveEffort(v) ?? null,
|
|
1940
|
+
max_output_tokens: (v) => {
|
|
1941
|
+
if (!v)
|
|
1942
|
+
return null;
|
|
1943
|
+
const n = parseMaxOutputTokens(v);
|
|
1944
|
+
if (n === undefined)
|
|
1945
|
+
throw new Error(`max_output_tokens: ${v} is not a whole number of tokens, 1 to ${MAX_OUTPUT_TOKENS_CAP}`);
|
|
1946
|
+
return String(n);
|
|
1947
|
+
},
|
|
1922
1948
|
verify: (v) => v || null,
|
|
1923
1949
|
when: (v) => v || null,
|
|
1924
1950
|
case: (v) => v || null,
|
|
@@ -3667,8 +3693,23 @@ export function providerEnvFor(spec) {
|
|
|
3667
3693
|
const lines = Object.entries(spec.headers).map(([k, v]) => `${k}: ${v}`);
|
|
3668
3694
|
if (lines.length)
|
|
3669
3695
|
env.ANTHROPIC_CUSTOM_HEADERS = lines.join("\n");
|
|
3696
|
+
// Claude Code puts an attribution line in every request's system prompt,
|
|
3697
|
+
// which means something to Anthropic only. Anywhere else it is prompt
|
|
3698
|
+
// text the provider is sent for nothing (e2e check, 3 Nov 2026).
|
|
3699
|
+
if (spec.baseUrl && !isAnthropicOrigin(spec.baseUrl))
|
|
3700
|
+
env.CLAUDE_CODE_ATTRIBUTION_HEADER = "0";
|
|
3670
3701
|
return env;
|
|
3671
3702
|
}
|
|
3703
|
+
/** Whether a base URL is Anthropic's own API (where the SDK's own
|
|
3704
|
+
* attribution belongs). */
|
|
3705
|
+
function isAnthropicOrigin(baseUrl) {
|
|
3706
|
+
try {
|
|
3707
|
+
return new URL(baseUrl).hostname.toLowerCase() === "api.anthropic.com";
|
|
3708
|
+
}
|
|
3709
|
+
catch {
|
|
3710
|
+
return false;
|
|
3711
|
+
}
|
|
3712
|
+
}
|
|
3672
3713
|
// The workspace tree, for history's first commit — see registerTreeReader.
|
|
3673
3714
|
registerTreeReader((tenant, scope) => {
|
|
3674
3715
|
if (scope === "@library" || !fs.existsSync(workspaceDir(tenant, scope)))
|
package/dist/src/translator.js
CHANGED
|
@@ -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 ?? "");
|