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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (234) hide show
  1. package/CHANGELOG.md +142 -2
  2. package/README.md +310 -98
  3. package/dist/adapters.d.ts +11 -0
  4. package/dist/adapters.js +49 -0
  5. package/dist/agent-package.d.ts +3 -3
  6. package/dist/agent-package.js +6 -13
  7. package/dist/agents-store.js +6 -5
  8. package/dist/answer-json.d.ts +6 -2
  9. package/dist/answer-json.js +22 -4
  10. package/dist/api-only.d.ts +16 -4
  11. package/dist/api-only.js +23 -7
  12. package/dist/calendar/tools.js +3 -2
  13. package/dist/chatgpt-plan.d.ts +16 -1
  14. package/dist/chatgpt-plan.js +116 -12
  15. package/dist/claude-login.d.ts +34 -5
  16. package/dist/claude-login.js +31 -7
  17. package/dist/claude-sign-in.d.ts +35 -0
  18. package/dist/claude-sign-in.js +90 -0
  19. package/dist/cli.js +5 -3
  20. package/dist/composio-made.d.ts +26 -1
  21. package/dist/composio-made.js +39 -2
  22. package/dist/composio-preset.d.ts +3 -2
  23. package/dist/composio-preset.js +46 -14
  24. package/dist/computer-held-routes.js +2 -3
  25. package/dist/computer-setting.d.ts +4 -2
  26. package/dist/computer-setting.js +0 -2
  27. package/dist/computers-running.d.ts +8 -0
  28. package/dist/computers-running.js +27 -0
  29. package/dist/console/assets/backend-Boh7tC4i.js +166 -0
  30. package/dist/console/assets/index-CQ3cJRzI.js +746 -0
  31. package/dist/console/assets/index-DKkaS3a0.css +1 -0
  32. package/dist/console/index.html +2 -2
  33. package/dist/docker-host-addresses.d.ts +23 -3
  34. package/dist/docker-host-addresses.js +90 -18
  35. package/dist/exa-keyless.d.ts +2 -3
  36. package/dist/exa-keyless.js +43 -127
  37. package/dist/firecrawl-keyless.d.ts +41 -0
  38. package/dist/firecrawl-keyless.js +152 -0
  39. package/dist/handed-secret.d.ts +3 -1
  40. package/dist/handed-secret.js +4 -2
  41. package/dist/harness-keys.d.ts +98 -0
  42. package/dist/harness-keys.js +247 -0
  43. package/dist/harness-recipe-entry.d.ts +14 -9
  44. package/dist/harness-recipe-entry.js +25 -14
  45. package/dist/harness-table.d.ts +16 -1
  46. package/dist/harness-table.js +19 -7
  47. package/dist/harness.d.ts +4 -0
  48. package/dist/harness.js +12 -1
  49. package/dist/host-check.d.ts +6 -0
  50. package/dist/host-check.js +10 -0
  51. package/dist/import-summary.d.ts +1 -1
  52. package/dist/import-summary.js +1 -1
  53. package/dist/import.d.ts +5 -5
  54. package/dist/import.js +54 -67
  55. package/dist/key-refusal.d.ts +21 -5
  56. package/dist/key-refusal.js +231 -37
  57. package/dist/keyless-mcp.d.ts +36 -0
  58. package/dist/keyless-mcp.js +127 -0
  59. package/dist/learn/audit.d.ts +3 -3
  60. package/dist/learn/audit.js +3 -3
  61. package/dist/learn/commit.d.ts +8 -7
  62. package/dist/learn/commit.js +60 -20
  63. package/dist/learn/compile.d.ts +4 -3
  64. package/dist/learn/compile.js +7 -5
  65. package/dist/learn/folder.d.ts +16 -3
  66. package/dist/learn/folder.js +46 -13
  67. package/dist/learn/promote.d.ts +37 -13
  68. package/dist/learn/promote.js +112 -40
  69. package/dist/learn/secrets.d.ts +20 -10
  70. package/dist/learn/secrets.js +44 -176
  71. package/dist/learning-routes.d.ts +22 -17
  72. package/dist/learning-routes.js +40 -39
  73. package/dist/learning.js +2 -2
  74. package/dist/llms.txt +1 -1
  75. package/dist/manifest.d.ts +10 -0
  76. package/dist/manifest.js +30 -0
  77. package/dist/mcp-pin-first.d.ts +4 -2
  78. package/dist/mcp-pin-first.js +5 -2
  79. package/dist/mcp-secret-writes.d.ts +16 -7
  80. package/dist/mcp-secret-writes.js +35 -27
  81. package/dist/mcp-servers-store.d.ts +30 -6
  82. package/dist/mcp-servers-store.js +112 -28
  83. package/dist/mcp-sources.d.ts +10 -2
  84. package/dist/mcp-sources.js +9 -2
  85. package/dist/mcp-store.d.ts +13 -7
  86. package/dist/mcp-store.js +12 -9
  87. package/dist/model-form.d.ts +3 -2
  88. package/dist/model-form.js +11 -7
  89. package/dist/model.d.ts +20 -4
  90. package/dist/model.js +68 -9
  91. package/dist/native/history.d.ts +1 -1
  92. package/dist/native/history.js +2 -2
  93. package/dist/ollama-provider.d.ts +92 -0
  94. package/dist/ollama-provider.js +495 -0
  95. package/dist/openapi/agentrun-v2.openapi.json +2 -2
  96. package/dist/openapi.d.ts +3 -3
  97. package/dist/openapi.js +197 -55
  98. package/dist/page.d.ts +11 -3
  99. package/dist/page.js +22 -7
  100. package/dist/place-offers.d.ts +25 -1
  101. package/dist/place-offers.js +62 -8
  102. package/dist/print.js +1 -1
  103. package/dist/purged-workflow.d.ts +35 -7
  104. package/dist/purged-workflow.js +73 -26
  105. package/dist/redact/match.d.ts +74 -0
  106. package/dist/redact/match.js +771 -0
  107. package/dist/run-computer.d.ts +2 -0
  108. package/dist/run-computer.js +2 -0
  109. package/dist/run-files.d.ts +4 -0
  110. package/dist/run-files.js +4 -0
  111. package/dist/run-keys.d.ts +2 -4
  112. package/dist/run-keys.js +6 -7
  113. package/dist/run-launch.d.ts +4 -0
  114. package/dist/run-launch.js +4 -0
  115. package/dist/run-reads-over-store.d.ts +3 -2
  116. package/dist/run-reads-over-store.js +66 -2
  117. package/dist/run-secrets.js +5 -2
  118. package/dist/run-timeline-served.d.ts +1 -1
  119. package/dist/run-timeline-served.js +4 -4
  120. package/dist/runner/adapter-loop.d.ts +9 -3
  121. package/dist/runner/adapter-loop.js +34 -15
  122. package/dist/runner/adapter-run-spec.d.ts +3 -0
  123. package/dist/runner/adapter-run-spec.js +9 -4
  124. package/dist/runner/audit.js +8 -4
  125. package/dist/runner/beside.d.ts +2 -1
  126. package/dist/runner/beside.js +13 -5
  127. package/dist/runner/claim-secrets.d.ts +5 -8
  128. package/dist/runner/claim-secrets.js +6 -0
  129. package/dist/runner/cli-run-spec.d.ts +1 -1
  130. package/dist/runner/cli-run-spec.js +41 -7
  131. package/dist/runner/harness-loops.d.ts +22 -9
  132. package/dist/runner/harness-loops.js +21 -11
  133. package/dist/runner/held.d.ts +3 -0
  134. package/dist/runner/learning-end.d.ts +1 -1
  135. package/dist/runner/learning-end.js +8 -3
  136. package/dist/runner/loop-contract.d.ts +9 -4
  137. package/dist/runner/main.js +12 -6
  138. package/dist/runner/mcp-claim.d.ts +3 -0
  139. package/dist/runner/mcp-claim.js +26 -2
  140. package/dist/runner/mcp-run.d.ts +3 -0
  141. package/dist/runner/mcp-run.js +2 -1
  142. package/dist/runner/metrics.d.ts +10 -10
  143. package/dist/runner/metrics.js +19 -38
  144. package/dist/runner/model-route.d.ts +3 -0
  145. package/dist/runner/model-route.js +6 -2
  146. package/dist/runner/presence.d.ts +4 -3
  147. package/dist/runner/presence.js +4 -2
  148. package/dist/runner/promotion.d.ts +15 -9
  149. package/dist/runner/promotion.js +25 -15
  150. package/dist/runner/run-child-host.d.ts +2 -0
  151. package/dist/runner/run-child-host.js +19 -9
  152. package/dist/runner/run-child.js +3 -1
  153. package/dist/runner/runner.d.ts +4 -0
  154. package/dist/runner/runner.js +33 -3
  155. package/dist/runner/sdk-loop.js +2 -0
  156. package/dist/runner/workflow-loop.d.ts +2 -2
  157. package/dist/runner/workflow-loop.js +1 -2
  158. package/dist/runner/workflow-spec.d.ts +1 -1
  159. package/dist/runner/workflow-spec.js +6 -6
  160. package/dist/sdk/check.d.ts +4 -1
  161. package/dist/sdk/check.js +2 -1
  162. package/dist/sdk/runs.d.ts +2 -2
  163. package/dist/sdk/runs.js +8 -6
  164. package/dist/secret-cut.js +2 -1
  165. package/dist/secret-writes.d.ts +3 -2
  166. package/dist/secret-writes.js +1 -1
  167. package/dist/server.d.ts +49 -10
  168. package/dist/server.js +324 -118
  169. package/dist/standard-webhooks.d.ts +11 -0
  170. package/dist/standard-webhooks.js +20 -2
  171. package/dist/store/dialect.d.ts +3 -0
  172. package/dist/store/dialect.js +1 -0
  173. package/dist/store/index.d.ts +2 -2
  174. package/dist/store/index.js +1 -1
  175. package/dist/store/postgres/dialect.js +3 -0
  176. package/dist/store/schema.js +5 -2
  177. package/dist/store/sqlite/store.js +133 -47
  178. package/dist/store/store.d.ts +64 -15
  179. package/dist/store/store.js +7 -0
  180. package/dist/store-reads/journal.d.ts +7 -2
  181. package/dist/store-reads/journal.js +9 -6
  182. package/dist/store-reads/learning.d.ts +12 -9
  183. package/dist/store-reads/learning.js +18 -24
  184. package/dist/store-view.d.ts +0 -5
  185. package/dist/store-view.js +10 -9
  186. package/dist/template-eval.d.ts +51 -6
  187. package/dist/template-eval.js +177 -53
  188. package/dist/template-import.js +4 -2
  189. package/dist/templates.d.ts +5 -3
  190. package/dist/templates.js +19 -40
  191. package/dist/timeline/index.d.ts +1 -1
  192. package/dist/timeline/index.js +1 -1
  193. package/dist/timeline/labels.d.ts +2 -2
  194. package/dist/timeline/labels.js +2 -2
  195. package/dist/timeline/timeline.d.ts +14 -9
  196. package/dist/timeline/timeline.js +15 -7
  197. package/dist/tool-gate.js +3 -1
  198. package/dist/tool-plane.d.ts +17 -9
  199. package/dist/tool-plane.js +38 -17
  200. package/dist/tools.js +2 -2
  201. package/dist/trigger-launch-hook.d.ts +16 -8
  202. package/dist/trigger-launch-hook.js +32 -23
  203. package/dist/trigger-targets.d.ts +18 -8
  204. package/dist/trigger-targets.js +42 -19
  205. package/dist/triggers.d.ts +85 -23
  206. package/dist/triggers.js +303 -96
  207. package/dist/validate.js +1 -1
  208. package/dist/web-fake.js +3 -3
  209. package/dist/web-fetch-direct.d.ts +4 -0
  210. package/dist/web-fetch-direct.js +8 -1
  211. package/dist/web-fetch.d.ts +12 -3
  212. package/dist/web-fetch.js +47 -14
  213. package/dist/web-search.d.ts +33 -4
  214. package/dist/web-search.js +100 -41
  215. package/dist/webhooks.js +4 -5
  216. package/dist/workspace/computer-deps.d.ts +2 -1
  217. package/dist/workspace/computer-deps.js +5 -4
  218. package/dist/workspace/computer-for-claim.d.ts +8 -2
  219. package/dist/workspace/computer-for-claim.js +28 -9
  220. package/dist/workspace/computer-janitor.d.ts +15 -7
  221. package/dist/workspace/computer-janitor.js +33 -8
  222. package/dist/workspace/computer-kept.d.ts +52 -4
  223. package/dist/workspace/computer-kept.js +118 -6
  224. package/dist/workspace/run-end-computers.d.ts +5 -1
  225. package/dist/workspace/run-end-computers.js +27 -1
  226. package/dist/wrapped.d.ts +57 -0
  227. package/dist/wrapped.js +51 -0
  228. package/launcher/agentrun-serve +5 -1
  229. package/package.json +17 -13
  230. package/templates/README.md +10 -9
  231. package/dist/console/assets/index-B_85An2t.js +0 -745
  232. package/dist/console/assets/index-n1YsbnYh.css +0 -1
  233. package/dist/import-sources.d.ts +0 -116
  234. package/dist/import-sources.js +0 -693
