@parcha/agentrun-serve 0.1.0-beta.58 → 0.1.0-beta.59

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 (375) hide show
  1. package/CHANGELOG.md +325 -1
  2. package/README.md +332 -88
  3. package/dist/acp-package.d.ts +5 -1
  4. package/dist/acp-package.js +19 -2
  5. package/dist/adapters.d.ts +23 -2
  6. package/dist/adapters.js +106 -33
  7. package/dist/agents-store.js +1 -1
  8. package/dist/answer-text.d.ts +3 -0
  9. package/dist/answer-text.js +22 -0
  10. package/dist/attach-conformance.js +5 -4
  11. package/dist/box-paths.d.ts +3 -2
  12. package/dist/box-paths.js +5 -4
  13. package/dist/browser-computer.d.ts +3 -8
  14. package/dist/browser-computer.js +12 -35
  15. package/dist/browser-cost.js +94 -20
  16. package/dist/capacity.d.ts +1 -1
  17. package/dist/capacity.js +3 -3
  18. package/dist/chatgpt-plan.d.ts +5 -0
  19. package/dist/chatgpt-plan.js +25 -11
  20. package/dist/claude-login-token.d.ts +15 -11
  21. package/dist/claude-login-token.js +167 -107
  22. package/dist/claude-login.d.ts +76 -31
  23. package/dist/claude-login.js +426 -79
  24. package/dist/claude-sign-in.d.ts +3 -0
  25. package/dist/claude-sign-in.js +10 -1
  26. package/dist/cli.js +323 -292
  27. package/dist/composio-made.d.ts +1 -6
  28. package/dist/composio-made.js +1 -6
  29. package/dist/composio-owners.d.ts +26 -0
  30. package/dist/composio-owners.js +36 -0
  31. package/dist/composio-preset.d.ts +56 -23
  32. package/dist/composio-preset.js +173 -77
  33. package/dist/composio-triggers.d.ts +4 -4
  34. package/dist/composio-triggers.js +6 -7
  35. package/dist/compute-cost.js +11 -2
  36. package/dist/computer-attach.d.ts +6 -3
  37. package/dist/computer-attach.js +41 -29
  38. package/dist/computer-held-routes.d.ts +1 -1
  39. package/dist/computer-held-routes.js +9 -4
  40. package/dist/computer-keys.d.ts +11 -1
  41. package/dist/computer-keys.js +26 -1
  42. package/dist/computer-record.js +3 -1
  43. package/dist/computer-view.d.ts +5 -3
  44. package/dist/computer-view.js +10 -6
  45. package/dist/computer-viewer.js +36 -7
  46. package/dist/computers.d.ts +2 -1
  47. package/dist/computers.js +6 -3
  48. package/dist/console/THIRD-PARTY-NOTICES.txt +50 -0
  49. package/dist/console/assets/backend-BztxEAvb.js +166 -0
  50. package/dist/console/assets/index-LwNL4L9q.js +619 -0
  51. package/dist/console/assets/share-L84tlUDW.js +6 -0
  52. package/dist/console/assets/styles-CaRKlHke.js +291 -0
  53. package/dist/console/assets/styles-DQo8rzY-.css +1 -0
  54. package/dist/console/index.html +4 -3
  55. package/dist/console/share.html +17 -0
  56. package/dist/decisions.d.ts +17 -7
  57. package/dist/decisions.js +41 -15
  58. package/dist/dial-relay.js +10 -4
  59. package/dist/docker-daemon.js +4 -5
  60. package/dist/docker-host-addresses.js +29 -11
  61. package/dist/email/account.d.ts +6 -0
  62. package/dist/email/account.js +6 -0
  63. package/dist/email/authentication.d.ts +21 -0
  64. package/dist/email/authentication.js +106 -0
  65. package/dist/email/email-faux.d.ts +11 -2
  66. package/dist/email/email-faux.js +21 -5
  67. package/dist/email/mail.d.ts +25 -0
  68. package/dist/email/mail.js +58 -2
  69. package/dist/email/names.js +2 -2
  70. package/dist/email/tools.d.ts +9 -4
  71. package/dist/email/tools.js +95 -13
  72. package/dist/env-switch.d.ts +12 -2
  73. package/dist/env-switch.js +23 -3
  74. package/dist/errors.d.ts +1 -0
  75. package/dist/errors.js +2 -0
  76. package/dist/fal-price.d.ts +11 -1
  77. package/dist/fal-price.js +33 -0
  78. package/dist/faux-computers.js +1 -1
  79. package/dist/filed-answer.d.ts +2 -2
  80. package/dist/filed-answer.js +2 -2
  81. package/dist/graph-served.d.ts +10 -5
  82. package/dist/graph-served.js +40 -10
  83. package/dist/handed-values.js +1 -2
  84. package/dist/harness-check.d.ts +2 -1
  85. package/dist/harness-check.js +45 -12
  86. package/dist/harness-keys.js +9 -6
  87. package/dist/harness-opencode/facts.js +2 -0
  88. package/dist/harness-recipe-entry.d.ts +9 -3
  89. package/dist/harness-recipe-entry.js +18 -9
  90. package/dist/harness-recipe.d.ts +21 -0
  91. package/dist/harness-recipe.js +25 -3
  92. package/dist/harness-table.d.ts +8 -0
  93. package/dist/harness-table.js +17 -6
  94. package/dist/helper-env.d.ts +4 -1
  95. package/dist/helper-env.js +4 -1
  96. package/dist/host-check.d.ts +2 -3
  97. package/dist/host-check.js +13 -7
  98. package/dist/hosted-search.js +1 -1
  99. package/dist/import.d.ts +11 -8
  100. package/dist/import.js +437 -186
  101. package/dist/key-refusal.d.ts +9 -2
  102. package/dist/key-refusal.js +86 -32
  103. package/dist/learn/audit.d.ts +8 -5
  104. package/dist/learn/audit.js +15 -7
  105. package/dist/learn/compile.d.ts +5 -2
  106. package/dist/learn/compile.js +45 -21
  107. package/dist/learn/field-check.d.ts +111 -0
  108. package/dist/learn/field-check.js +174 -0
  109. package/dist/learn/ledger.d.ts +32 -29
  110. package/dist/learn/ledger.js +26 -19
  111. package/dist/learn/promote.d.ts +79 -36
  112. package/dist/learn/promote.js +60 -65
  113. package/dist/learn/secrets.d.ts +4 -0
  114. package/dist/learn/secrets.js +12 -0
  115. package/dist/learned-nodes.d.ts +8 -5
  116. package/dist/learned-nodes.js +8 -5
  117. package/dist/learned-workflow.d.ts +2 -1
  118. package/dist/learned-workflow.js +13 -10
  119. package/dist/learning-cost.d.ts +25 -8
  120. package/dist/learning-cost.js +23 -8
  121. package/dist/learning-setting.d.ts +6 -0
  122. package/dist/learning-setting.js +11 -1
  123. package/dist/listen-first.d.ts +5 -4
  124. package/dist/listen-first.js +4 -5
  125. package/dist/live-reach.d.ts +7 -0
  126. package/dist/live-reach.js +7 -0
  127. package/dist/mcp-api-only-origins.d.ts +15 -0
  128. package/dist/mcp-api-only-origins.js +40 -0
  129. package/dist/mcp-gateway.d.ts +16 -2
  130. package/dist/mcp-gateway.js +41 -3
  131. package/dist/mcp-oauth.d.ts +1 -1
  132. package/dist/mcp-oauth.js +3 -2
  133. package/dist/mcp-probe.d.ts +3 -0
  134. package/dist/mcp-probe.js +3 -0
  135. package/dist/mcp-secret-writes.d.ts +24 -2
  136. package/dist/mcp-secret-writes.js +30 -2
  137. package/dist/mcp-servers-store.d.ts +52 -14
  138. package/dist/mcp-servers-store.js +165 -61
  139. package/dist/mcp-sources.d.ts +1 -2
  140. package/dist/mcp-sources.js +1 -2
  141. package/dist/mcp-store.d.ts +5 -5
  142. package/dist/mcp-store.js +3 -3
  143. package/dist/mcp.js +1 -1
  144. package/dist/model-gateway.d.ts +1 -1
  145. package/dist/model-gateway.js +20 -36
  146. package/dist/ollama-provider.d.ts +23 -9
  147. package/dist/ollama-provider.js +49 -20
  148. package/dist/openapi.js +202 -51
  149. package/dist/otel/genai.d.ts +83 -7
  150. package/dist/otel/genai.js +69 -9
  151. package/dist/otel/tracer.d.ts +42 -13
  152. package/dist/otel/tracer.js +241 -56
  153. package/dist/page.d.ts +7 -1
  154. package/dist/page.js +76 -22
  155. package/dist/paid-calls.d.ts +6 -4
  156. package/dist/paid-calls.js +15 -7
  157. package/dist/place-offers.d.ts +55 -34
  158. package/dist/place-offers.js +93 -54
  159. package/dist/place.d.ts +13 -14
  160. package/dist/place.js +56 -41
  161. package/dist/print.js +1 -1
  162. package/dist/provider.d.ts +3 -2
  163. package/dist/provider.js +17 -8
  164. package/dist/redact/match.d.ts +27 -9
  165. package/dist/redact/match.js +266 -57
  166. package/dist/run-census.d.ts +1 -1
  167. package/dist/run-census.js +4 -5
  168. package/dist/run-cut.js +4 -5
  169. package/dist/run-export-store.d.ts +15 -0
  170. package/dist/run-export-store.js +30 -0
  171. package/dist/run-export.d.ts +139 -0
  172. package/dist/run-export.js +379 -0
  173. package/dist/run-file-cut.d.ts +5 -0
  174. package/dist/run-file-cut.js +13 -0
  175. package/dist/run-launch.js +16 -3
  176. package/dist/run-model-key.d.ts +15 -6
  177. package/dist/run-model-key.js +30 -31
  178. package/dist/run-reads-over-store.js +4 -4
  179. package/dist/run-secrets.js +3 -5
  180. package/dist/run-timeline-served.js +3 -1
  181. package/dist/runnable.js +2 -2
  182. package/dist/runner/adapter-loop.d.ts +35 -18
  183. package/dist/runner/adapter-loop.js +94 -47
  184. package/dist/runner/adapter-run-spec.d.ts +14 -1
  185. package/dist/runner/adapter-run-spec.js +64 -28
  186. package/dist/runner/adapters/pi.js +4 -2
  187. package/dist/runner/audit.d.ts +8 -5
  188. package/dist/runner/audit.js +37 -17
  189. package/dist/runner/beside.js +5 -6
  190. package/dist/runner/claim-secrets.d.ts +10 -3
  191. package/dist/runner/claim-secrets.js +29 -13
  192. package/dist/runner/cli-run-spec.d.ts +18 -0
  193. package/dist/runner/cli-run-spec.js +81 -46
  194. package/dist/runner/compare-end.d.ts +2 -1
  195. package/dist/runner/compare-end.js +25 -10
  196. package/dist/runner/conformance/harness.js +2 -3
  197. package/dist/runner/conformance/subject.d.ts +4 -1
  198. package/dist/runner/harness-loops.js +3 -3
  199. package/dist/runner/held.d.ts +5 -2
  200. package/dist/runner/journal-kinds.d.ts +4 -1
  201. package/dist/runner/journal-kinds.js +22 -4
  202. package/dist/runner/learned-first.js +20 -4
  203. package/dist/runner/learning-end.d.ts +2 -8
  204. package/dist/runner/learning-end.js +11 -19
  205. package/dist/runner/live-ticker.js +7 -5
  206. package/dist/runner/loop-contract.d.ts +0 -2
  207. package/dist/runner/loop.d.ts +7 -0
  208. package/dist/runner/loop.js +1 -0
  209. package/dist/runner/main.js +12 -11
  210. package/dist/runner/mcp-claim.js +21 -5
  211. package/dist/runner/meta-tools.js +3 -2
  212. package/dist/runner/metrics.d.ts +7 -0
  213. package/dist/runner/metrics.js +19 -0
  214. package/dist/runner/model-route.d.ts +10 -7
  215. package/dist/runner/model-route.js +79 -15
  216. package/dist/runner/native-loop.js +10 -8
  217. package/dist/runner/presence.d.ts +1 -4
  218. package/dist/runner/presence.js +6 -8
  219. package/dist/runner/promotion.d.ts +25 -13
  220. package/dist/runner/promotion.js +125 -50
  221. package/dist/runner/redact.d.ts +3 -1
  222. package/dist/runner/redact.js +5 -3
  223. package/dist/runner/responses-fetch.d.ts +36 -0
  224. package/dist/runner/responses-fetch.js +511 -0
  225. package/dist/runner/run-child-host.d.ts +20 -5
  226. package/dist/runner/run-child-host.js +179 -77
  227. package/dist/runner/run-child.js +11 -4
  228. package/dist/runner/runner-check.js +5 -1
  229. package/dist/runner/runner.d.ts +2 -3
  230. package/dist/runner/runner.js +13 -9
  231. package/dist/runner/sdk-loop.js +8 -8
  232. package/dist/runner/spec-holds.d.ts +8 -1
  233. package/dist/runner/spec-holds.js +9 -4
  234. package/dist/runner/workflow-calls.d.ts +9 -0
  235. package/dist/runner/workflow-calls.js +150 -0
  236. package/dist/runner/workflow-first.d.ts +120 -32
  237. package/dist/runner/workflow-first.js +218 -94
  238. package/dist/runner/workflow-spec.js +1 -1
  239. package/dist/runs-over-store.js +8 -7
  240. package/dist/save-once.d.ts +14 -0
  241. package/dist/save-once.js +31 -0
  242. package/dist/scrub-command.d.ts +34 -31
  243. package/dist/scrub-command.js +116 -147
  244. package/dist/sdk/runs.d.ts +6 -0
  245. package/dist/sdk/runs.js +89 -10
  246. package/dist/seal-key.js +4 -4
  247. package/dist/secret-cut.d.ts +3 -0
  248. package/dist/secret-cut.js +7 -1
  249. package/dist/secret-rules.d.ts +8 -1
  250. package/dist/secret-rules.js +482 -53
  251. package/dist/secrets.d.ts +51 -9
  252. package/dist/secrets.js +311 -21
  253. package/dist/server-keys.d.ts +4 -3
  254. package/dist/server-keys.js +4 -3
  255. package/dist/server-secrets-store.js +2 -4
  256. package/dist/server.d.ts +15 -3
  257. package/dist/server.js +312 -80
  258. package/dist/share-context.d.ts +22 -0
  259. package/dist/share-context.js +76 -0
  260. package/dist/shell-lex.d.ts +105 -0
  261. package/dist/shell-lex.js +646 -0
  262. package/dist/sign-ins-store.d.ts +5 -7
  263. package/dist/sign-ins-store.js +12 -16
  264. package/dist/sign-ins.d.ts +7 -11
  265. package/dist/sign-ins.js +40 -41
  266. package/dist/skills/agentrun-serve/SKILL.md +5 -2
  267. package/dist/start-switches.d.ts +6 -5
  268. package/dist/start-switches.js +8 -4
  269. package/dist/stats.d.ts +5 -1
  270. package/dist/stats.js +1 -1
  271. package/dist/store/agent-body.js +2 -2
  272. package/dist/store/dialect.d.ts +4 -0
  273. package/dist/store/dialect.js +1 -0
  274. package/dist/store/index.d.ts +2 -2
  275. package/dist/store/index.js +1 -1
  276. package/dist/store/mcp-record-keys.d.ts +10 -0
  277. package/dist/store/mcp-record-keys.js +13 -0
  278. package/dist/store/postgres/dialect.js +2 -0
  279. package/dist/store/postgres/migrations/0029_run_launch_census_settle.sql +28 -0
  280. package/dist/store/postgres/migrations/0030_learning_ledger_epoch.sql +40 -0
  281. package/dist/store/postgres/migrations/0031_learning_ledger_calls.sql +12 -0
  282. package/dist/store/postgres/store.js +4 -0
  283. package/dist/store/schema.d.ts +33 -10
  284. package/dist/store/schema.js +70 -16
  285. package/dist/store/seal.d.ts +4 -1
  286. package/dist/store/sqlite/run-launch.d.ts +3 -10
  287. package/dist/store/sqlite/run-launch.js +12 -23
  288. package/dist/store/sqlite/run-patch.d.ts +17 -10
  289. package/dist/store/sqlite/run-patch.js +50 -13
  290. package/dist/store/sqlite/store.d.ts +3 -0
  291. package/dist/store/sqlite/store.js +116 -34
  292. package/dist/store/store-schema.js +3 -4
  293. package/dist/store/store.d.ts +67 -32
  294. package/dist/store/store.js +14 -11
  295. package/dist/store-reads/analytics.d.ts +2 -1
  296. package/dist/store-reads/analytics.js +7 -5
  297. package/dist/store-reads/learning.d.ts +35 -26
  298. package/dist/store-reads/learning.js +120 -92
  299. package/dist/store-reads/stats.d.ts +2 -2
  300. package/dist/store-reads/stats.js +13 -7
  301. package/dist/store-view.js +10 -7
  302. package/dist/suggestions.d.ts +1 -1
  303. package/dist/suggestions.js +29 -13
  304. package/dist/template-eval.d.ts +72 -9
  305. package/dist/template-eval.js +358 -64
  306. package/dist/timeline/labels.d.ts +1 -1
  307. package/dist/timeline/labels.js +4 -3
  308. package/dist/timeline/timeline.d.ts +23 -11
  309. package/dist/timeline/timeline.js +115 -31
  310. package/dist/timeline/web-calls.d.ts +8 -6
  311. package/dist/timeline/web-calls.js +10 -6
  312. package/dist/tool-gate.d.ts +13 -1
  313. package/dist/tool-gate.js +43 -3
  314. package/dist/tool-keys-store.js +2 -4
  315. package/dist/tool-keys.d.ts +11 -0
  316. package/dist/tool-keys.js +16 -0
  317. package/dist/tool-plane.d.ts +50 -11
  318. package/dist/tool-plane.js +94 -30
  319. package/dist/tools.d.ts +5 -1
  320. package/dist/tools.js +7 -7
  321. package/dist/trigger-email.js +12 -6
  322. package/dist/triggers.d.ts +15 -34
  323. package/dist/triggers.js +119 -126
  324. package/dist/validate.d.ts +8 -1
  325. package/dist/validate.js +163 -23
  326. package/dist/web-fake.d.ts +2 -1
  327. package/dist/web-fake.js +8 -6
  328. package/dist/web-fetch.d.ts +8 -6
  329. package/dist/web-fetch.js +13 -11
  330. package/dist/web-holds.d.ts +32 -0
  331. package/dist/web-holds.js +86 -0
  332. package/dist/web-run.d.ts +32 -5
  333. package/dist/web-run.js +75 -28
  334. package/dist/web-save.js +23 -12
  335. package/dist/web-search.js +14 -25
  336. package/dist/wires.d.ts +4 -3
  337. package/dist/wires.js +5 -4
  338. package/dist/workspace/archil-claim.d.ts +12 -5
  339. package/dist/workspace/archil-claim.js +45 -5
  340. package/dist/workspace/attach.js +52 -19
  341. package/dist/workspace/attached-computers.d.ts +6 -2
  342. package/dist/workspace/attached-computers.js +5 -4
  343. package/dist/workspace/computer-deps.d.ts +23 -6
  344. package/dist/workspace/computer-deps.js +35 -17
  345. package/dist/workspace/computer-for-claim.d.ts +21 -4
  346. package/dist/workspace/computer-for-claim.js +160 -54
  347. package/dist/workspace/computer-intervals.d.ts +2 -0
  348. package/dist/workspace/computer-intervals.js +1 -1
  349. package/dist/workspace/computer-janitor.d.ts +48 -14
  350. package/dist/workspace/computer-janitor.js +153 -44
  351. package/dist/workspace/computer-kept.d.ts +158 -32
  352. package/dist/workspace/computer-kept.js +288 -63
  353. package/dist/workspace/computer-providers.d.ts +8 -3
  354. package/dist/workspace/computer-providers.js +12 -5
  355. package/dist/workspace/index.d.ts +1 -1
  356. package/dist/workspace/index.js +1 -1
  357. package/dist/workspace/local.js +41 -1
  358. package/dist/workspace/mount-revoke-left.d.ts +31 -0
  359. package/dist/workspace/mount-revoke-left.js +72 -0
  360. package/dist/workspace/paired-route.js +4 -5
  361. package/dist/workspace/resolve-computer.d.ts +5 -2
  362. package/dist/workspace/resolve-computer.js +9 -3
  363. package/dist/workspace/run-end-computers.d.ts +11 -5
  364. package/dist/workspace/run-end-computers.js +153 -28
  365. package/dist/workspace/run-tools.d.ts +22 -3
  366. package/dist/workspace/run-tools.js +17 -5
  367. package/dist/workspace/run-workspace.d.ts +14 -1
  368. package/dist/workspace/run-workspace.js +34 -1
  369. package/dist/workspace/workspace.d.ts +6 -0
  370. package/package.json +12 -13
  371. package/skills/agentrun-serve/SKILL.md +5 -2
  372. package/templates/README.md +22 -6
  373. package/dist/console/assets/backend-CSAWUqtZ.js +0 -166
  374. package/dist/console/assets/index-Bwn1oTem.css +0 -1
  375. package/dist/console/assets/index-DPh29cyz.js +0 -747
