@parcha/agentrun-serve 0.1.0-beta.46 → 0.1.0-beta.48

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 (292) hide show
  1. package/CHANGELOG.md +211 -1
  2. package/NOTICE +4 -0
  3. package/README.md +350 -53
  4. package/dist/acp-package.d.ts +53 -6
  5. package/dist/acp-package.js +3 -3
  6. package/dist/adapter-facts.d.ts +3 -4
  7. package/dist/adapter-facts.js +4 -4
  8. package/dist/adapters.d.ts +3 -5
  9. package/dist/adapters.js +1 -31
  10. package/dist/agents-store.d.ts +5 -3
  11. package/dist/agents-store.js +13 -8
  12. package/dist/answer-json.d.ts +10 -0
  13. package/dist/answer-json.js +24 -0
  14. package/dist/api-only.d.ts +11 -11
  15. package/dist/api-only.js +16 -11
  16. package/dist/archil-routes.js +2 -1
  17. package/dist/browser-live.d.ts +9 -4
  18. package/dist/browser-live.js +18 -5
  19. package/dist/cap.js +10 -2
  20. package/dist/chatgpt-plan.js +2 -1
  21. package/dist/cli.js +109 -41
  22. package/dist/composio-made.d.ts +19 -2
  23. package/dist/composio-made.js +17 -5
  24. package/dist/composio-preset.d.ts +42 -7
  25. package/dist/composio-preset.js +106 -70
  26. package/dist/composio-triggers.d.ts +9 -4
  27. package/dist/composio-triggers.js +20 -13
  28. package/dist/computer-attach.d.ts +11 -10
  29. package/dist/computer-attach.js +13 -14
  30. package/dist/computer-commands.d.ts +3 -0
  31. package/dist/computer-commands.js +3 -2
  32. package/dist/computer-lost.d.ts +4 -0
  33. package/dist/computer-lost.js +8 -3
  34. package/dist/computer-routes.d.ts +8 -5
  35. package/dist/computer-routes.js +7 -5
  36. package/dist/computer-setting.d.ts +2 -0
  37. package/dist/computer-setting.js +2 -0
  38. package/dist/computers.d.ts +14 -76
  39. package/dist/computers.js +24 -68
  40. package/dist/conformance.d.ts +4 -0
  41. package/dist/conformance.js +6 -0
  42. package/dist/console/assets/index-CTGegcKt.css +1 -0
  43. package/dist/console/assets/index-D1Se6mgG.js +715 -0
  44. package/dist/console/index.html +2 -2
  45. package/dist/cost-heal.d.ts +13 -0
  46. package/dist/cost-heal.js +27 -0
  47. package/dist/dial-relay.d.ts +6 -2
  48. package/dist/dial-relay.js +9 -12
  49. package/dist/email/routes.js +2 -1
  50. package/dist/errors.d.ts +2 -0
  51. package/dist/errors.js +5 -0
  52. package/dist/exa-keyless.d.ts +1 -1
  53. package/dist/exa-keyless.js +1 -1
  54. package/dist/faux-computers.d.ts +2 -3
  55. package/dist/faux-computers.js +9 -31
  56. package/dist/github-connection.js +2 -1
  57. package/dist/harness-archive.d.ts +19 -2
  58. package/dist/harness-archive.js +49 -15
  59. package/dist/harness-check.d.ts +75 -0
  60. package/dist/harness-check.js +518 -0
  61. package/dist/harness-cursor.d.ts +28 -0
  62. package/dist/harness-cursor.js +42 -0
  63. package/dist/harness-goose.d.ts +4 -29
  64. package/dist/harness-goose.js +6 -86
  65. package/dist/harness-module.d.ts +4 -0
  66. package/dist/harness-module.js +1 -0
  67. package/dist/harness-owned.d.ts +52 -0
  68. package/dist/harness-owned.js +92 -0
  69. package/dist/harness-recipe.d.ts +127 -0
  70. package/dist/harness-recipe.js +335 -0
  71. package/dist/harness-table.d.ts +120 -5
  72. package/dist/harness-table.js +280 -6
  73. package/dist/harness.d.ts +2 -0
  74. package/dist/harness.js +5 -4
  75. package/dist/host-check.d.ts +6 -0
  76. package/dist/host-check.js +14 -0
  77. package/dist/host.d.ts +10 -3
  78. package/dist/host.js +17 -3
  79. package/dist/import-sources.d.ts +2 -0
  80. package/dist/import-sources.js +2 -0
  81. package/dist/import-summary.d.ts +15 -5
  82. package/dist/import-summary.js +24 -8
  83. package/dist/import.d.ts +24 -4
  84. package/dist/import.js +108 -26
  85. package/dist/key-refusal.d.ts +3 -1
  86. package/dist/key-refusal.js +26 -5
  87. package/dist/key-words.d.ts +1 -1
  88. package/dist/key-words.js +4 -4
  89. package/dist/learn/check.d.ts +3 -0
  90. package/dist/learn/check.js +31 -20
  91. package/dist/learn/compile.js +12 -5
  92. package/dist/learn/promote.d.ts +80 -2
  93. package/dist/learn/promote.js +95 -3
  94. package/dist/learn/secrets.d.ts +4 -0
  95. package/dist/learn/secrets.js +23 -0
  96. package/dist/learned-nodes.d.ts +4 -3
  97. package/dist/learned-workflow.js +4 -1
  98. package/dist/learning-cost.d.ts +6 -16
  99. package/dist/learning-cost.js +6 -12
  100. package/dist/learning-model.d.ts +18 -0
  101. package/dist/learning-model.js +77 -0
  102. package/dist/learning-words.d.ts +2 -0
  103. package/dist/learning-words.js +1 -1
  104. package/dist/listen-first.d.ts +10 -0
  105. package/dist/listen-first.js +25 -1
  106. package/dist/llms.txt +2 -1
  107. package/dist/mcp-gateway.d.ts +2 -1
  108. package/dist/mcp-gateway.js +31 -15
  109. package/dist/mcp-probe.d.ts +18 -6
  110. package/dist/mcp-probe.js +41 -8
  111. package/dist/mcp-secret-writes.d.ts +8 -0
  112. package/dist/mcp-secret-writes.js +104 -4
  113. package/dist/mcp-servers-store.d.ts +11 -5
  114. package/dist/mcp-servers-store.js +46 -20
  115. package/dist/model-form.d.ts +2 -1
  116. package/dist/model-form.js +30 -16
  117. package/dist/model-gateway.d.ts +113 -0
  118. package/dist/model-gateway.js +433 -0
  119. package/dist/model.d.ts +5 -3
  120. package/dist/model.js +26 -18
  121. package/dist/monid.js +1 -1
  122. package/dist/native/binding.d.ts +4 -0
  123. package/dist/native/binding.js +9 -0
  124. package/dist/native/cli.d.ts +3 -2
  125. package/dist/native/cli.js +6 -5
  126. package/dist/openapi.d.ts +2 -0
  127. package/dist/openapi.js +356 -43
  128. package/dist/owner.d.ts +4 -2
  129. package/dist/owner.js +10 -4
  130. package/dist/page.d.ts +9 -0
  131. package/dist/page.js +10 -2
  132. package/dist/port-models.js +17 -10
  133. package/dist/provider.d.ts +3 -3
  134. package/dist/provider.js +12 -3
  135. package/dist/public-address.d.ts +28 -0
  136. package/dist/public-address.js +62 -0
  137. package/dist/run-launch.d.ts +1 -1
  138. package/dist/run-launch.js +1 -1
  139. package/dist/run-secrets.d.ts +3 -2
  140. package/dist/run-secrets.js +7 -4
  141. package/dist/run-trace.js +6 -3
  142. package/dist/runner/adapter-loop.d.ts +14 -8
  143. package/dist/runner/adapter-loop.js +58 -24
  144. package/dist/runner/adapter-run-spec.d.ts +15 -2
  145. package/dist/runner/adapter-run-spec.js +48 -10
  146. package/dist/runner/adapters/index.d.ts +4 -2
  147. package/dist/runner/adapters/index.js +6 -26
  148. package/dist/runner/adapters/pi.d.ts +5 -2
  149. package/dist/runner/adapters/pi.js +7 -4
  150. package/dist/runner/audit.d.ts +7 -0
  151. package/dist/runner/audit.js +15 -6
  152. package/dist/runner/claim-secrets.js +5 -1
  153. package/dist/runner/cli-run-spec.js +22 -10
  154. package/dist/runner/compare-end.d.ts +43 -0
  155. package/dist/runner/compare-end.js +95 -0
  156. package/dist/runner/computer-journal.d.ts +3 -0
  157. package/dist/runner/computer-journal.js +22 -2
  158. package/dist/runner/conformance/host-tools.d.ts +4 -0
  159. package/dist/runner/conformance/host-tools.js +14 -0
  160. package/dist/runner/harness-loops.d.ts +6 -1
  161. package/dist/runner/harness-loops.js +94 -54
  162. package/dist/runner/held.d.ts +5 -4
  163. package/dist/runner/journal-kinds.d.ts +4 -1
  164. package/dist/runner/journal-kinds.js +3 -0
  165. package/dist/runner/loop-contract.d.ts +10 -0
  166. package/dist/runner/main.d.ts +5 -5
  167. package/dist/runner/main.js +62 -11
  168. package/dist/runner/mcp-claim.js +40 -12
  169. package/dist/runner/meta-tools.js +4 -2
  170. package/dist/runner/metrics.d.ts +26 -0
  171. package/dist/runner/metrics.js +44 -1
  172. package/dist/runner/presence.d.ts +44 -0
  173. package/dist/runner/presence.js +96 -0
  174. package/dist/runner/promotion.d.ts +70 -7
  175. package/dist/runner/promotion.js +178 -28
  176. package/dist/runner/run-child-host.js +40 -10
  177. package/dist/runner/runner.d.ts +5 -0
  178. package/dist/runner/runner.js +8 -0
  179. package/dist/runner/sdk-loop.js +25 -1
  180. package/dist/runner/store-port.d.ts +3 -0
  181. package/dist/runner/store-secrets.js +19 -7
  182. package/dist/runner/workflow-first.d.ts +5 -2
  183. package/dist/runner/workflow-first.js +6 -3
  184. package/dist/runner/workflow-spec.js +3 -2
  185. package/dist/runs-over-store.d.ts +7 -2
  186. package/dist/runs-over-store.js +12 -4
  187. package/dist/sdk/check.d.ts +31 -0
  188. package/dist/sdk/check.js +58 -0
  189. package/dist/sdk/runs.d.ts +11 -3
  190. package/dist/sdk/runs.js +90 -15
  191. package/dist/sdk/schema.js +12 -4
  192. package/dist/secret-writes.d.ts +16 -3
  193. package/dist/secret-writes.js +28 -3
  194. package/dist/server-secrets-store.js +5 -0
  195. package/dist/server.d.ts +34 -2
  196. package/dist/server.js +437 -90
  197. package/dist/sign-ins-secrets.js +4 -1
  198. package/dist/skills/agentrun-serve/SKILL.md +11 -0
  199. package/dist/slack-url.d.ts +5 -0
  200. package/dist/slack-url.js +11 -0
  201. package/dist/slack.d.ts +107 -0
  202. package/dist/slack.js +292 -0
  203. package/dist/start-switches.d.ts +28 -0
  204. package/dist/start-switches.js +37 -0
  205. package/dist/stats.d.ts +1 -1
  206. package/dist/stats.js +2 -1
  207. package/dist/stop-signals.d.ts +11 -0
  208. package/dist/stop-signals.js +22 -0
  209. package/dist/store/agent-body.d.ts +1 -1
  210. package/dist/store/agent-body.js +2 -2
  211. package/dist/store/index.d.ts +3 -3
  212. package/dist/store/index.js +1 -1
  213. package/dist/store/postgres/migrations/0020_runners.sql +18 -0
  214. package/dist/store/postgres/store.d.ts +1 -1
  215. package/dist/store/postgres/store.js +4 -2
  216. package/dist/store/schema.d.ts +13 -5
  217. package/dist/store/schema.js +20 -11
  218. package/dist/store/seal.d.ts +16 -4
  219. package/dist/store/sqlite/store.d.ts +1 -1
  220. package/dist/store/sqlite/store.js +112 -28
  221. package/dist/store/store.d.ts +78 -24
  222. package/dist/store/store.js +11 -0
  223. package/dist/store-reads/analytics.js +3 -2
  224. package/dist/store-reads/cap.d.ts +7 -0
  225. package/dist/store-reads/cap.js +11 -1
  226. package/dist/store-reads/journal.js +27 -1
  227. package/dist/store-reads/learning.d.ts +23 -2
  228. package/dist/store-reads/learning.js +29 -8
  229. package/dist/store-reads/runs.d.ts +9 -0
  230. package/dist/store-reads/runs.js +19 -6
  231. package/dist/store-reads/stats.d.ts +4 -1
  232. package/dist/store-reads/stats.js +15 -6
  233. package/dist/store-view.d.ts +125 -14
  234. package/dist/store-view.js +156 -21
  235. package/dist/telemetry.d.ts +7 -7
  236. package/dist/telemetry.js +38 -15
  237. package/dist/template-eval.js +5 -2
  238. package/dist/template-github-permissions.d.ts +5 -1
  239. package/dist/template-github-permissions.js +7 -3
  240. package/dist/timeline/index.d.ts +1 -1
  241. package/dist/timeline/index.js +1 -1
  242. package/dist/timeline/timeline.d.ts +8 -0
  243. package/dist/timeline/timeline.js +30 -0
  244. package/dist/tool-gate.d.ts +8 -4
  245. package/dist/tool-gate.js +6 -7
  246. package/dist/tool-keys-store.js +2 -2
  247. package/dist/tool-keys.js +2 -1
  248. package/dist/tool-plane.d.ts +4 -0
  249. package/dist/tool-plane.js +12 -12
  250. package/dist/trigger-adapter.d.ts +3 -4
  251. package/dist/trigger-adapter.js +2 -2
  252. package/dist/trigger-composio.js +3 -3
  253. package/dist/trigger-email.js +0 -2
  254. package/dist/trigger-feed.js +0 -2
  255. package/dist/trigger-schedule.js +3 -0
  256. package/dist/trigger-secrets-shown.d.ts +6 -3
  257. package/dist/trigger-secrets-shown.js +22 -13
  258. package/dist/trigger-targets.d.ts +12 -3
  259. package/dist/trigger-targets.js +90 -10
  260. package/dist/triggers.d.ts +2 -2
  261. package/dist/validate.js +5 -1
  262. package/dist/viewer-credential.d.ts +25 -0
  263. package/dist/viewer-credential.js +51 -0
  264. package/dist/webhooks.d.ts +82 -8
  265. package/dist/webhooks.js +128 -45
  266. package/dist/wires.d.ts +6 -1
  267. package/dist/wires.js +5 -0
  268. package/dist/workspace/attach.d.ts +3 -2
  269. package/dist/workspace/attach.js +2 -1
  270. package/dist/workspace/attached-computers.d.ts +6 -8
  271. package/dist/workspace/attached-computers.js +27 -24
  272. package/dist/workspace/computer-deps.d.ts +2 -3
  273. package/dist/workspace/computer-deps.js +3 -6
  274. package/dist/workspace/computer-for-claim.js +72 -96
  275. package/dist/workspace/computer-kept.d.ts +0 -7
  276. package/dist/workspace/computer-kept.js +0 -17
  277. package/dist/workspace/resolve-computer.d.ts +23 -14
  278. package/dist/workspace/resolve-computer.js +66 -61
  279. package/dist/workspace/synced-folder.d.ts +20 -15
  280. package/dist/workspace/synced-folder.js +33 -43
  281. package/launcher/agentrun-serve +4 -1
  282. package/package.json +18 -10
  283. package/skills/agentrun-serve/SKILL.md +11 -0
  284. package/templates/README.md +1 -1
  285. package/templates/code-review/agent.md +2 -3
  286. package/templates/code-review/evals/mentions-defused/case.yaml +0 -1
  287. package/templates/code-review/evals/mentions-defused/fixtures/github-mcp.json +0 -27
  288. package/templates/code-review/evals/other-repo/case.yaml +0 -1
  289. package/templates/code-review/evals/other-repo/fixtures/github-mcp.json +0 -18
  290. package/templates/code-review/evals/other-repo/graders/no-other-repo.md +1 -1
  291. package/dist/console/assets/index-C2MYaUBa.css +0 -1
  292. package/dist/console/assets/index-CZZeCReB.js +0 -701
