@parcha/agentrun-serve 0.1.0-beta.30 → 0.1.0-beta.31

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.
Files changed (76) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/README.md +182 -26
  3. package/dist/agents.d.ts +8 -3
  4. package/dist/agents.js +4 -1
  5. package/dist/app.js +23 -8
  6. package/dist/background.d.ts +2 -1
  7. package/dist/background.js +41 -20
  8. package/dist/box-egress-vm.d.ts +125 -0
  9. package/dist/box-egress-vm.js +350 -0
  10. package/dist/box-egress.d.ts +3 -2
  11. package/dist/box-relay-vm.d.ts +4 -0
  12. package/dist/box-relay-vm.js +76 -55
  13. package/dist/boxes.d.ts +7 -2
  14. package/dist/boxes.js +30 -11
  15. package/dist/cap.d.ts +2 -1
  16. package/dist/cap.js +2 -1
  17. package/dist/cli.js +30 -4
  18. package/dist/console/assets/{index-34jfpIbQ.js → index-CnJBf7Lc.js} +90 -85
  19. package/dist/console/index.html +1 -1
  20. package/dist/decisions.d.ts +3 -3
  21. package/dist/decisions.js +4 -3
  22. package/dist/files.d.ts +3 -0
  23. package/dist/files.js +3 -0
  24. package/dist/grade.d.ts +5 -2
  25. package/dist/grade.js +13 -5
  26. package/dist/harness-app.js +10 -1
  27. package/dist/host-check.d.ts +12 -0
  28. package/dist/host-check.js +34 -0
  29. package/dist/key-words.d.ts +37 -0
  30. package/dist/key-words.js +40 -0
  31. package/dist/learn/grade.d.ts +3 -0
  32. package/dist/learn/grade.js +3 -1
  33. package/dist/learn/index.d.ts +1 -1
  34. package/dist/learn/index.js +1 -1
  35. package/dist/learn/reflect.js +2 -0
  36. package/dist/learn/skills.d.ts +2 -0
  37. package/dist/learn/skills.js +16 -0
  38. package/dist/learning-routes.d.ts +30 -1
  39. package/dist/learning-routes.js +173 -19
  40. package/dist/learning-run.d.ts +1 -1
  41. package/dist/learning-run.js +25 -4
  42. package/dist/learning-words.d.ts +7 -3
  43. package/dist/learning-words.js +26 -8
  44. package/dist/learning.d.ts +9 -1
  45. package/dist/learning.js +57 -2
  46. package/dist/mcp-gateway.d.ts +96 -0
  47. package/dist/mcp-gateway.js +408 -0
  48. package/dist/mcp-meta.d.ts +17 -0
  49. package/dist/mcp-meta.js +38 -0
  50. package/dist/mcp-servers.d.ts +26 -5
  51. package/dist/mcp-servers.js +53 -10
  52. package/dist/openapi.js +52 -9
  53. package/dist/page.d.ts +2 -0
  54. package/dist/page.js +3 -0
  55. package/dist/place.d.ts +3 -2
  56. package/dist/place.js +11 -3
  57. package/dist/print.d.ts +7 -0
  58. package/dist/print.js +13 -0
  59. package/dist/run-box.js +15 -5
  60. package/dist/runnable.d.ts +8 -1
  61. package/dist/runnable.js +51 -2
  62. package/dist/runs.d.ts +15 -8
  63. package/dist/runs.js +66 -13
  64. package/dist/secrets.d.ts +15 -0
  65. package/dist/secrets.js +20 -2
  66. package/dist/server.d.ts +10 -1
  67. package/dist/server.js +111 -29
  68. package/dist/tool-gate.d.ts +18 -3
  69. package/dist/tool-gate.js +44 -13
  70. package/dist/tool-keys.d.ts +2 -1
  71. package/dist/tool-keys.js +4 -8
  72. package/dist/tool-plane.d.ts +5 -1
  73. package/dist/tool-plane.js +30 -6
  74. package/dist/tools.js +8 -5
  75. package/dist/web-fetch.js +3 -3
  76. package/package.json +12 -16
