@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/webhooks.js CHANGED
@@ -20,6 +20,7 @@ import { ApiError, invalid } from "./errors.js";
20
20
  import { SERVER_SCOPE, sealedSettingsOverStore } from "./sealed-settings-store.js";
21
21
  import { signatureOf } from "./standard-webhooks.js";
22
22
  import { webhookSecretMeta } from "./trigger-secrets-shown.js";
23
+ import { restartToAllow, WEBHOOK_PRIVATE_TARGETS_ENV } from "./start-switches.js";
23
24
  import { isObject, unknownFields } from "./validate.js";
24
25
  /** A run's two notices, which the server's run-change follower tells. */
25
26
  export const RUN_EVENTS = ["run.needs_input", "run.ended"];
@@ -48,13 +49,27 @@ const MAX_URL = 2048;
48
49
  const SECRET_FIELD = "secret";
49
50
  /** Where its secret is kept in trigger_settings (adapter WEBHOOK_CHANNEL): the server's one scope, one minted field. */
50
51
  export const WEBHOOK_SECRET_SPEC = { scope: "server", fields: { [SECRET_FIELD]: { mint: true } } };
52
+ /** The webhook's own: every message type and word as they always were. */
53
+ export const WEBHOOK_OUTBOUND = {
54
+ channel: WEBHOOK_CHANNEL, setting: WEBHOOK_SETTING, spec: WEBHOOK_SECRET_SPEC, field: SECRET_FIELD, testType: "webhook.test",
55
+ words: {
56
+ removed: "the webhook was removed", off: "the webhook is off", unset: "no webhook is set: PUT /v2/settings/webhook sets one",
57
+ offWith: (reason) => `the webhook is off (${reason}): set it again with PUT /v2/settings/webhook`,
58
+ unreadable: "the secret does not open here (unreadable): set the webhook again",
59
+ },
60
+ offCode: "webhook_off",
61
+ };
51
62
  /** How long a try's claim on its message holds (Store.channels.claim): past the try's own bound (TIMEOUT_MS, or the
52
63
  * option's, which the constructor holds under this). */
53
64
  const CLAIM_MS = 60_000;
54
65
  /** Names that are this machine or its own network, whatever they resolve to. */
55
66
  const LOCAL_NAME = /^(localhost|.*\.localhost|.*\.local|.*\.internal)$/i;
56
- /** The words a URL on a private network or this machine is refused in. */
57
- const PRIVATE_WORDS = "url is on a private network or this machine, which this server does not send to";
67
+ /** How a refusal of a private network or this machine is lifted: the operator's switch, at a restart (start-switches.ts). */
68
+ const RESTART_WORDS = restartToAllow(WEBHOOK_PRIVATE_TARGETS_ENV);
69
+ /** The words a URL on a private network or this machine is refused in, at its PUT. */
70
+ const PRIVATE_WORDS = `url is on a private network or this machine, which this server does not send to; ${RESTART_WORDS}`;
71
+ /** The words a try refuses `host` in, when it or an address its name resolves to now is not public. */
72
+ const notPublic = (host) => `refused: ${host} is not a public host; ${RESTART_WORDS}`;
58
73
  /** The webhook's URL as the server shows it (GET, its log): its origin and the last four characters of its path, never
59
74
  * the whole URL, which can be a credential itself (a chat service's incoming-hook URL). */