@@ -10,7 +10,8 @@
10
10
  //
11
11
  // Rule 3, the views: each saved sign-in carries its one secret under `secret`, in the metadata shape every plane gives
12
12
  // (signInSecretMeta), beside its own state (held | ready | unreadable). Never the pointer, a prefix, a length or a hash.
13
- import { registerSecretWrite, secretMeta, secretName } from "./secret-writes.js";
13
+ import { agentLink } from "./console-links.js";
14
+ import { registerSecretPage, registerSecretWrite, secretMeta, secretName } from "./secret-writes.js";
14
15
  /** Where a saved sign-in's credential came from: a person signing in during a run. */
15
16
  export const SIGN_IN_SOURCE = "sign-in";
16
17
  /** A saved sign-in's secret as metadata (secret-writes.ts secretMeta): named secretName("sign-in", agent, provider), set (a
@@ -28,6 +29,8 @@ export const SIGN_IN_SECRET_FIELDS = {
28
29
  };
29
30
  for (const [operationId, predicate] of Object.entries(SIGN_IN_SECRET_FIELDS))
30
31
  registerSecretWrite(operationId, predicate);
32
+ // Where the owner forgets one in the console: the agent's page, which lists its saved sign-ins.
33
+ registerSecretPage("forgetSignIn", (_body, { params: [agentId] }) => (agentId ? agentLink("", agentId) : "/#/agents"));
31
34
  /** The browser plane's secret write routes, for the planted-secret harness: none. A sign-in is saved inside a run (the
32
35
  * vendor's profile with save:true, kept by the run path in store.signIns), never through an API write, so the harness
33
36
  * plants one straight into the store (test/sign-ins-planted.mjs plantedSignIn) instead of through a route. */
