@qvac/core 0.5.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (399) hide show
  1. package/CHANGELOG.md +92 -1
  2. package/dist-lib/lib/api/agents.js +3 -2
  3. package/dist-lib/lib/api/app-config.d.ts +1 -1
  4. package/dist-lib/lib/api/app-config.js +54 -15
  5. package/dist-lib/lib/api/attachments.d.ts +6 -5
  6. package/dist-lib/lib/api/attachments.js +4 -2
  7. package/dist-lib/lib/api/chat.d.ts +7 -3
  8. package/dist-lib/lib/api/chat.js +4 -4
  9. package/dist-lib/lib/api/chunks.js +3 -3
  10. package/dist-lib/lib/api/config.js +2 -2
  11. package/dist-lib/lib/api/current-mesh.d.ts +3 -4
  12. package/dist-lib/lib/api/current-mesh.js +9 -4
  13. package/dist-lib/lib/api/custom-models.d.ts +8 -1
  14. package/dist-lib/lib/api/custom-models.js +53 -16
  15. package/dist-lib/lib/api/devices.d.ts +14 -5
  16. package/dist-lib/lib/api/devices.js +13 -8
  17. package/dist-lib/lib/api/diagnostics.d.ts +1 -0
  18. package/dist-lib/lib/api/diagnostics.js +1 -1
  19. package/dist-lib/lib/api/effective-ctx-size.d.ts +6 -1
  20. package/dist-lib/lib/api/effective-ctx-size.js +5 -3
  21. package/dist-lib/lib/api/execution.js +2 -1
  22. package/dist-lib/lib/api/files.js +2 -1
  23. package/dist-lib/lib/api/index.d.ts +5 -1
  24. package/dist-lib/lib/api/index.js +101 -102
  25. package/dist-lib/lib/api/instrument.js +29 -20
  26. package/dist-lib/lib/api/knowledge.d.ts +6 -5
  27. package/dist-lib/lib/api/knowledge.js +8 -6
  28. package/dist-lib/lib/api/local-files.js +1 -1
  29. package/dist-lib/lib/api/logs.js +6 -3
  30. package/dist-lib/lib/api/members.js +22 -13
  31. package/dist-lib/lib/api/mesh.js +3 -3
  32. package/dist-lib/lib/api/model-download.js +1 -1
  33. package/dist-lib/lib/api/network.d.ts +1 -0
  34. package/dist-lib/lib/api/network.js +1 -1
  35. package/dist-lib/lib/api/notifications.js +23 -13
  36. package/dist-lib/lib/api/rag.d.ts +6 -1
  37. package/dist-lib/lib/api/rag.js +20 -11
  38. package/dist-lib/lib/api/range.d.ts +2 -2
  39. package/dist-lib/lib/api/sync.js +1 -1
  40. package/dist-lib/lib/api/tool-activity.js +7 -3
  41. package/dist-lib/lib/api/tool-configs.js +2 -4
  42. package/dist-lib/lib/api/upload-frames.d.ts +7 -8
  43. package/dist-lib/lib/api/upload-frames.js +2 -1
  44. package/dist-lib/lib/api/watchable.d.ts +6 -1
  45. package/dist-lib/lib/api/watchable.js +23 -14
  46. package/dist-lib/lib/assistant/fetch-body.js +4 -2
  47. package/dist-lib/lib/assistant/harness.d.ts +48 -27
  48. package/dist-lib/lib/assistant/harness.js +40 -16
  49. package/dist-lib/lib/assistant/history.d.ts +9 -7
  50. package/dist-lib/lib/assistant/history.js +77 -42
  51. package/dist-lib/lib/assistant/message.d.ts +5 -3
  52. package/dist-lib/lib/assistant/message.js +4 -2
  53. package/dist-lib/lib/assistant/skill-encode.d.ts +3 -1
  54. package/dist-lib/lib/assistant/skill-encode.js +52 -62
  55. package/dist-lib/lib/assistant-client.js +7 -4
  56. package/dist-lib/lib/assistant-tree.js +27 -11
  57. package/dist-lib/lib/assistant.d.ts +31 -11
  58. package/dist-lib/lib/assistant.js +846 -390
  59. package/dist-lib/lib/audio-format.d.ts +1 -1
  60. package/dist-lib/lib/audio-format.js +1 -1
  61. package/dist-lib/lib/chat-title.js +9 -4
  62. package/dist-lib/lib/client.js +3 -2
  63. package/dist-lib/lib/collabora/convert.d.ts +2 -2
  64. package/dist-lib/lib/collabora/convert.js +6 -3
  65. package/dist-lib/lib/collabora/entry.js +9 -5
  66. package/dist-lib/lib/collabora/protocol.d.ts +2 -2
  67. package/dist-lib/lib/collabora/protocol.js +14 -7
  68. package/dist-lib/lib/collabora/worker.js +14 -7
  69. package/dist-lib/lib/compaction.d.ts +5 -6
  70. package/dist-lib/lib/compaction.js +14 -7
  71. package/dist-lib/lib/core/account-recovery.d.ts +4 -3
  72. package/dist-lib/lib/core/account-recovery.js +7 -4
  73. package/dist-lib/lib/core/agent.js +17 -15
  74. package/dist-lib/lib/core/approval-rules.d.ts +7 -6
  75. package/dist-lib/lib/core/approval-rules.js +12 -6
  76. package/dist-lib/lib/core/archived-mesh.d.ts +7 -5
  77. package/dist-lib/lib/core/archived-mesh.js +25 -22
  78. package/dist-lib/lib/core/async-iterable.js +10 -5
  79. package/dist-lib/lib/core/attachment-link.d.ts +2 -2
  80. package/dist-lib/lib/core/audio-attachment.js +1 -1
  81. package/dist-lib/lib/core/blind-peers.d.ts +2 -2
  82. package/dist-lib/lib/core/chat-activity.d.ts +2 -2
  83. package/dist-lib/lib/core/chat-activity.js +42 -21
  84. package/dist-lib/lib/core/chat-group.d.ts +8 -6
  85. package/dist-lib/lib/core/chat-group.js +17 -10
  86. package/dist-lib/lib/core/chat-order.d.ts +11 -9
  87. package/dist-lib/lib/core/chat-order.js +1 -3
  88. package/dist-lib/lib/core/chat-search.d.ts +4 -4
  89. package/dist-lib/lib/core/chat-search.js +38 -24
  90. package/dist-lib/lib/core/chat.d.ts +20 -14
  91. package/dist-lib/lib/core/chat.js +50 -31
  92. package/dist-lib/lib/core/chunk.d.ts +19 -23
  93. package/dist-lib/lib/core/chunk.js +27 -21
  94. package/dist-lib/lib/core/collections.d.ts +70 -0
  95. package/dist-lib/lib/core/collections.js +70 -0
  96. package/dist-lib/lib/core/contract/activity.d.ts +6 -2
  97. package/dist-lib/lib/core/contract/activity.js +15 -12
  98. package/dist-lib/lib/core/contract/agents.js +3 -2
  99. package/dist-lib/lib/core/contract/approval-rules.js +1 -1
  100. package/dist-lib/lib/core/contract/attestations.js +1 -1
  101. package/dist-lib/lib/core/contract/chat-group.js +1 -1
  102. package/dist-lib/lib/core/contract/chat.d.ts +2 -0
  103. package/dist-lib/lib/core/contract/chat.js +67 -1
  104. package/dist-lib/lib/core/contract/chunks.js +15 -9
  105. package/dist-lib/lib/core/contract/compute.d.ts +1 -1
  106. package/dist-lib/lib/core/contract/compute.js +4 -2
  107. package/dist-lib/lib/core/contract/devices.js +6 -5
  108. package/dist-lib/lib/core/contract/grant-order.js +5 -6
  109. package/dist-lib/lib/core/contract/index.js +4 -2
  110. package/dist-lib/lib/core/contract/indexing.js +3 -3
  111. package/dist-lib/lib/core/contract/invites.d.ts +8 -3
  112. package/dist-lib/lib/core/contract/invites.js +52 -26
  113. package/dist-lib/lib/core/contract/joined-meshes.js +3 -3
  114. package/dist-lib/lib/core/contract/knowledge.js +5 -5
  115. package/dist-lib/lib/core/contract/members.d.ts +13 -2
  116. package/dist-lib/lib/core/contract/members.js +46 -25
  117. package/dist-lib/lib/core/contract/mesh-kind.js +9 -8
  118. package/dist-lib/lib/core/contract/seal.js +1 -1
  119. package/dist-lib/lib/core/contract/seed-defaults.js +1 -3
  120. package/dist-lib/lib/core/contract/tool-activity.js +10 -5
  121. package/dist-lib/lib/core/contract/tool-configs.js +1 -2
  122. package/dist-lib/lib/core/contract/writers.d.ts +6 -1
  123. package/dist-lib/lib/core/contract/writers.js +55 -34
  124. package/dist-lib/lib/core/departures.js +16 -8
  125. package/dist-lib/lib/core/device-invites.js +3 -2
  126. package/dist-lib/lib/core/devices.js +6 -3
  127. package/dist-lib/lib/core/document-attachment.d.ts +20 -11
  128. package/dist-lib/lib/core/document-attachment.js +10 -5
  129. package/dist-lib/lib/core/files/attachments.d.ts +2 -5
  130. package/dist-lib/lib/core/files/attachments.js +6 -3
  131. package/dist-lib/lib/core/files/index.d.ts +46 -52
  132. package/dist-lib/lib/core/files/index.js +149 -94
  133. package/dist-lib/lib/core/files/knowledge.d.ts +2 -5
  134. package/dist-lib/lib/core/files/local-index.d.ts +4 -1
  135. package/dist-lib/lib/core/files/local-index.js +9 -5
  136. package/dist-lib/lib/core/files/preview/image.d.ts +0 -1
  137. package/dist-lib/lib/core/files/preview/image.js +9 -6
  138. package/dist-lib/lib/core/files/preview/index.d.ts +8 -11
  139. package/dist-lib/lib/core/files/preview/index.js +20 -15
  140. package/dist-lib/lib/core/files/processing/claims.d.ts +6 -5
  141. package/dist-lib/lib/core/files/processing/claims.js +16 -8
  142. package/dist-lib/lib/core/files/processing/document.d.ts +21 -50
  143. package/dist-lib/lib/core/files/processing/index.d.ts +21 -13
  144. package/dist-lib/lib/core/files/processing/index.js +74 -37
  145. package/dist-lib/lib/core/files/processing/ownership.d.ts +8 -1
  146. package/dist-lib/lib/core/files/processing/ownership.js +1 -1
  147. package/dist-lib/lib/core/files/processing/protocol.d.ts +19 -19
  148. package/dist-lib/lib/core/files/processing/protocol.js +5 -5
  149. package/dist-lib/lib/core/files/processing/settle.d.ts +10 -7
  150. package/dist-lib/lib/core/files/processing/settle.js +22 -11
  151. package/dist-lib/lib/core/files/processing/source.js +14 -8
  152. package/dist-lib/lib/core/files/processing/state.d.ts +14 -11
  153. package/dist-lib/lib/core/files/processing/state.js +24 -12
  154. package/dist-lib/lib/core/files/rag/build.d.ts +2 -2
  155. package/dist-lib/lib/core/files/rag/build.js +2 -1
  156. package/dist-lib/lib/core/files/rag/document-types.d.ts +4 -6
  157. package/dist-lib/lib/core/files/rag/index.d.ts +12 -13
  158. package/dist-lib/lib/core/files/rag/index.js +9 -2
  159. package/dist-lib/lib/core/files/rag/load.d.ts +10 -9
  160. package/dist-lib/lib/core/files/rag/load.js +26 -13
  161. package/dist-lib/lib/core/files/rag/policy.js +2 -1
  162. package/dist-lib/lib/core/files/rag/produce.js +33 -19
  163. package/dist-lib/lib/core/files/rag/retrieval/full-text.d.ts +5 -3
  164. package/dist-lib/lib/core/files/rag/retrieval/full-text.js +30 -10
  165. package/dist-lib/lib/core/files/records/chunks.js +4 -2
  166. package/dist-lib/lib/core/files/records/index.d.ts +1 -0
  167. package/dist-lib/lib/core/files/records/index.js +1 -0
  168. package/dist-lib/lib/core/files/records/knowledge.d.ts +10 -11
  169. package/dist-lib/lib/core/files/records/knowledge.js +9 -8
  170. package/dist-lib/lib/core/files/records/linkage.js +6 -3
  171. package/dist-lib/lib/core/files/records/output.d.ts +5 -4
  172. package/dist-lib/lib/core/files/records/output.js +8 -4
  173. package/dist-lib/lib/core/files/records/purge.d.ts +4 -0
  174. package/dist-lib/lib/core/files/records/purge.js +108 -0
  175. package/dist-lib/lib/core/files/records/reclaim.js +43 -25
  176. package/dist-lib/lib/core/files/records/routing.d.ts +4 -6
  177. package/dist-lib/lib/core/files/records/routing.js +15 -8
  178. package/dist-lib/lib/core/files/records/source.d.ts +5 -4
  179. package/dist-lib/lib/core/files/records/source.js +20 -14
  180. package/dist-lib/lib/core/files/records/sweep.js +1 -3
  181. package/dist-lib/lib/core/files/store/blob.d.ts +11 -10
  182. package/dist-lib/lib/core/files/store/blob.js +54 -19
  183. package/dist-lib/lib/core/files/store/index.d.ts +2 -6
  184. package/dist-lib/lib/core/files/store/index.js +10 -5
  185. package/dist-lib/lib/core/files/store/inline.d.ts +2 -2
  186. package/dist-lib/lib/core/files/store/inline.js +6 -3
  187. package/dist-lib/lib/core/files/store/reference.d.ts +6 -9
  188. package/dist-lib/lib/core/files/store/reference.js +25 -17
  189. package/dist-lib/lib/core/files/store/server.d.ts +7 -6
  190. package/dist-lib/lib/core/files/store/server.js +22 -11
  191. package/dist-lib/lib/core/files/store/sweep.js +13 -7
  192. package/dist-lib/lib/core/files/upload-input.d.ts +4 -12
  193. package/dist-lib/lib/core/files/upload-input.js +10 -5
  194. package/dist-lib/lib/core/files/upload.d.ts +27 -24
  195. package/dist-lib/lib/core/files/upload.js +74 -51
  196. package/dist-lib/lib/core/fs-drives.js +4 -2
  197. package/dist-lib/lib/core/grant-expiry.js +12 -7
  198. package/dist-lib/lib/core/handoff-channel.js +27 -13
  199. package/dist-lib/lib/core/harness-loan.js +35 -17
  200. package/dist-lib/lib/core/helpers/index.js +6 -2
  201. package/dist-lib/lib/core/hosted-agents.js +19 -12
  202. package/dist-lib/lib/core/id.js +1 -1
  203. package/dist-lib/lib/core/identity.js +6 -3
  204. package/dist-lib/lib/core/image/cache-sweep.d.ts +12 -10
  205. package/dist-lib/lib/core/image/cache-sweep.js +11 -6
  206. package/dist-lib/lib/core/image/normalize.d.ts +6 -0
  207. package/dist-lib/lib/core/image/normalize.js +12 -2
  208. package/dist-lib/lib/core/image/sniff.js +42 -21
  209. package/dist-lib/lib/core/inference-calls-receiver.js +7 -4
  210. package/dist-lib/lib/core/invite-grants.js +4 -2
  211. package/dist-lib/lib/core/invite.js +2 -1
  212. package/dist-lib/lib/core/local/files.d.ts +2 -0
  213. package/dist-lib/lib/core/local/files.js +51 -19
  214. package/dist-lib/lib/core/local/index.d.ts +69 -46
  215. package/dist-lib/lib/core/local/index.js +146 -129
  216. package/dist-lib/lib/core/membership.d.ts +12 -2
  217. package/dist-lib/lib/core/membership.js +55 -33
  218. package/dist-lib/lib/core/mesh-seed-handoff.js +7 -1
  219. package/dist-lib/lib/core/mesh.d.ts +37 -27
  220. package/dist-lib/lib/core/mesh.js +131 -73
  221. package/dist-lib/lib/core/migrations/agent-catalog.js +3 -2
  222. package/dist-lib/lib/core/migrations/agent-indexes.js +3 -3
  223. package/dist-lib/lib/core/migrations/file-index.js +7 -4
  224. package/dist-lib/lib/core/migrations/index.d.ts +4 -3
  225. package/dist-lib/lib/core/migrations/membership.js +9 -4
  226. package/dist-lib/lib/core/migrations/seal.js +3 -2
  227. package/dist-lib/lib/core/min-version.js +4 -2
  228. package/dist-lib/lib/core/next-frame.d.ts +5 -4
  229. package/dist-lib/lib/core/next-frame.js +6 -3
  230. package/dist-lib/lib/core/notification.d.ts +5 -1
  231. package/dist-lib/lib/core/notification.js +89 -77
  232. package/dist-lib/lib/core/ota-config.js +2 -1
  233. package/dist-lib/lib/core/pdf/rasterize.d.ts +18 -0
  234. package/dist-lib/lib/core/pdf/rasterize.js +57 -0
  235. package/dist-lib/lib/core/prompt-history.js +4 -2
  236. package/dist-lib/lib/core/range.d.ts +4 -4
  237. package/dist-lib/lib/core/range.js +12 -6
  238. package/dist-lib/lib/core/rank.d.ts +5 -4
  239. package/dist-lib/lib/core/rank.js +2 -1
  240. package/dist-lib/lib/core/send.d.ts +4 -4
  241. package/dist-lib/lib/core/send.js +6 -3
  242. package/dist-lib/lib/core/skill-overlay-receiver.js +7 -4
  243. package/dist-lib/lib/core/skill-secrets.js +16 -9
  244. package/dist-lib/lib/core/sync/chunks.js +2 -1
  245. package/dist-lib/lib/core/sync/devices.js +3 -1
  246. package/dist-lib/lib/core/sync/files.d.ts +2 -4
  247. package/dist-lib/lib/core/sync/files.js +28 -20
  248. package/dist-lib/lib/core/sync/index.d.ts +2 -5
  249. package/dist-lib/lib/core/sync/index.js +33 -15
  250. package/dist-lib/lib/core/sync-status.js +10 -7
  251. package/dist-lib/lib/core/system-info.js +4 -2
  252. package/dist-lib/lib/core/tool-activity.d.ts +4 -3
  253. package/dist-lib/lib/core/tool-activity.js +1 -1
  254. package/dist-lib/lib/core/tool-configs.js +12 -7
  255. package/dist-lib/lib/core.d.ts +38 -26
  256. package/dist-lib/lib/core.js +1009 -541
  257. package/dist-lib/lib/credential-pusher.d.ts +20 -20
  258. package/dist-lib/lib/credential-pusher.js +65 -43
  259. package/dist-lib/lib/custom-model-pusher.d.ts +7 -3
  260. package/dist-lib/lib/custom-model-pusher.js +15 -7
  261. package/dist-lib/lib/custom-model-task.d.ts +1 -0
  262. package/dist-lib/lib/custom-model-task.js +12 -0
  263. package/dist-lib/lib/deadline.js +4 -2
  264. package/dist-lib/lib/diagnostics.d.ts +1 -5
  265. package/dist-lib/lib/frame-readable.d.ts +3 -0
  266. package/dist-lib/lib/frame-readable.js +3 -0
  267. package/dist-lib/lib/fs-drive-bridge.js +24 -14
  268. package/dist-lib/lib/fs-grants.js +13 -8
  269. package/dist-lib/lib/guards.d.ts +3 -0
  270. package/dist-lib/lib/guards.js +9 -0
  271. package/dist-lib/lib/inference-calls.d.ts +28 -23
  272. package/dist-lib/lib/inference-calls.js +25 -13
  273. package/dist-lib/lib/integrations/mcp-providers.d.ts +2 -2
  274. package/dist-lib/lib/integrations/setup-routes.d.ts +2 -2
  275. package/dist-lib/lib/knowledge-search.d.ts +6 -5
  276. package/dist-lib/lib/knowledge-search.js +26 -18
  277. package/dist-lib/lib/kv-cache-reclaim.js +4 -2
  278. package/dist-lib/lib/kv-cache.js +8 -4
  279. package/dist-lib/lib/legacy-core-domain.d.ts +42 -42
  280. package/dist-lib/lib/log-buffer.js +2 -1
  281. package/dist-lib/lib/log.js +25 -15
  282. package/dist-lib/lib/mesh-scoped-engine.js +12 -4
  283. package/dist-lib/lib/model-catalog-revision.js +6 -3
  284. package/dist-lib/lib/model-clamp.js +6 -3
  285. package/dist-lib/lib/model-context.d.ts +8 -3
  286. package/dist-lib/lib/model-context.js +13 -5
  287. package/dist-lib/lib/model-download-status.js +4 -2
  288. package/dist-lib/lib/model-download.d.ts +12 -4
  289. package/dist-lib/lib/model-download.js +200 -103
  290. package/dist-lib/lib/model-idle-pusher.d.ts +2 -2
  291. package/dist-lib/lib/model-idle-pusher.js +3 -4
  292. package/dist-lib/lib/oauth/browser-connect.d.ts +10 -8
  293. package/dist-lib/lib/oauth/browser-connect.js +33 -20
  294. package/dist-lib/lib/oauth/client.d.ts +2 -2
  295. package/dist-lib/lib/oauth/flow-core.js +23 -9
  296. package/dist-lib/lib/oauth/flow.d.ts +1 -3
  297. package/dist-lib/lib/oauth/flow.js +9 -5
  298. package/dist-lib/lib/oauth/keys.d.ts +4 -4
  299. package/dist-lib/lib/oauth/keys.js +18 -12
  300. package/dist-lib/lib/oauth/loopback.d.ts +2 -2
  301. package/dist-lib/lib/oauth/loopback.js +147 -107
  302. package/dist-lib/lib/oauth/loopback.stub.d.ts +2 -2
  303. package/dist-lib/lib/oauth/loopback.stub.js +1 -1
  304. package/dist-lib/lib/oauth/pkce.d.ts +4 -2
  305. package/dist-lib/lib/oauth/pkce.js +10 -0
  306. package/dist-lib/lib/oauth/providers.js +5 -5
  307. package/dist-lib/lib/oauth/redirect-types.d.ts +12 -7
  308. package/dist-lib/lib/oauth/register.js +3 -2
  309. package/dist-lib/lib/oauth/registry.d.ts +2 -2
  310. package/dist-lib/lib/oauth/registry.js +2 -1
  311. package/dist-lib/lib/oauth/resolve.d.ts +30 -10
  312. package/dist-lib/lib/oauth/resolve.js +12 -6
  313. package/dist-lib/lib/oauth/token-exchange-core.d.ts +12 -4
  314. package/dist-lib/lib/oauth/token-exchange-core.js +1 -1
  315. package/dist-lib/lib/oauth/types.d.ts +12 -12
  316. package/dist-lib/lib/oauth.d.ts +4 -5
  317. package/dist-lib/lib/oauth.js +2 -3
  318. package/dist-lib/lib/reconnecting-watch.d.ts +1 -1
  319. package/dist-lib/lib/reconnecting-watch.js +6 -6
  320. package/dist-lib/lib/retry-budget.js +6 -3
  321. package/dist-lib/lib/run-notices.d.ts +1 -0
  322. package/dist-lib/lib/run-notices.js +5 -2
  323. package/dist-lib/lib/run-transcript.d.ts +2 -4
  324. package/dist-lib/lib/run-transcript.js +4 -2
  325. package/dist-lib/lib/skill-readiness.js +4 -2
  326. package/dist-lib/lib/skill-types.d.ts +16 -16
  327. package/dist-lib/lib/suspend-lifecycle.d.ts +4 -4
  328. package/dist-lib/lib/suspend-lifecycle.js +10 -5
  329. package/dist-lib/lib/task.js +22 -12
  330. package/dist-lib/lib/unref.d.ts +3 -2
  331. package/dist-lib/lib/unref.js +2 -1
  332. package/dist-lib/lib/wav-duration.js +10 -5
  333. package/dist-lib/lib/write-queue.d.ts +5 -4
  334. package/dist-lib/lib/write-queue.js +2 -1
  335. package/dist-lib/schema/build.js +10 -6
  336. package/dist-lib/schema/config.d.ts +2 -3
  337. package/dist-lib/schema/content.d.ts +17 -2
  338. package/dist-lib/schema/content.js +2 -1
  339. package/dist-lib/schema/engine.d.ts +3 -2
  340. package/dist-lib/schema/engine.js +95 -6
  341. package/dist-lib/schema/field-order.js +22 -11
  342. package/dist-lib/schema/indexes.d.ts +22 -0
  343. package/dist-lib/schema/{helpers.js → indexes.js} +14 -57
  344. package/dist-lib/schema/local.d.ts +3 -2
  345. package/dist-lib/schema/local.js +7 -2
  346. package/dist-lib/schema/media-kind.d.ts +8 -0
  347. package/dist-lib/schema/media-kind.js +52 -0
  348. package/dist-lib/schema/qvac.d.ts +12 -9
  349. package/dist-lib/schema/qvac.js +18 -4
  350. package/dist-lib/spec/bind.js +12 -0
  351. package/dist-lib/spec/calls.js +4 -0
  352. package/dist-lib/spec/capabilities.d.ts +12 -4
  353. package/dist-lib/spec/hrpc/hrpc.json +54 -2
  354. package/dist-lib/spec/hrpc/index.js +53 -5
  355. package/dist-lib/spec/hrpc/messages.js +783 -494
  356. package/dist-lib/spec/hyperschema/index.js +783 -494
  357. package/dist-lib/spec/hyperschema/schema.json +247 -1
  358. package/dist-lib/spec/hyperschema/types.d.ts +69 -1
  359. package/dist-lib/spec/local/hyperdb/index.js +1 -1
  360. package/dist-lib/spec/local/hyperdb/messages.js +82 -14
  361. package/dist-lib/spec/local/hyperschema/index.js +42 -8
  362. package/dist-lib/spec/local/hyperschema/schema.json +27 -1
  363. package/dist-lib/spec/local/hyperschema/types.d.ts +6 -1
  364. package/dist-lib/spec/mesh/hyperdb/db.json +16 -1
  365. package/dist-lib/spec/mesh/hyperdb/index.js +72 -3
  366. package/dist-lib/spec/mesh/hyperdb/messages.js +400 -221
  367. package/dist-lib/spec/mesh/hyperdispatch/dispatch.json +7 -1
  368. package/dist-lib/spec/mesh/hyperdispatch/index.js +18 -1
  369. package/dist-lib/spec/mesh/hyperdispatch/messages.js +117 -2
  370. package/dist-lib/spec/mesh/hyperschema/index.js +117 -2
  371. package/dist-lib/spec/mesh/hyperschema/schema.json +65 -1
  372. package/dist-lib/spec/mesh/hyperschema/types.d.ts +19 -1
  373. package/package.json +8 -4
  374. package/tui/app.mjs +2424 -941
  375. package/tui/boot.mjs +18 -49
  376. package/tui/index.mjs +10 -5
  377. package/tui/lib/boot-timing.mjs +8 -8
  378. package/tui/lib/busy-words.mjs +21 -22
  379. package/tui/lib/export.mjs +100 -32
  380. package/tui/lib/knowledge-command.mjs +64 -19
  381. package/tui/lib/knowledge-import.mjs +52 -18
  382. package/tui/lib/render.mjs +65 -33
  383. package/tui/lib/save-file.mjs +30 -13
  384. package/tui/lib/select.mjs +23 -5
  385. package/tui/lib/selection.mjs +6 -4
  386. package/tui/lib/setup.mjs +11 -19
  387. package/tui/lib/sidebar.mjs +23 -13
  388. package/tui/lib/splash.mjs +6 -7
  389. package/tui/lib/upload-frames.mjs +1 -2
  390. package/tui/lib/usage.mjs +13 -9
  391. package/tui/lib/wrap.mjs +35 -6
  392. package/tui/main.mjs +54 -78
  393. package/worker/assistant-sidecar.mjs +5 -10
  394. package/worker/stow-entry.mjs +7 -4
  395. package/dist-lib/lib/custom-model-source.d.ts +0 -15
  396. package/dist-lib/lib/custom-model-source.js +0 -46
  397. package/dist-lib/lib/oauth/common.d.ts +0 -38
  398. package/dist-lib/lib/oauth/common.js +0 -34
  399. package/dist-lib/schema/helpers.d.ts +0 -33