@@ -1,39 +1,33 @@
1
- // web_search's keyless fallback: Exa's public MCP endpoint (https://mcp.exa.ai/mcp, docs.exa.ai/reference/exa-mcp),
2
- // which answers its `web_search_exa` tool with no key at a free rate limit. One search is one MCP exchange over its
3
- // streamable HTTP transport: `initialize` (its session id, when it names one), `notifications/initialized`, then
4
- // `tools/call` of web_search_exa with `{query, numResults}`, at most 8. Exa answers one text block, a result per section split by
5
- // `---` lines, each `Title:`, `URL:`, `Published:`, `Author:`, then `Highlights:` (or `Text:`) and its lines; a `Note:`
6
- // line may lead it. That text is read into the same Search every web_search answers, and no more than 1 MiB of an
7
- // answer is read. Past its free limit Exa answers a 429 with Retry-After, or (when its search API refuses the keyless
8
- // call) a 200 whose tool result is marked isError and `ai.exa/rateLimited`, its text telling the user to put an API key
9
- // in their MCP URL. Either is tried once more, a new exchange after a jittered 1 to 3 s or the Retry-After Exa names when
10
- // it is 5 s or less (past that, as with its daily limit, the limit does not lift within a search, and it is not tried
11
- // again); still limited, the search answers RATE_LIMITED, in our words, never Exa's. Any other failure Exa answers is
12
- // ours too, quoting only the first sentence of Exa's (exaSaid). A 403 is a connection keyless use
13
- // refuses (Exa takes it over IPv4, straight to the endpoint), never tried again. Both say which limit they met
14
- // (ExaLimited), for the caller's fallback. A search ends at 60 s, its retry and wait included. No key is sent, ever.
15
- // Exa is dialled over IPv4 alone (ipv4Fetch): its name looked up for family 4 and the connection made to that address,
16
- // so a host whose default route is IPv6 reaches it the one way keyless use is taken.
1
+ // web_search's keyless fallback, behind keyless Firecrawl (firecrawl-keyless.ts) or alone where it is picked: Exa's
2
+ // public MCP endpoint (https://mcp.exa.ai/mcp, docs.exa.ai/reference/exa-mcp), which answers its `web_search_exa` tool
3
+ // with no key at a free rate limit. One search is one MCP exchange through the shared client (keyless-mcp.ts callTool):
4
+ // `tools/call` of web_search_exa with `{query, numResults}`, at most 8. Exa answers one text block, a result per section
5
+ // split by `---` lines, each `Title:`, `URL:`, `Published:`, `Author:`, then `Highlights:` (or `Text:`) and its lines; a
6
+ // `Note:` line may lead it. That text is read into the same Search every web_search answers. Past its free limit Exa
7
+ // answers a 429 with Retry-After, or (when its search API refuses the keyless call) a 200 whose tool result is marked
8
+ // isError and `ai.exa/rateLimited`, its text telling the user to put an API key in their MCP URL. Either is tried once
9
+ // more, a new exchange after a jittered 1 to 3 s or the Retry-After Exa names when it is 5 s or less (past that, as with
10
+ // its daily limit, the limit does not lift within a search, and it is not tried again); still limited, the search
11
+ // answers RATE_LIMITED, in our words, never Exa's. Any other failure Exa answers is ours too, quoting only the first
12
+ // sentence of Exa's (exaSaid). A 403 is a connection keyless use refuses (Exa takes it over IPv4, straight to the
13
+ // endpoint), never tried again. Both say which limit they met (ExaLimited), for the caller's breaker. A search ends at
14
+ // 60 s, its retry and wait included. No key is sent, ever. Exa is dialled over IPv4 alone (ipv4Fetch): its name looked
15
+ // up for family 4 and the connection made to that address, so a host whose default route is IPv6 reaches it the one way
16
+ // keyless use is taken.
17
17
  import { lookup as dnsLookup } from "node:dns";
