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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (224) hide show
  1. package/CHANGELOG.md +138 -3
  2. package/README.md +346 -99
  3. package/dist/adapters.d.ts +10 -0
  4. package/dist/adapters.js +46 -0
  5. package/dist/agent-package.d.ts +3 -3
  6. package/dist/agent-package.js +7 -14
  7. package/dist/agent-rows.d.ts +1 -1
  8. package/dist/agents-store.js +7 -6
  9. package/dist/api-only.d.ts +17 -6
  10. package/dist/api-only.js +22 -9
  11. package/dist/cli.js +11 -4
  12. package/dist/composio-made.d.ts +26 -1
  13. package/dist/composio-made.js +39 -2
  14. package/dist/composio-preset.d.ts +6 -4
  15. package/dist/composio-preset.js +50 -17
  16. package/dist/computer-held-routes.js +2 -3
  17. package/dist/computer-needs.d.ts +1 -1
  18. package/dist/computer-needs.js +1 -1
  19. package/dist/computer-setting.d.ts +8 -4
  20. package/dist/computer-setting.js +0 -2
  21. package/dist/computers-running.d.ts +8 -0
  22. package/dist/computers-running.js +27 -0
  23. package/dist/computers.d.ts +0 -2
  24. package/dist/computers.js +1 -1
  25. package/dist/console/assets/backend-D5EmB4N3.js +166 -0
  26. package/dist/console/assets/index-DUYLaqiR.js +746 -0
  27. package/dist/console/assets/index-DYhU4adm.css +1 -0
  28. package/dist/console/index.html +2 -2
  29. package/dist/docker-host-addresses.d.ts +23 -3
  30. package/dist/docker-host-addresses.js +90 -18
  31. package/dist/errors.d.ts +4 -0
  32. package/dist/errors.js +7 -0
  33. package/dist/exa-keyless.d.ts +2 -3
  34. package/dist/exa-keyless.js +43 -127
  35. package/dist/firecrawl-keyless.d.ts +41 -0
  36. package/dist/firecrawl-keyless.js +152 -0
  37. package/dist/github-connection.d.ts +50 -1
  38. package/dist/github-connection.js +96 -3
  39. package/dist/github-faux.d.ts +11 -2
  40. package/dist/github-faux.js +138 -7
  41. package/dist/github-pull-request.d.ts +37 -0
  42. package/dist/github-pull-request.js +110 -0
  43. package/dist/handed-secret.d.ts +3 -1
  44. package/dist/handed-secret.js +4 -2
  45. package/dist/harness-keys.d.ts +98 -0
  46. package/dist/harness-keys.js +247 -0
  47. package/dist/harness-recipe-entry.d.ts +14 -9
  48. package/dist/harness-recipe-entry.js +25 -14
  49. package/dist/harness-table.d.ts +16 -1
  50. package/dist/harness-table.js +19 -7
  51. package/dist/harness.d.ts +4 -0
  52. package/dist/harness.js +12 -1
  53. package/dist/host-check.d.ts +2 -0
  54. package/dist/host-check.js +6 -0
  55. package/dist/import-summary.d.ts +1 -1
  56. package/dist/import-summary.js +1 -1
  57. package/dist/import.d.ts +5 -5
  58. package/dist/import.js +54 -67
  59. package/dist/keyless-mcp.d.ts +36 -0
  60. package/dist/keyless-mcp.js +127 -0
  61. package/dist/learn/audit.d.ts +3 -3
  62. package/dist/learn/audit.js +3 -3
  63. package/dist/learn/commit.d.ts +8 -7
  64. package/dist/learn/commit.js +60 -20
  65. package/dist/learn/compile.d.ts +4 -3
  66. package/dist/learn/compile.js +7 -5
  67. package/dist/learn/folder.d.ts +16 -3
  68. package/dist/learn/folder.js +46 -13
  69. package/dist/learn/promote.d.ts +37 -13
  70. package/dist/learn/promote.js +112 -40
  71. package/dist/learn/secrets.js +10 -2
  72. package/dist/learning-routes.d.ts +22 -17
  73. package/dist/learning-routes.js +40 -39
  74. package/dist/learning.js +2 -2
  75. package/dist/live-reach.d.ts +34 -7
  76. package/dist/live-reach.js +76 -11
  77. package/dist/manifest.d.ts +10 -0
  78. package/dist/manifest.js +30 -0
  79. package/dist/mcp-pin-first.d.ts +4 -2
  80. package/dist/mcp-pin-first.js +5 -2
  81. package/dist/mcp-probe.js +2 -2
  82. package/dist/mcp-secret-writes.d.ts +16 -7
  83. package/dist/mcp-secret-writes.js +35 -27
  84. package/dist/mcp-servers-store.d.ts +30 -6
  85. package/dist/mcp-servers-store.js +112 -28
  86. package/dist/mcp-sources.d.ts +10 -2
  87. package/dist/mcp-sources.js +9 -2
  88. package/dist/mcp-store.d.ts +13 -7
  89. package/dist/mcp-store.js +12 -9
  90. package/dist/model-form.d.ts +3 -2
  91. package/dist/model-form.js +11 -7
  92. package/dist/model.d.ts +20 -4
  93. package/dist/model.js +68 -9
  94. package/dist/native/history.d.ts +1 -1
  95. package/dist/native/history.js +2 -2
  96. package/dist/ollama-provider.d.ts +92 -0
  97. package/dist/ollama-provider.js +495 -0
  98. package/dist/openapi/agentrun-v2.openapi.json +2 -2
  99. package/dist/openapi.js +235 -41
  100. package/dist/page.d.ts +11 -3
  101. package/dist/page.js +22 -7
  102. package/dist/place-offers.d.ts +17 -1
  103. package/dist/place-offers.js +46 -5
  104. package/dist/print.js +1 -1
  105. package/dist/purged-workflow.d.ts +35 -7
  106. package/dist/purged-workflow.js +73 -26
  107. package/dist/run-computer.d.ts +2 -0
  108. package/dist/run-computer.js +2 -0
  109. package/dist/run-files.d.ts +4 -0
  110. package/dist/run-files.js +4 -0
  111. package/dist/run-keys.d.ts +2 -4
  112. package/dist/run-keys.js +6 -7
  113. package/dist/run-launch.d.ts +4 -0
  114. package/dist/run-launch.js +4 -0
  115. package/dist/run-reads-over-store.d.ts +3 -2
  116. package/dist/run-reads-over-store.js +66 -2
  117. package/dist/run-secrets.js +5 -2
  118. package/dist/runner/adapter-loop.d.ts +6 -3
  119. package/dist/runner/adapter-loop.js +34 -15
  120. package/dist/runner/adapter-run-spec.d.ts +3 -0
  121. package/dist/runner/adapter-run-spec.js +6 -4
  122. package/dist/runner/audit.js +8 -4
  123. package/dist/runner/beside.d.ts +2 -1
  124. package/dist/runner/beside.js +6 -2
  125. package/dist/runner/claim-secrets.d.ts +5 -8
  126. package/dist/runner/claim-secrets.js +6 -0
  127. package/dist/runner/cli-run-spec.d.ts +1 -1
  128. package/dist/runner/cli-run-spec.js +39 -7
  129. package/dist/runner/harness-loops.d.ts +22 -9
  130. package/dist/runner/harness-loops.js +21 -11
  131. package/dist/runner/held.d.ts +3 -0
  132. package/dist/runner/learning-end.d.ts +1 -1
  133. package/dist/runner/learning-end.js +8 -3
  134. package/dist/runner/loop-contract.d.ts +5 -4
  135. package/dist/runner/main.js +4 -2
  136. package/dist/runner/mcp-claim.d.ts +3 -0
  137. package/dist/runner/mcp-claim.js +26 -2
  138. package/dist/runner/mcp-run.d.ts +3 -0
  139. package/dist/runner/mcp-run.js +2 -1
  140. package/dist/runner/metrics.d.ts +10 -8
  141. package/dist/runner/metrics.js +20 -27
  142. package/dist/runner/model-route.d.ts +3 -0
  143. package/dist/runner/model-route.js +6 -2
  144. package/dist/runner/pr-checkout.d.ts +21 -4
  145. package/dist/runner/pr-checkout.js +103 -4
  146. package/dist/runner/promotion.d.ts +15 -9
  147. package/dist/runner/promotion.js +25 -15
  148. package/dist/runner/run-child-host.js +24 -11
  149. package/dist/runner/run-child.js +3 -1
  150. package/dist/runner/runner-check.d.ts +3 -0
  151. package/dist/runner/runner-check.js +23 -0
  152. package/dist/runner/sdk-loop.js +2 -0
  153. package/dist/runner/workflow-loop.d.ts +2 -2
  154. package/dist/runner/workflow-loop.js +1 -2
  155. package/dist/runner/workflow-spec.d.ts +1 -1
  156. package/dist/runner/workflow-spec.js +6 -6
  157. package/dist/sdk/check.d.ts +4 -1
  158. package/dist/sdk/check.js +2 -1
  159. package/dist/sdk/runs.d.ts +2 -2
  160. package/dist/sdk/runs.js +8 -6
  161. package/dist/secret-cut.js +2 -1
  162. package/dist/secret-writes.d.ts +3 -2
  163. package/dist/secret-writes.js +1 -1
  164. package/dist/server.d.ts +55 -8
  165. package/dist/server.js +363 -118
  166. package/dist/standard-webhooks.d.ts +11 -0
  167. package/dist/standard-webhooks.js +20 -2
  168. package/dist/store/agent-body.d.ts +2 -2
  169. package/dist/store/agent-body.js +2 -2
  170. package/dist/store/index.d.ts +1 -1
  171. package/dist/store/schema.js +5 -2
  172. package/dist/store/sqlite/store.js +90 -34
  173. package/dist/store/store.d.ts +54 -14
  174. package/dist/store-reads/journal.d.ts +7 -2
  175. package/dist/store-reads/journal.js +9 -6
  176. package/dist/store-reads/learning.d.ts +12 -9
  177. package/dist/store-reads/learning.js +18 -24
  178. package/dist/store-view.d.ts +0 -5
  179. package/dist/store-view.js +9 -8
  180. package/dist/suggestions.d.ts +282 -0
  181. package/dist/suggestions.js +919 -0
  182. package/dist/telemetry.d.ts +8 -1
  183. package/dist/telemetry.js +12 -4
  184. package/dist/template-eval.d.ts +49 -4
  185. package/dist/template-eval.js +168 -45
  186. package/dist/template-import.d.ts +17 -0
  187. package/dist/template-import.js +36 -2
  188. package/dist/templates.d.ts +83 -76
  189. package/dist/templates.js +29 -48
  190. package/dist/timeline/labels.d.ts +2 -2
  191. package/dist/timeline/labels.js +2 -2
  192. package/dist/timeline/timeline.d.ts +2 -2
  193. package/dist/timeline/timeline.js +1 -1
  194. package/dist/tool-plane.d.ts +17 -9
  195. package/dist/tool-plane.js +38 -17
  196. package/dist/tools.js +2 -2
  197. package/dist/trigger-launch-hook.d.ts +19 -9
  198. package/dist/trigger-launch-hook.js +35 -25
  199. package/dist/trigger-targets.d.ts +18 -8
  200. package/dist/trigger-targets.js +42 -19
  201. package/dist/triggers.d.ts +85 -23
  202. package/dist/triggers.js +303 -96
  203. package/dist/validate.d.ts +1 -1
  204. package/dist/validate.js +2 -2
  205. package/dist/web-fake.js +3 -3
  206. package/dist/web-fetch-direct.d.ts +4 -0
  207. package/dist/web-fetch-direct.js +8 -1
  208. package/dist/web-fetch.d.ts +12 -3
  209. package/dist/web-fetch.js +47 -14
  210. package/dist/web-search.d.ts +33 -4
  211. package/dist/web-search.js +100 -41
  212. package/dist/webhooks.js +4 -5
  213. package/dist/workspace/synced-folder.d.ts +1 -1
  214. package/dist/workspace/synced-folder.js +11 -14
  215. package/launcher/agentrun-serve +5 -1
  216. package/package.json +17 -13
  217. package/templates/README.md +5 -4
  218. package/templates/agent-scout/agent.md +46 -0
  219. package/templates/agent-scout/skills/scout/SKILL.md +88 -0
  220. package/templates/agent-scout/skills/scout/suggestions.schema.json +112 -0
  221. package/dist/console/assets/index-BFgyZzF_.js +0 -734
  222. package/dist/console/assets/index-DbilxljH.css +0 -1
  223. package/dist/import-sources.d.ts +0 -116
  224. package/dist/import-sources.js +0 -693
