@qvac/core 0.9.0 → 0.10.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 (203) hide show
  1. package/CHANGELOG.md +112 -1
  2. package/README.md +4 -4
  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 +5 -3
  63. package/dist-lib/lib/assistant.js +50 -13
  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/local/index.d.ts +4 -1
  128. package/dist-lib/lib/core/local/index.js +23 -2
  129. package/dist-lib/lib/core/membership.d.ts +2 -2
  130. package/dist-lib/lib/core/mesh.d.ts +13 -7
  131. package/dist-lib/lib/core/mesh.js +55 -47
  132. package/dist-lib/lib/core/migrations/file-index.js +2 -4
  133. package/dist-lib/lib/core/next-frame.js +2 -1
  134. package/dist-lib/lib/core/pdf/rasterize.d.ts +2 -1
  135. package/dist-lib/lib/core/pdf/rasterize.js +5 -5
  136. package/dist-lib/lib/core/peer-duplex.d.ts +3 -3
  137. package/dist-lib/lib/core/peer-duplex.js +4 -4
  138. package/dist-lib/lib/core/secret-handoff.d.ts +2 -2
  139. package/dist-lib/lib/core/secret-handoff.js +7 -4
  140. package/dist-lib/lib/core/send.js +3 -2
  141. package/dist-lib/lib/core/skill-overlay-handoff.d.ts +2 -2
  142. package/dist-lib/lib/core/skill-overlay-handoff.js +6 -5
  143. package/dist-lib/lib/core/skill-overlay-receiver.js +5 -5
  144. package/dist-lib/lib/core/skill-secrets.d.ts +0 -5
  145. package/dist-lib/lib/core/skill-secrets.js +5 -9
  146. package/dist-lib/lib/core/sync/changed.d.ts +20 -0
  147. package/dist-lib/lib/core/sync/changed.js +7 -0
  148. package/dist-lib/lib/core/sync/devices.js +1 -1
  149. package/dist-lib/lib/core/sync/files.d.ts +1 -0
  150. package/dist-lib/lib/core/sync/files.js +50 -72
  151. package/dist-lib/lib/core/sync/index.d.ts +1 -2
  152. package/dist-lib/lib/core/sync/index.js +40 -62
  153. package/dist-lib/lib/core/sync/view-updates.d.ts +33 -0
  154. package/dist-lib/lib/core/sync/view-updates.js +133 -0
  155. package/dist-lib/lib/core/system-info.d.ts +2 -2
  156. package/dist-lib/lib/core/system-info.js +10 -11
  157. package/dist-lib/lib/core/tool-configs.js +6 -6
  158. package/dist-lib/lib/core.d.ts +1 -7
  159. package/dist-lib/lib/core.js +147 -131
  160. package/dist-lib/lib/custom-model-pusher.d.ts +2 -4
  161. package/dist-lib/lib/custom-model-task.d.ts +2 -1
  162. package/dist-lib/lib/custom-model-task.js +2 -2
  163. package/dist-lib/lib/downloads-allowed-pusher.d.ts +2 -4
  164. package/dist-lib/lib/errors.d.ts +603 -0
  165. package/dist-lib/lib/errors.js +552 -0
  166. package/dist-lib/lib/log.d.ts +7 -6
  167. package/dist-lib/lib/log.js +10 -6
  168. package/dist-lib/lib/logger-type.d.ts +2 -5
  169. package/dist-lib/lib/model-download-status.d.ts +2 -2
  170. package/dist-lib/lib/model-download.d.ts +2 -2
  171. package/dist-lib/lib/model-download.js +3 -2
  172. package/dist-lib/lib/model-idle-pusher.d.ts +2 -4
  173. package/dist-lib/lib/model-memory-cap.d.ts +2 -4
  174. package/dist-lib/lib/oauth/browser-connect.js +3 -2
  175. package/dist-lib/lib/oauth/flow-core.js +3 -3
  176. package/dist-lib/lib/oauth/loopback.js +10 -9
  177. package/dist-lib/lib/oauth/providers.js +4 -2
  178. package/dist-lib/lib/oauth/register.js +3 -2
  179. package/dist-lib/lib/oauth/token-exchange-core.js +5 -4
  180. package/dist-lib/lib/run-notices.d.ts +2 -0
  181. package/dist-lib/lib/run-notices.js +7 -2
  182. package/dist-lib/lib/run-transcript.d.ts +2 -2
  183. package/dist-lib/lib/task.js +2 -1
  184. package/dist-lib/schema/engine.js +6 -3
  185. package/dist-lib/schema/field-order.js +1 -3
  186. package/dist-lib/schema/local.js +11 -0
  187. package/dist-lib/spec/hrpc/messages.js +20 -9
  188. package/dist-lib/spec/hyperschema/index.js +20 -9
  189. package/dist-lib/spec/hyperschema/schema.json +15 -0
  190. package/dist-lib/spec/hyperschema/types.d.ts +3 -0
  191. package/dist-lib/spec/local/hyperdb/db.json +16 -1
  192. package/dist-lib/spec/local/hyperdb/index.js +71 -2
  193. package/dist-lib/spec/local/hyperdb/messages.js +300 -143
  194. package/dist-lib/spec/local/hyperschema/index.js +82 -2
  195. package/dist-lib/spec/local/hyperschema/schema.json +43 -1
  196. package/dist-lib/spec/local/hyperschema/types.d.ts +12 -1
  197. package/package.json +10 -3
  198. package/tui/app.mjs +1 -1
  199. package/worker/assistant-sidecar.mjs +7 -0
  200. package/dist-lib/lib/log-levels.d.ts +0 -7
  201. package/dist-lib/lib/log-levels.js +0 -1
  202. package/dist-lib/lib/logger.d.ts +0 -5
  203. package/dist-lib/lib/logger.js +0 -18
