@parcha/agentrun-serve 0.1.0-beta.45 → 0.1.0-beta.47

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 (256) hide show
  1. package/CHANGELOG.md +180 -0
  2. package/NOTICE +4 -0
  3. package/README.md +283 -47
  4. package/dist/acp-package.d.ts +35 -6
  5. package/dist/acp-package.js +3 -3
  6. package/dist/adapter-facts.d.ts +5 -2
  7. package/dist/adapter-facts.js +6 -3
  8. package/dist/adapters.d.ts +7 -0
  9. package/dist/adapters.js +39 -0
  10. package/dist/agents-store.d.ts +5 -3
  11. package/dist/agents-store.js +13 -8
  12. package/dist/api-only.d.ts +7 -10
  13. package/dist/api-only.js +7 -10
  14. package/dist/archil-routes.js +2 -1
  15. package/dist/cap.js +12 -2
  16. package/dist/chatgpt-plan.js +2 -1
  17. package/dist/cli.js +119 -44
  18. package/dist/composio-made.d.ts +19 -2
  19. package/dist/composio-made.js +17 -5
  20. package/dist/composio-preset.d.ts +42 -7
  21. package/dist/composio-preset.js +106 -70
  22. package/dist/composio-triggers.d.ts +9 -4
  23. package/dist/composio-triggers.js +20 -13
  24. package/dist/computer-attach.d.ts +11 -10
  25. package/dist/computer-attach.js +13 -14
  26. package/dist/computer-commands.d.ts +3 -0
  27. package/dist/computer-commands.js +3 -2
  28. package/dist/computer-lost.d.ts +4 -0
  29. package/dist/computer-lost.js +8 -3
  30. package/dist/computer-setting.d.ts +2 -0
  31. package/dist/computer-setting.js +2 -0
  32. package/dist/computers.d.ts +9 -75
  33. package/dist/computers.js +20 -66
  34. package/dist/console/assets/index-BBFzAxLB.js +715 -0
  35. package/dist/console/assets/index-BRi-Rgq6.css +1 -0
  36. package/dist/console/index.html +2 -2
  37. package/dist/cost-heal.d.ts +13 -0
  38. package/dist/cost-heal.js +27 -0
  39. package/dist/dial-relay.d.ts +6 -2
  40. package/dist/dial-relay.js +9 -12
  41. package/dist/email/routes.js +2 -1
  42. package/dist/errors.d.ts +2 -0
  43. package/dist/errors.js +5 -0
  44. package/dist/exa-keyless.d.ts +1 -1
  45. package/dist/exa-keyless.js +1 -1
  46. package/dist/faux-computers.d.ts +2 -3
  47. package/dist/faux-computers.js +9 -31
  48. package/dist/github-connection.js +2 -1
  49. package/dist/harness-archive.d.ts +19 -2
  50. package/dist/harness-archive.js +49 -15
  51. package/dist/harness-check.d.ts +73 -0
  52. package/dist/harness-check.js +489 -0
  53. package/dist/harness-cursor.d.ts +45 -0
  54. package/dist/harness-cursor.js +121 -0
  55. package/dist/harness-recipe.d.ts +127 -0
  56. package/dist/harness-recipe.js +357 -0
  57. package/dist/harness-table.d.ts +12 -0
  58. package/dist/harness-table.js +62 -2
  59. package/dist/harness.d.ts +2 -0
  60. package/dist/harness.js +3 -2
  61. package/dist/host-check.d.ts +6 -0
  62. package/dist/host-check.js +14 -0
  63. package/dist/host.d.ts +10 -3
  64. package/dist/host.js +17 -3
  65. package/dist/import-sources.d.ts +2 -0
  66. package/dist/import-sources.js +2 -0
  67. package/dist/import-summary.d.ts +15 -5
  68. package/dist/import-summary.js +24 -8
  69. package/dist/import.d.ts +34 -4
  70. package/dist/import.js +134 -32
  71. package/dist/key-refusal.d.ts +1 -0
  72. package/dist/key-refusal.js +8 -3
  73. package/dist/key-words.d.ts +1 -1
  74. package/dist/key-words.js +4 -4
  75. package/dist/learn/check.d.ts +3 -0
  76. package/dist/learn/check.js +31 -20
  77. package/dist/learn/compile.js +11 -4
  78. package/dist/learn/promote.d.ts +77 -4
  79. package/dist/learn/promote.js +123 -2
  80. package/dist/learned-nodes.d.ts +4 -3
  81. package/dist/learned-workflow.js +4 -1
  82. package/dist/learning-cost.d.ts +6 -16
  83. package/dist/learning-cost.js +6 -12
  84. package/dist/learning-setting.d.ts +17 -6
  85. package/dist/learning-setting.js +41 -5
  86. package/dist/learning-words.d.ts +2 -0
  87. package/dist/learning-words.js +1 -1
  88. package/dist/listen-first.d.ts +10 -0
  89. package/dist/listen-first.js +25 -1
  90. package/dist/llms.txt +1 -1
  91. package/dist/mcp-gateway.d.ts +2 -1
  92. package/dist/mcp-gateway.js +31 -15
  93. package/dist/mcp-probe.d.ts +18 -6
  94. package/dist/mcp-probe.js +41 -8
  95. package/dist/mcp-secret-writes.d.ts +8 -0
  96. package/dist/mcp-secret-writes.js +104 -4
  97. package/dist/mcp-servers-store.d.ts +11 -5
  98. package/dist/mcp-servers-store.js +46 -20
  99. package/dist/model-form.d.ts +2 -1
  100. package/dist/model-form.js +22 -8
  101. package/dist/model-gateway.d.ts +113 -0
  102. package/dist/model-gateway.js +433 -0
  103. package/dist/model.d.ts +2 -1
  104. package/dist/model.js +9 -7
  105. package/dist/monid.js +1 -1
  106. package/dist/native/binding.d.ts +4 -0
  107. package/dist/native/binding.js +9 -0
  108. package/dist/native/cli.d.ts +3 -2
  109. package/dist/native/cli.js +6 -5
  110. package/dist/openapi.d.ts +2 -0
  111. package/dist/openapi.js +326 -41
  112. package/dist/owner.d.ts +4 -2
  113. package/dist/owner.js +10 -4
  114. package/dist/page.d.ts +8 -0
  115. package/dist/page.js +9 -1
  116. package/dist/port-models.js +17 -10
  117. package/dist/provider.d.ts +3 -3
  118. package/dist/provider.js +12 -3
  119. package/dist/public-address.d.ts +28 -0
  120. package/dist/public-address.js +62 -0
  121. package/dist/run-launch.d.ts +1 -1
  122. package/dist/run-launch.js +1 -1
  123. package/dist/run-secrets.d.ts +3 -2
  124. package/dist/run-secrets.js +6 -4
  125. package/dist/runner/adapter-loop.d.ts +10 -7
  126. package/dist/runner/adapter-loop.js +57 -22
  127. package/dist/runner/adapter-run-spec.d.ts +12 -0
  128. package/dist/runner/adapter-run-spec.js +40 -6
  129. package/dist/runner/adapters/index.js +16 -0
  130. package/dist/runner/adapters/pi.d.ts +5 -2
  131. package/dist/runner/adapters/pi.js +7 -4
  132. package/dist/runner/audit.d.ts +7 -0
  133. package/dist/runner/audit.js +24 -6
  134. package/dist/runner/claim-secrets.js +5 -1
  135. package/dist/runner/cli-run-spec.js +15 -7
  136. package/dist/runner/compare-end.d.ts +43 -0
  137. package/dist/runner/compare-end.js +95 -0
  138. package/dist/runner/computer-journal.d.ts +3 -0
  139. package/dist/runner/computer-journal.js +22 -2
  140. package/dist/runner/conformance/harness.js +19 -8
  141. package/dist/runner/conformance/subject.d.ts +6 -0
  142. package/dist/runner/harness-loops.d.ts +6 -1
  143. package/dist/runner/harness-loops.js +94 -54
  144. package/dist/runner/held.d.ts +5 -4
  145. package/dist/runner/journal-kinds.d.ts +4 -1
  146. package/dist/runner/journal-kinds.js +3 -0
  147. package/dist/runner/loop-contract.d.ts +10 -0
  148. package/dist/runner/main.d.ts +5 -5
  149. package/dist/runner/main.js +81 -11
  150. package/dist/runner/mcp-claim.js +40 -12
  151. package/dist/runner/metrics.d.ts +26 -0
  152. package/dist/runner/metrics.js +44 -1
  153. package/dist/runner/presence.d.ts +41 -0
  154. package/dist/runner/presence.js +89 -0
  155. package/dist/runner/promotion.d.ts +10 -3
  156. package/dist/runner/promotion.js +42 -21
  157. package/dist/runner/run-child-host.js +52 -14
  158. package/dist/runner/runner.d.ts +5 -0
  159. package/dist/runner/runner.js +8 -0
  160. package/dist/runner/store-port.d.ts +3 -0
  161. package/dist/runner/store-secrets.js +19 -7
  162. package/dist/runner/workflow-first.d.ts +5 -2
  163. package/dist/runner/workflow-first.js +6 -3
  164. package/dist/runs-over-store.d.ts +6 -2
  165. package/dist/runs-over-store.js +14 -4
  166. package/dist/sdk/runs.d.ts +1 -1
  167. package/dist/sdk/runs.js +6 -1
  168. package/dist/sdk/schema.js +1 -1
  169. package/dist/secret-writes.d.ts +16 -3
  170. package/dist/secret-writes.js +28 -3
  171. package/dist/server-secrets-store.js +5 -0
  172. package/dist/server.d.ts +31 -2
  173. package/dist/server.js +326 -53
  174. package/dist/sign-ins-secrets.js +4 -1
  175. package/dist/skills/agentrun-serve/SKILL.md +11 -0
  176. package/dist/slack-url.d.ts +5 -0
  177. package/dist/slack-url.js +11 -0
  178. package/dist/slack.d.ts +107 -0
  179. package/dist/slack.js +292 -0
  180. package/dist/start-switches.d.ts +28 -0
  181. package/dist/start-switches.js +37 -0
  182. package/dist/stats.d.ts +1 -1
  183. package/dist/stats.js +2 -1
  184. package/dist/stop-signals.d.ts +11 -0
  185. package/dist/stop-signals.js +22 -0
  186. package/dist/store/agent-body.d.ts +1 -1
  187. package/dist/store/agent-body.js +2 -2
  188. package/dist/store/index.d.ts +3 -3
  189. package/dist/store/index.js +1 -1
  190. package/dist/store/postgres/migrations/0020_runners.sql +18 -0
  191. package/dist/store/postgres/store.d.ts +1 -1
  192. package/dist/store/postgres/store.js +4 -2
  193. package/dist/store/schema.d.ts +13 -5
  194. package/dist/store/schema.js +20 -11
  195. package/dist/store/seal.d.ts +16 -4
  196. package/dist/store/sqlite/store.d.ts +1 -1
  197. package/dist/store/sqlite/store.js +106 -27
  198. package/dist/store/store.d.ts +75 -23
  199. package/dist/store/store.js +11 -0
  200. package/dist/store-reads/analytics.js +3 -2
  201. package/dist/store-reads/cap.d.ts +7 -0
  202. package/dist/store-reads/cap.js +11 -1
  203. package/dist/store-reads/journal.js +27 -1
  204. package/dist/store-reads/learning.d.ts +23 -2
  205. package/dist/store-reads/learning.js +29 -8
  206. package/dist/store-reads/runs.d.ts +9 -0
  207. package/dist/store-reads/runs.js +19 -6
  208. package/dist/store-reads/stats.d.ts +4 -1
  209. package/dist/store-reads/stats.js +15 -6
  210. package/dist/store-view.d.ts +123 -14
  211. package/dist/store-view.js +154 -21
  212. package/dist/telemetry.d.ts +7 -7
  213. package/dist/telemetry.js +38 -15
  214. package/dist/templates.d.ts +6 -3
  215. package/dist/templates.js +38 -3
  216. package/dist/timeline/timeline.js +18 -0
  217. package/dist/tool-keys-store.js +2 -2
  218. package/dist/tool-keys.js +2 -1
  219. package/dist/tool-plane.js +2 -2
  220. package/dist/trigger-adapter.d.ts +3 -4
  221. package/dist/trigger-adapter.js +2 -2
  222. package/dist/trigger-composio.js +3 -3
  223. package/dist/trigger-email.js +0 -2
  224. package/dist/trigger-feed.js +0 -2
  225. package/dist/trigger-schedule.js +3 -0
  226. package/dist/trigger-secrets-shown.d.ts +6 -3
  227. package/dist/trigger-secrets-shown.js +22 -13
  228. package/dist/trigger-targets.d.ts +1 -1
  229. package/dist/trigger-targets.js +19 -8
  230. package/dist/triggers.d.ts +7 -3
  231. package/dist/triggers.js +2 -1
  232. package/dist/webhooks.d.ts +85 -9
  233. package/dist/webhooks.js +129 -46
  234. package/dist/wires.d.ts +6 -1
  235. package/dist/wires.js +5 -0
  236. package/dist/workspace/attach.d.ts +3 -2
  237. package/dist/workspace/attach.js +2 -1
  238. package/dist/workspace/attached-computers.d.ts +6 -8
  239. package/dist/workspace/attached-computers.js +27 -24
  240. package/dist/workspace/computer-deps.d.ts +2 -3
  241. package/dist/workspace/computer-deps.js +3 -6
  242. package/dist/workspace/computer-for-claim.js +72 -96
  243. package/dist/workspace/computer-kept.d.ts +0 -7
  244. package/dist/workspace/computer-kept.js +0 -17
  245. package/dist/workspace/resolve-computer.d.ts +18 -14
  246. package/dist/workspace/resolve-computer.js +47 -60
  247. package/dist/workspace/synced-folder.d.ts +20 -15
  248. package/dist/workspace/synced-folder.js +33 -43
  249. package/launcher/agentrun-serve +4 -1
  250. package/package.json +10 -10
  251. package/skills/agentrun-serve/SKILL.md +11 -0
  252. package/templates/README.md +1 -1
  253. package/templates/inbound-lead/agent.md +2 -1
  254. package/templates/kyb/agent.md +2 -1
  255. package/dist/console/assets/index-3O2Yl6hZ.js +0 -701
  256. package/dist/console/assets/index-DaFsZuzQ.css +0 -1
