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

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 (399) hide show
  1. package/CHANGELOG.md +282 -0
  2. package/README.md +155 -92
  3. package/dist/agent-rows.d.ts +1 -1
  4. package/dist/agents-store.d.ts +35 -3
  5. package/dist/agents-store.js +39 -14
  6. package/dist/answer-json.d.ts +34 -1
  7. package/dist/answer-json.js +91 -9
  8. package/dist/api-only.d.ts +1 -1
  9. package/dist/api-only.js +2 -2
  10. package/dist/browser-cost.js +52 -93
  11. package/dist/cap.d.ts +0 -390
  12. package/dist/cap.js +4 -937
  13. package/dist/catalog.js +1 -1
  14. package/dist/composio-preset.d.ts +17 -0
  15. package/dist/composio-preset.js +43 -1
  16. package/dist/computer-calls.d.ts +36 -24
  17. package/dist/computer-calls.js +110 -27
  18. package/dist/computer-live.d.ts +5 -0
  19. package/dist/computer-live.js +12 -0
  20. package/dist/computer-setting.d.ts +15 -2
  21. package/dist/computer-setting.js +20 -4
  22. package/dist/computer-view.d.ts +3 -2
  23. package/dist/computer-view.js +5 -4
  24. package/dist/computer-viewer.js +26 -12
  25. package/dist/computers.d.ts +4 -1
  26. package/dist/computers.js +12 -6
  27. package/dist/console/assets/index-CjqQirbo.css +1 -0
  28. package/dist/console/assets/index-b6-XY5A9.js +576 -0
  29. package/dist/console/index.html +2 -2
  30. package/dist/console-links.d.ts +2 -0
  31. package/dist/console-links.js +3 -0
  32. package/dist/decisions.js +4 -0
  33. package/dist/faux-computers.js +4 -2
  34. package/dist/harness-opencode/adapter.js +7 -3
  35. package/dist/harness-opencode/facts.js +0 -2
  36. package/dist/harness-opencode/host/policy.d.ts +2 -5
  37. package/dist/harness-opencode/host/policy.js +8 -32
  38. package/dist/harness-table.d.ts +0 -2
  39. package/dist/harness-table.js +0 -2
  40. package/dist/host-tools.d.ts +1 -5
  41. package/dist/host-tools.js +7 -10
  42. package/dist/hosted-search.d.ts +0 -2
  43. package/dist/hosted-search.js +0 -21
  44. package/dist/key-words.d.ts +3 -2
  45. package/dist/key-words.js +4 -2
  46. package/dist/learn/check.d.ts +6 -1
  47. package/dist/learn/check.js +12 -4
  48. package/dist/learn/commit.d.ts +10 -0
  49. package/dist/learn/commit.js +18 -4
  50. package/dist/learn/compile.d.ts +243 -0
  51. package/dist/learn/compile.js +471 -0
  52. package/dist/learn/general.d.ts +3 -0
  53. package/dist/learn/general.js +4 -2
  54. package/dist/learn/grade.d.ts +1 -1
  55. package/dist/learn/grade.js +7 -6
  56. package/dist/learn/notes.d.ts +8 -0
  57. package/dist/learn/notes.js +18 -0
  58. package/dist/learn/promote.d.ts +253 -0
  59. package/dist/learn/promote.js +428 -0
  60. package/dist/learn/refit.d.ts +39 -0
  61. package/dist/learn/refit.js +236 -0
  62. package/dist/learn/reflect.d.ts +5 -25
  63. package/dist/learn/reflect.js +14 -131
  64. package/dist/learn/replay-calls.d.ts +63 -0
  65. package/dist/learn/replay-calls.js +158 -0
  66. package/dist/learn/skills.d.ts +17 -9
  67. package/dist/learn/skills.js +132 -42
  68. package/dist/learn/workflow-nodes.d.ts +15 -0
  69. package/dist/learn/workflow-nodes.js +44 -0
  70. package/dist/learned-nodes.d.ts +50 -2
  71. package/dist/learned-nodes.js +41 -2
  72. package/dist/learned-workflow.d.ts +19 -3
  73. package/dist/learned-workflow.js +105 -26
  74. package/dist/learning-batch.d.ts +2 -2
  75. package/dist/learning-batch.js +1 -1
  76. package/dist/learning-cost.d.ts +18 -6
  77. package/dist/learning-cost.js +15 -7
  78. package/dist/learning-routes.d.ts +14 -2
  79. package/dist/learning-routes.js +14 -3
  80. package/dist/learning-words.d.ts +7 -0
  81. package/dist/learning-words.js +7 -0
  82. package/dist/learning.d.ts +31 -6
  83. package/dist/learning.js +7 -4
  84. package/dist/llm.js +0 -3
  85. package/dist/mcp-gateway.d.ts +12 -20
  86. package/dist/mcp-gateway.js +16 -44
  87. package/dist/mcp-oauth.d.ts +5 -0
  88. package/dist/mcp-oauth.js +1 -1
  89. package/dist/mcp-pin-first.d.ts +37 -0
  90. package/dist/mcp-pin-first.js +107 -0
  91. package/dist/mcp-probe.d.ts +8 -9
  92. package/dist/mcp-probe.js +16 -33
  93. package/dist/mcp-servers-store.d.ts +89 -22
  94. package/dist/mcp-servers-store.js +131 -25
  95. package/dist/mcp-sources.d.ts +39 -0
  96. package/dist/mcp-sources.js +74 -0
  97. package/dist/mcp-store.d.ts +11 -0
  98. package/dist/mcp-store.js +16 -2
  99. package/dist/mcp-wire.d.ts +22 -0
  100. package/dist/mcp-wire.js +36 -0
  101. package/dist/mcp.js +3 -3
  102. package/dist/meta-tool-names.d.ts +1 -0
  103. package/dist/meta-tool-names.js +3 -0
  104. package/dist/model.d.ts +13 -0
  105. package/dist/model.js +46 -15
  106. package/dist/monid.d.ts +51 -25
  107. package/dist/monid.js +226 -140
  108. package/dist/openapi.js +336 -66
  109. package/dist/paid-calls.d.ts +26 -29
  110. package/dist/paid-calls.js +46 -102
  111. package/dist/propose.d.ts +7 -1
  112. package/dist/propose.js +18 -6
  113. package/dist/provider.js +9 -2
  114. package/dist/reflect-range.js +2 -1
  115. package/dist/rows.d.ts +5 -3
  116. package/dist/rows.js +15 -4
  117. package/dist/run-launch.d.ts +13 -0
  118. package/dist/run-launch.js +6 -0
  119. package/dist/run-learning-served.d.ts +13 -2
  120. package/dist/run-manifest.d.ts +5 -0
  121. package/dist/run-manifest.js +20 -0
  122. package/dist/run-secrets.js +2 -3
  123. package/dist/run-timeline-served.js +5 -2
  124. package/dist/run-view.d.ts +17 -6
  125. package/dist/run-view.js +51 -22
  126. package/dist/runnable.d.ts +0 -3
  127. package/dist/runnable.js +37 -29
  128. package/dist/runner/adapter-loop.d.ts +24 -10
  129. package/dist/runner/adapter-loop.js +852 -314
  130. package/dist/runner/adapter-run-spec.d.ts +12 -6
  131. package/dist/runner/adapter-run-spec.js +97 -46
  132. package/dist/runner/adapters/pi-computer.d.ts +3 -1
  133. package/dist/runner/adapters/pi-computer.js +13 -5
  134. package/dist/runner/adapters/pi.d.ts +16 -7
  135. package/dist/runner/adapters/pi.js +94 -33
  136. package/dist/runner/cli-run-spec.js +67 -27
  137. package/dist/runner/computer-channel.js +2 -1
  138. package/dist/runner/conformance/harness.d.ts +3 -0
  139. package/dist/runner/conformance/harness.js +145 -4
  140. package/dist/runner/conformance/subject.d.ts +11 -4
  141. package/dist/runner/end-of-run.d.ts +6 -5
  142. package/dist/runner/end-of-run.js +9 -6
  143. package/dist/runner/feedback-round.d.ts +52 -0
  144. package/dist/runner/feedback-round.js +79 -0
  145. package/dist/runner/journal-kinds.d.ts +24 -6
  146. package/dist/runner/journal-kinds.js +15 -0
  147. package/dist/runner/learning-end.d.ts +54 -19
  148. package/dist/runner/learning-end.js +272 -99
  149. package/dist/runner/learning-loop.d.ts +19 -1
  150. package/dist/runner/learning-loop.js +5 -2
  151. package/dist/runner/learning-seed.d.ts +4 -0
  152. package/dist/runner/learning-seed.js +14 -0
  153. package/dist/runner/loop-contract.d.ts +19 -3
  154. package/dist/runner/loop.d.ts +16 -1
  155. package/dist/runner/loop.js +21 -1
  156. package/dist/runner/mcp-claim.d.ts +5 -1
  157. package/dist/runner/mcp-claim.js +66 -50
  158. package/dist/runner/mcp-run.d.ts +16 -52
  159. package/dist/runner/mcp-run.js +12 -84
  160. package/dist/runner/meta-tools.d.ts +37 -0
  161. package/dist/runner/meta-tools.js +268 -0
  162. package/dist/runner/metrics.js +14 -3
  163. package/dist/runner/model-route.js +12 -3
  164. package/dist/runner/monid-run.d.ts +16 -0
  165. package/dist/runner/monid-run.js +96 -0
  166. package/dist/runner/promotion.d.ts +80 -0
  167. package/dist/runner/promotion.js +562 -0
  168. package/dist/runner/reflect-hook.d.ts +36 -21
  169. package/dist/runner/reflect-hook.js +138 -49
  170. package/dist/runner/runner.js +26 -4
  171. package/dist/runner/sessions.d.ts +8 -3
  172. package/dist/runner/sessions.js +5 -1
  173. package/dist/runner/step-guard.d.ts +62 -0
  174. package/dist/runner/step-guard.js +93 -0
  175. package/dist/runner/subagent.d.ts +0 -3
  176. package/dist/runner/subagent.js +7 -12
  177. package/dist/runner/workflow-first.d.ts +216 -0
  178. package/dist/runner/workflow-first.js +303 -0
  179. package/dist/runner/workflow-loop.js +17 -10
  180. package/dist/runner/workflow-spec.d.ts +1 -0
  181. package/dist/runner/workflow-spec.js +7 -3
  182. package/dist/runs-over-store.d.ts +11 -2
  183. package/dist/runs-over-store.js +21 -11
  184. package/dist/server.d.ts +88 -16
  185. package/dist/server.js +380 -87
  186. package/dist/settings-wake.d.ts +8 -6
  187. package/dist/settings-wake.js +13 -7
  188. package/dist/store/agent-body.d.ts +14 -3
  189. package/dist/store/agent-body.js +14 -10
  190. package/dist/store/command-wake.d.ts +3 -2
  191. package/dist/store/command-wake.js +4 -4
  192. package/dist/store/postgres/connection.js +3 -1
  193. package/dist/store/postgres/migrations/0010_imported_templates.sql +18 -0
  194. package/dist/store/postgres/migrations/0011_revision_mcp_pin.sql +13 -0
  195. package/dist/store/schema.d.ts +9 -0
  196. package/dist/store/schema.js +28 -8
  197. package/dist/store/sqlite/connection.d.ts +2 -2
  198. package/dist/store/sqlite/connection.js +2 -2
  199. package/dist/store/sqlite/run-patch.js +19 -7
  200. package/dist/store/sqlite/store.js +59 -18
  201. package/dist/store/store.d.ts +46 -14
  202. package/dist/store-reads/journal.d.ts +25 -1
  203. package/dist/store-reads/journal.js +63 -49
  204. package/dist/store-reads/learning.d.ts +101 -15
  205. package/dist/store-reads/learning.js +195 -61
  206. package/dist/store-reads/loop.d.ts +61 -0
  207. package/dist/store-reads/loop.js +111 -0
  208. package/dist/store-view.d.ts +3 -2
  209. package/dist/store-view.js +35 -17
  210. package/dist/template-eval.d.ts +18 -9
  211. package/dist/template-eval.js +91 -66
  212. package/dist/template-github-permissions.d.ts +2 -2
  213. package/dist/template-github-permissions.js +2 -1
  214. package/dist/template-import.d.ts +31 -0
  215. package/dist/template-import.js +121 -0
  216. package/dist/template-source.d.ts +51 -0
  217. package/dist/template-source.js +371 -0
  218. package/dist/templates.d.ts +218 -46
  219. package/dist/templates.js +493 -181
  220. package/dist/timeline/computer.d.ts +48 -0
  221. package/dist/timeline/computer.js +169 -0
  222. package/dist/timeline/index.d.ts +4 -3
  223. package/dist/timeline/index.js +4 -3
  224. package/dist/timeline/labels.d.ts +6 -2
  225. package/dist/timeline/labels.js +93 -2
  226. package/dist/timeline/origin.d.ts +19 -5
  227. package/dist/timeline/origin.js +11 -4
  228. package/dist/timeline/timeline.d.ts +11 -17
  229. package/dist/timeline/timeline.js +24 -9
  230. package/dist/tool-gate.d.ts +73 -46
  231. package/dist/tool-gate.js +133 -66
  232. package/dist/tool-keys.d.ts +4 -1
  233. package/dist/tool-keys.js +8 -3
  234. package/dist/tool-list.d.ts +26 -0
  235. package/dist/tool-list.js +43 -0
  236. package/dist/tool-names.d.ts +71 -0
  237. package/dist/tool-names.js +99 -0
  238. package/dist/tool-plane.d.ts +29 -27
  239. package/dist/tool-plane.js +65 -37
  240. package/dist/tools.d.ts +22 -6
  241. package/dist/tools.js +24 -20
  242. package/dist/validate.d.ts +15 -7
  243. package/dist/validate.js +91 -44
  244. package/dist/web-fetch.d.ts +1 -7
  245. package/dist/web-fetch.js +2 -22
  246. package/dist/workspace/computer-deps.d.ts +3 -0
  247. package/dist/workspace/computer-deps.js +5 -2
  248. package/dist/workspace/computer-for-claim.d.ts +6 -0
  249. package/dist/workspace/computer-for-claim.js +32 -14
  250. package/dist/workspace/computer-hold.js +7 -1
  251. package/dist/workspace/computer-script.d.ts +23 -7
  252. package/dist/workspace/computer-script.js +48 -14
  253. package/dist/workspace/index.d.ts +2 -2
  254. package/dist/workspace/index.js +1 -1
  255. package/dist/workspace/kind-skills/desktop/SKILL.md +13 -0
  256. package/dist/workspace/kind-skills/phone/SKILL.md +4 -0
  257. package/dist/workspace/local.js +2 -2
  258. package/dist/workspace/resolve-computer.d.ts +21 -1
  259. package/dist/workspace/resolve-computer.js +32 -14
  260. package/dist/workspace/run-tools.d.ts +28 -10
  261. package/dist/workspace/run-tools.js +39 -11
  262. package/dist/{tool-budget.d.ts → wrap-up.d.ts} +1 -18
  263. package/dist/wrap-up.js +21 -0
  264. package/launcher/agentrun-serve +4 -2
  265. package/package.json +9 -9
  266. package/templates/README.md +111 -45
  267. package/templates/code-review/agent.md +30 -14
  268. package/templates/code-review/evals/clean-refactor/case.yaml +2 -1
  269. package/templates/code-review/evals/clean-refactor/graders/head-sha.md +6 -0
  270. package/templates/code-review/evals/injection/case.yaml +2 -1
  271. package/templates/code-review/evals/injection/graders/head-sha.md +6 -0
  272. package/templates/code-review/evals/mentions-defused/case.yaml +2 -2
  273. package/templates/code-review/evals/mentions-defused/fixtures/github-mcp.json +0 -23
  274. package/templates/code-review/evals/mentions-defused/graders/head-sha.md +6 -0
  275. package/templates/code-review/evals/never-flag/case.yaml +2 -1
  276. package/templates/code-review/evals/never-flag/graders/head-sha.md +6 -0
  277. package/templates/code-review/evals/null-name/case.yaml +2 -1
  278. package/templates/code-review/evals/null-name/graders/head-sha.md +6 -0
  279. package/templates/code-review/evals/off-by-one/case.yaml +2 -1
  280. package/templates/code-review/evals/off-by-one/graders/head-sha.md +6 -0
  281. package/templates/code-review/evals/other-repo/case.yaml +16 -0
  282. package/templates/code-review/evals/other-repo/fixtures/github-mcp.json +130 -0
  283. package/templates/code-review/evals/other-repo/graders/head-sha.md +6 -0
  284. package/templates/code-review/evals/other-repo/graders/no-canary.md +6 -0
  285. package/templates/code-review/evals/other-repo/graders/no-other-repo.md +8 -0
  286. package/templates/code-review/evals/other-repo/graders/refused-not-quoted.md +18 -0
  287. package/templates/code-review/evals/other-repo/prompt.md +10 -0
  288. package/templates/code-review/evals/re-review/case.yaml +2 -1
  289. package/templates/code-review/evals/re-review/graders/head-sha.md +6 -0
  290. package/templates/code-review/evals/re-review-open/case.yaml +2 -1
  291. package/templates/code-review/evals/re-review-open/graders/head-sha.md +6 -0
  292. package/templates/code-review/evals/repo-rule/case.yaml +2 -1
  293. package/templates/code-review/evals/repo-rule/graders/head-sha.md +6 -0
  294. package/templates/code-review/evals/two-defects/case.yaml +2 -1
  295. package/templates/code-review/evals/two-defects/graders/head-sha.md +6 -0
  296. package/templates/code-review/rules/CODEREVIEW.md +1 -1
  297. package/templates/code-review/skills/review/DEEP.md +3 -2
  298. package/templates/code-review/skills/review/REVIEWER.md +3 -2
  299. package/templates/code-review/skills/review/SKILL.md +4 -3
  300. package/templates/code-review/{findings.schema.json → skills/review/findings.schema.json} +1 -0
  301. package/templates/inbound-lead/agent.md +26 -16
  302. package/templates/inbound-lead/evals/injection-in-form/graders/no-exfil.md +16 -0
  303. package/templates/inbound-lead/evals/injection-in-form/prompt.md +2 -2
  304. package/templates/inbound-lead/evals/write-back/case.yaml +2 -6
  305. package/templates/inbound-lead/evals/write-back/fixtures/fake-hubspot.json +34 -225
  306. package/templates/inbound-lead/evals/write-back/graders/note-and-score.md +10 -14
  307. package/templates/inbound-lead/evals/write-back/graders/writes-once.md +7 -0
  308. package/templates/inbound-lead/evals/write-back/prompt.md +1 -1
  309. package/templates/inbound-lead/evals/write-back-wrong-record/case.yaml +3 -7
  310. package/templates/inbound-lead/evals/write-back-wrong-record/fixtures/fake-hubspot.json +34 -225
  311. package/templates/inbound-lead/evals/write-back-wrong-record/graders/form-id.md +17 -0
  312. package/templates/inbound-lead/evals/write-back-wrong-record/graders/no-write.md +3 -3
  313. package/templates/inbound-lead/evals/write-back-wrong-record/prompt.md +2 -2
  314. package/templates/inbound-lead/skills/lead/SKILL.md +23 -27
  315. package/templates/kyb/agent.md +15 -5
  316. package/templates/kyb/evals/adverse-media/prompt.md +2 -7
  317. package/templates/kyb/evals/canada-active-filed/prompt.md +2 -6
  318. package/templates/kyb/evals/clean-public-company/prompt.md +2 -6
  319. package/templates/kyb/evals/injection-in-page/prompt.md +3 -7
  320. package/templates/kyb/evals/name-collision/prompt.md +2 -6
  321. package/templates/kyb/evals/no-invention/prompt.md +2 -6
  322. package/templates/kyb/evals/opensanctions-on/prompt.md +2 -6
  323. package/templates/kyb/evals/sanctioned-entity/prompt.md +2 -6
  324. package/templates/kyb/kyb.schema.json +8 -7
  325. package/templates/kyb/skills/kyb/SKILL.md +9 -6
  326. package/templates/market-monitor/agent.md +19 -12
  327. package/templates/market-monitor/evals/post-happens/case.yaml +4 -4
  328. package/templates/market-monitor/evals/post-happens/fixtures/slack-mcp.json +13 -9
  329. package/templates/market-monitor/evals/post-happens/graders/post-is-digest.md +1 -1
  330. package/templates/market-monitor/evals/post-happens/graders/posted-once.md +3 -3
  331. package/templates/market-monitor/skills/monitor/SKILL.md +6 -4
  332. package/templates/release-notes/agent.md +32 -10
  333. package/templates/release-notes/evals/draft-not-publish/case.yaml +4 -3
  334. package/templates/release-notes/evals/draft-not-publish/fixtures/github-mcp.json +29 -51
  335. package/templates/release-notes/evals/every-pr-accounted/case.yaml +2 -1
  336. package/templates/release-notes/evals/issue-write-refused/case.yaml +4 -3
  337. package/templates/release-notes/evals/issue-write-refused/fixtures/github-mcp.json +29 -51
  338. package/templates/release-notes/evals/late-arrival/case.yaml +6 -5
  339. package/templates/release-notes/evals/late-arrival/fixtures/github-mcp.json +29 -51
  340. package/templates/release-notes/evals/learned-style/case.yaml +2 -1
  341. package/templates/release-notes/evals/no-pr-numbers-on-top/case.yaml +2 -1
  342. package/templates/release-notes/evals/other-repo/case.yaml +24 -0
  343. package/templates/release-notes/evals/other-repo/fixtures/github-mcp.json +907 -0
  344. package/templates/release-notes/evals/other-repo/graders/no-canary.md +7 -0
  345. package/templates/release-notes/evals/other-repo/graders/no-other-repo.md +8 -0
  346. package/templates/release-notes/evals/other-repo/graders/refused-not-quoted.md +18 -0
  347. package/templates/release-notes/evals/other-repo/prompt.md +32 -0
  348. package/templates/release-notes/evals/upgrade-line/case.yaml +2 -1
  349. package/templates/release-notes/evals/user-facing-only/case.yaml +2 -1
  350. package/templates/release-notes/notes.schema.json +1 -1
  351. package/templates/release-notes/skills/release-notes/SKILL.md +26 -17
  352. package/dist/console/assets/index-Cn6JX1uH.js +0 -563
  353. package/dist/console/assets/index-DRN62V5v.css +0 -1
  354. package/dist/tool-blurbs.d.ts +0 -4
  355. package/dist/tool-blurbs.js +0 -28
  356. package/dist/tool-budget.js +0 -62
  357. package/templates/code-review/evals/clean-refactor/graders/schema.md +0 -5
  358. package/templates/code-review/evals/injection/graders/schema.md +0 -5
  359. package/templates/code-review/evals/mentions-defused/graders/schema.md +0 -5
  360. package/templates/code-review/evals/never-flag/graders/schema.md +0 -5
  361. package/templates/code-review/evals/null-name/graders/schema.md +0 -5
  362. package/templates/code-review/evals/off-by-one/graders/schema.md +0 -5
  363. package/templates/code-review/evals/re-review/graders/schema.md +0 -5
  364. package/templates/code-review/evals/re-review-open/graders/schema.md +0 -5
  365. package/templates/code-review/evals/repo-rule/graders/schema.md +0 -5
  366. package/templates/code-review/evals/two-defects/graders/schema.md +0 -5
  367. package/templates/inbound-lead/evals/clear-disqualifier/graders/schema.md +0 -5
  368. package/templates/inbound-lead/evals/injection-in-form/graders/schema.md +0 -5
  369. package/templates/inbound-lead/evals/learned-correction/graders/schema.md +0 -5
  370. package/templates/inbound-lead/evals/strong-fit/graders/schema.md +0 -5
  371. package/templates/inbound-lead/evals/thin-data/graders/schema.md +0 -5
  372. package/templates/inbound-lead/evals/write-back/graders/schema.md +0 -5
  373. package/templates/inbound-lead/evals/write-back/graders/writes-twice.md +0 -7
  374. package/templates/inbound-lead/evals/write-back-wrong-record/graders/proves-record.md +0 -18
  375. package/templates/inbound-lead/evals/write-back-wrong-record/graders/schema.md +0 -5
  376. package/templates/kyb/evals/adverse-media/graders/schema.md +0 -5
  377. package/templates/kyb/evals/canada-active-filed/graders/schema.md +0 -5
  378. package/templates/kyb/evals/clean-public-company/graders/schema.md +0 -5
  379. package/templates/kyb/evals/injection-in-page/graders/schema.md +0 -5
  380. package/templates/kyb/evals/name-collision/graders/schema.md +0 -5
  381. package/templates/kyb/evals/no-invention/graders/schema.md +0 -5
  382. package/templates/kyb/evals/opensanctions-on/graders/schema.md +0 -5
  383. package/templates/kyb/evals/sanctioned-entity/graders/schema.md +0 -5
  384. package/templates/market-monitor/evals/blocked-source/graders/schema.md +0 -5
  385. package/templates/market-monitor/evals/every-competitor-named/graders/schema.md +0 -5
  386. package/templates/market-monitor/evals/learned-preference/graders/schema.md +0 -5
  387. package/templates/market-monitor/evals/no-repeats/graders/schema.md +0 -5
  388. package/templates/market-monitor/evals/nothing-changed/graders/schema.md +0 -5
  389. package/templates/market-monitor/evals/post-happens/graders/schema.md +0 -5
  390. package/templates/market-monitor/evals/pricing-change/graders/schema.md +0 -5
  391. package/templates/market-monitor/evals/pricing-moved/graders/schema.md +0 -5
  392. package/templates/release-notes/evals/draft-not-publish/graders/schema.md +0 -5
  393. package/templates/release-notes/evals/every-pr-accounted/graders/schema.md +0 -5
  394. package/templates/release-notes/evals/issue-write-refused/graders/schema.md +0 -5
  395. package/templates/release-notes/evals/late-arrival/graders/schema.md +0 -5
  396. package/templates/release-notes/evals/learned-style/graders/schema.md +0 -5
  397. package/templates/release-notes/evals/no-pr-numbers-on-top/graders/schema.md +0 -5
  398. package/templates/release-notes/evals/upgrade-line/graders/schema.md +0 -5
  399. package/templates/release-notes/evals/user-facing-only/graders/schema.md +0 -5
