@qvac/core 0.8.0 → 0.10.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 (204) hide show
  1. package/CHANGELOG.md +114 -1
  2. package/README.md +5 -5
  3. package/dist-lib/index.d.ts +0 -1
  4. package/dist-lib/index.js +0 -1
  5. package/dist-lib/lib/api/agents.d.ts +7 -1
  6. package/dist-lib/lib/api/agents.js +2 -2
  7. package/dist-lib/lib/api/app-config.d.ts +2 -1
  8. package/dist-lib/lib/api/app-config.js +2 -2
  9. package/dist-lib/lib/api/attachments.js +3 -2
  10. package/dist-lib/lib/api/chat-move.d.ts +2 -1
  11. package/dist-lib/lib/api/chat-move.js +2 -2
  12. package/dist-lib/lib/api/chat.d.ts +3 -1
  13. package/dist-lib/lib/api/chat.js +5 -5
  14. package/dist-lib/lib/api/chunks.d.ts +2 -1
  15. package/dist-lib/lib/api/chunks.js +3 -3
  16. package/dist-lib/lib/api/config.d.ts +2 -1
  17. package/dist-lib/lib/api/config.js +2 -2
  18. package/dist-lib/lib/api/current-mesh.d.ts +1 -3
  19. package/dist-lib/lib/api/current-mesh.js +4 -10
  20. package/dist-lib/lib/api/custom-models.d.ts +7 -1
  21. package/dist-lib/lib/api/custom-models.js +10 -8
  22. package/dist-lib/lib/api/device-routes.d.ts +0 -2
  23. package/dist-lib/lib/api/device-routes.js +4 -5
  24. package/dist-lib/lib/api/devices.d.ts +3 -1
  25. package/dist-lib/lib/api/devices.js +9 -8
  26. package/dist-lib/lib/api/diagnostics.d.ts +2 -1
  27. package/dist-lib/lib/api/diagnostics.js +2 -2
  28. package/dist-lib/lib/api/index.d.ts +2 -0
  29. package/dist-lib/lib/api/index.js +39 -21
  30. package/dist-lib/lib/api/instrument.d.ts +2 -2
  31. package/dist-lib/lib/api/instrument.js +10 -11
  32. package/dist-lib/lib/api/knowledge.d.ts +3 -1
  33. package/dist-lib/lib/api/knowledge.js +9 -7
  34. package/dist-lib/lib/api/logs.js +3 -3
  35. package/dist-lib/lib/api/members.d.ts +6 -1
  36. package/dist-lib/lib/api/members.js +11 -10
  37. package/dist-lib/lib/api/mesh.d.ts +2 -2
  38. package/dist-lib/lib/api/mesh.js +6 -6
  39. package/dist-lib/lib/api/model-download.d.ts +2 -1
  40. package/dist-lib/lib/api/model-download.js +2 -2
  41. package/dist-lib/lib/api/network.d.ts +3 -2
  42. package/dist-lib/lib/api/network.js +4 -4
  43. package/dist-lib/lib/api/notifications.d.ts +3 -1
  44. package/dist-lib/lib/api/notifications.js +5 -4
  45. package/dist-lib/lib/api/rag.d.ts +0 -1
  46. package/dist-lib/lib/api/rag.js +3 -4
  47. package/dist-lib/lib/api/sync.d.ts +2 -1
  48. package/dist-lib/lib/api/sync.js +2 -2
  49. package/dist-lib/lib/api/tool-activity.d.ts +2 -1
  50. package/dist-lib/lib/api/tool-activity.js +4 -3
  51. package/dist-lib/lib/api/tool-configs.d.ts +2 -1
  52. package/dist-lib/lib/api/tool-configs.js +4 -3
  53. package/dist-lib/lib/api/upload-frames.d.ts +0 -1
  54. package/dist-lib/lib/api/upload-frames.js +0 -1
  55. package/dist-lib/lib/api/watchable.d.ts +3 -2
  56. package/dist-lib/lib/api/watchable.js +2 -3
  57. package/dist-lib/lib/assistant/fake-models.d.ts +2 -4
  58. package/dist-lib/lib/assistant/harness.js +8 -6
  59. package/dist-lib/lib/assistant-client.d.ts +2 -0
  60. package/dist-lib/lib/assistant-client.js +4 -3
  61. package/dist-lib/lib/assistant-tree.d.ts +3 -3
  62. package/dist-lib/lib/assistant.d.ts +2 -2
  63. package/dist-lib/lib/assistant.js +11 -11
  64. package/dist-lib/lib/client.d.ts +2 -2
  65. package/dist-lib/lib/core/agent.js +5 -4
  66. package/dist-lib/lib/core/archived-mesh.d.ts +2 -3
  67. package/dist-lib/lib/core/archived-mesh.js +3 -3
  68. package/dist-lib/lib/core/chat-activity.js +5 -3
  69. package/dist-lib/lib/core/chat-copy.d.ts +0 -1
  70. package/dist-lib/lib/core/chat-copy.js +2 -2
  71. package/dist-lib/lib/core/chat-fork.d.ts +0 -6
  72. package/dist-lib/lib/core/chat-fork.js +11 -17
  73. package/dist-lib/lib/core/chat-group.js +8 -7
  74. package/dist-lib/lib/core/chat-move.d.ts +4 -6
  75. package/dist-lib/lib/core/chat-move.js +14 -15
  76. package/dist-lib/lib/core/chat-order.d.ts +2 -1
  77. package/dist-lib/lib/core/chat-order.js +15 -2
  78. package/dist-lib/lib/core/chat.js +8 -7
  79. package/dist-lib/lib/core/chunk.js +13 -8
  80. package/dist-lib/lib/core/collections.d.ts +1 -0
  81. package/dist-lib/lib/core/collections.js +1 -0
  82. package/dist-lib/lib/core/contract/compute.d.ts +0 -4
  83. package/dist-lib/lib/core/contract/compute.js +2 -9
  84. package/dist-lib/lib/core/contract/types.d.ts +2 -2
  85. package/dist-lib/lib/core/departures.d.ts +2 -2
  86. package/dist-lib/lib/core/device-control.d.ts +0 -2
  87. package/dist-lib/lib/core/device-control.js +5 -6
  88. package/dist-lib/lib/core/files/attachments.js +5 -4
  89. package/dist-lib/lib/core/files/index.d.ts +2 -1
  90. package/dist-lib/lib/core/files/index.js +20 -8
  91. package/dist-lib/lib/core/files/processing/claims.js +3 -3
  92. package/dist-lib/lib/core/files/processing/document.d.ts +2 -0
  93. package/dist-lib/lib/core/files/processing/document.js +3 -0
  94. package/dist-lib/lib/core/files/processing/index.js +4 -2
  95. package/dist-lib/lib/core/files/processing/source.d.ts +3 -0
  96. package/dist-lib/lib/core/files/processing/source.js +5 -3
  97. package/dist-lib/lib/core/files/processing/state.js +1 -0
  98. package/dist-lib/lib/core/files/rag/index.d.ts +3 -0
  99. package/dist-lib/lib/core/files/rag/index.js +3 -1
  100. package/dist-lib/lib/core/files/rag/load.js +6 -3
  101. package/dist-lib/lib/core/files/rag/produce.js +3 -3
  102. package/dist-lib/lib/core/files/rag/retrieval/full-text.js +1 -1
  103. package/dist-lib/lib/core/files/rag/similarity.d.ts +2 -2
  104. package/dist-lib/lib/core/files/rag/similarity.js +2 -3
  105. package/dist-lib/lib/core/files/records/chunks.js +1 -1
  106. package/dist-lib/lib/core/files/records/knowledge.js +2 -1
  107. package/dist-lib/lib/core/files/records/purge.js +9 -5
  108. package/dist-lib/lib/core/files/records/reclaim.js +20 -48
  109. package/dist-lib/lib/core/files/records/sweep.d.ts +3 -0
  110. package/dist-lib/lib/core/files/records/sweep.js +9 -3
  111. package/dist-lib/lib/core/files/store/blob.d.ts +2 -0
  112. package/dist-lib/lib/core/files/store/blob.js +2 -2
  113. package/dist-lib/lib/core/files/store/index.d.ts +1 -0
  114. package/dist-lib/lib/core/files/store/index.js +2 -0
  115. package/dist-lib/lib/core/files/store/reference.js +4 -2
  116. package/dist-lib/lib/core/files/upload.d.ts +1 -1
  117. package/dist-lib/lib/core/files/upload.js +10 -9
  118. package/dist-lib/lib/core/handoff-channel.d.ts +6 -4
  119. package/dist-lib/lib/core/handoff-channel.js +8 -9
  120. package/dist-lib/lib/core/harness-loan.d.ts +0 -2
  121. package/dist-lib/lib/core/harness-loan.js +3 -4
  122. package/dist-lib/lib/core/hosted-agents.d.ts +2 -2
  123. package/dist-lib/lib/core/inference-calls-handoff.d.ts +2 -2
  124. package/dist-lib/lib/core/inference-calls-handoff.js +6 -5
  125. package/dist-lib/lib/core/inference-calls-receiver.d.ts +0 -2
  126. package/dist-lib/lib/core/inference-calls-receiver.js +5 -7
  127. package/dist-lib/lib/core/invite.js +9 -4
  128. package/dist-lib/lib/core/local/index.d.ts +4 -1
  129. package/dist-lib/lib/core/local/index.js +23 -2
  130. package/dist-lib/lib/core/membership.d.ts +2 -2
  131. package/dist-lib/lib/core/mesh.d.ts +13 -7
  132. package/dist-lib/lib/core/mesh.js +55 -47
  133. package/dist-lib/lib/core/migrations/file-index.js +2 -4
  134. package/dist-lib/lib/core/next-frame.js +2 -1
  135. package/dist-lib/lib/core/pdf/rasterize.d.ts +2 -1
  136. package/dist-lib/lib/core/pdf/rasterize.js +5 -5
  137. package/dist-lib/lib/core/peer-duplex.d.ts +3 -3
  138. package/dist-lib/lib/core/peer-duplex.js +4 -4
  139. package/dist-lib/lib/core/secret-handoff.d.ts +2 -2
  140. package/dist-lib/lib/core/secret-handoff.js +7 -4
  141. package/dist-lib/lib/core/send.js +3 -2
  142. package/dist-lib/lib/core/skill-overlay-handoff.d.ts +2 -2
  143. package/dist-lib/lib/core/skill-overlay-handoff.js +6 -5
  144. package/dist-lib/lib/core/skill-overlay-receiver.js +5 -5
  145. package/dist-lib/lib/core/skill-secrets.d.ts +0 -5
  146. package/dist-lib/lib/core/skill-secrets.js +5 -9
  147. package/dist-lib/lib/core/sync/changed.d.ts +20 -0
  148. package/dist-lib/lib/core/sync/changed.js +7 -0
  149. package/dist-lib/lib/core/sync/devices.js +1 -1
  150. package/dist-lib/lib/core/sync/files.d.ts +1 -0
  151. package/dist-lib/lib/core/sync/files.js +50 -72
  152. package/dist-lib/lib/core/sync/index.d.ts +1 -2
  153. package/dist-lib/lib/core/sync/index.js +40 -62
  154. package/dist-lib/lib/core/sync/view-updates.d.ts +33 -0
  155. package/dist-lib/lib/core/sync/view-updates.js +133 -0
  156. package/dist-lib/lib/core/system-info.d.ts +2 -2
  157. package/dist-lib/lib/core/system-info.js +10 -11
  158. package/dist-lib/lib/core/tool-configs.js +6 -6
  159. package/dist-lib/lib/core.d.ts +1 -7
  160. package/dist-lib/lib/core.js +147 -131
  161. package/dist-lib/lib/custom-model-pusher.d.ts +2 -4
  162. package/dist-lib/lib/custom-model-task.d.ts +2 -1
  163. package/dist-lib/lib/custom-model-task.js +2 -2
  164. package/dist-lib/lib/downloads-allowed-pusher.d.ts +2 -4
  165. package/dist-lib/lib/errors.d.ts +603 -0
  166. package/dist-lib/lib/errors.js +552 -0
  167. package/dist-lib/lib/log.d.ts +7 -6
  168. package/dist-lib/lib/log.js +10 -6
  169. package/dist-lib/lib/logger-type.d.ts +2 -5
  170. package/dist-lib/lib/model-download-status.d.ts +2 -2
  171. package/dist-lib/lib/model-download.d.ts +2 -2
  172. package/dist-lib/lib/model-download.js +3 -2
  173. package/dist-lib/lib/model-idle-pusher.d.ts +2 -4
  174. package/dist-lib/lib/model-memory-cap.d.ts +2 -4
  175. package/dist-lib/lib/oauth/browser-connect.js +3 -2
  176. package/dist-lib/lib/oauth/flow-core.js +3 -3
  177. package/dist-lib/lib/oauth/loopback.js +10 -9
  178. package/dist-lib/lib/oauth/providers.js +4 -2
  179. package/dist-lib/lib/oauth/register.js +3 -2
  180. package/dist-lib/lib/oauth/token-exchange-core.js +5 -4
  181. package/dist-lib/lib/run-transcript.d.ts +2 -2
  182. package/dist-lib/lib/task.js +2 -1
  183. package/dist-lib/schema/engine.js +6 -3
  184. package/dist-lib/schema/field-order.js +1 -3
  185. package/dist-lib/schema/local.js +11 -0
  186. package/dist-lib/spec/hrpc/messages.js +20 -9
  187. package/dist-lib/spec/hyperschema/index.js +20 -9
  188. package/dist-lib/spec/hyperschema/schema.json +15 -0
  189. package/dist-lib/spec/hyperschema/types.d.ts +3 -0
  190. package/dist-lib/spec/local/hyperdb/db.json +16 -1
  191. package/dist-lib/spec/local/hyperdb/index.js +71 -2
  192. package/dist-lib/spec/local/hyperdb/messages.js +300 -143
  193. package/dist-lib/spec/local/hyperschema/index.js +82 -2
  194. package/dist-lib/spec/local/hyperschema/schema.json +43 -1
  195. package/dist-lib/spec/local/hyperschema/types.d.ts +12 -1
  196. package/package.json +9 -2
  197. package/tui/README.md +2 -2
  198. package/tui/app.mjs +11 -5
  199. package/tui/boot.mjs +1 -1
  200. package/worker/assistant-sidecar.mjs +7 -0
  201. package/dist-lib/lib/log-levels.d.ts +0 -7
  202. package/dist-lib/lib/log-levels.js +0 -1
  203. package/dist-lib/lib/logger.d.ts +0 -5
  204. package/dist-lib/lib/logger.js +0 -18
