@qvac/core 0.6.0 → 0.6.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 (82) hide show
  1. package/CHANGELOG.md +112 -2
  2. package/dist-lib/lib/api/chat.d.ts +1 -1
  3. package/dist-lib/lib/api/chat.js +2 -1
  4. package/dist-lib/lib/api/index.d.ts +3 -1
  5. package/dist-lib/lib/api/index.js +2 -0
  6. package/dist-lib/lib/api/watchable.d.ts +1 -0
  7. package/dist-lib/lib/api/watchable.js +1 -1
  8. package/dist-lib/lib/assistant/harness.d.ts +2 -0
  9. package/dist-lib/lib/assistant/harness.js +13 -9
  10. package/dist-lib/lib/assistant-tree.js +4 -0
  11. package/dist-lib/lib/assistant.d.ts +5 -1
  12. package/dist-lib/lib/assistant.js +66 -20
  13. package/dist-lib/lib/client.js +2 -1
  14. package/dist-lib/lib/collabora/entry.js +13 -19
  15. package/dist-lib/lib/collabora/worker.js +77 -18
  16. package/dist-lib/lib/core/chat.d.ts +1 -0
  17. package/dist-lib/lib/core/chat.js +26 -4
  18. package/dist-lib/lib/core/collections.d.ts +1 -0
  19. package/dist-lib/lib/core/collections.js +1 -0
  20. package/dist-lib/lib/core/contract/chat.d.ts +2 -0
  21. package/dist-lib/lib/core/contract/chat.js +77 -4
  22. package/dist-lib/lib/core/contract/chunks.js +5 -0
  23. package/dist-lib/lib/core/contract/compute.d.ts +1 -1
  24. package/dist-lib/lib/core/contract/compute.js +2 -1
  25. package/dist-lib/lib/core/contract/tool-activity.js +5 -0
  26. package/dist-lib/lib/core/files/index.d.ts +2 -0
  27. package/dist-lib/lib/core/files/index.js +7 -1
  28. package/dist-lib/lib/core/files/local-index.d.ts +4 -1
  29. package/dist-lib/lib/core/files/processing/index.d.ts +3 -0
  30. package/dist-lib/lib/core/files/processing/index.js +9 -0
  31. package/dist-lib/lib/core/files/processing/state.d.ts +1 -0
  32. package/dist-lib/lib/core/files/processing/state.js +5 -0
  33. package/dist-lib/lib/core/files/rag/index.d.ts +2 -0
  34. package/dist-lib/lib/core/files/rag/index.js +6 -0
  35. package/dist-lib/lib/core/files/records/index.d.ts +1 -0
  36. package/dist-lib/lib/core/files/records/index.js +1 -0
  37. package/dist-lib/lib/core/files/records/purge.d.ts +4 -0
  38. package/dist-lib/lib/core/files/records/purge.js +108 -0
  39. package/dist-lib/lib/core/files/records/reclaim.js +5 -3
  40. package/dist-lib/lib/core/files/store/blob.d.ts +1 -0
  41. package/dist-lib/lib/core/files/store/blob.js +29 -0
  42. package/dist-lib/lib/core/files/store/index.d.ts +1 -0
  43. package/dist-lib/lib/core/files/store/index.js +6 -1
  44. package/dist-lib/lib/core/local/files.d.ts +2 -0
  45. package/dist-lib/lib/core/local/files.js +31 -0
  46. package/dist-lib/lib/core/sync/index.js +14 -1
  47. package/dist-lib/lib/core.d.ts +12 -2
  48. package/dist-lib/lib/core.js +79 -16
  49. package/dist-lib/lib/credential-pusher.d.ts +8 -3
  50. package/dist-lib/lib/credential-pusher.js +4 -1
  51. package/dist-lib/lib/mesh-scoped-engine.js +3 -0
  52. package/dist-lib/lib/model-download.d.ts +11 -7
  53. package/dist-lib/lib/model-download.js +22 -21
  54. package/dist-lib/lib/models-watch.d.ts +6 -0
  55. package/dist-lib/lib/models-watch.js +45 -0
  56. package/dist-lib/schema/engine.d.ts +1 -0
  57. package/dist-lib/schema/engine.js +57 -3
  58. package/dist-lib/schema/field-order.js +3 -1
  59. package/dist-lib/schema/qvac.js +12 -1
  60. package/dist-lib/spec/bind.js +14 -0
  61. package/dist-lib/spec/calls.js +3 -0
  62. package/dist-lib/spec/capabilities.d.ts +6 -0
  63. package/dist-lib/spec/hrpc/hrpc.json +39 -0
  64. package/dist-lib/spec/hrpc/index.js +41 -4
  65. package/dist-lib/spec/hrpc/messages.js +788 -583
  66. package/dist-lib/spec/hyperschema/index.js +788 -583
  67. package/dist-lib/spec/hyperschema/schema.json +149 -0
  68. package/dist-lib/spec/hyperschema/types.d.ts +29 -0
  69. package/dist-lib/spec/mesh/hyperdb/db.json +16 -1
  70. package/dist-lib/spec/mesh/hyperdb/index.js +71 -2
  71. package/dist-lib/spec/mesh/hyperdb/messages.js +434 -227
  72. package/dist-lib/spec/mesh/hyperdispatch/dispatch.json +7 -1
  73. package/dist-lib/spec/mesh/hyperdispatch/index.js +18 -1
  74. package/dist-lib/spec/mesh/hyperdispatch/messages.js +134 -5
  75. package/dist-lib/spec/mesh/hyperschema/index.js +134 -5
  76. package/dist-lib/spec/mesh/hyperschema/schema.json +70 -1
  77. package/dist-lib/spec/mesh/hyperschema/types.d.ts +20 -1
  78. package/package.json +23 -10
  79. package/tui/app.mjs +3 -2
  80. package/tui/boot.mjs +1 -3
  81. package/dist-lib/lib/model-clamp.d.ts +0 -6
  82. package/dist-lib/lib/model-clamp.js +0 -23
