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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (375) hide show
  1. package/CHANGELOG.md +325 -1
  2. package/README.md +332 -88
  3. package/dist/acp-package.d.ts +5 -1
  4. package/dist/acp-package.js +19 -2
  5. package/dist/adapters.d.ts +23 -2
  6. package/dist/adapters.js +106 -33
  7. package/dist/agents-store.js +1 -1
  8. package/dist/answer-text.d.ts +3 -0
  9. package/dist/answer-text.js +22 -0
  10. package/dist/attach-conformance.js +5 -4
  11. package/dist/box-paths.d.ts +3 -2
  12. package/dist/box-paths.js +5 -4
  13. package/dist/browser-computer.d.ts +3 -8
  14. package/dist/browser-computer.js +12 -35
  15. package/dist/browser-cost.js +94 -20
  16. package/dist/capacity.d.ts +1 -1
  17. package/dist/capacity.js +3 -3
  18. package/dist/chatgpt-plan.d.ts +5 -0
  19. package/dist/chatgpt-plan.js +25 -11
  20. package/dist/claude-login-token.d.ts +15 -11
  21. package/dist/claude-login-token.js +167 -107
  22. package/dist/claude-login.d.ts +76 -31
  23. package/dist/claude-login.js +426 -79
  24. package/dist/claude-sign-in.d.ts +3 -0
  25. package/dist/claude-sign-in.js +10 -1
  26. package/dist/cli.js +323 -292
  27. package/dist/composio-made.d.ts +1 -6
  28. package/dist/composio-made.js +1 -6
  29. package/dist/composio-owners.d.ts +26 -0
  30. package/dist/composio-owners.js +36 -0
  31. package/dist/composio-preset.d.ts +56 -23
  32. package/dist/composio-preset.js +173 -77
  33. package/dist/composio-triggers.d.ts +4 -4
  34. package/dist/composio-triggers.js +6 -7
  35. package/dist/compute-cost.js +11 -2
  36. package/dist/computer-attach.d.ts +6 -3
  37. package/dist/computer-attach.js +41 -29
  38. package/dist/computer-held-routes.d.ts +1 -1
  39. package/dist/computer-held-routes.js +9 -4
  40. package/dist/computer-keys.d.ts +11 -1
  41. package/dist/computer-keys.js +26 -1
  42. package/dist/computer-record.js +3 -1
  43. package/dist/computer-view.d.ts +5 -3
  44. package/dist/computer-view.js +10 -6
  45. package/dist/computer-viewer.js +36 -7
  46. package/dist/computers.d.ts +2 -1
  47. package/dist/computers.js +6 -3
  48. package/dist/console/THIRD-PARTY-NOTICES.txt +50 -0
  49. package/dist/console/assets/backend-BztxEAvb.js +166 -0
  50. package/dist/console/assets/index-LwNL4L9q.js +619 -0
  51. package/dist/console/assets/share-L84tlUDW.js +6 -0
  52. package/dist/console/assets/styles-CaRKlHke.js +291 -0
  53. package/dist/console/assets/styles-DQo8rzY-.css +1 -0
  54. package/dist/console/index.html +4 -3
  55. package/dist/console/share.html +17 -0
  56. package/dist/decisions.d.ts +17 -7
  57. package/dist/decisions.js +41 -15
  58. package/dist/dial-relay.js +10 -4
  59. package/dist/docker-daemon.js +4 -5
  60. package/dist/docker-host-addresses.js +29 -11
  61. package/dist/email/account.d.ts +6 -0
  62. package/dist/email/account.js +6 -0
  63. package/dist/email/authentication.d.ts +21 -0
  64. package/dist/email/authentication.js +106 -0
  65. package/dist/email/email-faux.d.ts +11 -2
  66. package/dist/email/email-faux.js +21 -5
  67. package/dist/email/mail.d.ts +25 -0
  68. package/dist/email/mail.js +58 -2
  69. package/dist/email/names.js +2 -2
  70. package/dist/email/tools.d.ts +9 -4
  71. package/dist/email/tools.js +95 -13
  72. package/dist/env-switch.d.ts +12 -2
  73. package/dist/env-switch.js +23 -3
  74. package/dist/errors.d.ts +1 -0
  75. package/dist/errors.js +2 -0
  76. package/dist/fal-price.d.ts +11 -1
  77. package/dist/fal-price.js +33 -0
  78. package/dist/faux-computers.js +1 -1
  79. package/dist/filed-answer.d.ts +2 -2
  80. package/dist/filed-answer.js +2 -2
  81. package/dist/graph-served.d.ts +10 -5
  82. package/dist/graph-served.js +40 -10
  83. package/dist/handed-values.js +1 -2
  84. package/dist/harness-check.d.ts +2 -1
  85. package/dist/harness-check.js +45 -12
  86. package/dist/harness-keys.js +9 -6
  87. package/dist/harness-opencode/facts.js +2 -0
  88. package/dist/harness-recipe-entry.d.ts +9 -3
  89. package/dist/harness-recipe-entry.js +18 -9
  90. package/dist/harness-recipe.d.ts +21 -0
  91. package/dist/harness-recipe.js +25 -3
  92. package/dist/harness-table.d.ts +8 -0
  93. package/dist/harness-table.js +17 -6
  94. package/dist/helper-env.d.ts +4 -1
  95. package/dist/helper-env.js +4 -1
  96. package/dist/host-check.d.ts +2 -3
  97. package/dist/host-check.js +13 -7
  98. package/dist/hosted-search.js +1 -1
  99. package/dist/import.d.ts +11 -8
  100. package/dist/import.js +437 -186
  101. package/dist/key-refusal.d.ts +9 -2
  102. package/dist/key-refusal.js +86 -32
  103. package/dist/learn/audit.d.ts +8 -5
  104. package/dist/learn/audit.js +15 -7
  105. package/dist/learn/compile.d.ts +5 -2
  106. package/dist/learn/compile.js +45 -21
  107. package/dist/learn/field-check.d.ts +111 -0
  108. package/dist/learn/field-check.js +174 -0
  109. package/dist/learn/ledger.d.ts +32 -29
  110. package/dist/learn/ledger.js +26 -19
  111. package/dist/learn/promote.d.ts +79 -36
  112. package/dist/learn/promote.js +60 -65
  113. package/dist/learn/secrets.d.ts +4 -0
  114. package/dist/learn/secrets.js +12 -0
  115. package/dist/learned-nodes.d.ts +8 -5
  116. package/dist/learned-nodes.js +8 -5
  117. package/dist/learned-workflow.d.ts +2 -1
  118. package/dist/learned-workflow.js +13 -10
  119. package/dist/learning-cost.d.ts +25 -8
  120. package/dist/learning-cost.js +23 -8
  121. package/dist/learning-setting.d.ts +6 -0
  122. package/dist/learning-setting.js +11 -1
  123. package/dist/listen-first.d.ts +5 -4
  124. package/dist/listen-first.js +4 -5
  125. package/dist/live-reach.d.ts +7 -0
  126. package/dist/live-reach.js +7 -0
  127. package/dist/mcp-api-only-origins.d.ts +15 -0
  128. package/dist/mcp-api-only-origins.js +40 -0
  129. package/dist/mcp-gateway.d.ts +16 -2
  130. package/dist/mcp-gateway.js +41 -3
  131. package/dist/mcp-oauth.d.ts +1 -1
  132. package/dist/mcp-oauth.js +3 -2
  133. package/dist/mcp-probe.d.ts +3 -0
  134. package/dist/mcp-probe.js +3 -0
  135. package/dist/mcp-secret-writes.d.ts +24 -2
  136. package/dist/mcp-secret-writes.js +30 -2
  137. package/dist/mcp-servers-store.d.ts +52 -14
  138. package/dist/mcp-servers-store.js +165 -61
  139. package/dist/mcp-sources.d.ts +1 -2
  140. package/dist/mcp-sources.js +1 -2
  141. package/dist/mcp-store.d.ts +5 -5
  142. package/dist/mcp-store.js +3 -3
  143. package/dist/mcp.js +1 -1
  144. package/dist/model-gateway.d.ts +1 -1
  145. package/dist/model-gateway.js +20 -36
  146. package/dist/ollama-provider.d.ts +23 -9
  147. package/dist/ollama-provider.js +49 -20
  148. package/dist/openapi.js +202 -51
  149. package/dist/otel/genai.d.ts +83 -7
  150. package/dist/otel/genai.js +69 -9
  151. package/dist/otel/tracer.d.ts +42 -13
  152. package/dist/otel/tracer.js +241 -56
  153. package/dist/page.d.ts +7 -1
  154. package/dist/page.js +76 -22
  155. package/dist/paid-calls.d.ts +6 -4
  156. package/dist/paid-calls.js +15 -7
  157. package/dist/place-offers.d.ts +55 -34
  158. package/dist/place-offers.js +93 -54
  159. package/dist/place.d.ts +13 -14
  160. package/dist/place.js +56 -41
  161. package/dist/print.js +1 -1
  162. package/dist/provider.d.ts +3 -2
  163. package/dist/provider.js +17 -8
  164. package/dist/redact/match.d.ts +27 -9
  165. package/dist/redact/match.js +266 -57
  166. package/dist/run-census.d.ts +1 -1
  167. package/dist/run-census.js +4 -5
  168. package/dist/run-cut.js +4 -5
  169. package/dist/run-export-store.d.ts +15 -0
  170. package/dist/run-export-store.js +30 -0
  171. package/dist/run-export.d.ts +139 -0
  172. package/dist/run-export.js +379 -0
  173. package/dist/run-file-cut.d.ts +5 -0
  174. package/dist/run-file-cut.js +13 -0
  175. package/dist/run-launch.js +16 -3
  176. package/dist/run-model-key.d.ts +15 -6
  177. package/dist/run-model-key.js +30 -31
  178. package/dist/run-reads-over-store.js +4 -4
  179. package/dist/run-secrets.js +3 -5
  180. package/dist/run-timeline-served.js +3 -1
  181. package/dist/runnable.js +2 -2
  182. package/dist/runner/adapter-loop.d.ts +35 -18
  183. package/dist/runner/adapter-loop.js +94 -47
  184. package/dist/runner/adapter-run-spec.d.ts +14 -1
  185. package/dist/runner/adapter-run-spec.js +64 -28
  186. package/dist/runner/adapters/pi.js +4 -2
  187. package/dist/runner/audit.d.ts +8 -5
  188. package/dist/runner/audit.js +37 -17
  189. package/dist/runner/beside.js +5 -6
  190. package/dist/runner/claim-secrets.d.ts +10 -3
  191. package/dist/runner/claim-secrets.js +29 -13
  192. package/dist/runner/cli-run-spec.d.ts +18 -0
  193. package/dist/runner/cli-run-spec.js +81 -46
  194. package/dist/runner/compare-end.d.ts +2 -1
  195. package/dist/runner/compare-end.js +25 -10
  196. package/dist/runner/conformance/harness.js +2 -3
  197. package/dist/runner/conformance/subject.d.ts +4 -1
  198. package/dist/runner/harness-loops.js +3 -3
  199. package/dist/runner/held.d.ts +5 -2
  200. package/dist/runner/journal-kinds.d.ts +4 -1
  201. package/dist/runner/journal-kinds.js +22 -4
  202. package/dist/runner/learned-first.js +20 -4
  203. package/dist/runner/learning-end.d.ts +2 -8
  204. package/dist/runner/learning-end.js +11 -19
  205. package/dist/runner/live-ticker.js +7 -5
  206. package/dist/runner/loop-contract.d.ts +0 -2
  207. package/dist/runner/loop.d.ts +7 -0
  208. package/dist/runner/loop.js +1 -0
  209. package/dist/runner/main.js +12 -11
  210. package/dist/runner/mcp-claim.js +21 -5
  211. package/dist/runner/meta-tools.js +3 -2
  212. package/dist/runner/metrics.d.ts +7 -0
  213. package/dist/runner/metrics.js +19 -0
  214. package/dist/runner/model-route.d.ts +10 -7
  215. package/dist/runner/model-route.js +79 -15
  216. package/dist/runner/native-loop.js +10 -8
  217. package/dist/runner/presence.d.ts +1 -4
  218. package/dist/runner/presence.js +6 -8
  219. package/dist/runner/promotion.d.ts +25 -13
  220. package/dist/runner/promotion.js +125 -50
  221. package/dist/runner/redact.d.ts +3 -1
  222. package/dist/runner/redact.js +5 -3
  223. package/dist/runner/responses-fetch.d.ts +36 -0
  224. package/dist/runner/responses-fetch.js +511 -0
  225. package/dist/runner/run-child-host.d.ts +20 -5
  226. package/dist/runner/run-child-host.js +179 -77
  227. package/dist/runner/run-child.js +11 -4
  228. package/dist/runner/runner-check.js +5 -1
  229. package/dist/runner/runner.d.ts +2 -3
  230. package/dist/runner/runner.js +13 -9
  231. package/dist/runner/sdk-loop.js +8 -8
  232. package/dist/runner/spec-holds.d.ts +8 -1
  233. package/dist/runner/spec-holds.js +9 -4
  234. package/dist/runner/workflow-calls.d.ts +9 -0
  235. package/dist/runner/workflow-calls.js +150 -0
  236. package/dist/runner/workflow-first.d.ts +120 -32
  237. package/dist/runner/workflow-first.js +218 -94
  238. package/dist/runner/workflow-spec.js +1 -1
  239. package/dist/runs-over-store.js +8 -7
  240. package/dist/save-once.d.ts +14 -0
  241. package/dist/save-once.js +31 -0
  242. package/dist/scrub-command.d.ts +34 -31
  243. package/dist/scrub-command.js +116 -147
  244. package/dist/sdk/runs.d.ts +6 -0
  245. package/dist/sdk/runs.js +89 -10
  246. package/dist/seal-key.js +4 -4
  247. package/dist/secret-cut.d.ts +3 -0
  248. package/dist/secret-cut.js +7 -1
  249. package/dist/secret-rules.d.ts +8 -1
  250. package/dist/secret-rules.js +482 -53
  251. package/dist/secrets.d.ts +51 -9
  252. package/dist/secrets.js +311 -21
  253. package/dist/server-keys.d.ts +4 -3
  254. package/dist/server-keys.js +4 -3
  255. package/dist/server-secrets-store.js +2 -4
  256. package/dist/server.d.ts +15 -3
  257. package/dist/server.js +312 -80
  258. package/dist/share-context.d.ts +22 -0
  259. package/dist/share-context.js +76 -0
  260. package/dist/shell-lex.d.ts +105 -0
  261. package/dist/shell-lex.js +646 -0
  262. package/dist/sign-ins-store.d.ts +5 -7
  263. package/dist/sign-ins-store.js +12 -16
  264. package/dist/sign-ins.d.ts +7 -11
  265. package/dist/sign-ins.js +40 -41
  266. package/dist/skills/agentrun-serve/SKILL.md +5 -2
  267. package/dist/start-switches.d.ts +6 -5
  268. package/dist/start-switches.js +8 -4
  269. package/dist/stats.d.ts +5 -1
  270. package/dist/stats.js +1 -1
  271. package/dist/store/agent-body.js +2 -2
  272. package/dist/store/dialect.d.ts +4 -0
  273. package/dist/store/dialect.js +1 -0
  274. package/dist/store/index.d.ts +2 -2
  275. package/dist/store/index.js +1 -1
  276. package/dist/store/mcp-record-keys.d.ts +10 -0
  277. package/dist/store/mcp-record-keys.js +13 -0
  278. package/dist/store/postgres/dialect.js +2 -0
  279. package/dist/store/postgres/migrations/0029_run_launch_census_settle.sql +28 -0
  280. package/dist/store/postgres/migrations/0030_learning_ledger_epoch.sql +40 -0
  281. package/dist/store/postgres/migrations/0031_learning_ledger_calls.sql +12 -0
  282. package/dist/store/postgres/store.js +4 -0
  283. package/dist/store/schema.d.ts +33 -10
  284. package/dist/store/schema.js +70 -16
  285. package/dist/store/seal.d.ts +4 -1
  286. package/dist/store/sqlite/run-launch.d.ts +3 -10
  287. package/dist/store/sqlite/run-launch.js +12 -23
  288. package/dist/store/sqlite/run-patch.d.ts +17 -10
  289. package/dist/store/sqlite/run-patch.js +50 -13
  290. package/dist/store/sqlite/store.d.ts +3 -0
  291. package/dist/store/sqlite/store.js +116 -34
  292. package/dist/store/store-schema.js +3 -4
  293. package/dist/store/store.d.ts +67 -32
  294. package/dist/store/store.js +14 -11
  295. package/dist/store-reads/analytics.d.ts +2 -1
  296. package/dist/store-reads/analytics.js +7 -5
  297. package/dist/store-reads/learning.d.ts +35 -26
  298. package/dist/store-reads/learning.js +120 -92
  299. package/dist/store-reads/stats.d.ts +2 -2
  300. package/dist/store-reads/stats.js +13 -7
  301. package/dist/store-view.js +10 -7
  302. package/dist/suggestions.d.ts +1 -1
  303. package/dist/suggestions.js +29 -13
  304. package/dist/template-eval.d.ts +72 -9
  305. package/dist/template-eval.js +358 -64
  306. package/dist/timeline/labels.d.ts +1 -1
  307. package/dist/timeline/labels.js +4 -3
  308. package/dist/timeline/timeline.d.ts +23 -11
  309. package/dist/timeline/timeline.js +115 -31
  310. package/dist/timeline/web-calls.d.ts +8 -6
  311. package/dist/timeline/web-calls.js +10 -6
  312. package/dist/tool-gate.d.ts +13 -1
  313. package/dist/tool-gate.js +43 -3
  314. package/dist/tool-keys-store.js +2 -4
  315. package/dist/tool-keys.d.ts +11 -0
  316. package/dist/tool-keys.js +16 -0
  317. package/dist/tool-plane.d.ts +50 -11
  318. package/dist/tool-plane.js +94 -30
  319. package/dist/tools.d.ts +5 -1
  320. package/dist/tools.js +7 -7
  321. package/dist/trigger-email.js +12 -6
  322. package/dist/triggers.d.ts +15 -34
  323. package/dist/triggers.js +119 -126
  324. package/dist/validate.d.ts +8 -1
  325. package/dist/validate.js +163 -23
  326. package/dist/web-fake.d.ts +2 -1
  327. package/dist/web-fake.js +8 -6
  328. package/dist/web-fetch.d.ts +8 -6
  329. package/dist/web-fetch.js +13 -11
  330. package/dist/web-holds.d.ts +32 -0
  331. package/dist/web-holds.js +86 -0
  332. package/dist/web-run.d.ts +32 -5
  333. package/dist/web-run.js +75 -28
  334. package/dist/web-save.js +23 -12
  335. package/dist/web-search.js +14 -25
  336. package/dist/wires.d.ts +4 -3
  337. package/dist/wires.js +5 -4
  338. package/dist/workspace/archil-claim.d.ts +12 -5
  339. package/dist/workspace/archil-claim.js +45 -5
  340. package/dist/workspace/attach.js +52 -19
  341. package/dist/workspace/attached-computers.d.ts +6 -2
  342. package/dist/workspace/attached-computers.js +5 -4
  343. package/dist/workspace/computer-deps.d.ts +23 -6
  344. package/dist/workspace/computer-deps.js +35 -17
  345. package/dist/workspace/computer-for-claim.d.ts +21 -4
  346. package/dist/workspace/computer-for-claim.js +160 -54
  347. package/dist/workspace/computer-intervals.d.ts +2 -0
  348. package/dist/workspace/computer-intervals.js +1 -1
  349. package/dist/workspace/computer-janitor.d.ts +48 -14
  350. package/dist/workspace/computer-janitor.js +153 -44
  351. package/dist/workspace/computer-kept.d.ts +158 -32
  352. package/dist/workspace/computer-kept.js +288 -63
  353. package/dist/workspace/computer-providers.d.ts +8 -3
  354. package/dist/workspace/computer-providers.js +12 -5
  355. package/dist/workspace/index.d.ts +1 -1
  356. package/dist/workspace/index.js +1 -1
  357. package/dist/workspace/local.js +41 -1
  358. package/dist/workspace/mount-revoke-left.d.ts +31 -0
  359. package/dist/workspace/mount-revoke-left.js +72 -0
  360. package/dist/workspace/paired-route.js +4 -5
  361. package/dist/workspace/resolve-computer.d.ts +5 -2
  362. package/dist/workspace/resolve-computer.js +9 -3
  363. package/dist/workspace/run-end-computers.d.ts +11 -5
  364. package/dist/workspace/run-end-computers.js +153 -28
  365. package/dist/workspace/run-tools.d.ts +22 -3
  366. package/dist/workspace/run-tools.js +17 -5
  367. package/dist/workspace/run-workspace.d.ts +14 -1
  368. package/dist/workspace/run-workspace.js +34 -1
  369. package/dist/workspace/workspace.d.ts +6 -0
  370. package/package.json +12 -13
  371. package/skills/agentrun-serve/SKILL.md +5 -2
  372. package/templates/README.md +22 -6
  373. package/dist/console/assets/backend-CSAWUqtZ.js +0 -166
  374. package/dist/console/assets/index-Bwn1oTem.css +0 -1
  375. package/dist/console/assets/index-DPh29cyz.js +0 -747
