@parcha/agentrun-serve 0.1.0-beta.36 → 0.1.0-beta.37

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 (325) hide show
  1. package/CHANGELOG.md +170 -0
  2. package/README.md +158 -52
  3. package/dist/attach-conformance-cli.d.ts +1 -0
  4. package/dist/attach-conformance-cli.js +18 -0
  5. package/dist/attach-conformance.d.ts +25 -0
  6. package/dist/attach-conformance.js +343 -0
  7. package/dist/browser-cost.d.ts +1 -1
  8. package/dist/browser-live.d.ts +20 -8
  9. package/dist/browser-live.js +50 -27
  10. package/dist/cap.d.ts +0 -17
  11. package/dist/cap.js +0 -91
  12. package/dist/catalog.d.ts +1 -12
  13. package/dist/catalog.js +3 -33
  14. package/dist/cli.js +13 -4
  15. package/dist/composio-preset.d.ts +36 -0
  16. package/dist/composio-preset.js +179 -0
  17. package/dist/computer-attach.d.ts +125 -0
  18. package/dist/computer-attach.js +330 -0
  19. package/dist/computer-calls.d.ts +48 -0
  20. package/dist/computer-calls.js +126 -0
  21. package/dist/computer-channel.d.ts +57 -0
  22. package/dist/computer-channel.js +115 -0
  23. package/dist/computer-commands.d.ts +1 -1
  24. package/dist/computer-held-routes.d.ts +35 -0
  25. package/dist/computer-held-routes.js +106 -0
  26. package/dist/computer-held.d.ts +48 -0
  27. package/dist/computer-held.js +87 -0
  28. package/dist/computer-keys.d.ts +21 -1
  29. package/dist/computer-keys.js +53 -11
  30. package/dist/computer-live.d.ts +160 -0
  31. package/dist/computer-live.js +643 -0
  32. package/dist/computer-view.d.ts +13 -0
  33. package/dist/computer-view.js +50 -3
  34. package/dist/computer-viewer.d.ts +6 -0
  35. package/dist/computer-viewer.js +297 -0
  36. package/dist/computers.d.ts +33 -7
  37. package/dist/computers.js +50 -8
  38. package/dist/console/assets/index-Cn6JX1uH.js +563 -0
  39. package/dist/console/assets/index-DRN62V5v.css +1 -0
  40. package/dist/console/index.html +2 -2
  41. package/dist/faux-computers.d.ts +9 -20
  42. package/dist/faux-computers.js +53 -25
  43. package/dist/github-connection.d.ts +10 -2
  44. package/dist/github-connection.js +65 -2
  45. package/dist/github-faux.js +1 -1
  46. package/dist/graph-view.d.ts +1 -1
  47. package/dist/harness.d.ts +1 -0
  48. package/dist/harness.js +35 -1
  49. package/dist/host-tools.d.ts +1 -1
  50. package/dist/hosted-search.d.ts +5 -4
  51. package/dist/hosted-search.js +2 -7
  52. package/dist/import-sources.d.ts +10 -0
  53. package/dist/import-sources.js +44 -2
  54. package/dist/import.d.ts +3 -3
  55. package/dist/import.js +37 -6
  56. package/dist/learn/check.d.ts +4 -1
  57. package/dist/learn/check.js +1 -1
  58. package/dist/learn/commit.d.ts +4 -2
  59. package/dist/learn/commit.js +5 -5
  60. package/dist/learn/folder.d.ts +6 -0
  61. package/dist/learn/folder.js +4 -1
  62. package/dist/learn/general.d.ts +66 -0
  63. package/dist/learn/general.js +73 -0
  64. package/dist/learn/grade.d.ts +4 -0
  65. package/dist/learn/grade.js +22 -1
  66. package/dist/learn/reflect.d.ts +10 -1
  67. package/dist/learn/reflect.js +14 -4
  68. package/dist/learn/skills.d.ts +33 -5
  69. package/dist/learn/skills.js +53 -7
  70. package/dist/learned-workflow.d.ts +24 -0
  71. package/dist/learned-workflow.js +66 -3
  72. package/dist/learning-batch.d.ts +283 -0
  73. package/dist/learning-batch.js +574 -0
  74. package/dist/learning-evals.d.ts +33 -0
  75. package/dist/learning-evals.js +98 -0
  76. package/dist/learning-routes.d.ts +25 -2
  77. package/dist/learning-routes.js +39 -6
  78. package/dist/learning-words.d.ts +6 -0
  79. package/dist/learning-words.js +6 -0
  80. package/dist/learning.d.ts +28 -15
  81. package/dist/learning.js +84 -44
  82. package/dist/live/stream.js +6 -3
  83. package/dist/live/translate.d.ts +4 -3
  84. package/dist/live/translate.js +8 -4
  85. package/dist/live-reach.d.ts +37 -0
  86. package/dist/live-reach.js +62 -0
  87. package/dist/mcp-gateway.d.ts +9 -0
  88. package/dist/mcp-gateway.js +60 -11
  89. package/dist/mcp-oauth.d.ts +57 -7
  90. package/dist/mcp-oauth.js +133 -18
  91. package/dist/mcp-private-hosts.d.ts +4 -4
  92. package/dist/mcp-private-hosts.js +20 -12
  93. package/dist/mcp-probe.d.ts +19 -2
  94. package/dist/mcp-probe.js +44 -9
  95. package/dist/mcp-secret-writes.js +4 -0
  96. package/dist/mcp-servers-store.d.ts +38 -15
  97. package/dist/mcp-servers-store.js +112 -20
  98. package/dist/mcp-store.d.ts +10 -4
  99. package/dist/mcp-store.js +17 -6
  100. package/dist/model-form.d.ts +26 -0
  101. package/dist/model-form.js +80 -0
  102. package/dist/model.js +23 -10
  103. package/dist/openapi.js +386 -21
  104. package/dist/page.d.ts +18 -0
  105. package/dist/page.js +48 -20
  106. package/dist/paid-calls.d.ts +1 -1
  107. package/dist/place-offers.d.ts +2 -3
  108. package/dist/place-offers.js +3 -7
  109. package/dist/place.js +1 -2
  110. package/dist/print.d.ts +15 -1
  111. package/dist/print.js +14 -3
  112. package/dist/propose.d.ts +3 -0
  113. package/dist/propose.js +13 -5
  114. package/dist/provider.js +3 -2
  115. package/dist/reflect-range.d.ts +8 -1
  116. package/dist/reflect-range.js +1 -1
  117. package/dist/run-launch.d.ts +14 -2
  118. package/dist/run-launch.js +9 -4
  119. package/dist/run-learning-served.d.ts +2 -2
  120. package/dist/run-reads-over-store.d.ts +1 -1
  121. package/dist/run-repo.d.ts +20 -0
  122. package/dist/run-repo.js +63 -0
  123. package/dist/run-timeline-served.d.ts +1 -1
  124. package/dist/run-view.d.ts +3 -3
  125. package/dist/run-view.js +14 -7
  126. package/dist/runner/adapter-loop.d.ts +23 -7
  127. package/dist/runner/adapter-loop.js +648 -62
  128. package/dist/runner/adapter-run-spec.d.ts +11 -3
  129. package/dist/runner/adapter-run-spec.js +77 -22
  130. package/dist/runner/adapters/pi-computer.d.ts +7 -0
  131. package/dist/runner/adapters/pi-computer.js +43 -0
  132. package/dist/runner/adapters/pi.d.ts +9 -4
  133. package/dist/runner/adapters/pi.js +76 -14
  134. package/dist/runner/beside.d.ts +7 -3
  135. package/dist/runner/beside.js +21 -11
  136. package/dist/runner/claim-secrets.d.ts +4 -0
  137. package/dist/runner/claim-secrets.js +6 -1
  138. package/dist/runner/cli-run-spec.d.ts +20 -3
  139. package/dist/runner/cli-run-spec.js +113 -43
  140. package/dist/runner/commands.d.ts +3 -1
  141. package/dist/runner/commands.js +28 -3
  142. package/dist/runner/computer-channel.d.ts +34 -0
  143. package/dist/runner/computer-channel.js +61 -0
  144. package/dist/runner/conformance/harness.js +80 -14
  145. package/dist/runner/conformance/subject.d.ts +1 -1
  146. package/dist/runner/dispatch.js +3 -0
  147. package/dist/runner/end-of-run.d.ts +22 -12
  148. package/dist/runner/end-of-run.js +38 -16
  149. package/dist/runner/github-app.d.ts +2 -1
  150. package/dist/runner/github-app.js +4 -2
  151. package/dist/runner/harness-loops.js +15 -1
  152. package/dist/runner/held-run.d.ts +65 -0
  153. package/dist/runner/held-run.js +158 -0
  154. package/dist/runner/journal-kinds.d.ts +20 -1
  155. package/dist/runner/journal-kinds.js +14 -0
  156. package/dist/runner/journal-reader.d.ts +5 -4
  157. package/dist/runner/journal-reader.js +12 -10
  158. package/dist/runner/learning-ask.d.ts +7 -1
  159. package/dist/runner/learning-ask.js +21 -6
  160. package/dist/runner/learning-dispatch.d.ts +22 -0
  161. package/dist/runner/learning-dispatch.js +77 -10
  162. package/dist/runner/learning-end.d.ts +22 -1
  163. package/dist/runner/learning-end.js +92 -12
  164. package/dist/runner/learning-factory.d.ts +1 -1
  165. package/dist/runner/learning-factory.js +11 -5
  166. package/dist/runner/learning-loop.d.ts +67 -7
  167. package/dist/runner/learning-loop.js +173 -21
  168. package/dist/runner/learning-seed.d.ts +7 -0
  169. package/dist/runner/learning-seed.js +13 -0
  170. package/dist/runner/live-ticker.js +1 -0
  171. package/dist/runner/loop-contract.d.ts +8 -1
  172. package/dist/runner/loop.d.ts +5 -1
  173. package/dist/runner/loop.js +2 -1
  174. package/dist/runner/main.d.ts +13 -1
  175. package/dist/runner/main.js +27 -5
  176. package/dist/runner/mcp-claim.d.ts +10 -7
  177. package/dist/runner/mcp-claim.js +113 -24
  178. package/dist/runner/mcp-github.js +1 -1
  179. package/dist/runner/mcp-run.d.ts +5 -5
  180. package/dist/runner/mcp-run.js +15 -3
  181. package/dist/runner/metrics.d.ts +11 -2
  182. package/dist/runner/metrics.js +12 -2
  183. package/dist/runner/pr-checkout.d.ts +1 -0
  184. package/dist/runner/pr-checkout.js +1 -1
  185. package/dist/runner/reflect-hook.d.ts +18 -0
  186. package/dist/runner/reflect-hook.js +20 -8
  187. package/dist/runner/runner.d.ts +26 -0
  188. package/dist/runner/runner.js +184 -15
  189. package/dist/runner/scratch-sweep.d.ts +13 -0
  190. package/dist/runner/scratch-sweep.js +62 -0
  191. package/dist/runner/sessions.d.ts +1 -1
  192. package/dist/runner/store-port.d.ts +4 -2
  193. package/dist/runner/store-secrets.js +4 -3
  194. package/dist/runner/subagent.js +3 -1
  195. package/dist/runner/workflow-host.d.ts +6 -1
  196. package/dist/runner/workflow-host.js +1 -1
  197. package/dist/runner/workflow-loop.d.ts +1 -1
  198. package/dist/runner/workflow-spec.d.ts +14 -2
  199. package/dist/runner/workflow-spec.js +56 -20
  200. package/dist/runs-over-store.d.ts +6 -1
  201. package/dist/runs-over-store.js +38 -9
  202. package/dist/seal-key.js +3 -3
  203. package/dist/sealed-settings-store.d.ts +5 -2
  204. package/dist/sealed-settings-store.js +10 -4
  205. package/dist/secret-writes.d.ts +5 -4
  206. package/dist/secret-writes.js +5 -4
  207. package/dist/server-secrets-store.d.ts +4 -3
  208. package/dist/server-secrets-store.js +15 -9
  209. package/dist/server-secrets.js +3 -2
  210. package/dist/server.d.ts +43 -14
  211. package/dist/server.js +472 -126
  212. package/dist/settings-wake.d.ts +21 -0
  213. package/dist/settings-wake.js +59 -0
  214. package/dist/standard-webhooks.d.ts +4 -1
  215. package/dist/standard-webhooks.js +8 -4
  216. package/dist/store/command-wake.d.ts +12 -0
  217. package/dist/store/command-wake.js +37 -0
  218. package/dist/store/dialect.d.ts +6 -0
  219. package/dist/store/dialect.js +5 -0
  220. package/dist/store/index.d.ts +1 -1
  221. package/dist/store/journal/storage.d.ts +3 -2
  222. package/dist/store/journal/storage.js +13 -5
  223. package/dist/store/postgres/dialect.js +4 -0
  224. package/dist/store/postgres/migrations/0005_learning_rounds.sql +14 -0
  225. package/dist/store/postgres/migrations/0006_run_changes_channel_attempts.sql +57 -0
  226. package/dist/store/postgres/migrations/0007_viewer_host.sql +11 -0
  227. package/dist/store/postgres/migrations/0008_paired_computers.sql +30 -0
  228. package/dist/store/postgres/migrations/0009_commands_answer.sql +10 -0
  229. package/dist/store/schema.d.ts +1 -1
  230. package/dist/store/schema.js +77 -8
  231. package/dist/store/sqlite/run-patch.d.ts +7 -5
  232. package/dist/store/sqlite/run-patch.js +28 -13
  233. package/dist/store/sqlite/store.js +272 -54
  234. package/dist/store/store.d.ts +268 -9
  235. package/dist/store/store.js +12 -1
  236. package/dist/store-reads/cap.d.ts +1 -1
  237. package/dist/store-reads/cap.js +8 -1
  238. package/dist/store-reads/decisions.d.ts +2 -2
  239. package/dist/store-reads/decisions.js +1 -1
  240. package/dist/store-reads/import-summary.d.ts +1 -1
  241. package/dist/store-reads/journal.d.ts +5 -4
  242. package/dist/store-reads/journal.js +73 -15
  243. package/dist/store-reads/learning.d.ts +20 -4
  244. package/dist/store-reads/learning.js +74 -18
  245. package/dist/store-reads/runs.d.ts +1 -1
  246. package/dist/store-reads/workflow.d.ts +1 -1
  247. package/dist/store-view.d.ts +5 -0
  248. package/dist/store-view.js +26 -11
  249. package/dist/template-eval.js +6 -4
  250. package/dist/template-github-permissions.d.ts +22 -8
  251. package/dist/template-github-permissions.js +35 -15
  252. package/dist/timeline/timeline.d.ts +27 -0
  253. package/dist/timeline/timeline.js +10 -9
  254. package/dist/timeline/util.d.ts +4 -0
  255. package/dist/timeline/util.js +14 -0
  256. package/dist/tool-budget.d.ts +19 -7
  257. package/dist/tool-budget.js +14 -8
  258. package/dist/tool-gate.d.ts +16 -9
  259. package/dist/tool-gate.js +53 -42
  260. package/dist/tool-plane.d.ts +16 -12
  261. package/dist/tool-plane.js +9 -4
  262. package/dist/tools.d.ts +13 -4
  263. package/dist/tools.js +13 -4
  264. package/dist/trigger-adapter.d.ts +4 -0
  265. package/dist/trigger-secrets-shown.d.ts +2 -2
  266. package/dist/trigger-secrets-shown.js +1 -1
  267. package/dist/trigger-signatures.d.ts +25 -6
  268. package/dist/trigger-signatures.js +41 -7
  269. package/dist/trigger-targets.d.ts +2 -0
  270. package/dist/trigger-targets.js +1 -0
  271. package/dist/trigger-webhook.js +5 -2
  272. package/dist/triggers.d.ts +7 -3
  273. package/dist/triggers.js +35 -5
  274. package/dist/turns.js +16 -1
  275. package/dist/validate.js +11 -1
  276. package/dist/web-fetch.d.ts +1 -1
  277. package/dist/web-search.d.ts +10 -5
  278. package/dist/web-search.js +7 -6
  279. package/dist/webhooks.d.ts +145 -102
  280. package/dist/webhooks.js +559 -322
  281. package/dist/workflow/decisions.d.ts +1 -1
  282. package/dist/workflow/node-runner.d.ts +2 -1
  283. package/dist/workflow/node.d.ts +2 -1
  284. package/dist/workflow/node.js +3 -1
  285. package/dist/workflow/pi-versions.d.ts +23 -0
  286. package/dist/workflow/pi-versions.js +57 -0
  287. package/dist/workflow/record-tool.d.ts +2 -1
  288. package/dist/workflow/store.d.ts +1 -1
  289. package/dist/workflow/task.js +3 -2
  290. package/dist/workflow-run.d.ts +1 -1
  291. package/dist/workspace/attached-computers.d.ts +41 -0
  292. package/dist/workspace/attached-computers.js +114 -0
  293. package/dist/workspace/computer-deps.d.ts +16 -9
  294. package/dist/workspace/computer-deps.js +19 -7
  295. package/dist/workspace/computer-for-claim.d.ts +17 -8
  296. package/dist/workspace/computer-for-claim.js +62 -21
  297. package/dist/workspace/computer-hold.d.ts +11 -27
  298. package/dist/workspace/computer-hold.js +36 -56
  299. package/dist/workspace/computer-ledger.d.ts +3 -1
  300. package/dist/workspace/computer-ledger.js +4 -0
  301. package/dist/workspace/computer-mcp.d.ts +25 -0
  302. package/dist/workspace/computer-mcp.js +41 -0
  303. package/dist/workspace/computer-ports.d.ts +4 -13
  304. package/dist/workspace/computer-ports.js +4 -107
  305. package/dist/workspace/computer-script.d.ts +37 -0
  306. package/dist/workspace/computer-script.js +138 -0
  307. package/dist/workspace/executors.d.ts +1 -1
  308. package/dist/workspace/index.d.ts +4 -2
  309. package/dist/workspace/index.js +3 -1
  310. package/dist/workspace/kind-skills/desktop/SKILL.md +119 -84
  311. package/dist/workspace/kind-skills/phone/SKILL.md +100 -85
  312. package/dist/workspace/resolve-computer.d.ts +3 -0
  313. package/dist/workspace/resolve-computer.js +8 -2
  314. package/dist/workspace/run-tools.d.ts +32 -15
  315. package/dist/workspace/run-tools.js +23 -30
  316. package/package.json +19 -16
  317. package/templates/market-monitor/agent.md +1 -1
  318. package/dist/console/assets/index-BI4Byidu.js +0 -550
  319. package/dist/console/assets/index-C19gUF2n.css +0 -1
  320. package/dist/run-db.d.ts +0 -53
  321. package/dist/run-db.js +0 -116
  322. package/dist/workflow/readers.d.ts +0 -36
  323. package/dist/workflow/readers.js +0 -145
  324. package/dist/workflow/wal.d.ts +0 -11
  325. package/dist/workflow/wal.js +0 -106