@@ -4,21 +4,27 @@
4
4
  // adapter, no auth type, no key row of its own: after the save a Composio server is a saved MCP server, gated and
5
5
  // metered like every other. The four meta tools Composio adds (serve/src/mcp-meta.ts) stay refused; the helper actions
6
6
  // that connect an account are left off the server's address. The key goes only to Composio and into the sealed header: it
7
- // is never logged, echoed or put in an error.
7
+ // is never logged, echoed or put in an error. A save may name it instead by a variable of the server's environment
8
+ // (`api_key_env`, COMPOSIO_API_KEY only, a secret the launcher hands the server and each runner over its pipe): the server
9
+ // then keeps the name, seals nothing, and reads the value at each use (composio-made.ts composioKeyFromEnv).
8
10
  import { randomBytes } from "node:crypto";
11
+ import { COMPOSIO_KEY_ENV, COMPOSIO_ORIGIN, composioKeyFromEnv } from "./composio-made.js";
9
12
  import { ApiError, invalid } from "./errors.js";
10
13
  import { priceValid } from "./mcp-probe.js";
11
14
  import { MCP_SERVER_NAME } from "./tool-names.js";
12
- import { isObject } from "./validate.js";
13
- const BASE = "https://backend.composio.dev";
15
+ import { isObject, unknownFields } from "./validate.js";
16
+ const BASE = COMPOSIO_ORIGIN;
17
+ /** The fields a Composio save takes (composioSave): no `url`, no `headers`. */
18
+ const SAVE_FIELDS = ["api_key", "api_key_env", "toolkit", "tools", "user_id", "auth_config_id", "price_usd"];
14
19
  /** The one Composio user a server's actions run as, unless the owner names another. */
