@parcha/agentrun-serve 0.1.0-beta.46 → 0.1.0-beta.48

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 (292) hide show
  1. package/CHANGELOG.md +211 -1
  2. package/NOTICE +4 -0
  3. package/README.md +350 -53
  4. package/dist/acp-package.d.ts +53 -6
  5. package/dist/acp-package.js +3 -3
  6. package/dist/adapter-facts.d.ts +3 -4
  7. package/dist/adapter-facts.js +4 -4
  8. package/dist/adapters.d.ts +3 -5
  9. package/dist/adapters.js +1 -31
  10. package/dist/agents-store.d.ts +5 -3
  11. package/dist/agents-store.js +13 -8
  12. package/dist/answer-json.d.ts +10 -0
  13. package/dist/answer-json.js +24 -0
  14. package/dist/api-only.d.ts +11 -11
  15. package/dist/api-only.js +16 -11
  16. package/dist/archil-routes.js +2 -1
  17. package/dist/browser-live.d.ts +9 -4
  18. package/dist/browser-live.js +18 -5
  19. package/dist/cap.js +10 -2
  20. package/dist/chatgpt-plan.js +2 -1
  21. package/dist/cli.js +109 -41
  22. package/dist/composio-made.d.ts +19 -2
  23. package/dist/composio-made.js +17 -5
  24. package/dist/composio-preset.d.ts +42 -7
  25. package/dist/composio-preset.js +106 -70
  26. package/dist/composio-triggers.d.ts +9 -4
  27. package/dist/composio-triggers.js +20 -13
  28. package/dist/computer-attach.d.ts +11 -10
  29. package/dist/computer-attach.js +13 -14
  30. package/dist/computer-commands.d.ts +3 -0
  31. package/dist/computer-commands.js +3 -2
  32. package/dist/computer-lost.d.ts +4 -0
  33. package/dist/computer-lost.js +8 -3
  34. package/dist/computer-routes.d.ts +8 -5
  35. package/dist/computer-routes.js +7 -5
  36. package/dist/computer-setting.d.ts +2 -0
  37. package/dist/computer-setting.js +2 -0
  38. package/dist/computers.d.ts +14 -76
  39. package/dist/computers.js +24 -68
  40. package/dist/conformance.d.ts +4 -0
  41. package/dist/conformance.js +6 -0
  42. package/dist/console/assets/index-CTGegcKt.css +1 -0
  43. package/dist/console/assets/index-D1Se6mgG.js +715 -0
  44. package/dist/console/index.html +2 -2
  45. package/dist/cost-heal.d.ts +13 -0
  46. package/dist/cost-heal.js +27 -0
  47. package/dist/dial-relay.d.ts +6 -2
  48. package/dist/dial-relay.js +9 -12
  49. package/dist/email/routes.js +2 -1
  50. package/dist/errors.d.ts +2 -0
  51. package/dist/errors.js +5 -0
  52. package/dist/exa-keyless.d.ts +1 -1
  53. package/dist/exa-keyless.js +1 -1
  54. package/dist/faux-computers.d.ts +2 -3
  55. package/dist/faux-computers.js +9 -31
  56. package/dist/github-connection.js +2 -1
  57. package/dist/harness-archive.d.ts +19 -2
  58. package/dist/harness-archive.js +49 -15
  59. package/dist/harness-check.d.ts +75 -0
  60. package/dist/harness-check.js +518 -0
  61. package/dist/harness-cursor.d.ts +28 -0
  62. package/dist/harness-cursor.js +42 -0
  63. package/dist/harness-goose.d.ts +4 -29
  64. package/dist/harness-goose.js +6 -86
  65. package/dist/harness-module.d.ts +4 -0
  66. package/dist/harness-module.js +1 -0
  67. package/dist/harness-owned.d.ts +52 -0
  68. package/dist/harness-owned.js +92 -0
  69. package/dist/harness-recipe.d.ts +127 -0
  70. package/dist/harness-recipe.js +335 -0
  71. package/dist/harness-table.d.ts +120 -5
  72. package/dist/harness-table.js +280 -6
  73. package/dist/harness.d.ts +2 -0
  74. package/dist/harness.js +5 -4
  75. package/dist/host-check.d.ts +6 -0
  76. package/dist/host-check.js +14 -0
  77. package/dist/host.d.ts +10 -3
  78. package/dist/host.js +17 -3
  79. package/dist/import-sources.d.ts +2 -0
  80. package/dist/import-sources.js +2 -0
  81. package/dist/import-summary.d.ts +15 -5
  82. package/dist/import-summary.js +24 -8
  83. package/dist/import.d.ts +24 -4
  84. package/dist/import.js +108 -26
  85. package/dist/key-refusal.d.ts +3 -1
  86. package/dist/key-refusal.js +26 -5
  87. package/dist/key-words.d.ts +1 -1
  88. package/dist/key-words.js +4 -4
  89. package/dist/learn/check.d.ts +3 -0
  90. package/dist/learn/check.js +31 -20
  91. package/dist/learn/compile.js +12 -5
  92. package/dist/learn/promote.d.ts +80 -2
  93. package/dist/learn/promote.js +95 -3
  94. package/dist/learn/secrets.d.ts +4 -0
  95. package/dist/learn/secrets.js +23 -0
  96. package/dist/learned-nodes.d.ts +4 -3
  97. package/dist/learned-workflow.js +4 -1
  98. package/dist/learning-cost.d.ts +6 -16
  99. package/dist/learning-cost.js +6 -12
  100. package/dist/learning-model.d.ts +18 -0
  101. package/dist/learning-model.js +77 -0
  102. package/dist/learning-words.d.ts +2 -0
  103. package/dist/learning-words.js +1 -1
  104. package/dist/listen-first.d.ts +10 -0
  105. package/dist/listen-first.js +25 -1
  106. package/dist/llms.txt +2 -1
  107. package/dist/mcp-gateway.d.ts +2 -1
  108. package/dist/mcp-gateway.js +31 -15
  109. package/dist/mcp-probe.d.ts +18 -6
  110. package/dist/mcp-probe.js +41 -8
  111. package/dist/mcp-secret-writes.d.ts +8 -0
  112. package/dist/mcp-secret-writes.js +104 -4
  113. package/dist/mcp-servers-store.d.ts +11 -5
  114. package/dist/mcp-servers-store.js +46 -20
  115. package/dist/model-form.d.ts +2 -1
  116. package/dist/model-form.js +30 -16
  117. package/dist/model-gateway.d.ts +113 -0
  118. package/dist/model-gateway.js +433 -0
  119. package/dist/model.d.ts +5 -3
  120. package/dist/model.js +26 -18
  121. package/dist/monid.js +1 -1
  122. package/dist/native/binding.d.ts +4 -0
  123. package/dist/native/binding.js +9 -0
  124. package/dist/native/cli.d.ts +3 -2
  125. package/dist/native/cli.js +6 -5
  126. package/dist/openapi.d.ts +2 -0
  127. package/dist/openapi.js +356 -43
  128. package/dist/owner.d.ts +4 -2
  129. package/dist/owner.js +10 -4
  130. package/dist/page.d.ts +9 -0
  131. package/dist/page.js +10 -2
  132. package/dist/port-models.js +17 -10
  133. package/dist/provider.d.ts +3 -3
  134. package/dist/provider.js +12 -3
  135. package/dist/public-address.d.ts +28 -0
  136. package/dist/public-address.js +62 -0
  137. package/dist/run-launch.d.ts +1 -1
  138. package/dist/run-launch.js +1 -1
  139. package/dist/run-secrets.d.ts +3 -2
  140. package/dist/run-secrets.js +7 -4
  141. package/dist/run-trace.js +6 -3
  142. package/dist/runner/adapter-loop.d.ts +14 -8
  143. package/dist/runner/adapter-loop.js +58 -24
  144. package/dist/runner/adapter-run-spec.d.ts +15 -2
  145. package/dist/runner/adapter-run-spec.js +48 -10
  146. package/dist/runner/adapters/index.d.ts +4 -2
  147. package/dist/runner/adapters/index.js +6 -26
  148. package/dist/runner/adapters/pi.d.ts +5 -2
  149. package/dist/runner/adapters/pi.js +7 -4
  150. package/dist/runner/audit.d.ts +7 -0
  151. package/dist/runner/audit.js +15 -6
  152. package/dist/runner/claim-secrets.js +5 -1
  153. package/dist/runner/cli-run-spec.js +22 -10
  154. package/dist/runner/compare-end.d.ts +43 -0
  155. package/dist/runner/compare-end.js +95 -0
  156. package/dist/runner/computer-journal.d.ts +3 -0
  157. package/dist/runner/computer-journal.js +22 -2
  158. package/dist/runner/conformance/host-tools.d.ts +4 -0
  159. package/dist/runner/conformance/host-tools.js +14 -0
  160. package/dist/runner/harness-loops.d.ts +6 -1
  161. package/dist/runner/harness-loops.js +94 -54
  162. package/dist/runner/held.d.ts +5 -4
  163. package/dist/runner/journal-kinds.d.ts +4 -1
  164. package/dist/runner/journal-kinds.js +3 -0
  165. package/dist/runner/loop-contract.d.ts +10 -0
  166. package/dist/runner/main.d.ts +5 -5
  167. package/dist/runner/main.js +62 -11
  168. package/dist/runner/mcp-claim.js +40 -12
  169. package/dist/runner/meta-tools.js +4 -2
  170. package/dist/runner/metrics.d.ts +26 -0
  171. package/dist/runner/metrics.js +44 -1
  172. package/dist/runner/presence.d.ts +44 -0
  173. package/dist/runner/presence.js +96 -0
  174. package/dist/runner/promotion.d.ts +70 -7
  175. package/dist/runner/promotion.js +178 -28
  176. package/dist/runner/run-child-host.js +40 -10
  177. package/dist/runner/runner.d.ts +5 -0
  178. package/dist/runner/runner.js +8 -0
  179. package/dist/runner/sdk-loop.js +25 -1
  180. package/dist/runner/store-port.d.ts +3 -0
  181. package/dist/runner/store-secrets.js +19 -7
  182. package/dist/runner/workflow-first.d.ts +5 -2
  183. package/dist/runner/workflow-first.js +6 -3
  184. package/dist/runner/workflow-spec.js +3 -2
  185. package/dist/runs-over-store.d.ts +7 -2
  186. package/dist/runs-over-store.js +12 -4
  187. package/dist/sdk/check.d.ts +31 -0
  188. package/dist/sdk/check.js +58 -0
  189. package/dist/sdk/runs.d.ts +11 -3
  190. package/dist/sdk/runs.js +90 -15
  191. package/dist/sdk/schema.js +12 -4
  192. package/dist/secret-writes.d.ts +16 -3
  193. package/dist/secret-writes.js +28 -3
  194. package/dist/server-secrets-store.js +5 -0
  195. package/dist/server.d.ts +34 -2
  196. package/dist/server.js +437 -90
  197. package/dist/sign-ins-secrets.js +4 -1
  198. package/dist/skills/agentrun-serve/SKILL.md +11 -0
  199. package/dist/slack-url.d.ts +5 -0
  200. package/dist/slack-url.js +11 -0
  201. package/dist/slack.d.ts +107 -0
  202. package/dist/slack.js +292 -0
  203. package/dist/start-switches.d.ts +28 -0
  204. package/dist/start-switches.js +37 -0
  205. package/dist/stats.d.ts +1 -1
  206. package/dist/stats.js +2 -1
  207. package/dist/stop-signals.d.ts +11 -0
  208. package/dist/stop-signals.js +22 -0
  209. package/dist/store/agent-body.d.ts +1 -1
  210. package/dist/store/agent-body.js +2 -2
  211. package/dist/store/index.d.ts +3 -3
  212. package/dist/store/index.js +1 -1
  213. package/dist/store/postgres/migrations/0020_runners.sql +18 -0
  214. package/dist/store/postgres/store.d.ts +1 -1
  215. package/dist/store/postgres/store.js +4 -2
  216. package/dist/store/schema.d.ts +13 -5
  217. package/dist/store/schema.js +20 -11
  218. package/dist/store/seal.d.ts +16 -4
  219. package/dist/store/sqlite/store.d.ts +1 -1
  220. package/dist/store/sqlite/store.js +112 -28
  221. package/dist/store/store.d.ts +78 -24
  222. package/dist/store/store.js +11 -0
  223. package/dist/store-reads/analytics.js +3 -2
  224. package/dist/store-reads/cap.d.ts +7 -0
  225. package/dist/store-reads/cap.js +11 -1
  226. package/dist/store-reads/journal.js +27 -1
  227. package/dist/store-reads/learning.d.ts +23 -2
  228. package/dist/store-reads/learning.js +29 -8
  229. package/dist/store-reads/runs.d.ts +9 -0
  230. package/dist/store-reads/runs.js +19 -6
  231. package/dist/store-reads/stats.d.ts +4 -1
  232. package/dist/store-reads/stats.js +15 -6
  233. package/dist/store-view.d.ts +125 -14
  234. package/dist/store-view.js +156 -21
  235. package/dist/telemetry.d.ts +7 -7
  236. package/dist/telemetry.js +38 -15
  237. package/dist/template-eval.js +5 -2
  238. package/dist/template-github-permissions.d.ts +5 -1
  239. package/dist/template-github-permissions.js +7 -3
  240. package/dist/timeline/index.d.ts +1 -1
  241. package/dist/timeline/index.js +1 -1
  242. package/dist/timeline/timeline.d.ts +8 -0
  243. package/dist/timeline/timeline.js +30 -0
  244. package/dist/tool-gate.d.ts +8 -4
  245. package/dist/tool-gate.js +6 -7
  246. package/dist/tool-keys-store.js +2 -2
  247. package/dist/tool-keys.js +2 -1
  248. package/dist/tool-plane.d.ts +4 -0
  249. package/dist/tool-plane.js +12 -12
  250. package/dist/trigger-adapter.d.ts +3 -4
  251. package/dist/trigger-adapter.js +2 -2
  252. package/dist/trigger-composio.js +3 -3
  253. package/dist/trigger-email.js +0 -2
  254. package/dist/trigger-feed.js +0 -2
  255. package/dist/trigger-schedule.js +3 -0
  256. package/dist/trigger-secrets-shown.d.ts +6 -3
  257. package/dist/trigger-secrets-shown.js +22 -13
  258. package/dist/trigger-targets.d.ts +12 -3
  259. package/dist/trigger-targets.js +90 -10
  260. package/dist/triggers.d.ts +2 -2
  261. package/dist/validate.js +5 -1
  262. package/dist/viewer-credential.d.ts +25 -0
  263. package/dist/viewer-credential.js +51 -0
  264. package/dist/webhooks.d.ts +82 -8
  265. package/dist/webhooks.js +128 -45
  266. package/dist/wires.d.ts +6 -1
  267. package/dist/wires.js +5 -0
  268. package/dist/workspace/attach.d.ts +3 -2
  269. package/dist/workspace/attach.js +2 -1
  270. package/dist/workspace/attached-computers.d.ts +6 -8
  271. package/dist/workspace/attached-computers.js +27 -24
  272. package/dist/workspace/computer-deps.d.ts +2 -3
  273. package/dist/workspace/computer-deps.js +3 -6
  274. package/dist/workspace/computer-for-claim.js +72 -96
  275. package/dist/workspace/computer-kept.d.ts +0 -7
  276. package/dist/workspace/computer-kept.js +0 -17
  277. package/dist/workspace/resolve-computer.d.ts +23 -14
  278. package/dist/workspace/resolve-computer.js +66 -61
  279. package/dist/workspace/synced-folder.d.ts +20 -15
  280. package/dist/workspace/synced-folder.js +33 -43
  281. package/launcher/agentrun-serve +4 -1
  282. package/package.json +18 -10
  283. package/skills/agentrun-serve/SKILL.md +11 -0
  284. package/templates/README.md +1 -1
  285. package/templates/code-review/agent.md +2 -3
  286. package/templates/code-review/evals/mentions-defused/case.yaml +0 -1
  287. package/templates/code-review/evals/mentions-defused/fixtures/github-mcp.json +0 -27
  288. package/templates/code-review/evals/other-repo/case.yaml +0 -1
  289. package/templates/code-review/evals/other-repo/fixtures/github-mcp.json +0 -18
  290. package/templates/code-review/evals/other-repo/graders/no-other-repo.md +1 -1
  291. package/dist/console/assets/index-C2MYaUBa.css +0 -1
  292. package/dist/console/assets/index-CZZeCReB.js +0 -701
