@qvac/core 0.6.4 → 0.6.6

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 (87) hide show
  1. package/CHANGELOG.md +78 -1
  2. package/README.md +20 -4
  3. package/dist-lib/lib/api/chat-move.d.ts +3 -0
  4. package/dist-lib/lib/api/chat-move.js +7 -0
  5. package/dist-lib/lib/api/chat.d.ts +1 -1
  6. package/dist-lib/lib/api/chat.js +2 -1
  7. package/dist-lib/lib/api/chunk-delta.d.ts +7 -0
  8. package/dist-lib/lib/api/chunk-delta.js +33 -0
  9. package/dist-lib/lib/api/chunks.d.ts +1 -1
  10. package/dist-lib/lib/api/chunks.js +6 -3
  11. package/dist-lib/lib/api/index.d.ts +2 -0
  12. package/dist-lib/lib/api/index.js +2 -0
  13. package/dist-lib/lib/api/mesh.d.ts +2 -1
  14. package/dist-lib/lib/api/mesh.js +4 -0
  15. package/dist-lib/lib/assistant/harness.d.ts +8 -10
  16. package/dist-lib/lib/assistant.js +1 -1
  17. package/dist-lib/lib/constants.d.ts +1 -0
  18. package/dist-lib/lib/constants.js +1 -0
  19. package/dist-lib/lib/core/archived-mesh.js +3 -42
  20. package/dist-lib/lib/core/chat-activity.js +23 -10
  21. package/dist-lib/lib/core/chat-copy.d.ts +24 -0
  22. package/dist-lib/lib/core/chat-copy.js +115 -0
  23. package/dist-lib/lib/core/chat-move.d.ts +65 -0
  24. package/dist-lib/lib/core/chat-move.js +525 -0
  25. package/dist-lib/lib/core/chat.d.ts +6 -0
  26. package/dist-lib/lib/core/chat.js +11 -3
  27. package/dist-lib/lib/core/collections.d.ts +2 -0
  28. package/dist-lib/lib/core/collections.js +2 -0
  29. package/dist-lib/lib/core/contract/compute.d.ts +1 -1
  30. package/dist-lib/lib/core/contract/compute.js +2 -1
  31. package/dist-lib/lib/core/contract/index.js +2 -0
  32. package/dist-lib/lib/core/contract/invites.d.ts +1 -0
  33. package/dist-lib/lib/core/contract/invites.js +1 -1
  34. package/dist-lib/lib/core/contract/mesh-name.d.ts +3 -0
  35. package/dist-lib/lib/core/contract/mesh-name.js +26 -0
  36. package/dist-lib/lib/core/contract/writers.js +10 -3
  37. package/dist-lib/lib/core/files/index.d.ts +1 -1
  38. package/dist-lib/lib/core/files/index.js +1 -1
  39. package/dist-lib/lib/core/files/preview/index.js +4 -1
  40. package/dist-lib/lib/core/files/processing/source.js +4 -1
  41. package/dist-lib/lib/core/files/store/index.d.ts +2 -1
  42. package/dist-lib/lib/core/files/store/index.js +2 -1
  43. package/dist-lib/lib/core/files/store/reference.d.ts +3 -0
  44. package/dist-lib/lib/core/files/store/reference.js +8 -0
  45. package/dist-lib/lib/core/files/store/sweep.js +3 -1
  46. package/dist-lib/lib/core/local/index.d.ts +4 -1
  47. package/dist-lib/lib/core/local/index.js +14 -1
  48. package/dist-lib/lib/core/mesh-seed-handoff.d.ts +3 -1
  49. package/dist-lib/lib/core/mesh-seed-handoff.js +1 -0
  50. package/dist-lib/lib/core/mesh.d.ts +5 -1
  51. package/dist-lib/lib/core/mesh.js +16 -1
  52. package/dist-lib/lib/core/sync/index.js +9 -1
  53. package/dist-lib/lib/core.d.ts +9 -0
  54. package/dist-lib/lib/core.js +156 -30
  55. package/dist-lib/lib/custom-model-pusher.js +9 -5
  56. package/dist-lib/lib/mesh-scoped-engine.js +5 -0
  57. package/dist-lib/schema/engine.js +80 -1
  58. package/dist-lib/schema/local.js +17 -0
  59. package/dist-lib/schema/qvac.d.ts +2 -0
  60. package/dist-lib/schema/qvac.js +16 -0
  61. package/dist-lib/spec/bind.js +25 -0
  62. package/dist-lib/spec/calls.js +5 -0
  63. package/dist-lib/spec/capabilities.d.ts +10 -0
  64. package/dist-lib/spec/hrpc/hrpc.json +65 -0
  65. package/dist-lib/spec/hrpc/index.js +66 -4
  66. package/dist-lib/spec/hrpc/messages.js +1398 -1154
  67. package/dist-lib/spec/hyperschema/index.js +1398 -1154
  68. package/dist-lib/spec/hyperschema/schema.json +204 -0
  69. package/dist-lib/spec/hyperschema/types.d.ts +47 -0
  70. package/dist-lib/spec/local/hyperdb/db.json +17 -1
  71. package/dist-lib/spec/local/hyperdb/index.js +83 -2
  72. package/dist-lib/spec/local/hyperdb/messages.js +340 -136
  73. package/dist-lib/spec/local/hyperschema/index.js +107 -2
  74. package/dist-lib/spec/local/hyperschema/schema.json +78 -1
  75. package/dist-lib/spec/local/hyperschema/types.d.ts +18 -1
  76. package/dist-lib/spec/mesh/hyperdb/db.json +16 -1
  77. package/dist-lib/spec/mesh/hyperdb/index.js +71 -2
  78. package/dist-lib/spec/mesh/hyperdb/messages.js +454 -228
  79. package/dist-lib/spec/mesh/hyperdispatch/dispatch.json +7 -1
  80. package/dist-lib/spec/mesh/hyperdispatch/index.js +18 -1
  81. package/dist-lib/spec/mesh/hyperdispatch/messages.js +150 -2
  82. package/dist-lib/spec/mesh/hyperschema/index.js +150 -2
  83. package/dist-lib/spec/mesh/hyperschema/schema.json +76 -1
  84. package/dist-lib/spec/mesh/hyperschema/types.d.ts +21 -1
  85. package/package.json +5 -3
  86. package/tui/app.mjs +89 -3
  87. package/tui/lib/move-command.mjs +17 -0
