@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,5 +1,4 @@
1
1
  import type { HandlerFrames } from '../../spec/capabilities.d.ts';
2
- export declare const UPLOAD_NAMES_NO_MESH = "an upload must name its mesh on its first frame";
3
2
  export type UploadFrames<Frame> = AsyncIterable<Frame> | HandlerFrames<Frame>;
4
3
  export interface OpenedUpload<Frame> {
5
4
  readonly first: Frame;
@@ -1,5 +1,4 @@
1
1
  import { toAsyncIterable } from '../core/async-iterable.js';
2
- export const UPLOAD_NAMES_NO_MESH = 'an upload must name its mesh on its first frame';
3
2
  export async function openUpload(frames) {
4
3
  const iterator = toAsyncIterable(frames)[Symbol.asyncIterator]();
5
4
  const first = await iterator.next();
@@ -1,5 +1,5 @@
1
1
  import { Readable } from 'streamx';
2
- import '../logger.ts';
2
+ import type { LoggerInterface } from '@qvac/logging';
3
3
  export declare function snapshotEquals(a: unknown, b: unknown): boolean;
4
4
  interface WatchableStore {
5
5
  watch(listener: () => void): void;
@@ -12,7 +12,8 @@ interface WatchableStore {
12
12
  }
13
13
  export interface WatchableOptions {
14
14
  readonly name: string;
15
+ readonly log: LoggerInterface | null;
15
16
  readonly changes?: WatchableStore;
16
17
  }
17
- export declare function watchable<TRequest, TResult, TStore extends WatchableStore = WatchableStore>(storeOf: (request: TRequest) => TStore | null | Promise<TStore | null>, query: (request: TRequest, store: TStore) => Promise<TResult>, { name, changes }: WatchableOptions): (request: TRequest) => Readable & AsyncIterable<TResult>;
18
+ export declare function watchable<TRequest, TResult, TStore extends WatchableStore = WatchableStore>(storeOf: (request: TRequest) => TStore | null | Promise<TStore | null>, query: (request: TRequest, store: TStore) => Promise<TResult>, { name, log, changes }: WatchableOptions): (request: TRequest) => Readable & AsyncIterable<TResult>;
18
19
  export {};
@@ -1,7 +1,6 @@
1
1
  import b4a from 'b4a';
2
2
  import { Readable } from 'streamx';
3
3
  import { frameReadable } from '../frame-readable.js';
4
- import '../logger.js';
5
4
  import { asError, isRecord } from '../guards.js';
6
5
  const SCOPE = ['api', 'watch'];
7
6
  const CHURN_WINDOW_MS = 30_000;
@@ -26,7 +25,7 @@ export function snapshotEquals(a, b) {
26
25
  }
27
26
  return keys.every((key) => snapshotEquals(a[key], b[key]));
28
27
  }
29
- export function watchable(storeOf, query, { name, changes }) {
28
+ export function watchable(storeOf, query, { name, log, changes }) {
30
29
  return (request) => {
31
30
  const resolved = storeOf(request);
32
31
  const pending = resolved instanceof Promise ? resolved.catch(noop) : null;
@@ -45,7 +44,7 @@ export function watchable(storeOf, query, { name, changes }) {
45
44
  if (!force && elapsed < CHURN_WINDOW_MS) {
46
45
  return;
47
46
  }
48
- logger.debug(SCOPE, `${name} woke with no change`, { woke: churn, ms: elapsed });
47
+ log?.debug(SCOPE, `${name} woke with no change`, { woke: churn, ms: elapsed });
49
48
  churn = 0;
50
49
  reportedAt = now;
51
50
  };
@@ -1,11 +1,9 @@
1
1
  import type { openLocalStore } from '../core/local/index.ts';
2
2
  import type { Harness } from './harness.ts';
3
+ import type { LoggerInterface } from '@qvac/logging';
3
4
  export declare const MAX_QUACKS = 500;
4
5
  type LocalStore = Awaited<ReturnType<typeof openLocalStore>>;
5
6
  export type FakeModelsSource = Pick<LocalStore, 'get' | 'watch' | 'unwatch'>;
6
- interface Logger {
7
- warn(...args: unknown[]): void;
8
- }
9
7
  export interface FakeModelsOptions {
10
8
  enabled?: () => boolean;
11
9
  paceMs?: number;
@@ -15,7 +13,7 @@ export declare function readFakeModels(state: Pick<FakeModelsSource, 'get'>): Pr
15
13
  export interface FakeModelsWatchOptions {
16
14
  initial: boolean;
17
15
  onChange: (enabled: boolean) => void;
18
- logger?: Logger | null;
16
+ logger?: LoggerInterface | null;
19
17
  }
20
18
  export declare function watchFakeModels(state: FakeModelsSource, opts: FakeModelsWatchOptions): () => Promise<void>;
21
19
  export declare function withFakeModels(harness: Harness, opts?: FakeModelsOptions): Harness;
@@ -3,6 +3,7 @@ import { RUN_FAILURE_REASONS } from '../run-notices.js';
3
3
  import { MODEL_TASK_TYPES } from '../../schema/engine.js';
4
4
  import { toEngineSkill } from './skill-encode.js';
5
5
  import { isRecord } from '../guards.js';
6
+ import { CoreError } from '../errors.js';
6
7
  export function isHarnessEvent(event, type) {
7
8
  return event.type === type;
8
9
  }
@@ -34,7 +35,7 @@ export const DELETE_CONTRACT_MATCHES = true;
34
35
  export function harnessPreviewModelSource(harness) {
35
36
  return async ({ src, mmprojSrc }) => {
36
37
  if (!harness.previewModelSource) {
37
- throw new Error('harness does not support previewModelSource');
38
+ throw new CoreError('CAPABILITY_UNSUPPORTED', ['previewModelSource']);
38
39
  }
39
40
  const preview = await harness.previewModelSource({ src, mmprojSrc: mmprojSrc ?? undefined });
40
41
  return {
@@ -47,7 +48,7 @@ export function harnessPreviewModelSource(harness) {
47
48
  export function harnessTranscribe(harness) {
48
49
  return async ({ audio, model }) => {
49
50
  if (!harness.transcribe) {
50
- throw new Error('harness does not support transcribe');
51
+ throw new CoreError('CAPABILITY_UNSUPPORTED', ['transcribe']);
51
52
  }
52
53
  return { text: await harness.transcribe({ audio, model: model ?? '' }) };
53
54
  };
@@ -55,7 +56,7 @@ export function harnessTranscribe(harness) {
55
56
  export function harnessDetectLanguage(harness) {
56
57
  return async ({ text, topK }) => {
57
58
  if (!harness.detectLanguage) {
58
- throw new Error('harness does not support detectLanguage');
59
+ throw new CoreError('CAPABILITY_UNSUPPORTED', ['detectLanguage']);
59
60
  }
60
61
  const languages = await harness.detectLanguage({ text, topK: topK || undefined });
61
62
  return {
@@ -69,8 +70,9 @@ export function harnessDetectLanguage(harness) {
69
70
  }
70
71
  export function harnessSpeak(harness) {
71
72
  return async ({ text, model }) => {
72
- if (!harness.speak)
73
- throw new Error('harness does not support speak');
73
+ if (!harness.speak) {
74
+ throw new CoreError('CAPABILITY_UNSUPPORTED', ['speak']);
75
+ }
74
76
  const { audio, sampleRate } = await harness.speak({ text, model: model ?? '' });
75
77
  return { audio, sampleRate };
76
78
  };
@@ -136,7 +138,7 @@ export function toolReportEntry(tool) {
136
138
  export function harnessSpeakStream(harness) {
137
139
  return async function* (text) {
138
140
  if (!harness.speakStream) {
139
- throw new Error('harness does not support speakStream');
141
+ throw new CoreError('CAPABILITY_UNSUPPORTED', ['speakStream']);
140
142
  }
141
143
  for await (const { audio, sampleRate } of harness.speakStream({ model: '', text })) {
142
144
  yield { audio, sampleRate };
@@ -1,7 +1,9 @@
1
1
  import type { Core } from './core.ts';
2
2
  import type { DeviceMetadata } from './core/mesh.ts';
3
+ import type { Logger } from './logger-type.ts';
3
4
  import { Client, type ClientOptions } from './client.ts';
4
5
  export interface AssistantClientOptions extends ClientOptions {
6
+ logger?: Logger | null;
5
7
  sidecar?: boolean;
6
8
  storagePath: string;
7
9
  device?: DeviceMetadata;
@@ -1,12 +1,13 @@
1
1
  import { Client } from './client.js';
2
2
  import { duplexPair } from '@qvac/harness/transport';
3
3
  import b4a from 'b4a';
4
+ import { CoreError } from './errors.js';
4
5
  export class AssistantClient extends Client {
5
6
  _inline;
6
7
  constructor({ sidecar: spawnSidecar = true, storagePath, device, meshSeed, meshKey, bootstrapNodes, entry, ...engineOptions }) {
7
8
  const inline = { core: null };
8
9
  if (spawnSidecar && !entry) {
9
- throw new Error('sidecar mode needs a stowed bundle entry');
10
+ throw new CoreError('SIDECAR_ENTRY_MISSING');
10
11
  }
11
12
  const sidecarEntry = spawnSidecar ? entry : undefined;
12
13
  const args = [
@@ -22,10 +23,10 @@ export class AssistantClient extends Client {
22
23
  ? async () => {
23
24
  const { default: sidecarRunner } = await import('bare-supervisor/runner/sidecar');
24
25
  const { ipc, exit } = sidecarRunner(sidecarEntry, args, engineOptions.logger ?? null);
25
- const died = exit.then((code) => `sidecar exited (${code}) before ready`);
26
+ const died = exit.then((code) => new CoreError('SIDECAR_EXITED', [code]));
26
27
  const failure = await Promise.race([ipc.ready.then(() => null), died]);
27
28
  if (failure) {
28
- throw new Error(failure);
29
+ throw failure;
29
30
  }
30
31
  return ipc;
31
32
  }
@@ -3,7 +3,7 @@ import { type Harness } from './assistant.ts';
3
3
  import { Client } from './client.ts';
4
4
  import type { Core } from './core.ts';
5
5
  import type { IndexingEmbedder, RagExtractors } from './core/files/index.ts';
6
- import type { Logger } from './log.ts';
6
+ import type { LoggerInterface } from '@qvac/logging';
7
7
  export interface HarnessContext {
8
8
  engine: Client;
9
9
  onDeath: (error?: Error) => void;
@@ -19,7 +19,7 @@ export type OnHarness = (harness: Harness, ctx: {
19
19
  export interface AssistantTreeOptions {
20
20
  core: Core;
21
21
  harness: HarnessFactory | ChildSpec<Harness>;
22
- logger?: Logger | null;
22
+ logger?: LoggerInterface | null;
23
23
  imageCacheDir?: string;
24
24
  inferenceCallsDir?: string;
25
25
  runReplayDir?: string;
@@ -36,7 +36,7 @@ export declare function assistantTree(opts: AssistantTreeOptions): Supervisor;
36
36
  export interface AssistantChildOptions {
37
37
  harness: HarnessFactory | ChildSpec<Harness>;
38
38
  core?: string;
39
- logger?: Logger | null;
39
+ logger?: LoggerInterface | null;
40
40
  imageCacheDir?: string;
41
41
  inferenceCallsDir?: string;
42
42
  runReplayDir?: string;
@@ -7,7 +7,7 @@ import { type PdfRasterizer } from './core/pdf/rasterize.ts';
7
7
  import type { DriveHost } from './core/fs-drives.ts';
8
8
  import { type DiagnosticsSlice } from './diagnostics.ts';
9
9
  import { type InferenceCallPage } from './inference-calls.ts';
10
- import type { Logger } from './log.ts';
10
+ import type { LoggerInterface } from '@qvac/logging';
11
11
  import { type DeleteModelSummary, type Harness, type ListModelsOptions, type ModelInfo, type ToolCatalogEntry } from './assistant/harness.ts';
12
12
  import type { Skill } from './assistant/skill-encode.ts';
13
13
  import { type CompactOptions, type CompactResult } from './assistant/history.ts';
@@ -19,7 +19,7 @@ export declare const CAPTURE_INFERENCE_CALLS_KEY = "inspector.captureInferenceCa
19
19
  export declare const CAPTURE_ON = "on";
20
20
  export declare const CAPTURE_OFF = "off";
21
21
  export interface AssistantOptions {
22
- logger?: Logger | null;
22
+ logger?: LoggerInterface | null;
23
23
  imageCacheDir?: string;
24
24
  inferenceCallsDir?: string;
25
25
  runReplayDir?: string;
@@ -31,6 +31,7 @@ export interface AssistantOptions {
31
31
  drives?: DriveHost;
32
32
  borrowHarness?: (deviceId: string) => Duplex;
33
33
  blobReadTimeoutMs?: number;
34
+ runIdleTimeoutMs?: number;
34
35
  pdfRasterizer?: PdfRasterizer;
35
36
  }
36
37
  export interface SkillListOptions extends SkillOptions {
@@ -51,6 +52,7 @@ export declare class QvacAssistant extends ReadyResource {
51
52
  private readonly _preloadCurrentAgentModel;
52
53
  private readonly _drives?;
53
54
  private readonly _blobReadTimeoutMs;
55
+ private readonly _runIdleTimeoutMs;
54
56
  private readonly _pdfRasterizer;
55
57
  private readonly _warmAbort;
56
58
  private readonly _unloading;
@@ -99,7 +101,7 @@ export declare class QvacAssistant extends ReadyResource {
99
101
  private readonly _modelCatalog;
100
102
  private readonly _onHarnessStatus;
101
103
  private readonly _onModelCatalogEvent;
102
- constructor(engine: Capabilities, harness: Harness, { logger, imageCacheDir, inferenceCallsDir, runReplayDir, imageCacheMaxBytes, imageCacheMaxAgeMs, downloadRetryMs, platform, preloadCurrentAgentModel, drives, borrowHarness, blobReadTimeoutMs, pdfRasterizer: pdfRasterizerOption }?: AssistantOptions);
104
+ constructor(engine: Capabilities, harness: Harness, { logger, imageCacheDir, inferenceCallsDir, runReplayDir, imageCacheMaxBytes, imageCacheMaxAgeMs, downloadRetryMs, platform, preloadCurrentAgentModel, drives, borrowHarness, blobReadTimeoutMs, runIdleTimeoutMs, pdfRasterizer: pdfRasterizerOption }?: AssistantOptions);
103
105
  private _requireDeviceId;
104
106
  _open(): Promise<void>;
105
107
  private _triggerModelWarm;
@@ -17,7 +17,6 @@ import { acceptedRepairCount, historyBranches, isPromptChunk } from './core/prom
17
17
  import ReadyGuard from 'ready-guard';
18
18
  import ReadyResource from 'ready-resource';
19
19
  import { local } from '../spec/index.js';
20
- import { isMissingMesh } from './api/current-mesh.js';
21
20
  import { meshScoped } from './mesh-scoped-engine.js';
22
21
  import { buildTitlePrompt, deriveChatTitle, isDefaultChatTitle, parseTitleResponse } from './chat-title.js';
23
22
  import { matchApprovalRule } from './core/approval-rules.js';
@@ -26,7 +25,7 @@ import { attachTurnDocumentIds, formatRagContext, chooseRagNotice, RAG_KNOWLEDGE
26
25
  import { annotateDocumentAttachments, documentUnreadNotice, documentUnreadReason } from './core/document-attachment.js';
27
26
  import { imageCacheKey, imageCacheName, sweepImageCache } from './core/image/cache-sweep.js';
28
27
  import { IMAGE_MIMES, normalizeImageForModel } from './core/image/normalize.js';
29
- import { MAX_PDF_PAGE_IMAGES, pdfRasterizer } from './core/pdf/rasterize.js';
28
+ import { MAX_PDF_PAGE_IMAGES, createPdfRasterizer } from './core/pdf/rasterize.js';
30
29
  import { recordBackends, summarizeRuns } from './diagnostics.js';
31
30
  import { resolveFsGrants } from './fs-drive-bridge.js';
32
31
  import { InferenceCallStore } from './inference-calls.js';
@@ -42,12 +41,14 @@ import { AbortedError, raceAbort } from '@qvac/harness/race-abort';
42
41
  import { RunTranscript } from './run-transcript.js';
43
42
  import { searchKnowledge } from './knowledge-search.js';
44
43
  import { isLifecycleTeardown, knownAbortOutcome, RUN_ABORT_REASONS, RUN_FAILURE_REASONS, runFailureNotice } from './run-notices.js';
44
+ import { unref } from './unref.js';
45
45
  import { encodeAgentSkillReadiness } from './skill-readiness.js';
46
46
  import { harnessClearKvCache, harnessDeathReason, harnessDeleteModel, harnessDied, harnessListModels, harnessPreviewModelSource, harnessSkillCatalog, harnessSkillManagement, harnessDetectLanguage, harnessSpeak, harnessSpeakStream, harnessTools, harnessTranscribe, heldLoadModel, droppedHeldLoadModel, imageDownloadProgress, isHarnessEvent, modelCatalogChanged, toolReportEntry } from './assistant/harness.js';
47
47
  import { annotateUnreadableImages, audioTranscriptBlock, backfillDocumentOnlyTurn, backfillImageOnlyTurns, silentAudioNotice, unheardAudioNotice, nameSenders } from './assistant/message.js';
48
48
  import { drainBody, raceInactivity } from './assistant/fetch-body.js';
49
49
  import { GENERIC_ACKNOWLEDGEMENTS, HISTORY_TYPES, SKILL_TOOL, TERMINAL_STATES, couldNameSenders, historyFromChunks, inputAvailableToRun, listHistoryChunks, senderAttribution, senderNamesFrom, staleToolRunIds } from './assistant/history.js';
50
50
  import { errorMessage, isRecord } from './guards.js';
51
+ import { CoreError, isCoreError } from './errors.js';
51
52
  export { harnessClearKvCache, harnessDeleteModel, harnessListModels, harnessPreviewModelSource, harnessSkillCatalog, harnessSkillManagement, harnessDetectLanguage, harnessSpeak, harnessSpeakStream, harnessTools, harnessTranscribe } from './assistant/harness.js';
52
53
  export {} from './assistant/skill-encode.js';
53
54
  export { annotateUnreadableImages, unheardAudioNotice, unreadableImagesNotice, DOCUMENT_ONLY_USER_PROMPT, IMAGE_AND_DOCUMENT_USER_PROMPT, IMAGE_ONLY_USER_PROMPT, nameSenders } from './assistant/message.js';
@@ -57,6 +58,33 @@ const DEFAULT_PROFILE = 'mid';
57
58
  const QvacState = local.getEnum('@local/qvac-state');
58
59
  const FINAL_FLUSH_MS = 10_000;
59
60
  const UPLOAD_FRAME_BYTES = 64 * 1024;
61
+ const RUN_IDLE_TIMEOUT_MS = 15 * 60_000;
62
+ function idleWatch(controller, ms) {
63
+ let last = 0;
64
+ let parked = 0;
65
+ const timer = setInterval(() => {
66
+ if (last && !parked && Date.now() - last >= ms) {
67
+ controller.abort(RUN_ABORT_REASONS.stalled);
68
+ }
69
+ }, Math.min(ms, 30_000));
70
+ unref(timer);
71
+ return {
72
+ touch: () => {
73
+ last = Date.now();
74
+ },
75
+ parks: (fn) => async (...args) => {
76
+ parked++;
77
+ try {
78
+ return await fn(...args);
79
+ }
80
+ finally {
81
+ parked--;
82
+ last = Date.now();
83
+ }
84
+ },
85
+ stop: () => clearInterval(timer)
86
+ };
87
+ }
60
88
  function settledWithin(write, ms) {
61
89
  let timer;
62
90
  const expired = new Promise((resolve) => {
@@ -148,6 +176,7 @@ export class QvacAssistant extends ReadyResource {
148
176
  _preloadCurrentAgentModel;
149
177
  _drives;
150
178
  _blobReadTimeoutMs;
179
+ _runIdleTimeoutMs;
151
180
  _pdfRasterizer;
152
181
  _warmAbort = new AbortController();
153
182
  _unloading = new Map();
@@ -196,7 +225,7 @@ export class QvacAssistant extends ReadyResource {
196
225
  _modelCatalog = new ModelCatalogRevisionHub();
197
226
  _onHarnessStatus;
198
227
  _onModelCatalogEvent;
199
- constructor(engine, harness, { logger = null, imageCacheDir, inferenceCallsDir, runReplayDir, imageCacheMaxBytes, imageCacheMaxAgeMs, downloadRetryMs, platform = os.platform(), preloadCurrentAgentModel = true, drives, borrowHarness, blobReadTimeoutMs = BLOB_READ_TIMEOUT_MS, pdfRasterizer: pdfRasterizerOption = pdfRasterizer } = {}) {
228
+ constructor(engine, harness, { logger = null, imageCacheDir, inferenceCallsDir, runReplayDir, imageCacheMaxBytes, imageCacheMaxAgeMs, downloadRetryMs, platform = os.platform(), preloadCurrentAgentModel = true, drives, borrowHarness, blobReadTimeoutMs = BLOB_READ_TIMEOUT_MS, runIdleTimeoutMs = RUN_IDLE_TIMEOUT_MS, pdfRasterizer: pdfRasterizerOption } = {}) {
200
229
  super();
201
230
  this._engine = engine;
202
231
  this._harness = harness;
@@ -211,7 +240,8 @@ export class QvacAssistant extends ReadyResource {
211
240
  this._mobileClass = isMobilePlatform(platform);
212
241
  this._preloadCurrentAgentModel = preloadCurrentAgentModel;
213
242
  this._blobReadTimeoutMs = blobReadTimeoutMs;
214
- this._pdfRasterizer = pdfRasterizerOption;
243
+ this._runIdleTimeoutMs = runIdleTimeoutMs;
244
+ this._pdfRasterizer = pdfRasterizerOption ?? createPdfRasterizer(logger);
215
245
  this._deviceId = null;
216
246
  this._info = { toolNames: [], skills: [], supportsImages: false };
217
247
  this._readySkills = null;
@@ -593,7 +623,7 @@ export class QvacAssistant extends ReadyResource {
593
623
  this._lastCapabilities.set(meshId, key);
594
624
  }
595
625
  catch (err) {
596
- if (isMissingMesh(err)) {
626
+ if (isCoreError(err, 'MESH_NOT_FOUND')) {
597
627
  return;
598
628
  }
599
629
  this._log?.error('assistant', 'saveDeviceCapabilities failed', err);
@@ -700,7 +730,7 @@ export class QvacAssistant extends ReadyResource {
700
730
  this._harness.off?.('status', this._onHarnessStatus);
701
731
  this._harness.off?.('model', this._onModelCatalogEvent);
702
732
  this._warmAbort.abort(RUNNER_CLOSED);
703
- this._onlineBoot.destroy(new Error('assistant is closing'));
733
+ this._onlineBoot.destroy(new CoreError('ASSISTANT_CLOSING'));
704
734
  for (const run of this._runs.values()) {
705
735
  run.controller.abort(RUNNER_CLOSED);
706
736
  }
@@ -802,10 +832,10 @@ export class QvacAssistant extends ReadyResource {
802
832
  }
803
833
  async loadModel(name) {
804
834
  if (!this._harness.loadModel) {
805
- throw new Error('the model runtime cannot preload a model');
835
+ throw new CoreError('MODEL_RUNTIME_UNSUPPORTED', ['preload']);
806
836
  }
807
837
  if (!(await this._isCached(name))) {
808
- throw new Error(`${name} is not downloaded on this device`);
838
+ throw new CoreError('MODEL_NOT_DOWNLOADED', [name]);
809
839
  }
810
840
  const config = await this._engine.getConfig({}).catch(noop);
811
841
  const agent = await this._agentRunning(name, config?.activeAgentId ?? null);
@@ -848,7 +878,7 @@ export class QvacAssistant extends ReadyResource {
848
878
  }
849
879
  async _unloadModel(name) {
850
880
  if (!this._harness.unloadModel) {
851
- throw new Error('the model runtime cannot unload a model');
881
+ throw new CoreError('MODEL_RUNTIME_UNSUPPORTED', ['unload']);
852
882
  }
853
883
  const holders = [...this._runs.values()].filter((run) => run.executing && !run.borrowed && run.model === name);
854
884
  for (const run of holders) {
@@ -909,7 +939,7 @@ export class QvacAssistant extends ReadyResource {
909
939
  }
910
940
  async retryModelDownload(name) {
911
941
  if (!this._downloads) {
912
- throw new Error('model download reconciler is unavailable');
942
+ throw new CoreError('MODEL_DOWNLOAD_UNAVAILABLE');
913
943
  }
914
944
  await this._downloads.retry(name);
915
945
  }
@@ -984,7 +1014,7 @@ export class QvacAssistant extends ReadyResource {
984
1014
  let stopped = false;
985
1015
  const settle = (err) => {
986
1016
  running = false;
987
- if (err !== null && !stopped && !isMissingMesh(err)) {
1017
+ if (err !== null && !stopped && !isCoreError(err, 'MESH_NOT_FOUND')) {
988
1018
  this._log?.error('assistant', `${label} watch failed`, err);
989
1019
  }
990
1020
  if (again) {
@@ -1729,6 +1759,7 @@ export class QvacAssistant extends ReadyResource {
1729
1759
  agentId: agent.id,
1730
1760
  hasRun: () => ran
1731
1761
  });
1762
+ const idle = idleWatch(controller, this._runIdleTimeoutMs);
1732
1763
  const modelWatch = this._watchModelProgress((runStatus) => transcript.progress(runStatusId, runStatus), busyChatId !== null);
1733
1764
  let metrics;
1734
1765
  const sourceTagFilter = createRagSourceTagFilter();
@@ -1889,6 +1920,7 @@ export class QvacAssistant extends ReadyResource {
1889
1920
  const input = nameSenders(messages);
1890
1921
  inputLength = input.length;
1891
1922
  const inspecting = await this._capturingInferenceCalls();
1923
+ idle.touch();
1892
1924
  const events = this._harnessFor(runAgent).completion({
1893
1925
  model,
1894
1926
  agent: runAgent,
@@ -1902,7 +1934,7 @@ export class QvacAssistant extends ReadyResource {
1902
1934
  grantedDrives,
1903
1935
  driveOp,
1904
1936
  grantedWriteDirs: write,
1905
- approve: approvals.approve,
1937
+ approve: idle.parks(approvals.approve),
1906
1938
  attach: (input) => this._uploadGenerated(input, { meshId, chatId, runId, deviceId }),
1907
1939
  fetchAttachment: (query) => this._fetchAttachment(engine, chatId, query),
1908
1940
  ragSearch: async (input) => {
@@ -1939,7 +1971,10 @@ export class QvacAssistant extends ReadyResource {
1939
1971
  hits
1940
1972
  };
1941
1973
  },
1942
- progress: (update) => modelWatch.image(update),
1974
+ progress: (update) => {
1975
+ idle.touch();
1976
+ modelWatch.image(update);
1977
+ },
1943
1978
  generationParams: diagramRepair ? { reasoning_budget: 0 } : undefined,
1944
1979
  captureInferenceCalls: true,
1945
1980
  signal: controller.signal
@@ -1947,6 +1982,7 @@ export class QvacAssistant extends ReadyResource {
1947
1982
  let harnessEvents = 0;
1948
1983
  for await (const event of events) {
1949
1984
  harnessEvents++;
1985
+ idle.touch();
1950
1986
  modelWatch.clear();
1951
1987
  if (isHarnessEvent(event, 'content') || isHarnessEvent(event, 'thinking')) {
1952
1988
  await writeText(event.type, event.text);
@@ -2076,6 +2112,7 @@ export class QvacAssistant extends ReadyResource {
2076
2112
  })
2077
2113
  .catch((err) => this._log?.warn('assistant', 'run outcome not recorded', { err }));
2078
2114
  transcript.close();
2115
+ idle.stop();
2079
2116
  modelWatch.stop();
2080
2117
  ownershipWatch.stop();
2081
2118
  await approvals.settle({ preservePending: isLifecycleTeardown(controller.signal.reason) });
@@ -1,11 +1,11 @@
1
1
  import ReadyResource from 'ready-resource';
2
2
  import type { Capabilities } from './api/index.ts';
3
3
  import type { CapabilityHandlers } from '../spec/capabilities.d.ts';
4
- import type { Logger } from '../index.ts';
4
+ import type { LoggerInterface } from '@qvac/logging';
5
5
  import { type EngineSpec } from './spec-loader.ts';
6
6
  import { type Transport } from '@qvac/harness/rpc';
7
7
  export interface ClientOptions {
8
- logger?: Logger | null;
8
+ logger?: LoggerInterface | null;
9
9
  spec?: () => Promise<EngineSpec>;
10
10
  handlers?: Partial<CapabilityHandlers>;
11
11
  }
@@ -2,6 +2,7 @@ import { softDeleteChatsForAgent } from './chat.js';
2
2
  import { randomId } from './id.js';
3
3
  import { softDeleteToolConfigsForAgent } from './tool-configs.js';
4
4
  import b4a from 'b4a';
5
+ import { CoreError } from '../errors.js';
5
6
  import { ACTIVE_AGENTS, AGENTS, AGENTS_BY_PROVIDER, DEFAULT_AGENTS, DEVICES } from './collections.js';
6
7
  const DEFAULT_ICON_NAME = 'artificial-intelligence';
7
8
  export function allTools() {
@@ -78,14 +79,14 @@ export async function liveProviderIds(store) {
78
79
  export async function mustGetAgent(store, id) {
79
80
  const agent = await getAgent(store, id);
80
81
  if (!agent) {
81
- throw new Error(`agent not found: ${id}`);
82
+ throw new CoreError('AGENT_NOT_FOUND', [id]);
82
83
  }
83
84
  return agent;
84
85
  }
85
86
  export async function mustGetActiveAgent(store, id) {
86
87
  const agent = await mustGetAgent(store, id);
87
88
  if (agent.deletedAt) {
88
- throw new Error(`agent not found: ${id}`);
89
+ throw new CoreError('AGENT_NOT_FOUND', [id]);
89
90
  }
90
91
  return agent;
91
92
  }
@@ -153,7 +154,7 @@ export async function updateAgent(store, agentId, input) {
153
154
  if (input.clearIsDefault && current.isDefault) {
154
155
  const own = await ownDefaultAgents(store);
155
156
  if (own.length === 1 && own[0].id === current.id) {
156
- throw new Error('cannot clear the last default agent of this member');
157
+ throw new CoreError('AGENT_LAST_DEFAULT');
157
158
  }
158
159
  }
159
160
  const enabledSkills = patch(input.enabledSkills, current.enabledSkills);
@@ -203,7 +204,7 @@ export async function rehomeAgents(store, from, to) {
203
204
  export async function deleteAgent(store, deviceId, id) {
204
205
  const current = await mustGetAgent(store, id);
205
206
  if (current.isDefault) {
206
- throw new Error('cannot delete the default agent');
207
+ throw new CoreError('AGENT_DEFAULT_UNDELETABLE');
207
208
  }
208
209
  const deletedAt = Date.now();
209
210
  const updated = {
@@ -1,9 +1,8 @@
1
1
  import type Corestore from 'corestore';
2
2
  import type CorestoreStorage from 'hypercore-storage';
3
- import type { Logger } from '../../index.ts';
3
+ import type { LoggerInterface } from '@qvac/logging';
4
4
  import type { LocalMeshMembership } from '../../spec/local/hyperschema/types.d.ts';
5
5
  import { Mesh } from './mesh.ts';
6
- export declare const NO_ARCHIVE_HELD = "No archive is held for this mesh";
7
6
  export interface ArchivedMeshCounts {
8
7
  readonly chats: number;
9
8
  readonly agents: number;
@@ -20,7 +19,7 @@ export interface ArchivedMeshOptions {
20
19
  readonly store: Corestore;
21
20
  readonly storage: CorestoreStorage;
22
21
  readonly deviceId: Buffer;
23
- readonly logger: Logger | null;
22
+ readonly logger: LoggerInterface | null;
24
23
  }
25
24
  export declare function withArchivedMesh<T>(row: LocalMeshMembership, opts: ArchivedMeshOptions, fn: (mesh: Mesh) => Promise<T>): Promise<T>;
26
25
  export declare function countContents(mesh: Mesh, into?: Mesh | null): Promise<ArchivedMeshCounts>;
@@ -2,11 +2,11 @@ import crypto from 'hypercore-crypto';
2
2
  import { copyBlob, copyChunks, stripped } from './chat-copy.js';
3
3
  import { Mesh } from './mesh.js';
4
4
  import { ACTIVE_AGENTS, ACTIVE_CHATS, ACTIVE_CHAT_GROUPS, ACTIVE_TOOL_CONFIGS_BY_AGENT, AGENTS, KNOWLEDGE } from './collections.js';
5
+ import { CoreError } from '../errors.js';
5
6
  const MIGRATED_SUFFIX = ' (migrated)';
6
- export const NO_ARCHIVE_HELD = 'No archive is held for this mesh';
7
7
  export async function withArchivedMesh(row, opts, fn) {
8
8
  if (!(await opts.storage.hasCore(crypto.discoveryKey(row.key)))) {
9
- throw new Error(NO_ARCHIVE_HELD);
9
+ throw new CoreError('ARCHIVE_NOT_FOUND');
10
10
  }
11
11
  const mesh = new Mesh(opts.store, {
12
12
  seed: row.seed,
@@ -18,7 +18,7 @@ export async function withArchivedMesh(row, opts, fn) {
18
18
  await mesh.ready();
19
19
  try {
20
20
  if (mesh.localLength === 0) {
21
- throw new Error(NO_ARCHIVE_HELD);
21
+ throw new CoreError('ARCHIVE_NOT_FOUND');
22
22
  }
23
23
  await mesh.autobee.update();
24
24
  return await fn(mesh);
@@ -16,17 +16,19 @@ const catalogs = new WeakMap();
16
16
  export function listChatActivity(store, chatIds) {
17
17
  let catalog = catalogs.get(store);
18
18
  if (!catalog) {
19
- catalog = new ChatActivityCatalog();
19
+ catalog = new ChatActivityCatalog(store.log);
20
20
  catalogs.set(store, catalog);
21
21
  }
22
22
  return catalog.list(store, chatIds);
23
23
  }
24
24
  class ChatActivityCatalog {
25
+ _log;
25
26
  _lock;
26
27
  _chats;
27
28
  _head;
28
29
  _forwards;
29
- constructor() {
30
+ constructor(log) {
31
+ this._log = log;
30
32
  this._lock = new ScopeLock();
31
33
  this._chats = new Map();
32
34
  this._head = null;
@@ -117,7 +119,7 @@ class ChatActivityCatalog {
117
119
  }
118
120
  }
119
121
  catch (err) {
120
- logger.warn('chat-activity', 'diff from the cached head failed, rebuilding', err);
122
+ this._log?.warn('chat-activity', 'diff from the cached head failed, rebuilding', err);
121
123
  return false;
122
124
  }
123
125
  for (const [chatId, chunks] of chunksByChat) {
@@ -9,7 +9,6 @@ export interface ChatMoveCopy extends MeshCopy {
9
9
  readonly originDeviceId: Buffer;
10
10
  readonly references: Map<string, string>;
11
11
  }
12
- export declare const CHUNK_IN_ANOTHER_CHAT = "the target already holds this chat under another id";
13
12
  export declare function copyChunks(snap: HyperDB, chatId: string, { from, into }: MeshCopy): Promise<void>;
14
13
  export declare function copyMovedChunks(snap: HyperDB, chatId: string, copy: ChatMoveCopy): Promise<number>;
15
14
  export declare function copyMovedKnowledge(snap: HyperDB, chatId: string, copy: ChatMoveCopy): Promise<void>;
@@ -1,8 +1,8 @@
1
1
  import b4a from 'b4a';
2
2
  import { PENDING_BLOB_REFERENCE, isPendingBlobReference, parseBlobReference } from './files/store/index.js';
3
+ import { CoreError } from '../errors.js';
3
4
  import { inlineReference } from './files/store/inline.js';
4
5
  import { CHUNKS, CHUNKS_BY_CHAT, KNOWLEDGE, KNOWLEDGE_BY_CHAT } from './collections.js';
5
- export const CHUNK_IN_ANOTHER_CHAT = 'the target already holds this chat under another id';
6
6
  export async function copyChunks(snap, chatId, { from, into }) {
7
7
  const batch = into.batch();
8
8
  for (const chunk of await chunksOf(snap, chatId)) {
@@ -89,7 +89,7 @@ export function removedReference({ mimeType }) {
89
89
  async function heldInTarget(into, { collection, id, chatId }) {
90
90
  const existing = await into.view.get(collection, { id });
91
91
  if (existing && existing.chatId !== chatId) {
92
- throw new Error(CHUNK_IN_ANOTHER_CHAT);
92
+ throw new CoreError('CHAT_MOVE_ID_CONFLICT');
93
93
  }
94
94
  return !!existing;
95
95
  }
@@ -1,11 +1,5 @@
1
1
  import { type ChatListing } from './chat.ts';
2
2
  import type { Mesh } from './mesh.ts';
3
- export declare const NO_SUCH_TURN = "no turn of this chat has that run id";
4
- export declare const TURN_RUNNING = "a turn up to the fork point is still running; fork once it has finished";
5
- export declare const NOTHING_BEFORE = "nothing comes before the first turn, so there is nothing to fork";
6
- export declare const AGENT_REQUIRED = "a chat forked into another mesh needs an agent of that mesh";
7
- export declare const FILE_ARRIVING = "a file in this chat is still arriving; fork once it has landed";
8
- export declare const FILE_NOT_HERE = "a file in this chat is not on this device yet; open it here first";
9
3
  export interface ForkMeshes {
10
4
  readonly from: Mesh;
11
5
  readonly into: Mesh;