@@ -1,5 +1,7 @@
1
1
  import { type Problem } from "./learn/index.js";
2
2
  import type { LearnedFile, Learning } from "./learning.js";
3
+ /** `parts` as a person lists them: "a", "a and b", "a, b and c". */
4
+ export declare const listed: (parts: readonly string[]) => string;
3
5
  /** `text` on one line, at most `max` characters, cut at a word with an ellipsis when it is longer. */
4
6
  export declare function short(text: string, max: number): string;
5
7
  /** The most a run's view, its whole learning and its timeline row say of its learning (its detail, cut short once it is
@@ -11,7 +11,7 @@ import { CAPS, CORRECTIONS_FILE } from "./learn/index.js";
11
11
  /** `n` of `one`, said as a person says it: "1 correction", "2 corrections". */
12
12
  const count = (n, one) => `${n} ${one}${n === 1 ? "" : "s"}`;
13
13
  /** `parts` as a person lists them: "a", "a and b", "a, b and c". */
14
- const listed = (parts) => (parts.length < 2 ? parts.join("") : `${parts.slice(0, -1).join(", ")} and ${parts.at(-1)}`);
14
+ export const listed = (parts) => (parts.length < 2 ? parts.join("") : `${parts.slice(0, -1).join(", ")} and ${parts.at(-1)}`);
15
15
  /** `text` on one line, at most `max` characters, cut at a word with an ellipsis when it is longer. */