18
+ import { callTool, RATE_LIMITED, sleep, textBlocks } from "./keyless-mcp.js";
18
19
  import { clip, TITLE_CAP } from "./web-fetch-direct.js";
19
20
  import { snippetOf } from "./web-search.js";
21
+ export { RATE_LIMITED };
20
22
  export const EXA_MCP_URL = "https://mcp.exa.ai/mcp";
21
23
  export const EXA_SEARCH_TOOL = "web_search_exa";
22
24
  /** Under `--faux` only: a module whose default export is the fetch Exa's MCP exchange goes through (the tests' fake
23
25
  * MCP server), in place of Exa's endpoint. */
24
26
  export const FAUX_EXA_ENV = "AGENTRUN_SERVE_FAUX_EXA";
25
- /** The MCP revision this client speaks; the server answers the one it takes. */
26
- const PROTOCOL = "2025-06-18";
27
27
  const TIMEOUT_MS = 60_000;
28
28
  /** The most results Exa's free endpoint is asked for (its default is 10). Its own cap on purpose, not web search's
29
29
  * RESULTS_MAX: the hosted providers take more, and Exa's keyless limit is per request. */
30
30
  const RESULTS_MAX = 8;
31
- const ACCEPT = "application/json, text/event-stream";
32
- /** The most of an answer read: a search's text is a few kilobytes; past this the rest is never read. */
33
- const MAX_BYTES = 1 << 20;
34
- /** What a search answers when Exa's free limit holds after the one retry. Exa's own words name a fix (an API key in
35
- * its MCP URL) that means nothing to a person here, so they are never passed on. */
36
- export const RATE_LIMITED = "Free web search is rate-limited right now. Try again in a minute; add the free Parallel Search server in Settings → MCP servers and grant the agent its web_search; or add a Parallel key in Settings → API Keys to search with a key.";
37
31
  /** The most of Exa's own words a failure quotes: the first sentence of its first line, cut on a word. */
38
32
  const SAID_MAX = 120;
39
33
  /** A failure Exa answered, in our words: the first sentence of its text, short and quoted. Its later lines (a fix for its
@@ -48,33 +42,9 @@ function exaSaid(text) {
48
42
  const RATE_LIMITED_META = "ai.exa/rateLimited";
49
43
  /** The longest Retry-After waited out before the one retry. */
50
44
  const RETRY_AFTER_MAX_S = 5;
51
- /** The seconds a Retry-After names, as seconds or a date; undefined when it names none. */
52
- function retryAfterOf(response) {
53
- const said = response.headers.get("retry-after")?.trim();
54
- if (!said)
55
- return undefined;
56
- if (/^\d+$/.test(said))
57
- return Number(said);
58
- const at = Date.parse(said);
59
- return Number.isNaN(at) ? undefined : Math.max(0, Math.ceil((at - Date.now()) / 1000));
60
- }
61
45
  /** The wait before the one retry: the Retry-After Exa named, else 1 to 3 s, each with jitter so runs limited together
62
46
  * do not all ask again at once. */
63
47
  const waitOf = (retryAfterS) => (retryAfterS === undefined ? 1_000 + Math.random() * 2_000 : retryAfterS * 1_000 + Math.random() * 500);
