@parcha/agentrun-serve 0.1.0-beta.57 → 0.1.0-beta.58
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/CHANGELOG.md +52 -0
- package/README.md +64 -33
- package/dist/api-only.d.ts +2 -4
- package/dist/api-only.js +2 -4
- package/dist/box-paths.d.ts +4 -3
- package/dist/box-paths.js +7 -4
- package/dist/claude-login-token.d.ts +117 -0
- package/dist/claude-login-token.js +737 -0
- package/dist/claude-login.d.ts +52 -12
- package/dist/claude-login.js +164 -39
- package/dist/cli.js +7 -41
- package/dist/computer-attach.d.ts +35 -17
- package/dist/computer-attach.js +301 -49
- package/dist/computers.d.ts +10 -10
- package/dist/computers.js +5 -5
- package/dist/console/assets/{backend-DVhHzJX2.js → backend-CSAWUqtZ.js} +1 -1
- package/dist/console/assets/index-DPh29cyz.js +747 -0
- package/dist/console/index.html +1 -1
- package/dist/dial-relay.d.ts +25 -4
- package/dist/dial-relay.js +129 -1
- package/dist/env-switch.d.ts +1 -3
- package/dist/env-switch.js +1 -3
- package/dist/fal-price.d.ts +1 -3
- package/dist/fal-price.js +77 -26
- package/dist/learn/ledger.d.ts +170 -0
- package/dist/learn/ledger.js +218 -0
- package/dist/learn/promote.d.ts +3 -3
- package/dist/learn/promote.js +1 -1
- package/dist/learning-cost.d.ts +22 -20
- package/dist/learning-cost.js +15 -21
- package/dist/live-reach.d.ts +2 -0
- package/dist/live-reach.js +2 -0
- package/dist/mcp-api-only-origins.d.ts +8 -3
- package/dist/mcp-api-only-origins.js +17 -17
- package/dist/micro.d.ts +2 -0
- package/dist/micro.js +2 -0
- package/dist/model.d.ts +5 -4
- package/dist/model.js +7 -6
- package/dist/monid.d.ts +14 -1
- package/dist/monid.js +103 -26
- package/dist/openapi.js +34 -12
- package/dist/place-offers.d.ts +4 -0
- package/dist/place-offers.js +7 -4
- package/dist/provider.d.ts +2 -2
- package/dist/provider.js +9 -5
- package/dist/run-learning-served.d.ts +2 -2
- package/dist/run-view.d.ts +1 -2
- package/dist/run-view.js +2 -1
- package/dist/runner/adapter-loop.js +3 -16
- package/dist/runner/adapter-run-spec.d.ts +20 -13
- package/dist/runner/adapter-run-spec.js +57 -48
- package/dist/runner/beside.d.ts +9 -2
- package/dist/runner/beside.js +24 -7
- package/dist/runner/claim-secrets.d.ts +17 -15
- package/dist/runner/claim-secrets.js +32 -34
- package/dist/runner/cli-run-spec.js +21 -9
- package/dist/runner/held.d.ts +16 -4
- package/dist/runner/main.d.ts +11 -6
- package/dist/runner/main.js +12 -7
- package/dist/runner/mcp-claim.js +3 -2
- package/dist/runner/mcp-run.d.ts +3 -6
- package/dist/runner/mcp-run.js +3 -4
- package/dist/runner/presence.d.ts +11 -1
- package/dist/runner/presence.js +7 -0
- package/dist/runner/reflect-hook.js +1 -1
- package/dist/runner/run-child-host.d.ts +19 -8
- package/dist/runner/run-child-host.js +80 -34
- package/dist/runner/runner.d.ts +3 -0
- package/dist/runner/runner.js +1 -1
- package/dist/runner/save-slots.js +2 -1
- package/dist/runner/subagent.d.ts +11 -0
- package/dist/runner/subagent.js +17 -3
- package/dist/runner/workflow-first.d.ts +27 -14
- package/dist/runner/workflow-first.js +29 -22
- package/dist/runner/workflow-spec.js +1 -1
- package/dist/server.d.ts +18 -7
- package/dist/server.js +150 -64
- package/dist/slots.d.ts +9 -0
- package/dist/slots.js +45 -0
- package/dist/store/postgres/migrations/0028_learning_ledger.sql +44 -0
- package/dist/store/schema.d.ts +17 -0
- package/dist/store/schema.js +47 -1
- package/dist/store/sqlite/run-patch.d.ts +11 -1
- package/dist/store/sqlite/run-patch.js +29 -1
- package/dist/store/sqlite/store.js +72 -9
- package/dist/store/store.d.ts +14 -0
- package/dist/store-reads/learning.d.ts +81 -124
- package/dist/store-reads/learning.js +207 -286
- package/dist/template-eval.d.ts +19 -0
- package/dist/template-eval.js +92 -43
- package/dist/template-import.d.ts +0 -10
- package/dist/template-import.js +5 -10
- package/dist/timeline/web-calls.d.ts +12 -14
- package/dist/timeline/web-calls.js +14 -30
- package/dist/web-save.d.ts +4 -9
- package/dist/web-save.js +4 -43
- package/dist/workspace/attached-computers.d.ts +32 -9
- package/dist/workspace/attached-computers.js +77 -13
- package/dist/workspace/computer-deps.d.ts +6 -1
- package/dist/workspace/computer-deps.js +1 -1
- package/dist/workspace/computer-for-claim.js +6 -3
- package/dist/workspace/paired-route.d.ts +91 -0
- package/dist/workspace/paired-route.js +153 -0
- package/dist/wrapped.d.ts +8 -2
- package/dist/wrapped.js +21 -6
- package/package.json +12 -12
- package/templates/README.md +3 -3
- package/dist/console/assets/index-okP-y8PK.js +0 -747
package/dist/place-offers.js
CHANGED
|
@@ -169,13 +169,13 @@ export async function askDockerDaemon(env, signal, groups = ownGroups(), contain
|
|
|
169
169
|
return { up: true };
|
|
170
170
|
}
|
|
171
171
|
/** Docker's offer: `docker version` names the daemon's version, so the CLI is on PATH and its daemon answers this user.
|
|
172
|
-
* Bounded by `timeoutMs`; never rejects. */
|
|
173
|
-
async function probeDocker(env, timeoutMs, groups, container) {
|
|
172
|
+
* The same call names the daemon's architecture, told to `arch` when it does. Bounded by `timeoutMs`; never rejects. */
|
|
173
|
+
async function probeDocker(env, timeoutMs, groups, container, arch) {
|
|
174
174
|
const no = (reason) => ({ id: "docker", available: false, reason: inOtherContainer(container, reason) });
|
|
175
175
|
// Its environment is the server's through the cut a run's takes (withoutSecrets): no box key, no other secret, no
|
|
176
176
|
// name shaped like a key.
|
|
177
177
|
const dockerEnv = withoutSecrets(env);
|
|
178
|
-
const answer = await new Promise((resolve) => execFile("docker", ["version", "--format", "{{.Server.Version}}"], { env: dockerEnv, timeout: timeoutMs, killSignal: "SIGKILL", maxBuffer: 64 * 1024 }, (error, stdout, stderr) => {
|
|
178
|
+
const answer = await new Promise((resolve) => execFile("docker", ["version", "--format", "{{.Server.Version}} {{.Server.Arch}}"], { env: dockerEnv, timeout: timeoutMs, killSignal: "SIGKILL", maxBuffer: 64 * 1024 }, (error, stdout, stderr) => {
|
|
179
179
|
const failed = error;
|
|
180
180
|
const code = failed?.code;
|
|
181
181
|
resolve({ ...(failed ? { failed: typeof code === "number" ? `exit ${code}` : errorName(failed), ...(failed.killed ? { late: true } : {}), ...(SOCKET_DENIED.test(String(stderr)) ? { denied: true } : {}), ...endpointIn(stderr) } : {}), out: String(stdout) });
|
|
@@ -197,6 +197,9 @@ async function probeDocker(env, timeoutMs, groups, container) {
|
|
|
197
197
|
return no(`Docker isn't running on this machine, or this user may not use it (docker version failed: ${answer.failed}): start Docker, or add this user to the docker group, then restart AgentRun`);
|
|
198
198
|
if (!answer.out.trim())
|
|
199
199
|
return no("Docker isn't running on this machine (docker version named no daemon): start Docker, then restart AgentRun");
|
|
200
|
+
const named = /^\S+\s+(\S+)$/.exec(answer.out.trim())?.[1];
|
|
201
|
+
if (named !== undefined)
|
|
202
|
+
arch?.(named);
|
|
200
203
|
return { id: "docker", available: true };
|
|
201
204
|
}
|
|
202
205
|
/** A remote box's offer: available when every key its computer provider requires is set, read as a run's claim reads
|
|
@@ -223,7 +226,7 @@ export async function placeOffers(env, options = {}) {
|
|
|
223
226
|
if (!enabled.has(id))
|
|
224
227
|
return { id, available: false, reason: notEnabled(id, enabled) };
|
|
225
228
|
if (id === "docker")
|
|
226
|
-
return probeDocker(env, options.timeoutMs ?? PROBE_TIMEOUT_MS, options.groups ?? ownGroups(), options.container ?? containerOf(env));
|
|
229
|
+
return probeDocker(env, options.timeoutMs ?? PROBE_TIMEOUT_MS, options.groups ?? ownGroups(), options.container ?? containerOf(env), options.dockerArch);
|
|
227
230
|
return remoteOffer(id, keyOf);
|
|
228
231
|
}));
|
|
229
232
|
}
|
package/dist/provider.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { HarnessWire as Wire } from "@parcha/agentrun-kernel";
|
|
2
|
-
import type
|
|
2
|
+
import { type RunLogin } from "./claude-login.js";
|
|
3
3
|
import { type ModelNeeds, type ModelRef } from "./model.js";
|
|
4
4
|
import { modelWire, WIRES, wireOf } from "./wires.js";
|
|
5
5
|
export { modelWire, WIRES, wireOf };
|
|
@@ -76,7 +76,7 @@ export type Provider = {
|
|
|
76
76
|
priceModel: ModelRef;
|
|
77
77
|
billing?: "plan";
|
|
78
78
|
refused?: (credential: string) => Promise<void>;
|
|
79
|
-
login?:
|
|
79
|
+
login?: RunLogin;
|
|
80
80
|
headers?: Readonly<Record<string, string>>;
|
|
81
81
|
fetch?: typeof fetch;
|
|
82
82
|
};
|
package/dist/provider.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CredentialUnavailable, ROUTE_ORIGIN } from "@parcha/agentrun-kernel/host";
|
|
2
|
-
import { CLAUDE_LOGIN_PROVIDER, onClaudeLogin, claudeLoginOf } from "./claude-login.js";
|
|
2
|
+
import { CLAUDE_LOGIN_PROVIDER, onClaudeLogin, claudeLoginOf, loginServes } from "./claude-login.js";
|
|
3
3
|
import { chooseModel, FAUX_ENV, hostModel, MODEL_PROVIDER, ollamaWouldRun, START_OLLAMA } from "./model.js";
|
|
4
4
|
import { modelWire, routed, routedId, translatesOnto, WIRES, wireOf } from "./wires.js";
|
|
5
5
|
import { modelFormWhy } from "./model-form.js";
|
|
@@ -180,6 +180,14 @@ export function providerFor(wire, env, model, who) {
|
|
|
180
180
|
// own route, as on Responses. No harness of this wire chooses one (claude-agent's model is never the gateway's).
|
|
181
181
|
if (model.provider === MODEL_PROVIDER && env.AGENT_MODEL_BASE_URL)
|
|
182
182
|
return gatewayProvider(env, model);
|
|
183
|
+
// Claude Code's login on this machine, turned on here: a model it runs (loginServes: Anthropic's own) goes on it,
|
|
184
|
+
// whatever key is set. Any other, Anthropic's through OpenRouter included, goes on its provider's key below. The
|
|
185
|
+
// refusal's offer to move a box agent to the runner (loginOnRunnerOnly) asks the same rule.
|
|
186
|
+
const login = loginServes(named) && onClaudeLogin(env, who) ? claudeLoginOf(env) : undefined;
|
|
187
|
+
if (login) {
|
|
188
|
+
const own = anthropicModelId(model);
|
|
189
|
+
return { origin: ANTHROPIC_ORIGIN, credential: () => "", auth: "x-api-key", modelId: own, priceModel: { provider: CLAUDE_LOGIN_PROVIDER, modelId: own }, billing: "plan", login };
|
|
190
|
+
}
|
|
183
191
|
if (model.provider === "openrouter" && model.modelId.startsWith("anthropic/")) {
|
|
184
192
|
const own = anthropicModelId({ provider: "anthropic", modelId: model.modelId.slice("anthropic/".length) });
|
|
185
193
|
return { origin: OPENROUTER_BASE, credential: openRouterKey(env, who, named), auth: "bearer", modelId: own, priceModel: { provider: "openrouter", modelId: `anthropic/${openRouterName(own)}` } };
|
|
@@ -187,10 +195,6 @@ export function providerFor(wire, env, model, who) {
|
|
|
187
195
|
if (model.provider !== "anthropic")
|
|
188
196
|
throw new HarnessUnavailable(`${who} runs Anthropic models; the run's model is ${named}.`);
|
|
189
197
|
const own = anthropicModelId(model);
|
|
190
|
-
// Claude Code's login on this machine, turned on here: claude-agent's Anthropic model goes on it, whatever key is set.
|
|
191
|
-
const login = onClaudeLogin(env, who) ? claudeLoginOf(env) : undefined;
|
|
192
|
-
if (login)
|
|
193
|
-
return { origin: ANTHROPIC_ORIGIN, credential: () => "", auth: "x-api-key", modelId: own, priceModel: { provider: CLAUDE_LOGIN_PROVIDER, modelId: own }, billing: "plan", login };
|
|
194
198
|
if (openRouterOnly(wire, env))
|
|
195
199
|
return { origin: OPENROUTER_BASE, credential: openRouterKey(env, who, named), auth: "bearer", modelId: own, priceModel: { provider: "openrouter", modelId: `anthropic/${openRouterName(own)}` } };
|
|
196
200
|
// The endpoint first: one it refuses is the reason, and no key would fix it (no `keys`). An endpoint the host names
|
|
@@ -42,10 +42,10 @@ export declare function servedRunLearning(deps: {
|
|
|
42
42
|
} | {
|
|
43
43
|
graded: {
|
|
44
44
|
workflow: string | null;
|
|
45
|
-
feedback_status: "
|
|
45
|
+
feedback_status: "ended" | "running" | "not_run" | null;
|
|
46
46
|
source: "feedback" | "eval";
|
|
47
47
|
graded_at: string;
|
|
48
|
-
path: "agent" | "
|
|
48
|
+
path: "agent" | "handed_back" | "workflow" | "replay" | "audit";
|
|
49
49
|
workflow_digest: string | null;
|
|
50
50
|
feedback: "correction" | null;
|
|
51
51
|
run_id: string;
|
package/dist/run-view.d.ts
CHANGED
|
@@ -270,7 +270,7 @@ export declare const actingOn: (run: Pick<RunView, "approvals" | "meta">) => boo
|
|
|
270
270
|
* no cut leaves the head of a held key. */
|
|
271
271
|
export declare const shownArgs: (approval: Pick<Approval, "args_json">, redact: (text: string) => string) => string;
|
|
272
272
|
/** A dollar figure to a millionth, as the timeline's cost.usd is. */
|
|
273
|
-
export
|
|
273
|
+
export { micro } from "./micro.js";
|
|
274
274
|
/** How many of the refused request's least a run paused at its cap is offered on top of what was taken (suggestedCap). */
|
|
275
275
|
export declare const SUGGESTED_RAISE_FACTOR = 10;
|
|
276
276
|
/** The raise a run paused at its cap is offered: what the cap counted as taken plus SUGGESTED_RAISE_FACTOR times the
|
|
@@ -498,4 +498,3 @@ export declare function outcomeShows(tool: string, answer: {
|
|
|
498
498
|
* run's redactor, before any cut. The rows this function makes are dropped first, so a pass over its own output gives the
|
|
499
499
|
* same rows. */
|
|
500
500
|
export declare function withApprovalRows(rows: readonly TimelineEvent[], asks: ReadonlyMap<string, Approval>, answers: Readonly<Record<string, ApprovalAnswer>>, redact: (text: string) => string): TimelineEvent[];
|
|
501
|
-
export {};
|
package/dist/run-view.js
CHANGED
|
@@ -18,6 +18,7 @@ import { MIN_SECRET } from "./learn/secrets.js";
|
|
|
18
18
|
import { costWordsOf, usageParts } from "./runner/metrics.js";
|
|
19
19
|
import { KINDS } from "./runner/journal-kinds.js";
|
|
20
20
|
import { ENDED_WHILE_WAITING, STOPPED_WHILE_WAITING } from "./refusal-words.js";
|
|
21
|
+
import { micro } from "./micro.js";
|
|
21
22
|
/** How a run wound down for its spend cap (`max_cost_usd`), from its journal's root entries: the tool calls the cap's
|
|
22
23
|
* wrap-up refused (CAP_REFUSED, each call once however often it was refused: a replay is the same call), and whether it
|
|
23
24
|
* wound down under the cap it has now (`capUsd`, its newest raise's, else its start's): its model was told to wrap up
|
|
@@ -338,7 +339,7 @@ export const actingOn = (run) => [...(run.approvals?.values() ?? [])].some((a) =
|
|
|
338
339
|
* no cut leaves the head of a held key. */
|
|
339
340
|
export const shownArgs = (approval, redact) => previewOf(redact(approval.args_json));
|
|
340
341
|
/** A dollar figure to a millionth, as the timeline's cost.usd is. */
|
|
341
|
-
export
|
|
342
|
+
export { micro } from "./micro.js";
|
|
342
343
|
/** How many of the refused request's least a run paused at its cap is offered on top of what was taken (suggestedCap). */
|
|
343
344
|
export const SUGGESTED_RAISE_FACTOR = 10;
|
|
344
345
|
/** The raise a run paused at its cap is offered: what the cap counted as taken plus SUGGESTED_RAISE_FACTOR times the
|
|
@@ -70,20 +70,6 @@ import { LEARNED_CARD_FIELDS, LEARNED_CLIP, LEARNED_WORKFLOW_TOOL, learnedApprov
|
|
|
70
70
|
import { warnHoldShort } from "../print.js";
|
|
71
71
|
import { feedbackAsk, feedbackOf, jobEndOpen, pendingFeedbackOf } from "./feedback-round.js";
|
|
72
72
|
import { handbackText, servedAnswerOf, servedAnswerText, WORKFLOW_FIRST, WORKFLOW_FIRST_CALL } from "./workflow-first.js";
|
|
73
|
-
/** What a session's requests were charged (sessionSpendOf's figures of those answered, a crash's cut one at its hold among
|
|
74
|
-
* them), never one still in flight at its hold. Null: one charged has no figure. */
|
|
75
|
-
function chargedOf(records) {
|
|
76
|
-
const read = sessionSpendOf(records);
|
|
77
|
-
let usd = 0;
|
|
78
|
-
for (const figure of read.figures) {
|
|
79
|
-
if (!read.answered.has(figure.turn))
|
|
80
|
-
continue;
|
|
81
|
-
if (figure.usd === null)
|
|
82
|
-
return null;
|
|
83
|
-
usd += figure.usd;
|
|
84
|
-
}
|
|
85
|
-
return usd;
|
|
86
|
-
}
|
|
87
73
|
/** The end of a harness's own call (Claude Code's WebSearch) the gate held and then let run: the host ran nothing of it,
|
|
88
74
|
* and the harness's next call runs it. */
|
|
89
75
|
export const OWN_TOOL_RELEASED = "Allowed after it waited; the agent's own tool runs it on its next call.";
|
|
@@ -1661,13 +1647,14 @@ function adapterLoop(specOf, options, deps) {
|
|
|
1661
1647
|
for (const key of await sessions.keys()) {
|
|
1662
1648
|
if (key === spec.session.key)
|
|
1663
1649
|
continue;
|
|
1664
|
-
const
|
|
1650
|
+
const read = sessionSpendOf(await sessions.read(key));
|
|
1651
|
+
const spent = settled ? read.chargedUsd : read.spentUsd;
|
|
1665
1652
|
if (spent === null)
|
|
1666
1653
|
return undefined;
|
|
1667
1654
|
others += spent;
|
|
1668
1655
|
}
|
|
1669
1656
|
if (settled) {
|
|
1670
|
-
const own =
|
|
1657
|
+
const own = sessionSpendOf(await sessions.read(spec.session.key)).chargedUsd;
|
|
1671
1658
|
return own === null ? undefined : overCapEnd(others + own, cap);
|
|
1672
1659
|
}
|
|
1673
1660
|
// Its model session read as the cap reads it (the kernel's overCapOf: a request cut by a crash at its hold plus its
|
|
@@ -200,23 +200,30 @@ export declare function modelRetryOf(routes: Iterable<Pick<ModelRoute, "like">>)
|
|
|
200
200
|
* translates its model's requests (its own `fetch`) is named by its upstream's host (ModelRoute.upstreamOrigin), never
|
|
201
201
|
* its proxy's placeholder origin; one whose upstream is unknown names no host. */
|
|
202
202
|
export declare const traceOfRoute: (route: ModelRoute) => import("../otel/genai.js").RouteTrace;
|
|
203
|
-
/**
|
|
204
|
-
*
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
* modelTiers.fast, else AGENT_MODEL_FAST) when its revision names no agree_on, on pi's wires. A fast model may be another
|
|
211
|
-
* provider's than the run's own, whose key claimSecrets never opened: so its route reads every model key the server
|
|
212
|
-
* holds (savedModelKeys) as a subagent's tier does, held by the run's redactor, on the route's env alone; in a run's own
|
|
213
|
-
* process its runner hands it the fast model's provider's keys alone (run-child-host.ts savedModelKeys, graderModelOf). A
|
|
214
|
-
* run with its own model key carries that key, and no saved key is read. Undefined when there is no fast model, the
|
|
215
|
-
* revision names agree_on, or no route can be made (logged: the pair is then compared whole). */
|
|
203
|
+
/** A replay run's or an audit shadow's grader route (runner/compare-end.ts): on the fast tier routedSubagentTiers names
|
|
204
|
+
* (the revision's modelTiers.fast, else AGENT_MODEL_FAST), on pi's wires, when its revision names no agree_on. Its route
|
|
205
|
+
* reads the saved key of that tier's model alone (subagentTierKeys), held by the run's redactors, on the route's env
|
|
206
|
+
* alone; in a run's own process its runner hands it that tier's model's key (run-child-host.ts subagentTierKeys). A run
|
|
207
|
+
* with its own model key carries that key, and no saved key is read. Undefined, with nothing read, when
|
|
208
|
+
* there is no fast tier or the revision names agree_on; undefined when no route can be made (logged: the pair is then
|
|
209
|
+
* compared whole). */
|
|
216
210
|
export declare function graderRouteOf(body: {
|
|
217
211
|
readonly modelTiers?: Readonly<Partial<Record<SubagentTier, string>>>;
|
|
218
212
|
readonly learning?: unknown;
|
|
219
213
|
}, keyed: boolean, runKey: ClaimModelKey | undefined, claimed: NodeJS.ProcessEnv, cut: HeldRedact, log: (line: string) => void, deps: Pick<AdapterSpecDeps, "store" | "sealKey" | "env" | "routeOf">, holds?: readonly HeldRedact[], claim?: Pick<Claim, "runId" | "turn" | "attempt">): Promise<ModelRoute | undefined>;
|
|
214
|
+
/** A subagent run's tier routes (runner/subagent.ts): each tier routedSubagentTiers names, on its model (the revision's
|
|
215
|
+
* modelTiers, else the host's tier variable), under its own key (subagentRoute), on a route of its own. A tier's model may
|
|
216
|
+
* be another provider's than the run's own, whose key claimSecrets never opened (it scopes the claim's keys to the run's
|
|
217
|
+
* model): so the routes read the saved model keys of those tiers' models alone (subagentTierKeys), held by the run's
|
|
218
|
+
* redactor, on the routes' env alone, never the run's tools (toolEnv). A run with its own model key carries that key,
|
|
219
|
+
* and no saved key is read. A tier no route can be made for here is in `why`, cut, and no failure of the run: a call on
|
|
220
|
+
* it answers why. */
|
|
221
|
+
export declare function subagentTierRoutes(body: {
|
|
222
|
+
readonly modelTiers?: Readonly<Partial<Record<SubagentTier, string>>>;
|
|
223
|
+
}, keyed: boolean, runKey: ClaimModelKey | undefined, toolEnv: NodeJS.ProcessEnv, cut: HeldRedact, deps: Pick<AdapterSpecDeps, "store" | "sealKey" | "env" | "routeOf">, claim?: Pick<Claim, "runId" | "turn" | "attempt">): Promise<{
|
|
224
|
+
readonly routes: Map<string, ModelRoute>;
|
|
225
|
+
readonly why: Map<SubagentTier, string>;
|
|
226
|
+
}>;
|
|
220
227
|
/** What the runner routes a claimed run on: the launch's model as its start pinned it, sent as pinned, with the
|
|
221
228
|
* revision's own ref beside it (main prices a gateway's id by the provider that ref names); the revision's ref alone
|
|
222
229
|
* when the start pinned none. Never the pin's provider and id joined into a ref: a gateway refuses the joined id, and
|
|
@@ -52,7 +52,7 @@ import { filesToCopy, placeRunInputs } from "../uploads.js";
|
|
|
52
52
|
import { handedSignInReadsBack, signInReads } from "../sign-ins-store.js";
|
|
53
53
|
import { UNREADABLE_SIGN_IN } from "../run-view.js";
|
|
54
54
|
import { durableWait } from "../workflow/pi-versions.js";
|
|
55
|
-
import { claimModelEnv, claimModelKey, claimSecrets, claimSpendOff, holdRunKey, keyedAtClaim, hostDecisionKeys,
|
|
55
|
+
import { claimModelEnv, claimModelKey, claimSecrets, claimSpendOff, holdRunKey, keyedAtClaim, hostDecisionKeys, learnedDecisionKeys, subagentTierKeys, tierModelKeys, underClaimed, withoutModelKeys } from "./claim-secrets.js";
|
|
56
56
|
import { compareEndOfRun, GRADER, withGrader } from "./compare-end.js";
|
|
57
57
|
import { agreeOnOf } from "../learning-setting.js";
|
|
58
58
|
import { catalogSessionNames, claimMetering, mcpWhereHeld } from "./mcp-run.js";
|
|
@@ -61,7 +61,7 @@ import { hostLifecycle } from "./adapter-loop.js";
|
|
|
61
61
|
import { RUNNER_HARNESSES } from "./adapters/index.js";
|
|
62
62
|
import { DEFAULT_HARNESS } from "../harness.js";
|
|
63
63
|
import { agentEntriesOf } from "./loop.js";
|
|
64
|
-
import {
|
|
64
|
+
import { routedSubagentTiers, SUBAGENT_TOOL, subagentTool } from "./subagent.js";
|
|
65
65
|
import { ClaimRefused } from "./loop-contract.js";
|
|
66
66
|
import { bookedSpend, cliRunMetrics, costBasisOf, endCostOf, runCostOf, runMetrics } from "./metrics.js";
|
|
67
67
|
import { journalEntries } from "./journal-reader.js";
|
|
@@ -170,39 +170,56 @@ export const traceOfRoute = (route) => {
|
|
|
170
170
|
const origin = route.fetch ? route.upstreamOrigin : route.provider.origin;
|
|
171
171
|
return routeTrace({ ...(route.named ? { named: route.named } : {}), ...(origin ? { origin } : {}), model: route.model });
|
|
172
172
|
};
|
|
173
|
-
/**
|
|
174
|
-
*
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
/** A replay run's or an audit shadow's grader route (runner/compare-end.ts): its fast model (the revision's
|
|
181
|
-
* modelTiers.fast, else AGENT_MODEL_FAST) when its revision names no agree_on, on pi's wires. A fast model may be another
|
|
182
|
-
* provider's than the run's own, whose key claimSecrets never opened: so its route reads every model key the server
|
|
183
|
-
* holds (savedModelKeys) as a subagent's tier does, held by the run's redactor, on the route's env alone; in a run's own
|
|
184
|
-
* process its runner hands it the fast model's provider's keys alone (run-child-host.ts savedModelKeys, graderModelOf). A
|
|
185
|
-
* run with its own model key carries that key, and no saved key is read. Undefined when there is no fast model, the
|
|
186
|
-
* revision names agree_on, or no route can be made (logged: the pair is then compared whole). */
|
|
173
|
+
/** A replay run's or an audit shadow's grader route (runner/compare-end.ts): on the fast tier routedSubagentTiers names
|
|
174
|
+
* (the revision's modelTiers.fast, else AGENT_MODEL_FAST), on pi's wires, when its revision names no agree_on. Its route
|
|
175
|
+
* reads the saved key of that tier's model alone (subagentTierKeys), held by the run's redactors, on the route's env
|
|
176
|
+
* alone; in a run's own process its runner hands it that tier's model's key (run-child-host.ts subagentTierKeys). A run
|
|
177
|
+
* with its own model key carries that key, and no saved key is read. Undefined, with nothing read, when
|
|
178
|
+
* there is no fast tier or the revision names agree_on; undefined when no route can be made (logged: the pair is then
|
|
179
|
+
* compared whole). */
|
|
187
180
|
export async function graderRouteOf(body, keyed, runKey, claimed, cut, log, deps, holds = [cut], claim) {
|
|
188
181
|
if (agreeOnOf(body.learning)?.length)
|
|
189
182
|
return undefined;
|
|
190
|
-
const
|
|
183
|
+
const { tiers, refs } = routedSubagentTiers(body, deps.env ?? {});
|
|
184
|
+
if (!tiers.includes("fast"))
|
|
185
|
+
return undefined;
|
|
186
|
+
const savedKeys = keyed ? {} : await subagentTierKeys({ store: deps.store, sealKey: deps.sealKey, env: deps.env }, ["fast"], refs);
|
|
191
187
|
for (const redact of new Set(holds))
|
|
192
188
|
holdClaimed(redact, savedKeys);
|
|
193
189
|
// The claim's run, turn and attempt on its grader's requests too (request-metadata.ts): they spend on the run's cap.
|
|
194
|
-
|
|
195
|
-
const env = claimModelEnv(deps.env, keysOver(savedKeys, claimed), runKey, claim);
|
|
196
|
-
if (graderModelOf(body, env) === undefined)
|
|
197
|
-
return undefined;
|
|
190
|
+
const env = claimModelEnv(deps.env, [claimed, savedKeys], runKey, claim);
|
|
198
191
|
try {
|
|
199
|
-
return await deps.routeOf(
|
|
192
|
+
return await deps.routeOf(refs.fast, env, "fast", PI_WIRES, undefined, cut);
|
|
200
193
|
}
|
|
201
194
|
catch (error) {
|
|
202
195
|
log(`learning: no grader route (${error instanceof Error ? error.message : String(error)}): the answers are compared whole`);
|
|
203
196
|
return undefined;
|
|
204
197
|
}
|
|
205
198
|
}
|
|
199
|
+
/** A subagent run's tier routes (runner/subagent.ts): each tier routedSubagentTiers names, on its model (the revision's
|
|
200
|
+
* modelTiers, else the host's tier variable), under its own key (subagentRoute), on a route of its own. A tier's model may
|
|
201
|
+
* be another provider's than the run's own, whose key claimSecrets never opened (it scopes the claim's keys to the run's
|
|
202
|
+
* model): so the routes read the saved model keys of those tiers' models alone (subagentTierKeys), held by the run's
|
|
203
|
+
* redactor, on the routes' env alone, never the run's tools (toolEnv). A run with its own model key carries that key,
|
|
204
|
+
* and no saved key is read. A tier no route can be made for here is in `why`, cut, and no failure of the run: a call on
|
|
205
|
+
* it answers why. */
|
|
206
|
+
export async function subagentTierRoutes(body, keyed, runKey, toolEnv, cut, deps, claim) {
|
|
207
|
+
const routes = new Map();
|
|
208
|
+
const why = new Map();
|
|
209
|
+
const { tiers, refs } = routedSubagentTiers(body, deps.env ?? {});
|
|
210
|
+
const savedKeys = keyed ? {} : await subagentTierKeys({ store: deps.store, sealKey: deps.sealKey, env: deps.env }, tiers, refs);
|
|
211
|
+
holdClaimed(cut, savedKeys);
|
|
212
|
+
const tierEnv = claimModelEnv(deps.env, [toolEnv, savedKeys], runKey, claim);
|
|
213
|
+
for (const tier of tiers) {
|
|
214
|
+
try {
|
|
215
|
+
routes.set(subagentRoute(tier), await deps.routeOf(refs[tier], tierEnv, tier, PI_WIRES, undefined, cut));
|
|
216
|
+
}
|
|
217
|
+
catch (error) {
|
|
218
|
+
why.set(tier, cut(error instanceof Error ? error.message : String(error)));
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return { routes, why };
|
|
222
|
+
}
|
|
206
223
|
/** What the runner routes a claimed run on: the launch's model as its start pinned it, sent as pinned, with the
|
|
207
224
|
* revision's own ref beside it (main prices a gateway's id by the provider that ref names); the revision's ref alone
|
|
208
225
|
* when the start pinned none. Never the pin's provider and id joined into a ref: a gateway refuses the joined id, and
|
|
@@ -392,7 +409,9 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
|
|
|
392
409
|
// the process started (run-child-host.ts), as the server's held uploads are never the run's to read.
|
|
393
410
|
if (!(deps.sealKey === undefined && runnerSeam()))
|
|
394
411
|
await placeRunInputs(deps.data, claim.runId, ws.workspace, filesToCopy(launch), messageText(launch.input));
|
|
395
|
-
|
|
412
|
+
// The run's template eval fakes (AdapterSpecDeps.evalFakes), read once: its files, its metered jobs' media and its tools.
|
|
413
|
+
const fakes = deps.evalFakes?.(runRow.agentId);
|
|
414
|
+
await seedEvalFiles(ws.workspace, fakes?.files);
|
|
396
415
|
// The pull request's checkout, when the revision asks for one (pr-checkout.ts): the server's own fetch before the first
|
|
397
416
|
// turn, with the GitHub App's read-only token for that one repository (or none); the run is told what it holds, or why
|
|
398
417
|
// there is none. Held from the fetch's start, so the release (after the tools' end) removes it however the claim ends; a
|
|
@@ -428,7 +447,7 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
|
|
|
428
447
|
// words before the session opens. The seal key is the runner's own (deps.sealKey), not re-read from the environment.
|
|
429
448
|
// A credential the claim opens mid-run (a GitHub App token, a saved or per_run server's) joins the run's redactor.
|
|
430
449
|
const hold = (values) => cut.hold(values);
|
|
431
|
-
const mcp = await mcpWhereHeld({ claim, store: deps.store, sealKey: deps.sealKey, grants: granted, harness: run.harness, work: () => ws.workspace, launchInput: launch.input, hold, githubAppAccess: (store, key, input) => githubAppAccess(store, key, input, { ...(deps.githubApi ? { api: deps.githubApi } : {}), fromGitHub: launch.inputOrigin?.kind === "trigger" && launch.inputOrigin.source === "github", hold, ...(launch.repo !== undefined ? { repo: launch.repo } : {}) }), ...(deps.githubMcpOrigin ? { githubMcpOrigin: deps.githubMcpOrigin } : {}), ...(deps.composioMcpOrigin ? { composioMcpOrigin: deps.composioMcpOrigin } : {}), ...reach, ...claimMetering(deps,
|
|
450
|
+
const mcp = await mcpWhereHeld({ claim, store: deps.store, sealKey: deps.sealKey, grants: granted, harness: run.harness, work: () => ws.workspace, launchInput: launch.input, hold, githubAppAccess: (store, key, input) => githubAppAccess(store, key, input, { ...(deps.githubApi ? { api: deps.githubApi } : {}), fromGitHub: launch.inputOrigin?.kind === "trigger" && launch.inputOrigin.source === "github", hold, ...(launch.repo !== undefined ? { repo: launch.repo } : {}) }), ...(deps.githubMcpOrigin ? { githubMcpOrigin: deps.githubMcpOrigin } : {}), ...(deps.composioMcpOrigin ? { composioMcpOrigin: deps.composioMcpOrigin } : {}), ...reach, ...claimMetering(deps, fakes?.web, launch) });
|
|
432
451
|
// The claim's MCP goes to the loop, which lets it go; a build that throws lets it go itself.
|
|
433
452
|
holds.hold({ passed: mcp });
|
|
434
453
|
// The run's computer, from the one shared claim-time function (the CLI spec takes the same): none for a runner place, a
|
|
@@ -488,7 +507,7 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
|
|
|
488
507
|
holdClaimed(cut, toolEnv);
|
|
489
508
|
// The route reads its model's key from the runner's environment, else the one the claim opened from the store: a key
|
|
490
509
|
// saved in Settings → Model keys runs the next run with no restart (withModelKeys). A run with its own key: that key.
|
|
491
|
-
const modelEnv = claimModelEnv(deps.env, toolEnv, runKey, claim);
|
|
510
|
+
const modelEnv = claimModelEnv(deps.env, [toolEnv], runKey, claim);
|
|
492
511
|
// A held run its model kept from running at its create is never routed (heldRefusedRoute): its model's route chooses no
|
|
493
512
|
// model and reads no key, so a key saved since runs a new run, never this one. Its claim lays only the keys any claim
|
|
494
513
|
// of the run lays (its tools', a key handed with it: claimSecrets lays it no model key), routes no subagent tier and
|
|
@@ -514,9 +533,9 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
|
|
|
514
533
|
// host's for the tier (AGENT_MODEL_FAST, AGENT_MODEL_STRONG), each on a route of its own (its proxy on the session's
|
|
515
534
|
// booking, adapters/pi.ts tiers). A tier with neither is the agent's own model, as a learned workflow's node of it runs
|
|
516
535
|
// on the run's. A tier no route can be made for here is no failure of the run: a call on it answers why. A tier's model may be another
|
|
517
|
-
// provider's than the run's own, whose key claimSecrets never opened
|
|
518
|
-
//
|
|
519
|
-
//
|
|
536
|
+
// provider's than the run's own, whose key claimSecrets never opened: so its route reads the saved model keys of its
|
|
537
|
+
// tiers' models alone (subagentTierRoutes). Those reach the tier's proxy alone, as its credential, never the run's tools
|
|
538
|
+
// (toolEnv).
|
|
520
539
|
// Each is in tierRoutes under its own key (subagentRoute: never a learned workflow's tier, whose nodes keep their own
|
|
521
540
|
// routes and fallback), on a proxy of its own that names that key on each request, so the cap prices a child's
|
|
522
541
|
// requests as that route books them. A held run its model kept from running routes none: its subagent's calls run on
|
|
@@ -524,19 +543,11 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
|
|
|
524
543
|
const tierWhy = new Map();
|
|
525
544
|
if (revision.kind === "agentic" && granted.includes(SUBAGENT_TOOL) && heldRefusal === undefined) {
|
|
526
545
|
// A run with its own model key: its subagents' models carry that key too, and no saved key is read.
|
|
527
|
-
const
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
for (const tier of
|
|
531
|
-
|
|
532
|
-
continue;
|
|
533
|
-
try {
|
|
534
|
-
tierRoutes.set(subagentRoute(tier), await deps.routeOf(body.modelTiers?.[tier], tierEnv, tier, PI_WIRES, undefined, cut));
|
|
535
|
-
}
|
|
536
|
-
catch (error) {
|
|
537
|
-
tierWhy.set(tier, cut(error instanceof Error ? error.message : String(error)));
|
|
538
|
-
}
|
|
539
|
-
}
|
|
546
|
+
const subagent = await subagentTierRoutes(body, keyed, runKey, toolEnv, cut, deps, claim);
|
|
547
|
+
for (const [key, at] of subagent.routes)
|
|
548
|
+
tierRoutes.set(key, at);
|
|
549
|
+
for (const [tier, why] of subagent.why)
|
|
550
|
+
tierWhy.set(tier, why);
|
|
540
551
|
}
|
|
541
552
|
// The run's adapter is its runner's (runner/adapters/index.ts RunnerHarness: pi's, or the one a harness module's entry
|
|
542
553
|
// brings), made from the run's launch on its route. Its private files, where it keeps any, go in this claim's folder of
|
|
@@ -655,7 +666,7 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
|
|
|
655
666
|
// A run with its own model key: its learned nodes' tiers carry that key too, and no saved key is read.
|
|
656
667
|
const tierKeys = keyed ? {} : await tierModelKeys({ store: deps.store, sealKey: deps.sealKey, env: deps.env }, learnedTiers(workflows));
|
|
657
668
|
holdClaimed(cut, tierKeys);
|
|
658
|
-
const tierEnv = claimModelEnv(deps.env,
|
|
669
|
+
const tierEnv = claimModelEnv(deps.env, [tierKeys, toolEnv], runKey, claim);
|
|
659
670
|
for (const [tier, routed] of await learnedTierRoutes(workflows, tierEnv, (tier) => deps.routeOf(undefined, tierEnv, tier, PI_WIRES, undefined, cut))) {
|
|
660
671
|
if ("why" in routed)
|
|
661
672
|
tierUnreachable.set(tier, routed.why);
|
|
@@ -685,7 +696,6 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
|
|
|
685
696
|
// spec builds too), on the claim's keys and the run's one ledger and redactor.
|
|
686
697
|
// An agent whose computer is a browser the claim started gets the browser tool on that one session (tools.ts).
|
|
687
698
|
const claimBrowser = computer.computer?.kind === "browser" ? computer.computer.browser : undefined;
|
|
688
|
-
const fakes = deps.evalFakes?.(runRow.agentId);
|
|
689
699
|
const liveAt = await claimLiveAt(deps, claim.runId);
|
|
690
700
|
const host = { ...buildToolHost({ root, workspace: ws.workspace, claim, env: toolEnv, run, store: deps.store, sealKey: deps.sealKey, life, redact: cut, launch, toolSettings: body.toolSettings, ...(fakes ? { fakes } : {}), ...reach, ...(liveAt ? { liveAt } : {}), ...(deps.saveSlots ? { saveSlots: deps.saveSlots } : {}) }), ...(claimBrowser ? { browserComputer: claimBrowser } : {}) };
|
|
691
701
|
gate.askedOn(host);
|
|
@@ -1060,11 +1070,10 @@ export function answersCut(tool, cut) {
|
|
|
1060
1070
|
/** Whether `cut`, a redactor that does not know its values, takes from `joined` (`parts` joined by line breaks) what it
|
|
1061
1071
|
* does not take from the parts each read alone: a held value split across two parts. Its cut of the join whole being
|
|
1062
1072
|
* "[redacted]" is not enough: it reads a text longer than a piece in pieces of 8,192 characters (key-refusal.ts
|
|
1063
|
-
* redactedAnswer), and a value split inside one piece withholds only that piece, the rest of the join served.
|
|
1064
|
-
*
|
|
1065
|
-
*
|
|
1066
|
-
*
|
|
1067
|
-
* places), and a line break ends each part. */
|
|
1073
|
+
* redactedAnswer), and a value split inside one piece withholds only that piece, the rest of the join served. It misses
|
|
1074
|
+
* nothing: no value split across parts is in a part to cut, so the join's cut and the parts' differ wherever the join
|
|
1075
|
+
* holds one; where nothing spans two parts they are the same, as every piece ends at whitespace or inside a run longer
|
|
1076
|
+
* than a piece, and a line break ends each part. */
|
|
1068
1077
|
function joinCut(joined, parts, cut) {
|
|
1069
1078
|
const whole = cut(joined);
|
|
1070
1079
|
return whole === "[redacted]" || whole !== parts.map(cut).join("\n");
|
package/dist/runner/beside.d.ts
CHANGED
|
@@ -29,11 +29,14 @@ export declare function besideStopping(server: {
|
|
|
29
29
|
* caller hands its own: the template eval's in-process server, its faux's). `loops` and `drainMs`: the runner's
|
|
30
30
|
* (RunnerOptions), the CLI start's from the server's flags (besideRunnerOptions). `janitor`: run the computer janitor
|
|
31
31
|
* too (workspace/computer-janitor.ts), as the CLI's start asks. `hub`: the server's AttachHub (Serve.attachHub), which
|
|
32
|
-
* holds each paired computer's socket in this process, so a run here takes one
|
|
32
|
+
* holds each paired computer's socket in this process, so a run here takes one; with it `beside`, the name and
|
|
33
|
+
* incarnation the server gave this runner (Serve.beside), which it runs under and its run's route of a paired box names
|
|
34
|
+
* (dial-relay.ts pairedRelayOn over the server's hub), so a runner apart's take for another run is refused while the
|
|
35
|
+
* hold lasts and the server keeps the box in its hub. `dial`: the server's (Serve.dial), which
|
|
33
36
|
* a remote provider's create takes, so a machine that dials the server lands in this process's hub. Returns the runner
|
|
34
37
|
* and a close() that stops both and closes its store. `loopsTold`: `loops` was given (besideRunnerOptions), so on uid
|
|
35
38
|
* isolation a number past the helper's slots is refused rather than cut. */
|
|
36
|
-
export declare function runnerBeside(dataDir: string, { loops, loopsTold, drainMs, env, janitor, ownProcesses, hub, dial, mcpLoopback, mcpOwn, ollamaHost, evalFakes, harnessInstall, onLine, onRunEnded }?: {
|
|
39
|
+
export declare function runnerBeside(dataDir: string, { loops, loopsTold, drainMs, env, janitor, ownProcesses, hub, beside, dial, mcpLoopback, mcpOwn, ollamaHost, evalFakes, harnessInstall, onLine, onRunEnded }?: {
|
|
37
40
|
loops?: number;
|
|
38
41
|
loopsTold?: boolean;
|
|
39
42
|
drainMs?: number;
|
|
@@ -42,6 +45,10 @@ export declare function runnerBeside(dataDir: string, { loops, loopsTold, drainM
|
|
|
42
45
|
janitor?: boolean;
|
|
43
46
|
ownProcesses?: boolean;
|
|
44
47
|
hub?: import("@parcha/agentrun-computer").AttachHub;
|
|
48
|
+
beside?: {
|
|
49
|
+
readonly runner: string;
|
|
50
|
+
readonly incarnation: string;
|
|
51
|
+
};
|
|
45
52
|
dial?: import("@parcha/agentrun-computer").HostedDial;
|
|
46
53
|
mcpLoopback?: boolean;
|
|
47
54
|
mcpOwn?: readonly string[];
|
package/dist/runner/beside.js
CHANGED
|
@@ -29,11 +29,18 @@ export function besideStopping(server, held, drainMs) {
|
|
|
29
29
|
* caller hands its own: the template eval's in-process server, its faux's). `loops` and `drainMs`: the runner's
|
|
30
30
|
* (RunnerOptions), the CLI start's from the server's flags (besideRunnerOptions). `janitor`: run the computer janitor
|
|
31
31
|
* too (workspace/computer-janitor.ts), as the CLI's start asks. `hub`: the server's AttachHub (Serve.attachHub), which
|
|
32
|
-
* holds each paired computer's socket in this process, so a run here takes one
|
|
32
|
+
* holds each paired computer's socket in this process, so a run here takes one; with it `beside`, the name and
|
|
33
|
+
* incarnation the server gave this runner (Serve.beside), which it runs under and its run's route of a paired box names
|
|
34
|
+
* (dial-relay.ts pairedRelayOn over the server's hub), so a runner apart's take for another run is refused while the
|
|
35
|
+
* hold lasts and the server keeps the box in its hub. `dial`: the server's (Serve.dial), which
|
|
33
36
|
* a remote provider's create takes, so a machine that dials the server lands in this process's hub. Returns the runner
|
|
34
37
|
* and a close() that stops both and closes its store. `loopsTold`: `loops` was given (besideRunnerOptions), so on uid
|
|
35
38
|
* isolation a number past the helper's slots is refused rather than cut. */
|
|
36
|
-
export async function runnerBeside(dataDir, { loops, loopsTold, drainMs, env, janitor, ownProcesses, hub, dial, mcpLoopback, mcpOwn, ollamaHost, evalFakes, harnessInstall, onLine, onRunEnded } = {}) {
|
|
39
|
+
export async function runnerBeside(dataDir, { loops, loopsTold, drainMs, env, janitor, ownProcesses, hub, beside, dial, mcpLoopback, mcpOwn, ollamaHost, evalFakes, harnessInstall, onLine, onRunEnded } = {}) {
|
|
40
|
+
// A paired box in the server's hub is held under a route naming this runner, which the server must know: never one
|
|
41
|
+
// without the other.
|
|
42
|
+
if (hub !== undefined && beside === undefined)
|
|
43
|
+
throw new Error("a runner beside a server takes the server's hub with the name and incarnation the server gave it (Serve.beside)");
|
|
37
44
|
const { runnerName, startRunner } = await import("./runner.js");
|
|
38
45
|
const { dispatchRunner } = await import("./harness-loops.js");
|
|
39
46
|
const { routeOf } = await import("./model-route.js");
|
|
@@ -67,7 +74,12 @@ export async function runnerBeside(dataDir, { loops, loopsTold, drainMs, env, ja
|
|
|
67
74
|
const { hostAddressesOnce } = await import("../docker-host-addresses.js");
|
|
68
75
|
const { PROVIDERS } = await import("@parcha/agentrun-computer");
|
|
69
76
|
const { hostCommandRefusals } = await import("../computers.js");
|
|
70
|
-
|
|
77
|
+
// A paired box is brought and let go over the server's hub as a runner apart's is over its own (dial-relay.ts
|
|
78
|
+
// pairedRelayOn): its run's claim takes the box's route under this runner's name and incarnation, a cancel mid-bring
|
|
79
|
+
// or the run's release (its loop's finally, a cancel or a throw included) drops it, and a sweep drops one whose hold
|
|
80
|
+
// ended without either.
|
|
81
|
+
const paired = hub && beside ? (await import("../dial-relay.js")).pairedRelayOn({ store, hub, runner: beside.runner, incarnation: beside.incarnation, log: (line) => console.error(`agentrun-serve runner: ${line}`) }) : undefined;
|
|
82
|
+
const computers = runnerComputers(store, runs, seal.key, { dockerPaths: () => dockerPathsForRuns(runs, dataDir), hostAddresses: () => hostAddressesOnce(runs), hostWhy: hostCommandRefusals(PROVIDERS, process.env.PATH), ...(paired ? { pairedRelay: paired.paired } : {}), ...(dial ? { dial } : {}) });
|
|
71
83
|
// `mcpLoopback`: the server beside it is a local install (Serve.localInstall), so its runs may reach an MCP server on
|
|
72
84
|
// loopback; a runner in its own process does only as its own environment says (main.ts runnerLoopback). `mcpOwn`: that server's own addresses (Serve.own), whose ports a run's
|
|
73
85
|
// loopback read never goes to. A run's log lines (a sweep that failed) go to
|
|
@@ -87,6 +99,7 @@ export async function runnerBeside(dataDir, { loops, loopsTold, drainMs, env, ja
|
|
|
87
99
|
isolation = await runIsolationOf(process.env, loopsTold ? loops : undefined, deps.log);
|
|
88
100
|
}
|
|
89
101
|
catch (error) {
|
|
102
|
+
paired?.stop();
|
|
90
103
|
await store.close();
|
|
91
104
|
seal.release();
|
|
92
105
|
throw error;
|
|
@@ -112,7 +125,11 @@ export async function runnerBeside(dataDir, { loops, loopsTold, drainMs, env, ja
|
|
|
112
125
|
// stderr), so a lapse of its claims shows its cause.
|
|
113
126
|
const { runLine } = await import("../print.js");
|
|
114
127
|
const { metricLine, startRunnerGauge } = await import("./runner-metrics.js");
|
|
115
|
-
const name = runnerName();
|
|
128
|
+
const name = beside?.runner ?? runnerName();
|
|
129
|
+
// Said on the data folder before it claims: whether its runs on Claude Code's login stay in this process, its CLI on
|
|
130
|
+
// the login's folder (claude-login-token.ts sayLoginRunner), for a runner whose runs are users of their own to read.
|
|
131
|
+
const { sayLoginRunner } = await import("../claude-login-token.js");
|
|
132
|
+
sayLoginRunner(dataDir, name, isolation?.kind === "uid" ? "uid" : "process");
|
|
116
133
|
const said = (event) => {
|
|
117
134
|
for (const { line, error } of besideLines(name, event, { metricLine, troubleLine, runLine }))
|
|
118
135
|
(onLine ?? (error ? console.error : console.log))(line);
|
|
@@ -127,7 +144,7 @@ export async function runnerBeside(dataDir, { loops, loopsTold, drainMs, env, ja
|
|
|
127
144
|
const { runCensus } = await import("../run-census.js");
|
|
128
145
|
const self = () => (runner.incarnation ? { runner: name, incarnation: runner.incarnation } : undefined);
|
|
129
146
|
const runEnded = projectRunEnded(store, runEndComputers({ store, computers: computers.computerDeps, log: (line) => console.error(`agentrun-serve runner: ${line}`), self }));
|
|
130
|
-
const runner = startRunner({ store, name, createLoop, census: runCensus(store, { data: dataDir, sealKey: seal.key, env: runs }), memory: runnerMemory(store, undefined, runs, isolation ? RUN_PROCESS_MIB : 0), onEvent: said, runEnded, ...(held !== undefined ? { loops: held } : {}), ...(drainMs !== undefined ? { drainMs } : {}) });
|
|
147
|
+
const runner = startRunner({ store, name, ...(beside ? { incarnation: beside.incarnation } : {}), createLoop, census: runCensus(store, { data: dataDir, sealKey: seal.key, env: runs }), memory: runnerMemory(store, undefined, runs, isolation ? RUN_PROCESS_MIB : 0), onEvent: said, runEnded, ...(held !== undefined ? { loops: held } : {}), ...(drainMs !== undefined ? { drainMs } : {}) });
|
|
131
148
|
// The computer janitor over the same computers, when the start asks for it: never under --faux. Its lines are the
|
|
132
149
|
// runner's, on stderr (a stderr whose reader closed loses them, never the process: cli.ts).
|
|
133
150
|
const { startJanitor } = await import("../workspace/computer-janitor.js");
|
|
@@ -140,7 +157,7 @@ export async function runnerBeside(dataDir, { loops, loopsTold, drainMs, env, ja
|
|
|
140
157
|
// Its gauge (runner-metrics.ts): the runs it holds of its loops, and the process's memory (the server's with it), every
|
|
141
158
|
// minute until its close.
|
|
142
159
|
const gauge = startRunnerGauge({ runner: name, held: () => runner.held().length, slots: held ?? RUNNER_LOOPS, write: (line) => (onLine ?? console.log)(line) });
|
|
143
|
-
return { runner, close: async () => { gauge.stop(); await Promise.all([swept?.close(), runner.close()]); await claimInstallsStopped(); await store.close(); seal.release(); } };
|
|
160
|
+
return { runner, close: async () => { gauge.stop(); await Promise.all([swept?.close(), runner.close()]); paired?.stop(); await claimInstallsStopped(); await store.close(); seal.release(); } };
|
|
144
161
|
}
|
|
145
162
|
/** The lines runner `name` beside a server says for `event`, in order, each with whether it goes to stderr (`error`): its
|
|
146
163
|
* metric line (runner-metrics.ts metricLine: a claim, a hand-back by cause, a lost claim, the drain), then its trouble
|
|
@@ -172,7 +189,7 @@ export async function serveWithRunner(options) {
|
|
|
172
189
|
const serve = await startServe(options);
|
|
173
190
|
// Each run a process of its own, as a user of its own where the image's helper can switch, as the CLI's start runs
|
|
174
191
|
// them (cli.ts): the isolation the server's capabilities say (runIsolationOf over the same helper) is the runner's.
|
|
175
|
-
const beside = await runnerBeside(options.data, { loops, loopsTold, drainMs, env: besideRunEnv(process.env, fauxEnvOf(options)), ownProcesses: true, hub: serve.attachHub, dial: serve.dial, mcpLoopback: serve.localInstall, mcpOwn: serve.own, ollamaHost: serve.ollamaHost, ...(options.log ? { onLine: options.log } : {}) }).catch(async (error) => {
|
|
192
|
+
const beside = await runnerBeside(options.data, { loops, loopsTold, drainMs, env: besideRunEnv(process.env, fauxEnvOf(options)), ownProcesses: true, hub: serve.attachHub, beside: serve.beside, dial: serve.dial, mcpLoopback: serve.localInstall, mcpOwn: serve.own, ollamaHost: serve.ollamaHost, ...(options.log ? { onLine: options.log } : {}) }).catch(async (error) => {
|
|
176
193
|
await serve.close();
|
|
177
194
|
throw error;
|
|
178
195
|
});
|
|
@@ -61,8 +61,12 @@ export declare function hostDecisionKeys(deps: ClaimSecretsDeps, providers: read
|
|
|
61
61
|
/** The model keys the host's models of `tiers` need (model.ts modelKeys: each one's provider's, or the gateway's), read as
|
|
62
62
|
* claimSecrets reads a run's (the runner's environment first, then the key saved in Settings → Model keys), for a run's
|
|
63
63
|
* learned workflow nodes of those tiers (adapter-run-spec.ts learnedTierRoutes): claimSecrets opens only the run's own
|
|
64
|
-
* model's. For the tiers' routes alone, through withModelKeys (never enumerable), never onto a tool's environment.
|
|
65
|
-
|
|
64
|
+
* model's. For the tiers' routes alone, through withModelKeys (never enumerable), never onto a tool's environment.
|
|
65
|
+
* `refs`: a model named for a tier in place of the host's (an agentic revision's modelTiers, for its subagent tiers:
|
|
66
|
+
* subagentTierKeys), read on the runner alone; a run's process names none. It scopes the key names alone: the ChatGPT
|
|
67
|
+
* sign-in is given for the host's models of `tiers`, as before (a revision's own model on the plan reaches the sign-in
|
|
68
|
+
* through its claim: claimSecrets reachesPlan). */
|
|
69
|
+
export declare function tierModelKeys(deps: ClaimSecretsDeps, tiers: readonly Tier[], refs?: Readonly<Partial<Record<Tier, string>>>): Promise<NodeJS.ProcessEnv>;
|
|
66
70
|
/** Every model key a model route reads by name: each of pi-ai's providers' (model.ts PROVIDER_KEYS) and the gateway's. */
|
|
67
71
|
export declare const MODEL_KEY_NAMES: readonly string[];
|
|
68
72
|
/** `env` for a model route (model-route.ts routeOf, a CLI's providerFor): the runner's own environment, its secrets kept
|
|
@@ -70,17 +74,18 @@ export declare const MODEL_KEY_NAMES: readonly string[];
|
|
|
70
74
|
* a claim opened from the store (claimSecrets, scoped to the run's model), or every one the server holds
|
|
71
75
|
* (savedModelKeys). So a model key saved in Settings → Model keys reaches the next run's model requests with no
|
|
72
76
|
* restart, as a tool key reaches its tools; a key set where AgentRun starts still wins (claimSecrets reads it first),
|
|
73
|
-
* and a provider the runner holds any key of gets none of its saved ones.
|
|
77
|
+
* and a provider the runner holds any key of gets none of its saved ones. Each name is read from the first of `opened`
|
|
78
|
+
* that holds it, by name, as a run's process is handed its keys (run-child-host.ts handed): a claim's model keys, never
|
|
79
|
+
* enumerable, count as any other.
|
|
74
80
|
* The keys added are never enumerable either: a spread of the result, or a spawn given it, carries none of them. */
|
|
75
|
-
export declare function withModelKeys(env: NodeJS.ProcessEnv, opened: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
|
|
81
|
+
export declare function withModelKeys(env: NodeJS.ProcessEnv, ...opened: readonly NodeJS.ProcessEnv[]): NodeJS.ProcessEnv;
|
|
82
|
+
/** The saved model keys of the models of a run's subagent tiers (`tiers`, `refs` as subagent.ts routedSubagentTiers
|
|
83
|
+
* gives them; the revision's model of a tier over the host's): each model's provider's key, or the gateway's. None for
|
|
84
|
+
* no tier. */
|
|
85
|
+
export declare function subagentTierKeys(deps: ClaimSecretsDeps, tiers: readonly Tier[], refs: Readonly<Partial<Record<Tier, string>>>): Promise<NodeJS.ProcessEnv>;
|
|
76
86
|
/** Every model key the server holds, for a model route with no revision to scope it by (an SDK run's compile turn): each
|
|
77
87
|
* by its name from `deps.env` first, then the store's sealed value, as claimSecrets reads them. */
|
|
78
88
|
export declare function savedModelKeys(deps: ClaimSecretsDeps): Promise<NodeJS.ProcessEnv>;
|
|
79
|
-
/** Of `saved` (savedModelKeys'), the keys a route to `model` (`provider/model-id`) reads and no other: its provider's
|
|
80
|
-
* (PROVIDER_KEYS), or through a gateway (`env`'s AGENT_MODEL_BASE_URL, as modelKeys reads it) the gateway's key alone.
|
|
81
|
-
* None for no model, or one whose provider names no key. What a runner hands a run's process for one route of its
|
|
82
|
-
* (run-child-host.ts savedModelKeys): never every key the server holds. */
|
|
83
|
-
export declare function routeModelKeys(saved: NodeJS.ProcessEnv, env: NodeJS.ProcessEnv, model: string | undefined): NodeJS.ProcessEnv;
|
|
84
89
|
/** A run's own model key, held by its claim (run-model-key.ts): `fresh()` opens it from the run's launch again (a message's
|
|
85
90
|
* new key replaces it, or a run that started on the server's key takes its first); `everHeld()`, whether the claim ever
|
|
86
91
|
* held one, so spend after the turn never falls to the server's key for a run that brought its own. */
|
|
@@ -142,14 +147,11 @@ export declare function serverKeyless(deps: ClaimSecretsDeps): Promise<boolean>;
|
|
|
142
147
|
* Settings → Model keys) has none to spend (noServerKeyWords). Undefined where it runs. */
|
|
143
148
|
export declare function claimSpendOff(deps: ClaimSecretsDeps, runKey: ClaimModelKey | undefined): Promise<(what: string) => string | undefined>;
|
|
144
149
|
/** The env a claimed run's model routes read: the run's own key alone where the claim opened one (withRunModelKey); else
|
|
145
|
-
* the runner's environment with the keys `opened` for it
|
|
146
|
-
* once a message hands it one (withRunModelKeyLater). */
|
|
147
|
-
export declare function claimModelEnv(env: NodeJS.ProcessEnv, opened: NodeJS.ProcessEnv, runKey: ClaimModelKey | undefined, claim?: Pick<Claim, "runId" | "turn" | "attempt">): NodeJS.ProcessEnv;
|
|
150
|
+
* the runner's environment with the keys `opened` for it, each name from the first source that holds it (withModelKeys),
|
|
151
|
+
* whose gateway variables read the run's key once a message hands it one (withRunModelKeyLater). */
|
|
152
|
+
export declare function claimModelEnv(env: NodeJS.ProcessEnv, opened: readonly NodeJS.ProcessEnv[], runKey: ClaimModelKey | undefined, claim?: Pick<Claim, "runId" | "turn" | "attempt">): NodeJS.ProcessEnv;
|
|
148
153
|
/** `toolEnv` with no model key in it, for a run that holds its own: a tool's environment never carries a model key the
|
|
149
154
|
* run's model routes do not send. The decision providers' keys stay (DECISION_KEY_NAMES): a keyed workflow's judge,
|
|
150
155
|
* pick, sift, route and ask nodes run on them as any run's do. */
|
|
151
156
|
export declare function withoutModelKeys(toolEnv: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
|
|
152
|
-
/** `under` and `over` as one set of opened keys for claimModelEnv, `over`'s value winning by name: every property as it
|
|
153
|
-
* is, so a claim's model keys (claimSecrets: never enumerable), which a spread would drop, reach the route. */
|
|
154
|
-
export declare function keysOver(under: NodeJS.ProcessEnv, over: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
|
|
155
157
|
export {};
|