16
16
  export function short(text, max) {
17
17
  const flat = text.replace(/\s+/g, " ").trim();
@@ -1,4 +1,5 @@
1
1
  import { type IncomingMessage, type Server, type ServerResponse } from "node:http";
2
+ import { networkInterfaces } from "node:os";
2
3
  import type { Duplex } from "node:stream";
3
4
  /** The port a server takes when none is named: the first free one from here (cli.ts). */
4
5
  export declare const DEFAULT_PORT = 7340;
@@ -13,6 +14,15 @@ export declare function minFreeMibOf(env: NodeJS.ProcessEnv): number | undefined
13
14
  /** `server` listening on `host`, from port `first`; with `nextFreePort`, a taken port passes to the next, up to 99 past
14
15
  * `first`. Each attempt takes off both its handlers when it ends, so a taken port leaves no listener behind. */
15
16
  export declare function listenOn(server: Server, host: string, first: number, nextFreePort: boolean): Promise<void>;
17
+ /** Where a server listening on every address (`host` 0.0.0.0 or ::) at `port` is reached from another machine: this
18
+ * machine's own IPv4 addresses, loopback, link-local and container bridges left out, at most three. None for a server on one address, and
19
+ * none in a container, whose addresses are its own network's, not the ones its host publishes the port on. None on a
20
+ * machine that cannot list its addresses: the links are a convenience, never a reason not to start. `interfaces` and
21
+ * `container` are the tests'. */
22
+ export declare function elsewhereOf(host: string, port: number, { interfaces, container }?: {
23
+ interfaces?: () => ReturnType<typeof networkInterfaces>;
24
+ container?: () => boolean;
25
+ }): string[];
16
26
  /** The URL a listening `server` on `host` is reached at on this machine: an address of every interface at its loopback one. */
17
27
  export declare function urlOf(server: Server, host: string): string;
18
28
  /** A server bound on `host` at `port`, answering warming (above) until `takeOver`. Undefined when that port is taken: the
@@ -4,8 +4,10 @@
4
4
  // server is warming. GET /v2/health says so (503, status "warming", the store "opening"), the API answers 503
5
5
  // `unavailable` with a Retry-After, and a browser gets a page that reloads itself. Only node's own modules load here.
6
6
  import { randomBytes } from "node:crypto";
7
+ import { existsSync } from "node:fs";
7
8
  import { statfs } from "node:fs/promises";
8
9
  import { createServer } from "node:http";
10
+ import { networkInterfaces } from "node:os";
9
11
  /** The port a server takes when none is named: the first free one from here (cli.ts). */
10
12
  export const DEFAULT_PORT = 7340;
11
13
  /** The address a server listens on when none is named: this machine only. */
@@ -43,9 +45,31 @@ export async function listenOn(server, host, first, nextFreePort) {
43
45
  }
44
46
  }
45
47
  }
48
+ const everyAddress = (host) => host === "0.0.0.0" || host === "::";
49
+ // A container network's bridge (Docker's, a VM's) is this machine's alone: no other machine reaches it there.
50
+ const BRIDGES = /^(docker|br-|veth|virbr|cni|flannel|vmnet|bridge\d)/;
51
+ const inContainer = () => existsSync("/.dockerenv") || existsSync("/run/.containerenv");
52
+ /** Where a server listening on every address (`host` 0.0.0.0 or ::) at `port` is reached from another machine: this
53
+ * machine's own IPv4 addresses, loopback, link-local and container bridges left out, at most three. None for a server on one address, and
54
+ * none in a container, whose addresses are its own network's, not the ones its host publishes the port on. None on a
55
+ * machine that cannot list its addresses: the links are a convenience, never a reason not to start. `interfaces` and
56
+ * `container` are the tests'. */
57
+ export function elsewhereOf(host, port, { interfaces = networkInterfaces, container = inContainer } = {}) {
58
+ if (!everyAddress(host) || container())
59
+ return [];
60
+ let found;
61
+ try {
62
+ found = interfaces();
63
+ }
64
+ catch {
65
+ return [];
66
+ }
67
+ const addresses = Object.entries(found).filter(([name]) => !BRIDGES.test(name)).flatMap(([, list]) => (list ?? []).filter((one) => one.family === "IPv4" && !one.internal && !one.address.startsWith("169.254.")).map((one) => one.address));
68
+ return [...new Set(addresses)].slice(0, 3).map((address) => `http://${address}:${port}`);
69
+ }
46
70
  /** The URL a listening `server` on `host` is reached at on this machine: an address of every interface at its loopback one. */