15
20
  export const COMPOSIO_USER = "agentrun";
16
21
  /** A Composio toolkit's slug, as a save takes it once trimmed and lower-cased. */
17
22
  export const COMPOSIO_TOOLKIT = /^[a-z0-9][a-z0-9_-]{0,63}$/;
18
23
  const TOOLKIT = COMPOSIO_TOOLKIT;
19
- /** A Composio user id, as a save's `user_id` and a run's binding (mcp_auth's composio_user_id) take it. A `:` is taken:
20
- * a host names a team's connected accounts by a user such as `team:<tenant>`. */
24
+ /** A Composio user id, as a save's `user_id` and a run's binding take it. */
21
25
  export const COMPOSIO_USER_ID = /^[A-Za-z0-9._@:-]{1,128}$/;
26
+ /** COMPOSIO_USER_ID in words, for the messages that refuse a user id. */
27
+ export const COMPOSIO_USER_ID_WORDS = "letters, digits and . _ @ : - (1 to 128)";
22
28
  const USER_ID = COMPOSIO_USER_ID;
23
29
  /** The `user_id` a save names for a per-run server, reserved for that and never a Composio user: the server keeps no user
24
30
  * and no connected account, and each run names its own (mcp_auth.<server> = {composio_user_id, connected_account_id?}). */