@@ -15,8 +15,8 @@ import { checkPrivateHosts, privateOAuthHosts, savePrivateOAuthHosts } from "./m
15
15
  import { credentialMark } from "./mcp-secret-writes.js";
16
16
  import { secretMeta, secretName } from "./secret-writes.js";
17
17
  import { dialAt, issuerOf, LOOPBACK, MAX_PENDING, MCP_SETTINGS_PAGE, mcpServerAt, McpSignIns, reasonOf, SIGN_IN_AGAIN, systemNetwork } from "./mcp-oauth.js";
18
- import { cleanupOf, composioMadeKey, droppedOf, madeToWrite, recordedMade, storedMade } from "./composio-made.js";
19
- import { COMPOSIO_USER, composioServerId } from "./composio-preset.js";
18
+ import { cleanupOf, composioMadeKey, composioPerRun, droppedOf, madeToWrite, recordedMade, releasedOf, storedMade } from "./composio-made.js";
19
+ import { COMPOSIO_PER_RUN, COMPOSIO_USER, composioListingAddress, composioServerId } from "./composio-preset.js";
20
20
  import { mcpSourceKey, recordedForAnother, sourceOf, sourceToWrite, standInGiven, storedSource, toolkitGiven } from "./mcp-sources.js";
21
21
  import { SEAL_KEY_ENV, sealKeyOf } from "./tool-keys.js";