64
- /** `ms` of waiting that `signal` ends, rejecting with its reason. */
65
- const sleep = (ms, signal) => new Promise((resolve, reject) => {
66
- if (signal.aborted)
67
- return reject(signal.reason);
68
- const stop = () => {
69
- clearTimeout(timer);
70
- reject(signal.reason);
71
- };
72
- const timer = setTimeout(() => {
73
- signal.removeEventListener("abort", stop);
74
- resolve();
75
- }, ms);
76
- signal.addEventListener("abort", stop, { once: true });
77
- });
78
48
  /** A fetch that reaches hosts over IPv4 alone: each name looked up for family 4 (through `lookup`, default the system
79
49
  * resolver) and the connection dialled at the address found, never an IPv6 one. undici loads at the first request, so
80
50
  * a run that never searches never loads it; `close` ends the connections. */
@@ -88,36 +58,6 @@ export function ipv4Fetch(lookup = dnsLookup) {
88
58
  };
89
59
  return { send: send, close: async () => void (opened && (await (await opened).dispatcher.close())) };
90
60
  }
91
- /** At most MAX_BYTES of a body, as text; the rest is not read. */
92
- async function boundedText(response) {
93
- const reader = response.body?.getReader();
94
- const chunks = [];
95
- for (let size = 0; reader && size < MAX_BYTES;) {
96
- const { done, value } = await reader.read();
97
- if (done)
98
- break;
99
- chunks.push(value);
100
- size += value.byteLength;
101
- }
102
- await reader?.cancel().catch(() => undefined);
103
- return Buffer.concat(chunks).subarray(0, MAX_BYTES).toString("utf8");
104
- }
105
- /** A JSON-RPC answer's body: JSON, or the `data:` lines of an event stream, the one answering `id`. */
106
- async function answerOf(response, id) {
107
- const text = await boundedText(response);
108
- const messages = /event-stream/i.test(response.headers.get("content-type") ?? "")
109
- ? text.split("\n").filter((line) => line.startsWith("data:")).map((line) => line.slice(5).trim())
110
- : [text];
111
- for (const message of messages) {
112
- try {
113
- const parsed = JSON.parse(message);
114
- if (parsed.id === id)
115
- return parsed;
116
- }
117
- catch { }
118
- }
119
- return undefined;
120
- }
121
61
  /** Exa's text for one result as a Hit, or undefined when it names no URL. */
122
62
  function hitOf(section) {
123
63
  const lines = section.split("\n");
@@ -131,6 +71,28 @@ function hitOf(section) {
131
71
  const published = known(field("Published"));
132
72
  return { url, title: clip(known(field("Title")) ?? "", TITLE_CAP), snippet: snippetOf(snippet), ...(published ? { published } : {}) };
133
73
  }
74
+ /** One exchange's outcome as Exa's answer to a search for `query`, at most `n` results: its refusals and failures in our
75
+ * words, else its hits. */
76
+ function searchOf(called, query, n) {
77
+ if ("status" in called) {
78
+ if (called.status === 429)
79
+ return { error: RATE_LIMITED, limit: "rate_limited", ...(called.retryAfterS === undefined ? {} : { retryAfterS: called.retryAfterS }) };
80
+ if (called.status === 403)
81
+ return { error: "Exa refused keyless use from this connection (403): it takes keyless searches only over IPv4, straight to its endpoint, not over IPv6 or through a proxy", limit: "connection_refused" };
82
+ return { error: `Exa's MCP endpoint answered ${called.status} to ${called.step === "initialize" ? "initialize" : "the search"}` };
83
+ }
84
+ if ("error" in called)
85
+ return { error: called.rpc ? exaSaid(called.error) : "Exa's MCP endpoint did not answer initialize" };
86
+ const { result } = called;
87
+ const meta = result?._meta;
88
+ if (result?.isError === true && typeof meta === "object" && meta !== null && meta[RATE_LIMITED_META] === true)
89
+ return { error: RATE_LIMITED, limit: "rate_limited" };
90
+ const said = textBlocks(result);
91
+ if (!Array.isArray(result?.content) || result.isError === true)
92
+ return { error: exaSaid(said) };
93
+ const hits = said.split(/\n-{3,}\n/).flatMap((section) => hitOf(section) ?? []);
94
+ return { provider: "exa-keyless", query, results: hits.slice(0, n) };
95
+ }
134
96
  /** `query` searched on Exa's keyless MCP endpoint through `send` (a test's fake; default a fetch over IPv4 alone,
135
97
  * ipv4Fetch, closed when the search ends), at most `n` results: once, and once more past Exa's free limit after
136
98
  * `pause` (default a wait the search's signal ends; a test's records it). */
@@ -138,12 +100,13 @@ export async function exaSearch(query, n, { send, signal, pause = sleep } = {})
138
100
  const deadline = AbortSignal.any([AbortSignal.timeout(TIMEOUT_MS), ...(signal ? [signal] : [])]);
139
101
  const own = send ? undefined : ipv4Fetch();
140
102
  const dial = send ?? own.send;
103
+ const once = async () => searchOf(await callTool(EXA_MCP_URL, dial, deadline, EXA_SEARCH_TOOL, { query, numResults: Math.min(n, RESULTS_MAX) }), query, n);
141
104
  try {
142
- const first = await exchange(query, n, dial, deadline);
105
+ const first = await once();
143
106
  if (!("limit" in first) || first.limit !== "rate_limited" || (first.retryAfterS ?? 0) > RETRY_AFTER_MAX_S)
144
107
  return first;
145
108
  await pause(waitOf(first.retryAfterS), deadline);
146
- return await exchange(query, n, dial, deadline);
109
+ return await once();
147
110
  }
148
111
  catch (error) {
149
112
  const name = error?.name;
@@ -153,50 +116,3 @@ export async function exaSearch(query, n, { send, signal, pause = sleep } = {})
153
116
  await own?.close().catch(() => undefined);
154
117
  }
155
118
  }
