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

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 (312) hide show
  1. package/CHANGELOG.md +281 -0
  2. package/README.md +246 -66
  3. package/dist/acp-package.d.ts +2 -0
  4. package/dist/adapters.d.ts +15 -3
  5. package/dist/adapters.js +17 -6
  6. package/dist/agent-package.d.ts +3 -3
  7. package/dist/agent-package.js +17 -8
  8. package/dist/api-keys.d.ts +76 -0
  9. package/dist/api-keys.js +217 -0
  10. package/dist/api-only.d.ts +15 -5
  11. package/dist/api-only.js +32 -8
  12. package/dist/box-paths.d.ts +4 -3
  13. package/dist/box-paths.js +7 -4
  14. package/dist/browser-hold.d.ts +23 -0
  15. package/dist/browser-hold.js +48 -0
  16. package/dist/browser-person.d.ts +3 -0
  17. package/dist/browser-person.js +4 -1
  18. package/dist/chatgpt-plan.d.ts +18 -8
  19. package/dist/chatgpt-plan.js +91 -34
  20. package/dist/claude-login-token.d.ts +117 -0
  21. package/dist/claude-login-token.js +737 -0
  22. package/dist/claude-login.d.ts +120 -22
  23. package/dist/claude-login.js +347 -63
  24. package/dist/claude-sign-in.d.ts +17 -6
  25. package/dist/claude-sign-in.js +42 -39
  26. package/dist/cli.js +33 -10
  27. package/dist/composio-made.d.ts +4 -0
  28. package/dist/composio-made.js +4 -0
  29. package/dist/composio-preset.d.ts +43 -2
  30. package/dist/composio-preset.js +92 -4
  31. package/dist/computer-attach.d.ts +35 -17
  32. package/dist/computer-attach.js +301 -49
  33. package/dist/computer-held-routes.d.ts +5 -4
  34. package/dist/computer-held-routes.js +29 -8
  35. package/dist/computer-held.d.ts +6 -1
  36. package/dist/computer-held.js +14 -0
  37. package/dist/computer-record.js +4 -2
  38. package/dist/computer-viewer.js +4 -1
  39. package/dist/computers.d.ts +10 -10
  40. package/dist/computers.js +5 -5
  41. package/dist/console/assets/{backend-Boh7tC4i.js → backend-CSAWUqtZ.js} +19 -19
  42. package/dist/console/assets/index-Bwn1oTem.css +1 -0
  43. package/dist/console/assets/index-DPh29cyz.js +747 -0
  44. package/dist/console/index.html +2 -2
  45. package/dist/decisions.d.ts +1 -1
  46. package/dist/decisions.js +1 -1
  47. package/dist/dial-relay.d.ts +25 -4
  48. package/dist/dial-relay.js +129 -1
  49. package/dist/docker-host-addresses.d.ts +22 -11
  50. package/dist/docker-host-addresses.js +38 -26
  51. package/dist/env-switch.d.ts +8 -0
  52. package/dist/env-switch.js +31 -2
  53. package/dist/errors.d.ts +1 -0
  54. package/dist/errors.js +2 -0
  55. package/dist/fal-price.d.ts +56 -20
  56. package/dist/fal-price.js +400 -90
  57. package/dist/handed-values.d.ts +43 -1
  58. package/dist/handed-values.js +119 -2
  59. package/dist/harness-archive.d.ts +13 -10
  60. package/dist/harness-archive.js +60 -34
  61. package/dist/harness-check.d.ts +3 -1
  62. package/dist/harness-check.js +25 -46
  63. package/dist/harness-keys.d.ts +73 -27
  64. package/dist/harness-keys.js +194 -61
  65. package/dist/harness-recipe-entry.d.ts +8 -7
  66. package/dist/harness-recipe-entry.js +21 -32
  67. package/dist/harness-recipe.d.ts +38 -25
  68. package/dist/harness-recipe.js +49 -36
  69. package/dist/harness-sign-in.js +12 -23
  70. package/dist/harness-table.d.ts +10 -3
  71. package/dist/harness-table.js +26 -21
  72. package/dist/harness.d.ts +1 -0
  73. package/dist/harness.js +17 -5
  74. package/dist/hosted-search.d.ts +1 -1
  75. package/dist/hosted-search.js +1 -2
  76. package/dist/import-worker.d.ts +4 -2
  77. package/dist/import-worker.js +9 -2
  78. package/dist/in-flight.d.ts +26 -0
  79. package/dist/in-flight.js +52 -0
  80. package/dist/key-refusal.d.ts +9 -4
  81. package/dist/key-refusal.js +107 -25
  82. package/dist/learn/ledger.d.ts +170 -0
  83. package/dist/learn/ledger.js +218 -0
  84. package/dist/learn/promote.d.ts +3 -3
  85. package/dist/learn/promote.js +1 -1
  86. package/dist/learn/secrets.d.ts +13 -3
  87. package/dist/learn/secrets.js +118 -17
  88. package/dist/learning-cost.d.ts +28 -23
  89. package/dist/learning-cost.js +19 -23
  90. package/dist/link-check.js +1 -1
  91. package/dist/live-reach.d.ts +2 -0
  92. package/dist/live-reach.js +2 -0
  93. package/dist/llms.txt +1 -1
  94. package/dist/marketplace.d.ts +77 -0
  95. package/dist/marketplace.js +224 -0
  96. package/dist/mcp-api-only-origins.d.ts +35 -0
  97. package/dist/mcp-api-only-origins.js +57 -0
  98. package/dist/mcp-gateway.d.ts +7 -5
  99. package/dist/mcp-gateway.js +9 -12
  100. package/dist/mcp-secret-writes.js +5 -3
  101. package/dist/mcp-servers-store.d.ts +28 -6
  102. package/dist/mcp-servers-store.js +53 -4
  103. package/dist/media-duration.d.ts +3 -0
  104. package/dist/media-duration.js +90 -9
  105. package/dist/micro.d.ts +2 -0
  106. package/dist/micro.js +2 -0
  107. package/dist/model-form.d.ts +5 -4
  108. package/dist/model-form.js +11 -7
  109. package/dist/model.d.ts +10 -6
  110. package/dist/model.js +16 -11
  111. package/dist/monid.d.ts +14 -1
  112. package/dist/monid.js +103 -26
  113. package/dist/ollama-provider.d.ts +7 -1
  114. package/dist/ollama-provider.js +14 -2
  115. package/dist/openapi.js +210 -37
  116. package/dist/otel/genai.d.ts +65 -0
  117. package/dist/otel/genai.js +116 -0
  118. package/dist/otel/tracer.d.ts +55 -0
  119. package/dist/otel/tracer.js +308 -0
  120. package/dist/page.d.ts +2 -0
  121. package/dist/page.js +3 -1
  122. package/dist/paid-calls.d.ts +1 -32
  123. package/dist/paid-calls.js +4 -39
  124. package/dist/place-offers.d.ts +4 -0
  125. package/dist/place-offers.js +7 -4
  126. package/dist/provider.d.ts +11 -2
  127. package/dist/provider.js +59 -8
  128. package/dist/redact/match.d.ts +30 -3
  129. package/dist/redact/match.js +422 -41
  130. package/dist/refusal-words.d.ts +11 -0
  131. package/dist/refusal-words.js +11 -0
  132. package/dist/run-census.d.ts +67 -0
  133. package/dist/run-census.js +240 -0
  134. package/dist/run-computer.d.ts +6 -3
  135. package/dist/run-computer.js +4 -1
  136. package/dist/run-cut.d.ts +15 -6
  137. package/dist/run-cut.js +30 -9
  138. package/dist/run-files.d.ts +3 -0
  139. package/dist/run-files.js +3 -0
  140. package/dist/run-launch.d.ts +12 -1
  141. package/dist/run-launch.js +9 -10
  142. package/dist/run-learning-served.d.ts +4 -2
  143. package/dist/run-model-key.d.ts +8 -0
  144. package/dist/run-model-key.js +31 -1
  145. package/dist/run-reads-over-store.d.ts +24 -6
  146. package/dist/run-reads-over-store.js +67 -23
  147. package/dist/run-recordings.d.ts +5 -1
  148. package/dist/run-recordings.js +39 -14
  149. package/dist/run-timeline-served.d.ts +2 -0
  150. package/dist/run-timeline-served.js +2 -2
  151. package/dist/run-usage.d.ts +1 -0
  152. package/dist/run-view.d.ts +1 -2
  153. package/dist/run-view.js +2 -1
  154. package/dist/runnable.d.ts +10 -1
  155. package/dist/runnable.js +20 -8
  156. package/dist/runner/adapter-loop.d.ts +11 -0
  157. package/dist/runner/adapter-loop.js +58 -26
  158. package/dist/runner/adapter-run-spec.d.ts +55 -11
  159. package/dist/runner/adapter-run-spec.js +183 -52
  160. package/dist/runner/adapters/pi.js +25 -3
  161. package/dist/runner/beside.d.ts +9 -2
  162. package/dist/runner/beside.js +27 -9
  163. package/dist/runner/big-writes.js +1 -10
  164. package/dist/runner/claim-secrets.d.ts +27 -10
  165. package/dist/runner/claim-secrets.js +49 -22
  166. package/dist/runner/cli-run-spec.d.ts +6 -0
  167. package/dist/runner/cli-run-spec.js +97 -38
  168. package/dist/runner/computer-journal.d.ts +9 -1
  169. package/dist/runner/computer-journal.js +26 -0
  170. package/dist/runner/conformance/harness.js +1 -1
  171. package/dist/runner/feedback-round.js +3 -0
  172. package/dist/runner/harness-loops.d.ts +6 -5
  173. package/dist/runner/harness-loops.js +7 -7
  174. package/dist/runner/held.d.ts +24 -6
  175. package/dist/runner/journal-kinds.d.ts +5 -0
  176. package/dist/runner/journal-kinds.js +5 -0
  177. package/dist/runner/main.d.ts +11 -6
  178. package/dist/runner/main.js +19 -9
  179. package/dist/runner/mcp-claim.js +31 -3
  180. package/dist/runner/mcp-run.d.ts +9 -0
  181. package/dist/runner/mcp-run.js +11 -5
  182. package/dist/runner/model-route.d.ts +17 -0
  183. package/dist/runner/model-route.js +120 -2
  184. package/dist/runner/presence.d.ts +11 -1
  185. package/dist/runner/presence.js +7 -0
  186. package/dist/runner/reflect-hook.js +1 -1
  187. package/dist/runner/run-child-host.d.ts +22 -8
  188. package/dist/runner/run-child-host.js +128 -41
  189. package/dist/runner/run-child.js +5 -2
  190. package/dist/runner/runner.d.ts +17 -3
  191. package/dist/runner/runner.js +130 -34
  192. package/dist/runner/save-slots.js +2 -1
  193. package/dist/runner/store-port.d.ts +1 -1
  194. package/dist/runner/store-secrets.d.ts +6 -0
  195. package/dist/runner/store-secrets.js +49 -7
  196. package/dist/runner/subagent.d.ts +11 -0
  197. package/dist/runner/subagent.js +16 -38
  198. package/dist/runner/workflow-first.d.ts +35 -15
  199. package/dist/runner/workflow-first.js +38 -25
  200. package/dist/runner/workflow-spec.js +4 -3
  201. package/dist/runs-over-store.d.ts +15 -6
  202. package/dist/runs-over-store.js +33 -21
  203. package/dist/scrub-command.d.ts +73 -0
  204. package/dist/scrub-command.js +307 -0
  205. package/dist/secret-cut.d.ts +73 -0
  206. package/dist/secret-cut.js +291 -4
  207. package/dist/secret-rules.d.ts +143 -0
  208. package/dist/secret-rules.js +2564 -0
  209. package/dist/secrets.d.ts +7 -0
  210. package/dist/secrets.js +20 -0
  211. package/dist/server-keys.d.ts +20 -0
  212. package/dist/server-keys.js +25 -6
  213. package/dist/server.d.ts +65 -13
  214. package/dist/server.js +470 -157
  215. package/dist/skills/agentrun-serve/SKILL.md +4 -0
  216. package/dist/slots.d.ts +9 -0
  217. package/dist/slots.js +45 -0
  218. package/dist/store/index.d.ts +1 -1
  219. package/dist/store/index.js +1 -1
  220. package/dist/store/journal/storage.js +1 -1
  221. package/dist/store/postgres/migrations/0027_run_launch_census.sql +31 -0
  222. package/dist/store/postgres/migrations/0028_learning_ledger.sql +44 -0
  223. package/dist/store/schema.d.ts +23 -0
  224. package/dist/store/schema.js +58 -2
  225. package/dist/store/seal.d.ts +6 -1
  226. package/dist/store/seal.js +5 -3
  227. package/dist/store/sqlite/run-launch.d.ts +9 -1
  228. package/dist/store/sqlite/run-launch.js +24 -13
  229. package/dist/store/sqlite/run-patch.d.ts +12 -2
  230. package/dist/store/sqlite/run-patch.js +42 -5
  231. package/dist/store/sqlite/store.js +105 -12
  232. package/dist/store/store.d.ts +57 -2
  233. package/dist/store/store.js +20 -0
  234. package/dist/store-reads/learning.d.ts +84 -124
  235. package/dist/store-reads/learning.js +210 -274
  236. package/dist/store-view.d.ts +3 -0
  237. package/dist/store-view.js +3 -3
  238. package/dist/suggestions.js +3 -2
  239. package/dist/template-eval.d.ts +39 -9
  240. package/dist/template-eval.js +191 -60
  241. package/dist/template-import.js +6 -2
  242. package/dist/templates.d.ts +10 -2
  243. package/dist/templates.js +28 -8
  244. package/dist/timeline/labels.d.ts +6 -4
  245. package/dist/timeline/labels.js +18 -6
  246. package/dist/timeline/timeline.d.ts +5 -0
  247. package/dist/timeline/timeline.js +14 -8
  248. package/dist/timeline/util.js +1 -1
  249. package/dist/timeline/web-calls.d.ts +22 -7
  250. package/dist/timeline/web-calls.js +106 -35
  251. package/dist/tool-gate.d.ts +42 -3
  252. package/dist/tool-gate.js +66 -5
  253. package/dist/tool-keys-store.d.ts +2 -4
  254. package/dist/tool-keys-store.js +5 -21
  255. package/dist/tool-keys.d.ts +2 -2
  256. package/dist/tool-keys.js +2 -2
  257. package/dist/tool-list.js +1 -1
  258. package/dist/tool-plane.d.ts +2 -2
  259. package/dist/tool-plane.js +35 -33
  260. package/dist/tools.js +13 -7
  261. package/dist/trigger-targets.d.ts +4 -0
  262. package/dist/trigger-targets.js +9 -2
  263. package/dist/triggers.d.ts +67 -4
  264. package/dist/triggers.js +171 -22
  265. package/dist/until.d.ts +3 -0
  266. package/dist/until.js +11 -0
  267. package/dist/web-fake.d.ts +1 -3
  268. package/dist/web-fake.js +7 -18
  269. package/dist/web-fetch.d.ts +6 -72
  270. package/dist/web-fetch.js +11 -265
  271. package/dist/web-run.d.ts +31 -0
  272. package/dist/web-run.js +90 -0
  273. package/dist/web-save.d.ts +10 -13
  274. package/dist/web-save.js +13 -55
  275. package/dist/web-search.d.ts +9 -127
  276. package/dist/web-search.js +23 -259
  277. package/dist/wires.d.ts +13 -0
  278. package/dist/wires.js +11 -0
  279. package/dist/workflow-run.d.ts +5 -4
  280. package/dist/workflow-run.js +5 -4
  281. package/dist/workspace/attached-computers.d.ts +32 -9
  282. package/dist/workspace/attached-computers.js +77 -13
  283. package/dist/workspace/computer-deps.d.ts +8 -2
  284. package/dist/workspace/computer-deps.js +10 -3
  285. package/dist/workspace/computer-for-claim.d.ts +12 -1
  286. package/dist/workspace/computer-for-claim.js +83 -11
  287. package/dist/workspace/computer-kept.d.ts +3 -0
  288. package/dist/workspace/computer-kept.js +11 -2
  289. package/dist/workspace/index.d.ts +1 -1
  290. package/dist/workspace/index.js +1 -1
  291. package/dist/workspace/kind-skills.d.ts +4 -0
  292. package/dist/workspace/kind-skills.js +9 -0
  293. package/dist/workspace/paired-route.d.ts +91 -0
  294. package/dist/workspace/paired-route.js +153 -0
  295. package/dist/workspace/synced-folder.js +3 -4
  296. package/dist/wrapped.d.ts +20 -6
  297. package/dist/wrapped.js +66 -25
  298. package/package.json +17 -11
  299. package/skills/agentrun-serve/SKILL.md +4 -0
  300. package/templates/README.md +32 -10
  301. package/dist/console/assets/index-CQ3cJRzI.js +0 -746
  302. package/dist/console/assets/index-DKkaS3a0.css +0 -1
  303. package/dist/exa-keyless.d.ts +0 -34
  304. package/dist/exa-keyless.js +0 -118
  305. package/dist/firecrawl-keyless.d.ts +0 -41
  306. package/dist/firecrawl-keyless.js +0 -152
  307. package/dist/keyless-mcp.d.ts +0 -36
  308. package/dist/keyless-mcp.js +0 -127
  309. package/dist/text-urls.d.ts +0 -38
  310. package/dist/text-urls.js +0 -170
  311. package/dist/web-fetch-direct.d.ts +0 -119
  312. package/dist/web-fetch-direct.js +0 -190
