@qvac/core 0.6.7 → 0.7.0

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 (116) hide show
  1. package/CHANGELOG.md +145 -1
  2. package/README.md +2 -0
  3. package/dist-lib/lib/api/app-config.d.ts +3 -1
  4. package/dist-lib/lib/api/app-config.js +15 -4
  5. package/dist-lib/lib/assistant/fake-models.d.ts +22 -0
  6. package/dist-lib/lib/assistant/fake-models.js +112 -0
  7. package/dist-lib/lib/assistant/harness.d.ts +10 -0
  8. package/dist-lib/lib/assistant/harness.js +26 -0
  9. package/dist-lib/lib/assistant/history.d.ts +5 -1
  10. package/dist-lib/lib/assistant/history.js +14 -2
  11. package/dist-lib/lib/assistant-tree.d.ts +4 -0
  12. package/dist-lib/lib/assistant-tree.js +45 -7
  13. package/dist-lib/lib/assistant.d.ts +15 -2
  14. package/dist-lib/lib/assistant.js +175 -41
  15. package/dist-lib/lib/constants.d.ts +6 -0
  16. package/dist-lib/lib/constants.js +6 -0
  17. package/dist-lib/lib/core/chat-activity.d.ts +1 -1
  18. package/dist-lib/lib/core/chat-activity.js +3 -0
  19. package/dist-lib/lib/core/collections.d.ts +1 -0
  20. package/dist-lib/lib/core/collections.js +1 -0
  21. package/dist-lib/lib/core/contract/compute.d.ts +1 -1
  22. package/dist-lib/lib/core/contract/compute.js +2 -1
  23. package/dist-lib/lib/core/contract/index.js +6 -1
  24. package/dist-lib/lib/core/contract/invites.d.ts +1 -11
  25. package/dist-lib/lib/core/contract/invites.js +3 -3
  26. package/dist-lib/lib/core/contract/mesh-seeds.d.ts +2 -0
  27. package/dist-lib/lib/core/contract/mesh-seeds.js +26 -0
  28. package/dist-lib/lib/core/contract/open-join.d.ts +2 -0
  29. package/dist-lib/lib/core/contract/open-join.js +57 -0
  30. package/dist-lib/lib/core/departures.d.ts +3 -0
  31. package/dist-lib/lib/core/departures.js +44 -1
  32. package/dist-lib/lib/core/identity.d.ts +1 -1
  33. package/dist-lib/lib/core/identity.js +6 -4
  34. package/dist-lib/lib/core/invite.d.ts +2 -0
  35. package/dist-lib/lib/core/invite.js +6 -2
  36. package/dist-lib/lib/core/membership.d.ts +1 -12
  37. package/dist-lib/lib/core/membership.js +1 -94
  38. package/dist-lib/lib/core/mesh.d.ts +8 -13
  39. package/dist-lib/lib/core/mesh.js +41 -87
  40. package/dist-lib/lib/core/sync/index.js +2 -16
  41. package/dist-lib/lib/core.d.ts +30 -49
  42. package/dist-lib/lib/core.js +341 -868
  43. package/dist-lib/lib/diagnostics.d.ts +7 -0
  44. package/dist-lib/lib/diagnostics.js +22 -0
  45. package/dist-lib/lib/doctor/checks.d.ts +15 -0
  46. package/dist-lib/lib/doctor/checks.js +269 -0
  47. package/dist-lib/lib/doctor/redact.d.ts +4 -0
  48. package/dist-lib/lib/doctor/redact.js +31 -0
  49. package/dist-lib/lib/doctor/render.d.ts +8 -0
  50. package/dist-lib/lib/doctor/render.js +83 -0
  51. package/dist-lib/lib/doctor/tree.d.ts +5 -0
  52. package/dist-lib/lib/doctor/tree.js +167 -0
  53. package/dist-lib/lib/downloads-allowed-pusher.d.ts +10 -0
  54. package/dist-lib/lib/downloads-allowed-pusher.js +37 -0
  55. package/dist-lib/lib/guards.d.ts +1 -0
  56. package/dist-lib/lib/guards.js +4 -0
  57. package/dist-lib/lib/inference-calls.js +1 -5
  58. package/dist-lib/lib/kv-cache-reclaim.d.ts +2 -1
  59. package/dist-lib/lib/kv-cache-reclaim.js +24 -0
  60. package/dist-lib/lib/mesh-scoped-engine.js +1 -0
  61. package/dist-lib/lib/model-download-status.d.ts +1 -1
  62. package/dist-lib/lib/model-download.d.ts +9 -1
  63. package/dist-lib/lib/model-download.js +48 -3
  64. package/dist-lib/lib/model-memory-cap.d.ts +29 -0
  65. package/dist-lib/lib/model-memory-cap.js +69 -0
  66. package/dist-lib/lib/models-watch.d.ts +1 -1
  67. package/dist-lib/lib/models-watch.js +4 -4
  68. package/dist-lib/lib/oauth/flow.js +1 -1
  69. package/dist-lib/lib/oauth/loopback.js +16 -2
  70. package/dist-lib/lib/oauth/redirect-types.d.ts +1 -0
  71. package/dist-lib/lib/run-replay.d.ts +26 -0
  72. package/dist-lib/lib/run-replay.js +107 -0
  73. package/dist-lib/schema/config.d.ts +1 -1
  74. package/dist-lib/schema/config.js +1 -1
  75. package/dist-lib/schema/content.js +9 -1
  76. package/dist-lib/schema/engine.js +30 -5
  77. package/dist-lib/schema/local.js +3 -2
  78. package/dist-lib/schema/qvac.js +18 -1
  79. package/dist-lib/spec/bind.js +3 -0
  80. package/dist-lib/spec/calls.js +1 -0
  81. package/dist-lib/spec/capabilities.d.ts +2 -0
  82. package/dist-lib/spec/config/hyperconf/index.js +1 -1
  83. package/dist-lib/spec/hrpc/hrpc.json +13 -0
  84. package/dist-lib/spec/hrpc/index.js +15 -3
  85. package/dist-lib/spec/hrpc/messages.js +646 -557
  86. package/dist-lib/spec/hyperschema/index.js +646 -557
  87. package/dist-lib/spec/hyperschema/schema.json +80 -0
  88. package/dist-lib/spec/hyperschema/types.d.ts +20 -3
  89. package/dist-lib/spec/local/hyperdb/messages.js +22 -10
  90. package/dist-lib/spec/local/hyperschema/index.js +16 -7
  91. package/dist-lib/spec/local/hyperschema/schema.json +10 -1
  92. package/dist-lib/spec/local/hyperschema/types.d.ts +3 -2
  93. package/dist-lib/spec/mesh/hyperdb/db.json +16 -1
  94. package/dist-lib/spec/mesh/hyperdb/index.js +71 -2
  95. package/dist-lib/spec/mesh/hyperdb/messages.js +477 -240
  96. package/dist-lib/spec/mesh/hyperdispatch/dispatch.json +13 -1
  97. package/dist-lib/spec/mesh/hyperdispatch/index.js +35 -1
  98. package/dist-lib/spec/mesh/hyperdispatch/messages.js +180 -7
  99. package/dist-lib/spec/mesh/hyperschema/index.js +180 -7
  100. package/dist-lib/spec/mesh/hyperschema/schema.json +98 -1
  101. package/dist-lib/spec/mesh/hyperschema/types.d.ts +26 -2
  102. package/package.json +8 -16
  103. package/tui/README.md +7 -1
  104. package/tui/app.mjs +245 -11
  105. package/tui/boot.mjs +1 -0
  106. package/tui/index.mjs +1 -0
  107. package/tui/lib/render.mjs +25 -1
  108. package/worker/assistant-sidecar.mjs +5 -2
  109. package/dist-lib/lib/core/device-invites.d.ts +0 -11
  110. package/dist-lib/lib/core/device-invites.js +0 -63
  111. package/dist-lib/lib/core/grant-expiry.d.ts +0 -11
  112. package/dist-lib/lib/core/grant-expiry.js +0 -66
  113. package/dist-lib/lib/core/mesh-seed-handoff.d.ts +0 -27
  114. package/dist-lib/lib/core/mesh-seed-handoff.js +0 -53
  115. package/dist-lib/lib/oauth/loopback.stub.d.ts +0 -3
  116. package/dist-lib/lib/oauth/loopback.stub.js +0 -6
