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

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 (234) hide show
  1. package/CHANGELOG.md +142 -2
  2. package/README.md +310 -98
  3. package/dist/adapters.d.ts +11 -0
  4. package/dist/adapters.js +49 -0
  5. package/dist/agent-package.d.ts +3 -3
  6. package/dist/agent-package.js +6 -13
  7. package/dist/agents-store.js +6 -5
  8. package/dist/answer-json.d.ts +6 -2
  9. package/dist/answer-json.js +22 -4
  10. package/dist/api-only.d.ts +16 -4
  11. package/dist/api-only.js +23 -7
  12. package/dist/calendar/tools.js +3 -2
  13. package/dist/chatgpt-plan.d.ts +16 -1
  14. package/dist/chatgpt-plan.js +116 -12
  15. package/dist/claude-login.d.ts +34 -5
  16. package/dist/claude-login.js +31 -7
  17. package/dist/claude-sign-in.d.ts +35 -0
  18. package/dist/claude-sign-in.js +90 -0
  19. package/dist/cli.js +5 -3
  20. package/dist/composio-made.d.ts +26 -1
  21. package/dist/composio-made.js +39 -2
  22. package/dist/composio-preset.d.ts +3 -2
  23. package/dist/composio-preset.js +46 -14
  24. package/dist/computer-held-routes.js +2 -3
  25. package/dist/computer-setting.d.ts +4 -2
  26. package/dist/computer-setting.js +0 -2
  27. package/dist/computers-running.d.ts +8 -0
  28. package/dist/computers-running.js +27 -0
  29. package/dist/console/assets/backend-Boh7tC4i.js +166 -0
  30. package/dist/console/assets/index-CQ3cJRzI.js +746 -0
  31. package/dist/console/assets/index-DKkaS3a0.css +1 -0
  32. package/dist/console/index.html +2 -2
  33. package/dist/docker-host-addresses.d.ts +23 -3
  34. package/dist/docker-host-addresses.js +90 -18
  35. package/dist/exa-keyless.d.ts +2 -3
  36. package/dist/exa-keyless.js +43 -127
  37. package/dist/firecrawl-keyless.d.ts +41 -0
  38. package/dist/firecrawl-keyless.js +152 -0
  39. package/dist/handed-secret.d.ts +3 -1
  40. package/dist/handed-secret.js +4 -2
  41. package/dist/harness-keys.d.ts +98 -0
  42. package/dist/harness-keys.js +247 -0
  43. package/dist/harness-recipe-entry.d.ts +14 -9
  44. package/dist/harness-recipe-entry.js +25 -14
  45. package/dist/harness-table.d.ts +16 -1
  46. package/dist/harness-table.js +19 -7
  47. package/dist/harness.d.ts +4 -0
  48. package/dist/harness.js +12 -1
  49. package/dist/host-check.d.ts +6 -0
  50. package/dist/host-check.js +10 -0
  51. package/dist/import-summary.d.ts +1 -1
  52. package/dist/import-summary.js +1 -1
  53. package/dist/import.d.ts +5 -5
  54. package/dist/import.js +54 -67
  55. package/dist/key-refusal.d.ts +21 -5
  56. package/dist/key-refusal.js +231 -37
  57. package/dist/keyless-mcp.d.ts +36 -0
  58. package/dist/keyless-mcp.js +127 -0
  59. package/dist/learn/audit.d.ts +3 -3
  60. package/dist/learn/audit.js +3 -3
  61. package/dist/learn/commit.d.ts +8 -7
  62. package/dist/learn/commit.js +60 -20
  63. package/dist/learn/compile.d.ts +4 -3
  64. package/dist/learn/compile.js +7 -5
  65. package/dist/learn/folder.d.ts +16 -3
  66. package/dist/learn/folder.js +46 -13
  67. package/dist/learn/promote.d.ts +37 -13
  68. package/dist/learn/promote.js +112 -40
  69. package/dist/learn/secrets.d.ts +20 -10
  70. package/dist/learn/secrets.js +44 -176
  71. package/dist/learning-routes.d.ts +22 -17
  72. package/dist/learning-routes.js +40 -39
  73. package/dist/learning.js +2 -2
  74. package/dist/llms.txt +1 -1
  75. package/dist/manifest.d.ts +10 -0
  76. package/dist/manifest.js +30 -0
  77. package/dist/mcp-pin-first.d.ts +4 -2
  78. package/dist/mcp-pin-first.js +5 -2
  79. package/dist/mcp-secret-writes.d.ts +16 -7
  80. package/dist/mcp-secret-writes.js +35 -27
  81. package/dist/mcp-servers-store.d.ts +30 -6
  82. package/dist/mcp-servers-store.js +112 -28
  83. package/dist/mcp-sources.d.ts +10 -2
  84. package/dist/mcp-sources.js +9 -2
  85. package/dist/mcp-store.d.ts +13 -7
  86. package/dist/mcp-store.js +12 -9
  87. package/dist/model-form.d.ts +3 -2
  88. package/dist/model-form.js +11 -7
  89. package/dist/model.d.ts +20 -4
  90. package/dist/model.js +68 -9
  91. package/dist/native/history.d.ts +1 -1
  92. package/dist/native/history.js +2 -2
  93. package/dist/ollama-provider.d.ts +92 -0
  94. package/dist/ollama-provider.js +495 -0
  95. package/dist/openapi/agentrun-v2.openapi.json +2 -2
  96. package/dist/openapi.d.ts +3 -3
  97. package/dist/openapi.js +197 -55
  98. package/dist/page.d.ts +11 -3
  99. package/dist/page.js +22 -7
  100. package/dist/place-offers.d.ts +25 -1
  101. package/dist/place-offers.js +62 -8
  102. package/dist/print.js +1 -1
  103. package/dist/purged-workflow.d.ts +35 -7
  104. package/dist/purged-workflow.js +73 -26
  105. package/dist/redact/match.d.ts +74 -0
  106. package/dist/redact/match.js +771 -0
  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/run-timeline-served.d.ts +1 -1
  119. package/dist/run-timeline-served.js +4 -4
  120. package/dist/runner/adapter-loop.d.ts +9 -3
  121. package/dist/runner/adapter-loop.js +34 -15
  122. package/dist/runner/adapter-run-spec.d.ts +3 -0
  123. package/dist/runner/adapter-run-spec.js +9 -4
  124. package/dist/runner/audit.js +8 -4
  125. package/dist/runner/beside.d.ts +2 -1
  126. package/dist/runner/beside.js +13 -5
  127. package/dist/runner/claim-secrets.d.ts +5 -8
  128. package/dist/runner/claim-secrets.js +6 -0
  129. package/dist/runner/cli-run-spec.d.ts +1 -1
  130. package/dist/runner/cli-run-spec.js +41 -7
  131. package/dist/runner/harness-loops.d.ts +22 -9
  132. package/dist/runner/harness-loops.js +21 -11
  133. package/dist/runner/held.d.ts +3 -0
  134. package/dist/runner/learning-end.d.ts +1 -1
  135. package/dist/runner/learning-end.js +8 -3
  136. package/dist/runner/loop-contract.d.ts +9 -4
  137. package/dist/runner/main.js +12 -6
  138. package/dist/runner/mcp-claim.d.ts +3 -0
  139. package/dist/runner/mcp-claim.js +26 -2
  140. package/dist/runner/mcp-run.d.ts +3 -0
  141. package/dist/runner/mcp-run.js +2 -1
  142. package/dist/runner/metrics.d.ts +10 -10
  143. package/dist/runner/metrics.js +19 -38
  144. package/dist/runner/model-route.d.ts +3 -0
  145. package/dist/runner/model-route.js +6 -2
  146. package/dist/runner/presence.d.ts +4 -3
  147. package/dist/runner/presence.js +4 -2
  148. package/dist/runner/promotion.d.ts +15 -9
  149. package/dist/runner/promotion.js +25 -15
  150. package/dist/runner/run-child-host.d.ts +2 -0
  151. package/dist/runner/run-child-host.js +19 -9
  152. package/dist/runner/run-child.js +3 -1
  153. package/dist/runner/runner.d.ts +4 -0
  154. package/dist/runner/runner.js +33 -3
  155. package/dist/runner/sdk-loop.js +2 -0
  156. package/dist/runner/workflow-loop.d.ts +2 -2
  157. package/dist/runner/workflow-loop.js +1 -2
  158. package/dist/runner/workflow-spec.d.ts +1 -1
  159. package/dist/runner/workflow-spec.js +6 -6
  160. package/dist/sdk/check.d.ts +4 -1
  161. package/dist/sdk/check.js +2 -1
  162. package/dist/sdk/runs.d.ts +2 -2
  163. package/dist/sdk/runs.js +8 -6
  164. package/dist/secret-cut.js +2 -1
  165. package/dist/secret-writes.d.ts +3 -2
  166. package/dist/secret-writes.js +1 -1
  167. package/dist/server.d.ts +49 -10
  168. package/dist/server.js +324 -118
  169. package/dist/standard-webhooks.d.ts +11 -0
  170. package/dist/standard-webhooks.js +20 -2
  171. package/dist/store/dialect.d.ts +3 -0
  172. package/dist/store/dialect.js +1 -0
  173. package/dist/store/index.d.ts +2 -2
  174. package/dist/store/index.js +1 -1
  175. package/dist/store/postgres/dialect.js +3 -0
  176. package/dist/store/schema.js +5 -2
  177. package/dist/store/sqlite/store.js +133 -47
  178. package/dist/store/store.d.ts +64 -15
  179. package/dist/store/store.js +7 -0
  180. package/dist/store-reads/journal.d.ts +7 -2
  181. package/dist/store-reads/journal.js +9 -6
  182. package/dist/store-reads/learning.d.ts +12 -9
  183. package/dist/store-reads/learning.js +18 -24
  184. package/dist/store-view.d.ts +0 -5
  185. package/dist/store-view.js +10 -9
  186. package/dist/template-eval.d.ts +51 -6
  187. package/dist/template-eval.js +177 -53
  188. package/dist/template-import.js +4 -2
  189. package/dist/templates.d.ts +5 -3
  190. package/dist/templates.js +19 -40
  191. package/dist/timeline/index.d.ts +1 -1
  192. package/dist/timeline/index.js +1 -1
  193. package/dist/timeline/labels.d.ts +2 -2
  194. package/dist/timeline/labels.js +2 -2
  195. package/dist/timeline/timeline.d.ts +14 -9
  196. package/dist/timeline/timeline.js +15 -7
  197. package/dist/tool-gate.js +3 -1
  198. package/dist/tool-plane.d.ts +17 -9
  199. package/dist/tool-plane.js +38 -17
  200. package/dist/tools.js +2 -2
  201. package/dist/trigger-launch-hook.d.ts +16 -8
  202. package/dist/trigger-launch-hook.js +32 -23
  203. package/dist/trigger-targets.d.ts +18 -8
  204. package/dist/trigger-targets.js +42 -19
  205. package/dist/triggers.d.ts +85 -23
  206. package/dist/triggers.js +303 -96
  207. package/dist/validate.js +1 -1
  208. package/dist/web-fake.js +3 -3
  209. package/dist/web-fetch-direct.d.ts +4 -0
  210. package/dist/web-fetch-direct.js +8 -1
  211. package/dist/web-fetch.d.ts +12 -3
  212. package/dist/web-fetch.js +47 -14
  213. package/dist/web-search.d.ts +33 -4
  214. package/dist/web-search.js +100 -41
  215. package/dist/webhooks.js +4 -5
  216. package/dist/workspace/computer-deps.d.ts +2 -1
  217. package/dist/workspace/computer-deps.js +5 -4
  218. package/dist/workspace/computer-for-claim.d.ts +8 -2
  219. package/dist/workspace/computer-for-claim.js +28 -9
  220. package/dist/workspace/computer-janitor.d.ts +15 -7
  221. package/dist/workspace/computer-janitor.js +33 -8
  222. package/dist/workspace/computer-kept.d.ts +52 -4
  223. package/dist/workspace/computer-kept.js +118 -6
  224. package/dist/workspace/run-end-computers.d.ts +5 -1
  225. package/dist/workspace/run-end-computers.js +27 -1
  226. package/dist/wrapped.d.ts +57 -0
  227. package/dist/wrapped.js +51 -0
  228. package/launcher/agentrun-serve +5 -1
  229. package/package.json +17 -13
  230. package/templates/README.md +10 -9
  231. package/dist/console/assets/index-B_85An2t.js +0 -745
  232. package/dist/console/assets/index-n1YsbnYh.css +0 -1
  233. package/dist/import-sources.d.ts +0 -116
  234. package/dist/import-sources.js +0 -693
