@qvac/core 0.10.4 → 0.11.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 (104) hide show
  1. package/CHANGELOG.md +114 -1
  2. package/dist-lib/index.d.ts +1 -0
  3. package/dist-lib/index.js +1 -0
  4. package/dist-lib/lib/api/chunk-delta.d.ts +6 -2
  5. package/dist-lib/lib/api/chunk-delta.js +69 -7
  6. package/dist-lib/lib/api/chunks.js +6 -2
  7. package/dist-lib/lib/api/config.d.ts +4 -1
  8. package/dist-lib/lib/api/config.js +23 -4
  9. package/dist-lib/lib/api/devices.js +3 -1
  10. package/dist-lib/lib/api/rag.js +4 -2
  11. package/dist-lib/lib/assistant/harness.d.ts +3 -1
  12. package/dist-lib/lib/assistant/harness.js +10 -0
  13. package/dist-lib/lib/assistant/history.d.ts +2 -1
  14. package/dist-lib/lib/assistant/history.js +39 -6
  15. package/dist-lib/lib/assistant/message.d.ts +3 -0
  16. package/dist-lib/lib/assistant/message.js +10 -2
  17. package/dist-lib/lib/assistant/pdf-budget.d.ts +3 -0
  18. package/dist-lib/lib/assistant/pdf-budget.js +13 -0
  19. package/dist-lib/lib/assistant-tree.d.ts +1 -0
  20. package/dist-lib/lib/assistant-tree.js +10 -3
  21. package/dist-lib/lib/assistant.d.ts +5 -1
  22. package/dist-lib/lib/assistant.js +112 -37
  23. package/dist-lib/lib/client.js +10 -1
  24. package/dist-lib/lib/core/archived-mesh.js +1 -0
  25. package/dist-lib/lib/core/chunk.d.ts +5 -2
  26. package/dist-lib/lib/core/chunk.js +74 -18
  27. package/dist-lib/lib/core/collections.d.ts +1 -0
  28. package/dist-lib/lib/core/collections.js +1 -0
  29. package/dist-lib/lib/core/config-value.d.ts +6 -0
  30. package/dist-lib/lib/core/config-value.js +14 -0
  31. package/dist-lib/lib/core/contract/chat.d.ts +1 -0
  32. package/dist-lib/lib/core/contract/chat.js +8 -1
  33. package/dist-lib/lib/core/contract/chunks.js +20 -6
  34. package/dist-lib/lib/core/contract/compute.d.ts +1 -1
  35. package/dist-lib/lib/core/contract/compute.js +2 -1
  36. package/dist-lib/lib/core/contract/devices.js +3 -2
  37. package/dist-lib/lib/core/departures.js +7 -0
  38. package/dist-lib/lib/core/devices.d.ts +2 -1
  39. package/dist-lib/lib/core/devices.js +4 -2
  40. package/dist-lib/lib/core/document-attachment.d.ts +7 -0
  41. package/dist-lib/lib/core/document-attachment.js +6 -0
  42. package/dist-lib/lib/core/files/index.d.ts +1 -1
  43. package/dist-lib/lib/core/files/index.js +1 -1
  44. package/dist-lib/lib/core/files/rag/index.d.ts +1 -1
  45. package/dist-lib/lib/core/files/rag/index.js +1 -1
  46. package/dist-lib/lib/core/files/rag/retrieval/full-text.d.ts +1 -0
  47. package/dist-lib/lib/core/files/rag/retrieval/full-text.js +4 -1
  48. package/dist-lib/lib/core/identity.d.ts +2 -0
  49. package/dist-lib/lib/core/identity.js +19 -0
  50. package/dist-lib/lib/core/inference-calls-receiver.js +2 -2
  51. package/dist-lib/lib/core/known-sender.d.ts +3 -0
  52. package/dist-lib/lib/core/known-sender.js +26 -0
  53. package/dist-lib/lib/core/local/index.d.ts +2 -0
  54. package/dist-lib/lib/core/local/index.js +17 -10
  55. package/dist-lib/lib/core/mesh.d.ts +5 -1
  56. package/dist-lib/lib/core/mesh.js +6 -6
  57. package/dist-lib/lib/core/migrations/chat-chunks.d.ts +4 -0
  58. package/dist-lib/lib/core/migrations/chat-chunks.js +43 -0
  59. package/dist-lib/lib/core/pdf/rasterize.d.ts +0 -1
  60. package/dist-lib/lib/core/pdf/rasterize.js +0 -1
  61. package/dist-lib/lib/core/skill-overlay-receiver.js +2 -2
  62. package/dist-lib/lib/core/skill-secrets.js +2 -2
  63. package/dist-lib/lib/core.d.ts +12 -1
  64. package/dist-lib/lib/core.js +75 -11
  65. package/dist-lib/lib/credential-pusher.d.ts +1 -0
  66. package/dist-lib/lib/credential-pusher.js +34 -48
  67. package/dist-lib/lib/device-tree.d.ts +18 -0
  68. package/dist-lib/lib/device-tree.js +32 -0
  69. package/dist-lib/lib/errors.d.ts +8 -0
  70. package/dist-lib/lib/errors.js +8 -0
  71. package/dist-lib/lib/oauth/flow-core.js +2 -0
  72. package/dist-lib/lib/oauth/loopback.d.ts +1 -0
  73. package/dist-lib/lib/oauth/loopback.js +31 -1
  74. package/dist-lib/lib/oauth/register.js +33 -18
  75. package/dist-lib/lib/oauth/request.d.ts +10 -0
  76. package/dist-lib/lib/oauth/request.js +22 -0
  77. package/dist-lib/lib/oauth/token-exchange-core.js +29 -32
  78. package/dist-lib/lib/oauth/types.d.ts +3 -0
  79. package/dist-lib/lib/oauth.d.ts +2 -1
  80. package/dist-lib/lib/oauth.js +1 -0
  81. package/dist-lib/lib/run-replay.d.ts +8 -2
  82. package/dist-lib/lib/run-replay.js +29 -11
  83. package/dist-lib/schema/engine.js +20 -3
  84. package/dist-lib/schema/field-order.js +8 -1
  85. package/dist-lib/schema/local.js +7 -3
  86. package/dist-lib/schema/qvac.js +19 -2
  87. package/dist-lib/spec/hrpc/messages.js +1236 -1184
  88. package/dist-lib/spec/hyperschema/index.js +1236 -1184
  89. package/dist-lib/spec/hyperschema/schema.json +47 -0
  90. package/dist-lib/spec/hyperschema/types.d.ts +11 -0
  91. package/dist-lib/spec/local/hyperdb/messages.js +70 -20
  92. package/dist-lib/spec/local/hyperschema/index.js +36 -11
  93. package/dist-lib/spec/local/hyperschema/schema.json +21 -1
  94. package/dist-lib/spec/local/hyperschema/types.d.ts +5 -1
  95. package/dist-lib/spec/mesh/hyperdb/db.json +17 -1
  96. package/dist-lib/spec/mesh/hyperdb/index.js +83 -2
  97. package/dist-lib/spec/mesh/hyperdb/messages.js +573 -255
  98. package/dist-lib/spec/mesh/hyperdispatch/dispatch.json +7 -1
  99. package/dist-lib/spec/mesh/hyperdispatch/index.js +18 -1
  100. package/dist-lib/spec/mesh/hyperdispatch/messages.js +121 -8
  101. package/dist-lib/spec/mesh/hyperschema/index.js +121 -8
  102. package/dist-lib/spec/mesh/hyperschema/schema.json +69 -1
  103. package/dist-lib/spec/mesh/hyperschema/types.d.ts +19 -1
  104. package/package.json +12 -10