package/dist/runs.d.ts CHANGED
@@ -4,6 +4,7 @@ import { type MessageOrigin, type RunMetrics, type TimelineEvent } from "@parcha
4
4
  import type { RUN_EVENTS, RunNotice } from "./webhooks.js";
5
5
  import type { RunTrigger } from "./triggers.js";
6
6
  import { type AgentEntry, type Agents } from "./agents.js";
7
+ import { type McpServerSource } from "./mcp-gateway.js";
7
8
  import { type DaytonaApi } from "./daytona-api.js";
8
9
  import { type Learning, type LearningMode, type LearningReason, type LearningState } from "./learning.js";
9
10
  import { LearningRuns, type Reflect } from "./learning-run.js";
@@ -313,12 +314,12 @@ export declare const SUGGESTED_RAISE_FACTOR = 10;
313
314
  export declare const suggestedCap: (cap: number, spentUsd: number, needsUsd: number) => number;
314
315
  /** The run's cost from its usage row: null when a response's cost is unknown, 0 before any request. */
315
316
  export declare const costOf: (rows: readonly TimelineEvent[]) => number | null;
316
- /** What a run's paid tools charged (`tool`'s alone, when given), from the same rows its cost is read from: each charge's
317
- * line carries it (`usage` on a `phase` row); null when one is unknown. A call still marked, in flight or cut, is no
318
- * charge here. */
319
- export declare const toolCostOf: (rows: readonly TimelineEvent[], tool?: string) => number | null;
317
+ /** What a run's paid tools charged (`tool`'s alone, when given; every other tool's with `others`), from the same rows its
318
+ * cost is read from: each charge's line carries it (`usage` on a `phase` row), and a browser call's row what its charges
319
+ * came to; null when one is unknown. A call still marked, in flight or cut, is no charge here. */
320
+ export declare const toolCostOf: (rows: readonly TimelineEvent[], tool?: string, others?: boolean) => number | null;
320
321
  /** What a run's paid tools are known to have charged (`tool`'s alone, when given; every other tool's with `others`): each
321
- * charge's line that names its cost, a charge of unknown cost adding nothing. */
322
+ * charge's line that names its cost, a charge of unknown cost adding nothing (a browser call's row, what is known of it). */
322
323
  export declare const knownToolCostOf: (rows: readonly TimelineEvent[], tool?: string, others?: boolean) => number;
323
324
  /** A run's cost for its views: its usage row's, else what the store kept when it carried the run back (0 before any
324
325
  * request). A usage row that says unknown, or says nothing, stays unknown: what the store kept dates from before a
@@ -377,10 +378,12 @@ export type StartOptions = {
377
378
  * tried again; `readyTimeoutMs`: how long a request to a run waits for its door (a run's first message, sent by its
378
379
  * start, always waits READY_TIMEOUT_MS); `log` takes a run's start and end (print.ts). */