@@ -1,4 +1,4 @@
1
- import type { Cleanup, ComposioMade } from "./composio-made.js";
1
+ import { type Cleanup, type ComposioMade } from "./composio-made.js";
2
2
  import { type InputIssue } from "./errors.js";
3
3
  import { type Json } from "./validate.js";
4
4
  /** Another Composio than the real one, and its fetch: a test's fake (the same seam as `archilControl`). */
@@ -66,7 +66,8 @@ export declare const composioRunQuery: (binding: {
66
66
  * the owner has, a custom OAuth app's say: read first, and refused unless it is this toolkit's and enabled), else the
67
67
  * toolkit's Composio-managed one, found or made. `save` gets what the server stands on there too (`stands`,
68
68
  * composio-made.ts): the auth config found or made and the account found or started, each marked whether this save made
69
- * it, for its delete to remove what was made. */
69
+ * it, for its delete to remove what was made. The key is the body's `api_key`, or COMPOSIO_API_KEY's value when the body
70
+ * sends `api_key_env` (head): then `stands.key_env` names it, and the store seals no credential. */
70
71
  export declare function composioSave<T extends {
71
72
  tools?: readonly {
72
73
  name: string;
@@ -4,13 +4,18 @@
4
4
  // adapter, no auth type, no key row of its own: after the save a Composio server is a saved MCP server, gated and
5
5
  // metered like every other. The four meta tools Composio adds (serve/src/mcp-meta.ts) stay refused; the helper actions
6
6
  // that connect an account are left off the server's address. The key goes only to Composio and into the sealed header: it
7
- // is never logged, echoed or put in an error.
7
+ // is never logged, echoed or put in an error. A save may name it instead by a variable of the server's environment
8
+ // (`api_key_env`, COMPOSIO_API_KEY only, a secret the launcher hands the server and each runner over its pipe): the server
9
+ // then keeps the name, seals nothing, and reads the value at each use (composio-made.ts composioKeyFromEnv).
8
10
  import { randomBytes } from "node:crypto";
11
+ import { COMPOSIO_KEY_ENV, COMPOSIO_ORIGIN, composioKeyFromEnv } from "./composio-made.js";
9
12
  import { ApiError, invalid } from "./errors.js";
10
13
  import { priceValid } from "./mcp-probe.js";
11
14
  import { MCP_SERVER_NAME } from "./tool-names.js";
12
- import { isObject } from "./validate.js";
13
- const BASE = "https://backend.composio.dev";
15
+ import { isObject, unknownFields } from "./validate.js";
16
+ const BASE = COMPOSIO_ORIGIN;
17
+ /** The fields a Composio save takes (composioSave): no `url`, no `headers`. */
18
+ const SAVE_FIELDS = ["api_key", "api_key_env", "toolkit", "tools", "user_id", "auth_config_id", "price_usd"];
14
19
  /** The one Composio user a server's actions run as, unless the owner names another. */
15
20
  export const COMPOSIO_USER = "agentrun";
16
21
  /** A Composio toolkit's slug, as a save takes it once trimmed and lower-cased. */
@@ -93,20 +98,38 @@ export function asking(control, key, signal, outcome = "nothing was saved", seal
93
98
  throw new ApiError("upstream_failed", `Composio failed while ${step} (${res.status}): ${outcome}.`);
94
99
  };
95
100
  }
96
- /** The key and toolkit of a body, checked. */
97
- function head(body) {
101
+ /** The key and toolkit of a body, checked. The key is the body's `api_key`, or, where `keyEnv` is taken (a save), the value
102
+ * of the variable its `api_key_env` names: COMPOSIO_KEY_ENV only, so no other secret of the server's environment is sent
103
+ * to Composio. `keyEnv` in the answer: the key came from there. */
104
+ function head(body, { keyEnv = false } = {}) {
98
105
  if (!isObject(body))
99
- throw invalid([issue("body", "invalid", "The body is {api_key, toolkit}.")]);
100
- const key = typeof body.api_key === "string" ? body.api_key.trim() : "";
106
+ throw invalid([issue("body", "invalid", `The body is {${keyEnv ? "api_key or api_key_env" : "api_key"}, toolkit}.`)]);
101
107
  const toolkit = typeof body.toolkit === "string" ? body.toolkit.trim().toLowerCase() : "";
102
108
  const issues = [];
103
- if (!key || key.length > 8192)
104
- issues.push(issue("api_key", "missing", "Send your Composio API key."));
109
+ let key = "";
110
+ let named;
111
+ if (keyEnv && body.api_key_env !== undefined) {
112
+ if (body.api_key !== undefined)
113
+ issues.push(issue("api_key_env", "not_allowed", "Send api_key or api_key_env, not both."));
114
+ else if (body.api_key_env !== COMPOSIO_KEY_ENV)
115
+ issues.push(issue("api_key_env", "invalid", `api_key_env names the variable the key is read from, and only ${COMPOSIO_KEY_ENV} is taken.`));
116
+ else {
117
+ named = COMPOSIO_KEY_ENV;
118
+ key = composioKeyFromEnv(named) ?? "";
119
+ if (!key)
120
+ issues.push(issue("api_key_env", "missing", `${COMPOSIO_KEY_ENV} is not set where AgentRun runs: set it to your Composio API key, then save again.`));
121
+ }
122
+ }
123
+ else {
124
+ key = typeof body.api_key === "string" ? body.api_key.trim() : "";
125
+ if (!key || key.length > 8192)
126
+ issues.push(issue("api_key", "missing", keyEnv ? `Send your Composio API key, or api_key_env: "${COMPOSIO_KEY_ENV}" to read it from the server's environment.` : "Send your Composio API key."));
127
+ }
105
128
  if (!TOOLKIT.test(toolkit))
106
129
  issues.push(issue("toolkit", "invalid", "Send the toolkit's slug as Composio names it (github, slack, gmail...)."));
107
130
  if (issues.length)
108
131
  throw invalid(issues);
109
- return { key, toolkit, rest: body };
132
+ return { key, toolkit, rest: body, ...(named ? { keyEnv: named } : {}) };
110
133
  }
111
134
  /** Whether a toolkit needs no sign-in. Composio's answer for one toolkit has no `no_auth` field (only its toolkit list
112
135
  * does): it says so as every auth mode in `auth_config_details` being NO_AUTH. */
@@ -187,9 +210,17 @@ export const composioRunQuery = (binding) => ({ [ADDRESS_USER]: binding.user_id,
187
210
  * the owner has, a custom OAuth app's say: read first, and refused unless it is this toolkit's and enabled), else the
188
211
  * toolkit's Composio-managed one, found or made. `save` gets what the server stands on there too (`stands`,
189
212
  * composio-made.ts): the auth config found or made and the account found or started, each marked whether this save made
190
- * it, for its delete to remove what was made. */
213
+ * it, for its delete to remove what was made. The key is the body's `api_key`, or COMPOSIO_API_KEY's value when the body
214
+ * sends `api_key_env` (head): then `stands.key_env` names it, and the store seals no credential. */
191
215
  export async function composioSave(body, control, save, name, signal, savedUrl) {
192
- const { key, toolkit, rest } = head(body);
216
+ // No address and no headers of the caller's own: Composio makes the server and answers its address, and the key is the
217
+ // one header sent. Any field the save does not take is refused before anything is sent, never ignored.
218
+ if (isObject(body)) {
219
+ const extra = unknownFields(body, SAVE_FIELDS);
220
+ if (extra.length)
221
+ throw invalid(extra);
222
+ }
223
+ const { key, toolkit, rest, keyEnv } = head(body, { keyEnv: true });
193
224
  const tools = Array.isArray(rest.tools) ? rest.tools : [];
194
225
  const user = rest.user_id === undefined ? COMPOSIO_USER : typeof rest.user_id === "string" ? rest.user_id : "";
195
226
  const price = rest.price_usd;
@@ -294,8 +325,9 @@ export async function composioSave(body, control, save, name, signal, savedUrl)
294
325
  }
295
326
  }
296
327
  }
