@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
|
@@ -62,6 +62,12 @@ function effortCheck(tenant, accountProvider) {
|
|
|
62
62
|
const runs = effortRunsAs(provider, id, effort);
|
|
63
63
|
return runs ? { effort: runs, model: id, on } : null;
|
|
64
64
|
},
|
|
65
|
+
outputCeiling: (model) => {
|
|
66
|
+
const tier = resolveTier(model);
|
|
67
|
+
const id = tier ? tiers[tier] : model;
|
|
68
|
+
const ceiling = id ? answer.ceilings?.[id] : undefined;
|
|
69
|
+
return id && ceiling ? { ceiling, model: id, on } : null;
|
|
70
|
+
},
|
|
65
71
|
};
|
|
66
72
|
}
|
|
67
73
|
export function checkWorkspace(tenant, workspace, tree = checkTree(workspaceDir(tenant, workspace))) {
|
package/package.json
CHANGED
package/src/completions.ts
CHANGED
|
@@ -138,6 +138,7 @@ const FIELDS: Record<string, Completion[]> = {
|
|
|
138
138
|
{ label: "description", insert: "description: ", hint: "required — what it does, and when" },
|
|
139
139
|
{ label: "model", insert: "model: default" },
|
|
140
140
|
{ label: "effort", insert: "effort: high", hint: "how hard it thinks" },
|
|
141
|
+
{ label: "max_output_tokens", insert: "max_output_tokens: 16000", hint: "the longest one reply may be, in tokens" },
|
|
141
142
|
{ label: "tools", insert: "tools:\n - write", hint: "what the runtime gives it" },
|
|
142
143
|
{ label: "secrets", insert: "secrets:\n - ", hint: "credentials it may spend" },
|
|
143
144
|
{ label: "skills", insert: "skills:\n - ", hint: "allowlist; omit to inherit all" },
|
|
@@ -212,6 +213,7 @@ const FIELDS: Record<string, Completion[]> = {
|
|
|
212
213
|
{ label: "timezone", insert: "timezone: Australia/Sydney" },
|
|
213
214
|
{ label: "model", insert: "model: fast", hint: "every step, unless the step says" },
|
|
214
215
|
{ label: "effort", insert: "effort: high", hint: "every step, unless the step says" },
|
|
216
|
+
{ label: "max_output_tokens", insert: "max_output_tokens: 16000", hint: "every step's longest reply, unless the step says" },
|
|
215
217
|
],
|
|
216
218
|
evalFile: [
|
|
217
219
|
{ label: "name", insert: "name: " },
|
|
@@ -322,6 +324,7 @@ const STEP_OPTIONS: Completion[] = [
|
|
|
322
324
|
{ label: "each", insert: "each: items", hint: "fan out: lines | items | rows of <csv>" },
|
|
323
325
|
{ label: "model", insert: "model: fast" },
|
|
324
326
|
{ label: "effort", insert: "effort: high", hint: "this step only" },
|
|
327
|
+
{ label: "max_output_tokens", insert: "max_output_tokens: 16000", hint: "the longest one reply may be, this step only" },
|
|
325
328
|
{ label: "approve", insert: "approve: true", hint: "pause for a human" },
|
|
326
329
|
];
|
|
327
330
|
|
package/src/flow-lint.ts
CHANGED
|
@@ -24,7 +24,7 @@ const SUBFLOW_DROPPED: [keyof FlowStep, string][] = [
|
|
|
24
24
|
["effort", "effort:"], ["onFail", "on-fail:"], ["waitSecs", "wait:"], ["waitFor", "wait:"],
|
|
25
25
|
["ask", "ask:"], ["preview", "preview:"], ["delegate", "delegate:"], ["loop", "loop:"],
|
|
26
26
|
["until", "until:"], ["each", "each:"], ["max", "max:"], ["output", "output:"],
|
|
27
|
-
["schema", "schema:"], ["parallel", "parallel:"], ["maxTurns", "max_turns:"], ["limits", "limits:"],
|
|
27
|
+
["schema", "schema:"], ["parallel", "parallel:"], ["maxTurns", "max_turns:"], ["maxOutputTokens", "max_output_tokens:"], ["limits", "limits:"],
|
|
28
28
|
];
|
|
29
29
|
|
|
30
30
|
export interface FlowWarning {
|
|
@@ -78,6 +78,7 @@ const AGENT: FieldSpec[] = [
|
|
|
78
78
|
{ key: "owner", type: "string", help: "the person accountable for it — an email or a name; else the workspace's, else the account's" },
|
|
79
79
|
{ key: "model", type: "string", help: "fast | default | max, an alias, or a full model id" },
|
|
80
80
|
{ key: "effort", type: "string", values: EFFORT_LEVELS, help: "how long it thinks" },
|
|
81
|
+
{ 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" },
|
|
81
82
|
{ key: "size", type: "string", values: ["small", "large", "heavy"], help: "the sandbox it rents; anything else becomes large" },
|
|
82
83
|
{ 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" },
|
|
83
84
|
{ key: "permissionMode", type: "string", values: ["plan"], help: "plan = read-only; no other mode changes anything here" },
|
|
@@ -151,6 +152,7 @@ const FLOW: FieldSpec[] = [
|
|
|
151
152
|
{ key: "timezone", type: "string", validated: true, help: "the zone its schedule reads in" },
|
|
152
153
|
{ key: "model", type: "string", help: "every step's model unless the step says" },
|
|
153
154
|
{ key: "effort", type: "string", values: EFFORT_LEVELS, help: "every step's effort unless the step says" },
|
|
155
|
+
{ key: "max_output_tokens", type: ["number", "string"], help: "every step's longest reply, in tokens, unless the step or its agent says" },
|
|
154
156
|
{ key: "overlap", type: "string", validated: true, help: "skip | queue" },
|
|
155
157
|
{ 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" },
|
|
156
158
|
{ key: "priority", type: "string", validated: true, help: "high | normal | low" },
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import { FRONTMATTER, JOBS, type FieldType, type SchemaKind } from "./frontmatter-fields.ts";
|
|
6
6
|
import { jobFold } from "./matter.ts";
|
|
7
|
-
import { resolveEffort, parseDuration, parseInstant, parseRate, STEP_OPTION_KEYS } from "./store.ts";
|
|
7
|
+
import { resolveEffort, parseDuration, parseInstant, parseRate, STEP_OPTION_KEYS, parseMaxOutputTokens, MAX_OUTPUT_TOKENS_CAP } from "./store.ts";
|
|
8
8
|
import { budgetProblem } from "./budget.ts";
|
|
9
9
|
import { cronProblem, parseCron, cronCanFire } from "./cron.ts";
|
|
10
10
|
import { SECRET_NAME } from "./secrets.ts";
|
|
@@ -29,11 +29,17 @@ const DURATION = (min: number, max: number, unit = "") => (v: unknown) => {
|
|
|
29
29
|
return null;
|
|
30
30
|
};
|
|
31
31
|
|
|
32
|
+
/** `max_output_tokens:` — a whole number of tokens the runtime can be told. */
|
|
33
|
+
function maxOutputProblem(v: unknown): string | null {
|
|
34
|
+
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;
|
|
35
|
+
}
|
|
36
|
+
|
|
32
37
|
/** Why a value is wrong, or null — per kind, per field: the rules a list of
|
|
33
38
|
* values cannot say (aliases, durations, cron, budgets). */
|
|
34
39
|
const CHECKS: Partial<Record<SchemaKind, Record<string, (value: unknown) => string | null>>> = {
|
|
35
40
|
"agent": {
|
|
36
41
|
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`),
|
|
42
|
+
max_output_tokens: maxOutputProblem,
|
|
37
43
|
apis: apisProblem,
|
|
38
44
|
remotes: remotesProblem,
|
|
39
45
|
budget: (v) => budgetProblem(v, ["run"]),
|
|
@@ -49,6 +55,7 @@ const CHECKS: Partial<Record<SchemaKind, Record<string, (value: unknown) => stri
|
|
|
49
55
|
"flow": {
|
|
50
56
|
schedule: cronProblem,
|
|
51
57
|
effort: (v) => (resolveEffort(v) ? null : `"${String(v)}" is not an effort — low, medium, high, xhigh or max`),
|
|
58
|
+
max_output_tokens: maxOutputProblem,
|
|
52
59
|
at: (v) => (parseInstant(v) ? null : `"${String(v)}" is not an ISO 8601 instant — a once flow with it never fires`),
|
|
53
60
|
url: (v) => (/^https?:\/\//i.test(String(v)) ? null : `"${String(v)}" is not an http(s) URL`),
|
|
54
61
|
every: DURATION(1, 30 * 86400, "1s to 30 days"),
|
package/src/model-supply.ts
CHANGED
|
@@ -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
|
};
|
|
@@ -156,7 +165,14 @@ export const SUPPLY_KEY_NAME = "FOLDRUN_SUPPLY_KEY";
|
|
|
156
165
|
*/
|
|
157
166
|
export type SupplyAnswer =
|
|
158
167
|
| { kind: "none" }
|
|
159
|
-
| {
|
|
168
|
+
| {
|
|
169
|
+
kind: "foldrun";
|
|
170
|
+
provider: SupplyProviderName;
|
|
171
|
+
tiers: Partial<Record<"fast" | "default" | "max", string>>;
|
|
172
|
+
/** The price list's output ceiling per model id: the most one reply
|
|
173
|
+
* may be on the platform's key, told to the runtime up front. */
|
|
174
|
+
ceilings?: Record<string, number>;
|
|
175
|
+
}
|
|
160
176
|
| { kind: "refused"; reason: string };
|
|
161
177
|
|
|
162
178
|
/** The token a supply provider block carries: a marker, not a secret. The
|
|
@@ -210,6 +226,32 @@ export function shapeRequest(p: SupplyProvider, json: Record<string, unknown>):
|
|
|
210
226
|
for (const k of Object.keys(t)) if (!shape.thinking.includes(k)) (delete t[k], (changed = true));
|
|
211
227
|
}
|
|
212
228
|
}
|
|
229
|
+
if (shape.dropDeferredTools && Array.isArray(json.tools)) {
|
|
230
|
+
const kept = (json.tools as unknown[]).filter((t) => !(t && typeof t === "object" && (t as Record<string, unknown>).defer_loading === true));
|
|
231
|
+
if (kept.length !== json.tools.length) {
|
|
232
|
+
json.tools = kept;
|
|
233
|
+
changed = true;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
if (shape.mergeSystemMessages && Array.isArray(json.messages)) {
|
|
237
|
+
const out: Record<string, unknown>[] = [];
|
|
238
|
+
const blocksOf = (c: unknown): Record<string, unknown>[] =>
|
|
239
|
+
typeof c === "string" ? [{ type: "text", text: c }] : Array.isArray(c) ? (c as Record<string, unknown>[]) : [];
|
|
240
|
+
for (const m of json.messages as Record<string, unknown>[]) {
|
|
241
|
+
if (!m || m.role !== "system") {
|
|
242
|
+
out.push(m);
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
changed = true;
|
|
246
|
+
// Its words only: an effort-only system message carries none.
|
|
247
|
+
const text = blocksOf(m.content).filter((b) => b && b.type === "text" && typeof b.text === "string" && b.text).map((b) => ({ type: "text", text: b.text }));
|
|
248
|
+
if (!text.length) continue;
|
|
249
|
+
const prev = out[out.length - 1];
|
|
250
|
+
if (prev && prev.role === "user") prev.content = [...blocksOf(prev.content), ...text];
|
|
251
|
+
else out.push({ role: "user", content: text });
|
|
252
|
+
}
|
|
253
|
+
json.messages = out;
|
|
254
|
+
}
|
|
213
255
|
const oc = json.output_config;
|
|
214
256
|
if (shape.effort && oc && typeof oc === "object" && typeof (oc as Record<string, unknown>).effort === "string") {
|
|
215
257
|
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
|
@@ -73,6 +73,7 @@ import {
|
|
|
73
73
|
parseProvider,
|
|
74
74
|
providerEnvFor,
|
|
75
75
|
resolveEffort,
|
|
76
|
+
parseMaxOutputTokens,
|
|
76
77
|
isEffortWord,
|
|
77
78
|
EFFORT_LEVELS,
|
|
78
79
|
checkFormatVersion,
|
|
@@ -2672,6 +2673,21 @@ async function runStep(
|
|
|
2672
2673
|
// step was stopped at up to fifteen times what it had spent.
|
|
2673
2674
|
tokenPrice ??= knownPrice(wireModel);
|
|
2674
2675
|
|
|
2676
|
+
// `max_output_tokens:` — the step's own (or its flow's, snapshotted on
|
|
2677
|
+
// the run), else the agent's; on foldrun's models never above the price
|
|
2678
|
+
// list's ceiling for the model it runs, so the runtime knows its real
|
|
2679
|
+
// limit up front instead of the gateway cutting it short (3 Nov 2026).
|
|
2680
|
+
const askedOut = step.maxOutputTokens ?? parseMaxOutputTokens(front.max_output_tokens);
|
|
2681
|
+
const outCeiling = onSupply && supply.kind === "foldrun" ? supply.ceilings?.[wireModel] : undefined;
|
|
2682
|
+
const maxOut = askedOut && outCeiling ? Math.min(askedOut, outCeiling) : (askedOut ?? outCeiling);
|
|
2683
|
+
if (askedOut && outCeiling && askedOut > outCeiling) {
|
|
2684
|
+
push("info", `max_output_tokens: ${askedOut} runs as ${outCeiling} — the price list's ceiling for ${wireModel} on foldrun's models`);
|
|
2685
|
+
}
|
|
2686
|
+
const outputEnv: Record<string, string> = maxOut ? { CLAUDE_CODE_MAX_OUTPUT_TOKENS: String(maxOut) } : {};
|
|
2687
|
+
if (maxOut && !(askedOut && outCeiling && askedOut > outCeiling)) {
|
|
2688
|
+
push("info", `max_output_tokens: ${maxOut}${askedOut ? "" : " — the price list's ceiling on foldrun's models"}`);
|
|
2689
|
+
}
|
|
2690
|
+
|
|
2675
2691
|
fs.mkdirSync(path.join(agentDir, "outputs"), { recursive: true });
|
|
2676
2692
|
fs.mkdirSync(path.join(agentDir, "memory"), { recursive: true });
|
|
2677
2693
|
|
|
@@ -3276,6 +3292,7 @@ async function runStep(
|
|
|
3276
3292
|
// A provider: block still wins, because providerEnv is spread
|
|
3277
3293
|
// after and carries the agent's chosen endpoint + token.
|
|
3278
3294
|
...proxied(Object.keys(providerEnv).length === 0 ? modelEnv : providerEnv, keyName),
|
|
3295
|
+
...outputEnv,
|
|
3279
3296
|
...(lease ? { [EGRESS_ENV]: lease.url } : {}),
|
|
3280
3297
|
// Every program's HTTP(S) through the proxy's forward door, and
|
|
3281
3298
|
// the CA it signs bound sites with, for the sandbox to trust.
|
|
@@ -3742,7 +3759,7 @@ async function runStep(
|
|
|
3742
3759
|
// the allowlisted host environment, not process.env: the SDK's
|
|
3743
3760
|
// Bash tool runs with this, and on a platform process.env holds
|
|
3744
3761
|
// every tenant's root key and the datastore credentials.
|
|
3745
|
-
env: { ...hostSafeEnv(), ...clockEnv, ...(testRun ? testModeEnv() : {}), ...mat.env, ...installEnv, ...modelEnv },
|
|
3762
|
+
env: { ...hostSafeEnv(), ...clockEnv, ...(testRun ? testModeEnv() : {}), ...mat.env, ...installEnv, ...modelEnv, ...outputEnv },
|
|
3746
3763
|
timeoutSec: step.timeout,
|
|
3747
3764
|
budgetUsd: stepBudgetUsd,
|
|
3748
3765
|
budgetNote: stepBudgetNote,
|
|
@@ -4168,6 +4185,10 @@ const MAX_BACKOFF_MS = 30_000;
|
|
|
4168
4185
|
*/
|
|
4169
4186
|
export function isTransientOverload(text: string): boolean {
|
|
4170
4187
|
if (/credits?\b|quota|billing|insufficient|payment|401|402|403/i.test(text)) return false;
|
|
4188
|
+
// The platform's own answer on foldrun's models (no price, the day's cap,
|
|
4189
|
+
// the provider withdrawn) is a decision, not load: a retry cannot change
|
|
4190
|
+
// it (e2e check, 3 Nov 2026 — a cap refusal retried for minutes).
|
|
4191
|
+
if (/foldrun's models/i.test(text)) return false;
|
|
4171
4192
|
return /\b(429|503|529)\b|overloaded|rate.?limit|too many requests|try again/i.test(text);
|
|
4172
4193
|
}
|
|
4173
4194
|
|
|
@@ -4397,6 +4418,12 @@ export function createFlowRun(
|
|
|
4397
4418
|
* own trailing argument, so the signature only widened. */
|
|
4398
4419
|
a2a?: { task: string; key: string },
|
|
4399
4420
|
): RunRecord {
|
|
4421
|
+
let flowMaxOut: number | undefined;
|
|
4422
|
+
try {
|
|
4423
|
+
flowMaxOut = readFlow(tenant, workspace, flowName)?.maxOutputTokens;
|
|
4424
|
+
} catch {
|
|
4425
|
+
flowMaxOut = undefined;
|
|
4426
|
+
}
|
|
4400
4427
|
const run: RunRecord = {
|
|
4401
4428
|
id: `run-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 6)}`,
|
|
4402
4429
|
flow: flowName,
|
|
@@ -4415,6 +4442,11 @@ export function createFlowRun(
|
|
|
4415
4442
|
optional: s.optional ?? false,
|
|
4416
4443
|
model: s.model,
|
|
4417
4444
|
effort: s.effort,
|
|
4445
|
+
// The flow's default snapshotted here, as a step's own options are:
|
|
4446
|
+
// what the run started with is what it runs with. A step from a
|
|
4447
|
+
// nested flow carries that flow's own (expandSubflows).
|
|
4448
|
+
...((s.maxOutputTokens ?? s.flowMaxOutputTokens ?? flowMaxOut) ? { maxOutputTokens: s.maxOutputTokens ?? s.flowMaxOutputTokens ?? flowMaxOut } : {}),
|
|
4449
|
+
...((s.flowMaxOutputTokens ?? flowMaxOut) ? { flowMaxOutputTokens: s.flowMaxOutputTokens ?? flowMaxOut } : {}),
|
|
4418
4450
|
approve: s.approve,
|
|
4419
4451
|
when: s.when,
|
|
4420
4452
|
case: s.case,
|
|
@@ -5383,6 +5415,8 @@ function driveRunInner(
|
|
|
5383
5415
|
delegation: id,
|
|
5384
5416
|
instruction: job,
|
|
5385
5417
|
group: parent.group,
|
|
5418
|
+
// A job done for a step is held to that step's output limit.
|
|
5419
|
+
...(parent.maxOutputTokens ? { maxOutputTokens: parent.maxOutputTokens } : {}),
|
|
5386
5420
|
optional: true,
|
|
5387
5421
|
timeout: parent.timeout,
|
|
5388
5422
|
attempts: 1,
|
|
@@ -5897,6 +5931,9 @@ function driveRunInner(
|
|
|
5897
5931
|
optional: false,
|
|
5898
5932
|
model: step.model,
|
|
5899
5933
|
effort: step.effort,
|
|
5934
|
+
// The step's output limit (its own, or the flow's snapshotted
|
|
5935
|
+
// on it) holds for whoever takes the step over (Codex review).
|
|
5936
|
+
...(step.maxOutputTokens ? { maxOutputTokens: step.maxOutputTokens } : {}),
|
|
5900
5937
|
timeout: step.timeout,
|
|
5901
5938
|
// The rescuer inherits the contract, not just the job: a step
|
|
5902
5939
|
// that promised data still owes data when someone else does it,
|
|
@@ -5986,6 +6023,10 @@ function driveRunInner(
|
|
|
5986
6023
|
instruction: m[2].trim(),
|
|
5987
6024
|
group: chooser.group,
|
|
5988
6025
|
optional: false,
|
|
6026
|
+
// The output limit of the flow the chooser was written in, as a
|
|
6027
|
+
// step of that file would have it (Codex review); the chooser's
|
|
6028
|
+
// own options are its own.
|
|
6029
|
+
...(chooser.flowMaxOutputTokens ? { maxOutputTokens: chooser.flowMaxOutputTokens, flowMaxOutputTokens: chooser.flowMaxOutputTokens } : {}),
|
|
5989
6030
|
attempts: 0,
|
|
5990
6031
|
status: "pending",
|
|
5991
6032
|
events: [],
|
|
@@ -6194,11 +6235,17 @@ function expandSubflows(
|
|
|
6194
6235
|
for (const ns of nestedSteps) {
|
|
6195
6236
|
const g = base + ns.group;
|
|
6196
6237
|
maxGroup = Math.max(maxGroup, g);
|
|
6238
|
+
// The nested flow's own output limit holds for its steps (a step's
|
|
6239
|
+
// own still wins), as its file says (Codex review).
|
|
6240
|
+
const flowMax = ns.flowMaxOutputTokens ?? nested.maxOutputTokens;
|
|
6241
|
+
const maxOut = ns.maxOutputTokens ?? flowMax;
|
|
6197
6242
|
out.push({
|
|
6198
6243
|
...ns,
|
|
6199
6244
|
group: g,
|
|
6200
6245
|
optional: ns.optional || step.optional,
|
|
6201
6246
|
instruction: ns.instruction || step.instruction,
|
|
6247
|
+
...(maxOut ? { maxOutputTokens: maxOut } : {}),
|
|
6248
|
+
...(flowMax ? { flowMaxOutputTokens: flowMax } : {}),
|
|
6202
6249
|
});
|
|
6203
6250
|
}
|
|
6204
6251
|
group = maxGroup;
|
package/src/scan.ts
CHANGED
|
@@ -33,7 +33,7 @@ import { resolveNetwork } from "./network.ts";
|
|
|
33
33
|
import { frontmatterProblems, schemaKindOf } from "./frontmatter-schema.ts";
|
|
34
34
|
import { parseRemotes } from "./a2a-remotes.ts";
|
|
35
35
|
import { isA2aPublished } from "./a2a-publish.ts";
|
|
36
|
-
import { parseFlow, resolveEffort, type FlowStep } from "./store.ts";
|
|
36
|
+
import { parseFlow, resolveEffort, parseMaxOutputTokens, type FlowStep } from "./store.ts";
|
|
37
37
|
|
|
38
38
|
export type ScanLevel = "error" | "warn" | "info";
|
|
39
39
|
export type ScanCategory = "secret" | "security" | "content" | "supply-chain" | "config";
|
|
@@ -85,6 +85,10 @@ export interface ScanOptions {
|
|
|
85
85
|
* (a `model:` word or id, an effort word), and where — or null when that
|
|
86
86
|
* is not known here (the CLI, offline: it knows no account's choice). */
|
|
87
87
|
effortRunsAs?: (model: string, effort: string) => { effort: string; model: string; on: string } | null;
|
|
88
|
+
/** The most one reply may be on the model this account's steps run on
|
|
89
|
+
* (a `model:` word or id) — the price list's ceiling on foldrun's
|
|
90
|
+
* models — or null when that is not known here. */
|
|
91
|
+
outputCeiling?: (model: string) => { ceiling: number; model: string; on: string } | null;
|
|
88
92
|
}
|
|
89
93
|
|
|
90
94
|
export const OWASP_URL = "https://genai.owasp.org/resource/owasp-top-10-for-agentic-applications-for-2026";
|
|
@@ -314,6 +318,16 @@ export const SCAN_RULES: readonly ScanRule[] = [
|
|
|
314
318
|
"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 " +
|
|
315
319
|
"a provider whose model has the one you want (Settings → Model provider).",
|
|
316
320
|
},
|
|
321
|
+
{
|
|
322
|
+
id: "config/output-fitted",
|
|
323
|
+
category: "config",
|
|
324
|
+
level: "warn",
|
|
325
|
+
title: "A max_output_tokens above what the account's model allows",
|
|
326
|
+
help:
|
|
327
|
+
"On foldrun's models one reply may be at most the price list's ceiling for its model. The step still runs, with " +
|
|
328
|
+
"the ceiling as its limit, and the step's log says so. Write a number at or under the ceiling, or run the agent " +
|
|
329
|
+
"on your own key.",
|
|
330
|
+
},
|
|
317
331
|
{
|
|
318
332
|
id: "config/cron-never-fires",
|
|
319
333
|
category: "config",
|
|
@@ -1079,6 +1093,65 @@ function scanEfforts(agents: AgentFacts[], flows: FlowFacts[], runsAs: NonNullab
|
|
|
1079
1093
|
}
|
|
1080
1094
|
}
|
|
1081
1095
|
|
|
1096
|
+
/**
|
|
1097
|
+
* A `max_output_tokens:` above the ceiling of the model a step will run on:
|
|
1098
|
+
* warned, not refused (the step runs at the ceiling). Resolved step → flow
|
|
1099
|
+
* → agent, the written value first, as scanEfforts does.
|
|
1100
|
+
*/
|
|
1101
|
+
function scanOutputs(agents: AgentFacts[], flows: FlowFacts[], ceilingOf: NonNullable<ScanOptions["outputCeiling"]>, push: Push): void {
|
|
1102
|
+
const say = (file: string, line: number | undefined, asked: number, model: string, whence: string) => {
|
|
1103
|
+
const c = ceilingOf(model);
|
|
1104
|
+
if (!c || asked <= c.ceiling) return;
|
|
1105
|
+
push(
|
|
1106
|
+
"config/output-fitted",
|
|
1107
|
+
file,
|
|
1108
|
+
line,
|
|
1109
|
+
`config/output-fitted ${file} ${whence} ${asked} ${c.model}`,
|
|
1110
|
+
`max_output_tokens: ${asked}${whence} runs as ${c.ceiling} on ${c.on} (${c.model}) — the price list's ceiling for that model.`,
|
|
1111
|
+
);
|
|
1112
|
+
};
|
|
1113
|
+
const byName = new Map<string, { model: string; raw: unknown }>();
|
|
1114
|
+
const ownProvider = new Set<string>();
|
|
1115
|
+
for (const a of agents) {
|
|
1116
|
+
const model = typeof a.data.model === "string" && a.data.model.trim() ? a.data.model.trim() : "default";
|
|
1117
|
+
byName.set(a.name, { model, raw: a.data.max_output_tokens });
|
|
1118
|
+
if (a.data.provider) {
|
|
1119
|
+
ownProvider.add(a.name);
|
|
1120
|
+
continue;
|
|
1121
|
+
}
|
|
1122
|
+
const n = parseMaxOutputTokens(a.data.max_output_tokens);
|
|
1123
|
+
if (n) say(a.file, keyLine(a.lines, "max_output_tokens"), n, model, "");
|
|
1124
|
+
}
|
|
1125
|
+
for (const fl of flows) {
|
|
1126
|
+
let info: ReturnType<typeof parseFlow>;
|
|
1127
|
+
try {
|
|
1128
|
+
info = parseFlow(fl.file, fl.content);
|
|
1129
|
+
} catch {
|
|
1130
|
+
continue;
|
|
1131
|
+
}
|
|
1132
|
+
const steps = [...(info.steps ?? [])].sort((x, y) => (x.line ?? 0) - (y.line ?? 0));
|
|
1133
|
+
const flowLine = keyLine(fl.lines, "max_output_tokens");
|
|
1134
|
+
steps.forEach((st, i) => {
|
|
1135
|
+
if (st.subflow || ownProvider.has(st.agent)) return;
|
|
1136
|
+
const agent = byName.get(st.agent);
|
|
1137
|
+
const from = st.maxOutputTokens != null ? "step" : info.maxOutputTokens != null ? "flow" : "agent";
|
|
1138
|
+
const n = from === "step" ? st.maxOutputTokens : from === "flow" ? info.maxOutputTokens : parseMaxOutputTokens(agent?.raw);
|
|
1139
|
+
if (!n) return;
|
|
1140
|
+
const model = st.model ?? info.model ?? agent?.model ?? "default";
|
|
1141
|
+
if (from === "step") {
|
|
1142
|
+
const to = steps[i + 1]?.line ?? fl.lines.length + 1;
|
|
1143
|
+
let at: number | undefined;
|
|
1144
|
+
for (let k = st.line ?? 1; k < to; k++) if (/^\s+max_output_tokens\s*:/.test(fl.lines[k - 1] ?? "")) at = k;
|
|
1145
|
+
say(fl.file, at ?? st.line, n, model, ` (step ${st.agent})`);
|
|
1146
|
+
} else if (from === "flow") {
|
|
1147
|
+
say(fl.file, flowLine, n, model, ` (the flow's, on step ${st.agent})`);
|
|
1148
|
+
} else if (st.model || info.model) {
|
|
1149
|
+
say(fl.file, st.line, n, model, ` (${st.agent}'s own, on this step's model)`);
|
|
1150
|
+
}
|
|
1151
|
+
});
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
|
|
1082
1155
|
export function scanFiles(files: ScanFile[], options: ScanOptions = {}): ScanFinding[] {
|
|
1083
1156
|
const want = options.only?.length ? new Set(options.only) : null;
|
|
1084
1157
|
const enabled = (rule: string) => !want || want.has(rule) || want.has(scanRule(rule)?.category ?? "") || rule === "check/ignore-needs-reason";
|
|
@@ -1182,7 +1255,9 @@ export function scanFiles(files: ScanFile[], options: ScanOptions = {}): ScanFin
|
|
|
1182
1255
|
scanPublishedFlows(flows, legs, push);
|
|
1183
1256
|
// A workspace that names its own provider: does not run on the account's
|
|
1184
1257
|
// choice, so the account's models say nothing about its efforts.
|
|
1185
|
-
|
|
1258
|
+
const ownWorkspaceProvider = Boolean(workspaceMd && frontOf(workspaceMd.content, "AGENTS.md")?.provider);
|
|
1259
|
+
if (options.effortRunsAs && !ownWorkspaceProvider) scanEfforts(agents, flows, options.effortRunsAs, push);
|
|
1260
|
+
if (options.outputCeiling && !ownWorkspaceProvider) scanOutputs(agents, flows, options.outputCeiling, push);
|
|
1186
1261
|
for (const m of more.values()) {
|
|
1187
1262
|
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 });
|
|
1188
1263
|
}
|
package/src/starter.ts
CHANGED
|
@@ -467,6 +467,7 @@ Indented under a step, any of:
|
|
|
467
467
|
| \`verify: judge: <claim>\` | a model grades the claim against the output |
|
|
468
468
|
| \`verify: contains:\` / \`not-contains:\` / \`matches:\` / \`file:\` | the cheap checks, no shell |
|
|
469
469
|
| \`model:\` / \`effort:\` | override the flow's default for this step |
|
|
470
|
+
| \`max_output_tokens:\` | the longest one reply may be, in tokens, for this step |
|
|
470
471
|
| \`loop: 3\` / \`until: <condition>\` | repeat until it holds, at most 5 |
|
|
471
472
|
| \`each: lines\` | run once per line of the previous result |
|
|
472
473
|
| \`each: rows of <path>\` | run once per CSV row |
|
package/src/store.ts
CHANGED
|
@@ -984,6 +984,8 @@ export interface AgentInfo {
|
|
|
984
984
|
* the interface did not say so, so every consumer had to re-read the file
|
|
985
985
|
* to show it. */
|
|
986
986
|
effort: string | null;
|
|
987
|
+
/** `max_output_tokens:` — the longest one reply may be, when it says. */
|
|
988
|
+
maxOutputTokens?: number;
|
|
987
989
|
tools: string[];
|
|
988
990
|
apis: ApiSpec[];
|
|
989
991
|
/** `remotes:` — the outside A2A agents it may call, the entries that read
|
|
@@ -1360,6 +1362,14 @@ export interface FlowStep {
|
|
|
1360
1362
|
parallel?: number;
|
|
1361
1363
|
/** `max_turns:` — the most model turns this step may take before it is
|
|
1362
1364
|
* stopped, beside `budget:` (money) and `timeout:` (time). */
|
|
1365
|
+
/** `max_output_tokens:` — the longest one model reply may be, in tokens.
|
|
1366
|
+
* On a run's step: the step's own, else the flow's, snapshotted when the
|
|
1367
|
+
* run was created (createFlowRun); the agent's is read at the step. */
|
|
1368
|
+
maxOutputTokens?: number;
|
|
1369
|
+
/** The `max_output_tokens:` default of the flow this step was written in
|
|
1370
|
+
* (a nested flow's own, when it came from one): what a `delegate:`
|
|
1371
|
+
* chooser's picks are held to. Set by expansion and createFlowRun. */
|
|
1372
|
+
flowMaxOutputTokens?: number;
|
|
1363
1373
|
maxTurns?: number;
|
|
1364
1374
|
/** `limits: {web.search: 10}` — this step's call limits, over the agent's
|
|
1365
1375
|
* (nearest wins per key). See limits.ts. */
|
|
@@ -1386,6 +1396,8 @@ export interface FlowInfo {
|
|
|
1386
1396
|
model: string | null;
|
|
1387
1397
|
/** Same, for effort. */
|
|
1388
1398
|
effort: string | null;
|
|
1399
|
+
/** `max_output_tokens:` — every step's longest reply unless it says. */
|
|
1400
|
+
maxOutputTokens?: number;
|
|
1389
1401
|
/** What a new fire does while a run of this flow is still live:
|
|
1390
1402
|
* "skip" doesn't start one, "queue" starts it but the worker holds it
|
|
1391
1403
|
* until the live run finishes. Unset keeps today's behaviour (runs may
|
|
@@ -1676,6 +1688,7 @@ export function listAgents(tenant: string, workspace: string): AgentInfo[] {
|
|
|
1676
1688
|
...resolveOwner(data.owner, workspaceFront.owner, accountFront.owner),
|
|
1677
1689
|
model: data.model ?? "default",
|
|
1678
1690
|
effort: data.effort ?? null,
|
|
1691
|
+
...(parseMaxOutputTokens(data.max_output_tokens) ? { maxOutputTokens: parseMaxOutputTokens(data.max_output_tokens) } : {}),
|
|
1679
1692
|
tools,
|
|
1680
1693
|
apis: parseApis(data.apis),
|
|
1681
1694
|
remotes: parseRemotes(data.remotes),
|
|
@@ -1734,7 +1747,7 @@ const OPTION_RE = /^(\s+)([a-z_-]+):(.*)$/;
|
|
|
1734
1747
|
* swallowed as an unknown option, silently, along with any typo of a real
|
|
1735
1748
|
* key. The consistency suite reads this list against the docs. */
|
|
1736
1749
|
export const STEP_OPTION_KEYS: ReadonlySet<string> = new Set([
|
|
1737
|
-
"approve", "ask", "case", "delegate", "each", "effort", "else", "limits", "loop", "max", "max_turns", "model",
|
|
1750
|
+
"approve", "ask", "case", "delegate", "each", "effort", "else", "limits", "loop", "max", "max_output_tokens", "max_turns", "model",
|
|
1738
1751
|
"on-fail", "onfail", "output", "parallel", "preview", "retry", "schema", "timeout", "until", "verify", "wait", "when",
|
|
1739
1752
|
]);
|
|
1740
1753
|
|
|
@@ -1747,6 +1760,17 @@ const MARKDOWN_BLOCK_RE = /^(?:#{1,6}\s|[-*+]\s|>\s|\d+[.)]\s|\*\*|__|---|\|)/;
|
|
|
1747
1760
|
/** The most fan-out instances `parallel:` may run at once — the fan-out's
|
|
1748
1761
|
* own hard cap, since more slots than items is no cap. */
|
|
1749
1762
|
export const PARALLEL_CAP = 20;
|
|
1763
|
+
/** The most `max_output_tokens:` may say — 2^20, above any model's own
|
|
1764
|
+
* limit today (Kimi's 1,048,576): a ceiling on typos, not on models. */
|
|
1765
|
+
export const MAX_OUTPUT_TOKENS_CAP = 1_048_576;
|
|
1766
|
+
|
|
1767
|
+
/** `max_output_tokens:` as a whole number of tokens, or undefined when it
|
|
1768
|
+
* is not one in range (YAML may hand over a number or a string). */
|
|
1769
|
+
export function parseMaxOutputTokens(v: unknown): number | undefined {
|
|
1770
|
+
const n = typeof v === "number" ? v : typeof v === "string" && /^\s*\d+\s*$/.test(v) ? Number(v) : NaN;
|
|
1771
|
+
return Number.isInteger(n) && n >= 1 && n <= MAX_OUTPUT_TOKENS_CAP ? n : undefined;
|
|
1772
|
+
}
|
|
1773
|
+
|
|
1750
1774
|
/** The most turns `max_turns:` may allow. A turn is one model reply, tool
|
|
1751
1775
|
* calls included; a step that needs more than this is not one step. */
|
|
1752
1776
|
export const MAX_TURNS_CAP = 500;
|
|
@@ -2066,6 +2090,11 @@ export function parseFlow(file: string, raw: string): FlowInfo {
|
|
|
2066
2090
|
if (n === undefined) problem(`a whole number of instances to run at once, 1 to ${PARALLEL_CAP}`);
|
|
2067
2091
|
else step.parallel = n;
|
|
2068
2092
|
}
|
|
2093
|
+
else if (key === "max_output_tokens") {
|
|
2094
|
+
const n = parseMaxOutputTokens(value);
|
|
2095
|
+
if (n === undefined) problem(`a whole number of tokens, 1 to ${MAX_OUTPUT_TOKENS_CAP}`);
|
|
2096
|
+
else step.maxOutputTokens = n;
|
|
2097
|
+
}
|
|
2069
2098
|
else if (key === "max_turns") {
|
|
2070
2099
|
const n = parseCount(value, 1, MAX_TURNS_CAP);
|
|
2071
2100
|
if (n === undefined) problem(`a whole number of turns, 1 to ${MAX_TURNS_CAP}`);
|
|
@@ -2115,6 +2144,7 @@ export function parseFlow(file: string, raw: string): FlowInfo {
|
|
|
2115
2144
|
timezone: data.timezone ?? null,
|
|
2116
2145
|
model: data.model ?? null,
|
|
2117
2146
|
effort: data.effort ?? null,
|
|
2147
|
+
...(parseMaxOutputTokens(data.max_output_tokens) ? { maxOutputTokens: parseMaxOutputTokens(data.max_output_tokens) } : {}),
|
|
2118
2148
|
overlap: data.overlap === "skip" || data.overlap === "queue" ? data.overlap : null,
|
|
2119
2149
|
...(data.issues === "auto-close" || data.issues === "stay-open" ? { issues: data.issues } : {}),
|
|
2120
2150
|
live: data.live === true,
|
|
@@ -2388,7 +2418,7 @@ function updateFlowStepInstructionLF(raw: string, index: number, instruction: st
|
|
|
2388
2418
|
function updateFlowStepLF(
|
|
2389
2419
|
raw: string,
|
|
2390
2420
|
index: number,
|
|
2391
|
-
options: Partial<Record<"model" | "effort" | "retry" | "timeout" | "verify" | "when" | "case" | "else" | "loop" | "until" | "each" | "max" | "limits", string | number | null>>,
|
|
2421
|
+
options: Partial<Record<"model" | "effort" | "max_output_tokens" | "retry" | "timeout" | "verify" | "when" | "case" | "else" | "loop" | "until" | "each" | "max" | "limits", string | number | null>>,
|
|
2392
2422
|
): string {
|
|
2393
2423
|
const { head, preamble, blocks } = splitFlowBlocks(raw);
|
|
2394
2424
|
if (!Number.isInteger(index) || index < 0 || index >= blocks.length) {
|
|
@@ -2398,6 +2428,12 @@ function updateFlowStepLF(
|
|
|
2398
2428
|
const clamp: Record<string, (v: string) => string | null> = {
|
|
2399
2429
|
model: (v) => v || null,
|
|
2400
2430
|
effort: (v) => resolveEffort(v) ?? null,
|
|
2431
|
+
max_output_tokens: (v) => {
|
|
2432
|
+
if (!v) return null;
|
|
2433
|
+
const n = parseMaxOutputTokens(v);
|
|
2434
|
+
if (n === undefined) throw new Error(`max_output_tokens: ${v} is not a whole number of tokens, 1 to ${MAX_OUTPUT_TOKENS_CAP}`);
|
|
2435
|
+
return String(n);
|
|
2436
|
+
},
|
|
2401
2437
|
verify: (v) => v || null,
|
|
2402
2438
|
when: (v) => v || null,
|
|
2403
2439
|
case: (v) => v || null,
|
|
@@ -3580,6 +3616,9 @@ export interface StepRecord {
|
|
|
3580
3616
|
schema?: Record<string, unknown> | boolean;
|
|
3581
3617
|
schemaPath?: string;
|
|
3582
3618
|
parallel?: number;
|
|
3619
|
+
maxOutputTokens?: number;
|
|
3620
|
+
/** See FlowStep: the default of the flow this step was written in. */
|
|
3621
|
+
flowMaxOutputTokens?: number;
|
|
3583
3622
|
maxTurns?: number;
|
|
3584
3623
|
limits?: Record<string, number>;
|
|
3585
3624
|
/** The parsed JSON an `output: json` step returned. Kept beside the prose
|
|
@@ -4904,9 +4943,23 @@ export function providerEnvFor(spec: {
|
|
|
4904
4943
|
}
|
|
4905
4944
|
const lines = Object.entries(spec.headers).map(([k, v]) => `${k}: ${v}`);
|
|
4906
4945
|
if (lines.length) env.ANTHROPIC_CUSTOM_HEADERS = lines.join("\n");
|
|
4946
|
+
// Claude Code puts an attribution line in every request's system prompt,
|
|
4947
|
+
// which means something to Anthropic only. Anywhere else it is prompt
|
|
4948
|
+
// text the provider is sent for nothing (e2e check, 3 Nov 2026).
|
|
4949
|
+
if (spec.baseUrl && !isAnthropicOrigin(spec.baseUrl)) env.CLAUDE_CODE_ATTRIBUTION_HEADER = "0";
|
|
4907
4950
|
return env;
|
|
4908
4951
|
}
|
|
4909
4952
|
|
|
4953
|
+
/** Whether a base URL is Anthropic's own API (where the SDK's own
|
|
4954
|
+
* attribution belongs). */
|
|
4955
|
+
function isAnthropicOrigin(baseUrl: string): boolean {
|
|
4956
|
+
try {
|
|
4957
|
+
return new URL(baseUrl).hostname.toLowerCase() === "api.anthropic.com";
|
|
4958
|
+
} catch {
|
|
4959
|
+
return false;
|
|
4960
|
+
}
|
|
4961
|
+
}
|
|
4962
|
+
|
|
4910
4963
|
// The workspace tree, for history's first commit — see registerTreeReader.
|
|
4911
4964
|
registerTreeReader((tenant, scope) => {
|
|
4912
4965
|
if (scope === "@library" || !fs.existsSync(workspaceDir(tenant, scope))) return null;
|
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
|
|
package/src/workspace-check.ts
CHANGED
|
@@ -46,7 +46,7 @@ export function checkOptions(tenant: string, workspace: string): ScanOptions {
|
|
|
46
46
|
* and its tiers the platform knows). An account AGENTS.md provider: block
|
|
47
47
|
* runs instead, and its own key's models are not the platform's to say.
|
|
48
48
|
*/
|
|
49
|
-
function effortCheck(tenant: string, accountProvider: unknown): Pick<ScanOptions, "effortRunsAs"> {
|
|
49
|
+
function effortCheck(tenant: string, accountProvider: unknown): Pick<ScanOptions, "effortRunsAs" | "outputCeiling"> {
|
|
50
50
|
if (parseProvider(accountProvider)?.baseUrl) return {};
|
|
51
51
|
let answer: ReturnType<NonNullable<typeof platform.modelSupply>> | undefined;
|
|
52
52
|
try {
|
|
@@ -65,6 +65,12 @@ function effortCheck(tenant: string, accountProvider: unknown): Pick<ScanOptions
|
|
|
65
65
|
const runs = effortRunsAs(provider, id, effort);
|
|
66
66
|
return runs ? { effort: runs, model: id, on } : null;
|
|
67
67
|
},
|
|
68
|
+
outputCeiling: (model) => {
|
|
69
|
+
const tier = resolveTier(model);
|
|
70
|
+
const id = tier ? tiers[tier as "fast" | "default" | "max"] : model;
|
|
71
|
+
const ceiling = id ? answer.ceilings?.[id] : undefined;
|
|
72
|
+
return id && ceiling ? { ceiling, model: id, on } : null;
|
|
73
|
+
},
|
|
68
74
|
};
|
|
69
75
|
}
|
|
70
76
|
|