379
380
  export type RunsOptions = {
380
- dockerAllow?: readonly string[] | "none";
381
+ dockerAllow?: readonly string[] | "none"; /** On a Mac, the server's proxy container's volume a run's Docker box mounts (box-egress-vm.ts). */
382
+ dockerVolume?: string;
381
383
  agents: Agents;
382
384
  token: string; /** The server's saved tool keys, read by name for its runs alone (secrets.ts). */
383
- storedKeys?: StoredKeys;
385
+ storedKeys?: StoredKeys; /** The server's saved MCP servers (mcp-servers.ts): a run's pin and its credentials come from them at each launch. */
386
+ mcpServers?: McpServerSource;
384
387
  documents?: string;
385
388
  doorTokenFile: string;
386
389
  doorToken: string; /** The test switches a run's process gets (server.ts fauxEnvOf): empty outside tests. */
@@ -688,6 +691,9 @@ export declare class Runs {
688
691
  /** Reads what decides the secrets runs of `run`'s revision are handed (needsOf), once per revision: from `given` (a
689
692
  * start's, read from the store), else from the agent store, waiting out a busy one as a run's end does. */
690
693
  private pinNeeds;
694
+ /** `run`'s pinned MCP tools: read from its directory, or at its first launch made from the granted `tools` and the
695
+ * servers saved now, and written before its process starts. Undefined when it grants none. */
696
+ private mcpPin;
691
697
  /** The saved sign-in the run's browser starts from (sign-ins.ts), resolved before each launch: made at the vendor when
692
698
  * its agent has none, and leased to this run to save unless another run of the agent holds the lease. One that cannot
693
699
  * be had (the vendor not answering, a seal key changed) leaves its browser signed out, said in its log. */
@@ -758,7 +764,8 @@ export declare class Runs {
758
764
  /** One message to the run's door. `origin`: who wrote it when the person did not (a raised cap's follow-up, an
759
765
  * approval's resume), carried to its user entry so the Timeline shows it as the server's (pi-durable-agent's
760
766
  * MessageOrigin); the model reads the same text either way. `answers: false`: the run's door refuses the message
761
- * (WAITING) when the run's turn ended on ask_person, and when the run is busy (BUSY), so it is never queued behind a
767
+ * (WAITING) when the run's turn ended on ask_person or a tool call of it waits for its owner's approval (the gate's
768
+ * park, APPROVAL_ENTRY), and when the run is busy (BUSY), so it is never queued behind a
762
769
  * turn that may end so; decided at the door's admission, past every wait here. */
763
770
  private submit;
764
771
  /** Whether the run's harness takes a message mid-turn. */
package/dist/runs.js CHANGED
@@ -13,12 +13,14 @@ import { ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
13
13
  import { processAlive } from "@parcha/agentrun-kernel/host";
14
14
  import { doorTook } from "@parcha/pi-durable-disk";
15
15
  import { AgentHomeError } from "@parcha/pi-durable-agent";
16
- import { isMessageRow, registerLabel, registerTurnEnding, REQUEST_STARTED, runMetricsWithDecisions, timelineOf, timelineReducer } from "@parcha/pi-durable-agent/timeline";
16
+ import { chargedTool, isMessageRow, registerLabel, registerTurnEnding, REQUEST_STARTED, runMetricsWithDecisions, timelineOf, timelineReducer } from "@parcha/pi-durable-agent/timeline";
17
17
  import { HARNESS_LOG_EVENT, harnessModelKeys, thinkingFor } from "./adapters.js";
18
18
  import { DEFAULT_HARNESS, harnessOfBody, steersMidTurn } from "./harness.js";
19
19
  import { hostMemory, memoryFull, neverFits, runMibOf, runsMemoryMib } from "./host.js";
20
20
  import { storeBusy, storeError, whenFree } from "./agents.js";
21
- import { FOLLOW_UP_OPEN_ENV, LAUNCH_LOST, readJson, RUN_CANCELLED, RUN_DOOR_TOKEN, RUN_LAUNCHING, RUN_META, runDoorToken, SETUP_LOST, writeWhole } from "./files.js";
21
+ import { FOLLOW_UP_OPEN_ENV, LAUNCH_LOST, readJson, RUN_CANCELLED, RUN_DOOR_TOKEN, RUN_LAUNCHING, RUN_META, runDoorToken, SETUP_LOST, writeDurableSync, writeWhole } from "./files.js";
22
+ import { MCP_PIN, mcpCredentialsOf, mcpPinOf } from "./mcp-gateway.js";
23
+ import { META_REASON, metaToolOf } from "./mcp-meta.js";
22
24
  import { KEPT_AUTOSTOP_MINUTES, keepWhenIdle, wakeBoxes } from "./daytona-api.js";
23
25
  import { LEARNING_LABEL, shortOf } from "./learning.js";
24
26
  import { labelled, LearningRuns, reflecting, reflects, withLearning } from "./learning-run.js";
@@ -40,7 +42,7 @@ import { TOOL_KEYS } from "./tool-keys.js";
40
42
  import { isObject } from "./validate.js";
41
43
  import { firstMessage } from "./run-manifest.js";
42
44
  import { REFLECT_REQUEST, Turns } from "./turns.js";
43
- import { DECISION_KEYS, handover, handoverSignIn, hostSecrets, secret, SECRET_NAMES, SECRETS_FD_ENV, SECRETS_LEN_ENV, withoutSecrets, withSecrets } from "./secrets.js";
45
+ import { DECISION_KEYS, handover, handoverSignIn, hostSecrets, mcpHandover, mcpSecretValues, secret, SECRET_NAMES, SECRETS_FD_ENV, SECRETS_LEN_ENV, withoutSecrets, withSecrets } from "./secrets.js";
44
46
  import { MIN_SECRET } from "./learn/secrets.js";
45
47
  import { keyRefusal, redacted, redactedAnswer, redactedLive, redactedOutput, runKeyOf, withoutLoopback } from "./key-refusal.js";
46
48
  import { GRAPH_CACHE_BYTES, PartCache, servedPart } from "./graph-served.js";
@@ -50,6 +52,7 @@ import { remotePlace, storedPlace } from "./place.js";
50
52
  import { destroyRunBoxes, ensureRemoteBox, PullIncomplete, pullRemoteBox, RUN_LABEL, sweepRunBoxes } from "./run-box.js";
51
53
  import { BACKGROUND_DIR, endBackground } from "./background.js";
52
54
  import { removeEgressDir, RUN_BOX_ALLOW_ENV } from "./box-egress.js";
55
+ import { RUN_BOX_VOLUME_ENV } from "./box-egress-vm.js";
53
56
  import { BACKGROUND_CONTEXT, withAbortSignal } from "@earendil-works/chord/context";
54
57
  export const STATUSES = ["queued", "working", "paused", "input_required", "completed", "failed", "cancelled"];
55
58
  const TERMINAL = new Set(["completed", "failed", "cancelled"]);
@@ -318,13 +321,19 @@ export const costOf = (rows) => {
318
321
  const usage = usageOf(rows);
319
322
  return usage ? (usage.usage?.usd ?? null) : 0;
320
323
  };
321
- /** What a run's paid tools charged (`tool`'s alone, when given), from the same rows its cost is read from: each charge's
322
- * line carries it (`usage` on a `phase` row); null when one is unknown. A call still marked, in flight or cut, is no
323
- * charge here. */
324
- export const toolCostOf = (rows, tool) => rows.reduce((sum, row) => (row.kind !== "phase" || !row.usage || (tool !== undefined && row.tool_name !== tool) ? sum : sum === null || row.usage.usd === null ? null : sum + row.usage.usd), 0);
324
+ /** Whether `row` carries a paid tool's charge counted here: `tool`'s alone when given, every other tool's with `others`
325
+ * (chargedTool: a charge's own `phase` row, or a browser call's row its charges fold into). */
326
+ const chargeOf = (row, tool, others) => {
327
+ const charged = chargedTool(row);
328
+ return charged !== undefined && (tool === undefined || (others ? charged !== tool : charged === tool));
329
+ };
330
+ /** What a run's paid tools charged (`tool`'s alone, when given; every other tool's with `others`), from the same rows its
331
+ * cost is read from: each charge's line carries it (`usage` on a `phase` row), and a browser call's row what its charges
332
+ * came to; null when one is unknown. A call still marked, in flight or cut, is no charge here. */
333
+ export const toolCostOf = (rows, tool, others = false) => rows.reduce((sum, row) => (!chargeOf(row, tool, others) ? sum : sum === null || row.usage.usd === null ? null : sum + row.usage.usd), 0);
325
334
  /** What a run's paid tools are known to have charged (`tool`'s alone, when given; every other tool's with `others`): each
326
- * charge's line that names its cost, a charge of unknown cost adding nothing. */
327
- export const knownToolCostOf = (rows, tool, others = false) => rows.reduce((sum, row) => (row.kind !== "phase" || !row.usage || typeof row.usage.usd !== "number" || (tool !== undefined && (others ? row.tool_name === tool : row.tool_name !== tool)) ? sum : sum + row.usage.usd), 0);
335
+ * charge's line that names its cost, a charge of unknown cost adding nothing (a browser call's row, what is known of it). */
336
+ export const knownToolCostOf = (rows, tool, others = false) => rows.reduce((sum, row) => (!chargeOf(row, tool, others) ? sum : sum + (row.usage.usd ?? row.usage.so_far_usd ?? 0)), 0);
328
337
  /** A run's cost for its views: its usage row's, else what the store kept when it carried the run back (0 before any
329
338
  * request). A usage row that says unknown, or says nothing, stays unknown: what the store kept dates from before a
330
339
  * follow-up. */
@@ -1669,6 +1678,29 @@ export class Runs {
1669
1678
  const revision = given ?? (await whenFree(() => this.store.readRevision(run.revision), this.busyDelays(), this.onBusy(run.id, "the agent store")));
1670
1679
  this.needs.set(run.revision, await needsOf(revision));
1671
1680
  }
1681
+ /** `run`'s pinned MCP tools: read from its directory, or at its first launch made from the granted `tools` and the
1682
+ * servers saved now, and written before its process starts. Undefined when it grants none. */
1683
+ mcpPin(run, tools) {
1684
+ const file = join(run.dir, MCP_PIN);
1685
+ if (existsSync(file)) {
1686
+ const pinned = JSON.parse(readFileSync(file, "utf8"));
1687
+ // A pin made before meta tools were refused (mcp-meta.ts) is checked at each launch, never rewritten: one it holds
1688
+ // refuses the launch, as making the pin does.
1689
+ for (const [server, { url, tools: listed }] of Object.entries(pinned)) {
1690
+ for (const tool of listed)
1691
+ if (metaToolOf(url, tool.name))
1692
+ throw new Error(`mcp:${server}/${tool.name} can't be granted: ${META_REASON}`);
1693
+ }
1694
+ return pinned;
1695
+ }
1696
+ if (!tools?.some((name) => name.startsWith("mcp:")) || !this.options.mcpServers)
1697
+ return undefined;
1698
+ const pin = mcpPinOf(tools, this.options.mcpServers);
1699
+ if (!Object.keys(pin).length)
1700
+ return undefined;
1701
+ writeDurableSync(file, JSON.stringify(pin));
1702
+ return pin;
1703
+ }
1672
1704
  /** The saved sign-in the run's browser starts from (sign-ins.ts), resolved before each launch: made at the vendor when
1673
1705
  * its agent has none, and leased to this run to save unless another run of the agent holds the lease. One that cannot
1674
1706
  * be had (the vendor not answering, a seal key changed) leaves its browser signed out, said in its log. */
@@ -1700,10 +1732,24 @@ export class Runs {
1700
1732
  const served = withSecrets(process.env, "all", this.options.storedKeys);
1701
1733
  const needs = this.needs.get(run.revision);
1702
1734
  const handed = needs ? keysFor(needs, served) : NO_TOOL_KEYS;
1735
+ // Its MCP servers: the tools it grants, pinned at its first launch in its directory (mcp-gateway.ts), and the
1736
+ // credentials of those servers alone, read now, on the same pipe.
1737
+ let pin;
1738
+ try {
1739
+ pin = this.mcpPin(run, needs?.tools);
1740
+ }
1741
+ catch (error) {
1742
+ // A granted tool that cannot be pinned refuses the launch in words, rather than a run without the tool.
1743
+ run.error = { code: "run_failed", message: error.message, retryable: false };
1744
+ run.finishing = "failed";
1745
+ void this.settle(run, 1, true);
1746
+ return;
1747
+ }
1748
+ const mcp = pin && this.options.mcpServers ? mcpCredentialsOf(pin, this.options.mcpServers) : undefined;
1703
1749
  // And its saved sign-in, on the same pipe after them (pinSignIn): a pointer its browser opens, never in its environment.
1704
- const secrets = run.signIn ? Buffer.concat([handover(handed, this.options.storedKeys), handoverSignIn(run.signIn)]) : handover(handed, this.options.storedKeys);
1750
+ const secrets = Buffer.concat([handover(handed, this.options.storedKeys), ...(mcp ? [mcpHandover(mcp)] : []), ...(run.signIn ? [handoverSignIn(run.signIn)] : [])]);
1705
1751
  // What it was handed, for the check of what its end-of-run turn writes (learning-run.ts).
1706
- this.learning.onLaunch(run, handed);
1752
+ this.learning.onLaunch(run, handed, mcpSecretValues(mcp ?? {}));
1707
1753
  // And for what its errors show (refusedValues): each value handed, kept past a key's rotation.
1708
1754
  run.handed ??= new Set();
1709
1755
  for (const name of handed) {
@@ -1711,12 +1757,18 @@ export class Runs {
1711
1757
  if (value && value.length >= MIN_SECRET)
1712
1758
  run.handed.add(value);
1713
1759
  }
1760
+ for (const value of mcpSecretValues(mcp ?? {}))
1761
+ if (value.length >= MIN_SECRET)
1762
+ run.handed.add(value);
1714
1763
  if (run.signIn && run.signIn.ref.length >= MIN_SECRET)
1715
1764
  run.handed.add(run.signIn.ref);
1716
1765
  const env = {
1717
1766
  ...childEnv(process.env, this.options.token),
1718
1767
  // The run's box's network, as the server resolved it: never the setting itself, which the run's process ignores.
1719
1768
  [RUN_BOX_ALLOW_ENV]: this.options.dockerAllow === undefined || this.options.dockerAllow === "none" ? "none" : this.options.dockerAllow.join(","),
1769
+ // And, on a Mac, its proxy's volume: set always, empty for none, so a stale value in the server's own environment
1770
+ // never reaches a run.
1771
+ [RUN_BOX_VOLUME_ENV]: this.options.dockerVolume ?? "",
1720
1772
  [SECRETS_FD_ENV]: "3",
1721
1773
  [SECRETS_LEN_ENV]: String(secrets.length),
1722
1774
  ...this.fauxEnv(),
@@ -2309,11 +2361,12 @@ export class Runs {
2309
2361
  /** One message to the run's door. `origin`: who wrote it when the person did not (a raised cap's follow-up, an
2310
2362
  * approval's resume), carried to its user entry so the Timeline shows it as the server's (pi-durable-agent's
2311
2363
  * MessageOrigin); the model reads the same text either way. `answers: false`: the run's door refuses the message
2312
- * (WAITING) when the run's turn ended on ask_person, and when the run is busy (BUSY), so it is never queued behind a
2364
+ * (WAITING) when the run's turn ended on ask_person or a tool call of it waits for its owner's approval (the gate's
2365
+ * park, APPROVAL_ENTRY), and when the run is busy (BUSY), so it is never queued behind a
2313
2366
  * turn that may end so; decided at the door's admission, past every wait here. */
2314
2367
  async submit(run, content, whenBusy, requestId, readyMs, origin, answers = true) {
2315
2368
  await this.beforeSubmit?.(run.id, content);
2316
- const answer = await this.toDoor(run, "/submit", { requestId, content, whenBusy, ...(origin ? { origin } : {}), ...(answers ? {} : { answers: false, asks: [ASK_TOOL] }) }, readyMs);
2369
+ const answer = await this.toDoor(run, "/submit", { requestId, content, whenBusy, ...(origin ? { origin } : {}), ...(answers ? {} : { answers: false, asks: [ASK_TOOL], parks: [APPROVAL_ENTRY] }) }, readyMs);
2317
2370
  if (answer.status === 409 && answer.body?.error === "WAITING")
2318
2371
  throw new ApiError("not_continuable", WAITS_ON_A_PERSON, { details: { reason: "waiting" } });
2319
2372
  if (answer.status === 409 && answer.body?.error === "BUSY" && !answers)
package/dist/secrets.d.ts CHANGED
@@ -5,6 +5,10 @@ export declare const SECRETS_LEN_ENV = "AGENTRUN_SECRETS_LEN";
5
5
  * key pi-ai's providers read is on it (model.ts' PROVIDER_KEYS, which the custody test checks against pi-ai's own
6
6
  * table), so a key set for any provider's model is held here, never left in an environment. */
7
7
  export declare const SECRET_NAMES: readonly string[];
8
+ /** A run's remote MCP servers' credentials, the one entry its pipe holds that is not on the launcher's list: JSON, each
9
+ * server the run's revision grants a tool of with its URL now and, when that is the run's pinned one, its headers
10
+ * (mcp-gateway.ts McpCredentials). A run that grants none gets no entry. */
11
+ export declare const MCP_AUTH = "AGENTRUN_MCP_AUTH";
8
12
  /** The decision keys among them: a run's process gets them only on its decision descriptor (decisions.ts), never with
9
13
  * the secrets on its pipe, which are its tools' environment. */
10
14
  export declare const DECISION_KEYS: readonly string[];
@@ -38,6 +42,17 @@ export declare const withoutSecrets: (env: NodeJS.ProcessEnv) => NodeJS.ProcessE
38
42
  /** What a run's process is handed: the secrets named `names` that this process holds, or its server saved (`stored`),
39
43
  * as its pipe carries them. */
40
44
  export declare function handover(names: readonly string[], stored?: StoredKeys): Buffer;
45
+ /** The MCP credentials this process was handed (MCP_AUTH), by server; none when it was handed none. */
46
+ export declare function mcpCredentials(): Record<string, {
47
+ url: string;
48
+ headers?: Record<string, string>;
49
+ }>;
50
+ /** Every header value of `credentials`: what a secret scan refuses. */
51
+ export declare const mcpSecretValues: (credentials: Record<string, {
52
+ headers?: Record<string, string>;
53
+ }>) => string[];
54
+ /** The pipe's MCP entry for `credentials`, to follow the secrets `handover` encodes. */
55
+ export declare const mcpHandover: (credentials: Record<string, unknown>) => Buffer;
41
56
  /** A run's saved sign-in as its pipe carries it, after its secrets (handover). */
42
57
  export declare const handoverSignIn: (value: {
43
58
  provider: string;
package/dist/secrets.js CHANGED
@@ -24,6 +24,10 @@ export const SECRET_NAMES = (() => {
24
24
  throw new Error("agentrun-serve's launcher names no SECRETS");
25
25
  return list.split(" ").filter(Boolean);
26
26
  })();
27
+ /** A run's remote MCP servers' credentials, the one entry its pipe holds that is not on the launcher's list: JSON, each
28
+ * server the run's revision grants a tool of with its URL now and, when that is the run's pinned one, its headers
29
+ * (mcp-gateway.ts McpCredentials). A run that grants none gets no entry. */
30
+ export const MCP_AUTH = "AGENTRUN_MCP_AUTH";
27
31
  /** The decision keys among them: a run's process gets them only on its decision descriptor (decisions.ts), never with
28
32
  * the secrets on its pipe, which are its tools' environment. */
29
33
  export const DECISION_KEYS = ["TYPESAFE_API_KEY", "PARALLEL_API_KEY"];
@@ -39,7 +43,7 @@ const encode = (pairs) => Buffer.concat([...pairs].map(([name, value]) => Buffer
39
43
  function decode(bytes) {
40
44
  for (const pair of bytes.toString("utf8").split("\0")) {
41
45
  const at = pair.indexOf("=");
42
- if (at > 0 && SECRET_NAMES.includes(pair.slice(0, at)))
46
+ if (at > 0 && (SECRET_NAMES.includes(pair.slice(0, at)) || pair.slice(0, at) === MCP_AUTH))
43
47
  held.set(pair.slice(0, at), pair.slice(at + 1));
44
48
  else if (pair.slice(0, at) === SIGN_IN_PAIR)
45
49
  signIn = pair.slice(at + 1);
@@ -90,7 +94,7 @@ const SECRET_NAME = /(?:^|_)(?:KEY|TOKEN|SECRET|PASSWORD)$/i;
90
94
  * every other key, token, secret or password `env` names. One shorter than the checker's MIN_SECRET,
91
95
  * whitespace aside, matches too much text by chance to be refused, and is left out. */
92
96
  export const hostSecrets = (env, stored) => {
93
- const held = SECRET_NAMES.flatMap((name) => [secret(name) ?? "", stored?.(name) ?? ""]);
97
+ const held = [...SECRET_NAMES.flatMap((name) => [secret(name) ?? "", stored?.(name) ?? ""]), ...mcpSecretValues(mcpCredentials())];
94
98
  const named = Object.entries(env).filter(([name]) => SECRET_NAME.test(name) && !SECRET_NAMES.includes(name)).map(([, value]) => value ?? "");
95
99
  return [...new Set([...held, ...named])].filter((value) => value.replace(/\s+/g, "").length >= MIN_SECRET);
96
100
  };
@@ -137,6 +141,20 @@ export function handover(names, stored) {
137
141
  return value === undefined ? [] : [[name, value]];
138
142
  }));
139
143
  }
144
+ /** The MCP credentials this process was handed (MCP_AUTH), by server; none when it was handed none. */
145
+ export function mcpCredentials() {
146
+ try {
147
+ const parsed = JSON.parse(held.get(MCP_AUTH) ?? "{}");
148
+ return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
149
+ }
150
+ catch {
151
+ return {};
152
+ }
153
+ }
154
+ /** Every header value of `credentials`: what a secret scan refuses. */
155
+ export const mcpSecretValues = (credentials) => Object.values(credentials).flatMap((server) => Object.values(server.headers ?? {})).flatMap((value) => [value, value.replace(/^Bearer\s+/i, "")]);
156
+ /** The pipe's MCP entry for `credentials`, to follow the secrets `handover` encodes. */
157
+ export const mcpHandover = (credentials) => encode([[MCP_AUTH, JSON.stringify(credentials)]]);
140
158
  /** A run's saved sign-in as its pipe carries it, after its secrets (handover). */
141
159
  export const handoverSignIn = (value) => encode([[SIGN_IN_PAIR, JSON.stringify(value)]]);
142
160
  /** The saved sign-in this run's process was handed over its pipe, if any: read by the browser tool alone. */
package/dist/server.d.ts CHANGED
@@ -6,6 +6,7 @@ import { type Place } from "./place.js";
6
6
  import { type CarryBackRetry } from "./runs.js";
7
7
  import { type BoxHost } from "./box/sweep.js";
8
8
  import { type BoxOffer } from "./boxes.js";
9
+ import { type ImageState } from "./box-image.js";
9
10
  import { type StoredKeys } from "./secrets.js";
10
11
  import { type TriggerClock } from "./triggers.js";
11
12
  import { type ToolSettingsMap } from "./tool-plane.js";
@@ -95,7 +96,10 @@ export type ServeOptions = {
95
96
  /** Under `faux`: a module whose default export gives a box's egress proxy its `lookup` and `dial` (box-egress.ts), the
96
97
  * tests' fake network. */
97
98
  fauxEgress?: string;
98
- /** Extra `Host` names to accept besides the loopback ones. */
99
+ /** With `faux` only: the platform this server takes itself to run on (tests: `darwin`, to take a Mac's path to a box's
100
+ * network, box-egress-vm.ts, on another machine). */
101
+ fauxPlatform?: NodeJS.Platform;
102
+ /** Extra `Host` names to accept besides the loopback ones, on any port (host-check.ts). */
99
103
  allowHosts?: string[];
100
104
  /** The console's built files, answered at / (default dist/console beside the server, which this package's build copies
101
105
  * from apps/console/dist). */
@@ -111,6 +115,9 @@ export type ServeOptions = {
111
115
  settleRetryMs?: number;
112
116
  /** Where the log lines go (print.ts); none without it. AGENTRUN_LOG=quiet leaves out the request lines. */
113
117
  log?: (line: string) => void;
118
+ /** Told the Docker box image's state at the start, when this server has a Docker box, then each change (box-image.ts):
119
+ * the CLI says a first build in words, as it starts and as it ends. */
120
+ onBoxImage?: (state: ImageState) => void;
114
121
  /** The lines a person reads about a stop on this data root: this server's, as its close begins and runs' processes are
115
122
  * left to finish their turn, and this start's, when it waits for a server that is stopping (server-lock.ts). Default:
116
123
  * standard error, after `agentrun-serve: `. */
@@ -406,6 +413,7 @@ export declare function readingOf(base: NodeJS.ProcessEnv, maxRuns: number, stor
406
413
  transports: string[];
407
414
  auth: ("headers" | "none" | "bearer")[];
408
415
  at_rest: string;
416
+ harnesses: string[];
409
417
  };
410
418
  /** This server's learning switch (`--learning`): on, a run learns when its agent says `learning: true`; off, none does. */
411
419
  learning: "off" | "on";
@@ -654,6 +662,7 @@ export declare function capabilities(env?: NodeJS.ProcessEnv, maxRuns?: number,
654
662
  transports: string[];
655
663
  auth: ("headers" | "none" | "bearer")[];
656
664
  at_rest: string;
665
+ harnesses: string[];
657
666
  };
658
667
  /** This server's learning switch (`--learning`): on, a run learns when its agent says `learning: true`; off, none does. */
659
668
  learning: "off" | "on";