@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,6 +1,6 @@
1
1
  import { liveDeviceForWriter } from './contract/activity.js';
2
2
  import { DeadlineScheduler } from '../deadline.js';
3
- const GRANTS = '@qvac/mesh-invite-grants';
3
+ import { MESH_INVITE_GRANTS } from './collections.js';
4
4
  const MAX_DELAY_MS = 2 ** 31 - 1;
5
5
  export class GrantExpiry {
6
6
  _mesh;
@@ -22,29 +22,34 @@ export class GrantExpiry {
22
22
  async _sweep() {
23
23
  const mesh = this._mesh;
24
24
  this._timer.clear();
25
- if (mesh.closing || !mesh.writable)
25
+ if (mesh.closing || !mesh.writable) {
26
26
  return;
27
+ }
27
28
  const now = Date.now();
28
29
  const expired = [];
29
30
  let soonest = Infinity;
30
31
  const snap = mesh.view.snapshot();
31
32
  try {
32
- if (!(await liveDeviceForWriter(snap, mesh.localWriterKey)))
33
+ if (!(await liveDeviceForWriter(snap, mesh.localWriterKey))) {
33
34
  return;
34
- for await (const grant of snap.find(GRANTS)) {
35
+ }
36
+ for await (const grant of snap.find(MESH_INVITE_GRANTS)) {
35
37
  if (grant.revokedAt || !grant.expiresAt)
36
38
  continue;
37
- if (now > grant.expiresAt)
39
+ if (now > grant.expiresAt) {
38
40
  expired.push(grant.grantKey);
39
- else
41
+ }
42
+ else {
40
43
  soonest = Math.min(soonest, grant.expiresAt);
44
+ }
41
45
  }
42
46
  }
43
47
  finally {
44
48
  await snap.close();
45
49
  }
46
- if (mesh.closing)
50
+ if (mesh.closing) {
47
51
  return;
52
+ }
48
53
  if (expired.length) {
49
54
  const batch = mesh.batch();
50
55
  for (const grantKey of expired) {
@@ -1,5 +1,6 @@
1
1
  import b4a from 'b4a';
2
2
  import Protomux, {} from 'protomux';
3
+ import { errorMessage } from '../guards.js';
3
4
  export const HOST_UNREACHABLE = 'the device hosting this agent is not connected';
4
5
  export const HOST_SILENT = 'the device hosting this agent did not answer';
5
6
  export const ACK_TIMEOUT_MS = 60_000;
@@ -17,18 +18,21 @@ export class HandoffChannel {
17
18
  this._nextId = 0;
18
19
  }
19
20
  addStream(stream) {
20
- const deviceId = b4a.toString(stream.remotePublicKey, 'hex');
21
- if (this._peers.has(deviceId))
21
+ const deviceId = b4a.toHex(stream.remotePublicKey);
22
+ if (this._peers.has(deviceId)) {
22
23
  return;
24
+ }
23
25
  const channel = Protomux.from(stream.noiseStream).createChannel({
24
26
  protocol: this._opts.protocol,
25
27
  onclose: () => {
26
- if (channel)
28
+ if (channel) {
27
29
  this._drop(deviceId, channel);
30
+ }
28
31
  }
29
32
  });
30
- if (!channel)
33
+ if (!channel) {
31
34
  return;
35
+ }
32
36
  const requests = channel.addMessage({
33
37
  encoding: this._opts.requestEncoding,
34
38
  onmessage: (m) => void this._serve(deviceId, m)
@@ -48,48 +52,58 @@ export class HandoffChannel {
48
52
  channel.open();
49
53
  }
50
54
  send(hostDeviceId, request, kind = 0) {
51
- const deviceId = b4a.toString(hostDeviceId, 'hex');
55
+ const deviceId = b4a.toHex(hostDeviceId);
52
56
  const peer = this._peers.get(deviceId);
53
- if (!peer)
57
+ if (!peer) {
54
58
  return Promise.reject(new Error(HOST_UNREACHABLE));
59
+ }
55
60
  const id = this._nextId++;
56
61
  const { promise, resolve, reject } = Promise.withResolvers();
57
62
  const timer = setTimeout(() => this._fail((w) => w === this._waiters.get(id), new Error(HOST_SILENT)), this._ackTimeoutMs);
58
63
  this._waiters.set(id, { deviceId, timer, resolve, reject });
59
- (kind === 0 ? peer.requests : peer.extraRequests[kind - 1]).send({ id, request });
64
+ const target = kind === 0 ? peer.requests : peer.extraRequests[kind - 1];
65
+ if (!target) {
66
+ return Promise.reject(new Error(`no request encoding of kind ${kind}`));
67
+ }
68
+ target.send({ id, request });
60
69
  return promise;
61
70
  }
62
71
  destroy() {
63
- for (const peer of this._peers.values())
72
+ for (const peer of this._peers.values()) {
64
73
  peer.channel.close();
74
+ }
65
75
  this._peers.clear();
66
76
  this._fail(() => true, new Error(`${this._opts.protocol} destroyed`));
67
77
  }
68
78
  async _serve(deviceId, m) {
69
79
  const peer = this._peers.get(deviceId);
70
- if (!peer)
80
+ if (!peer) {
71
81
  return;
82
+ }
72
83
  let error = '';
73
84
  let result = null;
74
85
  try {
75
86
  result = await this._opts.onrequest(m.request, peer.remoteKey);
76
87
  }
77
88
  catch (err) {
78
- error = err instanceof Error ? err.message : String(err);
89
+ error = errorMessage(err);
79
90
  }
80
91
  peer.responses.send(this._opts.buildAck(m.id, error, result));
81
92
  }
82
93
  _settle(deviceId, ack) {
83
94
  const waiter = this._waiters.get(ack.id);
84
- if (!waiter || waiter.deviceId !== deviceId)
95
+ if (!waiter || waiter.deviceId !== deviceId) {
85
96
  return;
97
+ }
86
98
  this._waiters.delete(ack.id);
87
99
  clearTimeout(waiter.timer);
88
100
  const { error, result } = this._opts.readAck(ack);
89
- if (error)
101
+ if (error) {
90
102
  waiter.reject(new Error(error));
91
- else
103
+ }
104
+ else {
92
105
  waiter.resolve(result);
106
+ }
93
107
  }
94
108
  _drop(deviceId, channel) {
95
109
  if (this._peers.get(deviceId)?.channel !== channel)
@@ -8,13 +8,20 @@ export const LOAN_UNREACHABLE = 'the device lending its model is not connected';
8
8
  export const LOAN_REFUSED = 'the device would not lend its model';
9
9
  export const LOAN_REVOKED = 'the device stopped lending its model';
10
10
  export function loanFailureNotice(error) {
11
- const message = error instanceof Error ? error.message : typeof error === 'string' ? error : '';
12
- if (message.includes(LOAN_UNREACHABLE))
11
+ const message = messageOf(error);
12
+ if (message.includes(LOAN_UNREACHABLE)) {
13
13
  return LOAN_UNREACHABLE;
14
- if (message.includes('CHANNEL_CLOSED'))
14
+ }
15
+ if (message.includes('CHANNEL_CLOSED')) {
15
16
  return LOAN_REFUSED;
17
+ }
16
18
  return null;
17
19
  }
20
+ function messageOf(error) {
21
+ if (error instanceof Error)
22
+ return error.message;
23
+ return typeof error === 'string' ? error : '';
24
+ }
18
25
  const bytes = raw;
19
26
  const frame = {
20
27
  preencode(state, f) {
@@ -56,15 +63,17 @@ export class HarnessLoan {
56
63
  this._nextId = 1;
57
64
  }
58
65
  addStream(stream) {
59
- const deviceId = b4a.toString(stream.remotePublicKey, 'hex');
60
- if (this._peers.has(deviceId))
66
+ const deviceId = b4a.toHex(stream.remotePublicKey);
67
+ if (this._peers.has(deviceId)) {
61
68
  return;
69
+ }
62
70
  const channel = Protomux.from(stream.noiseStream).createChannel({
63
71
  protocol: PROTOCOL,
64
72
  onclose: () => this._drop(deviceId)
65
73
  });
66
- if (!channel)
74
+ if (!channel) {
67
75
  return;
76
+ }
68
77
  const open = channel.addMessage({
69
78
  encoding: uint,
70
79
  onmessage: (id) => void this._serve(deviceId, id)
@@ -90,11 +99,12 @@ export class HarnessLoan {
90
99
  }
91
100
  borrow(deviceId) {
92
101
  const peer = this._peers.get(deviceId);
93
- if (!peer)
102
+ if (!peer) {
94
103
  throw new Error(LOAN_UNREACHABLE);
104
+ }
95
105
  const id = this._nextId;
96
106
  this._nextId += 1;
97
- const stream = this._attach(peer, id, true);
107
+ const stream = this._attach(peer, id, { mine: true });
98
108
  peer.open.send(id);
99
109
  return stream;
100
110
  }
@@ -120,7 +130,8 @@ export class HarnessLoan {
120
130
  this._drop(deviceId);
121
131
  }
122
132
  }
123
- _attach(peer, id, mine) {
133
+ _attach(peer, id, opts) {
134
+ const { mine } = opts;
124
135
  const held = mine ? peer.borrowed : peer.served;
125
136
  const stream = new Duplex({
126
137
  write: (chunk, cb) => {
@@ -132,8 +143,9 @@ export class HarnessLoan {
132
143
  cb(null);
133
144
  },
134
145
  destroy: (cb) => {
135
- if (held.delete(id))
146
+ if (held.delete(id)) {
136
147
  peer.close.send({ id, mine });
148
+ }
137
149
  cb(null);
138
150
  }
139
151
  });
@@ -142,9 +154,10 @@ export class HarnessLoan {
142
154
  }
143
155
  async _serve(deviceId, id) {
144
156
  const peer = this._peers.get(deviceId);
145
- if (!peer || peer.served.has(id))
157
+ if (!peer || peer.served.has(id)) {
146
158
  return;
147
- const stream = this._attach(peer, id, false);
159
+ }
160
+ const stream = this._attach(peer, id, { mine: false });
148
161
  const served = await this._opts.onborrow(peer.remoteKey).catch(noop);
149
162
  if (!served) {
150
163
  stream.destroy();
@@ -156,31 +169,36 @@ export class HarnessLoan {
156
169
  }
157
170
  _deliver(deviceId, f) {
158
171
  const peer = this._peers.get(deviceId);
159
- if (!peer)
172
+ if (!peer) {
160
173
  return;
174
+ }
161
175
  const held = f.mine ? peer.served : peer.borrowed;
162
176
  held.get(f.id)?.push(f.data);
163
177
  }
164
178
  _end(deviceId, e) {
165
179
  const peer = this._peers.get(deviceId);
166
- if (!peer)
180
+ if (!peer) {
167
181
  return;
182
+ }
168
183
  const held = e.mine ? peer.served : peer.borrowed;
169
184
  const stream = held.get(e.id);
170
- if (!stream)
185
+ if (!stream) {
171
186
  return;
187
+ }
172
188
  held.delete(e.id);
173
189
  stream.push(null);
174
190
  stream.destroy();
175
191
  }
176
192
  _drop(deviceId) {
177
193
  const peer = this._peers.get(deviceId);
178
- if (!peer)
194
+ if (!peer) {
179
195
  return;
196
+ }
180
197
  this._peers.delete(deviceId);
181
198
  for (const held of [peer.borrowed, peer.served]) {
182
- for (const stream of held.values())
199
+ for (const stream of held.values()) {
183
200
  stream.destroy(new Error(LOAN_UNREACHABLE));
201
+ }
184
202
  held.clear();
185
203
  }
186
204
  }
@@ -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';
@@ -65,10 +66,13 @@ export function buildDefaultSeed(device, blindPeerKeys) {
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));
69
72
  }
70
73
  export function isKickedRow(device) {
71
- return (device.revoked === true && !(device.writerKey && device.revokedBy?.equals(device.writerKey)));
74
+ return (device.revoked === true &&
75
+ !(device.writerKey && device.revokedBy && b4a.equals(device.revokedBy, device.writerKey)));
72
76
  }
73
77
  export function isOwnKickedRow(mesh, device) {
74
78
  return isOwnRevokedRow(mesh, device) && isKickedRow(device);
@@ -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
  }
@@ -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, {
@@ -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
  }