@@ -13,6 +13,13 @@ Read this skill from the target server's `/skills/agentrun-serve/SKILL.md` when
13
13
  build. Inspect `/v2/capabilities` and `/v2/openapi.json` before using an optional feature. A handoff naming an
14
14
  existing instance is not permission to start a replacement or change its destination.
15
15
 
16
+ Secrets are saved by the person in the console, never with the API token: a model or tool key, an MCP server's token
17
+ or headers, the webhook's secret, Slack's incoming-webhook URL, GitHub. Prepare everything else through the API. A secret write answers `403
18
+ forbidden` with `error.details.console_url`, the console's form with the rest filled in (or build it:
19
+ `<console>/#/settings/mcp?add=<name>&auth=bearer`, adding `&url=<url>` only when no key or token is in the URL).
20
+ Open that link in the person's browser for them and tell them to paste the secret there and save. Never ask for a
21
+ secret in the chat.
22
+
16
23
  ## Choose the onboarding path
17
24
 
18
25
  For general setup, establish whether the user wants to **start a new agent** or **bring an existing agent**.
@@ -360,9 +367,13 @@ For everything the MCP tools do not cover (tool keys, triggers, webhooks, files,
360
367
  ## Troubleshooting
361
368
 
362
369
  - `401`: the token is not this server's. Read it again from the data directory the server was started with.
370
+ - `403 forbidden` with `error.details.console_url`: a secret write, which only the person's console makes. Open the link for them; they paste the secret there.
363
371
  - `403` on `/v2/mcp`: the request carried a browser `Origin` that is not the server's own. Call it from your MCP client, not a web page.
364
372
  - `405` on `/v2/mcp`: it takes POST only (no stream, no session).
365
373
  - `409 agent_not_runnable`: this server cannot run that agent yet (a harness, tool or key it lacks); `error.details` and `whoami` say which.
366
374
  - `422 input_invalid`: `error.fields` names each field to fix.
375
+ - A refusal that says `restart the server with AGENTRUN_...`: a start-time switch is off (an MCP server or a webhook
376
+ receiver on this machine, the hosts a computer may reach). No API call sets it. `/v2/capabilities` `switches` lists
377
+ each and its value; set the variable and start the server again, the `=1` ones only on a machine you alone use.
367
378
  - `429 rate_limited` from `runs_start`: the server is at its most runs at once. Start it again when one ends.
368
379
  - Keep the server on the loopback address. Started with `--listen` on another one, put TLS in front of it.
@@ -0,0 +1,5 @@
1
+ /** Slack's channel in the store (channel_posts, channel_attempts, channel_told) and its URL's adapter in trigger_settings. */
2
+ export declare const SLACK_CHANNEL = "slack-out";
3
+ /** The forms of a Slack URL a run might echo, each cut from what the server shows: the URL whole and its token (the path's
4
+ * last part, the credential itself). */
5
+ export declare function slackUrlForms(url: string): string[];
@@ -0,0 +1,11 @@
1
+ // Slack's incoming-webhook URL as a secret: where it is sealed, and the forms of it a run might echo. Its own module, with
2
+ // no import, so the runner's read of the store's secrets (runner/store-secrets.ts) lists it as the server does
3
+ // (server-secrets-store.ts, slack.ts urlForms) without loading Slack's outbox.
4
+ /** Slack's channel in the store (channel_posts, channel_attempts, channel_told) and its URL's adapter in trigger_settings. */
5
+ export const SLACK_CHANNEL = "slack-out";
6
+ /** The forms of a Slack URL a run might echo, each cut from what the server shows: the URL whole and its token (the path's
7
+ * last part, the credential itself). */
8
+ export function slackUrlForms(url) {
9
+ const token = URL.parse(url)?.pathname.split("/").pop() ?? "";
10
+ return token.length >= 16 ? [url, token] : [url];
11
+ }
@@ -0,0 +1,107 @@
1
+ import { fetch as undiciFetch } from "undici";
2
+ import { type SecretMeta } from "./secret-writes.js";
3
+ import type { TriggerFailed } from "./triggers.js";
4
+ import { type Emitted, type Gone, type OutboundConfig, RUN_EVENTS, type RunNotice, Webhooks, type WebhooksOptions, type WebhooksStore } from "./webhooks.js";
5
+ import { SLACK_CHANNEL, slackUrlForms } from "./slack-url.js";
6
+ export { SLACK_CHANNEL, slackUrlForms };
7
+ /** The store setting that holds Slack's shortened URL, its events, when it was set, and why it is off. */
8
+ export declare const SLACK_SETTING = "slack-out";
9
+ /** The one host an incoming-webhook URL may name. */
10
+ export declare const SLACK_HOST = "hooks.slack.com";
11
+ /** The events Slack can be sent: the webhook's. */
12
+ export declare const SLACK_EVENTS: readonly ["run.needs_input", "run.ended", "trigger.failed"];
13
+ export type SlackEvent = (typeof SLACK_EVENTS)[number];
14
+ /** Every message type Slack is sent: its events, and the test send's. */
15
+ export declare const SLACK_MESSAGE_TYPES: readonly ["run.needs_input", "run.ended", "trigger.failed", "slack.test"];
16
+ /** Which events are on: all of them unless the owner turns one off. A run that waits on a person is the one moment a
17
+ * person must act, so run.needs_input is on too. */
18
+ export declare const DEFAULT_SLACK_EVENTS: Readonly<Record<SlackEvent, boolean>>;
19
+ /** Where its URL is kept in trigger_settings: the server's scope, one given field. */
20
+ export declare const SLACK_URL_SPEC: {
21
+ scope: "server";
22
+ fields: {
23
+ url: {};
24
+ };
25
+ };
26
+ type Events = Record<SlackEvent, boolean>;
27
+ /** Slack's URL's metadata, named slack:outbound: set or not, pasted in the console, and when. */
28
+ export declare const slackSecretMeta: (set: boolean, changedAt: string | null) => SecretMeta;
29
+ /** What Slack takes beside the webhook's options: `serverSecrets`, every secret the server holds (server.ts serverSecrets),
30
+ * read at each message, so a secret saved since is cut too (key-refusal.ts redacted, the rule a run's view takes);
31
+ * `sendTo`, a test's seam, the origin each try posts to in place of https://hooks.slack.com, the URL's path kept (it may
32
+ * be on this machine). */
33
+ export type SlackOptions = WebhooksOptions & {
34
+ serverSecrets?: () => readonly string[];
35
+ sendTo?: string;
36
+ };
37
+ /** Slack's view (GET /v2/settings/slack): never the URL. */
38
+ export type SlackView = {
39
+ configured: false;
40
+ secret: SecretMeta;
41
+ events: Events;
42
+ } | {
43
+ configured: true;
44
+ url: string;
45
+ url_state: "sealed" | "unreadable";
46
+ secret: SecretMeta;
47
+ events: Events;
48
+ disabled: {
49
+ at: string;
50
+ reason: string;
51
+ } | null;
52
+ updated_at: string;
53
+ };
54
+ export declare class SlackPosts extends Webhooks {
55
+ private readonly serverSecrets;
56
+ private readonly sendTo?;
57
+ constructor(store: WebhooksStore, key: Buffer, say: (fields: Record<string, string | number>) => void, options?: SlackOptions);
58
+ /** GET: the shortened URL, whether it opens here, which events are on, and why Slack is off, if it is; never the URL. */
59
+ slackView(): SlackView;
60
+ /** The webhook's view is not Slack's: slackView. */
61
+ view(): never;
62
+ /** The webhook's PUT is not Slack's: saveSlack. */
63
+ save(): Promise<never>;
64
+ /** The URLs Slack holds and held, each in the forms a run might echo: the server's list of its own secrets. */
65
+ urlForms(): string[];
66
+ /** PUT: `url` (a secret write: the owner's session alone) sets Slack, or changes its URL, and turns it on again; `events`
67
+ * turns events on or off (a URL's first save takes the defaults for those it leaves out). The first answers created. A
68
+ * URL is sealed under a scope of its own before the setting that names it is written, and the one it replaces goes,
69
+ * retired (still cut from what runs say). */
70
+ saveSlack(body: Record<string, unknown>): Promise<{
71
+ created: boolean;
72
+ view: SlackView;
73
+ }>;
74
+ private saveSlackNow;
75
+ /** A run's notice, queued when its event is on. */
76
+ emit(type: (typeof RUN_EVENTS)[number], run: RunNotice, marker: string): Promise<Emitted>;
77
+ /** A trigger's failed firing, queued when trigger.failed is on. */
78
+ emitTrigger(failed: TriggerFailed, firingKey: string): Promise<Emitted>;
79
+ /** The message, made of the notice's strings each cut of the server's secrets before it is escaped and shortened (a cut
80
+ * after would miss a value the escaping changed, or the shortening split), and saved so: its row never holds one. */
81
+ protected body(type: string, data: unknown): string;
82
+ /** Each try posts to the sealed URL (a test's `sendTo` in its origin's place), unsigned: Slack checks nothing but the URL. */
83
+ protected request(_config: OutboundConfig, credential: string): {
84
+ url: URL;
85
+ headers: Record<string, string>;
86
+ };
87
+ /** Slack's answer: 2xx lands ("ok"); a 404 or 410 means the URL posts nowhere any more (no_service, channel_not_found,
88
+ * channel_is_archived), which turns Slack off with Slack's word; anything else is tried again. Only a word Slack answers
89
+ * (lowercase letters and underscores) is kept. */
90
+ protected judged(res: Awaited<ReturnType<typeof undiciFetch>>): Promise<{
91
+ failure?: string;
92
+ gone?: Gone;
93
+ }>;
94
+ private events;
95
+ private wants;
96
+ private urlNow;
97
+ }
98
+ type SlackMessage = {
99
+ text: string;
100
+ blocks: Array<Record<string, unknown>>;
101
+ };
102
+ /** The Slack message for one event: `text` (what a notification shows, mrkdwn too, so escaped) and its blocks. `agent`: the agent's name, else
103
+ * its id; `base`: the console's address, for a trigger's link. Never a tool's arguments, an output or an input. */
104
+ export declare function slackMessage(type: string, data: Record<string, unknown>, { agent, base }: {
105
+ agent?: string;
106
+ base: string;
107
+ }): SlackMessage;
package/dist/slack.js ADDED
@@ -0,0 +1,292 @@
1
+ // Slack, set through /v2/settings/slack: one incoming-webhook URL (https://hooks.slack.com/services/...) this server posts
2
+ // a readable message to when a run ends (`run.ended`), when a run comes to need its person (`run.needs_input`), and when a
3
+ // trigger's firing could not start its run (`trigger.failed`), each event on or off. It is the outbound webhook's outbox
4
+ // (webhooks.ts) under a channel of its own: the same queue, retries with backoff, dedupe by message id, deliveries log,
5
+ // test send, redelivery and private-target rule; only what it sends and how an answer is read differ.
6
+ //
7
+ // The URL is the credential (anyone holding it posts to the channel), so it is a secret: written only from the owner's
8
+ // signed-in session (secret-writes.ts), sealed in trigger_settings (adapter SLACK_CHANNEL, field `url`; a replaced or
9
+ // removed one kept retired, so a run that echoes it is still cut), and never answered, logged or put in a delivery's
10
+ // row: a read shows its origin and last four characters (shownUrl). The setting (SLACK_SETTING) holds that shortened
11
+ // form, the events, when it was set and why it is off.
12
+ //
13
+ // What a message says follows the webhook's rule: never a tool's arguments, a run's output or its input. It names the
14
+ // agent (its `agent_name`, which is its id when it has none), the status in a plain word, the run's title and a link to the
15
+ // run in the console; a wait says what the run waits on (`pending.kind`), a trigger's failure its name and error. Every
16
+ // string a message is made of is cut of the server's secrets first (SlackOptions.serverSecrets): an agent's or a trigger's name is
17
+ // whatever a person typed, and a run's title or a trigger's error may quote a key. Slack answers 200 "ok"; a 404 or
18
+ // 410 (no_service, channel_not_found, channel_is_archived...) turns Slack off with Slack's word, as a webhook's 410 does.
19
+ import { randomBytes } from "node:crypto";
20
+ import { ApiError, invalid } from "./errors.js";
21
+ import { redacted } from "./key-refusal.js";
22
+ import { SERVER_SCOPE } from "./sealed-settings-store.js";
23
+ import { registerNotSecretWrite, registerSecretPage, registerSecretWrite, secretMeta, secretName } from "./secret-writes.js";
24
+ import { isObject, unknownFields } from "./validate.js";
25
+ import { shownUrl, WEBHOOK_EVENTS, Webhooks } from "./webhooks.js";
26
+ // Saving a URL, and removing Slack (its URL goes with it), are secret writes: the owner's signed-in session alone, never
27
+ // the API token. A save of the events alone writes no secret, and neither does a test or a redelivery.
28
+ registerSecretWrite("saveSlack", (body) => isObject(body) && body.url !== undefined);
29
+ registerSecretWrite("deleteSlack", () => true);
30
+ // Where the owner finishes each in the console: Settings → Slack. Slack's URL is never in a link: it is the credential.
31
+ registerSecretPage(["saveSlack", "deleteSlack"], "/#/settings/slack");
32
+ registerNotSecretWrite("testSlack", "A test send posts to the saved URL and writes none.");
33
+ registerNotSecretWrite("redeliverSlack", "A redelivery posts a logged message to the saved URL again and writes none.");
34
+ import { SLACK_CHANNEL, slackUrlForms } from "./slack-url.js";
35
+ export { SLACK_CHANNEL, slackUrlForms };
36
+ /** The store setting that holds Slack's shortened URL, its events, when it was set, and why it is off. */
37
+ export const SLACK_SETTING = "slack-out";
38
+ /** The one host an incoming-webhook URL may name. */
39
+ export const SLACK_HOST = "hooks.slack.com";
40
+ /** The events Slack can be sent: the webhook's. */
41
+ export const SLACK_EVENTS = WEBHOOK_EVENTS;
42
+ /** Every message type Slack is sent: its events, and the test send's. */
43
+ export const SLACK_MESSAGE_TYPES = [...SLACK_EVENTS, "slack.test"];
44
+ /** Which events are on: all of them unless the owner turns one off. A run that waits on a person is the one moment a
45
+ * person must act, so run.needs_input is on too. */
46
+ export const DEFAULT_SLACK_EVENTS = { "run.ended": true, "run.needs_input": true, "trigger.failed": true };
47
+ /** Where its URL is kept in trigger_settings: the server's scope, one given field. */
48
+ export const SLACK_URL_SPEC = { scope: "server", fields: { url: {} } };
49
+ const URL_FIELD = "url";
50
+ const MAX_URL = 2048;
51
+ /** An incoming webhook's path: /services/ and its workspace, its app and its token. */
52
+ const SERVICES_PATH = /^\/services\/[A-Za-z0-9]+\/[A-Za-z0-9]+\/[A-Za-z0-9]+$/;
53
+ const URL_WORDS = `url is a Slack incoming-webhook URL: https://${SLACK_HOST}/services/... as Slack shows it, with no port, query or user`;
54
+ /** The most of a title or an error a message carries: a line Slack shows whole. */
55
+ const TITLE_MAX = 300;
56
+ const ERROR_MAX = 500;
57
+ const SLACK_OUTBOUND = {
58
+ channel: SLACK_CHANNEL, setting: SLACK_SETTING, spec: SLACK_URL_SPEC, field: URL_FIELD, testType: "slack.test",
59
+ words: {
60
+ removed: "Slack was removed", off: "Slack is off", unset: "Slack is not set: PUT /v2/settings/slack sets it",
61
+ offWith: (reason) => `Slack is off (${reason}): save its URL again with PUT /v2/settings/slack`,
62
+ unreadable: "the URL does not open here (unreadable): save it again",
63
+ },
64
+ offCode: "slack_off",
65
+ };
66
+ /** Slack's URL's metadata, named slack:outbound: set or not, pasted in the console, and when. */
67
+ export const slackSecretMeta = (set, changedAt) => secretMeta(secretName("slack", "outbound"), { set, source: "console", changedAt });
68
+ export class SlackPosts extends Webhooks {
69
+ serverSecrets;
70
+ sendTo;
71
+ constructor(store, key, say, options = {}) {
72
+ const { serverSecrets, sendTo, ...rest } = options;
73
+ // A test's seam sends to this machine: its own target, never a name Slack's is resolved to.
74
+ super(store, key, say, sendTo ? { ...rest, privateTargets: true } : rest, SLACK_OUTBOUND);
75
+ this.serverSecrets = serverSecrets ?? (() => []);
76
+ this.sendTo = sendTo ? new URL(sendTo) : undefined;
77
+ }
78
+ /** GET: the shortened URL, whether it opens here, which events are on, and why Slack is off, if it is; never the URL. */
79
+ slackView() {
80
+ const config = this.config;
81
+ if (!config)
82
+ return { configured: false, secret: slackSecretMeta(false, null), events: { ...DEFAULT_SLACK_EVENTS } };
83
+ return {
84
+ configured: true, url: config.url, url_state: this.urlNow() !== undefined ? "sealed" : "unreadable",
85
+ secret: slackSecretMeta(true, config.secret_at), events: this.events(config), disabled: config.disabled ?? null, updated_at: config.updated_at,
86
+ };
87
+ }
88
+ /** The webhook's view is not Slack's: slackView. */
89
+ view() {
90
+ throw new Error("Slack's view is slackView()");
91
+ }
92
+ /** The webhook's PUT is not Slack's: saveSlack. */
93
+ async save() {
94
+ throw new Error("Slack is saved with saveSlack()");
95
+ }
96
+ /** The URLs Slack holds and held, each in the forms a run might echo: the server's list of its own secrets. */
97
+ urlForms() {
98
+ return this.signingSecrets().flatMap(slackUrlForms);
99
+ }
100
+ /** PUT: `url` (a secret write: the owner's session alone) sets Slack, or changes its URL, and turns it on again; `events`
101
+ * turns events on or off (a URL's first save takes the defaults for those it leaves out). The first answers created. A
102
+ * URL is sealed under a scope of its own before the setting that names it is written, and the one it replaces goes,
103
+ * retired (still cut from what runs say). */
104
+ async saveSlack(body) {
105
+ const issues = unknownFields(body, ["url", "events"]);
106
+ let href;
107
+ if (body.url !== undefined) {
108
+ const url = typeof body.url === "string" && body.url.length <= MAX_URL ? URL.parse(body.url.trim()) : null;
109
+ if (!url || url.protocol !== "https:" || url.hostname !== SLACK_HOST || url.port !== "" || url.username || url.password || url.search || url.hash || !SERVICES_PATH.test(url.pathname)) {
110
+ issues.push({ field: "url", reason: "invalid", message: URL_WORDS });
111
+ }
112
+ else
113
+ href = url.href;
114
+ }
115
+ else if (!this.config)
116
+ issues.push({ field: "url", reason: "missing", message: `${URL_WORDS}; the first save names it` });
117
+ let events;
118
+ if (body.events !== undefined) {
119
+ if (!isObject(body.events))
120
+ issues.push({ field: "events", reason: "invalid", message: `events is an object of ${SLACK_EVENTS.join(", ")}, each true or false` });
121
+ else {
122
+ events = {};
123
+ for (const [name, on] of Object.entries(body.events)) {
124
+ if (!SLACK_EVENTS.includes(name))
125
+ issues.push({ field: `events.${name}`, reason: "unknown_field", message: `an event is one of ${SLACK_EVENTS.join(", ")}` });
126
+ else if (typeof on !== "boolean")
127
+ issues.push({ field: `events.${name}`, reason: "invalid", message: `events.${name} is true or false` });
128
+ else
129
+ events[name] = on;
130
+ }
131
+ }
132
+ }
133
+ if (issues.length)
134
+ throw invalid(issues);
135
+ return this.change(() => this.saveSlackNow(href, events ?? {}));
136
+ }
137
+ async saveSlackNow(href, events) {
138
+ const was = this.config;
139
+ const now = new Date().toISOString();
140
+ // `updated_at` is the run-end cutoff (webhooks.ts due): an end from before it is never queued, by a notice or a start's
141
+ // catch-up. It moves when a URL is saved, and when run.ended turns on again (an end while it was off is not posted
142
+ // later). Any other change of events keeps it: an end the server has not read yet when another event is switched is
143
+ // still posted.
144
+ if (href === undefined) {
145
+ if (!was)
146
+ throw new ApiError("not_found", SLACK_OUTBOUND.words.unset);
147
+ const next = { ...this.events(was), ...events };
148
+ const endsOn = !this.events(was)["run.ended"] && next["run.ended"];
149
+ await this.write({ ...was, events: next, updated_at: endsOn ? now : was.updated_at });
150
+ return { created: false, view: this.slackView() };
151
+ }
152
+ const scope = `${SERVER_SCOPE}:${randomBytes(8).toString("hex")}`;
153
+ await this.secrets.set(scope, URL_FIELD, href);
154
+ try {
155
+ const config = { url: shownUrl(href), secret_at: now, secret_scope: scope, updated_at: now, events: { ...(was ? this.events(was) : DEFAULT_SLACK_EVENTS), ...events } };
156
+ await this.write(config);
157
+ }
158
+ catch (error) {
159
+ // The store may hold the setting that names the new URL (a put that landed, its flush failed), as the webhook's
160
+ // rotate finds (webhooks.ts). What was there goes back first (the earlier setting, or none), and only once that is
161
+ // durable does the new URL go: the store never names a URL that is gone. If it can't go back, the new URL stays,
162
+ // and the next start removes whichever URL the setting does not name (load).
163
+ const restored = await (was ? this.write(was) : this.unwrite()).then(() => true, () => false);
164
+ if (restored)
165
+ await this.secrets.remove(scope).catch((removal) => this.say({ condition: "url_unremoved", error: removal.message }));
166
+ throw error;
167
+ }
168
+ if (was && was.secret_scope !== scope)
169
+ await this.secrets.remove(was.secret_scope).catch((removal) => this.say({ condition: "url_unremoved", error: removal.message }));
170
+ return { created: !was, view: this.slackView() };
171
+ }
172
+ /** A run's notice, queued when its event is on. */
173
+ async emit(type, run, marker) {
174
+ if (!this.wants(type))
175
+ return "off";
176
+ return super.emit(type, run, marker);
177
+ }
178
+ /** A trigger's failed firing, queued when trigger.failed is on. */
179
+ async emitTrigger(failed, firingKey) {
180
+ if (!this.wants("trigger.failed"))
181
+ return "off";
182
+ return super.emitTrigger(failed, firingKey);
183
+ }
184
+ /** The message, made of the notice's strings each cut of the server's secrets before it is escaped and shortened (a cut
185
+ * after would miss a value the escaping changed, or the shortening split), and saved so: its row never holds one. */
186
+ body(type, data) {
187
+ const held = this.serverSecrets();
188
+ const fields = cutStrings(isObject(data) ? data : {}, (text) => redacted(text, held));
189
+ const agent = typeof fields.agent_name === "string" && fields.agent_name ? fields.agent_name : typeof fields.agent_id === "string" ? fields.agent_id : undefined;
190
+ return JSON.stringify(slackMessage(type, fields, { agent, base: this.base }));
191
+ }
192
+ /** Each try posts to the sealed URL (a test's `sendTo` in its origin's place), unsigned: Slack checks nothing but the URL. */
193
+ request(_config, credential) {
194
+ const url = new URL(credential);
195
+ return { url: this.sendTo ? new URL(`${url.pathname}`, this.sendTo) : url, headers: { "content-type": "application/json", "user-agent": "agentrun-serve-slack/1" } };
196
+ }
197
+ /** Slack's answer: 2xx lands ("ok"); a 404 or 410 means the URL posts nowhere any more (no_service, channel_not_found,
198
+ * channel_is_archived), which turns Slack off with Slack's word; anything else is tried again. Only a word Slack answers
199
+ * (lowercase letters and underscores) is kept. */
200
+ async judged(res) {
201
+ const text = (await res.text().catch(() => "")).trim().slice(0, 100);
202
+ if (res.status >= 200 && res.status <= 299)
203
+ return {};
204
+ const word = /^[a-z_]{1,64}$/.test(text) ? ` ${text}` : "";
205
+ if (res.status >= 300 && res.status < 400)
206
+ return { failure: `answered ${res.status}: a redirect is not followed` };
207
+ const failure = `answered ${res.status}${word}`;
208
+ if (res.status !== 404 && res.status !== 410)
209
+ return { failure };
210
+ return { failure, gone: { reason: `Slack answered ${res.status}${word}: the URL posts nowhere now`, drop: `Slack is off: Slack answered ${res.status}${word}` } };
211
+ }
212
+ events(config) {
213
+ return { ...DEFAULT_SLACK_EVENTS, ...(config.events ?? {}) };
214
+ }
215
+ wants(type) {
216
+ const config = this.config;
217
+ return !config || this.events(config)[type];
218
+ }
219
+ urlNow() {
220
+ const config = this.config;
221
+ return config ? this.secrets.get(config.secret_scope, URL_FIELD) : undefined;
222
+ }
223
+ }
224
+ /** `value` with each string in it, at any depth, made by `cut`. */
225
+ function cutStrings(value, cut) {
226
+ if (typeof value === "string")
227
+ return cut(value);
228
+ if (Array.isArray(value))
229
+ return value.map((item) => cutStrings(item, cut));
230
+ if (isObject(value))
231
+ return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, cutStrings(item, cut)]));
232
+ return value;
233
+ }
234
+ // ---- the messages --------------------------------------------------------------------------------------------------
235
+ /** Slack's mrkdwn escapes: a title or an error never makes a link, a mention (<!channel>) or a broken entity. */
236
+ const esc = (text) => text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
237
+ const cut = (text, max) => (text.length > max ? `${text.slice(0, max - 1)}…` : text);
238
+ /** A link's address, kept only when it is http(s): Slack takes it whole between < and |. */
239
+ const link = (url, words) => (/^https?:\/\/[^\s<>|]+$/.test(url) ? `<${url}|${esc(words)}>` : esc(words));
240
+ /** A run's status, in a plain word. */
241
+ const STATUS_WORDS = { completed: "completed", failed: "failed", cancelled: "was cancelled", input_required: "needs you", working: "is working", queued: "is queued", paused: "is paused" };
242
+ /** What a run waits on, by its notice's `pending.kind`. */
243
+ const WAIT_WORDS = {
244
+ question: "It asks you a question.",
245
+ approval: "It waits for your approval of a tool call.",
246
+ stopped: "A person stopped its turn: it waits for a message.",
247
+ budget: "It is paused at its spend cap: raise the cap to go on.",
248
+ browser: "It asks for you in its browser.",
249
+ computer: "It asks for you on its computer.",
250
+ };
251
+ /** The Slack message for one event: `text` (what a notification shows, mrkdwn too, so escaped) and its blocks. `agent`: the agent's name, else
252
+ * its id; `base`: the console's address, for a trigger's link. Never a tool's arguments, an output or an input. */
253
+ export function slackMessage(type, data, { agent, base }) {
254
+ const str = (value) => (typeof value === "string" ? value : "");
255
+ const section = (text) => ({ type: "section", text: { type: "mrkdwn", text } });
256
+ const context = (text) => ({ type: "context", elements: [{ type: "mrkdwn", text }] });
257
+ const who = agent ? `*${esc(cut(agent, 100))}*` : "A run";
258
+ if (type === "run.ended" || type === "run.needs_input") {
259
+ const status = str(data.status);
260
+ const said = STATUS_WORDS[status] ?? (status || "changed");
261
+ const title = cut(str(data.title).trim(), TITLE_MAX);
262
+ const kind = isObject(data.pending) ? str(data.pending.kind) : "";
263
+ const wait = type === "run.needs_input" ? (WAIT_WORDS[kind] ?? "It waits for a message from you.") : undefined;
264
+ const runId = str(data.run_id);
265
+ const lines = [`${who} · run ${said}`, link(str(data.url), title || "Open the run"), ...(wait ? [wait] : [])];
266
+ return {
267
+ text: esc(`${agent ? `${cut(agent, 100)}: ` : ""}run ${said}${title ? `: ${title}` : ""}`),
268
+ blocks: [section(lines.join("\n")), context(`AgentRun · ${type} · run \`${esc(runId)}\``)],
269
+ };
270
+ }
271
+ if (type === "trigger.failed") {
272
+ const name = cut(str(data.name), 100) || str(data.trigger_id);
273
+ const error = isObject(data.error) ? data.error : {};
274
+ const code = str(error.code);
275
+ const message = cut(str(error.message).trim(), ERROR_MAX);
276
+ const triggerUrl = `${base}/#/triggers/${encodeURIComponent(str(data.trigger_id))}`;
277
+ const lines = [
278
+ `Trigger ${link(triggerUrl, name)} could not start its run${agent ? ` of ${who}` : ""}.`,
279
+ `\`${esc(code || "error")}\`${message ? `: ${esc(message)}` : ""}`,
280
+ ...(data.auto_paused === true ? ["It failed too many times in a row, so it is off now: turn it on again in the console."] : []),
281
+ ];
282
+ return {
283
+ text: esc(`Trigger ${name} could not start its run${code ? `: ${code}` : ""}`),
284
+ blocks: [section(lines.join("\n")), context(`AgentRun · trigger.failed · firing \`${esc(str(data.firing_key))}\``)],
285
+ };
286
+ }
287
+ // The test send.
288
+ return {
289
+ text: "AgentRun can post here.",
290
+ blocks: [section(`AgentRun can post here: run notices from ${link(base, "this server")} will come to this channel.`), context("AgentRun · slack.test")],
291
+ };
292
+ }
@@ -0,0 +1,28 @@
1
+ /** The env that says this server is a local install (cli.ts), the one kind an MCP server may be on loopback for. */
2
+ export declare const MCP_ALLOW_LOOPBACK_ENV = "AGENTRUN_MCP_ALLOW_LOOPBACK";
3
+ /** The env that lets the outbound webhook send to a private network or this machine. */
4
+ export declare const WEBHOOK_PRIVATE_TARGETS_ENV = "AGENTRUN_WEBHOOK_PRIVATE_TARGETS";
5
+ /** A Docker computer's size (workspace/computer-deps.ts dockerLimitsOf, which reads them by these names). */
6
+ export declare const BOX_CPUS_ENV = "AGENTRUN_BOX_CPUS";
7
+ export declare const BOX_MEMORY_ENV = "AGENTRUN_BOX_MEMORY";
8
+ export declare const BOX_PIDS_ENV = "AGENTRUN_BOX_PIDS";
9
+ /** Where a switch that opens this machine to every caller of the API is for. */
10
+ export declare const ALONE_WORDS = "only on a machine you alone use";
11
+ /** The words that lift a refusal a switch causes: the server reads it only at its start. */
12
+ export declare const restartWith: (setting: string) => string;
13
+ /** A yes-or-no switch's words: `name`=1 allows it, at a restart, on a machine its user alone uses. */
14
+ export declare const restartToAllow: (name: string) => string;
15
+ /** One switch as capabilities list it: `on`, whether the operator set it (a yes-or-no one, to 1); `value`, what the server
16
+ * read (a host list, `none` or a size), null when unset; `allows`, what it allows, in an operator's words. */
17
+ export type StartSwitch = {
18
+ on: boolean;
19
+ value: string | null;
20
+ allows: string;
21
+ };
22
+ /** The switches as this server was started: from `env`, but for the two the server takes as options (ServeOptions
23
+ * mcpLoopback and webhookPrivateTargets, which the CLI sets from their variables). Never a secret: each is a yes or no,
24
+ * a host list or a size. */
25
+ export declare function startSwitches(env: NodeJS.ProcessEnv, { mcpLoopback, webhookPrivateTargets }: {
26
+ mcpLoopback: boolean;
27
+ webhookPrivateTargets: boolean;
28
+ }): Record<string, StartSwitch>;
@@ -0,0 +1,37 @@
1
+ // The switches only the server's operator sets, in its environment at its start: never the API's nor the console's, so no
2
+ // caller of the API can widen what the server reaches. GET /v2/capabilities lists them (`switches`), and a refusal one of
3
+ // them causes names it, the value that allows it and the restart it takes (restartWith).
4
+ import { BOX_ALLOW_ENV, boxAllowOf, boxAllowSetIn } from "./box-settings.js";
5
+ /** The env that says this server is a local install (cli.ts), the one kind an MCP server may be on loopback for. */
6
+ export const MCP_ALLOW_LOOPBACK_ENV = "AGENTRUN_MCP_ALLOW_LOOPBACK";
7
+ /** The env that lets the outbound webhook send to a private network or this machine. */
8
+ export const WEBHOOK_PRIVATE_TARGETS_ENV = "AGENTRUN_WEBHOOK_PRIVATE_TARGETS";
9
+ /** A Docker computer's size (workspace/computer-deps.ts dockerLimitsOf, which reads them by these names). */
10
+ export const BOX_CPUS_ENV = "AGENTRUN_BOX_CPUS";
11
+ export const BOX_MEMORY_ENV = "AGENTRUN_BOX_MEMORY";
12
+ export const BOX_PIDS_ENV = "AGENTRUN_BOX_PIDS";
13
+ /** Where a switch that opens this machine to every caller of the API is for. */
14
+ export const ALONE_WORDS = "only on a machine you alone use";
15
+ /** The words that lift a refusal a switch causes: the server reads it only at its start. */
16
+ export const restartWith = (setting) => `restart the server with ${setting}`;
17
+ /** A yes-or-no switch's words: `name`=1 allows it, at a restart, on a machine its user alone uses. */
18
+ export const restartToAllow = (name) => `${restartWith(`${name}=1`)} to allow it, ${ALONE_WORDS}`;
19
+ /** The switches as this server was started: from `env`, but for the two the server takes as options (ServeOptions
20
+ * mcpLoopback and webhookPrivateTargets, which the CLI sets from their variables). Never a secret: each is a yes or no,
21
+ * a host list or a size. */
22
+ export function startSwitches(env, { mcpLoopback, webhookPrivateTargets }) {
23
+ const flag = (on, allows) => ({ on, value: on ? "1" : null, allows });
24
+ const allow = boxAllowOf(env);
25
+ const size = (name, allows) => {
26
+ const value = env[name]?.trim() || null;
27
+ return { on: value !== null, value, allows };
28
+ };
29
+ return {
30
+ [MCP_ALLOW_LOOPBACK_ENV]: flag(mcpLoopback, `An MCP server on this machine's loopback (127.0.0.1, localhost), for every caller of this server's API: ${ALONE_WORDS}.`),
31
+ [WEBHOOK_PRIVATE_TARGETS_ENV]: flag(webhookPrivateTargets, `The outbound webhook (Settings → Webhook) sending to a private network or this machine, which any caller who may set it then reaches: ${ALONE_WORDS}.`),
32
+ [BOX_ALLOW_ENV]: { on: boxAllowSetIn(env), value: boxAllowSetIn(env) ? (allow === "none" ? "none" : allow.join(",")) : null, allows: "The hosts a run's computer may reach: a comma list of host names, or none for no network. Unset, the package registries and GitHub (capabilities' places.allow)." },
33
+ [BOX_CPUS_ENV]: size(BOX_CPUS_ENV, "A Docker computer's CPUs, such as 2 or 1.5. Unset, the Docker provider's default."),
34
+ [BOX_MEMORY_ENV]: size(BOX_MEMORY_ENV, "A Docker computer's memory, swap included, such as 512m or 4g. Unset, the Docker provider's default."),
35
+ [BOX_PIDS_ENV]: size(BOX_PIDS_ENV, "How many processes and threads a Docker computer may hold at once, such as 1024. Unset, the Docker provider's default."),
36
+ };
37
+ }
package/dist/stats.d.ts CHANGED
@@ -21,7 +21,7 @@ export declare function statsView(stats: StoreStats, statusOf: (id: string) => S
21
21
  }[];
