@qvac/core 0.11.0 → 0.11.2

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 (104) hide show
  1. package/CHANGELOG.md +148 -1
  2. package/README.md +19 -16
  3. package/dist-lib/index.d.ts +1 -0
  4. package/dist-lib/index.js +1 -0
  5. package/dist-lib/lib/api/chunk-delta.d.ts +6 -2
  6. package/dist-lib/lib/api/chunk-delta.js +69 -7
  7. package/dist-lib/lib/api/chunks.js +10 -4
  8. package/dist-lib/lib/api/config.d.ts +4 -1
  9. package/dist-lib/lib/api/config.js +23 -4
  10. package/dist-lib/lib/api/devices.js +3 -1
  11. package/dist-lib/lib/api/rag.js +11 -7
  12. package/dist-lib/lib/assistant/harness.d.ts +3 -1
  13. package/dist-lib/lib/assistant/harness.js +10 -0
  14. package/dist-lib/lib/assistant/history.d.ts +1 -0
  15. package/dist-lib/lib/assistant/history.js +9 -3
  16. package/dist-lib/lib/assistant/message.js +2 -2
  17. package/dist-lib/lib/assistant-tree.d.ts +2 -0
  18. package/dist-lib/lib/assistant-tree.js +5 -3
  19. package/dist-lib/lib/assistant.d.ts +6 -1
  20. package/dist-lib/lib/assistant.js +77 -24
  21. package/dist-lib/lib/client.js +10 -1
  22. package/dist-lib/lib/compaction.d.ts +2 -1
  23. package/dist-lib/lib/compaction.js +14 -4
  24. package/dist-lib/lib/constants.d.ts +3 -0
  25. package/dist-lib/lib/constants.js +3 -0
  26. package/dist-lib/lib/core/archived-mesh.js +1 -0
  27. package/dist-lib/lib/core/chat-activity.js +12 -15
  28. package/dist-lib/lib/core/chunk.d.ts +14 -3
  29. package/dist-lib/lib/core/chunk.js +112 -22
  30. package/dist-lib/lib/core/collections.d.ts +1 -0
  31. package/dist-lib/lib/core/collections.js +1 -0
  32. package/dist-lib/lib/core/config-value.d.ts +6 -0
  33. package/dist-lib/lib/core/config-value.js +14 -0
  34. package/dist-lib/lib/core/contract/chat.d.ts +1 -0
  35. package/dist-lib/lib/core/contract/chat.js +8 -1
  36. package/dist-lib/lib/core/contract/chunks.js +20 -6
  37. package/dist-lib/lib/core/contract/compute.d.ts +1 -1
  38. package/dist-lib/lib/core/contract/compute.js +2 -1
  39. package/dist-lib/lib/core/contract/devices.js +3 -2
  40. package/dist-lib/lib/core/departures.js +1 -0
  41. package/dist-lib/lib/core/devices.d.ts +2 -1
  42. package/dist-lib/lib/core/devices.js +4 -2
  43. package/dist-lib/lib/core/files/attachments.js +3 -3
  44. package/dist-lib/lib/core/files/index.d.ts +1 -1
  45. package/dist-lib/lib/core/files/index.js +3 -2
  46. package/dist-lib/lib/core/files/processing/index.d.ts +1 -0
  47. package/dist-lib/lib/core/files/processing/index.js +8 -0
  48. package/dist-lib/lib/core/files/processing/settle.d.ts +1 -0
  49. package/dist-lib/lib/core/files/processing/settle.js +20 -13
  50. package/dist-lib/lib/core/files/rag/index.d.ts +1 -1
  51. package/dist-lib/lib/core/files/rag/index.js +1 -1
  52. package/dist-lib/lib/core/files/rag/retrieval/full-text.d.ts +1 -0
  53. package/dist-lib/lib/core/files/rag/retrieval/full-text.js +4 -1
  54. package/dist-lib/lib/core/hosted-agents.d.ts +3 -0
  55. package/dist-lib/lib/core/hosted-agents.js +19 -0
  56. package/dist-lib/lib/core/inference-calls-receiver.js +2 -2
  57. package/dist-lib/lib/core/known-sender.d.ts +3 -0
  58. package/dist-lib/lib/core/known-sender.js +26 -0
  59. package/dist-lib/lib/core/local/index.d.ts +2 -0
  60. package/dist-lib/lib/core/local/index.js +17 -10
  61. package/dist-lib/lib/core/mesh.d.ts +5 -1
  62. package/dist-lib/lib/core/mesh.js +6 -6
  63. package/dist-lib/lib/core/migrations/chat-chunks.d.ts +4 -0
  64. package/dist-lib/lib/core/migrations/chat-chunks.js +43 -0
  65. package/dist-lib/lib/core/notification.js +16 -13
  66. package/dist-lib/lib/core/skill-overlay-receiver.js +2 -2
  67. package/dist-lib/lib/core/skill-secrets.js +2 -2
  68. package/dist-lib/lib/core.d.ts +17 -1
  69. package/dist-lib/lib/core.js +55 -5
  70. package/dist-lib/lib/credential-pusher.d.ts +11 -7
  71. package/dist-lib/lib/credential-pusher.js +40 -8
  72. package/dist-lib/lib/device-tree.d.ts +18 -0
  73. package/dist-lib/lib/device-tree.js +32 -0
  74. package/dist-lib/lib/integrations/setup-routes.js +7 -5
  75. package/dist-lib/lib/kv-cache-retention.d.ts +34 -0
  76. package/dist-lib/lib/kv-cache-retention.js +98 -0
  77. package/dist-lib/schema/content.js +2 -1
  78. package/dist-lib/schema/engine.js +20 -3
  79. package/dist-lib/schema/field-order.js +8 -1
  80. package/dist-lib/schema/local.js +7 -3
  81. package/dist-lib/schema/qvac.js +23 -4
  82. package/dist-lib/spec/hrpc/messages.js +1240 -1194
  83. package/dist-lib/spec/hyperschema/index.js +1240 -1194
  84. package/dist-lib/spec/hyperschema/schema.json +49 -1
  85. package/dist-lib/spec/hyperschema/types.d.ts +12 -1
  86. package/dist-lib/spec/local/hyperdb/messages.js +70 -20
  87. package/dist-lib/spec/local/hyperschema/index.js +36 -11
  88. package/dist-lib/spec/local/hyperschema/schema.json +21 -1
  89. package/dist-lib/spec/local/hyperschema/types.d.ts +5 -1
  90. package/dist-lib/spec/mesh/hyperdb/db.json +17 -1
  91. package/dist-lib/spec/mesh/hyperdb/index.js +83 -2
  92. package/dist-lib/spec/mesh/hyperdb/messages.js +602 -264
  93. package/dist-lib/spec/mesh/hyperdispatch/dispatch.json +7 -1
  94. package/dist-lib/spec/mesh/hyperdispatch/index.js +18 -1
  95. package/dist-lib/spec/mesh/hyperdispatch/messages.js +137 -14
  96. package/dist-lib/spec/mesh/hyperschema/index.js +137 -14
  97. package/dist-lib/spec/mesh/hyperschema/schema.json +79 -1
  98. package/dist-lib/spec/mesh/hyperschema/types.d.ts +21 -1
  99. package/package.json +13 -9
  100. package/tui/app.mjs +743 -266
  101. package/tui/boot.mjs +2 -2
  102. package/tui/lib/connect-sheet.mjs +350 -0
  103. package/tui/lib/setup.mjs +59 -25
  104. package/tui/lib/skill-connect.mjs +145 -0