22
22
  import { GITHUB_MCP_ONLY, GITHUB_MCP_ORIGIN, githubMcpUrl } from "./github.js";
@@ -26,6 +26,7 @@ import { HARNESSES } from "./harness.js";
26
26
  import { harnessOf } from "./harness-table.js";
27
27
  import { droppedWords, mcpGrantNameProblem, mcpToolName } from "./tool-names.js";
28
28
  import { isObject, unknownFields } from "./validate.js";
29
+ import { MCP_ALLOW_LOOPBACK_ENV, restartToAllow } from "./start-switches.js";
29
30
  /** How many writes an owner's save or tools refresh makes over a row whose credential a run's refresh keeps changing,
30
31
  * each re-applied onto the row read again, before it is refused in words. */
31
32
  const REWRITE_TRIES = 3;
@@ -191,7 +192,7 @@ export class McpServersOverStore {
191
192
  const kept = await this.need(name);
192
193
  const url = new URL(kept.url);
193
194
  const send = await this.reached(kept.auth, url, stop);
194
- return marked(kept.url, await this.signInNoted(url, this.listServer(url, await this.withAppToken(kept.auth, url, (await this.opened(name, kept, "name")).headers, stop), send, stop), stop));
195
+ return marked(kept.url, await this.signInNoted(url, this.listServer(url, await this.withAppToken(kept.auth, url, (await this.opened(name, kept, "name")).headers, stop), send, stop, await this.perRunComposio(name, kept)), stop));
195
196
  }