@@ -32,13 +32,14 @@
32
32
  // and its words kept on the row. The server's tick (every PAIRED_ROUTE_MS) compares each route with where the box's
33
33
  // socket is, and closes a socket that is in the wrong place with 1001: the box's own redial lands where its route says.
34
34
  import { createHash, randomBytes, randomInt } from "node:crypto";
35
- import { ATTACH_CLOSE, ATTACH_HEARTBEAT_MS, ATTACH_IDLE_MS, ATTACH_PATH, ATTACH_SUBPROTOCOL, hostedDaemonPath, MAX_LINE_BYTES, mintedComputer, newMachineToken, PAIRING_CODE_PATTERN, PAIRING_CODE_TTL_MS, PROTOCOL_VERSION, RUN_LABEL } from "@parcha/agentrun-computer";
35
+ import { ATTACH_CLOSE, ATTACH_HEARTBEAT_MS, ATTACH_IDLE_MS, ATTACH_PATH, ATTACH_SUBPROTOCOL, attachSubprotocolOf, helloProblem, hostedDaemonPath, laterProtocol, MAX_LINE_BYTES, mintedComputer, newMachineToken, PAIRING_CODE_PATTERN, PAIRING_CODE_TTL_MS, RUN_LABEL, upgradeRefusal } from "@parcha/agentrun-computer";
36
36
  import { WebSocket, WebSocketServer } from "ws";
