@foldrun/core 24.0.0 → 24.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -220,7 +220,12 @@ export declare function unsubstitute(text: string, knownSecrets: Record<string,
220
220
  * not from what the step reports. */
221
221
  export interface SupplyGrant {
222
222
  provider: string;
223
+ /** "login": the account's Claude subscription — the proxy sends the call
224
+ * on one of the platform's Claude logins (the gateway's login path),
225
+ * after checking the account still holds a plan; nothing is metered on
226
+ * an API key. Absent: the platform's API key for `provider`, metered. */
227
+ via?: "login";
223
228
  }
224
229
  /** Grant the platform's key for `provider` under `name`, to its host. */
225
- export declare function addSupplyGrant(grant: EgressGrant, name: string, provider: string, host: string): void;
230
+ export declare function addSupplyGrant(grant: EgressGrant, name: string, provider: string, host: string, via?: "login"): void;
226
231
  export declare function addGrant(grant: EgressGrant, name: string, value: string, host: string): void;
@@ -42,7 +42,7 @@
42
42
  // This file is the vocabulary both sides share. The server is the
43
43
  // platform's (it needs a long-lived process and a Service); the pod side is
44
44
  // here in core, because it is what the runner image runs.
45
- import { supplyProviderOfToken } from "./model-supply.js";
45
+ import { supplyProviderOfToken, supplyViaOfToken } from "./model-supply.js";
46
46
  import { trimSlashes } from "./paths.js";
47
47
  /** `${NAME}` — the shape a secret reference takes everywhere in foldrun. */
48
48
  export const PLACEHOLDER = /\$\{([A-Z][A-Z0-9_]*)\}/g;
@@ -123,7 +123,7 @@ export function proxyModelEnv(env, leaseUrl, grant, knownSecrets = {}, name = MO
123
123
  export function grantModelKey(grant, name, value, host) {
124
124
  const supply = supplyProviderOfToken(value);
125
125
  if (supply)
126
- addSupplyGrant(grant, name, supply, host);
126
+ addSupplyGrant(grant, name, supply, host, supplyViaOfToken(value) ?? undefined);
127
127
  else
128
128
  addGrant(grant, name, value, host);
129
129
  }
@@ -142,20 +142,21 @@ export function unsubstitute(text, knownSecrets, host, grant) {
142
142
  return out;
143
143
  }
144
144
  /** Grant the platform's key for `provider` under `name`, to its host. */
145
- export function addSupplyGrant(grant, name, provider, host) {
145
+ export function addSupplyGrant(grant, name, provider, host, via) {
146
146
  const h = host.toLowerCase();
147
147
  const existing = grant.secrets[name];
148
148
  // A name already granted as an ordinary secret is never turned into the
149
149
  // platform's key, nor the other way round: two meanings under one name
150
- // is how a value would be filled where it was not meant to be.
151
- if (existing && existing.supply?.provider !== provider)
150
+ // is how a value would be filled where it was not meant to be. Nor is a
151
+ // subscription grant the API key's, or the other way round.
152
+ if (existing && (existing.supply?.provider !== provider || existing.supply?.via !== via))
152
153
  throw new Error(`egress: ${name} is already granted as another credential`);
153
154
  if (existing) {
154
155
  if (!existing.hosts.includes(h))
155
156
  existing.hosts.push(h);
156
157
  }
157
158
  else
158
- grant.secrets[name] = { value: "", hosts: [h], supply: { provider } };
159
+ grant.secrets[name] = { value: "", hosts: [h], supply: { provider, ...(via ? { via } : {}) } };
159
160
  }
160
161
  export function addGrant(grant, name, value, host) {
161
162
  const h = host.toLowerCase();
@@ -41,7 +41,7 @@ export function accountModelEnv(tenant, workspace, platformEnv) {
41
41
  if (supply.kind === "refused")
42
42
  throw new ModelKeyError(`foldrun's models: ${supply.reason}`, 403);
43
43
  if (supply.kind === "foldrun") {
44
- const s = parseProvider(supplyProviderBlock(supply.provider, supply.tiers));
44
+ const s = parseProvider(supplyProviderBlock(supply.provider, supply.tiers, supply.via));
45
45
  const preset = providerPreset(s.name);
46
46
  return {
47
47
  env: providerEnvFor({ baseUrl: s.baseUrl, token: s.token, auth: s.auth, models: s.models, headers: {} }),
@@ -62,7 +62,11 @@ export declare const SUPPLY_KEY_NAME = "FOLDRUN_SUPPLY_KEY";
62
62
  * What the platform says about one account's model supply, before any
63
63
  * provider: block of its own is considered (a written block always wins):
64
64
  * none — it did not choose foldrun's models: its own key, as before
65
- * foldrun — it chose them and they are on: run on the platform's key
65
+ * foldrun — it chose them and they are on: run on the platform's key;
66
+ * with `via: "login"`, on the account's Claude subscription
67
+ * instead (16 Nov 2026: an account holding a Claude Code plan
68
+ * runs its routines and sessions on Claude, counted in the
69
+ * plan's monthly and weekly windows like its Claude Code calls)
66
70
  * refused — it chose them and they cannot be had now (switched off, the
67
71
  * provider withdrawn, the account refused). The step FAILS
68
72
  * with the reason: never quietly onto the account's stored
@@ -77,16 +81,23 @@ export type SupplyAnswer = {
77
81
  /** The price list's output ceiling per model id: the most one reply
78
82
  * may be on the platform's key, told to the runtime up front. */
79
83
  ceilings?: Record<string, number>;
84
+ /** "login": the calls go on the platform's Claude logins, as the
85
+ * account's subscription — the proxy sends them through the gateway's
86
+ * login path (pool, windows, extra usage), not metered on an API key.
87
+ * Anthropic only. Absent: the platform's API key, metered. */
88
+ via?: "login";
80
89
  } | {
81
90
  kind: "refused";
82
91
  reason: string;
83
92
  };
84
- export declare const supplyToken: (provider: SupplyProviderName) => string;
93
+ export declare const supplyToken: (provider: SupplyProviderName, via?: "login") => string;
85
94
  export declare function supplyProviderOfToken(value: string | null | undefined): SupplyProviderName | null;
95
+ /** "login" when the marker is the subscription's, else null. */
96
+ export declare function supplyViaOfToken(value: string | null | undefined): "login" | null;
86
97
  /** The provider block a step on foldrun's models runs with: the preset's
87
98
  * endpoint and format, the operator's tier map, and the key as a
88
99
  * placeholder only. */
89
- export declare function supplyProviderBlock(provider: SupplyProviderName, tiers: Partial<Record<"fast" | "default" | "max", string>>): Record<string, unknown>;
100
+ export declare function supplyProviderBlock(provider: SupplyProviderName, tiers: Partial<Record<"fast" | "default" | "max", string>>, via?: "login"): Record<string, unknown>;
90
101
  /**
91
102
  * Reshape a request body for a provider (its `send`), in place. True when
92
103
  * anything changed. What a provider's schema does not list is not sent,
@@ -182,17 +182,29 @@ export const SUPPLY_KEY_NAME = "FOLDRUN_SUPPLY_KEY";
182
182
  * which the proxy fills with the platform's key. Sent anywhere unproxied
183
183
  * it is only a word a provider refuses. */
184
184
  const MARKER = "foldrun-supply:";
185
- export const supplyToken = (provider) => `${MARKER}${provider}`;
185
+ /** `+login` after the provider: the subscription's marker (SupplyAnswer.via). */
186
+ const VIA_LOGIN = "+login";
187
+ export const supplyToken = (provider, via) => `${MARKER}${provider}${via === "login" ? VIA_LOGIN : ""}`;
186
188
  export function supplyProviderOfToken(value) {
187
189
  if (typeof value !== "string" || !value.startsWith(MARKER))
188
190
  return null;
189
- const p = value.slice(MARKER.length);
191
+ let p = value.slice(MARKER.length);
192
+ if (p.endsWith(VIA_LOGIN)) {
193
+ p = p.slice(0, -VIA_LOGIN.length);
194
+ // A subscription is Claude's alone.
195
+ if (p !== "anthropic")
196
+ return null;
197
+ }
190
198
  return isSupplyProvider(p) ? p : null;
191
199
  }
200
+ /** "login" when the marker is the subscription's, else null. */
201
+ export function supplyViaOfToken(value) {
202
+ return supplyProviderOfToken(value) !== null && String(value).endsWith(VIA_LOGIN) ? "login" : null;
203
+ }
192
204
  /** The provider block a step on foldrun's models runs with: the preset's
193
205
  * endpoint and format, the operator's tier map, and the key as a
194
206
  * placeholder only. */
195
- export function supplyProviderBlock(provider, tiers) {
207
+ export function supplyProviderBlock(provider, tiers, via) {
196
208
  const p = SUPPLY_PROVIDERS[provider];
197
209
  const preset = p.preset ? providerPreset(p.preset) : undefined;
198
210
  const baseUrl = p.baseUrl ?? preset?.baseUrl;
@@ -205,7 +217,7 @@ export function supplyProviderBlock(provider, tiers) {
205
217
  base_url: baseUrl,
206
218
  format: p.format,
207
219
  auth: p.auth,
208
- token: supplyToken(provider),
220
+ token: supplyToken(provider, via),
209
221
  ...(Object.keys(tiers).length ? { models: tiers } : {}),
210
222
  };
211
223
  }
@@ -1285,7 +1285,7 @@ grantsOnly = false) {
1285
1285
  const supply = fileBlock ? { kind: "none" } : platform.modelSupply?.(tenant) ?? { kind: "none" };
1286
1286
  const providerBlock = fileBlock ??
1287
1287
  (supply.kind === "foldrun"
1288
- ? supplyProviderBlock(supply.provider, supply.tiers)
1288
+ ? supplyProviderBlock(supply.provider, supply.tiers, supply.via)
1289
1289
  : supply.kind === "refused"
1290
1290
  ? undefined
1291
1291
  : accountModelBlock((name) => getSecret(tenant, name)?.value ?? null));
@@ -2420,7 +2420,9 @@ conversation) {
2420
2420
  for (const t of step.tries ?? [])
2421
2421
  t.supply ??= before;
2422
2422
  step.credential = onSupply
2423
- ? `foldrun models · ${SUPPLY_TITLES[supply.provider]}`
2423
+ ? supply.via === "login"
2424
+ ? "Claude subscription"
2425
+ : `foldrun models · ${SUPPLY_TITLES[supply.provider]}`
2424
2426
  : credential ? credential.label : noKey ? "none — this account has no model key" : `provider: ${providerLabel}`;
2425
2427
  step.supply = onSupply ? "foldrun" : primaryOnPlatform ? "operator" : "own";
2426
2428
  if (onSupply)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@foldrun/core",
3
- "version": "24.0.0",
3
+ "version": "24.1.1",
4
4
  "description": "Agents are just folders. The format, the runner, the checks.",
5
5
  "license": "FSL-1.1-ALv2",
6
6
  "type": "module",
package/src/egress.ts CHANGED
@@ -43,7 +43,7 @@
43
43
  // platform's (it needs a long-lived process and a Service); the pod side is
44
44
  // here in core, because it is what the runner image runs.
45
45
 
46
- import { supplyProviderOfToken } from "./model-supply.ts";
46
+ import { supplyProviderOfToken, supplyViaOfToken } from "./model-supply.ts";
47
47
  import type { DelegationResult, PeerInfo } from "./operator.ts";
48
48
  import { trimSlashes } from "./paths.ts";
49
49
  import type { TestEffect } from "./test-mode.ts";
@@ -275,7 +275,7 @@ export function proxyModelEnv(
275
275
  * the call), else the value itself. */
276
276
  export function grantModelKey(grant: EgressGrant, name: string, value: string, host: string): void {
277
277
  const supply = supplyProviderOfToken(value);
278
- if (supply) addSupplyGrant(grant, name, supply, host);
278
+ if (supply) addSupplyGrant(grant, name, supply, host, supplyViaOfToken(value) ?? undefined);
279
279
  else addGrant(grant, name, value, host);
280
280
  }
281
281
 
@@ -302,19 +302,25 @@ export function unsubstitute(text: string, knownSecrets: Record<string, string>,
302
302
  * not from what the step reports. */
303
303
  export interface SupplyGrant {
304
304
  provider: string;
305
+ /** "login": the account's Claude subscription — the proxy sends the call
306
+ * on one of the platform's Claude logins (the gateway's login path),
307
+ * after checking the account still holds a plan; nothing is metered on
308
+ * an API key. Absent: the platform's API key for `provider`, metered. */
309
+ via?: "login";
305
310
  }
306
311
 
307
312
  /** Grant the platform's key for `provider` under `name`, to its host. */
308
- export function addSupplyGrant(grant: EgressGrant, name: string, provider: string, host: string): void {
313
+ export function addSupplyGrant(grant: EgressGrant, name: string, provider: string, host: string, via?: "login"): void {
309
314
  const h = host.toLowerCase();
310
315
  const existing = grant.secrets[name];
311
316
  // A name already granted as an ordinary secret is never turned into the
312
317
  // platform's key, nor the other way round: two meanings under one name
313
- // is how a value would be filled where it was not meant to be.
314
- if (existing && existing.supply?.provider !== provider) throw new Error(`egress: ${name} is already granted as another credential`);
318
+ // is how a value would be filled where it was not meant to be. Nor is a
319
+ // subscription grant the API key's, or the other way round.
320
+ if (existing && (existing.supply?.provider !== provider || existing.supply?.via !== via)) throw new Error(`egress: ${name} is already granted as another credential`);
315
321
  if (existing) {
316
322
  if (!existing.hosts.includes(h)) existing.hosts.push(h);
317
- } else grant.secrets[name] = { value: "", hosts: [h], supply: { provider } };
323
+ } else grant.secrets[name] = { value: "", hosts: [h], supply: { provider, ...(via ? { via } : {}) } };
318
324
  }
319
325
 
320
326
  export function addGrant(grant: EgressGrant, name: string, value: string, host: string): void {
package/src/model-env.ts CHANGED
@@ -59,7 +59,7 @@ export function accountModelEnv(
59
59
  const supply: SupplyAnswer = written ? { kind: "none" } : platform.modelSupply?.(tenant) ?? { kind: "none" };
60
60
  if (supply.kind === "refused") throw new ModelKeyError(`foldrun's models: ${supply.reason}`, 403);
61
61
  if (supply.kind === "foldrun") {
62
- const s = parseProvider(supplyProviderBlock(supply.provider, supply.tiers))!;
62
+ const s = parseProvider(supplyProviderBlock(supply.provider, supply.tiers, supply.via))!;
63
63
  const preset = providerPreset(s.name);
64
64
  return {
65
65
  env: providerEnvFor({ baseUrl: s.baseUrl!, token: s.token, auth: s.auth, models: s.models, headers: {} }),
@@ -240,7 +240,11 @@ export const SUPPLY_KEY_NAME = "FOLDRUN_SUPPLY_KEY";
240
240
  * What the platform says about one account's model supply, before any
241
241
  * provider: block of its own is considered (a written block always wins):
242
242
  * none — it did not choose foldrun's models: its own key, as before
243
- * foldrun — it chose them and they are on: run on the platform's key
243
+ * foldrun — it chose them and they are on: run on the platform's key;
244
+ * with `via: "login"`, on the account's Claude subscription
245
+ * instead (16 Nov 2026: an account holding a Claude Code plan
246
+ * runs its routines and sessions on Claude, counted in the
247
+ * plan's monthly and weekly windows like its Claude Code calls)
244
248
  * refused — it chose them and they cannot be had now (switched off, the
245
249
  * provider withdrawn, the account refused). The step FAILS
246
250
  * with the reason: never quietly onto the account's stored
@@ -255,6 +259,11 @@ export type SupplyAnswer =
255
259
  /** The price list's output ceiling per model id: the most one reply
256
260
  * may be on the platform's key, told to the runtime up front. */
257
261
  ceilings?: Record<string, number>;
262
+ /** "login": the calls go on the platform's Claude logins, as the
263
+ * account's subscription — the proxy sends them through the gateway's
264
+ * login path (pool, windows, extra usage), not metered on an API key.
265
+ * Anthropic only. Absent: the platform's API key, metered. */
266
+ via?: "login";
258
267
  }
259
268
  | { kind: "refused"; reason: string };
260
269
 
@@ -263,17 +272,28 @@ export type SupplyAnswer =
263
272
  * which the proxy fills with the platform's key. Sent anywhere unproxied
264
273
  * it is only a word a provider refuses. */
265
274
  const MARKER = "foldrun-supply:";
266
- export const supplyToken = (provider: SupplyProviderName) => `${MARKER}${provider}`;
275
+ /** `+login` after the provider: the subscription's marker (SupplyAnswer.via). */
276
+ const VIA_LOGIN = "+login";
277
+ export const supplyToken = (provider: SupplyProviderName, via?: "login") => `${MARKER}${provider}${via === "login" ? VIA_LOGIN : ""}`;
267
278
  export function supplyProviderOfToken(value: string | null | undefined): SupplyProviderName | null {
268
279
  if (typeof value !== "string" || !value.startsWith(MARKER)) return null;
269
- const p = value.slice(MARKER.length);
280
+ let p = value.slice(MARKER.length);
281
+ if (p.endsWith(VIA_LOGIN)) {
282
+ p = p.slice(0, -VIA_LOGIN.length);
283
+ // A subscription is Claude's alone.
284
+ if (p !== "anthropic") return null;
285
+ }
270
286
  return isSupplyProvider(p) ? p : null;
271
287
  }
288
+ /** "login" when the marker is the subscription's, else null. */
289
+ export function supplyViaOfToken(value: string | null | undefined): "login" | null {
290
+ return supplyProviderOfToken(value) !== null && String(value).endsWith(VIA_LOGIN) ? "login" : null;
291
+ }
272
292
 
273
293
  /** The provider block a step on foldrun's models runs with: the preset's
274
294
  * endpoint and format, the operator's tier map, and the key as a
275
295
  * placeholder only. */
276
- export function supplyProviderBlock(provider: SupplyProviderName, tiers: Partial<Record<"fast" | "default" | "max", string>>): Record<string, unknown> {
296
+ export function supplyProviderBlock(provider: SupplyProviderName, tiers: Partial<Record<"fast" | "default" | "max", string>>, via?: "login"): Record<string, unknown> {
277
297
  const p = SUPPLY_PROVIDERS[provider];
278
298
  const preset = p.preset ? providerPreset(p.preset) : undefined;
279
299
  const baseUrl = p.baseUrl ?? preset?.baseUrl;
@@ -285,7 +305,7 @@ export function supplyProviderBlock(provider: SupplyProviderName, tiers: Partial
285
305
  base_url: baseUrl,
286
306
  format: p.format,
287
307
  auth: p.auth,
288
- token: supplyToken(provider),
308
+ token: supplyToken(provider, via),
289
309
  ...(Object.keys(tiers).length ? { models: tiers } : {}),
290
310
  };
291
311
  }
package/src/runner.ts CHANGED
@@ -1439,7 +1439,7 @@ export function agentContext(
1439
1439
  const providerBlock =
1440
1440
  fileBlock ??
1441
1441
  (supply.kind === "foldrun"
1442
- ? supplyProviderBlock(supply.provider, supply.tiers)
1442
+ ? supplyProviderBlock(supply.provider, supply.tiers, supply.via)
1443
1443
  : supply.kind === "refused"
1444
1444
  ? undefined
1445
1445
  : accountModelBlock((name) => getSecret(tenant, name)?.value ?? null));
@@ -2624,7 +2624,9 @@ async function runStepBody(
2624
2624
  const before: StepSupply = (step.credential ?? "").startsWith("provider:") ? "own" : "operator";
2625
2625
  for (const t of step.tries ?? []) t.supply ??= before;
2626
2626
  step.credential = onSupply
2627
- ? `foldrun models · ${SUPPLY_TITLES[supply.provider]}`
2627
+ ? supply.via === "login"
2628
+ ? "Claude subscription"
2629
+ : `foldrun models · ${SUPPLY_TITLES[supply.provider]}`
2628
2630
  : credential ? credential.label : noKey ? "none — this account has no model key" : `provider: ${providerLabel}`;
2629
2631
  step.supply = onSupply ? "foldrun" : primaryOnPlatform ? "operator" : "own";
2630
2632
  if (onSupply) step.supplyProvider = supply.provider;