package/CHANGELOG.md CHANGED
@@ -13,6 +13,114 @@ release.
13
13
 
14
14
  ## [Unreleased]
15
15
 
16
+ ## [0.6.2] - 2026-09-30
17
+
18
+ ### Added
19
+
20
+ - `modelUsers` names the agents on this device that use a model, for a Models
21
+ screen to show before a delete and offer to switch them to another model. It
22
+ counts the model each agent actually runs here, including a skill's image or
23
+ music model and the model a phone clamps an oversized pick to.
24
+
25
+ ```js
26
+ const { agents } = await engine.modelUsers({ name: 'Qwen3.5-32B' })
27
+ ```
28
+
29
+ (#277)
30
+
31
+ - `listModels` rows carry `taskType`, what the model is for, so a Models
32
+ screen groups by task rather than by the addon in `type`: `whisper` and
33
+ `parakeet` are both `speech-to-text`. `listModels({ taskType })` keeps only
34
+ that task's models. The harness names it, from `@qvac/harness` 0.7.0.
35
+
36
+ ```js
37
+ const { models } = await engine.listModels({ taskType: 'speech-to-text' })
38
+ ```
39
+
40
+ (#278)
41
+
42
+ - Whether a chat was read now reaches every device of the mesh.
43
+ `markChatRead({ meshId, chatId })` marks a chat read up to its newest chunk,
44
+ and every chat row carries `readThrough`, the next unread seq, so a client can
45
+ clear an unread mark whose event `seq` is below it. It rides `put-chat` and
46
+ never lowers, so it needs no new mesh route and older builds keep applying
47
+ chats. A read is per chat, not per person.
48
+
49
+ ```js
50
+ await engine.markChatRead({ meshId, chatId })
51
+ ```
52
+
53
+ (#283)
54
+
55
+ - `isLoading` on `listModels` rows: true while the harness loads a chat model
56
+ into memory for the boot warm, `loadModel` or a run this device serves, with a
57
+ `modelCatalogWatch` bump when it turns on and again when it turns off. A
58
+ Models screen or host bar can say a model is loading at boot, before any
59
+ message is sent. The harness names it, from `@qvac/harness` 0.8.0; an older
60
+ harness lists every row as `false`, and other rows read `false` for now.
61
+
62
+ ```js
63
+ const { models } = await engine.listModels({ cachedOnly: true })
64
+ const loading = models.filter((model) => model.isLoading)
65
+ ```
66
+
67
+ (#270)
68
+
69
+ - `modelsWatch`: the `listModels` rows as a stream, sent again when a load,
70
+ unload, download or custom-model change alters a field a row carries, so a
71
+ Models screen sees a model start loading and become ready without re-reading
72
+ `listModels` on each `modelCatalogWatch` bump.
73
+ `excludeCustom` leaves out the models the user added, on `listModels` too.
74
+
75
+ ```js
76
+ for await (const { models } of engine.modelsWatch({ cachedOnly: true })) render(models)
77
+ ```
78
+
79
+ (#271)
80
+
81
+ ### Changed
82
+
83
+ - `deleteChat` purges the chat on every device, with the file bytes and index
84
+ rows it held, and a device that joins later gets none of it; `deleteAgent`
85
+ purges every chat the agent answered the same way. A device on an older build
86
+ halts on the purge until it updates. This was in the 0.6.1 build unannounced.
87
+ (#266)
88
+ - `engines.bare` is `>=1.34.0`. `bare-runtime` is pinned to 1.34.0 and
89
+ `bare-sidecar` to 0.5.7 (Bare 1.34.0) across the tree, with `bare-thread` at
90
+ least 1.2.7 and `bare-module` 7.1.0 for `bare-worker`'s copy: a worker that
91
+ starts inside a bundle needs `module.resolutions`. (#268)
92
+ - `bare-module` is no longer overridden to 6.4.0, and `bare-module-traverse` is
93
+ overridden to `~2.5.8`, which keeps the addon and asset conditions Bare needs to
94
+ load a bundle's native files. (#268)
95
+ - The collabora worker's entry is now in sight of a bundler. A host that stows
96
+ core carries `bare-collabora` in the bundle for office conversion, or defers
97
+ it and gets "the document engine failed to load". (#268)
98
+ - A conversion whose engine thread dies reports what killed it after "the
99
+ document engine closed unexpectedly", and a malformed job ends the thread at
100
+ once instead of waiting out the deadline. (#268)
101
+ - `bare-channel` is no longer a direct dependency; `bare-worker` brings it. (#268)
102
+
103
+ ### Fixed
104
+
105
+ - The collabora worker starts on Bare 1.33 and later, whose threads cannot read
106
+ a module off disk. It is spawned through `worker_threads`, which the package
107
+ maps to `bare-worker` on Bare, and its entry is named with a literal
108
+ `#collabora-worker-entry`, so its graph is bundled into the thread. (#268)
109
+ - `duck` crashed at start on Bare 1.33 and later, `--help` and `--version`
110
+ included, with "Invalid left-hand side expression in prefix operation": Bare
111
+ now links what `import.meta.resolve()` names, and the TUI named a `SKILL.md`.
112
+ This was in the 0.6.1 build unannounced. (#267)
113
+
114
+ ## [0.6.1] - 2026-09-29
115
+
116
+ ### Fixed
117
+
118
+ - A connected skill's OAuth token and settings reach the harness again. Since
119
+ 0.4.0 the credential pusher listed agents without naming the account mesh, so
120
+ every push failed before `setCredentials` and a skill read `needs-setup` as if
121
+ it had no credential. The pusher now lists the account mesh's agents, and
122
+ between accounts pushes the shared scope alone. (#265)
123
+
16
124
  ## [0.6.0] - 2026-09-28
17
125
 
18
126
  ### Added
@@ -57,7 +165,7 @@ release.
57
165
  model, storing nothing; with no harness that can preview, it rejects.
58
166
  `removeCustomModel` also frees the downloaded copy and answers with the
59
167
  `deleteModel` summary in place of `{ ok }`. Needs `@qvac/harness` 0.6. See
60
- [custom models](docs/api/custom-models.md). (#215)
168
+ [custom models](docs/api/models.md#custom-models). (#215)
61
169
 
62
170
  ```js
63
171
  // 0.5.0
@@ -1036,7 +1144,9 @@ Published under the `release-0.1` dist-tag.
1036
1144
  await assistant.ready()
1037
1145
  ```
1038
1146
 
1039
- [Unreleased]: https://github.com/tetherto/qvac-core/compare/v0.6.0...HEAD
1147
+ [Unreleased]: https://github.com/tetherto/qvac-core/compare/v0.6.2...HEAD
1148
+ [0.6.2]: https://github.com/tetherto/qvac-core/compare/v0.6.1...v0.6.2
1149
+ [0.6.1]: https://github.com/tetherto/qvac-core/compare/v0.6.0...v0.6.1
1040
1150
  [0.6.0]: https://github.com/tetherto/qvac-core/compare/v0.5.0...v0.6.0
1041
1151
  [0.5.0]: https://github.com/tetherto/qvac-core/compare/v0.4.1...v0.5.0
1042
1152
  [0.4.1]: https://github.com/tetherto/qvac-core/compare/v0.4.0...v0.4.1
@@ -2,7 +2,7 @@ import type { CapabilityHandlers } from '../../spec/capabilities.d.ts';
2
2
  import type { openLocalStore } from '../core/local/index.ts';
3
3
  import { type MeshPool } from './current-mesh.ts';
4
4
  type LocalStore = ReturnType<typeof openLocalStore>;
5
- type ChatCapabilities = Pick<CapabilityHandlers, 'createChat' | 'listChats' | 'getChat' | 'renameChat' | 'setChatRagEnabled' | 'setChatWebSearchEnabled' | 'deleteChat' | 'chatsWatch' | 'listChatActivity' | 'chatActivityWatch' | 'searchChats'>;
5
+ type ChatCapabilities = Pick<CapabilityHandlers, 'createChat' | 'listChats' | 'getChat' | 'renameChat' | 'markChatRead' | 'setChatRagEnabled' | 'setChatWebSearchEnabled' | 'deleteChat' | 'chatsWatch' | 'listChatActivity' | 'chatActivityWatch' | 'searchChats'>;
6
6
  export interface CreateChatApiOptions {
7
7
  readonly deviceId: Buffer | null;
8
8
  readonly inferenceCalls?: {
@@ -1,5 +1,5 @@
1
1
  import { AbortController } from 'bare-abort-controller';
2
- import { createChat, deleteChat, mustGetActiveChatListing, renameChat, setChatRagEnabled, setChatWebSearchEnabled } from '../core/chat.js';
2
+ import { createChat, deleteChat, markChatRead, mustGetActiveChatListing, renameChat, setChatRagEnabled, setChatWebSearchEnabled } from '../core/chat.js';
3
3
  import { listChatActivity } from '../core/chat-activity.js';
4
4
  import { listChatPage } from '../core/chat-order.js';
5
5
  import { searchChats } from '../core/chat-search.js';
@@ -14,6 +14,7 @@ export function createChatApi(pool, local, { deviceId, inferenceCalls = null })
14
14
  listChats: async (request) => chatList(await requireMesh(pool, request.meshId), request),
15
15
  getChat: async ({ chatId, meshId }) => mustGetActiveChatListing(await requireMesh(pool, meshId), chatId),
16
16
  renameChat: async ({ chatId, meshId, config }) => renameChat(await requireMesh(pool, meshId), chatId, config.title),
17
+ markChatRead: async ({ chatId, meshId }) => markChatRead(await requireMesh(pool, meshId), chatId),
17
18
  setChatRagEnabled: async ({ chatId, enabled, meshId }) => setChatRagEnabled(await requireMesh(pool, meshId), chatId, { ragEnabled: enabled ?? false }),
18
19
  setChatWebSearchEnabled: async ({ chatId, enabled, meshId }) => setChatWebSearchEnabled(await requireMesh(pool, meshId), chatId, enabled ?? false),
19
20
  deleteChat: async ({ chatId, meshId }) => {
@@ -1,5 +1,5 @@
1
1
  import type { CapabilityHandlers } from '../../spec/capabilities.d.ts';
2
- import type { AssistantCapabilityProfile, AssistantClearModelDownloadRequest, AssistantDeleteModelRequest, AssistantDeleteModelResponse, AssistantCompactChatResponse, AssistantKvCacheDeletionResponse, AssistantListModelsRequest, AssistantLoadModelRequest, AssistantLoadModelResponse, AssistantModelCatalogRevision, AssistantCopySkillResponse, AssistantDeleteSkillResponse, AssistantManagedSkillsResponse, AssistantModelInfoList, AssistantOkResponse, AssistantPushSkillSecretRequest, AssistantSkillCatalogResponse, AssistantSkillFileResponse, AssistantSpeakRequest, AssistantSpeakResponse, AssistantToolCatalogResponse, AssistantDetectLanguageRequest, AssistantDetectLanguageResponse, AssistantTranscribeRequest, AssistantTranscribeResponse, AssistantUnloadModelRequest, AssistantUnloadModelResponse } from '../../spec/hyperschema/types.d.ts';
2
+ import type { AssistantCapabilityProfile, AssistantClearModelDownloadRequest, AssistantDeleteModelRequest, AssistantDeleteModelResponse, AssistantCompactChatResponse, AssistantKvCacheDeletionResponse, AssistantListModelsRequest, AssistantLoadModelRequest, AssistantLoadModelResponse, AssistantModelCatalogRevision, AssistantCopySkillResponse, AssistantDeleteSkillResponse, AssistantManagedSkillsResponse, AssistantModelInfoList, AssistantOkResponse, AssistantPushSkillSecretRequest, AssistantSkillCatalogResponse, AssistantSkillFileResponse, AssistantSpeakRequest, AssistantSpeakResponse, AssistantToolCatalogResponse, AssistantDetectLanguageRequest, AssistantDetectLanguageResponse, AssistantTranscribeRequest, AssistantTranscribeResponse, AssistantUnloadModelRequest, AssistantUnloadModelResponse, AssistantModelUsers, AssistantModelUsersRequest } from '../../spec/hyperschema/types.d.ts';
3
3
  import type { openLocalStore } from '../core/local/index.ts';
4
4
  import type { Mesh } from '../core/mesh.ts';
5
5
  import type { MeshPool } from './current-mesh.ts';
@@ -27,10 +27,12 @@ interface ApiDeps {
27
27
  deleteModel?: ((options: AssistantDeleteModelRequest) => Promise<AssistantDeleteModelResponse>) | null;
28
28
  loadModel?: ((request: AssistantLoadModelRequest) => Promise<AssistantLoadModelResponse>) | null;
29
29
  unloadModel?: ((request: AssistantUnloadModelRequest) => Promise<AssistantUnloadModelResponse>) | null;
30
+ modelUsers?: ((request: AssistantModelUsersRequest) => Promise<AssistantModelUsers>) | null;
30
31
  clearKvCache?: (() => Promise<AssistantKvCacheDeletionResponse>) | null;
31
32
  deleteChatKvCache?: ((chatId: string) => Promise<AssistantKvCacheDeletionResponse>) | null;
32
33
  compactChat?: ((chatId: string, meshId: string) => Promise<AssistantCompactChatResponse>) | null;
33
34
  modelCatalogWatch?: (() => AsyncIterable<AssistantModelCatalogRevision>) | null;
35
+ modelsWatch?: ((request: AssistantListModelsRequest) => AsyncIterable<AssistantModelInfoList>) | null;
34
36
  retryModelDownload?: ((request: AssistantClearModelDownloadRequest) => Promise<void>) | null;
35
37
  transcribe?: ((request: AssistantTranscribeRequest) => Promise<AssistantTranscribeResponse>) | null;
36
38
  detectLanguage?: ((request: AssistantDetectLanguageRequest) => Promise<AssistantDetectLanguageResponse>) | null;
@@ -105,6 +105,7 @@ export function createApi(deps = {}) {
105
105
  deleteModel: deps.deleteModel ?? undefined,
106
106
  loadModel: deps.loadModel ?? undefined,
107
107
  unloadModel: deps.unloadModel ?? undefined,
108
+ modelUsers: deps.modelUsers ?? undefined,
108
109
  clearKvCache: deps.clearKvCache ?? undefined,
109
110
  deleteChatKvCache: deleteChatKvCache
110
111
  ? ({ chatId }) => deleteChatKvCache(chatId)
@@ -113,6 +114,7 @@ export function createApi(deps = {}) {
113
114
  ? ({ chatId, meshId }) => compactChat(chatId, meshId)
114
115
  : undefined,
115
116
  modelCatalogWatch: deps.modelCatalogWatch ?? undefined,
117
+ modelsWatch: deps.modelsWatch ?? undefined,
116
118
  retryModelDownload: retryModelDownload
117
119
  ? async (request) => {
118
120
  await retryModelDownload(request);
@@ -1,5 +1,6 @@
1
1
  import { Readable } from 'streamx';
2
2
  import '../logger.ts';
3
+ export declare function snapshotEquals(a: unknown, b: unknown): boolean;
3
4
  interface WatchableStore {
4
5
  watch(listener: () => void): void;
5
6
  unwatch(listener: () => void): void;
@@ -5,7 +5,7 @@ import '../logger.js';
5
5
  import { asError, isRecord } from '../guards.js';
6
6
  const SCOPE = ['api', 'watch'];
7
7
  const CHURN_WINDOW_MS = 30_000;
8
- function snapshotEquals(a, b) {
8
+ export function snapshotEquals(a, b) {
9
9
  if (a === b)
10
10
  return true;
11
11
  if (b4a.isBuffer(a) || b4a.isBuffer(b)) {
@@ -44,9 +44,11 @@ export interface ModelInfo {
44
44
  registrySource: string;
45
45
  isCached: boolean;
46
46
  isLoaded: boolean;
47
+ isLoading?: boolean;
47
48
  supportsImages?: boolean;
48
49
  expectedSize: number;
49
50
  actualSize?: number;
51
+ taskType?: string;
50
52
  }
51
53
  export interface ListModelsOptions {
52
54
  type?: ModelType;
@@ -1,20 +1,24 @@
1
1
  import { diffusionDownloadName } from '@qvac/harness/lib/models/model-catalog.ts';
2
2
  import { RUN_FAILURE_REASONS } from '../run-notices.js';
3
+ import { MODEL_TASK_TYPES } from '../../schema/engine.js';
3
4
  import { toEngineSkill } from './skill-encode.js';
4
5
  import { isRecord } from '../guards.js';
5
6
  export function isHarnessEvent(event, type) {
6
7
  return event.type === type;
7
8
  }
8
9
  export function harnessListModels(harness) {
9
- return async ({ type, cachedOnly, fullRegistry } = {}) => ({
10
- models: [
11
- ...((await harness.list?.({
12
- type: type ?? undefined,
13
- cachedOnly: cachedOnly ?? undefined,
14
- fullRegistry: fullRegistry ?? undefined
15
- })) ?? [])
16
- ]
17
- });
10
+ return async ({ type, cachedOnly, fullRegistry, taskType } = {}) => {
11
+ const rows = (await harness.list?.({
12
+ type: type ?? undefined,
13
+ cachedOnly: cachedOnly ?? undefined,
14
+ fullRegistry: fullRegistry ?? undefined
15
+ })) ?? [];
16
+ const models = rows.map((row) => ({
17
+ ...row,
18
+ taskType: MODEL_TASK_TYPES.find((known) => known === row.taskType)
19
+ }));
20
+ return { models: taskType ? models.filter((model) => model.taskType === taskType) : models };
21
+ };
18
22
  }
19
23
  export function harnessDeleteModel(harness) {
20
24
  return async ({ name }) => (await harness.deleteModel?.(name)) ?? { name, removed: 0, freedBytes: 0 };
@@ -22,6 +22,7 @@ export function assistantTree(opts) {
22
22
  let offCompactChat = null;
23
23
  let offRetryModelDownload = null;
24
24
  let offModelResidency = null;
25
+ let offModelUsers = null;
25
26
  let offSkills = null;
26
27
  let offSkillCatalog = null;
27
28
  let offSkillManagement = null;
@@ -95,6 +96,7 @@ export function assistantTree(opts) {
95
96
  load: (name) => assistant.loadModel(name),
96
97
  unload: (name) => assistant.unloadModel(name)
97
98
  });
99
+ offModelUsers = core.registerModelUsers((name) => assistant.modelUsers(name));
98
100
  offSkills = core.registerSkills((agentId, modelName, options) => assistant.skills(agentId, modelName, options));
99
101
  const transcribe = harnessTranscribe(harness);
100
102
  offTranscribe = core.registerTranscribe(async (request) => {
@@ -163,6 +165,8 @@ export function assistantTree(opts) {
163
165
  offRetryModelDownload = null;
164
166
  offModelResidency?.();
165
167
  offModelResidency = null;
168
+ offModelUsers?.();
169
+ offModelUsers = null;
166
170
  offSkills?.();
167
171
  offSkills = null;
168
172
  offSkillCatalog?.();
@@ -1,7 +1,7 @@
1
1
  import type { ModelCategory } from '@qvac/harness';
2
2
  import type { Duplex } from 'streamx';
3
3
  import ReadyResource from 'ready-resource';
4
- import type { AssistantKvCacheDeletionResponse, AssistantLoadModelResponse, AssistantModelCatalogRevision, AssistantUnloadModelResponse } from '../spec/hyperschema/types.d.ts';
4
+ import type { AssistantKvCacheDeletionResponse, AssistantLoadModelResponse, AssistantModelCatalogRevision, AssistantModelUsers, AssistantUnloadModelResponse } from '../spec/hyperschema/types.d.ts';
5
5
  import type { Capabilities, SkillOptions } from './api/index.ts';
6
6
  import { type PdfRasterizer } from './core/pdf/rasterize.ts';
7
7
  import type { DriveHost } from './core/fs-drives.ts';
@@ -134,6 +134,9 @@ export declare class QvacAssistant extends ReadyResource {
134
134
  private _agentRunning;
135
135
  unloadModel(name: string): Promise<AssistantUnloadModelResponse>;
136
136
  private _unloadModel;
137
+ modelUsers(name: string): Promise<AssistantModelUsers>;
138
+ private _meshModelUsers;
139
+ private _runnableHost;
137
140
  notifyModelCatalog(): void;
138
141
  retryModelDownload(name: string): Promise<void>;
139
142
  skills(agentId?: string | null, modelName?: string | null, options?: SkillListOptions): Promise<ReadonlyArray<Skill>>;
@@ -142,6 +145,7 @@ export declare class QvacAssistant extends ReadyResource {
142
145
  tools(): Promise<ReadonlyArray<ToolCatalogEntry>>;
143
146
  private _supervisedWatch;
144
147
  private _reclaimDeletedChats;
148
+ private _dropDeletedChat;
145
149
  private _reclaimRekeyedAgents;
146
150
  private _reclaimAgentChatCaches;
147
151
  private _reconcileCompaction;
@@ -5,7 +5,7 @@ import fs from 'fs';
5
5
  import crypto from 'hypercore-crypto';
6
6
  import os from 'os';
7
7
  import path from 'path';
8
- import { mediaModelNameFor } from '@qvac/harness/lib/models/model-catalog.ts';
8
+ import { isMobilePlatform, mediaModelNameFor, modelsForAgent, runnableModelName } from '@qvac/harness/lib/models/model-catalog.ts';
9
9
  import { connectHarness } from '@qvac/harness';
10
10
  import * as z from 'zod';
11
11
  import { loanFailureNotice } from './core/harness-loan.js';
@@ -36,8 +36,7 @@ import { defaultImageCacheDir } from './image-cache-dir.js';
36
36
  import { ModelCatalogRevisionHub } from './model-catalog-revision.js';
37
37
  import { agentRekeyFingerprint, chatKvCacheKey, chatRepairKvCacheKey, disappearedChatIds } from './kv-cache-reclaim.js';
38
38
  import { buildCompactionPrompt, canCompact, foldReducesPrompt, COMPACTION_KEEP_TURNS, COMPACTION_TURN_PREFIX, isContextOverflowFailure, nearContextLimit, compactionBoundary, lastCompactedThroughId, parseCompactionSummary } from './compaction.js';
39
- import { isMobilePlatform, runnableModelName } from './model-clamp.js';
40
- import { ModelDownloadReconciler } from './model-download.js';
39
+ import { ModelDownloadReconciler, musicModelChoiceOf } from './model-download.js';
41
40
  import { AbortedError, raceAbort } from '@qvac/harness/race-abort';
42
41
  import { RunTranscript } from './run-transcript.js';
43
42
  import { searchKnowledge } from './knowledge-search.js';
@@ -312,7 +311,7 @@ export class QvacAssistant extends ReadyResource {
312
311
  this.suspended) {
313
312
  return;
314
313
  }
315
- const model = runnableModelName(agent.modelName, await this._ensureCapability(), this._mobileClass);
314
+ const model = runnableModelName(agent.modelName, await this._runnableHost());
316
315
  if (!(await this._isCached(model))) {
317
316
  this._log?.info('models', 'model warm skipped', { model, reason: 'not cached' });
318
317
  return;
@@ -417,9 +416,9 @@ export class QvacAssistant extends ReadyResource {
417
416
  return DEFAULT_PROFILE;
418
417
  }
419
418
  }
420
- async _sweepImageCache() {
419
+ async _sweepImageCache(gone = new Set()) {
421
420
  try {
422
- const keep = await this._referencedImageNames();
421
+ const keep = await this._referencedImageNames(gone);
423
422
  await sweepImageCache(this._imageCacheDir, {
424
423
  maxBytes: this._imageCacheMaxBytes,
425
424
  maxAgeMs: this._imageCacheMaxAgeMs,
@@ -449,13 +448,14 @@ export class QvacAssistant extends ReadyResource {
449
448
  }
450
449
  return false;
451
450
  }
452
- async _referencedImageNames() {
451
+ async _referencedImageNames(gone) {
453
452
  try {
454
453
  const { files } = await this._engine.listLocalFiles({});
455
454
  if (!files?.length) {
456
455
  return null;
457
456
  }
458
- return new Set(files.map((file) => imageCacheKey(file.blobId)));
457
+ const live = files.filter((file) => !file.chatId || !gone.has(file.chatId));
458
+ return new Set(live.map((file) => imageCacheKey(file.blobId)));
459
459
  }
460
460
  catch (err) {
461
461
  this._log?.warn('assistant', 'reading the local file index failed', err);
@@ -793,8 +793,8 @@ export class QvacAssistant extends ReadyResource {
793
793
  if (!meshId) {
794
794
  return null;
795
795
  }
796
- const capability = await this._ensureCapability();
797
- const runs = (agent) => runnableModelName(agent.modelName, capability, this._mobileClass) === model;
796
+ const host = await this._runnableHost();
797
+ const runs = (agent) => runnableModelName(agent.modelName, host) === model;
798
798
  const active = await this._currentAgent(activeAgentId, deviceId);
799
799
  if (active?.providerDeviceId && b4a.equals(active.providerDeviceId, deviceId) && runs(active)) {
800
800
  return active;
@@ -830,6 +830,43 @@ export class QvacAssistant extends ReadyResource {
830
830
  });
831
831
  return { unloaded };
832
832
  }
833
+ async modelUsers(name) {
834
+ const providerDeviceId = this._requireDeviceId();
835
+ const host = await this._runnableHost();
836
+ const { meshes } = await this._engine.listMeshes({});
837
+ const scanned = await Promise.all((meshes ?? [])
838
+ .filter((mesh) => mesh.open && !mesh.compute)
839
+ .map((mesh) => this._meshModelUsers(name, { meshId: mesh.meshId, providerDeviceId, host })));
840
+ return { agents: scanned.flat() };
841
+ }
842
+ async _meshModelUsers(name, { meshId, providerDeviceId, host }) {
843
+ const { agents } = await this._engine.listAgents({ meshId, providerDeviceId });
844
+ const perAgent = await Promise.all((agents ?? [])
845
+ .filter((agent) => !this._lenderFor(agent))
846
+ .map(async (agent) => {
847
+ let models = modelsForAgent(agent, host);
848
+ if (models.some((model) => model.use === 'music')) {
849
+ const configs = await this._engine
850
+ .listToolConfigs({ agentId: agent.id, meshId })
851
+ .then((result) => result.configs ?? [])
852
+ .catch(() => []);
853
+ models = modelsForAgent({ ...agent, musicModelChoice: musicModelChoiceOf(configs) }, host);
854
+ }
855
+ return models
856
+ .filter((model) => model.name === name)
857
+ .map(({ use }) => ({
858
+ agentId: agent.id,
859
+ meshId,
860
+ agentName: agent.name,
861
+ via: use
862
+ }));
863
+ }));
864
+ return perAgent.flat();
865
+ }
866
+ async _runnableHost() {
867
+ const capability = await this._ensureCapability();
868
+ return capability && { ...capability, mobile: this._mobileClass };
869
+ }
833
870
  notifyModelCatalog() {
834
871
  this._modelCatalog.notify();
835
872
  }
@@ -936,21 +973,30 @@ export class QvacAssistant extends ReadyResource {
936
973
  if (this.closing || this.suspended)
937
974
  return;
938
975
  const ids = (frame.chats ?? []).map((chat) => chat.id);
976
+ const gone = new Set(known === null ? [] : disappearedChatIds(known, ids));
939
977
  if (known !== null) {
940
- for (const chatId of disappearedChatIds(known, ids)) {
941
- this._reconciledCompactions.delete(chatId);
942
- this._chatAttribution.delete(chatId);
943
- void this._deleteChatKvCache(chatId, 'chat deleted');
944
- void this._inferenceCalls
945
- .forget(chatId)
946
- .catch((err) => this._log?.warn('assistant', 'inspector records not dropped', { err }));
978
+ for (const chatId of gone) {
979
+ this._dropDeletedChat(chatId);
947
980
  }
948
981
  }
949
982
  known = new Set(ids);
950
- await this._sweepImageCache();
983
+ await this._sweepImageCache(gone);
951
984
  await this._sweepInferenceCalls();
952
985
  }
953
986
  }
987
+ _dropDeletedChat(chatId) {
988
+ for (const run of this._runs.values()) {
989
+ if (run.chatId === chatId) {
990
+ void RUN_SETTLED;
991
+ }
992
+ }
993
+ this._reconciledCompactions.delete(chatId);
994
+ this._chatAttribution.delete(chatId);
995
+ void this._deleteChatKvCache(chatId, 'chat deleted');
996
+ void this._inferenceCalls
997
+ .forget(chatId)
998
+ .catch((err) => this._log?.warn('assistant', 'inspector records not dropped', { err }));
999
+ }
954
1000
  async _reclaimRekeyedAgents(meshId, frames) {
955
1001
  let known = null;
956
1002
  for await (const frame of frames) {
@@ -1387,7 +1433,7 @@ export class QvacAssistant extends ReadyResource {
1387
1433
  const lender = this._lenderFor(agent);
1388
1434
  const model = lender
1389
1435
  ? agent.modelName
1390
- : runnableModelName(agent.modelName, await this._ensureCapability(), this._mobileClass);
1436
+ : runnableModelName(agent.modelName, await this._runnableHost());
1391
1437
  if (model !== agent.modelName) {
1392
1438
  this._log?.warn('runs', 'model clamped to what this device can run', {
1393
1439
  runId,
@@ -2411,7 +2457,7 @@ export class QvacAssistant extends ReadyResource {
2411
2457
  if (!agent || !agent.providerDeviceId || !b4a.equals(agent.providerDeviceId, deviceId)) {
2412
2458
  return { compacted: false, reason: 'not the provider device' };
2413
2459
  }
2414
- const model = runnableModelName(agent.modelName, await this._ensureCapability(), this._mobileClass);
2460
+ const model = runnableModelName(agent.modelName, await this._runnableHost());
2415
2461
  const config = await engine.getConfig({}).catch(noop);
2416
2462
  const ctxSize = agent.ctxSize || config?.ctxSize || undefined;
2417
2463
  if (ctxSize !== undefined && !canCompact(ctxSize)) {
@@ -27,7 +27,8 @@ export class Client extends ReadyResource {
27
27
  const capabilities = engineClient(rpc);
28
28
  const modelDownloadsWatch = this._reconnecting(capabilities.modelDownloadsWatch, 'model-download');
29
29
  const modelCatalogWatch = this._reconnecting(capabilities.modelCatalogWatch, 'model-catalog');
30
- Object.assign(this, capabilities, { modelCatalogWatch, modelDownloadsWatch });
30
+ const modelsWatch = this._reconnecting(capabilities.modelsWatch, 'models');
31
+ Object.assign(this, capabilities, { modelCatalogWatch, modelDownloadsWatch, modelsWatch });
31
32
  this._log?.info('lifecycle', 'client open');
32
33
  }
33
34
  _reconnecting(open, scope) {
@@ -1,25 +1,25 @@
1
+ import { parentPort } from 'worker_threads';
1
2
  import { asHostJob } from './protocol.js';
2
- import { errorMessage, isRecord } from '../guards.js';
3
+ import { errorMessage } from '../guards.js';
3
4
  async function main() {
4
- const self = Bare.Thread.self;
5
- if (!self) {
5
+ if (!parentPort) {
6
6
  throw new Error('collabora entry loaded on the main thread');
7
7
  }
8
- const { default: Channel } = await import('bare-channel');
9
- const port = Channel.from(handleFrom(self.data)).connect();
8
+ const port = parentPort;
10
9
  const convert = await load();
11
- for (;;) {
12
- const job = asHostJob(await port.read());
10
+ port.on('message', (message) => {
11
+ const job = asHostJob(message);
13
12
  if (!job) {
14
- break;
13
+ port.close();
14
+ return;
15
15
  }
16
16
  if (typeof convert === 'string') {
17
- port.write({ id: job.id, error: convert });
18
- break;
17
+ port.postMessage({ id: job.id, error: convert });
18
+ port.close();
19
+ return;
19
20
  }
20
- port.write(run(convert, job));
21
- }
22
- await port.close();
21
+ port.postMessage(run(convert, job));
22
+ });
23
23
  }
24
24
  async function load() {
25
25
  try {
@@ -39,10 +39,4 @@ function run(convert, job) {
39
39
  return { id: job.id, error: errorMessage(error) };
40
40
  }
41
41
  }
42
- function handleFrom(data) {
43
- if (isRecord(data) && 'handle' in data) {
44
- return data.handle;
45
- }
46
- throw new Error('collabora worker started without a channel handle');
47
- }
48
42
  await main();