@parcha/agentrun-serve 0.1.0-beta.54 → 0.1.0-beta.55

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 (190) hide show
  1. package/CHANGELOG.md +110 -2
  2. package/README.md +266 -88
  3. package/dist/adapters.d.ts +10 -0
  4. package/dist/adapters.js +46 -0
  5. package/dist/agent-package.d.ts +3 -3
  6. package/dist/agent-package.js +6 -13
  7. package/dist/agents-store.js +6 -5
  8. package/dist/api-only.d.ts +16 -4
  9. package/dist/api-only.js +21 -7
  10. package/dist/cli.js +5 -3
  11. package/dist/composio-made.d.ts +26 -1
  12. package/dist/composio-made.js +39 -2
  13. package/dist/composio-preset.d.ts +3 -2
  14. package/dist/composio-preset.js +46 -14
  15. package/dist/computer-held-routes.js +2 -3
  16. package/dist/computer-setting.d.ts +4 -2
  17. package/dist/computer-setting.js +0 -2
  18. package/dist/computers-running.d.ts +8 -0
  19. package/dist/computers-running.js +27 -0
  20. package/dist/console/assets/backend-D5EmB4N3.js +166 -0
  21. package/dist/console/assets/index-DUYLaqiR.js +746 -0
  22. package/dist/console/assets/index-DYhU4adm.css +1 -0
  23. package/dist/console/index.html +2 -2
  24. package/dist/docker-host-addresses.d.ts +23 -3
  25. package/dist/docker-host-addresses.js +90 -18
  26. package/dist/exa-keyless.d.ts +2 -3
  27. package/dist/exa-keyless.js +43 -127
  28. package/dist/firecrawl-keyless.d.ts +41 -0
  29. package/dist/firecrawl-keyless.js +152 -0
  30. package/dist/handed-secret.d.ts +3 -1
  31. package/dist/handed-secret.js +4 -2
  32. package/dist/harness-keys.d.ts +98 -0
  33. package/dist/harness-keys.js +247 -0
  34. package/dist/harness-recipe-entry.d.ts +14 -9
  35. package/dist/harness-recipe-entry.js +25 -14
  36. package/dist/harness-table.d.ts +16 -1
  37. package/dist/harness-table.js +19 -7
  38. package/dist/harness.d.ts +4 -0
  39. package/dist/harness.js +12 -1
  40. package/dist/host-check.d.ts +2 -0
  41. package/dist/host-check.js +6 -0
  42. package/dist/import-summary.d.ts +1 -1
  43. package/dist/import-summary.js +1 -1
  44. package/dist/import.d.ts +5 -5
  45. package/dist/import.js +54 -67
  46. package/dist/keyless-mcp.d.ts +36 -0
  47. package/dist/keyless-mcp.js +127 -0
  48. package/dist/learn/audit.d.ts +3 -3
  49. package/dist/learn/audit.js +3 -3
  50. package/dist/learn/commit.d.ts +8 -7
  51. package/dist/learn/commit.js +60 -20
  52. package/dist/learn/compile.d.ts +4 -3
  53. package/dist/learn/compile.js +7 -5
  54. package/dist/learn/folder.d.ts +16 -3
  55. package/dist/learn/folder.js +46 -13
  56. package/dist/learn/promote.d.ts +37 -13
  57. package/dist/learn/promote.js +112 -40
  58. package/dist/learn/secrets.js +10 -2
  59. package/dist/learning-routes.d.ts +22 -17
  60. package/dist/learning-routes.js +40 -39
  61. package/dist/learning.js +2 -2
  62. package/dist/manifest.d.ts +10 -0
  63. package/dist/manifest.js +30 -0
  64. package/dist/mcp-pin-first.d.ts +4 -2
  65. package/dist/mcp-pin-first.js +5 -2
  66. package/dist/mcp-secret-writes.d.ts +16 -7
  67. package/dist/mcp-secret-writes.js +35 -27
  68. package/dist/mcp-servers-store.d.ts +30 -6
  69. package/dist/mcp-servers-store.js +112 -28
  70. package/dist/mcp-sources.d.ts +10 -2
  71. package/dist/mcp-sources.js +9 -2
  72. package/dist/mcp-store.d.ts +13 -7
  73. package/dist/mcp-store.js +12 -9
  74. package/dist/model-form.d.ts +3 -2
  75. package/dist/model-form.js +11 -7
  76. package/dist/model.d.ts +20 -4
  77. package/dist/model.js +68 -9
  78. package/dist/native/history.d.ts +1 -1
  79. package/dist/native/history.js +2 -2
  80. package/dist/ollama-provider.d.ts +92 -0
  81. package/dist/ollama-provider.js +495 -0
  82. package/dist/openapi/agentrun-v2.openapi.json +2 -2
  83. package/dist/openapi.js +127 -37
  84. package/dist/page.d.ts +11 -3
  85. package/dist/page.js +22 -7
  86. package/dist/place-offers.d.ts +17 -1
  87. package/dist/place-offers.js +46 -5
  88. package/dist/print.js +1 -1
  89. package/dist/purged-workflow.d.ts +35 -7
  90. package/dist/purged-workflow.js +73 -26
  91. package/dist/run-computer.d.ts +2 -0
  92. package/dist/run-computer.js +2 -0
  93. package/dist/run-files.d.ts +4 -0
  94. package/dist/run-files.js +4 -0
  95. package/dist/run-keys.d.ts +2 -4
  96. package/dist/run-keys.js +6 -7
  97. package/dist/run-launch.d.ts +4 -0
  98. package/dist/run-launch.js +4 -0
  99. package/dist/run-reads-over-store.d.ts +3 -2
  100. package/dist/run-reads-over-store.js +66 -2
  101. package/dist/run-secrets.js +5 -2
  102. package/dist/runner/adapter-loop.d.ts +6 -3
  103. package/dist/runner/adapter-loop.js +34 -15
  104. package/dist/runner/adapter-run-spec.d.ts +3 -0
  105. package/dist/runner/adapter-run-spec.js +5 -3
  106. package/dist/runner/audit.js +8 -4
  107. package/dist/runner/beside.d.ts +2 -1
  108. package/dist/runner/beside.js +6 -2
  109. package/dist/runner/claim-secrets.d.ts +5 -8
  110. package/dist/runner/claim-secrets.js +6 -0
  111. package/dist/runner/cli-run-spec.d.ts +1 -1
  112. package/dist/runner/cli-run-spec.js +38 -6
  113. package/dist/runner/harness-loops.d.ts +22 -9
  114. package/dist/runner/harness-loops.js +21 -11
  115. package/dist/runner/held.d.ts +3 -0
  116. package/dist/runner/learning-end.d.ts +1 -1
  117. package/dist/runner/learning-end.js +8 -3
  118. package/dist/runner/loop-contract.d.ts +5 -4
  119. package/dist/runner/main.js +4 -2
  120. package/dist/runner/mcp-claim.d.ts +3 -0
  121. package/dist/runner/mcp-claim.js +26 -2
  122. package/dist/runner/mcp-run.d.ts +3 -0
  123. package/dist/runner/mcp-run.js +2 -1
  124. package/dist/runner/metrics.d.ts +10 -10
  125. package/dist/runner/metrics.js +19 -38
  126. package/dist/runner/model-route.d.ts +3 -0
  127. package/dist/runner/model-route.js +6 -2
  128. package/dist/runner/promotion.d.ts +15 -9
  129. package/dist/runner/promotion.js +25 -15
  130. package/dist/runner/run-child-host.js +17 -7
  131. package/dist/runner/run-child.js +3 -1
  132. package/dist/runner/sdk-loop.js +2 -0
  133. package/dist/runner/workflow-loop.d.ts +2 -2
  134. package/dist/runner/workflow-loop.js +1 -2
  135. package/dist/runner/workflow-spec.d.ts +1 -1
  136. package/dist/runner/workflow-spec.js +6 -6
  137. package/dist/sdk/check.d.ts +4 -1
  138. package/dist/sdk/check.js +2 -1
  139. package/dist/sdk/runs.d.ts +2 -2
  140. package/dist/sdk/runs.js +8 -6
  141. package/dist/secret-cut.js +2 -1
  142. package/dist/secret-writes.d.ts +3 -2
  143. package/dist/secret-writes.js +1 -1
  144. package/dist/server.d.ts +44 -8
  145. package/dist/server.js +283 -108
  146. package/dist/standard-webhooks.d.ts +11 -0
  147. package/dist/standard-webhooks.js +20 -2
  148. package/dist/store/index.d.ts +1 -1
  149. package/dist/store/schema.js +5 -2
  150. package/dist/store/sqlite/store.js +90 -34
  151. package/dist/store/store.d.ts +54 -14
  152. package/dist/store-reads/journal.d.ts +7 -2
  153. package/dist/store-reads/journal.js +9 -6
  154. package/dist/store-reads/learning.d.ts +12 -9
  155. package/dist/store-reads/learning.js +18 -24
  156. package/dist/store-view.d.ts +0 -5
  157. package/dist/store-view.js +9 -8
  158. package/dist/template-eval.d.ts +49 -4
  159. package/dist/template-eval.js +168 -45
  160. package/dist/template-import.js +4 -2
  161. package/dist/templates.d.ts +5 -3
  162. package/dist/templates.js +19 -40
  163. package/dist/timeline/labels.d.ts +2 -2
  164. package/dist/timeline/labels.js +2 -2
  165. package/dist/timeline/timeline.d.ts +2 -2
  166. package/dist/timeline/timeline.js +1 -1
  167. package/dist/tool-plane.d.ts +17 -9
  168. package/dist/tool-plane.js +38 -17
  169. package/dist/tools.js +2 -2
  170. package/dist/trigger-launch-hook.d.ts +16 -8
  171. package/dist/trigger-launch-hook.js +32 -23
  172. package/dist/trigger-targets.d.ts +18 -8
  173. package/dist/trigger-targets.js +42 -19
  174. package/dist/triggers.d.ts +85 -23
  175. package/dist/triggers.js +303 -96
  176. package/dist/web-fake.js +3 -3
  177. package/dist/web-fetch-direct.d.ts +4 -0
  178. package/dist/web-fetch-direct.js +8 -1
  179. package/dist/web-fetch.d.ts +12 -3
  180. package/dist/web-fetch.js +47 -14
  181. package/dist/web-search.d.ts +33 -4
  182. package/dist/web-search.js +100 -41
  183. package/dist/webhooks.js +4 -5
  184. package/launcher/agentrun-serve +5 -1
  185. package/package.json +17 -13
  186. package/templates/README.md +2 -2
  187. package/dist/console/assets/index-B_85An2t.js +0 -745
  188. package/dist/console/assets/index-n1YsbnYh.css +0 -1
  189. package/dist/import-sources.d.ts +0 -116
  190. package/dist/import-sources.js +0 -693