@@ -7,13 +7,13 @@ const USAGE =
7
7
 
8
8
  export async function knowledgeCommand(engine, { chatId, meshId, saveDir }, input) {
9
9
  try {
10
- return { type: 'notice', text: await execute(engine, { chatId, meshId }, saveDir, input) }
10
+ return { type: 'notice', text: await execute(engine, { chatId, meshId, saveDir }, input) }
11
11
  } catch (error) {
12
12
  return { type: 'run.error', error }
13
13
  }
14
14
  }
15
15
 
16
- async function execute(engine, scope, saveDir, input) {
16
+ async function execute(engine, { saveDir, ...scope }, input) {
17
17
  const { chatId, meshId } = scope
18
18
  const { action, argument } = parseInput(input)
19
19
  if ((!action || action === 'list') && !argument) {
@@ -23,21 +23,31 @@ async function execute(engine, scope, saveDir, input) {
23
23
  ])
24
24
  return formatKnowledge(sortKnowledge(knowledge ?? []), statuses ?? [])
25
25
  }
26
+
26
27
  if (action === 'add' || action === 'add-dir') {
27
- if (!argument) return USAGE
28
+ if (!argument) {
29
+ return USAGE
30
+ }
31
+
28
32
  if (action === 'add') {
29
33
  const added = await importKnowledgeFile(engine, scope, argument)
30
34
  return `uploaded ${singleLine(added.fileName)} (${added.byteLength}B) · run /knowledge to track indexing`
31
35
  }
36
+
32
37
  return formatDirectoryImport(await importKnowledgeDirectory(engine, scope, argument))
33
38
  }
34
39
 
35
40
  const [selector, ...extra] = argument.split(/\s+/)
36
- if ((action !== 'download' && action !== 'remove') || !selector || extra.length) return USAGE
41
+ if ((action !== 'download' && action !== 'remove') || !selector || extra.length) {
42
+ return USAGE
43
+ }
37
44
 
38
45
  const { knowledge } = await engine.listKnowledge({ chatId, meshId })
39
46
  const selected = resolveKnowledge(sortKnowledge(knowledge ?? []), selector)
40
- if (selected.error) return selected.error
47
+ if (selected.error) {
48
+ return selected.error
49
+ }
50
+
41
51
  const row = selected.knowledge
42
52
  if (action === 'remove') {
43
53
  await engine.removeKnowledge({ knowledgeId: row.id, at: Date.now(), meshId })
@@ -45,18 +55,23 @@ async function execute(engine, scope, saveDir, input) {
45
55
  }
46
56
 
47
57
  const saved = await saveUniqueStream(
48
- saveDir,
49
- row.fileName,
50
- frameData(engine.downloadKnowledge({ blobId: row.blobId, meshId }))
58
+ frameData(engine.downloadKnowledge({ blobId: row.blobId, meshId })),
59
+ { dir: saveDir, fileName: row.fileName }
51
60
  )
52
- if (saved) return `saved ${singleLine(row.fileName)} (${saved.bytesWritten}B) to ${saved.file}`
61
+ if (saved) {
62
+ return `saved ${singleLine(row.fileName)} (${saved.bytesWritten}B) to ${saved.file}`
63
+ }
64
+
53
65
  return `not saved: 100 files named ${singleLine(row.fileName)} already exist in ${saveDir}`
54
66
  }
55
67
 
56
68
  function parseInput(input) {
57
69
  const value = input.trim()
58
70
  const separator = value.search(/\s/)
59
- if (separator === -1) return { action: value, argument: '' }
71
+ if (separator === -1) {
72
+ return { action: value, argument: '' }
73
+ }
74
+
60
75
  return {
61
76
  action: value.slice(0, separator),
62
77
  argument: value.slice(separator).trimStart()
@@ -67,21 +82,28 @@ function formatDirectoryImport(result) {
67
82
  if (!result.added.length && !result.failed.length) {
68
83
  return `no supported knowledge files in ${result.directory}`
69
84
  }
85
+
70
86
  const lines = [
71
87
  `uploaded ${result.added.length} knowledge file${result.added.length === 1 ? '' : 's'}`
72
88
  ]
73
89
  for (const row of result.added) {
74
90
  lines.push(` + ${singleLine(row.fileName)} (${row.byteLength}B)`)
75
91
  }
92
+
76
93
  for (const row of result.failed) {
77
94
  lines.push(` ! ${singleLine(row.fileName)} · ${singleLine(row.error)}`)
78
95
  }
96
+
79
97
  if (result.skipped.length) {
80
98
  lines.push(
81
99
  ` - skipped ${result.skipped.length} unsupported ${result.skipped.length === 1 ? 'entry' : 'entries'}`
82
100
  )
83
101
  }
84
- if (result.added.length) lines.push('run /knowledge to track indexing')
102
+
103
+ if (result.added.length) {
104
+ lines.push('run /knowledge to track indexing')
105
+ }
106
+
85
107
  return lines.join('\n')
86
108
  }
87
109
 
@@ -93,6 +115,7 @@ function formatKnowledge(knowledge, statuses) {
93
115
  rows.push(row)
94
116
  byKnowledge.set(row.knowledgeId, rows)
95
117
  }
118
+
96
119
  return knowledge
97
120
  .map((row, index) => formatKnowledgeRow(row, index, byKnowledge.get(row.id) ?? []))
98
121
  .join('\n')
@@ -102,8 +125,14 @@ function formatKnowledgeRow(knowledge, index, statuses) {
102
125
  const name = singleLine(knowledge.fileName) || '(unnamed)'
103
126
  const lines = [`${index + 1}. ${name} (${knowledge.byteLength}B) · ${knowledge.id.slice(0, 8)}`]
104
127
  const sorted = [...statuses].sort((a, b) => a.id.localeCompare(b.id))
105
- if (!sorted.length) lines.push(' - not indexed')
106
- for (const row of sorted) lines.push(` - ${formatStatus(row)}`)
128
+ if (!sorted.length) {
129
+ lines.push(' - not indexed')
130
+ }
131
+
132
+ for (const row of sorted) {
133
+ lines.push(` - ${formatStatus(row)}`)
134
+ }
135
+
107
136
  return lines.join('\n')
108
137
  }
109
138
 
@@ -111,9 +140,13 @@ function formatStatus(row) {
111
140
  const status = row.status === 'indexing' && !row.claimLive ? 'expired' : row.status
112
141
  let detail = `${status} · artifact ${row.id.slice(0, 8)}`
113
142
  if (row.status === 'indexing' && row.claimLive) {
114
- detail += ` · claimed by ${b4a.toString(row.claimedBy, 'hex').slice(0, 8)}`
143
+ detail += ` · claimed by ${b4a.toHex(row.claimedBy).slice(0, 8)}`
144
+ }
145
+
146
+ if (row.status === 'failed' && row.error) {
147
+ detail += ` · ${singleLine(row.error)}`
115
148
  }
116
- if (row.status === 'failed' && row.error) detail += ` · ${singleLine(row.error)}`
149
+
117
150
  return detail
118
151
  }
119
152
 
@@ -123,14 +156,24 @@ function sortKnowledge(rows) {
123
156
 
124
157
  function resolveKnowledge(rows, selector) {
125
158
  const exact = rows.find((row) => row.id === selector)
126
- if (exact) return { knowledge: exact }
159
+ if (exact) {
160
+ return { knowledge: exact }
161
+ }
162
+
127
163
  if (/^\d+$/.test(selector)) {
128
164
  const index = Number(selector) - 1
129
165
  return rows[index] ? { knowledge: rows[index] } : { error: `no knowledge #${selector}` }
130
166
  }
167
+
131
168
  const matches = rows.filter((row) => row.id.startsWith(selector))
132
- if (matches.length === 1) return { knowledge: matches[0] }
133
- if (matches.length > 1) return { error: `ambiguous knowledge id: ${selector}` }
169
+ if (matches.length === 1) {
170
+ return { knowledge: matches[0] }
171
+ }
172
+
173
+ if (matches.length > 1) {
174
+ return { error: `ambiguous knowledge id: ${selector}` }
175
+ }
176
+
134
177
  return { error: `no knowledge matching: ${selector}` }
135
178
  }
136
179
 
@@ -140,6 +183,8 @@ function singleLine(value) {
140
183
 
141
184
  async function* frameData(frames) {
142
185
  for await (const frame of frames) {
143
- if (frame.data) yield frame.data
186
+ if (frame.data) {
187
+ yield frame.data
188
+ }
144
189
  }
145
190
  }
@@ -4,6 +4,7 @@ import path from 'path'
4
4
  import { fileURLToPath } from 'url'
5
5
  import { RAG_ACCEPT_EXTENSIONS } from 'rag-extract'
6
6
  import { UPLOAD_FRAME_BYTES, writeFrame } from './upload-frames.mjs'
7
+ import { errorMessage } from '../../dist-lib/lib/guards.js'
7
8
  const ACCEPTED = new Set(RAG_ACCEPT_EXTENSIONS)
8
9
  const MIME_TYPES = new Map([
9
10
  ['.pdf', 'application/pdf'],
@@ -31,15 +32,23 @@ const MIME_TYPES = new Map([
31
32
  export async function importKnowledgeFile(engine, scope, inputPath) {
32
33
  const file = resolvePath(inputPath)
33
34
  const stat = await fs.promises.stat(file)
34
- if (!stat.isFile()) throw new Error(`not a file: ${file}`)
35
- if (!supported(file)) throw new Error(`unsupported knowledge file: ${path.basename(file)}`)
36
- return upload(engine, scope, file, stat.size)
35
+ if (!stat.isFile()) {
36
+ throw new Error(`not a file: ${file}`)
37
+ }
38
+
39
+ if (!supported(file)) {
40
+ throw new Error(`unsupported knowledge file: ${path.basename(file)}`)
41
+ }
42
+
43
+ return upload(engine, file, { ...scope, byteLength: stat.size })
37
44
  }
38
45
 
39
46
  export async function importKnowledgeDirectory(engine, scope, inputPath) {
40
47
  const directory = resolvePath(inputPath)
41
48
  const stat = await fs.promises.stat(directory)
42
- if (!stat.isDirectory()) throw new Error(`not a directory: ${directory}`)
49
+ if (!stat.isDirectory()) {
50
+ throw new Error(`not a directory: ${directory}`)
51
+ }
43
52
 
44
53
  const added = []
45
54
  const failed = []
@@ -54,24 +63,36 @@ export async function importKnowledgeDirectory(engine, scope, inputPath) {
54
63
  failed.push({ fileName: name, error: errorMessage(error) })
55
64
  continue
56
65
  }
66
+
57
67
  if (!fileStat.isFile() || !supported(file)) {
58
68
  skipped.push(name)
59
69
  continue
60
70
  }
71
+
61
72
  try {
62
- added.push(await upload(engine, scope, file, fileStat.size))
73
+ added.push(await upload(engine, file, { ...scope, byteLength: fileStat.size }))
63
74
  } catch (error) {
64
75
  failed.push({ fileName: name, error: errorMessage(error) })
65
76
  }
66
77
  }
78
+
67
79
  return { directory, added, failed, skipped }
68
80
  }
69
81
 
70
82
  function resolvePath(input) {
71
83
  const value = input.trim()
72
- if (value.startsWith('file://')) return fileURLToPath(value)
73
- if (value === '~') return os.homedir()
74
- if (value.startsWith('~/')) return path.join(os.homedir(), value.slice(2))
84
+ if (value.startsWith('file://')) {
85
+ return fileURLToPath(value)
86
+ }
87
+
88
+ if (value === '~') {
89
+ return os.homedir()
90
+ }
91
+
92
+ if (value.startsWith('~/')) {
93
+ return path.join(os.homedir(), value.slice(2))
94
+ }
95
+
75
96
  return path.resolve(value)
76
97
  }
77
98
 
@@ -79,7 +100,7 @@ function supported(file) {
79
100
  return ACCEPTED.has(path.extname(file).toLowerCase())
80
101
  }
81
102
 
82
- async function upload(engine, { chatId, meshId }, file, byteLength) {
103
+ async function upload(engine, file, { chatId, meshId, byteLength }) {
83
104
  const fileName = path.basename(file)
84
105
  const extension = path.extname(file).toLowerCase()
85
106
  const stream = engine.uploadKnowledge()
@@ -87,6 +108,7 @@ async function upload(engine, { chatId, meshId }, file, byteLength) {
87
108
  const response = readFinal(stream).catch((error) => {
88
109
  responseError = error
89
110
  safeDestroy(stream)
111
+
90
112
  return null
91
113
  })
92
114
  const source = fs.createReadStream(file, { highWaterMark: UPLOAD_FRAME_BYTES })
@@ -100,27 +122,43 @@ async function upload(engine, { chatId, meshId }, file, byteLength) {
100
122
  mimeType: MIME_TYPES.get(extension) ?? 'application/octet-stream',
101
123
  totalBytes: byteLength
102
124
  })
103
- if (!metadataWritten) throw responseError ?? new Error('knowledge upload closed while writing')
125
+ if (!metadataWritten) {
126
+ throw responseError ?? new Error('knowledge upload closed while writing')
127
+ }
128
+
104
129
  for await (const data of source) {
105
130
  if (responseError) throw responseError
106
131
  const dataWritten = await writeFrame(stream, { data })
107
- if (!dataWritten) throw responseError ?? new Error('knowledge upload closed while writing')
132
+ if (!dataWritten) {
133
+ throw responseError ?? new Error('knowledge upload closed while writing')
134
+ }
108
135
  }
136
+
109
137
  stream.end()
110
138
  const final = await response
111
- if (responseError) throw responseError
112
- if (!final?.knowledge) throw new Error('knowledge upload ended without a knowledge row')
139
+ if (responseError) {
140
+ throw responseError
141
+ }
142
+
143
+ if (!final?.knowledge) {
144
+ throw new Error('knowledge upload ended without a knowledge row')
145
+ }
146
+
113
147
  return { fileName, byteLength, knowledge: final.knowledge }
114
148
  } catch (error) {
115
149
  source.destroy()
116
150
  safeDestroy(stream)
151
+
117
152
  throw error
118
153
  }
119
154
  }
120
155
 
121
156
  async function readFinal(stream) {
122
157
  let final = null
123
- for await (const frame of stream) final = frame
158
+ for await (const frame of stream) {
159
+ final = frame
160
+ }
161
+
124
162
  return final
125
163
  }
126
164
 
@@ -131,7 +169,3 @@ function safeDestroy(stream) {
131
169
  // Cleanup must not replace the file or transport error.
132
170
  }
133
171
  }
134
-
135
- function errorMessage(error) {
136
- return error instanceof Error ? error.message : String(error)
137
- }
@@ -9,15 +9,22 @@ const PAYLOAD_FIELDS = {
9
9
  attachment: 'attachment'
10
10
  }
11
11
 
12
- // A fold before a run is written after the message that triggered it and before any of
13
- // its answer, so the marker goes above that message: that is where the folded history ends.
14
- // An upload is appended before the message it belongs to, so the marker goes above it too.
12
+ // a fold lands after its triggering message (and that message's upload), so the marker goes above
15
13
  function foldMarkerIndex(turns) {
16
14
  let at = turns.length
17
- while (at > 0 && turns[at - 1].from === 'agent' && turns[at - 1].segments.length === 0) at--
18
- if (at === turns.length || at === 0 || turns[at - 1].from !== 'user') return turns.length
15
+ while (at > 0 && turns[at - 1].from === 'agent' && turns[at - 1].segments.length === 0) {
16
+ at--
17
+ }
18
+
19
+ if (at === turns.length || at === 0 || turns[at - 1].from !== 'user') {
20
+ return turns.length
21
+ }
22
+
19
23
  at--
20
- while (at > 0 && turns[at - 1].from === 'user' && isUpload(turns[at - 1])) at--
24
+ while (at > 0 && turns[at - 1].from === 'user' && isUpload(turns[at - 1])) {
25
+ at--
26
+ }
27
+
21
28
  return at
22
29
  }
23
30
 
@@ -29,8 +36,7 @@ export function turnsFromChunks(chunks) {
29
36
  const turns = []
30
37
  const byRun = new Map()
31
38
  for (const chunk of chunks) {
32
- // deviceId (hex of the chunk's originDeviceId) lets a renderer label the
33
- // human side per device — purely presentational, nothing schema-enforced.
39
+ // purely presentational: lets a renderer label the human side per device
34
40
  if (chunk.type === 'user-message') {
35
41
  turns.push({
36
42
  from: 'user',
@@ -39,9 +45,8 @@ export function turnsFromChunks(chunks) {
39
45
  })
40
46
  continue
41
47
  }
42
- // A user-uploaded attachment has no runId (it isn't part of an agent
43
- // turn) — an attachment a tool call produced mid-run does, and groups
44
- // into that run's turn below like any other segment.
48
+
49
+ // an attachment a tool produced mid-run has a runId and groups into that run's turn below
45
50
  if (chunk.type === 'attachment' && !chunk.runId) {
46
51
  turns.push({
47
52
  from: 'user',
@@ -50,49 +55,56 @@ export function turnsFromChunks(chunks) {
50
55
  })
51
56
  continue
52
57
  }
53
- // A fold has no run: grouped by its absent runId it would become an agent turn that
54
- // never reaches a terminal state, and the busy gate would stay up on it.
58
+
59
+ // grouped by its absent runId a fold would be an agent turn that never ends, holding the busy gate
55
60
  if (chunk.type === 'compaction') {
56
61
  turns.splice(foldMarkerIndex(turns), 0, { from: 'compaction', segments: [] })
57
62
  continue
58
63
  }
64
+
59
65
  let turn = byRun.get(chunk.runId)
60
66
  if (!turn) {
61
67
  turn = { from: 'agent', runId: chunk.runId, status: null, segments: [] }
62
68
  byRun.set(chunk.runId, turn)
63
69
  turns.push(turn)
64
70
  }
65
- // The ask itself materializes the turn (so EVERY peer sees a run is in
66
- // flight before the host even starts) but renders nothing of its own —
67
- // the provider's run-status/content chunks are the visible side.
68
- if (chunk.type === 'run-request') continue
71
+
72
+ // the ask materializes the turn so every peer sees a run in flight before the host even starts
73
+ if (chunk.type === 'run-request') {
74
+ continue
75
+ }
76
+
69
77
  if (chunk.type === 'run-status') {
70
78
  turn.status = chunk.runStatus.state
71
79
  turn.statusReason = chunk.runStatus.reason
72
80
  turn.statusDetail = chunk.runStatus
73
- // Status chunks are stamped by the device doing the work (the
74
- // provider), so progress can be labelled with WHERE it's happening.
81
+ // stamped by the provider, so progress can be labelled with where it is happening
75
82
  turn.statusDeviceId = chunk.originDeviceId && b4a.toHex(chunk.originDeviceId)
76
83
  continue
77
84
  }
78
- // An approval-request chunk IS the approval state (see runAgent's
79
- // createApprove) — never coalesced with a neighbor, and carries its own
80
- // id so the UI can resolveApproval() it directly.
85
+
86
+ // the chunk is the approval state, so it is never coalesced and carries its own id to resolve
81
87
  if (chunk.type === 'approval-request') {
82
88
  turn.segments.push({ type: 'approval-request', id: chunk.id, detail: chunk.approvalRequest })
83
89
  continue
84
90
  }
91
+
85
92
  // recovery appends a fresh sources chunk on the same run - the newest wins (v1 rule)
86
93
  if (chunk.type === 'sources') {
87
94
  const stale = turn.segments.findIndex((segment) => segment.type === 'sources')
88
- if (stale >= 0) turn.segments.splice(stale, 1)
95
+ if (stale >= 0) {
96
+ turn.segments.splice(stale, 1)
97
+ }
98
+
89
99
  turn.segments.push({ type: 'sources', detail: chunk.sources })
90
100
  continue
91
101
  }
102
+
92
103
  const detail = chunk[PAYLOAD_FIELDS[chunk.type]] ?? {}
93
104
  const last = turn.segments[turn.segments.length - 1]
94
- if (last && last.type === chunk.type) last.text += detail.text ?? ''
95
- else {
105
+ if (last && last.type === chunk.type) {
106
+ last.text += detail.text ?? ''
107
+ } else {
96
108
  turn.segments.push({
97
109
  type: chunk.type,
98
110
  text: detail.text ?? '',
@@ -100,26 +112,31 @@ export function turnsFromChunks(chunks) {
100
112
  })
101
113
  }
102
114
  }
115
+
103
116
  return turns
104
117
  }
105
118
 
106
- // The latest still-pending approval-request across every turn, or null —
107
- // there's at most one live tool call awaiting approval at a time (the
108
- // harness's own loop blocks on it before doing anything else).
119
+ // the harness's loop blocks on an approval, so at most one is live at a time
109
120
  export function findPendingApproval(turns) {
110
121
  for (let i = turns.length - 1; i >= 0; i--) {
111
122
  for (const segment of turns[i].segments) {
112
- if (segment.type === 'approval-request' && segment.detail.status === 'pending') return segment
123
+ if (segment.type === 'approval-request' && segment.detail.status === 'pending') {
124
+ return segment
125
+ }
113
126
  }
114
127
  }
128
+
115
129
  return null
116
130
  }
117
131
 
118
132
  export function runningAgentTurn(turns) {
119
133
  for (let i = turns.length - 1; i >= 0; i--) {
120
134
  const turn = turns[i]
121
- if (turn.from === 'agent' && turn.status === 'executing') return turn
135
+ if (turn.from === 'agent' && turn.status === 'executing') {
136
+ return turn
137
+ }
122
138
  }
139
+
123
140
  return null
124
141
  }
125
142
 
@@ -134,31 +151,46 @@ export function runInFlight(turns) {
134
151
  if (turns[i].from !== 'agent') continue
135
152
  return !TERMINAL_RUN_STATES.has(turns[i].status)
136
153
  }
154
+
137
155
  return false
138
156
  }
139
157
 
140
158
  export function busyStatus(modelState, runTurn, elapsed) {
141
- if (modelState?.status === 'loading') return { text: `loading ${modelState.model}…`, on: 'local' }
159
+ if (modelState?.status === 'loading') {
160
+ return { text: `loading ${modelState.model}…`, on: 'local' }
161
+ }
162
+
142
163
  if (modelState?.status === 'downloading') {
143
164
  return {
144
165
  text: `downloading ${modelState.model}: ${Math.round(modelState.percentage ?? 0)}%`,
145
166
  on: 'local'
146
167
  }
147
168
  }
169
+
148
170
  if (modelState?.status === 'unloading') {
149
171
  return { text: `unloading ${modelState.model}…`, on: 'local' }
150
172
  }
173
+
151
174
  const progress = runTurn?.statusDetail?.progress
152
- if (progress?.phase === 'loading') return { text: `loading ${progress.model}…`, on: 'host' }
175
+ if (progress?.phase === 'loading') {
176
+ return { text: `loading ${progress.model}…`, on: 'host' }
177
+ }
178
+
153
179
  if (progress?.phase === 'downloading') {
154
180
  return { text: `downloading ${progress.model}: ${progress.percentage ?? 0}%`, on: 'host' }
155
181
  }
182
+
156
183
  if (progress?.phase === 'generating') {
157
184
  return { text: `generating image: ${progress.percentage ?? 0}%`, on: 'host' }
158
185
  }
186
+
159
187
  if (progress?.phase === 'queued') {
160
188
  return { text: `queued - agent busy in ${progress.busyChatId}`, on: 'host' }
161
189
  }
162
- if (progress?.phase === 'compacting') return { text: 'compacting conversation…', on: 'host' }
190
+
191
+ if (progress?.phase === 'compacting') {
192
+ return { text: 'compacting conversation…', on: 'host' }
193
+ }
194
+
163
195
  return { text: busyWord(runTurn?.runId, elapsed), on: null }
164
196
  }
@@ -1,45 +1,58 @@
1
1
  import fs from 'fs'
2
2
  import path from 'path'
3
3
 
4
- export async function saveUniqueFile(dir, fileName, bytes, extension) {
5
- const saved = await saveUnique(dir, fileName, extension, (handle) => write(handle, bytes))
4
+ export async function saveUniqueFile(bytes, target) {
5
+ const saved = await saveUnique(target, (handle) => write(handle, bytes))
6
6
  return saved?.file ?? null
7
7
  }
8
8
 
9
- export function saveUniqueStream(dir, fileName, source, extension) {
10
- return saveUnique(dir, fileName, extension, async (handle) => {
9
+ export function saveUniqueStream(source, target) {
10
+ return saveUnique(target, async (handle) => {
11
11
  let bytesWritten = 0
12
- for await (const data of source) bytesWritten += await write(handle, data)
12
+ for await (const data of source) {
13
+ bytesWritten += await write(handle, data)
14
+ }
15
+
13
16
  return bytesWritten
14
17
  })
15
18
  }
16
19
 
17
- async function saveUnique(dir, fileName, extension, writeFile) {
18
- const tempDir = await fs.promises.mkdtemp(path.join(dir, '.qvac-download-'))
20
+ async function saveUnique(target, writeFile) {
21
+ const tempDir = await fs.promises.mkdtemp(path.join(target.dir, '.qvac-download-'))
19
22
  const tempFile = path.join(tempDir, 'download')
20
23
  let handle = await fs.promises.open(tempFile, 'w')
21
24
  let file = null
22
25
 
23
26
  try {
24
- file = await claimUniqueFile(dir, fileName, extension, tempFile)
25
- if (!file) return null
27
+ file = await claimUniqueFile(target, tempFile)
28
+ if (!file) {
29
+ return null
30
+ }
31
+
26
32
  const bytesWritten = await writeFile(handle)
27
33
  await handle.close()
28
34
  handle = null
35
+
29
36
  return { file, bytesWritten }
30
37
  } catch (err) {
31
38
  await handle.close().catch(noop)
32
39
  handle = null
33
- if (file) await fs.promises.unlink(file).catch(noop)
40
+ if (file) {
41
+ await fs.promises.unlink(file).catch(noop)
42
+ }
43
+
34
44
  throw err
35
45
  } finally {
36
46
  // Cleanup must not replace the download error or remove the reserved destination.
37
- if (handle) await handle.close().catch(noop)
47
+ if (handle) {
48
+ await handle.close().catch(noop)
49
+ }
50
+
38
51
  await fs.promises.rm(tempDir, { recursive: true, force: true }).catch(noop)
39
52
  }
40
53
  }
41
54
 
42
- async function claimUniqueFile(dir, fileName, extension, source) {
55
+ async function claimUniqueFile({ dir, fileName, extension }, source) {
43
56
  const sanitized = path.basename(fileName).replace(/[^a-zA-Z0-9_.-]/g, '_')
44
57
  const safe = !sanitized || sanitized === '.' || sanitized === '..' ? 'download' : sanitized
45
58
  const dot = safe.lastIndexOf('.')
@@ -53,9 +66,12 @@ async function claimUniqueFile(dir, fileName, extension, source) {
53
66
  await fs.promises.link(source, file)
54
67
  return file
55
68
  } catch (err) {
56
- if (err.code !== 'EEXIST') throw err
69
+ if (err.code !== 'EEXIST') {
70
+ throw err
71
+ }
57
72
  }
58
73
  }
74
+
59
75
  return null
60
76
  }
61
77
 
@@ -65,6 +81,7 @@ async function write(handle, data) {
65
81
  const result = await handle.write(offset ? data.subarray(offset) : data)
66
82
  offset += result.bytesWritten
67
83
  }
84
+
68
85
  return data.length
69
86
  }
70
87
 
@@ -29,18 +29,35 @@ function walk(line, start, end) {
29
29
  for (const cell of cells(line)) {
30
30
  if (cell.esc) {
31
31
  painted += cell.esc
32
- if (on && RESETS.has(cell.esc)) painted += REVERSE
32
+ if (on && RESETS.has(cell.esc)) {
33
+ painted += REVERSE
34
+ }
35
+
33
36
  continue
34
37
  }
38
+
35
39
  const inside = col >= start && col < end
36
- if (inside && !on) painted += REVERSE
37
- if (!inside && on) painted += REVERSE_OFF
40
+ if (inside && !on) {
41
+ painted += REVERSE
42
+ }
43
+
44
+ if (!inside && on) {
45
+ painted += REVERSE_OFF
46
+ }
47
+
38
48
  on = inside
39
- if (inside) text += cell.ch
49
+ if (inside) {
50
+ text += cell.ch
51
+ }
52
+
40
53
  painted += cell.ch
41
54
  col += cell.w
42
55
  }
43
- if (on) painted += REVERSE_OFF
56
+
57
+ if (on) {
58
+ painted += REVERSE_OFF
59
+ }
60
+
44
61
  return { text: text.replace(/ +$/, ''), painted }
45
62
  }
46
63
 
@@ -51,6 +68,7 @@ export function selectionText(lines, anchor, focus) {
51
68
  const at = span(row, from, to)
52
69
  rows.push(walk(lines[row], at.start, at.end).text)
53
70
  }
71
+
54
72
  return rows.join('\n').replace(/^\n+|\n+$/g, '')
55
73
  }
56
74