@parcha/agentrun-serve 0.1.0-beta.38 → 0.1.0-beta.40

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 (423) hide show
  1. package/CHANGELOG.md +455 -0
  2. package/README.md +376 -125
  3. package/dist/adapters.d.ts +4 -1
  4. package/dist/adapters.js +4 -2
  5. package/dist/agent-rows.d.ts +0 -2
  6. package/dist/agents-store.d.ts +5 -5
  7. package/dist/agents-store.js +14 -14
  8. package/dist/bash-read-only.js +2 -1
  9. package/dist/cap-short.d.ts +12 -0
  10. package/dist/cap-short.js +60 -0
  11. package/dist/cap.d.ts +3 -10
  12. package/dist/cap.js +2 -5
  13. package/dist/catalog.d.ts +0 -5
  14. package/dist/catalog.js +1 -5
  15. package/dist/chatgpt-plan.d.ts +163 -0
  16. package/dist/chatgpt-plan.js +549 -0
  17. package/dist/cli.js +26 -6
  18. package/dist/composio-preset.d.ts +8 -0
  19. package/dist/composio-preset.js +8 -7
  20. package/dist/composio-triggers.d.ts +113 -0
  21. package/dist/composio-triggers.js +411 -0
  22. package/dist/computer-calls.js +2 -2
  23. package/dist/computer-commands.d.ts +2 -0
  24. package/dist/computer-commands.js +7 -3
  25. package/dist/computer-live.d.ts +7 -2
  26. package/dist/computer-live.js +9 -5
  27. package/dist/computer-routes.d.ts +2 -2
  28. package/dist/computer-routes.js +2 -2
  29. package/dist/computer-setting.d.ts +3 -3
  30. package/dist/computer-setting.js +5 -5
  31. package/dist/computer-view.d.ts +15 -0
  32. package/dist/computer-view.js +16 -2
  33. package/dist/computer-viewer.js +14 -1
  34. package/dist/computers.d.ts +5 -2
  35. package/dist/computers.js +9 -5
  36. package/dist/console/assets/index-B8Zn1Iqn.css +1 -0
  37. package/dist/console/assets/index-Jbxjcmdp.js +705 -0
  38. package/dist/console/index.html +2 -2
  39. package/dist/console-links.js +3 -3
  40. package/dist/decision-cap.d.ts +2 -5
  41. package/dist/decision-cap.js +3 -6
  42. package/dist/decision-rows.js +11 -11
  43. package/dist/email/account.d.ts +83 -0
  44. package/dist/email/account.js +159 -0
  45. package/dist/email/answer.d.ts +15 -0
  46. package/dist/email/answer.js +217 -0
  47. package/dist/email/email-faux.d.ts +95 -0
  48. package/dist/email/email-faux.js +849 -0
  49. package/dist/email/labels.d.ts +1 -0
  50. package/dist/email/labels.js +84 -0
  51. package/dist/email/mail.d.ts +186 -0
  52. package/dist/email/mail.js +373 -0
  53. package/dist/email/names.d.ts +50 -0
  54. package/dist/email/names.js +74 -0
  55. package/dist/email/routes.d.ts +10 -0
  56. package/dist/email/routes.js +50 -0
  57. package/dist/email/tools.d.ts +27 -0
  58. package/dist/email/tools.js +562 -0
  59. package/dist/environment.d.ts +17 -2
  60. package/dist/environment.js +36 -8
  61. package/dist/errors.d.ts +6 -0
  62. package/dist/errors.js +12 -0
  63. package/dist/eval-mailbox.d.ts +103 -0
  64. package/dist/eval-mailbox.js +236 -0
  65. package/dist/graph-view.d.ts +9 -2
  66. package/dist/graph-view.js +6 -2
  67. package/dist/harness-install.d.ts +28 -2
  68. package/dist/harness-install.js +147 -59
  69. package/dist/harness-opencode/adapter.js +2 -26
  70. package/dist/harness-opencode/facts.js +5 -2
  71. package/dist/harness-opencode/host/policy.d.ts +2 -0
  72. package/dist/harness-opencode/host/policy.js +10 -5
  73. package/dist/harness-opencode/index.d.ts +1 -1
  74. package/dist/harness-opencode/index.js +1 -1
  75. package/dist/harness-opencode/versions.d.ts +6 -0
  76. package/dist/harness-opencode/versions.js +6 -0
  77. package/dist/harness-table.js +8 -5
  78. package/dist/harness.d.ts +12 -0
  79. package/dist/harness.js +15 -3
  80. package/dist/hosted-search.d.ts +3 -1
  81. package/dist/hosted-search.js +51 -11
  82. package/dist/import-sources.d.ts +1 -1
  83. package/dist/import-sources.js +3 -3
  84. package/dist/import.d.ts +21 -0
  85. package/dist/import.js +186 -1
  86. package/dist/key-check.d.ts +0 -2
  87. package/dist/key-check.js +3 -4
  88. package/dist/key-refusal.d.ts +8 -2
  89. package/dist/key-refusal.js +16 -13
  90. package/dist/learn/check.d.ts +18 -3
  91. package/dist/learn/check.js +328 -3
  92. package/dist/learn/compile.d.ts +12 -4
  93. package/dist/learn/compile.js +57 -20
  94. package/dist/learn/grade.d.ts +4 -0
  95. package/dist/learn/grade.js +4 -1
  96. package/dist/learn/promote.d.ts +130 -64
  97. package/dist/learn/promote.js +113 -202
  98. package/dist/learn/refit.d.ts +21 -12
  99. package/dist/learn/refit.js +51 -23
  100. package/dist/learn/replay-calls.js +1 -1
  101. package/dist/learn/skills.d.ts +2 -7
  102. package/dist/learn/skills.js +28 -14
  103. package/dist/learned-nodes.d.ts +15 -7
  104. package/dist/learned-nodes.js +29 -5
  105. package/dist/learned-workflow.d.ts +41 -31
  106. package/dist/learned-workflow.js +122 -63
  107. package/dist/learning-batch.js +3 -3
  108. package/dist/learning-cost.d.ts +35 -8
  109. package/dist/learning-cost.js +27 -9
  110. package/dist/learning-routes.d.ts +2 -4
  111. package/dist/learning-routes.js +20 -3
  112. package/dist/learning-words.d.ts +1 -1
  113. package/dist/learning-words.js +4 -1
  114. package/dist/learning.d.ts +5 -5
  115. package/dist/link-check.d.ts +27 -0
  116. package/dist/link-check.js +164 -0
  117. package/dist/local-models.d.ts +39 -2
  118. package/dist/local-models.js +49 -5
  119. package/dist/mcp-pin-first.js +6 -0
  120. package/dist/mcp-secret-writes.js +3 -0
  121. package/dist/mcp-servers-store.d.ts +25 -16
  122. package/dist/mcp-servers-store.js +23 -3
  123. package/dist/model-form.d.ts +11 -0
  124. package/dist/model-form.js +17 -1
  125. package/dist/model.d.ts +26 -6
  126. package/dist/model.js +126 -18
  127. package/dist/monid.d.ts +26 -31
  128. package/dist/monid.js +84 -79
  129. package/dist/native/binding.d.ts +13 -0
  130. package/dist/native/binding.js +57 -0
  131. package/dist/native/cli.d.ts +2 -0
  132. package/dist/native/cli.js +48 -0
  133. package/dist/native/connection.d.ts +8 -0
  134. package/dist/native/connection.js +94 -0
  135. package/dist/native/context.d.ts +6 -0
  136. package/dist/native/context.js +22 -0
  137. package/dist/native/discovery.d.ts +27 -0
  138. package/dist/native/discovery.js +404 -0
  139. package/dist/native/environment.d.ts +4 -0
  140. package/dist/native/environment.js +18 -0
  141. package/dist/native/history.d.ts +20 -0
  142. package/dist/native/history.js +147 -0
  143. package/dist/native/instructions.d.ts +21 -0
  144. package/dist/native/instructions.js +173 -0
  145. package/dist/native/remote-worker-bridge.d.ts +3 -0
  146. package/dist/native/remote-worker-bridge.js +278 -0
  147. package/dist/native/remote.d.ts +187 -0
  148. package/dist/native/remote.js +492 -0
  149. package/dist/native/runtime.d.ts +17 -0
  150. package/dist/native/runtime.js +316 -0
  151. package/dist/native/runtimes.d.ts +66 -0
  152. package/dist/native/runtimes.js +41 -0
  153. package/dist/native/schema.d.ts +46 -0
  154. package/dist/native/schema.js +41 -0
  155. package/dist/native/types.d.ts +87 -0
  156. package/dist/native/types.js +1 -0
  157. package/dist/observation/http.d.ts +4 -0
  158. package/dist/observation/http.js +140 -0
  159. package/dist/observation/observer.d.ts +301 -0
  160. package/dist/observation/observer.js +919 -0
  161. package/dist/observation/schema.d.ts +52 -0
  162. package/dist/observation/schema.js +154 -0
  163. package/dist/openapi.d.ts +2 -1
  164. package/dist/openapi.js +404 -93
  165. package/dist/paid-calls.d.ts +8 -3
  166. package/dist/paid-calls.js +6 -2
  167. package/dist/place-offers.d.ts +4 -8
  168. package/dist/place-offers.js +4 -9
  169. package/dist/port-models.d.ts +10 -2
  170. package/dist/port-models.js +6 -2
  171. package/dist/print.d.ts +4 -2
  172. package/dist/print.js +4 -3
  173. package/dist/propose.d.ts +1 -2
  174. package/dist/propose.js +10 -1
  175. package/dist/provider.d.ts +5 -1
  176. package/dist/provider.js +8 -0
  177. package/dist/push-handler.d.ts +3 -2
  178. package/dist/push-handler.js +20 -6
  179. package/dist/refusal-words.d.ts +14 -0
  180. package/dist/refusal-words.js +16 -2
  181. package/dist/run-launch.d.ts +12 -1
  182. package/dist/run-launch.js +13 -4
  183. package/dist/run-learning-served.d.ts +75 -2
  184. package/dist/run-manifest.d.ts +3 -0
  185. package/dist/run-manifest.js +13 -1
  186. package/dist/run-reads-over-store.d.ts +3 -3
  187. package/dist/run-reads-over-store.js +13 -10
  188. package/dist/run-timeline-served.d.ts +3 -2
  189. package/dist/run-timeline-served.js +8 -9
  190. package/dist/run-view.d.ts +44 -38
  191. package/dist/run-view.js +93 -56
  192. package/dist/runnable.d.ts +13 -5
  193. package/dist/runnable.js +69 -60
  194. package/dist/runner/adapter-loop.d.ts +48 -13
  195. package/dist/runner/adapter-loop.js +691 -254
  196. package/dist/runner/adapter-run-spec.d.ts +38 -12
  197. package/dist/runner/adapter-run-spec.js +175 -106
  198. package/dist/runner/adapters/pi.d.ts +24 -0
  199. package/dist/runner/adapters/pi.js +59 -9
  200. package/dist/runner/beside.d.ts +3 -1
  201. package/dist/runner/beside.js +24 -8
  202. package/dist/runner/claim-secrets.d.ts +3 -1
  203. package/dist/runner/claim-secrets.js +28 -4
  204. package/dist/runner/cli-run-spec.d.ts +30 -0
  205. package/dist/runner/cli-run-spec.js +95 -50
  206. package/dist/runner/computer-channel.d.ts +5 -2
  207. package/dist/runner/computer-channel.js +3 -2
  208. package/dist/runner/computer-journal.d.ts +6 -0
  209. package/dist/runner/computer-journal.js +8 -10
  210. package/dist/runner/conformance/harness.js +6 -3
  211. package/dist/runner/end-of-run.d.ts +2 -0
  212. package/dist/runner/end-of-run.js +3 -1
  213. package/dist/runner/feedback-round.d.ts +40 -13
  214. package/dist/runner/feedback-round.js +64 -16
  215. package/dist/runner/harness-loops.js +17 -0
  216. package/dist/runner/journal-kinds.d.ts +59 -13
  217. package/dist/runner/journal-kinds.js +48 -5
  218. package/dist/runner/learning-dispatch.d.ts +3 -2
  219. package/dist/runner/learning-dispatch.js +6 -6
  220. package/dist/runner/learning-end.d.ts +4 -0
  221. package/dist/runner/learning-end.js +64 -36
  222. package/dist/runner/learning-factory.d.ts +3 -0
  223. package/dist/runner/learning-factory.js +8 -2
  224. package/dist/runner/learning-loop.d.ts +2 -0
  225. package/dist/runner/learning-loop.js +19 -4
  226. package/dist/runner/loop.d.ts +18 -0
  227. package/dist/runner/loop.js +34 -0
  228. package/dist/runner/main.d.ts +6 -1
  229. package/dist/runner/main.js +26 -4
  230. package/dist/runner/mcp-run.d.ts +4 -1
  231. package/dist/runner/mcp-run.js +11 -5
  232. package/dist/runner/meta-tools.d.ts +10 -3
  233. package/dist/runner/meta-tools.js +112 -36
  234. package/dist/runner/metrics.d.ts +80 -21
  235. package/dist/runner/metrics.js +114 -39
  236. package/dist/runner/model-route.d.ts +14 -3
  237. package/dist/runner/model-route.js +155 -19
  238. package/dist/runner/monid-run.d.ts +8 -6
  239. package/dist/runner/monid-run.js +117 -43
  240. package/dist/runner/native-loop.d.ts +11 -0
  241. package/dist/runner/native-loop.js +438 -0
  242. package/dist/runner/promotion.d.ts +76 -10
  243. package/dist/runner/promotion.js +476 -154
  244. package/dist/runner/redact.js +3 -0
  245. package/dist/runner/reflect-hook.js +9 -0
  246. package/dist/runner/runner.d.ts +7 -1
  247. package/dist/runner/runner.js +8 -4
  248. package/dist/runner/sdk-loop.d.ts +7 -0
  249. package/dist/runner/sdk-loop.js +470 -0
  250. package/dist/runner/spec-holds.d.ts +16 -2
  251. package/dist/runner/spec-holds.js +42 -14
  252. package/dist/runner/store-secrets.js +17 -2
  253. package/dist/runner/workflow-first.d.ts +30 -20
  254. package/dist/runner/workflow-first.js +22 -32
  255. package/dist/runner/workflow-loop.d.ts +1 -1
  256. package/dist/runner/workflow-loop.js +18 -12
  257. package/dist/runner/workflow-spec.d.ts +4 -1
  258. package/dist/runner/workflow-spec.js +56 -45
  259. package/dist/runs-over-store.d.ts +30 -2
  260. package/dist/runs-over-store.js +46 -14
  261. package/dist/sdk/runs.d.ts +115 -0
  262. package/dist/sdk/runs.js +422 -0
  263. package/dist/sdk/schema.d.ts +175 -0
  264. package/dist/sdk/schema.js +138 -0
  265. package/dist/sdk/workflows.d.ts +22 -0
  266. package/dist/sdk/workflows.js +39 -0
  267. package/dist/secrets.d.ts +2 -0
  268. package/dist/secrets.js +19 -1
  269. package/dist/server.d.ts +48 -32
  270. package/dist/server.js +568 -137
  271. package/dist/skill-route.d.ts +3 -0
  272. package/dist/skill-route.js +16 -0
  273. package/dist/skills/agentrun-serve/SKILL.md +368 -0
  274. package/dist/stats.d.ts +10 -10
  275. package/dist/store/agent-body.d.ts +12 -8
  276. package/dist/store/agent-body.js +9 -4
  277. package/dist/store/dialect.d.ts +3 -0
  278. package/dist/store/dialect.js +1 -0
  279. package/dist/store/index.d.ts +1 -1
  280. package/dist/store/native-command-owner.d.ts +10 -0
  281. package/dist/store/native-command-owner.js +47 -0
  282. package/dist/store/postgres/connection.d.ts +11 -5
  283. package/dist/store/postgres/connection.js +44 -17
  284. package/dist/store/postgres/dialect.js +5 -0
  285. package/dist/store/postgres/migrations/0012_revision_monid_pin.sql +4 -0
  286. package/dist/store/postgres/migrations/0013_native_command_owner.sql +6 -0
  287. package/dist/store/postgres/migrations/0014_run_cost_upper_bound.sql +6 -0
  288. package/dist/store/postgres/store.d.ts +7 -3
  289. package/dist/store/postgres/store.js +4 -0
  290. package/dist/store/schema.d.ts +7 -0
  291. package/dist/store/schema.js +20 -1
  292. package/dist/store/sqlite/connection.js +72 -8
  293. package/dist/store/sqlite/run-launch.d.ts +11 -0
  294. package/dist/store/sqlite/run-launch.js +8 -0
  295. package/dist/store/sqlite/run-patch.d.ts +8 -1
  296. package/dist/store/sqlite/run-patch.js +14 -3
  297. package/dist/store/sqlite/store.js +170 -34
  298. package/dist/store/sqlite/worker.d.ts +2 -0
  299. package/dist/store/sqlite/worker.js +13 -10
  300. package/dist/store/store.d.ts +67 -7
  301. package/dist/store-reads/analytics.d.ts +7 -7
  302. package/dist/store-reads/analytics.js +23 -5
  303. package/dist/store-reads/cap.js +8 -6
  304. package/dist/store-reads/journal.d.ts +5 -0
  305. package/dist/store-reads/journal.js +85 -41
  306. package/dist/store-reads/learning.d.ts +115 -18
  307. package/dist/store-reads/learning.js +170 -68
  308. package/dist/store-reads/runs.d.ts +5 -0
  309. package/dist/store-reads/runs.js +3 -2
  310. package/dist/store-view.js +75 -21
  311. package/dist/template-eval.d.ts +73 -11
  312. package/dist/template-eval.js +535 -75
  313. package/dist/templates.d.ts +84 -21
  314. package/dist/templates.js +254 -47
  315. package/dist/text-urls.d.ts +38 -0
  316. package/dist/text-urls.js +170 -0
  317. package/dist/timeline/index.d.ts +3 -2
  318. package/dist/timeline/index.js +3 -2
  319. package/dist/timeline/labels.d.ts +5 -2
  320. package/dist/timeline/labels.js +29 -6
  321. package/dist/timeline/origin.d.ts +1 -1
  322. package/dist/timeline/origin.js +2 -2
  323. package/dist/timeline/render-text.js +1 -1
  324. package/dist/timeline/timeline.d.ts +66 -4
  325. package/dist/timeline/timeline.js +160 -30
  326. package/dist/timeline/util.d.ts +5 -0
  327. package/dist/timeline/util.js +44 -8
  328. package/dist/timeline/web-calls.d.ts +17 -0
  329. package/dist/timeline/web-calls.js +106 -0
  330. package/dist/tool-gate.d.ts +46 -44
  331. package/dist/tool-gate.js +101 -92
  332. package/dist/tool-list.d.ts +4 -1
  333. package/dist/tool-list.js +8 -1
  334. package/dist/tool-names.d.ts +18 -13
  335. package/dist/tool-names.js +19 -17
  336. package/dist/tool-plane.d.ts +17 -13
  337. package/dist/tool-plane.js +12 -5
  338. package/dist/tools.d.ts +57 -16
  339. package/dist/tools.js +33 -28
  340. package/dist/trigger-adapter.d.ts +56 -5
  341. package/dist/trigger-adapter.js +6 -0
  342. package/dist/trigger-adapters.js +3 -1
  343. package/dist/trigger-composio.d.ts +10 -0
  344. package/dist/trigger-composio.js +122 -0
  345. package/dist/trigger-email.d.ts +4 -0
  346. package/dist/trigger-email.js +181 -0
  347. package/dist/trigger-signatures.d.ts +6 -10
  348. package/dist/trigger-signatures.js +16 -16
  349. package/dist/trigger-targets.d.ts +1 -1
  350. package/dist/trigger-targets.js +4 -3
  351. package/dist/trigger-webhook.js +6 -4
  352. package/dist/triggers.d.ts +105 -8
  353. package/dist/triggers.js +286 -62
  354. package/dist/uploads.d.ts +9 -0
  355. package/dist/uploads.js +27 -0
  356. package/dist/validate.js +1 -7
  357. package/dist/web-fake.d.ts +56 -0
  358. package/dist/web-fake.js +102 -0
  359. package/dist/web-fetch-direct.d.ts +3 -0
  360. package/dist/web-fetch-direct.js +4 -1
  361. package/dist/web-fetch.d.ts +5 -1
  362. package/dist/web-fetch.js +8 -31
  363. package/dist/web-search.d.ts +51 -2
  364. package/dist/web-search.js +116 -18
  365. package/dist/webhooks.d.ts +2 -1
  366. package/dist/webhooks.js +5 -1
  367. package/dist/workflow/decision-recovery.js +5 -2
  368. package/dist/workflow/decisions.d.ts +7 -0
  369. package/dist/workflow/node-runner.js +10 -2
  370. package/dist/workspace/archil-claim.d.ts +3 -0
  371. package/dist/workspace/archil-claim.js +9 -2
  372. package/dist/workspace/computer-deps.d.ts +22 -9
  373. package/dist/workspace/computer-deps.js +78 -37
  374. package/dist/workspace/computer-for-claim.d.ts +54 -4
  375. package/dist/workspace/computer-for-claim.js +179 -39
  376. package/dist/workspace/computer-janitor.d.ts +10 -3
  377. package/dist/workspace/computer-janitor.js +96 -29
  378. package/dist/workspace/computer-kept.d.ts +82 -0
  379. package/dist/workspace/computer-kept.js +147 -0
  380. package/dist/workspace/computer-mcp.js +4 -3
  381. package/dist/workspace/computer-ports.d.ts +23 -3
  382. package/dist/workspace/computer-ports.js +115 -5
  383. package/dist/workspace/index.d.ts +1 -2
  384. package/dist/workspace/index.js +1 -2
  385. package/dist/workspace/kind-skills/desktop/SKILL.md +25 -18
  386. package/dist/workspace/kind-skills/phone/SKILL.md +28 -17
  387. package/dist/workspace/resolve-computer.d.ts +15 -3
  388. package/dist/workspace/resolve-computer.js +10 -7
  389. package/dist/workspace/revision-skills.d.ts +6 -2
  390. package/dist/workspace/revision-skills.js +12 -5
  391. package/dist/workspace/run-end-computers.d.ts +30 -0
  392. package/dist/workspace/run-end-computers.js +137 -0
  393. package/dist/workspace/run-tools.d.ts +28 -29
  394. package/dist/workspace/run-tools.js +29 -30
  395. package/dist/wrap-up.d.ts +19 -5
  396. package/dist/wrap-up.js +31 -4
  397. package/package.json +13 -9
  398. package/skills/agentrun-serve/SKILL.md +248 -10
  399. package/templates/README.md +117 -23
  400. package/templates/TOOLS.md +168 -0
  401. package/templates/code-review/agent.md +18 -4
  402. package/templates/code-review/evals/mentions-defused/case.yaml +1 -1
  403. package/templates/code-review/evals/off-by-one/graders/no-repo-reads.md +2 -1
  404. package/templates/code-review/evals/other-repo/case.yaml +1 -1
  405. package/templates/code-review/evals/pasted-by-reference/case.yaml +5 -0
  406. package/templates/code-review/evals/pasted-by-reference/graders/by-reference.md +15 -0
  407. package/templates/code-review/evals/pasted-by-reference/graders/head-sha.md +6 -0
  408. package/templates/code-review/evals/pasted-by-reference/prompt.md +31 -0
  409. package/templates/code-review/skills/review/DEEP.md +2 -2
  410. package/templates/code-review/skills/review/REVIEWER.md +2 -2
  411. package/templates/code-review/skills/review/SKILL.md +7 -3
  412. package/templates/release-notes/evals/draft-not-publish/case.yaml +1 -1
  413. package/templates/release-notes/evals/issue-write-refused/case.yaml +1 -1
  414. package/templates/release-notes/evals/late-arrival/case.yaml +1 -1
  415. package/templates/release-notes/evals/other-repo/case.yaml +1 -1
  416. package/dist/console/assets/index-CjqQirbo.css +0 -1
  417. package/dist/console/assets/index-b6-XY5A9.js +0 -576
  418. package/dist/host-calls.d.ts +0 -20
  419. package/dist/host-calls.js +0 -12
  420. package/dist/runner/adapters/pi-computer.d.ts +0 -9
  421. package/dist/runner/adapters/pi-computer.js +0 -51
  422. package/dist/workspace/computer-script.d.ts +0 -53
  423. package/dist/workspace/computer-script.js +0 -172
