@parcha/agentrun-serve 0.1.0-beta.46 → 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 (247) hide show
  1. package/CHANGELOG.md +164 -1
  2. package/NOTICE +4 -0
  3. package/README.md +267 -40
  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 +109 -41
  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 +24 -4
  70. package/dist/import.js +108 -26
  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 +12 -5
  78. package/dist/learn/promote.d.ts +69 -2
  79. package/dist/learn/promote.js +95 -3
  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-words.d.ts +2 -0
  85. package/dist/learning-words.js +1 -1
  86. package/dist/listen-first.d.ts +10 -0
  87. package/dist/listen-first.js +25 -1
  88. package/dist/llms.txt +1 -1
  89. package/dist/mcp-gateway.d.ts +2 -1
  90. package/dist/mcp-gateway.js +31 -15
  91. package/dist/mcp-probe.d.ts +18 -6
  92. package/dist/mcp-probe.js +41 -8
  93. package/dist/mcp-secret-writes.d.ts +8 -0
  94. package/dist/mcp-secret-writes.js +104 -4
  95. package/dist/mcp-servers-store.d.ts +11 -5
  96. package/dist/mcp-servers-store.js +46 -20
  97. package/dist/model-form.d.ts +2 -1
  98. package/dist/model-form.js +22 -8
  99. package/dist/model-gateway.d.ts +113 -0
  100. package/dist/model-gateway.js +433 -0
  101. package/dist/model.d.ts +2 -1
  102. package/dist/model.js +9 -7
  103. package/dist/monid.js +1 -1
  104. package/dist/native/binding.d.ts +4 -0
  105. package/dist/native/binding.js +9 -0
  106. package/dist/native/cli.d.ts +3 -2
  107. package/dist/native/cli.js +6 -5
  108. package/dist/openapi.d.ts +2 -0
  109. package/dist/openapi.js +322 -39
  110. package/dist/owner.d.ts +4 -2
  111. package/dist/owner.js +10 -4
  112. package/dist/page.d.ts +8 -0
  113. package/dist/page.js +9 -1
  114. package/dist/port-models.js +17 -10
  115. package/dist/provider.d.ts +3 -3
  116. package/dist/provider.js +12 -3
  117. package/dist/public-address.d.ts +28 -0
  118. package/dist/public-address.js +62 -0
  119. package/dist/run-launch.d.ts +1 -1
  120. package/dist/run-launch.js +1 -1
  121. package/dist/run-secrets.d.ts +3 -2
  122. package/dist/run-secrets.js +6 -4
  123. package/dist/runner/adapter-loop.d.ts +10 -7
  124. package/dist/runner/adapter-loop.js +57 -22
  125. package/dist/runner/adapter-run-spec.d.ts +12 -0
  126. package/dist/runner/adapter-run-spec.js +40 -6
  127. package/dist/runner/adapters/index.js +16 -0
  128. package/dist/runner/adapters/pi.d.ts +5 -2
  129. package/dist/runner/adapters/pi.js +7 -4
  130. package/dist/runner/audit.d.ts +7 -0
  131. package/dist/runner/audit.js +15 -6
  132. package/dist/runner/claim-secrets.js +5 -1
  133. package/dist/runner/cli-run-spec.js +15 -7
  134. package/dist/runner/compare-end.d.ts +43 -0
  135. package/dist/runner/compare-end.js +95 -0
  136. package/dist/runner/computer-journal.d.ts +3 -0
  137. package/dist/runner/computer-journal.js +22 -2
  138. package/dist/runner/harness-loops.d.ts +6 -1
  139. package/dist/runner/harness-loops.js +94 -54
  140. package/dist/runner/held.d.ts +5 -4
  141. package/dist/runner/journal-kinds.d.ts +4 -1
  142. package/dist/runner/journal-kinds.js +3 -0
  143. package/dist/runner/loop-contract.d.ts +10 -0
  144. package/dist/runner/main.d.ts +5 -5
  145. package/dist/runner/main.js +62 -11
  146. package/dist/runner/mcp-claim.js +40 -12
  147. package/dist/runner/metrics.d.ts +26 -0
  148. package/dist/runner/metrics.js +44 -1
  149. package/dist/runner/presence.d.ts +41 -0
  150. package/dist/runner/presence.js +89 -0
  151. package/dist/runner/promotion.d.ts +9 -4
  152. package/dist/runner/promotion.js +33 -14
  153. package/dist/runner/run-child-host.js +40 -10
  154. package/dist/runner/runner.d.ts +5 -0
  155. package/dist/runner/runner.js +8 -0
  156. package/dist/runner/store-port.d.ts +3 -0
  157. package/dist/runner/store-secrets.js +19 -7
  158. package/dist/runner/workflow-first.d.ts +5 -2
  159. package/dist/runner/workflow-first.js +6 -3
  160. package/dist/runs-over-store.d.ts +6 -2
  161. package/dist/runs-over-store.js +14 -4
  162. package/dist/sdk/runs.d.ts +1 -1
  163. package/dist/sdk/runs.js +6 -1
  164. package/dist/sdk/schema.js +1 -1
  165. package/dist/secret-writes.d.ts +16 -3
  166. package/dist/secret-writes.js +28 -3
  167. package/dist/server-secrets-store.js +5 -0
  168. package/dist/server.d.ts +31 -2
  169. package/dist/server.js +322 -51
  170. package/dist/sign-ins-secrets.js +4 -1
  171. package/dist/skills/agentrun-serve/SKILL.md +11 -0
  172. package/dist/slack-url.d.ts +5 -0
  173. package/dist/slack-url.js +11 -0
  174. package/dist/slack.d.ts +107 -0
  175. package/dist/slack.js +292 -0
  176. package/dist/start-switches.d.ts +28 -0
  177. package/dist/start-switches.js +37 -0
  178. package/dist/stats.d.ts +1 -1
  179. package/dist/stats.js +2 -1
  180. package/dist/stop-signals.d.ts +11 -0
  181. package/dist/stop-signals.js +22 -0
  182. package/dist/store/agent-body.d.ts +1 -1
  183. package/dist/store/agent-body.js +2 -2
  184. package/dist/store/index.d.ts +3 -3
  185. package/dist/store/index.js +1 -1
  186. package/dist/store/postgres/migrations/0020_runners.sql +18 -0
  187. package/dist/store/postgres/store.d.ts +1 -1
  188. package/dist/store/postgres/store.js +4 -2
  189. package/dist/store/schema.d.ts +13 -5
  190. package/dist/store/schema.js +20 -11
  191. package/dist/store/seal.d.ts +16 -4
  192. package/dist/store/sqlite/store.d.ts +1 -1
  193. package/dist/store/sqlite/store.js +106 -27
  194. package/dist/store/store.d.ts +75 -23
  195. package/dist/store/store.js +11 -0
  196. package/dist/store-reads/analytics.js +3 -2
  197. package/dist/store-reads/cap.d.ts +7 -0
  198. package/dist/store-reads/cap.js +11 -1
  199. package/dist/store-reads/journal.js +27 -1
  200. package/dist/store-reads/learning.d.ts +23 -2
  201. package/dist/store-reads/learning.js +29 -8
  202. package/dist/store-reads/runs.d.ts +9 -0
  203. package/dist/store-reads/runs.js +19 -6
  204. package/dist/store-reads/stats.d.ts +4 -1
  205. package/dist/store-reads/stats.js +15 -6
  206. package/dist/store-view.d.ts +123 -14
  207. package/dist/store-view.js +154 -21
  208. package/dist/telemetry.d.ts +7 -7
  209. package/dist/telemetry.js +38 -15
  210. package/dist/timeline/timeline.js +18 -0
  211. package/dist/tool-keys-store.js +2 -2
  212. package/dist/tool-keys.js +2 -1
  213. package/dist/tool-plane.js +2 -2
  214. package/dist/trigger-adapter.d.ts +3 -4
  215. package/dist/trigger-adapter.js +2 -2
  216. package/dist/trigger-composio.js +3 -3
  217. package/dist/trigger-email.js +0 -2
  218. package/dist/trigger-feed.js +0 -2
  219. package/dist/trigger-schedule.js +3 -0
  220. package/dist/trigger-secrets-shown.d.ts +6 -3
  221. package/dist/trigger-secrets-shown.js +22 -13
  222. package/dist/trigger-targets.d.ts +1 -1
  223. package/dist/trigger-targets.js +19 -8
  224. package/dist/triggers.d.ts +2 -2
  225. package/dist/webhooks.d.ts +82 -8
  226. package/dist/webhooks.js +128 -45
  227. package/dist/wires.d.ts +6 -1
  228. package/dist/wires.js +5 -0
  229. package/dist/workspace/attach.d.ts +3 -2
  230. package/dist/workspace/attach.js +2 -1
  231. package/dist/workspace/attached-computers.d.ts +6 -8
  232. package/dist/workspace/attached-computers.js +27 -24
  233. package/dist/workspace/computer-deps.d.ts +2 -3
  234. package/dist/workspace/computer-deps.js +3 -6
  235. package/dist/workspace/computer-for-claim.js +72 -96
  236. package/dist/workspace/computer-kept.d.ts +0 -7
  237. package/dist/workspace/computer-kept.js +0 -17
  238. package/dist/workspace/resolve-computer.d.ts +18 -14
  239. package/dist/workspace/resolve-computer.js +47 -60
  240. package/dist/workspace/synced-folder.d.ts +20 -15
  241. package/dist/workspace/synced-folder.js +33 -43
  242. package/launcher/agentrun-serve +4 -1
  243. package/package.json +10 -10
  244. package/skills/agentrun-serve/SKILL.md +11 -0
  245. package/templates/README.md +1 -1
  246. package/dist/console/assets/index-C2MYaUBa.css +0 -1
  247. package/dist/console/assets/index-CZZeCReB.js +0 -701
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 {};
@@ -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 ")}`;