@qvac/core 0.4.1 → 0.6.0

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 (417) hide show
  1. package/CHANGELOG.md +262 -1
  2. package/README.md +1 -1
  3. package/dist-lib/lib/api/agents.js +3 -2
  4. package/dist-lib/lib/api/app-config.d.ts +1 -1
  5. package/dist-lib/lib/api/app-config.js +54 -15
  6. package/dist-lib/lib/api/attachments.d.ts +6 -5
  7. package/dist-lib/lib/api/attachments.js +4 -2
  8. package/dist-lib/lib/api/chat.d.ts +7 -3
  9. package/dist-lib/lib/api/chat.js +4 -4
  10. package/dist-lib/lib/api/chunks.js +3 -3
  11. package/dist-lib/lib/api/config.js +2 -2
  12. package/dist-lib/lib/api/current-mesh.d.ts +3 -4
  13. package/dist-lib/lib/api/current-mesh.js +9 -4
  14. package/dist-lib/lib/api/custom-models.d.ts +8 -1
  15. package/dist-lib/lib/api/custom-models.js +53 -16
  16. package/dist-lib/lib/api/devices.d.ts +14 -5
  17. package/dist-lib/lib/api/devices.js +14 -9
  18. package/dist-lib/lib/api/diagnostics.d.ts +1 -0
  19. package/dist-lib/lib/api/diagnostics.js +1 -1
  20. package/dist-lib/lib/api/effective-ctx-size.d.ts +6 -1
  21. package/dist-lib/lib/api/effective-ctx-size.js +5 -3
  22. package/dist-lib/lib/api/execution.js +9 -2
  23. package/dist-lib/lib/api/files.js +2 -1
  24. package/dist-lib/lib/api/index.d.ts +7 -1
  25. package/dist-lib/lib/api/index.js +101 -101
  26. package/dist-lib/lib/api/instrument.js +29 -20
  27. package/dist-lib/lib/api/knowledge.d.ts +6 -5
  28. package/dist-lib/lib/api/knowledge.js +8 -6
  29. package/dist-lib/lib/api/local-files.js +1 -1
  30. package/dist-lib/lib/api/logs.js +6 -3
  31. package/dist-lib/lib/api/members.js +22 -13
  32. package/dist-lib/lib/api/mesh.d.ts +7 -2
  33. package/dist-lib/lib/api/mesh.js +10 -5
  34. package/dist-lib/lib/api/model-download.js +1 -1
  35. package/dist-lib/lib/api/network.d.ts +1 -0
  36. package/dist-lib/lib/api/network.js +1 -1
  37. package/dist-lib/lib/api/notifications.js +23 -13
  38. package/dist-lib/lib/api/rag.d.ts +6 -1
  39. package/dist-lib/lib/api/rag.js +20 -11
  40. package/dist-lib/lib/api/range.d.ts +2 -2
  41. package/dist-lib/lib/api/sync.js +1 -1
  42. package/dist-lib/lib/api/tool-activity.js +7 -3
  43. package/dist-lib/lib/api/tool-configs.js +2 -4
  44. package/dist-lib/lib/api/upload-frames.d.ts +7 -8
  45. package/dist-lib/lib/api/upload-frames.js +2 -1
  46. package/dist-lib/lib/api/watchable.d.ts +6 -1
  47. package/dist-lib/lib/api/watchable.js +23 -14
  48. package/dist-lib/lib/assistant/fetch-body.js +4 -2
  49. package/dist-lib/lib/assistant/harness.d.ts +72 -24
  50. package/dist-lib/lib/assistant/harness.js +53 -15
  51. package/dist-lib/lib/assistant/history.d.ts +9 -7
  52. package/dist-lib/lib/assistant/history.js +77 -42
  53. package/dist-lib/lib/assistant/message.d.ts +5 -3
  54. package/dist-lib/lib/assistant/message.js +4 -2
  55. package/dist-lib/lib/assistant/skill-encode.d.ts +3 -1
  56. package/dist-lib/lib/assistant/skill-encode.js +52 -62
  57. package/dist-lib/lib/assistant-client.js +7 -4
  58. package/dist-lib/lib/assistant-tree.js +36 -11
  59. package/dist-lib/lib/assistant.d.ts +37 -12
  60. package/dist-lib/lib/assistant.js +977 -373
  61. package/dist-lib/lib/audio-format.d.ts +1 -1
  62. package/dist-lib/lib/audio-format.js +1 -1
  63. package/dist-lib/lib/chat-title.js +9 -4
  64. package/dist-lib/lib/client.js +3 -2
  65. package/dist-lib/lib/collabora/convert.d.ts +2 -2
  66. package/dist-lib/lib/collabora/convert.js +6 -3
  67. package/dist-lib/lib/collabora/entry.js +9 -5
  68. package/dist-lib/lib/collabora/protocol.d.ts +2 -2
  69. package/dist-lib/lib/collabora/protocol.js +14 -7
  70. package/dist-lib/lib/collabora/worker.js +14 -7
  71. package/dist-lib/lib/compaction.d.ts +5 -6
  72. package/dist-lib/lib/compaction.js +14 -7
  73. package/dist-lib/lib/constants.d.ts +2 -0
  74. package/dist-lib/lib/constants.js +4 -0
  75. package/dist-lib/lib/core/account-recovery.d.ts +4 -3
  76. package/dist-lib/lib/core/account-recovery.js +7 -4
  77. package/dist-lib/lib/core/agent.d.ts +0 -1
  78. package/dist-lib/lib/core/agent.js +18 -16
  79. package/dist-lib/lib/core/approval-rules.d.ts +7 -6
  80. package/dist-lib/lib/core/approval-rules.js +12 -6
  81. package/dist-lib/lib/core/archived-mesh.d.ts +7 -5
  82. package/dist-lib/lib/core/archived-mesh.js +25 -22
  83. package/dist-lib/lib/core/async-iterable.js +10 -5
  84. package/dist-lib/lib/core/attachment-link.d.ts +2 -2
  85. package/dist-lib/lib/core/audio-attachment.js +1 -1
  86. package/dist-lib/lib/core/blind-peers.d.ts +2 -2
  87. package/dist-lib/lib/core/chat-activity.d.ts +2 -2
  88. package/dist-lib/lib/core/chat-activity.js +42 -21
  89. package/dist-lib/lib/core/chat-group.d.ts +8 -6
  90. package/dist-lib/lib/core/chat-group.js +17 -10
  91. package/dist-lib/lib/core/chat-order.d.ts +11 -9
  92. package/dist-lib/lib/core/chat-order.js +1 -3
  93. package/dist-lib/lib/core/chat-search.d.ts +4 -4
  94. package/dist-lib/lib/core/chat-search.js +38 -24
  95. package/dist-lib/lib/core/chat.d.ts +20 -14
  96. package/dist-lib/lib/core/chat.js +42 -28
  97. package/dist-lib/lib/core/chunk.d.ts +20 -24
  98. package/dist-lib/lib/core/chunk.js +34 -22
  99. package/dist-lib/lib/core/collections.d.ts +69 -0
  100. package/dist-lib/lib/core/collections.js +69 -0
  101. package/dist-lib/lib/core/contract/activity.d.ts +8 -2
  102. package/dist-lib/lib/core/contract/activity.js +39 -11
  103. package/dist-lib/lib/core/contract/agents.js +3 -2
  104. package/dist-lib/lib/core/contract/approval-rules.js +1 -1
  105. package/dist-lib/lib/core/contract/attestations.js +1 -1
  106. package/dist-lib/lib/core/contract/chat-group.js +1 -1
  107. package/dist-lib/lib/core/contract/chat.js +1 -1
  108. package/dist-lib/lib/core/contract/chunks.js +16 -9
  109. package/dist-lib/lib/core/contract/compute.js +2 -1
  110. package/dist-lib/lib/core/contract/devices.js +10 -6
  111. package/dist-lib/lib/core/contract/grant-order.d.ts +5 -0
  112. package/dist-lib/lib/core/contract/grant-order.js +20 -0
  113. package/dist-lib/lib/core/contract/index.d.ts +1 -1
  114. package/dist-lib/lib/core/contract/index.js +27 -2
  115. package/dist-lib/lib/core/contract/indexing.js +3 -3
  116. package/dist-lib/lib/core/contract/invites.d.ts +16 -0
  117. package/dist-lib/lib/core/contract/invites.js +256 -0
  118. package/dist-lib/lib/core/contract/joined-meshes.js +22 -22
  119. package/dist-lib/lib/core/contract/knowledge.js +5 -5
  120. package/dist-lib/lib/core/contract/members.d.ts +15 -0
  121. package/dist-lib/lib/core/contract/members.js +116 -31
  122. package/dist-lib/lib/core/contract/mesh-kind.d.ts +6 -0
  123. package/dist-lib/lib/core/contract/mesh-kind.js +49 -0
  124. package/dist-lib/lib/core/contract/seal.js +1 -1
  125. package/dist-lib/lib/core/contract/seed-defaults.js +1 -3
  126. package/dist-lib/lib/core/contract/tool-activity.js +5 -5
  127. package/dist-lib/lib/core/contract/tool-configs.js +1 -2
  128. package/dist-lib/lib/core/contract/writers.d.ts +13 -0
  129. package/dist-lib/lib/core/contract/writers.js +181 -24
  130. package/dist-lib/lib/core/departures.js +16 -8
  131. package/dist-lib/lib/core/device-attestation.d.ts +5 -0
  132. package/dist-lib/lib/core/device-attestation.js +24 -0
  133. package/dist-lib/lib/core/device-invites.d.ts +2 -0
  134. package/dist-lib/lib/core/device-invites.js +29 -7
  135. package/dist-lib/lib/core/devices.d.ts +2 -1
  136. package/dist-lib/lib/core/devices.js +52 -2
  137. package/dist-lib/lib/core/document-attachment.d.ts +20 -11
  138. package/dist-lib/lib/core/document-attachment.js +10 -5
  139. package/dist-lib/lib/core/files/attachments.d.ts +2 -5
  140. package/dist-lib/lib/core/files/attachments.js +6 -3
  141. package/dist-lib/lib/core/files/index.d.ts +44 -52
  142. package/dist-lib/lib/core/files/index.js +142 -93
  143. package/dist-lib/lib/core/files/knowledge.d.ts +2 -5
  144. package/dist-lib/lib/core/files/local-index.js +9 -5
  145. package/dist-lib/lib/core/files/preview/image.d.ts +0 -1
  146. package/dist-lib/lib/core/files/preview/image.js +9 -6
  147. package/dist-lib/lib/core/files/preview/index.d.ts +8 -11
  148. package/dist-lib/lib/core/files/preview/index.js +20 -15
  149. package/dist-lib/lib/core/files/processing/claims.d.ts +6 -5
  150. package/dist-lib/lib/core/files/processing/claims.js +16 -8
  151. package/dist-lib/lib/core/files/processing/document.d.ts +21 -50
  152. package/dist-lib/lib/core/files/processing/index.d.ts +18 -13
  153. package/dist-lib/lib/core/files/processing/index.js +65 -37
  154. package/dist-lib/lib/core/files/processing/ownership.d.ts +8 -1
  155. package/dist-lib/lib/core/files/processing/ownership.js +1 -1
  156. package/dist-lib/lib/core/files/processing/protocol.d.ts +19 -19
  157. package/dist-lib/lib/core/files/processing/protocol.js +5 -5
  158. package/dist-lib/lib/core/files/processing/settle.d.ts +10 -7
  159. package/dist-lib/lib/core/files/processing/settle.js +22 -11
  160. package/dist-lib/lib/core/files/processing/source.js +14 -8
  161. package/dist-lib/lib/core/files/processing/state.d.ts +13 -11
  162. package/dist-lib/lib/core/files/processing/state.js +19 -12
  163. package/dist-lib/lib/core/files/rag/build.d.ts +2 -2
  164. package/dist-lib/lib/core/files/rag/build.js +2 -1
  165. package/dist-lib/lib/core/files/rag/document-types.d.ts +4 -6
  166. package/dist-lib/lib/core/files/rag/index.d.ts +10 -13
  167. package/dist-lib/lib/core/files/rag/index.js +3 -2
  168. package/dist-lib/lib/core/files/rag/load.d.ts +10 -9
  169. package/dist-lib/lib/core/files/rag/load.js +26 -13
  170. package/dist-lib/lib/core/files/rag/policy.js +2 -1
  171. package/dist-lib/lib/core/files/rag/produce.js +33 -19
  172. package/dist-lib/lib/core/files/rag/retrieval/full-text.d.ts +5 -3
  173. package/dist-lib/lib/core/files/rag/retrieval/full-text.js +30 -10
  174. package/dist-lib/lib/core/files/records/chunks.js +4 -2
  175. package/dist-lib/lib/core/files/records/knowledge.d.ts +10 -11
  176. package/dist-lib/lib/core/files/records/knowledge.js +9 -8
  177. package/dist-lib/lib/core/files/records/linkage.js +6 -3
  178. package/dist-lib/lib/core/files/records/output.d.ts +5 -4
  179. package/dist-lib/lib/core/files/records/output.js +8 -4
  180. package/dist-lib/lib/core/files/records/reclaim.js +41 -25
  181. package/dist-lib/lib/core/files/records/routing.d.ts +4 -6
  182. package/dist-lib/lib/core/files/records/routing.js +15 -8
  183. package/dist-lib/lib/core/files/records/source.d.ts +5 -4
  184. package/dist-lib/lib/core/files/records/source.js +20 -14
  185. package/dist-lib/lib/core/files/records/sweep.js +1 -3
  186. package/dist-lib/lib/core/files/store/blob.d.ts +10 -10
  187. package/dist-lib/lib/core/files/store/blob.js +25 -19
  188. package/dist-lib/lib/core/files/store/index.d.ts +1 -6
  189. package/dist-lib/lib/core/files/store/index.js +4 -4
  190. package/dist-lib/lib/core/files/store/inline.d.ts +2 -2
  191. package/dist-lib/lib/core/files/store/inline.js +6 -3
  192. package/dist-lib/lib/core/files/store/reference.d.ts +6 -9
  193. package/dist-lib/lib/core/files/store/reference.js +25 -17
  194. package/dist-lib/lib/core/files/store/server.d.ts +7 -6
  195. package/dist-lib/lib/core/files/store/server.js +22 -11
  196. package/dist-lib/lib/core/files/store/sweep.js +13 -7
  197. package/dist-lib/lib/core/files/upload-input.d.ts +4 -12
  198. package/dist-lib/lib/core/files/upload-input.js +10 -5
  199. package/dist-lib/lib/core/files/upload.d.ts +27 -24
  200. package/dist-lib/lib/core/files/upload.js +74 -51
  201. package/dist-lib/lib/core/fs-drives.js +4 -2
  202. package/dist-lib/lib/core/grant-expiry.d.ts +11 -0
  203. package/dist-lib/lib/core/grant-expiry.js +66 -0
  204. package/dist-lib/lib/core/handoff-channel.d.ts +2 -1
  205. package/dist-lib/lib/core/handoff-channel.js +36 -15
  206. package/dist-lib/lib/core/harness-loan.js +35 -17
  207. package/dist-lib/lib/core/helpers/index.d.ts +2 -1
  208. package/dist-lib/lib/core/helpers/index.js +11 -6
  209. package/dist-lib/lib/core/hosted-agents.js +19 -12
  210. package/dist-lib/lib/core/id.js +1 -1
  211. package/dist-lib/lib/core/identity.d.ts +1 -0
  212. package/dist-lib/lib/core/identity.js +11 -3
  213. package/dist-lib/lib/core/image/cache-sweep.d.ts +12 -10
  214. package/dist-lib/lib/core/image/cache-sweep.js +11 -6
  215. package/dist-lib/lib/core/image/normalize.d.ts +6 -0
  216. package/dist-lib/lib/core/image/normalize.js +12 -2
  217. package/dist-lib/lib/core/image/sniff.js +42 -21
  218. package/dist-lib/lib/core/inference-calls-receiver.js +7 -4
  219. package/dist-lib/lib/core/invite-grants.d.ts +20 -0
  220. package/dist-lib/lib/core/invite-grants.js +46 -0
  221. package/dist-lib/lib/core/invite.d.ts +3 -0
  222. package/dist-lib/lib/core/invite.js +6 -3
  223. package/dist-lib/lib/core/local/files.js +20 -19
  224. package/dist-lib/lib/core/local/index.d.ts +70 -45
  225. package/dist-lib/lib/core/local/index.js +157 -126
  226. package/dist-lib/lib/core/membership.d.ts +15 -2
  227. package/dist-lib/lib/core/membership.js +95 -20
  228. package/dist-lib/lib/core/mesh-seed-handoff.d.ts +12 -4
  229. package/dist-lib/lib/core/mesh-seed-handoff.js +23 -5
  230. package/dist-lib/lib/core/mesh.d.ts +57 -30
  231. package/dist-lib/lib/core/mesh.js +232 -78
  232. package/dist-lib/lib/core/migrations/agent-catalog.js +3 -2
  233. package/dist-lib/lib/core/migrations/agent-indexes.js +3 -3
  234. package/dist-lib/lib/core/migrations/device-indexes.d.ts +2 -0
  235. package/dist-lib/lib/core/migrations/device-indexes.js +7 -0
  236. package/dist-lib/lib/core/migrations/file-index.js +7 -4
  237. package/dist-lib/lib/core/migrations/index.d.ts +4 -3
  238. package/dist-lib/lib/core/migrations/index.js +3 -1
  239. package/dist-lib/lib/core/migrations/membership.js +9 -4
  240. package/dist-lib/lib/core/migrations/seal.js +3 -2
  241. package/dist-lib/lib/core/min-version.js +4 -2
  242. package/dist-lib/lib/core/next-frame.d.ts +5 -4
  243. package/dist-lib/lib/core/next-frame.js +6 -3
  244. package/dist-lib/lib/core/notification.d.ts +5 -1
  245. package/dist-lib/lib/core/notification.js +89 -77
  246. package/dist-lib/lib/core/ota-config.js +2 -1
  247. package/dist-lib/lib/core/pdf/rasterize.d.ts +18 -0
  248. package/dist-lib/lib/core/pdf/rasterize.js +57 -0
  249. package/dist-lib/lib/core/prompt-history.js +4 -2
  250. package/dist-lib/lib/core/range.d.ts +4 -4
  251. package/dist-lib/lib/core/range.js +12 -6
  252. package/dist-lib/lib/core/rank.d.ts +5 -4
  253. package/dist-lib/lib/core/rank.js +2 -1
  254. package/dist-lib/lib/core/send.d.ts +8 -5
  255. package/dist-lib/lib/core/send.js +9 -3
  256. package/dist-lib/lib/core/skill-overlay-receiver.js +7 -4
  257. package/dist-lib/lib/core/skill-secrets.js +16 -9
  258. package/dist-lib/lib/core/sync/chunks.js +2 -1
  259. package/dist-lib/lib/core/sync/devices.js +3 -1
  260. package/dist-lib/lib/core/sync/files.d.ts +2 -4
  261. package/dist-lib/lib/core/sync/files.js +28 -20
  262. package/dist-lib/lib/core/sync/index.d.ts +2 -5
  263. package/dist-lib/lib/core/sync/index.js +33 -17
  264. package/dist-lib/lib/core/sync-status.js +10 -7
  265. package/dist-lib/lib/core/system-info.js +4 -2
  266. package/dist-lib/lib/core/tool-activity.d.ts +4 -3
  267. package/dist-lib/lib/core/tool-activity.js +1 -1
  268. package/dist-lib/lib/core/tool-configs.js +12 -7
  269. package/dist-lib/lib/core.d.ts +107 -45
  270. package/dist-lib/lib/core.js +1765 -595
  271. package/dist-lib/lib/credential-pusher.d.ts +12 -17
  272. package/dist-lib/lib/credential-pusher.js +61 -42
  273. package/dist-lib/lib/custom-model-pusher.d.ts +7 -3
  274. package/dist-lib/lib/custom-model-pusher.js +15 -7
  275. package/dist-lib/lib/custom-model-task.d.ts +1 -0
  276. package/dist-lib/lib/custom-model-task.js +12 -0
  277. package/dist-lib/lib/deadline.js +4 -2
  278. package/dist-lib/lib/diagnostics.d.ts +1 -5
  279. package/dist-lib/lib/frame-readable.d.ts +3 -0
  280. package/dist-lib/lib/frame-readable.js +3 -0
  281. package/dist-lib/lib/fs-drive-bridge.js +24 -14
  282. package/dist-lib/lib/fs-grants.js +13 -8
  283. package/dist-lib/lib/guards.d.ts +3 -0
  284. package/dist-lib/lib/guards.js +9 -0
  285. package/dist-lib/lib/inference-calls.d.ts +28 -23
  286. package/dist-lib/lib/inference-calls.js +25 -13
  287. package/dist-lib/lib/integrations/mcp-providers.d.ts +2 -2
  288. package/dist-lib/lib/integrations/setup-routes.d.ts +2 -2
  289. package/dist-lib/lib/knowledge-search.d.ts +6 -5
  290. package/dist-lib/lib/knowledge-search.js +26 -18
  291. package/dist-lib/lib/kv-cache-reclaim.js +4 -2
  292. package/dist-lib/lib/kv-cache.js +8 -4
  293. package/dist-lib/lib/legacy-core-domain.d.ts +42 -42
  294. package/dist-lib/lib/log-buffer.js +2 -1
  295. package/dist-lib/lib/log.js +25 -15
  296. package/dist-lib/lib/mesh-scoped-engine.js +14 -4
  297. package/dist-lib/lib/model-catalog-revision.js +6 -3
  298. package/dist-lib/lib/model-clamp.js +6 -3
  299. package/dist-lib/lib/model-context.d.ts +8 -3
  300. package/dist-lib/lib/model-context.js +13 -5
  301. package/dist-lib/lib/model-download-status.js +4 -2
  302. package/dist-lib/lib/model-download.d.ts +12 -4
  303. package/dist-lib/lib/model-download.js +200 -103
  304. package/dist-lib/lib/model-idle-pusher.d.ts +10 -0
  305. package/dist-lib/lib/model-idle-pusher.js +41 -0
  306. package/dist-lib/lib/oauth/browser-connect.d.ts +10 -8
  307. package/dist-lib/lib/oauth/browser-connect.js +33 -20
  308. package/dist-lib/lib/oauth/client.d.ts +2 -2
  309. package/dist-lib/lib/oauth/flow-core.js +23 -9
  310. package/dist-lib/lib/oauth/flow.d.ts +1 -3
  311. package/dist-lib/lib/oauth/flow.js +9 -5
  312. package/dist-lib/lib/oauth/keys.d.ts +4 -4
  313. package/dist-lib/lib/oauth/keys.js +18 -12
  314. package/dist-lib/lib/oauth/loopback.d.ts +2 -2
  315. package/dist-lib/lib/oauth/loopback.js +147 -107
  316. package/dist-lib/lib/oauth/loopback.stub.d.ts +2 -2
  317. package/dist-lib/lib/oauth/loopback.stub.js +1 -1
  318. package/dist-lib/lib/oauth/pkce.d.ts +4 -2
  319. package/dist-lib/lib/oauth/pkce.js +10 -0
  320. package/dist-lib/lib/oauth/providers.js +5 -5
  321. package/dist-lib/lib/oauth/redirect-types.d.ts +12 -7
  322. package/dist-lib/lib/oauth/register.js +3 -2
  323. package/dist-lib/lib/oauth/registry.d.ts +2 -2
  324. package/dist-lib/lib/oauth/registry.js +2 -1
  325. package/dist-lib/lib/oauth/resolve.d.ts +30 -10
  326. package/dist-lib/lib/oauth/resolve.js +12 -6
  327. package/dist-lib/lib/oauth/token-exchange-core.d.ts +12 -4
  328. package/dist-lib/lib/oauth/token-exchange-core.js +1 -1
  329. package/dist-lib/lib/oauth/types.d.ts +12 -12
  330. package/dist-lib/lib/oauth.d.ts +4 -5
  331. package/dist-lib/lib/oauth.js +2 -3
  332. package/dist-lib/lib/reconnecting-watch.d.ts +1 -1
  333. package/dist-lib/lib/reconnecting-watch.js +6 -6
  334. package/dist-lib/lib/retry-budget.js +6 -3
  335. package/dist-lib/lib/run-notices.d.ts +2 -0
  336. package/dist-lib/lib/run-notices.js +7 -3
  337. package/dist-lib/lib/run-transcript.d.ts +2 -4
  338. package/dist-lib/lib/run-transcript.js +4 -2
  339. package/dist-lib/lib/skill-readiness.d.ts +1 -0
  340. package/dist-lib/lib/skill-readiness.js +17 -2
  341. package/dist-lib/lib/skill-types.d.ts +16 -16
  342. package/dist-lib/lib/suspend-lifecycle.d.ts +4 -4
  343. package/dist-lib/lib/suspend-lifecycle.js +10 -5
  344. package/dist-lib/lib/task.d.ts +5 -1
  345. package/dist-lib/lib/task.js +29 -12
  346. package/dist-lib/lib/unref.d.ts +3 -2
  347. package/dist-lib/lib/unref.js +2 -1
  348. package/dist-lib/lib/wav-duration.js +10 -5
  349. package/dist-lib/lib/write-queue.d.ts +5 -4
  350. package/dist-lib/lib/write-queue.js +2 -1
  351. package/dist-lib/schema/build.js +16 -8
  352. package/dist-lib/schema/config.d.ts +3 -4
  353. package/dist-lib/schema/config.js +1 -1
  354. package/dist-lib/schema/content.d.ts +18 -2
  355. package/dist-lib/schema/content.js +4 -1
  356. package/dist-lib/schema/engine.d.ts +3 -2
  357. package/dist-lib/schema/engine.js +192 -12
  358. package/dist-lib/schema/field-order.js +22 -11
  359. package/dist-lib/schema/indexes.d.ts +22 -0
  360. package/dist-lib/schema/{helpers.js → indexes.js} +19 -57
  361. package/dist-lib/schema/local.d.ts +3 -2
  362. package/dist-lib/schema/local.js +9 -3
  363. package/dist-lib/schema/media-kind.d.ts +8 -0
  364. package/dist-lib/schema/media-kind.js +52 -0
  365. package/dist-lib/schema/qvac.d.ts +12 -9
  366. package/dist-lib/schema/qvac.js +132 -7
  367. package/dist-lib/spec/bind.js +21 -0
  368. package/dist-lib/spec/calls.js +7 -0
  369. package/dist-lib/spec/capabilities.d.ts +18 -4
  370. package/dist-lib/spec/config/hyperconf/index.js +1 -1
  371. package/dist-lib/spec/hrpc/hrpc.json +93 -2
  372. package/dist-lib/spec/hrpc/index.js +89 -5
  373. package/dist-lib/spec/hrpc/messages.js +1568 -941
  374. package/dist-lib/spec/hyperschema/index.js +1568 -941
  375. package/dist-lib/spec/hyperschema/schema.json +531 -1
  376. package/dist-lib/spec/hyperschema/types.d.ts +145 -1
  377. package/dist-lib/spec/local/hyperdb/index.js +1 -1
  378. package/dist-lib/spec/local/hyperdb/messages.js +92 -20
  379. package/dist-lib/spec/local/hyperschema/index.js +47 -11
  380. package/dist-lib/spec/local/hyperschema/schema.json +32 -1
  381. package/dist-lib/spec/local/hyperschema/types.d.ts +7 -1
  382. package/dist-lib/spec/mesh/hyperdb/db.json +131 -3
  383. package/dist-lib/spec/mesh/hyperdb/index.js +548 -5
  384. package/dist-lib/spec/mesh/hyperdb/messages.js +2444 -893
  385. package/dist-lib/spec/mesh/hyperdispatch/dispatch.json +37 -1
  386. package/dist-lib/spec/mesh/hyperdispatch/index.js +104 -2
  387. package/dist-lib/spec/mesh/hyperdispatch/messages.js +1035 -11
  388. package/dist-lib/spec/mesh/hyperschema/index.js +1035 -11
  389. package/dist-lib/spec/mesh/hyperschema/schema.json +553 -1
  390. package/dist-lib/spec/mesh/hyperschema/types.d.ts +143 -1
  391. package/package.json +11 -5
  392. package/tui/app.mjs +2624 -986
  393. package/tui/boot.mjs +17 -46
  394. package/tui/index.mjs +10 -5
  395. package/tui/lib/boot-timing.mjs +8 -8
  396. package/tui/lib/busy-words.mjs +21 -22
  397. package/tui/lib/export.mjs +100 -32
  398. package/tui/lib/knowledge-command.mjs +64 -19
  399. package/tui/lib/knowledge-import.mjs +52 -18
  400. package/tui/lib/render.mjs +65 -33
  401. package/tui/lib/save-file.mjs +30 -13
  402. package/tui/lib/select.mjs +23 -5
  403. package/tui/lib/selection.mjs +6 -4
  404. package/tui/lib/setup.mjs +11 -19
  405. package/tui/lib/sidebar.mjs +23 -13
  406. package/tui/lib/splash.mjs +6 -7
  407. package/tui/lib/upload-frames.mjs +1 -2
  408. package/tui/lib/usage.mjs +13 -9
  409. package/tui/lib/wrap.mjs +35 -6
  410. package/tui/main.mjs +54 -78
  411. package/worker/assistant-sidecar.mjs +5 -10
  412. package/worker/stow-entry.mjs +7 -4
  413. package/dist-lib/lib/custom-model-source.d.ts +0 -15
  414. package/dist-lib/lib/custom-model-source.js +0 -46
  415. package/dist-lib/lib/oauth/common.d.ts +0 -38
  416. package/dist-lib/lib/oauth/common.js +0 -34
  417. package/dist-lib/schema/helpers.d.ts +0 -32