package/dist/uploads.js CHANGED
@@ -18,6 +18,11 @@ export const MAX_UPLOAD_BYTES = 50 * 2 ** 20;
18
18
  export const MAX_FILES_PER_RUN = 20;
19
19
  /** Where a run finds its files: `work/inputs/<path>`, each file's `path` with its folders. */
20
20
  export const INPUTS_DIR = "inputs";
21
+ /** The run's opening message as a file of its inputs/ (`inputs/message.md`): the start's text `content` byte for byte,
22
+ * so a long one (a pasted diff) is read by its path and named to a subagent, never copied into a call. The name is the
23
+ * message's alone: an upload at that path takes the next free one (`message-2.md`), with a message or without, and a
24
+ * run with no text message has no such file. */
25
+ export const MESSAGE_FILE = "message.md";
21
26
  /** The data directory's folder of uploads. */
22
27
  export const UPLOADS_DIR = "files";
23
28
  const RECORD = "file.json";
@@ -435,6 +440,10 @@ export class Uploads {
435
440
  const workspace = workspaceAt(work);
436
441
  await uploadTestHooks.beforeCopy?.(workspace);
437
442
  const names = takenNames(workspace);
443
+ // inputs/message.md is the run's message's (MESSAGE_FILE), never an upload's.
444
+ const top = await names(INPUTS_DIR);
445
+ if (!top.has(MESSAGE_FILE))
446
+ top.set(MESSAGE_FILE, "file");
438
447
  for (const file of files) {
439
448
  const segments = file.path.split("/");
440
449
  let dir = INPUTS_DIR;
@@ -494,6 +503,24 @@ export class Uploads {
494
503
  }
495
504
  /** The words a run fails in when its files cannot be copied into its workspace at its claim. */
496
505
  export const notCopied = (why) => `The run's files could not be copied into its workspace: ${why}`;
506
+ /** At a run's claim: its opening message (`message`, the start's text content) saved as inputs/message.md
507
+ * (MESSAGE_FILE) when it has one and the file is not there yet, then its uploaded files (`ids`) copied in as
508
+ * copyRunFiles copies them. Neither, and nothing is written. */
509
+ export async function placeRunInputs(data, runId, workspace, ids, message) {
510
+ if (ids.length)
511
+ await copyRunFiles(data, runId, workspace, ids);
512
+ if (!message)
513
+ return;
514
+ const there = await workspace.list(INPUTS_DIR).then((entries) => entries.some((entry) => entry.name === MESSAGE_FILE), () => false);
515
+ if (there)
516
+ return;
517
+ try {
518
+ await workspace.write(`${INPUTS_DIR}/${MESSAGE_FILE}`, Buffer.from(message, "utf8"));
519
+ }
520
+ catch (error) {
521
+ throw new Error(`The run's message could not be saved in its workspace as ${INPUTS_DIR}/${MESSAGE_FILE}: ${error.message}`, { cause: error });
522
+ }
523
+ }
497
524
  /** At a run's claim: its uploaded files (`ids`, the launch's file_ids) copied into its work/inputs/ once, from its hold
498
525
  * (Uploads.hold), and the hold let go. A resumed claim finds inputs/ there and copies nothing, so the copy's suffixes
499
526
  * never duplicate a file across claims. A copy that fails throws in notCopied's words: the run ends failed, saying why. */
package/dist/validate.js CHANGED
@@ -6,7 +6,6 @@ import { likelyModel, modelShape } from "./model-form.js";
6
6
  import { placeIssues } from "./place.js";
7
7
  import { computerIssues, settingConflict } from "./computer-setting.js";
8
8
  import { settingsIssues } from "./tool-plane.js";
9
- import { CAP_MODES } from "./cap.js";
10
9
  import { APPROVALS } from "./approvals.js";
11
10
  import { schemaCheck } from "./answer-json.js";
12
11
  export const ID = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
@@ -18,7 +17,7 @@ export const isObject = (value) => typeof value === "object" && value !== null &
18
17
  /** How long an Idempotency-Key answers with its first answer (capabilities' limits.idempotency_ttl_s). */
19
18
  export const IDEMPOTENCY_TTL_S = 86_400;
20
19
  export const stable = (value) => Array.isArray(value) ? `[${value.map(stable).join(",")}]` : isObject(value) ? `{${Object.keys(value).sort().map((k) => `${JSON.stringify(k)}:${stable(value[k])}`).join(",")}}` : JSON.stringify(value);
21
- export const DEFINITION_FIELDS = ["id", "version", "name", "description", "instructions", "workflow", "model", "model_tiers", "thinking", "harness", "place", "computer", "learning", "skills", "tools", "tool_settings", "approvals", "max_cost_usd", "cap_mode", "input_schema", "output_schema", "checkout"];
20
+ export const DEFINITION_FIELDS = ["id", "version", "name", "description", "instructions", "workflow", "model", "model_tiers", "thinking", "harness", "place", "computer", "learning", "skills", "tools", "tool_settings", "approvals", "max_cost_usd", "input_schema", "output_schema", "checkout", "native", "sdk"];
22
21
  /** What an agentic definition may ask the server to check out in each run's folder before its first turn
23
22
  * (runner/pr-checkout.ts): `pull_request`, the pull request the run's GitHub event names, at its head, read-only, in
24
23
  * `repo/`; `none` clears it on an edit. */
@@ -173,11 +172,6 @@ export function definitionIssues(definition, { at = "definition", creating = tru
173
172
  else if (!CHECKOUTS.includes(d.checkout))
174
173
  out.push(issue(`${at}.checkout`, "not_an_option", `${at}.checkout is one of ${CHECKOUTS.join(", ")}: pull_request checks out the pull request the run's GitHub event names, at its head, in repo/ before the first turn; none clears it`));
175
174
  }
176
- // How a run's cap prices its requests (cap.ts CapMode): kept, as the default cap is, by an edit that leaves it out.
177
- if (d.cap_mode !== undefined) {
178
- if (!CAP_MODES.includes(d.cap_mode))
179
- out.push(issue(`${at}.cap_mode`, "not_an_option", `${at}.cap_mode is one of ${CAP_MODES.join(", ")}: expected prices a request's input from the previous request's cache, strict prices all of it uncached`));
180
- }
181
175
  return out;
182
176
  }
183
177
  /** The skill files a body names: an object of relative paths inside `.agents/skills/` to text. */
@@ -0,0 +1,56 @@
1
+ import { type Page, type Part } from "./web-fetch-direct.js";
2
+ import { type WebPage } from "./web-fetch.js";
3
+ import { type Hit, type Search } from "./web-search.js";
4
+ import type { Plane } from "./tool-plane.js";
5
+ export type SearchAnswer = {
6
+ query: string;
7
+ results: Hit[];
8
+ } | {
9
+ query: string;
10
+ error: string;
11
+ };
12
+ export type FetchAnswer = {
13
+ url: string;
14
+ status?: number;
15
+ title?: string;
16
+ text: string;
17
+ } | {
18
+ url: string;
19
+ error: string;
20
+ };
21
+ export type WebFixture = {
22
+ search: {
23
+ answers: SearchAnswer[];
24
+ default: {
25
+ results: Hit[];
26
+ } | {
27
+ error: string;
28
+ };
29
+ };
30
+ fetch: {
31
+ answers: FetchAnswer[];
32
+ default: {
33
+ status?: number;
34
+ title?: string;
35
+ text: string;
36
+ } | {
37
+ error: string;
38
+ };
39
+ };
40
+ };
41
+ /** A case's web fake: every web call failing, or a fixture. */
42
+ export type WebFake = "unavailable" | WebFixture;
43
+ /** `value` checked as a web fixture: the fixture, else each problem said through `bad`, `at` naming the file. */
44
+ export declare function webFixtureOf(value: unknown, at: string, bad: (message: string) => void): WebFixture | undefined;
45
+ /** `args` searched in `fake`, as the run's web_search answers: `provider`, the one the run's plane names. */
46
+ export declare function fakeSearch(fake: WebFake, args: Record<string, unknown>, provider: Exclude<Search, {
47
+ error: string;
48
+ }>["provider"]): Search;
49
+ /** The part `part` names of the page at `url` in `fake`, as the run's web_fetch answers, through the guarded direct
50
+ * fetch's own path with the fake standing in for the network. */
51
+ export declare function fakeFetch(fake: WebFake, url: unknown, part?: Part & {
52
+ signal?: AbortSignal;
53
+ }): Promise<WebPage | Page>;
54
+ /** A faked run's plane: web_search never a harness's own search (Claude's or Codex's, which would answer in its stead), so
55
+ * the run's own web_search tool, the one the fake answers through, is the one its harness offers. */
56
+ export declare function fakedPlane(plane: Plane | undefined): Plane | undefined;
@@ -0,0 +1,102 @@
1
+ // A template eval's fake of the web tools for one case (template-eval.ts, `web:` in a case's case.yaml): its runs'
2
+ // web_search and web_fetch answer from the case, never from the network, in the shapes and through the tool names the
3
+ // model sees live. `unavailable`: every search fails as keyless search past its free limit does (exa-keyless.ts
4
+ // RATE_LIMITED), and every page fails as a fetch whose connection is refused does (the guarded direct fetch's own words,
5
+ // web-fetch-direct.ts readDirect). A fixture: each search answered by the first answer whose `query` (a regular
6
+ // expression, case-insensitive) matches the query, else its default; each page by the answer for exactly its URL, else
7
+ // its default, read through the guarded direct fetch's own path (its URL, port and status checks, its parts).
8
+ //
9
+ // Only the eval's own in-process runner binds it (runner/beside.ts `evalFakes`, by the agent the eval made for the run):
10
+ // no package field, API field, setting or environment variable reaches it, so no other server's runs ever see a fake.
11
+ import { RATE_LIMITED } from "./exa-keyless.js";
12
+ import { clip, partProblem, TITLE_CAP, URL_MAX } from "./web-fetch-direct.js";
13
+ import { webFetch } from "./web-fetch.js";
14
+ import { searchArgs, snippetOf } from "./web-search.js";
15
+ /** A public address the fake's lookup answers: the guard checks it is public, and no connection is ever made to it. */
16
+ const PUBLIC_ADDRESS = "203.0.114.1";
17
+ /** The statuses whose answer carries no body (a Response refuses one). */
18
+ const NULL_BODY = new Set([204, 205, 304]);
19
+ const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
20
+ const isText = (value) => typeof value === "string";
21
+ /** `value` checked as a web fixture: the fixture, else each problem said through `bad`, `at` naming the file. */
22
+ export function webFixtureOf(value, at, bad) {
23
+ const problems = [];
24
+ const say = (message) => void problems.push(`${at}: ${message}`);
25
+ if (!isObject(value) || !isObject(value.search) || !isObject(value.fetch)) {
26
+ bad(`${at}: a web fixture is {search: {answers, default}, fetch: {answers, default}}`);
27
+ return undefined;
28
+ }
29
+ const hitOk = (hit) => isObject(hit) && isText(hit.url) && URL.canParse(hit.url) && isText(hit.title) && isText(hit.snippet) && (hit.published === undefined || isText(hit.published));
30
+ const searchOk = (answer, keyed) => isObject(answer) && (!keyed || isText(answer.query)) && (Array.isArray(answer.results) ? answer.results.every(hitOk) && answer.error === undefined : isText(answer.error));
31
+ const pageOk = (answer, keyed) => isObject(answer) && (!keyed || (isText(answer.url) && URL.canParse(answer.url))) && (isText(answer.text) ? answer.error === undefined && (answer.title === undefined || isText(answer.title)) && (answer.status === undefined || (Number.isInteger(answer.status) && answer.status >= 200 && answer.status <= 599)) : isText(answer.error));
32
+ const search = value.search;
33
+ const fetch = value.fetch;
34
+ if (!Array.isArray(search.answers))
35
+ say("search.answers is a list of {query, results} or {query, error}");
36
+ else
37
+ search.answers.forEach((answer, i) => {
38
+ if (!searchOk(answer, true))
39
+ return void say(`search.answers.${i} is {query, results} or {query, error}, each result {url, title, snippet, published?}`);
40
+ try {
41
+ new RegExp(answer.query, "i");
42
+ }
43
+ catch {
44
+ say(`search.answers.${i}.query does not compile as a regular expression`);
45
+ }
46
+ });
47
+ if (!searchOk(search.default, false))
48
+ say("search.default is {results} or {error}, each result {url, title, snippet, published?}");
49
+ if (!Array.isArray(fetch.answers))
50
+ say("fetch.answers is a list of {url, status?, title?, text} or {url, error}");
51
+ else
52
+ fetch.answers.forEach((answer, i) => {
53
+ if (!pageOk(answer, true))
54
+ say(`fetch.answers.${i} is {url, status?, title?, text} or {url, error}, its url absolute and its status 200 to 599`);
55
+ });
56
+ if (!pageOk(fetch.default, false))
57
+ say("fetch.default is {status?, title?, text} or {error}");
58
+ for (const problem of problems)
59
+ bad(problem);
60
+ return problems.length ? undefined : value;
61
+ }
62
+ /** `args` searched in `fake`, as the run's web_search answers: `provider`, the one the run's plane names. */
63
+ export function fakeSearch(fake, args, provider) {
64
+ const { query, n } = searchArgs(args);
65
+ if (!query)
66
+ return { error: "web_search needs a query" };
67
+ if (fake === "unavailable")
68
+ return { error: RATE_LIMITED };
69
+ const answer = fake.search.answers.find((one) => new RegExp(one.query, "i").test(query)) ?? fake.search.default;
70
+ if ("error" in answer)
71
+ return { error: answer.error };
72
+ const results = answer.results.slice(0, n).map((hit) => ({ url: hit.url, title: clip(hit.title, TITLE_CAP), snippet: snippetOf(hit.snippet), ...(hit.published === undefined ? {} : { published: hit.published }) }));
73
+ return { provider, query, results };
74
+ }
75
+ /** The part `part` names of the page at `url` in `fake`, as the run's web_fetch answers, through the guarded direct
76
+ * fetch's own path with the fake standing in for the network. */
77
+ export async function fakeFetch(fake, url, part = {}) {
78
+ const problem = partProblem(part);
79
+ if (problem)
80
+ return { ok: false, url: typeof url === "string" ? clip(url, URL_MAX) : "", status: 0, title: "", text: "", links: [], error: problem };
81
+ const answer = fake === "unavailable" ? undefined : (fake.fetch.answers.find((one) => one.url === url) ?? fake.fetch.default);
82
+ const page = await webFetch(url, {
83
+ ...part,
84
+ lookup: async () => [PUBLIC_ADDRESS],
85
+ fetchImpl: async () => {
86
+ // As undici's fetch rejects when a connection is refused: the guarded fetch says it in its own words.
87
+ if (answer === undefined)
88
+ throw new TypeError("fetch failed", { cause: Object.assign(new Error("connect ECONNREFUSED"), { code: "ECONNREFUSED" }) });
89
+ if ("error" in answer)
90
+ throw new TypeError(answer.error);
91
+ const status = answer.status ?? 200;
92
+ return new Response(NULL_BODY.has(status) ? null : answer.text, { status, headers: { "content-type": "text/plain; charset=utf-8" } });
93
+ },
94
+ });
95
+ // A page served as text has no title of its own: the fixture's.
96
+ return page.ok && answer && !("error" in answer) && answer.title ? { ...page, title: clip(answer.title, TITLE_CAP) } : page;
97
+ }
98
+ /** A faked run's plane: web_search never a harness's own search (Claude's or Codex's, which would answer in its stead), so
99
+ * the run's own web_search tool, the one the fake answers through, is the one its harness offers. */
100
+ export function fakedPlane(plane) {
101
+ return plane?.web_search === "native" ? { ...plane, web_search: "exa-keyless" } : plane;
102
+ }
@@ -1,5 +1,8 @@
1
1
  import type { TSchema } from "typebox";
2
2
  import type { PublicFetchOptions } from "@parcha/pi-browser";
3
+ import { linksOf } from "./text-urls.js";
4
+ /** A page's text read for its links (text-urls.ts): web_fetch's Parallel read takes it from here. */
5
+ export { linksOf };
3
6
  /** On a page that was read, `chars`: the length of `text`, the part of the page's text this answer holds. `truncated`
4
7
  * while more of it follows this part, and `next_offset` where that begins; `offset` where this part begins, when not 0;
5
8
  * `original_chars` the whole text's length in characters, when it is known and this part is not all of it;
@@ -12,6 +12,9 @@
12
12
  // Every field of a Page is held to a cap (its text, its title, its URL, its links), so one answer is too: serve's
13
13
  // host-bounds test holds it to the host's result bound.
14
14
  import { pathToFileURL } from "node:url";
15
+ import { linksOf } from "./text-urls.js";
16
+ /** A page's text read for its links (text-urls.ts): web_fetch's Parallel read takes it from here. */
17
+ export { linksOf };
15
18
  /** Under `--faux` only: a module whose default export gives `{ lookup, fetchImpl }` for the fetch (the tests' fake
16
19
  * network), in place of the system's resolver and undici. */
17
20
  export const FAUX_WEB_ENV = "AGENTRUN_SERVE_FAUX_WEB";
@@ -146,7 +149,7 @@ export async function readDirect(url, options = {}) {
146
149
  return failed({ url: clip(answer.url, URL_MAX), status: answer.status, error: `the page answered ${answer.status}` });
147
150
  // The caller's stop reaches the read too; the timeout is the network's, and readPage keeps its own deadline.
148
151
  const read = /html/i.test(answer.contentType) ? await readPage(answer.body, answer.url, options.signal ? { signal: options.signal } : {}) : null;
149
- const page = read ?? { title: "", text: answer.body, links: [] };
152
+ const page = read ?? { title: "", text: answer.body, links: linksOf(answer.body) };
150
153
  return { ok: true, url: clip(answer.url, URL_MAX), status: answer.status, title: clip(page.title, TITLE_CAP), ...textOf(page.text, !read?.truncated), ...(read?.truncated ? { html_chars: read.html_chars } : {}), ...(read?.converted === "text" ? { converted: "text" } : {}), ...linksWithin(page.links) };
151
154
  }
152
155
  catch (error) {
@@ -62,5 +62,9 @@ export declare function webFetchText(page: WebPage | Page, name?: string): strin
62
62
  /** The agent's tool: the WebPage as JSON text (webFetchText), named `name`. A
63
63
  * run whose web_fetch resolves to Parallel reads its key as the tool is made, when the run opens. */
64
64
  /** Typed here, so its declaration names the schema type by a package serve declares (pi-ai), whatever else the build loads. */
65
- export declare function webFetchTool(env: NodeJS.ProcessEnv, name?: string): ToolRegistration<TSchema, JsonValue>;
65
+ /** `fake`: what reads each page in the provider's place (a template eval's web fake, web-fake.ts), the tool otherwise
66
+ * the same. */
67
+ export declare function webFetchTool(env: NodeJS.ProcessEnv, name?: string, fake?: (url: unknown, part: Part & {
68
+ signal?: AbortSignal;
69
+ }) => Promise<WebPage | Page>): ToolRegistration<TSchema, JsonValue>;
66
70
  export {};
package/dist/web-fetch.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { defineTool } from "@earendil-works/pi-durable";
2
2
  import { FAUX_PARALLEL_ENV, fauxFetch, parallelKeyOf } from "./decisions.js";
3
- import { clip, fetchOptions, HTML_READ_CHARS, linksWithin, MAX_CHARS_MIN, PAGE_CHARS, PAGE_READ_MAX_CHARS, partOfRead, partProblem, readDirect, TEXT_CAP, TIMEOUT_MS, TITLE_CAP, textOf, URL_MAX, URL_PARAMETERS } from "./web-fetch-direct.js";
3
+ import { clip, fetchOptions, HTML_READ_CHARS, linksOf, linksWithin, MAX_CHARS_MIN, PAGE_CHARS, PAGE_READ_MAX_CHARS, partOfRead, partProblem, readDirect, TEXT_CAP, TIMEOUT_MS, TITLE_CAP, textOf, URL_MAX, URL_PARAMETERS } from "./web-fetch-direct.js";
4
4
  import { FAUX_ENV } from "./model.js";
5
5
  import { PaidRefused, paidRequest, parallelFeeOf } from "./paid-calls.js";
6
6
  import { forModel } from "./result.js";
@@ -11,32 +11,6 @@ const PARALLEL_TIMEOUT_MS = 60_000;
11
11
  const PORTS = new Set(["", "80", "443"]);
12
12
  /** How many pages a run keeps what it read of (Pages): each at most PAGE_READ_MAX_CHARS characters of text. */
13
13
  export const PAGES_HELD = 8;
14
- /** The absolute http(s) URLs a markdown text links to (`[text](url)`), each once and without its fragment, in order, as
15
- * they are read (linksWithin keeps those within the caps and counts the rest). A URL ends at whitespace or at the ")"
16
- * that closes the link, so parentheses it holds in pairs (a wiki title's) stay. */
17
- function* linksOf(markdown) {
18
- const seen = new Set();
19
- // The next "](" is looked for from where this one's URL ended, so no character is scanned twice: one pass, however
20
- // many unclosed "](" a hostile page holds.
21
- for (let at = markdown.indexOf("]("), end = 0; at !== -1; at = markdown.indexOf("](", Math.max(at + 2, end))) {
22
- end = at + 2;
23
- for (let depth = 0; end < markdown.length && !/\s/.test(markdown[end]); end++) {
24
- if (markdown[end] === "(")
25
- depth++;
26
- else if (markdown[end] === ")" && depth-- === 0)
27
- break;
28
- }
29
- const href = markdown.slice(at + 2, end);
30
- const link = /^https?:\/\//i.test(href) ? URL.parse(href) : null;
31
- if (!link)
32
- continue;
33
- link.hash = "";
34
- if (seen.has(link.href))
35
- continue;
36
- seen.add(link.href);
37
- yield link.href;
38
- }
39
- }
40
14
  /** Parallel's extract on `apiKey`: one URL a request, each a billed extract, its full content to the most of a page
41
15
  * web_fetch reads as the page's text (markdown), its links read from it, status 200 (Parallel answers a page it could
42
16
  * not read in `errors`, with no content). */
@@ -260,17 +234,20 @@ export function webFetchText(page, name = WEB_FETCH_TOOL) {
260
234
  /** The agent's tool: the WebPage as JSON text (webFetchText), named `name`. A
261
235
  * run whose web_fetch resolves to Parallel reads its key as the tool is made, when the run opens. */
262
236
  /** Typed here, so its declaration names the schema type by a package serve declares (pi-ai), whatever else the build loads. */
263
- export function webFetchTool(env, name = WEB_FETCH_TOOL) {
264
- if (planeOf(env).web_fetch === "parallel")
237
+ /** `fake`: what reads each page in the provider's place (a template eval's web fake, web-fake.ts), the tool otherwise
238
+ * the same. */
239
+ export function webFetchTool(env, name = WEB_FETCH_TOOL, fake) {
240
+ if (planeOf(env).web_fetch === "parallel" && !fake)
265
241
  parallelOf(env);
266
242
  return defineTool({
267
243
  name,
268
- description: `Read one web page from a public host, a part at a time. It has no cookies, sign-ins or session: it reads one page cold, so a page behind a sign-in, or one that depends on an earlier page, needs the browser tool, where this run has it. Answers JSON: ok, the final url, the HTTP status, the page's title, text (a part of its readable text as markdown: about max_chars characters from offset, ${PAGE_CHARS.toLocaleString("en-US")} by default, at least ${MAX_CHARS_MIN} and at most ${TEXT_CAP.toLocaleString("en-US")}) and chars (that part's length), the absolute links the page holds (with the part at offset 0; links_omitted counts those its caps left out), and via: parallel when Parallel's extract read it, direct when it was fetched from the host (with parallel saying why, where Parallel was picked and gave no page), stopped when the call was stopped before its page arrived. A part that is not the whole page says so: truncated is true while more follows, next_offset is where the rest begins, original_chars is the page's whole length where it is known, and a line after the JSON says which characters these are; call again with offset to read on. A page whose HTML is longer than ${HTML_READ_CHARS.toLocaleString("en-US")} characters (scripts and styles aside) is cut before it is read: html_chars gives its whole length on every part, its text is only the start of the page, and the last part's line says it was cut. converted is "text" when the text is the page's plain text, its conversion to markdown having run out of time. A page is read to its first ${PAGE_READ_MAX_CHARS.toLocaleString("en-US")} characters (beyond_read on the last part says it goes on). A page is fetched once a run, at its first call: its later parts come from that read, with no request (through Parallel, one billed extract a page). A private or local address, a port other than 80 or 443, or a scheme other than http(s) is refused and never read (ok false, with refused saying why); so is a page fetched directly that is not text.`,
244
+ description: `Read one web page from a public host, a part at a time. It has no cookies, sign-ins or session: it reads one page cold, so a page behind a sign-in, or one that depends on an earlier page, needs the browser tool, where this run has it. Answers JSON: ok, the final url, the HTTP status, the page's title, text (a part of its readable text as markdown: about max_chars characters from offset, ${PAGE_CHARS.toLocaleString("en-US")} by default, at least ${MAX_CHARS_MIN} and at most ${TEXT_CAP.toLocaleString("en-US")}) and chars (that part's length), the absolute links the page holds (its link targets and the URLs written out in its text, a JSON body's strings and an XML feed's links among them, where an HTML page fetched directly gives its link targets alone; with the part at offset 0; links_omitted counts those its caps left out), and via: parallel when Parallel's extract read it, direct when it was fetched from the host (with parallel saying why, where Parallel was picked and gave no page), stopped when the call was stopped before its page arrived. A part that is not the whole page says so: truncated is true while more follows, next_offset is where the rest begins, original_chars is the page's whole length where it is known, and a line after the JSON says which characters these are; call again with offset to read on. A page whose HTML is longer than ${HTML_READ_CHARS.toLocaleString("en-US")} characters (scripts and styles aside) is cut before it is read: html_chars gives its whole length on every part, its text is only the start of the page, and the last part's line says it was cut. converted is "text" when the text is the page's plain text, its conversion to markdown having run out of time. A page is read to its first ${PAGE_READ_MAX_CHARS.toLocaleString("en-US")} characters (beyond_read on the last part says it goes on). A page is fetched once a run, at its first call: its later parts come from that read, with no request (through Parallel, one billed extract a page). A private or local address, a port other than 80 or 443, or a scheme other than http(s) is refused and never read (ok false, with refused saying why); so is a page fetched directly that is not text.`,
269
245
  parameters: URL_PARAMETERS,
270
246
  replay: "safe",
271
247
  execute: async (args, _api, context) => {
272
248
  const { url, offset, max_chars } = args;
273
- const page = await fetchFor(env, url, { ...(await fetchOptions(env, FAUX_ENV)), offset, maxChars: max_chars, pages: pagesOf(env), ...(context?.abortSignal ? { signal: context.abortSignal } : {}) });
249
+ const signal = context?.abortSignal ? { signal: context.abortSignal } : {};
250
+ const page = fake ? await fake(url, { offset, maxChars: max_chars, ...signal }) : await fetchFor(env, url, { ...(await fetchOptions(env, FAUX_ENV)), offset, maxChars: max_chars, pages: pagesOf(env), ...signal });
274
251
  return forModel(webFetchText(page, name), { details: page });
275
252
  },
276
253
  });
@@ -1,6 +1,7 @@
1
1
  import type { TSchema } from "typebox";
2
2
  import type { JsonValue } from "@earendil-works/chord/json";
3
3
  import { type ToolRegistration } from "@earendil-works/pi-durable";
4
+ import { type ExaLimited } from "./exa-keyless.js";
4
5
  import { type SearchModels } from "./hosted-search.js";
5
6
  import { type Extract } from "./web-fetch.js";
6
7
  export declare const WEB_SEARCH_TOOL = "web_search";
@@ -16,6 +17,11 @@ export declare const ANSWER_MAX = 4000;
16
17
  /** The most characters a search's answer takes, its citing line included: about RESULTS_MAX results with whole snippets,
17
18
  * under the host's result bound (HOST_RESULT_MAX_CHARS), which the host-bounds test holds it to. */
18
19
  export declare const SEARCH_MAX_CHARS = 100000;
20
+ /** What every later web_search call of a run answers once its provider said the run is out of quota (a Limit of kind
21
+ * quota): the provider is not asked again in that run. */
22
+ export declare const SEARCH_UNAVAILABLE = "search is unavailable for the rest of this run; answer from what you have";
23
+ /** What a call answers while a rate limit's wait holds, `seconds` of it left. */
24
+ export declare const searchBusy: (seconds: number) => string;
19
25
  export type Hit = {
20
26
  url: string;
21
27
  title: string;
@@ -31,6 +37,41 @@ export type Search = {
31
37
  } | {
32
38
  error: string;
33
39
  };
40
+ /** What a provider's failure said of the run's search: out of quota, or rate-limited, with the wait it named as it
41
+ * handed it back (a Retry-After header's value, delta-seconds or an HTTP date, or Exa's seconds). `repeatIsQuota`, the
42
+ * server's mark on keyless Exa's limit naming no wait alone (exaLimitOf): Exa answers its daily count running out as
43
+ * that limit, so the same answer again once a wait has passed is that count (searchBreaker). */
44
+ export type Limit = {
45
+ kind: "quota";
46
+ } | {
47
+ kind: "rate";
48
+ retryAfter?: string | number;
49
+ repeatIsQuota?: true;
50
+ };
51
+ /** A Search, and the limit its provider answered, if any: the run's breaker reads `limit` (searchBreaker), the model the
52
+ * Search alone. */
53
+ export type Searched = {
54
+ answer: Search;
55
+ limit?: Limit;
56
+ };
57
+ /** The wait `retryAfter` names, in ms from `nowMs`: delta-seconds, an HTTP date, or Exa's seconds. None, or words that
58
+ * read as neither, 60 s; a date already passed, none; never more than 15 minutes (MAX_WAIT_MS). */
59
+ export declare function waitOf(retryAfter: string | number | undefined, nowMs: number): number;
60
+ /** A run's breaker on its web_search, read at `now`. `held` is what a call answers unsent while it holds: SEARCH_UNAVAILABLE
61
+ * for the rest of the run once a quota answer came, or searchBusy with the seconds left of a rate limit's wait (rounded
62
+ * up, so at least 1); else undefined, and the call asks the provider. `read` takes a search's own answer and its limit:
63
+ * a quota answer turns search off for good, a rate limit holds search for its wait from now, or for the wait already
64
+ * open when that ends later (two calls in flight: a short wait never shrinks a long one), anything else leaves it as it
65
+ * is. A rate limit marked repeatIsQuota (keyless Exa's, naming no wait) after an earlier marked one whose wait has
66
+ * passed counts as a quota answer: off for the run, and that call answers SEARCH_UNAVAILABLE in place of its own words
67
+ * (Exa's "try again in a minute"). A quota answer keeps the call's own answer, which names no retry. One that comes
68
+ * while a wait is open (in flight with the first) only holds it, and a search that succeeds in between resets the
69
+ * count: once Exa's daily count is spent every keyless call is limited, so a success means it is not. A failed search
70
+ * that is no limit resets nothing. */
71
+ export declare function searchBreaker(now?: () => number): {
72
+ held(): Search | undefined;
73
+ read(searched: Searched): Search;
74
+ };
34
75
  /** The line that ends a search's answer to the model, as Claude Code's WebSearch ends its own. */
35
76
  export declare const CITE = "Cite the URL of each result you rely on.";
36
77
  /** `answer` within SEARCH_MAX_CHARS, as searchText writes it: whole when it fits, else without its least relevant results
@@ -54,6 +95,14 @@ export type SearchOn = () => Promise<SearchModels | undefined>;
54
95
  /** `{query, n?}` searched by the provider the run's plane resolves web_search to, as a Search. `models`: the run's own
55
96
  * models a native search goes through (none: a native search has no model to search on). */
56
97
  export declare function searchFor(env: NodeJS.ProcessEnv, args: Record<string, unknown>, signal?: AbortSignal, models?: SearchOn): Promise<Search>;
98
+ /** Keyless Exa's refusal as the run's breaker reads it: a rate limit, with the wait it named. One naming no wait (its MCP
99
+ * notice, as its daily count running out answers) is marked repeatIsQuota, so a second one past a wait is that count; a
100
+ * 429 with Retry-After is a timed limit, unmarked. A refused connection is no limit (a 403 no wait lifts). */
101
+ export declare function exaLimitOf(found: ExaLimited): Limit | undefined;
57
102
  /** The agent's tool: the Search as JSON text. A run whose web_search resolves to Parallel reads its key as the tool is
58
- * made, when the run opens; one that resolves native searches through `models`, the run's own (ToolHost.search). */
59
- export declare function webSearchTool(env: NodeJS.ProcessEnv, models?: SearchOn): ToolRegistration<TSchema, JsonValue>;
103
+ * made, when the run opens; one that resolves native searches through `models`, the run's own (ToolHost.search).
104
+ * `fake`: what answers each search in the provider's place (a template eval's web fake, web-fake.ts), the provider
105
+ * the run's plane names given it, the tool otherwise the same. */
106
+ export declare function webSearchTool(env: NodeJS.ProcessEnv, models?: SearchOn, fake?: (args: Record<string, unknown>, provider: Exclude<Search, {
107
+ error: string;
108
+ }>["provider"]) => Search): ToolRegistration<TSchema, JsonValue>;