package/CHANGELOG.md CHANGED
@@ -13,6 +13,117 @@ release.
13
13
 
14
14
  ## [Unreleased]
15
15
 
16
+ ## [0.10.0] - 2026-10-16
17
+
18
+ ### Added
19
+
20
+ - Core's refusals carry a registered `@qvac/error` code, so a caller matches
21
+ them with `isCoreError` from `@qvac/core/errors` instead of their message,
22
+ which is unchanged. Every route family has its codes (`CHAT_*`, `MESH_*`,
23
+ `INVITE_*`, `MEMBER_*`, `DEVICE_*`, `AGENT_*`, `UPLOAD_*`, `MODEL_*`, `OAUTH_*`
24
+ and the rest, exported from `@qvac/core/errors`), and a refusal from a hosting device reaches the caller with
25
+ its code. An older host sends none, so its refusal arrives as its message
26
+ alone. Each module's codes are in its file under
27
+ [`docs/api/`](docs/api/README.md). (#382, #383, #384, #385, #386, #387, #388)
28
+ - `Logger` from `@qvac/core/log` implements `@qvac/logging`'s
29
+ `LoggerInterface`, has `getLevel()`, and takes `logLevel: 'off'`. `Client`,
30
+ `QvacAssistant`, the assistant children and the model pushers take any
31
+ `LoggerInterface`, so a `QvacLogger` can be passed. (#389)
32
+ - `duck` indexes office attachments with the harness extractor. (#457)
33
+
34
+ ### Changed
35
+
36
+ - **Breaking:** each `Core` writes only to the logger it is given, and one
37
+ created without a `logger` writes nothing, where it used to fall back to the
38
+ process-wide logger. Pass the logger to `Core`, `Client` and `QvacAssistant`.
39
+ (#389)
40
+ - `logSimilarityScores` from `@qvac/core/rag/similarity` writes only to the
41
+ logger passed as its third argument. (#389)
42
+
43
+ ```js
44
+ logSimilarityScores(candidates, kept) // 0.9
45
+ logSimilarityScores(candidates, kept, logger) // 0.10
46
+ ```
47
+
48
+ - **Breaking:** a compute mesh's dropped write is named
49
+ `COMPUTE_ROUTE_DROPPED`, where it was `ComputeRouteDropped`, and has no
50
+ `route` field. Match it by code. (#382)
51
+
52
+ ```js
53
+ err.name === 'ComputeRouteDropped' // 0.9
54
+ isCoreError(err, 'COMPUTE_ROUTE_DROPPED') // 0.10
55
+ ```
56
+
57
+ ### Removed
58
+
59
+ - **Breaking:** `setLogger` and the `globalThis.logger` it set. (#389)
60
+
61
+ ```js
62
+ setLogger(logger) // 0.9, then new Core(options)
63
+ new Core({ ...options, logger }) // 0.10
64
+ ```
65
+
66
+ - **Breaking:** `LEVELS` from `@qvac/core/log`. Use `LEVEL_PRIORITIES` from
67
+ `@qvac/logging/constants`, which ranks the other way round: `error` is 0.
68
+ (#389)
69
+
70
+ ```js
71
+ LEVELS[level] >= LEVELS.warn // 0.9
72
+ LEVEL_PRIORITIES[level] <= LEVEL_PRIORITIES.warn // 0.10
73
+ ```
74
+
75
+ ### Fixed
76
+
77
+ - An office file the agent host cannot decode reads `failed` with
78
+ `extractor unavailable on this device` in `fileStatusWatch`, and `ragSearch`
79
+ lists it in `failedFiles`, instead of staying pending forever and holding up
80
+ the run waiting on it. (#456)
81
+ - `updateMember` or `removeMember` called right after a join no longer fails
82
+ with `this device is in no member of its account`; it waits for the join to
83
+ land. (#391)
84
+ - A device that fast-forwards back onto a mesh lands without reading the view
85
+ in the update hook, as a joiner does. It used to scan every device, chat and
86
+ purged chat first. Chats deleted while it was away are found by the chat
87
+ order rebuild, purges by the device's own file index, and its own kick by
88
+ its own device row. (#465)
89
+ - A fast-forward no longer downloads every version of the view, and the
90
+ move-to sweep reads attachments only in the chats this device holds files
91
+ for, and knowledge rows whole, not every chat and attachment in the mesh. (#465)
92
+ - A linear update reads at most one old row per change. A revoked device or a
93
+ re-homed chat no longer scans every agent or a chat's whole history to find
94
+ its files, and the membership tally runs after the update instead of inside
95
+ it. (#465)
96
+ - A joiner no longer walks every chunk of the mesh it joined to backfill its
97
+ file index, and the backfill, the orphan sweep at every open and the purged
98
+ file reclaim read attachments chat by chat off an index instead of every
99
+ message. (#465)
100
+ - The view update hook only queues the update. A background pass syncs what
101
+ the device derives from the view, and folds updates that land while it runs
102
+ into one diff, so a streamed reply or a catch-up no longer walks once per
103
+ append, and the drain never waits on a peer for a block a side effect reads. (#465)
104
+ - The oldest view head a device has not synced is kept in the device-local
105
+ `@local/mesh-updates`, so a pass a close or crash cuts short resumes on the
106
+ next open instead of losing what it would have raised. (#465)
107
+
108
+ ## [0.9.0] - 2026-10-15
109
+
110
+ ### Changed
111
+
112
+ - **Breaking:** `meshInvite` mints a member invite as `qvac://workspace/…` and
113
+ a device invite as `qvac://device/…`, instead of `qvac://mesh/…`
114
+ (QVAC-26926). `joinMesh`, `previewMeshInvite` and `decodeMeshInvite` read all
115
+ three, so a link shared before still works, but a release before this one
116
+ refuses the new links with `Invalid mesh invite`: both sides of a join need
117
+ this version. An app that matches the prefix itself has to accept all three
118
+ before it takes this release, as tetherto/qvac-app#2535 does. (#394)
119
+
120
+ ```js
121
+ const { invite } = await engine.meshInvite({ meshId, member: true })
122
+ // 0.8: qvac://mesh/… 0.9: qvac://workspace/…
123
+ const { invite: pairing } = await engine.meshInvite({})
124
+ // 0.8: qvac://mesh/… 0.9: qvac://device/…
125
+ ```
126
+
16
127
  ## [0.8.0] - 2026-10-15
17
128
 
18
129
  ### Added
@@ -1669,7 +1780,9 @@ Published under the `release-0.1` dist-tag.
1669
1780
  await assistant.ready()
1670
1781
  ```
1671
1782
 
1672
- [Unreleased]: https://github.com/tetherto/qvac-core/compare/v0.8.0...HEAD
1783
+ [Unreleased]: https://github.com/tetherto/qvac-core/compare/v0.10.0...HEAD
1784
+ [0.10.0]: https://github.com/tetherto/qvac-core/compare/v0.9.0...v0.10.0
1785
+ [0.9.0]: https://github.com/tetherto/qvac-core/compare/v0.8.0...v0.9.0
1673
1786
  [0.8.0]: https://github.com/tetherto/qvac-core/compare/v0.7.6...v0.8.0
1674
1787
  [0.7.6]: https://github.com/tetherto/qvac-core/compare/v0.7.5...v0.7.6
1675
1788
  [0.7.5]: https://github.com/tetherto/qvac-core/compare/v0.7.4...v0.7.5
package/README.md CHANGED
@@ -705,11 +705,11 @@ feature checklist vs core v1.
705
705
 
706
706
  ### Office documents
707
707
 
708
- Core ships no office decoder. Word-processor documents (`.docx`, `.doc`,
708
+ Core ships no office decoder. Office documents (`.docx`, `.xlsx`, `.pptx`,
709
709
  `.odt`, …) index only when the host passes one through the `extractors.office`
710
- option — the app injects `extractOfficeText` from `@qvac/harness/office`.
711
- `duck` injects none, so those formats fail to index there even though
712
- `/knowledge add` accepts them. Everything else it accepts — `.pdf`, `.txt`,
710
+ option — the desktop app and `duck` inject `extractOfficeText` from
711
+ `@qvac/harness/office`. A host without one, such as mobile, fails those files
712
+ as `extractor unavailable on this device`. Everything else — `.pdf`, `.txt`,
713
713
  `.md`, `.rtf`, `.html`, `.csv`, `.json` and the rest — works from any install.
714
714
 
715
715
  ## The duck TUI
@@ -722,7 +722,7 @@ The TUI copies its mesh invite to the clipboard on ctrl+y. On a second machine
722
722
  (or a second terminal), start `duck` and join from inside it:
723
723
 
724
724
  ```
725
- /join qvac://mesh/…
725
+ /join qvac://device/…
726
726
  ```
727
727
 
728
728
  The preview says who you would join as. A device invite (`/invite`) retires the
@@ -1,6 +1,5 @@
1
1
  export type { AssistantAgent, AssistantAgentList, AssistantConfigValue } from './spec/hyperschema/types.d.ts';
2
2
  export type { Logger } from './lib/logger-type.ts';
3
- export { setLogger } from './lib/logger.ts';
4
3
  export { Core } from './lib/core.ts';
5
4
  export { Client } from './lib/client.ts';
6
5
  export { AssistantClient } from './lib/assistant-client.ts';
package/dist-lib/index.js CHANGED
@@ -1,4 +1,3 @@
1
- export { setLogger } from './lib/logger.js';
2
1
  export { Core } from './lib/core.js';
3
2
  export { Client } from './lib/client.js';
4
3
  export { AssistantClient } from './lib/assistant-client.js';
@@ -1,5 +1,11 @@
1
+ import type { LoggerInterface } from '@qvac/logging';
1
2
  import { type MeshPool } from './current-mesh.ts';
2
3
  import type { CapabilityHandlers } from '../../spec/capabilities.d.ts';
3
4
  type AgentCapabilities = Pick<CapabilityHandlers, 'createAgent' | 'listAgents' | 'getAgent' | 'getDefaultAgent' | 'updateAgent' | 'deleteAgent' | 'agentsWatch'>;
4
- export declare function createAgentsApi(pool: MeshPool, deviceId: Buffer | null, computeLender?: (() => Promise<Buffer | null>) | null): AgentCapabilities;
5
+ export interface CreateAgentsApiOptions {
6
+ readonly deviceId: Buffer | null;
7
+ readonly computeLender: (() => Promise<Buffer | null>) | null;
8
+ readonly log: LoggerInterface | null;
9
+ }
10
+ export declare function createAgentsApi(pool: MeshPool, { deviceId, computeLender, log }: CreateAgentsApiOptions): AgentCapabilities;
5
11
  export {};
@@ -1,7 +1,7 @@
1
1
  import { createAgent, deleteAgent, getDefaultAgent, isOrphaned, listAgents, liveProviderIds, mustGetActiveAgent, updateAgent } from '../core/agent.js';
2
2
  import { meshWatchable, requireMesh } from './current-mesh.js';
3
3
  import b4a from 'b4a';
4
- export function createAgentsApi(pool, deviceId, computeLender = null) {
4
+ export function createAgentsApi(pool, { deviceId, computeLender, log }) {
5
5
  const withOrphaned = async (mesh, agent) => ({
6
6
  ...agent,
7
7
  orphaned: await isOrphaned(mesh, agent)
@@ -45,6 +45,6 @@ export function createAgentsApi(pool, deviceId, computeLender = null) {
45
45
  const mesh = await requireMesh(pool, meshId);
46
46
  return withOrphaned(mesh, await deleteAgent(mesh, deviceId, agentId));
47
47
  },
48
- agentsWatch: meshWatchable(pool, (request, mesh) => list(mesh, request.providerDeviceId ?? undefined), { name: 'agentsWatch' })
48
+ agentsWatch: meshWatchable(pool, (request, mesh) => list(mesh, request.providerDeviceId ?? undefined), { name: 'agentsWatch', log })
49
49
  };
50
50
  }
@@ -1,7 +1,8 @@
1
+ import type { LoggerInterface } from '@qvac/logging';
1
2
  import type { AssistantAppConfig } from '../../spec/hyperschema/types.d.ts';
2
3
  import type { openLocalStore } from '../core/local/index.ts';
3
4
  import type { CapabilityHandlers } from '../../spec/capabilities.d.ts';
4
5
  type LocalStore = Awaited<ReturnType<typeof openLocalStore>>;
5
6
  export declare function writeAutoDownloadModels(state: LocalStore, enabled: boolean): Promise<AssistantAppConfig>;
6
- export declare function createAppConfigApi(state: LocalStore): Pick<CapabilityHandlers, 'getConfig' | 'setConfig' | 'setModelPaused' | 'setModelReleased' | 'setAutoDownloadModels' | 'configWatchTyped'>;
7
+ export declare function createAppConfigApi(state: LocalStore, log: LoggerInterface | null): Pick<CapabilityHandlers, 'getConfig' | 'setConfig' | 'setModelPaused' | 'setModelReleased' | 'setAutoDownloadModels' | 'configWatchTyped'>;
7
8
  export {};
@@ -121,7 +121,7 @@ export async function writeAutoDownloadModels(state, enabled) {
121
121
  const row = await state.updateAppConfigRow((current) => toRow({ ...toConfig(current), autoDownloadModels: enabled }));
122
122
  return toConfig(row);
123
123
  }
124
- export function createAppConfigApi(state) {
124
+ export function createAppConfigApi(state, log) {
125
125
  return {
126
126
  getConfig(_) {
127
127
  return readConfig(state);
@@ -153,6 +153,6 @@ export function createAppConfigApi(state) {
153
153
  setAutoDownloadModels(input) {
154
154
  return writeAutoDownloadModels(state, input.enabled ?? false);
155
155
  },
156
- configWatchTyped: watchable(() => state, () => readConfig(state), { name: 'configWatchTyped' })
156
+ configWatchTyped: watchable(() => state, () => readConfig(state), { name: 'configWatchTyped', log })
157
157
  };
158
158
  }
@@ -1,4 +1,5 @@
1
- import { openUpload, UPLOAD_NAMES_NO_MESH } from './upload-frames.js';
1
+ import { CoreError } from '../errors.js';
2
+ import { openUpload } from './upload-frames.js';
2
3
  import { requireMesh } from './current-mesh.js';
3
4
  export { MAX_ATTACHMENT_BYTES } from '../core/files/attachments.js';
4
5
  export function createAttachmentsApi(pool, options = {}) {
@@ -9,7 +10,7 @@ export function createAttachmentsApi(pool, options = {}) {
9
10
  return;
10
11
  }
11
12
  if (!upload.first.meshId) {
12
- throw new Error(UPLOAD_NAMES_NO_MESH);
13
+ throw new CoreError('UPLOAD_MESH_MISSING');
13
14
  }
14
15
  const mesh = await requireMesh(pool, upload.first.meshId);
15
16
  yield* mesh.files.attachments(options).uploadAttachment(upload.rest);
@@ -1,3 +1,4 @@
1
+ import type { LoggerInterface } from '@qvac/logging';
1
2
  import type { CapabilityHandlers } from '../../spec/capabilities.d.ts';
2
3
  import type { ChatMoves } from '../core/chat-move.ts';
3
- export declare function createChatMoveApi(moves: ChatMoves): Pick<CapabilityHandlers, 'moveChatToMesh' | 'chatMoveWatch'>;
4
+ export declare function createChatMoveApi(moves: ChatMoves, log: LoggerInterface | null): Pick<CapabilityHandlers, 'moveChatToMesh' | 'chatMoveWatch'>;
@@ -1,7 +1,7 @@
1
1
  import { watchable } from './watchable.js';
2
- export function createChatMoveApi(moves) {
2
+ export function createChatMoveApi(moves, log) {
3
3
  return {
4
4
  moveChatToMesh: (request) => moves.move(request),
5
- chatMoveWatch: watchable(() => moves, (request, store) => store.status(request), { name: 'chatMoveWatch' })
5
+ chatMoveWatch: watchable(() => moves, (request, store) => store.status(request), { name: 'chatMoveWatch', log })
6
6
  };
7
7
  }
@@ -1,3 +1,4 @@
1
+ import type { LoggerInterface } from '@qvac/logging';
1
2
  import type { CapabilityHandlers } from '../../spec/capabilities.d.ts';
2
3
  import type { openLocalStore } from '../core/local/index.ts';
3
4
  import { type MeshPool } from './current-mesh.ts';
@@ -8,6 +9,7 @@ export interface CreateChatApiOptions {
8
9
  readonly inferenceCalls?: {
9
10
  forget(chatId: string): Promise<void>;
10
11
  } | null;
12
+ readonly log: LoggerInterface | null;
11
13
  }
12
- export declare function createChatApi(pool: MeshPool, local: LocalStore, { deviceId, inferenceCalls }: CreateChatApiOptions): ChatCapabilities;
14
+ export declare function createChatApi(pool: MeshPool, local: LocalStore, { deviceId, inferenceCalls, log }: CreateChatApiOptions): ChatCapabilities;
13
15
  export {};
@@ -1,13 +1,13 @@
1
1
  import { AbortController } from 'bare-abort-controller';
2
2
  import { createChat, deleteChat, markChatRead, mustGetActiveChatListing, renameChat, setChatAgent, setChatRagEnabled, setChatWebSearchEnabled } from '../core/chat.js';
3
+ import { CoreError } from '../errors.js';
3
4
  import { listChatActivity } from '../core/chat-activity.js';
4
5
  import { forkChat } from '../core/chat-fork.js';
5
6
  import { listChatPage } from '../core/chat-order.js';
6
7
  import { searchChats } from '../core/chat-search.js';
7
8
  import { meshWatchable, requireMesh } from './current-mesh.js';
8
9
  const SEARCH_SUPERSEDED_ABORT = 'superseded by a newer chat search';
9
- const NO_DEVICE = 'this device has no identity yet, so it cannot write a fork';
10
- export function createChatApi(pool, local, { deviceId, inferenceCalls = null }) {
10
+ export function createChatApi(pool, local, { deviceId, inferenceCalls = null, log }) {
11
11
  let searchAbort = null;
12
12
  const chatList = (mesh, { limit, cursor }) => listChatPage(mesh, local, { limit: limit || undefined, cursor: cursor ?? undefined });
13
13
  const chatActivity = (mesh, chatIds) => listChatActivity(mesh, chatIds ?? undefined).then((activities) => ({ activities }));
@@ -20,7 +20,7 @@ export function createChatApi(pool, local, { deviceId, inferenceCalls = null })
20
20
  setChatAgent: async ({ chatId, agentId, meshId }) => setChatAgent(await requireMesh(pool, meshId), chatId, agentId),
21
21
  forkChat: async ({ meshId, targetMeshId, config, ...cut }) => {
22
22
  if (!deviceId)
23
- throw new Error(NO_DEVICE);
23
+ throw new CoreError('CHAT_FORK_NO_DEVICE');
24
24
  const from = await requireMesh(pool, meshId);
25
25
  const into = targetMeshId ? await requireMesh(pool, targetMeshId) : from;
26
26
  return forkChat({ from, into }, { ...cut, title: config?.title, originDeviceId: deviceId });
@@ -32,9 +32,9 @@ export function createChatApi(pool, local, { deviceId, inferenceCalls = null })
32
32
  await inferenceCalls?.forget(chatId);
33
33
  return deleted;
34
34
  },
35
- chatsWatch: meshWatchable(pool, (request, store) => chatList(store, request), { name: 'chatsWatch', changes: local }),
35
+ chatsWatch: meshWatchable(pool, (request, store) => chatList(store, request), { name: 'chatsWatch', log, changes: local }),
36
36
  listChatActivity: async (input) => chatActivity(await requireMesh(pool, input.meshId), input.chatIds),
37
- chatActivityWatch: meshWatchable(pool, (request, store) => chatActivity(store, request.chatIds), { name: 'chatActivityWatch' }),
37
+ chatActivityWatch: meshWatchable(pool, (request, store) => chatActivity(store, request.chatIds), { name: 'chatActivityWatch', log }),
38
38
  searchChats: async (input) => {
39
39
  searchAbort?.abort(SEARCH_SUPERSEDED_ABORT);
40
40
  const controller = new AbortController();
@@ -1,5 +1,6 @@
1
+ import type { LoggerInterface } from '@qvac/logging';
1
2
  import { type MeshPool } from './current-mesh.ts';
2
3
  import type { CapabilityHandlers } from '../../spec/capabilities.d.ts';
3
4
  type ChunkCapabilities = Pick<CapabilityHandlers, 'appendChunk' | 'updateChunk' | 'resolveApproval' | 'listChunks' | 'listAttachmentsByKind' | 'chunksWatch' | 'chunksDeltaWatch' | 'runRequestsWatch'>;
4
- export declare function createChunksApi(pool: MeshPool, deviceId: Buffer | null): ChunkCapabilities;
5
+ export declare function createChunksApi(pool: MeshPool, deviceId: Buffer | null, log: LoggerInterface | null): ChunkCapabilities;
5
6
  export {};
@@ -2,10 +2,10 @@ import { appendChunk, listAttachmentsByKind, listChunks, listRunRequests, record
2
2
  import { chunkDeltaStream } from './chunk-delta.js';
3
3
  import { meshWatchable, requireMesh } from './current-mesh.js';
4
4
  import { bounds } from './range.js';
5
- export function createChunksApi(pool, deviceId) {
5
+ export function createChunksApi(pool, deviceId, log) {
6
6
  const chunksWatch = meshWatchable(pool, async ({ meshId, ...input }, mesh) => ({
7
7
  chunks: await recordLinks(mesh, await listChunks(mesh, chunkSelection(input)))
8
- }), { name: 'chunksWatch' });
8
+ }), { name: 'chunksWatch', log });
9
9
  return {
10
10
  appendChunk: async ({ meshId, ...input }) => appendChunk(await requireMesh(pool, meshId), input),
11
11
  updateChunk: async ({ meshId, chunkId, runStatus }) => {
@@ -37,7 +37,7 @@ export function createChunksApi(pool, deviceId) {
37
37
  },
38
38
  chunksWatch,
39
39
  chunksDeltaWatch: (request) => chunkDeltaStream(chunksWatch(request)),
40
- runRequestsWatch: meshWatchable(pool, async (_request, mesh) => ({ chunks: await listRunRequests(mesh, deviceId) }), { name: 'runRequestsWatch' })
40
+ runRequestsWatch: meshWatchable(pool, async (_request, mesh) => ({ chunks: await listRunRequests(mesh, deviceId) }), { name: 'runRequestsWatch', log })
41
41
  };
42
42
  }
43
43
  function chunkSelection({ chatId, type, types, ...rest }) {
@@ -1,5 +1,6 @@
1
+ import type { LoggerInterface } from '@qvac/logging';
1
2
  import type { openLocalStore } from '../core/local/index.ts';
2
3
  import type { CapabilityHandlers } from '../../spec/capabilities.d.ts';
3
4
  type LocalStore = Awaited<ReturnType<typeof openLocalStore>>;
4
- export declare function createConfigApi(state: LocalStore): Pick<CapabilityHandlers, 'configGet' | 'configSet' | 'configWatch'>;
5
+ export declare function createConfigApi(state: LocalStore, log: LoggerInterface | null): Pick<CapabilityHandlers, 'configGet' | 'configSet' | 'configWatch'>;
5
6
  export {};
@@ -1,5 +1,5 @@
1
1
  import { watchable } from './watchable.js';
2
- export function createConfigApi(state) {
2
+ export function createConfigApi(state, log) {
3
3
  return {
4
4
  async configGet({ key }) {
5
5
  return { value: await state.get(key) };
@@ -10,6 +10,6 @@ export function createConfigApi(state) {
10
10
  },
11
11
  configWatch: watchable(() => state, async ({ key }) => ({
12
12
  value: await state.get(key)
13
- }), { name: 'configWatch' })
13
+ }), { name: 'configWatch', log })
14
14
  };
15
15
  }
@@ -2,10 +2,8 @@ import type { Readable } from 'streamx';
2
2
  import type { Mesh } from '../core/mesh.ts';
3
3
  import { type WatchableOptions } from './watchable.ts';
4
4
  export type MeshPool = (meshId: string) => Mesh | null | Promise<Mesh | null>;
5
- export declare const NO_SUCH_MESH = "no such mesh";
6
5
  export declare function requireMesh(pool: MeshPool, meshId: string): Promise<Mesh>;
7
- export declare function isMissingMesh(err: unknown): boolean;
8
- export declare function meshWatchable<TRequest extends MeshScoped, TResult>(pool: MeshPool, query: (request: TRequest, mesh: Mesh) => Promise<TResult>, { name, changes }: WatchableOptions): (request: TRequest) => Readable & AsyncIterable<TResult>;
6
+ export declare function meshWatchable<TRequest extends MeshScoped, TResult>(pool: MeshPool, query: (request: TRequest, mesh: Mesh) => Promise<TResult>, options: WatchableOptions): (request: TRequest) => Readable & AsyncIterable<TResult>;
9
7
  interface MeshScoped {
10
8
  readonly meshId: string;
11
9
  }
@@ -1,21 +1,15 @@
1
1
  import { watchable } from './watchable.js';
2
- export const NO_SUCH_MESH = 'no such mesh';
2
+ import { CoreError } from '../errors.js';
3
3
  export async function requireMesh(pool, meshId) {
4
4
  const mesh = await pool(meshId);
5
5
  if (!mesh) {
6
- throw new Error(`${NO_SUCH_MESH}: ${meshId}`);
6
+ throw new CoreError('MESH_NOT_FOUND', [meshId]);
7
7
  }
8
8
  if (!mesh.opened) {
9
9
  await mesh.ready();
10
10
  }
11
11
  return mesh;
12
12
  }
13
- export function isMissingMesh(err) {
14
- return err instanceof Error && err.message.startsWith(`${NO_SUCH_MESH}: `);
15
- }
16
- export function meshWatchable(pool, query, { name, changes }) {
17
- return watchable((request) => requireMesh(pool, request.meshId), query, {
18
- name,
19
- changes
20
- });
13
+ export function meshWatchable(pool, query, options) {
14
+ return watchable((request) => requireMesh(pool, request.meshId), query, options);
21
15
  }
@@ -1,3 +1,4 @@
1
+ import type { LoggerInterface } from '@qvac/logging';
1
2
  import type { AssistantCustomModelPreview, AssistantDeleteModelResponse, AssistantPreviewCustomModelRequest } from '../../spec/hyperschema/types.d.ts';
2
3
  import type { openLocalStore } from '../core/local/index.ts';
3
4
  import type { CapabilityHandlers } from '../../spec/capabilities.d.ts';
@@ -8,5 +9,10 @@ export type CustomModelFileDelete = (request: {
8
9
  name: string;
9
10
  }) => Promise<AssistantDeleteModelResponse>;
10
11
  export type CustomModelPreviewSource = (request: AssistantPreviewCustomModelRequest) => Promise<AssistantCustomModelPreview>;
11
- export declare function createCustomModelApi(state: LocalStore, preview: CustomModelPreviewSource | null, deleteFiles?: CustomModelFileDelete | null): Pick<CapabilityHandlers, 'customModelsWatch' | 'addCustomModel' | 'removeCustomModel' | 'previewCustomModel'>;
12
+ export interface CreateCustomModelApiOptions {
13
+ readonly preview: CustomModelPreviewSource | null;
14
+ readonly deleteFiles: CustomModelFileDelete | null;
15
+ readonly log: LoggerInterface | null;
16
+ }
17
+ export declare function createCustomModelApi(state: LocalStore, { preview, deleteFiles, log }: CreateCustomModelApiOptions): Pick<CapabilityHandlers, 'customModelsWatch' | 'addCustomModel' | 'removeCustomModel' | 'previewCustomModel'>;
12
18
  export {};
@@ -2,6 +2,7 @@ import b4a from 'b4a';
2
2
  import crypto from 'hypercore-crypto';
3
3
  import { watchable } from './watchable.js';
4
4
  import { customModelTaskRefusal } from '../custom-model-task.js';
5
+ import { CoreError } from '../errors.js';
5
6
  export const CUSTOM_MODEL_ID_PREFIX = 'custom:';
6
7
  export function customModelId(src) {
7
8
  return CUSTOM_MODEL_ID_PREFIX + b4a.toHex(crypto.hash(b4a.from(src))).slice(0, 12);
@@ -25,32 +26,33 @@ async function readCustomModels(state) {
25
26
  }))
26
27
  };
27
28
  }
28
- export function createCustomModelApi(state, preview, deleteFiles = null) {
29
+ export function createCustomModelApi(state, { preview, deleteFiles, log }) {
29
30
  const previewSource = async (request) => {
30
- if (!preview)
31
- throw new Error('no model source preview bound');
31
+ if (!preview) {
32
+ throw new CoreError('CAPABILITY_UNBOUND', ['model source preview']);
33
+ }
32
34
  return await preview(request);
33
35
  };
34
36
  return {
35
- customModelsWatch: watchable(() => state, () => readCustomModels(state), { name: 'customModelsWatch' }),
37
+ customModelsWatch: watchable(() => state, () => readCustomModels(state), { name: 'customModelsWatch', log }),
36
38
  previewCustomModel: previewSource,
37
39
  addCustomModel: async (input) => {
38
40
  const checked = await previewSource({ src: input.src, mmprojSrc: input.mmprojSrc });
39
41
  if (!checked.ok) {
40
- throw new Error(checked.reason || 'The model source was refused.');
42
+ throw new CoreError('CUSTOM_MODEL_SOURCE_REFUSED', [checked.reason]);
41
43
  }
42
44
  if (!checked.src) {
43
- throw new Error('This repository holds several models; add one of its files.');
45
+ throw new CoreError('CUSTOM_MODEL_AMBIGUOUS');
44
46
  }
45
47
  const unrunnable = customModelTaskRefusal(checked.taskType);
46
48
  if (unrunnable) {
47
- throw new Error(unrunnable);
49
+ throw unrunnable;
48
50
  }
49
51
  const id = customModelId(checked.src);
50
52
  const label = input.label.trim();
51
53
  const taken = (await state.getCustomModelRows()).find((row) => (row.label || row.name) === label && row.name !== id);
52
54
  if (taken) {
53
- throw new Error(`${label} is already the name of another model you added.`);
55
+ throw new CoreError('CUSTOM_MODEL_LABEL_TAKEN', [label]);
54
56
  }
55
57
  const row = {
56
58
  name: id,
@@ -1,6 +1,4 @@
1
1
  import type { Capabilities, CapabilityHandlers } from '../../spec/capabilities.d.ts';
2
- export declare const LINK_SOURCES_ONLY = "A model added from another device must come from a link: a path would name a file on this device.";
3
- export declare const MODEL_SETTINGS_ONLY = "Another device may read and change only the model settings of this one.";
4
2
  export declare const DEVICE_ROUTES: readonly ["listModels", "deleteModel", "loadModel", "unloadModel", "retryModelDownload", "clearModelDownload", "modelCatalogWatch", "modelDownloadsWatch", "customModelsWatch", "previewCustomModel", "addCustomModel", "removeCustomModel", "modelUsers", "modelsWatch", "configGet", "configSet", "configWatch", "setModelPaused"];
5
3
  export type DeviceRoutes = Pick<CapabilityHandlers, (typeof DEVICE_ROUTES)[number]>;
6
4
  export interface ForwardingOptions {
@@ -1,10 +1,9 @@
1
1
  import b4a from 'b4a';
2
2
  import { Readable } from 'streamx';
3
3
  import { asError } from '../guards.js';
4
+ import { CoreError } from '../errors.js';
4
5
  import { frameReadable } from '../frame-readable.js';
5
6
  import { MODEL_IDLE_UNLOAD_KEY, MODEL_MEMORY_CAP_KEY } from '../constants.js';
6
- export const LINK_SOURCES_ONLY = 'A model added from another device must come from a link: a path would name a file on this device.';
7
- export const MODEL_SETTINGS_ONLY = 'Another device may read and change only the model settings of this one.';
8
7
  const SIBLING_CONFIG_KEYS = new Set([
9
8
  MODEL_IDLE_UNLOAD_KEY,
10
9
  MODEL_MEMORY_CAP_KEY
@@ -96,7 +95,7 @@ function here(input) {
96
95
  }
97
96
  function required(handler, route) {
98
97
  if (!handler) {
99
- throw new Error(`${route} is not served on this device`);
98
+ throw new CoreError('DEVICE_ROUTE_NOT_SERVED', [route]);
100
99
  }
101
100
  return handler;
102
101
  }
@@ -114,11 +113,11 @@ async function answer(handler, route, input) {
114
113
  function refuseLocalSources(input) {
115
114
  const sources = [input.src, input.mmprojSrc].filter((src) => !!src);
116
115
  if (!sources.every((src) => /^https?:\/\//i.test(src?.trim() ?? ''))) {
117
- throw new Error(LINK_SOURCES_ONLY);
116
+ throw new CoreError('LINK_SOURCES_ONLY');
118
117
  }
119
118
  }
120
119
  function refuseOtherKeys({ key }) {
121
120
  if (!SIBLING_CONFIG_KEYS.has(key)) {
122
- throw new Error(MODEL_SETTINGS_ONLY);
121
+ throw new CoreError('MODEL_SETTINGS_ONLY');
123
122
  }
124
123
  }
@@ -1,9 +1,11 @@
1
+ import type { LoggerInterface } from '@qvac/logging';
1
2
  import type { AssistantCapabilityProfile } from '../../spec/hyperschema/types.d.ts';
2
3
  import type { Mesh } from '../core/mesh.ts';
3
4
  import { type MeshPool } from './current-mesh.ts';
4
5
  import type { CapabilityHandlers } from '../../spec/capabilities.d.ts';
5
6
  export interface CreateDevicesApiOptions {
6
7
  readonly deviceId: Buffer;
8
+ readonly log: LoggerInterface | null;
7
9
  readonly removeWriter: (writerKey: Buffer, deviceId: Buffer, mesh: Mesh) => Promise<void>;
8
10
  readonly renameLocal: (name: string) => Promise<void>;
9
11
  readonly saveProfileLocal: (capabilityProfile: AssistantCapabilityProfile, recommendedModelName: string, platform?: string) => Promise<void>;
@@ -15,4 +17,4 @@ export interface CreateDevicesApiOptions {
15
17
  readonly isAccount: (mesh: Mesh) => boolean;
16
18
  readonly computeLender?: (() => Promise<Buffer | null>) | null;
17
19
  }
18
- export declare function createDevicesApi(pool: MeshPool, { deviceId, removeWriter, renameLocal, saveProfileLocal, readLocalProfile, isAccount, computeLender }: CreateDevicesApiOptions): Pick<CapabilityHandlers, 'listDevices' | 'getDevice' | 'devicesWatch' | 'deviceInfo' | 'saveDeviceCapabilities' | 'saveDeviceProfile' | 'removeDevice' | 'renameDevice'>;
20
+ export declare function createDevicesApi(pool: MeshPool, { deviceId, log, removeWriter, renameLocal, saveProfileLocal, readLocalProfile, isAccount, computeLender }: CreateDevicesApiOptions): Pick<CapabilityHandlers, 'listDevices' | 'getDevice' | 'devicesWatch' | 'deviceInfo' | 'saveDeviceCapabilities' | 'saveDeviceProfile' | 'removeDevice' | 'renameDevice'>;
@@ -3,6 +3,7 @@ import { saveDeviceCapabilities } from '../core/devices.js';
3
3
  import { meshWatchable, requireMesh } from './current-mesh.js';
4
4
  import b4a from 'b4a';
5
5
  import { DEVICES } from '../core/collections.js';
6
+ import { CoreError } from '../errors.js';
6
7
  function toEngineDevice(device, overrides = {}) {
7
8
  return {
8
9
  id: device.id,
@@ -25,13 +26,13 @@ function toEngineDevice(device, overrides = {}) {
25
26
  ...overrides
26
27
  };
27
28
  }
28
- export function createDevicesApi(pool, { deviceId, removeWriter, renameLocal, saveProfileLocal, readLocalProfile, isAccount, computeLender = null }) {
29
+ export function createDevicesApi(pool, { deviceId, log, removeWriter, renameLocal, saveProfileLocal, readLocalProfile, isAccount, computeLender = null }) {
29
30
  const mustGetDevice = async (mesh, id) => {
30
31
  const snap = mesh.view.snapshot();
31
32
  try {
32
33
  const device = await snap.get(DEVICES, { id });
33
34
  if (!device) {
34
- throw new Error(`device not found: ${b4a.toHex(id)}`);
35
+ throw new CoreError('DEVICE_NOT_FOUND', [b4a.toHex(id)]);
35
36
  }
36
37
  return device;
37
38
  }
@@ -52,9 +53,9 @@ export function createDevicesApi(pool, { deviceId, removeWriter, renameLocal, sa
52
53
  return {
53
54
  listDevices: async (request) => list(await requireMesh(pool, request.meshId)),
54
55
  getDevice: async ({ deviceId: id, meshId }) => toEngineDevice(await mustGetDevice(await requireMesh(pool, meshId), id)),
55
- devicesWatch: meshWatchable(pool, (_request, mesh) => list(mesh), { name: 'devicesWatch' }),
56
+ devicesWatch: meshWatchable(pool, (_request, mesh) => list(mesh), { name: 'devicesWatch', log }),
56
57
  deviceInfo: async () => {
57
- logger.info(['api', 'devices'], 'deviceInfo handler reached');
58
+ log?.info(['api', 'devices'], 'deviceInfo handler reached');
58
59
  const computeLenderId = (await computeLender?.()) ?? undefined;
59
60
  return { id: deviceId, supportsKvCacheDeletion: true, computeLenderId };
60
61
  },
@@ -72,7 +73,7 @@ export function createDevicesApi(pool, { deviceId, removeWriter, renameLocal, sa
72
73
  },
73
74
  removeDevice: async ({ deviceId: target, meshId }) => {
74
75
  if (b4a.equals(target, deviceId)) {
75
- throw new Error('cannot remove own device, use leaveMesh');
76
+ throw new CoreError('DEVICE_REMOVE_SELF');
76
77
  }
77
78
  const mesh = await requireMesh(pool, meshId);
78
79
  const device = await mustGetDevice(mesh, target);
@@ -80,7 +81,7 @@ export function createDevicesApi(pool, { deviceId, removeWriter, renameLocal, sa
80
81
  return { ok: true };
81
82
  }
82
83
  if (!device.writerKey) {
83
- throw new Error('device has no writer key, cannot remove');
84
+ throw new CoreError('DEVICE_NO_WRITER_KEY');
84
85
  }
85
86
  await removeWriter(device.writerKey, target, mesh);
86
87
  return { ok: true };
@@ -88,10 +89,10 @@ export function createDevicesApi(pool, { deviceId, removeWriter, renameLocal, sa
88
89
  renameDevice: async ({ meshId, config }) => {
89
90
  const trimmed = config.name.trim();
90
91
  if (!trimmed) {
91
- throw new Error('device name must not be empty');
92
+ throw new CoreError('DEVICE_NAME_EMPTY');
92
93
  }
93
94
  if (!deviceNameWithinBounds(trimmed)) {
94
- throw new Error(`device name must be at most ${MAX_DEVICE_NAME_CHARS} characters`);
95
+ throw new CoreError('DEVICE_NAME_TOO_LONG', [MAX_DEVICE_NAME_CHARS]);
95
96
  }
96
97
  const mesh = await requireMesh(pool, meshId);
97
98
  const device = await mustGetDevice(mesh, deviceId);
@@ -1,3 +1,4 @@
1
+ import type { LoggerInterface } from '@qvac/logging';
1
2
  import type { CapabilityHandlers } from '../../spec/capabilities.d.ts';
2
3
  export interface DiagnosticsSource {
3
4
  watch(listener: () => void): void;
@@ -5,4 +6,4 @@ export interface DiagnosticsSource {
5
6
  snapshot(): Record<string, unknown>;
6
7
  readonly sampled: true;
7
8
  }
8
- export declare function createDiagnosticsApi(source: DiagnosticsSource): Pick<CapabilityHandlers, 'diagnostics' | 'diagnosticsWatch'>;
9
+ export declare function createDiagnosticsApi(source: DiagnosticsSource, log: LoggerInterface | null): Pick<CapabilityHandlers, 'diagnostics' | 'diagnosticsWatch'>;