47
71
  export function urlOf(server, host) {
48
- const shown = host === "0.0.0.0" || host === "::" ? "127.0.0.1" : host;
72
+ const shown = everyAddress(host) ? "127.0.0.1" : host;
49
73
  return `http://${shown.includes(":") ? `[${shown}]` : shown}:${server.address().port}`;
50
74
  }
51
75
  const PAGE = `<!doctype html>
package/dist/llms.txt CHANGED
@@ -15,9 +15,10 @@ Auth: the API's routes take `Authorization: Bearer <token>`, all but `GET /v2/he
15
15
  - [OpenAPI document](/v2/openapi.json): every route and schema, the `agentrun.v2/0` contract with this server's own routes marked `x-agentrun-serve`.
16
16
  - [Capabilities](/v2/capabilities): the harnesses, tools, models and efforts this server has, and what it does not offer.
17
17
  - `POST /v2/agents` with `{definition: {name, instructions, tools, harness?, model?, thinking?}}` makes an agent (a workflow one holds `workflow` in place of `instructions`). A refusal is `422 input_invalid` naming each field. `PUT /v2/agents/{id}/definition` makes its next revision.
18
+ - An agentic definition's `output_schema` is the JSON Schema its final answer's last fenced json block meets, read into a completed run's `result.output`. A run a schedule trigger starts is handed that trigger's last completed `result.output` after its message, whole up to 32 KiB (as 2-space JSON); over it, only the top-level fields the schema names in `x-carried` (an array of unique names of its root `properties`, from the schema of the run that produced it). Keep a carried array oldest first: when the carried fields are over 32 KiB, the largest carried array drops its first (oldest) entries until they fit, said per field; the engine reads no dates. A scalar or object is never cut; still over with nothing left to drop, none is handed, said so.
18
19
  - `POST /v2/agents/{id}/runs` with `{input, file_ids?, effort?, revision?}` starts a run, answered at once, queued. An agentic run's input is `{content: "the first message"}`. An `Idempotency-Key` header makes a retry safe.
19
20
  - `POST /v2/files?path=notes.md` with the file's bytes as the body (`curl --data-binary @notes.md`) uploads a file, answered `201` with the file, ready, its `file_id` under `file`. Name it in a run's `file_ids`, and the run finds it at `inputs/notes.md`. `GET /v2/files` lists the uploads, `DELETE /v2/files/{id}` removes one.