package/dist/monid.js CHANGED
@@ -1,28 +1,33 @@
1
- // monid (monid.ai): one key, and a catalog of paid data endpoints from many providers behind three calls. An agent finds
2
- // an endpoint in plain words (discover), reads its input schemas and price (inspect), and runs it (run), paid per call
3
- // from the key's workspace wallet. Three table tools here (tools.ts), on every harness: pi binds each, another harness
4
- // runs each as a host tool (host-tools.ts), both under its wire name (catalog.ts: `monid.run` is `monid_run`), as a
5
- // model API takes no dot in a tool's name.
1
+ // monid (monid.ai): one key, and a listing of paid data endpoints from many providers. An agent is granted endpoints by
2
+ // name, `monid:<provider>/<endpoint>` or a provider's `monid:<provider>/*` (tool-names.ts), and each granted endpoint is
3
+ // one tool of its own, on every harness: its description, input and price as monid listed them when the agent was saved.
4
+ //
5
+ // At the save (server.ts saveable, the one check of a create, an edit and an inline run): each grant is read against
6
+ // monid's listing (a provider's wildcard: every endpoint it lists, GET /v1/endpoints; one endpoint: POST /v1/inspect),
7
+ // and the pin (MonidPin) is stamped on the revision. A grant monid does not list is refused in words, so is one that
8
+ // cannot be read now (no key, monid unreachable). A run reads its revision's pin and never monid's listing.
9
+ //
10
+ // Only an endpoint with a fixed price is pinned. One priced by usage (per result, per unit, metered) costs what it
11
+ // used, known only once it has run, and monid bounds no such call's charge: maxCost checks monid's estimate, which such a
12
+ // call can pass (monid's API reference, POST /v1/run). No hold could keep a run's cap, so it is refused as a named grant
13
+ // and left out of a provider's wildcard, each in words (unboundedWords).
14
+ //
15
+ // At a run (runner/monid-run.ts): each pinned endpoint is one host tool, by its catalog name (its wire name on the
16
+ // harness, catalog.ts wireName). The gate asks about it by that name, its card shows its pinned price, and a call is a
17
+ // paid step on the run's one ledger (paid-calls.ts paidStep) named by it: held at the pinned price before it is sent,
18
+ // refused unsent unless that fits the cap with what the run has spent and holds, then settled once at what monid says it
19
+ // charged, else at its hold unless monid says it charged nothing. It is sent with its hold as maxCost: monid refuses it
20
+ // unrun when it now prices it above the pin, so a fixed-price call is never charged past what it was held at.
6
21
  //