156
- /** One MCP exchange searching `query` through `dial`, each request ended by `deadline`; a failure to reach Exa throws. */
157
- async function exchange(query, n, dial, deadline) {
158
- let session;
159
- const post = (body) => dial(EXA_MCP_URL, {
160
- method: "POST",
161
- headers: { "content-type": "application/json", accept: ACCEPT, "mcp-protocol-version": PROTOCOL, ...(session ? { "mcp-session-id": session } : {}) },
162
- body: JSON.stringify({ jsonrpc: "2.0", ...body }),
163
- signal: deadline,
164
- });
165
- const refused = async (response, step) => {
166
- if (response.ok)
167
- return undefined;
168
- await response.body?.cancel().catch(() => undefined);
169
- if (response.status === 429) {
170
- const retryAfterS = retryAfterOf(response);
171
- return { error: RATE_LIMITED, limit: "rate_limited", ...(retryAfterS === undefined ? {} : { retryAfterS }) };
172
- }
173
- if (response.status === 403)
174
- return { error: "Exa refused keyless use from this connection (403): it takes keyless searches only over IPv4, straight to its endpoint, not over IPv6 or through a proxy", limit: "connection_refused" };
175
- return { error: `Exa's MCP endpoint answered ${response.status} to ${step}` };
176
- };
177
- const opened = await post({ id: 1, method: "initialize", params: { protocolVersion: PROTOCOL, capabilities: {}, clientInfo: { name: "agentrun-serve", version: "1" } } });
178
- const failed = await refused(opened, "initialize");
179
- if (failed)
180
- return failed;
181
- session = opened.headers.get("mcp-session-id") ?? undefined;
182
- if (!(await answerOf(opened, 1))?.result)
183
- return { error: "Exa's MCP endpoint did not answer initialize" };
184
- const ready = await post({ method: "notifications/initialized" });
185
- await ready.body?.cancel().catch(() => undefined);
186
- const called = await post({ id: 2, method: "tools/call", params: { name: EXA_SEARCH_TOOL, arguments: { query, numResults: Math.min(n, RESULTS_MAX) } } });
187
- const late = await refused(called, "the search");
188
- if (late)
189
- return late;
190
- const answer = await answerOf(called, 2);
191
- if (answer?.error)
192
- return { error: exaSaid(typeof answer.error.message === "string" ? answer.error.message : "") };
193
- const meta = answer?.result?._meta;
194
- if (answer?.result?.isError === true && typeof meta === "object" && meta !== null && meta[RATE_LIMITED_META] === true)
195
- return { error: RATE_LIMITED, limit: "rate_limited" };
196
- const content = Array.isArray(answer?.result?.content) ? answer.result.content : undefined;
197
- const said = content?.flatMap((part) => (part.type === "text" && typeof part.text === "string" ? [part.text] : [])).join("\n") ?? "";
198
- if (!content || answer?.result?.isError === true)
199
- return { error: exaSaid(said) };
200
- const hits = said.split(/\n-{3,}\n/).flatMap((section) => hitOf(section) ?? []);
201
- return { provider: "exa-keyless", query, results: hits.slice(0, n) };
202
- }
@@ -0,0 +1,41 @@
1
+ import { type Read } from "./web-fetch-direct.js";
2
+ import { type Limit, type Search } from "./web-search.js";
3
+ export declare const FIRECRAWL_MCP_URL = "https://mcp.firecrawl.dev/v2/mcp";
4
+ export declare const FIRECRAWL_SEARCH_TOOL = "firecrawl_search";
5
+ export declare const FIRECRAWL_SCRAPE_TOOL = "firecrawl_scrape";
6
+ /** Under `--faux` only: the URL of a fake MCP server (a test's, on loopback) asked in place of Firecrawl's endpoint.
7
+ * Under --faux with none named, Firecrawl is never asked. */
8
+ export declare const FAUX_FIRECRAWL_ENV = "AGENTRUN_SERVE_FAUX_FIRECRAWL";
9
+ /** The most one call to Firecrawl takes: half a search's one deadline (web-search.ts KEYLESS_SEARCH_MS). */
10
+ export declare const FIRECRAWL_MS = 30000;
11
+ /** A call Firecrawl refused or failed, in our words, and the limit it met, if any (for the run's breaker). */
12
+ export type FirecrawlFailed = {
13
+ error: string;
14
+ limit?: Limit;
15
+ };
16
+ /** Where a call goes: `endpoint` (default Firecrawl's), through `send` (default fetch), ended at `timeoutMs` (default
17
+ * FIRECRAWL_MS) or by `signal`, whichever is first. */
18
+ export type FirecrawlOptions = {
19
+ endpoint?: string;
20
+ send?: typeof fetch;
21
+ signal?: AbortSignal;
22
+ timeoutMs?: number;
23
+ };
24
+ /** The limit a refusal's `code` names (QUOTA_CODES, RATE_CODES), with the wait its payload names; undefined for any
25
+ * other code. */
26
+ export declare function firecrawlLimitOf(payload: Record<string, unknown> | undefined): Limit | undefined;
27
+ /** `query` searched on Firecrawl's keyless endpoint, at most `n` results, its answer at most MAX_BYTES. */
28
+ export declare function firecrawlSearch(query: string, n: number, options?: FirecrawlOptions): Promise<Search | FirecrawlFailed>;
29
+ /** The page at `url` scraped by Firecrawl's keyless endpoint, as markdown, its answer at most the direct fetch's bound
30
+ * (pi-browser's PUBLIC_MAX_BYTES). Firecrawl names no cut, so the text is read as the whole page's. A page whose status
31
+ * is not 2xx is no read: the caller fetches directly, as for a refusal. */
32
+ export declare function firecrawlScrape(url: string, options?: FirecrawlOptions): Promise<Read | FirecrawlFailed>;
33
+ /** keyless Firecrawl's scrape for one run's web_fetch, with the run's breaker on it: `live` is false once a quota answer
34
+ * came (for the rest of the run) and while a rate limit's wait holds (waitOf: the wait Firecrawl named, else 60 s, at
35
+ * most 15 minutes); `read` is one scrape, the page or, for any failure, why there is none (the caller then fetches
36
+ * directly). `now` is the breaker's clock (a test's). */
37
+ export type KeylessFetch = {
38
+ live(): boolean;
39
+ read(url: string, signal?: AbortSignal): Promise<Read | string>;
40
+ };
41
+ export declare function firecrawlFetch(options?: Omit<FirecrawlOptions, "signal">, now?: () => number): KeylessFetch;
@@ -0,0 +1,152 @@
1
+ // Keyless Firecrawl: Firecrawl's public MCP endpoint (https://mcp.firecrawl.dev/v2/mcp, the console's preset too), which
2
+ // answers its keyless tools with no key, under a free daily limit. The default backend of web_search (keyless Exa behind
3
+ // it, web-search.ts) and of web_fetch (the guarded direct fetch behind it, web-fetch.ts). Each call is one MCP exchange
4
+ // through the shared client (keyless-mcp.ts callTool), with no key, no Authorization and no header of our own:
5
+ // `firecrawl_search` with `{query, limit}`, whose text block is JSON, `{success, data: {web: [{url, title, description,
6
+ // position}]}}`; or `firecrawl_scrape` with `{url, formats: ["markdown"]}`, whose text block is JSON, `{markdown,
7
+ // metadata: {title, sourceURL, statusCode, ...}}`. Those are read into the same Search every web_search answers, or the
8
+ // same Read every web_fetch answers. web_fetch sends each URL it reads this way to Firecrawl, a third party; a URL the
9
+ // public-host guard refuses (a private, loopback, link-local or intranet address) never goes (web-fetch.ts).
10
+ //
11
+ // Firecrawl refuses a keyless call it will not serve with a tool result marked isError whose payload (its
12
+ // recoveryPayload: `{code, request_id, auth_mode: "keyless", message, signup_url?, retry_after_seconds?}`) comes as the
13
+ // result's structuredContent or as JSON in its text: both are read, and only `code` is, never the message's words.
14
+ // KEYLESS_QUOTA_EXHAUSTED (its daily limit), KEYLESS_ACCESS_NOT_AVAILABLE and KEYLESS_TOOL_NOT_AVAILABLE are a quota
15
+ // answer: the run's breaker turns Firecrawl off for the rest of the run. KEYLESS_LIMIT_REACHED and an HTTP 429 are a
16
+ // rate limit, with the wait it names (retry_after_seconds, Retry-After), which the breaker holds Firecrawl for. Firecrawl's
17
+ // own words (a link to sign up) are never passed on: a call answers ours. A call is not retried here (the backend behind
18
+ // Firecrawl answers it in its place), and ends at FIRECRAWL_MS (30 s), inside any deadline its caller holds, so a
19
+ // Firecrawl that hangs leaves the backend behind it the rest of a search's 60 s, or a fetch's direct read its own time.
20
+ import { callTool, MAX_BYTES, RATE_LIMITED, textBlocks } from "./keyless-mcp.js";
21
+ import { clip, markdownRead, TITLE_CAP } from "./web-fetch-direct.js";
22
+ import { snippetOf, waitOf } from "./web-search.js";
23
+ export const FIRECRAWL_MCP_URL = "https://mcp.firecrawl.dev/v2/mcp";
24
+ export const FIRECRAWL_SEARCH_TOOL = "firecrawl_search";
25
+ export const FIRECRAWL_SCRAPE_TOOL = "firecrawl_scrape";
26
+ /** Under `--faux` only: the URL of a fake MCP server (a test's, on loopback) asked in place of Firecrawl's endpoint.
27
+ * Under --faux with none named, Firecrawl is never asked. */
28
+ export const FAUX_FIRECRAWL_ENV = "AGENTRUN_SERVE_FAUX_FIRECRAWL";
29
+ /** The most one call to Firecrawl takes: half a search's one deadline (web-search.ts KEYLESS_SEARCH_MS). */
30
+ export const FIRECRAWL_MS = 30_000;
31
+ /** Firecrawl's keyless refusal codes, by what the run's breaker makes of each. */
32
+ const QUOTA_CODES = new Set(["KEYLESS_QUOTA_EXHAUSTED", "KEYLESS_ACCESS_NOT_AVAILABLE", "KEYLESS_TOOL_NOT_AVAILABLE"]);
33
+ const RATE_CODES = new Set(["KEYLESS_LIMIT_REACHED"]);
34
+ /** A refusal's payload: the result's structuredContent, else its text read as JSON; undefined when neither is an object. */
35
+ function payloadOf(result) {
36
+ const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
37
+ if (isObject(result?.structuredContent) && typeof result.structuredContent.code === "string")
38
+ return result.structuredContent;
39
+ try {
40
+ const parsed = JSON.parse(textBlocks(result));
41
+ return isObject(parsed) ? parsed : undefined;
42
+ }
43
+ catch {
44
+ return undefined;
45
+ }
46
+ }
47
+ /** The limit a refusal's `code` names (QUOTA_CODES, RATE_CODES), with the wait its payload names; undefined for any
48
+ * other code. */
49
+ export function firecrawlLimitOf(payload) {
50
+ const code = payload?.code;
51
+ if (typeof code !== "string")
52
+ return undefined;
53
+ if (QUOTA_CODES.has(code))
54
+ return { kind: "quota" };
55
+ if (!RATE_CODES.has(code))
56
+ return undefined;
57
+ const seconds = payload.retry_after_seconds;
58
+ if (typeof seconds === "number" && Number.isFinite(seconds) && seconds >= 0)
59
+ return { kind: "rate", retryAfter: seconds };
60
+ return { kind: "rate" };
61
+ }
62
+ /** What a call answers for a limit Firecrawl met. */
63
+ const limitWords = (limit, what) => (limit.kind === "rate" ? RATE_LIMITED : `Keyless Firecrawl will not serve this server's ${what}es now (its free limit is spent, or keyless use is not open to it): it is not asked again in this run`);
64
+ /** One call's outcome as Firecrawl's answer to `what`: its refusals and failures in our words, else `read` of the result's
65
+ * JSON text. */
66
+ function readCalled(called, what, read) {
67
+ if ("status" in called) {
68
+ if (called.status === 429) {
69
+ const limit = { kind: "rate", ...(called.retryAfterS === undefined ? {} : { retryAfter: called.retryAfterS }) };
70
+ return { error: limitWords(limit, what), limit };
71
+ }
72
+ return { error: `Firecrawl's MCP endpoint answered ${called.status} to ${called.step === "initialize" ? "initialize" : `the ${what}`}` };
73
+ }
74
+ if ("over" in called)
75
+ return { error: `Firecrawl's ${what} answered more than ${called.over / MAX_BYTES} MiB: not read` };
76
+ if ("error" in called)
77
+ return { error: called.rpc ? `Firecrawl's ${what} failed: its MCP endpoint answered an error` : "Firecrawl's MCP endpoint did not answer initialize" };
78
+ const { result } = called;
79
+ if (result?.isError === true) {
80
+ const payload = payloadOf(result);
81
+ const limit = firecrawlLimitOf(payload);
82
+ if (limit)
83
+ return { error: limitWords(limit, what), limit };
84
+ return { error: typeof payload?.code === "string" ? `Firecrawl's ${what} failed (${clip(payload.code, 60)})` : `Firecrawl's ${what} failed` };
85
+ }
86
+ try {
87
+ const parsed = JSON.parse(textBlocks(result));
88
+ if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed))
89
+ return read(parsed);
90
+ }
91
+ catch { }
92
+ return { error: `Firecrawl's ${what} answered no result this server reads` };
93
+ }
94
+ /** The tool `name` with `args` on Firecrawl's keyless endpoint, its answer bounded at `maxBytes`, read by `read`: once. */
95
+ async function firecrawlCall(name, args, what, maxBytes, read, { endpoint = FIRECRAWL_MCP_URL, send = fetch, signal, timeoutMs = FIRECRAWL_MS }) {
96
+ const own = AbortSignal.timeout(timeoutMs);
97
+ const deadline = AbortSignal.any([own, ...(signal ? [signal] : [])]);
98
+ try {
99
+ return readCalled(await callTool(endpoint, send, deadline, name, args, maxBytes), what, read);
100
+ }
101
+ catch (error) {
102
+ // Firecrawl's own bound, or the caller's: its deadline (a search's, spent) or its stop.
103
+ if (own.aborted)
104
+ return { error: `Firecrawl's ${what} did not answer within ${timeoutMs / 1000} s` };
105
+ const reason = signal?.aborted ? signal.reason?.name : error?.name;
106
+ return { error: reason === "TimeoutError" ? `Firecrawl's ${what} did not answer before the ${what}'s time ran out` : reason === "AbortError" ? `the ${what} was stopped` : `Firecrawl's ${what} failed: ${String(error?.message ?? error).slice(0, 300)}` };
107
+ }
108
+ }
109
+ /** `query` searched on Firecrawl's keyless endpoint, at most `n` results, its answer at most MAX_BYTES. */
110
+ export async function firecrawlSearch(query, n, options = {}) {
111
+ return firecrawlCall(FIRECRAWL_SEARCH_TOOL, { query, limit: n }, "search", MAX_BYTES, (json) => {
112
+ const data = json.data;
113
+ const rows = Array.isArray(data) ? data : Array.isArray(data?.web) ? data.web : undefined;
114
+ if (!rows)
115
+ return { error: "Firecrawl's search answered no results this server reads" };
116
+ const hits = rows.flatMap((row) => (typeof row?.url === "string" && URL.canParse(row.url) ? [{ url: row.url, title: typeof row.title === "string" ? clip(row.title, TITLE_CAP) : "", snippet: snippetOf(typeof row.description === "string" ? row.description : "") }] : []));
117
+ return { provider: "firecrawl-keyless", query, results: hits.slice(0, n) };
118
+ }, options);
119
+ }
120
+ /** The page at `url` scraped by Firecrawl's keyless endpoint, as markdown, its answer at most the direct fetch's bound
121
+ * (pi-browser's PUBLIC_MAX_BYTES). Firecrawl names no cut, so the text is read as the whole page's. A page whose status
122
+ * is not 2xx is no read: the caller fetches directly, as for a refusal. */
123
+ export async function firecrawlScrape(url, options = {}) {
124
+ const { PUBLIC_MAX_BYTES } = await import("@parcha/pi-browser");
125
+ return firecrawlCall(FIRECRAWL_SCRAPE_TOOL, { url, formats: ["markdown"] }, "fetch", PUBLIC_MAX_BYTES, (json) => {
126
+ if (typeof json.markdown !== "string" || json.markdown.trim() === "")
127
+ return { error: "Firecrawl's fetch answered no page text" };
128
+ const meta = (typeof json.metadata === "object" && json.metadata !== null ? json.metadata : {});
129
+ const final = [meta.url, meta.sourceURL].find((one) => typeof one === "string" && URL.canParse(one)) ?? url;
130
+ const status = typeof meta.statusCode === "number" && Number.isInteger(meta.statusCode) ? meta.statusCode : 200;
131
+ if (status < 200 || status > 299)
132
+ return { error: `Firecrawl's fetch: the page answered ${status}` };
133
+ return markdownRead(final, typeof meta.title === "string" ? meta.title : "", json.markdown, true, status);
134
+ }, options);
135
+ }
136
+ export function firecrawlFetch(options = {}, now = Date.now) {
137
+ let off = false;
138
+ let until = 0;
139
+ return {
140
+ live: () => !off && now() >= until,
141
+ async read(url, signal) {
142
+ const read = await firecrawlScrape(url, { ...options, ...(signal ? { signal } : {}) });
143
+ if ("ok" in read)
144
+ return read;
145
+ if (read.limit?.kind === "quota")
146
+ off = true;
147
+ else if (read.limit)
148
+ until = Math.max(until, now() + waitOf(read.limit.retryAfter, now()));
149
+ return read.error;
150
+ },
151
+ };
152
+ }
@@ -1,4 +1,6 @@
1
1
  import type { InputIssue } from "./errors.js";