package/CHANGELOG.md CHANGED
@@ -13,6 +13,151 @@ release.
13
13
 
14
14
  ## [Unreleased]
15
15
 
16
+ ## [0.11.2] - 2026-10-28
17
+
18
+ ### Added
19
+
20
+ - A chat's KV cache is deleted once the chat has been idle for the retention, so a device no
21
+ longer keeps the cache of every chat it ever ran. The chat itself is untouched; its next message
22
+ primes from history. An app sets its default with `kvCacheRetentionMs` on `assistantChild` (14
23
+ days without it, `0` for Never), and a device overrides it with `kvCache.retentionDays`. (#589)
24
+
25
+ ```js
26
+ import { assistantChild } from '@qvac/core'
27
+ import { KV_CACHE_RETENTION_KEY } from '@qvac/core/constants'
28
+
29
+ assistantChild({ harness, kvCacheRetentionMs: 30 * 24 * 60 * 60_000 })
30
+ await engine.configSet({ key: KV_CACHE_RETENTION_KEY, value: 7 })
31
+ ```
32
+
33
+ - Every credential a skill declares is pushed to the harness, not only the built-in keys and
34
+ OAuth tokens, so a skill with its own key no longer reads needs-setup for good and needs no core
35
+ release. Where a value may be sent is unchanged, and an overlay skill gets no credential. (#596)
36
+ - A credential with no setup block and no token provider gets a one-field token route named after
37
+ its key, so any setup UI can set it. (#591)
38
+ - `duck` sets a skill up through one sheet, opened by `/skill <name>`. (#592)
39
+
40
+ ### Changed
41
+
42
+ - `toolResult.result` is required on the wire, so a tool result of `false`, `0` or `''` reads
43
+ back as written from `listChunks` and `chunksWatch` instead of `null`. A device on 0.11.0 or
44
+ earlier, and a result one of those releases wrote, still read `null`. (#559)
45
+
46
+ ```js
47
+ // 0.11.1
48
+ { type: 'tool-result', toolResult: { name } }
49
+ // 0.11.2
50
+ { type: 'tool-result', toolResult: { name, result: null } }
51
+ ```
52
+
53
+ ### Removed
54
+
55
+ - `duck`'s `/cred`: every value is set through its skill's sheet. (#593)
56
+
57
+ ### Fixed
58
+
59
+ - Chat activity no longer diffs across a fast-forward it has not counted yet. It
60
+ dropped its cached view head only once `fastForwards` moved, which can be
61
+ after the view has landed on another core, and a diff from the old head read
62
+ every node of the new view. It now drops the head whenever the view is on
63
+ another core, as `chunksDeltaWatch` does. (#623)
64
+ - A device that does not hold a mesh no longer downloads most of it to show chat
65
+ activity and notifications. Both read a few chunk types per chat, each through
66
+ its type index and then row by row from `@qvac/chunks`; they now read the
67
+ chat's range of `@qvac/chat-chunks` once and keep those types, where that
68
+ range is whole. A member joining a 170-chat mesh with both open downloaded
69
+ about 39,000 blocks (155 MB) instead of 258,000 (640 MB), and on a device that
70
+ holds the mesh their first frames take 2.2 s and 3.7 s instead of 5.8 s and
71
+ 9.8 s. (#624)
72
+ - `compactChat` folds whole turns, so a chat whose messages were queued no longer keeps answers
73
+ without their questions. (#607)
74
+ - A run whose injected excerpts overflow the model window, with no older turns to fold, is retried
75
+ with half the excerpts instead of failing. (#599)
76
+ - `ragSearch` on a remote agent host waits for an attached file still replicating to it instead of
77
+ answering that the file is still being indexed. (#562)
78
+ - A chat whose first message carries a document is titled from the words the user typed, not the
79
+ document text. (#516)
80
+ - A re-homed agent's skill values are retried until the new host takes them; a host that refused
81
+ before it replicated the re-home left them unset. (#478)
82
+
83
+ ## [0.11.1] - 2026-10-26
84
+
85
+ ### Added
86
+
87
+ - `deviceTree(transport, { core, assistant, office, logger })` boots Core and
88
+ the assistant under one supervisor, the way the app does. (#544)
89
+ - The `reindex-chat-chunks` op copies a chat written before this release into
90
+ `@qvac/chat-chunks`. A build older than this one halts on it, so a device
91
+ sends it only once the published version floor shuts out every app release
92
+ before 0.21.0, the first whose core applies it. A build under the floor opens
93
+ no mesh, so none can halt on it; publish `>=0.21.0` once that release is in
94
+ both stores. (#491)
95
+ - A device's row in the account carries `customModels`: the label, task type
96
+ and size of each custom model it has. A paired desktop showed a custom model
97
+ added on the phone by its `custom:…` id, as Other and of unknown size, and
98
+ counted it outside the phone's LLMs. `saveDeviceCapabilities` takes the field,
99
+ and the assistant reports it again when a custom model is renamed. (#556)
100
+
101
+ ### Changed
102
+
103
+ - `chunksDeltaWatch` reads only the rows that changed after its opening reset,
104
+ so an update no longer costs the whole chat. Frames are unchanged; a
105
+ selection with `limit` is still read whole. (#538)
106
+ - Injection-mode `ragSearch` sizes its excerpts to a quarter of the agent's
107
+ context window, capped at the 3072-token default, so a small window gets
108
+ fewer excerpts instead of overflowing. (#588)
109
+ - `hypercore` 11.39 and `hypercore-storage` 3.4, for a working purge. (#539)
110
+ - `hypercore-blob-server` 1.15.1 keeps its socket listening across a suspend,
111
+ so resume keeps the port and every minted link, and replaces the local patch.
112
+ (#561)
113
+
114
+ ### Fixed
115
+
116
+ - A member whose only device in a shared mesh comes back far behind
117
+ fast-forwards instead of replaying everything it missed (183 s to 3.9 s on a
118
+ mesh about 6,900 flushes ahead): a shared mesh trusts every member's live
119
+ devices, not only this member's own, and never a device admitted unlinked. A
120
+ compute mesh still trusts only its own member's devices. (#492)
121
+ - Opening a chat on a device that does not hold the mesh no longer downloads most
122
+ of the mesh. Each chunk is also kept in `@qvac/chat-chunks`, keyed by chat and
123
+ `seq`, and a chat read is one range of it: a 1,100-chunk chat fetched about
124
+ 1,000 blocks instead of 100,000. Once the published floor is at app 0.21.0 or
125
+ later, the chats written before this release are copied in the background, one
126
+ op per chat; until then, or while an older build still writes to a chat, it
127
+ reads the way it did before. A chat an older build purged also loses the rows
128
+ that build left in `@qvac/chat-chunks`. (#490, #491)
129
+ - `configGet` and `configWatch` return a stored `false`, `0` or `''` as written
130
+ instead of `null`. A device on 0.11.0 or earlier, a value one of those
131
+ releases wrote, and a downgrade to one still read them as `null`. (#546)
132
+ - A message's audio attachment is presented to the model as a transcript of its
133
+ speech only, so a tool that reads the audio itself, such as music
134
+ transcription, is used again. (#337)
135
+ - The assistant reports an agent it hosts in a shared mesh as soon as this
136
+ device has joined it. A device still joining had its report refused and never
137
+ reported again. (#324)
138
+ - `removeDevice` on the account revokes the device in a shared mesh whose row
139
+ for it arrives after the removal. Before, it stayed a writer there. (#547)
140
+ - `inferenceCalls` and the skill routes (`pushSkillSecret`,
141
+ `listManagedSkills`, `readSkillFile`, `writeSkillFile`, `copySkillForEdit`,
142
+ `deleteOverlaySkill`) from a device that has just paired no longer fail with
143
+ `PEER_SENDER_REVOKED`: the host waits up to 30 s for the new device's row.
144
+ (#544)
145
+ - Core no longer dies of an unhandled `REQUEST_CANCELLED` when a fast-forward
146
+ cancels the read that follows a joined mesh's shared meshes. (#474)
147
+ - A device restarted while its `joinMesh` is still `joining` boots the mesh
148
+ from the head its invite carried, instead of replaying it from its first
149
+ block, which on a big mesh took minutes. (#515)
150
+ - `meshInvite` on a device that just recovered with `recoverAccount` waits for
151
+ its member link instead of failing with "This device cannot reach its account
152
+ to check". (#540)
153
+ - A question sent while the previous run was still answering is shown to the
154
+ model after that answer, not before it, once compaction folds the earlier
155
+ turns. The run's reply and its file turns were sorted behind the new question,
156
+ and the model answered as if they came later (QVAC-24502). A file a run
157
+ produced is now replayed right behind that run's answer instead of at the end
158
+ of the chat; an existing chat with such a turn re-reads once after the update.
159
+ (#584)
160
+
16
161
  ## [0.11.0] - 2026-10-23
17
162
 
18
163
  ### Added
@@ -1925,7 +2070,9 @@ Published under the `release-0.1` dist-tag.
1925
2070
  await assistant.ready()
1926
2071
  ```
1927
2072
 
1928
- [Unreleased]: https://github.com/tetherto/qvac-core/compare/v0.11.0...HEAD
2073
+ [Unreleased]: https://github.com/tetherto/qvac-core/compare/v0.11.2...HEAD
2074
+ [0.11.2]: https://github.com/tetherto/qvac-core/compare/v0.11.1...v0.11.2
2075
+ [0.11.1]: https://github.com/tetherto/qvac-core/compare/v0.11.0...v0.11.1
1929
2076
  [0.11.0]: https://github.com/tetherto/qvac-core/compare/v0.10.4...v0.11.0
1930
2077
  [0.10.4]: https://github.com/tetherto/qvac-core/compare/v0.10.3...v0.10.4
1931
2078
  [0.10.3]: https://github.com/tetherto/qvac-core/compare/v0.10.2...v0.10.3
package/README.md CHANGED
@@ -661,19 +661,23 @@ skill's `allow_list` binds that key to the URL prefixes it may be sent to.
661
661
  Credentials are **per agent** (stored at `skills.<agentId>.<key>`), so two
662
662
  agents never share one connection.
663
663
 
664
- Fill a key with a slash command in the running TUI — see
665
- [The duck TUI](#the-duck-tui):
666
-
667
- - `/connect google` · `/connect spotify` · `/connect asana` · `/connect notion` — browser OAuth;
668
- the example stores the token and refreshes it on use.
669
- - `/cred <key> <value>` — set any credential key by hand, for a service with
670
- no built-in OAuth flow.
671
-
672
- `/connect google` needs `GOOGLE_OAUTH_CLIENT_ID` + `GOOGLE_OAUTH_CLIENT_SECRET`
673
- in env, `/connect spotify` needs `SPOTIFY_OAUTH_CLIENT_ID`, `/connect asana` needs
674
- `ASANA_OAUTH_CLIENT_ID` + `ASANA_OAUTH_CLIENT_SECRET` (an MCP-type app registered
675
- at app.asana.com); `/connect notion` needs nothing — its MCP server self-provisions
676
- a public client via dynamic registration (RFC 7591) + PKCE.
664
+ Set a skill up in the running TUI — see [The duck TUI](#the-duck-tui):
665
+
666
+ - `/skill <name>` — opens the skill's setup: what it needs, its fields, and the
667
+ button that finishes it. OAuth skills sign in through the browser and refresh
668
+ on use; a token skill saves its token; a folder skill checks the folder exists.
669
+ Secrets are masked while typed and never reach the transcript or ↑ history.
670
+ - `/skill on <name>` — turning on a skill that needs setup opens it first; the
671
+ skill turns on once the setup succeeds. `/skills` does the same on space.
672
+ - `/skill <name> set <field> [value]` — set one field from a script.
673
+ - `/skill <name> disconnect` — remove what the skill stored.
674
+ - `/connect <name>` is the same sheet, signing in straight away.
675
+
676
+ An OAuth skill asks for its own client app (Client ID and, unless it is
677
+ PKCE-only, Client Secret), and its sheet walks through creating one. Leave the
678
+ fields blank to use `<PROVIDER>_OAUTH_CLIENT_ID` + `<PROVIDER>_OAUTH_CLIENT_SECRET`
679
+ from the env when both are set. Notion needs nothing — its MCP server
680
+ self-provisions a public client via dynamic registration (RFC 7591) + PKCE.
677
681
 
678
682
  ### Notion
679
683
 
@@ -681,13 +685,12 @@ Notion runs over its official MCP server (`https://mcp.notion.com/mcp`) via
681
685
  the `mcp_call` tool, under the credential key `notion_mcp_access_token`:
682
686
 
683
687
  ```
684
- /connect notion # authorize in the browser, pick the pages to share
685
- /skill on notion # if the agent's skill scope is 'selected'
688
+ /skill on notion # sign in through the browser, then the skill turns on
686
689
  ```
687
690
 
688
691
  Then ask the assistant anything Notion — it loads the `notion` skill and calls
689
692
  `mcp_call` itself; the session handshake and auth are handled for you. A `401`
690
- in a tool result means the token expired — run `/connect notion` again.
693
+ in a tool result means the token expired — run `/skill notion connect` again.
691
694
 
692
695
  ## Development
693
696
 
@@ -5,6 +5,7 @@ export { Client } from './lib/client.ts';
5
5
  export { AssistantClient } from './lib/assistant-client.ts';
6
6
  export { harnessDeleteModel, harnessListModels, harnessSkillCatalog, harnessTools, QvacAssistant, type Harness, type ListModelsOptions, type ModelInfo, type ModelType, type Skill, type ToolCatalogEntry } from './lib/assistant.ts';
7
7
  export { assistantChild, assistantTree, type AssistantChildOptions, type AssistantTreeOptions, type EmbedderFactory, type HarnessContext, type HarnessFactory } from './lib/assistant-tree.ts';
8
+ export { deviceTree, type DeviceTree, type DeviceTreeOptions } from './lib/device-tree.ts';
8
9
  export { ASSISTANT_WAKEUP_LINGER_MS, createAssistantSuspendLifecycle, type AssistantSuspendLifecycleOptions } from './lib/suspend-lifecycle.ts';
9
10
  export { default as Supervisor } from 'bare-supervisor';
10
11
  export type { AssistantDiagnostics, DiagnosticsSlice, HarnessDiagnostics, RunSummary } from './lib/diagnostics.ts';
package/dist-lib/index.js CHANGED
@@ -3,6 +3,7 @@ export { Client } from './lib/client.js';
3
3
  export { AssistantClient } from './lib/assistant-client.js';
4
4
  export { harnessDeleteModel, harnessListModels, harnessSkillCatalog, harnessTools, QvacAssistant } from './lib/assistant.js';
5
5
  export { assistantChild, assistantTree } from './lib/assistant-tree.js';
6
+ export { deviceTree } from './lib/device-tree.js';
6
7
  export { ASSISTANT_WAKEUP_LINGER_MS, createAssistantSuspendLifecycle } from './lib/suspend-lifecycle.js';
7
8
  export { default as Supervisor } from 'bare-supervisor';
8
9
  export { clientSessions, duplexPair } from '@qvac/harness/transport';
@@ -1,7 +1,11 @@
1
1
  import { type Readable } from 'streamx';
2
- import type { AssistantChunk, AssistantChunkDelta, AssistantChunkList } from '../../spec/hyperschema/types.d.ts';
2
+ import type { LoggerInterface } from '@qvac/logging';
3
+ import type { AssistantChunk, AssistantChunkDelta } from '../../spec/hyperschema/types.d.ts';
3
4
  import type { WatchStream } from '../../spec/capabilities.d.ts';
5
+ import { type ListChunksInput } from '../core/chunk.ts';
6
+ import type { Mesh } from '../core/mesh.ts';
4
7
  type Rows = ReadonlyMap<string, AssistantChunk>;
5
8
  export declare function chunkDelta(prev: Rows | null, next: ReadonlyArray<AssistantChunk>): AssistantChunkDelta;
6
- export declare function chunkDeltaStream(lists: Readable & AsyncIterable<AssistantChunkList>): Readable & WatchStream<AssistantChunkDelta>;
9
+ export declare function chunkDeltas(selection: ListChunksInput, log: LoggerInterface | null): (mesh: Mesh) => Promise<AssistantChunkDelta>;
10
+ export declare function chunkDeltaStream(frames: Readable & AsyncIterable<AssistantChunkDelta>): Readable & WatchStream<AssistantChunkDelta>;
7
11
  export {};
@@ -1,4 +1,7 @@
1
+ import b4a from 'b4a';
1
2
  import { pipeline, Transform } from 'streamx';
3
+ import { linkChunks, listChunks, recordLinks, selectsChunk } from '../core/chunk.js';
4
+ import { CHUNKS } from '../core/collections.js';
2
5
  import { frameReadable } from '../frame-readable.js';
3
6
  import { snapshotEquals } from './watchable.js';
4
7
  export function chunkDelta(prev, next) {
@@ -14,13 +17,72 @@ export function chunkDelta(prev, next) {
14
17
  }
15
18
  return { reset: false, chunks: upserts, removed, count };
16
19
  }
17
- export function chunkDeltaStream(lists) {
18
- let prev = null;
20
+ export function chunkDeltas(selection, log) {
21
+ let rows = null;
22
+ let head = null;
23
+ return async (mesh) => {
24
+ const current = mesh.view.db.head();
25
+ const from = head && current && b4a.equals(head.key, current.key) ? head : null;
26
+ head = current;
27
+ const changed = rows && from && selection.limit === undefined
28
+ ? await changedRows(mesh, { from, selection, rows, log })
29
+ : null;
30
+ if (rows === null || changed === null) {
31
+ const next = await listChunks(mesh, selection);
32
+ const delta = chunkDelta(rows, next);
33
+ const sent = new Set(delta.chunks?.map((chunk) => chunk.id));
34
+ rows = new Map(next.map((chunk) => [chunk.id, chunk]));
35
+ await recordLinks(mesh, next.filter((chunk) => sent.has(chunk.id)));
36
+ return delta;
37
+ }
38
+ const delta = applyChanged(rows, changed, selection.reverse === true);
39
+ await recordLinks(mesh, delta.chunks);
40
+ return delta;
41
+ };
42
+ }
43
+ function applyChanged(rows, { upserts, removed }, reverse) {
44
+ for (const id of removed) {
45
+ rows.delete(id);
46
+ }
47
+ for (const chunk of upserts) {
48
+ rows.set(chunk.id, chunk);
49
+ }
50
+ const count = rows.size;
51
+ const reset = upserts.length + removed.length > count / 2;
52
+ const chunks = (reset ? [...rows.values()] : upserts).sort((a, b) => reverse ? b.seq - a.seq : a.seq - b.seq);
53
+ return { reset, chunks, removed: reset ? [] : removed, count };
54
+ }
55
+ async function changedRows(mesh, { from, selection, rows, log }) {
56
+ const snap = mesh.view.snapshot();
57
+ const upserts = [];
58
+ const removed = [];
59
+ try {
60
+ for await (const change of snap.changes({ from })) {
61
+ if (change.collection !== CHUNKS)
62
+ continue;
63
+ if (change.type === 'insert' && selectsChunk(selection, change.value)) {
64
+ upserts.push(change.value);
65
+ }
66
+ else if (rows.has(change.value.id)) {
67
+ removed.push(change.value.id);
68
+ }
69
+ }
70
+ }
71
+ catch (err) {
72
+ log?.warn(['api', 'watch'], 'chunk diff from the held head failed, reading in full', err);
73
+ return null;
74
+ }
75
+ finally {
76
+ await snap.close();
77
+ }
78
+ return {
79
+ upserts: linkChunks(mesh, upserts).filter((chunk) => !snapshotEquals(chunk, rows.get(chunk.id))),
80
+ removed
81
+ };
82
+ }
83
+ export function chunkDeltaStream(frames) {
19
84
  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]));
85
+ transform(delta, cb) {
24
86
  if (!delta.reset && delta.chunks?.length === 0 && delta.removed?.length === 0) {
25
87
  cb(null);
26
88
  return;
@@ -28,6 +90,6 @@ export function chunkDeltaStream(lists) {
28
90
  cb(null, delta);
29
91
  }
30
92
  });
31
- return frameReadable(pipeline(lists, deltas, noop));
93
+ return frameReadable(pipeline(frames, deltas, noop));
32
94
  }
33
95
  function noop() { }
@@ -1,5 +1,5 @@
1
- import { appendChunk, listAttachmentsByKind, listChunks, listRunRequests, recordLinks, resolveApproval, updateChunk } from '../core/chunk.js';
2
- import { chunkDeltaStream } from './chunk-delta.js';
1
+ import { appendChunk, listAttachmentsByKind, listChunks, listRunRequests, readChunk, recordLinks, resolveApproval, updateChunk } from '../core/chunk.js';
2
+ import { chunkDeltaStream, chunkDeltas } from './chunk-delta.js';
3
3
  import { meshWatchable, requireMesh } from './current-mesh.js';
4
4
  import { bounds } from './range.js';
5
5
  export function createChunksApi(pool, deviceId, log) {
@@ -36,8 +36,14 @@ export function createChunksApi(pool, deviceId, log) {
36
36
  return { chunks: await recordLinks(mesh, chunks) };
37
37
  },
38
38
  chunksWatch,
39
- chunksDeltaWatch: (request) => chunkDeltaStream(chunksWatch(request)),
40
- runRequestsWatch: meshWatchable(pool, async (_request, mesh) => ({ chunks: await listRunRequests(mesh, deviceId) }), { name: 'runRequestsWatch', log })
39
+ chunksDeltaWatch: (request) => {
40
+ const deltas = chunkDeltas(chunkSelection(request), log);
41
+ const watch = meshWatchable(pool, (_request, mesh) => deltas(mesh), { name: 'chunksDeltaWatch', log });
42
+ return chunkDeltaStream(watch(request));
43
+ },
44
+ runRequestsWatch: meshWatchable(pool, async (_request, mesh) => ({
45
+ chunks: (await listRunRequests(mesh, deviceId)).map(readChunk)
46
+ }), { name: 'runRequestsWatch', log })
41
47
  };
42
48
  }
43
49
  function chunkSelection({ chatId, type, types, ...rest }) {
@@ -1,6 +1,9 @@
1
1
  import type { LoggerInterface } from '@qvac/logging';
2
+ import type { AssistantConfigValue } from '../../spec/hyperschema/types.d.ts';
2
3
  import type { openLocalStore } from '../core/local/index.ts';
3
- import type { CapabilityHandlers } from '../../spec/capabilities.d.ts';
4
+ import type { CapabilityHandlers, WatchStream } from '../../spec/capabilities.d.ts';
4
5
  type LocalStore = Awaited<ReturnType<typeof openLocalStore>>;
6
+ export declare function readConfigAnswer(answer: AssistantConfigValue): AssistantConfigValue;
7
+ export declare function readConfigFrames(source: WatchStream<AssistantConfigValue>): WatchStream<AssistantConfigValue>;
5
8
  export declare function createConfigApi(state: LocalStore, log: LoggerInterface | null): Pick<CapabilityHandlers, 'configGet' | 'configSet' | 'configWatch'>;
6
9
  export {};
@@ -1,15 +1,34 @@
1
+ import { Readable } from 'streamx';
1
2
  import { watchable } from './watchable.js';
3
+ import { frameReadable } from '../frame-readable.js';
4
+ import { configValue, readConfigValue } from '../core/config-value.js';
5
+ export function readConfigAnswer(answer) {
6
+ return { value: readConfigValue(answer) };
7
+ }
8
+ export function readConfigFrames(source) {
9
+ const output = new Readable({
10
+ destroy(cb) {
11
+ source.destroy();
12
+ cb(null);
13
+ }
14
+ });
15
+ output.on('error', noop);
16
+ source.on('data', (frame) => output.push(readConfigAnswer(frame)));
17
+ source.on('error', (err) => output.destroy(err));
18
+ source.on('end', () => output.push(null));
19
+ source.on('close', () => output.destroy());
20
+ return frameReadable(output);
21
+ }
2
22
  export function createConfigApi(state, log) {
3
23
  return {
4
24
  async configGet({ key }) {
5
- return { value: await state.get(key) };
25
+ return configValue(await state.get(key));
6
26
  },
7
27
  async configSet({ key, value }) {
8
28
  await state.set(key, value);
9
29
  return { ok: true };
10
30
  },
11
- configWatch: watchable(() => state, async ({ key }) => ({
12
- value: await state.get(key)
13
- }), { name: 'configWatch', log })
31
+ configWatch: watchable(() => state, async ({ key }) => configValue(await state.get(key)), { name: 'configWatch', log })
14
32
  };
15
33
  }
34
+ function noop() { }
@@ -14,6 +14,7 @@ function toEngineDevice(device, overrides = {}) {
14
14
  installedSkillNames: device.installedSkillNames ?? [],
15
15
  readySkillNames: device.readySkillNames,
16
16
  toolCatalog: device.toolCatalog,
17
+ customModels: device.customModels,
17
18
  installedModelNames: device.installedModelNames ?? [],
18
19
  cachedModelNames: device.cachedModelNames ?? [],
19
20
  capabilityProfile: device.capabilityProfile,
@@ -67,7 +68,8 @@ export function createDevicesApi(pool, { deviceId, log, removeWriter, renameLoca
67
68
  installedModelNames: input.installedModelNames ?? [],
68
69
  cachedModelNames: input.cachedModelNames ?? [],
69
70
  readySkillNames: input.readySkillNames ?? null,
70
- toolCatalog: input.toolCatalog ?? null
71
+ toolCatalog: input.toolCatalog ?? null,
72
+ customModels: input.customModels ?? null
71
73
  }, isAccount);
72
74
  return { ok: true };
73
75
  },
@@ -1,7 +1,7 @@
1
1
  import { toolsetEnabled } from '@qvac/harness/lib/tools/toolsets.ts';
2
2
  import { getAgent } from '../core/agent.js';
3
3
  import { getChat } from '../core/chat.js';
4
- import { isKnowledgeRoutedAttachment, fullTextBudgetChars, fullTextHits, retrieveRagKnowledge, searchRagChunks, referencesPendingFile, referencedDocuments } from '../core/files/index.js';
4
+ import { isKnowledgeRoutedAttachment, fullTextBudgetChars, fullTextHits, retrievalBudgetTokens, retrieveRagKnowledge, searchRagChunks, referencesPendingFile, referencedDocuments } from '../core/files/index.js';
5
5
  import { requireMesh } from './current-mesh.js';
6
6
  import { errorMessage } from '../guards.js';
7
7
  export const MAX_RAG_SEARCH_LIMIT = 20;
@@ -48,16 +48,15 @@ export function createRagApi(pool, { index, embedder, effectiveCtxSize = null })
48
48
  if (!toolMode && !agentAllowsRagSearch(agent)) {
49
49
  return respond({ enabled: false });
50
50
  }
51
- if (rows.length === 0) {
52
- return respond({});
53
- }
54
51
  const namedRows = referencedDocuments(query, rows.map((row) => ({ id: row.id, title: row.fileName })));
55
52
  const unscoped = namedRows.length ? namedRows : rows;
56
53
  const requested = scopeIds.size ? scopeRows : unscoped;
57
- const waiting = requested.filter((row) => !mesh.files.hydratedArtifact(row.id));
54
+ const waiting = scopeIds.size
55
+ ? [...scopeIds].filter((id) => !mesh.files.hydratedArtifact(id))
56
+ : requested.filter((row) => !mesh.files.hydratedArtifact(row.id)).map((row) => row.id);
58
57
  if (waiting.length) {
59
58
  try {
60
- await mesh.files.settle(waiting.map((row) => row.id));
59
+ await mesh.files.settle(waiting, { chatId });
61
60
  }
62
61
  catch (err) {
63
62
  mesh.log?.warn('rag', 'indexing settle failed', { err });
@@ -65,6 +64,9 @@ export function createRagApi(pool, { index, embedder, effectiveCtxSize = null })
65
64
  rows = await mesh.files.listKnowledge(chatId);
66
65
  scopeRows = rows.filter((row) => scopeIds.has(row.id));
67
66
  }
67
+ if (rows.length === 0) {
68
+ return respond({});
69
+ }
68
70
  const hasKnowledge = rows.length > 0;
69
71
  const vectorIndex = index(meshId);
70
72
  const embed = embedder(meshId);
@@ -169,12 +171,14 @@ export function createRagApi(pool, { index, embedder, effectiveCtxSize = null })
169
171
  }
170
172
  }
171
173
  try {
174
+ const ctxSize = effectiveCtxSize ? await effectiveCtxSize(agent) : 0;
172
175
  const result = await retrieveRagKnowledge({
173
176
  query,
174
177
  chatId,
175
178
  documents: hydratedDocuments,
176
179
  liveSourceIds: rows.map((row) => row.id),
177
- scopeDocumentIds: scopeDocumentIds.length > 0 ? scopeDocumentIds : undefined
180
+ scopeDocumentIds: scopeDocumentIds.length > 0 ? scopeDocumentIds : undefined,
181
+ chunkBudgetTokens: retrievalBudgetTokens(ctxSize)
178
182
  }, {
179
183
  index: vectorIndex,
180
184
  embed: (texts) => embed.embed({ texts }),
@@ -3,7 +3,7 @@ import type { ApprovalCall, CompletionEvent, DeleteModelSummary, MemoryBudget, M
3
3
  import type { ManagedSkill, SkillFileContent } from '@qvac/harness/lib/tools/skills/overlay-crud.ts';
4
4
  import type { SkillCatalogOptions, SkillManagementHooks } from '../core.ts';
5
5
  import type { DriveOpFn, GrantedDrive } from '@qvac/harness/lib/tools/fs/remote.ts';
6
- import type { AssistantAgent, AssistantCapabilityProfile, AssistantChunkContentAttachment, AssistantCustomModelPreview, AssistantDeleteModelRequest, AssistantDetectLanguageRequest, AssistantDetectLanguageResponse, AssistantDeleteModelResponse, AssistantEnhanceMode, AssistantKvCacheDeletionResponse, AssistantListModelsRequest, AssistantModelInfoList, AssistantPreviewCustomModelRequest, AssistantSkillCatalogResponse, AssistantSpeakRequest, AssistantSpeakResponse, AssistantToolCatalogResponse, AssistantToolReportEntry, AssistantTranscribeRequest, AssistantTranscribeResponse } from '../../spec/hyperschema/types.d.ts';
6
+ import type { AssistantAgent, AssistantCapabilityProfile, AssistantChunkContentAttachment, AssistantCustomModelPreview, AssistantCustomModelReportEntry, AssistantDeleteModelRequest, AssistantDetectLanguageRequest, AssistantDetectLanguageResponse, AssistantDeleteModelResponse, AssistantEnhanceMode, AssistantKvCacheDeletionResponse, AssistantListModelsRequest, AssistantModelInfoList, AssistantPreviewCustomModelRequest, AssistantSkillCatalogResponse, AssistantSpeakRequest, AssistantSpeakResponse, AssistantToolCatalogResponse, AssistantToolReportEntry, AssistantTranscribeRequest, AssistantTranscribeResponse } from '../../spec/hyperschema/types.d.ts';
7
7
  import type { HarnessDiagnostics } from '../diagnostics.ts';
8
8
  import type { DownloadArgs, DownloadEventStream, ImageDownloadObservation } from '../model-download.ts';
9
9
  import type { AttachInput, AttachmentMeta, ChatMessage, FetchedAttachment } from './message.ts';
@@ -50,6 +50,7 @@ export interface ModelInfo {
50
50
  actualSize?: number;
51
51
  taskType?: string;
52
52
  memoryBytes?: number;
53
+ label?: string;
53
54
  }
54
55
  export interface ListModelsOptions {
55
56
  type?: ModelType;
@@ -277,6 +278,7 @@ export declare function harnessSkillCatalog(harness: Pick<Harness, 'skills'>, sy
277
278
  export declare function harnessSkillManagement(harness: Pick<Harness, 'listManagedSkills' | 'readSkillFile' | 'writeSkillFile' | 'copyBaseForEdit' | 'deleteOverlaySkill'>): SkillManagementHooks;
278
279
  export declare function harnessTools(harness: Pick<Harness, 'tools'>): () => Promise<AssistantToolCatalogResponse>;
279
280
  export declare function toolReportEntry(tool: ToolCatalogEntry): AssistantToolReportEntry;
281
+ export declare function customModelReportEntries(models: ReadonlyArray<ModelInfo>): AssistantCustomModelReportEntry[];
280
282
  export declare function harnessSpeakStream(harness: Pick<Harness, 'speakStream'>): (text: AsyncIterable<string>) => AsyncIterable<AssistantSpeakResponse>;
281
283
  export declare function harnessDeathReason(status: unknown): string;
282
284
  export declare function harnessDied(status: unknown): boolean;
@@ -135,6 +135,16 @@ export function toolReportEntry(tool) {
135
135
  writeRootsRequired: tool.writeRootsRequired === true
136
136
  };
137
137
  }
138
+ export function customModelReportEntries(models) {
139
+ return models
140
+ .filter((model) => model.registrySource === 'custom')
141
+ .map((model) => ({
142
+ name: model.name,
143
+ label: model.label || model.name,
144
+ taskType: model.taskType ?? null,
145
+ expectedSize: model.expectedSize
146
+ }));
147
+ }
138
148
  export function harnessSpeakStream(harness) {
139
149
  return async function* (text) {
140
150
  if (!harness.speakStream) {
@@ -16,6 +16,7 @@ export interface CompactOptions {
16
16
  readonly signal?: AbortSignal;
17
17
  readonly onFold?: () => Promise<void> | void;
18
18
  readonly meshId: string;
19
+ readonly requestSeq?: number;
19
20
  }
20
21
  export type CompactionTrigger = 'before-run' | 'overflow';
21
22
  export interface CompactResult {
@@ -136,6 +136,13 @@ export function historyFromChunks(chunks, stale = {}, { senderNames = new Map(),
136
136
  }
137
137
  return turn;
138
138
  };
139
+ const afterRun = (runId) => {
140
+ let at = history.indexOf(anchor(runId)) + 1;
141
+ while (history[at]?.role === 'tool') {
142
+ at++;
143
+ }
144
+ return at;
145
+ };
139
146
  for (const chunk of source) {
140
147
  if (chunk.userMessage) {
141
148
  if (staleQuestionChunkIds.has(chunk.id)) {
@@ -198,8 +205,7 @@ export function historyFromChunks(chunks, stale = {}, { senderNames = new Map(),
198
205
  const loaded = isRecord(result) ? result.name : undefined;
199
206
  if (typeof loaded === 'string' && !replayedSkills.has(loaded)) {
200
207
  replayedSkills.add(loaded);
201
- const at = history.indexOf(anchor(chunk.runId)) + 1;
202
- history.splice(at, 0, { role: 'tool', content: skillLoadedTurn(loaded) });
208
+ history.splice(afterRun(chunk.runId), 0, { role: 'tool', content: skillLoadedTurn(loaded) });
203
209
  }
204
210
  continue;
205
211
  }
@@ -212,7 +218,7 @@ export function historyFromChunks(chunks, stale = {}, { senderNames = new Map(),
212
218
  }
213
219
  const produced = attachmentTurn(chunk.toolResult.name, chunk.toolResult.result);
214
220
  if (produced) {
215
- history.push({ role: 'tool', content: produced });
221
+ history.splice(afterRun(chunk.runId), 0, { role: 'tool', content: produced });
216
222
  }
217
223
  continue;
218
224
  }
@@ -42,8 +42,8 @@ export function silentAudioNotice(fileName) {
42
42
  }
43
43
  export function audioTranscriptBlock(fileName, transcript) {
44
44
  return [
45
- `The audio file "${fileName}" has already been transcribed on-device. You cannot open the file itself — use the transcript below as its full content and answer from it.`,
46
- 'Transcript:',
45
+ `The audio file "${fileName}" has already been transcribed on-device for its speech. You cannot open the file itself, but a tool that takes an audio attachment still reads the audio.`,
46
+ 'Transcript of the speech in it, which is its words and not any music:',
47
47
  transcript
48
48
  ].join('\n');
49
49
  }
@@ -26,6 +26,7 @@ export interface AssistantTreeOptions {
26
26
  runReplayDir?: string;
27
27
  imageCacheMaxBytes?: number;
28
28
  imageCacheMaxAgeMs?: number;
29
+ kvCacheRetentionMs?: number;
29
30
  embedder?: EmbedderFactory;
30
31
  extractors?: RagExtractors;
31
32
  onHarness?: OnHarness;
@@ -43,6 +44,7 @@ export interface AssistantChildOptions {
43
44
  runReplayDir?: string;
44
45
  imageCacheMaxBytes?: number;
45
46
  imageCacheMaxAgeMs?: number;
47
+ kvCacheRetentionMs?: number;
46
48
  embedder?: EmbedderFactory;
47
49
  extractors?: RagExtractors;
48
50
  onHarness?: OnHarness;