196
197
  // `name` with a url: the saved server the form is editing. Its address as every read shows it (shownUrl), sent back
197
198
  // unchanged, is the saved one here too (as save and sign-in map it): the browser never gets the real address back.
@@ -203,7 +204,9 @@ export class McpServersOverStore {
203
204
  if (auth.type !== "none" && auth.type !== "github_app" && auth.type !== "per_run" && !auth.headers)
204
205
  throw invalid([credentialMissing(auth.type, "A preview needs the credential it is to connect with.")]);
205
206
  const send = await this.reached(auth.type, url, stop);
206
- return marked(url.href, await this.signInNoted(url, this.listServer(url, await this.withAppToken(auth.type, url, auth.headers ?? {}, stop), send, stop), stop));
207
+ // The edit form of a per-run Composio server at its saved address lists it as a preview by name does.
208
+ const perRun = !!saved && auth.type === "headers" && saved.url === url.href && (await this.perRunComposio(String(editing), saved));
209
+ return marked(url.href, await this.signInNoted(url, this.listServer(url, await this.withAppToken(auth.type, url, auth.headers ?? {}, stop), send, stop, perRun), stop));
207
210
  }
208
211
  /** What an agent's save pins of the saved server `name` (mcp-gateway.ts mcpPinOf): its URL, its tools as it lists them
209
212
  * now (listed once, with its saved credential, as a preview by name lists them; nothing stored), each marked grantable
@@ -222,7 +225,7 @@ export class McpServersOverStore {
222
225
  };
223
226
  const send = await this.reached(row.auth, url, stop);
224
227
  try {
225
- return pinned((await this.listServer(url, await this.withAppToken(row.auth, url, (await this.opened(name, row, "name")).headers, stop), send, stop)).tools);
228
+ return pinned((await this.listServer(url, await this.withAppToken(row.auth, url, (await this.opened(name, row, "name")).headers, stop), send, stop, await this.perRunComposio(name, row))).tools);
226
229
  }
227
230
  catch (error) {
228
231
  if ((row.auth === "per_run" || row.auth === "oauth") && error instanceof ApiError && error.code === "auth_required")
@@ -314,14 +317,20 @@ export class McpServersOverStore {
314
317
  else if (auth.type !== "none") {
315
318
  credential = { type: "headers", headers: headers };
316
319
  }
317
- const listed = await this.listServer(url, await this.withAppToken(auth.type, url, headers ?? {}, stop), send, stop);
318
- const unlisted = Object.keys(prices ?? {}).filter((tool) => !listed.tools.some((listedTool) => listedTool.name === tool));
320
+ // A per-run Composio server, made so now (`stands`) or saved so and kept at its address by an ordinary save.
321
+ const perRun = Boolean(stands?.per_run) || (!made && was !== undefined && auth.type === "headers" && was.url === url.href && (await this.perRunComposio(name, was)));
322
+ const listed = await this.listServer(url, await this.withAppToken(auth.type, url, headers ?? {}, stop), send, stop, perRun);
323
+ // The Composio preset prices each action it granted (its price_usd): one its server doesn't list goes unpriced, as the
324
+ // preset's answer names it (not_served), never a refusal. An owner's prices name only tools the server lists.
325
+ const asked = made && prices ? pricesListed(prices, listed.tools) : prices;
326
+ const unlisted = Object.keys(asked ?? {}).filter((tool) => !listed.tools.some((listedTool) => listedTool.name === tool));
319
327
  if (unlisted.length)
320
328
  throw invalid(unlisted.map((tool) => ({ field: `prices.${tool}`, reason: "not_an_option", message: `The server ${name} lists no tool ${tool}; its tools are ${listed.tools.map((t) => t.name).join(", ") || "none"}.` })));
321
329
  // The row as saved over `row` (the one read, or read again): a body with no `prices` keeps the saved ones, for the tools
322
- // still listed at the same address.
330
+ // still listed at the same address; a preset save over a preset row keeps them at the new address its Composio server
331
+ // has (each preset save makes one), so a re-save never leaves a priced action unmetered.
323
332
  const fields = (row) => {
324
- const priced = prices ?? (row?.url === url.href ? pricesListed((row.prices ?? undefined), listed.tools) : undefined);
333
+ const priced = asked ?? (row && (row.url === url.href || (made && wasPreset)) ? pricesListed((row.prices ?? undefined), listed.tools) : undefined);
325
334
  return {
326
335
  name, url: url.href, auth: auth.type, protocol: listed.protocol, tools: listed.tools, serverInfo: listed.server_info, instructions: listed.instructions ?? null,
327
336
  ...(priced && Object.keys(priced).length ? { prices: priced } : {}),
@@ -332,7 +341,7 @@ export class McpServersOverStore {
332
341
  const write = async () => {
333
342
  if (guard && wasPreset) {
334
343
  const stood = recordedMade(await this.store.settings.get(composioMadeKey(name)), was.createdAt);
335
- if (moved || (made && stands && (!stood || stood.user !== stands.user || (stood.auth_config?.id ?? null) !== (stands.auth_config?.id ?? null))))
344
+ if (moved || (made && stands && (!stood || stood.user !== stands.user || Boolean(stood.per_run) !== Boolean(stands.per_run) || (stood.auth_config?.id ?? null) !== (stands.auth_config?.id ?? null))))
336
345
  await guard.inUse();
337
346
  }
338
347
  const saved = keeping
@@ -353,7 +362,12 @@ export class McpServersOverStore {
353
362
  // What it stands on at Composio: what the preset found and made, over what the server saved before over this row had
354
363
  // made. A row moved off Composio stands on nothing there: its delete removes nothing at Composio.
355
364
  if (made && stands) {
356
- const others = (await this.composioRecords()).filter(([other]) => other !== name);
365
+ // An auth config the owner named (auth_config_id) is theirs from this save on: every other saved server's claim to
366
+ // have made it is let go first, so neither this record nor theirs, nor what they hand on, ever removes it.
367
+ const listed = (await this.composioRecords()).filter(([other]) => other !== name);
368
+ const released = stands.auth_config?.named ? releasedOf(stands.auth_config.id, listed) : [];
369
+ await this.handOver(listed, released);
370
+ const others = listed.map(([other, record, at]) => [other, released.find(([one]) => one === other)?.[1] ?? record, at]);
357
371
  const before = was ? recordedMade(await this.store.settings.get(composioMadeKey(name)), was.createdAt) : undefined;
358
372
  const record = madeToWrite(stands, before, others.map(([, other]) => other));
359
373
  await this.store.settings.put(composioMadeKey(name), storedMade(record, saved));
@@ -399,7 +413,7 @@ export class McpServersOverStore {
399
413
  const was = await this.need(name);
400
414
  const send = await this.reached(was.auth, new URL(was.url), stop);
401
415
  const open = await this.opened(name, was, "name");
402
- const listed = await this.listServer(new URL(was.url), await this.withAppToken(was.auth, new URL(was.url), open.headers, stop), send, stop);
416
+ const listed = await this.listServer(new URL(was.url), await this.withAppToken(was.auth, new URL(was.url), open.headers, stop), send, stop, await this.perRunComposio(name, was));
403
417
  const before = new Map(was.tools.map((tool) => [tool.name, canonical(tool)]));
404
418
  const after = new Map(listed.tools.map((tool) => [tool.name, canonical(tool)]));
405
419
  // A refresh re-lists the tools and leaves the credential as it is (rewriteKeeping: a run's refreshed set kept meanwhile
@@ -578,9 +592,15 @@ export class McpServersOverStore {
578
592
  return back(await reasonOf(error));
579
593
  }
580
594
  }
581
- listServer(url, headers, send, stop) {
595
+ /** `perRun`: the server is a per-run Composio server, whose saved address names no user, which Composio refuses even
596
+ * for a listing: listed as composio-preset.ts COMPOSIO_LISTING_USER, at that address alone. */
597
+ listServer(url, headers, send, stop, perRun = false) {
582
598
  // The shared probe (mcp-probe.listServer), bound also to this server's own stop, each request sent as `send` (reached).
583
- return listServer(url, headers, this.version, AbortSignal.any([this.stopped.signal, ...(stop ? [stop] : [])]), send);
599
+ return listServer(perRun ? composioListingAddress(url) : url, headers, this.version, AbortSignal.any([this.stopped.signal, ...(stop ? [stop] : [])]), send);
600
+ }
601
+ /** Whether the saved server `row` (named `name`) is a per-run Composio server (composio-made.ts composioPerRun). */
602
+ async perRunComposio(name, row) {
603
+ return composioPerRun(row, await this.store.settings.get(composioMadeKey(name)));
584
604
  }