@@ -88,8 +88,9 @@ export async function webSearch(args, parallel, signal) {
88
88
  return { error: error?.name === "TimeoutError" ? "Parallel's search did not answer within 60 s" : `Parallel's search failed: ${error?.message ?? String(error)}` };
89
89
  }
90
90
  }
91
- /** `{query, n?}` searched by the provider the run's plane resolves web_search to, as a Search. */
92
- export async function searchFor(env, args, signal) {
91
+ /** `{query, n?}` searched by the provider the run's plane resolves web_search to, as a Search. `models`: the run's own
92
+ * models a native search goes through (none: a native search has no model to search on). */
93
+ export async function searchFor(env, args, signal, models) {
93
94
  const plane = planeOf(env);
94
95
  if (plane.web_search === "parallel")
95
96
  return webSearch(args, parallelOf(env), signal);
@@ -99,7 +100,7 @@ export async function searchFor(env, args, signal) {
99
100
  if (!query)
100
101
  return { error: "web_search needs a query" };
101
102
  if (plane.web_search === "native")
102
- return hostedSearch(query, n, plane.model, signal);
103
+ return hostedSearch(query, n, plane.model, signal, await models?.());
103
104
  // Under --faux, Exa is the faux module's or none: a test never reaches the network.
104
105
  const faux = await fauxFetch(env, FAUX_EXA_ENV);
105
106
  if (env[FAUX_ENV] && !faux)
@@ -109,8 +110,8 @@ export async function searchFor(env, args, signal) {
109
110
  return "limit" in found ? { error: found.error } : found;
110
111
  }
111
112
  /** The agent's tool: the Search as JSON text. A run whose web_search resolves to Parallel reads its key as the tool is
112
- * made, when the run opens. */
113
- export function webSearchTool(env) {
113
+ * made, when the run opens; one that resolves native searches through `models`, the run's own (ToolHost.search). */
114
+ export function webSearchTool(env, models) {
114
115
  const provider = planeOf(env).web_search;
115
116
  const parallel = provider === "parallel";
116
117
  if (parallel)
@@ -129,7 +130,7 @@ export function webSearchTool(env) {
129
130
  },
130
131
  replay: "safe",
131
132
  execute: async (args, _api, context) => {
132
- const answer = fitSearch(await searchFor(env, args, context?.abortSignal));
133
+ const answer = fitSearch(await searchFor(env, args, context?.abortSignal, models));
133
134
  return forModel(searchText(answer), { details: answer });
134
135
  },
135
136
  });
@@ -1,32 +1,50 @@
1
- import { type SealedSettingsOverStore, type SettingsSpec } from "./sealed-settings-store.js";
2
- import type { Settings } from "./store/index.js";
1
+ import type { Store } from "./store/index.js";
3
2
  import type { TriggerFailed } from "./triggers.js";
4
- /** A run's two notices, which runs.ts tells. */
3
+ /** A run's two notices, which the server's run-change follower tells. */
5
4
  export declare const RUN_EVENTS: readonly ["run.needs_input", "run.ended"];
6
5
  /** Every message type a webhook is sent: a run's notices, and a trigger's failed firing (triggers.ts). */
7
6
  export declare const WEBHOOK_EVENTS: readonly ["run.needs_input", "run.ended", "trigger.failed"];
8
7
  /** The message types: a run's two notices, and the test send's. */
9
8
  export declare const MESSAGE_TYPES: readonly ["run.needs_input", "run.ended", "trigger.failed", "webhook.test"];
10
9
  type MessageType = (typeof MESSAGE_TYPES)[number];
11
- /** The store setting the webhook is kept in: its URL, when its secret was made, and why it is off, if it is. */
12
- export declare const WEBHOOK_SETTING = "webhook";
13
- /** The store setting the outbox is kept in: the messages, the last attempts and the ledger, written whole. */
14
- export declare const OUTBOX_SETTING = "webhook_outbox";
15
- /** The webhook's signing secret among the server's sealed settings (sealed-settings-store.ts): minted at the first PUT,
16
- * kept sealed in the store, retired (still cut from what runs say) when it goes. Not a trigger source: its own adapter id. */
17
- export declare const OUTBOUND_WEBHOOK: {
18
- readonly id: string;
19
- readonly settings: SettingsSpec;
20
- };
10
+ /** The file an earlier version kept the webhook in, beside its store: never read, only said at a start when it is left. */
11
+ export declare const WEBHOOK_FILE = "webhook.json";
12
+ /** The webhook's channel in the store (channel_posts, channel_attempts, channel_told) and its secret's adapter in
13
+ * trigger_settings. */
14
+ export declare const WEBHOOK_CHANNEL = "webhook-out";
15
+ /** The store setting that holds the webhook's URL, when its secret was made, and why it is off. */
16
+ export declare const WEBHOOK_SETTING = "webhook-out";
21
17
  /** The waits before each try again, after the first at once: the Standard Webhooks schedule, cut at about a day. */
22
18
  export declare const RETRY_MS: readonly number[];
23
19
  /** How many attempts the log keeps, and with them the messages they tried, for a redelivery. */
24
20
  export declare const ATTEMPTS_KEPT = 50;
25
- /** What a notice says of its run: never its tools' arguments, its output or its input, which a receiver reads through the API. */
26
- /** What `emit` did with a notice: `queued`, in the outbox in the store (or already there, or counted as sent); `unsaved`,
27
- * held here only, its outbox write failed; `off`, no webhook set, or one a 410 turned off, so nothing is to be sent;
28
- * `closed`, the server is stopping. */
21
+ /** Where its secret is kept in trigger_settings (adapter WEBHOOK_CHANNEL): the server's one scope, one minted field. */
22
+ export declare const WEBHOOK_SECRET_SPEC: {
23
+ scope: "server";
24
+ fields: {
25
+ secret: {
26
+ mint: true;
27
+ };
28
+ };
29
+ };
30
+ /** The webhook's URL as the server shows it (GET, its log): its origin and the last four characters of its path, never
31
+ * the whole URL, which can be a credential itself (a chat service's incoming-hook URL). */
32
+ export declare function shownUrl(url: string): string;
33
+ /** What the webhook takes beside its store: `retryMs`, the waits between tries; `privateTargets`, whether it may send to a
34
+ * private network or this machine (the operator's AGENTRUN_WEBHOOK_PRIVATE_TARGETS, never the API's); `lookup`, every
35
+ * address a name resolves to (the system resolver by default); `storeRetryMs`, the wait before a try the store failed is
36
+ * tried again (STORE_RETRY_MS by default). */
37
+ export type WebhooksOptions = {
38
+ retryMs?: readonly number[];
39
+ privateTargets?: boolean;
40
+ lookup?: (host: string) => Promise<string[]>;
41
+ storeRetryMs?: number;
42
+ };
43
+ /** What `emit` did with a notice: `queued`, in the store (or already there, or counted as sent); `unsaved`, the store
44
+ * refused the write, so the caller tells it again; `off`, no webhook set, or one a 410 turned off, so nothing is to be
45
+ * sent; `closed`, the server is stopping. */
29
46
  export type Emitted = "queued" | "unsaved" | "off" | "closed";
47
+ /** What a notice says of its run: never its tools' arguments, its output or its input, which a receiver reads through the API. */
30
48
  export type RunNotice = {
31
49
  run_id: string;
32
50
  agent_id: string;
@@ -48,13 +66,6 @@ export type Attempt = {
48
66
  };
49
67
  /** Whether the secret signs here: sealed, or not, for a seal key it does not open under (or damaged). */
50
68
  type Signing = "sealed" | "unreadable";
51
- /** The store slice the webhook reads and writes: its two settings, and the durable commit after each write. */
52
- export type WebhookStore = {
53
- readonly settings: Pick<Settings, "get" | "put" | "remove">;
54
- flush(): Promise<void>;
55
- };
56
- /** The webhook's secret, among the server's sealed settings (OUTBOUND_WEBHOOK), loaded before the webhook is. */
57
- export type WebhookSecret = Pick<SealedSettingsOverStore, "get" | "mint" | "remove">;
58
69
  export { signatureOf } from "./standard-webhooks.js";
59
70
  /** The mark of the wait a run stands at, its webhook-id's marker: one per ask, however often or whenever the run is read,
60
71
  * so every read of the same ask makes the same webhook-id. A question's is its waiting row (run-view.ts withAsks: the
@@ -73,19 +84,16 @@ export declare function waitMarkerOf(rows: readonly {
73
84
  asked_at?: unknown;
74
85
  cap_usd?: unknown;
75
86
  } | null | undefined, waiting: boolean, learningLabel: string): string | undefined;
87
+ /** The store slice the webhook reads and writes. */
88
+ export type WebhooksStore = Pick<Store, "settings" | "triggerSettings" | "channels" | "flush">;
76
89
  export declare class Webhooks {
77
90
  private readonly store;
78
- private readonly secret;
79
91
  private readonly say;
80
- private readonly retryMs;
81
- private messages;
82
- private attempts;
83
- /** The ledger, by run: written with the messages, in the same write. */
84
- private notices;
85
- /** The webhook as the store holds it: read at load, then kept with every write (this server is the store's one writer).
86
- * A write that failed (a 410 that turned it off, on a store that refused the write) leaves it held here as it now is, and
87
- * the next PUT writes it whole. */
88
- private current?;
92
+ private readonly secrets;
93
+ private config?;
94
+ /** The ledger, by run, as channel_told holds it (this server is its one writer), and the waits seen while nothing is
95
+ * sent, held here only. */
96
+ private readonly notices;
89
97
  /** The runs told of since this server started: their ledger entries are this server's news, which a start's catch-up
90
98
  * never drops. */
91
99
  private readonly told;
@@ -93,31 +101,40 @@ export declare class Webhooks {
93
101
  private readonly timers;
94
102
  /** The tries in flight, which close() stops and waits for: nothing is written once it is closed. */
95
103
  private readonly trying;
104
+ /** The messages with a try in flight, and how many: a settle keeps each in the store until it lands, so one whose
105
+ * earlier attempts left the log meanwhile can still be redelivered. */
106
+ private readonly sending;
96
107
  private readonly stop;
97
108
  private closed;
98
- /** The outbox as held here is not in the store: its last write failed. Written again soon, and at the close. */
99
- private unsaved;
100
- private saving?;
101
- /** The outbox's writes, one after another: each writes the outbox as it stands when its turn comes. */
102
- private writing;
103
- /** What reads the webhook and then writes it (a PUT, a DELETE, a try's 410 that turns it off), one after another: each
104
- * reads it as the last one left it, so a 410 never turns off a webhook a PUT set again meanwhile. */
109
+ /** What reads the webhook and then writes it (a PUT, a DELETE, a try's outcome and its 410), one after another: each
110
+ * reads it as the last one left it, so a 410 never turns off a webhook a PUT set again meanwhile, and two first PUTs
111
+ * never each show a secret the other replaced. */
105
112
  private changing;
106
- /** A DELETE under way: no notice is queued meanwhile, so none slips past its drop of the pending messages. */
113
+ /** A DELETE under way: no notice is queued meanwhile, so none slips past its drop of the queued messages. */
107
114
  private removing;
108
- /** The messages with a try in flight, by id, and how many: kept in the outbox until each lands, so one whose earlier
109
- * attempts left the log meanwhile can still be redelivered. */
110
- private readonly sending;
111
- /** `store` keeps the webhook and its outbox, `secret` its signing secret (the server's sealed settings for
112
- * OUTBOUND_WEBHOOK, loaded); `say` takes a log line's fields; `retryMs` the waits between tries. load() before use. */
113
- constructor(store: WebhookStore, secret: WebhookSecret, say: (fields: Record<string, string | number>) => void, retryMs?: readonly number[]);
114
- /** Reads the webhook and the outbox as the last server left them, and goes on with the messages it left pending, each at
115
- * its next try's time; a test send is tried once, so one left in flight failed. Awaited once, before anything else. */
115
+ /** The tries' writes the store refused, each waiting to be written again (resettle), by its timer: the close writes each
116
+ * at once instead. */
117
+ private readonly rewriting;
118
+ /** Those writes under way, which the close waits for, so each lands before the store closes. */
119
+ private readonly rewrites;
120
+ /** The message writes in flight (posted), each settled or not: a DELETE, and a 410's turn-off, waits for them before its drop. */
121
+ private readonly posting;
122
+ private readonly retryMs;
123
+ private readonly privateTargets;
124
+ private readonly lookup;
125
+ private readonly storeRetryMs;
126
+ /** `key` is the server's seal key; `say` takes a log line's fields. */
127
+ constructor(store: WebhooksStore, key: Buffer, say: (fields: Record<string, string | number>) => void, options?: WebhooksOptions);
128
+ /** Reads the webhook, its secret and its ledger once, and goes on with the messages an earlier server left queued, each
129
+ * at its next try's time; a test send is tried once, so one left queued failed. Awaited once at start. */
116
130
  load(): Promise<void>;
117
131
  /** Where the page is, for each notice's link to its run. */
118
132
  attach(base: string): void;
119
- /** GET: the URL, whether the secret signs here, and why the webhook is off, if it is; its secret's metadata (secret-writes.ts
120
- * SecretMeta), never the secret. */
133
+ /** The secret, and each one this webhook held before (removed by a DELETE, or replaced: kept retired in the store), for
134
+ * the server's list of its own secrets (server-secrets.ts): a run that echoes an old one is cut all the same. */
135
+ signingSecrets(): string[];
136
+ /** GET: the URL, whether the secret signs here, and why the webhook is off, if it is; its secret's metadata, never the
137
+ * secret. */
121
138
  view(): {
122
139
  configured: false;
123
140
  secret: import("./secret-writes.js").SecretMeta;
@@ -136,36 +153,43 @@ export declare class Webhooks {
136
153
  } | null;
137
154
  updated_at: string;
138
155
  };
139
- /** PUT: the URL, and the webhook on again. The first makes the secret and answers it, once; a later one keeps it, or
140
- * makes a new one (answered once) when the one kept does not open under this server's seal key. */
156
+ /** PUT: the URL, and the webhook on again. The first makes the secret and answers it, once, and so does one that changes
157
+ * the URL: a new receiver gets a new secret, so no one who may set the URL can have messages signed for another
158
+ * receiver. One that keeps the URL keeps the secret. A URL on a private network or this machine is refused (unless the
159
+ * operator allows it), by name or by any address its name resolves to; each try checks again (tryOnce). */
141
160
  save(body: Record<string, unknown>): Promise<{
142
161
  created: boolean;
143
162
  view: ReturnType<Webhooks["view"]>;
144
163
  secret?: string;
145
164
  }>;
146
- /** DELETE: the webhook gone, its secret with it (retired: still cut from what a run says), and its pending messages; the
147
- * log of attempts stays. */
165
+ /** The PUT's change, once every change before it has landed: the webhook as the last one left it, then the new one. */
166
+ private saveNow;
167
+ /** DELETE: the webhook gone, its queued messages with it, and its secret (retired: still cut from what a run says); the
168
+ * log of attempts stays. In that order: shut to new notices, its queued messages dropped, the setting removed, then
169
+ * every secret of the webhook, on every DELETE (none once gone), so a removal of a secret that failed is finished by
170
+ * the next DELETE, and whatever fails, nothing of the removed webhook is left to send, to it or to a later one. */
148
171
  remove(): Promise<void>;
172
+ /** `work`, once every change of the webhook asked for before it has settled, failed or not. */
173
+ private change;
149
174
  /** GET .../deliveries: the last attempts, newest first. */
150
- attemptsView(): {
175
+ attemptsView(): Promise<{
151
176
  attempts: Attempt[];
152
- };
177
+ }>;
153
178
  /** 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
154
- * webhook is set and on, and kept in the ledger in the same write. `marker` makes its webhook-id: the same moment, seen
155
- * again after a restart, has the same id, which is a receiver's idempotency key. An end before the webhook was set, or
156
- * past the outbox's day, counts as sent. */
179
+ * webhook is set and on, with its ledger row in the same transaction. `marker` makes its webhook-id: the same moment,
180
+ * seen again after a restart, has the same id, which is a receiver's idempotency key. An end before the webhook was
181
+ * set, or past the day, counts as sent. */
157
182
  emit(type: (typeof RUN_EVENTS)[number], run: RunNotice, marker: string): Promise<Emitted>;
158
183
  /** A trigger's failed firing (triggers.ts), queued once: its webhook-id is made from the firing's key, so the same
159
184
  * failure told again, by a later server too, is the same message. Its trigger keeps whether it was queued. */
160
185
  emitTrigger(failed: TriggerFailed, firingKey: string): Promise<Emitted>;
161
- /** A start's catch-up, once its runs are read (`rows`, the store's: a row with no state is an ended one). First, before
162
- * anything is awaited, the ledger as the store now stands: a run the store no longer has goes, and a wait of a run it
163
- * holds as ended goes (an end the webhook was off for never moved it past). Then each end the store holds that the
164
- * ledger does not, and that is still due, is queued under the store's end time, so under the same webhook-id: its
165
- * server was killed between the run's end and the outbox write, or that write never landed. `current` reads the run as
166
- * the store holds it right before its end is queued, with its notice (null: no such run now). The server takes
167
- * requests meanwhile, so a run continued since the rows were read has moved past that end, which was queued before it
168
- * could be continued: its end is not queued again. */
186
+ /** A start's catch-up, once its runs are read (`rows`, the store's: a row with no state is an ended one). First the
187
+ * ledger as the store now stands: a run the store no longer has goes, and a wait of a run it holds as ended goes (an
188
+ * end the webhook was off for never moved it past). Then each end the store holds that the ledger does not, and that is
189
+ * still due, is queued under the store's end time, so under the same webhook-id. `current` reads the run as the store
190
+ * holds it right before its end is queued, with its notice (null: no such run now): a run continued since the rows
191
+ * were read has moved past that end, which is not queued again. Answers the runs whose end the store refused to queue
192
+ * (`unsaved`): the caller tells each again until it is saved (server.ts endsLeft), since no feed change will. */
169
193
  catchUp(rows: Iterable<{
170
194
  id: string;
171
195
  state?: string;
@@ -174,52 +198,71 @@ export declare class Webhooks {
174
198
  state?: string;
175
199
  endedAt?: string;
176
200
  notice: RunNotice;
177
- } | null>): Promise<void>;
201
+ } | null>): Promise<string[]>;
178
202
  /** POST .../test: a `webhook.test` message tried once now, never again; its attempt. */
179
203
  test(): Promise<Attempt>;
204
+ /** A message (and its ledger row, `told`) queued in one transaction, then made durable (the store's flush, as every write
205
+ * the server confirms is) before it is answered or tried: a crash of the machine never loses a message answered
206
+ * `queued`, nor the row that keeps it from being told twice. Tracked while in flight, so a DELETE waits for it. */
207
+ private posted;
180
208
  /** POST .../deliveries/{webhook_id}/redeliver: the message sent again once now, under its own webhook-id and body. */
181
209
  redeliver(id: string): Promise<Attempt>;
182
- /** Stops: no try starts, those in flight are cut and waited for, and nothing more is written but what a failed write left
183
- * only here. A message cut here is still pending in the store, for the next server (its receiver may get it twice,
184
- * under the same webhook-id). Before the store closes. */
210
+ /** Stops: no try starts, those in flight are cut and waited for, and nothing more is written but the tries' writes the
211
+ * store refused before (resettle), each written now and waited for, so a try's known outcome (a delivered message, a
212
+ * 410's turn-off) lands before the store closes. A message cut here is still queued in the store, for the next server
213
+ * (its receiver may get it twice, under the same webhook-id). */
185
214
  close(): Promise<void>;
186
- private config;
187
- /** Whether what is held here is in the store: once every outbox write asked for so far has settled (each writes it
188
- * whole), `queued` when the last one landed, else `unsaved`. A moment told again while its first write is still in
189
- * flight waits for it, never answering `queued` before it lands. */
190
- private landed;
191
- /** `work`, once every change of the webhook asked for before it has settled, failed or not. */
192
- private change;
193
- /** The signing secret, opened here; undefined when there is none, or it does not open under this server's seal key. */
215
+ /** Why `url` may not be sent to (a private address, by name or by what the name resolves to now), or undefined. A name
216
+ * that does not resolve passes here: the try resolves it again, and refuses then. */
217
+ private privateAt;
218
+ /** The address a try dials for `url`, checked: every address its name resolves to now is public (unless the operator
219
+ * allows private ones), and the connection goes to the one checked, so a name that resolves again between the check
220
+ * and the connect cannot reach another. A refusal in words. */
221
+ private dialled;
222
+ private signing;
223
+ /** The secret the webhook's setting names, opened here; undefined when none is set, or it does not open here. */
194
224
  private signingSecret;
195
- /** Throws when the write fails: the webhook as held here stays as it was. */
225
+ private body;
226
+ /** The setting written, then held here: a write the store refuses throws, and what was held stays held. */
196
227
  private write;
197
- /** The outbox as the last server left it. One of another version is not read, and the log says which it was. */
198
- private outboxOf;
199
- /** Whether an end's run.ended is still to be queued: at or after the webhook was set and the outbox's day began (a
200
- * marker that names no time is not judged by one). The catch-up and the ledger's pruning read the same line, so the
201
- * ledger never forgets an end a start would look for. */
228
+ /** 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
229
+ * names no time is not judged by one). The catch-up and the ledger's pruning read the same line, so the ledger never
230
+ * forgets an end a start would look for. */
202
231
  private due;
203
- /** The ledger without what no start looks for: a run whose end is no longer due goes, with the waits it ended past.
204
- * Waits with no end after them stay while the run stands at it, however long: never pruned by age, so the same question
205
- * is never asked again. */
232
+ /** The ledger's ends no longer due go (a start would not look for them). Waits with no end after them stay while the run
233
+ * stands at them, however long: never pruned by age, so the same question is never asked again. */
206
234
  private prune;
207
- /** The outbox written, after every write asked for before it; whether it landed. One that failed is kept here and
208
- * written again until a write lands (or the close writes it). Closed, nothing is written: the store may be the next
209
- * server's already. */
210
- private writeOutbox;
211
- /** The outbox written whole, in one durable commit: the last attempts, and the messages pending or tried by one of
212
- * those (a redelivery sends one again). False when the write failed, which the log says once until one lands. */
213
- private persist;
214
- /** A new pending message, and its outbox write (whether it landed). */
215
- private enqueue;
216
235
  private schedule;
217
236
  private attempt;
218
237
  /** One try: POSTed, signed, to the URL set now; no redirect followed, at most 15 s. Not 2xx: tried again after the
219
- * next wait (`retry`), else failed, and the log says so. A 410 turns the webhook off. A redelivery is a try of its
220
- * own: it settles a message still pending when it lands, and never fails one. */
238
+ * next wait (`retry`), else dropped, and the log says so. A 410 turns the webhook off. A redelivery is a try of its
239
+ * own: it marks a message sent when it lands, and never drops one. */
221
240
  private tryOnce;
222
- /** Every pending message failed, with `why` in the log. */
241
+ /** A try's outcome written: the message's new state and the try, in one transaction; its next try armed; a 410 that
242
+ * still names the webhook as it stands turns it off.
243
+ *
244
+ * Every write of a message's state after a try is fenced, never worked out from a read of the message: a message's
245
+ * own try writes under its claim (`claimed`, taken by `tryId`), and the store writes it only while the message still
246
+ * holds that claim (Channels.settle), so a write that lands late, after a redelivery sent the message, a newer try
247
+ * claimed it or a DELETE dropped it, changes nothing and arms nothing. A redelivery claims nothing: a landed one writes
248
+ * sent, which no try's write undoes (sent is final), and a failed one writes no state at all, only its try. */
249
+ private settleTry;
250
+ /** What follows a try's write: its next try armed and its failure said, only when its state was written (`written`: a
251
+ * fenced write that found the message taken by something newer arms nothing), and a 410's turn-off of the webhook as it
252
+ * stands, whatever the message's state, since it is the receiver's answer. The 410 is checked again against the webhook
253
+ * as it stands now: one whose write landed late (resettle), after a PUT set another URL or a DELETE removed it, was the
254
+ * old URL's, and turns nothing off. */
255
+ private afterSettle;
256
+ /** A try's write the store refused (`write`), written again after the store's wait until it lands, then what follows it
257
+ * (`after`, told whether the state was written), among the webhook's changes. Its own timer, beside the message's: the
258
+ * message keeps its schedule meanwhile. The write is the same one, under the same fence (settleTry): it reads nothing
259
+ * first, and a message's own try writes only while the message still holds its claim, so one a DELETE dropped, a
260
+ * redelivery sent or a newer try claimed meanwhile is left as that left it. One under way when the server closes is
261
+ * waited for, and one waiting is written at the close (close); one refused again then is left as the store holds it,
262
+ * for the next server. */
263
+ private resettle;
264
+ /** Every queued message dropped, with `why` in the log. `strict`: a drop the store refuses throws (a DELETE then fails
265
+ * before anything else of it is done); else it is let be, and a queued message's try finds the webhook off. */
223
266
  private drop;
224
267
  /** The webhook, set and on: a test or a redelivery sends nothing to one a 410 turned off, as no try does. */
225
268
  private need;