37
37
  import { ApiError, invalid } from "./errors.js";
38
- import { dialHost, LIVE_PROOF_HEADER, RELAY_CONNECT_MS, relayProof } from "./live-reach.js";
38
+ import { dialHost, LIVE_PROOF_HEADER, RELAY_CONNECT_MS, RELAY_TOKEN_HEADER, relayProof } from "./live-reach.js";
39
39
  import { peerKey } from "./owner.js";
40
40
  import { registerNotSecretWrite } from "./secret-writes.js";
41
- import { liveRelays, PRESENCE_STALE_MS } from "./runner/presence.js";
41
+ import { liveRelays } from "./runner/presence.js";
42
+ import { RUNNER_STALE_MS } from "./store/index.js";
42
43
  import { pairedOf, PAIRED_ID_PREFIX, RUNNER_APART_WORDS, servesNoKind } from "./workspace/attached-computers.js";
43
44
  import { allRoutes, EMPTY_ROUTE, notAttachedWords, PAIRED_BRING_MS, replaceRoute, ROUTE_COMES_BACK, routeKeyOf, routeRestartedWords, seeRoute } from "./workspace/paired-route.js";
44
45
  // Where they were first defined, for the readers that import them from here.
@@ -179,11 +180,14 @@ export function pairBodyOf(body) {
179
180
  return { code: code, name, hello: hello };
180
181
  }