2
+ /** A handed key's characters: visible ASCII alone, no space. The API's schema states the same (openapi.ts). */
3
+ export declare const HANDED_SECRET: RegExp;
2
4
  /** Why `value` (text) is not a key a run can be handed at `field`, as a 422 issue that never shows it, or undefined for
3
- * one it can: MIN_SECRET to `max` characters with no space or control character. */
5
+ * one it can: MIN_SECRET to `max` characters of visible ASCII. */
4
6
  export declare function handedSecretOf(value: string, field: string, max: number): InputIssue | undefined;
@@ -1,10 +1,12 @@
1
1
  import { MIN_SECRET } from "./learn/secrets.js";
2
+ /** A handed key's characters: visible ASCII alone, no space. The API's schema states the same (openapi.ts). */
3
+ export const HANDED_SECRET = /^[\x21-\x7e]+$/;
2
4
  /** Why `value` (text) is not a key a run can be handed at `field`, as a 422 issue that never shows it, or undefined for
3
- * one it can: MIN_SECRET to `max` characters with no space or control character. */
5
+ * one it can: MIN_SECRET to `max` characters of visible ASCII. */
4
6
  export function handedSecretOf(value, field, max) {
5
7
  const wrong = value.length < MIN_SECRET ? `at least ${MIN_SECRET} characters: a shorter key can't be cut from what the run writes`
6
8
  : value.length > max ? `at most ${max} characters`
7
- : /[\s\x00-\x1f\x7f]/.test(value) ? "text with no space or control character"
9
+ : !HANDED_SECRET.test(value) ? "visible ASCII alone, with no space or control character: a key goes in a header"
8
10
  : undefined;
9
11
  return wrong === undefined ? undefined : { field, reason: "invalid", message: `${field} is ${wrong}.` };
10
12
  }