@@ -92,20 +98,38 @@ export function asking(control, key, signal, outcome = "nothing was saved", seal
92
98
  throw new ApiError("upstream_failed", `Composio failed while ${step} (${res.status}): ${outcome}.`);
93
99
  };
94
100
  }
95
- /** The key and toolkit of a body, checked. */
96
- function head(body) {
101
+ /** The key and toolkit of a body, checked. The key is the body's `api_key`, or, where `keyEnv` is taken (a save), the value
102
+ * of the variable its `api_key_env` names: COMPOSIO_KEY_ENV only, so no other secret of the server's environment is sent
103
+ * to Composio. `keyEnv` in the answer: the key came from there. */
104
+ function head(body, { keyEnv = false } = {}) {
97
105
  if (!isObject(body))
98
- throw invalid([issue("body", "invalid", "The body is {api_key, toolkit}.")]);
99
- const key = typeof body.api_key === "string" ? body.api_key.trim() : "";
106
+ throw invalid([issue("body", "invalid", `The body is {${keyEnv ? "api_key or api_key_env" : "api_key"}, toolkit}.`)]);
100
107
  const toolkit = typeof body.toolkit === "string" ? body.toolkit.trim().toLowerCase() : "";
101
108
  const issues = [];
102
- if (!key || key.length > 8192)
103
- issues.push(issue("api_key", "missing", "Send your Composio API key."));
109
+ let key = "";
110
+ let named;
111
+ if (keyEnv && body.api_key_env !== undefined) {
112
+ if (body.api_key !== undefined)
113
+ issues.push(issue("api_key_env", "not_allowed", "Send api_key or api_key_env, not both."));
114
+ else if (body.api_key_env !== COMPOSIO_KEY_ENV)
115
+ issues.push(issue("api_key_env", "invalid", `api_key_env names the variable the key is read from, and only ${COMPOSIO_KEY_ENV} is taken.`));
116
+ else {
117
+ named = COMPOSIO_KEY_ENV;
118
+ key = composioKeyFromEnv(named) ?? "";
119
+ if (!key)
120
+ issues.push(issue("api_key_env", "missing", `${COMPOSIO_KEY_ENV} is not set where AgentRun runs: set it to your Composio API key, then save again.`));
121
+ }
122
+ }
123
+ else {
124
+ key = typeof body.api_key === "string" ? body.api_key.trim() : "";
125
+ if (!key || key.length > 8192)
126
+ issues.push(issue("api_key", "missing", keyEnv ? `Send your Composio API key, or api_key_env: "${COMPOSIO_KEY_ENV}" to read it from the server's environment.` : "Send your Composio API key."));
127
+ }
104
128
  if (!TOOLKIT.test(toolkit))
105
129
  issues.push(issue("toolkit", "invalid", "Send the toolkit's slug as Composio names it (github, slack, gmail...)."));
106
130
  if (issues.length)
107
131
  throw invalid(issues);
108
- return { key, toolkit, rest: body };
132
+ return { key, toolkit, rest: body, ...(named ? { keyEnv: named } : {}) };
109
133
  }
110
134
  /** Whether a toolkit needs no sign-in. Composio's answer for one toolkit has no `no_auth` field (only its toolkit list
111
135
  * does): it says so as every auth mode in `auth_config_details` being NO_AUTH. */
@@ -186,9 +210,17 @@ export const composioRunQuery = (binding) => ({ [ADDRESS_USER]: binding.user_id,
186
210
  * the owner has, a custom OAuth app's say: read first, and refused unless it is this toolkit's and enabled), else the
187
211
  * toolkit's Composio-managed one, found or made. `save` gets what the server stands on there too (`stands`,
188
212
  * composio-made.ts): the auth config found or made and the account found or started, each marked whether this save made
189
- * it, for its delete to remove what was made. */
213
+ * it, for its delete to remove what was made. The key is the body's `api_key`, or COMPOSIO_API_KEY's value when the body
214
+ * sends `api_key_env` (head): then `stands.key_env` names it, and the store seals no credential. */
190
215
  export async function composioSave(body, control, save, name, signal, savedUrl) {
191
- const { key, toolkit, rest } = head(body);
216
+ // No address and no headers of the caller's own: Composio makes the server and answers its address, and the key is the
217
+ // one header sent. Any field the save does not take is refused before anything is sent, never ignored.
218
+ if (isObject(body)) {
219
+ const extra = unknownFields(body, SAVE_FIELDS);
220
+ if (extra.length)
221
+ throw invalid(extra);
222
+ }
223
+ const { key, toolkit, rest, keyEnv } = head(body, { keyEnv: true });
192
224
  const tools = Array.isArray(rest.tools) ? rest.tools : [];
193
225
  const user = rest.user_id === undefined ? COMPOSIO_USER : typeof rest.user_id === "string" ? rest.user_id : "";
194
226
  const price = rest.price_usd;
@@ -197,7 +229,7 @@ export async function composioSave(body, control, save, name, signal, savedUrl)
197
229
  if (!tools.length || tools.length > MAX_TOOLS || !tools.every((t) => typeof t === "string" && t && t.length <= MAX_SLUG))
198
230
  issues.push(issue("tools", "invalid", `Send the slugs of the actions to grant: 1 to ${MAX_TOOLS} of them, each at most ${MAX_SLUG} characters.`));
199
231
  if (!USER_ID.test(user))
200
- issues.push(issue("user_id", "invalid", `A user_id is letters, digits and . _ @ : - (at most 128), or "${COMPOSIO_PER_RUN}" for a server each run names its own account for.`));
232
+ issues.push(issue("user_id", "invalid", `A user_id is ${COMPOSIO_USER_ID_WORDS}, or "${COMPOSIO_PER_RUN}" for a server each run names its own account for.`));
201
233
  if (price !== undefined && !priceValid(price))
202
234
  issues.push(issue("price_usd", "invalid", "price_usd is what each call of the server's actions costs, in USD: a finite number, 0 or more."));
203
235
  if (ownConfig !== undefined && !COMPOSIO_AUTH_CONFIG_ID.test(ownConfig))
@@ -293,8 +325,9 @@ export async function composioSave(body, control, save, name, signal, savedUrl)
293
325
  }
294
326
  }