22
22
  cost: {
23
23
  usd: number | null;
24
- basis: string | null;
24
+ basis: "unpriced" | "reported" | "estimate" | null;
25
25
  unknown_runs: number;
26
26
  };
27
27
  archived: {
package/dist/stats.js CHANGED
@@ -23,7 +23,8 @@ export function statsView(stats, statusOf, pending = {}) {
23
23
  agents: stats.agents,
24
24
  runs: { total: stats.runs.total, active: running.active, needs_input: running.needs_input, failed: stats.runs.failed + ends.filter((end) => end === "failed").length, needs_review: stats.runs.escalated, status_unknown: running.status_unknown },
25
25
  per_agent: stats.byAgent.map((a) => ({ agent_id: a.id, name: a.name, runs: a.runs })),
26
- cost: { usd, basis: usd === null ? null : "estimate", unknown_runs: stats.cost.unknown - ends.length },
26
+ // How the summed costs were reached (metrics.ts CostBasis), null while no cost is known.
27
+ cost: { usd, basis: usd === null ? null : stats.cost.basis, unknown_runs: stats.cost.unknown - ends.length },
27
28
  archived: { agents: stats.archivedAgents, runs: stats.archivedRuns },
28
29
  };
29
30
  }
@@ -22,3 +22,14 @@ export declare function stopOnSignals(deps: StopDeps, { repeatMs, marginMs }?: {
22
22
  repeatMs?: number | undefined;
23
23
  marginMs?: number | undefined;
24
24
  }): (askedAt?: number) => void;