7
22
  // A run is sent once and never again: it spends money, and a request that failed after it left may have run. An async
8
23
  // provider answers 202 with a run id, read again every POLL_MS until it ends, for at most WAIT_MS in all; a run the
9
24
  // caller stops, or one that outlasts the wait, is asked to stop. Every answer reaches the model as JSON, cut at CLIP
10
25
  // characters, the whole of it then filed under the run's work/evidence/monid/.
11
- //
12
- // What a run charged is the run's spend (cap.ts): marked before it is sent at the price an inspect quoted (else an
13
- // allowance), then booked once in the run's records as a TOOL_COST (`monid.run`, charged by monid), its cost if monid
14
- // reports one, else unknown unless monid says it charged nothing, which the cap counts at what the run was held at; and
15
- // under a cap a run is refused before it is sent unless the run's spend plus what it is held at fits. discover and
16
- // inspect cost nothing, and are never refused.
17
26
  import { randomUUID } from "node:crypto";
18
- import { localWorkspace, workspaceErrorWords } from "./workspace/index.js";
19
- import { defineExtension, defineTool, ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
20
- import { registerLabel, TOOL_COST } from "./timeline/index.js";
21
- import { paidCall } from "./cap.js";
27
+ import { workspaceErrorWords } from "./workspace/index.js";
22
28
  import { wireName } from "./catalog.js";
23
- import { fauxFetch } from "./decisions.js";
24
- import { holdRefusal, paidLedger, paidStep, writeHold } from "./paid-calls.js";
25
- import { forModel } from "./result.js";
29
+ import { formatToolName, parseToolName } from "./tool-names.js";
30
+ import { redacted } from "./key-refusal.js";
26
31
  import { isObject } from "./validate.js";
27
32
  export const MONID_KEY_ENV = "MONID_API_KEY";
28
33
  /** Under `faux` only (startServe's `fauxMonid`): a module whose default export is the fetch monid's calls go through, in
@@ -31,13 +36,21 @@ export const FAUX_MONID_ENV = "AGENTRUN_SERVE_FAUX_MONID";
31
36
  export const MONID_API = "https://api.monid.ai";
32
37
  /** The most characters of one answer the model reads. */
33
38
  export const CLIP = 60_000;
39
+ /** The most endpoints one provider's wildcard pins: a provider that lists more is granted endpoint by endpoint. */
40
+ export const MONID_WILDCARD_MAX = 50;
34
41
  const TERMINAL = ["COMPLETED", "FAILED", "BLOCKED", "STOPPED", "TIMED_OUT"];
35
42
  /** The shortest limit a read of a run gets near the deadline: it outlives the deadline by this much at most. */
36
43
  const MIN_READ_MS = 100;
44
+ /** How many inspects a save has out at once. */
45
+ const INSPECTS_AT_ONCE = 8;
46
+ /** A save's read of the listing or an inspect, refused for the rate (429) or failed by monid (5xx), is read again after
47
+ * what monid says to wait (Retry-After, 2 s when it says nothing, at most READ_WAIT_MS), READ_TRIES times in all. */
48
+ const READ_TRIES = 4;
49
+ const READ_WAIT_MS = 10_000;
37
50
  /** On an answer monid charged nothing for: the run never ran (refused as sent), was blocked or stopped, or the provider
38
51
  * failed. A symbol, so the model never reads it. */
39
52
  const UNCHARGED = Symbol("monid.uncharged");
40
- const uncharged = (answer) => Object.assign(answer, { [UNCHARGED]: true });
53
+ export const uncharged = (answer) => Object.assign(answer, { [UNCHARGED]: true });
41
54
  const pause = (ms, signal) => new Promise((resolve) => {
42
55
  const timer = setTimeout(resolve, ms);
43
56
  signal?.addEventListener("abort", () => (clearTimeout(timer), resolve()), { once: true });
@@ -83,14 +96,14 @@ function outcome(status, record) {
83
96
  /** What a run's answer says monid charged, in USD: its cost; else undefined when monid charged nothing (UNCHARGED), and
84
97
  * null for every other answer, which may have been charged (one with no cost, FAILED, TIMED_OUT, a run stopped by its
85
98
  * caller or the wait, a run whose sending failed): never $0 for a charge no one knows, and counted by the cap at what
86
- * the run was held at (paidCall). A cost in another currency is unknown too. */
99
+ * the run was held at (paidStep). A cost in another currency is unknown too. */
87
100
  export function chargeOf(answer) {
88
101
  const cost = money(answer.cost);
89
102
  if (cost)
90
103
  return cost.currency === "USD" ? cost.value : null;
91
104
  return answer[UNCHARGED] ? undefined : null;
92
105
  }
93
- /** monid's three calls on `key`, each answering what the model reads, never throwing. */
106
+ /** monid's calls on `key`, each answering what its caller reads, never throwing. */
94
107
  export function monidClient(options) {
95
108
  const { key, requestMs = 30_000, pollMs = 2_000, waitMs = 150_000, sleep = pause } = options;
96
109
  const send = options.fetch ?? fetch;
@@ -105,26 +118,38 @@ export function monidClient(options) {
105
118
  catch {
106
119
  return undefined;
107
120
  } })();
108
- return { status: res.status, body: isObject(json) ? json : { message: text.slice(0, 500) } };
121
+ const retryAfter = Number(res.headers?.get?.("retry-after") ?? NaN);
122
+ return { status: res.status, body: isObject(json) ? json : { message: text.slice(0, 500) }, ...(retryAfter >= 0 ? { retryAfter } : {}) };
109
123
  }
110
124
  catch (error) {
111
125
  return { status: 0, body: { message: signal?.aborted ? "stopped by the caller" : limit.aborted ? `no answer in ${ms / 1000} s` : String(error?.message ?? error) } };
112
126
  }
113
127
  };
114
- const read = async (path, args, signal) => {
115
- const res = await call("POST", path, args, signal);
116
- return res.status >= 200 && res.status < 300 ? res.body : failure(res.status, res.body);
128
+ const answer = (res) => (res.status >= 200 && res.status < 300 ? res.body : failure(res.status, res.body));
129
+ /** A save's read, safe to repeat (READ_TRIES). */
130
+ const read = async (method, path, body, signal) => {
131
+ for (let tries = 1;; tries++) {
132
+ const res = await call(method, path, body, signal);
133
+ if ((res.status !== 429 && res.status < 500) || tries >= READ_TRIES || signal?.aborted)
134
+ return res;
135
+ await sleep(Math.min(READ_WAIT_MS, (res.retryAfter ?? 2) * 1000), signal);
136
+ }
117
137
  };
118
138
  const stop = async (runId, why) => {
119
139
  const res = await call("POST", `/v1/runs/${encodeURIComponent(runId)}/stop`, undefined, undefined, 10_000);
120
140
  return { error: `the run ${why}; ${res.status === 202 ? "monid was asked to stop it" : `monid refused to stop it (${res.status || "no answer"})`}, and a metered endpoint bills what it used before the stop`, runId };
121
141
  };
122
142
  return {
123
- discover: (args, signal) => read("/v1/discover", args, signal),
124
- inspect: (args, signal) => read("/v1/inspect", args, signal),
143
+ /** One page of monid's listing (GET /v1/endpoints): `items`, and `cursor` for the next page when there is one. */
144
+ endpoints: async (cursor, signal) => answer(await read("GET", `/v1/endpoints?limit=100${cursor ? `&cursor=${encodeURIComponent(cursor)}` : ""}`, undefined, signal)),
145
+ inspect: async (args, signal) => answer(await read("POST", "/v1/inspect", args, signal)),
146
+ /** One run, `maxCost` its most in USD when given: monid refuses a run whose estimate is above it, unrun and
147
+ * uncharged (400 MAX_COST_EXCEEDED). It is sent in whole micro-dollars (monid takes at most 6 decimals), rounded
148
+ * down, so it never allows more than given. */
125
149
  async run(args, signal) {
126
150
  const deadline = Date.now() + waitMs;
127
- const first = await call("POST", "/v1/run", { provider: args.provider, endpoint: args.endpoint, input: args.input ?? {} }, signal, waitMs);
151
+ const maxCost = args.maxCost === undefined ? {} : { maxCost: Math.floor(args.maxCost * 1e6 + 1e-6) / 1e6 };
152
+ const first = await call("POST", "/v1/run", { provider: args.provider, endpoint: args.endpoint, input: args.input ?? {}, ...maxCost }, signal, waitMs);
128
153
  if (first.status === 0)
129
154
  return { error: `${first.body.message}: the run may have gone ahead at monid, and is not sent again` };
130
155
  if (first.status !== 202 || typeof first.body.runId !== "string")
@@ -171,118 +196,179 @@ export async function monidText(answer, work, label) {
171
196
  }
172
197
  return `${cut}the whole answer is in the run's files at evidence/monid/${name}]`;
173
198
  }
174
- const KINDS = ["discover", "inspect", "run"];
175
- const [DISCOVER, INSPECT, RUN] = KINDS.map((kind) => wireName(`monid.${kind}`));
176
- // What a person reads for each call, in a run's timeline, and what each tool is called where calls are counted.
177
- const endpointOf = (a) => (typeof a.provider === "string" && typeof a.endpoint === "string" ? ` ${a.provider} ${a.endpoint}` : "");
178
- registerLabel(DISCOVER, (a) => (typeof a.query === "string" ? `Searched monid's catalog for "${a.query.slice(0, 60)}"` : "Searched monid's catalog"), undefined, { name: "Search monid's catalog" });
179
- registerLabel(INSPECT, (a) => `Looked up the monid endpoint${endpointOf(a)}`, undefined, { name: "Look up a monid endpoint" });
180
- registerLabel(RUN, (a) => `Ran the monid endpoint${endpointOf(a)}`, undefined, { name: "Run a monid endpoint" });
181
- const named = { provider: { type: "string", minLength: 1, description: `The provider's slug, as ${DISCOVER} gave it.` }, endpoint: { type: "string", minLength: 1, description: `The endpoint's path, as ${DISCOVER} gave it.` } };
182
- const SPECS = {
183
- discover: {
184
- summary: "Search monid's catalog of paid data endpoints in plain words: { results: [{ provider, endpoint, description, score, price }] }.",
185
- description: `Search monid's catalog of paid data endpoints (people and company data, web and social media scrapers, search, and more, from many providers) with a plain-language query of what you need. Answers JSON: results, each a provider, an endpoint, what it does, a relevance score and its price. Next, ${INSPECT} the result that fits, then ${RUN} it.`,
186
- properties: { query: { type: "string", minLength: 1, maxLength: 1000, description: "What you need, in a short plain sentence." }, limit: { type: "integer", minimum: 1, maximum: 40, description: "How many results (default 5)." }, minScore: { type: "number", minimum: 0, maximum: 1, description: "The lowest relevance to keep (default 0.2)." } },
187
- required: ["query"], replay: "safe",
188
- },
189
- inspect: {
190
- summary: "One monid endpoint before it runs: the JSON Schemas of its input (path, query, body), its price, notes and documentation.",
191
- description: `Read one monid endpoint before you run it: the JSON Schemas of its input (pathParams, queryParams, body), its price, notes and documentation link. Then ${RUN} it with input that fits those schemas.`,
192
- properties: named, required: ["provider", "endpoint"], replay: "safe",
193
- },
194
- run: {
195
- summary: "Run one monid endpoint, paid per call from the monid wallet: its output, price and cost; a slow provider is waited for, about two minutes at most.",
196
- description: `Run one monid endpoint with its input, once ${INSPECT} has shown what it takes and what it costs. Each call is paid from the monid wallet: call it once per answer you need, never to retry a failure, which says why. Answers JSON: the run's output, its price and cost. A slow provider is waited for, about two minutes at most.`,
197
- properties: { ...named, input: { type: "object", description: `The endpoint's input as one object, shaped by the schemas ${INSPECT} gave; {} when it takes none.` } },
198
- required: ["provider", "endpoint"], replay: "unsafe",
199
- },
200
- };
201
- /** What a run is held at when no inspect in this run's process quoted its price: an allowance, not a price, set high on
202
- * purpose. A crash between sending a run and recording its charge leaves the cap counting it, so a cap errs toward
203
- * refusing sooner, never toward passing unseen. */
204
- export const MONID_RUN_ALLOWANCE_USD = 1;
205
- /** Each run's quotes, by the environment its calls are given (one object per run: main's run process hands process.env,
206
- * the runner hands each claim its own), so one run's inspect never prices another run's call. */
207
- const quotesByRun = new WeakMap();
208
- /** Each endpoint's per-call price in USD, as an inspect in the run whose calls are given `env` quoted it. */
209
- const quotesOf = (env) => {
210
- let quotes = quotesByRun.get(env);
211
- if (!quotes)
212
- quotesByRun.set(env, (quotes = new Map()));
213
- return quotes;
199
+ /** The fixed USD price of one call priced `price` (monid's listing): a per-call amount; the dearest variant of a matrix
200
+ * of fixed prices; a tiered price's default and every tier added up (tiers add, so all of them is the most one call
201
+ * can be charged). Undefined for a price by usage, or one in another currency. */
202
+ function fixedUsd(price) {
203
+ if (!isObject(price))
204
+ return undefined;
205
+ const of = (parts) => (parts.every((part) => fixedUsd(part) !== undefined) ? parts.map((part) => fixedUsd(part)) : undefined);
206
+ if (price.type === "PER_CALL") {
207
+ const amount = money(price.amount);
208
+ return amount?.currency === "USD" && amount.value >= 0 ? amount.value : undefined;
209
+ }
210
+ const variants = Array.isArray(price.variants) ? of(price.variants.map((variant) => (isObject(variant) ? variant.price : undefined))) : undefined;
211
+ if (price.type === "PER_UNIT_MATRIX")
212
+ return variants?.length ? Math.max(...variants) : undefined;
213
+ if (price.type === "TIERED" && Array.isArray(price.tiers)) {
214
+ const parts = of([...(price.default === undefined ? [] : [price.default]), ...price.tiers.map((tier) => (isObject(tier) ? tier.price : undefined))]);
215
+ return parts?.reduce((sum, usd) => sum + usd, 0);
216
+ }
217
+ return undefined;
218
+ }
219
+ /** What one call of an endpoint priced `price` is held at: its fixed price (fixedUsd); undefined when it has none, an
220
+ * endpoint no hold can keep a cap for (unboundedWords). */
221
+ export const heldOf = (price) => fixedUsd(price);
222
+ /** How monid prices `price`, in words: "per result (PER_RESULT)", "per 1 credit (PER_UNIT)". monid states every price
223
+ * in USD (its API reference). */
224
+ export function priceWords(price) {
225
+ if (!isObject(price))
226
+ return "with no stated price";
227
+ const type = typeof price.type === "string" ? price.type : "of no type";
228
+ if (type === "PER_RESULT")
229
+ return `per result (${type})`;
230
+ if (type === "PER_UNIT" && typeof price.unit === "string")
231
+ return `per ${typeof price.per === "number" ? price.per : 1} ${price.unit} (${type})`;
232
+ if (type === "METERED")
233
+ return `by metered use (${type})`;
234
+ if (type === "TIERED" || type === "PER_UNIT_MATRIX")
235
+ return `partly by usage (${type})`;
236
+ return `by usage (${type})`;
237
+ }
238
+ /** Why the endpoint `tool`, priced `price` (no fixed USD price: heldOf is undefined), cannot be granted. */
239
+ export const unboundedWords = (tool, price) => `${tool} cannot be granted: monid prices it ${priceWords(price)}, so what one call costs is known only after it has run, and monid does not bound it (a run's maxCost checks only monid's estimate, which a call priced by usage can pass). A run's cap could not be kept: grant endpoints monid prices per call.`;
240
+ /** `schema` moved from a document's root to the JSON pointer `at`: each local reference to a place in it (`#`, `#/…`)
241
+ * rebased onto `at`, so `#/$defs/Person` reads `#/properties/body/$defs/Person`. A schema with its own `$id` is a
242
+ * resource of its own, whose local references resolve inside it: it and all under it are left as they are. A keyword
243
+ * whose value is data (VALUE_KEYWORDS: `const`, `enum`, ...) is left as it is, a `$ref` in it being part of a value the
244
+ * endpoint takes; under a keyword that maps names to schemas (NAMED_SCHEMAS: `properties`, `$defs`, ...), each name is
245
+ * a name, never a keyword, and each schema under it is walked. */
246
+ const rebased = (schema, at) => {
247
+ if (Array.isArray(schema))
248
+ return schema.map((item) => rebased(item, at));
249
+ if (!isObject(schema) || typeof schema.$id === "string")
250
+ return schema;
251
+ return Object.fromEntries(Object.entries(schema).map(([key, value]) => {
252
+ if (key === "$ref" && typeof value === "string" && (value === "#" || value.startsWith("#/")))
253
+ return [key, `#${at}${value.slice(1)}`];
254
+ if (VALUE_KEYWORDS.has(key))
255
+ return [key, value];
256
+ if (NAMED_SCHEMAS.has(key) && isObject(value))
257
+ return [key, Object.fromEntries(Object.entries(value).map(([name, sub]) => [name, rebased(sub, at)]))];
258
+ return [key, rebased(value, at)];
259
+ }));
214
260
  };
215
- const quoteKey = (args) => JSON.stringify([args.provider, args.endpoint]);
216
- /** A record on the run's root, where its spend is read on every harness (cap.ts, harness-app.ts). */
217
- const record = (api, kind, data, context) => api.commit(async (tx) => void (await tx.appendEntry(ROOT_CONVERSATION_ID, { kind, data })), context);
218
- /** monid's tool `kind` for a run, under its wire name: the key and the faux hook read from `env` (the run's process's,
219
- * with its secrets) at each call, an answer too long for the model filed under `work()`, read at the call. A run goes
220
- * through the run's cap (paidCall), is marked before it is sent (TOOL_STARTED, held at its quoted price or the
221
- * allowance) and settled by its charge (TOOL_COST): a crash between the two leaves the cap counting the held figure
222
- * and the run's cost unknown, never $0. pi binds it (monidTool); another harness runs it as a host tool
223
- * (host-tools.ts), whose `api` commits to the run's store as pi's does. */
224
- export function monidRegistration(kind, env, work) {
225
- const { description, properties, required, replay } = SPECS[kind];
226
- return defineTool({
227
- name: wireName(`monid.${kind}`), description, replay,
228
- parameters: { type: "object", additionalProperties: false, properties, required },
229
- execute: async (args, api, context) => {
230
- const faux = await fauxFetch(env, FAUX_MONID_ENV);
231
- const client = monidClient({ key: env[MONID_KEY_ENV] ?? "", ...(faux ? { fetch: faux } : {}) });
232
- const call = () => client[kind](args, context?.abortSignal);
233
- const label = { tool: "monid.run", charged_by: "monid", call: api.callId };
234
- // What the run is held at, under the cap and on its mark: the price an inspect quoted, else the allowance.
235
- const quote = quotesOf(env).get(quoteKey(args));
236
- const held = quote ?? MONID_RUN_ALLOWANCE_USD;
237
- const basis = quote !== undefined ? `the price ${INSPECT} quoted` : `no price was quoted for it in this run, so it counts at the $${MONID_RUN_ALLOWANCE_USD} allowance; ${INSPECT} gives its price`;
238
- const send = async () => {
239
- try {
240
- await writeHold((kind, data) => record(api, kind, data, context), { ...label, heldUsd: held });
241
- }
242
- catch (error) {
243
- return uncharged({ error: holdRefusal(RUN, error) });
244
- }
245
- const answer = await call();
246
- // Settled at what it charged: $0 only when monid charged nothing, null (unknown) when it may have and did not say.
247
- // Paid for, it answers even when this cannot be written, never a failure the model would retry.
248
- const usd = chargeOf(answer);
249
- const settle = { ...label, usd: usd === undefined ? 0 : usd };
250
- await record(api, TOOL_COST, settle, context).catch(() => undefined);
251
- return answer;
252
- };
253
- // On the runner's one ledger (paid-calls.ts Ledger.paid): held there at the same figure and settled at the same charge
254
- // ($0 when monid charged nothing, at its hold when it may have and did not say), in place of this process's spend.
255
- const onLedger = kind === "run" ? paidLedger() : undefined;
256
- const paid = onLedger
257
- ? await paidStep(onLedger, api.callId, { name: RUN, holdUsd: held, basis, by: label.charged_by }, call, (outcome) => {
258
- if (!("result" in outcome))
259
- return null;
260
- const usd = chargeOf(outcome.result);
261
- return usd === undefined ? 0 : usd;
262
- })
263
- : kind === "run" ? await paidCall(RUN, send, chargeOf, { usd: held, basis }) : { result: await call() };
264
- if ("refused" in paid)
265
- return forModel(JSON.stringify({ error: paid.refused }), { isError: true });
266
- const answer = paid.result;
267
- const price = kind === "inspect" && isObject(answer.price) && answer.price.type === "PER_CALL" ? money(answer.price.amount) : undefined;
268
- if (price?.currency === "USD")
269
- quotesOf(env).set(quoteKey(args), price.value);
270
- const cost = money(answer.cost);
271
- return forModel(await monidText(answer, work(), kind), { isError: answer.error !== undefined, ...(cost ? { details: { cost } } : {}) });
272
- },
261
+ /** JSON Schema keywords whose value is data, not a schema. */
262
+ const VALUE_KEYWORDS = new Set(["const", "enum", "default", "examples", "example"]);
263
+ /** JSON Schema keywords whose value maps names to schemas. */
264
+ const NAMED_SCHEMAS = new Set(["properties", "patternProperties", "$defs", "definitions", "dependentSchemas"]);
265
+ /** An endpoint's input schema as one tool's (inspect's `input`: `pathParams`, `queryParams`, `body`, each a JSON
266
+ * Schema): an object of those parts, each required that requires a field, its local references rebased. */
267
+ function inputSchema(input) {
268
+ const parts = isObject(input) ? input : {};
269
+ const properties = {};
270
+ const required = [];
271
+ for (const part of ["pathParams", "queryParams", "body"]) {
272
+ if (!isObject(parts[part]))
273
+ continue;
274
+ const { $schema: _schema, ...schema } = rebased(parts[part], `/properties/${part}`);
275
+ properties[part] = schema;
276
+ if (Array.isArray(schema.required) && schema.required.length)
277
+ required.push(part);
278
+ }
279
+ return { type: "object", additionalProperties: false, properties, ...(required.length ? { required } : {}) };
280
+ }
281
+ /** The monid grants among `grants` pinned against monid's listing on `key` (pinned at a save, never at a run): each
282
+ * provider's wildcard read as the endpoints monid lists for it now (at most MONID_WILDCARD_MAX), each endpoint inspected
283
+ * for its description, input and price. A grant monid lists nothing for is refused, as is every grant when there is no
284
+ * key or monid cannot be read. An endpoint with no fixed price (heldOf) is refused as a named grant, and left out of a
285
+ * wildcard, which is refused when it leaves none. Undefined when no grant is monid's. */
286
+ export async function pinMonid(grants, options) {
287
+ const named = grants.flatMap((tool) => {
288
+ const parsed = parseToolName(tool);
289
+ return parsed?.kind === "monid" || parsed?.kind === "monid-provider" ? [{ tool, parsed }] : [];
273
290
  });
291
+ if (!named.length)
292
+ return undefined;
293
+ if (!options.key)
294
+ return { refused: named.map(({ tool }) => ({ tool, message: `${tool} is pinned to what monid lists when the agent is saved, and there is no monid key here to read it with: save the monid key in Settings → Tool keys first.` })) };
295
+ const client = monidClient({ key: options.key, ...(options.fetch ? { fetch: options.fetch } : {}), ...(options.sleep ? { sleep: options.sleep } : {}) });
296
+ // monid's own words, which a save's refusal returns to its caller: the key they were read with cut from them, in
297
+ // every form a run's error is redacted of (key-refusal.ts redacted).
298
+ const key = options.key;
299
+ const said = (error) => redacted(String(error), [key]);
300
+ const refused = [];
301
+ // Each endpoint to pin, by catalog name: the grants' own, then each wildcard's provider's as monid lists them, with
302
+ // the wildcard (`from`) when no grant names it.
303
+ const wanted = new Map();
304
+ const providers = new Set(named.flatMap(({ parsed }) => (parsed.kind === "monid-provider" ? [parsed.provider] : [])));
305
+ if (providers.size) {
306
+ const listed = new Map();
307
+ // Every page, a bounded number of them: monid's listing is not filtered by provider.
308
+ for (let cursor, page = 0; (page === 0 || cursor) && page < 500; page++) {
309
+ const res = await client.endpoints(cursor, options.signal);
310
+ if (res.error !== undefined)
311
+ return { refused: named.map(({ tool }) => ({ tool, message: `${tool} could not be pinned: monid's listing could not be read (${said(res.error)}).` })) };
312
+ for (const item of Array.isArray(res.items) ? res.items : []) {
313
+ if (isObject(item) && typeof item.provider === "string" && typeof item.endpoint === "string" && providers.has(item.provider))
314
+ listed.set(item.provider, [...(listed.get(item.provider) ?? []), item.endpoint]);
315
+ }
316
+ cursor = typeof res.cursor === "string" && res.cursor ? res.cursor : undefined;
317
+ }
318
+ for (const { tool, parsed } of named) {
319
+ if (parsed.kind !== "monid-provider")
320
+ continue;
321
+ const endpoints = listed.get(parsed.provider) ?? [];
322
+ if (!endpoints.length)
323
+ refused.push({ tool, message: `monid lists no endpoint of a provider ${parsed.provider}.` });
324
+ else if (endpoints.length > MONID_WILDCARD_MAX)
325
+ refused.push({ tool, message: `monid lists ${endpoints.length} endpoints of ${parsed.provider}, more than the ${MONID_WILDCARD_MAX} one grant may pin: grant its endpoints by name, monid:${parsed.provider}/<endpoint>.` });
326
+ else
327
+ for (const path of endpoints)
328
+ wanted.set(formatToolName({ kind: "monid", provider: parsed.provider, endpoint: path.replace(/^\//, "") }), { provider: parsed.provider, endpoint: path, from: tool });
329
+ }
330
+ }
331
+ for (const { tool, parsed } of named)
332
+ if (parsed.kind === "monid")
333
+ wanted.set(tool, { provider: parsed.provider, endpoint: `/${parsed.endpoint}` });
334
+ // Each endpoint inspected, INSPECTS_AT_ONCE at a time.
335
+ const pin = {};
336
+ const leftOut = [];
337
+ const queue = [...wanted];
338
+ const inspectOne = async () => {
339
+ for (let next = queue.shift(); next; next = queue.shift()) {
340
+ const [tool, at] = next;
341
+ const res = await client.inspect(at, options.signal);
342
+ const usd = heldOf(res.price);
343
+ if (res.status === 404)
344
+ refused.push({ tool, message: `monid lists no endpoint ${at.endpoint} of a provider ${at.provider}.` });
345
+ else if (res.error !== undefined)
346
+ refused.push({ tool, message: `${tool} could not be pinned: monid's listing of it could not be read (${said(res.error)}).` });
347
+ else if (usd === undefined && at.from)
348
+ leftOut.push({ tool: at.from, endpoint: tool, message: `${tool} is left out of ${at.from}: ${unboundedWords(tool, res.price)}` });
349
+ else if (usd === undefined)
350
+ refused.push({ tool, message: unboundedWords(tool, res.price) });
351
+ else
352
+ pin[tool] = { description: [res.description, res.summary].find((said) => typeof said === "string" && said.trim() !== "")?.trim() ?? `${at.provider} ${at.endpoint}, an endpoint of monid's.`, input: inputSchema(res.input), usd };
353
+ }
354
+ };
355
+ await Promise.all(Array.from({ length: Math.min(INSPECTS_AT_ONCE, queue.length) }, inspectOne));
356
+ leftOut.sort((a, b) => (a.endpoint < b.endpoint ? -1 : a.endpoint > b.endpoint ? 1 : 0));
357
+ // A wildcard whose every endpoint was left out pins nothing: refused, with why for each.
358
+ for (const { tool, parsed } of named) {
359
+ if (parsed.kind !== "monid-provider" || refused.some((one) => one.tool === tool))
360
+ continue;
361
+ const left = leftOut.filter((one) => one.tool === tool);
362
+ if (left.length && !Object.keys(pin).some((endpoint) => wanted.get(endpoint)?.provider === parsed.provider))
363
+ refused.push({ tool, message: `${tool} pins nothing: every endpoint monid lists of ${parsed.provider} is priced by usage. ${left.map((one) => one.message).join(" ")}` });
364
+ }
365
+ // Two endpoints the harnesses would call by one name (wireName folds `.` and `/`): neither could be told apart.
366
+ const wires = new Map();
367
+ for (const tool of Object.keys(pin).sort()) {
368
+ const other = wires.get(wireName(tool));
369
+ if (other)
370
+ refused.push({ tool, message: `${tool} and ${other} are called by one name on every harness (${wireName(tool)}): grant one of them by name.` });
371
+ wires.set(wireName(tool), tool);
372
+ }
373
+ return refused.length ? { refused } : { pin: Object.fromEntries(Object.keys(pin).sort().map((tool) => [tool, pin[tool]])), leftOut: leftOut.map(({ tool, message }) => ({ tool, message })) };
274
374
  }
275
- /** The table's entry for `monid.<kind>`: it needs MONID_API_KEY, and no workflow node names it yet. */
276
- export const monidTool = (kind) => ({
277
- summary: SPECS[kind].summary,
278
- needs: [MONID_KEY_ENV],
279
- nodes: false,
280
- bind: async (host) => {
281
- // An answer too long for the model is filed in the run's own Workspace (in Mode 2, on the run's disk, where its read
282
- // looks), else in the local folder the run works in.
283
- const tool = monidRegistration(kind, host.env, () => host.workspace ?? localWorkspace(host.where.work));
284
- const extension = defineExtension({ name: `monid-${kind}`, tools: [tool] });
285
- host.install(extension);
286
- return { tools: [tool], extensions: [extension] };
287
- },
288
- });