181
182
  /** Why a driver's hello may not pair here, in the version rule's words (attach.ts helloMismatch), or undefined: its
182
- * protocol version must be this server's. The code stays good, for the driver once it is updated. */
183
+ * protocol version must be one this server takes (helloProblem: 0.2 or a later 0.x). The words name the side to
184
+ * update, and the code stays good, for the driver once it is updated. */
183
185
  export function pairRefusal(name, hello) {
184
- if (hello.protocol === PROTOCOL_VERSION)
186
+ const problem = helloProblem(hello.protocol, "server");
187
+ if (!problem)
185
188
  return undefined;
186
- return `${name}'s driver ${hello.version} speaks protocol ${hello.protocol}, and this server ${PROTOCOL_VERSION}: update whichever is older (the driver on that computer, or this server, which whoever runs it updates), then pair with the same code`;
189
+ const update = laterProtocol(hello.protocol) ? "the server is older, so once whoever runs it updates it, pair" : `update the driver on ${name}, then pair`;
190
+ return `${name}'s driver ${hello.version} ${problem}: ${update} with the same code`;
187
191
  }
188
192
  /** A hello's features as the list shows them: each that is on (true) or off with why ({off: words}); anything else a
189
193
  * driver sent is left out, so a malformed hello never reaches the console as a shape it does not know. */