60
75
  export function shownUrl(url) {
@@ -116,6 +131,7 @@ const attemptView = (row) => ({
116
131
  export class Webhooks {
117
132
  store;
118
133
  say;
134
+ outbound;
119
135
  secrets;
120
136
  config;
121
137
  /** The ledger, by run, as channel_told holds it (this server is its one writer), and the waits seen while nothing is
@@ -152,14 +168,17 @@ export class Webhooks {
152
168
  storeRetryMs;
153
169
  timeoutMs;
154
170
  /** `key` is the server's seal key; `say` takes a log line's fields. */
155
- constructor(store, key, say, options = {}) {
171
+ constructor(store, key, say, options = {},
172
+ /** Which outbox this is: the webhook's (WEBHOOK_OUTBOUND), or another destination's over the same machinery. */
173
+ outbound = WEBHOOK_OUTBOUND) {
156
174
  this.store = store;
157
175
  this.say = say;
176
+ this.outbound = outbound;
158
177
  this.timeoutMs = options.timeoutMs ?? TIMEOUT_MS;
159
178
  // Whole milliseconds: AbortSignal.timeout takes no other, and would throw at every send, after its claim.
160
179
  if (!(Number.isInteger(this.timeoutMs) && this.timeoutMs > 0 && this.timeoutMs < CLAIM_MS))
161
180
  throw new RangeError(`a webhook try's bound is whole milliseconds between 0 and ${CLAIM_MS} (its claim), not ${this.timeoutMs}`);
162
- this.secrets = sealedSettingsOverStore(store, WEBHOOK_CHANNEL, WEBHOOK_SECRET_SPEC, key, say);
181
+ this.secrets = sealedSettingsOverStore(store, outbound.channel, outbound.spec, key, say);
163
182
  this.retryMs = options.retryMs ?? RETRY_MS;
164
183
  this.storeRetryMs = options.storeRetryMs ?? STORE_RETRY_MS;
165
184
  this.privateTargets = options.privateTargets ?? false;
@@ -169,7 +188,7 @@ export class Webhooks {
169
188
  * at its next try's time; a test send is tried once, so one left queued failed. Awaited once at start. */
170
189
  async load() {
171
190
  await this.secrets.load();
172
- const kept = await this.store.settings.get(WEBHOOK_SETTING);
191
+ const kept = await this.store.settings.get(this.outbound.setting);
173
192
  this.config = isObject(kept) && typeof kept.url === "string" && typeof kept.secret_scope === "string" && typeof kept.updated_at === "string" ? kept : undefined;
174
193
  // A secret no setting names (one made by a PUT whose setting never landed, or the one a later PUT replaced and could not
175
194
  // remove) signs nothing: it goes, retired, still cut from what runs say.
@@ -177,7 +196,7 @@ export class Webhooks {
177
196
  if (scope !== this.config?.secret_scope)
178
197
  await this.secrets.remove(scope).catch((error) => this.say({ condition: "secret_unremoved", error: error.message }));
179
198
  }
180
- for (const row of await this.store.channels.told(WEBHOOK_CHANNEL)) {
199
+ for (const row of await this.store.channels.told(this.outbound.channel)) {
181
200
  const noticed = this.notices.get(row.runId) ?? {};
182
201
  if (row.marker.startsWith(ENDED))
183
202
  noticed.ended = row.marker.slice(ENDED.length);
@@ -186,9 +205,9 @@ export class Webhooks {
186
205
  this.notices.set(row.runId, noticed);
187
206
  }
188
207
  // The store's one server (its lock): a claim an earlier server held is that server's try, cut by its stop.
189
- await this.store.channels.release(WEBHOOK_CHANNEL);
190
- for (const post of await this.store.channels.queued(WEBHOOK_CHANNEL)) {
191
- if (post.moment === "webhook.test")
208
+ await this.store.channels.release(this.outbound.channel);
209
+ for (const post of await this.store.channels.queued(this.outbound.channel)) {
210
+ if (post.moment === this.outbound.testType)
192
211
  await this.store.channels.settle(post.id, { state: "dropped", reason: "a test send is tried once" });
193
212
  else
194
213
  this.schedule(post.id, Math.max(0, post.nextAt - Date.now()));
@@ -256,6 +275,36 @@ export class Webhooks {
256
275
  await this.secrets.remove(was.secret_scope).catch((removal) => this.say({ condition: "secret_unremoved", error: removal.message }));
257
276
  return { created: !was, view: this.view(), ...(secret ? { secret } : {}) };
258
277
  }
278
+ /** POST .../secret: a new secret for the URL set now, answered once; the webhook is otherwise as it was (its URL, when
279
+ * it was set, and off if a 410 turned it off). The secret it replaces goes at once, retired (still cut from what a run
280
+ * says): every try from then on, of a message queued before it too, is signed with the new one, since a try signs with
281
+ * the secret the setting names when it sends (tryOnce). A try already sending was signed with the old one. As a PUT
282
+ * does, the new secret is sealed under a scope of its own before the setting that names it is written, and a write
283
+ * that fails leaves the old secret signing, after a restart too. */
284
+ rotate() {
285
+ return this.change(async () => {
286
+ const was = this.config;
287
+ if (!was)
288
+ throw new ApiError("not_found", "no webhook is set: PUT /v2/settings/webhook sets one");
289
+ const scope = `${SERVER_SCOPE}:${randomBytes(8).toString("hex")}`;
290
+ const secret = await this.secrets.mint(scope, SECRET_FIELD);
291
+ try {
292
+ await this.write({ ...was, secret_at: new Date().toISOString(), secret_scope: scope });
293
+ }
294
+ catch (error) {
295
+ // The store may hold the setting that names the new secret (a put that landed, its flush failed). The old setting
296
+ // goes back first, and only once it is durable does the new secret go: the store never names a secret that is gone.
297
+ // If it can't go back, the new secret stays, and the next start removes whichever secret the setting does not name
298
+ // (load).
299
+ const restored = await this.write(was).then(() => true, () => false);
300
+ if (restored)
301
+ await this.secrets.remove(scope).catch((removal) => this.say({ condition: "secret_unremoved", error: removal.message }));
302
+ throw error;
303
+ }
304
+ await this.secrets.remove(was.secret_scope).catch((removal) => this.say({ condition: "secret_unremoved", error: removal.message }));
305
+ return { view: this.view(), secret };
306
+ });
307
+ }
259
308
  /** DELETE: the webhook gone, its queued messages with it, and its secret (retired: still cut from what a run says); the
260
309
  * log of attempts stays. In that order: shut to new notices, its queued messages dropped, the setting removed, then
261
310
  * every secret of the webhook, on every DELETE (none once gone), so a removal of a secret that failed is finished by
@@ -268,8 +317,8 @@ export class Webhooks {
268
317
  // Every message whose write passed the check before the DELETE began lands first (on Postgres another pooled
269
318
  // connection may commit it later): then the drop takes it too, and none outlives the DELETE.
270
319
  await Promise.all([...this.posting]);
271
- await this.drop("the webhook was removed", true);
272
- await this.store.settings.remove(WEBHOOK_SETTING);
320
+ await this.drop(this.outbound.words.removed, true);
321
+ await this.store.settings.remove(this.outbound.setting);
273
322
  await this.store.flush();
274
323
  this.config = undefined;
275
324
  }
@@ -289,7 +338,7 @@ export class Webhooks {
289
338
  }
290
339
  /** GET .../deliveries: the last attempts, newest first. */
291
340
  async attemptsView() {
292
- return { attempts: (await this.store.channels.attempts(WEBHOOK_CHANNEL, ATTEMPTS_KEPT)).map(attemptView) };
341
+ return { attempts: (await this.store.channels.attempts(this.outbound.channel, ATTEMPTS_KEPT)).map(attemptView) };
293
342
  }
294
343
  /** A run's moment, told by the server each time it sees it (a wait reached, an end the store has): queued once, when a
295
344
  * webhook is set and on, with its ledger row in the same transaction. `marker` makes its webhook-id: the same moment,
@@ -317,14 +366,14 @@ export class Webhooks {
317
366
  }
318
367
  if (ends && !this.due(marker, config))
319
368
  return "queued";
320
- const id = `msg_${createHash("sha256").update(`${run.run_id}\n${type}\n${marker}`).digest("hex").slice(0, 32)}`;
369
+ const id = this.messageId(`${run.run_id}\n${type}\n${marker}`);
321
370
  const data = { run_id: run.run_id, agent_id: run.agent_id, agent_name: run.agent_name, status: run.status, title: run.title, url: `${this.base}/#/runs/${encodeURIComponent(run.run_id)}`, ...(run.pending ? { pending: run.pending } : {}) };
322
371
  // A new wait goes beside the run's earlier waits and replaces its end (one after an end is a continued run's, past that
323
372
  // end); an end replaces the run's last end and keeps its waits.
324
373
  const told = ends ? { runId: run.run_id, marker: `${ENDED}${marker}`, replacing: ENDED } : { runId: run.run_id, marker: `${WAIT}${marker}`, replacing: ENDED };
325
374
  let added;
326
375
  try {
327
- added = await this.posted({ id, channel: WEBHOOK_CHANNEL, runId: run.run_id, moment: type, body: this.body(type, data), nextAt: Date.now() }, told);
376
+ added = await this.posted({ id, channel: this.outbound.channel, runId: run.run_id, moment: type, body: this.body(type, data), nextAt: Date.now() }, told);
328
377
  }
329
378
  catch (error) {
330
379
  this.say({ condition: "outbox_unwritable", webhook_id: id, error: error.message });
@@ -333,7 +382,7 @@ export class Webhooks {
333
382
  this.notices.set(run.run_id, ends ? { ...seen, ended: marker } : { waits: kept });
334
383
  // The waits past WAITS_KEPT leave the store's ledger too; one not forgotten now is forgotten with the next.
335
384
  if (!ends && waits.length > kept.length)
336
- await this.store.channels.forget(WEBHOOK_CHANNEL, waits.slice(0, waits.length - kept.length).map((gone) => ({ runId: run.run_id, marker: `${WAIT}${gone}` }))).catch(() => undefined);
385
+ await this.store.channels.forget(this.outbound.channel, waits.slice(0, waits.length - kept.length).map((gone) => ({ runId: run.run_id, marker: `${WAIT}${gone}` }))).catch(() => undefined);
337
386
  await this.prune(config);
338
387
  // A message already there (an earlier telling whose durable commit failed after its write) is armed too, unless it is.
339
388
  if (added || !this.timers.has(id))
@@ -347,9 +396,9 @@ export class Webhooks {
347
396
  return "closed";
348
397
  if (!this.config || this.config.disabled || this.removing)
349
398
  return "off";
350
- const id = `msg_${createHash("sha256").update(`trigger.failed\n${firingKey}`).digest("hex").slice(0, 32)}`;
399
+ const id = this.messageId(`trigger.failed\n${firingKey}`);
351
400
  try {
352
- if ((await this.posted({ id, channel: WEBHOOK_CHANNEL, moment: "trigger.failed", body: this.body("trigger.failed", failed), nextAt: Date.now() })) || !this.timers.has(id))
401
+ if ((await this.posted({ id, channel: this.outbound.channel, moment: "trigger.failed", body: this.body("trigger.failed", failed), nextAt: Date.now() })) || !this.timers.has(id))
353
402
  this.schedule(id, 0);
354
403
  }
355
404
  catch (error) {
@@ -383,7 +432,7 @@ export class Webhooks {
383
432
  forget.push({ runId: id, marker: `${ENDED}${noticed.ended}` });
384
433
  }
385
434
  if (forget.length) {
386
- await this.store.channels.forget(WEBHOOK_CHANNEL, forget);
435
+ await this.store.channels.forget(this.outbound.channel, forget);
387
436
  for (const { runId } of forget) {
388
437
  const noticed = this.notices.get(runId);
389
438
  if (store.has(runId) && noticed?.ended !== undefined)
@@ -410,11 +459,18 @@ export class Webhooks {
410
459
  }
411
460
  return unsaved;
412
461
  }
462
+ /** A moment's message id, made from `key` (the same moment, told again by a later server too, has the same id). The
463
+ * store keeps one message per id across every channel, so another outbox's ids are made under its channel too: Slack's
464
+ * message for a run's end is never the webhook's, whichever is written first. The webhook's ids are as they always were. */
465
+ messageId(key) {
466
+ const made = this.outbound.channel === WEBHOOK_CHANNEL ? key : `${this.outbound.channel}\n${key}`;
467
+ return `msg_${createHash("sha256").update(made).digest("hex").slice(0, 32)}`;
468
+ }
413
469
  /** POST .../test: a `webhook.test` message tried once now, never again; its attempt. */
414
470
  async test() {
415
471
  this.need();
416
472
  const id = `msg_${randomBytes(16).toString("hex")}`;
417
- await this.posted({ id, channel: WEBHOOK_CHANNEL, moment: "webhook.test", body: this.body("webhook.test", {}), nextAt: Date.now() });
473
+ await this.posted({ id, channel: this.outbound.channel, moment: this.outbound.testType, body: this.body(this.outbound.testType, {}), nextAt: Date.now() });
418
474
  return this.attempt(id, { retry: false, redelivery: false });
419
475
  }
420
476
  /** A message (and its ledger row, `told`) queued in one transaction, then made durable (the store's flush, as every write
@@ -435,7 +491,7 @@ export class Webhooks {
435
491
  async redeliver(id) {
436
492
  this.need();
437
493
  const post = await this.store.channels.get(id);
438
- if (!post || post.channel !== WEBHOOK_CHANNEL)
494
+ if (!post || post.channel !== this.outbound.channel)
439
495
  throw new ApiError("not_found", `no message ${id} among the last ${ATTEMPTS_KEPT} attempts`);
440
496
  return this.attempt(id, { retry: false, redelivery: true });
441
497
  }
@@ -478,7 +534,7 @@ export class Webhooks {
478
534
  return {};
479
535
  const host = url.hostname.replace(/^\[|\]$/g, "");
480
536
  if (LOCAL_NAME.test(host))
481
- return { refused: `refused: ${host} is not a public host` };
537
+ return { refused: notPublic(host) };
482
538
  const { isPrivateAddress, pinnedLookup } = await import("@parcha/pi-browser");
483
539
  let addresses;
484
540
  try {
@@ -490,8 +546,11 @@ export class Webhooks {
490
546
  return { refused: signal.reason?.name === "TimeoutError" ? `no answer in ${this.timeoutMs / 1000} s` : "not reached: the server is stopping" };
491
547
  return { refused: `not reached: ${error.code ?? "its name does not resolve"}` };
492
548
  }
493
- if (!addresses.length || addresses.some(isPrivateAddress))
549
+ // A name that resolves to nothing is no switch's refusal: the operator's switch would not reach it either.
550
+ if (!addresses.length)
494
551
  return { refused: `refused: ${host} is not a public host` };
552
+ if (addresses.some(isPrivateAddress))
553
+ return { refused: notPublic(host) };
495
554
  return { dispatcher: new Agent({ connect: { lookup: pinnedLookup(addresses[0]) } }) };
496
555
  }
497
556
  signing() {
@@ -499,18 +558,24 @@ export class Webhooks {
499
558
  }
500
559
  /** The secret the webhook's setting names, opened here; undefined when none is set, or it does not open here. */
501
560
  signingSecret(config = this.config) {
502
- return config ? this.secrets.get(config.secret_scope, SECRET_FIELD) : undefined;
561
+ return config ? this.secrets.get(config.secret_scope, this.outbound.field) : undefined;
503
562
  }
504
563
  body(type, data) {
505
564
  return JSON.stringify({ type, timestamp: new Date().toISOString(), data });
506
565
  }
507
566
  /** The setting written, then held here: a write the store refuses throws, and what was held stays held. */
508
567
  async write(config) {
509
- await this.store.settings.put(WEBHOOK_SETTING, config);
568
+ await this.store.settings.put(this.outbound.setting, config);
510
569
  // Durable before the PUT (or the 410 that turns it off) answers, as the store's other confirmed writes are.
511
570
  await this.store.flush();
512
571
  this.config = config;
513
572
  }
573
+ /** The setting removed, durably, and none held here: a removal the store refuses throws, and what was held stays held. */
574
+ async unwrite() {
575
+ await this.store.settings.remove(this.outbound.setting);
576
+ await this.store.flush();
577
+ this.config = undefined;
578
+ }
514
579
  /** Whether an end's run.ended is still to be queued: at or after the webhook was set and the day began (a marker that
515
580
  * names no time is not judged by one). The catch-up and the ledger's pruning read the same line, so the ledger never
516
581
  * forgets an end a start would look for. */
@@ -525,7 +590,7 @@ export class Webhooks {
525
590
  if (!stale.length)
526
591
  return;
527
592
  try {
528
- await this.store.channels.forget(WEBHOOK_CHANNEL, stale.map(([runId, noticed]) => ({ runId, marker: `${ENDED}${noticed.ended}` })));
593
+ await this.store.channels.forget(this.outbound.channel, stale.map(([runId, noticed]) => ({ runId, marker: `${ENDED}${noticed.ended}` })));
529
594
  }
530
595
  catch {
531
596
  return;
@@ -576,7 +641,7 @@ export class Webhooks {
576
641
  async tryOnce(id, how) {
577
642
  const now = Date.now();
578
643
  const post = await this.store.channels.get(id);
579
- const attempt = { webhook_id: id, type: (post?.moment ?? "webhook.test"), at: iso(now), status_code: null, latency_ms: 0, error: null, retry_at: null, redelivery: how.redelivery };
644
+ const attempt = { webhook_id: id, type: (post?.moment ?? this.outbound.testType), at: iso(now), status_code: null, latency_ms: 0, error: null, retry_at: null, redelivery: how.redelivery };
580
645
  if (this.closed || !post)
581
646
  return attempt;
582
647
  // The try's own id: its claim's token, which fences its outcome's write (settleTry), and its row in the log, once.
@@ -600,16 +665,17 @@ export class Webhooks {
600
665
  // Signed with the secret this setting names: the URL and its secret, as the store holds them together.
601
666
  const secret = this.signingSecret(config);
602
667
  let failure;
668
+ let gone;
603
669
  if (!config)
604
- failure = "the webhook was removed";
670
+ failure = this.outbound.words.removed;
605
671
  else if (config.disabled)
606
- failure = "the webhook is off";
672
+ failure = this.outbound.words.off;
607
673
  else if (secret === undefined)
608
- failure = "the secret does not open here (unreadable): set the webhook again";
674
+ failure = this.outbound.words.unreadable;
609
675
  else {
610
676
  const timestamp = String(Math.floor(now / 1000));
611
677
  const started = performance.now();
612
- const target = new URL(config.url);
678
+ const { url: target, headers } = this.request(config, secret, id, timestamp, post.body);
613
679
  // One bound for the whole try, its name's lookup included, and the server's stop cuts it all (close()).
614
680
  const signal = AbortSignal.any([AbortSignal.timeout(this.timeoutMs), this.stop.signal]);
615
681
  const dial = await this.dialled(target, signal);
@@ -619,14 +685,12 @@ export class Webhooks {
619
685
  try {
620
686
  const res = await undiciFetch(target, {
621
687
  method: "POST", redirect: "manual", signal,
622
- headers: { "content-type": "application/json", "user-agent": "agentrun-serve-webhook/1", "webhook-id": id, "webhook-timestamp": timestamp, "webhook-signature": signatureOf(secret, id, timestamp, post.body) },
688
+ headers,
623
689
  body: post.body,
624
690
  ...(dial.dispatcher ? { dispatcher: dial.dispatcher } : {}),
625
691
  });
626
- await res.body?.cancel().catch(() => undefined);
627
692
  attempt.status_code = res.status;
628
- if (res.status < 200 || res.status > 299)
629
- failure = res.status >= 300 && res.status < 400 ? `answered ${res.status}: a redirect is not followed` : `answered ${res.status}`;
693
+ ({ failure, gone } = await this.judged(res));
630
694
  }
631
695
  catch (error) {
632
696
  failure = error.name === "TimeoutError" ? `no answer in ${this.timeoutMs / 1000} s` : `not reached: ${error.cause?.code ?? error.message}`;
@@ -637,13 +701,30 @@ export class Webhooks {
637
701
  }
638
702
  attempt.latency_ms = Math.round(performance.now() - started);
639
703
  }
704
+ // A failure's words never hold the credential (an outbox whose URL is its credential: Slack's).
705
+ if (failure !== undefined && secret)
706
+ failure = failure.split(secret).join("…");
640
707
  // In its words, written or not: a try the server's stop cut short still says why it ended.
641
708
  attempt.error = failure ?? null;
642
709
  if (this.closed)
643
710
  return attempt;
644
711
  // What the try found is settled against the webhook as it stands once every change asked for before it (a PUT, a
645
712
  // DELETE, another try's 410) has landed: a 410 never turns off a webhook a PUT is setting again meanwhile.
646
- return this.change(() => this.settleTry(id, how, now, tryId, claimed, config, failure, attempt));
713
+ return this.change(() => this.settleTry(id, how, now, tryId, claimed, config, failure, attempt, gone));
714
+ }
715
+ /** What a try sends to (`url`) and with which headers, for the outbox's credential: the webhook's URL, signed with its
716
+ * secret. Slack's outbox sends to its sealed URL (slack.ts). */
717
+ request(config, credential, id, timestamp, body) {
718
+ return { url: new URL(config.url), headers: { "content-type": "application/json", "user-agent": "agentrun-serve-webhook/1", "webhook-id": id, "webhook-timestamp": timestamp, "webhook-signature": signatureOf(credential, id, timestamp, body) } };
719
+ }
720
+ /** What a receiver's answer says: why the try failed (none when it landed), and whether the receiver is gone, which
721
+ * turns the outbox off. The webhook's: 2xx lands; a redirect is not followed; a 410 is gone. */
722
+ async judged(res) {
723
+ await res.body?.cancel().catch(() => undefined);
724
+ if (res.status >= 200 && res.status <= 299)
725
+ return {};
726
+ const failure = res.status >= 300 && res.status < 400 ? `answered ${res.status}: a redirect is not followed` : `answered ${res.status}`;
727
+ return res.status === 410 ? { failure, gone: { reason: "the receiver answered 410 Gone", drop: "the webhook is off: its receiver answered 410" } } : { failure };
647
728
  }
648
729
  /** A try's outcome written: the message's new state and the try, in one transaction; its next try armed; a 410 that
649
730
  * still names the webhook as it stands turns it off.
@@ -653,7 +734,7 @@ export class Webhooks {
653
734
  * holds that claim (Channels.settle), so a write that lands late, after a redelivery sent the message, a newer try
654
735
  * claimed it or a DELETE dropped it, changes nothing and arms nothing. A redelivery claims nothing: a landed one writes
655
736
  * sent, which no try's write undoes (sent is final), and a failed one writes no state at all, only its try. */
656
- async settleTry(id, how, now, tryId, claimed, config, failure, attempt) {
737
+ async settleTry(id, how, now, tryId, claimed, config, failure, attempt, goneBy) {
657
738
  if (this.closed)
658
739
  return attempt;
659
740
  // The schedule counts the message's own tries, from the count its claim took it at; a redelivery counts none.
@@ -661,7 +742,7 @@ export class Webhooks {
661
742
  // A 410 turns off the webhook as this try found it: one set again or removed while the try waited is not its to turn
662
743
  // off, and the 410 is then a failure like any other.
663
744
  const standing = this.config;
664
- const gone = attempt.status_code === 410 && config !== undefined && standing !== undefined && standing.url === config.url && standing.updated_at === config.updated_at && !standing.disabled;
745
+ const gone = goneBy !== undefined && config !== undefined && standing !== undefined && standing.url === config.url && standing.updated_at === config.updated_at && !standing.disabled;
665
746
  let to;
666
747
  let delay;
667
748
  if (attempts === undefined) {
@@ -688,7 +769,7 @@ export class Webhooks {
688
769
  // The same write each time it is tried: its fence and its values fixed here, so one whose outcome is unknown (the store
689
770
  // threw) is written again as it was, and lands once.
690
771
  const write = () => this.store.channels.settle(id, to, row, { kept: ATTEMPTS_KEPT, sending: [...this.sending.keys()], ...(claimed ? { claim: tryId } : {}) });
691
- const after = (written) => this.afterSettle(id, written, to, delay, attempt, attempts, failure, gone, standing);
772
+ const after = (written) => this.afterSettle(id, written, to, delay, attempt, attempts, failure, gone ? goneBy : undefined, standing);
692
773
  let written;
693
774
  try {
694
775
  written = await write();
@@ -722,10 +803,12 @@ export class Webhooks {
722
803
  this.say({ condition: "delivery_failed", type: attempt.type, webhook_id: id, attempts: attempts ?? 0, ...(attempt.status_code !== null ? { status_code: attempt.status_code } : {}), error: failure });
723
804
  }
724
805
  const current = this.config;
725
- const stillGone = gone && standing !== undefined && current !== undefined && !current.disabled && current.url === standing.url && current.secret_scope === standing.secret_scope && current.updated_at === standing.updated_at;
806
+ const stillGone = gone !== undefined && standing !== undefined && current !== undefined && !current.disabled && current.url === standing.url && current.secret_scope === standing.secret_scope && current.updated_at === standing.updated_at;
726
807
  if (stillGone) {
727
- // Gone: the receiver says this endpoint is no more. Off, its queued messages dropped, until a PUT sets it again.
728
- const off = { ...standing, disabled: { at: attempt.at, reason: "the receiver answered 410 Gone" } };
808
+ // Gone: the receiver says this endpoint is no more. Off, its queued messages dropped, until a PUT sets it again. It is
809
+ // the setting as it stands now that goes off (the same URL, secret and cutoff as the try's): a change since that
810
+ // kept those (Slack's events, slack.ts) is kept, never written over by the try's older copy.
811
+ const off = { ...current, disabled: { at: attempt.at, reason: gone.reason } };
729
812
  try {
730
813
  await this.write(off);
731
814
  }
@@ -738,7 +821,7 @@ export class Webhooks {
738
821
  // Every message whose write passed the check before the webhook went off lands first (as a DELETE waits, remove):
739
822
  // then the drop takes it too, and none reaches a receiver a later PUT sets.
740
823
  await Promise.all([...this.posting]);
741
- await this.drop("the webhook is off: its receiver answered 410");
824
+ await this.drop(gone.drop);
742
825
  }
743
826
  }
744
827
  /** A try's write the store refused (`write`), written again after the store's wait until it lands, then what follows it
@@ -778,7 +861,7 @@ export class Webhooks {
778
861
  async drop(why, strict = false) {
779
862
  let count = 0;
780
863
  try {
781
- count = await this.store.channels.dropAll(WEBHOOK_CHANNEL, why);
864
+ count = await this.store.channels.dropAll(this.outbound.channel, why);
782
865
  }
783
866
  catch (error) {
784
867
  // Refused: a DELETE fails with the webhook still set, its messages still queued and their timers kept, so each is
@@ -796,9 +879,9 @@ export class Webhooks {
796
879
  need() {
797
880
  const config = this.config;
798
881
  if (!config)
799
- throw new ApiError("not_found", "no webhook is set: PUT /v2/settings/webhook sets one");
882
+ throw new ApiError("not_found", this.outbound.words.unset);
800
883
  if (config.disabled)
801
- throw new ApiError("webhook_off", `the webhook is off (${config.disabled.reason}): set it again with PUT /v2/settings/webhook`);
884
+ throw new ApiError(this.outbound.offCode, this.outbound.words.offWith(config.disabled.reason));
802
885
  return config;
803
886
  }
804
887
  }
package/dist/wires.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Wire } from "@parcha/agentrun-kernel";
1
+ import type { HarnessWire, Wire } from "@parcha/agentrun-kernel";
2
2
  /** Each wire's own settings: the vendor whose models it runs (a MODEL_KEYS row's id, model.ts), the endpoint a host may
3
3
  * name for it, the vendor's key, and whether it is serve's gateway (AGENT_MODEL_BASE_URL), which pi's models take too and
4
4
  * which runs any id (the gateway's own string, naming no vendor here). */
@@ -9,3 +9,8 @@ export declare const WIRES: Readonly<Record<Wire, {
9
9
  key: string;
10
10
  gateway: boolean;
11
11
  }>>;
12
+ /** Whether a harness's wire is a model wire of ours (WIRES): not "plan", a harness billed to its own vendor's plan
13
+ * (Cursor's), whose requests never reach a route of ours, so it has no vendor, endpoint, key or gateway here. */
14
+ export declare const modelWire: (wire: HarnessWire) => wire is Wire;
15
+ /** A harness's wire's settings, or undefined for one billed to its own plan (modelWire). */
16
+ export declare const wireOf: (wire: HarnessWire) => (typeof WIRES)[Wire] | undefined;
package/dist/wires.js CHANGED
@@ -5,3 +5,8 @@ export const WIRES = Object.freeze({
5
5
  "anthropic-messages": { vendor: "anthropic", label: "Anthropic", base: "ANTHROPIC_BASE_URL", key: "ANTHROPIC_API_KEY", gateway: false },
6
6
  "openai-responses": { vendor: "openai", label: "OpenAI", base: "AGENT_MODEL_BASE_URL", key: "OPENAI_API_KEY", gateway: true },
7
7
  });
8
+ /** Whether a harness's wire is a model wire of ours (WIRES): not "plan", a harness billed to its own vendor's plan
9
+ * (Cursor's), whose requests never reach a route of ours, so it has no vendor, endpoint, key or gateway here. */
10
+ export const modelWire = (wire) => wire !== "plan";
11
+ /** A harness's wire's settings, or undefined for one billed to its own plan (modelWire). */
12
+ export const wireOf = (wire) => (modelWire(wire) ? WIRES[wire] : undefined);
@@ -3,9 +3,10 @@ import { type Workspace } from "./workspace.js";
3
3
  /** What attach runs of D, passed in (the cutover passes D's own): the read-back a mount made as `spec` asks gives, and
4
4
  * the claim's epoch it is read back under (D reads an Archil mount back with the computer's claim epoch; a bind takes
5
5
  * none). `sync`: the claim made the computer a synced folder of the Workspace (resolve-computer.ts), so it reads back
6
- * as one, under the epoch. */
6
+ * as one, under the epoch. `readBackOf` may answer as a promise: a run's own process (run-child.ts) hands its check to
7
+ * the runner's Workspace across the run channel, where a function is a handle whose call is answered later. */
7
8
  export type MountCheck = {
8
- readonly readBackOf: (spec: MountSpec, epoch?: number) => MountReadBack;
9
+ readonly readBackOf: (spec: MountSpec, epoch?: number) => MountReadBack | Promise<MountReadBack>;
9
10
  readonly epoch?: number;
10
11
  readonly sync?: true;
11
12
  };
@@ -436,7 +436,8 @@ export async function checkReadBack(computer, spec, check) {
436
436
  const read = await computer.readBack();
437
437
  if (!read.ok)
438
438
  throw new WorkspaceError("UNAVAILABLE", `the computer ${computer.id} did not say what it mounts at ${MOUNT_AT}: ${read.error.message}`);
439
- const want = check.readBackOf(spec, check.epoch);
439
+ // Awaited: across the run channel the check's readBackOf is a handle, and an unawaited answer reads as no mount at all.
440
+ const want = await check.readBackOf(spec, check.epoch);
440
441
  if (keyOf(read.value) !== keyOf(want)) {
441
442
  throw new WorkspaceError("REFUSED", `the computer ${computer.id} does not hold this run's folder at ${MOUNT_AT}: it mounts ${shown(read.value)}, not ${shown(want)}`);
442
443
  }
@@ -29,20 +29,18 @@ export declare const pairedOf: (row: PairedComputerRow) => PairedComputer;
29
29
  /** What a driver's hello lacks to serve `kind`, by the kind registry's rule (the computer package's SETTING_KINDS, which
30
30
  * servingRefusals reads): "it says desktop but declares no input.pointer, input.keys", "it says android, which no
31
31
  * desktop computer is"; undefined when the hello serves the kind. The one source of a paired computer's words for a
32
- * kind it cannot serve: at pairing (servesNoKind) and at a run's start (withPaired's unservedWhy). */
32
+ * kind it cannot serve: at pairing (servesNoKind) and at a run's start (pairedEntry's unserved). */
33
33
  export declare function helloLacks(hello: Partial<HelloResult>, kind: ComputerSettingKind): string | undefined;
34
34
  /** Why `name`'s driver may not pair: its hello serves no kind an agent's computer can be, so no agent could pick it; in
35
35
  * words that say what it lacks and to update the driver. Undefined when it serves one. */
36
36
  export declare function servesNoKind(name: string, hello: Partial<HelloResult>): string | undefined;
37
37
  /** A paired computer as a provider of `registry`: named by its name and its os, as an agent's computer picker lists it;
38
- * the setting kinds its paired hello serves, no keys, the machine's own network ("open": a run never narrows a person's
39
- * own machine), never metered. A sandbox (a Linux box with files and exec) takes the run's folder as a synced folder
40
- * (the computer package's attachedProvider checks its /workspace); a desktop or a phone takes no mount. */
38
+ * the setting kinds its paired hello serves, why it serves each other one (unserved, pairedUnserved's words), no keys,
39
+ * the machine's own network ("open": a run never narrows a person's own machine), never metered. A sandbox (a Linux box
40
+ * with files and exec) takes the run's folder as a synced folder (the computer package's attachedProvider checks its
41
+ * /workspace); a desktop or a phone takes no mount. */
41
42
  export declare function pairedEntry(row: PairedComputerRow, registry: Pick<KindRegistry, "SETTING_KINDS" | "servingRefusals">): ProviderEntry;
42
- /** `registry` with each paired computer of `rows` as one more provider (pairedEntry), and the words for one that cannot
43
- * serve a kind an agent asks of it: it is a computer of the person's own, and either the attach path carries no such
44
- * kind (ATTACH_CANNOT: a browser), or it is a desktop or a phone asked to be a sandbox (PAIRED_SANDBOX), so the agent
45
- * takes it as the kind it serves, or its driver lacks what the kind needs (helloLacks), so the driver is what to update. */
43
+ /** `registry` with each paired computer of `rows` as one more provider (pairedEntry). */
46
44
  export declare function withPaired<R extends KindRegistry>(registry: R, rows: readonly PairedComputerRow[]): R;
47
45
  /** The provider of the paired computer `row`: attachedProvider over the hub, or a refusal in ONE_PROCESS_WORDS where this
48
46
  * process holds no hub. */
@@ -44,7 +44,7 @@ const PAIRED_SANDBOX = "only a Linux box paired with computerd and no display ca
44
44
  /** What a driver's hello lacks to serve `kind`, by the kind registry's rule (the computer package's SETTING_KINDS, which
45
45
  * servingRefusals reads): "it says desktop but declares no input.pointer, input.keys", "it says android, which no
46
46
  * desktop computer is"; undefined when the hello serves the kind. The one source of a paired computer's words for a
47
- * kind it cannot serve: at pairing (servesNoKind) and at a run's start (withPaired's unservedWhy). */
47
+ * kind it cannot serve: at pairing (servesNoKind) and at a run's start (pairedEntry's unserved). */
48
48
  export function helloLacks(hello, kind) {
49
49
  const spec = SETTING_KINDS[kind];
50
50
  const said = String(hello.kind ?? "nothing");
@@ -69,14 +69,33 @@ export function servesNoKind(name, hello) {
69
69
  const lack = near === undefined ? `it says ${String(hello.kind ?? "nothing")}, which no kind of computer is` : helloLacks(hello, near);
70
70
  return `${name}'s driver serves no kind: ${lack}: update the driver on ${name}`;
71
71
  }
72
+ /** Why the paired computer `row`, which serves `kinds`, gives no computer of `kind`: it is a computer of the person's
73
+ * own, and either the attach path carries no such kind (ATTACH_CANNOT: a browser), or it is a desktop or a phone asked
74
+ * to be a sandbox (PAIRED_SANDBOX), so the agent takes it as the kind it serves, or its driver lacks what the kind needs
75
+ * (helloLacks), so the driver is what to update. Undefined where none of these says why. */
76
+ function pairedUnserved(row, kinds, kind) {
77
+ const as = `give this agent ${row.name} as a ${kinds.join(" or ")} computer`;
78
+ if (kind in ATTACH_CANNOT && kinds.length > 0)
79
+ return `it is a computer of your own, and a paired computer can't be a ${kind} computer yet; ${as}`;
80
+ if (kind === "sandbox" && kinds.length > 0)
81
+ return `it is a computer of your own, and ${PAIRED_SANDBOX}; ${as}`;
82
+ const lack = helloLacks(row.hello, kind);
83
+ return lack === undefined ? undefined : `it is a computer of your own, and ${lack}; update the driver on ${row.name}`;
84
+ }
72
85
  /** A paired computer as a provider of `registry`: named by its name and its os, as an agent's computer picker lists it;
73
- * the setting kinds its paired hello serves, no keys, the machine's own network ("open": a run never narrows a person's
74
- * own machine), never metered. A sandbox (a Linux box with files and exec) takes the run's folder as a synced folder
75
- * (the computer package's attachedProvider checks its /workspace); a desktop or a phone takes no mount. */
86
+ * the setting kinds its paired hello serves, why it serves each other one (unserved, pairedUnserved's words), no keys,
87
+ * the machine's own network ("open": a run never narrows a person's own machine), never metered. A sandbox (a Linux box
88
+ * with files and exec) takes the run's folder as a synced folder (the computer package's attachedProvider checks its
89
+ * /workspace); a desktop or a phone takes no mount. */
76
90
  export function pairedEntry(row, registry) {
77
91
  const hello = row.hello;
78
92
  const configuration = { kind: String(hello.kind ?? ""), groups: Array.isArray(hello.groups) ? [...hello.groups] : [] };
79
- const kinds = Object.keys(registry.SETTING_KINDS).filter((kind) => kind !== "none" && !(kind in ATTACH_CANNOT) && registry.servingRefusals(configuration, kind).length === 0);
93
+ const named = Object.keys(registry.SETTING_KINDS).filter((kind) => kind !== "none");
94
+ const kinds = named.filter((kind) => !(kind in ATTACH_CANNOT) && registry.servingRefusals(configuration, kind).length === 0);
95
+ const unserved = Object.fromEntries(named.filter((kind) => !kinds.includes(kind)).flatMap((kind) => {
96
+ const why = pairedUnserved(row, kinds, kind);
97
+ return why === undefined ? [] : [[kind, why]];
98
+ }));
80
99
  return {
81
100
  id: row.id,
82
101
  label: typeof hello.os === "string" ? `${row.name} (${hello.os})` : row.name,
@@ -86,31 +105,15 @@ export function pairedEntry(row, registry) {
86
105
  network: ["open"],
87
106
  metered: false,
88
107
  capabilities: [configuration],
108
+ unserved,
89
109
  defaultImage: Object.fromEntries(kinds.map((kind) => [kind, ATTACHED_IMAGE])),
90
110
  };
91
111
  }
92
- /** `registry` with each paired computer of `rows` as one more provider (pairedEntry), and the words for one that cannot
93
- * serve a kind an agent asks of it: it is a computer of the person's own, and either the attach path carries no such
94
- * kind (ATTACH_CANNOT: a browser), or it is a desktop or a phone asked to be a sandbox (PAIRED_SANDBOX), so the agent
95
- * takes it as the kind it serves, or its driver lacks what the kind needs (helloLacks), so the driver is what to update. */
112
+ /** `registry` with each paired computer of `rows` as one more provider (pairedEntry). */
96
113
  export function withPaired(registry, rows) {
97
114
  if (rows.length === 0)
98
115
  return registry;
99
- const byId = new Map(rows.map((row) => [row.id, row]));
100
- const unservedWhy = (entry, kind) => {
101
- const row = byId.get(entry.id);
102
- if (row !== undefined && kind in ATTACH_CANNOT && entry.kinds.length > 0) {
103
- return `${row.name} is a computer of your own, and a paired computer can't be a ${kind} computer yet: give this agent ${row.name} as a ${entry.kinds.join(" or ")} computer`;
104
- }
105
- if (row !== undefined && kind === "sandbox" && entry.kinds.length > 0) {
106
- return `${row.name} is a computer of your own, and ${PAIRED_SANDBOX}: give this agent ${row.name} as a ${entry.kinds.join(" or ")} computer`;
107
- }
108
- const lack = row === undefined ? undefined : helloLacks(row.hello, kind);
109
- if (row === undefined || lack === undefined)
110
- return registry.unservedWhy?.(entry, kind);
111
- return `${row.name} is a computer of your own, and its driver gives no ${kind} computer: ${lack}. Update the driver on ${row.name}`;
112
- };
113
- return { ...registry, PROVIDERS: [...registry.PROVIDERS, ...rows.map((row) => pairedEntry(row, registry))], unservedWhy };
116
+ return { ...registry, PROVIDERS: [...registry.PROVIDERS, ...rows.map((row) => pairedEntry(row, registry))] };
114
117
  }
115
118
  /** The provider of the paired computer `row`: attachedProvider over the hub, or a refusal in ONE_PROCESS_WORDS where this
116
119
  * process holds no hub. */
@@ -4,6 +4,7 @@ import { type HostRead } from "../docker-host-addresses.js";
4
4
  import { type ProviderFactories } from "../computer-keys.js";
5
5
  import type { FauxComputers } from "../faux-computers.js";
6
6
  import { type KeyEnv } from "../key-meta.js";
7
+ import { BOX_CPUS_ENV, BOX_MEMORY_ENV, BOX_PIDS_ENV } from "../start-switches.js";
7
8
  import type { Store } from "../store/index.js";
8
9
  import { type ClaimComputer, type ClaimLaunch, computerForClaim, type ComputerForClaimDeps, type ComputerSaid, type KeptKind, type OpenComputerView, type Replaced } from "./computer-for-claim.js";
9
10
  import { type ProviderLoad } from "./computer-providers.js";
@@ -14,9 +15,7 @@ export declare const COMPUTER_LIFETIME_MS: number;
14
15
  /** The settings that size a Docker computer (a sandbox or a desktop): its CPUs, its memory (swap included) and how many
15
16
  * processes and threads it may hold at once. Unset, the Docker provider's own defaults hold. A vendor's computer sizes
16
17
  * itself and is never given them. */
17
- export declare const BOX_CPUS_ENV = "AGENTRUN_BOX_CPUS";
18
- export declare const BOX_MEMORY_ENV = "AGENTRUN_BOX_MEMORY";
19
- export declare const BOX_PIDS_ENV = "AGENTRUN_BOX_PIDS";
18
+ export { BOX_CPUS_ENV, BOX_MEMORY_ENV, BOX_PIDS_ENV };
20
19
  /** A Docker computer's size, as the Docker provider takes it on its spec. */
21
20
  export type DockerLimits = Pick<ComputerSpec, "cpus" | "memoryMb" | "pids">;
22
21
  /** A Docker computer's size from `env`'s AGENTRUN_BOX_CPUS, _MEMORY and _PIDS: each one set, as its spec field; none set,