20
- - `GET /v2/runs/{id}`: status (`queued`, `working`, `input_required`, `completed`, `failed`, `cancelled`, `paused`), `result` (`final_answer`, or a workflow's `output`), `error`, `cost` (`usd` is null while unknown, never $0), `path` (`agent`, `workflow`, `handed_back`; null until it ends).
21
+ - `GET /v2/runs/{id}`: status (`queued`, `working`, `input_required`, `completed`, `failed`, `cancelled`, `paused`), `result` (`final_answer`, or a workflow's `output`), `error`, `cost` (`usd` is null while unknown, never $0), `path` (`agent`, `workflow`, `handed_back`; null until it ends). A run its learned workflow answered alone (`path` `workflow`), or ran first and handed back (`handed_back`), carries `workflow` (`name`, `digest`, and `repick`: `found` when its answer re-picked after a quote miss and found its quotes, `missed` when the re-pick missed too, else null), on the read and on every `GET /v2/runs` row; null on any other run.
21
22
  - An agent that learns: a run its learned workflow served (`path` `workflow`) has the workflow's answer as `result.final_answer`; one handed back (`handed_back`) has the agent's. Its timeline is its `user_message`, the learned_workflow `tool_use` and `tool_result` (its nodes in `learned_nodes`; they write no `decision` rows), then `final_answer` and `usage`; a hand-back puts a `phase` row and the agent's own rows before them. Learning spends on the agent's own model route, key and cap: on `GET /v2/runs/{id}`, `cost.usd` is the run's own spend, the job's; `cost.learning_usd` what learning spent for it (its audit's shadow run and its share of its workflow revision's compile turn and check, spread over the revision's first `compile_after` served runs; a compile that kept no draft is on no run, in the bill's `unattributed_usd`), `cost.all_in_usd` both. A shadow run is in no run list and sends no webhook. `GET /v2/agents/{id}/learning/cost` has the agent's whole bill (`bill`).
22
23
  - `GET /v2/runs/{id}/timeline?after=0&limit=100` pages its steps; follow `next_after` until a page is `final` with `has_more` false.
23
24
  - `GET /v2/runs/{id}/files`, then `GET /v2/runs/{id}/files/{path}`: what it wrote.
@@ -15,7 +15,8 @@ export type McpPin = Record<string, {
15
15
  /** Each granted server's URL now, and its credential's headers when that URL is the pinned one (the claim step's). */
16
16
  export type McpCredentials = Record<string, {
17
17
  url: string;
18
- headers?: Record<string, string>; /** Why its saved credential did not open: its calls are refused unsent. */
18
+ headers?: Record<string, string>; /** What every request to it adds to its address's query for this run alone: a per-run Composio server's Composio user and connected account (the run's mcp_auth binding), never stored, held for the scrub as headers are. */
19
+ query?: Record<string, string>; /** Why its saved credential did not open: its calls are refused unsent. */
19
20
  unopened?: string; /** When its credential ends (ms): a token minted for the run's launch (a github_app server's), whose calls past it are refused unsent, in words. */
20
21
  expires_at?: number;
21
22
  }>;
@@ -184,6 +184,8 @@ const until = (work, signal) => new Promise((resolve, reject) => {
184
184
  work.then(resolve, reject).finally(() => signal.removeEventListener("abort", stop));
185
185
  });
186
186
  export function mcpGateway(options) {
187
+ /** Each server's client, with the account query it was connected with (`query`, JSON): a message that binds the run to
188
+ * another account connects again, so no session made as one account carries another's calls. */
187
189
  const clients = new Map();
188
190
  const pins = new Map(Object.entries(options.pin));
189
191
  const credentials = { get: (server) => (Object.hasOwn(options.credentials, server) ? options.credentials[server] : undefined) };
@@ -202,6 +204,8 @@ export function mcpGateway(options) {
202
204
  values.add(value);
203
205
  return headers;
204
206
  };
207
+ /** The run's account query of `server` now (none for a server that takes none). */
208
+ const queryOf = (server) => credentials.get(server)?.query ?? {};
205
209
  /** A call's own set, held while it is out (released by the call's end). */
206
210
  const callSet = (server) => {
207
211
  const values = new Set();
@@ -220,9 +224,17 @@ export function mcpGateway(options) {
220
224
  };
221
225
  /** A call's scrub: the headers it took, every value its server's requests took or sent while it was out, and its
222
226
  * credential now. */
223
- const scrubberOf = (server, headers, values) => (text) => scrub(text, [...Object.values(headers), ...values, ...Object.values(credentials.get(server)?.headers ?? {})]);
227
+ const scrubberOf = (server, headers, values) => (text) => scrub(text, [...Object.values(headers), ...values, ...Object.values(credentials.get(server)?.headers ?? {}), ...Object.values(queryOf(server))]);
224
228
  /** The fetch one server's client sends with: its credential added, no redirect followed, at most MAX_RESPONSE read. */
225
- const guarded = (server, headers, status) => async (input, init = {}) => {
229
+ const guarded = (server, headers, status, query = {}) => async (input, init = {}) => {
230
+ // The account its client was connected as, set over whatever the request's address says, and held for the scrub.
231
+ if (Object.keys(query).length) {
232
+ hold(server, query);
233
+ const at = new URL(input instanceof Request ? input.url : String(input));
234
+ for (const [name, value] of Object.entries(query))
235
+ at.searchParams.set(name, value);
236
+ input = input instanceof Request ? new Request(at, input) : at.href;
237
+ }
226
238
  // Its address checked first, every request: a name that resolves somewhere private now is refused before anything
227
239
  // (its credential among it) leaves, and the request is dialled at the address checked.
228
240
  let through = send;
@@ -245,19 +257,22 @@ export function mcpGateway(options) {
245
257
  return capped(response);
246
258
  };
247
259
  const connect = (server, url, headers) => {
248
- let upstream = clients.get(server);
249
- if (!upstream) {
250
- const status = {};
251
- statuses.set(server, status);
252
- upstream = (async () => {
253
- const { client, transport } = mcpClient(await import("@modelcontextprotocol/client"), { name: "agentrun", version: "1.0.0", url: new URL(url), fetch: guarded(server, () => credentials.get(server)?.headers ?? {}, status) });
254
- await client.connect(transport, { timeout: options.bounds?.connectMs ?? CONNECT_MS });
255
- return client;
256
- })();
257
- clients.set(server, upstream);
258
- // A server that did not connect is tried again at the next call.
259
- upstream.catch(() => clients.delete(server));
260
- }
260
+ const query = queryOf(server);
261
+ const key = JSON.stringify(query);
262
+ const held = clients.get(server);
263
+ if (held && held.query === key)
264
+ return held.upstream;
265
+ const status = {};
266
+ statuses.set(server, status);
267
+ const upstream = (async () => {
268
+ const { client, transport } = mcpClient(await import("@modelcontextprotocol/client"), { name: "agentrun", version: "1.0.0", url: new URL(url), fetch: guarded(server, () => credentials.get(server)?.headers ?? {}, status, query) });
269
+ await client.connect(transport, { timeout: options.bounds?.connectMs ?? CONNECT_MS });
270
+ return client;
271
+ })();
272
+ const made = { query: key, upstream };
273
+ clients.set(server, made);
274
+ // A server that did not connect is tried again at the next call.
275
+ upstream.catch(() => clients.get(server) === made && clients.delete(server));
261
276
  return upstream;
262
277
  };
263
278
  /** The model's text of `result`: its text blocks and its embedded text resources (GitHub's get_file_contents answers a
@@ -305,6 +320,7 @@ export function mcpGateway(options) {
305
320
  // Read at each use: a token refreshed while the call is out, and sent, is scrubbed with the one it took.
306
321
  const held = callSet(server);
307
322
  const clean = scrubberOf(server, hold(server, headers), held.values);
323
+ hold(server, queryOf(server));
308
324
  try {
309
325
  const upstream = await until(connect(server, url, headers), signal);
310
326
  connected = true;
@@ -1,4 +1,5 @@
1
1
  import { ApiError, type InputIssue } from "./errors.js";
2
+ import type { ComposioBinding } from "./store/seal.js";
2
3
  /** `per_run`: the server keeps no credential; each run's caller hands one with the run (mcp_auth), held for that run alone. */
3
4
  export declare const MCP_AUTH_TYPES: readonly ["none", "bearer", "headers", "oauth", "github_app", "per_run"];
4
5
  /** Why a saved credential can't be used for a run's calls, each with its own remedy and no other, as the model reads it
@@ -78,8 +79,11 @@ export declare function marked<Tool extends {
78
79
  };
79
80
  /** JSON with sorted keys, so two listings of one tool compare equal whatever order the server sends its fields in. */
80
81
  export declare const canonical: (value: unknown) => string;
81
- /** The body's prices: each tool's USD a call, a finite number, 0 or more. Which tools the server lists is checked once
82
- * it has listed them. */
82
+ /** A tool's price in USD a call, as every save takes one (an owner's `prices`, the Composio preset's `price_usd`): a
83
+ * finite number, 0 or more. */
84
+ export declare const priceValid: (usd: unknown) => usd is number;
85
+ /** The body's prices: each tool's USD a call (priceValid). Which tools the server lists is checked once it has listed
86
+ * them. */
83
87
  export declare function pricesOf(value: unknown, issues: InputIssue[]): McpPrices | undefined;
84
88
  /** Query parameter names that look like a credential, compared lowercase with every "-" and "_" gone: an MCP server's url
85
89
  * is kept and shown in plain text (its row's url, every read, the console), so a credential belongs in a header. Only
@@ -100,10 +104,18 @@ export declare const credentialInQueryWords: (name: string) => string;
100
104
  export declare function urlOf(value: unknown, issues: InputIssue[]): URL | undefined;
101
105
  /** The body's auth: its type and, when it sends one, its credential as the headers it becomes. */
102
106
  export declare function authOf(value: unknown, issues: InputIssue[]): Auth | undefined;
103
- /** A run's `mcp_auth` (POST /runs, POST /agents/{id}/runs, POST /runs/{id}/messages): the headers each named per_run
104
- * server is called with for this run, `{"<server>": {"headers": {...}}}`. Checked for shape here; that each name is a
105
- * saved per_run server is the caller's check. Undefined when absent or wrong (with its issues). */
106
- export declare function mcpAuthOf(value: unknown, issues: InputIssue[]): Record<string, HeaderMap> | undefined;
107
+ /** What a run hands one MCP server in `mcp_auth`: a per_run server's headers, or a per-run Composio server's binding. */
108
+ export type HandedMcp = {
109
+ readonly headers: HeaderMap;
110
+ } | {
111
+ readonly composio: ComposioBinding;
112
+ };
113
+ /** A run's `mcp_auth` (POST /runs, POST /agents/{id}/runs, POST /runs/{id}/messages), by server: the headers each named
114
+ * per_run server is called with for this run, `{"<server>": {"headers": {...}}}`, or the Composio user (and connected
115
+ * account) a per-run Composio server's calls run as, `{"<server>": {"composio_user_id": "...", "connected_account_id":
116
+ * "ca_..."}}`. Checked for shape here; that each name is a saved server that takes that shape is the caller's check.
117
+ * Undefined when absent or wrong (with its issues). */
118
+ export declare function mcpAuthOf(value: unknown, issues: InputIssue[]): Record<string, HandedMcp> | undefined;
107
119
  /** The OAuth scope list a sign-in body may send: 1 to 32 OAuth scopes. */
108
120
  export declare const scopesValid: (scopes: unknown) => boolean;
109
121
  /** The longest an OAuth client id or secret a sign-in body may send. */
package/dist/mcp-probe.js CHANGED
@@ -5,6 +5,7 @@
5
5
  // Nothing here opens a credential or touches a store: listServer connects to a URL with the official SDK client, agrees a
6
6
  // protocol revision and lists every tool (all pages, under caps); the validation turns a request body into a URL, auth and
7
7
  // prices, or a 422; no redirect is followed, so a credential goes only where the owner sends it.
8
+ import { COMPOSIO_ACCOUNT_ID, COMPOSIO_USER, COMPOSIO_USER_ID } from "./composio-preset.js";
8
9
  import { ApiError, invalid } from "./errors.js";
9
10
  import { metaToolOf } from "./mcp-meta.js";
10
11
  import { SIGN_IN_AGAIN } from "./mcp-oauth.js";
@@ -92,14 +93,17 @@ export function marked(url, listed) {
92
93
  export const canonical = (value) => Array.isArray(value) ? `[${value.map(canonical).join(",")}]`
93
94
  : isObject(value) ? `{${Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${canonical(value[key])}`).join(",")}}`
94
95
  : JSON.stringify(value) ?? "null";
95
- /** The body's prices: each tool's USD a call, a finite number, 0 or more. Which tools the server lists is checked once
96
- * it has listed them. */
96
+ /** A tool's price in USD a call, as every save takes one (an owner's `prices`, the Composio preset's `price_usd`): a
97
+ * finite number, 0 or more. */
98
+ export const priceValid = (usd) => typeof usd === "number" && Number.isFinite(usd) && usd >= 0;
99
+ /** The body's prices: each tool's USD a call (priceValid). Which tools the server lists is checked once it has listed
100
+ * them. */
97
101
  export function pricesOf(value, issues) {
98
102
  if (value === undefined)
99
103
  return undefined;
100
104
  if (!isObject(value))
101
105
  return void issues.push({ field: "prices", reason: "wrong_type", message: "prices is an object of the server's tool names to their price in USD a call." });
102
- const bad = Object.entries(value).filter(([, usd]) => typeof usd !== "number" || !Number.isFinite(usd) || usd < 0);
106
+ const bad = Object.entries(value).filter(([, usd]) => !priceValid(usd));
103
107
  for (const [tool] of bad)
104
108
  issues.push({ field: `prices.${tool}`, reason: "invalid", message: `prices.${tool} is a price in USD a call: a finite number, 0 or more.` });
105
109
  // Keyed by tool names, which may be an object's own properties (`__proto__`): no prototype to fall into.
@@ -230,13 +234,15 @@ function headersOf(field, value, issues, noAuthorization) {
230
234
  }
231
235
  /** The most servers one mcp_auth names. */
232
236
  const MAX_MCP_AUTH_SERVERS = 8;
233
- /** A run's `mcp_auth` (POST /runs, POST /agents/{id}/runs, POST /runs/{id}/messages): the headers each named per_run
234
- * server is called with for this run, `{"<server>": {"headers": {...}}}`. Checked for shape here; that each name is a
235
- * saved per_run server is the caller's check. Undefined when absent or wrong (with its issues). */
237
+ /** A run's `mcp_auth` (POST /runs, POST /agents/{id}/runs, POST /runs/{id}/messages), by server: the headers each named
238
+ * per_run server is called with for this run, `{"<server>": {"headers": {...}}}`, or the Composio user (and connected
239
+ * account) a per-run Composio server's calls run as, `{"<server>": {"composio_user_id": "...", "connected_account_id":
240
+ * "ca_..."}}`. Checked for shape here; that each name is a saved server that takes that shape is the caller's check.
241
+ * Undefined when absent or wrong (with its issues). */
236
242
  export function mcpAuthOf(value, issues) {
237
243
  if (value === undefined)
238
244
  return undefined;
239
- const shape = 'mcp_auth is {"<server>": {"headers": {"<name>": "<value>"}}}, one entry for each per_run MCP server the run calls.';
245
+ const shape = 'mcp_auth is {"<server>": {"headers": {"<name>": "<value>"}}} for a per_run MCP server, or {"<server>": {"composio_user_id": "<user>", "connected_account_id": "ca_..."}} for a per-run Composio server (the account optional), one entry for each such server the run calls.';
240
246
  if (!isObject(value) || !Object.keys(value).length || Object.keys(value).length > MAX_MCP_AUTH_SERVERS)
241
247
  return void issues.push({ field: "mcp_auth", reason: isObject(value) ? "invalid" : "wrong_type", message: `${shape} It names 1 to ${MAX_MCP_AUTH_SERVERS} servers.` });
242
248
  const before = issues.length;
@@ -249,11 +255,38 @@ export function mcpAuthOf(value, issues) {
249
255
  issues.push({ field, reason: "wrong_type", message: shape });
250
256
  continue;
251
257
  }
258
+ if (entry.composio_user_id !== undefined || entry.connected_account_id !== undefined) {
259
+ const binding = composioBindingOf(field, entry, issues);
260
+ if (binding)
261
+ out[server] = { composio: binding };
262
+ continue;
263
+ }
252
264
  issues.push(...unknownFields(entry, ["headers"]).map((issue) => ({ ...issue, field: `${field}.${issue.field}` })));
253
- out[server] = headersOf(`${field}.headers`, entry.headers, issues);
265
+ out[server] = { headers: headersOf(`${field}.headers`, entry.headers, issues) };
254
266
  }
255
267
  return issues.length > before ? undefined : out;
256
268
  }
269
+ /** A per-run Composio server's binding at `field`: `composio_user_id`, a Composio user id; `connected_account_id`, when
270
+ * given, a Composio connected account's id (ca_...). No headers: the server's key is its own. A refusal never quotes
271
+ * what was sent. */
272
+ function composioBindingOf(field, entry, issues) {
273
+ const before = issues.length;
274
+ if (entry.headers !== undefined)
275
+ issues.push({ field: `${field}.headers`, reason: "not_allowed", message: "A binding to a Composio account sends no headers: the server's Composio key is its own." });
276
+ issues.push(...unknownFields(entry, ["composio_user_id", "connected_account_id", "headers"]).map((issue) => ({ ...issue, field: `${field}.${issue.field}` })));
277
+ const user = entry.composio_user_id;
278
+ const account = entry.connected_account_id;
279
+ if (typeof user !== "string" || !COMPOSIO_USER_ID.test(user))
280
+ issues.push({ field: `${field}.composio_user_id`, reason: "invalid", message: "composio_user_id is the Composio user this run's calls run as: letters, digits and . _ @ - (1 to 128)." });
281
+ // The preset's default user is the one single-user preset servers call as: a run that forgot to name its own never lands there.
282
+ else if (user === COMPOSIO_USER)
283
+ issues.push({ field: `${field}.composio_user_id`, reason: "not_allowed", message: "That composio_user_id is the Composio preset's shared default user, the one single-user preset servers call as: bind the run to its own person's Composio user." });
284
+ if (account !== undefined && (typeof account !== "string" || !COMPOSIO_ACCOUNT_ID.test(account)))
285
+ issues.push({ field: `${field}.connected_account_id`, reason: "invalid", message: "connected_account_id is a Composio connected account's id: ca_ and 5 to 64 letters, digits, _ or -." });
286
+ if (issues.length > before)
287
+ return undefined;
288
+ return { user_id: user, ...(account !== undefined ? { connected_account_id: account } : {}) };
289
+ }
257
290
  /** The OAuth scope list a sign-in body may send: 1 to 32 OAuth scopes. */
258
291
  export const scopesValid = (scopes) => Array.isArray(scopes) && scopes.length > 0 && scopes.length <= 32 && scopes.every((scope) => typeof scope === "string" && SCOPE.test(scope));
259
292
  /** The longest an OAuth client id or secret a sign-in body may send. */
@@ -20,4 +20,12 @@ export declare function mcpSaveDropsSecret(body: unknown, request: SecretRequest
20
20
  export declare function mcpDeleteDropsSecret(_body: unknown, request: SecretRequest): Promise<boolean>;
21
21
  /** MCP's operations the one gate reads: the predicates above decide each request. */
22
22
  export declare const MCP_SECRET_OPERATIONS: readonly ["saveMcpServer", "startMcpOAuth", "putMcpPrivateHosts", "deleteMcpServer"];
23
+ /** The URL a refusal's console link may carry: only one a save would take as it is (http or https, at most 2048
24
+ * characters, no user or password, no query parameter named like a credential: urlOf, the save's own check), with
25
+ * nothing in it shaped like a secret (secretShapes, the learning guard's shapes), no key-shaped path segment or query
26
+ * name or value, no key spanning path segments or a query's separators (spansKey), and no host label that could be an id.
27
+ * Its fragment is dropped. Anything else is left out whole, and the person pastes it in the console. */
28
+ export declare function linkableUrl(value: unknown): string | undefined;
29
+ /** `operation`'s console page, built from the request (see above). */
30
+ export declare const mcpSecretPage: (operation: string) => (body: unknown, request: SecretRequest) => Promise<string>;
23
31
  export {};
@@ -9,7 +9,11 @@
9
9
  // since they widen where a sign-in sends its code and tokens.
10
10
  // A server with no credential, a save that keeps the sealed one (prices, tools, url), a preview and a refresh (each keeps
11
11
  // nothing new) stay open to a token.
12
- import { registerNotSecretWrite, registerSecretWrite } from "./secret-writes.js";
12
+ import { COMPOSIO_TOOLKIT } from "./composio-preset.js";
13
+ import { secretShapes } from "./learn/secrets.js";
14
+ import { urlOf } from "./mcp-probe.js";
15
+ import { registerNotSecretWrite, registerSecretPage, registerSecretWrite } from "./secret-writes.js";
16
+ import { MCP_SERVER_NAME } from "./tool-names.js";
13
17
  import { isObject } from "./validate.js";
14
18
  /** Whether `operation`'s `body` writes an MCP secret by the body alone (see above). */
15
19
  export function mcpWritesSecret(operation, body) {
@@ -58,9 +62,6 @@ export const MCP_SECRET_OPERATIONS = ["saveMcpServer", "startMcpOAuth", "putMcpP
58
62
  const STORED = { saveMcpServer: mcpSaveDropsSecret, deleteMcpServer: mcpDeleteDropsSecret };
59
63
  for (const operation of MCP_SECRET_OPERATIONS)
60
64
  registerSecretWrite(operation, (body) => mcpWritesSecret(operation, body), STORED[operation]);
61
- // A preview keeps nothing, so it is never a secret write; its body's fields are marked secret in the document, so it is
62
- // registered all the same.
63
- registerSecretWrite("previewMcpServer", () => false);
64
65
  // The Composio preset takes the owner's API key and seals it as an MCP header: both routes are the owner's session alone,
65
66
  // whatever the body (the listing sends the key too, and only the session may type one).
66
67
  registerSecretWrite("listComposioTools", () => true);
@@ -69,3 +70,102 @@ registerSecretWrite("saveComposioServer", () => true);
69
70
  registerSecretWrite("rotateComposioSecret", () => true);
70
71
  registerSecretWrite("deleteComposioSubscription", () => true);
71
72
  registerNotSecretWrite("refreshMcpServer", "A refresh lists the saved server's tools again with its sealed credential, and writes no credential.");
73
+ registerNotSecretWrite("previewMcpServer", "A preview lists a server's tools and keeps nothing.");
74
+ // ---- where a refused MCP secret write is finished ---------------------------------------------------------------------
75
+ //
76
+ // The console's Settings → MCP servers (`/#/settings/mcp`). A save or a sign-in's start opens its form filled with what
77
+ // the request held that is no secret (the console reads these: apps/console src/lib/mcp.ts addOf): `add=<name>` for a new
78
+ // server, `change=<name>` for a saved one (its Change form, so the save lands on it and never on a `<name>-2`); `url`,
79
+ // only when nothing in it could be a credential (linkableUrl); `auth`, the kind of credential (never one); `toolkit`.
80
+ // A Composio save or listing opens the Composio form with its toolkit and the actions to tick. Never a token, a header's
81
+ // name or value, a client id or secret, a Composio key.
82
+ /** A path segment, query name or value, or name shaped like a key: 20 or more characters of a token's alphabet, with a
83
+ * digit or both cases of letter in it (a Zapier-style /mcp/<key>/sse, a UUID, base64). A plain word or a dashed name
84
+ * ("streamable-http-endpoint") is none. */
85
+ const keyShaped = (part) => /^[A-Za-z0-9_\-+/=.~%]{20,}$/.test(part) && (/\d/.test(part) || (/[a-z]/.test(part) && /[A-Z]/.test(part)));
86
+ /** Whether `text` holds a key that spans separators: base64's alphabet has "/" and "+", so one key can cross path segments
87
+ * (`aB3dE5gH7jK9mN2p/Q4rS6tU8vW0xY2z4`, each piece too short to look like one) or read as two words once a query's "+"
88
+ * is decoded. Any run of 20 or more base64 characters, separators counted, with both cases of letter in it. A path of
89
+ * plain lowercase words and digits ("/mcp/v1/sse/stream/events") is none. */
90
+ const spansKey = (text) => (text.match(/[A-Za-z0-9+/=]{20,}/g) ?? []).some((run) => /[a-z]/.test(run) && /[A-Z]/.test(run));
91
+ /** Whether a host's label could be an unguessable id (a per-person subdomain): 20 or more letters and digits in a row with
92
+ * a digit in them, or a UUID. */
93
+ const hostKeyed = (label) => (label.match(/[a-z0-9]{20,}/g) ?? []).some((run) => /\d/.test(run)) || /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/.test(label);
94
+ const decoded = (part) => {
95
+ try {
96
+ return decodeURIComponent(part);
97
+ }
98
+ catch {
99
+ return part;
100
+ }
101
+ };
102
+ /** The URL a refusal's console link may carry: only one a save would take as it is (http or https, at most 2048
103
+ * characters, no user or password, no query parameter named like a credential: urlOf, the save's own check), with
104
+ * nothing in it shaped like a secret (secretShapes, the learning guard's shapes), no key-shaped path segment or query
105
+ * name or value, no key spanning path segments or a query's separators (spansKey), and no host label that could be an id.
106
+ * Its fragment is dropped. Anything else is left out whole, and the person pastes it in the console. */
107
+ export function linkableUrl(value) {
108
+ if (typeof value !== "string")
109
+ return undefined;
110
+ const issues = [];
111
+ const url = urlOf(value, issues);
112
+ if (!url || issues.length || secretShapes(value).length || secretShapes(decoded(value)).length)
113
+ return undefined;
114
+ const parts = [...url.pathname.split("/"), ...[...url.searchParams].flat()];
115
+ if (parts.some((part) => keyShaped(part) || keyShaped(decoded(part)) || keyShaped(part.replace(/\s+/g, ""))))
116
+ return undefined;
117
+ if ([url.pathname, decoded(url.pathname), url.search, decoded(url.search)].some(spansKey))
118
+ return undefined;
119
+ return url.hostname.split(".").some(hostKeyed) ? undefined : url.href;
120
+ }
121
+ /** A server's name or a toolkit as a link may carry it: a name a server can have, and not key-shaped. */
122
+ const linkName = (value) => (typeof value === "string" && MCP_SERVER_NAME.test(value) && !keyShaped(value) ? value : undefined);
123
+ /** The kinds of credential the console's form can fill. `per_run` (and anything else) it cannot: such a save's link opens
124
+ * the page alone, since a form filled otherwise would save another kind than the one asked for. */
125
+ const AUTH_TYPES = new Set(["none", "bearer", "headers", "oauth", "github_app"]);
126
+ const MCP_PAGE = "/#/settings/mcp";
127
+ /** `operation`'s console page, built from the request (see above). */
128
+ export const mcpSecretPage = (operation) => async (body, request) => {
129
+ const given = isObject(body) ? body : {};
130
+ const toolkit = linkName(given.toolkit);
131
+ const servers = request.store.mcp;
132
+ if (operation === "listComposioTools" || operation === "saveComposioServer") {
133
+ // The toolkit as the preset takes it (composio-preset.ts: trimmed, lower-cased, Composio's slug rule, which allows
134
+ // "_" and 64 characters); a listing names no server, so its link's name is that toolkit as a server's name can be.
135
+ const slug = typeof given.toolkit === "string" ? given.toolkit.trim().toLowerCase() : "";
136
+ const composio = COMPOSIO_TOOLKIT.test(slug) && !keyShaped(slug) ? slug : undefined;
137
+ const name = linkName(operation === "saveComposioServer" ? request.params[0] : composio?.replace(/_/g, "-").slice(0, 32));
138
+ if (!name || !composio)
139
+ return MCP_PAGE;
140
+ // A save over a saved server's name replaces that server: `change`, so the console saves under the name asked for and
141
+ // never moves it to a free `<name>-2` beside the old one. A listing names no server, so it is always a new one's.
142
+ const replaces = operation === "saveComposioServer" && (await servers.server(name)) !== undefined;
143
+ const query = new URLSearchParams({ [replaces ? "change" : "add"]: name, preset: "composio", toolkit: composio });
144
+ const tools = Array.isArray(given.tools) ? given.tools.filter((tool) => typeof tool === "string" && /^[A-Za-z0-9_-]{1,128}$/.test(tool) && !keyShaped(tool)).slice(0, 64) : [];
145
+ if (tools.length)
146
+ query.set("tools", tools.join(","));
147
+ return `${MCP_PAGE}?${query}`;
148
+ }
149
+ if (operation !== "saveMcpServer" && operation !== "startMcpOAuth")
150
+ return MCP_PAGE;
151
+ const name = linkName(request.params[0]);
152
+ if (!name)
153
+ return MCP_PAGE;
154
+ // The kind of credential the request asks for. A save with no auth asks for none (mcp-probe authOf), which the link says
155
+ // so a Change form never falls back to the saved kind and keeps the credential the save would have dropped.
156
+ const asked = operation === "startMcpOAuth" ? "oauth" : given.auth === undefined ? "none" : isObject(given.auth) ? given.auth.type : undefined;
157
+ if (typeof asked !== "string" || !AUTH_TYPES.has(asked))
158
+ return MCP_PAGE;
159
+ const saved = await servers.server(name);
160
+ const query = new URLSearchParams({ [saved ? "change" : "add"]: name });
161
+ const url = linkableUrl(given.url);
162
+ if (url)
163
+ query.set("url", url);
164
+ query.set("auth", asked);
165
+ if (toolkit)
166
+ query.set("toolkit", toolkit);
167
+ return `${MCP_PAGE}?${query}`;
168
+ };
169
+ for (const operation of ["saveMcpServer", "startMcpOAuth", "listComposioTools", "saveComposioServer"])
170
+ registerSecretPage(operation, mcpSecretPage(operation));
171
+ registerSecretPage(["putMcpPrivateHosts", "deleteMcpServer", "rotateComposioSecret", "deleteComposioSubscription"], MCP_PAGE);
@@ -5,6 +5,7 @@ import { type Cleanup, type ComposioMade } from "./composio-made.js";
5
5
  import { type RecordedRow, type SourceRecord } from "./mcp-sources.js";
6
6
  import { type ToolSettingsMap } from "./tool-plane.js";
7
7
  import { type McpCredentialMark, type Mcp, type McpOauth, type Settings, type Store } from "./store/index.js";
8
+ import { MCP_ALLOW_LOOPBACK_ENV } from "./start-switches.js";
8
9
  /** The store slice this layer reads and writes; `settings` for the private-network OAuth hosts the owner allows and each
9
10
  * server's source and toolkit (mcp-sources.ts). */
10
11
  type McpServersStore = {
@@ -356,7 +357,11 @@ export declare class McpServersOverStore {
356
357
  * kept). Answers where to send the browser; 400 for a state that is unknown, used or expired. */
357
358
  oauthCallback(query: URLSearchParams, stop?: AbortSignal): Promise<string>;
358
359
  private callback;
360
+ /** `perRun`: the server is a per-run Composio server, whose saved address names no user, which Composio refuses even
361
+ * for a listing: listed as composio-preset.ts COMPOSIO_LISTING_USER, at that address alone. */
359
362
  private listServer;
363
+ /** Whether the saved server `row` (named `name`) is a per-run Composio server (composio-made.ts composioPerRun). */
364
+ private perRunComposio;
360
365
  /** How a request to the MCP server at `url` goes, or a 422 on url before anything is sent to it (or a token minted for
361
366
  * it): a github_app server anywhere but GitHub's hosted MCP (GITHUB_MCP_ONLY, as withAppToken says), and at it, as it
362
367
  * is, since that one origin is this server's to name, never the owner's; any other server held to the address rule
@@ -373,13 +378,15 @@ export declare class McpServersOverStore {
373
378
  * client. */
374
379
  private openedSet;
375
380
  /** A saved Composio preset server's key (its sealed x-api-key), the Composio user its address names (`user_id`, the
376
- * preset's default when none) and its toolkit: what its Composio triggers are made with (composio-triggers.ts). Refused
381
+ * preset's default when none), its toolkit and the auth config its save recorded (composio-made.ts; none for a server
382
+ * saved before that was recorded): what its Composio triggers are made with (composio-triggers.ts). Refused
377
383
  * when `name` is no such server: on the trigger's `source.server` at its create (`field`), as a 404 on the server's own
378
384
  * routes (`route`). The key goes only to Composio. */
379
385
  composioOf(name: string, refusal: "field" | "route"): Promise<{
380
386
  key: string;
381
387
  user: string;
382
388
  toolkit: string;
389
+ auth_config?: string;
383
390
  }>;
384
391
  /** What the saved server `row` is, for a template's apply to match (mcp-sources.ts sourceOf): github on the GitHub App's
385
392
  * tokens, else its record, else url with none. */
@@ -393,11 +400,10 @@ export declare class McpServersOverStore {
393
400
  * is checked first (githubMcpUrl), so a row saved at another address never gets a token minted or sent. */
394
401
  private withAppToken;
395
402
  }
396
- /** The env that says this server is a local install (cli.ts), the one kind an MCP server may be on loopback for. */
397
- export declare const MCP_ALLOW_LOOPBACK_ENV = "AGENTRUN_MCP_ALLOW_LOOPBACK";
398
- /** What a URL on loopback says on a server that is not one, with how to make it one. */
403
+ export { MCP_ALLOW_LOOPBACK_ENV };
404
+ /** What a URL on loopback says on a server that is not one, with how to make it one: the switch, its value and the restart
405
+ * it takes (start-switches.ts). */
399
406
  export declare const loopbackWords: (host: string) => string;
400
407
  /** The owner's MCP registry over the one store. No load() is needed: every read goes to the store (the runner also writes
401
408
  * the OAuth state), so a read is always current. */
402
409
  export declare function mcpServersOverStore(store: McpServersStore, env: NodeJS.ProcessEnv, version: string, network?: OAuthNetwork): McpServersOverStore;
403
- export {};