@@ -327,7 +331,7 @@ export function createAttachRoutes(options) {
327
331
  const fetches = new MinuteLimit(DAEMON_FETCHES_PER_MINUTE, undefined, now);
328
332
  const sockets = new Set();
329
333
  let closing = false;
330
- const wss = new WebSocketServer({ noServer: true, maxPayload: MAX_LINE_BYTES, clientTracking: false, handleProtocols: () => ATTACH_SUBPROTOCOL });
334
+ const wss = new WebSocketServer({ noServer: true, maxPayload: MAX_LINE_BYTES, clientTracking: false, handleProtocols: (asked) => attachSubprotocolOf([...asked]) ?? false });
331
335
  // The server's side of the paired computers' routes (no owner: this is the server, not a runner's listener).
332
336
  /** Each paired computer whose socket is in this hub, by its id: the socket the tick closes for a move. */
333
337
  const home = new Map();
@@ -491,7 +495,7 @@ export function createAttachRoutes(options) {
491
495
  const machineTarget = (row, bearer) => {
492
496
  const runner = row.runner;
493
497
  return {
494
- runner, incarnation: row.incarnation, subject: dialOf(row), whose: "made it",
498
+ runner, incarnation: row.incarnation, token: { authorization: `Bearer ${bearer}` }, subject: dialOf(row), whose: "made it",
495
499
  gone: "its run makes a new machine at its next claim",
496
500
  restarted: `runner ${runner}, which made it, restarted since, and the machine was its earlier process's: its run makes a new machine at its next claim`,
497
501
  event: "machine", named: { ...(row.run !== null ? { run: row.run } : {}), machine: row.machine, runner },
@@ -503,10 +507,10 @@ export function createAttachRoutes(options) {
503
507
  * stale route's refusal drops the route and keeps its words on the row, in one compare-and-set on the row as read: the
504
508
  * box's next dial lands in this hub. Any other refusal is noted on the route, so the claim waiting for the box ends at
505
509
  * once in its words. */
506
- const pairedTarget = (row, route, seen) => {
510
+ const pairedTarget = (row, route, seen, bearer) => {
507
511
  const runner = route.runner;
508
512
  return {
509
- runner, incarnation: route.incarnation, subject: `${row.name} (${row.id}) for run ${route.run}`, whose: "holds it",
513
+ runner, incarnation: route.incarnation, token: { [RELAY_TOKEN_HEADER]: sha256Hex(bearer) }, subject: `${row.name} (${row.id}) for run ${route.run}`, whose: "holds it",
510
514
  gone: ROUTE_COMES_BACK,
511
515
  restarted: routeRestartedWords(runner),
512
516
  event: "computer", named: { run: route.run, computer: row.id, runner },
@@ -541,29 +545,32 @@ export function createAttachRoutes(options) {
541
545
  * name the dial (its run, then the machine or the computer), never its token, where that runner keeps no fresh
542
546
  * listener, restarted since, answers at a host this server does not dial, or does not take it; else the box's socket
543
547
  * is joined to one opened to the runner's listener with the proxy's proof for this token, runner and incarnation, each
544
- * with this module's limits. */
548
+ * with this module's limits. The token goes on that hop as `target.token` names it: a paired box's never as itself. */
545
549
  async function relayDial(target, bearer, req, socket, head, deny) {
546
550
  const { runner, named, event } = target;
547
551
  // Kept before the answer, so whoever reads the row after the 503 (the waiting create, the box's next dial) reads it.
548
- const refuse = async (why, stale = false) => {
549
- const words = `${target.subject}: ${why}`;
550
- log(`${event}_relay_refused`, { ...named, why: words });
551
- await target.keep(words, stale).catch((error) => log(`${event}_relay_refusal_unkept`, { ...named, error: error instanceof Error ? error.message : String(error) }));
552
- deny("503 Service Unavailable", words);
552
+ // The box and the row get `told` where the words name where the runner answers (an internal host and port, a
553
+ // socket's error): the row's words reach a person too (a paired box's hold note, the waiting claim's failure, a
554
+ // minted machine's create), so those stay in the log line alone.
555
+ const refuse = async (why, stale = false, told = why) => {
556
+ const said = `${target.subject}: ${told}`;
557
+ log(`${event}_relay_refused`, { ...named, why: `${target.subject}: ${why}` });
558
+ await target.keep(said, stale).catch((error) => log(`${event}_relay_refusal_unkept`, { ...named, error: error instanceof Error ? error.message : String(error) }));
559
+ deny("503 Service Unavailable", said);
553
560
  };
554
561
  if (options.relay === undefined)
555
562
  return refuse(`runner ${runner} ${target.whose}, and this server relays no dial to a runner`);
556
563
  const at = (await liveRelays(options.relay.runners)).find((row) => row.runner === runner);
557
564
  if (at === undefined)
558
- return refuse(`runner ${runner}, which ${target.whose}, is not running now (no attach listener of its has said it is there for ${PRESENCE_STALE_MS / 1000} s): ${target.gone}`, true);
565
+ return refuse(`runner ${runner}, which ${target.whose}, is not running now (no attach listener of its has said it is there for ${RUNNER_STALE_MS / 1000} s): ${target.gone}`, true);
559
566
  if (at.incarnation !== target.incarnation)
560
567
  return refuse(target.restarted, true);
561
568
  const host = dialHost(at.host, options.relay.reach);
562
569
  if (host === undefined)
563
- return refuse(`runner ${runner}, which ${target.whose}, answers at ${at.host}, which is not one of this server's runners' hosts (AGENTRUN_RUNNER_HOSTS)`);
570
+ return refuse(`runner ${runner}, which ${target.whose}, answers at ${at.host}, which is not one of this server's runners' hosts (AGENTRUN_RUNNER_HOSTS)`, false, `runner ${runner}, which ${target.whose}, answers at a host this server does not dial (AGENTRUN_RUNNER_HOSTS)`);
564
571
  const proof = relayProof(options.relay.reach, { tokenSha256: sha256Hex(bearer), runner, incarnation: at.incarnation });
565
572
  const upstream = new WebSocket(`ws://${host}:${at.port}${ATTACH_PATH}`, ATTACH_SUBPROTOCOL, {
566
- headers: { authorization: `Bearer ${bearer}`, [LIVE_PROOF_HEADER]: proof },
573
+ headers: { ...target.token, [LIVE_PROOF_HEADER]: proof },
567
574
  maxPayload: MAX_LINE_BYTES, perMessageDeflate: false, followRedirects: false, handshakeTimeout: RELAY_CONNECT_MS,
568
575
  });
569
576
  let settled = false;
@@ -578,7 +585,7 @@ export function createAttachRoutes(options) {
578
585
  return;
579
586
  settled = true;
580
587
  // The library's words name the address and the step, never a header.
581
- void refuse(`runner ${runner}, which ${target.whose}, did not answer at ${host}:${at.port} (${error.message})`);
588
+ void refuse(`runner ${runner}, which ${target.whose}, did not answer at ${host}:${at.port} (${error.message})`, false, `runner ${runner}, which ${target.whose}, did not answer`);
582
589
  });
583
590
  upstream.once("open", () => {
584
591
  settled = true;
@@ -604,7 +611,7 @@ export function createAttachRoutes(options) {
604
611
  const done = () => void dialing.delete(row.id);
605
612
  socket.once("close", done);
606
613
  try {
607
- await relayDial(pairedTarget(row, route, seen), bearer, req, socket, head, (status, words) => (done(), deny(status, words)));
614
+ await relayDial(pairedTarget(row, route, seen, bearer), bearer, req, socket, head, (status, words) => (done(), deny(status, words)));
608
615
  }
609
616
  catch (error) {
610
617
  done();
@@ -626,18 +633,24 @@ export function createAttachRoutes(options) {
626
633
  return hostedDaemonPath(arch);
627
634
  }
628
635
  /** GET /v2/computers/attach's upgrade: the token's paired computer or minted machine, then the protocol, then the hub's
629
- * hello. A refusal is an HTTP answer before the upgrade (401 for a token neither has good, 426 for another protocol
630
- * version). A minted machine's socket goes to the hub under its name. */
631
- function upgrade(req, socket, head, deny) {
636
+ * hello. A refusal is an HTTP answer before the upgrade (401 for a token neither has good, 426 when no
637
+ * subprotocol it asks for names a protocol this server takes, in words naming the side to update: upgradeRefusal). A
638
+ * minted machine's socket goes to the hub under its name.
639
+ *
640
+ * On a runner's listener (`owner`), a paired computer's token comes as `hop`, its SHA-256 alone as the server's
641
+ * relay hop names it (dial-relay.ts reads it off RELAY_TOKEN_HEADER, its proof checked): a paired token as a bearer
642
+ * is one it does not know, and a hash finds no minted machine (whose token comes as its bearer). */
643
+ function upgrade(req, socket, head, deny, hop) {
632
644
  void (async () => {
633
645
  if (closing)
634
646
  return deny("503 Service Unavailable", "this server is stopping");
635
647
  const bearer = bearerOf(req.headers.authorization);
636
- const found = !options.machinesOnly && bearer?.startsWith(ATTACH_TOKEN_PREFIX) ? await paired.byToken(sha256Hex(bearer)) : undefined;
648
+ const pairedSha256 = options.owner ? hop?.tokenSha256 : bearer?.startsWith(ATTACH_TOKEN_PREFIX) ? sha256Hex(bearer) : undefined;
649
+ const found = !options.machinesOnly && pairedSha256 !== undefined ? await paired.byToken(pairedSha256) : undefined;
637
650
  // On a runner's listener, a paired computer's token is taken only while its route names this runner and incarnation:
638
651
  // any other is one it does not know.
639
652
  const row = found !== undefined && options.owner !== undefined && !(await routedHere(found.id)) ? undefined : found;
640
- const machine = found === undefined ? await machineBy(req.headers.authorization) : undefined;
653
+ const machine = found === undefined && hop === undefined ? await machineBy(req.headers.authorization) : undefined;
641
654
  // Another runner's machine, on the server: relayed to that runner's listener below. On a runner's listener, a token
642
655
  // of any other's (another runner's, another incarnation's, the server's) is one it does not know.
643
656
  const relayed = machine !== undefined && !options.owner && machine.runner !== null;
@@ -645,9 +658,8 @@ export function createAttachRoutes(options) {
645
658
  if (dialer === undefined)
646
659
  return deny("401 Unauthorized", options.machinesOnly ? MACHINE_TOKEN_REFUSED : TOKEN_REFUSED, { "www-authenticate": "Bearer" });
647
660
  const asked = String(req.headers["sec-websocket-protocol"] ?? "").split(",").map((one) => one.trim()).filter(Boolean);
648
- if (!asked.includes(ATTACH_SUBPROTOCOL)) {
649
- return deny("426 Upgrade Required", `this server speaks ${ATTACH_SUBPROTOCOL}, and the driver asked for ${asked.join(", ") || "no subprotocol"}: update whichever is older`, { "sec-websocket-protocol": ATTACH_SUBPROTOCOL });
650
- }
661
+ if (attachSubprotocolOf(asked) === undefined)
662
+ return deny("426 Upgrade Required", upgradeRefusal(dialer.computer, asked), { "sec-websocket-protocol": ATTACH_SUBPROTOCOL });
651
663
  // A paired computer on the server: its route says where its socket goes (no route, or a run's of the runner beside
652
664
  // this server: this hub).
653
665
  const routed = row !== undefined && !options.owner && settings !== undefined ? await seeRoute(settings, row.id) : undefined;
@@ -21,7 +21,7 @@ export declare function heldField(store: HeldStore, runId: string, options?: Hel
21
21
  * the one its place says; released once a stop let it go, or while the run is parked with it let go (releasedAtPark); taken_over while the owner holds its desktop or phone (computerHoldOf, read from the run's
22
22
  * journal only while that computer is up) or its browser (browserHeld, one settings read while it is up); with `held` for a run that holds its computer for its owner. The journal is
23
23
  * read at most once, and not at all for a run that neither can be taken over nor holds. `view` is the run read so far. */
24
- export declare function runComputerRead(store: HeldStore & Pick<Store, "agents" | "settings">, runId: string, view: Record<string, unknown>, options?: HeldOptions): Promise<{
24
+ export declare function runComputerRead(store: HeldStore & Pick<Store, "agents" | "settings" | "sealedKeys">, runId: string, view: Record<string, unknown>, options?: HeldOptions): Promise<{
25
25
  computer?: Record<string, unknown>;
26
26
  }>;
27
27
  /**
@@ -40,12 +40,17 @@ export async function heldField(store, runId, options = {}) {
40
40
  return { state, minutes: read.minutes, ...(state === "released" ? {} : { until: new Date(read.until).toISOString() }), ...(read.why ? { why: read.why } : {}) };
41
41
  }
42
42
  /** Whether parked run `runId`'s computer of `kind` was let go: a park's claim releases it but for a desktop, a phone or a
43
- * sandbox kept for the resume, until its keep's time (workspace/computer-kept.ts). A browser's is said on its own read. */
44
- async function releasedAtPark(store, runId, kind, now) {
43
+ * sandbox kept for the resume, until its keep's time (workspace/computer-kept.ts). A browser's is said on its own read.
44
+ * The keep's `until` was stamped on the store's clock (Kept.until), so its time is judged on it, as the run's computer
45
+ * view judges it (server.ts getRunComputer); a clock that can't be read judges no time, as that view does. */
46
+ async function releasedAtPark(store, runId, kind) {
45
47
  if (kind === "browser")
46
48
  return false;
47
49
  const kept = await readKept(store.settings, runId).catch(() => undefined);
48
- return !kept || kept.kind !== kind || kept.ended === true || kept.ending === true || now >= kept.until;
50
+ if (!kept || kept.kind !== kind || kept.ended === true || kept.ending === true)
51
+ return true;
52
+ const at = await store.sealedKeys.clock().catch(() => undefined);
53
+ return at !== undefined && at >= kept.until;
49
54
  }
50
55
  /** The run read's `computer` field (`{ computer }`, or nothing for a run with none): its revision's computer setting, else
51
56
  * the one its place says; released once a stop let it go, or while the run is parked with it let go (releasedAtPark); taken_over while the owner holds its desktop or phone (computerHoldOf, read from the run's
@@ -59,7 +64,7 @@ export async function runComputerRead(store, runId, view, options = {}) {
59
64
  const error = view.error;
60
65
  // A stop lets the run's computer go (the run's row is final until a follow-up queues it again); a park keeps a desktop,
61
66
  // a phone or a sandbox only for its keep's time.
62
- const released = run?.state === "stopped" || (run?.state === "parked" && (await releasedAtPark(store, runId, setting.kind, options.now?.() ?? Date.now())));
67
+ const released = run?.state === "stopped" || (run?.state === "parked" && (await releasedAtPark(store, runId, setting.kind)));
63
68
  const read = { id: runId, status: String(view.status), ...(error && typeof error.code === "string" ? { error: { code: error.code, message: String(error.message ?? "") } } : {}), ...(released ? { released } : {}) };
64
69
  // The run's journal, read at most once for the whole field (the hold and `held` both read it), and only when one needs
65
70
  // it: a long run's every poll would pay for a read that grows with it.
@@ -1,4 +1,4 @@
1
- import { type ProviderEntry } from "@parcha/agentrun-computer";
1
+ import { type ComputerProvider, type ProviderEntry } from "@parcha/agentrun-computer";
2
2
  /** One key a provider takes: its name in its descriptor, the create() option it fills, and whether it is needed. */
3
3
  export interface ProviderKey {
4
4
  readonly name: string;
@@ -83,6 +83,16 @@ export declare function providerOptions(providerId: string, keys: Readonly<Recor
83
83
  /** The create() options provider `providerId`'s settings fill from the server's settings (each of its descriptor's
84
84
  * settings, by name, else its default), with no key: what a provider is made with that is no secret (its connect). */
85
85
  export declare function settingOptions(providerId: string, settings?: ProviderSettings, table?: KeyTable): Record<string, string>;
86
+ /**
87
+ * Provider `providerId` of the registry, made from what `env` holds by its descriptor's names: its keys (KEY_TABLE, as
88
+ * providerOptions takes them) and the server's own variables it reads (hostEnv: the gateway a server behind one reaches
89
+ * the vendor through), as the claim's providers get them (workspace/computer-deps.ts). `fetch` stands in for the
90
+ * provider's own where it takes one (the tests' fakes under faux). Refused, in words naming what to save, when a required
91
+ * key is missing; `invalid`, in the provider's words, when it cannot be made from them.
92
+ */
93
+ export declare function providerFromEnv(providerId: string, env: NodeJS.ProcessEnv, { fetch: fetcher }?: {
94
+ fetch?: typeof fetch;
95
+ }): Promise<KeyResult<ComputerProvider>>;
86
96
  /**
87
97
  * The values Settings offers for provider `providerId`'s picked key `keyName` (its descriptor key's picked), read by the
88
98
  * provider made from its saved keys (its keyChoices, by the option the key fills), never making a computer. ok with each
@@ -10,8 +10,9 @@
10
10
  // in (workspace/computer-providers.ts makes the computer package's; a test gives stand-ins): a provider with no module
11
11
  // here answers that its test is not available. No key is ever in an answer: each value is scrubbed from the provider's
12
12
  // words, and the words this module adds name keys only by their names.
13
- import { PROVIDERS } from "@parcha/agentrun-computer";
13
+ import { PROVIDERS, providerFor, SDK_MISSING } from "@parcha/agentrun-computer";
14
14
  import { keyShaped } from "./secret-name.js";
15
+ import { hostEnvOf } from "./workspace/computer-providers.js";
15
16
  /** The key table of `entries` (the kind registry's PROVIDERS, each from its descriptor). */
16
17
  export function keyTableOf(entries) {
17
18
  return {
@@ -65,6 +66,27 @@ export function settingOptions(providerId, settings = {}, table = KEY_TABLE) {
65
66
  }
66
67
  return options;
67
68
  }
69
+ /**
70
+ * Provider `providerId` of the registry, made from what `env` holds by its descriptor's names: its keys (KEY_TABLE, as
71
+ * providerOptions takes them) and the server's own variables it reads (hostEnv: the gateway a server behind one reaches
72
+ * the vendor through), as the claim's providers get them (workspace/computer-deps.ts). `fetch` stands in for the
73
+ * provider's own where it takes one (the tests' fakes under faux). Refused, in words naming what to save, when a required
74
+ * key is missing; `invalid`, in the provider's words, when it cannot be made from them.
75
+ */
76
+ export async function providerFromEnv(providerId, env, { fetch: fetcher } = {}) {
77
+ const keys = Object.fromEntries((KEY_TABLE.keys[providerId] ?? []).flatMap((key) => (typeof env[key.name] === "string" && env[key.name] !== "" ? [[key.name, env[key.name]]] : [])));
78
+ const options = providerOptions(providerId, keys);
79
+ if (!options.ok)
80
+ return options;
81
+ const names = PROVIDERS.find((one) => one.id === providerId)?.hostEnv;
82
+ const hostEnv = names ? { env: hostEnvOf(env, names) } : {};
83
+ try {
84
+ return { ok: true, value: await providerFor(providerId, { ...options.options, ...hostEnv, ...(fetcher ? { fetch: fetcher } : {}) }) };
85
+ }
86
+ catch (error) {
87
+ return refused("invalid", scrub(messageOf(error), Object.values(keys)));
88
+ }
89
+ }
68
90
  /** `text` with every key value in `values` replaced by "[the key]". */
69
91
  function scrub(text, values) {
70
92
  let out = text;
@@ -119,6 +141,9 @@ async function builtFrom(providerId, keys, factories, settings, table, what) {
119
141
  return { ok: true, value: { provider: await create(made.options), label, values } };
120
142
  }
121
143
  catch (error) {
144
+ // The vendor's SDK is not installed here: its words name the package and the install step, and nothing else is wrong.
145
+ if (error?.code === SDK_MISSING)
146
+ return refused(SDK_MISSING, scrub(messageOf(error), values));
122
147
  return refused("invalid", wordsFor("invalid", providerId, scrub(messageOf(error), values), table));
123
148
  }
124
149
  }
@@ -27,6 +27,7 @@
27
27
  import { spawn } from "node:child_process";
28
28
  import { mkdir, readdir, stat } from "node:fs/promises";
29
29
  import { join } from "node:path";
30
+ import { helperEnv } from "./helper-env.js";
30
31
  import { commandOnPath } from "./host-command.js";
31
32
  /** The program that encodes the video. */
32
33
  export const FFMPEG = "ffmpeg";
@@ -180,7 +181,8 @@ export function startRecording(input) {
180
181
  return undefined;
181
182
  }
182
183
  const [width, height] = fitted(frame.frameWidth, frame.frameHeight, limits.edge);
183
- const child = spawn(input.ffmpeg ?? FFMPEG, argsOf(frame.format, width, height, path), { stdio: ["pipe", "ignore", "pipe"] });
184
+ // A helper program's environment (PATH, the locale, TMPDIR), never the server's own, which holds its secrets.
185
+ const child = spawn(input.ffmpeg ?? FFMPEG, argsOf(frame.format, width, height, path), { stdio: ["pipe", "ignore", "pipe"], env: helperEnv() });
184
186
  let exited;
185
187
  const opened = { child, format: frame.format, name, path, exited: new Promise((resolve) => (exited = resolve)), dead: false, ending: false, stderr: "" };
186
188
  /** Set when ffmpeg did not start (its 'error' comes before any 'close'). */
@@ -36,9 +36,11 @@ export type ComputerAnswer = {
36
36
  hold: ComputerHold;
37
37
  };
38
38
  /** Why a parked run's kept computer of `kind` is not kept any more, from its keep's row (computer-kept.ts): its time
39
- * passed or its end began, in the timeout's words, at that time; nothing while it is kept, with no row, or with one of
40
- * another kind (a sandbox's: it has no screen). Only for a run still parked: a resumed run's row, taken or left ended,
41
- * says nothing. */
39
+ * passed, in the timeout's words, at that time; its end begun before its time (a claim that could not reach it gave its
40
+ * row back for its runner to end, or a later park kept nothing beside that runner's row), not kept with no reason, at
41
+ * `now` (its `until` is no time of this run's, and is still to come); nothing while it is kept, with no row, or with one
42
+ * of another kind (a sandbox's: it has no screen). Only for a run still parked: a resumed run's row, taken or left
43
+ * ended, says nothing. `now` is on the store's clock, the one the row's `until` was stamped on. */
42
44
  export declare function lapsedOf(kind: ComputerKind, kept: Kept | undefined, now: number): {
43
45
  at: string;
44
46
  why: string;
@@ -3,19 +3,23 @@
3
3
  // run holds the keys it started with). With none open, the run's computer says `none` with its kind and where its session
4
4
  // is (never opened, opening, closed), or `off` with why there is no computer here. `hold` is who drives now. A parked
5
5
  // run's desktop or phone kept at its park is `closed` (the run's timeline says until when), then `ended` in the timeout's
6
- // words once its time passed.
6
+ // words once its time passed, or `ended` as not kept, with no reason, once its end began before that time.
7
7
  import { KINDS } from "./runner/journal-kinds.js";
8
8
  import { BROWSER_STEPS } from "./timeline/labels.js";
9
- import { lapsedWords } from "./workspace/computer-kept.js";
9
+ import { lapsedWords, unkeptWords } from "./workspace/computer-kept.js";
10
10
  /** Why a parked run's kept computer of `kind` is not kept any more, from its keep's row (computer-kept.ts): its time
11
- * passed or its end began, in the timeout's words, at that time; nothing while it is kept, with no row, or with one of
12
- * another kind (a sandbox's: it has no screen). Only for a run still parked: a resumed run's row, taken or left ended,
13
- * says nothing. */
11
+ * passed, in the timeout's words, at that time; its end begun before its time (a claim that could not reach it gave its
12
+ * row back for its runner to end, or a later park kept nothing beside that runner's row), not kept with no reason, at
13
+ * `now` (its `until` is no time of this run's, and is still to come); nothing while it is kept, with no row, or with one
14
+ * of another kind (a sandbox's: it has no screen). Only for a run still parked: a resumed run's row, taken or left
15
+ * ended, says nothing. `now` is on the store's clock, the one the row's `until` was stamped on. */
14
16
  export function lapsedOf(kind, kept, now) {
15
17
  if (!kept || kept.kind !== kind)
16
18
  return undefined;
17
- if (kept.ended || kept.ending || now >= kept.until)
19
+ if (now >= kept.until)
18
20
  return { at: new Date(kept.until).toISOString(), why: lapsedWords(kind) };
21
+ if (kept.ended || kept.ending)
22
+ return { at: new Date(now).toISOString(), why: unkeptWords(kind) };
19
23
  return undefined;
20
24
  }
21
25
  export async function computerView(deps) {
@@ -78,15 +78,43 @@ const js = `"use strict";
78
78
  var drive = $("drive");
79
79
  var handsEl = $("hands");
80
80
  function focusScreen() { try { sink.focus({ preventScroll: true }); } catch (e) { canvas.focus(); } }
81
+ // The newest frame's image, kept to draw again when the stage changes size.
82
+ var shown = null;
83
+ // The screen's box: the frame's shape fitted in the stage, counted in device pixels, and the canvas's own pixels the
84
+ // same as the device's under it (its CSS size times devicePixelRatio). The frame is then scaled once, by drawImage at
85
+ // its best smoothing, never again by the browser: a canvas of the frame's own size, stretched by CSS to a box of
86
+ // another size, came out soft. What is left beside it is kept even, so the centred canvas starts on a whole pixel.
81
87
  function fit() {
82
- if (!canvas.width || !canvas.height) return;
88
+ if (!shown) return;
83
89
  var box = stage.getBoundingClientRect();
84
- var scale = Math.min(box.width / canvas.width, box.height / canvas.height);
90
+ var dpr = window.devicePixelRatio > 0 ? window.devicePixelRatio : 1;
91
+ var scale = Math.min(box.width / shown.width, box.height / shown.height);
85
92
  if (!(scale > 0)) return;
86
- canvas.style.width = Math.floor(canvas.width * scale) + "px";
87
- canvas.style.height = Math.floor(canvas.height * scale) + "px";
93
+ var across = Math.round(box.width * dpr), down = Math.round(box.height * dpr);
94
+ var w = Math.min(across, Math.round(shown.width * scale * dpr)), h = Math.min(down, Math.round(shown.height * scale * dpr));
95
+ w -= (across - w) % 2; h -= (down - h) % 2;
96
+ if (!(w > 0 && h > 0)) return;
97
+ if (canvas.width !== w || canvas.height !== h) { canvas.width = w; canvas.height = h; }
98
+ canvas.style.width = w / dpr + "px";
99
+ canvas.style.height = h / dpr + "px";
100
+ paint();
101
+ }
102
+ // A canvas given a new size resets its context, so the smoothing is set on every draw.
103
+ function paint() {
104
+ if (!shown || !canvas.width) return;
105
+ ctx.imageSmoothingEnabled = true;
106
+ ctx.imageSmoothingQuality = "high";
107
+ ctx.drawImage(shown, 0, 0, canvas.width, canvas.height);
88
108
  }
89
109
  if (typeof ResizeObserver === "function") new ResizeObserver(fit).observe(stage); else window.addEventListener("resize", fit);
110
+ // The window moved to a screen of another density: its CSS size is the same, its device pixels are not.
111
+ function watchDensity() {
112
+ if (typeof window.matchMedia !== "function") return;
113
+ var query = window.matchMedia("(resolution: " + (window.devicePixelRatio || 1) + "dppx)");
114
+ var changed = function () { query.removeEventListener("change", changed); fit(); watchDensity(); };
115
+ query.addEventListener("change", changed);
116
+ }
117
+ watchDensity();
90
118
 
91
119
  var fatal = false;
92
120
  function say(text, isFatal) {
@@ -144,9 +172,10 @@ const js = `"use strict";
144
172
  var h = view.getUint16(2);
145
173
  var bytes = new Uint8Array(buffer, 4);
146
174
  createImageBitmap(new Blob([bytes], { type: formatOf(bytes) })).then(function (bitmap) {
147
- if (canvas.width !== bitmap.width || canvas.height !== bitmap.height) { canvas.width = bitmap.width; canvas.height = bitmap.height; fit(); }
148
- ctx.drawImage(bitmap, 0, 0);
149
- if (bitmap.close) bitmap.close();
175
+ var before = shown;
176
+ shown = bitmap;
177
+ if (!before || before.width !== bitmap.width || before.height !== bitmap.height) fit(); else paint();
178
+ if (before && before.close) before.close();
150
179
  frame = { w: w || bitmap.width, h: h || bitmap.height };
151
180
  document.body.dataset.frames = String(Number(document.body.dataset.frames || "0") + 1);
152
181
  }, function () {}).then(function () { raw({ type: "ack" }); });
@@ -164,7 +164,8 @@ export declare const COMPUTER_UNAVAILABLE = "computer_unavailable";
164
164
  * computer that binds a local folder (Docker) reaches; Mode 2 keeps it on the owner's disk, which a computer holds as an
165
165
  * Archil mount where its provider takes one and Archil's image is here, else as a synced folder the runner keeps on the
166
166
  * disk (never a local Docker bind). A desktop, phone or browser holds no folder unless its provider takes one, so either
167
- * mode takes it. `provider` is as this server has it (resolve-computer.ts entryHere). */
167
+ * mode takes it. `provider` is as this server has it (resolve-computer.ts entryHere). In Mode 1, a provider that would
168
+ * hold the folder in Mode 2 is told how to get there: Archil on, in Settings → Workspace. */
168
169
  export declare function modeRefusal(kind: ComputerKind, provider: ProviderEntry, mode: FolderMode): string | undefined;
169
170
  /** The routes' work over the server's store: GET /v2/computers (view), PUT /v2/computers/{provider}/keys (saveKeys), POST
170
171
  * /v2/computers/{provider}/test (test), GET /v2/computers/{provider}/choices (choices), and the provider of an agent's
package/dist/computers.js CHANGED
@@ -90,12 +90,15 @@ export const COMPUTER_UNAVAILABLE = "computer_unavailable";
90
90
  * computer that binds a local folder (Docker) reaches; Mode 2 keeps it on the owner's disk, which a computer holds as an
91
91
  * Archil mount where its provider takes one and Archil's image is here, else as a synced folder the runner keeps on the
92
92
  * disk (never a local Docker bind). A desktop, phone or browser holds no folder unless its provider takes one, so either
93
- * mode takes it. `provider` is as this server has it (resolve-computer.ts entryHere). */
93
+ * mode takes it. `provider` is as this server has it (resolve-computer.ts entryHere). In Mode 1, a provider that would
94
+ * hold the folder in Mode 2 is told how to get there: Archil on, in Settings → Workspace. */
94
95
  export function modeRefusal(kind, provider, mode) {
95
96
  if (kind !== "sandbox")
96
97
  return undefined;
97
- if (mode === "local" && !provider.mounts.includes("bind"))
98
- return `${provider.label} can't mount this server's run folders (they are on its own disk): set this agent's computer to sandbox on Docker, or none (Settings → Computers)`;
98
+ if (mode === "local" && !provider.mounts.includes("bind")) {
99
+ const archil = folderKindOf(provider, 2) === undefined ? "" : "keep run folders on an Archil disk instead (turn on Archil in Settings → Workspace), or ";
100
+ return `${provider.label} can't mount this server's run folders (they are on its own disk): ${archil}set this agent's computer to sandbox on Docker, or none (Settings → Computers)`;
101
+ }
99
102
  if (mode === "disk" && folderKindOf(provider, 2) === undefined) {
100
103
  const why = [provider.unmounted?.archil, provider.unmounted?.sync].filter((one) => one !== undefined).join("; ");
101
104
  return `${provider.label} can't mount the owner's disk this server keeps run folders on${why ? ` (${why})` : ""}: set this agent's computer to a sandbox that mounts it, or none (Settings → Computers)`;
@@ -340,6 +340,56 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
340
340
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
341
341
  SOFTWARE.
342
342
 
343
+ ------------------------------------------------------------------------------
344
+ @tanstack/react-virtual 3.14.26 (MIT)
345
+
346
+ MIT License
347
+
348
+ Copyright (c) 2021-present Tanner Linsley
349
+
350
+ Permission is hereby granted, free of charge, to any person obtaining a copy
351
+ of this software and associated documentation files (the "Software"), to deal
352
+ in the Software without restriction, including without limitation the rights
353
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
354
+ copies of the Software, and to permit persons to whom the Software is
355
+ furnished to do so, subject to the following conditions:
356
+
357
+ The above copyright notice and this permission notice shall be included in all
358
+ copies or substantial portions of the Software.
359
+
360
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
361
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
362
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
363
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
364
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
365
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
366
+ SOFTWARE.
367
+
368
+ ------------------------------------------------------------------------------
369
+ @tanstack/virtual-core 3.19.11 (MIT)
370
+
371
+ MIT License
372
+
373
+ Copyright (c) 2021-present Tanner Linsley
374
+
375
+ Permission is hereby granted, free of charge, to any person obtaining a copy
376
+ of this software and associated documentation files (the "Software"), to deal
377
+ in the Software without restriction, including without limitation the rights
378
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
379
+ copies of the Software, and to permit persons to whom the Software is
380
+ furnished to do so, subject to the following conditions:
381
+
382
+ The above copyright notice and this permission notice shall be included in all
383
+ copies or substantial portions of the Software.
384
+
385
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
386
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
387
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
388
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
389
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
390
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
391
+ SOFTWARE.
392
+
343
393
  ------------------------------------------------------------------------------
344
394
  class-variance-authority 0.7.1 (Apache-2.0)
345
395