package/CHANGELOG.md CHANGED
@@ -13,10 +13,153 @@ release.
13
13
 
14
14
  ## [Unreleased]
15
15
 
16
+ ## [0.7.0] - 2026-10-09
17
+
18
+ ### Added
19
+
20
+ - Model downloads can wait to be asked for, so a phone on cellular does not
21
+ fetch gigabytes on its own. Pass `autoDownloadModels: false` to the Core
22
+ constructor so it holds from the first boot, or toggle it later. A run that
23
+ needs a missing model then waits as `awaiting-download` instead of fetching it,
24
+ and so do image, music, transcription, speech and embedding loads in the
25
+ harness (#332, #333):
26
+
27
+ ```js
28
+ await engine.setAutoDownloadModels({ enabled: false })
29
+ for await (const { downloads } of engine.modelDownloadsWatch({})) {
30
+ const held = (downloads ?? []).find((row) => row.phase === 'held')
31
+ if (held) {
32
+ await engine.retryModelDownload({ name: held.name })
33
+ break
34
+ }
35
+ }
36
+ ```
37
+
38
+ - The OAuth loopback serves callbacks under Bare too, so a mobile worklet can
39
+ complete sign-in on the same `127.0.0.1` redirect desktop registers. (#329)
40
+ - `openOAuthLoopback` takes an optional `returnTo`: the callback redirects the
41
+ browser there instead of showing the done page. (#329)
42
+ - Several models stay loaded when memory allows (QVAC-25735). On desktop the
43
+ assistant pushes `model.memoryCapPercent` to the harness: loaded models may
44
+ fill that share of the memory usable for models, 85% by default, so two chat
45
+ models that fit stay loaded and switching chats between them loads neither
46
+ again. A load that would not fit unloads idle models one at a time, other
47
+ kinds before chat models and the least recently used first. It applies with
48
+ no restart; the minimum keeps one chat model loaded, and a mobile device
49
+ always does. `listModels` and `modelsWatch` carry the device's `memory`
50
+ (`usableBytes`, `capPercent`, `capBytes`, `usedBytes`, and `overCap` when a
51
+ model larger than the cap loaded anyway) and each loaded row its
52
+ `memoryBytes`, so a Models screen shows used against the cap. Needs the
53
+ `@qvac/harness` release with `setModelMemoryCap` and `memoryUsage`; an older
54
+ one keeps one chat model loaded and lists no `memory`. (#343)
55
+
56
+ ```js
57
+ import { MODEL_MEMORY_CAP_KEY } from '@qvac/core/constants'
58
+
59
+ await engine.configSet({ key: MODEL_MEMORY_CAP_KEY, value: 70 })
60
+ const { memory } = await engine.listModels({ cachedOnly: true })
61
+ ```
62
+
63
+ - A device pairs and follows its member with no other device online. A device
64
+ invite carries a keypair attested into the inviter's member, so the joiner
65
+ links itself, and the account holds every shared mesh's seed (the new
66
+ `@qvac/put-mesh-seed` route), so a new device opens them all from a blind
67
+ peer alone. A device invite minted by 0.6.6 still admits a device but no
68
+ longer links it into the member. `meshInvite` refuses a device invite from a
69
+ device whose proof chain is too long to extend, naming another device or the
70
+ phrase instead. (#342)
71
+ - `diagnostics` carries `backendUse`: per tool, the backends its recent runs
72
+ on this device reported, newest last. A run that asked for the gpu and ran
73
+ on the cpu is the fallback to look for. (#22)
74
+
75
+ ```js
76
+ const { stats } = await engine.diagnostics({})
77
+ stats.backendUse.generate_music.at(-1)
78
+ // { requestedGpu: true, device: 'cpu', backend: 'cpu' }
79
+ ```
80
+
81
+ - `duck`: `/doctor` checks this device (hardware, engine, model backends, mesh,
82
+ network) and `/doctor debug` shows the raw diagnostics frame behind it.
83
+ `ctrl+y` copies either as plain text, with the mesh seed and any invite
84
+ redacted and keys truncated. (#22)
85
+
86
+ ### Changed
87
+
88
+ - An invite is a password again, as it was before 0.5.0. A member invite mints
89
+ no grant and a device invite no expiring token: either link is the mesh
90
+ seed, reusable for good, and the joining device admits itself with the new
91
+ `@qvac/open-join` route; `joinMesh` and `recoverAccount` return once the
92
+ join is recorded, appending it in the background, with the account reporting
93
+ `joining` until the mesh reaches it. A device invite pairs with the inviting
94
+ device offline, and `recoverAccount` needs no other device online. A removed
95
+ device comes back the next time it joins. Every route that shipped keeps its
96
+ 0.6.6 meaning, and a 0.6.6 or 0.6.7 replica halts on the new one, so this
97
+ raises the floor to `>=0.19.1`. (#342)
98
+
99
+ ```js
100
+ const { invite } = await engine.meshInvite({ member: true })
101
+ await engine.joinMesh({ invite }) // any number of times, by anyone holding it
102
+ ```
103
+
104
+ - `joinMesh` and `recoverAccount` fail with "This device has no device
105
+ details: pass `device` when creating Core" on a Core created without
106
+ `device` and with none stored, and a `meshSeed` boot reports it as its
107
+ status error: a mesh admits only a device it can list and remove. (#342)
108
+
109
+ - A mesh still `joining` refuses a write into it at once with "This mesh is
110
+ still joining: it accepts writes once it is joined", since nothing written
111
+ there reaches disk until a peer serves the mesh. Reads keep working; retry
112
+ the write once the mesh lists `joined`. (#342)
113
+
114
+ - `listMeshes` and `meshesWatch` rows no longer set `reason` or
115
+ `awaitingFrom`: no other device admits a joining one any more. Read
116
+ `state: 'joining'` alone. (#342)
117
+
118
+ ### Deprecated
119
+
120
+ - `meshEntry.reason` and `meshEntry.awaitingFrom`, which are never set. (#342)
121
+
122
+ ### Removed
123
+
124
+ - The `grantWritableMs`, `grantVisibleMs` and `accountWritableMs` Core options.
125
+ Nothing on a join, a mint or a logout waits for a mesh to go writable any
126
+ more: a departure the mesh cannot take yet is revoked by the departures
127
+ outbox once it can, and a mesh minted before the account can write is
128
+ registered there once it can. (#342)
129
+
130
+ ### Fixed
131
+
132
+ - A chat's KV cache no longer grows by duplicated history: each run is replayed
133
+ to the model exactly as it was sent. (#338)
134
+ - A chat handed to another agent on the same device, by `setChatAgent` or a
135
+ `sendMessage` naming another `agentId`, no longer leaves the old agent's KV
136
+ cache file on disk until the chat is deleted. (#330)
137
+ - Reopening the account mesh after its local database died clears "the local
138
+ database died" error once the reopened mesh is healthy. (#340)
139
+ - `duck`: `/agent new` gives the new agent a real model in a mesh with no agent
140
+ yet, and `/agent use` hands the open chat to the agent it selects. (#348, #331)
141
+
16
142
  ## [0.6.7] - 2026-10-06
17
143
 
18
144
  ### Added
19
145
 
146
+ - A `quack` model for testing mesh, sync and chat flows without inference. An
147
+ agent on it replies with `quack` repeated 1 to 500 times, counted from a hash
148
+ of the last user turn, so the same prompt always gets the same reply. Every
149
+ other model still runs on the real harness. The device-local
150
+ `debug.fakeModels` key (`FAKE_MODELS_KEY` in `@qvac/core/constants`, beside the `QUACK_MODEL` name) turns it
151
+ on and off live, which is what an app's Debug toggle writes. `assistantChild`
152
+ and `assistantTree` take `fakeModels: true` to force it on, which is what duck
153
+ does with its `--fake-models` flag or `QVAC_FAKE_MODELS=1`.
154
+
155
+ ```js
156
+ await engine.configSet({ key: FAKE_MODELS_KEY, value: true })
157
+ ```
158
+
159
+ ```sh
160
+ QVAC_MODEL=quack duck --temp --fake-models
161
+ ```
162
+
20
163
  - `Core` accepts `store`, `swarm` and `wakeup`, so a host that is already a
21
164
  peer-to-peer application passes the ones it runs rather than having Core
22
165
  stand up a second of each. Core never closes, destroys or suspends what it
@@ -1273,7 +1416,8 @@ Published under the `release-0.1` dist-tag.
1273
1416
  await assistant.ready()
1274
1417
  ```
1275
1418
 
1276
- [Unreleased]: https://github.com/tetherto/qvac-core/compare/v0.6.7...HEAD
1419
+ [Unreleased]: https://github.com/tetherto/qvac-core/compare/v0.7.0...HEAD
1420
+ [0.7.0]: https://github.com/tetherto/qvac-core/compare/v0.6.7...v0.7.0
1277
1421
  [0.6.7]: https://github.com/tetherto/qvac-core/compare/v0.6.6...v0.6.7
1278
1422
  [0.6.6]: https://github.com/tetherto/qvac-core/compare/v0.6.5...v0.6.6
1279
1423
  [0.6.5]: https://github.com/tetherto/qvac-core/compare/v0.6.4...v0.6.5
package/README.md CHANGED
@@ -279,6 +279,8 @@ replicated runs:
279
279
  - `generating-image` / `generating-audio` / `transcribing-audio` — the active run
280
280
  refined by the media it is producing.
281
281
  - `awaiting-approval` — the active run paused on the user.
282
+ - `awaiting-download` — the active run waits for a model the user has not let
283
+ download yet (`autoDownloadModels` is off).
282
284
 
283
285
  Every value is a mutually-exclusive state, not a parallel flag. Runs serialize
284
286
  per chat, so at most one is executing. The list carries only active chats — a
@@ -1,5 +1,7 @@
1
+ import type { AssistantAppConfig } from '../../spec/hyperschema/types.d.ts';
1
2
  import type { openLocalStore } from '../core/local/index.ts';
2
3
  import type { CapabilityHandlers } from '../../spec/capabilities.d.ts';
3
4
  type LocalStore = Awaited<ReturnType<typeof openLocalStore>>;
4
- export declare function createAppConfigApi(state: LocalStore): Pick<CapabilityHandlers, 'getConfig' | 'setConfig' | 'setModelPaused' | 'setModelReleased' | 'configWatchTyped'>;
5
+ export declare function writeAutoDownloadModels(state: LocalStore, enabled: boolean): Promise<AssistantAppConfig>;
6
+ export declare function createAppConfigApi(state: LocalStore): Pick<CapabilityHandlers, 'getConfig' | 'setConfig' | 'setModelPaused' | 'setModelReleased' | 'setAutoDownloadModels' | 'configWatchTyped'>;
5
7
  export {};
@@ -22,7 +22,8 @@ const DEFAULT_CONFIG = {
22
22
  onboardingCompleted: false,
23
23
  delegation: EMPTY_DELEGATION,
24
24
  pausedModels: [],
25
- releasedModels: []
25
+ releasedModels: [],
26
+ autoDownloadModels: true
26
27
  };
27
28
  const DelegationSchema = z.object({
28
29
  enabled: z.boolean().optional(),
@@ -71,7 +72,8 @@ function toConfig(row) {
71
72
  onboardingCompleted: row.onboardingCompleted ?? false,
72
73
  delegation: normalizeDelegation(row.delegation),
73
74
  pausedModels: row.pausedModels ?? [],
74
- releasedModels: row.releasedModels ?? []
75
+ releasedModels: row.releasedModels ?? [],
76
+ autoDownloadModels: !row.manualModelDownloads
75
77
  };
76
78
  }
77
79
  function applyWrite(current, update) {
@@ -84,7 +86,8 @@ function applyWrite(current, update) {
84
86
  onboardingCompleted: update.onboardingCompleted ?? false,
85
87
  delegation: normalizeDelegation(update.delegation),
86
88
  pausedModels: current.pausedModels,
87
- releasedModels: current.releasedModels
89
+ releasedModels: current.releasedModels,
90
+ autoDownloadModels: current.autoDownloadModels
88
91
  };
89
92
  }
90
93
  function toggled(names, name, on) {
@@ -110,9 +113,14 @@ function toRow(config) {
110
113
  onboardingCompleted: config.onboardingCompleted,
111
114
  delegation: config.delegation,
112
115
  pausedModels: config.pausedModels,
113
- releasedModels: config.releasedModels
116
+ releasedModels: config.releasedModels,
117
+ manualModelDownloads: !config.autoDownloadModels
114
118
  };
115
119
  }
120
+ export async function writeAutoDownloadModels(state, enabled) {
121
+ const row = await state.updateAppConfigRow((current) => toRow({ ...toConfig(current), autoDownloadModels: enabled }));
122
+ return toConfig(row);
123
+ }
116
124
  export function createAppConfigApi(state) {
117
125
  return {
118
126
  getConfig(_) {
@@ -142,6 +150,9 @@ export function createAppConfigApi(state) {
142
150
  });
143
151
  return toConfig(row);
144
152
  },
153
+ setAutoDownloadModels(input) {
154
+ return writeAutoDownloadModels(state, input.enabled ?? false);
155
+ },
145
156
  configWatchTyped: watchable(() => state, () => readConfig(state), { name: 'configWatchTyped' })
146
157
  };
147
158
  }
@@ -0,0 +1,22 @@
1
+ import type { openLocalStore } from '../core/local/index.ts';
2
+ import type { Harness } from './harness.ts';
3
+ export declare const MAX_QUACKS = 500;
4
+ type LocalStore = Awaited<ReturnType<typeof openLocalStore>>;
5
+ export type FakeModelsSource = Pick<LocalStore, 'get' | 'watch' | 'unwatch'>;
6
+ interface Logger {
7
+ warn(...args: unknown[]): void;
8
+ }
9
+ export interface FakeModelsOptions {
10
+ enabled?: () => boolean;
11
+ paceMs?: number;
12
+ }
13
+ export declare function quackCount(prompt: string): number;
14
+ export declare function readFakeModels(state: Pick<FakeModelsSource, 'get'>): Promise<boolean>;
15
+ export interface FakeModelsWatchOptions {
16
+ initial: boolean;
17
+ onChange: (enabled: boolean) => void;
18
+ logger?: Logger | null;
19
+ }
20
+ export declare function watchFakeModels(state: FakeModelsSource, opts: FakeModelsWatchOptions): () => Promise<void>;
21
+ export declare function withFakeModels(harness: Harness, opts?: FakeModelsOptions): Harness;
22
+ export {};
@@ -0,0 +1,112 @@
1
+ import b4a from 'b4a';
2
+ import crypto from 'hypercore-crypto';
3
+ import ScopeLock from 'scope-lock';
4
+ import { FAKE_MODELS_KEY, QUACK_MODEL } from '../constants.js';
5
+ import { errorMessage } from '../guards.js';
6
+ export const MAX_QUACKS = 500;
7
+ const QUACK_ROW = {
8
+ name: QUACK_MODEL,
9
+ type: 'llm',
10
+ taskType: 'llm',
11
+ registryPath: QUACK_MODEL,
12
+ registrySource: 'fake',
13
+ isCached: true,
14
+ isLoaded: true,
15
+ expectedSize: 0,
16
+ supportsImages: false
17
+ };
18
+ export function quackCount(prompt) {
19
+ return 1 + (b4a.readUInt32LE(crypto.hash(b4a.from(prompt)), 0) % MAX_QUACKS);
20
+ }
21
+ export async function readFakeModels(state) {
22
+ return (await state.get(FAKE_MODELS_KEY)) === true;
23
+ }
24
+ export function watchFakeModels(state, opts) {
25
+ const { onChange, logger } = opts;
26
+ const lock = new ScopeLock({ debounce: true });
27
+ let disposed = false;
28
+ let reported = opts.initial;
29
+ const schedule = async () => {
30
+ if (disposed || !(await lock.lock()))
31
+ return;
32
+ try {
33
+ const enabled = await readFakeModels(state);
34
+ if (!disposed && enabled !== reported) {
35
+ reported = enabled;
36
+ onChange(enabled);
37
+ }
38
+ }
39
+ catch (err) {
40
+ logger?.warn('fake-models', 'reading the switch failed', errorMessage(err));
41
+ }
42
+ finally {
43
+ lock.unlock();
44
+ }
45
+ };
46
+ const listener = () => void schedule();
47
+ state.watch(listener);
48
+ return async () => {
49
+ disposed = true;
50
+ state.unwatch(listener);
51
+ lock.destroy();
52
+ await lock.flush();
53
+ };
54
+ }
55
+ export function withFakeModels(harness, opts = {}) {
56
+ const { enabled = () => true, paceMs = 10 } = opts;
57
+ const isQuack = (model) => model === QUACK_MODEL && enabled();
58
+ const quacking = {
59
+ ...modelCalls(harness, isQuack),
60
+ completion: (context) => isQuack(context.model) ? quack(context, paceMs) : harness.completion(context)
61
+ };
62
+ return new Proxy(harness, {
63
+ get(target, key) {
64
+ if (Object.hasOwn(quacking, key)) {
65
+ return Reflect.get(quacking, key);
66
+ }
67
+ const value = Reflect.get(target, key);
68
+ return typeof value === 'function' ? value.bind(target) : value;
69
+ }
70
+ });
71
+ }
72
+ function modelCalls(harness, isQuack) {
73
+ const list = harness.list?.bind(harness);
74
+ const warmModel = harness.warmModel?.bind(harness);
75
+ const loadModel = harness.loadModel?.bind(harness);
76
+ const unloadModel = harness.unloadModel?.bind(harness);
77
+ const deleteModel = harness.deleteModel?.bind(harness);
78
+ return {
79
+ list: list &&
80
+ (async (options) => {
81
+ const rows = await list(options);
82
+ return isQuack(QUACK_MODEL) ? withQuackRow(rows, options?.type) : rows;
83
+ }),
84
+ warmModel: warmModel && ((context) => (isQuack(context.model) ? Promise.resolve() : warmModel(context))),
85
+ loadModel: loadModel &&
86
+ ((context) => isQuack(context.model) ? Promise.resolve({ loaded: true }) : loadModel(context)),
87
+ unloadModel: unloadModel &&
88
+ ((context) => isQuack(context.model) ? Promise.resolve({ unloaded: true }) : unloadModel(context)),
89
+ deleteModel: deleteModel &&
90
+ ((name) => isQuack(name) ? Promise.resolve({ name, removed: 0, freedBytes: 0 }) : deleteModel(name))
91
+ };
92
+ }
93
+ function withQuackRow(rows, type) {
94
+ return type && type !== 'llm' ? rows : [...rows, QUACK_ROW];
95
+ }
96
+ async function* quack(context, paceMs) {
97
+ const prompt = context.messages.findLast((turn) => turn.role === 'user')?.content ?? '';
98
+ const count = quackCount(prompt);
99
+ for (let i = 0; i < count; i++) {
100
+ if (i > 0) {
101
+ await pace(paceMs);
102
+ }
103
+ if (context.signal?.aborted) {
104
+ yield { type: 'aborted' };
105
+ return;
106
+ }
107
+ yield { type: 'content', text: i === 0 ? 'quack' : ' quack' };
108
+ }
109
+ }
110
+ function pace(ms) {
111
+ return new Promise((resolve) => setTimeout(resolve, ms));
112
+ }
@@ -49,6 +49,7 @@ export interface ModelInfo {
49
49
  expectedSize: number;
50
50
  actualSize?: number;
51
51
  taskType?: string;
52
+ memoryBytes?: number;
52
53
  }
53
54
  export interface ListModelsOptions {
54
55
  type?: ModelType;
@@ -220,6 +221,13 @@ export interface Harness {
220
221
  contextLength?: number;
221
222
  }>): void | Promise<void>;
222
223
  setModelIdleTimeout?(ms: number): void | Promise<void>;
224
+ setModelMemoryCap?(percent: number): void | Promise<void>;
225
+ memoryUsage?(): Promise<{
226
+ usedBytes: number;
227
+ }>;
228
+ setDownloadsAllowed?(request: {
229
+ allowed: boolean;
230
+ }): void | Promise<void>;
223
231
  previewModelSource?(input: PreviewModelSourceContext): Promise<ModelSourcePreview>;
224
232
  on?(event: 'model' | 'status', listener: (...args: never[]) => void): unknown;
225
233
  off?(event: 'model' | 'status', listener: (...args: never[]) => void): unknown;
@@ -271,4 +279,6 @@ export declare function harnessSpeakStream(harness: Pick<Harness, 'speakStream'>
271
279
  export declare function harnessDeathReason(status: unknown): string;
272
280
  export declare function harnessDied(status: unknown): boolean;
273
281
  export declare function modelCatalogChanged(state: unknown): boolean;
282
+ export declare function heldLoadModel(state: unknown): string | null;
283
+ export declare function droppedHeldLoadModel(state: unknown): string | null;
274
284
  export declare function imageDownloadProgress(state: unknown): ImageDownloadObservation | null;
@@ -164,6 +164,32 @@ export function harnessDied(status) {
164
164
  export function modelCatalogChanged(state) {
165
165
  return isRecord(state) && state.catalogChanged === true;
166
166
  }
167
+ export function heldLoadModel(state) {
168
+ if (typeof state !== 'object' ||
169
+ state === null ||
170
+ !('status' in state) ||
171
+ state.status !== 'held' ||
172
+ !('model' in state) ||
173
+ typeof state.model !== 'string') {
174
+ return null;
175
+ }
176
+ return state.model;
177
+ }
178
+ export function droppedHeldLoadModel(state) {
179
+ if (typeof state !== 'object' ||
180
+ state === null ||
181
+ !('status' in state) ||
182
+ state.status !== 'error' ||
183
+ !('message' in state) ||
184
+ state.message !== 'aborted' ||
185
+ !('addon' in state) ||
186
+ typeof state.addon !== 'string' ||
187
+ !('model' in state) ||
188
+ typeof state.model !== 'string') {
189
+ return null;
190
+ }
191
+ return state.model;
192
+ }
167
193
  export function imageDownloadProgress(state) {
168
194
  if (typeof state !== 'object' ||
169
195
  state === null ||
@@ -34,7 +34,11 @@ export interface SenderDevice {
34
34
  }
35
35
  export declare function senderNamesFrom(chunks: ReadonlyArray<AssistantChunk>, members: ReadonlyArray<SenderMember>, devices: ReadonlyArray<SenderDevice>): ReadonlyMap<string, string>;
36
36
  export declare function senderAttribution(names: ReadonlyMap<string, string>): string;
37
- export declare function historyFromChunks(chunks: ReadonlyArray<AssistantChunk>, stale?: Partial<StaleToolRuns>, senderNames?: ReadonlyMap<string, string>): ChatMessage[];
37
+ export interface HistoryReplay {
38
+ readonly senderNames?: ReadonlyMap<string, string>;
39
+ readonly sentRuns?: ReadonlyMap<string, ReadonlyArray<ChatMessage>>;
40
+ }
41
+ export declare function historyFromChunks(chunks: ReadonlyArray<AssistantChunk>, stale?: Partial<StaleToolRuns>, { senderNames, sentRuns }?: HistoryReplay): ChatMessage[];
38
42
  export declare function inputAvailableToRun(chunk: AssistantChunk, requestSeq: number): boolean;
39
43
  export declare function normalizeQuestion(text: string): string;
40
44
  export declare const GENERIC_ACKNOWLEDGEMENTS: Set<string>;
@@ -76,7 +76,7 @@ export function senderAttribution(names) {
76
76
  const distinct = [...new Set(names.values())].sort();
77
77
  return distinct.length > 1 ? distinct.join('\u0000') : '';
78
78
  }
79
- export function historyFromChunks(chunks, stale = {}, senderNames = new Map()) {
79
+ export function historyFromChunks(chunks, stale = {}, { senderNames = new Map(), sentRuns = new Map() } = {}) {
80
80
  const attemptStarts = latestAttemptStarts(chunks);
81
81
  const shared = new Set(senderNames.values()).size > 1;
82
82
  const staleRunIds = stale.runIds ?? new Set();
@@ -100,11 +100,20 @@ export function historyFromChunks(chunks, stale = {}, senderNames = new Map()) {
100
100
  history.push({ role: 'user', content: compactionTurn(folded.summary) });
101
101
  }
102
102
  const byRun = new Map();
103
+ const kept = new Set();
103
104
  const anchor = (runId) => {
104
105
  let turn = byRun.get(runId);
105
106
  if (!turn) {
106
107
  turn = { role: 'assistant', content: '' };
107
108
  byRun.set(runId, turn);
109
+ const sent = runId && !staleRunIds.has(runId) ? sentRuns.get(runId) : undefined;
110
+ if (sent) {
111
+ const replayed = sent.map((message) => ({ ...message }));
112
+ history.push(...replayed);
113
+ for (const message of [...replayed, turn]) {
114
+ kept.add(message);
115
+ }
116
+ }
108
117
  history.push(turn);
109
118
  }
110
119
  return turn;
@@ -148,6 +157,9 @@ export function historyFromChunks(chunks, stale = {}, senderNames = new Map()) {
148
157
  anchor(chunk.runId);
149
158
  continue;
150
159
  }
160
+ if (chunk.toolResult && chunk.runId && sentRuns.has(chunk.runId)) {
161
+ continue;
162
+ }
151
163
  if (chunk.toolResult?.name === SKILL_TOOL) {
152
164
  if (chunk.runId && staleRunIds.has(chunk.runId)) {
153
165
  continue;
@@ -188,7 +200,7 @@ export function historyFromChunks(chunks, stale = {}, senderNames = new Map()) {
188
200
  }
189
201
  anchor(chunk.runId).content += chunk.content.text;
190
202
  }
191
- return history.filter((turn) => turn.role === 'user' || turn.content.length > 0);
203
+ return history.filter((turn) => turn.role === 'user' || turn.content.length > 0 || kept.has(turn));
192
204
  }
193
205
  export function inputAvailableToRun(chunk, requestSeq) {
194
206
  const userInput = Boolean(chunk.userMessage || (chunk.attachment && !chunk.runId));
@@ -22,6 +22,7 @@ export interface AssistantTreeOptions {
22
22
  logger?: Logger | null;
23
23
  imageCacheDir?: string;
24
24
  inferenceCallsDir?: string;
25
+ runReplayDir?: string;
25
26
  imageCacheMaxBytes?: number;
26
27
  imageCacheMaxAgeMs?: number;
27
28
  embedder?: EmbedderFactory;
@@ -29,6 +30,7 @@ export interface AssistantTreeOptions {
29
30
  onHarness?: OnHarness;
30
31
  platform?: string;
31
32
  preloadCurrentAgentModel?: boolean;
33
+ fakeModels?: boolean;
32
34
  }
33
35
  export declare function assistantTree(opts: AssistantTreeOptions): Supervisor;
34
36
  export interface AssistantChildOptions {
@@ -37,12 +39,14 @@ export interface AssistantChildOptions {
37
39
  logger?: Logger | null;
38
40
  imageCacheDir?: string;
39
41
  inferenceCallsDir?: string;
42
+ runReplayDir?: string;
40
43
  imageCacheMaxBytes?: number;
41
44
  imageCacheMaxAgeMs?: number;
42
45
  embedder?: EmbedderFactory;
43
46
  extractors?: RagExtractors;
44
47
  onHarness?: OnHarness;
45
48
  preloadCurrentAgentModel?: boolean;
49
+ fakeModels?: boolean;
46
50
  restart?: 'always' | 'never';
47
51
  maxRestarts?: number;
48
52
  window?: number;
@@ -1,12 +1,15 @@
1
1
  import Supervisor, {} from 'bare-supervisor';
2
2
  import { harnessClearKvCache, harnessListModels, harnessPreviewModelSource, harnessSkillCatalog, harnessSkillManagement, harnessDetectLanguage, harnessSpeak, harnessSpeakStream, harnessTools, harnessTranscribe, QvacAssistant } from './assistant.js';
3
3
  import { Client } from './client.js';
4
+ import { readFakeModels, watchFakeModels, withFakeModels } from './assistant/fake-models.js';
4
5
  import { startCustomModelPusher } from './custom-model-pusher.js';
5
6
  import { startModelIdlePusher } from './model-idle-pusher.js';
7
+ import { startModelMemoryCap } from './model-memory-cap.js';
8
+ import { startDownloadsAllowedPusher } from './downloads-allowed-pusher.js';
6
9
  import { serveHarness } from '@qvac/harness';
7
10
  import { duplexPair } from '@qvac/harness/transport';
8
11
  export function assistantTree(opts) {
9
- const { core, harness, logger = null, imageCacheDir, inferenceCallsDir, imageCacheMaxBytes, imageCacheMaxAgeMs, embedder, extractors, onHarness, platform, preloadCurrentAgentModel } = opts;
12
+ const { core, harness, logger = null, imageCacheDir, inferenceCallsDir, runReplayDir, imageCacheMaxBytes, imageCacheMaxAgeMs, embedder, extractors, onHarness, platform, preloadCurrentAgentModel, fakeModels = false } = opts;
10
13
  const sup = new Supervisor();
11
14
  const logged = ['child-died', 'child-restarting', 'child-ready', 'gave-up', 'stall'];
12
15
  for (const event of logged) {
@@ -37,6 +40,10 @@ export function assistantTree(opts) {
37
40
  let offModelCatalogWatch = null;
38
41
  let offCustomModels = null;
39
42
  let offModelIdle = null;
43
+ let modelMemoryCap = null;
44
+ let offModelMemory = null;
45
+ let offDownloadsAllowed = null;
46
+ let offFakeModels = null;
40
47
  let offLoanableHarness = null;
41
48
  sup.add('engine', {
42
49
  start: async () => {
@@ -60,13 +67,16 @@ export function assistantTree(opts) {
60
67
  }
61
68
  sup.add('assistant', {
62
69
  deps: ['engine', 'harness'],
63
- start: (ctx) => {
64
- const harness = ctx.get('harness');
70
+ start: async (ctx) => {
71
+ let fakeModelsOn = fakeModels || (await readFakeModels(core.local));
72
+ const supervised = ctx.get('harness');
73
+ const harness = withFakeModels(supervised, { enabled: () => fakeModelsOn });
65
74
  const engine = ctx.get('engine');
66
75
  const assistant = new QvacAssistant(engine, harness, {
67
76
  logger,
68
77
  imageCacheDir,
69
78
  inferenceCallsDir,
79
+ runReplayDir,
70
80
  imageCacheMaxBytes,
71
81
  imageCacheMaxAgeMs,
72
82
  platform,
@@ -81,7 +91,7 @@ export function assistantTree(opts) {
81
91
  });
82
92
  offListModels = core.registerListModels(harnessListModels(harness));
83
93
  offDeleteModel = core.registerDeleteModel(({ name }) => assistant.deleteModel(name));
84
- offClearKvCache = core.registerClearKvCache(harnessClearKvCache(harness));
94
+ offClearKvCache = core.registerClearKvCache(() => assistant.clearKvCache());
85
95
  offDeleteChatKvCache = core.registerDeleteChatKvCache((chatId) => assistant.deleteChatKvCache(chatId));
86
96
  offCompactChat = core.registerCompactChat((chatId, meshId) => assistant.compactChat(chatId, { meshId }));
87
97
  offModelCatalogWatch = core.registerModelCatalogWatch(() => assistant.modelCatalogWatch());
@@ -90,6 +100,24 @@ export function assistantTree(opts) {
90
100
  onPushed: () => assistant.notifyModelCatalog()
91
101
  });
92
102
  offModelIdle = startModelIdlePusher(harness, core.local, logger);
103
+ modelMemoryCap = assistant.mobileClass
104
+ ? null
105
+ : startModelMemoryCap(harness, core.local, {
106
+ logger,
107
+ onPushed: () => assistant.notifyModelCatalog()
108
+ });
109
+ offModelMemory = core.registerModelMemory(async () => (await modelMemoryCap?.summary()) ?? null);
110
+ offDownloadsAllowed = startDownloadsAllowedPusher(harness, core.local, logger);
111
+ offFakeModels = fakeModels
112
+ ? null
113
+ : watchFakeModels(core.local, {
114
+ initial: fakeModelsOn,
115
+ onChange: (enabled) => {
116
+ fakeModelsOn = enabled;
117
+ assistant.cachedModelsChanged();
118
+ },
119
+ logger
120
+ });
93
121
  offLoanableHarness = core.registerLoanableHarness((stream) => serveHarness(stream, harness));
94
122
  offRetryModelDownload = core.registerRetryModelDownload((name) => assistant.retryModelDownload(name));
95
123
  offModelResidency = core.registerModelResidency({
@@ -132,7 +160,7 @@ export function assistantTree(opts) {
132
160
  };
133
161
  offEmbedder = core.registerEmbedder(wrapped, extractors);
134
162
  }
135
- const off = onHarness?.(harness, { engine });
163
+ const off = onHarness?.(supervised, { engine });
136
164
  if (typeof off === 'function') {
137
165
  offHarness = off;
138
166
  }
@@ -159,6 +187,14 @@ export function assistantTree(opts) {
159
187
  offCustomModels = null;
160
188
  await offModelIdle?.();
161
189
  offModelIdle = null;
190
+ offModelMemory?.();
191
+ offModelMemory = null;
192
+ await modelMemoryCap?.stop();
193
+ modelMemoryCap = null;
194
+ await offDownloadsAllowed?.();
195
+ offDownloadsAllowed = null;
196
+ await offFakeModels?.();
197
+ offFakeModels = null;
162
198
  offLoanableHarness?.();
163
199
  offLoanableHarness = null;
164
200
  offRetryModelDownload?.();
@@ -199,7 +235,7 @@ export function assistantTree(opts) {
199
235
  return sup;
200
236
  }
201
237
  export function assistantChild(opts) {
202
- const { harness, core = 'core', logger = null, imageCacheDir, inferenceCallsDir, imageCacheMaxBytes, imageCacheMaxAgeMs, embedder, extractors, onHarness, preloadCurrentAgentModel, ...spec } = opts;
238
+ const { harness, core = 'core', logger = null, imageCacheDir, inferenceCallsDir, runReplayDir, imageCacheMaxBytes, imageCacheMaxAgeMs, embedder, extractors, onHarness, preloadCurrentAgentModel, fakeModels, ...spec } = opts;
203
239
  return {
204
240
  ...spec,
205
241
  deps: [core],
@@ -210,12 +246,14 @@ export function assistantChild(opts) {
210
246
  logger,
211
247
  imageCacheDir,
212
248
  inferenceCallsDir,
249
+ runReplayDir,
213
250
  imageCacheMaxBytes,
214
251
  imageCacheMaxAgeMs,
215
252
  embedder,
216
253
  extractors,
217
254
  onHarness,
218
- preloadCurrentAgentModel
255
+ preloadCurrentAgentModel,
256
+ fakeModels
219
257
  });
220
258
  tree.on('gave-up', ({ error }) => ctx.onDeath(error));
221
259
  return tree;