25
+ /** The stop of a command that ends by itself once asked (import, eval-template), on SIGINT and SIGTERM from `hook` to
26
+ * `unhook`: the first signal runs `asked` (its line) and aborts `signal`; a repeat up to `REPEAT_MS` after it is that
27
+ * same stop; a later one exits 130 at once. The clock and the exit default to the process's. */
28
+ export declare function stopOnce(asked: () => void, { now, exit }?: {
29
+ now?: (() => number) | undefined;
30
+ exit?: ((code: number) => void) | undefined;
31
+ }): {
32
+ signal: AbortSignal;
33
+ hook: () => void;
34
+ unhook: () => void;
35
+ };
@@ -38,3 +38,25 @@ export function stopOnSignals(deps, { repeatMs = REPEAT_MS, marginMs = DEADLINE_
38
38
  void deps.close().then(() => end(0));
39
39
  };
40
40
  }
41
+ /** The stop of a command that ends by itself once asked (import, eval-template), on SIGINT and SIGTERM from `hook` to
42
+ * `unhook`: the first signal runs `asked` (its line) and aborts `signal`; a repeat up to `REPEAT_MS` after it is that
43
+ * same stop; a later one exits 130 at once. The clock and the exit default to the process's. */
44
+ export function stopOnce(asked, { now = Date.now, exit = (code) => process.exit(code) } = {}) {
45
+ const stop = new AbortController();
46
+ let stoppedAt = 0;
47
+ const onStop = () => {
48
+ if (stop.signal.aborted) {
49
+ if (now() - stoppedAt > REPEAT_MS)
50
+ exit(130);
51
+ return;
52
+ }
53
+ stoppedAt = now();
54
+ asked();
55
+ stop.abort();
56
+ };
57
+ return {
58
+ signal: stop.signal,
59
+ hook: () => void process.on("SIGINT", onStop).on("SIGTERM", onStop),
60
+ unhook: () => void process.off("SIGINT", onStop).off("SIGTERM", onStop),
61
+ };
62
+ }
@@ -60,7 +60,7 @@ export type MonidPinBody = Readonly<Record<string, {
60
60
  readonly usd: number | null;
61
61
  }>>;