295
327
  }
296
- // One the owner named is theirs (`named`): never recorded as made here, whoever made it (composio-made.ts).
297
- const stands = { user, auth_config: authConfig ? { id: authConfig, made: madeConfig, ...(ownConfig ? { named: true } : {}) } : null, accounts, ...(perRun ? { per_run: true } : {}) };
328
+ // One the owner named is theirs (`named`): never recorded as made here, whoever made it (composio-made.ts). A key read
329
+ // from the environment (`key_env`): the save lists the tools with it, and the store keeps the variable's name alone.
330
+ const stands = { user, auth_config: authConfig ? { id: authConfig, made: madeConfig, ...(ownConfig ? { named: true } : {}) } : null, accounts, ...(perRun ? { per_run: true } : {}), ...(keyEnv ? { key_env: keyEnv } : {}) };
298
331
  url = composioAddress(address, perRun);
299
332
  // Saved as what it is, a Composio server of this toolkit: a template that needs the toolkit maps to it, whatever its
300
333
  // name. A slug no template can name (mcp:<toolkit>/<tool>: no `_`) is saved as a Composio server of no toolkit.
@@ -12,7 +12,7 @@
12
12
  import { callComputer, callIssues, sendRow, TAKE_MS } from "./computer-channel.js";
13
13
  import { computerHoldOf, entriesOf, runOver } from "./computer-commands.js";