@@ -2,7 +2,8 @@
2
2
  // it (PEEK only: every message stays as unread as it was), email_draft keeps a message in its Drafts folder, email_send
3
3
  // sends one, marked as this server's (X-AgentRun-Sent, its value the run's id) so the email trigger never starts a run on
4
4
  // it, and files a copy in Sent unless the provider files its own (Gmail); email_file files a message under a Gmail label
5
- // or in a folder, and never deletes one (the trash and junk folders are refused). Host tools on every harness, bound beside
5
+ // or in a folder, and never deletes one (the trash and junk folders are refused) nor files one into Sent or Drafts. Host
6
+ // tools on every harness, bound beside
6
7
  // web_fetch (tool-list.ts `host`); the password is read in the runner, from the one store under its seal key, and never
7
8
  // in an answer. Each answer is held under the host's result bound (answer.ts).
8
9
  // Thread scope: a run an email trigger started reads only that email's thread (the message, and every message whose
@@ -24,7 +25,7 @@ const opens = (host) => host.store !== undefined && (host.sealKey !== undefined
24
25
  const accountOf = async (host) => (host.sealKey ? openAccount(host.store, host.sealKey) : held()?.emailAccount());
25
26
  import { EMAIL_ANSWER_MAX_CHARS, emailError, emailText } from "./answer.js";
26
27
  import { archiveDescription, EMAIL_ADDRESS, EMAIL_DESCRIPTIONS, EMAIL_DRAFT, EMAIL_FILE, EMAIL_READ, EMAIL_SEARCH, EMAIL_SEND, fileDescription, LIMIT_DEFAULT, LIMIT_MAX, OUTSIDE_THREAD, SEND_CAP } from "./names.js";
27
- import { composed, foundOf, inThread, involves, MailError, READ_BYTES, readOf, SEARCH_BYTES, SENT_HEADER, smtpSend, TOOL_SOCKET_TIMEOUT_MS, withImap } from "./mail.js";
28
+ import { addressKey, composed, foundOf, inThread, involves, MailError, neverSentTo, READ_BYTES, readOf, SEARCH_BYTES, SENT_HEADER, smtpSend, TOOL_SOCKET_TIMEOUT_MS, withImap } from "./mail.js";
28
29
  export { EMAIL_DRAFT, EMAIL_FILE, EMAIL_READ, EMAIL_SCOPES, EMAIL_SEARCH, EMAIL_SEND, OUTSIDE_THREAD, SCOPED_TOOLS, SEND_CAP, sendSummary } from "./names.js";
29
30
  /** The most ids a thread is read by: its message and the 49 nearest it. */
30
31
  const THREAD_IDS = 50;
@@ -72,11 +73,11 @@ const messageId = (value) => {
72
73
  * sender, its Message-ID and where the trigger found it. Null when any of them is missing or does not read, so the run
73
74
  * reads nothing (fail closed). */
74
75
  export function threadRootOf(attrs) {
75
- const { from, message_id, mailbox, uidvalidity, uid } = attrs ?? {};
76
+ const { from, message_id, mailbox, uidvalidity, uid, dmarc } = attrs ?? {};
76
77
  const named = (value) => typeof value === "string" && value.trim() !== "";
77
78
  if (!named(from) || !named(message_id) || !named(mailbox) || !named(uidvalidity) || !named(uid) || !/^[1-9]\d{0,15}$/.test(uid))
78
79
  return null;
79
- return { from: from.trim().toLowerCase(), message_id, mailbox, uidvalidity, uid: Number(uid) };
80
+ return { from: addressKey(from), message_id, mailbox, uidvalidity, uid: Number(uid), dmarc: dmarc === "pass" };
80
81
  }
81
82
  /** The scope of `tool`'s calls in the run `host` binds for: the agent's `scope: "mailbox"` reads the whole account; a run
82
83
  * an email trigger started reads its thread; any other run, the whole account. */
@@ -112,7 +113,7 @@ async function located(session, root) {
112
113
  return head ? { ids: new Set(threadIds(root.message_id, head)), sender: root.from } : nothing();
113
114
  }
114
115
  /** Whether `head` is `root`'s message: its Message-ID, from its sender. */
115
- const isRoot = (head, root) => head.message_id === root.message_id && head.from.trim().toLowerCase() === root.from;
116
+ const isRoot = (head, root) => head.message_id === root.message_id && addressKey(head.from) === root.from;
116
117
  /** `root`'s message where the trigger found it, when it is still there. */
117
118
  async function recorded(session, root) {
118
119
  if (root.mailbox.toUpperCase() !== "INBOX" && !(await session.mailboxes()).some((box) => box.path === root.mailbox))
@@ -182,13 +183,13 @@ class Mail {
182
183
  const inside = new Set(await session.uids(session.threadQuery([...thread])));
183
184
  return found.filter((uid) => inside.has(uid));
184
185
  }
185
- /** The thread's people, lowercased: the account's own address and every From, To and Cc of the thread's messages (those
186
+ /** The thread's people, as compared (addressKey): the account's own address and every From, To and Cc of the thread's messages (those
186
187
  * `allows` takes), across the account's mailboxes; undefined when the run reads the whole account. */
187
188
  async people(session) {
188
189
  const ids = await this.thread(session);
189
190
  if (!ids)
190
191
  return undefined;
191
- const people = new Set([this.account.address.trim().toLowerCase()]);
192
+ const people = new Set([addressKey(this.account.address)]);
192
193
  if (!ids.size)
193
194
  return people;
194
195
  for (const path of await session.searchable()) {
@@ -196,7 +197,7 @@ class Mail {
196
197
  for (const head of await session.heads(path, await session.uids(session.threadQuery([...ids])))) {
197
198
  if (inThread(head, ids) && (await this.allows(session, head)))
198
199
  for (const one of [head.from, ...head.to, ...head.cc])
199
- people.add(one.trim().toLowerCase());
200
+ people.add(addressKey(one));
200
201
  }
201
202
  }
202
203
  return people;
@@ -383,8 +384,11 @@ async function send(mail, args, runId) {
383
384
  const listed = (names) => (names.length < 2 ? names.join("") : `${names.slice(0, -1).join(", ")} and ${names.at(-1)}`);
384
385
  /** Why an email_send its setting allows asks a person anyway (tools.ts ToolEntry.asks), or nothing: the run has sent
385
386
  * SEND_CAP emails or more (its record's count, across pauses); or, on a run that reads only its email's thread (email_read's
386
- * scope), it sends to someone outside the thread's people (Mail.people), each named. Both, when both. A thread that can't
387
- * be read asks too, saying so. A call whose arguments don't read asks nothing: the tool refuses it in its own words. */
387
+ * scope), it sends to someone outside the thread's people (Mail.people), each named; or, on any run a trigger started
388
+ * (that thread run too), it sends to an address the account has never sent to (newWords), each named. Each that holds,
389
+ * joined. A thread
390
+ * or a Sent folder that can't be read asks too, saying so. A call whose arguments don't read asks nothing: the tool
391
+ * refuses it in its own words. */
388
392
  export async function sendAsks(args, ctx) {
389
393
  const why = [];
390
394
  const sent = await ctx.ran(EMAIL_SEND);
@@ -393,8 +397,59 @@ export async function sendAsks(args, ctx) {
393
397
  const outside = await outsideWords(ctx.host, args);
394
398
  if (outside)
395
399
  why.push(outside);
400
+ const fresh = await newWords(ctx, args);
401
+ if (fresh)
402
+ why.push(fresh);
396
403
  return why.length ? why.join("; ") : undefined;
397
404
  }
405
+ /** The recipients of a send's arguments (to and cc), as compared (addressKey), once each; none when they don't read. */
406
+ function recipientsOf(args) {
407
+ const list = (value) => (typeof value === "string" ? [value] : Array.isArray(value) ? value.filter((one) => typeof one === "string") : []);
408
+ return [...new Set([...list(args.to), ...list(args.cc)].map(addressKey))];
409
+ }
410
+ /** On a run a trigger started (host.startedBy: a schedule, a webhook, an email, any source), the recipients of the send
411
+ * `args` this account has never sent to, in words: none of its Sent mail, from the account and no draft, is to them
412
+ * (mail.ts neverSentTo, To, Cc or Bcc, the exact address). The account's own address is never new, nor one this run
413
+ * already sent to (its earlier sends, unasked or approved, from its record: a copy in Sent or not), nor, on a run that
414
+ * reads only its email's thread, the thread's starter (its root's From, as the trigger read it: ThreadRoot.from), whom
415
+ * an auto-responder answers, but only when the receiving server vouched for that From (ThreadRoot.dmarc: its own
416
+ * Authentication-Results said dmarc=pass for the From's domain); a From it didn't vouch for may be forged, and asks
417
+ * as anyone's. Everyone else that message names, its Cc's strangers among them, is checked as on any other run. A Sent
418
+ * folder that can't be read asks, saying so (fail closed). Nothing on a run no trigger started. */
419
+ async function newWords(ctx, args) {
420
+ const host = ctx.host;
421
+ if (!host.startedBy || !opens(host))
422
+ return undefined;
423
+ const scope = await scopeOf(host, EMAIL_READ);
424
+ const starter = scope.kind === "thread" && scope.root?.dmarc ? [scope.root.from] : [];
425
+ let recipients;
426
+ try {
427
+ const letter = letterOf(args);
428
+ recipients = [...new Set([...letter.to, ...letter.cc].map(addressKey))];
429
+ }
430
+ catch {
431
+ return undefined;
432
+ }
433
+ try {
434
+ const account = await accountOf(host);
435
+ // No account when the send is checked: the tool opens the account again when it runs, so one saved in between would
436
+ // let the send out unchecked. It asks, saying so (fail closed).
437
+ if (!account)
438
+ throw new MailError("missing", NO_ACCOUNT);
439
+ // One a template eval's run may not open: the send itself is refused in its own words.
440
+ if (!fakeHeld(host, account))
441
+ return undefined;
442
+ const known = new Set([addressKey(account.address), ...starter, ...(await ctx.made(EMAIL_SEND)).flatMap((one) => (isObject(one) ? recipientsOf(one) : []))]);
443
+ const unknown = recipients.filter((one) => !known.has(one));
444
+ if (!unknown.length)
445
+ return undefined;
446
+ const never = await withImap(account, (session) => neverSentTo(session, unknown, account.address), { socketTimeoutMs: TOOL_SOCKET_TIMEOUT_MS });
447
+ return never.length ? `${listed(never)}: this account has never sent to them` : undefined;
448
+ }
449
+ catch (error) {
450
+ return `its recipients couldn't be checked against this account's sent mail (${error?.message ?? String(error)})`;
451
+ }
452
+ }
398
453
  /** The recipients of the send `args` outside the run's thread, in words; nothing on a run that reads the whole account. */
399
454
  async function outsideWords(host, args) {
400
455
  const scope = await scopeOf(host, EMAIL_READ);
@@ -403,7 +458,7 @@ async function outsideWords(host, args) {
403
458
  let recipients;
404
459
  try {
405
460
  const letter = letterOf(args);
406
- recipients = [...new Set([...letter.to, ...letter.cc].map((one) => one.toLowerCase()))];
461
+ recipients = [...new Set([...letter.to, ...letter.cc].map(addressKey))];
407
462
  }
408
463
  catch {
409
464
  return undefined;
@@ -432,13 +487,20 @@ function fakeHeld(host, account) {
432
487
  }
433
488
  /** The names email_file refuses whatever the account flags: the trash and junk folders by their usual names. */
434
489
  const BINS = new Set(["trash", "junk", "spam", "[gmail]/trash", "[gmail]/spam", "\\trash", "\\junk"]);
490
+ /** The names email_file refuses as Sent or Drafts whatever the account flags: those ImapSession.resolve takes for them,
491
+ * Gmail's folders and its \Sent and \Draft labels. Sent holds what the account sent (the never-written-to check reads
492
+ * it), so only email_send and email_draft put mail there. */
493
+ const KEPT = new Set(["sent", "drafts", "\\sent", "\\drafts", "\\draft", "[gmail]/sent mail", "[gmail]/drafts"]);
435
494
  /** A folders server's answer to an explicit archive: false, a filing that would keep the message in the inbox. */
436
495
  const FOLDERS_REFUSAL = "this server has folders: filing moves the message out of the inbox; pass archive: true to move it";
437
496
  /** Gmail's label for a message in the inbox: taken off, the message is archived. */
438
497
  const INBOX_LABEL = "\\Inbox";
439
498
  /** The message `id` filed under `to`: a Gmail label (archive: true takes its \Inbox label off too), else a move to the
440
499
  * folder `to`, created if missing, with no archive or archive: true. Never a delete: the trash and junk folders are
441
- * refused before anything is touched; and an explicit archive: false never takes mail out of the inbox. */
500
+ * refused before anything is touched; and an explicit archive: false never takes mail out of the inbox. Never into Sent
501
+ * or Drafts either (KEPT, or the folder flagged \Sent or \Drafts; and once made, only into a mailbox the server lists
502
+ * by exactly that name: listedExactly): a message filed there would read as the account's own sent mail to the
503
+ * never-written-to check. */
442
504
  async function file(mail, args) {
443
505
  const id = messageId(text(args, "message_id", 998, true));
444
506
  const to = text(args, "to", 300, true).trim();
@@ -447,18 +509,25 @@ async function file(mail, args) {
447
509
  if (args.archive !== undefined && typeof args.archive !== "boolean")
448
510
  throw new BadArgs("archive is true or false.");
449
511
  const refused = () => new BadArgs(`${EMAIL_FILE} files mail, it never deletes it: ${to} is the trash or junk folder.`);
512
+ const kept = () => new BadArgs(`${EMAIL_FILE} never files into Sent or Drafts: ${to} is the account's sent or drafts mail, which only ${EMAIL_SEND} and ${EMAIL_DRAFT} write.`);
450
513
  if (BINS.has(to.toLowerCase()))
451
514
  throw refused();
515
+ if (KEPT.has(to.toLowerCase()))
516
+ throw kept();
452
517
  return withMail(mail, async (session) => {
453
- const bin = (await session.mailboxes()).find((box) => box.path === to && (box.specialUse === "\\Trash" || box.specialUse === "\\Junk"));
518
+ const boxes = await session.mailboxes();
519
+ const bin = boxes.find((box) => box.path === to && (box.specialUse === "\\Trash" || box.specialUse === "\\Junk"));
454
520
  if (bin)
455
521
  throw refused();
522
+ if (boxes.some((box) => box.path.toLowerCase() === to.toLowerCase() && (box.specialUse === "\\Sent" || box.specialUse === "\\Drafts")))
523
+ throw kept();
456
524
  const found = await findById(session, id, mail);
457
525
  if (!found)
458
526
  throw new MailError("missing", mail.scope.kind === "thread" ? `${id} is ${OUTSIDE_THREAD}, or not in this account: this run files only the thread of the email that started it.` : `No message ${id} in this account.`);
459
527
  const done = (archived, note) => ({ filed: true, message_id: id, to, archived, subject: found.subject, ...(note ? { note } : {}) });
460
528
  if (session.can("X-GM-EXT-1")) {
461
529
  await session.ensure(to);
530
+ await listedExactly(session, to, kept);
462
531
  await session.select(found.mailbox);
463
532
  await session.label(found.uid, [to]);
464
533
  const leaves = args.archive === true && found.mailbox.toUpperCase() === "INBOX";
@@ -471,12 +540,25 @@ async function file(mail, args) {
471
540
  if (args.archive === false)
472
541
  throw new BadArgs(FOLDERS_REFUSAL);
473
542
  await session.ensure(to);
543
+ await listedExactly(session, to, kept);
474
544
  await session.select(found.mailbox);
475
545
  await session.move(found.uid, to);
476
546
  // The answer says the move: the model reads the answer, not the timeline.
477
547
  return done(true, `moved out of the inbox to ${to}`);
478
548
  });
479
549
  }
550
+ /** Once `to` is made (ImapSession.ensure), that the server lists a mailbox of exactly that name (INBOX in any case), and
551
+ * that it is neither Sent nor Drafts, by its flag or as ImapSession.resolve reads them: a server may take a name as
552
+ * another's (CREATE may drop a trailing hierarchy delimiter, so `Sent/` is Sent; an alias), and the names alone
553
+ * can't say so. Otherwise nothing is filed: `kept()`'s refusal for Sent or Drafts, else one that says the name. */
554
+ async function listedExactly(session, to, kept) {
555
+ const box = (await session.mailboxes()).find((one) => one.path === to || (to.toUpperCase() === "INBOX" && one.path.toUpperCase() === "INBOX"));
556
+ if (!box)
557
+ throw new MailError("failed", `the mail server lists no mailbox named exactly ${JSON.stringify(to)} once it is made, so nothing was filed: give the folder's name as the server lists it.`);
558
+ const special = await Promise.all(["Sent", "Drafts"].map((name) => session.resolve(name).catch(() => undefined)));
559
+ if (box.specialUse === "\\Sent" || box.specialUse === "\\Drafts" || special.includes(box.path))
560
+ throw kept();
561
+ }
480
562
  const STRING = { type: "string" };
481
563
  const ADDRESSES = { type: "array", items: STRING, description: "Email addresses, such as [\"ana@example.com\"]." };
482
564
  /** The five tools, by name: their words for the model (names.ts EMAIL_DESCRIPTIONS, the catalog's too), their arguments,
@@ -2,21 +2,31 @@
2
2
  export declare const API_ONLY_ENV = "AGENTRUN_API_ONLY";
3
3
  /** The run-keys setting (run-keys.ts). */
4
4
  export declare const RUN_KEYS_ENV = "AGENTRUN_RUN_KEYS";
5
+ /** Jev off for the web tools (web-run.ts jevWebOf): web_search's results go unranked, whatever key the server holds. */
6
+ export declare const WEB_JEV_OFF_ENV = "AGENTRUN_WEB_JEV_OFF";
5
7
  /** What each setting means on, and off where off needs saying: the words a refused value answers. */
6
8
  declare const MEANS: {
7
9
  readonly AGENTRUN_API_ONLY: readonly ["serve the run API only", "the whole server"];
8
10
  readonly AGENTRUN_RUN_KEYS: readonly ["each run brings the tool keys this server does not hold"];
11
+ readonly AGENTRUN_WEB_JEV_OFF: readonly ["the web tools run without Jev", "Jev ranks web_search's results where the server holds a TypeSafe key"];
9
12
  };
10
13
  /** Whether `env` turns setting `name` on: `1` or `true` on; unset, empty, `0` or `false` off. Any other value is refused
11
14
  * in words that say what each means (a TypeError), so a typo never leaves the console open on a server meant to be
12
15
  * API-only. */
13
16
  export declare function switchFrom(name: keyof typeof MEANS, env?: NodeJS.ProcessEnv): boolean;
17
+ /** Whether Jev is off for the web tools under `env`: AGENTRUN_WEB_JEV_OFF on. The CLI refuses any other value at start;
18
+ * one met later (a runner's claim) reads as off, so a typo never turns Jev on. */
19
+ export declare function webJevOff(env: NodeJS.ProcessEnv): boolean;
14
20
  /** The MCP origins an API-only server's token may save a per_run MCP server at: the serve README's API-only section. */
15
21
  export declare const API_ONLY_MCP_ORIGINS_ENV = "AGENTRUN_API_ONLY_MCP_ORIGINS";
22
+ /** A URL hostname on this machine: localhost, ::1 (bracketed, as URL writes it) or 127.0.0.0/8. Defined here, since this
23
+ * module imports nothing; mcp-oauth.ts LOOPBACK is this one. */
24
+ export declare const LOOPBACK_HOST: RegExp;
16
25
  /** The origins `value` (API_ONLY_MCP_ORIGINS_ENV) names, each once, in its order: none when unset or blank. An entry
17
26
  * that is not an http or https origin alone (a path, query, fragment, user or password, or no URL at all) is refused
18
27
  * (a TypeError naming the entry by its place, never its text, which could hold a password), and so is a wildcard
19
- * (`https://*.example.com`), which would otherwise be taken as a literal host and match nothing. Empty entries are
20
- * skipped. */
28
+ * (`https://*.example.com`), which would otherwise be taken as a literal host and match nothing, and so is plain http
29
+ * to any host but a loopback one (LOOPBACK_HOST), whose traffic would cross the network in the clear. Empty entries
30
+ * are skipped. */
21
31
  export declare function apiOnlyMcpOriginsFrom(value: string | undefined): string[];
22
32
  export {};
@@ -1,13 +1,16 @@
1
- // The server's two on/off settings, and the API-only profile's MCP origins, which the CLI reads before the rest of the
1
+ // The server's on/off settings, and the API-only profile's MCP origins, which the CLI reads before the rest of the
2
2
  // server loads (cli.ts): this module imports nothing.
3
3
  /** The API-only profile (api-only.ts). */
4
4
  export const API_ONLY_ENV = "AGENTRUN_API_ONLY";
5
5
  /** The run-keys setting (run-keys.ts). */
6
6
  export const RUN_KEYS_ENV = "AGENTRUN_RUN_KEYS";
7
+ /** Jev off for the web tools (web-run.ts jevWebOf): web_search's results go unranked, whatever key the server holds. */
8
+ export const WEB_JEV_OFF_ENV = "AGENTRUN_WEB_JEV_OFF";
7
9
  /** What each setting means on, and off where off needs saying: the words a refused value answers. */
8
10
  const MEANS = {
9
11
  [API_ONLY_ENV]: ["serve the run API only", "the whole server"],
10
12
  [RUN_KEYS_ENV]: ["each run brings the tool keys this server does not hold"],
13
+ [WEB_JEV_OFF_ENV]: ["the web tools run without Jev", "Jev ranks web_search's results where the server holds a TypeSafe key"],
11
14
  };
12
15
  /** Whether `env` turns setting `name` on: `1` or `true` on; unset, empty, `0` or `false` off. Any other value is refused
13
16
  * in words that say what each means (a TypeError), so a typo never leaves the console open on a server meant to be
@@ -21,13 +24,27 @@ export function switchFrom(name, env = process.env) {
21
24
  const [on, off] = MEANS[name];
22
25
  throw new TypeError(`${name} is 1 (${on}) or 0${off === undefined ? "" : ` (${off})`}, not ${JSON.stringify(env[name])}`);
23
26
  }
27
+ /** Whether Jev is off for the web tools under `env`: AGENTRUN_WEB_JEV_OFF on. The CLI refuses any other value at start;
28
+ * one met later (a runner's claim) reads as off, so a typo never turns Jev on. */
29
+ export function webJevOff(env) {
30
+ try {
31
+ return switchFrom(WEB_JEV_OFF_ENV, env);
32
+ }
33
+ catch {
34
+ return true;
35
+ }
36
+ }
24
37
  /** The MCP origins an API-only server's token may save a per_run MCP server at: the serve README's API-only section. */
25
38
  export const API_ONLY_MCP_ORIGINS_ENV = "AGENTRUN_API_ONLY_MCP_ORIGINS";
39
+ /** A URL hostname on this machine: localhost, ::1 (bracketed, as URL writes it) or 127.0.0.0/8. Defined here, since this
40
+ * module imports nothing; mcp-oauth.ts LOOPBACK is this one. */
41
+ export const LOOPBACK_HOST = /^(?:localhost|\[::1\]|127(?:[.]\d{1,3}){3})$/; // key-gate: loopback-rule the one loopback rule, for the API-only MCP origins and MCP sign-in
26
42
  /** The origins `value` (API_ONLY_MCP_ORIGINS_ENV) names, each once, in its order: none when unset or blank. An entry
27
43
  * that is not an http or https origin alone (a path, query, fragment, user or password, or no URL at all) is refused
28
44
  * (a TypeError naming the entry by its place, never its text, which could hold a password), and so is a wildcard
29
- * (`https://*.example.com`), which would otherwise be taken as a literal host and match nothing. Empty entries are
30
- * skipped. */
45
+ * (`https://*.example.com`), which would otherwise be taken as a literal host and match nothing, and so is plain http
46
+ * to any host but a loopback one (LOOPBACK_HOST), whose traffic would cross the network in the clear. Empty entries
47
+ * are skipped. */
31
48
  export function apiOnlyMcpOriginsFrom(value) {
32
49
  const origins = [];
33
50
  (value ?? "").split(",").map((entry) => entry.trim()).forEach((entry, at) => {
@@ -45,6 +62,9 @@ export function apiOnlyMcpOriginsFrom(value) {
45
62
  if (!url || (url.protocol !== "http:" && url.protocol !== "https:") || url.href !== `${url.origin}/`) {
46
63
  throw new TypeError(`${API_ONLY_MCP_ORIGINS_ENV} is a comma-separated list of MCP origins (http or https, scheme://host[:port], no path): entry ${at + 1} is not one`);
47
64
  }
65
+ if (url.protocol === "http:" && !LOOPBACK_HOST.test(url.hostname)) {
66
+ throw new TypeError(`${API_ONLY_MCP_ORIGINS_ENV} takes plain http only for this machine (127.0.0.0/8, ::1, localhost): entry ${at + 1} is plain http to a host off this machine; list it as https`);
67
+ }
48
68
  if (!origins.includes(url.origin))
49
69
  origins.push(url.origin);
50
70
  });
package/dist/errors.d.ts CHANGED
@@ -64,6 +64,7 @@ export declare const ERROR_STATUS: {
64
64
  readonly run_not_final: 409;
65
65
  readonly run_learning: 409;
66
66
  readonly not_exportable: 409;
67
+ readonly export_too_large: 413;
67
68
  readonly purged: 410;
68
69
  readonly model_key_required: 422;
69
70
  readonly runner_refused: 503;
package/dist/errors.js CHANGED
@@ -96,6 +96,8 @@ export const ERROR_STATUS = {
96
96
  // GET /agents/{id}/package (agent-package.ts) of an agent whose source is elsewhere (a native, CLI learning, SDK or
97
97
  // another system's agent), a workflow, or one with no revision: there is no package of it to write.
98
98
  not_exportable: 409,
99
+ // GET /runs/{id}/export (run-export.ts) of a run whose bundle is over its 8 MiB cap: it is never cut short.
100
+ export_too_large: 413,
99
101
  // A run or an agent that was purged (DELETE /runs/{id}, /agents/{id}): every route of it reads its tombstone in the
100
102
  // error's details, and its DELETE answers 204 again.
101
103
  purged: 410,
@@ -1,5 +1,5 @@
1
1
  import type { PublicFetchOptions } from "@parcha/pi-browser";
2
- import type { McpKeys, McpMeter } from "./mcp-gateway.js";
2
+ import type { McpKeys, McpMeter, McpResults } from "./mcp-gateway.js";
3
3
  import { type SaveSlots } from "./web-save.js";
4
4
  /** The host of fal's hosted MCP server (its key endpoint /mcp and its sign-in endpoint /mcp-relay). */
5
5
  export declare const FAL_MCP_HOST = "mcp.fal.ai";
@@ -94,6 +94,16 @@ export declare const publicMedia: (guard: () => Promise<Omit<PublicFetchOptions,
94
94
  * (over KEY_ROOM) is refused unsent, in words. `back` reads each scoped key in a reply as the agent's by taking the
95
95
  * suffix off. */
96
96
  export declare function falKeys(run: string): McpKeys;
97
+ /** Where a fal job's result is filed in the run's files: evidence/fal/<request_id>.json. */
98
+ export declare const FAL_RESULTS_DIR = "evidence/fal";
99
+ /** fal's request ids: UUIDs. Only one names a file: anything else (a path, a dot name, a name past a filename's
100
+ * limit, a plain name fal never gives) is never filed. */
101
+ export declare const FAL_REQUEST_ID: RegExp;
102
+ /** The completed jobs of fal's answer to `tool`, each by its request_id with its `result` as fal answered it: the answer
103
+ * itself (run_model), and each entry of a list in it (submit_jobs', wait_for_jobs' `jobs`). A job is completed when
104
+ * fal says so (`status` "completed") and it carries a `result`. One whose request_id is not a UUID is left out, and a
105
+ * request_id twice in one answer is filed from its first entry. */
106
+ export declare const falResults: McpResults;
97
107
  /** A fal server's meter: fal's unit prices read through the gateway's `ask`, kept per endpoint for PRICE_TTL_MS.
98
108
  * `media` reads an input media file (none: such a job is unpriceable); `now`, the clock. */
99
109
  export declare function falMeter({ media, now }?: {
package/dist/fal-price.js CHANGED
@@ -510,6 +510,38 @@ export function falKeys(run) {
510
510
  back: (text) => (text.includes(mark) ? text.replace(suffix, "") : text),
511
511
  };
512
512
  }
513
+ /** Where a fal job's result is filed in the run's files: evidence/fal/<request_id>.json. */
514
+ export const FAL_RESULTS_DIR = "evidence/fal";
515
+ /** fal's request ids: UUIDs. Only one names a file: anything else (a path, a dot name, a name past a filename's
516
+ * limit, a plain name fal never gives) is never filed. */
517
+ export const FAL_REQUEST_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
518
+ /** fal's tools whose answers carry completed jobs: run_model's one, submit_jobs' and wait_for_jobs' each. */
519
+ const WITH_RESULTS = new Set(["run_model", "submit_jobs", "wait_for_jobs"]);
520
+ /** The completed jobs of fal's answer to `tool`, each by its request_id with its `result` as fal answered it: the answer
521
+ * itself (run_model), and each entry of a list in it (submit_jobs', wait_for_jobs' `jobs`). A job is completed when
522
+ * fal says so (`status` "completed") and it carries a `result`. One whose request_id is not a UUID is left out, and a
523
+ * request_id twice in one answer is filed from its first entry. */
524
+ export const falResults = {
525
+ dir: FAL_RESULTS_DIR,
526
+ of(tool, reply) {
527
+ if (!WITH_RESULTS.has(tool))
528
+ return [];
529
+ const body = bodyOf(reply);
530
+ if (!isObject(body))
531
+ return [];
532
+ const entries = [body, ...Object.values(body).flatMap((value) => (Array.isArray(value) ? value : []))];
533
+ const seen = new Set();
534
+ return entries.flatMap((entry) => {
535
+ if (!isObject(entry) || entry.status !== "completed" || !Object.hasOwn(entry, "result"))
536
+ return [];
537
+ const id = entry.request_id;
538
+ if (typeof id !== "string" || !FAL_REQUEST_ID.test(id) || seen.has(id))
539
+ return [];
540
+ seen.add(id);
541
+ return [{ name: id, value: entry.result }];
542
+ });
543
+ },
544
+ };
513
545
  /** A fal server's meter: fal's unit prices read through the gateway's `ask`, kept per endpoint for PRICE_TTL_MS.
514
546
  * `media` reads an input media file (none: such a job is unpriceable); `now`, the clock. */
515
547
  export function falMeter({ media, now = Date.now } = {}) {
@@ -624,6 +656,7 @@ export function falMeter({ media, now = Date.now } = {}) {
624
656
  };
625
657
  return {
626
658
  bills: falBills,
659
+ results: falResults,
627
660
  async quote(tool, args, ask, signal) {
628
661
  const quotes = [];
629
662
  // One at a time: each endpoint's price is read once, the next job's from what the last one kept.
@@ -143,7 +143,7 @@ export function fauxComputers() {
143
143
  async function fauxDial(dial, run) {
144
144
  // The computer package's words for a dial provider with no dial (hosted/provider.ts #dialed).
145
145
  if (dial === undefined)
146
- throw new Error("Faux dial machines dial in to this server, and this runner runs in a process of its own, with no attach hub to take their socket: start the image with the server options alone, without server-and-runner (outside the image: agentrun-serve without --no-runner)");
146
+ throw new Error("Faux dial machines dial in to this server, and this runner runs in a process of its own and relays no machine's socket: give the runner AGENTRUN_PUBLIC_URL (this server's public address), or start the image with the server options alone, without server-and-runner (outside the image: agentrun-serve without --no-runner)");
147
147
  if (!dial.url)
148
148
  throw new Error("Faux dial machines dial in to this server, which has no public address: set AGENTRUN_PUBLIC_URL");
149
149
  const name = `faux-dial-${randomBytes(6).toString("hex")}`;
@@ -24,8 +24,8 @@ export declare function laidOut(text: string): string | undefined;
24
24
  /** The model's text for `text`, longer than `clip` characters: the filed text's first lines, whole, within `clip`, then
25
25
  * a note naming the file (`<folder>/<stem>.txt`, or `.json` for JSON) and the read offset that goes on. A file that
26
26
  * cannot be written still answers its start, saying why in the Workspace's words (never an error's message, which
27
- * names paths). `clip` is at least FILED_LINE_MAX, so the start holds at least one line. */
28
- export declare function filedAnswer(work: Workspace | (() => Workspace), folder: string, stem: string, text: string, clip: number): Promise<string>;
27
+ * names paths), a Workspace that cannot be opened (`work` a thunk that rejects) too. `clip` is at least FILED_LINE_MAX, so the start holds at least one line. */
28
+ export declare function filedAnswer(work: Workspace | (() => Workspace | Promise<Workspace>), folder: string, stem: string, text: string, clip: number): Promise<string>;
29
29
  /** For a unified diff (`diff --git a/... b/...` lines), where each file not wholly shown starts in the filed text and
30
30
  * how many lines it runs, so a reader takes the files it needs by range (and passes a generated one by) rather than
31
31
  * paging through all of it: "; files past the cut, from the line each starts at (its lines): a.ts 908 (120), ...". */
@@ -100,7 +100,7 @@ export function laidOut(text) {
100
100
  /** The model's text for `text`, longer than `clip` characters: the filed text's first lines, whole, within `clip`, then
101
101
  * a note naming the file (`<folder>/<stem>.txt`, or `.json` for JSON) and the read offset that goes on. A file that
102
102
  * cannot be written still answers its start, saying why in the Workspace's words (never an error's message, which
103
- * names paths). `clip` is at least FILED_LINE_MAX, so the start holds at least one line. */
103
+ * names paths), a Workspace that cannot be opened (`work` a thunk that rejects) too. `clip` is at least FILED_LINE_MAX, so the start holds at least one line. */
104
104
  export async function filedAnswer(work, folder, stem, text, clip) {
105
105
  const filed = fileable(text);
106
106
  const lines = filed.text.split("\n");
@@ -120,7 +120,7 @@ export async function filedAnswer(work, folder, stem, text, clip) {
120
120
  const cut = `\n[cut at line ${shown} of ${total} (${head.length} of ${filed.text.length} characters${how.length ? `; ${how.join("; ")}` : ""}); `;
121
121
  const path = `${folder}/${stem}.${filed.json ? "json" : "txt"}`;
122
122
  try {
123
- await (typeof work === "function" ? work() : work).write(path, filed.text);
123
+ await (await (typeof work === "function" ? work() : work)).write(path, filed.text);
124
124
  }
125
125
  catch (error) {
126
126
  return `${head}${cut}the whole answer could not be saved (${workspaceErrorWords(error) ?? error?.code ?? "write failed"})]`;
@@ -2,10 +2,12 @@
2
2
  export declare const LABEL_SHOWN = 200;
3
3
  export declare const ERROR_SHOWN = 2000;
4
4
  export type PartKind = "nodes" | "decision" | "effect";
5
- /** `value`, a part of a graph view of `kind`, as the graph serves it with `values` held: each string and number by
6
- * redactedOutput, then a map item's label cut at LABEL_SHOWN and an error at ERROR_SHOWN. A text stored cut (a
7
- * decision's state past 64 KB, an error marked cut, or one of exactly ERROR_CUT_BEFORE characters from before) has its
8
- * last 6 times the longest held value plus 16 characters held back, where a value the stored cut split would sit. */
5
+ /** `value`, a part of a graph view of `kind`, as the graph serves it with `values` held: read whole first, so a held
6
+ * value split across two of its fields withholds the part as "[redacted]", then each string and number by
7
+ * redactedOutput (redactedOutputWhole); then a map item's label cut at LABEL_SHOWN and an error at ERROR_SHOWN. A text
8
+ * stored cut (a decision's state past 64 KB, an error marked cut, or one of exactly ERROR_CUT_BEFORE characters from
9
+ * before) has its last 6 times the longest held value plus 16 characters held back, where a value the stored cut split
10
+ * would sit. */
9
11
  export declare function servedPart(kind: PartKind, value: unknown, values: readonly string[]): unknown;
10
12
  /** How many walks servedGraphView made, by what it walked: a part (servedPart over the nodes, a decision or a call) or a
11
13
  * field of the rest (redactedOutput over one top-level field). Counted for the tests, which read that a read again walks
@@ -18,7 +20,10 @@ export declare const graphWalks: {
18
20
  * over the same values), the parts by the file path's rule on top:
19
21
  * - its nodes, each decision and each call through servedPart (a map item's label and an error cut short after);
20
22
  * - every other top-level field (its run, its workflow, its structure `graph`, which echoes the workflow's nodes and their
21
- * words, its totals, and any field added later) through redactedOutput, each by itself, its keys included;
23
+ * words, its totals, and any field added later) through redactedOutputWhole, each by itself, its keys included: a
24
+ * field whose JSON holds a held value split across two of its strings is "[redacted]", but for `graph` and `run`,
25
+ * each served in its own shape (IN_SHAPE), so every reader that draws the run still reads a graph's nodes and edges
26
+ * and the run's status;
22
27
  * - `read_at`, which moves with every read: the server's clock as toISOString writes it, served as it is, never kept;
23
28
  * anything else under the name is cut each read.
24
29
  * Each part and each field, its name and its value, scalar or not, is cut once per content and held set and kept in
@@ -1,20 +1,22 @@
1
1
  // What GET /runs/{id}/graph serves of each part of a run's graph (servedGraphView, below): redacted by a run's answer's rule
2
- // (key-refusal.ts redactedOutput, over the values the server holds and handed the run), and only then cut. graph-view.ts
3
- // makes the view whole, so a key saved after it was made, or kept for a busy store's read, is still found.
2
+ // (key-refusal.ts redactedOutputWhole, over the values the server holds and handed the run), and only then cut.
3
+ // graph-view.ts makes the view whole, so a key saved after it was made, or kept for a busy store's read, is still found.
4
4
  import { createHash } from "node:crypto";
5
- import { redactedOutput } from "./key-refusal.js";
5
+ import { redactedOutput, redactedOutputWhole } from "./key-refusal.js";
6
6
  /** The most of a map item's label and of an error (a call's, a decision's) the graph shows. */
7
7
  export const LABEL_SHOWN = 200;
8
8
  export const ERROR_SHOWN = 2000;
9
9
  /** Where an error was cut when it was stored, before errors were stored whole: one this long may have been cut there. */
10
10
  const ERROR_CUT_BEFORE = 2000;
11
11
  const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
12
- /** `value`, a part of a graph view of `kind`, as the graph serves it with `values` held: each string and number by
13
- * redactedOutput, then a map item's label cut at LABEL_SHOWN and an error at ERROR_SHOWN. A text stored cut (a
14
- * decision's state past 64 KB, an error marked cut, or one of exactly ERROR_CUT_BEFORE characters from before) has its
15
- * last 6 times the longest held value plus 16 characters held back, where a value the stored cut split would sit. */
12
+ /** `value`, a part of a graph view of `kind`, as the graph serves it with `values` held: read whole first, so a held
13
+ * value split across two of its fields withholds the part as "[redacted]", then each string and number by
14
+ * redactedOutput (redactedOutputWhole); then a map item's label cut at LABEL_SHOWN and an error at ERROR_SHOWN. A text
15
+ * stored cut (a decision's state past 64 KB, an error marked cut, or one of exactly ERROR_CUT_BEFORE characters from
16
+ * before) has its last 6 times the longest held value plus 16 characters held back, where a value the stored cut split
17
+ * would sit. */
16
18
  export function servedPart(kind, value, values) {
17
- const shown = redactedOutput(value, values);
19
+ const shown = redactedOutputWhole(value, values);
18
20
  if (!isRecord(shown))
19
21
  return shown;
20
22
  const hold = 6 * values.reduce((most, held) => Math.max(most, held.length), 0) + 16;
@@ -38,13 +40,35 @@ export function servedPart(kind, value, values) {
38
40
  * nothing, with no clock. */
39
41
  export const graphWalks = { part: 0, rest: 0 };
40
42
  const isRecordOrArray = (value) => typeof value === "object" && value !== null;
43
+ /** The graph's structure (`graph`) when its JSON holds a held value split across two of its strings (a question's
44
+ * instructions ending with the value's head and its first option starting with the rest): the shape the contract gives
45
+ * the field, no nodes and no edges, and `withheld`, so a reader draws nothing and can say why. */
46
+ const WITHHELD_GRAPH = { nodes: [], edges: [], withheld: true };
47
+ /** The run's facts (`run`) when their JSON holds a held value split across two of them (its agent and its revision): the
48
+ * facts the server makes itself, which carry no one's words (its id, status, pause and times), each still cut as any
49
+ * string is, the agent and the revision "[redacted]", and `withheld`. */
50
+ const withheldRun = (run, values) => ({
51
+ ...Object.fromEntries(["id", "status", "paused", "startedAt", "endedAt"].filter((key) => key in run).map((key) => [key, redactedOutput(run[key], values)])),
52
+ agent: "[redacted]",
53
+ revision: "[redacted]",
54
+ withheld: true,
55
+ });
56
+ /** The top-level fields served in their own shape when withheld whole, by name: what a reader of the graph reads at once
57
+ * (the console draws the graph's nodes and reads the run's status). Any other field withheld whole is "[redacted]". */
58
+ const IN_SHAPE = {
59
+ graph: () => ({ ...WITHHELD_GRAPH }),
60
+ run: withheldRun,
61
+ };
41
62
  /** A time as Date's toISOString writes it, and nothing else: digits, its fixed separators and Z. */
42
63
  const ISO_TIME = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/;
43
64
  /** A graph view as GET /runs/{id}/graph serves it with `values` held, every field of it cut by the one rule (redactedOutput
44
65
  * over the same values), the parts by the file path's rule on top:
45
66
  * - its nodes, each decision and each call through servedPart (a map item's label and an error cut short after);
46
67
  * - every other top-level field (its run, its workflow, its structure `graph`, which echoes the workflow's nodes and their
47
- * words, its totals, and any field added later) through redactedOutput, each by itself, its keys included;
68
+ * words, its totals, and any field added later) through redactedOutputWhole, each by itself, its keys included: a
69
+ * field whose JSON holds a held value split across two of its strings is "[redacted]", but for `graph` and `run`,
70
+ * each served in its own shape (IN_SHAPE), so every reader that draws the run still reads a graph's nodes and edges
71
+ * and the run's status;
48
72
  * - `read_at`, which moves with every read: the server's clock as toISOString writes it, served as it is, never kept;
49
73
  * anything else under the name is cut each read.
50
74
  * Each part and each field, its name and its value, scalar or not, is cut once per content and held set and kept in
@@ -69,7 +93,13 @@ export function servedGraphView(view, values, cache) {
69
93
  // A field's name and its value, scalar or not, each cut once per content and held set: a poll walks none again.
70
94
  // (graphWalks.rest counts the walks of a field that holds more than one value, as before.)
71
95
  const cutName = kept(`name:${keys}:${digest(name)}`, () => redactedOutput(name, values));
72
- fields[cutName] = kept(`field:${keys}:${digest(name)}:${digest(value)}`, () => (isRecordOrArray(value) && graphWalks.rest++, redactedOutput(value, values)));
96
+ fields[cutName] = kept(`field:${keys}:${digest(name)}:${digest(value)}`, () => {
97
+ if (isRecordOrArray(value))
98
+ graphWalks.rest++;
99
+ const cut = redactedOutputWhole(value, values);
100
+ const shape = Object.hasOwn(IN_SHAPE, name) ? IN_SHAPE[name] : undefined;
101
+ return shape && isRecord(value) && cut === "[redacted]" ? shape(value, values) : cut;
102
+ });
73
103
  }
74
104
  return {
75
105
  // The read's own time, the server's clock as toISOString writes it, holds nothing of the run: served as it is. Any other
@@ -12,6 +12,7 @@ import { ServerSecrets } from "./server-secrets.js";
12
12
  import { sealedAt, unsealColumn } from "./store/seal.js";
13
13
  import { handedMark, handedPointers } from "./run-view.js";
14
14
  import { readLaunchBody } from "./run-launch.js";
15
+ import { SIGN_IN_VENDORS } from "./sign-ins-store.js";
15
16
  import { StoreLaunchMissing } from "./store/store.js";
16
17
  import { keptVendor } from "./tool-plane.js";
17
18
  /** The run's launch body read back, or undefined when it has none (an old run, or one not started with one). */
@@ -148,8 +149,6 @@ export function cutHanded(value, values) {
148
149
  };
149
150
  return walk(value);
150
151
  }
151
- /** The browser vendors that keep a sign-in (sign-ins-store.ts vendorOf). */
152
- const SIGN_IN_VENDORS = ["browserbase", "kernel"];
153
152
  /** Why what an agent learned is withheld (403): a pointer of its sign-in can't be read here, so the cut would be shorter
154
153
  * than what a note may hold. */
155
154
  export const WITHHELD_LEARNING = "This server can't read the agent's browser sign-in (its seal key changed or is missing, or the sign-in is damaged), so what it learned is not shown.";
@@ -12,7 +12,8 @@ export interface HarnessCheckOptions {
12
12
  /** The most the check may spend, USD. */
13
13
  capUsd?: number;
14
14
  platform?: string;
15
- /** For tests: the fetch the model proxy forwards with. */
15
+ /** For tests: the network the model proxy forwards to, under the check's recorder. A model the route translates goes
16
+ * through the route's own fetch instead, as on a server. */
16
17
  fetch?: typeof fetch;
17
18
  /** Each step as it happens, a line of words. */
18
19
  say?: (line: string) => void;