@@ -1,137 +1,19 @@
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";
5
- import { type SearchModels } from "./hosted-search.js";
6
- import { type Extract } from "./web-fetch.js";
4
+ import { type Search, type SearchBounds } from "@parcha/agentrun-web";
5
+ import { type SearchOn } from "./web-run.js";
6
+ export type { SearchOn };
7
7
  export declare const WEB_SEARCH_TOOL = "web_search";
8
8
  /** The tools that reach the web, each through the provider its run's plane resolves it to. */
9
9
  export declare const WEB_TOOLS: readonly string[];
10
- export declare const PARALLEL_SEARCH_URL = "https://api.parallel.ai/v1/search";
11
- export declare const QUERY_MAX = 200;
12
- export declare const RESULTS_MAX = 25;
13
- /** The most of a result's text its snippet keeps; Parallel is asked for as much of each result's excerpts. */
14
- export declare const SNIPPET_MAX = 3000;
15
- /** The most of the provider's own short answer (`text`) a search keeps (hosted-search.ts). */
16
- export declare const ANSWER_MAX = 4000;
17
- /** The most characters a search's answer takes, its citing line included: about RESULTS_MAX results with whole snippets,
18
- * under the host's result bound (HOST_RESULT_MAX_CHARS), which the host-bounds test holds it to. */
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;
25
- export type Hit = {
26
- url: string;
27
- title: string;
28
- snippet: string;
29
- published?: string;
30
- };
31
- export type Search = {
32
- provider: "native" | "firecrawl-keyless" | "exa-keyless" | "parallel";
33
- query: string;
34
- results: Hit[];
35
- text?: string;
36
- omitted?: number;
37
- } | {
38
- error: string;
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 type Breaker = {
72
- held(): Search | undefined;
73
- read(searched: Searched): Search;
74
- off(): boolean;
75
- left(): number;
76
- };
77
- export declare function searchBreaker(now?: () => number): Breaker;
78
- /** The line that ends a search's answer to the model, as Claude Code's WebSearch ends its own. */
79
- export declare const CITE = "Cite the URL of each result you rely on.";
80
- /** `answer` within SEARCH_MAX_CHARS, as searchText writes it: whole when it fits, else without its least relevant results
81
- * (the last), as many as it takes, `omitted` counting them. */
82
- export declare function fitSearch(answer: Search): Search;
83
- /** A search as the model reads it: its JSON (fitSearch), then the line asking it to cite the URLs it relies on; an
84
- * error's JSON alone. */
85
- export declare function searchText(answer: Search): string;
86
- /** A result's text as its snippet: links reduced to their text, whitespace collapsed, cut at SNIPPET_MAX on a word. */
87
- export declare function snippetOf(raw: string): string;
88
- /** `{query, n?}` as every provider takes it: the query trimmed and cut at QUERY_MAX, n 1 to RESULTS_MAX. */
89
- export declare const searchArgs: (args: Record<string, unknown>) => {
90
- query: string;
91
- n: number;
92
- };
93
- /** `{query, n?}` searched through `parallel` (null: the run holds no key), as a Search. */
94
- export declare function webSearch(args: Record<string, unknown>, parallel: Extract | null, signal?: AbortSignal): Promise<Search>;
95
- /** The run's models a native search goes through, asked when a search runs (the runner's: the session's port, up once
96
- * the session is open): ToolHost.search, EffectRun.search. */
97
- export type SearchOn = () => Promise<SearchModels | undefined>;
98
- /** `{query, n?}` searched by the provider the run's plane resolves web_search to, as a Search. `models`: the run's own
99
- * models a native search goes through (none: a native search has no model to search on). */
10
+ /** `args` searched as the run's web_search, on fresh breakers: a call node's search falls to the next backend as the
11
+ * agent's does, and holds nothing after. */
100
12
  export declare function searchFor(env: NodeJS.ProcessEnv, args: Record<string, unknown>, signal?: AbortSignal, models?: SearchOn): Promise<Search>;
101
- /** A backend a call of web_search asks: its name (its breaker's), and its one search. The keyless backends end at
102
- * `deadline`, the call's one deadline for every backend it asks (searchInTurn); Parallel and a native search keep the
103
- * caller's signal and their own bounds. */
104
- type Backend = {
105
- name: string;
106
- ask(deadline: AbortSignal): Promise<Searched>;
107
- };
108
- /** The most one call of web_search spends across its keyless backends together: Firecrawl's failing or timing out
109
- * leaves Exa what is left of it, never a fresh bound. Firecrawl's own bound inside it (FIRECRAWL_MS, 30 s) leaves Exa
110
- * at least the rest. */
111
- export declare const KEYLESS_SEARCH_MS = 60000;
112
- /** A call's bounds, a test's: `searchMs`, its one deadline (KEYLESS_SEARCH_MS); `firecrawlMs`, Firecrawl's own inside it
113
- * (FIRECRAWL_MS). */
114
- export type SearchBounds = {
115
- searchMs?: number;
116
- firecrawlMs?: number;
117
- };
118
- /** A call's search through `backends` in turn, each through its breaker (`breakerOf`, by its name) and all under one
119
- * deadline, `boundMs` from the call's start or the caller's `signal`: the first that answers results is the answer,
120
- * and one that fails or that its breaker holds passes the call to the next, unless the deadline is spent: no backend
121
- * starts on a spent one. None left:
122
- * SEARCH_UNAVAILABLE where every backend is off (a lone backend's own answer where it was asked, as its breaker reads
123
- * it), else the last failure, else searchBusy for the shortest wait. */
124
- export declare function searchInTurn(backends: readonly Backend[], breakerOf: (name: string) => Breaker, signal?: AbortSignal, boundMs?: number): Promise<Search>;
125
- /** 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
126
- * notice, as its daily count running out answers) is marked repeatIsQuota, so a second one past a wait is that count; a
127
- * 429 with Retry-After is a timed limit, unmarked. A refused connection is no limit (a 403 no wait lifts). */
128
- export declare function exaLimitOf(found: ExaLimited): Limit | undefined;
129
- /** The agent's tool: the Search as JSON text. A run whose web_search resolves to Parallel reads its key as the tool is
130
- * made, when the run opens; one that resolves native searches through `models`, the run's own (ToolHost.search).
131
- * `fake`: what answers each search in the provider's place (a template eval's web fake, web-fake.ts), the provider
132
- * the run's plane names given it, the tool otherwise the same. `now`: the breakers' clock (a test's); `bounds`: a call's
133
- * deadline across its keyless backends and Firecrawl's own inside it (a test's; SearchBounds). */
13
+ /** The agent's tool. The run's Web is made as the tool is bound, so a run whose web_search resolves to Parallel reads its
14
+ * key when the run opens. `fake`: what answers each search in the provider's place (a template eval's web fake,
15
+ * web-fake.ts). `now` and `bounds`: a test's breaker clock and this binding's search deadlines, held by its calls
16
+ * alone. */
134
17
  export declare function webSearchTool(env: NodeJS.ProcessEnv, models?: SearchOn, fake?: (args: Record<string, unknown>, provider: Exclude<Search, {
135
18
  error: string;
136
19
  }>["provider"]) => Search, now?: () => number, bounds?: SearchBounds): ToolRegistration<TSchema, JsonValue>;
137
- export {};
@@ -1,276 +1,40 @@
1
1
  import { defineTool } from "@earendil-works/pi-durable";
2
- import { clip, TITLE_CAP } from "./web-fetch-direct.js";
2
+ import { breakers, fitSearch, QUERY_MAX, RESULTS_DEFAULT, RESULTS_MAX, searchArgs, searchText } from "@parcha/agentrun-web";
3
3
  import { forModel } from "./result.js";
4
- import { fauxFetch } from "./decisions.js";
5
- import { FAUX_ENV } from "./model.js";
6
- import { exaSearch, FAUX_EXA_ENV } from "./exa-keyless.js";
7
- import { FAUX_FIRECRAWL_ENV, firecrawlSearch } from "./firecrawl-keyless.js";
8
- import { hostedSearched } from "./hosted-search.js";
9
- import { PaidRefused } from "./paid-calls.js";
10
4
  import { planeOf, whyUnavailable } from "./tool-plane.js";
11
- import { parallelOf, WEB_FETCH_TOOL } from "./web-fetch.js";
5
+ import { WEB_FETCH_TOOL } from "./web-fetch.js";
6
+ import { ordersOf, searchingOn, webOf } from "./web-run.js";
12
7
  export const WEB_SEARCH_TOOL = "web_search";
13
8
  /** The tools that reach the web, each through the provider its run's plane resolves it to. */
14
9
  export const WEB_TOOLS = [WEB_FETCH_TOOL, WEB_SEARCH_TOOL];
15
- export const PARALLEL_SEARCH_URL = "https://api.parallel.ai/v1/search";
16
- export const QUERY_MAX = 200;
17
- export const RESULTS_MAX = 25;
18
- const RESULTS_DEFAULT = 10;
19
- /** The most of a result's text its snippet keeps; Parallel is asked for as much of each result's excerpts. */
20
- export const SNIPPET_MAX = 3_000;
21
- /** The most of the provider's own short answer (`text`) a search keeps (hosted-search.ts). */
22
- export const ANSWER_MAX = 4_000;
23
- /** The most characters a search's answer takes, its citing line included: about RESULTS_MAX results with whole snippets,
24
- * under the host's result bound (HOST_RESULT_MAX_CHARS), which the host-bounds test holds it to. */
25
- export const SEARCH_MAX_CHARS = 100_000;
26
- const REFUSED = "Parallel refused this run's key (401 or 403): it is not asked again in this run";
27
- /** What every later web_search call of a run answers once its provider said the run is out of quota (a Limit of kind
28
- * quota): the provider is not asked again in that run. */
29
- export const SEARCH_UNAVAILABLE = "search is unavailable for the rest of this run; answer from what you have";
30
- /** What a call answers while a rate limit's wait holds, `seconds` of it left. */
31
- export const searchBusy = (seconds) => `search is busy; try again in ${seconds} s, or answer from what you have`;
32
- /** The wait a rate limit holds a run's search for when no Retry-After reaches here. */
33
- const DEFAULT_WAIT_MS = 60_000;
34
- /** The longest wait a Retry-After holds a run's search for: 15 minutes. A provider naming hours, or a date far off (a
35
- * clock that is wrong), would stop a long run's search as a quota answer does; past 15 minutes the next call asks. */
36
- const MAX_WAIT_MS = 15 * 60_000;
37
- /** The wait `retryAfter` names, in ms from `nowMs`: delta-seconds, an HTTP date, or Exa's seconds. None, or words that
38
- * read as neither, 60 s; a date already passed, none; never more than 15 minutes (MAX_WAIT_MS). */
39
- export function waitOf(retryAfter, nowMs) {
40
- const said = typeof retryAfter === "string" ? retryAfter.trim() : retryAfter;
41
- const ms = typeof said === "number" ? said * 1_000 : said && /^\d+$/.test(said) ? Number(said) * 1_000 : said ? Date.parse(said) - nowMs : Number.NaN;
42
- return Number.isFinite(ms) ? Math.min(Math.max(ms, 0), MAX_WAIT_MS) : DEFAULT_WAIT_MS;
43
- }
44
- /** `ms` of a wait as searchBusy's seconds: rounded up, at least 1. */
45
- const busyFor = (ms) => ({ error: searchBusy(Math.max(1, Math.ceil(ms / 1_000))) });
46
- export function searchBreaker(now = Date.now) {
47
- let off = false;
48
- let until = 0;
49
- // A marked rate limit (keyless Exa's) has opened a wait in this run, with no search succeeding since.
50
- let marked = false;
51
- return {
52
- held() {
53
- if (off)
54
- return { error: SEARCH_UNAVAILABLE };
55
- const left = until - now();
56
- return left > 0 ? busyFor(left) : undefined;
57
- },
58
- off: () => off,
59
- left: () => Math.max(0, until - now()),
60
- read({ answer, limit }) {
61
- if (!("error" in answer))
62
- marked = false;
63
- if (limit?.kind === "quota")
64
- off = true;
65
- else if (limit) {
66
- const at = now();
67
- // The call that turns search off answers so itself, never its limit's "try again" words.
68
- if (limit.repeatIsQuota && marked && at >= until) {
69
- off = true;
70
- return { error: SEARCH_UNAVAILABLE };
71
- }
72
- else {
73
- if (limit.repeatIsQuota)
74
- marked = true;
75
- until = Math.max(until, at + waitOf(limit.retryAfter, at));
76
- }
77
- }
78
- return answer;
79
- },
80
- };
81
- }
82
- /** The line that ends a search's answer to the model, as Claude Code's WebSearch ends its own. */
83
- export const CITE = "Cite the URL of each result you rely on.";
84
- /** `answer` within SEARCH_MAX_CHARS, as searchText writes it: whole when it fits, else without its least relevant results
85
- * (the last), as many as it takes, `omitted` counting them. */
86
- export function fitSearch(answer) {
87
- if ("error" in answer)
88
- return answer;
89
- const room = SEARCH_MAX_CHARS - CITE.length - 1;
90
- let fitted = answer;
91
- for (let kept = answer.results.length; JSON.stringify(fitted).length > room && kept > 0;) {
92
- kept -= 1;
93
- fitted = { ...answer, results: answer.results.slice(0, kept), omitted: answer.results.length - kept };
94
- }
95
- return fitted;
96
- }
97
- /** A search as the model reads it: its JSON (fitSearch), then the line asking it to cite the URLs it relies on; an
98
- * error's JSON alone. */
99
- export function searchText(answer) {
100
- const fitted = fitSearch(answer);
101
- return "error" in fitted ? JSON.stringify(fitted) : `${JSON.stringify(fitted)}\n${CITE}`;
102
- }
103
- /** A result's text as its snippet: links reduced to their text, whitespace collapsed, cut at SNIPPET_MAX on a word. */
104
- export function snippetOf(raw) {
105
- const text = raw.replace(/!?\[([^\]]*)\]\([^)\s]*\)/g, "$1").replace(/\s+/g, " ").trim();
106
- if (text.length <= SNIPPET_MAX)
107
- return text;
108
- const cut = text.slice(0, SNIPPET_MAX - 1);
109
- const space = cut.lastIndexOf(" ");
110
- return `${(space > SNIPPET_MAX / 2 ? cut.slice(0, space) : cut).trimEnd()}…`;
111
- }
112
- /** `{query, n?}` as every provider takes it: the query trimmed and cut at QUERY_MAX, n 1 to RESULTS_MAX. */
113
- export const searchArgs = (args) => ({
114
- query: typeof args.query === "string" ? args.query.trim().slice(0, QUERY_MAX) : "",
115
- n: Math.max(1, Math.min(RESULTS_MAX, Math.floor(Number(args.n) || RESULTS_DEFAULT))),
116
- });
117
- /** What a Parallel answer's status says of the run's search: out of credit (402), or rate-limited (429) for its
118
- * Retry-After. */
119
- const parallelLimit = (response) => {
120
- if (response.status === 402)
121
- return { kind: "quota" };
122
- const retryAfter = response.headers.get("retry-after");
123
- return response.status === 429 ? { kind: "rate", ...(retryAfter ? { retryAfter } : {}) } : undefined;
124
- };
125
- /** `{query, n?}` searched through `parallel` (null: the run holds no key), as a Search. */
126
- export async function webSearch(args, parallel, signal) {
127
- return (await parallelSearched(args, parallel, signal)).answer;
128
- }
129
- /** webSearch, and the limit Parallel answered for the run's key, if any. */
130
- async function parallelSearched(args, parallel, signal) {
131
- const answer = (search) => ({ answer: search });
132
- const { query, n } = searchArgs(args);
133
- if (!query)
134
- return answer({ error: "web_search needs a query" });
135
- if (!parallel)
136
- return answer({ error: "web_search searches through Parallel, and this run holds no Parallel key (PARALLEL_API_KEY)" });
137
- if (!parallel.live())
138
- return answer({ error: REFUSED });
139
- try {
140
- const response = await parallel.post(PARALLEL_SEARCH_URL, { objective: query, search_queries: [query], mode: "fast", advanced_settings: { max_results: n, excerpt_settings: { max_chars_per_result: SNIPPET_MAX } } }, signal);
141
- if (!response.ok) {
142
- await response.body?.cancel().catch(() => undefined);
143
- const limit = parallelLimit(response);
144
- return parallel.live() ? { answer: { error: `Parallel's search answered ${response.status}` }, ...(limit ? { limit } : {}) } : answer({ error: REFUSED });
145
- }
146
- const { results } = (await response.json());
147
- const hits = (Array.isArray(results) ? results : []).flatMap((row) => {
148
- if (typeof row?.url !== "string")
149
- return [];
150
- const excerpts = Array.isArray(row.excerpts) ? row.excerpts.filter((text) => typeof text === "string") : [];
151
- return [{ url: row.url, title: typeof row.title === "string" ? clip(row.title, TITLE_CAP) : "", snippet: snippetOf(excerpts.join(" … ")), ...(typeof row.publish_date === "string" ? { published: row.publish_date } : {}) }];
152
- });
153
- return answer({ provider: "parallel", query, results: hits.slice(0, n) });
154
- }
155
- catch (error) {
156
- if (error instanceof PaidRefused)
157
- return answer({ error: error.message });
158
- return answer({ error: error?.name === "TimeoutError" ? "Parallel's search did not answer within 60 s" : `Parallel's search failed: ${error?.message ?? String(error)}` });
159
- }
160
- }
161
- /** `{query, n?}` searched by the provider the run's plane resolves web_search to, as a Search. `models`: the run's own
162
- * models a native search goes through (none: a native search has no model to search on). */
10
+ /** `args` searched as the run's web_search, on fresh breakers: a call node's search falls to the next backend as the
11
+ * agent's does, and holds nothing after. */
163
12
  export async function searchFor(env, args, signal, models) {
164
- // One call's breakers: a call node's search falls to the next backend as the agent's does, and holds nothing after.
165
13
  return searched(env, args, breakers(), signal, models);
166
14
  }