package/CHANGELOG.md CHANGED
@@ -13,6 +13,117 @@ release.
13
13
 
14
14
  ## [Unreleased]
15
15
 
16
+ ## [0.11.1] - 2026-10-26
17
+
18
+ ### Added
19
+
20
+ - `deviceTree(transport, { core, assistant, office, logger })` boots Core and
21
+ the assistant under one supervisor, the way the app does. (#544)
22
+ - The `reindex-chat-chunks` op copies a chat written before this release into
23
+ `@qvac/chat-chunks`. A build older than this one halts on it, so a device
24
+ sends it only once the published version floor shuts out every app release
25
+ before 0.21.0, the first whose core applies it. A build under the floor opens
26
+ no mesh, so none can halt on it; publish `>=0.21.0` once that release is in
27
+ both stores. (#491)
28
+ - A device's row in the account carries `customModels`: the label, task type
29
+ and size of each custom model it has. A paired desktop showed a custom model
30
+ added on the phone by its `custom:…` id, as Other and of unknown size, and
31
+ counted it outside the phone's LLMs. `saveDeviceCapabilities` takes the field,
32
+ and the assistant reports it again when a custom model is renamed. (#556)
33
+
34
+ ### Changed
35
+
36
+ - `chunksDeltaWatch` reads only the rows that changed after its opening reset,
37
+ so an update no longer costs the whole chat. Frames are unchanged; a
38
+ selection with `limit` is still read whole. (#538)
39
+ - Injection-mode `ragSearch` sizes its excerpts to a quarter of the agent's
40
+ context window, capped at the 3072-token default, so a small window gets
41
+ fewer excerpts instead of overflowing. (#588)
42
+ - `hypercore` 11.39 and `hypercore-storage` 3.4, for a working purge. (#539)
43
+ - `hypercore-blob-server` 1.15.1 keeps its socket listening across a suspend,
44
+ so resume keeps the port and every minted link, and replaces the local patch.
45
+ (#561)
46
+
47
+ ### Fixed
48
+
49
+ - A member whose only device in a shared mesh comes back far behind
50
+ fast-forwards instead of replaying everything it missed (183 s to 3.9 s on a
51
+ mesh about 6,900 flushes ahead): a shared mesh trusts every member's live
52
+ devices, not only this member's own, and never a device admitted unlinked. A
53
+ compute mesh still trusts only its own member's devices. (#492)
54
+ - Opening a chat on a device that does not hold the mesh no longer downloads most
55
+ of the mesh. Each chunk is also kept in `@qvac/chat-chunks`, keyed by chat and
56
+ `seq`, and a chat read is one range of it: a 1,100-chunk chat fetched about
57
+ 1,000 blocks instead of 100,000. Once the published floor is at app 0.21.0 or
58
+ later, the chats written before this release are copied in the background, one
59
+ op per chat; until then, or while an older build still writes to a chat, it
60
+ reads the way it did before. A chat an older build purged also loses the rows
61
+ that build left in `@qvac/chat-chunks`. (#490, #491)
62
+ - `configGet` and `configWatch` return a stored `false`, `0` or `''` as written
63
+ instead of `null`. A device on 0.11.0 or earlier, a value one of those
64
+ releases wrote, and a downgrade to one still read them as `null`. (#546)
65
+ - A message's audio attachment is presented to the model as a transcript of its
66
+ speech only, so a tool that reads the audio itself, such as music
67
+ transcription, is used again. (#337)
68
+ - The assistant reports an agent it hosts in a shared mesh as soon as this
69
+ device has joined it. A device still joining had its report refused and never
70
+ reported again. (#324)
71
+ - `removeDevice` on the account revokes the device in a shared mesh whose row
72
+ for it arrives after the removal. Before, it stayed a writer there. (#547)
73
+ - `inferenceCalls` and the skill routes (`pushSkillSecret`,
74
+ `listManagedSkills`, `readSkillFile`, `writeSkillFile`, `copySkillForEdit`,
75
+ `deleteOverlaySkill`) from a device that has just paired no longer fail with
76
+ `PEER_SENDER_REVOKED`: the host waits up to 30 s for the new device's row.
77
+ (#544)
78
+ - Core no longer dies of an unhandled `REQUEST_CANCELLED` when a fast-forward
79
+ cancels the read that follows a joined mesh's shared meshes. (#474)
80
+ - A device restarted while its `joinMesh` is still `joining` boots the mesh
81
+ from the head its invite carried, instead of replaying it from its first
82
+ block, which on a big mesh took minutes. (#515)
83
+ - `meshInvite` on a device that just recovered with `recoverAccount` waits for
84
+ its member link instead of failing with "This device cannot reach its account
85
+ to check". (#540)
86
+ - A question sent while the previous run was still answering is shown to the
87
+ model after that answer, not before it, once compaction folds the earlier
88
+ turns. The run's reply and its file turns were sorted behind the new question,
89
+ and the model answered as if they came later (QVAC-24502). A file a run
90
+ produced is now replayed right behind that run's answer instead of at the end
91
+ of the chat; an existing chat with such a turn re-reads once after the update.
92
+ (#584)
93
+
94
+ ## [0.11.0] - 2026-10-23
95
+
96
+ ### Added
97
+
98
+ - `OAuthFlowDeps.onStage` reports `awaiting-callback` and `exchanging-code`, so a
99
+ host can log where a connect flow stopped. (#550)
100
+ - `deliverOAuthCallback(address)` in `@qvac/core/oauth` settles a waiting
101
+ sign-in from a callback address the user pastes, for a browser that cannot
102
+ reach the loopback. (#551)
103
+
104
+ ### Changed
105
+
106
+ - The OAuth loopback done page tells the user to return to QV.AC to finish
107
+ connecting. (#550)
108
+ - The PDF page-image cap scales with the run's context window, between 2 and
109
+ 32 pages, instead of a fixed 10. (#526)
110
+
111
+ ### Fixed
112
+
113
+ - An OAuth connect whose provider stops answering now fails after 30 s instead
114
+ of waiting forever: the code exchange after the browser hands back the code
115
+ with `OAUTH_TOKEN_EXCHANGE_TIMEOUT`, and dynamic client registration, before
116
+ the browser opens, with `OAUTH_REGISTRATION_TIMEOUT`.
117
+ `OAuthFlowDeps.requestTimeoutMs` sets the limit per request. (#555)
118
+ - A PDF cut at the page-image cap tells the model the last page shown. (#525)
119
+ - Each user turn renders the same bytes on every request, so the chat's KV
120
+ cache is reused. (#528)
121
+ - Two devices that take turns to leave the account and pair back can both still
122
+ `meshInvite`. Before, the fourth pairing left a device refused with
123
+ `DEVICE_INVITE_CHAIN_TOO_LONG`. (#513)
124
+ - `joinMesh` no longer hangs when a device pairs back right after it unpaired,
125
+ while the removal its leave left behind is still being delivered. (#513)
126
+
16
127
  ## [0.10.4] - 2026-10-22
17
128
 
18
129
  ### Added
@@ -1892,7 +2003,9 @@ Published under the `release-0.1` dist-tag.
1892
2003
  await assistant.ready()
1893
2004
  ```
1894
2005
 
1895
- [Unreleased]: https://github.com/tetherto/qvac-core/compare/v0.10.4...HEAD
2006
+ [Unreleased]: https://github.com/tetherto/qvac-core/compare/v0.11.1...HEAD
2007
+ [0.11.1]: https://github.com/tetherto/qvac-core/compare/v0.11.0...v0.11.1
2008
+ [0.11.0]: https://github.com/tetherto/qvac-core/compare/v0.10.4...v0.11.0
1896
2009
  [0.10.4]: https://github.com/tetherto/qvac-core/compare/v0.10.3...v0.10.4
1897
2010
  [0.10.3]: https://github.com/tetherto/qvac-core/compare/v0.10.2...v0.10.3
1898
2011
  [0.10.2]: https://github.com/tetherto/qvac-core/compare/v0.10.1...v0.10.2
@@ -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
1
  import { appendChunk, listAttachmentsByKind, listChunks, listRunRequests, recordLinks, resolveApproval, updateChunk } from '../core/chunk.js';
2
- import { chunkDeltaStream } from './chunk-delta.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,7 +36,11 @@ 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)),
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
+ },
40
44
  runRequestsWatch: meshWatchable(pool, async (_request, mesh) => ({ chunks: await listRunRequests(mesh, deviceId) }), { name: 'runRequestsWatch', log })
41
45
  };
42
46
  }
@@ -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;
@@ -169,12 +169,14 @@ export function createRagApi(pool, { index, embedder, effectiveCtxSize = null })
169
169
  }
170
170
  }
171
171
  try {
172
+ const ctxSize = effectiveCtxSize ? await effectiveCtxSize(agent) : 0;
172
173
  const result = await retrieveRagKnowledge({
173
174
  query,
174
175
  chatId,
175
176
  documents: hydratedDocuments,
176
177
  liveSourceIds: rows.map((row) => row.id),
177
- scopeDocumentIds: scopeDocumentIds.length > 0 ? scopeDocumentIds : undefined
178
+ scopeDocumentIds: scopeDocumentIds.length > 0 ? scopeDocumentIds : undefined,
179
+ chunkBudgetTokens: retrievalBudgetTokens(ctxSize)
178
180
  }, {
179
181
  index: vectorIndex,
180
182
  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) {
@@ -37,8 +37,9 @@ export declare function senderAttribution(names: ReadonlyMap<string, string>): s
37
37
  export interface HistoryReplay {
38
38
  readonly senderNames?: ReadonlyMap<string, string>;
39
39
  readonly sentRuns?: ReadonlyMap<string, ReadonlyArray<ChatMessage>>;
40
+ readonly askedRuns?: ReadonlyMap<string, string>;
40
41
  }
41
- export declare function historyFromChunks(chunks: ReadonlyArray<AssistantChunk>, stale?: Partial<StaleToolRuns>, { senderNames, sentRuns }?: HistoryReplay): ChatMessage[];
42
+ export declare function historyFromChunks(chunks: ReadonlyArray<AssistantChunk>, stale?: Partial<StaleToolRuns>, { senderNames, sentRuns, askedRuns }?: HistoryReplay): ChatMessage[];
42
43
  export declare function inputAvailableToRun(chunk: AssistantChunk, requestSeq: number): boolean;
43
44
  export declare function normalizeQuestion(text: string): string;
44
45
  export declare const GENERIC_ACKNOWLEDGEMENTS: Set<string>;
@@ -87,7 +87,7 @@ function derivedAttachments(chunks) {
87
87
  }
88
88
  return derived;
89
89
  }
90
- export function historyFromChunks(chunks, stale = {}, { senderNames = new Map(), sentRuns = new Map() } = {}) {
90
+ export function historyFromChunks(chunks, stale = {}, { senderNames = new Map(), sentRuns = new Map(), askedRuns = new Map() } = {}) {
91
91
  const attemptStarts = latestAttemptStarts(chunks);
92
92
  const shared = new Set(senderNames.values()).size > 1;
93
93
  const staleRunIds = stale.runIds ?? new Set();
@@ -113,12 +113,18 @@ export function historyFromChunks(chunks, stale = {}, { senderNames = new Map(),
113
113
  }
114
114
  const byRun = new Map();
115
115
  const kept = new Set();
116
+ let asking = null;
116
117
  const anchor = (runId) => {
117
118
  let turn = byRun.get(runId);
118
119
  if (!turn) {
119
120
  turn = { role: 'assistant', content: '' };
120
121
  byRun.set(runId, turn);
121
- const sent = runId && !staleRunIds.has(runId) ? sentRuns.get(runId) : undefined;
122
+ const live = runId && !staleRunIds.has(runId) ? runId : undefined;
123
+ const asked = live ? askedRuns.get(live) : undefined;
124
+ if (asking && asked !== undefined) {
125
+ asking.sentContent = asked;
126
+ }
127
+ const sent = live ? sentRuns.get(live) : undefined;
122
128
  if (sent) {
123
129
  const replayed = sent.map((message) => ({ ...message }));
124
130
  history.push(...replayed);
@@ -130,16 +136,34 @@ export function historyFromChunks(chunks, stale = {}, { senderNames = new Map(),
130
136
  }
131
137
  return turn;
132
138
  };
139
+ const foldedRequests = foldedRequestRuns(chunks, source);
140
+ for (const chunk of source) {
141
+ if (chunk.runId && foldedRequests.has(chunk.runId) && (chunk.content || chunk.toolResult)) {
142
+ anchor(chunk.runId);
143
+ }
144
+ }
145
+ const afterRun = (runId) => {
146
+ let at = history.indexOf(anchor(runId)) + 1;
147
+ while (history[at]?.role === 'tool') {
148
+ at++;
149
+ }
150
+ return at;
151
+ };
133
152
  for (const chunk of source) {
134
153
  if (chunk.userMessage) {
135
154
  if (staleQuestionChunkIds.has(chunk.id)) {
136
155
  continue;
137
156
  }
138
157
  const sender = shared ? senderNames.get(chunk.id) : undefined;
139
- const turn = { role: 'user', content: chunk.userMessage.text };
158
+ const turn = {
159
+ role: 'user',
160
+ content: chunk.userMessage.text,
161
+ sentAt: chunk.createdAt
162
+ };
140
163
  if (sender) {
141
164
  turn.sender = sender;
142
165
  }
166
+ asking = turn;
143
167
  const refs = (byMessage.get(chunk.id) ?? [])
144
168
  .flatMap((attachmentChunk) => attachmentChunk.attachment ?? [])
145
169
  .filter((ref) => !ref.deletedAt);
@@ -187,8 +211,7 @@ export function historyFromChunks(chunks, stale = {}, { senderNames = new Map(),
187
211
  const loaded = isRecord(result) ? result.name : undefined;
188
212
  if (typeof loaded === 'string' && !replayedSkills.has(loaded)) {
189
213
  replayedSkills.add(loaded);
190
- const at = history.indexOf(anchor(chunk.runId)) + 1;
191
- history.splice(at, 0, { role: 'tool', content: skillLoadedTurn(loaded) });
214
+ history.splice(afterRun(chunk.runId), 0, { role: 'tool', content: skillLoadedTurn(loaded) });
192
215
  }
193
216
  continue;
194
217
  }
@@ -201,7 +224,7 @@ export function historyFromChunks(chunks, stale = {}, { senderNames = new Map(),
201
224
  }
202
225
  const produced = attachmentTurn(chunk.toolResult.name, chunk.toolResult.result);
203
226
  if (produced) {
204
- history.push({ role: 'tool', content: produced });
227
+ history.splice(afterRun(chunk.runId), 0, { role: 'tool', content: produced });
205
228
  }
206
229
  continue;
207
230
  }
@@ -218,6 +241,16 @@ export function historyFromChunks(chunks, stale = {}, { senderNames = new Map(),
218
241
  }
219
242
  return history.filter((turn) => turn.role === 'user' || turn.content.length > 0 || kept.has(turn));
220
243
  }
244
+ function foldedRequestRuns(chunks, kept) {
245
+ const keptIds = new Set(kept.map((chunk) => chunk.id));
246
+ const folded = new Set();
247
+ for (const chunk of chunks) {
248
+ if (chunk.type === 'run-request' && chunk.runId && !keptIds.has(chunk.id)) {
249
+ folded.add(chunk.runId);
250
+ }
251
+ }
252
+ return folded;
253
+ }
221
254
  export function inputAvailableToRun(chunk, requestSeq) {
222
255
  const userInput = Boolean(chunk.userMessage || (chunk.attachment && !chunk.runId));
223
256
  return !userInput || chunk.seq < requestSeq;
@@ -3,6 +3,8 @@ export interface ChatMessage {
3
3
  role: 'user' | 'assistant' | 'tool';
4
4
  content: string;
5
5
  sender?: string;
6
+ sentAt?: number;
7
+ sentContent?: string;
6
8
  attachments?: {
7
9
  path: string;
8
10
  }[];
@@ -63,4 +65,5 @@ export interface AttachmentMeta {
63
65
  export interface FetchedAttachment extends AttachmentMeta {
64
66
  bytes: Uint8Array;
65
67
  }
68
+ export declare function restoreSentContent(messages: ChatMessage[]): void;
66
69
  export declare function nameSenders(messages: ReadonlyArray<ChatMessage>): ChatMessage[];
@@ -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
  }
@@ -80,6 +80,14 @@ function displayableSender(name) {
80
80
  const flat = name?.replace(/\s+/g, ' ').trim();
81
81
  return flat ? Array.from(flat).slice(0, MAX_SENDER_NAME_CHARS).join('') : undefined;
82
82
  }
83
+ export function restoreSentContent(messages) {
84
+ for (const turn of messages) {
85
+ if (turn.sentContent === undefined)
86
+ continue;
87
+ turn.content = turn.sentContent;
88
+ delete turn.sentContent;
89
+ }
90
+ }
83
91
  export function nameSenders(messages) {
84
92
  return messages.map(({ sender, ...turn }) => {
85
93
  const name = displayableSender(sender);
@@ -0,0 +1,3 @@
1
+ export declare const MIN_PDF_PAGE_IMAGES = 2;
2
+ export declare const MAX_PDF_PAGE_IMAGES = 32;
3
+ export declare function pdfPageBudget(ctxSize: number): number;
@@ -0,0 +1,13 @@
1
+ import { MAX_IMAGE_WIDTH } from '../core/image/normalize.js';
2
+ import { frameTokens } from './video-budget.js';
3
+ const PAGE_TOKENS = frameTokens({
4
+ width: MAX_IMAGE_WIDTH,
5
+ height: Math.ceil(MAX_IMAGE_WIDTH * Math.SQRT2)
6
+ });
7
+ const PDF_SHARE = 0.5;
8
+ export const MIN_PDF_PAGE_IMAGES = 2;
9
+ export const MAX_PDF_PAGE_IMAGES = 32;
10
+ export function pdfPageBudget(ctxSize) {
11
+ const fits = Math.floor((ctxSize * PDF_SHARE) / PAGE_TOKENS);
12
+ return Math.min(MAX_PDF_PAGE_IMAGES, Math.max(MIN_PDF_PAGE_IMAGES, fits));
13
+ }
@@ -12,6 +12,7 @@ export type HarnessFactory = (ctx: HarnessContext) => Harness | Promise<Harness>
12
12
  export type EmbedderFactory = (harness: Harness) => IndexingEmbedder | null | undefined;
13
13
  export type OnHarnessDisposer = (() => void | Promise<void>) & {
14
14
  sync?: () => Promise<void>;
15
+ ready?: () => Promise<void>;
15
16
  };
16
17
  export type OnHarness = (harness: Harness, ctx: {
17
18
  engine: Client;
@@ -98,7 +98,7 @@ export function assistantTree(opts) {
98
98
  offModelCatalogWatch = core.registerModelCatalogWatch(() => assistant.modelCatalogWatch());
99
99
  offCustomModels = startCustomModelPusher(harness, core.local, {
100
100
  logger,
101
- onPushed: () => assistant.notifyModelCatalog()
101
+ onPushed: () => assistant.cachedModelsChanged()
102
102
  });
103
103
  offModelIdle = startModelIdlePusher(harness, core.local, logger);
104
104
  modelMemoryCap = assistant.mobileClass
@@ -126,7 +126,10 @@ export function assistantTree(opts) {
126
126
  unload: (name) => assistant.unloadModel(name)
127
127
  });
128
128
  offModelUsers = core.registerModelUsers((name) => assistant.modelUsers(name));
129
- offSkills = core.registerSkills((agentId, modelName, options) => assistant.skills(agentId, modelName, options));
129
+ offSkills = core.registerSkills(async (agentId, modelName, options) => {
130
+ await offHarness?.ready?.();
131
+ return assistant.skills(agentId, modelName, options);
132
+ });
130
133
  const transcribe = harnessTranscribe(harness);
131
134
  offTranscribe = core.registerTranscribe(async (request) => {
132
135
  await assistant.ensureMediaModelUnpaused('transcription', request.model);
@@ -144,7 +147,11 @@ export function assistantTree(opts) {
144
147
  await assistant.ensureMediaModelUnpaused('tts');
145
148
  yield* speakStream(text);
146
149
  })());
147
- offSkillCatalog = core.registerSkillCatalog(harnessSkillCatalog(assistant, () => offHarness?.sync?.()));
150
+ const skillCatalog = harnessSkillCatalog(assistant, () => offHarness?.sync?.());
151
+ offSkillCatalog = core.registerSkillCatalog(async (agentId, modelName, options) => {
152
+ await offHarness?.ready?.();
153
+ return skillCatalog(agentId, modelName, options);
154
+ });
148
155
  offSkillManagement = core.registerSkillManagement(harnessSkillManagement(harness));
149
156
  offTools = core.registerTools(harnessTools(assistant));
150
157
  const emb = embedder?.(harness);