@@ -22,6 +22,16 @@ export declare function installedHere(name: string, from?: string): string | und
22
22
  * (~/.agentrun) is not the server's default, and after the server's own command when the store is not its default.
23
23
  */
24
24
  export declare function npxLine(spec: string, env?: NodeJS.ProcessEnv, installed?: (name: string) => string | undefined): string;
25
+ /**
26
+ * A start `npx @parcha/agentrun` made (NPX_PACKAGE_ENV) that a data directory refused because an earlier version wrote it
27
+ * (store.ts StoreFromEarlierVersion, or SchemaVersionUnknown on an earlier release's store): the refusal's own first line,
28
+ * then the two ways on as commands to paste. That command keeps its data in ~/.agentrun wherever it is run, so a new
29
+ * folder alone is not a new AgentRun. First, the old folder moved aside whole, so the same command starts this version
30
+ * where it was, and the earlier version still opens what it holds; then this version on a new, empty folder: the same
31
+ * command with --data. Nothing is deleted either way. Any other error, or a start the launcher did not
32
+ * make, is undefined: the refusal's own words stand.
33
+ */
34
+ export declare function earlierDataRefusal(error: unknown, data: string, env?: NodeJS.ProcessEnv, exists?: (path: string) => boolean): string | undefined;
25
35
  /** The port the server was started on when `--port` named one, and whether `--open` was given (1 or 0): set by its CLI
26
36
  * for itself and its runs (startedWith), read by npxLine, so a hint keeps them. */
27
37
  export declare const STARTED_PORT_ENV = "AGENTRUN_SERVE_PORT";
package/dist/adapters.js CHANGED
@@ -5,6 +5,7 @@
5
5
  // alone (harness-install.ts); opencode's pinned CLI that is missing says so with the one line that installs it: an npm
6
6
  // install beside serve, or, when serve runs from npx, the npx line that runs it with the missing package.
7
7
  import { accessSync, constants, existsSync, readFileSync, statSync } from "node:fs";
8
+ import { homedir } from "node:os";
8
9
  import { dirname, join, resolve, sep } from "node:path";
9
10
  import { fileURLToPath } from "node:url";
10
11
  import { facts as claudeFacts } from "@parcha/agentrun-harness-claude/facts";
@@ -74,6 +75,51 @@ export function npxLine(spec, env = {}, installed = installedHere) {
74
75
  const flags = [...(port && /^\d{1,5}$/.test(port) ? [`--port ${port}`] : []), ...(command && env[STARTED_OPEN_ENV] === "0" ? ["--no-open"] : []), ...(!command && env[STARTED_OPEN_ENV] === "1" ? ["--open"] : [])];
75
76
  return `npx ${yes}${packages.map((name) => `-p ${name}`).join(" ")} ${command ? "agentrun" : "agentrun-serve"}${named}${flags.map((flag) => ` ${flag}`).join("")}`;
76
77
  }