585
605
  /** 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
586
606
  * it): a github_app server anywhere but GitHub's hosted MCP (GITHUB_MCP_ONLY, as withAppToken says), and at it, as it
@@ -653,7 +673,8 @@ export class McpServersOverStore {
653
673
  return "credential" in open && open.credential.type === "oauth" ? open.credential.set : undefined;
654
674
  }
655
675
  /** A saved Composio preset server's key (its sealed x-api-key), the Composio user its address names (`user_id`, the
656
- * preset's default when none) and its toolkit: what its Composio triggers are made with (composio-triggers.ts). Refused
676
+ * preset's default when none), its toolkit and the auth config its save recorded (composio-made.ts; none for a server
677
+ * saved before that was recorded): what its Composio triggers are made with (composio-triggers.ts). Refused
657
678
  * when `name` is no such server: on the trigger's `source.server` at its create (`field`), as a 404 on the server's own
658
679
  * routes (`route`). The key goes only to Composio. */
659
680
  async composioOf(name, refusal) {
@@ -666,11 +687,16 @@ export class McpServersOverStore {
666
687
  throw refuse(`${name} is not a Composio server: only one saved with Settings → MCP servers → Composio makes Composio triggers.`);
667
688
  if (!toolkit)
668
689
  throw refuse(`${name} is a Composio server of no toolkit this server can name: save it again with its toolkit's slug.`);
690
+ const recorded = await this.store.settings.get(composioMadeKey(name));
691
+ // A trigger runs as one Composio account, and a per-run server has none: each run names its own.
692
+ if (refusal === "field" && composioPerRun(row, recorded))
693
+ throw refuse(`${name} takes its Composio account from each run (saved with user_id "${COMPOSIO_PER_RUN}"), and a trigger runs as one account: save a Composio server for that account to make its triggers.`);
669
694
  const { headers } = await this.opened(name, row, refusal === "field" ? "source.server" : "api_key");
670
695
  const key = Object.entries(headers).find(([header]) => header.toLowerCase() === "x-api-key")?.[1];
671
696
  if (!key)
672
697
  throw refuse(`${name}'s saved credential holds no Composio key: save it again with its key.`);
673
- return { key, user: new URL(row.url).searchParams.get("user_id") || COMPOSIO_USER, toolkit };
698
+ const config = recordedMade(recorded, row.createdAt)?.auth_config?.id;
699
+ return { key, user: new URL(row.url).searchParams.get("user_id") || COMPOSIO_USER, toolkit, ...(config ? { auth_config: config } : {}) };
674
700
  }
675
701
  /** What the saved server `row` is, for a template's apply to match (mcp-sources.ts sourceOf): github on the GitHub App's
676
702
  * tokens, else its record, else url with none. */
@@ -769,10 +795,10 @@ function grantProblemsOf(env, server, tool) {
769
795
  /** Which save of a server this is: a PUT or a sign-in makes a new one (its updated time moves), a refresh of its tools or
770
796
  * token does not change the url. The staleness key an OAuth sign-in carries from start to callback. */
771
797
  const saving = (row) => `${row.url} ${row.updatedAt}`;
772
- /** The env that says this server is a local install (cli.ts), the one kind an MCP server may be on loopback for. */
773
- export const MCP_ALLOW_LOOPBACK_ENV = "AGENTRUN_MCP_ALLOW_LOOPBACK";
774
- /** What a URL on loopback says on a server that is not one, with how to make it one. */
775
- export const loopbackWords = (host) => `${host} is this machine; set ${MCP_ALLOW_LOOPBACK_ENV}=1 when starting the server, only on a machine you alone use.`;
798
+ export { MCP_ALLOW_LOOPBACK_ENV };
799
+ /** 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
800
+ * it takes (start-switches.ts). */
801
+ export const loopbackWords = (host) => `${host} is this machine; ${restartToAllow(MCP_ALLOW_LOOPBACK_ENV)}.`;
776
802
  /** The owner's MCP registry over the one store. No load() is needed: every read goes to the store (the runner also writes
777
803
  * the OAuth state), so a read is always current. */
778
804
  export function mcpServersOverStore(store, env, version, network) {
@@ -33,5 +33,6 @@ export declare function likelyModel(env: NodeJS.ProcessEnv, harness: string, giv
33
33
  export declare function modelFormWhy(env: NodeJS.ProcessEnv, harness: string, named: string, host: boolean): string;
34
34
  /** "On pi, a model is <provider>/<model id>, like A or B": the forms this server can run, each of the harness's first
35
35
  * vendor's everyday model, the vendor's own and OpenRouter's. Only the forms a key here runs; with neither key both, since
36
- * either key makes one run. */
36
+ * either key makes one run. A harness billed to its own plan (Cursor: its wire `plan`, so no vendor of ours) takes its
37
+ * own form, `<harness>/<model id>`, a model its vendor lists for its owner's key, like its own default. */
37
38
  export declare function modelShape(env: NodeJS.ProcessEnv, harness: string): string;
@@ -5,9 +5,12 @@
5
5
  import { adapterFactsOf } from "./adapter-facts.js";
6
6
  import { FAUX_ENV, MODEL_KEYS } from "./model.js";
7
7
  import { openRouterName } from "./provider.js";
8
- import { WIRES } from "./wires.js";
8
+ import { wireOf } from "./wires.js";
9
9
  import { PLAN_PROVIDER, planOf, signedIn } from "./chatgpt-plan.js";
10
10
  import { PLAN_HARNESSES } from "./harness.js";
11
+ // The default a harness billed to its own plan is named by (Cursor's, the one such harness: `cursor/default`). Already in
12
+ // any process that loads model.ts (whose harness table imports it), so no module is added to its graph.
13
+ import { CURSOR_DEFAULT_MODEL } from "./harness-cursor.js";
11
14
  /** The current models a person may pick, by vendor, in the vendor's own ids (Anthropic's dashes; OpenRouter's dotted name
12
15
  * for the same model is derived, provider.ts openRouterName). The everyday model first: it is the example a refusal gives.
13
16
  * A candidate a harness cannot run on this server (one pi-ai's catalog does not list) is dropped before it is served
@@ -17,10 +20,14 @@ export const PICKABLE = Object.freeze([
17
20
  { vendor: "openai", ids: Object.freeze(["gpt-6.1-sol", "gpt-6.1-terra", "gpt-6-luna"]) },
18
21
  { vendor: "particle", ids: Object.freeze(["particle-1"]) },
19
22
  ]);
20
- /** The vendors whose models `harness` runs: pi any; an adapter harness, its wire's vendor. */
23
+ /** The vendors whose models `harness` runs: pi any; an adapter harness, its wire's vendor; one billed to its own plan, none
24
+ * of ours. */
21
25
  const vendorsOf = (harness) => {
22
26
  const facts = adapterFactsOf(harness);
23
- return facts ? [WIRES[facts.wire].vendor] : PICKABLE.map((p) => p.vendor);
27
+ if (!facts)
28
+ return PICKABLE.map((p) => p.vendor);
29
+ const settings = wireOf(facts.wire);
30
+ return settings ? [settings.vendor] : [];
24
31
  };
25
32
  /** `vendor`'s model `id` in the form this server runs it: `vendor/id` on the vendor's own key, or through OpenRouter
26
33
  * (`openrouter/vendor/id`, Anthropic's id in OpenRouter's dotted name) when OpenRouter's key is the only one here. */
@@ -34,11 +41,13 @@ export function formOf(env, vendor, id) {
34
41
  * (harness.ts harnessOffers drops those it does not run). Behind serve's gateway every id is the gateway's own string, so
35
42
  * the host's tier models stand for what it runs; with the faux model none is offered. */
36
43
  export function pickerCandidates(env, harness) {
37
- if (env[FAUX_ENV])
44
+ // A harness billed to its own plan (Cursor) runs its vendor's models, listed by its vendor for its owner's key alone: its
45
+ // entry's default is offered (harness.ts harnessOffers' default_model), and none of ours.
46
+ const facts = adapterFactsOf(harness);
47
+ if (env[FAUX_ENV] || (facts && !wireOf(facts.wire)))
38
48
  return [];
39
49
  // The gateway serves the harnesses whose wire goes through it (pi, and the OpenAI Responses wire: providerFor); the
40
50
  // Anthropic Messages wire never does, so Claude is offered Anthropic's models on its own key.
41
- const facts = adapterFactsOf(harness);
42
51
  if (env.AGENT_MODEL_BASE_URL && facts?.wire !== "anthropic-messages")
43
52
  return [...new Set([env.AGENT_MODEL, env.AGENT_MODEL_FAST, env.AGENT_MODEL_STRONG].filter((id) => Boolean(id)))];
44
53
  const vendors = vendorsOf(harness);
@@ -86,11 +95,16 @@ export function modelFormWhy(env, harness, named, host) {
86
95
  }
87
96
  /** "On pi, a model is <provider>/<model id>, like A or B": the forms this server can run, each of the harness's first
88
97
  * vendor's everyday model, the vendor's own and OpenRouter's. Only the forms a key here runs; with neither key both, since
89
- * either key makes one run. */
98
+ * either key makes one run. A harness billed to its own plan (Cursor: its wire `plan`, so no vendor of ours) takes its
99
+ * own form, `<harness>/<model id>`, a model its vendor lists for its owner's key, like its own default. */
90
100
  export function modelShape(env, harness) {
101
+ const facts = adapterFactsOf(harness);
91
102
  const first = PICKABLE.find((p) => vendorsOf(harness).includes(p.vendor));
92
- const id = first.ids[0];
93
- const own = Boolean(env[MODEL_KEYS.find((r) => r.id === first.vendor).field]);
103
+ const id = first?.ids[0];
104
+ if (!first || !id)
105
+ return `On ${harness}, a model is ${harness}/<model id> (one ${facts?.label ?? harness} lists for your key), like ${harness}/${CURSOR_DEFAULT_MODEL}`;
106
+ const key = MODEL_KEYS.find((r) => r.id === first.vendor)?.field;
107
+ const own = Boolean(key && env[key]);
94
108
  const router = Boolean(env.OPENROUTER_API_KEY);
95
109
  const shown = [...(own || !router ? [`${first.vendor}/${id}`] : []), ...(router || !own ? [`openrouter/${first.vendor}/${first.vendor === "anthropic" ? openRouterName(id) : id}`] : [])];
96
110
  return `On ${harness}, a model is <provider>/<model id>, like ${shown.join(" or ")}`;
@@ -0,0 +1,113 @@
1
+ import { type KeyEnv } from "./key-meta.js";
2
+ import { type Tier } from "./model.js";
3
+ import { type SecretMeta } from "./secret-writes.js";
4
+ import type { SealedKeys, Settings } from "./store/index.js";
5
+ /** The routes, by their operation names. */
6
+ export declare const MODEL_GATEWAY_ROUTES: ReadonlySet<string>;
7
+ /** The settings row: the address, the id style and the models. */
8
+ export declare const GATEWAY_SETTING = "model_gateway";
9
+ /** The sealed-key row of the gateway's key: never AGENT_MODEL_API_KEY's name, so nothing that reads a key by that name
10
+ * (a run's claim, the environment's gateway) opens it. Only withSavedGateway hands it on, with its own address. */
11
+ export declare const GATEWAY_KEY_ROW = "model_gateway.api_key";
12
+ /** How the gateway takes the ids a revision or a provider key's default names: whole (`as_named`, `openai/gpt-x`), or
13
+ * `bare`, the part after the provider (AGENT_MODEL_GATEWAY_IDS=bare). The tiers' own models go as saved either way. */
14
+ export declare const GATEWAY_IDS: readonly ["as_named", "bare"];
15
+ export type GatewayIds = (typeof GATEWAY_IDS)[number];
16
+ /** How long the test waits for the gateway, and how many ids it lists. */
17
+ export declare const TEST_TIMEOUT_MS = 10000;
18
+ /** The most of the gateway's answer to the test that is read: a list of MAX_LISTED models is far smaller. */
19
+ export declare const MAX_TEST_BYTES: number;
20
+ /** The saved row. */
21
+ export type GatewaySetting = {
22
+ v: 1;
23
+ base_url: string;
24
+ ids: GatewayIds;
25
+ models: Partial<Record<Tier, string>>;
26
+ };
27
+ /** The saved gateway with its key opened (none saved, or one that does not open: none). */
28
+ export type SavedGateway = GatewaySetting & {
29
+ key?: string;
30
+ };
31
+ /** The key's name in every secret's view (secret-writes.ts SecretMeta). */
32
+ export declare const GATEWAY_SECRET: string;
33
+ /** The row as saved, or undefined when there is none (or it is not one this reads). */
34
+ export declare function gatewaySettingOf(settings: Pick<Settings, "get">): Promise<GatewaySetting | undefined>;
35
+ /** The secrets of the key's row as opened, for the scan of every stored secret (runner/store-secrets.ts): the key itself,
36
+ * which is what a gateway's reply or a tool's output could quote, never the JSON it is sealed in alone. A row not of
37
+ * this shape is one secret whole. */
38
+ export declare const gatewayKeyRowSecrets: (opened: string) => string[];
39
+ /** The saved gateway with its key opened under `sealKey`, or undefined when none is saved. The key is there only when it
40
+ * was saved for the address's origin: none without a seal key, one that does not open, or one saved for another origin
41
+ * (an address changed while this read, or a save that failed between its two writes). */
42
+ export declare function readSavedGateway(store: {
43
+ readonly settings: Pick<Settings, "get">;
44
+ readonly sealedKeys: Pick<SealedKeys, "get">;
45
+ }, sealKey: Buffer | undefined): Promise<SavedGateway | undefined>;
46
+ /** Whether the environment AgentRun started with names its own gateway: then it is the one in force, whole. */
47
+ export declare const envGatewayInForce: (env: KeyEnv) => boolean;
48
+ /** Whether `env`'s gateway is the one saved in the console. */
49
+ export declare const savedGatewayIn: (env: NodeJS.ProcessEnv) => boolean;
50
+ /** The plain variable a runner sets on a run's own process (run-child-host.ts) whose gateway is the one saved in the
51
+ * console: that process holds no seal key and reads no store row of the gateway, so its runner lays the gateway over the
52
+ * claim and hands its key over the secrets' pipe, and this says the gateway is the saved one (savedGatewayIn), so its
53
+ * key stays off the run's tools there too. Not a secret. */
54
+ export declare const SAVED_GATEWAY_ENV = "AGENTRUN_MODEL_GATEWAY_SAVED";
55
+ /** `env` (a run's own process's, its runner having laid the saved gateway over it) marked as the saved gateway's, without
56
+ * SAVED_GATEWAY_ENV; `env` itself where that variable is not set. A copy, every property of `env` as it is. */
57
+ export declare function savedGatewayMarked<E extends NodeJS.ProcessEnv>(env: E): E;
58
+ /**
59
+ * `env` with the saved gateway laid over it, as the variables would set it: AGENT_MODEL_BASE_URL, its key as
60
+ * AGENT_MODEL_API_KEY (non-enumerable; empty where none is saved, so a key the environment holds for no address never goes
61
+ * to this one), and AGENT_MODEL_GATEWAY_IDS and each tier's model where the environment sets none. `env` itself where
62
+ * nothing is saved or the environment names its own gateway (envGatewayInForce). A copy, every property of `env` as it is
63
+ * (non-enumerable secrets and symbols too), never `env` changed.
64
+ */
65
+ export declare function withSavedGateway<E extends NodeJS.ProcessEnv>(env: E, saved: SavedGateway | undefined): E;
66
+ /** GET /v2/settings/model-gateway. `source`: the gateway in force, the environment's (`env`), the console's (`console`),
67
+ * or none (`null`: the provider keys are). `set_at_start`: the variables of these fields set where AgentRun starts, which
68
+ * win, read-only here. `problem`: why the gateway in force runs no model (an address the one rule refuses), else null. */
69
+ export type GatewayView = {
70
+ source: "env" | "console" | null;
71
+ base_url: string | null;
72
+ ids: GatewayIds;
73
+ models: Record<Tier, string | null>;
74
+ set_at_start: string[];
75
+ secret: SecretMeta;
76
+ problem: string | null;
77
+ };
78
+ /** What the test answers: the model ids the gateway lists, or why it could not be asked, in words. */
79
+ export type GatewayTest = {
80
+ ok: true;
81
+ models: string[];
82
+ } | {
83
+ ok: false;
84
+ why: string;
85
+ };
86
+ /** What the routes need of the server: its store, its seal key, the environment it started with (never a saved key), and
87
+ * `changed`, its reading made again after a save or a removal. `fetch` is the test's (a test's fake, else the global). */
88
+ export type ModelGatewayDeps = {
89
+ readonly store: {
90
+ readonly settings: Pick<Settings, "get" | "put" | "remove">;
91
+ readonly sealedKeys: Pick<SealedKeys, "get" | "put" | "remove" | "all">;
92
+ flush(): Promise<void>;
93
+ };
94
+ readonly sealKey: Buffer;
95
+ readonly env: KeyEnv;
96
+ readonly changed: () => Promise<void>;
97
+ readonly fetch?: typeof fetch;
98
+ };
99
+ export declare function gatewayView({ store, env }: Pick<ModelGatewayDeps, "store" | "env">): Promise<GatewayView>;
100
+ /** PUT: the gateway saved, once every field is right; nothing is saved when one is not. No message holds the key. */
101
+ export declare function saveGateway(deps: ModelGatewayDeps, body: unknown): Promise<GatewayView>;
102
+ /** DELETE: the gateway and its key gone; the provider keys are in force again. */
103
+ export declare function removeGateway(deps: ModelGatewayDeps): Promise<GatewayView>;
104
+ /** POST /test: the model ids the gateway lists at GET <base>/v1/models, asked with its key. The body may name an address
105
+ * and a key not saved yet (the form's), else the gateway in force is asked with its own. A saved key goes only to the
106
+ * origin it was saved for; the environment's key only to the environment's gateway. No redirect is followed, and the
107
+ * answer never holds the key. */
108
+ export declare function testGateway(deps: ModelGatewayDeps, body: unknown, signal?: AbortSignal): Promise<GatewayTest>;
109
+ /** One of the routes at its handler: its answer (sent 200), or an ApiError. */
110
+ export declare function modelGatewayRoute(deps: ModelGatewayDeps, name: string, request: {
111
+ readonly body?: unknown;
112
+ readonly signal?: AbortSignal;
113
+ }): Promise<unknown>;