@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
@@ -1,16 +1,16 @@
1
1
  import { diagramRepairAccepted, diagramRepairLinks, isDiagramRepairPrompt } from '@qvac/harness/lib/diagram-repair.ts';
2
- import { chunkTypeOrdinal } from '../../schema/helpers.js';
2
+ import { chunkTypeOrdinal } from '../../schema/indexes.js';
3
3
  import { enrichAll, lastActivity, liveGroupIds } from './chat.js';
4
4
  import { foldSearchText } from './search-fold.js';
5
- const ACTIVE_CHATS = '@qvac/active-chats';
6
- const CHUNKS_BY_TYPE = '@qvac/chunks-by-type';
5
+ import { ACTIVE_CHATS, CHUNKS_BY_TYPE } from './collections.js';
7
6
  const DEFAULT_LIMIT = 100;
8
7
  const PER_CHAT_LIMIT = 20;
9
8
  const SNIPPET_PAD = 40;
10
9
  export async function searchChats(store, input) {
11
10
  const needle = foldSearchText(input.query.trim());
12
- if (!needle)
11
+ if (!needle) {
13
12
  return [];
13
+ }
14
14
  const limit = input.limit || DEFAULT_LIMIT;
15
15
  const snap = store.view.snapshot();
16
16
  try {
@@ -20,23 +20,27 @@ export async function searchChats(store, input) {
20
20
  const titled = [];
21
21
  const untitled = [];
22
22
  for (const chat of chats) {
23
- if (foldSearchText(chat.title).includes(needle))
23
+ if (foldSearchText(chat.title).includes(needle)) {
24
24
  titled.push(chat);
25
- else
25
+ }
26
+ else {
26
27
  untitled.push(chat);
28
+ }
27
29
  }
28
30
  const hits = [];
29
31
  for (const chat of titled) {
30
32
  hits.push(titleHit(chat));
31
- if (hits.length >= limit)
33
+ if (hits.length >= limit) {
32
34
  return hits;
35
+ }
33
36
  }
34
37
  for (const chat of [...titled, ...untitled]) {
35
38
  if (input.signal?.aborted)
36
39
  break;
37
- hits.push(...(await contentHits(snap, chat, needle, remainingCap(hits.length, limit))));
38
- if (hits.length >= limit)
40
+ hits.push(...(await contentHits(snap, chat, { needle, cap: remainingCap(hits.length, limit) })));
41
+ if (hits.length >= limit) {
39
42
  break;
43
+ }
40
44
  }
41
45
  return hits;
42
46
  }
@@ -50,7 +54,7 @@ function remainingCap(used, limit) {
50
54
  function titleHit(chat) {
51
55
  return { chat, match: 'title', snippet: '', chunkId: '', runId: '' };
52
56
  }
53
- async function contentHits(snap, chat, needle, cap) {
57
+ async function contentHits(snap, chat, { needle, cap }) {
54
58
  if (cap <= 0)
55
59
  return [];
56
60
  const [users, content, attachments, requests, statuses] = await Promise.all([
@@ -76,18 +80,20 @@ async function contentHits(snap, chat, needle, cap) {
76
80
  for (const repair of repairs) {
77
81
  const parentRunId = requests.find((request) => request.id === repair.parentId)?.runId;
78
82
  if (completedRunIds.has(repair.runId) && diagramRepairAccepted(repairText(repair.runId))) {
79
- if (parentRunId)
83
+ if (parentRunId) {
80
84
  hiddenRunIds.add(parentRunId);
85
+ }
81
86
  }
82
87
  else {
83
88
  hiddenRunIds.add(repair.runId);
84
- if (parentRunId)
89
+ if (parentRunId) {
85
90
  redactedRunIds.add(parentRunId);
91
+ }
86
92
  }
87
93
  }
88
94
  const matches = [
89
- ...matchUserMessages(users, needle, cap, hiddenPromptIds),
90
- ...matchJoinedContent(content, needle, cap, { hidden: hiddenRunIds, redacted: redactedRunIds }),
95
+ ...matchUserMessages(users, needle, { cap, hiddenIds: hiddenPromptIds }),
96
+ ...matchJoinedContent(content, needle, { cap, hidden: hiddenRunIds, redacted: redactedRunIds }),
91
97
  ...matchAttachments(attachments, needle, cap)
92
98
  ];
93
99
  return matches
@@ -110,28 +116,31 @@ async function chunksOfType(snap, chatId, type) {
110
116
  })
111
117
  .toArray();
112
118
  }
113
- function matchUserMessages(chunks, needle, cap, hiddenIds) {
119
+ function matchUserMessages(chunks, needle, { cap, hiddenIds }) {
114
120
  const matches = [];
115
121
  for (const chunk of chunks) {
116
122
  if (matches.length >= cap)
117
123
  break;
118
124
  const text = chunk.userMessage?.text;
119
- if (!text || hiddenIds.has(chunk.id))
125
+ if (!text || hiddenIds.has(chunk.id)) {
120
126
  continue;
127
+ }
121
128
  const found = locate(text, needle);
122
- if (!found)
129
+ if (!found) {
123
130
  continue;
131
+ }
124
132
  matches.push({ seq: chunk.seq, snippet: found, chunkId: chunk.id, runId: chunk.runId ?? '' });
125
133
  }
126
134
  return matches;
127
135
  }
128
- function matchJoinedContent(chunks, needle, cap, runs) {
136
+ function matchJoinedContent(chunks, needle, { cap, ...runs }) {
129
137
  const byRun = new Map();
130
138
  const order = [];
131
139
  for (const chunk of chunks) {
132
140
  const runId = chunk.runId;
133
- if (!runId || runs.hidden.has(runId))
141
+ if (!runId || runs.hidden.has(runId)) {
134
142
  continue;
143
+ }
135
144
  const group = byRun.get(runId);
136
145
  if (group) {
137
146
  group.push(chunk);
@@ -146,13 +155,15 @@ function matchJoinedContent(chunks, needle, cap, runs) {
146
155
  break;
147
156
  const group = byRun.get(runId);
148
157
  const first = group?.[0];
149
- if (!group || !first)
158
+ if (!group || !first) {
150
159
  continue;
160
+ }
151
161
  const content = group.map((chunk) => chunk.content?.text ?? '').join('');
152
162
  const text = runs.redacted.has(runId) ? withoutMermaidDiagrams(content) : content;
153
163
  const found = locate(text, needle);
154
- if (!found)
164
+ if (!found) {
155
165
  continue;
166
+ }
156
167
  matches.push({ seq: first.seq, snippet: found, chunkId: first.id, runId });
157
168
  }
158
169
  return matches;
@@ -166,11 +177,13 @@ function matchAttachments(chunks, needle, cap) {
166
177
  if (matches.length >= cap)
167
178
  break;
168
179
  const attachment = chunk.attachment;
169
- if (!attachment || (attachment.deletedAt ?? 0) > 0)
180
+ if (!attachment || (attachment.deletedAt ?? 0) > 0) {
170
181
  continue;
182
+ }
171
183
  const found = locate(attachment.fileName, needle);
172
- if (!found)
184
+ if (!found) {
173
185
  continue;
186
+ }
174
187
  matches.push({ seq: chunk.seq, snippet: found, chunkId: chunk.id, runId: chunk.runId ?? '' });
175
188
  }
176
189
  return matches;
@@ -179,8 +192,9 @@ function locate(text, needle) {
179
192
  if (!text)
180
193
  return null;
181
194
  const index = foldSearchText(text).indexOf(needle);
182
- if (index < 0)
195
+ if (index < 0) {
183
196
  return null;
197
+ }
184
198
  return snippetAround(text, index, needle.length);
185
199
  }
186
200
  function snippetAround(text, index, needleLength) {
@@ -20,23 +20,29 @@ export declare function getChat(store: Mesh, id: string): Promise<QvacChat | nul
20
20
  export declare function mustGetChat(store: Mesh, id: string): Promise<QvacChat>;
21
21
  export declare function mustGetActiveChat(store: Mesh, id: string): Promise<QvacChat>;
22
22
  export declare function mustGetActiveChatListing(store: Mesh, id: string): Promise<ChatListing>;
23
- export declare function buildChat(input: {
24
- agentId: string;
25
- title: string;
26
- }): QvacChat;
27
- export declare function createChat(store: Mesh, input: {
28
- agentId: string;
29
- title: string;
30
- }): Promise<ChatListing>;
23
+ export interface CreateChatInput {
24
+ readonly agentId: string;
25
+ readonly title: string;
26
+ }
27
+ export declare function buildChat(input: CreateChatInput): QvacChat;
28
+ export declare function createChat(store: Mesh, input: CreateChatInput): Promise<ChatListing>;
31
29
  export declare function renameChat(store: Mesh, id: string, title: string): Promise<ChatListing>;
32
- export declare function setChatRagEnabled(store: Mesh, id: string, ragEnabled: boolean): Promise<ChatListing>;
30
+ export interface SetChatRagEnabledOptions {
31
+ readonly ragEnabled: boolean;
32
+ }
33
+ export declare function setChatRagEnabled(store: Mesh, id: string, opts: SetChatRagEnabledOptions): Promise<ChatListing>;
33
34
  export declare function setChatGroup(store: Mesh, id: string, groupId: string | null | undefined): Promise<ChatListing>;
34
- export declare function moveChat(store: Mesh, id: string, { groupId, afterId }: {
35
- groupId?: string | null;
36
- afterId?: string | null;
37
- }): Promise<ChatListing>;
35
+ export interface MoveChatOptions {
36
+ readonly groupId?: string | null;
37
+ readonly afterId?: string | null;
38
+ }
39
+ export declare function moveChat(store: Mesh, id: string, { groupId, afterId }: MoveChatOptions): Promise<ChatListing>;
38
40
  export declare function setChatWebSearchEnabled(store: Mesh, id: string, webSearchEnabled: boolean): Promise<ChatListing>;
39
41
  export declare function removeChatKnowledge(store: Mesh, chatId: string, at: number): Promise<void>;
40
- export declare function removeChatAttachments(store: Mesh, deviceId: Buffer, chatId: string, at: number): Promise<void>;
42
+ export interface RemoveChatAttachmentsOptions {
43
+ readonly deviceId: Buffer;
44
+ readonly at: number;
45
+ }
46
+ export declare function removeChatAttachments(store: Mesh, chatId: string, { deviceId, at }: RemoveChatAttachmentsOptions): Promise<void>;
41
47
  export declare function deleteChat(store: Mesh, deviceId: Buffer | null, id: string): Promise<ChatListing>;
42
48
  export declare function softDeleteChatsForAgent(store: Mesh, deviceId: Buffer | null, agentId: string): Promise<void>;
@@ -2,14 +2,11 @@ import { listChatGroupsIn, mustGetActiveChatGroup } from './chat-group.js';
2
2
  import { appendChunk, listChunks, updateOp } from './chunk.js';
3
3
  import { randomId } from './id.js';
4
4
  import { assertRemovableAt } from './files/index.js';
5
+ import { chatReferences, reclaimReferences } from './files/records/purge.js';
5
6
  import { place } from './rank.js';
6
7
  import { chatSortKey } from './chat-order.js';
7
- const CHATS = '@qvac/chats';
8
- const CHAT_GROUPS = '@qvac/chat-groups';
9
- const ACTIVE_CHATS = '@qvac/active-chats';
10
- const ACTIVE_CHATS_BY_AGENT = '@qvac/active-chats-by-agent';
11
- const ACTIVE_CHAT_GROUPS = '@qvac/active-chat-groups';
12
- const CHUNK_COUNTERS = '@qvac/chunk-counters';
8
+ import b4a from 'b4a';
9
+ import { ACTIVE_CHATS, ACTIVE_CHATS_BY_AGENT, ACTIVE_CHAT_GROUPS, CHATS, CHAT_GROUPS, CHUNK_COUNTERS } from './collections.js';
13
10
  const TERMINAL_RUN_STATES = new Set(['completed', 'failed', 'canceled']);
14
11
  function byChatOrder(a, b) {
15
12
  return chatSortKey(a) - chatSortKey(b) || (a.id < b.id ? -1 : 1);
@@ -22,11 +19,11 @@ export async function lastActivity(snap) {
22
19
  const counters = await snap.find(CHUNK_COUNTERS).toArray();
23
20
  return new Map(counters.map((counter) => [counter.chatId, counter.lastActivityAt ?? 0]));
24
21
  }
25
- function listingOf(chat, inLiveGroup, activityAt) {
22
+ function listingOf(chat, opts) {
26
23
  return {
27
24
  ...chat,
28
- groupId: inLiveGroup ? chat.groupId : undefined,
29
- lastActivityAt: activityAt || chat.createdAt
25
+ groupId: opts.inLiveGroup ? chat.groupId : undefined,
26
+ lastActivityAt: opts.activityAt || chat.createdAt
30
27
  };
31
28
  }
32
29
  export async function enrichChat(store, chat) {
@@ -45,10 +42,16 @@ export async function enrichIn(snap, chat) {
45
42
  : Promise.resolve(null),
46
43
  snap.get(CHUNK_COUNTERS, { chatId: chat.id })
47
44
  ]);
48
- return listingOf(chat, Boolean(group) && !group?.deletedAt, counter?.lastActivityAt);
45
+ return listingOf(chat, {
46
+ inLiveGroup: !!group && !group?.deletedAt,
47
+ activityAt: counter?.lastActivityAt
48
+ });
49
49
  }
50
50
  export function enrichAll(chats, activity, liveGroups) {
51
- return chats.map((chat) => listingOf(chat, Boolean(chat.groupId && liveGroups.has(chat.groupId)), activity.get(chat.id)));
51
+ return chats.map((chat) => listingOf(chat, {
52
+ inLiveGroup: Boolean(chat.groupId && liveGroups.has(chat.groupId)),
53
+ activityAt: activity.get(chat.id)
54
+ }));
52
55
  }
53
56
  export async function listSidebar(store) {
54
57
  const snap = store.view.snapshot();
@@ -80,14 +83,16 @@ export async function getChat(store, id) {
80
83
  }
81
84
  export async function mustGetChat(store, id) {
82
85
  const chat = await getChat(store, id);
83
- if (!chat)
86
+ if (!chat) {
84
87
  throw new Error(`chat not found: ${id}`);
88
+ }
85
89
  return chat;
86
90
  }
87
91
  export async function mustGetActiveChat(store, id) {
88
92
  const chat = await mustGetChat(store, id);
89
- if (chat.deletedAt)
93
+ if (chat.deletedAt) {
90
94
  throw new Error(`chat not found: ${id}`);
95
+ }
91
96
  return chat;
92
97
  }
93
98
  export async function mustGetActiveChatListing(store, id) {
@@ -109,7 +114,7 @@ export function buildChat(input) {
109
114
  export async function createChat(store, input) {
110
115
  const chat = buildChat(input);
111
116
  await store.dispatch('put-chat', { chat });
112
- return listingOf(chat, false, undefined);
117
+ return listingOf(chat, { inLiveGroup: false });
113
118
  }
114
119
  async function patchChat(store, id, patch) {
115
120
  return patchChatRow(store, await mustGetActiveChat(store, id), patch);
@@ -122,13 +127,14 @@ async function patchChatRow(store, current, patch) {
122
127
  export function renameChat(store, id, title) {
123
128
  return patchChat(store, id, { title });
124
129
  }
125
- export function setChatRagEnabled(store, id, ragEnabled) {
126
- return patchChat(store, id, { ragEnabled });
130
+ export function setChatRagEnabled(store, id, opts) {
131
+ return patchChat(store, id, { ragEnabled: opts.ragEnabled });
127
132
  }
128
133
  export async function setChatGroup(store, id, groupId) {
129
134
  const target = groupId || undefined;
130
- if (target)
135
+ if (target) {
131
136
  await mustGetActiveChatGroup(store, target);
137
+ }
132
138
  const current = await mustGetActiveChat(store, id);
133
139
  const kept = (current.groupId || undefined) === target;
134
140
  return patchChatRow(store, current, kept ? { groupId: target } : { groupId: target, rank: undefined, rankedAt: undefined });
@@ -136,23 +142,26 @@ export async function setChatGroup(store, id, groupId) {
136
142
  export async function moveChat(store, id, { groupId, afterId }) {
137
143
  const target = groupId || undefined;
138
144
  const anchor = afterId || undefined;
139
- if (anchor === id)
145
+ if (anchor === id) {
140
146
  throw new Error(`a chat cannot be placed after itself: ${id}`);
147
+ }
141
148
  const now = Date.now();
142
149
  const snap = store.view.snapshot();
143
150
  let moved;
144
151
  let placement;
145
- let stored;
152
+ let respaced;
146
153
  try {
147
154
  if (target) {
148
155
  const group = await snap.get(CHAT_GROUPS, { id: target });
149
- if (!group || group.deletedAt)
156
+ if (!group || group.deletedAt) {
150
157
  throw new Error(`chat group not found: ${target}`);
158
+ }
151
159
  }
152
160
  const { chats } = await listSidebarIn(snap);
153
161
  const me = chats.find((chat) => chat.id === id);
154
- if (!me)
162
+ if (!me) {
155
163
  throw new Error(`chat not found: ${id}`);
164
+ }
156
165
  moved = me;
157
166
  const siblings = chats
158
167
  .filter((sibling) => sibling.id !== id && (sibling.groupId || undefined) === target)
@@ -165,7 +174,11 @@ export async function moveChat(store, id, { groupId, afterId }) {
165
174
  }
166
175
  }
167
176
  placement = place(siblings, chatSortKey, { at, now });
168
- stored = new Map(await Promise.all(placement.respaced.map(async ({ row }) => [row.id, (await snap.get(CHATS, { id: row.id })) ?? row])));
177
+ respaced = await Promise.all(placement.respaced.map(async ({ row, rank }) => ({
178
+ chat: (await snap.get(CHATS, { id: row.id })) ?? row,
179
+ lastActivityAt: row.lastActivityAt,
180
+ rank
181
+ })));
169
182
  }
170
183
  finally {
171
184
  await snap.close();
@@ -177,8 +190,8 @@ export async function moveChat(store, id, { groupId, afterId }) {
177
190
  updatedAt: Math.max(now, chat.updatedAt ?? 0)
178
191
  });
179
192
  const batch = store.batch();
180
- for (const { row, rank } of placement.respaced) {
181
- batch.dispatch('put-chat', { chat: stamp(stored.get(row.id), row.lastActivityAt, rank) });
193
+ for (const { chat, lastActivityAt, rank } of respaced) {
194
+ batch.dispatch('put-chat', { chat: stamp(chat, lastActivityAt, rank) });
182
195
  }
183
196
  const { lastActivityAt, ...chat } = moved;
184
197
  batch.dispatch('put-chat', {
@@ -217,14 +230,16 @@ export async function removeChatKnowledge(store, chatId, at) {
217
230
  }
218
231
  await batch.flush();
219
232
  }
220
- export async function removeChatAttachments(store, deviceId, chatId, at) {
233
+ export async function removeChatAttachments(store, chatId, { deviceId, at }) {
221
234
  const batch = store.batch();
222
235
  for (const chunk of await listChunks(store, { chatId, type: 'attachment' })) {
223
236
  const attachment = chunk.attachment;
224
- if (!attachment || attachment.deletedAt)
237
+ if (!attachment || attachment.deletedAt) {
225
238
  continue;
226
- if (!chunk.originDeviceId.equals(deviceId))
239
+ }
240
+ if (!b4a.equals(chunk.originDeviceId, deviceId)) {
227
241
  continue;
242
+ }
228
243
  const tombstone = { ...attachment, deletedAt: at };
229
244
  batch.dispatch('update-chunk', updateOp(chunk, { id: chunk.id, attachment: tombstone }));
230
245
  }
@@ -232,15 +247,19 @@ export async function removeChatAttachments(store, deviceId, chatId, at) {
232
247
  }
233
248
  export async function deleteChat(store, deviceId, id) {
234
249
  const current = await mustGetChat(store, id);
250
+ const references = await chatReferences(store, id);
235
251
  const now = Date.now();
236
252
  if (deviceId) {
237
253
  await cancelActiveRuns(store, deviceId, id);
238
- await removeChatAttachments(store, deviceId, id, now);
239
254
  }
240
- await removeChatKnowledge(store, id, now);
241
255
  const deleted = { ...current, deletedAt: now, updatedAt: now };
242
- await store.dispatch('put-chat', { chat: deleted });
243
- return enrichChat(store, deleted);
256
+ const listing = await enrichChat(store, deleted);
257
+ const batch = store.batch();
258
+ batch.dispatch('put-chat', { chat: deleted });
259
+ batch.dispatch('purge-chat', { chatId: id, at: now });
260
+ await batch.flush();
261
+ await reclaimReferences(store, references).catch((err) => logger.warn('sync', "reclaiming a deleted chat's files failed", { id, err }));
262
+ return listing;
244
263
  }
245
264
  export async function softDeleteChatsForAgent(store, deviceId, agentId) {
246
265
  const snap = store.view.snapshot();
@@ -1,5 +1,5 @@
1
1
  import type HyperDB from 'hyperdb';
2
- import type { QvacChunk } from '../../spec/mesh/hyperschema/types.d.ts';
2
+ import type { QvacChunk, QvacUpdateChunkOperation } from '../../spec/mesh/hyperschema/types.d.ts';
3
3
  import type { Mesh, MeshDispatcher } from './mesh.ts';
4
4
  import { type Bounds } from './range.ts';
5
5
  type ChunkPayload = Pick<QvacChunk, 'userMessage' | 'content' | 'thinking' | 'toolCall' | 'toolResult' | 'attachment' | 'approvalRequest' | 'runStatus' | 'runRequest' | 'sources' | 'compaction'>;
@@ -25,31 +25,27 @@ type ListChunksInput = Bounds & {
25
25
  type?: QvacChunk['type'];
26
26
  types?: ReadonlyArray<QvacChunk['type']>;
27
27
  };
28
- export declare function findChunksOfType(snap: HyperDB, chatId: string, type: QvacChunk['type'], bounds?: Bounds): Promise<QvacChunk[]>;
28
+ export interface FindChunksOfTypeInput extends Bounds {
29
+ readonly chatId: string;
30
+ readonly type: QvacChunk['type'];
31
+ }
32
+ export declare function findChunksOfType(snap: HyperDB, { chatId, type, ...bounds }: FindChunksOfTypeInput): Promise<QvacChunk[]>;
29
33
  export declare function listChunks(store: Mesh, { chatId, type, types, ...bounds }: ListChunksInput): Promise<ReadChunk[]>;
30
34
  export declare function listAttachmentsByKind(store: Mesh, { kind, origin, ...bounds }: ListAttachmentsByKindInput): Promise<ReadChunk[]>;
31
35
  export declare function getChunk(store: Mesh, id: string): Promise<QvacChunk | null>;
32
- export declare function appendChunk(store: Mesh, { id, chatId, runId, type, originDeviceId, parentId, effect, intent, display, rawCall, capability, capabilityArgs, enhance, ...payload }: AppendChunkInput, into?: MeshDispatcher): Promise<{
33
- id: string;
34
- }>;
36
+ export interface AppendedChunk {
37
+ readonly id: string;
38
+ }
39
+ export declare function appendChunk(store: Mesh, { id, chatId, runId, type, originDeviceId, parentId, effect, intent, display, rawCall, capability, capabilityArgs, enhance, ...payload }: AppendChunkInput, into?: MeshDispatcher): Promise<AppendedChunk>;
35
40
  export declare function updateChunk(store: Mesh, { id, runStatus, attachment }: UpdateChunkInput): Promise<QvacChunk>;
36
- export declare function updateOp(chunk: QvacChunk, { id, runStatus, attachment }: UpdateChunkInput): {
37
- id: string;
38
- runStatus: import("../../spec/index").QvacChunkContentRunStatus;
39
- updatedAt: number;
40
- attachment?: undefined;
41
- } | {
42
- runStatus?: undefined;
43
- id: string;
44
- attachment: import("../../spec/index").QvacChunkContentAttachment;
45
- updatedAt: number;
46
- };
47
- export declare function resolveApproval(store: Mesh, { id, approved, scope, expiresAt, agentId }: {
48
- id: string;
49
- approved: boolean;
50
- scope?: 'once' | 'always';
51
- expiresAt?: number;
52
- agentId?: string;
53
- }): Promise<QvacChunk>;
41
+ export declare function updateOp(chunk: QvacChunk, { id, runStatus, attachment }: UpdateChunkInput): QvacUpdateChunkOperation;
42
+ export interface ResolveApprovalInput {
43
+ readonly id: string;
44
+ readonly approved: boolean;
45
+ readonly scope?: 'once' | 'always';
46
+ readonly expiresAt?: number;
47
+ readonly agentId?: string;
48
+ }
49
+ export declare function resolveApproval(store: Mesh, { id, approved, scope, expiresAt, agentId }: ResolveApprovalInput): Promise<QvacChunk>;
54
50
  export declare function listRunRequests(store: Mesh, deviceId: Buffer | null): Promise<QvacChunk[]>;
55
51
  export {};
@@ -1,15 +1,12 @@
1
1
  import { CHUNK_PAYLOAD_FIELDS, ragSourcesWithinBounds } from '../../schema/qvac.js';
2
- import { chunkTypeOrdinal, mediaKindOrdinal } from '../../schema/helpers.js';
2
+ import { chunkTypeOrdinal } from '../../schema/indexes.js';
3
+ import { mediaKindOrdinal } from '../../schema/media-kind.js';
3
4
  import { putApprovalRule } from './approval-rules.js';
4
5
  import { linkAttachment } from './attachment-link.js';
5
6
  import { randomId } from './id.js';
6
7
  import { keyRange } from './range.js';
7
- const CHUNKS = '@qvac/chunks';
8
- const CHUNKS_BY_CHAT = '@qvac/chunks-by-chat';
9
- const CHUNKS_BY_TYPE = '@qvac/chunks-by-type';
10
- const HISTORY_CHUNKS = '@qvac/history-chunks';
11
- const ATTACHMENTS_BY_MEDIA_KIND = '@qvac/attachments-by-media-kind';
12
- const ATTACHMENTS_BY_MEDIA_KIND_ORIGIN = '@qvac/attachments-by-media-kind-origin';
8
+ import b4a from 'b4a';
9
+ import { AGENTS, ATTACHMENTS_BY_MEDIA_KIND, ATTACHMENTS_BY_MEDIA_KIND_ORIGIN, CHUNKS, CHUNKS_BY_CHAT, CHUNKS_BY_TYPE, HISTORY_CHUNKS, RUN_REQUESTS } from './collections.js';
13
10
  export const HISTORY_CHUNK_TYPES = [
14
11
  'user-message',
15
12
  'run-request',
@@ -19,15 +16,16 @@ export const HISTORY_CHUNK_TYPES = [
19
16
  ];
20
17
  function linkChunks(store, chunks) {
21
18
  const mint = store.attachmentUrl;
22
- if (!mint)
19
+ if (!mint) {
23
20
  return chunks;
21
+ }
24
22
  return chunks.map((chunk) => chunk.attachment ? { ...chunk, attachment: linkAttachment(mint, chunk.attachment) } : chunk);
25
23
  }
26
24
  export async function recordLinks(store, chunks) {
27
25
  await store.fileIndex?.record(chunks.filter((chunk) => chunk.attachment?.url));
28
26
  return chunks;
29
27
  }
30
- export function findChunksOfType(snap, chatId, type, bounds = {}) {
28
+ export function findChunksOfType(snap, { chatId, type, ...bounds }) {
31
29
  const prefix = { chatId, type: chunkTypeOrdinal(type) };
32
30
  return snap
33
31
  .find(CHUNKS_BY_TYPE, keyRange(prefix, 'seq', bounds))
@@ -35,8 +33,9 @@ export function findChunksOfType(snap, chatId, type, bounds = {}) {
35
33
  }
36
34
  export async function listChunks(store, { chatId, type, types, ...bounds }) {
37
35
  const selected = selectedChunkTypes(type, types);
38
- if (selected?.length === 0)
36
+ if (selected?.length === 0) {
39
37
  return [];
38
+ }
40
39
  if (selected && selected.length > 1 && !isHistorySelection(selected)) {
41
40
  throw new Error('multiple chunk types require a mapped index');
42
41
  }
@@ -82,8 +81,9 @@ function selectedChunkTypes(type, types) {
82
81
  if (!type && types === undefined)
83
82
  return null;
84
83
  const selected = new Set(types);
85
- if (type)
84
+ if (type) {
86
85
  selected.add(type);
86
+ }
87
87
  return [...selected];
88
88
  }
89
89
  function isHistorySelection(types) {
@@ -102,8 +102,9 @@ export async function getChunk(store, id) {
102
102
  }
103
103
  async function mustGetChunk(store, id) {
104
104
  const chunk = await getChunk(store, id);
105
- if (!chunk)
105
+ if (!chunk) {
106
106
  throw new Error(`chunk not found: ${id}`);
107
+ }
107
108
  return chunk;
108
109
  }
109
110
  function assertPayloadMatchesType(type, payload) {
@@ -127,8 +128,9 @@ export async function appendChunk(store, { id = randomId(), chatId, runId, type,
127
128
  if (capability && type !== 'run-request') {
128
129
  throw new Error('chunk payload invalid: only a run-request carries a capability');
129
130
  }
130
- if (type === 'user-message' && !store.ourMemberId)
131
+ if (type === 'user-message' && !store.ourMemberId) {
131
132
  await store.refreshOurMember();
133
+ }
132
134
  if (parentId) {
133
135
  const parent = await getChunk(store, parentId);
134
136
  if (!parent || parent.chatId !== chatId) {
@@ -150,14 +152,15 @@ export async function appendChunk(store, { id = randomId(), chatId, runId, type,
150
152
  capabilityArgs,
151
153
  enhance,
152
154
  createdAt: Date.now(),
153
- ...(type === 'user-message' && store.ourMemberId && store.ourDeviceId?.equals(originDeviceId)
154
- ? { senderMemberId: store.ourMemberId }
155
- : undefined),
155
+ senderMemberId: type === 'user-message' && store.ourDeviceId && b4a.equals(store.ourDeviceId, originDeviceId)
156
+ ? store.ourMemberId || undefined
157
+ : undefined,
156
158
  ...payload
157
159
  };
158
160
  await into.dispatch('append-chunk', op);
159
- if (type === 'attachment')
161
+ if (type === 'attachment') {
160
162
  await store.fileIndex?.record([op]);
163
+ }
161
164
  return { id };
162
165
  }
163
166
  export async function updateChunk(store, { id, runStatus, attachment }) {
@@ -208,21 +211,24 @@ export async function listRunRequests(store, deviceId) {
208
211
  return [];
209
212
  const snap = store.view.snapshot();
210
213
  try {
211
- const requests = await snap.find('@qvac/run-requests').toArray();
214
+ const requests = await snap.find(RUN_REQUESTS).toArray();
212
215
  const providers = new Map();
213
216
  const mine = [];
214
217
  for (const request of requests) {
215
218
  if (store.closing)
216
219
  return mine;
217
220
  const agentId = request.runRequest?.agentId;
218
- if (!agentId)
221
+ if (!agentId) {
219
222
  continue;
223
+ }
220
224
  if (!providers.has(agentId)) {
221
- const agent = await snap.get('@qvac/agents', { id: agentId });
225
+ const agent = await snap.get(AGENTS, { id: agentId });
222
226
  providers.set(agentId, agent?.providerDeviceId);
223
227
  }
224
- if (providers.get(agentId)?.equals(deviceId))
228
+ const provider = providers.get(agentId);
229
+ if (provider && b4a.equals(provider, deviceId)) {
225
230
  mine.push(request);
231
+ }
226
232
  }
227
233
  return mine;
228
234
  }