78
+ /** The first of `base`, `base-2`, `base-3`… that is not there. */
79
+ const freeName = (base, exists) => {
80
+ let name = base;
81
+ for (let n = 2; exists(name); n++)
82
+ name = `${base}-${n}`;
83
+ return name;
84
+ };
85
+ /**
86
+ * A start `npx @parcha/agentrun` made (NPX_PACKAGE_ENV) that a data directory refused because an earlier version wrote it
87
+ * (store.ts StoreFromEarlierVersion, or SchemaVersionUnknown on an earlier release's store): the refusal's own first line,
88
+ * then the two ways on as commands to paste. That command keeps its data in ~/.agentrun wherever it is run, so a new
89
+ * folder alone is not a new AgentRun. First, the old folder moved aside whole, so the same command starts this version
90
+ * where it was, and the earlier version still opens what it holds; then this version on a new, empty folder: the same
91
+ * command with --data. Nothing is deleted either way. Any other error, or a start the launcher did not
92
+ * make, is undefined: the refusal's own words stand.
93
+ */
94
+ export function earlierDataRefusal(error, data, env = {}, exists = existsSync) {
95
+ const refused = error;
96
+ const earlier = refused?.name === "StoreFromEarlierVersion" || (refused?.name === "SchemaVersionUnknown" && typeof refused.found === "number" && typeof refused.known === "number" && refused.found < refused.known);
97
+ const door = env[NPX_PACKAGE_ENV];
98
+ if (!earlier || typeof refused?.message !== "string" || door === undefined || !/^@parcha\/agentrun@\d[\w.+-]*$/.test(door))
99
+ return undefined;
100
+ const dir = resolve(data);
101
+ const yes = env.npm_config_yes === "true" ? "-y " : "";
102
+ const port = env[STARTED_PORT_ENV];
103
+ const flags = `${port && /^\d{1,5}$/.test(port) ? ` --port ${port}` : ""}${env[STARTED_OPEN_ENV] === "0" ? " --no-open" : ""}`;
104
+ const command = `npx ${yes}${door}`;
105
+ // The launcher's own folder when --data names none (agentrun start.mjs): this same command opens `dir` again with no
106
+ // --data only when `dir` is it.
107
+ const launcherData = resolve(env.HOME || homedir(), ".agentrun");
108
+ const again = `${command}${dir === launcherData ? "" : ` --data ${shellWord(dir)}`}${flags}`;
109
+ const fresh = freeName(`${dir}-new`, exists);
110
+ const aside = freeName(`${dir}-earlier`, exists);
111
+ const installed = exists(join(dir, "bin", "agentrun")) ? " Its bin/agentrun (the earlier installer's command) moves with it: run the installer again for this version's." : "";
112
+ return [
113
+ refused.message.split("\n")[0],
114
+ // Moved aside first: every later command (doctor, the harness commands, the service) then finds this version where it
115
+ // looks with nothing more to remember; a new folder means the same --data on each of them.
116
+ `To keep all of it where the earlier version still opens it and start this version in ${dir}: mv ${shellWord(dir)} ${shellWord(aside)}, then ${again}. The earlier version opens the old data with --data ${shellWord(aside)}.${installed}`,
117
+ `Or start this version on a new, empty folder: ${command} --data ${shellWord(fresh)}${flags}`,
118
+ ` (every later agentrun command then takes the same --data: without it, they open ${launcherData})`,
119
+ // The store's own refusal already says to add them again; an earlier release's schema says it only in the lines cut here.
120
+ `Either way, nothing is deleted.${refused.name === "SchemaVersionUnknown" ? " Add your agents, MCP servers, keys and sign-ins again in this version." : ""}`,
121
+ ].join("\n");
122
+ }
77
123
  /** The port the server was started on when `--port` named one, and whether `--open` was given (1 or 0): set by its CLI
78
124
  * for itself and its runs (startedWith), read by npxLine, so a hint keeps them. */
79
125
  export const STARTED_PORT_ENV = "AGENTRUN_SERVE_PORT";
@@ -8,7 +8,7 @@ export type PackageFile = {
8
8
  };
9
9
  /** What an export's note can be about: the document's enum of them (openapi.ts), so a note of a kind not here fails the
10
10
  * build, and an answer the document does not list fails its schema check. */
11
- export declare const EXPORT_NOTE_KINDS: readonly ["mcp_server", "trigger", "pin", "tool_setting", "tool_policy", "computer", "paired_computer", "sign_in", "learning", "secrets", "input_schema", "budget", "package"];
11
+ export declare const EXPORT_NOTE_KINDS: readonly ["mcp_server", "trigger", "pin", "tool_setting", "tool_policy", "computer", "paired_computer", "sign_in", "learning", "input_schema", "budget", "package"];
12
12
  /** One thing an export could not carry as it is here: what it is, which one, and why, in words. */