@@ -0,0 +1,98 @@
1
+ import type { PlanRecipe } from "./harness-table.js";
2
+ import { type SecretMeta } from "./secret-writes.js";
3
+ import { type SealedKeys } from "./store/index.js";
4
+ /** The console's page for these keys (Settings → Harness keys). */
5
+ export declare const HARNESS_KEYS_PAGE = "/#/settings/harness-keys";
6
+ /** The plane of a harness key's name (its row's, and its view's: harness:<harness>:<KEY>). */
7
+ export declare const HARNESS_KEY_PLANE = "harness";
8
+ /** How many replaced or removed values of one key stay sealed for the cut: the oldest beyond it leaves. */
9
+ export declare const RETIRED_KEPT = 8;
10
+ /** The row (and view) name of `key` saved for `harness`. */
11
+ export declare const harnessKeyRow: (harness: string, key: string) => string;
12
+ type HarnessKeysStore = {
13
+ readonly sealedKeys: Pick<SealedKeys, "all" | "get" | "put" | "remove">;
14
+ flush(): Promise<void>;
15
+ };
16
+ /** The keys of `names` saved for `harness` that open under `sealKey`, by name. One that does not open (another seal key, or
17
+ * damaged) reads as not saved, never a clear fallback. For a runner's claim, whose run is on that harness. */
18
+ export declare function openHarnessKeys(store: {
19
+ sealedKeys: Pick<SealedKeys, "get">;
20
+ }, sealKey: Buffer, harness: string, names: readonly string[]): Promise<Record<string, string>>;
21
+ /** Whether every key of `names` has a row saved for `harness` (its bytes never opened): a trigger's check, and a runner's
22
+ * claim before it opens them. */
23
+ export declare function harnessKeysSaved(store: {
24
+ sealedKeys: Pick<SealedKeys, "all">;
25
+ }, harness: string, names: readonly string[]): Promise<boolean>;
26
+ /** Whether a claim laid every key of `names` on `env` (layHarnessKeys: own, never enumerable, not empty), which is when
27
+ * a start takes the keys route (harness-recipe-entry.ts serverRoute). A variable of the same name the environment
28
+ * carries enumerable (one the operator's shell set) is never one: a run takes the keys saved for its harness alone. */
29
+ export declare function keysLaid(env: NodeJS.ProcessEnv, names: readonly string[]): boolean;
30
+ export declare const harnessKeysSavedHere: (data: string, harness: string) => boolean;
31
+ /** The words a run no person started (a schedule's, a trigger's, a learned workflow's audit shadow or replay:
32
+ * run-launch.ts personStarted) on a plan-billed recipe is refused in at its claim (runner/harness-loops.ts,
33
+ * runner/cli-run-spec.ts): such a run takes keys saved for that harness, never its owner's own sign-in, and not every
34
+ * one is saved, or not every one opened. */
35
+ export declare const RECIPE_SIGN_IN_PERSON_ONLY = "A run its owner did not start (a scheduled or triggered run, a learned workflow's audit or replay) on a harness recipe billed to its vendor's plan runs on keys saved for that harness, never on its owner's own sign-in, and not every one of its keys is saved: save them in Settings \u2192 Harness keys (/#/settings/harness-keys), start this run yourself, or run the agent on a harness billed through this server's model proxy.";
36
+ /** The words a trigger's message is refused in by a session its claim started with not every key of its plan-billed
37
+ * recipe laid (runner/adapter-loop.ts, the spec's personOnly): that session runs on its owner's own sign-in, or on
38
+ * nothing, whatever was saved since, so a turn no person sent never goes into it. */
39
+ export declare const RECIPE_TURN_PERSON_ONLY = "This run started on its owner's own sign-in (its harness recipe is billed to its vendor's plan, and its claim opened not every key saved for that harness), so a trigger's message never runs in it, keys saved since or not: message the run yourself, or target a run started once every key was saved in Settings \u2192 Harness keys (/#/settings/harness-keys).";
40
+ /** Lays `keys` on `env` where only a direct read finds them: never enumerable, so no spread, copy or child environment
41
+ * built from `env` carries them (claim-secrets.ts withModelKeys). */
42
+ export declare function layHarnessKeys(env: NodeJS.ProcessEnv, keys: Readonly<Record<string, string>>): void;
43
+ /** What one plan-billed recipe's keys look like in Settings → Harness keys: each key's SecretMeta (never a value), and
44
+ * whether every one is saved, which is when its runs take the keys route. */
45
+ export type HarnessKeysView = {
46
+ readonly id: string;
47
+ readonly label: string;
48
+ readonly keys: SecretMeta[];
49
+ readonly ready: boolean;
50
+ };
51
+ /** The saved harness keys over the one store, for the server (the one writer of these rows): a snapshot loaded once at
52
+ * start (load()) and kept in step with every write, so a read answers without a round trip. */
53
+ export declare class HarnessKeysOverStore {
54
+ private readonly store;
55
+ private readonly sealKey;
56
+ readonly recipes: readonly PlanRecipe[];
57
+ private readonly data;
58
+ private current;
59
+ private retired;
60
+ /** The last write in flight (save, remove): each waits for the one before it, so two that overlap never read the same
61
+ * value as the one they replace, and every value a claim may have opened is retired. */
62
+ private writing;
63
+ /** `work` once every write before it has settled, its failure its own. */
64
+ private serial;
65
+ /** `recipes`: the plan-billed recipes this server is started with (harness-table.ts planRecipesOf), the only harnesses
66
+ * whose keys it saves or shows. `data`: its data directory, which its registry (harnessKeysSavedHere) is kept under. */
67
+ constructor(store: HarnessKeysStore, sealKey: Buffer, recipes: readonly PlanRecipe[], data: string);
68
+ /** This server's registry (harnessKeysSavedHere) set from the snapshot: each recipe whose every key is saved. */
69
+ private mark;
70
+ /** Reads every harness key row once: each current one opened, each retired one opened for the cut. A row that does not
71
+ * open reads as not saved. */
72
+ load(): Promise<void>;
73
+ /** Whether every key `recipe` runs on is saved for it. */
74
+ saved(recipe: Pick<PlanRecipe, "id" | "keys">): boolean;
75
+ /** Every value to cut: each saved key's, and each retired one's still kept. */
76
+ values(): string[];
77
+ /** GET: `recipe`'s keys, each by name, whether saved and when it changed: never a value. */
78
+ view(recipe: PlanRecipe): HarnessKeysView;
79
+ /** GET /settings/harness-keys: every plan-billed recipe this server is started with, its keys by name. */
80
+ list(): {
81
+ harnesses: HarnessKeysView[];
82
+ };
83
+ /** The plan-billed recipe `id` names on this server, else 404. */
84
+ recipe(id: string): PlanRecipe;
85
+ /** PUT: `value` sealed as `key` for `recipe`'s harness alone; a value it replaces kept as a retired row. Durable before it
86
+ * resolves, so a 204 never outruns the store. */
87
+ save(recipe: PlanRecipe, key: string, body: unknown): Promise<void>;
88
+ /** DELETE: `key`'s value for `recipe`'s harness gone from its runs, kept as a retired row for the cut. A row the snapshot
89
+ * does not hold (one that does not open under this server's seal key) is removed too, so no claim counts it saved. */
90
+ remove(recipe: PlanRecipe, key: string): Promise<void>;
91
+ /** `value`, which `key` held, sealed as a retired row of its own; the oldest beyond RETIRED_KEPT leaves. */
92
+ private retire;
93
+ }
94
+ /** 404 for a harness that is not a plan-billed recipe on this server's table: its keys are saved nowhere. */
95
+ export declare function planRecipeOr404(recipes: readonly PlanRecipe[], id: string): PlanRecipe;
96
+ /** The bytes a value would be sealed as, for a test that checks a key is sealed at rest. */
97
+ export declare const sealedHarnessKeyBytes: (key: Buffer, harness: string, name: string, value: string) => Uint8Array;
98
+ export {};