@foldrun/core 24.11.0 → 24.13.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/deploy.d.ts +4 -0
- package/dist/src/deploy.js +13 -1
- package/dist/src/engine-common.d.ts +21 -0
- package/dist/src/engine-common.js +12 -1
- package/dist/src/engine-loop.js +7 -2
- package/dist/src/engine-mcp.d.ts +4 -0
- package/dist/src/engine-mcp.js +62 -2
- package/dist/src/engine-tools.d.ts +7 -0
- package/dist/src/engine-tools.js +275 -19
- package/dist/src/local-sandbox.d.ts +135 -0
- package/dist/src/local-sandbox.js +1289 -0
- package/dist/src/model-credential.d.ts +3 -0
- package/dist/src/model-credential.js +3 -0
- package/dist/src/model-env.js +10 -3
- package/dist/src/platform.d.ts +7 -0
- package/dist/src/provider-health.js +5 -0
- package/dist/src/runner.js +16 -5
- package/dist/src/scan.d.ts +5 -0
- package/dist/src/scan.js +22 -0
- package/dist/src/starter.js +1 -1
- package/dist/src/workspace-check.js +5 -1
- package/package.json +9 -2
- package/src/deploy.ts +13 -1
- package/src/engine-common.ts +29 -1
- package/src/engine-loop.ts +7 -2
- package/src/engine-mcp.ts +60 -3
- package/src/engine-tools.ts +257 -25
- package/src/local-sandbox.ts +1274 -0
- package/src/model-credential.ts +5 -0
- package/src/model-env.ts +9 -3
- package/src/platform.ts +7 -0
- package/src/provider-health.ts +4 -0
- package/src/runner.ts +16 -5
- package/src/scan.ts +26 -0
- package/src/starter.ts +1 -1
- package/src/workspace-check.ts +5 -1
package/src/model-credential.ts
CHANGED
|
@@ -79,6 +79,11 @@ export function credentialLine(c: ModelCredential): { type: "info" | "error"; te
|
|
|
79
79
|
// level still wins; this is what a step falls to when none names one, before
|
|
80
80
|
// the platform's own credential.
|
|
81
81
|
|
|
82
|
+
/** Why a step or a call that names its own model endpoint (`provider:`)
|
|
83
|
+
* is refused where a platform admin turned own keys off (models.byok). */
|
|
84
|
+
export const OWN_KEYS_OFF =
|
|
85
|
+
"this platform runs every model call on foldrun's models, so an agent or project cannot name its own model endpoint — remove `provider:` from the agent or AGENTS.md (a platform admin can allow own keys: setting models.byok)";
|
|
86
|
+
|
|
82
87
|
/** The account vault names the account's own model key lives under. */
|
|
83
88
|
export const ACCOUNT_MODEL_SECRETS = {
|
|
84
89
|
provider: "FOLDRUN_MODEL_PROVIDER",
|
package/src/model-env.ts
CHANGED
|
@@ -10,7 +10,7 @@ import { accountDir, workspaceDir, parseProvider, providerEnvFor } from "./store
|
|
|
10
10
|
import { readAgentsMd } from "./runner.ts";
|
|
11
11
|
import { getSecret } from "./secrets.ts";
|
|
12
12
|
import { platform, hostUrlProblem } from "./platform.ts";
|
|
13
|
-
import { accountModelBlock, isClaudeLoginToken } from "./model-credential.ts";
|
|
13
|
+
import { accountModelBlock, isClaudeLoginToken, OWN_KEYS_OFF } from "./model-credential.ts";
|
|
14
14
|
import { providerPreset } from "./providers.ts";
|
|
15
15
|
import { startTranslator, translatorSpecFor, type TranslatorSpec } from "./translator.ts";
|
|
16
16
|
import { supplyProviderBlock, type SupplyAnswer } from "./model-supply.ts";
|
|
@@ -50,9 +50,15 @@ export function accountModelEnv(
|
|
|
50
50
|
translator: TranslatorSpec | null;
|
|
51
51
|
tenant?: string;
|
|
52
52
|
} {
|
|
53
|
-
const
|
|
53
|
+
const writtenBlock =
|
|
54
54
|
(readAgentsMd(workspaceDir(tenant, workspace))?.data?.provider as Record<string, unknown> | undefined) ??
|
|
55
55
|
(readAgentsMd(accountDir(tenant))?.data?.provider as Record<string, unknown> | undefined);
|
|
56
|
+
// Own keys as the platform admin allows them (models.byok), as a step
|
|
57
|
+
// takes them (runner.ts): off, a written block is refused and the stored
|
|
58
|
+
// key never read.
|
|
59
|
+
const ownKeys = platform.ownModelKeys?.(tenant) ?? true;
|
|
60
|
+
if (writtenBlock && !ownKeys) throw new ModelKeyError(OWN_KEYS_OFF, 403);
|
|
61
|
+
const written = writtenBlock;
|
|
56
62
|
// foldrun's models, the same rung a step takes (runner.ts agentContext):
|
|
57
63
|
// after the written blocks, before the account's stored key; chosen but
|
|
58
64
|
// refused fails here, never onto the stored key or the operator's.
|
|
@@ -78,7 +84,7 @@ export function accountModelEnv(
|
|
|
78
84
|
tenant,
|
|
79
85
|
};
|
|
80
86
|
}
|
|
81
|
-
const raw = written ?? accountModelBlock((name) => getSecret(tenant, name)?.value ?? null);
|
|
87
|
+
const raw = written ?? (ownKeys ? accountModelBlock((name) => getSecret(tenant, name)?.value ?? null) : undefined);
|
|
82
88
|
const spec = parseProvider(raw);
|
|
83
89
|
if (!spec?.baseUrl) {
|
|
84
90
|
if (!platform.platformKeyAllowed(tenant)) throw new ModelKeyError(NO_MODEL_KEY);
|
package/src/platform.ts
CHANGED
|
@@ -165,6 +165,13 @@ export interface PlatformHooks {
|
|
|
165
165
|
* operator's accounts do so; every customer brings their own API key.
|
|
166
166
|
* Default: yes — a laptop or a self-hosted install is its own operator. */
|
|
167
167
|
platformKeyAllowed(tenant: string): boolean;
|
|
168
|
+
/** May this account's steps run on a model key or endpoint of its own —
|
|
169
|
+
* the account's stored key (Settings → Models) or a `provider:` block in
|
|
170
|
+
* its files (BYOK)? A platform admin decides, for the whole install
|
|
171
|
+
* (setting models.byok, 22 Nov 2026: off unless turned on). No: a stored
|
|
172
|
+
* key is never used, and a step whose files name a provider: is refused
|
|
173
|
+
* before it starts. Absent: yes — a laptop runs on what it is given. */
|
|
174
|
+
ownModelKeys?(tenant: string): boolean;
|
|
168
175
|
/** foldrun's models (3 Nov 2026): whether this account chose to run on
|
|
169
176
|
* the platform's own key for a provider, and whether it can now. Asked
|
|
170
177
|
* only where no provider: block of the account's own says otherwise.
|
package/src/provider-health.ts
CHANGED
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
// pass here means a run would reach the same place with the same key.
|
|
20
20
|
|
|
21
21
|
import { accountModelBlock } from "./model-credential.ts";
|
|
22
|
+
import { platform } from "./platform.ts";
|
|
22
23
|
import fs from "node:fs";
|
|
23
24
|
import path from "node:path";
|
|
24
25
|
import { configMatter } from "./matter.ts";
|
|
@@ -224,6 +225,9 @@ function frontmatterOf(file: string): Record<string, unknown> {
|
|
|
224
225
|
export function providersInUse(tenant: string): ProviderInUse[] {
|
|
225
226
|
const out: ProviderInUse[] = [];
|
|
226
227
|
const seen = new Set<string>();
|
|
228
|
+
// Own keys off on this platform (models.byok): nothing of the account's
|
|
229
|
+
// is used, so nothing is probed (or spent) on its behalf.
|
|
230
|
+
if (!(platform.ownModelKeys?.(tenant) ?? true)) return out;
|
|
227
231
|
|
|
228
232
|
const add = (raw: unknown, workspace: string | null, declaredIn: string) => {
|
|
229
233
|
const spec = parseProvider(raw);
|
package/src/runner.ts
CHANGED
|
@@ -24,7 +24,7 @@ import { eventUrl } from "./webhook.ts";
|
|
|
24
24
|
import { runStepInContainer, resolveResources, memoryGiB, heldCores, killRunSandboxes, classDisk, type StepTiming } from "./run-container.ts";
|
|
25
25
|
import { readResources, hasOverride, anyMemoryMi } from "./resources.ts";
|
|
26
26
|
import { hostSafeEnv, platformApiUrl } from "./host-env.ts";
|
|
27
|
-
import { resolveModelCredential, credentialLine, accountModelBlock, isClaudeLoginToken, isModelEnvName, DECLARED_ENV_PREFIX } from "./model-credential.ts";
|
|
27
|
+
import { resolveModelCredential, credentialLine, accountModelBlock, isClaudeLoginToken, isModelEnvName, DECLARED_ENV_PREFIX, OWN_KEYS_OFF } from "./model-credential.ts";
|
|
28
28
|
import { parseJudge } from "./judge-verdict.ts";
|
|
29
29
|
import { validateSchema, describeSchemaErrors, looksLikeSchema } from "./json-schema.ts";
|
|
30
30
|
import { EGRESS_ENV, MODEL_KEY_NAME, addGrant, grantModelKey, hostOf, placeholderNames, proxyModelEnv, unsubstitute, type EgressGrant } from "./egress.ts";
|
|
@@ -1453,20 +1453,31 @@ export function agentContext(
|
|
|
1453
1453
|
// agent's own block wins over the workspace's, like everything else here.
|
|
1454
1454
|
// Then the account's own model key (Settings → Models), when it set one:
|
|
1455
1455
|
// an account that brings its key need not write a block anywhere.
|
|
1456
|
-
const
|
|
1456
|
+
const writtenBlock =
|
|
1457
1457
|
(front.provider as Record<string, unknown> | undefined) ?? workspaceFrontmatter(agentDir, tenant).provider;
|
|
1458
|
+
// Own keys (BYOK) as the platform admin allows them (models.byok): off,
|
|
1459
|
+
// a written provider: block refuses the step and a stored key is never
|
|
1460
|
+
// read — every call goes through foldrun's models.
|
|
1461
|
+
const ownKeys = platform.ownModelKeys?.(tenant) ?? true;
|
|
1462
|
+
const fileBlock = ownKeys ? writtenBlock : undefined;
|
|
1458
1463
|
// foldrun's models (3 Nov 2026): an account that chose the platform's key
|
|
1459
1464
|
// for a provider runs on it here, between its written blocks (which still
|
|
1460
1465
|
// win) and its stored key. Chosen but not to be had now — refused, and
|
|
1461
1466
|
// the step fails with why (runStep); it never falls to the stored key.
|
|
1462
|
-
const supply: SupplyAnswer = fileBlock
|
|
1467
|
+
const supply: SupplyAnswer = fileBlock
|
|
1468
|
+
? { kind: "none" }
|
|
1469
|
+
: writtenBlock
|
|
1470
|
+
? { kind: "refused", reason: OWN_KEYS_OFF }
|
|
1471
|
+
: platform.modelSupply?.(tenant) ?? { kind: "none" };
|
|
1463
1472
|
const providerBlock =
|
|
1464
1473
|
fileBlock ??
|
|
1465
1474
|
(supply.kind === "foldrun"
|
|
1466
1475
|
? supplyProviderBlock(supply.provider, supply.tiers, supply.via)
|
|
1467
1476
|
: supply.kind === "refused"
|
|
1468
1477
|
? undefined
|
|
1469
|
-
:
|
|
1478
|
+
: ownKeys
|
|
1479
|
+
? accountModelBlock((name) => getSecret(tenant, name)?.value ?? null)
|
|
1480
|
+
: undefined);
|
|
1470
1481
|
let providerEnv: Record<string, string> = {};
|
|
1471
1482
|
let providerLabel: string | null = null;
|
|
1472
1483
|
// Secret values pulled into the provider block, name → value. Kept apart
|
|
@@ -2658,7 +2669,7 @@ async function runStepBody(
|
|
|
2658
2669
|
// Chosen, but not to be had now: failed with why, before a sandbox —
|
|
2659
2670
|
// never onto the account's stored key or the operator's.
|
|
2660
2671
|
if (supply.kind === "refused") {
|
|
2661
|
-
push("error", `foldrun's models: ${supply.reason} — or switch this account back to its own key (Settings → Models, \`foldrun account model use own\`)`);
|
|
2672
|
+
push("error", platform.ownModelKeys?.(tenant) ?? true ? `foldrun's models: ${supply.reason} — or switch this account back to its own key (Settings → Models, \`foldrun account model use own\`)` : `foldrun's models: ${supply.reason}`);
|
|
2662
2673
|
step.status = "failed";
|
|
2663
2674
|
save();
|
|
2664
2675
|
return;
|
package/src/scan.ts
CHANGED
|
@@ -95,6 +95,11 @@ export interface ScanOptions {
|
|
|
95
95
|
* (a `model:` word or id) — the price list's ceiling on foldrun's
|
|
96
96
|
* models — or null when that is not known here. */
|
|
97
97
|
outputCeiling?: (model: string) => { ceiling: number; model: string; on: string } | null;
|
|
98
|
+
/** May this account's files name their own model endpoint (`provider:`)?
|
|
99
|
+
* False where a platform admin turned own keys off (models.byok): each
|
|
100
|
+
* one is config/own-model-key, an error, so the deploy is refused.
|
|
101
|
+
* Absent (the CLI offline, a laptop): yes. */
|
|
102
|
+
ownModelKeys?: boolean;
|
|
98
103
|
}
|
|
99
104
|
|
|
100
105
|
export const OWASP_URL = "https://genai.owasp.org/resource/owasp-top-10-for-agentic-applications-for-2026";
|
|
@@ -343,6 +348,16 @@ export const SCAN_RULES: readonly ScanRule[] = [
|
|
|
343
348
|
"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 " +
|
|
344
349
|
"a provider whose model has the one you want (Settings → Models).",
|
|
345
350
|
},
|
|
351
|
+
{
|
|
352
|
+
id: "config/own-model-key",
|
|
353
|
+
category: "config",
|
|
354
|
+
level: "error",
|
|
355
|
+
title: "A model endpoint of its own, where this platform runs every call on its own models",
|
|
356
|
+
help:
|
|
357
|
+
"This platform's admin turned own model keys off (setting models.byok), so every model call goes through foldrun's models. " +
|
|
358
|
+
"An agent's or a project's `provider:` block names an endpoint and key of its own, which would run unmetered. Remove the " +
|
|
359
|
+
"block: the agent then runs on the account's choice in Settings → Models.",
|
|
360
|
+
},
|
|
346
361
|
{
|
|
347
362
|
id: "config/output-fitted",
|
|
348
363
|
category: "config",
|
|
@@ -1368,6 +1383,17 @@ export function scanFiles(files: ScanFile[], options: ScanOptions = {}): ScanFin
|
|
|
1368
1383
|
// A workspace that names its own provider: does not run on the account's
|
|
1369
1384
|
// choice, so the account's models say nothing about its efforts.
|
|
1370
1385
|
const ownWorkspaceProvider = Boolean(workspaceMd && frontOf(workspaceMd.content, "AGENTS.md")?.provider);
|
|
1386
|
+
// Own keys off on this platform (models.byok): every provider: is refused.
|
|
1387
|
+
if (options.ownModelKeys === false) {
|
|
1388
|
+
const lineOf = (content: string) => {
|
|
1389
|
+
const i = content.split("\n").findIndex((l) => /^provider\s*:/.test(l));
|
|
1390
|
+
return i >= 0 ? i + 1 : 1;
|
|
1391
|
+
};
|
|
1392
|
+
const say = (file: string, content: string) =>
|
|
1393
|
+
push("config/own-model-key", file, lineOf(content), `config/own-model-key ${file}`, "provider: names a model endpoint of its own, and this platform runs every model call on its own models (own keys are off) — remove it; the agent runs on the account's choice in Settings → Models.");
|
|
1394
|
+
for (const a of agents) if (a.data.provider) say(a.file, files.find((f) => f.path === a.file)?.content ?? "");
|
|
1395
|
+
if (workspaceMd && ownWorkspaceProvider) say(workspaceMd.path, workspaceMd.content);
|
|
1396
|
+
}
|
|
1371
1397
|
if (options.effortRunsAs && !ownWorkspaceProvider) scanEfforts(agents, flows, options.effortRunsAs, push);
|
|
1372
1398
|
if (options.outputCeiling && !ownWorkspaceProvider) scanOutputs(agents, flows, options.outputCeiling, push);
|
|
1373
1399
|
for (const m of more.values()) {
|
package/src/starter.ts
CHANGED
|
@@ -520,7 +520,7 @@ secrets: [CRM_TOKEN] # keys the agent uses itself; a tool's own come with
|
|
|
520
520
|
limits: {web.search: 40, crm: 20, calls: 300} # per step; a call past a limit is refused, never run
|
|
521
521
|
network: [api.example.com] # sites its sandbox may reach, added to the trusted list; open | trusted | none
|
|
522
522
|
timezone: Australia/Sydney # the calendar it works to — IANA name or UTC+10
|
|
523
|
-
provider: {} # BYOK for this agent; account-wide: \`foldrun account model set\`
|
|
523
|
+
provider: {} # BYOK for this agent, where the platform allows own keys (models.byok); account-wide: \`foldrun account model set\`
|
|
524
524
|
permissionMode: plan # plan first, act once approved
|
|
525
525
|
runtime: # only if scripts need packages
|
|
526
526
|
packages: [requests]
|
package/src/workspace-check.ts
CHANGED
|
@@ -37,7 +37,11 @@ export function checkOptions(tenant: string, workspace: string): ScanOptions {
|
|
|
37
37
|
// AGENTS.md, or the older project.md, as the runner reads it (Codex review).
|
|
38
38
|
const accountKeys = readAgentsMdKeys(accountDir(tenant));
|
|
39
39
|
const accountNetwork = accountKeys.network;
|
|
40
|
-
|
|
40
|
+
// Own keys as the platform admin set them (models.byok): off, a provider:
|
|
41
|
+
// in these files is an error, so the deploy, a save and the Checks page
|
|
42
|
+
// all refuse it as the runner would.
|
|
43
|
+
const ownModelKeys = platform.ownModelKeys?.(tenant) ?? true;
|
|
44
|
+
return { outwardTools, accountNetwork, ...effortCheck(tenant, accountKeys.provider), ...(ownModelKeys ? {} : { ownModelKeys: false }) };
|
|
41
45
|
}
|
|
42
46
|
|
|
43
47
|
/**
|