@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,6 +7,8 @@ import { runnableModelName } from './model-clamp.js';
7
7
  import { ModelDownloadStatus } from './model-download-status.js';
8
8
  import { RetryBudget } from './retry-budget.js';
9
9
  import { unref } from './unref.js';
10
+ import b4a from 'b4a';
11
+ import { errorMessage } from './guards.js';
10
12
  const WATCH_RETRY_MS = 30_000;
11
13
  const LOCAL_PROGRESS_INTERVAL_MS = 750;
12
14
  const LOCAL_PROGRESS_PERCENTAGE_STEP = 1;
@@ -32,6 +34,7 @@ export class ModelDownloadReconciler {
32
34
  _observedProgress = new Map();
33
35
  _observedSpeed = new Map();
34
36
  _requestedModels = new Set();
37
+ _releasing = new Set();
35
38
  _targetTotals = new Map();
36
39
  _config = null;
37
40
  _active = null;
@@ -85,7 +88,7 @@ export class ModelDownloadReconciler {
85
88
  const first = await it.next();
86
89
  await it.return?.();
87
90
  for (const row of first.value?.downloads ?? []) {
88
- await this._engine.clearModelDownload({ name: row.name }).catch(() => { });
91
+ await this._engine.clearModelDownload({ name: row.name }).catch(noop);
89
92
  }
90
93
  }
91
94
  catch (err) {
@@ -109,8 +112,9 @@ export class ModelDownloadReconciler {
109
112
  return;
110
113
  const agents = this._agentsStream;
111
114
  this._agentsStream = null;
112
- if (agents?.return)
113
- void agents.return().catch(() => { });
115
+ if (agents?.return) {
116
+ void agents.return().catch(noop);
117
+ }
114
118
  this._watchAgents();
115
119
  this._swapToolConfigsWatch(this._toolConfigsAgentId);
116
120
  this._kick();
@@ -119,8 +123,9 @@ export class ModelDownloadReconciler {
119
123
  if (this._closed)
120
124
  return;
121
125
  const next = new Set(models);
122
- if (next.size === this._runModels.size && [...next].every((m) => this._runModels.has(m)))
126
+ if (next.size === this._runModels.size && [...next].every((m) => this._runModels.has(m))) {
123
127
  return;
128
+ }
124
129
  this._runModels = next;
125
130
  this._kick();
126
131
  }
@@ -175,13 +180,15 @@ export class ModelDownloadReconciler {
175
180
  return;
176
181
  }
177
182
  const rows = await this._harness.list({}).catch(noop);
178
- if (this._closed || this._handled.has(model) || signal.aborted)
183
+ if (this._closed || this._handled.has(model) || signal.aborted) {
179
184
  return;
185
+ }
180
186
  let addon = 'llm';
181
187
  if (rows) {
182
188
  const row = rows.find((entry) => entry.name === model);
183
- if (!row || row.isCached)
189
+ if (!row || row.isCached) {
184
190
  return;
191
+ }
185
192
  addon = row.type;
186
193
  }
187
194
  await new Promise((resolve, reject) => {
@@ -207,30 +214,57 @@ export class ModelDownloadReconciler {
207
214
  this._requestedModels.add(name);
208
215
  this._attemptGenerations.set(name, this._attemptGeneration(name) + 1);
209
216
  const demand = this._demands.get(name);
210
- if (demand)
217
+ if (demand) {
211
218
  demand.failures = 0;
219
+ }
212
220
  this._retry.reset(name);
213
221
  this._scheduler.clear();
214
- if (this._active?.model === name)
222
+ if (this._active?.model === name) {
215
223
  await this._stopActive(false);
224
+ }
216
225
  this._kick();
217
226
  }
227
+ async release(name, removeFiles) {
228
+ if (this._closed)
229
+ throw new Error('model download reconciler is closed');
230
+ this._releasing.add(name);
231
+ this._requestedModels.delete(name);
232
+ this._handled.delete(name);
233
+ try {
234
+ if (this._active?.model === name) {
235
+ await this._stopActive(true);
236
+ }
237
+ const result = await removeFiles();
238
+ this._config = await this._engine.setModelReleased({ name, released: true });
239
+ await this._running;
240
+ return result;
241
+ }
242
+ finally {
243
+ this._releasing.delete(name);
244
+ this._kick();
245
+ }
246
+ }
218
247
  async close() {
219
248
  this._closed = true;
220
249
  this._scheduler.clear();
221
- for (const timer of this._timers)
250
+ for (const timer of this._timers) {
222
251
  clearTimeout(timer);
252
+ }
223
253
  this._timers.clear();
224
- if (this._configStream?.return)
254
+ if (this._configStream?.return) {
225
255
  await this._configStream.return();
226
- if (this._agentsStream?.return)
256
+ }
257
+ if (this._agentsStream?.return) {
227
258
  await this._agentsStream.return();
228
- if (this._toolConfigsStream?.return)
259
+ }
260
+ if (this._toolConfigsStream?.return) {
229
261
  await this._toolConfigsStream.return();
262
+ }
230
263
  await this._stopActive(false);
231
264
  await this._running;
232
- for (const name of [...this._demands.keys()])
265
+ for (const name of [...this._demands.keys()]) {
233
266
  this._resolveDemand(name);
267
+ }
234
268
  }
235
269
  _watchConfig() {
236
270
  if (this._closed)
@@ -240,8 +274,9 @@ export class ModelDownloadReconciler {
240
274
  this._configStream = stream[Symbol.asyncIterator]();
241
275
  while (true) {
242
276
  const { value, done } = await this._configStream.next();
243
- if (done || this._closed)
277
+ if (done || this._closed) {
244
278
  return;
279
+ }
245
280
  this._config = value;
246
281
  this._syncToolConfigsWatch();
247
282
  this._kick();
@@ -251,25 +286,29 @@ export class ModelDownloadReconciler {
251
286
  }
252
287
  _syncToolConfigsWatch() {
253
288
  const agentId = this._config?.activeAgentId ?? null;
254
- if (agentId === this._toolConfigsAgentId)
289
+ if (agentId === this._toolConfigsAgentId) {
255
290
  return;
291
+ }
256
292
  this._swapToolConfigsWatch(agentId);
257
293
  }
258
294
  _swapToolConfigsWatch(agentId) {
259
295
  const previous = this._toolConfigsStream;
260
296
  this._toolConfigsStream = null;
261
297
  this._toolConfigsAgentId = agentId;
262
- if (previous?.return)
263
- void previous.return().catch(() => { });
264
- if (agentId)
298
+ if (previous?.return) {
299
+ void previous.return().catch(noop);
300
+ }
301
+ if (agentId) {
265
302
  this._watchToolConfigs(agentId);
303
+ }
266
304
  }
267
305
  _watchToolConfigs(agentId) {
268
306
  if (this._closed)
269
307
  return;
270
308
  const meshId = this._meshId();
271
- if (!meshId)
309
+ if (!meshId) {
272
310
  return;
311
+ }
273
312
  let active = null;
274
313
  const run = async () => {
275
314
  const stream = this._engine.toolConfigsWatch({ agentId, meshId });
@@ -278,8 +317,9 @@ export class ModelDownloadReconciler {
278
317
  this._toolConfigsStream = iterator;
279
318
  while (true) {
280
319
  const { done } = await iterator.next();
281
- if (done || this._closed || this._toolConfigsStream !== iterator)
320
+ if (done || this._closed || this._toolConfigsStream !== iterator) {
282
321
  return;
322
+ }
283
323
  this._kick();
284
324
  }
285
325
  };
@@ -287,8 +327,9 @@ export class ModelDownloadReconciler {
287
327
  if (active && this._toolConfigsStream !== active)
288
328
  return;
289
329
  this._restartWatch('toolConfigs', err, () => {
290
- if (this._toolConfigsAgentId === agentId)
330
+ if (this._toolConfigsAgentId === agentId) {
291
331
  this._watchToolConfigs(agentId);
332
+ }
292
333
  });
293
334
  });
294
335
  }
@@ -296,15 +337,17 @@ export class ModelDownloadReconciler {
296
337
  if (this._closed)
297
338
  return;
298
339
  const meshId = this._meshId();
299
- if (!meshId)
340
+ if (!meshId) {
300
341
  return;
342
+ }
301
343
  const run = async () => {
302
344
  const stream = this._engine.agentsWatch({ meshId });
303
345
  this._agentsStream = stream[Symbol.asyncIterator]();
304
346
  while (true) {
305
347
  const { done } = await this._agentsStream.next();
306
- if (done || this._closed)
348
+ if (done || this._closed) {
307
349
  return;
350
+ }
308
351
  this._kick();
309
352
  }
310
353
  };
@@ -319,8 +362,9 @@ export class ModelDownloadReconciler {
319
362
  _scheduleRestart(restart) {
320
363
  const timer = setTimeout(() => {
321
364
  this._timers.delete(timer);
322
- if (this._closed)
365
+ if (this._closed) {
323
366
  return;
367
+ }
324
368
  restart();
325
369
  }, this._watchRetryMs);
326
370
  unref(timer);
@@ -330,12 +374,14 @@ export class ModelDownloadReconciler {
330
374
  if (this._closed || this._paused)
331
375
  return;
332
376
  this._dirty = true;
333
- if (this._running)
377
+ if (this._running) {
334
378
  return;
379
+ }
335
380
  this._running = this._drain().finally(() => {
336
381
  this._running = null;
337
- if (this._dirty)
382
+ if (this._dirty) {
338
383
  this._kick();
384
+ }
339
385
  });
340
386
  }
341
387
  async _drain() {
@@ -362,8 +408,9 @@ export class ModelDownloadReconciler {
362
408
  }
363
409
  await this._flushObservedProgress();
364
410
  const targets = await this._desired();
365
- if (this._closed || this._paused)
411
+ if (this._closed || this._paused) {
366
412
  return;
413
+ }
367
414
  const downloadable = new Map(targets.filter((t) => !t.paused).map((t) => [t.name, t]));
368
415
  if (this._active && !downloadable.has(this._active.model)) {
369
416
  const stillWanted = targets.some((t) => t.name === this._active?.model);
@@ -375,13 +422,15 @@ export class ModelDownloadReconciler {
375
422
  if (this._runModels.size === 0) {
376
423
  const preemptLlm = this._preemptLlm;
377
424
  this._preemptLlm = null;
378
- if (this._shouldPreempt(preferred, preemptLlm))
425
+ if (this._shouldPreempt(preferred, preemptLlm)) {
379
426
  await this._stopActive(false);
427
+ }
380
428
  }
381
429
  const next = this._active ? null : preferred;
382
430
  await this._writeWaiting(targets, next?.name, now);
383
- if (next && !this._closed && !this._paused)
431
+ if (next && !this._closed && !this._paused) {
384
432
  this._begin(next);
433
+ }
385
434
  }
386
435
  async _writeWaiting(targets, nextName, now) {
387
436
  for (const target of targets) {
@@ -403,8 +452,9 @@ export class ModelDownloadReconciler {
403
452
  if (progress.phase === 'complete') {
404
453
  await this._completeTransfer(model);
405
454
  this._observedTransfers.delete(model);
406
- if (this._observedProgress.get(model) === progress)
455
+ if (this._observedProgress.get(model) === progress) {
407
456
  this._observedProgress.delete(model);
457
+ }
408
458
  this._handled.add(model);
409
459
  this._retry.reset(model);
410
460
  this._observedSpeed.delete(model);
@@ -414,8 +464,9 @@ export class ModelDownloadReconciler {
414
464
  continue;
415
465
  }
416
466
  await this._engine.beginModelTransfer({ name: model, transferred: true });
417
- if (this._observedProgress.get(model) === progress)
467
+ if (this._observedProgress.get(model) === progress) {
418
468
  this._observedProgress.delete(model);
469
+ }
419
470
  const total = progress.total > 0 ? progress.total : expectedTotal;
420
471
  const downloaded = total > 0 ? Math.min(progress.downloaded, total) : progress.downloaded;
421
472
  let speed = this._observedSpeed.get(model);
@@ -463,8 +514,9 @@ export class ModelDownloadReconciler {
463
514
  _scheduleNextRetry(downloadable, now) {
464
515
  this._scheduler.clear();
465
516
  const deadline = this._retry.nextDeadline(new Set(downloadable.keys()), now);
466
- if (deadline !== null)
517
+ if (deadline !== null) {
467
518
  this._scheduler.schedule(deadline);
519
+ }
468
520
  }
469
521
  async _desired() {
470
522
  if (this._demands.size === 0 &&
@@ -477,9 +529,12 @@ export class ModelDownloadReconciler {
477
529
  return [];
478
530
  }
479
531
  const availability = await this._modelAvailability();
480
- for (const name of availability.cached)
532
+ for (const name of availability.cached) {
481
533
  this._handled.delete(name);
534
+ }
482
535
  const paused = new Set(this._config?.pausedModels ?? []);
536
+ await this._reclaimCached(new Set([...availability.cached, ...this._handled]));
537
+ const released = new Set([...(this._config?.releasedModels ?? []), ...this._releasing]);
483
538
  const wanted = new Map();
484
539
  for (const [name, demand] of this._demands) {
485
540
  wanted.set(name, { name, addon: demand.addon, paused: paused.has(name) });
@@ -493,11 +548,11 @@ export class ModelDownloadReconciler {
493
548
  this._preemptLlm = localLlm;
494
549
  }
495
550
  this._pausedLocalLlm = localLlm !== null && paused.has(localLlm) ? localLlm : null;
496
- if (localLlm && !wanted.has(localLlm)) {
551
+ if (localLlm && !wanted.has(localLlm) && !released.has(localLlm)) {
497
552
  wanted.set(localLlm, { name: localLlm, addon: 'llm', paused: paused.has(localLlm) });
498
553
  }
499
554
  for (const model of [...this._localSkillModels, ...infra]) {
500
- if (!wanted.has(model.name)) {
555
+ if (!wanted.has(model.name) && !released.has(model.name)) {
501
556
  wanted.set(model.name, { ...model, paused: paused.has(model.name) });
502
557
  }
503
558
  }
@@ -506,14 +561,16 @@ export class ModelDownloadReconciler {
506
561
  if (wanted.has(name))
507
562
  continue;
508
563
  const addon = availability.addons.get(name);
509
- if (addon === undefined)
564
+ if (addon === undefined) {
510
565
  continue;
566
+ }
511
567
  wanted.set(name, { name, addon, paused: paused.has(name) });
512
568
  }
513
569
  const wantedNames = new Set(wanted.keys());
514
570
  for (const name of this._attemptGenerations.keys()) {
515
- if (!wantedNames.has(name))
571
+ if (!wantedNames.has(name)) {
516
572
  this._attemptGenerations.delete(name);
573
+ }
517
574
  }
518
575
  this._retry.retain(wantedNames);
519
576
  await this._status.clearUnwanted(wantedNames);
@@ -531,8 +588,9 @@ export class ModelDownloadReconciler {
531
588
  });
532
589
  }
533
590
  const pendingNames = new Set(pending.map((target) => target.name));
534
- for (const target of pending)
591
+ for (const target of pending) {
535
592
  this._targetTotals.set(target.name, target.total);
593
+ }
536
594
  for (const name of this._targetTotals.keys()) {
537
595
  if (pendingNames.has(name))
538
596
  continue;
@@ -542,6 +600,13 @@ export class ModelDownloadReconciler {
542
600
  }
543
601
  return pending;
544
602
  }
603
+ async _reclaimCached(cached) {
604
+ for (const name of this._config?.releasedModels ?? []) {
605
+ if (!cached.has(name) || this._releasing.has(name))
606
+ continue;
607
+ this._config = await this._engine.setModelReleased({ name, released: false });
608
+ }
609
+ }
545
610
  async _modelAvailability() {
546
611
  const rows = (await this._harness.list?.({}).catch(() => [])) ?? [];
547
612
  const cached = new Set(rows.filter((row) => row.isCached).map((row) => row.name));
@@ -558,12 +623,14 @@ export class ModelDownloadReconciler {
558
623
  if (this._profile)
559
624
  return this._profile;
560
625
  const meshId = this._meshId();
561
- if (!meshId)
626
+ if (!meshId) {
562
627
  return this._profile ?? 'mid';
628
+ }
563
629
  const { devices } = await this._engine.listDevices({ meshId }).catch(() => ({ devices: [] }));
564
- const self = (devices ?? []).find((device) => device.id.equals(this._deviceId));
565
- if (self)
630
+ const self = (devices ?? []).find((device) => b4a.equals(device.id, this._deviceId));
631
+ if (self) {
566
632
  this._profile = self.capabilityProfile;
633
+ }
567
634
  return this._profile ?? 'mid';
568
635
  }
569
636
  async _hostCapability() {
@@ -571,8 +638,9 @@ export class ModelDownloadReconciler {
571
638
  return this._capability;
572
639
  try {
573
640
  const probed = await this._harness.capability?.();
574
- if (!probed?.recommendedModelName)
641
+ if (!probed?.recommendedModelName) {
575
642
  return null;
643
+ }
576
644
  this._capability = probed;
577
645
  return probed;
578
646
  }
@@ -584,72 +652,82 @@ export class ModelDownloadReconciler {
584
652
  async _refreshLocalAgentModels() {
585
653
  const activeAgentId = this._config?.activeAgentId;
586
654
  const meshId = this._meshId();
587
- if (!activeAgentId || !meshId)
655
+ if (!activeAgentId || !meshId) {
588
656
  return;
657
+ }
589
658
  const agent = await this._engine.getAgent({ agentId: activeAgentId, meshId }).catch(noop);
590
- if (!agent?.modelName)
659
+ if (!agent?.modelName) {
591
660
  return;
592
- if (!agent.providerDeviceId?.equals(this._deviceId))
661
+ }
662
+ if (!agent.providerDeviceId || !b4a.equals(agent.providerDeviceId, this._deviceId)) {
593
663
  return;
664
+ }
594
665
  const model = runnableModelName(agent.modelName, await this._hostCapability(), this._mobileClass);
595
666
  const music = await this._musicModelChoice(activeAgentId);
596
- if (this._config?.activeAgentId !== activeAgentId)
667
+ if (this._config?.activeAgentId !== activeAgentId) {
597
668
  return;
669
+ }
598
670
  if (model !== agent.modelName) {
599
671
  this._log?.warn('model-download', 'model clamped to what this device can run', {
600
672
  requested: agent.modelName,
601
673
  model
602
674
  });
603
675
  }
604
- if (model !== this._localLlm)
676
+ if (model !== this._localLlm) {
605
677
  this._preemptLlm = model;
678
+ }
606
679
  this._localLlm = model;
607
- if (music.ok)
680
+ if (music.ok) {
608
681
  this._musicChoice = music.choice;
682
+ }
609
683
  this._localSkillModels = skillModelsForAgent({ ...agent, musicModelChoice: this._musicChoice });
610
684
  }
611
685
  async _musicModelChoice(agentId) {
612
686
  const meshId = this._meshId();
613
- if (!meshId)
687
+ if (!meshId) {
614
688
  return { ok: false };
689
+ }
615
690
  const configs = await this._engine
616
691
  .listToolConfigs({ agentId, meshId })
617
692
  .then((result) => result.configs ?? [])
618
693
  .catch(noop);
619
- if (!configs)
694
+ if (!configs) {
620
695
  return { ok: false };
696
+ }
621
697
  const row = configs.find((entry) => entry?.toolName === GENERATE_MUSIC_TOOL);
622
698
  const settings = row?.settings;
623
- if (!settings || typeof settings !== 'object')
699
+ if (!settings || typeof settings !== 'object') {
624
700
  return { ok: true, choice: undefined };
625
- const choice = settings.modelChoice;
626
- return {
627
- ok: true,
628
- choice: typeof choice === 'string' &&
629
- MUSIC_MODEL_CHOICES.includes(choice)
630
- ? choice
631
- : undefined
632
- };
701
+ }
702
+ const choice = 'modelChoice' in settings ? settings.modelChoice : undefined;
703
+ return { ok: true, choice: isMusicModelChoice(choice) ? choice : undefined };
633
704
  }
634
705
  _begin({ name, addon, total }) {
635
706
  const controller = new AbortController();
636
- const done = this._download(name, addon, total, controller, this._attemptGeneration(name));
707
+ const done = this._download(name, controller, {
708
+ addon,
709
+ expectedTotal: total,
710
+ attemptGeneration: this._attemptGeneration(name)
711
+ });
637
712
  this._active = { model: name, addon, total, controller, done };
638
713
  }
639
714
  _removeDemandWaiter(model, waiter) {
640
715
  const demand = this._demands.get(model);
641
- if (!demand)
716
+ if (!demand) {
642
717
  return;
718
+ }
643
719
  demand.waiters.delete(waiter);
644
720
  waiter.signal.removeEventListener('abort', waiter.abort);
645
- if (demand.waiters.size === 0)
721
+ if (demand.waiters.size === 0) {
646
722
  this._demands.delete(model);
723
+ }
647
724
  this._kick();
648
725
  }
649
726
  _resolveDemand(model) {
650
727
  const demand = this._demands.get(model);
651
- if (!demand)
728
+ if (!demand) {
652
729
  return;
730
+ }
653
731
  this._demands.delete(model);
654
732
  for (const waiter of demand.waiters) {
655
733
  waiter.signal.removeEventListener('abort', waiter.abort);
@@ -658,11 +736,13 @@ export class ModelDownloadReconciler {
658
736
  }
659
737
  _failDemand(model, message) {
660
738
  const demand = this._demands.get(model);
661
- if (!demand)
739
+ if (!demand) {
662
740
  return;
741
+ }
663
742
  demand.failures += 1;
664
- if (demand.failures < MAX_DEMAND_FAILURES)
743
+ if (demand.failures < MAX_DEMAND_FAILURES) {
665
744
  return;
745
+ }
666
746
  this._demands.delete(model);
667
747
  for (const waiter of demand.waiters) {
668
748
  waiter.signal.removeEventListener('abort', waiter.abort);
@@ -674,15 +754,17 @@ export class ModelDownloadReconciler {
674
754
  }
675
755
  async _stopActive(clear) {
676
756
  const active = this._active;
677
- if (!active)
757
+ if (!active) {
678
758
  return;
759
+ }
679
760
  this._active = null;
680
761
  active.controller.abort('model-download superseded');
681
762
  await active.done;
682
- if (clear)
763
+ if (clear) {
683
764
  await this._status.clear(active.model);
765
+ }
684
766
  }
685
- async _download(model, addon, expectedTotal, controller, attemptGeneration) {
767
+ async _download(model, controller, { addon, expectedTotal, attemptGeneration }) {
686
768
  const current = () => this._active?.controller === controller;
687
769
  const speed = new DownloadSpeedSampler();
688
770
  let localFlush = null;
@@ -691,12 +773,41 @@ export class ModelDownloadReconciler {
691
773
  let retry = false;
692
774
  let completed = false;
693
775
  let failureMessage = 'model download failed';
776
+ const recordProgress = async (event) => {
777
+ const at = this._now();
778
+ const transfer = transferProgress(event);
779
+ if (!recordedTransfer &&
780
+ (event.transferred === true ||
781
+ (event.transferred === undefined && transfer && transfer.percentage < 100))) {
782
+ await this._engine.beginModelTransfer({ name: model, transferred: true });
783
+ recordedTransfer = true;
784
+ }
785
+ if (hasTransfer && isEmptyTick(transfer)) {
786
+ return;
787
+ }
788
+ const bytes = transfer ?? progressBytes(event);
789
+ const percentage = transfer?.percentage ?? 0;
790
+ if (shouldFlush(localFlush, { at, percentage })) {
791
+ const written = await this._status.write(model, 'downloading', {
792
+ percentage,
793
+ downloaded: bytes.downloaded,
794
+ total: bytes.total,
795
+ bytesPerSecond: speed.sample(bytes, at, event.downloadKey)
796
+ });
797
+ if (written) {
798
+ localFlush = { at, percentage };
799
+ hasTransfer ||= !isEmptyTick(transfer);
800
+ }
801
+ }
802
+ };
694
803
  try {
695
- if (this._completedTransfers.delete(model))
804
+ if (this._completedTransfers.delete(model)) {
696
805
  this._transfers.delete(model);
806
+ }
697
807
  await this._transfer(model);
698
- if (controller.signal.aborted || !current())
808
+ if (controller.signal.aborted || !current()) {
699
809
  return;
810
+ }
700
811
  const initialPercentage = 0;
701
812
  const initialAt = this._now();
702
813
  if (await this._status.write(model, 'downloading', {
@@ -707,6 +818,9 @@ export class ModelDownloadReconciler {
707
818
  })) {
708
819
  localFlush = { at: initialAt, percentage: initialPercentage };
709
820
  }
821
+ if (!this._harness.download) {
822
+ throw new Error('the harness cannot download models');
823
+ }
710
824
  for await (const event of this._harness.download({
711
825
  model,
712
826
  addon,
@@ -714,35 +828,12 @@ export class ModelDownloadReconciler {
714
828
  })) {
715
829
  if (this._closed || !current())
716
830
  return;
831
+ if (event.type === 'complete' && controller.signal.aborted)
832
+ return;
717
833
  if (event.type === 'progress') {
718
- const at = this._now();
719
- const transfer = transferProgress(event);
720
- if (!recordedTransfer &&
721
- (event.transferred === true ||
722
- (event.transferred === undefined && transfer && transfer.percentage < 100))) {
723
- await this._engine.beginModelTransfer({ name: model, transferred: true });
724
- recordedTransfer = true;
725
- }
726
- if (hasTransfer && isEmptyTick(transfer))
727
- continue;
728
- const bytes = transfer ?? progressBytes(event);
729
- const percentage = transfer?.percentage ?? 0;
730
- if (shouldFlush(localFlush, percentage, at, LOCAL_PROGRESS_INTERVAL_MS, LOCAL_PROGRESS_PERCENTAGE_STEP)) {
731
- const written = await this._status.write(model, 'downloading', {
732
- percentage,
733
- downloaded: bytes.downloaded,
734
- total: bytes.total,
735
- bytesPerSecond: speed.sample(bytes, at, event.downloadKey)
736
- });
737
- if (written) {
738
- localFlush = { at, percentage };
739
- hasTransfer ||= !isEmptyTick(transfer);
740
- }
741
- }
834
+ await recordProgress(event);
742
835
  }
743
836
  else if (event.type === 'complete') {
744
- if (controller.signal.aborted)
745
- return;
746
837
  await this._completeTransfer(model, { downloaded: event.downloaded !== false });
747
838
  completed = true;
748
839
  retry = false;
@@ -769,13 +860,14 @@ export class ModelDownloadReconciler {
769
860
  });
770
861
  }
771
862
  }
772
- if (current() && !controller.signal.aborted && !completed && !retry)
863
+ if (current() && !controller.signal.aborted && !completed && !retry) {
773
864
  retry = true;
865
+ }
774
866
  }
775
867
  catch (err) {
776
868
  if (!this._closed && current()) {
777
869
  retry = true;
778
- failureMessage = err instanceof Error ? err.message : String(err);
870
+ failureMessage = errorMessage(err);
779
871
  await this._status.write(model, 'error', {
780
872
  error: failureMessage,
781
873
  bytesPerSecond: 0
@@ -784,8 +876,9 @@ export class ModelDownloadReconciler {
784
876
  }
785
877
  finally {
786
878
  const wasCurrent = current();
787
- if (wasCurrent)
879
+ if (wasCurrent) {
788
880
  this._active = null;
881
+ }
789
882
  if (retry &&
790
883
  !this._closed &&
791
884
  !this._paused &&
@@ -793,8 +886,9 @@ export class ModelDownloadReconciler {
793
886
  this._failDemand(model, failureMessage);
794
887
  this._scheduler.schedule(this._retry.fail(model, this._now()));
795
888
  }
796
- if (!this._closed && !this._paused && wasCurrent)
889
+ if (!this._closed && !this._paused && wasCurrent) {
797
890
  this._kick();
891
+ }
798
892
  }
799
893
  }
800
894
  }
@@ -802,9 +896,12 @@ function isEmptyTick(transfer) {
802
896
  return (transfer === null ||
803
897
  (transfer.percentage === 0 && transfer.downloaded === 0 && transfer.total === 0));
804
898
  }
805
- function shouldFlush(previous, percentage, at, intervalMs, percentageStep) {
899
+ function shouldFlush(previous, { at, percentage }) {
806
900
  return (previous === null ||
807
- at - previous.at >= intervalMs ||
808
- percentage - previous.percentage >= percentageStep);
901
+ at - previous.at >= LOCAL_PROGRESS_INTERVAL_MS ||
902
+ percentage - previous.percentage >= LOCAL_PROGRESS_PERCENTAGE_STEP);
903
+ }
904
+ function isMusicModelChoice(value) {
905
+ return MUSIC_MODEL_CHOICES.some((choice) => choice === value);
809
906
  }
810
907
  function noop() { }