297
- // One the owner named is theirs (`named`): never recorded as made here, whoever made it (composio-made.ts).
298
- const stands = { user, auth_config: authConfig ? { id: authConfig, made: madeConfig, ...(ownConfig ? { named: true } : {}) } : null, accounts, ...(perRun ? { per_run: true } : {}) };
328
+ // One the owner named is theirs (`named`): never recorded as made here, whoever made it (composio-made.ts). A key read
329
+ // from the environment (`key_env`): the save lists the tools with it, and the store keeps the variable's name alone.
330
+ const stands = { user, auth_config: authConfig ? { id: authConfig, made: madeConfig, ...(ownConfig ? { named: true } : {}) } : null, accounts, ...(perRun ? { per_run: true } : {}), ...(keyEnv ? { key_env: keyEnv } : {}) };
299
331
  url = composioAddress(address, perRun);
300
332
  // Saved as what it is, a Composio server of this toolkit: a template that needs the toolkit maps to it, whatever its
301
333
  // name. A slug no template can name (mcp:<toolkit>/<tool>: no `_`) is saved as a Composio server of no toolkit.
@@ -12,7 +12,7 @@
12
12
  import { callComputer, callIssues, sendRow, TAKE_MS } from "./computer-channel.js";
13
13
  import { computerHoldOf, entriesOf, runOver } from "./computer-commands.js";