@@ -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 { AssistantCapabilityProfile, AssistantClearModelDownloadRequest, AssistantDeleteModelRequest, AssistantDeleteModelResponse, AssistantCompactChatResponse, AssistantKvCacheDeletionResponse, AssistantListModelsRequest, AssistantLoadModelRequest, AssistantLoadModelResponse, AssistantModelCatalogRevision, AssistantCopySkillResponse, AssistantDeleteSkillResponse, AssistantManagedSkillsResponse, AssistantModelInfoList, AssistantOkResponse, AssistantPushSkillSecretRequest, AssistantSkillCatalogResponse, AssistantSkillFileResponse, AssistantSpeakRequest, AssistantSpeakResponse, AssistantToolCatalogResponse, AssistantDetectLanguageRequest, AssistantDetectLanguageResponse, AssistantTranscribeRequest, AssistantTranscribeResponse, AssistantUnloadModelRequest, AssistantUnloadModelResponse, AssistantModelUsers, AssistantModelUsersRequest } from '../../spec/hyperschema/types.d.ts';
3
4
  import type { openLocalStore } from '../core/local/index.ts';
@@ -21,6 +22,7 @@ interface ApiDeps {
21
22
  inferenceCalls?: InferenceCallReader | null;
22
23
  chatMoves?: ChatMoves | null;
23
24
  logs?: LogSource | null;
25
+ log?: LoggerInterface | null;
24
26
  deviceId?: Buffer | null;
25
27
  lifecycle?: {
26
28
  suspend(): Promise<void>;
@@ -36,34 +36,47 @@ export function createApi(deps = {}) {
36
36
  const mesh = deps.mesh ?? null;
37
37
  const { retryModelDownload, lifecycle, deleteChatKvCache, compactChat, pushSkillSecret, speakStream, skills, skillCatalog, listManagedSkills, readSkillFile, writeSkillFile, copySkillForEdit, deleteOverlaySkill } = deps;
38
38
  const state = deps.state ?? null;
39
- const members = mesh && deps.meshStatus ? createMembersApi(mesh, deps.meshStatus, state) : null;
40
- return instrument({
41
- ...(state ? createConfigApi(state) : null),
42
- ...(state ? createAppConfigApi(state) : null),
43
- ...(state ? createModelDownloadApi(state) : null),
39
+ const log = deps.log ?? null;
40
+ const members = mesh && deps.meshStatus ? createMembersApi(mesh, deps.meshStatus, { state, log }) : null;
41
+ const handlers = {
42
+ ...(state ? createConfigApi(state, log) : null),
43
+ ...(state ? createAppConfigApi(state, log) : null),
44
+ ...(state ? createModelDownloadApi(state, log) : null),
44
45
  ...(state
45
- ? createCustomModelApi(state, deps.previewModelSource ?? null, deps.deleteModel ?? null)
46
+ ? createCustomModelApi(state, {
47
+ preview: deps.previewModelSource ?? null,
48
+ deleteFiles: deps.deleteModel ?? null,
49
+ log
50
+ })
51
+ : null),
52
+ ...(mesh
53
+ ? createAgentsApi(mesh, {
54
+ deviceId: deps.deviceId ?? null,
55
+ computeLender: deps.computeLender ?? null,
56
+ log
57
+ })
46
58
  : null),
47
- ...(mesh ? createAgentsApi(mesh, deps.deviceId ?? null, deps.computeLender ?? null) : null),
48
59
  ...(mesh && state
49
60
  ? createChatApi(mesh, state, {
50
61
  deviceId: deps.deviceId ?? null,
51
- inferenceCalls: deps.inferenceCalls ?? null
62
+ inferenceCalls: deps.inferenceCalls ?? null,
63
+ log
52
64
  })
53
65
  : null),
54
- ...(deps.chatMoves ? createChatMoveApi(deps.chatMoves) : null),
66
+ ...(deps.chatMoves ? createChatMoveApi(deps.chatMoves, log) : null),
55
67
  ...(mesh ? createChatGroupsApi(mesh) : null),
56
68
  ...(mesh ? createApprovalRulesApi(mesh) : null),
57
- ...(mesh ? createChunksApi(mesh, deps.deviceId ?? null) : null),
69
+ ...(mesh ? createChunksApi(mesh, deps.deviceId ?? null, log) : null),
58
70
  ...(mesh && deps.deviceId && deps.deviceHost
59
71
  ? createDevicesApi(mesh, {
60
72
  ...deps.deviceHost,
61
73
  deviceId: deps.deviceId,
62
- computeLender: deps.computeLender ?? null
74
+ computeLender: deps.computeLender ?? null,
75
+ log
63
76
  })
64
77
  : null),
65
78
  ...(mesh ? createAttachmentsApi(mesh, { deviceId: deps.deviceId }) : null),
66
- ...(mesh ? createKnowledgeApi(mesh, { deviceId: deps.deviceId }) : null),
79
+ ...(mesh ? createKnowledgeApi(mesh, { deviceId: deps.deviceId, log }) : null),
67
80
  ...(mesh ? createFilesApi(mesh) : null),
68
81
  ...(state ? createLocalFilesApi(state.files) : null),
69
82
  ...(mesh
@@ -80,15 +93,19 @@ export function createApi(deps = {}) {
80
93
  })
81
94
  : null),
82
95
  ...(mesh && deps.deviceId ? createExecutionApi(mesh, deps.deviceId) : null),
83
- ...(mesh ? createSyncApi(mesh) : null),
84
- ...(mesh ? createToolConfigsApi(mesh) : null),
85
- ...(mesh ? createToolActivityApi(mesh, deps.deviceId ?? null) : null),
86
- ...(mesh && state ? createNotificationsApi(mesh, state, { deviceId: deps.deviceId }) : null),
96
+ ...(mesh ? createSyncApi(mesh, log) : null),
97
+ ...(mesh ? createToolConfigsApi(mesh, log) : null),
98
+ ...(mesh ? createToolActivityApi(mesh, deps.deviceId ?? null, log) : null),
99
+ ...(mesh && state
100
+ ? createNotificationsApi(mesh, state, { deviceId: deps.deviceId, log })
101
+ : null),
87
102
  ...members,
88
- ...(deps.meshStatus && members ? createMeshApi(deps.meshStatus, members.updateMember) : null),
89
- ...(deps.network ? createNetworkApi(deps.network) : null),
90
- ...(deps.blindPeering ? createBlindPeeringApi(deps.blindPeering) : null),
91
- ...(deps.diagnostics ? createDiagnosticsApi(deps.diagnostics) : null),
103
+ ...(deps.meshStatus && members
104
+ ? createMeshApi(deps.meshStatus, members.updateMember, log)
105
+ : null),
106
+ ...(deps.network ? createNetworkApi(deps.network, log) : null),
107
+ ...(deps.blindPeering ? createBlindPeeringApi(deps.blindPeering, log) : null),
108
+ ...(deps.diagnostics ? createDiagnosticsApi(deps.diagnostics, log) : null),
92
109
  ...(deps.inferenceCalls ? createInferenceCallsApi(deps.inferenceCalls) : null),
93
110
  ...(deps.logs ? createLogsApi(deps.logs) : null),
94
111
  suspend: lifecycle
@@ -172,7 +189,8 @@ export function createApi(deps = {}) {
172
189
  ? async (req) => deleteOverlaySkill(req?.name, req?.agentId)
173
190
  : undefined,
174
191
  tools: deps.tools ?? undefined
175
- });
192
+ };
193
+ return instrument(handlers, log);
176
194
  }
177
195
  async function transcodeImage(request) {
178
196
  const normalized = await normalizeImageForModel(request.bytes);
@@ -1,2 +1,2 @@
1
- import '../logger.ts';
2
- export declare function instrument<T extends object>(handlers: T): T;
1
+ import type { LoggerInterface } from '@qvac/logging';
2
+ export declare function instrument<T extends object>(handlers: T, log: LoggerInterface | null): T;
@@ -1,13 +1,12 @@
1
1
  import b4a from 'b4a';
2
- import '../logger.js';
3
2
  import { errorMessage, isRecord } from '../guards.js';
4
3
  const SCOPE = ['api'];
5
4
  const MAX_STRING = 40;
6
- export function instrument(handlers) {
5
+ export function instrument(handlers, log) {
7
6
  const out = { ...handlers };
8
7
  for (const [name, handler] of Object.entries(out)) {
9
8
  if (isHandler(handler)) {
10
- Object.assign(out, { [name]: wrap(name, handler) });
9
+ Object.assign(out, { [name]: wrap(name, handler, log) });
11
10
  }
12
11
  }
13
12
  return out;
@@ -15,7 +14,7 @@ export function instrument(handlers) {
15
14
  function isHandler(value) {
16
15
  return typeof value === 'function';
17
16
  }
18
- function wrap(name, handler) {
17
+ function wrap(name, handler, log) {
19
18
  return function (...args) {
20
19
  const started = Date.now();
21
20
  const request = summarize(args[0]);
@@ -24,28 +23,28 @@ function wrap(name, handler) {
24
23
  result = handler.apply(this, args);
25
24
  }
26
25
  catch (err) {
27
- logFailure(name, { request, started, err });
26
+ logFailure(log, name, { request, started, err });
28
27
  throw err;
29
28
  }
30
29
  if (isStream(result)) {
31
- logger.debug(SCOPE, `${name} opened`, { request });
30
+ log?.debug(SCOPE, `${name} opened`, { request });
32
31
  return result;
33
32
  }
34
33
  if (isPromise(result)) {
35
34
  return result.then((value) => {
36
- logger.debug(SCOPE, name, { request, ms: Date.now() - started, ...count(value) });
35
+ log?.debug(SCOPE, name, { request, ms: Date.now() - started, ...count(value) });
37
36
  return value;
38
37
  }, (err) => {
39
- logFailure(name, { request, started, err });
38
+ logFailure(log, name, { request, started, err });
40
39
  throw err;
41
40
  });
42
41
  }
43
- logger.debug(SCOPE, name, { request, ms: Date.now() - started, ...count(result) });
42
+ log?.debug(SCOPE, name, { request, ms: Date.now() - started, ...count(result) });
44
43
  return result;
45
44
  };
46
45
  }
47
- function logFailure(name, { request, started, err }) {
48
- logger.debug(SCOPE, `${name} failed`, {
46
+ function logFailure(log, name, { request, started, err }) {
47
+ log?.debug(SCOPE, `${name} failed`, {
49
48
  request,
50
49
  ms: Date.now() - started,
51
50
  err: errorMessage(err)
@@ -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 MeshPool } from './current-mesh.ts';
3
4
  export { MAX_KNOWLEDGE_BYTES } from '../core/files/knowledge.ts';
@@ -5,5 +6,6 @@ export interface CreateKnowledgeApiOptions {
5
6
  readonly maxBytes?: number;
6
7
  readonly inactivityMs?: number;
7
8
  readonly deviceId?: Buffer | null;
9
+ readonly log: LoggerInterface | null;
8
10
  }
9
- export declare function createKnowledgeApi(pool: MeshPool, options?: CreateKnowledgeApiOptions): Pick<CapabilityHandlers, 'uploadKnowledge' | 'downloadKnowledge' | 'removeKnowledge' | 'listKnowledge' | 'knowledgeWatch' | 'listIndexing' | 'indexingWatch' | 'fileStatusWatch' | 'indexingProgressWatch'>;
11
+ export declare function createKnowledgeApi(pool: MeshPool, options: CreateKnowledgeApiOptions): Pick<CapabilityHandlers, 'uploadKnowledge' | 'downloadKnowledge' | 'removeKnowledge' | 'listKnowledge' | 'knowledgeWatch' | 'listIndexing' | 'indexingWatch' | 'fileStatusWatch' | 'indexingProgressWatch'>;
@@ -1,8 +1,10 @@
1
1
  import { meshWatchable, requireMesh } from './current-mesh.js';
2
2
  import { watchable } from './watchable.js';
3
- import { openUpload, UPLOAD_NAMES_NO_MESH } from './upload-frames.js';
3
+ import { CoreError } from '../errors.js';
4
+ import { openUpload } from './upload-frames.js';
4
5
  export { MAX_KNOWLEDGE_BYTES } from '../core/files/knowledge.js';
5
- export function createKnowledgeApi(pool, options = {}) {
6
+ export function createKnowledgeApi(pool, options) {
7
+ const { log } = options;
6
8
  return {
7
9
  async *uploadKnowledge(frames) {
8
10
  const upload = await openUpload(frames);
@@ -10,7 +12,7 @@ export function createKnowledgeApi(pool, options = {}) {
10
12
  return;
11
13
  }
12
14
  if (!upload.first.meshId) {
13
- throw new Error(UPLOAD_NAMES_NO_MESH);
15
+ throw new CoreError('UPLOAD_MESH_MISSING');
14
16
  }
15
17
  const mesh = await requireMesh(pool, upload.first.meshId);
16
18
  yield* mesh.files.knowledge(options).uploadKnowledge(upload.rest);
@@ -35,9 +37,9 @@ export function createKnowledgeApi(pool, options = {}) {
35
37
  .knowledge(options)
36
38
  .listIndexing(request);
37
39
  },
38
- knowledgeWatch: meshWatchable(pool, async (request, mesh) => mesh.files.knowledge(options).listKnowledge(request), { name: 'knowledgeWatch' }),
39
- indexingWatch: watchable(async (request) => (await requireMesh(pool, request.meshId)).files, ({ chatId }, files) => files.listIndexing(chatId), { name: 'indexingWatch' }),
40
- fileStatusWatch: watchable(async (request) => (await requireMesh(pool, request.meshId)).files, ({ chatId }, files) => files.status(chatId), { name: 'fileStatusWatch' }),
41
- indexingProgressWatch: watchable(async (request) => (await requireMesh(pool, request.meshId)).files, ({ chatId }, files) => Promise.resolve({ entries: files.progress(chatId) }), { name: 'indexingProgressWatch' })
40
+ knowledgeWatch: meshWatchable(pool, async (request, mesh) => mesh.files.knowledge(options).listKnowledge(request), { name: 'knowledgeWatch', log }),
41
+ indexingWatch: watchable(async (request) => (await requireMesh(pool, request.meshId)).files, ({ chatId }, files) => files.listIndexing(chatId), { name: 'indexingWatch', log }),
42
+ fileStatusWatch: watchable(async (request) => (await requireMesh(pool, request.meshId)).files, ({ chatId }, files) => files.status(chatId), { name: 'fileStatusWatch', log }),
43
+ indexingProgressWatch: watchable(async (request) => (await requireMesh(pool, request.meshId)).files, ({ chatId }, files) => Promise.resolve({ entries: files.progress(chatId) }), { name: 'indexingProgressWatch', log })
42
44
  };
43
45
  }
@@ -1,6 +1,6 @@
1
1
  import { Readable } from 'streamx';
2
2
  import { frameReadable } from '../frame-readable.js';
3
- import { LEVELS } from '../log-levels.js';
3
+ import { LEVEL_PRIORITIES } from '@qvac/logging/constants';
4
4
  import { asError } from '../guards.js';
5
5
  const MAX_LIVE_QUEUE = 1000;
6
6
  export function createLogsApi(source) {
@@ -85,11 +85,11 @@ function logStream(source, request) {
85
85
  return frameReadable(stream);
86
86
  }
87
87
  function makeFilter(request) {
88
- const minLevel = request.level ? LEVELS[request.level] : 0;
88
+ const threshold = LEVEL_PRIORITIES[request.level ?? 'debug'];
89
89
  const scope = request.scope ?? [];
90
90
  const origin = request.origin ?? null;
91
91
  return (record) => {
92
- if (LEVELS[record.level] < minLevel)
92
+ if (LEVEL_PRIORITIES[record.level] > threshold)
93
93
  return false;
94
94
  if (origin && record.origin !== origin)
95
95
  return false;
@@ -1,3 +1,4 @@
1
+ import type { LoggerInterface } from '@qvac/logging';
1
2
  import type { AssistantAccount } from '../../spec/hyperschema/types.d.ts';
2
3
  import type { openLocalStore } from '../core/local/index.ts';
3
4
  import { type MeshPool } from './current-mesh.ts';
@@ -6,5 +7,9 @@ type LocalStore = Awaited<ReturnType<typeof openLocalStore>>;
6
7
  export interface OwnMember {
7
8
  account(): Promise<AssistantAccount>;
8
9
  }
9
- export declare function createMembersApi(pool: MeshPool, self: OwnMember, state?: LocalStore | null): Pick<CapabilityHandlers, 'listMembers' | 'membersWatch' | 'updateMember' | 'removeMember'>;
10
+ export interface CreateMembersApiOptions {
11
+ readonly state: LocalStore | null;
12
+ readonly log: LoggerInterface | null;
13
+ }
14
+ export declare function createMembersApi(pool: MeshPool, self: OwnMember, { state, log }: CreateMembersApiOptions): Pick<CapabilityHandlers, 'listMembers' | 'membersWatch' | 'updateMember' | 'removeMember'>;
10
15
  export {};
@@ -1,14 +1,15 @@
1
1
  import { meshWatchable, requireMesh } from './current-mesh.js';
2
2
  import b4a from 'b4a';
3
3
  import { DEVICES, MEMBERS } from '../core/collections.js';
4
+ import { CoreError } from '../errors.js';
4
5
  const RESOLVE_MEMBER_MS = 10_000;
5
6
  async function resolveOurMember(mesh) {
6
7
  let timer = null;
7
8
  try {
8
9
  await Promise.race([
9
- mesh.refreshOurMember(),
10
+ mesh.autobee.update().then(() => mesh.refreshOurMember()),
10
11
  new Promise((_, reject) => {
11
- timer = setTimeout(() => reject(new Error('resolving our member in this mesh timed out')), RESOLVE_MEMBER_MS);
12
+ timer = setTimeout(() => reject(new CoreError('MEMBER_RESOLVE_TIMEOUT')), RESOLVE_MEMBER_MS);
12
13
  })
13
14
  ]);
14
15
  }
@@ -31,11 +32,11 @@ async function liveMemberIds(snap) {
31
32
  }
32
33
  return live;
33
34
  }
34
- export function createMembersApi(pool, self, state = null) {
35
+ export function createMembersApi(pool, self, { state, log }) {
35
36
  const mustGetMember = async (reader, id) => {
36
37
  const member = await reader.get(MEMBERS, { id });
37
38
  if (!member) {
38
- throw new Error(`member not found: ${b4a.toHex(id)}`);
39
+ throw new CoreError('MEMBER_NOT_FOUND', [b4a.toHex(id)]);
39
40
  }
40
41
  return member;
41
42
  };
@@ -64,15 +65,15 @@ export function createMembersApi(pool, self, state = null) {
64
65
  };
65
66
  return {
66
67
  listMembers: async (request) => list(await requireMesh(pool, request.meshId)),
67
- membersWatch: meshWatchable(pool, (_request, mesh) => list(mesh), { name: 'membersWatch' }),
68
+ membersWatch: meshWatchable(pool, (_request, mesh) => list(mesh), { name: 'membersWatch', log }),
68
69
  updateMember: async ({ config }) => {
69
70
  const trimmed = config.name.trim();
70
71
  if (!trimmed) {
71
- throw new Error('member name must not be empty');
72
+ throw new CoreError('MEMBER_NAME_EMPTY');
72
73
  }
73
74
  const { meshId } = await self.account();
74
75
  if (!meshId) {
75
- throw new Error('no account to rename the member in');
76
+ throw new CoreError('MEMBER_RENAME_NO_ACCOUNT');
76
77
  }
77
78
  const mesh = await requireMesh(pool, meshId);
78
79
  if (!mesh.ourMemberId) {
@@ -80,7 +81,7 @@ export function createMembersApi(pool, self, state = null) {
80
81
  }
81
82
  const id = mesh.ourMemberId;
82
83
  if (!id) {
83
- throw new Error('this device is in no member of its account');
84
+ throw new CoreError('OWN_MEMBER_UNKNOWN', ['its account']);
84
85
  }
85
86
  const member = await mustGetMember(mesh.view, id);
86
87
  const namedAt = Math.max(Date.now(), member.updatedAt + 1);
@@ -96,10 +97,10 @@ export function createMembersApi(pool, self, state = null) {
96
97
  await resolveOurMember(mesh);
97
98
  }
98
99
  if (!mesh.ourMemberId) {
99
- throw new Error('this device is in no member of this mesh');
100
+ throw new CoreError('OWN_MEMBER_UNKNOWN', ['this mesh']);
100
101
  }
101
102
  if (b4a.equals(mesh.ourMemberId, id)) {
102
- throw new Error('cannot remove own member, use leaveMesh');
103
+ throw new CoreError('MEMBER_REMOVE_SELF');
103
104
  }
104
105
  await mesh.dispatch('remove-member', { memberId: id, revokedAt: Date.now() });
105
106
  return { ok: true };
@@ -1,6 +1,6 @@
1
+ import type { LoggerInterface } from '@qvac/logging';
1
2
  import type { AssistantAccount, AssistantArchivedMeshContents, AssistantArchivedMeshList, AssistantArchivedMeshMigration, AssistantMeshList, AssistantMeshStatus } from '../../spec/hyperschema/types.d.ts';
2
3
  import type { CapabilityHandlers } from '../../spec/capabilities.d.ts';
3
- export declare const CREATE_ROOM_RETIRED = "createRoom is retired: call createMesh with the same input";
4
4
  export interface MeshInviteResult {
5
5
  readonly invite?: string;
6
6
  readonly meshId?: string;
@@ -36,4 +36,4 @@ export interface MeshStatusSource {
36
36
  recover(phrase: string, timeout?: number): Promise<void>;
37
37
  displayName(): Promise<string | null>;
38
38
  }
39
- export declare function createMeshApi(status: MeshStatusSource, updateMember: CapabilityHandlers['updateMember']): Pick<CapabilityHandlers, 'meshStatusWatch' | 'listMeshes' | 'meshesWatch' | 'account' | 'accountWatch' | 'openMesh' | 'closeMesh' | 'leaveMesh' | 'acknowledgeKicked' | 'joinMesh' | 'cancelMeshJoin' | 'meshInvite' | 'previewMeshInvite' | 'setMeshLabel' | 'setMeshName' | 'createMesh' | 'createRoom' | 'listArchivedMeshes' | 'archivedMeshContents' | 'migrateArchivedMesh' | 'accountRecoverable' | 'recoveryPublish' | 'recoverAccount' | 'displayName' | 'setDisplayName'>;
39
+ export declare function createMeshApi(status: MeshStatusSource, updateMember: CapabilityHandlers['updateMember'], log: LoggerInterface | null): Pick<CapabilityHandlers, 'meshStatusWatch' | 'listMeshes' | 'meshesWatch' | 'account' | 'accountWatch' | 'openMesh' | 'closeMesh' | 'leaveMesh' | 'acknowledgeKicked' | 'joinMesh' | 'cancelMeshJoin' | 'meshInvite' | 'previewMeshInvite' | 'setMeshLabel' | 'setMeshName' | 'createMesh' | 'createRoom' | 'listArchivedMeshes' | 'archivedMeshContents' | 'migrateArchivedMesh' | 'accountRecoverable' | 'recoveryPublish' | 'recoverAccount' | 'displayName' | 'setDisplayName'>;
@@ -1,12 +1,12 @@
1
1
  import { watchable } from './watchable.js';
2
- export const CREATE_ROOM_RETIRED = 'createRoom is retired: call createMesh with the same input';
3
- export function createMeshApi(status, updateMember) {
2
+ import { CoreError } from '../errors.js';
3
+ export function createMeshApi(status, updateMember, log) {
4
4
  return {
5
- meshStatusWatch: watchable(() => status, async () => status.snapshot(), { name: 'meshStatusWatch' }),
5
+ meshStatusWatch: watchable(() => status, async () => status.snapshot(), { name: 'meshStatusWatch', log }),
6
6
  listMeshes: () => status.list(),
7
- meshesWatch: watchable(() => status, () => status.list(), { name: 'meshesWatch' }),
7
+ meshesWatch: watchable(() => status, () => status.list(), { name: 'meshesWatch', log }),
8
8
  account: () => status.account(),
9
- accountWatch: watchable(() => status, () => status.account(), { name: 'accountWatch' }),
9
+ accountWatch: watchable(() => status, () => status.account(), { name: 'accountWatch', log }),
10
10
  openMesh: async ({ meshId }) => {
11
11
  await status.open(meshId);
12
12
  return { ok: true };
@@ -45,7 +45,7 @@ export function createMeshApi(status, updateMember) {
45
45
  meshId: await status.createMesh({ compute: request?.config?.compute })
46
46
  }),
47
47
  createRoom: async () => {
48
- throw new Error(CREATE_ROOM_RETIRED);
48
+ throw new CoreError('ROUTE_RETIRED', ['createRoom', 'createMesh']);
49
49
  },
50
50
  listArchivedMeshes: () => status.listArchived(),
51
51
  archivedMeshContents: ({ meshId }) => status.archivedContents(meshId),
@@ -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 createModelDownloadApi(state: LocalStore): Pick<CapabilityHandlers, 'modelDownloadsWatch' | 'setModelDownloadStatus' | 'clearModelDownload' | 'beginModelTransfer' | 'completeModelTransfer'>;
5
+ export declare function createModelDownloadApi(state: LocalStore, log: LoggerInterface | null): Pick<CapabilityHandlers, 'modelDownloadsWatch' | 'setModelDownloadStatus' | 'clearModelDownload' | 'beginModelTransfer' | 'completeModelTransfer'>;
5
6
  export {};
@@ -14,7 +14,7 @@ async function readDownloads(state) {
14
14
  }))
15
15
  };
16
16
  }
17
- export function createModelDownloadApi(state) {
17
+ export function createModelDownloadApi(state, log) {
18
18
  return {
19
19
  beginModelTransfer: async ({ name, transferred }) => {
20
20
  const { transferId } = await state.beginModelTransfer(name, { transferred });
@@ -24,7 +24,7 @@ export function createModelDownloadApi(state) {
24
24
  await state.completeModelTransfer(request);
25
25
  return { ok: true };
26
26
  },
27
- modelDownloadsWatch: watchable(() => state, () => readDownloads(state), { name: 'modelDownloadsWatch' }),
27
+ modelDownloadsWatch: watchable(() => state, () => readDownloads(state), { name: 'modelDownloadsWatch', log }),
28
28
  setModelDownloadStatus: async (input) => {
29
29
  const row = {
30
30
  name: input.name,
@@ -1,3 +1,4 @@
1
+ import type { LoggerInterface } from '@qvac/logging';
1
2
  import type { AssistantBlindPeering, AssistantNetworkStatus } from '../../spec/hyperschema/types.d.ts';
2
3
  import type { CapabilityHandlers } from '../../spec/capabilities.d.ts';
3
4
  export interface NetworkSource {
@@ -12,5 +13,5 @@ export interface BlindPeeringSource {
12
13
  snapshot(): AssistantBlindPeering;
13
14
  set(enabled: boolean): Promise<AssistantBlindPeering>;
14
15
  }
15
- export declare function createNetworkApi(source: NetworkSource): Pick<CapabilityHandlers, 'networkWatch'>;
16
- export declare function createBlindPeeringApi(source: BlindPeeringSource): Pick<CapabilityHandlers, 'setBlindPeering' | 'blindPeeringWatch'>;
16
+ export declare function createNetworkApi(source: NetworkSource, log: LoggerInterface | null): Pick<CapabilityHandlers, 'networkWatch'>;
17
+ export declare function createBlindPeeringApi(source: BlindPeeringSource, log: LoggerInterface | null): Pick<CapabilityHandlers, 'setBlindPeering' | 'blindPeeringWatch'>;
@@ -1,12 +1,12 @@
1
1
  import { watchable } from './watchable.js';
2
- export function createNetworkApi(source) {
2
+ export function createNetworkApi(source, log) {
3
3
  return {
4
- networkWatch: watchable(() => source, async () => source.snapshot(), { name: 'networkWatch' })
4
+ networkWatch: watchable(() => source, async () => source.snapshot(), { name: 'networkWatch', log })
5
5
  };
6
6
  }
7
- export function createBlindPeeringApi(source) {
7
+ export function createBlindPeeringApi(source, log) {
8
8
  return {
9
9
  setBlindPeering: ({ enabled }) => source.set(enabled === true),
10
- blindPeeringWatch: watchable(() => source, async () => source.snapshot(), { name: 'blindPeeringWatch' })
10
+ blindPeeringWatch: watchable(() => source, async () => source.snapshot(), { name: 'blindPeeringWatch', log })
11
11
  };
12
12
  }
@@ -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';
@@ -5,6 +6,7 @@ type LocalStore = Awaited<ReturnType<typeof openLocalStore>>;
5
6
  type NotificationCapabilities = Pick<CapabilityHandlers, 'notificationsWatch' | 'ackNotification'>;
6
7
  interface NotificationOptions {
7
8
  readonly deviceId?: Buffer | null;
9
+ readonly log: LoggerInterface | null;
8
10
  }
9
- export declare function createNotificationsApi(pool: MeshPool, local: LocalStore, options?: NotificationOptions): NotificationCapabilities;
11
+ export declare function createNotificationsApi(pool: MeshPool, local: LocalStore, options: NotificationOptions): NotificationCapabilities;
10
12
  export {};
@@ -1,22 +1,23 @@
1
+ import { CoreError } from '../errors.js';
1
2
  import { deriveNotifications } from '../core/notification.js';
2
3
  import { requireMesh } from './current-mesh.js';
3
4
  import { watchable } from './watchable.js';
4
- export function createNotificationsApi(pool, local, options = {}) {
5
+ export function createNotificationsApi(pool, local, options) {
5
6
  return {
6
7
  notificationsWatch: watchable(async (request) => notificationSource(await requireMesh(pool, request.meshId), local), (request, source) => notificationSnapshot(source.mesh, local, {
7
8
  limit: request.limit,
8
9
  deviceId: options.deviceId
9
- }), { name: 'notificationsWatch' }),
10
+ }), { name: 'notificationsWatch', log: options.log }),
10
11
  ackNotification: async ({ chatId, seq, notificationId, meshId }) => {
11
12
  if (notificationId) {
12
13
  if ((chatId !== undefined && chatId !== null) || (seq ?? 0) !== 0) {
13
- throw new Error('notification acknowledgement must select one source');
14
+ throw new CoreError('NOTIFICATION_ACK_AMBIGUOUS');
14
15
  }
15
16
  await local.ackModelNotification(notificationId);
16
17
  }
17
18
  else {
18
19
  if (!chatId || seq === undefined || seq === null) {
19
- throw new Error('chat acknowledgement requires chatId and seq');
20
+ throw new CoreError('NOTIFICATION_CHAT_ACK_INCOMPLETE');
20
21
  }
21
22
  await requireMesh(pool, meshId);
22
23
  await local.ackChatNotify(chatId, seq);
@@ -1,4 +1,3 @@
1
- import '../logger.ts';
2
1
  import type { CapabilityHandlers } from '../../spec/capabilities.d.ts';
3
2
  import type { QvacAgent } from '../../spec/mesh/hyperschema/types.d.ts';
4
3
  import { type IndexingEmbedder, type VectorIndex } from '../core/files/index.ts';
@@ -1,4 +1,3 @@
1
- import '../logger.js';
2
1
  import { toolsetEnabled } from '@qvac/harness/lib/tools/toolsets.ts';
3
2
  import { getAgent } from '../core/agent.js';
4
3
  import { getChat } from '../core/chat.js';
@@ -61,7 +60,7 @@ export function createRagApi(pool, { index, embedder, effectiveCtxSize = null })
61
60
  await mesh.files.settle(waiting.map((row) => row.id));
62
61
  }
63
62
  catch (err) {
64
- logger.warn('rag', 'indexing settle failed', { err });
63
+ mesh.log?.warn('rag', 'indexing settle failed', { err });
65
64
  }
66
65
  rows = await mesh.files.listKnowledge(chatId);
67
66
  scopeRows = rows.filter((row) => scopeIds.has(row.id));
@@ -150,7 +149,7 @@ export function createRagApi(pool, { index, embedder, effectiveCtxSize = null })
150
149
  }, {
151
150
  index: vectorIndex,
152
151
  embed: (texts) => embed.embed({ texts }),
153
- debug: (message) => logger.debug('rag', message)
152
+ debug: (message) => mesh.log?.debug('rag', message)
154
153
  });
155
154
  return respond({
156
155
  searchedCount: hits.length,
@@ -179,7 +178,7 @@ export function createRagApi(pool, { index, embedder, effectiveCtxSize = null })
179
178
  }, {
180
179
  index: vectorIndex,
181
180
  embed: (texts) => embed.embed({ texts }),
182
- debug: (message) => logger.debug('rag', message)
181
+ debug: (message) => mesh.log?.debug('rag', message)
183
182
  });
184
183
  return respond({
185
184
  searchedCount: result.searchedCount,
@@ -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 MeshPool } from './current-mesh.ts';
3
- export declare function createSyncApi(pool: MeshPool): Pick<CapabilityHandlers, 'syncStatusWatch'>;
4
+ export declare function createSyncApi(pool: MeshPool, log: LoggerInterface | null): Pick<CapabilityHandlers, 'syncStatusWatch'>;
@@ -1,7 +1,7 @@
1
1
  import { requireMesh } from './current-mesh.js';
2
2
  import { watchable } from './watchable.js';
3
- export function createSyncApi(pool) {
3
+ export function createSyncApi(pool, log) {
4
4
  return {
5
- syncStatusWatch: watchable(async (request) => (await requireMesh(pool, request.meshId)).syncActivity ?? null, (_request, activity) => activity.snapshot(), { name: 'syncStatusWatch' })
5
+ syncStatusWatch: watchable(async (request) => (await requireMesh(pool, request.meshId)).syncActivity ?? null, (_request, activity) => activity.snapshot(), { name: 'syncStatusWatch', log })
6
6
  };
7
7
  }
@@ -1,5 +1,6 @@
1
+ import type { LoggerInterface } from '@qvac/logging';
1
2
  import type { CapabilityHandlers } from '../../spec/capabilities.d.ts';
2
3
  import { type MeshPool } from './current-mesh.ts';
3
4
  type ToolActivityCapabilities = Pick<CapabilityHandlers, 'listToolActivity' | 'toolActivityWatch' | 'recordToolActivity'>;
4
- export declare function createToolActivityApi(pool: MeshPool, deviceId: Buffer | null): ToolActivityCapabilities;
5
+ export declare function createToolActivityApi(pool: MeshPool, deviceId: Buffer | null, log: LoggerInterface | null): ToolActivityCapabilities;
5
6
  export {};
@@ -1,6 +1,7 @@
1
1
  import { listToolActivity, recordToolActivity } from '../core/tool-activity.js';
2
2
  import { meshWatchable, requireMesh } from './current-mesh.js';
3
3
  import { bounds } from './range.js';
4
+ import { CoreError } from '../errors.js';
4
5
  import b4a from 'b4a';
5
6
  const DEFAULT_LIMIT = 200;
6
7
  const MAX_LIMIT = 1000;
@@ -27,7 +28,7 @@ function toEntry(row) {
27
28
  seq: row.seq ?? 0
28
29
  };
29
30
  }
30
- export function createToolActivityApi(pool, deviceId) {
31
+ export function createToolActivityApi(pool, deviceId, log) {
31
32
  const query = async ({ agentId, ...input }, mesh) => ({
32
33
  activities: (await listToolActivity(mesh, agentId, {
33
34
  ...bounds(input),
@@ -36,10 +37,10 @@ export function createToolActivityApi(pool, deviceId) {
36
37
  });
37
38
  return {
38
39
  listToolActivity: async (request) => query(request, await requireMesh(pool, request.meshId)),
39
- toolActivityWatch: meshWatchable(pool, query, { name: 'toolActivityWatch' }),
40
+ toolActivityWatch: meshWatchable(pool, query, { name: 'toolActivityWatch', log }),
40
41
  recordToolActivity: async (request) => {
41
42
  if (!deviceId) {
42
- throw new Error('cannot record tool activity without a device id');
43
+ throw new CoreError('DEVICE_ID_UNAVAILABLE');
43
44
  }
44
45
  return recordToolActivity(await requireMesh(pool, request.meshId), {
45
46
  agentId: request.agentId,
@@ -1,6 +1,7 @@
1
+ import type { LoggerInterface } from '@qvac/logging';
1
2
  import type { CapabilityHandlers } from '../../spec/capabilities.d.ts';
2
3
  import { getToolConfigs } from '../core/tool-configs.ts';
3
4
  import { type MeshPool } from './current-mesh.ts';
4
5
  type ToolConfigsCapabilities = Pick<CapabilityHandlers, 'setToolConfigs' | 'deleteToolConfigs' | 'listToolConfigs' | 'toolConfigsWatch'>;
5
- export declare function createToolConfigsApi(pool: MeshPool): ToolConfigsCapabilities;
6
+ export declare function createToolConfigsApi(pool: MeshPool, log: LoggerInterface | null): ToolConfigsCapabilities;
6
7
  export { getToolConfigs };
@@ -1,12 +1,13 @@
1
1
  import { deleteToolConfigs, getToolConfigs, listToolConfigs, setToolConfigs } from '../core/tool-configs.js';
2
2
  import { meshWatchable, requireMesh } from './current-mesh.js';
3
+ import { CoreError } from '../errors.js';
3
4
  import { isRecord } from '../guards.js';
4
5
  function ensureSettingsPayload(value) {
5
6
  if (!isRecord(value))
6
- throw new Error('tool configs must be a plain object');
7
+ throw new CoreError('TOOL_CONFIGS_INVALID');
7
8
  return value;
8
9
  }
9
- export function createToolConfigsApi(pool) {
10
+ export function createToolConfigsApi(pool, log) {
10
11
  const query = async ({ agentId }, mesh) => ({
11
12
  configs: await listToolConfigs(mesh, agentId)
12
13
  });
@@ -18,7 +19,7 @@ export function createToolConfigsApi(pool) {
18
19
  }),
19
20
  deleteToolConfigs: async ({ agentId, toolName, meshId }) => deleteToolConfigs(await requireMesh(pool, meshId), agentId, toolName),
20
21
  listToolConfigs: async (request) => query(request, await requireMesh(pool, request.meshId)),
21
- toolConfigsWatch: meshWatchable(pool, query, { name: 'toolConfigsWatch' })
22
+ toolConfigsWatch: meshWatchable(pool, query, { name: 'toolConfigsWatch', log })
22
23
  };
23
24
  }
24
25
  export { getToolConfigs };