13
13
  export type ExportNote = {
14
14
  kind: (typeof EXPORT_NOTE_KINDS)[number];
@@ -46,8 +46,8 @@ export type ExportInput = {
46
46
  definition: Json;
47
47
  /** The revision's skill files, by path under the agent's skills folder. */
48
48
  skills: Readonly<Record<string, string>>;
49
- /** The package the agent was applied from (agentView's `template`) with the key names its apply kept (absent on a
50
- * revision applied before they were kept), and that package as this server holds it now. */
49
+ /** The package the agent was applied from (agentView's `template`) with the key names its apply kept, and that package
50
+ * as this server holds it now. */
51
51
  template: {
52
52
  id: string;
53
53
  version: string;
@@ -8,7 +8,7 @@
8
8
  import { createHash } from "node:crypto";
9
9
  import { stringify } from "yaml";
10
10
  import { LOOPBACK } from "./mcp-oauth.js";
11
- import { MANIFEST, memoryFiles, onServerNames, PackageError, readPackage } from "./templates.js";
11
+ import { INPUT_KEYS, ITEM_KEYS, MANIFEST, memoryFiles, onServerNames, PackageError, readPackage } from "./templates.js";
12
12
  import { isMcpName, isMonidName, mcpToolName, parseToolName } from "./tool-names.js";
13
13
  import { isPinKeys, permissionKeys, SHELL_FAMILY } from "./tool-gate.js";
14
14
  import { toolOf } from "./tools.js";
@@ -18,7 +18,7 @@ import { isObject, MODEL_TIER_NAMES, stable } from "./validate.js";
18
18
  import { PAIRED_ID_PREFIX } from "./workspace/attached-computers.js";
19
19
  /** What an export's note can be about: the document's enum of them (openapi.ts), so a note of a kind not here fails the
20
20
  * build, and an answer the document does not list fails its schema check. */
21
- export const EXPORT_NOTE_KINDS = ["mcp_server", "trigger", "pin", "tool_setting", "tool_policy", "computer", "paired_computer", "sign_in", "learning", "secrets", "input_schema", "budget", "package"];
21
+ export const EXPORT_NOTE_KINDS = ["mcp_server", "trigger", "pin", "tool_setting", "tool_policy", "computer", "paired_computer", "sign_in", "learning", "input_schema", "budget", "package"];
22
22
  /** The package's digest: sha256, in hex, over its files sorted by path, each written as `path NUL bytes NUL`. */
23
23
  export function packageSha256(files) {
24
24
  const hash = createHash("sha256");
@@ -37,9 +37,8 @@ const REMADE_TRIGGERS = {
37
37
  composio: "A composio trigger is made again on the target's Composio project.",
38
38
  email: "An email trigger receives at an address the target gives it: point the sender at the new one.",
39
39
  };
40
- /** The input fields' keys in the order a package writes them (templates.ts INPUT_KEYS), and a list's items'. */
41
- const FIELD_KEYS = ["type", "title", "description", "pattern", "format", "minLength", "maxLength", "minimum", "maximum", "enum", "examples", "default"];
42
- const ITEM_KEYS = ["type", "pattern", "format", "minLength", "maxLength", "minimum", "maximum", "enum"];
40
+ /** An input field's own keys, in the order a package writes them: `required` and `items` are written after them. */
41
+ const FIELD_KEYS = INPUT_KEYS.filter((key) => key !== "required" && key !== "items");
43
42
  const pick = (from, keys) => Object.fromEntries(keys.flatMap((key) => (from[key] !== undefined ? [[key, from[key]]] : [])));
44
43
  /** Each field of `value`, a part of the agent an export copies as it is, that holds a credential in the clear, as its
45
44
  * path from `at` (source.urls.0, target.input.api_key): by the walk a composio trigger's config is sealed by
@@ -71,7 +70,6 @@ export function agentPackage(input) {
71
70
  const remade = [];
72
71
  // Its name: the template's it was applied from, else the agent's own as a package name.
73
72
  const pkgName = origin?.name || (template ? slug(template.id.split(/[/:]/).at(-1) ?? "") : "") || slug(agent.name) || slug(agent.id) || "agent";
74
- const sameVersion = !!origin && !!template && origin.version === template.version;
75
73
  const settings = (isObject(definition.tool_settings) ? definition.tool_settings : {});
76
74
  // Denied as the gate reads the agent's own settings: a shell tool by bash's, then the most specific key set (the tool's
77
75
  // own, else its MCP server's or monid provider's wildcard).
@@ -287,13 +285,8 @@ export function agentPackage(input) {
287
285
  const inputs = inputSchema && inputsOf(inputSchema);
288
286
  if (inputSchema && !inputs)
289
287
  blocked.push({ kind: "input_schema", name: "inputs", reason: "Its input schema is not a closed object of fields, which is what a package's inputs are." });
290
- // The keys its package declared, as its apply kept them; for a revision applied before they were kept, the package as
291
- // this server holds it, which names them only while it is the same version.
292
- const declared = template?.secrets ?? (sameVersion ? origin.secrets : []);
293
- const secrets = [...new Set([...declared, ...((plain ?? []).some(isMonidName) ? ["MONID_API_KEY"] : [])])].sort();
294
- // Such a revision of a package updated or removed since its apply: the keys it was applied with are unknown here.
295
- if (template && !template.secrets && !sameVersion)
296
- remade.push({ kind: "secrets", name: template.id, reason: `The keys version ${template.version} of ${template.id} names are not known here: ${origin ? `this server holds version ${origin.version}` : "this server no longer holds it"}. Save the keys the agent uses on the target, and name them under secrets in ${MANIFEST}.` });
288
+ // The keys its package declared, as its apply kept them.
289
+ const secrets = [...new Set([...(template?.secrets ?? []), ...((plain ?? []).some(isMonidName) ? ["MONID_API_KEY"] : [])])].sort();
297
290
  const bash = settings.bash?.policy;
298
291
  // Bash's policy holds every shell tool, and a package writes it only beside bash: a shell tool kept without bash would
299
292
  // run there what the policy refuses here.
@@ -17,7 +17,7 @@ import { learningSettingForBody } from "./store/agent-body.js";
17
17
  import { storedHarness } from "./harness-table.js";
18
18
  import { AgentBodyInvalid, RevisionMoved, bodyOf, canonical, isObject, StoreConstraint, } from "./store/index.js";
19
19
  import { canonicalToolSettings, settingsIssues } from "./tool-plane.js";
20
- import { computerOfPlace, settingOfDefinition } from "./computer-setting.js";
20
+ import { settingOfDefinition } from "./computer-setting.js";
21
21
  import { skillIssues, skillNames } from "./validate.js";
22
22
  const ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
23
23
  /** A store refusal as the request's answer: a duplicate name (agent exists) and a constraint map the right way. */
@@ -400,6 +400,9 @@ export const etagOf = (entry) => `"${entry.revision?.id ?? "none"}"`;
400
400
  export function definitionOf(agent, revision, version) {
401
401
  const body = revision.body;
402
402
  const common = { ...(body.maxCostUsd !== undefined ? { max_cost_usd: body.maxCostUsd } : {}), ...(body.maxRequests !== undefined ? { max_requests: body.maxRequests } : {}) };
403
+ // A revision saved before the computer setting keeps its place alone; one that names neither has no computer here
404
+ // (the host's default applies).
405
+ const computer = settingOfDefinition(body)?.computer;
403
406
  const kindBody = revision.kind === "agentic"
404
407
  ? { instructions: body.instructions, ...(body.model ? { model: body.model } : {}), ...(body.modelTiers ? { model_tiers: body.modelTiers } : {}), ...(body.thinking ? { thinking: body.thinking } : {}), ...(learningSettingForBody(body) !== undefined ? { learning: learningSettingForBody(body) } : {}), ...(body.inputSchema !== undefined ? { input_schema: body.inputSchema } : {}), ...(body.outputSchema !== undefined ? { output_schema: body.outputSchema } : {}), ...(body.checkout !== undefined ? { checkout: body.checkout } : {}), ...common }
405
408
  : { workflow: body.workflow, ...common };
@@ -416,9 +419,7 @@ export function definitionOf(agent, revision, version) {
416
419
  approvals: approvalsOf(body.approvals),
417
420
  harness: harnessOfBody(body),
418
421
  ...(body.place ? { place: body.place } : {}),
419
- // A revision's computer as the API shows it: its own, else the one its place says (a revision saved before the
420
- // setting keeps its place alone); none when it names neither (the host's default applies).
421
- ...(body.computer ? { computer: body.computer } : body.place ? { computer: computerOfPlace(body.place) } : {}),
422
+ ...(computer ? { computer } : {}),
422
423
  skills: skillNames(Object.keys(body.skills ?? {})),
423
424
  tools: body.tools,
424
425
  ...(body.toolSettings ? { tool_settings: body.toolSettings } : {}),
@@ -442,7 +443,7 @@ export function agentView(entry, origin, extra = {}) {
442
443
  revisions: entry.revisions,
443
444
  source: null,
444
445
  ...(sourceSyncOf(body) ? { source_sync: { moved: true } } : {}),
445
- // The template package it was applied from (its first revision keeps it): the package's id, version and the commit an
446
+ // The package its current revision came from (packageOf): the package's id, version and the commit an
446
447
  // imported one was read at (null for a bundled one). Null for an agent made otherwise.
447
448
  template: entry.template ? { id: entry.template.id, version: entry.template.version, sha: entry.template.sha ?? null } : null,
448
449
  skills: Object.entries(body.skills ?? {}).map(([path, sha]) => ({ path, sha256: sha, size_bytes: entry.sizes.get(sha) ?? null })),
@@ -3,8 +3,9 @@ import type { Route } from "./server.js";
3
3
  /** The routes (server.ts ROUTES, by name) an API-only server serves. Past a run's own, why each group is here:
4
4
  * - a run's hosted machine fetches computerd with the token its create minted, not the server's;
5
5
  * - the computers list and the Archil settings are read before a launch, naming keys, never a value;
6
- * - an agent its inline runs made has its disk, its delete and its runs' purges sent by the backend that made it (a run
7
- * of an agent made here is refused by the purge's route itself, server.ts deleteRun, in this profile's words);
6
+ * - an agent its inline runs made has its disk, its delete and its runs' purges sent by the backend that made it. A run
7
+ * of an agent made here is purged too (deleteRun): the token may archive and delete that whole agent below, every
8
+ * run of it purged, so one run of it is no more;
8
9
  * - a run's computer, take-over, hand-back and viewer link go to the backend, which has no owner's session here;
9
10
  * - a backend reads what its agents learned (loop, promotions, cost per run, a run's learning), cut as the console's,
10
11
  * and resets it (deleteAgentLearning: the agent and its runs kept) when it erases what an agent learned;
@@ -15,8 +16,19 @@ import type { Route } from "./server.js";
15
16
  * words, template-import.ts), which an apply then makes into its agent;
16
17
  * - a backend that deploys agents here applies their template, reads the agent and its revisions, moves its current
17
18
  * revision back, and archives it before its delete (or unarchives it, the schedule and feed triggers its archive
18
- * turned off on again when the server has the launch hook): its token already makes agents through inline runs, so it
19
- * gains no new power. A trigger the apply can't make here is skipped, and said (apiOnlyTriggerSkipped). */
19
+ * turned off on again when the server has the launch hook). That is more than inline runs give its token: it makes
20
+ * agents and revisions that stay, archives and deletes any agent made here and purges any run of one, as the whole
21
+ * server's token does, and with the launch hook its apply makes schedule and feed triggers. A trigger the apply can't
22
+ * make here is skipped, and said (apiOnlyTriggerSkipped). One the agent had before the profile stays as it was:
23
+ * without the hook, an enabled one still fires here on this server's keys until the agent is archived;
24
+ * - an API-only server has no owner, so the token is the backend's own, as with take-over: it saves the Composio servers
25
+ * its agents need through the preset (saveComposioServer), saves over or deletes only a server it saved
26
+ * (mcp-secret-writes.ts tokenWriteOverRefused), and never writes a secret (secret-writes.ts). A Composio server names
27
+ * its key by api_key_env (COMPOSIO_API_KEY, on the launcher's list of secrets, read at each use through secrets.ts
28
+ * secret, sent to Composio's origin alone: composio-made.ts composioEnvKey), and its body names no address or headers.
29
+ * There is no list or read of the servers here (listMcpServerNames above is the listing), and no generic save (saveMcpServer), so the
30
+ * token saves no server at an address or with headers of its own. Previews, refreshes, sign-ins and Composio's
31
+ * triggers stay refused. */
20
32
  export declare const API_ONLY_ROUTES: ReadonlySet<string>;
21
33
  /** The trigger sources an apply on an API-only server makes once the server has the launch hook: the ones that fire on
22
34
  * its own clock and need nothing a refused route sets up. Each firing goes to the backend in front of it
package/dist/api-only.js CHANGED
@@ -1,15 +1,17 @@
1
1
  // The API-only profile (AGENTRUN_API_ONLY=1): a server that runs behind its caller's backend serves the run routes and a
2
2
  // deploy's routes alone, and refuses every other address before anything else reads the request: the console at "/" and
3
- // its assets, sign-in and setup, settings, MCP, triggers and their webhook hooks, the rest of agents and templates.
4
- // Off by default.
3
+ // its assets, sign-in and setup, settings but the MCP servers' names, a Composio server's save and the delete of a server
4
+ // (the secret-write gate lets the token save over or delete only a server it saved, mcp-secret-writes.ts), the MCP
5
+ // endpoint, triggers and their webhook hooks, the rest of agents and templates. Off by default.
5
6
  import { API_ONLY_ENV } from "./env-switch.js";
6
7
  import { NOT_SET_UP } from "./runnable.js";
7
8
  import { LAUNCH_HOOK_SECRET_ENV, LAUNCH_HOOK_URL_ENV } from "./trigger-launch-hook.js";
8
9
  /** The routes (server.ts ROUTES, by name) an API-only server serves. Past a run's own, why each group is here:
9
10
  * - a run's hosted machine fetches computerd with the token its create minted, not the server's;
10
11
  * - the computers list and the Archil settings are read before a launch, naming keys, never a value;
11
- * - an agent its inline runs made has its disk, its delete and its runs' purges sent by the backend that made it (a run
12
- * of an agent made here is refused by the purge's route itself, server.ts deleteRun, in this profile's words);
12
+ * - an agent its inline runs made has its disk, its delete and its runs' purges sent by the backend that made it. A run
13
+ * of an agent made here is purged too (deleteRun): the token may archive and delete that whole agent below, every
14
+ * run of it purged, so one run of it is no more;
13
15
  * - a run's computer, take-over, hand-back and viewer link go to the backend, which has no owner's session here;
14
16
  * - a backend reads what its agents learned (loop, promotions, cost per run, a run's learning), cut as the console's,
15
17
  * and resets it (deleteAgentLearning: the agent and its runs kept) when it erases what an agent learned;
@@ -20,12 +22,23 @@ import { LAUNCH_HOOK_SECRET_ENV, LAUNCH_HOOK_URL_ENV } from "./trigger-launch-ho
20
22
  * words, template-import.ts), which an apply then makes into its agent;
21
23
  * - a backend that deploys agents here applies their template, reads the agent and its revisions, moves its current
22
24
  * revision back, and archives it before its delete (or unarchives it, the schedule and feed triggers its archive
23
- * turned off on again when the server has the launch hook): its token already makes agents through inline runs, so it
24
- * gains no new power. A trigger the apply can't make here is skipped, and said (apiOnlyTriggerSkipped). */
25
+ * turned off on again when the server has the launch hook). That is more than inline runs give its token: it makes
26
+ * agents and revisions that stay, archives and deletes any agent made here and purges any run of one, as the whole
27
+ * server's token does, and with the launch hook its apply makes schedule and feed triggers. A trigger the apply can't
28
+ * make here is skipped, and said (apiOnlyTriggerSkipped). One the agent had before the profile stays as it was:
29
+ * without the hook, an enabled one still fires here on this server's keys until the agent is archived;
30
+ * - an API-only server has no owner, so the token is the backend's own, as with take-over: it saves the Composio servers
31
+ * its agents need through the preset (saveComposioServer), saves over or deletes only a server it saved
32
+ * (mcp-secret-writes.ts tokenWriteOverRefused), and never writes a secret (secret-writes.ts). A Composio server names
33
+ * its key by api_key_env (COMPOSIO_API_KEY, on the launcher's list of secrets, read at each use through secrets.ts
34
+ * secret, sent to Composio's origin alone: composio-made.ts composioEnvKey), and its body names no address or headers.
35
+ * There is no list or read of the servers here (listMcpServerNames above is the listing), and no generic save (saveMcpServer), so the
36
+ * token saves no server at an address or with headers of its own. Previews, refreshes, sign-ins and Composio's
37
+ * triggers stay refused. */
25
38
  export const API_ONLY_ROUTES = new Set([
26
39
  "createRun", "createInlineRun", "getComputerDaemon",
27
40
  "getRunComputer", "takeOverRunComputer", "handBackRunComputer", "createRunComputerViewer",
28
- "listComputers", "getWorkspaceArchil",
41
+ "listComputers", "listRunningComputers", "getWorkspaceArchil",
29
42
  "getAgentArchil", "deleteAgentArchil", "deleteAgent", "deleteAgentLearning", "deleteRun",
30
43
  "getLearningLoop", "listLearningPromotions", "getLearningCost", "getRunLearning",
31
44
  "getRun", "getRunUsage", "listRuns", "listAllRuns", "getTimeline",
@@ -34,6 +47,7 @@ export const API_ONLY_ROUTES = new Set([
34
47
  "createFile", "listFiles", "getFile", "uploadFile", "deleteFile",
35
48
  "getCapabilities", "getHealth", "getUsage", "getCapacity", "listMcpServerNames",
36
49
  "importTemplate", "applyTemplate", "getAgent", "listRevisions", "setCurrent", "archiveAgent", "unarchiveAgent",
50
+ "saveComposioServer", "deleteMcpServer",
37
51
  ]);
38
52
  /** The trigger sources an apply on an API-only server makes once the server has the launch hook: the ones that fire on
39
53
  * its own clock and need nothing a refused route sets up. Each firing goes to the backend in front of it
package/dist/cli.js CHANGED
@@ -573,7 +573,7 @@ catch (error) {
573
573
  }
574
574
  if (early)
575
575
  console.log(`Starting ${publicUrl ?? urlOf(early, values.listen ?? DEFAULT_HOST)}/ (warming: health says so and the API answers 503 until the server is ready)`);
576
- const [{ fauxEnvOf, startServe }, { besideRunnerOptions, besideStopping, runnerBeside }, { startedWith }, { canOpen }] = await Promise.all([import("./server.js"), import("./runner/beside.js"), import("./adapters.js"), import("./host.js")]);
576
+ const [{ fauxEnvOf, startServe }, { besideRunnerOptions, besideStopping, runnerBeside }, { earlierDataRefusal, startedWith }, { canOpen }] = await Promise.all([import("./server.js"), import("./runner/beside.js"), import("./adapters.js"), import("./host.js")]);
577
577
  // How it was started, for the hints that start it again (adapters.ts npxLine): itself and its runs read it.
578
578
  Object.assign(process.env, startedWith({ ...(values.port !== undefined ? { port: values.port } : {}), open: values.open === true }));
579
579
  let serve;
@@ -611,7 +611,9 @@ try {
611
611
  });
612
612
  }
613
613
  catch (error) {
614
- console.error(`agentrun-serve: ${error.message}`);
614
+ // A data directory an earlier version wrote, refused on a start `npx @parcha/agentrun` made: the ways on as that command
615
+ // (adapters.ts earlierDataRefusal). Any other start keeps the refusal's own words.
616
+ console.error(`agentrun-serve: ${earlierDataRefusal(error, data, process.env) ?? error.message}`);
615
617
  process.exit(1);
616
618
  }
617
619
  // The start launches one runner beside the server on the same data dir (design: "server and runner"): it claims and runs
@@ -638,7 +640,7 @@ if (!values["no-runner"] && askedAt === undefined) {
638
640
  // separate runners refuse it in words). Its runs reach an MCP server on loopback only when this server is a local
639
641
  // install (Serve.localInstall).
640
642
  // Each run a process of its own, as a user of its own where the image's helper can switch (run-child-host.ts).
641
- runnerProc = await runnerBeside(data, { loops, loopsTold, drainMs, env: besideRunEnv(process.env, fauxEnvOf(serveOptions)), janitor: true, ownProcesses: true, hub: serve.attachHub, dial: serve.dial, mcpLoopback: serve.localInstall, mcpOwn: serve.own, onRunEnded: telemetry.runEnded });
643
+ runnerProc = await runnerBeside(data, { loops, loopsTold, drainMs, env: besideRunEnv(process.env, fauxEnvOf(serveOptions)), janitor: true, ownProcesses: true, hub: serve.attachHub, dial: serve.dial, mcpLoopback: serve.localInstall, mcpOwn: serve.own, ollamaHost: serve.ollamaHost, onRunEnded: telemetry.runEnded });
642
644
  }
643
645
  catch (error) {
644
646
  // A run isolation the runner cannot give (run-child-host.ts runIsolationOf) is said, and the server serves on with no
@@ -8,7 +8,8 @@ export type Made = {
8
8
  * under it. `per_run`: saved with `user_id: "per_run"` (COMPOSIO_PER_RUN), its address names no user and no account,
9
9
  * and each run names its own (mcp_auth, composioPerRun); `user` is then that word and `accounts` empty. Only a save made
10
10
  * since the mode exists writes it, so a server saved before for a Composio user literally named "per_run" keeps that
11
- * user until it is saved again. */
11
+ * user until it is saved again. `key_env`: saved with `api_key_env`, its key is the value of this variable the server and
12
+ * each runner were started with, read at each use, and its row seals no credential (composioKeyFromEnv). */
12
13
  export type ComposioMade = {
13
14
  user: string;
14
15
  auth_config: (Made & {
@@ -16,7 +17,14 @@ export type ComposioMade = {
16
17
  }) | null;
17
18
  accounts: Made[];
18
19
  per_run?: true;
20
+ key_env?: typeof COMPOSIO_KEY_ENV;
19
21
  };
22
+ /** The one variable a Composio save may name for its key (`api_key_env`). Composio's host is fixed in code, so no other
23
+ * secret of the server's environment is ever sent there. */
24
+ export declare const COMPOSIO_KEY_ENV = "COMPOSIO_API_KEY";
25
+ /** Composio's origin: its API's base (composio-preset.ts) and where its MCP servers are (a preset save's address). The one
26
+ * place a key read from the environment is ever sent. */
27
+ export declare const COMPOSIO_ORIGIN = "https://backend.composio.dev";
20
28
  /** What a delete does at Composio beyond the MCP server: what it removes, in order (the accounts before the auth config
21
29
  * they are under), and what it keeps, each with whose it stays (`by`: the saved server that uses it too; none: this
22
30
  * server didn't make it). */
@@ -52,6 +60,23 @@ export declare const composioPerRun: (row: {
52
60
  * saved before over this row (`was`) or of another saved server (`others`) says was made here stays made here; and the
53
61
  * accounts the server saved before had made, under the same auth config and user, stay its own. */
54
62
  export declare function madeToWrite(found: ComposioMade, was: ComposioMade | undefined, others: readonly ComposioMade[]): ComposioMade;
63
+ /** The value of `name`, a server's key variable (ComposioMade.key_env), as this process (the server, or a runner) was
64
+ * handed it at its start: over the launcher's pipe, so its environment never holds it (secrets.ts secret; the launcher
65
+ * names it among its secrets). Trimmed; none when unset, blank or longer than any key. Read at each use, never kept. */
66
+ export declare function composioKeyFromEnv(name?: typeof COMPOSIO_KEY_ENV): string | undefined;
67
+ /** Why the server `server`, which reads its key from `name`, can't be used now: the variable is unset. */
68
+ export declare const composioKeyUnset: (server: string, name?: string) => string;
69
+ /** The key the server `server` (its address `url`) reads from `name`, its record's key_env, for a request to that address:
70
+ * the variable's value as this process was started with it (composioKeyFromEnv), only while the address is on Composio's origin (`origin`, COMPOSIO_ORIGIN; a test's fake
71
+ * through the server's and runner's seam). Otherwise why not, in words, and the caller sends nothing: `not_allowed`, an
72
+ * address no preset save writes (a row written by hand); `missing`, the variable unset. Every read of such a key for a
73
+ * request to the server's address goes through here: a save's and a refresh's listing, a run's start, a claim. */
74
+ export declare function composioEnvKey(server: string, url: string, name: typeof COMPOSIO_KEY_ENV, origin?: string): {
75
+ key: string;
76
+ } | {
77
+ refused: string;
78
+ reason: "not_allowed" | "missing";
79
+ };
55
80
  /** The records of the other saved servers (`others`, by name) that say they made the auth config `id`, each as it is to
56
81
  * be written once the owner named that config in a save: made by none of them, so none of their deletes removes it. */
57
82
  export declare function releasedOf(id: string, others: readonly (readonly [string, ComposioMade, ...unknown[]])[]): [string, ComposioMade][];
@@ -9,7 +9,14 @@
9
9
  // same with what the record it replaces made that the new one no longer stands on (droppedOf). An auth config the owner
10
10
  // names in a save (auth_config_id) is the owner's from that save on, whoever made it: the record written says it was not
11
11
  // made here, and every other record's claim to have made it is let go (releasedOf), so no delete or save removes it.
12
+ import { secret } from "./secrets.js";
12
13
  import { isObject } from "./validate.js";
14
+ /** The one variable a Composio save may name for its key (`api_key_env`). Composio's host is fixed in code, so no other
15
+ * secret of the server's environment is ever sent there. */
16
+ export const COMPOSIO_KEY_ENV = "COMPOSIO_API_KEY";
17
+ /** Composio's origin: its API's base (composio-preset.ts) and where its MCP servers are (a preset save's address). The one
18
+ * place a key read from the environment is ever sent. */
19
+ export const COMPOSIO_ORIGIN = "https://backend.composio.dev";
13
20
  /** The store.settings key a server's record lives under. */
14
21
  export const composioMadeKey = (name) => `mcp.composio/${name}`;
15
22
  /** The settings value a record is stored as, bound to the server row it was written for. */
@@ -25,7 +32,7 @@ export function recordedMade(value, createdAt) {
25
32
  const accounts = value.accounts.map(thingOf);
26
33
  if (config === undefined || accounts.some((account) => !account))
27
34
  return undefined;
28
- return { user: value.user, auth_config: config, accounts: accounts, ...(value.per_run === true ? { per_run: true } : {}) };
35
+ return { user: value.user, auth_config: config, accounts: accounts, ...(value.per_run === true ? { per_run: true } : {}), ...(value.key_env === COMPOSIO_KEY_ENV ? { key_env: COMPOSIO_KEY_ENV } : {}) };
29
36
  }
30
37
  /** Whether the saved server `row` is a per-run Composio server: auth headers (the install's sealed key) and its own
31
38
  * record (`recorded`, read at composioMadeKey) saying per_run. Its runs call it as the Composio user and account each
@@ -44,7 +51,37 @@ export function madeToWrite(found, was, others) {
44
51
  const config = found.auth_config && { id: found.auth_config.id, made: !found.auth_config.named && (found.auth_config.made || madeHere(found.auth_config.id)) };
45
52
  const accounts = found.accounts.map((a) => ({ id: a.id, made: a.made || madeHere(a.id) }));
46
53
  const kept = was && sharesAccounts(found, was) ? was.accounts.filter((a) => a.made && !accounts.some((b) => b.id === a.id)) : [];
47
- return { user: found.user, auth_config: config, accounts: [...accounts, ...kept], ...(found.per_run ? { per_run: true } : {}) };
54
+ return { user: found.user, auth_config: config, accounts: [...accounts, ...kept], ...(found.per_run ? { per_run: true } : {}), ...(found.key_env ? { key_env: found.key_env } : {}) };
55
+ }
56
+ /** The value of `name`, a server's key variable (ComposioMade.key_env), as this process (the server, or a runner) was
57
+ * handed it at its start: over the launcher's pipe, so its environment never holds it (secrets.ts secret; the launcher
58
+ * names it among its secrets). Trimmed; none when unset, blank or longer than any key. Read at each use, never kept. */
59
+ export function composioKeyFromEnv(name = COMPOSIO_KEY_ENV) {
60
+ const value = secret(name)?.trim();
61
+ return value && value.length <= 8192 ? value : undefined;
62
+ }
63
+ /** Why the server `server`, which reads its key from `name`, can't be used now: the variable is unset. */
64
+ export const composioKeyUnset = (server, name = COMPOSIO_KEY_ENV) => `The MCP server ${server} reads its Composio key from the environment variable ${name}, which is not set: set it where AgentRun runs, then try again.`;
65
+ /** Why the server `server`, which reads its key from `name`, is never sent it: its address is not on Composio's origin. */
66
+ const composioKeyOffOrigin = (server, url, name, origin) => `The MCP server ${server} reads its Composio key from the environment variable ${name}, and its address (${originOf(url)}) is not Composio's (${origin}): that key is only ever sent to Composio. Save it again with the Composio preset.`;
67
+ const originOf = (url) => {
68
+ try {
69
+ return new URL(url).origin;
70
+ }
71
+ catch {
72
+ return "not a URL";
73
+ }
74
+ };
75
+ /** The key the server `server` (its address `url`) reads from `name`, its record's key_env, for a request to that address:
76
+ * the variable's value as this process was started with it (composioKeyFromEnv), only while the address is on Composio's origin (`origin`, COMPOSIO_ORIGIN; a test's fake
77
+ * through the server's and runner's seam). Otherwise why not, in words, and the caller sends nothing: `not_allowed`, an
78
+ * address no preset save writes (a row written by hand); `missing`, the variable unset. Every read of such a key for a
79
+ * request to the server's address goes through here: a save's and a refresh's listing, a run's start, a claim. */
80
+ export function composioEnvKey(server, url, name, origin = COMPOSIO_ORIGIN) {
81
+ if (originOf(url) !== new URL(origin).origin)
82
+ return { refused: composioKeyOffOrigin(server, url, name, origin), reason: "not_allowed" };
83
+ const key = composioKeyFromEnv(name);
84
+ return key ? { key } : { refused: composioKeyUnset(server, name), reason: "missing" };
48
85
  }
49
86
  /** The records of the other saved servers (`others`, by name) that say they made the auth config `id`, each as it is to
50
87
  * be written once the owner named that config in a save: made by none of them, so none of their deletes removes it. */
@@ -1,4 +1,4 @@
1
- import type { Cleanup, ComposioMade } from "./composio-made.js";
1
+ import { type Cleanup, type ComposioMade } from "./composio-made.js";
2
2
  import { type InputIssue } from "./errors.js";
3
3
  import { type Json } from "./validate.js";
4
4
  /** Another Composio than the real one, and its fetch: a test's fake (the same seam as `archilControl`). */
@@ -66,7 +66,8 @@ export declare const composioRunQuery: (binding: {
66
66
  * the owner has, a custom OAuth app's say: read first, and refused unless it is this toolkit's and enabled), else the
67
67
  * toolkit's Composio-managed one, found or made. `save` gets what the server stands on there too (`stands`,
68
68
  * composio-made.ts): the auth config found or made and the account found or started, each marked whether this save made
69
- * it, for its delete to remove what was made. */
69
+ * it, for its delete to remove what was made. The key is the body's `api_key`, or COMPOSIO_API_KEY's value when the body
70
+ * sends `api_key_env` (head): then `stands.key_env` names it, and the store seals no credential. */
70
71
  export declare function composioSave<T extends {
71
72
  tools?: readonly {
72
73
  name: string;
@@ -4,13 +4,18 @@
4
4
  // adapter, no auth type, no key row of its own: after the save a Composio server is a saved MCP server, gated and
5
5
  // metered like every other. The four meta tools Composio adds (serve/src/mcp-meta.ts) stay refused; the helper actions
6
6
  // that connect an account are left off the server's address. The key goes only to Composio and into the sealed header: it
7
- // is never logged, echoed or put in an error.
7
+ // is never logged, echoed or put in an error. A save may name it instead by a variable of the server's environment
8
+ // (`api_key_env`, COMPOSIO_API_KEY only, a secret the launcher hands the server and each runner over its pipe): the server
9
+ // then keeps the name, seals nothing, and reads the value at each use (composio-made.ts composioKeyFromEnv).
8
10
  import { randomBytes } from "node:crypto";
11
+ import { COMPOSIO_KEY_ENV, COMPOSIO_ORIGIN, composioKeyFromEnv } from "./composio-made.js";
9
12
  import { ApiError, invalid } from "./errors.js";
10
13
  import { priceValid } from "./mcp-probe.js";
11
14
  import { MCP_SERVER_NAME } from "./tool-names.js";
12
- import { isObject } from "./validate.js";
13
- const BASE = "https://backend.composio.dev";
15
+ import { isObject, unknownFields } from "./validate.js";
16
+ const BASE = COMPOSIO_ORIGIN;
17
+ /** The fields a Composio save takes (composioSave): no `url`, no `headers`. */
18
+ const SAVE_FIELDS = ["api_key", "api_key_env", "toolkit", "tools", "user_id", "auth_config_id", "price_usd"];
14
19
  /** The one Composio user a server's actions run as, unless the owner names another. */
15
20
  export const COMPOSIO_USER = "agentrun";
16
21
  /** A Composio toolkit's slug, as a save takes it once trimmed and lower-cased. */
@@ -93,20 +98,38 @@ export function asking(control, key, signal, outcome = "nothing was saved", seal
93
98
  throw new ApiError("upstream_failed", `Composio failed while ${step} (${res.status}): ${outcome}.`);
94
99
  };
95
100
  }
96
- /** The key and toolkit of a body, checked. */
97
- function head(body) {
101
+ /** The key and toolkit of a body, checked. The key is the body's `api_key`, or, where `keyEnv` is taken (a save), the value
102
+ * of the variable its `api_key_env` names: COMPOSIO_KEY_ENV only, so no other secret of the server's environment is sent
103
+ * to Composio. `keyEnv` in the answer: the key came from there. */
104
+ function head(body, { keyEnv = false } = {}) {
98
105
  if (!isObject(body))
99
- throw invalid([issue("body", "invalid", "The body is {api_key, toolkit}.")]);
100
- const key = typeof body.api_key === "string" ? body.api_key.trim() : "";
106
+ throw invalid([issue("body", "invalid", `The body is {${keyEnv ? "api_key or api_key_env" : "api_key"}, toolkit}.`)]);
101
107
  const toolkit = typeof body.toolkit === "string" ? body.toolkit.trim().toLowerCase() : "";
102
108
  const issues = [];
103
- if (!key || key.length > 8192)
104
- issues.push(issue("api_key", "missing", "Send your Composio API key."));
109
+ let key = "";
110
+ let named;
111
+ if (keyEnv && body.api_key_env !== undefined) {
112
+ if (body.api_key !== undefined)
113
+ issues.push(issue("api_key_env", "not_allowed", "Send api_key or api_key_env, not both."));
114
+ else if (body.api_key_env !== COMPOSIO_KEY_ENV)
115
+ issues.push(issue("api_key_env", "invalid", `api_key_env names the variable the key is read from, and only ${COMPOSIO_KEY_ENV} is taken.`));
116
+ else {
117
+ named = COMPOSIO_KEY_ENV;
118
+ key = composioKeyFromEnv(named) ?? "";
119
+ if (!key)
120
+ issues.push(issue("api_key_env", "missing", `${COMPOSIO_KEY_ENV} is not set where AgentRun runs: set it to your Composio API key, then save again.`));
121
+ }
122
+ }
123
+ else {
124
+ key = typeof body.api_key === "string" ? body.api_key.trim() : "";
125
+ if (!key || key.length > 8192)
126
+ issues.push(issue("api_key", "missing", keyEnv ? `Send your Composio API key, or api_key_env: "${COMPOSIO_KEY_ENV}" to read it from the server's environment.` : "Send your Composio API key."));
127
+ }
105
128
  if (!TOOLKIT.test(toolkit))
106
129
  issues.push(issue("toolkit", "invalid", "Send the toolkit's slug as Composio names it (github, slack, gmail...)."));
107
130
  if (issues.length)
108
131
  throw invalid(issues);
109
- return { key, toolkit, rest: body };
132
+ return { key, toolkit, rest: body, ...(named ? { keyEnv: named } : {}) };
110
133
  }
111
134
  /** Whether a toolkit needs no sign-in. Composio's answer for one toolkit has no `no_auth` field (only its toolkit list
112
135
  * does): it says so as every auth mode in `auth_config_details` being NO_AUTH. */
@@ -187,9 +210,17 @@ export const composioRunQuery = (binding) => ({ [ADDRESS_USER]: binding.user_id,
187
210
  * the owner has, a custom OAuth app's say: read first, and refused unless it is this toolkit's and enabled), else the
188
211
  * toolkit's Composio-managed one, found or made. `save` gets what the server stands on there too (`stands`,
189
212
  * composio-made.ts): the auth config found or made and the account found or started, each marked whether this save made
190
- * it, for its delete to remove what was made. */
213
+ * it, for its delete to remove what was made. The key is the body's `api_key`, or COMPOSIO_API_KEY's value when the body
214
+ * sends `api_key_env` (head): then `stands.key_env` names it, and the store seals no credential. */
191
215
  export async function composioSave(body, control, save, name, signal, savedUrl) {
192
- const { key, toolkit, rest } = head(body);
216
+ // No address and no headers of the caller's own: Composio makes the server and answers its address, and the key is the
217
+ // one header sent. Any field the save does not take is refused before anything is sent, never ignored.
218
+ if (isObject(body)) {
219
+ const extra = unknownFields(body, SAVE_FIELDS);
220
+ if (extra.length)
221
+ throw invalid(extra);
222
+ }
223
+ const { key, toolkit, rest, keyEnv } = head(body, { keyEnv: true });
193
224
  const tools = Array.isArray(rest.tools) ? rest.tools : [];
194
225
  const user = rest.user_id === undefined ? COMPOSIO_USER : typeof rest.user_id === "string" ? rest.user_id : "";
195
226
  const price = rest.price_usd;
@@ -294,8 +325,9 @@ export async function composioSave(body, control, save, name, signal, savedUrl)
294
325
  }
295
326
  }
296
327
  }
297
- // One the owner named is theirs (`named`): never recorded as made here, whoever made it (composio-made.ts).
298
- const stands = { user, auth_config: authConfig ? { id: authConfig, made: madeConfig, ...(ownConfig ? { named: true } : {}) } : null, accounts, ...(perRun ? { per_run: true } : {}) };
328
+ // One the owner named is theirs (`named`): never recorded as made here, whoever made it (composio-made.ts). A key read
329
+ // from the environment (`key_env`): the save lists the tools with it, and the store keeps the variable's name alone.
330
+ const stands = { user, auth_config: authConfig ? { id: authConfig, made: madeConfig, ...(ownConfig ? { named: true } : {}) } : null, accounts, ...(perRun ? { per_run: true } : {}), ...(keyEnv ? { key_env: keyEnv } : {}) };
299
331
  url = composioAddress(address, perRun);
300
332
  // Saved as what it is, a Composio server of this toolkit: a template that needs the toolkit maps to it, whatever its
301
333
  // name. A slug no template can name (mcp:<toolkit>/<tool>: no `_`) is saved as a Composio server of no toolkit.
@@ -12,7 +12,7 @@
12
12
  import { callComputer, callIssues, sendRow, TAKE_MS } from "./computer-channel.js";
13
13
  import { computerHoldOf, entriesOf, runOver } from "./computer-commands.js";
14
14
  import { COMPUTER_RELEASE, COMPUTER_START, heldIn, holdIssues } from "./computer-held.js";
15
- import { computerOfPlace } from "./computer-setting.js";
15
+ import { settingOfDefinition } from "./computer-setting.js";
16
16
  import { ApiError, invalid } from "./errors.js";
17
17
  import { runComputerField } from "./run-computer.js";
18
18
  import { readLaunchBody } from "./run-launch.js";
@@ -43,8 +43,7 @@ export async function heldField(store, runId, options = {}) {
43
43
  * read at most once, and not at all for a run that neither can be taken over nor holds. `view` is the run read so far. */
44
44
  export async function runComputerRead(store, runId, view, options = {}) {
45
45
  const run = await store.runs.get(runId);
46
- const body = run ? (await store.agents.revision(run.revisionId))?.body : undefined;
47
- const setting = body?.computer ?? (body?.place ? computerOfPlace(body.place) : undefined);
46
+ const setting = run ? settingOfDefinition(((await store.agents.revision(run.revisionId))?.body ?? {}))?.computer : undefined;
48
47
  if (!setting)
49
48
  return {};
50
49
  const error = view.error;
@@ -73,10 +73,12 @@ export declare const sameComputer: (a: ComputerSetting, b: ComputerSetting) => b
73
73
  export declare function computerIssues(value: unknown, field: string): InputIssue[];
74
74
  /** The setting and its place a definition says, from `computer` or `place` (both: they must agree), or undefined when
75
75
  * it says neither. Each is checked already (computerIssues, placeIssues). */
76
- export declare function settingOfDefinition(definition: {
76
+ /** What settingOfDefinition reads of a definition or a stored revision body. */
77
+ export type Definition = {
77
78
  computer?: unknown;
78
79
  place?: unknown;
79
- }): {
80
+ };
81
+ export declare function settingOfDefinition(definition: Definition): {
80
82
  computer: ComputerSetting;
81
83
  place: PlaceView;
82
84
  } | undefined;
@@ -155,8 +155,6 @@ function persistenceIssues(kind, provider, image, field) {
155
155
  fix: `Remove ${field}, or pick a computer that keeps one (GET /v2/computers shows which do).`,
156
156
  }];
157
157
  }
158
- /** The setting and its place a definition says, from `computer` or `place` (both: they must agree), or undefined when
159
- * it says neither. Each is checked already (computerIssues, placeIssues). */
160
158
  export function settingOfDefinition(definition) {
161
159
  if (isObject(definition.computer)) {
162
160
  const computer = definition.computer;