14
14
  import { COMPUTER_RELEASE, COMPUTER_START, heldIn, holdIssues } from "./computer-held.js";
15
- import { computerOfPlace } from "./computer-setting.js";
15
+ import { settingOfDefinition } from "./computer-setting.js";
16
16
  import { ApiError, invalid } from "./errors.js";
17
17
  import { runComputerField } from "./run-computer.js";
18
18
  import { readLaunchBody } from "./run-launch.js";
@@ -43,8 +43,7 @@ export async function heldField(store, runId, options = {}) {
43
43
  * read at most once, and not at all for a run that neither can be taken over nor holds. `view` is the run read so far. */
44
44
  export async function runComputerRead(store, runId, view, options = {}) {
45
45
  const run = await store.runs.get(runId);
46
- const body = run ? (await store.agents.revision(run.revisionId))?.body : undefined;
47
- const setting = body?.computer ?? (body?.place ? computerOfPlace(body.place) : undefined);
46
+ const setting = run ? settingOfDefinition(((await store.agents.revision(run.revisionId))?.body ?? {}))?.computer : undefined;
48
47
  if (!setting)
49
48
  return {};
50
49
  const error = view.error;
@@ -73,10 +73,12 @@ export declare const sameComputer: (a: ComputerSetting, b: ComputerSetting) => b
73
73
  export declare function computerIssues(value: unknown, field: string): InputIssue[];
74
74
  /** The setting and its place a definition says, from `computer` or `place` (both: they must agree), or undefined when
75
75
  * it says neither. Each is checked already (computerIssues, placeIssues). */
76
- export declare function settingOfDefinition(definition: {
76
+ /** What settingOfDefinition reads of a definition or a stored revision body. */
77
+ export type Definition = {
77
78
  computer?: unknown;
78
79
  place?: unknown;
79
- }): {
80
+ };
81
+ export declare function settingOfDefinition(definition: Definition): {
80
82
  computer: ComputerSetting;
81
83
  place: PlaceView;
82
84
  } | undefined;
@@ -155,8 +155,6 @@ function persistenceIssues(kind, provider, image, field) {
155
155
  fix: `Remove ${field}, or pick a computer that keeps one (GET /v2/computers shows which do).`,
156
156
  }];
157
157
  }
158
- /** The setting and its place a definition says, from `computer` or `place` (both: they must agree), or undefined when
159
- * it says neither. Each is checked already (computerIssues, placeIssues). */
160
158
  export function settingOfDefinition(definition) {
161
159
  if (isObject(definition.computer)) {
162
160
  const computer = definition.computer;
@@ -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
+ }