package/CHANGELOG.md CHANGED
@@ -13,6 +13,81 @@ release.
13
13
 
14
14
  ## [Unreleased]
15
15
 
16
+ ## [0.6.6] - 2026-10-05
17
+
18
+ ### Changed
19
+
20
+ - The consensus floor, `VENDORED_MIN_SUPPORTED_VERSION`, is back to `>=0.19.0`.
21
+ The app ships the #308 apply change in 0.19, so that release is the floor; at
22
+ `>=0.20.0` a 0.19 build would withhold itself from its own meshes. (#317)
23
+
24
+ ## [0.6.5] - 2026-10-01
25
+
26
+ ### Added
27
+
28
+ - `setMeshName` names a mesh for every member in it. `setMeshLabel` only
29
+ names it for the member who set it, so someone who joined a shared mesh read
30
+ it unnamed. `listMeshes` and `meshesWatch` rows carry the shared name as
31
+ `name`, and `meshesWatch` emits when another member renames the mesh. A build
32
+ older than this one halts on the new `name-mesh` op, so every member's devices
33
+ need this release before a mesh is named.
34
+
35
+ ```js
36
+ await engine.setMeshName({ meshId, name: 'Design team' })
37
+ const { meshes } = await engine.listMeshes({})
38
+ meshes.find((mesh) => mesh.meshId === meshId).name // 'Design team', on every member
39
+ ```
40
+
41
+ (#310)
42
+
43
+ - `moveChatToMesh` moves a chat to another mesh with its files and its running
44
+ turn: the copy lands at once under `targetChatId`, the turn is retried there,
45
+ and the source is purged once every file has arrived. `chatMoveWatch` reports
46
+ the move, and `setChatAgent` hands a chat to another agent of its mesh. Until
47
+ its bytes arrive, a moved attachment's `blobId` is `PENDING_BLOB_REFERENCE`,
48
+ which `downloadAttachment` rejects with `blob unavailable`. (#312)
49
+ - `chunksDeltaWatch` streams an open chat as changes: a `reset` with the whole
50
+ selection first, then only the rows appended, edited or reordered, and the ids
51
+ of rows that left. A transcript that re-rendered the whole chat on every
52
+ streamed chunk pays for one row per chunk instead; `chunksWatch` is
53
+ unchanged. (#314)
54
+
55
+ ### Changed
56
+
57
+ - The consensus floor, `VENDORED_MIN_SUPPORTED_VERSION`, is `>=0.20.0`. How a
58
+ re-paired device's removal is weighed changed in apply, so a device on an
59
+ older build would read a shared mesh differently. Ship the 0.20 app before
60
+ publishing this floor to the lane cores. (#308)
61
+ - `@qvac/harness` is `^0.7.2`. `web_fetch` attaches a plain-text file it
62
+ fetched to the chat beside returning its text, and devices on the `mid`
63
+ profile and up speak with `Supertonic3-FP16` at 16 steps instead of
64
+ `Supertonic3-Q8_0` at 5, so a host that prefetches the infra models downloads
65
+ the FP16 model once. (#311)
66
+
67
+ ### Fixed
68
+
69
+ - A device unpaired and paired back gets every project back, however its
70
+ removal synced, and one that left a shared mesh on its own comes back as soon
71
+ as it asks; only another member's removal still needs a grant. A re-paired
72
+ device still live on its old writer is moved onto its new one instead of
73
+ staying a reader, and a late leave no longer turns a kick into a leave. A
74
+ consensus change, covered by the `>=0.20.0` floor. (#308)
75
+ - A member re-invited to a mesh it left brings every device back, not only the
76
+ one that redeemed the invite. A device asking its siblings to admit it asks
77
+ again, about once a second for up to a minute, while they are mid-join,
78
+ instead of waiting as a reader until the next restart. (#307)
79
+ - `leaveMesh` on the account is no longer refused while this device holds
80
+ another mesh: it departs each of them as this device alone, then leaves the
81
+ account. Unpairing a device that held a project did nothing. (#306)
82
+ - `chatActivityWatch` no longer fails on every tick after a fast-forward leaves
83
+ its cached view head undiffable. It rebuilds from the current view instead;
84
+ before, the error repeated until restart. (#301)
85
+ - `modelCatalogWatch` bumps only when the custom-model set changed. It bumped on
86
+ every device-local write, several times a second while a reply streamed. (#300)
87
+ - A typed harness can ask `fetchAttachment` for the newest audio. (#309)
88
+ - PDF extraction works on Android again: `bare-pdfium` 1.5.5 links its C++
89
+ runtime into the addon, which 1.5.4's prebuilds left undefined. (#305)
90
+
16
91
  ## [0.6.4] - 2026-09-30
17
92
 
18
93
  ### Removed
@@ -1159,7 +1234,9 @@ Published under the `release-0.1` dist-tag.
1159
1234
  await assistant.ready()
1160
1235
  ```
1161
1236
 
1162
- [Unreleased]: https://github.com/tetherto/qvac-core/compare/v0.6.4...HEAD
1237
+ [Unreleased]: https://github.com/tetherto/qvac-core/compare/v0.6.6...HEAD
1238
+ [0.6.6]: https://github.com/tetherto/qvac-core/compare/v0.6.5...v0.6.6
1239
+ [0.6.5]: https://github.com/tetherto/qvac-core/compare/v0.6.4...v0.6.5
1163
1240
  [0.6.4]: https://github.com/tetherto/qvac-core/compare/v0.6.3...v0.6.4
1164
1241
  [0.6.3]: https://github.com/tetherto/qvac-core/compare/v0.6.2...v0.6.3
1165
1242
  [0.6.2]: https://github.com/tetherto/qvac-core/compare/v0.6.1...v0.6.2
package/README.md CHANGED
@@ -339,11 +339,25 @@ A chat IS its chunk stream — one watch drives the whole view, and every
339
339
  device renders the same thing because they all see the same chunks:
340
340
 
341
341
  ```js
342
- for await (const { chunks } of engine.chunksWatch({ meshId, chatId })) render(chunks)
342
+ const rows = new Map()
343
+ for await (const { reset, chunks = [], removed = [] } of engine.chunksDeltaWatch({
344
+ meshId,
345
+ chatId
346
+ })) {
347
+ if (reset) rows.clear()
348
+ for (const id of removed) rows.delete(id)
349
+ for (const chunk of chunks) rows.set(chunk.id, chunk)
350
+ render([...rows.values()].sort((a, b) => a.seq - b.seq))
351
+ }
343
352
  ```
344
353
 
345
- Each frame is the full chat in seq order. To render it, group chunks into
346
- turns, then map each chunk type:
354
+ The first frame is the whole chat; after that each frame carries only the rows
355
+ that changed, so a long streamed answer costs one row per chunk rather than the
356
+ whole chat each time. `chunksWatch` takes the same request and sends the full
357
+ list on every change, for a reader that wants it that way. A view over a long
358
+ chat also opens on a page and watches from its floor — see
359
+ [`chunksDeltaWatch`](docs/api/chunks.md#chunksdeltawatch). To render the rows,
360
+ group chunks into turns, then map each chunk type:
347
361
 
348
362
  **Grouping.** A `user-message` (and an `attachment`) is its own user turn —
349
363
  label it by `originDeviceId`, resolved to a name via `devicesWatch`. Every
@@ -551,7 +565,9 @@ contract:
551
565
  the fetch — there is no fetch-then-subscribe race to paper over, ever.
552
566
  - **Later frames arrive only on real change** (identical snapshots are
553
567
  deduped server-side), and each frame is the full current result, not a
554
- delta.
568
+ delta. The one exception says so in its name: `chunksDeltaWatch` sends a
569
+ `reset` first and the changed rows after it, and its reset is still the
570
+ snapshot.
555
571
  - **`destroy()` is the unsubscribe** (ending a `for await` does the same
556
572
  thing). Nothing else to call, no registry to clean up — in any process,
557
573
  over any transport.
@@ -0,0 +1,3 @@
1
+ import type { CapabilityHandlers } from '../../spec/capabilities.d.ts';
2
+ import type { ChatMoves } from '../core/chat-move.ts';
3
+ export declare function createChatMoveApi(moves: ChatMoves): Pick<CapabilityHandlers, 'moveChatToMesh' | 'chatMoveWatch'>;
@@ -0,0 +1,7 @@
1
+ import { watchable } from './watchable.js';
2
+ export function createChatMoveApi(moves) {
3
+ return {
4
+ moveChatToMesh: (request) => moves.move(request),
5
+ chatMoveWatch: watchable(() => moves, (request, store) => store.status(request), { name: 'chatMoveWatch' })
6
+ };
7
+ }
@@ -2,7 +2,7 @@ import type { CapabilityHandlers } from '../../spec/capabilities.d.ts';
2
2
  import type { openLocalStore } from '../core/local/index.ts';
3
3
  import { type MeshPool } from './current-mesh.ts';
4
4
  type LocalStore = ReturnType<typeof openLocalStore>;
5
- type ChatCapabilities = Pick<CapabilityHandlers, 'createChat' | 'listChats' | 'getChat' | 'renameChat' | 'markChatRead' | 'setChatRagEnabled' | 'setChatWebSearchEnabled' | 'deleteChat' | 'chatsWatch' | 'listChatActivity' | 'chatActivityWatch' | 'searchChats'>;
5
+ type ChatCapabilities = Pick<CapabilityHandlers, 'createChat' | 'listChats' | 'getChat' | 'renameChat' | 'markChatRead' | 'setChatAgent' | 'setChatRagEnabled' | 'setChatWebSearchEnabled' | 'deleteChat' | 'chatsWatch' | 'listChatActivity' | 'chatActivityWatch' | 'searchChats'>;
6
6
  export interface CreateChatApiOptions {
7
7
  readonly deviceId: Buffer | null;
8
8
  readonly inferenceCalls?: {
@@ -1,5 +1,5 @@
1
1
  import { AbortController } from 'bare-abort-controller';
2
- import { createChat, deleteChat, markChatRead, mustGetActiveChatListing, renameChat, setChatRagEnabled, setChatWebSearchEnabled } from '../core/chat.js';
2
+ import { createChat, deleteChat, markChatRead, mustGetActiveChatListing, renameChat, setChatAgent, setChatRagEnabled, setChatWebSearchEnabled } from '../core/chat.js';
3
3
  import { listChatActivity } from '../core/chat-activity.js';
4
4
  import { listChatPage } from '../core/chat-order.js';
5
5
  import { searchChats } from '../core/chat-search.js';
@@ -15,6 +15,7 @@ export function createChatApi(pool, local, { deviceId, inferenceCalls = null })
15
15
  getChat: async ({ chatId, meshId }) => mustGetActiveChatListing(await requireMesh(pool, meshId), chatId),
16
16
  renameChat: async ({ chatId, meshId, config }) => renameChat(await requireMesh(pool, meshId), chatId, config.title),
17
17
  markChatRead: async ({ chatId, meshId }) => markChatRead(await requireMesh(pool, meshId), chatId),
18
+ setChatAgent: async ({ chatId, agentId, meshId }) => setChatAgent(await requireMesh(pool, meshId), chatId, agentId),
18
19
  setChatRagEnabled: async ({ chatId, enabled, meshId }) => setChatRagEnabled(await requireMesh(pool, meshId), chatId, { ragEnabled: enabled ?? false }),
19
20
  setChatWebSearchEnabled: async ({ chatId, enabled, meshId }) => setChatWebSearchEnabled(await requireMesh(pool, meshId), chatId, enabled ?? false),
20
21
  deleteChat: async ({ chatId, meshId }) => {
@@ -0,0 +1,7 @@
1
+ import { type Readable } from 'streamx';
2
+ import type { AssistantChunk, AssistantChunkDelta, AssistantChunkList } from '../../spec/hyperschema/types.d.ts';
3
+ import type { WatchStream } from '../../spec/capabilities.d.ts';
4
+ type Rows = ReadonlyMap<string, AssistantChunk>;
5
+ export declare function chunkDelta(prev: Rows | null, next: ReadonlyArray<AssistantChunk>): AssistantChunkDelta;
6
+ export declare function chunkDeltaStream(lists: Readable & AsyncIterable<AssistantChunkList>): Readable & WatchStream<AssistantChunkDelta>;
7
+ export {};
@@ -0,0 +1,33 @@
1
+ import { pipeline, Transform } from 'streamx';
2
+ import { frameReadable } from '../frame-readable.js';
3
+ import { snapshotEquals } from './watchable.js';
4
+ export function chunkDelta(prev, next) {
5
+ const count = next.length;
6
+ if (prev === null) {
7
+ return { reset: true, chunks: [...next], removed: [], count };
8
+ }
9
+ const upserts = next.filter((chunk) => !snapshotEquals(chunk, prev.get(chunk.id)));
10
+ const kept = new Set(next.map((chunk) => chunk.id));
11
+ const removed = [...prev.keys()].filter((id) => !kept.has(id));
12
+ if (upserts.length + removed.length > count / 2) {
13
+ return { reset: true, chunks: [...next], removed: [], count };
14
+ }
15
+ return { reset: false, chunks: upserts, removed, count };
16
+ }
17
+ export function chunkDeltaStream(lists) {
18
+ let prev = null;
19
+ const deltas = new Transform({
20
+ transform(list, cb) {
21
+ const next = list.chunks ?? [];
22
+ const delta = chunkDelta(prev, next);
23
+ prev = new Map(next.map((chunk) => [chunk.id, chunk]));
24
+ if (!delta.reset && delta.chunks?.length === 0 && delta.removed?.length === 0) {
25
+ cb(null);
26
+ return;
27
+ }
28
+ cb(null, delta);
29
+ }
30
+ });
31
+ return frameReadable(pipeline(lists, deltas, noop));
32
+ }
33
+ function noop() { }
@@ -1,5 +1,5 @@
1
1
  import { type MeshPool } from './current-mesh.ts';
2
2
  import type { CapabilityHandlers } from '../../spec/capabilities.d.ts';
3
- type ChunkCapabilities = Pick<CapabilityHandlers, 'appendChunk' | 'updateChunk' | 'resolveApproval' | 'listChunks' | 'listAttachmentsByKind' | 'chunksWatch' | 'runRequestsWatch'>;
3
+ type ChunkCapabilities = Pick<CapabilityHandlers, 'appendChunk' | 'updateChunk' | 'resolveApproval' | 'listChunks' | 'listAttachmentsByKind' | 'chunksWatch' | 'chunksDeltaWatch' | 'runRequestsWatch'>;
4
4
  export declare function createChunksApi(pool: MeshPool, deviceId: Buffer | null): ChunkCapabilities;
5
5
  export {};
@@ -1,7 +1,11 @@
1
1
  import { appendChunk, listAttachmentsByKind, listChunks, listRunRequests, recordLinks, resolveApproval, updateChunk } from '../core/chunk.js';
2
+ import { chunkDeltaStream } from './chunk-delta.js';
2
3
  import { meshWatchable, requireMesh } from './current-mesh.js';
3
4
  import { bounds } from './range.js';
4
5
  export function createChunksApi(pool, deviceId) {
6
+ const chunksWatch = meshWatchable(pool, async ({ meshId, ...input }, mesh) => ({
7
+ chunks: await recordLinks(mesh, await listChunks(mesh, chunkSelection(input)))
8
+ }), { name: 'chunksWatch' });
5
9
  return {
6
10
  appendChunk: async ({ meshId, ...input }) => appendChunk(await requireMesh(pool, meshId), input),
7
11
  updateChunk: async ({ meshId, chunkId, runStatus }) => {
@@ -31,9 +35,8 @@ export function createChunksApi(pool, deviceId) {
31
35
  });
32
36
  return { chunks: await recordLinks(mesh, chunks) };
33
37
  },
34
- chunksWatch: meshWatchable(pool, async ({ meshId, ...input }, mesh) => ({
35
- chunks: await recordLinks(mesh, await listChunks(mesh, chunkSelection(input)))
36
- }), { name: 'chunksWatch' }),
38
+ chunksWatch,
39
+ chunksDeltaWatch: (request) => chunkDeltaStream(chunksWatch(request)),
37
40
  runRequestsWatch: meshWatchable(pool, async (_request, mesh) => ({ chunks: await listRunRequests(mesh, deviceId) }), { name: 'runRequestsWatch' })
38
41
  };
39
42
  }
@@ -3,6 +3,7 @@ import type { AssistantCapabilityProfile, AssistantClearModelDownloadRequest, As
3
3
  import type { openLocalStore } from '../core/local/index.ts';
4
4
  import type { Mesh } from '../core/mesh.ts';
5
5
  import type { MeshPool } from './current-mesh.ts';
6
+ import type { ChatMoves } from '../core/chat-move.ts';
6
7
  import { type DiagnosticsSource } from './diagnostics.ts';
7
8
  import { type InferenceCallReader } from './inference-calls.ts';
8
9
  import { type LogSource } from './logs.ts';
@@ -17,6 +18,7 @@ interface ApiDeps {
17
18
  network?: NetworkSource | null;
18
19
  diagnostics?: DiagnosticsSource | null;
19
20
  inferenceCalls?: InferenceCallReader | null;
21
+ chatMoves?: ChatMoves | null;
20
22
  logs?: LogSource | null;
21
23
  deviceId?: Buffer | null;
22
24
  lifecycle?: {
@@ -5,6 +5,7 @@ import { createAgentsApi } from './agents.js';
5
5
  import { createApprovalRulesApi } from './approval-rules.js';
6
6
  import { createAttachmentsApi } from './attachments.js';
7
7
  import { createChatApi } from './chat.js';
8
+ import { createChatMoveApi } from './chat-move.js';
8
9
  import { createChatGroupsApi } from './chat-groups.js';
9
10
  import { createChunksApi } from './chunks.js';
10
11
  import { createAppConfigApi } from './app-config.js';
@@ -50,6 +51,7 @@ export function createApi(deps = {}) {
50
51
  inferenceCalls: deps.inferenceCalls ?? null
51
52
  })
52
53
  : null),
54
+ ...(deps.chatMoves ? createChatMoveApi(deps.chatMoves) : null),
53
55
  ...(mesh ? createChatGroupsApi(mesh) : null),
54
56
  ...(mesh ? createApprovalRulesApi(mesh) : null),
55
57
  ...(mesh ? createChunksApi(mesh, deps.deviceId ?? null) : null),
@@ -24,6 +24,7 @@ export interface MeshStatusSource {
24
24
  open(meshId: string): Promise<void>;
25
25
  close(meshId: string): Promise<void>;
26
26
  label(meshId: string, label: string): Promise<void>;
27
+ name(meshId: string, name: string): Promise<void>;
27
28
  createMesh(opts?: {
28
29
  compute?: boolean;
29
30
  }): Promise<string>;
@@ -35,4 +36,4 @@ export interface MeshStatusSource {
35
36
  recover(phrase: string, timeout?: number): Promise<void>;
36
37
  displayName(): Promise<string | null>;
37
38
  }
38
- 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' | 'createMesh' | 'createRoom' | 'listArchivedMeshes' | 'archivedMeshContents' | 'migrateArchivedMesh' | 'accountRecoverable' | 'recoveryPublish' | 'recoverAccount' | 'displayName' | 'setDisplayName'>;
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'>;
@@ -37,6 +37,10 @@ export function createMeshApi(status, updateMember) {
37
37
  await status.label(meshId, label ?? '');
38
38
  return { ok: true };
39
39
  },
40
+ setMeshName: async ({ meshId, name }) => {
41
+ await status.name(meshId, name ?? '');
42
+ return { ok: true };
43
+ },
40
44
  createMesh: async (request) => ({
41
45
  meshId: await status.createMesh({ compute: request?.config?.compute })
42
46
  }),
@@ -74,6 +74,12 @@ export interface DeviceCapability {
74
74
  export interface ImageProgress {
75
75
  readonly percentage: number;
76
76
  }
77
+ export interface FetchAttachmentOptions {
78
+ readonly attachmentId?: string;
79
+ readonly kind?: 'image' | 'audio';
80
+ readonly signal?: AbortSignal;
81
+ readonly meta?: boolean;
82
+ }
77
83
  export interface Harness {
78
84
  completion(context: {
79
85
  model: string;
@@ -111,11 +117,7 @@ export interface Harness {
111
117
  };
112
118
  approve?: (call: ApprovalCall) => Promise<boolean>;
113
119
  attach?: (input: AttachInput) => Promise<AssistantChunkContentAttachment>;
114
- fetchAttachment?: (query: {
115
- attachmentId?: string;
116
- signal?: AbortSignal;
117
- meta?: boolean;
118
- }) => Promise<FetchedAttachment | AttachmentMeta | null>;
120
+ fetchAttachment?: (query: FetchAttachmentOptions) => Promise<FetchedAttachment | AttachmentMeta | null>;
119
121
  ragSearch?: (input: {
120
122
  query: string;
121
123
  limit?: number;
@@ -140,11 +142,7 @@ export interface Harness {
140
142
  enhance?: AssistantEnhanceMode;
141
143
  agent?: AssistantAgent;
142
144
  attach?: (input: AttachInput) => Promise<AssistantChunkContentAttachment>;
143
- fetchAttachment?: (query: {
144
- attachmentId?: string;
145
- signal?: AbortSignal;
146
- meta?: boolean;
147
- }) => Promise<FetchedAttachment | AttachmentMeta | null>;
145
+ fetchAttachment?: (query: FetchAttachmentOptions) => Promise<FetchedAttachment | AttachmentMeta | null>;
148
146
  progress?: (update: ImageProgress | null) => void;
149
147
  signal?: AbortSignal;
150
148
  }): AsyncIterable<HarnessEvent>;
@@ -987,7 +987,7 @@ export class QvacAssistant extends ReadyResource {
987
987
  _dropDeletedChat(chatId) {
988
988
  for (const run of this._runs.values()) {
989
989
  if (run.chatId === chatId) {
990
- void RUN_SETTLED;
990
+ run.controller.abort(RUN_SETTLED);
991
991
  }
992
992
  }
993
993
  this._reconciledCompactions.delete(chatId);
@@ -1,4 +1,5 @@
1
1
  export { COMPACTION_MIN_CTX_SIZE, contextOptionsForModel, DEFAULT_CONTEXT_SIZE, defaultContextForModel, formatTokenCount, MODEL_CONTEXT_TARGET, type ModelContextTarget, maxContextForModel, modelContextTargetForPlatform } from './model-context.ts';
2
+ export declare const PENDING_BLOB_REFERENCE = "{\"pending\":true}";
2
3
  export declare const CANCELED_CHAT_MESSAGE = "Stopped the current run. Send a follow-up to steer the next step.";
3
4
  export declare const HOMEBREW_BIN_DIRS: ReadonlyArray<string>;
4
5
  export declare const SAFE_BIN_NAME: RegExp;
@@ -1,4 +1,5 @@
1
1
  export { COMPACTION_MIN_CTX_SIZE, contextOptionsForModel, DEFAULT_CONTEXT_SIZE, defaultContextForModel, formatTokenCount, MODEL_CONTEXT_TARGET, maxContextForModel, modelContextTargetForPlatform } from './model-context.js';
2
+ export const PENDING_BLOB_REFERENCE = '{"pending":true}';
2
3
  export const CANCELED_CHAT_MESSAGE = 'Stopped the current run. Send a follow-up to steer the next step.';
3
4
  export const HOMEBREW_BIN_DIRS = ['/opt/homebrew/bin', '/usr/local/bin'];
4
5
  export const SAFE_BIN_NAME = /^[A-Za-z0-9._-]+$/;
@@ -1,7 +1,7 @@
1
1
  import crypto from 'hypercore-crypto';
2
- import { parseBlobReferenceCoreKey } from './files/index.js';
2
+ import { copyBlob, copyChunks, stripped } from './chat-copy.js';
3
3
  import { Mesh } from './mesh.js';
4
- import { ACTIVE_AGENTS, ACTIVE_CHATS, ACTIVE_CHAT_GROUPS, ACTIVE_TOOL_CONFIGS_BY_AGENT, AGENTS, CHUNKS, CHUNKS_BY_CHAT, KNOWLEDGE } from './collections.js';
4
+ import { ACTIVE_AGENTS, ACTIVE_CHATS, ACTIVE_CHAT_GROUPS, ACTIVE_TOOL_CONFIGS_BY_AGENT, AGENTS, KNOWLEDGE } from './collections.js';
5
5
  const MIGRATED_SUFFIX = ' (migrated)';
6
6
  export const NO_ARCHIVE_HELD = 'No archive is held for this mesh';
7
7
  export async function withArchivedMesh(row, opts, fn) {
@@ -68,7 +68,7 @@ export async function migrateContents(from, into) {
68
68
  }
69
69
  await batch.flush();
70
70
  for (const chat of chats) {
71
- await migrateChunks(snap, chat.id, { from, into });
71
+ await copyChunks(snap, chat.id, { from, into });
72
72
  }
73
73
  let carried = 0;
74
74
  for (const row of knowledge) {
@@ -114,45 +114,6 @@ async function migrateAgents(snap, into, batch) {
114
114
  async function alreadyHeld(into, row) {
115
115
  return !!(await into.view.get(AGENTS, { id: row.id }));
116
116
  }
117
- async function migrateChunks(snap, chatId, { from, into }) {
118
- const chunks = await snap
119
- .find(CHUNKS_BY_CHAT, { gte: { chatId }, lte: { chatId } })
120
- .toArray();
121
- const batch = into.batch();
122
- for (const chunk of chunks) {
123
- if (await into.view.get(CHUNKS, { id: chunk.id }))
124
- continue;
125
- const { seq, updatedAt, attachment, ...op } = stripped(chunk);
126
- if (!attachment) {
127
- batch.dispatch('append-chunk', op);
128
- continue;
129
- }
130
- const blobId = await copyBlob(from, into, attachment.blobId);
131
- if (!blobId) {
132
- continue;
133
- }
134
- batch.dispatch('append-chunk', { ...op, attachment: { ...attachment, blobId } });
135
- await batch.flush();
136
- await into.fileIndex?.record([{ ...chunk, attachment: { ...attachment, blobId } }]);
137
- }
138
- await batch.flush();
139
- }
140
- async function copyBlob(from, into, reference) {
141
- if (parseBlobReferenceCoreKey(reference) === undefined)
142
- return reference;
143
- let bytes;
144
- try {
145
- bytes = await from.files.readBytes(reference, { wait: false });
146
- }
147
- catch {
148
- return null;
149
- }
150
- return (await into.files.put(bytes)).reference;
151
- }
152
- function stripped(row) {
153
- const { version: _version, ...rest } = row;
154
- return rest;
155
- }
156
117
  async function liveKnowledge(snap) {
157
118
  const rows = await snap.find(KNOWLEDGE).toArray();
158
119
  return rows.filter((row) => !row.deletedAt);
@@ -25,15 +25,22 @@ class ChatActivityCatalog {
25
25
  _lock;
26
26
  _chats;
27
27
  _head;
28
+ _forwards;
28
29
  constructor() {
29
30
  this._lock = new ScopeLock();
30
31
  this._chats = new Map();
31
32
  this._head = null;
33
+ this._forwards = 0;
32
34
  }
33
35
  async list(store, chatIds) {
34
36
  await this._lock.lock();
35
37
  try {
36
38
  const head = store.view.db.head();
39
+ const forwards = store.autobee.stats.fastForwards;
40
+ if (forwards !== this._forwards) {
41
+ this._head = null;
42
+ }
43
+ this._forwards = forwards;
37
44
  const snap = store.view.snapshot();
38
45
  try {
39
46
  const chats = await snap.find(ACTIVE_CHATS).toArray();
@@ -95,17 +102,23 @@ class ChatActivityCatalog {
95
102
  }
96
103
  async _applyChanges(snap, from, activeChatIds) {
97
104
  const chunksByChat = new Map();
98
- for await (const change of snap.changes({ from })) {
99
- if (change.collection !== CHUNKS)
100
- continue;
101
- if (change.type === 'delete')
102
- return false;
103
- if (!activeChatIds.has(change.value.chatId)) {
104
- continue;
105
+ try {
106
+ for await (const change of snap.changes({ from })) {
107
+ if (change.collection !== CHUNKS)
108
+ continue;
109
+ if (change.type === 'delete')
110
+ return false;
111
+ if (!activeChatIds.has(change.value.chatId)) {
112
+ continue;
113
+ }
114
+ const chunks = chunksByChat.get(change.value.chatId) ?? [];
115
+ chunks.push(change.value);
116
+ chunksByChat.set(change.value.chatId, chunks);
105
117
  }
106
- const chunks = chunksByChat.get(change.value.chatId) ?? [];
107
- chunks.push(change.value);
108
- chunksByChat.set(change.value.chatId, chunks);
118
+ }
119
+ catch (err) {
120
+ logger.warn('chat-activity', 'diff from the cached head failed, rebuilding', err);
121
+ return false;
109
122
  }
110
123
  for (const [chatId, chunks] of chunksByChat) {
111
124
  const activity = this._chats.get(chatId);
@@ -0,0 +1,24 @@
1
+ import type HyperDB from 'hyperdb';
2
+ import type { Mesh } from './mesh.ts';
3
+ export interface MeshCopy {
4
+ readonly from: Mesh;
5
+ readonly into: Mesh;
6
+ }
7
+ export interface ChatMoveCopy extends MeshCopy {
8
+ readonly chatId: string;
9
+ readonly originDeviceId: Buffer;
10
+ readonly references: Map<string, string>;
11
+ }
12
+ export declare const CHUNK_IN_ANOTHER_CHAT = "the target already holds this chat under another id";
13
+ export declare function copyChunks(snap: HyperDB, chatId: string, { from, into }: MeshCopy): Promise<void>;
14
+ export declare function copyMovedChunks(snap: HyperDB, chatId: string, copy: ChatMoveCopy): Promise<number>;
15
+ export declare function copyMovedKnowledge(snap: HyperDB, chatId: string, copy: ChatMoveCopy): Promise<void>;
16
+ export declare function movedBlob({ from, into, references }: ChatMoveCopy, { blobId }: BlobHolder): Promise<string>;
17
+ interface BlobHolder {
18
+ readonly blobId: string;
19
+ }
20
+ export declare function copyBlob(from: Mesh, into: Mesh, reference: string): Promise<string | null>;
21
+ export declare function stripped<T extends {
22
+ version?: number;
23
+ }>(row: T): Omit<T, 'version'>;
24
+ export {};
@@ -0,0 +1,115 @@
1
+ import b4a from 'b4a';
2
+ import { PENDING_BLOB_REFERENCE, isPendingBlobReference, parseBlobReference } from './files/store/index.js';
3
+ import { inlineReference } from './files/store/inline.js';
4
+ 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
+ export async function copyChunks(snap, chatId, { from, into }) {
7
+ const batch = into.batch();
8
+ for (const chunk of await chunksOf(snap, chatId)) {
9
+ if (await into.view.get(CHUNKS, { id: chunk.id }))
10
+ continue;
11
+ const { seq, updatedAt, attachment, ...op } = stripped(chunk);
12
+ if (!attachment) {
13
+ batch.dispatch('append-chunk', op);
14
+ continue;
15
+ }
16
+ const blobId = await copyBlob(from, into, attachment.blobId);
17
+ if (!blobId) {
18
+ continue;
19
+ }
20
+ batch.dispatch('append-chunk', { ...op, attachment: { ...attachment, blobId } });
21
+ await batch.flush();
22
+ await into.fileIndex?.record([{ ...chunk, attachment: { ...attachment, blobId } }]);
23
+ }
24
+ await batch.flush();
25
+ }
26
+ export async function copyMovedChunks(snap, chatId, copy) {
27
+ const { into, originDeviceId } = copy;
28
+ let copied = 0;
29
+ const batch = into.batch();
30
+ for (const chunk of await chunksOf(snap, chatId)) {
31
+ if (await heldInTarget(into, { collection: CHUNKS, id: chunk.id, chatId: copy.chatId })) {
32
+ continue;
33
+ }
34
+ const { seq, updatedAt, attachment, ...op } = stripped(chunk);
35
+ copied++;
36
+ if (!attachment) {
37
+ batch.dispatch('append-chunk', { ...op, chatId: copy.chatId });
38
+ continue;
39
+ }
40
+ const blobId = attachment.deletedAt
41
+ ? removedReference(attachment)
42
+ : await movedBlob(copy, attachment);
43
+ const moved = {
44
+ ...op,
45
+ chatId: copy.chatId,
46
+ originDeviceId,
47
+ attachment: { ...attachment, blobId }
48
+ };
49
+ batch.dispatch('append-chunk', moved);
50
+ await batch.flush();
51
+ if (!isPendingBlobReference(blobId)) {
52
+ await into.fileIndex?.record([{ ...chunk, ...moved }]);
53
+ }
54
+ }
55
+ await batch.flush();
56
+ return copied;
57
+ }
58
+ export async function copyMovedKnowledge(snap, chatId, copy) {
59
+ const batch = copy.into.batch();
60
+ const inChat = { gte: { chatId }, lte: { chatId } };
61
+ for (const row of await snap.find(KNOWLEDGE_BY_CHAT, inChat).toArray()) {
62
+ if (await heldInTarget(copy.into, { collection: KNOWLEDGE, id: row.id, chatId: copy.chatId })) {
63
+ continue;
64
+ }
65
+ const blobId = row.deletedAt ? removedReference(row) : await movedBlob(copy, row);
66
+ if (isPendingBlobReference(blobId)) {
67
+ continue;
68
+ }
69
+ batch.dispatch('add-knowledge', {
70
+ knowledge: { ...stripped(row), chatId: copy.chatId, blobId }
71
+ });
72
+ }
73
+ await batch.flush();
74
+ }
75
+ export async function movedBlob({ from, into, references }, { blobId }) {
76
+ const known = references.get(blobId);
77
+ if (known) {
78
+ return known;
79
+ }
80
+ const moved = (await copyBlob(from, into, blobId)) ?? PENDING_BLOB_REFERENCE;
81
+ if (!isPendingBlobReference(moved)) {
82
+ references.set(blobId, moved);
83
+ }
84
+ return moved;
85
+ }
86
+ function removedReference({ mimeType }) {
87
+ return inlineReference(b4a.alloc(0), mimeType);
88
+ }
89
+ async function heldInTarget(into, { collection, id, chatId }) {
90
+ const existing = await into.view.get(collection, { id });
91
+ if (existing && existing.chatId !== chatId) {
92
+ throw new Error(CHUNK_IN_ANOTHER_CHAT);
93
+ }
94
+ return !!existing;
95
+ }
96
+ function chunksOf(snap, chatId) {
97
+ return snap.find(CHUNKS_BY_CHAT, { gte: { chatId }, lte: { chatId } }).toArray();
98
+ }
99
+ export async function copyBlob(from, into, reference) {
100
+ let bytes;
101
+ try {
102
+ if (parseBlobReference(reference).inline) {
103
+ return reference;
104
+ }
105
+ bytes = await from.files.readBytes(reference, { wait: false });
106
+ }
107
+ catch {
108
+ return null;
109
+ }
110
+ return (await into.files.put(bytes)).reference;
111
+ }
112
+ export function stripped(row) {
113
+ const { version: _version, ...rest } = row;
114
+ return rest;
115
+ }