14
14
  import { COMPUTER_RELEASE, COMPUTER_START, heldIn, holdIssues } from "./computer-held.js";
15
- import { computerOfPlace } from "./computer-setting.js";
15
+ import { settingOfDefinition } from "./computer-setting.js";
16
16
  import { ApiError, invalid } from "./errors.js";
17
17
  import { runComputerField } from "./run-computer.js";
18
18
  import { readLaunchBody } from "./run-launch.js";
@@ -43,8 +43,7 @@ export async function heldField(store, runId, options = {}) {
43
43
  * read at most once, and not at all for a run that neither can be taken over nor holds. `view` is the run read so far. */
44
44
  export async function runComputerRead(store, runId, view, options = {}) {
45
45
  const run = await store.runs.get(runId);
46
- const body = run ? (await store.agents.revision(run.revisionId))?.body : undefined;
47
- const setting = body?.computer ?? (body?.place ? computerOfPlace(body.place) : undefined);
46
+ const setting = run ? settingOfDefinition(((await store.agents.revision(run.revisionId))?.body ?? {}))?.computer : undefined;
48
47
  if (!setting)
49
48
  return {};
50
49
  const error = view.error;
@@ -24,7 +24,7 @@ export type NeedsAnswer = {
24
24
  export declare function missingNeeds(client: ComputerClient, needs: readonly string[], signal?: AbortSignal): Promise<NeedsAnswer>;
25
25
  /** How to give the Docker box an image that has what a sandbox needs. */
26
26
  export declare const DOCKER_IMAGE_FIX = "Set AGENTRUN_DOCKER_IMAGE to an image that has them and restart the server. For video (chrome, ffmpeg, ffprobe, hyperframes), build the media image: docker build -t agentrun-media:<first 12 hex of its sha256> - < packages/computer/media/Dockerfile, and name that tag. For decks, documents and sheets (python-pptx, python-docx, openpyxl, pptxgenjs, docx, exceljs), build the documents image: docker build -t agentrun-documents:<first 12 hex of the sha256 of its Dockerfile and documents.sh> packages/computer/documents, and name that tag.";
27
- /** The words a run ends with when its setting needs programs but is no sandbox (`what`: "none", "a desktop on E2B"):
27
+ /** The words a run ends with when its setting has needs but is no sandbox (`what`: "none", "a desktop on E2B"):
28
28
  * only a sandbox's box is checked for them, so nothing ran. The validator keeps needs to a sandbox; a stored body and a
29
29
  * launch's computer are read as given, so the claim refuses this too, never running without them. */
30
30
  export declare function needsNoSandboxWords(needs: readonly string[], what: string): string;
@@ -63,7 +63,7 @@ function fixFor(entry) {
63
63
  return `Set ${entry.imageEnv} to an image of ${entry.label}'s that has them and restart the server, or run this agent on the Docker box with an image that has them (AGENTRUN_DOCKER_IMAGE).`;
64
64
  return `Give this agent a computer whose image has them: on the Docker box, set AGENTRUN_DOCKER_IMAGE to such an image (the media image, ${MEDIA_RECIPE_PATH}, has chrome, ffmpeg, ffprobe and hyperframes).`;
65
65
  }
66
- /** The words a run ends with when its setting needs programs but is no sandbox (`what`: "none", "a desktop on E2B"):
66
+ /** The words a run ends with when its setting has needs but is no sandbox (`what`: "none", "a desktop on E2B"):
67
67
  * only a sandbox's box is checked for them, so nothing ran. The validator keeps needs to a sandbox; a stored body and a
68
68
  * launch's computer are read as given, so the claim refuses this too, never running without them. */
69
69
  export function needsNoSandboxWords(needs, what) {
@@ -48,8 +48,10 @@ export declare const gpuOf: (computer: {
48
48
  export declare const kindSettings: (kind: ComputerKind) => string[];
49
49
  /** Whether a run of a kind can record its screen on this server (GET /v2/computers' `record`), and why not, in words. */
50
50
  export type RecordView = {
51
- available: boolean;
52
- why?: string;
51
+ available: true;
52
+ } | {
53
+ available: false;
54
+ why: string;
53
55
  };
54
56
  /** Whether a run of `kind` can record its screen here: the kind takes record (OPTIONAL's record.kinds) and ffmpeg is on
55
57
  * `path` (recorderMissing, the server's PATH now when absent), as a save of record: true is checked. */
@@ -71,10 +73,12 @@ export declare const sameComputer: (a: ComputerSetting, b: ComputerSetting) => b
71
73
  export declare function computerIssues(value: unknown, field: string): InputIssue[];
72
74
  /** The setting and its place a definition says, from `computer` or `place` (both: they must agree), or undefined when
73
75
  * it says neither. Each is checked already (computerIssues, placeIssues). */
74
- export declare function settingOfDefinition(definition: {
76
+ /** What settingOfDefinition reads of a definition or a stored revision body. */
77
+ export type Definition = {
75
78
  computer?: unknown;
76
79
  place?: unknown;
77
- }): {
80
+ };
81
+ export declare function settingOfDefinition(definition: Definition): {
78
82
  computer: ComputerSetting;
79
83
  place: PlaceView;
80
84
  } | undefined;
@@ -155,8 +155,6 @@ function persistenceIssues(kind, provider, image, field) {
155
155
  fix: `Remove ${field}, or pick a computer that keeps one (GET /v2/computers shows which do).`,
156
156
  }];
157
157
  }
158
- /** The setting and its place a definition says, from `computer` or `place` (both: they must agree), or undefined when
159
- * it says neither. Each is checked already (computerIssues, placeIssues). */
160
158
  export function settingOfDefinition(definition) {
161
159
  if (isObject(definition.computer)) {
162
160
  const computer = definition.computer;
@@ -0,0 +1,8 @@
1
+ import type { Store } from "./store/index.js";
2
+ /** GET /v2/computers/running's answer: the runs still going whose agent has a computer, newest first, each read by
3
+ * `read` (the run as GET /v2/runs/{run_id} answers it; undefined for a run gone meanwhile). A run is listed once though
4
+ * it moves from one state's rows to the next while they are listed, and one whose computer ended or failed since is
5
+ * left out. */
6
+ export declare function runningComputers(store: Pick<Store, "runs" | "agents">, read: (runId: string) => Promise<Record<string, unknown> | undefined>): Promise<{
7
+ runs: Record<string, unknown>[];
8
+ }>;
@@ -0,0 +1,27 @@
1
+ // GET /v2/computers/running: every run still going whose agent has a computer, each as GET /v2/runs/{run_id} answers
2
+ // it. The runs list reads run rows alone and carries no computer, so this is the one read of the computers up across
3
+ // runs and agents. A run whose agent has no computer is passed over before its read, so the list costs one run read for
4
+ // each going run that has a computer and nothing for the rest.
5
+ import { settingOfDefinition } from "./computer-setting.js";
6
+ import { COMPUTER_UP } from "./run-computer.js";
7
+ /** Every state a run's row is in while the run is still going: typed against the store's, so a new one is added here. */
8
+ const GOING = Object.keys({ queued: true, running: true, parked: true });
9
+ /** GET /v2/computers/running's answer: the runs still going whose agent has a computer, newest first, each read by
10
+ * `read` (the run as GET /v2/runs/{run_id} answers it; undefined for a run gone meanwhile). A run is listed once though
11
+ * it moves from one state's rows to the next while they are listed, and one whose computer ended or failed since is
12
+ * left out. */
13
+ export async function runningComputers(store, read) {
14
+ const going = new Map();
15
+ for (const state of GOING)
16
+ for (const row of await store.runs.list({ state }))
17
+ going.set(row.id, row.revisionId);
18
+ const computerOf = new Map();
19
+ const hasComputer = (revisionId) => {
20
+ if (!computerOf.has(revisionId))
21
+ computerOf.set(revisionId, store.agents.revision(revisionId).then((revision) => (settingOfDefinition((revision?.body ?? {}))?.computer.kind ?? "none") !== "none"));
22
+ return computerOf.get(revisionId);
23
+ };
24
+ const reads = await Promise.all([...going].map(async ([runId, revisionId]) => ((await hasComputer(revisionId)) ? read(runId) : undefined)));
25
+ const runs = reads.filter((run) => COMPUTER_UP.has(run?.computer?.state));
26
+ return { runs: runs.sort((a, b) => String(b.created_at).localeCompare(String(a.created_at))) };
27
+ }
@@ -56,8 +56,6 @@ export interface ComputerRoutesOptions {
56
56
  * relays each socket to it, so a dial provider's runs can use it and its row says nothing. Read once per view and per
57
57
  * test. Absent: none does. A paired computer's socket is never relayed. */
58
58
  readonly relayed?: () => Promise<boolean>;
59
- /** The PATH a kind's `record` looks for ffmpeg on. Absent: the server's, read at each view, as a save's check reads it. */
60
- readonly path?: string;
61
59
  }
62
60
  /** A provider as Settings shows it: `metered` straight from the kind registry (its computers are billed by the vendor);
63
61
  * its keys as SecretMeta under `secrets`, each named "computer:<provider>:<KEY>", and `required`, the names of the ones
package/dist/computers.js CHANGED
@@ -194,7 +194,7 @@ export function createComputerRoutes(options) {
194
194
  const why = offered ? undefined
195
195
  : serving.length && serving.every(refusedOpen) ? `every provider of a ${kind} computer needs a network, and this server's ${BOX_ALLOW_ENV} is none (no network)`
196
196
  : serving.length ? `no provider of a ${kind} computer can reach this server's run folders` : `no provider serves a ${kind} computer`;
197
- return { kind, offered, ...(why ? { why } : {}), groups: [...spec.required, ...spec.optional], tools: [...tools(kind)], settings: kindSettings(kind), record: recordOf(kind, options.path), providers, ...(kind === "none" ? choice({ kind: "none" }) : {}) };
197
+ return { kind, offered, ...(why ? { why } : {}), groups: [...spec.required, ...spec.optional], tools: [...tools(kind)], settings: kindSettings(kind), record: recordOf(kind, options.env?.PATH), providers, ...(kind === "none" ? choice({ kind: "none" }) : {}) };
198
198
  }),
199
199
  paired,
200
200
  };