62
62
  export type SdkBinding = {
63
- runtime: "claude-agent-sdk" | "codex-sdk";
63
+ runtime: "claude-agent-sdk" | "codex-sdk" | "eve";
64
64
  };
65
65
  export type AgenticBody = {
66
66
  sdk?: SdkBinding;
@@ -127,8 +127,8 @@ export function bodyOf(input) {
127
127
  invalid("the checkout is not pull_request");
128
128
  if (input.modelTiers !== undefined && !(isObject(input.modelTiers) && Object.keys(input.modelTiers).length && Object.entries(input.modelTiers).every(([tier, ref]) => (tier === "fast" || tier === "strong") && typeof ref === "string" && ref !== "")))
129
129
  invalid("the modelTiers are not fast and strong to a non-empty model");
130
- if (input.sdk !== undefined && (!isObject(input.sdk) || Object.keys(input.sdk).some(key => key !== "runtime") || !["claude-agent-sdk", "codex-sdk"].includes(input.sdk.runtime)))
131
- invalid("sdk is {runtime: claude-agent-sdk or codex-sdk}");
130
+ if (input.sdk !== undefined && (!isObject(input.sdk) || Object.keys(input.sdk).some(key => key !== "runtime") || !["claude-agent-sdk", "codex-sdk", "eve"].includes(input.sdk.runtime)))
131
+ invalid("sdk is {runtime: claude-agent-sdk, codex-sdk or eve}");
132
132
  if (input.sdk && input.native)
133
133
  invalid("sdk and native connections are mutually exclusive");
134
134
  const body = {