167
- /** The most one call of web_search spends across its keyless backends together: Firecrawl's failing or timing out
168
- * leaves Exa what is left of it, never a fresh bound. Firecrawl's own bound inside it (FIRECRAWL_MS, 30 s) leaves Exa
169
- * at least the rest. */
170
- export const KEYLESS_SEARCH_MS = 60_000;
171
- /** The backends a call searching `query` asks in turn, by the provider the run's plane resolves web_search to (with
172
- * keyless Firecrawl, keyless Exa behind it), or why it asks none. Under --faux, Firecrawl is the fake's URL
173
- * (FAUX_FIRECRAWL_ENV) and Exa the faux module's: one the server names none of is not asked, so a test never reaches
174
- * the network. */
175
- async function backendsOf(env, args, signal, models, firecrawlMs) {
176
- const plane = planeOf(env);
177
- const resolved = plane.web_search;
178
- if (resolved === "parallel")
179
- return [{ name: "parallel", ask: () => parallelSearched(args, parallelOf(env), signal) }];
180
- if (resolved !== "native" && resolved !== "exa-keyless" && resolved !== "firecrawl-keyless")
181
- return `web_search does not run here: ${resolved === undefined ? "no provider was resolved for it" : whyUnavailable(resolved)}`;
15
+ async function searched(env, args, breakerOf, signal, models, bounds) {
16
+ const resolved = planeOf(env).web_search;
17
+ if (resolved !== "parallel" && resolved !== "native" && resolved !== "exa-keyless" && resolved !== "firecrawl-keyless")
18
+ return { error: `web_search does not run here: ${resolved === undefined ? "no provider was resolved for it" : whyUnavailable(resolved)}` };
182
19
  const { query, n } = searchArgs(args);
183
- if (!query)
184
- return "web_search needs a query";
185
- if (resolved === "native")
186
- return [{ name: "native", ask: async () => hostedSearched(query, n, plane.model, signal, await models?.()) }];
187
- const faux = Boolean(env[FAUX_ENV]);
188
- const backends = [];
189
- const fakeFirecrawl = faux ? env[FAUX_FIRECRAWL_ENV] : undefined;
190
- if (resolved === "firecrawl-keyless" && (!faux || fakeFirecrawl)) {
191
- backends.push({ name: "firecrawl-keyless", ask: async (deadline) => {
192
- const found = await firecrawlSearch(query, n, { ...(fakeFirecrawl ? { endpoint: fakeFirecrawl } : {}), signal: deadline, ...(firecrawlMs === undefined ? {} : { timeoutMs: firecrawlMs }) });
193
- // Which limit Firecrawl met is the server's to read, never the model's: it reads the error alone.
194
- if (!("error" in found))
195
- return { answer: found };
196
- return { answer: { error: found.error }, ...("limit" in found && found.limit ? { limit: found.limit } : {}) };
197
- } });
198
- }
199
- const fakeExa = await fauxFetch(env, FAUX_EXA_ENV);
200
- if (!faux || fakeExa) {
201
- backends.push({ name: "exa-keyless", ask: async (deadline) => {
202
- const found = await exaSearch(query, n, { ...(fakeExa ? { send: fakeExa } : {}), signal: deadline });
203
- if (!("limit" in found))
204
- return { answer: found };
205
- const limit = exaLimitOf(found);
206
- return { answer: { error: found.error }, ...(limit ? { limit } : {}) };
207
- } });
20
+ if (resolved !== "parallel") {
21
+ if (!query)
22
+ return { error: "web_search needs a query" };
23
+ if (!ordersOf(env).search.length)
24
+ return { error: "web_search: under --faux, the keyless search endpoints are fakes', and this server names none" };
208
25
  }
209
- return backends.length ? backends : "web_search: under --faux, the keyless search endpoints are fakes', and this server names none";
210
- }
211
- /** A call's search through `backends` in turn, each through its breaker (`breakerOf`, by its name) and all under one
212
- * deadline, `boundMs` from the call's start or the caller's `signal`: the first that answers results is the answer,
213
- * and one that fails or that its breaker holds passes the call to the next, unless the deadline is spent: no backend
214
- * starts on a spent one. None left:
215
- * SEARCH_UNAVAILABLE where every backend is off (a lone backend's own answer where it was asked, as its breaker reads
216
- * it), else the last failure, else searchBusy for the shortest wait. */
217
- export async function searchInTurn(backends, breakerOf, signal, boundMs = KEYLESS_SEARCH_MS) {
218
- const deadline = AbortSignal.any([AbortSignal.timeout(boundMs), ...(signal ? [signal] : [])]);
219
- let last;
220
- for (const backend of backends) {
221
- const breaker = breakerOf(backend.name);
222
- if (breaker.held())
223
- continue;
224
- if (last && deadline.aborted)
225
- break;
226
- const answer = breaker.read(await backend.ask(deadline));
227
- if (!("error" in answer))
228
- return answer;
229
- last = answer;
230
- }
231
- const breakers = backends.map((backend) => breakerOf(backend.name));
232
- if (breakers.every((breaker) => breaker.off()))
233
- return backends.length === 1 && last ? last : { error: SEARCH_UNAVAILABLE };
234
- // A backend that turned off in this call while another only waits: the run's search is not off, so it waits.
235
- if (last && !("error" in last && last.error === SEARCH_UNAVAILABLE))
236
- return last;
237
- return busyFor(Math.min(...breakers.filter((breaker) => !breaker.off()).map((breaker) => breaker.left())));
238
- }
239
- /** Breakers by backend name, made at first use: one run's (webSearchTool), or one call's (searchFor). */
240
- const breakers = (now = Date.now) => {
241
- const made = new Map();
242
- return (name) => {
243
- let breaker = made.get(name);
244
- if (!breaker)
245
- made.set(name, (breaker = searchBreaker(now)));
246
- return breaker;
247
- };
248
- };
249
- /** searchFor through `breakerOf`: an error with no backend to ask, else searchInTurn. */
250
- async function searched(env, args, breakerOf, signal, models, bounds = {}) {
251
- const backends = await backendsOf(env, args, signal, models, bounds.firecrawlMs);
252
- return typeof backends === "string" ? { error: backends } : searchInTurn(backends, breakerOf, signal, bounds.searchMs);
253
- }
254
- /** 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
255
- * notice, as its daily count running out answers) is marked repeatIsQuota, so a second one past a wait is that count; a
256
- * 429 with Retry-After is a timed limit, unmarked. A refused connection is no limit (a 403 no wait lifts). */
257
- export function exaLimitOf(found) {
258
- if (found.limit !== "rate_limited")
259
- return undefined;
260
- return found.retryAfterS === undefined ? { kind: "rate", repeatIsQuota: true } : { kind: "rate", retryAfter: found.retryAfterS };
26
+ const { answer } = await searchingOn.run(models, () => webOf(env).search(query, { n, breakers: breakerOf, ...(signal ? { signal } : {}), ...(bounds ? { bounds } : {}) }));
27
+ return answer;
261
28
  }
262
- /** The agent's tool: the Search as JSON text. A run whose web_search resolves to Parallel reads its key as the tool is
263
- * made, when the run opens; one that resolves native searches through `models`, the run's own (ToolHost.search).
264
- * `fake`: what answers each search in the provider's place (a template eval's web fake, web-fake.ts), the provider
265
- * the run's plane names given it, the tool otherwise the same. `now`: the breakers' clock (a test's); `bounds`: a call's
266
- * deadline across its keyless backends and Firecrawl's own inside it (a test's; SearchBounds). */
29
+ /** The agent's tool. The run's Web is made as the tool is bound, so a run whose web_search resolves to Parallel reads its
30
+ * key when the run opens. `fake`: what answers each search in the provider's place (a template eval's web fake,
31
+ * web-fake.ts). `now` and `bounds`: a test's breaker clock and this binding's search deadlines, held by its calls
32
+ * alone. */
267
33
  export function webSearchTool(env, models, fake, now = Date.now, bounds) {
268
34
  const provider = planeOf(env).web_search;
269
35
  const parallel = provider === "parallel";
270
- if (parallel && !fake)
271
- parallelOf(env);
272
- // The run's breakers, one a backend, made with the tool as the run binds it, so they are this run's alone: a call
273
- // every backend's breaker holds answers its words unsent (searchInTurn).
36
+ if (!fake)
37
+ webOf(env);
274
38
  const breakerOf = breakers(now);
275
39
  const named = provider === "native" || provider === "parallel" || provider === "exa-keyless" ? provider : "firecrawl-keyless";
276
40
  return defineTool({
@@ -287,7 +51,7 @@ export function webSearchTool(env, models, fake, now = Date.now, bounds) {
287
51
  },
288
52
  replay: "safe",
289
53
  execute: async (args, _api, context) => {
290
- const answer = fitSearch(fake ? fake(args, named) : await searched(env, args, breakerOf, context?.abortSignal, models, bounds));
54
+ const answer = fake ? fitSearch(fake(args, named)) : await searched(env, args, breakerOf, context?.abortSignal, models, bounds);
291
55
  return forModel(searchText(answer), { details: answer });
292
56
  },
293
57
  });
package/dist/wires.d.ts CHANGED
@@ -14,3 +14,16 @@ export declare const WIRES: Readonly<Record<Wire, {
14
14
  export declare const modelWire: (wire: HarnessWire) => wire is Wire;
15
15
  /** A harness's wire's settings, or undefined for one billed to its own plan (modelWire). */
16
16
  export declare const wireOf: (wire: HarnessWire) => (typeof WIRES)[Wire] | undefined;
17
+ /** The providers whose models the runner's model route translates onto a wire, each with the wires it translates them
18
+ * onto (runner/model-route.ts routeOf, its own fetch: messagesFetch): an Ollama model of this machine (ollama-provider.ts)
19
+ * onto Anthropic's Messages. Every harness on such a wire is offered those models and runs them through the route, at
20
+ * their price, whatever harness it is: the wire decides, never a harness's id. A leaf's data: provider ids by name. */
21
+ export declare const TRANSLATED: Readonly<Record<string, readonly Wire[]>>;
22
+ /** Whether `model`'s requests on a harness of `wire` go through the route's translation (TRANSLATED). */
23
+ export declare const routed: (wire: HarnessWire, model: {
24
+ readonly provider: string;
25
+ }) => boolean;
26
+ /** routed, for a model named `provider/model-id`. */
27
+ export declare const routedId: (wire: HarnessWire, id: string) => boolean;
28
+ /** Whether the route translates any provider's models onto `wire` (TRANSLATED): a harness on it may run on one with no key. */
29
+ export declare const translatesOnto: (wire: HarnessWire) => boolean;
package/dist/wires.js CHANGED
@@ -10,3 +10,14 @@ export const WIRES = Object.freeze({
10
10
  export const modelWire = (wire) => wire !== "plan";
11
11
  /** A harness's wire's settings, or undefined for one billed to its own plan (modelWire). */
12
12
  export const wireOf = (wire) => (modelWire(wire) ? WIRES[wire] : undefined);
13
+ /** The providers whose models the runner's model route translates onto a wire, each with the wires it translates them
14
+ * onto (runner/model-route.ts routeOf, its own fetch: messagesFetch): an Ollama model of this machine (ollama-provider.ts)
15
+ * onto Anthropic's Messages. Every harness on such a wire is offered those models and runs them through the route, at
16
+ * their price, whatever harness it is: the wire decides, never a harness's id. A leaf's data: provider ids by name. */
17
+ export const TRANSLATED = Object.freeze({ ollama: Object.freeze(["anthropic-messages"]) });
18
+ /** Whether `model`'s requests on a harness of `wire` go through the route's translation (TRANSLATED). */
19
+ export const routed = (wire, model) => Object.hasOwn(TRANSLATED, model.provider) && TRANSLATED[model.provider].includes(wire);
20
+ /** routed, for a model named `provider/model-id`. */
21
+ export const routedId = (wire, id) => id.indexOf("/") > 0 && routed(wire, { provider: id.slice(0, id.indexOf("/")) });
22
+ /** Whether the route translates any provider's models onto `wire` (TRANSLATED): a harness on it may run on one with no key. */
23
+ export const translatesOnto = (wire) => Object.values(TRANSLATED).some((wires) => wires.includes(wire));
@@ -36,10 +36,11 @@ export type WorkflowIssue = {
36
36
  message: string;
37
37
  };
38
38
  /**
39
- * Every issue a save of `workflow` as a workflow revision listing `tools` would refuse, and the DSL's warnings: the DSL's
40
- * structural validation (code not run, no input), a call node `via: "tool"` whose tool is not in `tools`
41
- * (`TOOL_NOT_LISTED`; `tools` undefined lists every tool), and what the durable runner refuses before any step (only
42
- * once the DSL found nothing). It writes nothing.
39
+ * Every issue POST /workflows/validate lists for `workflow` as a workflow revision listing `tools`, and the DSL's
40
+ * warnings: the DSL's structural validation (code not run, no input), a call node `via: "tool"` whose tool is not in
41
+ * `tools` (`TOOL_NOT_LISTED`; `tools` undefined lists every tool), and what the durable runner refuses before any step
42
+ * (only once the DSL found nothing). A save asks with no `tools`: its run binds a call node's tool listed or not
43
+ * (tools.ts grantedTools). It writes nothing.
43
44
  */
44
45
  export declare function workflowIssues(workflow: unknown, tools?: readonly string[]): Promise<{
45
46
  issues: WorkflowIssue[];
@@ -7,10 +7,11 @@ export class WorkflowRunUnread extends Error {
7
7
  }
8
8
  const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
9
9
  /**
10
- * Every issue a save of `workflow` as a workflow revision listing `tools` would refuse, and the DSL's warnings: the DSL's
11
- * structural validation (code not run, no input), a call node `via: "tool"` whose tool is not in `tools`
12
- * (`TOOL_NOT_LISTED`; `tools` undefined lists every tool), and what the durable runner refuses before any step (only
13
- * once the DSL found nothing). It writes nothing.
10
+ * Every issue POST /workflows/validate lists for `workflow` as a workflow revision listing `tools`, and the DSL's
11
+ * warnings: the DSL's structural validation (code not run, no input), a call node `via: "tool"` whose tool is not in
12
+ * `tools` (`TOOL_NOT_LISTED`; `tools` undefined lists every tool), and what the durable runner refuses before any step
13
+ * (only once the DSL found nothing). A save asks with no `tools`: its run binds a call node's tool listed or not
14
+ * (tools.ts grantedTools). It writes nothing.
14
15
  */
15
16
  export async function workflowIssues(workflow, tools) {
16
17
  if (!isRecord(workflow))
@@ -1,5 +1,5 @@
1
1
  import { type AttachHub, type ComputerProvider, type HelloResult, type PairedComputer } from "@parcha/agentrun-computer";
2
- import type { PairedComputerRow } from "../store/index.js";
2
+ import type { Claim, PairedComputerRow } from "../store/index.js";
3
3
  import type { ComputerSettingKind, KindRegistry, ProviderEntry } from "./resolve-computer.js";
4
4
  /** A paired computer's id starts with this; the rest is lowercase letters and digits, so the whole is an id an agent's
5
5
  * computer setting takes as its provider (lowercase letters, digits and dashes). */
@@ -8,21 +8,42 @@ export declare const PAIRED_ID_PREFIX = "cmp-";
8
8
  export declare const ATTACHED_IMAGE = "attached";
9
9
  /** How to start a server so its runs can use a paired computer, in one line: the same words wherever it is said. */
10
10
  export declare const ONE_PROCESS_FIX = "start the image with the server options alone, without server-and-runner (outside the image: agentrun-serve without --no-runner)";
11
- /** The words a run gets when its agent's computer is a paired computer and its runner is not in the server's process. */
12
- export declare const ONE_PROCESS_WORDS = "a paired computer's socket is held by the server process it dialed, and this runner runs in a process of its own: start the image with the server options alone, without server-and-runner (outside the image: agentrun-serve without --no-runner)";
11
+ /** The words a run gets when its agent's computer is a paired computer and its runner, in a process of its own, keeps
12
+ * no relay. */
13
+ export declare const ONE_PROCESS_WORDS = "a paired computer's socket is held by the server process it dialed, and this runner runs in a process of its own and relays no computer's socket: give the runner AGENTRUN_PUBLIC_URL (this server's public address), or start the image with the server options alone, without server-and-runner (outside the image: agentrun-serve without --no-runner)";
13
14
  /** What a pairing code, the pair answer and each paired computer say on a server whose runner runs in a process of its
14
- * own (--no-runner; the image's server-and-runner): the computer pairs, and no run here can use it. */
15
- export declare const RUNNER_APART_WORDS = "no run on this server can use a paired computer: its runner runs in a process of its own, and the computer's socket is held by the server's: start the image with the server options alone, without server-and-runner (outside the image: agentrun-serve without --no-runner)";
15
+ * own (--no-runner; the image's server-and-runner) while no runner relays: the computer pairs, and no run here can use
16
+ * it. */
17
+ export declare const RUNNER_APART_WORDS = "no run on this server can use a paired computer: its runner runs in a process of its own and relays no computer's socket: give the runner AGENTRUN_PUBLIC_URL (this server's public address), or start the image with the server options alone, without server-and-runner (outside the image: agentrun-serve without --no-runner)";
16
18
  /** What a provider whose machines dial this server (the computer package's connectOf "dial": Fly Machines, Cloudflare,
17
19
  * and E2B, Daytona or Modal set to dial) says on such a server: its row in GET /v2/computers and its test. Its
18
20
  * machines' sockets are taken by the server's attach hub, and a runner of its own process has none, so its create
19
21
  * refuses (the computer package's hosted/provider.ts, naming the same fix). */
20
22
  export declare const dialApartWords: (label: string) => string;
23
+ /** A runner's relay of the paired computers (dial-relay.ts pairedRelayOn): its hub, where the server moves a box's
24
+ * socket for a run of this runner (a runner apart's own; the server's, for the runner beside it). `bring` routes the
25
+ * box here for `run` (its hold's end `until`, ms; under `claim`, the run's claim, so a superseded claim's take throws
26
+ * Fenced) and resolves once the box is on the hub; it rejects with code computer_unavailable in words (another run
27
+ * holds it, it is not attached, it did not come in time, its claim was cancelled: `signal`, the create's, which drops
28
+ * the route it took at once), never hanging past PAIRED_BRING_MS. `letGo` ends `hold` (once every remove or KILL it
29
+ * sent has answered), then drops the route where no hold is left. */
30
+ export interface PairedRelay {
31
+ readonly hub: AttachHub;
32
+ bring(row: Pick<PairedComputerRow, "id" | "name">, hold: {
33
+ readonly run: string;
34
+ readonly until: number;
35
+ readonly claim?: Claim;
36
+ readonly signal?: AbortSignal;
37
+ }): Promise<void>;
38
+ letGo(computer: string, hold?: string, run?: string): Promise<void>;
39
+ }
21
40
  /** What the claim reads of the paired computers: the store's rows (removed ones left out), and the server's hub where
22
- * the runner shares its process (absent: a runner of its own process). */
41
+ * the runner shares its process, or the runner's relay where it runs in a process of its own and relays (neither: a
42
+ * runner of its own process with no relay). */
23
43
  export interface AttachedComputers {
24
44
  rows(): Promise<readonly PairedComputerRow[]>;
25
45
  readonly hub?: AttachHub;
46
+ readonly relay?: PairedRelay;
26
47
  }
27
48
  /** The store's row as the hub and attachedProvider take it. */
28
49
  export declare const pairedOf: (row: PairedComputerRow) => PairedComputer;
@@ -42,9 +63,11 @@ export declare function servesNoKind(name: string, hello: Partial<HelloResult>):
42
63
  export declare function pairedEntry(row: PairedComputerRow, registry: Pick<KindRegistry, "SETTING_KINDS" | "servingRefusals">): ProviderEntry;
43
64
  /** `registry` with each paired computer of `rows` as one more provider (pairedEntry). */
44
65
  export declare function withPaired<R extends KindRegistry>(registry: R, rows: readonly PairedComputerRow[]): R;
45
- /** The provider of the paired computer `row`: attachedProvider over the hub, or a refusal in ONE_PROCESS_WORDS where this
46
- * process holds no hub. */
47
- export declare function pairedProvider(row: PairedComputerRow, hub: AttachHub | undefined): ComputerProvider;
66
+ /** The provider of the paired computer `row`: over a relay's hub where the runner has one (`relay`: a runner apart's
67
+ * own, or the server's for the runner beside it), the box brought there before each create and let go after each
68
+ * release (relayedProvider); else attachedProvider over the server's hub (`hub`) with no route; else a refusal in
69
+ * ONE_PROCESS_WORDS. `claim`: the run's claim (ClaimLaunch.claim), which the bring's route takes under. */
70
+ export declare function pairedProvider(row: PairedComputerRow, hub: AttachHub | undefined, relay?: PairedRelay, claim?: Claim): ComputerProvider;
48
71
  /** Why the paired computer `row` cannot be had now, in words that say what to do, or undefined: it must be attached (its
49
72
  * driver dialed this server). Asked at a run's start, as a vendor's readiness is; another run's hold is the claim's. */
50
73
  export declare function pairedRefusal(row: PairedComputerRow, hub: Pick<AttachHub, "online"> | undefined): string | undefined;