@@ -1,4 +1,5 @@
1
1
  import { randomId } from '../id.js';
2
+ import b4a from 'b4a';
2
3
  export const DEFAULT_AGENT_NAME = 'QV.AC';
3
4
  const DEFAULT_AGENT_BIO = 'You are a helpful local assistant. Be clear, practical, and concise.';
4
5
  const DEFAULT_AGENT_ICON = 'artificial-intelligence';
@@ -32,13 +33,13 @@ function seedableChat(chat) {
32
33
  updatedAt: chat.updatedAt
33
34
  };
34
35
  }
35
- export function buildDefaultSeed(device, blindPeerKeys, agentName = DEFAULT_AGENT_NAME) {
36
+ export function buildDefaultSeed(device, blindPeerKeys) {
36
37
  const now = Date.now();
37
38
  const agentId = randomId();
38
39
  return {
39
40
  agent: seedableAgent({
40
41
  id: agentId,
41
- name: agentName,
42
+ name: DEFAULT_AGENT_NAME,
42
43
  bio: DEFAULT_AGENT_BIO,
43
44
  providerDeviceId: device.id,
44
45
  modelName: device.recommendedModelName,
@@ -65,10 +66,14 @@ export function buildDefaultSeed(device, blindPeerKeys, agentName = DEFAULT_AGEN
65
66
  };
66
67
  }
67
68
  export function isOwnRevokedRow(mesh, device) {
68
- return device.revoked === true && device.writerKey?.equals(mesh.localWriterKey) === true;
69
+ return (device.revoked === true &&
70
+ !!device.writerKey &&
71
+ b4a.equals(device.writerKey, mesh.localWriterKey));
72
+ }
73
+ export function isKickedRow(device) {
74
+ return (device.revoked === true &&
75
+ !(device.writerKey && device.revokedBy && b4a.equals(device.revokedBy, device.writerKey)));
69
76
  }
70
77
  export function isOwnKickedRow(mesh, device) {
71
- if (!isOwnRevokedRow(mesh, device))
72
- return false;
73
- return device.revokedBy?.equals(mesh.localWriterKey) !== true;
78
+ return isOwnRevokedRow(mesh, device) && isKickedRow(device);
74
79
  }
@@ -49,8 +49,9 @@ export class HostedAgents {
49
49
  if (!(await this._lock.lock()))
50
50
  return;
51
51
  try {
52
- if (!this._closed && !this._mesh.closing)
52
+ if (!this._closed && !this._mesh.closing) {
53
53
  await this._pass();
54
+ }
54
55
  }
55
56
  catch (err) {
56
57
  this._log?.warn(SCOPE, 'hosted agent pass failed', err);
@@ -69,27 +70,31 @@ export class HostedAgents {
69
70
  if (departed.length > 0) {
70
71
  const catalog = await this._catalog();
71
72
  for (const id of departed) {
72
- try {
73
- if (await this._handOver(id, catalog))
74
- holding.delete(id);
75
- }
76
- catch (err) {
73
+ const released = await this._handOver(id, catalog).catch((err) => {
77
74
  this._log?.warn(SCOPE, 'skill values could not follow the agent', err);
75
+ return false;
76
+ });
77
+ if (released) {
78
+ holding.delete(id);
78
79
  }
79
80
  }
80
81
  }
81
- if (!sameIds(held, holding))
82
+ if (!sameIds(held, holding)) {
82
83
  await this._local.set(this._heldKey, [...holding]);
84
+ }
83
85
  }
84
86
  async _handOver(id, catalog) {
85
87
  const agent = await getAgent(this._mesh, id);
86
- if (!agent)
88
+ if (!agent) {
87
89
  return false;
88
- if (agent.deletedAt)
90
+ }
91
+ if (agent.deletedAt) {
89
92
  return true;
93
+ }
90
94
  const stored = await this._stored(agentSkillValues(catalog, agent));
91
- if (stored.length === 0)
95
+ if (stored.length === 0) {
92
96
  return true;
97
+ }
93
98
  for (const [skillName, values] of bySkill(stored)) {
94
99
  await this._send(agent.providerDeviceId, { agentId: id, skillName, values });
95
100
  }
@@ -101,8 +106,9 @@ export class HostedAgents {
101
106
  const stored = [];
102
107
  for (const value of values) {
103
108
  const held = await this._local.get(value.storageKey);
104
- if (typeof held === 'string' && held !== '')
109
+ if (typeof held === 'string' && held !== '') {
105
110
  stored.push({ ...value, value: held });
111
+ }
106
112
  }
107
113
  return stored;
108
114
  }
@@ -112,8 +118,9 @@ export class HostedAgents {
112
118
  const ids = new Set();
113
119
  if (Array.isArray(stored)) {
114
120
  for (const id of stored) {
115
- if (typeof id === 'string')
121
+ if (typeof id === 'string') {
116
122
  ids.add(id);
123
+ }
117
124
  }
118
125
  }
119
126
  return ids;
@@ -1,5 +1,5 @@
1
1
  import b4a from 'b4a';
2
2
  import crypto from 'hypercore-crypto';
3
3
  export function randomId() {
4
- return b4a.toString(crypto.randomBytes(16), 'hex');
4
+ return b4a.toHex(crypto.randomBytes(16));
5
5
  }
@@ -23,4 +23,5 @@ export declare function claimAttestation(meshPublicKey: Buffer, deviceId: Buffer
23
23
  export declare function deviceInviteToken(nonce: Buffer, deviceId: Buffer): Buffer;
24
24
  export declare function attestMemberClaim(attestation: Buffer, deviceKeyPair: KeyPair, deviceProof: Buffer): Promise<Buffer>;
25
25
  export declare function verifyMemberClaim(proof: Buffer, expected: ExpectedMemberClaim): Promise<boolean>;
26
+ export declare function verifyRecoveryClaim(proof: Buffer, expected: ExpectedMemberClaim): Promise<boolean>;
26
27
  export declare function bareDeviceProof(proof: Buffer): Buffer | null;
@@ -6,8 +6,9 @@ const [CLAIM_NAMESPACE] = crypto.namespace('@qvac/core/member-claim', 1);
6
6
  const [INVITE_NAMESPACE] = crypto.namespace('@qvac/core/device-invite', 1);
7
7
  let loaded = null;
8
8
  async function identityKey() {
9
- if (loaded === null)
9
+ if (loaded === null) {
10
10
  loaded = await import('keet-identity-key');
11
+ }
11
12
  return loaded.default;
12
13
  }
13
14
  export async function generateMnemonic() {
@@ -35,8 +36,9 @@ export async function verifyDeviceProof(proof, expected) {
35
36
  catch {
36
37
  return false;
37
38
  }
38
- if (decoded.data)
39
+ if (decoded.data) {
39
40
  return false;
41
+ }
40
42
  try {
41
43
  const IdentityKey = await identityKey();
42
44
  return !!IdentityKey.verify(proof, null, {
@@ -67,8 +69,9 @@ export async function verifyMemberClaim(proof, expected) {
67
69
  catch {
68
70
  return false;
69
71
  }
70
- if (!decoded.data)
72
+ if (!decoded.data) {
71
73
  return false;
74
+ }
72
75
  try {
73
76
  const IdentityKey = await identityKey();
74
77
  return !!IdentityKey.verify(proof, expected.attestation, {
@@ -80,6 +83,11 @@ export async function verifyMemberClaim(proof, expected) {
80
83
  return false;
81
84
  }
82
85
  }
86
+ export async function verifyRecoveryClaim(proof, expected) {
87
+ if (!(await verifyMemberClaim(proof, expected)))
88
+ return false;
89
+ return c.decode(ProofEncoding, proof).chain.length === 1;
90
+ }
83
91
  export function bareDeviceProof(proof) {
84
92
  let decoded;
85
93
  try {
@@ -1,13 +1,15 @@
1
1
  export declare const IMAGE_CACHE_MAX_BYTES: number;
2
2
  export declare const IMAGE_CACHE_MAX_AGE_MS: number;
3
- export declare function imageCacheName(image: {
4
- blobId: string;
5
- fileName: string;
6
- }): string;
3
+ export interface CachedImage {
4
+ readonly blobId: string;
5
+ readonly fileName: string;
6
+ }
7
+ export declare function imageCacheName(image: CachedImage): string;
7
8
  export declare function imageCacheKey(blobId: string): string;
8
- export declare function sweepImageCache(dir: string, { maxBytes, maxAgeMs, keep, inUse }?: {
9
- maxBytes?: number;
10
- maxAgeMs?: number;
11
- keep?: ReadonlySet<string>;
12
- inUse?: (name: string) => boolean;
13
- }): Promise<void>;
9
+ export interface SweepImageCacheOptions {
10
+ readonly maxBytes?: number;
11
+ readonly maxAgeMs?: number;
12
+ readonly keep?: ReadonlySet<string>;
13
+ readonly inUse?: (name: string) => boolean;
14
+ }
15
+ export declare function sweepImageCache(dir: string, { maxBytes, maxAgeMs, keep, inUse }?: SweepImageCacheOptions): Promise<void>;
@@ -12,19 +12,21 @@ export function imageCacheName(image) {
12
12
  return `${imageCacheKey(image.blobId)}-${name}`;
13
13
  }
14
14
  export function imageCacheKey(blobId) {
15
- return b4a.toHex(crypto.hash(Buffer.from(blobId))).slice(0, CACHE_KEY_CHARS);
15
+ return b4a.toHex(crypto.hash(b4a.from(blobId))).slice(0, CACHE_KEY_CHARS);
16
16
  }
17
17
  export async function sweepImageCache(dir, { maxBytes = IMAGE_CACHE_MAX_BYTES, maxAgeMs = IMAGE_CACHE_MAX_AGE_MS, keep, inUse } = {}) {
18
18
  const names = await fs.promises.readdir(dir).catch(toNull);
19
- if (!names)
19
+ if (!names) {
20
20
  return;
21
+ }
21
22
  const now = Date.now();
22
23
  const entries = [];
23
24
  let total = 0;
24
25
  for (const entry of await liveEntries(dir, names, now)) {
25
26
  total += entry.size;
26
- if (inUse?.(entry.name))
27
+ if (inUse?.(entry.name)) {
27
28
  continue;
29
+ }
28
30
  if (keep && !keep.has(entry.name.slice(0, CACHE_KEY_CHARS))) {
29
31
  await fs.promises.unlink(entry.file).catch(noop);
30
32
  total -= entry.size;
@@ -37,8 +39,9 @@ export async function sweepImageCache(dir, { maxBytes = IMAGE_CACHE_MAX_BYTES, m
37
39
  }
38
40
  entries.push(entry);
39
41
  }
40
- if (total <= maxBytes)
42
+ if (total <= maxBytes) {
41
43
  return;
44
+ }
42
45
  entries.sort((a, b) => a.mtimeMs - b.mtimeMs);
43
46
  for (const entry of entries) {
44
47
  if (total <= maxBytes)
@@ -54,11 +57,13 @@ async function liveEntries(dir, names, now) {
54
57
  for (const name of names) {
55
58
  const file = path.join(dir, name);
56
59
  const stats = await fs.promises.stat(file).catch(toNull);
57
- if (!stats?.isFile())
60
+ if (!stats?.isFile()) {
58
61
  continue;
62
+ }
59
63
  if (STAGING_SUFFIX.test(name)) {
60
- if (now - stats.mtimeMs > STALE_PARTIAL_MS)
64
+ if (now - stats.mtimeMs > STALE_PARTIAL_MS) {
61
65
  await fs.promises.unlink(file).catch(noop);
66
+ }
62
67
  continue;
63
68
  }
64
69
  entries.push({ file, name, size: stats.size, mtimeMs: stats.mtimeMs });
@@ -1,3 +1,9 @@
1
1
  export declare const MAX_IMAGE_WIDTH = 768;
2
2
  export declare const IMAGE_MIMES: Set<string>;
3
3
  export declare function normalizeImageForModel(bytes: Uint8Array): Promise<Uint8Array>;
4
+ export interface Raster {
5
+ readonly width: number;
6
+ readonly height: number;
7
+ readonly data: Uint8Array;
8
+ }
9
+ export declare function rasterToModelJpeg(raster: Raster): Promise<Uint8Array | null>;
@@ -27,8 +27,9 @@ async function loadMedia() {
27
27
  }
28
28
  export async function normalizeImageForModel(bytes) {
29
29
  const mod = await loadMedia();
30
- if (!mod)
30
+ if (!mod) {
31
31
  return bytes;
32
+ }
32
33
  try {
33
34
  const frame = firstFrame(await mod.image.decode(bytes));
34
35
  const oriented = await mod.image.orientate(frame, { file: bytes });
@@ -39,11 +40,20 @@ export async function normalizeImageForModel(bytes) {
39
40
  return bytes;
40
41
  }
41
42
  }
43
+ export async function rasterToModelJpeg(raster) {
44
+ const mod = await loadMedia();
45
+ if (!mod) {
46
+ return null;
47
+ }
48
+ const resized = await mod.image.resize(raster, { maxWidth: MAX_IMAGE_WIDTH });
49
+ return mod.image.encode(resized, { mimetype: 'image/jpeg' });
50
+ }
42
51
  function firstFrame(decoded) {
43
52
  if (!decoded.frames)
44
53
  return decoded;
45
54
  const [first] = decoded.frames;
46
- if (!first)
55
+ if (!first) {
47
56
  throw new Error('decoded image had no frames');
57
+ }
48
58
  return first;
49
59
  }
@@ -15,38 +15,52 @@ export function detectImageMime(bytes) {
15
15
  return 'image/png';
16
16
  if (isJpeg(bytes))
17
17
  return 'image/jpeg';
18
- if (isAvif(bytes))
18
+ if (isAvif(bytes)) {
19
19
  return 'image/avif';
20
- if (isHeif(bytes))
20
+ }
21
+ if (isHeif(bytes)) {
21
22
  return 'image/heic';
22
- if (isWebp(bytes))
23
+ }
24
+ if (isWebp(bytes)) {
23
25
  return 'image/webp';
24
- if (isGif(bytes))
26
+ }
27
+ if (isGif(bytes)) {
25
28
  return 'image/gif';
26
- if (isBmp(bytes))
29
+ }
30
+ if (isBmp(bytes)) {
27
31
  return 'image/bmp';
28
- if (isTiff(bytes))
32
+ }
33
+ if (isTiff(bytes)) {
29
34
  return 'image/tiff';
35
+ }
30
36
  return null;
31
37
  }
32
38
  export function mapDeclaredToSniffed(declared) {
33
39
  const normalized = declared.toLowerCase();
34
- if (normalized === 'image/png')
40
+ if (normalized === 'image/png') {
35
41
  return 'image/png';
36
- if (normalized === 'image/jpeg' || normalized === 'image/jpg')
42
+ }
43
+ if (normalized === 'image/jpeg' || normalized === 'image/jpg') {
37
44
  return 'image/jpeg';
38
- if (normalized === 'image/heic' || normalized === 'image/heif')
45
+ }
46
+ if (normalized === 'image/heic' || normalized === 'image/heif') {
39
47
  return 'image/heic';
40
- if (normalized === 'image/avif')
48
+ }
49
+ if (normalized === 'image/avif') {
41
50
  return 'image/avif';
42
- if (normalized === 'image/webp')
51
+ }
52
+ if (normalized === 'image/webp') {
43
53
  return 'image/webp';
44
- if (normalized === 'image/gif')
54
+ }
55
+ if (normalized === 'image/gif') {
45
56
  return 'image/gif';
46
- if (normalized === 'image/bmp' || normalized === 'image/x-ms-bmp')
57
+ }
58
+ if (normalized === 'image/bmp' || normalized === 'image/x-ms-bmp') {
47
59
  return 'image/bmp';
48
- if (normalized === 'image/tiff' || normalized === 'image/tif')
60
+ }
61
+ if (normalized === 'image/tiff' || normalized === 'image/tif') {
49
62
  return 'image/tiff';
63
+ }
50
64
  return null;
51
65
  }
52
66
  function isPng(bytes) {
@@ -73,8 +87,9 @@ function isHeif(bytes) {
73
87
  const b9 = bytes[9];
74
88
  const b10 = bytes[10];
75
89
  const b11 = bytes[11];
76
- if (b8 === undefined || b9 === undefined || b10 === undefined || b11 === undefined)
90
+ if (b8 === undefined || b9 === undefined || b10 === undefined || b11 === undefined) {
77
91
  return false;
92
+ }
78
93
  const brand = String.fromCharCode(b8, b9, b10, b11).toLowerCase();
79
94
  return HEIF_BRANDS.has(brand);
80
95
  }
@@ -85,13 +100,15 @@ function isAvif(bytes) {
85
100
  return false;
86
101
  }
87
102
  const major = brandAt(bytes, 8);
88
- if (major && AVIF_BRANDS.has(major))
103
+ if (major && AVIF_BRANDS.has(major)) {
89
104
  return true;
105
+ }
90
106
  const end = ftypBoxEnd(bytes);
91
107
  for (let offset = 16; offset + 4 <= end; offset += 4) {
92
108
  const compatible = brandAt(bytes, offset);
93
- if (compatible && AVIF_BRANDS.has(compatible))
109
+ if (compatible && AVIF_BRANDS.has(compatible)) {
94
110
  return true;
111
+ }
95
112
  }
96
113
  return false;
97
114
  }
@@ -100,8 +117,9 @@ function brandAt(bytes, offset) {
100
117
  const b = bytes[offset + 1];
101
118
  const c = bytes[offset + 2];
102
119
  const d = bytes[offset + 3];
103
- if (a === undefined || b === undefined || c === undefined || d === undefined)
120
+ if (a === undefined || b === undefined || c === undefined || d === undefined) {
104
121
  return null;
122
+ }
105
123
  return String.fromCharCode(a, b, c, d).toLowerCase();
106
124
  }
107
125
  function ftypBoxEnd(bytes) {
@@ -131,8 +149,9 @@ function isGif(bytes) {
131
149
  return false;
132
150
  if (bytes[0] !== 0x47 || bytes[1] !== 0x49 || bytes[2] !== 0x46)
133
151
  return false;
134
- if (bytes[3] !== 0x38 || bytes[5] !== 0x61)
152
+ if (bytes[3] !== 0x38 || bytes[5] !== 0x61) {
135
153
  return false;
154
+ }
136
155
  return bytes[4] === 0x37 || bytes[4] === 0x39;
137
156
  }
138
157
  function isBmp(bytes) {
@@ -141,9 +160,11 @@ function isBmp(bytes) {
141
160
  function isTiff(bytes) {
142
161
  if (bytes.length < 4)
143
162
  return false;
144
- if (bytes[0] === 0x49 && bytes[1] === 0x49)
163
+ if (bytes[0] === 0x49 && bytes[1] === 0x49) {
145
164
  return bytes[2] === 0x2a && bytes[3] === 0x00;
146
- if (bytes[0] === 0x4d && bytes[1] === 0x4d)
165
+ }
166
+ if (bytes[0] === 0x4d && bytes[1] === 0x4d) {
147
167
  return bytes[2] === 0x00 && bytes[3] === 0x2a;
168
+ }
148
169
  return false;
149
170
  }
@@ -2,21 +2,24 @@ import b4a from 'b4a';
2
2
  import { getAgent } from './agent.js';
3
3
  import { getChat } from './chat.js';
4
4
  import { NO_SUCH_AGENT, NOT_THE_HOST, SENDER_REVOKED } from './skill-secrets.js';
5
- const DEVICES = '@qvac/devices';
5
+ import { DEVICES } from './collections.js';
6
6
  export const NO_SUCH_CHAT = 'no such chat on the device hosting this agent';
7
7
  export const NO_RECORD_STORE = 'the device hosting this agent is not recording prompts right now';
8
8
  const MAX_ANSWER_BYTES = 2 * 1024 * 1024;
9
9
  export function createInferenceCallsReceiver(opts) {
10
10
  return async (request, fromDeviceId) => {
11
11
  const sender = await opts.mesh.view.get(DEVICES, { id: fromDeviceId });
12
- if (!sender || sender.revoked)
12
+ if (!sender || sender.revoked) {
13
13
  throw new Error(SENDER_REVOKED);
14
+ }
14
15
  const chat = await getChat(opts.mesh, request.chatId);
15
- if (!chat)
16
+ if (!chat) {
16
17
  throw new Error(NO_SUCH_CHAT);
18
+ }
17
19
  const agent = await getAgent(opts.mesh, chat.agentId);
18
- if (!agent)
20
+ if (!agent) {
19
21
  throw new Error(NO_SUCH_AGENT);
22
+ }
20
23
  if (!agent.providerDeviceId || !b4a.equals(agent.providerDeviceId, opts.deviceId)) {
21
24
  throw new Error(NOT_THE_HOST);
22
25
  }
@@ -0,0 +1,20 @@
1
+ import type { KeyPair } from 'hypercore-crypto';
2
+ export declare const GRANT_MAX_TTL_MS: number;
3
+ export declare const GRANT_MAX_USES = 100;
4
+ export declare const INVITE_GRANT_NO_EXPIRY = "An invite must expire";
5
+ export declare const INVITE_GRANT_TOO_LONG = "An invite cannot expire more than 30 days after it is made";
6
+ export declare const INVITE_GRANT_USES_OUT_OF_RANGE = "An invite admits between 1 and 100 people";
7
+ export interface InviteGrantTerms {
8
+ readonly expiresAt?: number;
9
+ readonly maxUses?: number;
10
+ }
11
+ export interface InviteClaimBinding {
12
+ readonly meshPublicKey: Buffer;
13
+ readonly grantKey: Buffer;
14
+ readonly deviceId: Buffer;
15
+ readonly writerKey: Buffer;
16
+ }
17
+ export declare function grantKeyPair(secret: Buffer): KeyPair;
18
+ export declare function inviteGrantTermsRefusal(terms: InviteGrantTerms, mintedAt: number): string | null;
19
+ export declare function signInviteClaim(secretKey: Buffer, binding: InviteClaimBinding): Buffer;
20
+ export declare function verifyInviteClaim(signature: Buffer | null | undefined, binding: InviteClaimBinding): boolean;
@@ -0,0 +1,46 @@
1
+ import crypto from 'hypercore-crypto';
2
+ const [GRANT_KEYPAIR_NAMESPACE] = crypto.namespace('@qvac/core/mesh-invite-grant', 1);
3
+ const [INVITE_CLAIM_NAMESPACE] = crypto.namespace('@qvac/core/mesh-invite-claim', 1);
4
+ export const GRANT_MAX_TTL_MS = 30 * 24 * 60 * 60 * 1000;
5
+ export const GRANT_MAX_USES = 100;
6
+ export const INVITE_GRANT_NO_EXPIRY = 'An invite must expire';
7
+ export const INVITE_GRANT_TOO_LONG = 'An invite cannot expire more than 30 days after it is made';
8
+ export const INVITE_GRANT_USES_OUT_OF_RANGE = 'An invite admits between 1 and 100 people';
9
+ export function grantKeyPair(secret) {
10
+ return crypto.keyPair(crypto.hash([GRANT_KEYPAIR_NAMESPACE, secret]));
11
+ }
12
+ function inviteClaimMessage(binding) {
13
+ return crypto.hash([
14
+ INVITE_CLAIM_NAMESPACE,
15
+ binding.meshPublicKey,
16
+ binding.grantKey,
17
+ binding.deviceId,
18
+ binding.writerKey
19
+ ]);
20
+ }
21
+ export function inviteGrantTermsRefusal(terms, mintedAt) {
22
+ const { expiresAt, maxUses } = terms;
23
+ if (!expiresAt) {
24
+ return INVITE_GRANT_NO_EXPIRY;
25
+ }
26
+ if (expiresAt > mintedAt + GRANT_MAX_TTL_MS) {
27
+ return INVITE_GRANT_TOO_LONG;
28
+ }
29
+ if (!maxUses || !Number.isInteger(maxUses) || maxUses < 1 || maxUses > GRANT_MAX_USES) {
30
+ return INVITE_GRANT_USES_OUT_OF_RANGE;
31
+ }
32
+ return null;
33
+ }
34
+ export function signInviteClaim(secretKey, binding) {
35
+ return crypto.sign(inviteClaimMessage(binding), secretKey);
36
+ }
37
+ export function verifyInviteClaim(signature, binding) {
38
+ if (!signature)
39
+ return false;
40
+ try {
41
+ return crypto.verify(inviteClaimMessage(binding), signature, binding.grantKey);
42
+ }
43
+ catch {
44
+ return false;
45
+ }
46
+ }
@@ -1,4 +1,5 @@
1
1
  import type { QvacAutobeeHead } from '../../spec/mesh/hyperschema/types.d.ts';
2
+ import type { RecoveryProof } from './mesh.ts';
2
3
  export interface MeshInviteNode {
3
4
  readonly host: string;
4
5
  readonly port: number;
@@ -13,6 +14,8 @@ export interface MeshInvite {
13
14
  readonly memberId?: Buffer;
14
15
  readonly inviteNonce?: Buffer;
15
16
  readonly compute?: boolean;
17
+ readonly recovery?: RecoveryProof;
18
+ readonly inviterName?: string;
16
19
  }
17
20
  export declare function encodeMeshInvite(invite: MeshInvite): string;
18
21
  export declare function decodeMeshInvite(raw: string): MeshInvite | null;
@@ -12,14 +12,16 @@ export function encodeMeshInvite(invite) {
12
12
  memberInvite: invite.memberInvite ?? false,
13
13
  memberId: invite.memberId ?? null,
14
14
  inviteNonce: invite.inviteNonce ?? null,
15
- compute: invite.compute ?? false
15
+ compute: invite.compute ?? false,
16
+ inviterName: invite.inviterName ?? null
16
17
  };
17
18
  return INVITE_PREFIX + z32.encode(encodeStruct(INVITE_STRUCT, payload));
18
19
  }
19
20
  export function decodeMeshInvite(raw) {
20
21
  const value = raw.trim().toLowerCase();
21
- if (!value.startsWith(INVITE_PREFIX))
22
+ if (!value.startsWith(INVITE_PREFIX)) {
22
23
  return null;
24
+ }
23
25
  let payload;
24
26
  try {
25
27
  payload = decodeStruct(INVITE_STRUCT, z32.decode(value.slice(INVITE_PREFIX.length)));
@@ -39,6 +41,7 @@ export function decodeMeshInvite(raw) {
39
41
  memberInvite: payload.memberInvite ?? false,
40
42
  memberId: payload.memberId ?? undefined,
41
43
  inviteNonce: payload.inviteNonce ?? undefined,
42
- compute: payload.compute ?? false
44
+ compute: payload.compute ?? false,
45
+ inviterName: payload.inviterName ?? undefined
43
46
  };
44
47
  }
@@ -1,9 +1,5 @@
1
1
  import b4a from 'b4a';
2
- const FILES = '@local/files';
3
- const FILES_BY_BLOB = '@local/files-by-blob';
4
- const RECLAIMABLE_FILES = '@local/reclaimable-files-by-last-accessed';
5
- const LIVE_FILES = '@local/live-files';
6
- const CONFIG = '@local/config';
2
+ import { LOCAL_CONFIG, LOCAL_FILES, LOCAL_FILES_BY_BLOB, LOCAL_LIVE_FILES, LOCAL_RECLAIMABLE_FILES_BY_LAST_ACCESSED } from '../collections.js';
7
3
  const TOUCH_GRAIN_MS = 60 * 60 * 1000;
8
4
  export class LocalFiles {
9
5
  _db;
@@ -59,12 +55,12 @@ export class LocalFiles {
59
55
  const tx = this._db.transaction();
60
56
  let changed = false;
61
57
  for (const file of files) {
62
- const known = await tx.get(FILES, keyOf(file));
58
+ const known = await tx.get(LOCAL_FILES, keyOf(file));
63
59
  const row = next(file, known);
64
60
  if (!row) {
65
61
  continue;
66
62
  }
67
- await tx.insert(FILES, row);
63
+ await tx.insert(LOCAL_FILES, row);
68
64
  changed = true;
69
65
  }
70
66
  if (changed) {
@@ -78,45 +74,50 @@ export class LocalFiles {
78
74
  markCleared(file) {
79
75
  return this._locked(async () => {
80
76
  const tx = this._db.transaction();
81
- const known = await tx.get(FILES, keyOf(file));
77
+ const known = await tx.get(LOCAL_FILES, keyOf(file));
82
78
  if (!known) {
83
79
  await tx.close();
84
80
  return;
85
81
  }
86
- await tx.insert(FILES, { ...known, cleared: true });
82
+ await tx.insert(LOCAL_FILES, { ...known, cleared: true });
87
83
  await tx.flush();
88
84
  });
89
85
  }
90
86
  async meshOf(coreKey, blockOffset) {
91
87
  const key = { coreKey, blockOffset };
92
- const row = await this._db.findOne(FILES_BY_BLOB, { gte: key, lte: key });
88
+ const row = await this._db.findOne(LOCAL_FILES_BY_BLOB, { gte: key, lte: key });
93
89
  return row?.meshKey ?? null;
94
90
  }
95
91
  async backfilled(meshKey) {
96
- return (await this._db.get(CONFIG, { key: backfillKey(meshKey) })) !== null;
92
+ return ((await this._db.get(LOCAL_CONFIG, { key: backfillKey(meshKey) })) !== null);
97
93
  }
98
94
  markBackfilled(meshKey) {
99
95
  return this._locked(async () => {
100
96
  const tx = this._db.transaction();
101
- await tx.insert(CONFIG, { key: backfillKey(meshKey), value: true });
97
+ await tx.insert(LOCAL_CONFIG, { key: backfillKey(meshKey), value: true });
102
98
  await tx.flush();
103
99
  });
104
100
  }
105
101
  list(meshKey) {
106
- return this._db.find(FILES, meshRange(meshKey)).toArray();
102
+ return this._db.find(LOCAL_FILES, meshRange(meshKey)).toArray();
107
103
  }
108
104
  live(meshKey) {
109
- return this._db.find(LIVE_FILES, meshRange(meshKey)).toArray();
105
+ return this._db.find(LOCAL_LIVE_FILES, meshRange(meshKey)).toArray();
110
106
  }
111
107
  stale(cutoff) {
112
- return this._db.find(RECLAIMABLE_FILES, { lt: { lastAccessed: cutoff } }).toArray();
108
+ return this._db
109
+ .find(LOCAL_RECLAIMABLE_FILES_BY_LAST_ACCESSED, { lt: { lastAccessed: cutoff } })
110
+ .toArray();
113
111
  }
114
112
  }
115
113
  export async function dropMeshFiles(tx, meshKey) {
116
- const rows = await tx.find(FILES, { gte: { meshKey }, lte: { meshKey } }).toArray();
117
- for (const row of rows)
118
- await tx.delete(FILES, keyOf(row));
119
- await tx.delete(CONFIG, { key: backfillKey(meshKey) });
114
+ const rows = await tx
115
+ .find(LOCAL_FILES, { gte: { meshKey }, lte: { meshKey } })
116
+ .toArray();
117
+ for (const row of rows) {
118
+ await tx.delete(LOCAL_FILES, keyOf(row));
119
+ }
120
+ await tx.delete(LOCAL_CONFIG, { key: backfillKey(meshKey) });
120
121
  }
121
122
  function meshRange(meshKey) {
122
123
  return meshKey ? { gte: { meshKey }, lte: { meshKey } } : {};