@qvac/core 0.6.1 → 0.6.3
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.
- package/CHANGELOG.md +102 -1
- package/dist-lib/lib/api/chat.d.ts +1 -1
- package/dist-lib/lib/api/chat.js +2 -1
- package/dist-lib/lib/api/index.d.ts +3 -1
- package/dist-lib/lib/api/index.js +2 -0
- package/dist-lib/lib/api/watchable.d.ts +1 -0
- package/dist-lib/lib/api/watchable.js +1 -1
- package/dist-lib/lib/assistant/harness.d.ts +2 -0
- package/dist-lib/lib/assistant/harness.js +13 -9
- package/dist-lib/lib/assistant-tree.js +4 -0
- package/dist-lib/lib/assistant.d.ts +4 -1
- package/dist-lib/lib/assistant.js +44 -8
- package/dist-lib/lib/client.js +2 -1
- package/dist-lib/lib/collabora/entry.js +13 -19
- package/dist-lib/lib/collabora/worker.js +77 -18
- package/dist-lib/lib/core/chat.d.ts +1 -0
- package/dist-lib/lib/core/chat.js +17 -0
- package/dist-lib/lib/core/contract/chat.js +10 -3
- package/dist-lib/lib/core.d.ts +12 -2
- package/dist-lib/lib/core.js +57 -14
- package/dist-lib/lib/mesh-scoped-engine.js +3 -0
- package/dist-lib/lib/model-download.d.ts +11 -7
- package/dist-lib/lib/model-download.js +22 -21
- package/dist-lib/lib/models-watch.d.ts +6 -0
- package/dist-lib/lib/models-watch.js +45 -0
- package/dist-lib/schema/engine.d.ts +1 -0
- package/dist-lib/schema/engine.js +57 -3
- package/dist-lib/schema/field-order.js +3 -1
- package/dist-lib/schema/qvac.js +2 -1
- package/dist-lib/spec/bind.js +14 -0
- package/dist-lib/spec/calls.js +3 -0
- package/dist-lib/spec/capabilities.d.ts +6 -0
- package/dist-lib/spec/hrpc/hrpc.json +39 -0
- package/dist-lib/spec/hrpc/index.js +41 -4
- package/dist-lib/spec/hrpc/messages.js +788 -583
- package/dist-lib/spec/hyperschema/index.js +788 -583
- package/dist-lib/spec/hyperschema/schema.json +149 -0
- package/dist-lib/spec/hyperschema/types.d.ts +29 -0
- package/dist-lib/spec/mesh/hyperdb/messages.js +36 -8
- package/dist-lib/spec/mesh/hyperdispatch/messages.js +19 -5
- package/dist-lib/spec/mesh/hyperschema/index.js +19 -5
- package/dist-lib/spec/mesh/hyperschema/schema.json +6 -1
- package/dist-lib/spec/mesh/hyperschema/types.d.ts +2 -1
- package/package.json +22 -9
- package/tui/app.mjs +3 -2
- package/dist-lib/lib/model-clamp.d.ts +0 -6
- package/dist-lib/lib/model-clamp.js +0 -23
package/CHANGELOG.md
CHANGED
|
@@ -13,11 +13,110 @@ release.
|
|
|
13
13
|
|
|
14
14
|
## [Unreleased]
|
|
15
15
|
|
|
16
|
+
## [0.6.3] - 2026-09-30
|
|
17
|
+
|
|
18
|
+
### Changed
|
|
19
|
+
|
|
20
|
+
- `@qvac/harness` is `^0.7.1`, the first harness that names `isLoading` on
|
|
21
|
+
`listModels` rows. Before it every row read `false`. (#288)
|
|
22
|
+
|
|
23
|
+
## [0.6.2] - 2026-09-30
|
|
24
|
+
|
|
25
|
+
### Added
|
|
26
|
+
|
|
27
|
+
- `modelUsers` names the agents on this device that use a model, for a Models
|
|
28
|
+
screen to show before a delete and offer to switch them to another model. It
|
|
29
|
+
counts the model each agent actually runs here, including a skill's image or
|
|
30
|
+
music model and the model a phone clamps an oversized pick to.
|
|
31
|
+
|
|
32
|
+
```js
|
|
33
|
+
const { agents } = await engine.modelUsers({ name: 'Qwen3.5-32B' })
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
(#277)
|
|
37
|
+
|
|
38
|
+
- `listModels` rows carry `taskType`, what the model is for, so a Models
|
|
39
|
+
screen groups by task rather than by the addon in `type`: `whisper` and
|
|
40
|
+
`parakeet` are both `speech-to-text`. `listModels({ taskType })` keeps only
|
|
41
|
+
that task's models. The harness names it, from `@qvac/harness` 0.7.0.
|
|
42
|
+
|
|
43
|
+
```js
|
|
44
|
+
const { models } = await engine.listModels({ taskType: 'speech-to-text' })
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
(#278)
|
|
48
|
+
|
|
49
|
+
- Whether a chat was read now reaches every device of the mesh.
|
|
50
|
+
`markChatRead({ meshId, chatId })` marks a chat read up to its newest chunk,
|
|
51
|
+
and every chat row carries `readThrough`, the next unread seq, so a client can
|
|
52
|
+
clear an unread mark whose event `seq` is below it. It rides `put-chat` and
|
|
53
|
+
never lowers, so it needs no new mesh route and older builds keep applying
|
|
54
|
+
chats. A read is per chat, not per person.
|
|
55
|
+
|
|
56
|
+
```js
|
|
57
|
+
await engine.markChatRead({ meshId, chatId })
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
(#283)
|
|
61
|
+
|
|
62
|
+
- `isLoading` on `listModels` rows: true while the harness loads a chat model
|
|
63
|
+
into memory for the boot warm, `loadModel` or a run this device serves, with a
|
|
64
|
+
`modelCatalogWatch` bump when it turns on and again when it turns off. A
|
|
65
|
+
Models screen or host bar can say a model is loading at boot, before any
|
|
66
|
+
message is sent. The harness names it, from `@qvac/harness` 0.7.1; an older
|
|
67
|
+
harness lists every row as `false`, and other rows read `false` for now.
|
|
68
|
+
|
|
69
|
+
```js
|
|
70
|
+
const { models } = await engine.listModels({ cachedOnly: true })
|
|
71
|
+
const loading = models.filter((model) => model.isLoading)
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
(#270)
|
|
75
|
+
|
|
76
|
+
- `modelsWatch`: the `listModels` rows as a stream, sent again when a load,
|
|
77
|
+
unload, download or custom-model change alters a field a row carries, so a
|
|
78
|
+
Models screen sees a model start loading and become ready without re-reading
|
|
79
|
+
`listModels` on each `modelCatalogWatch` bump.
|
|
80
|
+
`excludeCustom` leaves out the models the user added, on `listModels` too.
|
|
81
|
+
|
|
82
|
+
```js
|
|
83
|
+
for await (const { models } of engine.modelsWatch({ cachedOnly: true })) render(models)
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
(#271)
|
|
87
|
+
|
|
88
|
+
### Changed
|
|
89
|
+
|
|
90
|
+
- `deleteChat` purges the chat on every device, with the file bytes and index
|
|
91
|
+
rows it held, and a device that joins later gets none of it; `deleteAgent`
|
|
92
|
+
purges every chat the agent answered the same way. A device on an older build
|
|
93
|
+
halts on the purge until it updates. This was in the 0.6.1 build unannounced.
|
|
94
|
+
(#266)
|
|
95
|
+
- `engines.bare` is `>=1.34.0`. `bare-runtime` is pinned to 1.34.0 and
|
|
96
|
+
`bare-sidecar` to 0.5.7 (Bare 1.34.0) across the tree, with `bare-thread` at
|
|
97
|
+
least 1.2.7 and `bare-module` 7.1.0 for `bare-worker`'s copy: a worker that
|
|
98
|
+
starts inside a bundle needs `module.resolutions`. (#268)
|
|
99
|
+
- `bare-module` is no longer overridden to 6.4.0, and `bare-module-traverse` is
|
|
100
|
+
overridden to `~2.5.8`, which keeps the addon and asset conditions Bare needs to
|
|
101
|
+
load a bundle's native files. (#268)
|
|
102
|
+
- The collabora worker's entry is now in sight of a bundler. A host that stows
|
|
103
|
+
core carries `bare-collabora` in the bundle for office conversion, or defers
|
|
104
|
+
it and gets "the document engine failed to load". (#268)
|
|
105
|
+
- A conversion whose engine thread dies reports what killed it after "the
|
|
106
|
+
document engine closed unexpectedly", and a malformed job ends the thread at
|
|
107
|
+
once instead of waiting out the deadline. (#268)
|
|
108
|
+
- `bare-channel` is no longer a direct dependency; `bare-worker` brings it. (#268)
|
|
109
|
+
|
|
16
110
|
### Fixed
|
|
17
111
|
|
|
112
|
+
- The collabora worker starts on Bare 1.33 and later, whose threads cannot read
|
|
113
|
+
a module off disk. It is spawned through `worker_threads`, which the package
|
|
114
|
+
maps to `bare-worker` on Bare, and its entry is named with a literal
|
|
115
|
+
`#collabora-worker-entry`, so its graph is bundled into the thread. (#268)
|
|
18
116
|
- `duck` crashed at start on Bare 1.33 and later, `--help` and `--version`
|
|
19
117
|
included, with "Invalid left-hand side expression in prefix operation": Bare
|
|
20
118
|
now links what `import.meta.resolve()` names, and the TUI named a `SKILL.md`.
|
|
119
|
+
This was in the 0.6.1 build unannounced. (#267)
|
|
21
120
|
|
|
22
121
|
## [0.6.1] - 2026-09-29
|
|
23
122
|
|
|
@@ -1052,7 +1151,9 @@ Published under the `release-0.1` dist-tag.
|
|
|
1052
1151
|
await assistant.ready()
|
|
1053
1152
|
```
|
|
1054
1153
|
|
|
1055
|
-
[Unreleased]: https://github.com/tetherto/qvac-core/compare/v0.6.
|
|
1154
|
+
[Unreleased]: https://github.com/tetherto/qvac-core/compare/v0.6.3...HEAD
|
|
1155
|
+
[0.6.3]: https://github.com/tetherto/qvac-core/compare/v0.6.2...v0.6.3
|
|
1156
|
+
[0.6.2]: https://github.com/tetherto/qvac-core/compare/v0.6.1...v0.6.2
|
|
1056
1157
|
[0.6.1]: https://github.com/tetherto/qvac-core/compare/v0.6.0...v0.6.1
|
|
1057
1158
|
[0.6.0]: https://github.com/tetherto/qvac-core/compare/v0.5.0...v0.6.0
|
|
1058
1159
|
[0.5.0]: https://github.com/tetherto/qvac-core/compare/v0.4.1...v0.5.0
|
|
@@ -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?: {
|
package/dist-lib/lib/api/chat.js
CHANGED
|
@@ -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);
|
|
@@ -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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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>>;
|
|
@@ -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 {
|
|
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.
|
|
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;
|
|
@@ -794,8 +793,8 @@ export class QvacAssistant extends ReadyResource {
|
|
|
794
793
|
if (!meshId) {
|
|
795
794
|
return null;
|
|
796
795
|
}
|
|
797
|
-
const
|
|
798
|
-
const runs = (agent) => runnableModelName(agent.modelName,
|
|
796
|
+
const host = await this._runnableHost();
|
|
797
|
+
const runs = (agent) => runnableModelName(agent.modelName, host) === model;
|
|
799
798
|
const active = await this._currentAgent(activeAgentId, deviceId);
|
|
800
799
|
if (active?.providerDeviceId && b4a.equals(active.providerDeviceId, deviceId) && runs(active)) {
|
|
801
800
|
return active;
|
|
@@ -831,6 +830,43 @@ export class QvacAssistant extends ReadyResource {
|
|
|
831
830
|
});
|
|
832
831
|
return { unloaded };
|
|
833
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
|
+
}
|
|
834
870
|
notifyModelCatalog() {
|
|
835
871
|
this._modelCatalog.notify();
|
|
836
872
|
}
|
|
@@ -1397,7 +1433,7 @@ export class QvacAssistant extends ReadyResource {
|
|
|
1397
1433
|
const lender = this._lenderFor(agent);
|
|
1398
1434
|
const model = lender
|
|
1399
1435
|
? agent.modelName
|
|
1400
|
-
: runnableModelName(agent.modelName, await this.
|
|
1436
|
+
: runnableModelName(agent.modelName, await this._runnableHost());
|
|
1401
1437
|
if (model !== agent.modelName) {
|
|
1402
1438
|
this._log?.warn('runs', 'model clamped to what this device can run', {
|
|
1403
1439
|
runId,
|
|
@@ -2421,7 +2457,7 @@ export class QvacAssistant extends ReadyResource {
|
|
|
2421
2457
|
if (!agent || !agent.providerDeviceId || !b4a.equals(agent.providerDeviceId, deviceId)) {
|
|
2422
2458
|
return { compacted: false, reason: 'not the provider device' };
|
|
2423
2459
|
}
|
|
2424
|
-
const model = runnableModelName(agent.modelName, await this.
|
|
2460
|
+
const model = runnableModelName(agent.modelName, await this._runnableHost());
|
|
2425
2461
|
const config = await engine.getConfig({}).catch(noop);
|
|
2426
2462
|
const ctxSize = agent.ctxSize || config?.ctxSize || undefined;
|
|
2427
2463
|
if (ctxSize !== undefined && !canCompact(ctxSize)) {
|
package/dist-lib/lib/client.js
CHANGED
|
@@ -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
|
-
|
|
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
|
|
3
|
+
import { errorMessage } from '../guards.js';
|
|
3
4
|
async function main() {
|
|
4
|
-
|
|
5
|
-
if (!self) {
|
|
5
|
+
if (!parentPort) {
|
|
6
6
|
throw new Error('collabora entry loaded on the main thread');
|
|
7
7
|
}
|
|
8
|
-
const
|
|
9
|
-
const port = Channel.from(handleFrom(self.data)).connect();
|
|
8
|
+
const port = parentPort;
|
|
10
9
|
const convert = await load();
|
|
11
|
-
|
|
12
|
-
const job = asHostJob(
|
|
10
|
+
port.on('message', (message) => {
|
|
11
|
+
const job = asHostJob(message);
|
|
13
12
|
if (!job) {
|
|
14
|
-
|
|
13
|
+
port.close();
|
|
14
|
+
return;
|
|
15
15
|
}
|
|
16
16
|
if (typeof convert === 'string') {
|
|
17
|
-
port.
|
|
18
|
-
|
|
17
|
+
port.postMessage({ id: job.id, error: convert });
|
|
18
|
+
port.close();
|
|
19
|
+
return;
|
|
19
20
|
}
|
|
20
|
-
port.
|
|
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();
|
|
@@ -2,17 +2,25 @@ import process from 'process';
|
|
|
2
2
|
import ScopeLock from 'scope-lock';
|
|
3
3
|
import safetyCatch from 'safety-catch';
|
|
4
4
|
import { fileURLToPath } from 'url';
|
|
5
|
+
import { Worker as Thread } from 'worker_threads';
|
|
5
6
|
import { asWorkerReply } from './protocol.js';
|
|
7
|
+
import { errorMessage } from '../guards.js';
|
|
6
8
|
const DEADLINE_MS = 60_000;
|
|
7
9
|
const lock = new ScopeLock();
|
|
8
10
|
let active = null;
|
|
9
11
|
export async function convertInWorker(job, signal) {
|
|
10
12
|
await lock.lock();
|
|
11
13
|
try {
|
|
12
|
-
const worker = active ?? (active =
|
|
14
|
+
const worker = active ?? (active = spawn());
|
|
13
15
|
const id = worker.nextId++;
|
|
14
|
-
worker.link.
|
|
15
|
-
|
|
16
|
+
worker.link.ref();
|
|
17
|
+
try {
|
|
18
|
+
worker.link.write({ id, ...job });
|
|
19
|
+
await settle(worker, id, signal);
|
|
20
|
+
}
|
|
21
|
+
finally {
|
|
22
|
+
worker.link.unref();
|
|
23
|
+
}
|
|
16
24
|
}
|
|
17
25
|
finally {
|
|
18
26
|
lock.unlock();
|
|
@@ -62,34 +70,85 @@ function abandon(worker) {
|
|
|
62
70
|
}
|
|
63
71
|
worker.link.kill();
|
|
64
72
|
}
|
|
65
|
-
|
|
73
|
+
function spawn() {
|
|
66
74
|
if (typeof Bare === 'undefined') {
|
|
67
75
|
throw new Error('the document engine needs the Bare runtime');
|
|
68
76
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
77
|
+
let thread;
|
|
78
|
+
try {
|
|
79
|
+
thread = new Thread(entry());
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
throw new Error(`the document engine failed to load: ${errorMessage(error)}`);
|
|
83
|
+
}
|
|
84
|
+
const inbox = new Inbox(thread);
|
|
85
|
+
thread.unref();
|
|
73
86
|
return {
|
|
74
87
|
nextId: 1,
|
|
75
88
|
link: {
|
|
76
|
-
read: () =>
|
|
77
|
-
write: (job) =>
|
|
89
|
+
read: () => inbox.read(),
|
|
90
|
+
write: (job) => thread.postMessage(job),
|
|
91
|
+
ref: () => thread.ref(),
|
|
92
|
+
unref: () => thread.unref(),
|
|
78
93
|
kill() {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
catch (error) {
|
|
83
|
-
safetyCatch(error);
|
|
84
|
-
}
|
|
85
|
-
port.close().catch(safetyCatch);
|
|
94
|
+
thread.unref();
|
|
95
|
+
thread.terminate().catch(safetyCatch);
|
|
86
96
|
}
|
|
87
97
|
}
|
|
88
98
|
};
|
|
89
99
|
}
|
|
100
|
+
class Inbox {
|
|
101
|
+
replies = [];
|
|
102
|
+
waiting = [];
|
|
103
|
+
ended = false;
|
|
104
|
+
failure = null;
|
|
105
|
+
constructor(thread) {
|
|
106
|
+
thread.on('message', (reply) => this.push(reply));
|
|
107
|
+
thread.on('error', (error) => this.end(error));
|
|
108
|
+
thread.on('exit', () => this.end());
|
|
109
|
+
}
|
|
110
|
+
read() {
|
|
111
|
+
if (this.replies.length > 0) {
|
|
112
|
+
return Promise.resolve(this.replies.shift());
|
|
113
|
+
}
|
|
114
|
+
if (this.failure) {
|
|
115
|
+
return Promise.reject(this.failure);
|
|
116
|
+
}
|
|
117
|
+
if (this.ended) {
|
|
118
|
+
return Promise.resolve(null);
|
|
119
|
+
}
|
|
120
|
+
return new Promise((resolve, reject) => this.waiting.push({ resolve, reject }));
|
|
121
|
+
}
|
|
122
|
+
push(reply) {
|
|
123
|
+
const next = this.waiting.shift();
|
|
124
|
+
if (next) {
|
|
125
|
+
next.resolve(reply);
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
this.replies.push(reply);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
end(error) {
|
|
132
|
+
if (this.ended) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
this.ended = true;
|
|
136
|
+
if (error !== undefined) {
|
|
137
|
+
this.failure = new Error(`the document engine closed unexpectedly: ${errorMessage(error)}`);
|
|
138
|
+
}
|
|
139
|
+
for (const next of this.waiting.splice(0)) {
|
|
140
|
+
if (this.failure) {
|
|
141
|
+
next.reject(this.failure);
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
next.resolve(null);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
90
149
|
function entry() {
|
|
91
150
|
return (process.env.QVAC_COLLABORA_WORKER_ENTRY ||
|
|
92
|
-
fileURLToPath(
|
|
151
|
+
fileURLToPath(import.meta.resolve('#collabora-worker-entry')));
|
|
93
152
|
}
|
|
94
153
|
function deadlineMs() {
|
|
95
154
|
const ms = Number(process.env.QVAC_COLLABORA_TIMEOUT_MS);
|
|
@@ -38,6 +38,7 @@ export interface MoveChatOptions {
|
|
|
38
38
|
}
|
|
39
39
|
export declare function moveChat(store: Mesh, id: string, { groupId, afterId }: MoveChatOptions): Promise<ChatListing>;
|
|
40
40
|
export declare function setChatWebSearchEnabled(store: Mesh, id: string, webSearchEnabled: boolean): Promise<ChatListing>;
|
|
41
|
+
export declare function markChatRead(store: Mesh, id: string): Promise<ChatListing>;
|
|
41
42
|
export declare function removeChatKnowledge(store: Mesh, chatId: string, at: number): Promise<void>;
|
|
42
43
|
export interface RemoveChatAttachmentsOptions {
|
|
43
44
|
readonly deviceId: Buffer;
|
|
@@ -203,6 +203,23 @@ export async function moveChat(store, id, { groupId, afterId }) {
|
|
|
203
203
|
export function setChatWebSearchEnabled(store, id, webSearchEnabled) {
|
|
204
204
|
return patchChat(store, id, { webSearchEnabled });
|
|
205
205
|
}
|
|
206
|
+
export async function markChatRead(store, id) {
|
|
207
|
+
const chat = await mustGetActiveChat(store, id);
|
|
208
|
+
const snap = store.view.snapshot();
|
|
209
|
+
let count = 0;
|
|
210
|
+
try {
|
|
211
|
+
count = (await snap.get(CHUNK_COUNTERS, { chatId: id }))?.count ?? 0;
|
|
212
|
+
}
|
|
213
|
+
finally {
|
|
214
|
+
await snap.close();
|
|
215
|
+
}
|
|
216
|
+
if (count <= (chat.readThrough || 0)) {
|
|
217
|
+
return enrichChat(store, chat);
|
|
218
|
+
}
|
|
219
|
+
const read = { ...chat, readThrough: count };
|
|
220
|
+
await store.dispatch('put-chat', { chat: read });
|
|
221
|
+
return enrichChat(store, read);
|
|
222
|
+
}
|
|
206
223
|
async function cancelActiveRuns(store, deviceId, chatId) {
|
|
207
224
|
const statuses = await listChunks(store, { chatId, type: 'run-status' });
|
|
208
225
|
const terminal = new Set(statuses.filter((c) => TERMINAL_RUN_STATES.has(c.runStatus?.state ?? '')).map((c) => c.runId));
|
|
@@ -10,17 +10,24 @@ export function registerChatRoutes(router) {
|
|
|
10
10
|
log?.debug('contract', 'put-chat dropped: tombstone is sticky', { id: chat.id });
|
|
11
11
|
return;
|
|
12
12
|
}
|
|
13
|
+
const readThrough = Math.max(existing?.readThrough || 0, chat.readThrough || 0) || undefined;
|
|
13
14
|
if (existing && !chat.deletedAt && (existing.updatedAt ?? 0) > (chat.updatedAt ?? 0)) {
|
|
14
|
-
|
|
15
|
+
if (readThrough === (existing.readThrough || undefined)) {
|
|
16
|
+
log?.debug('contract', 'put-chat dropped: stale updatedAt', { id: chat.id });
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
await tx.insert(CHATS, { ...existing, readThrough });
|
|
20
|
+
log?.debug('contract', 'put-chat stale: read marker kept', { id: chat.id });
|
|
15
21
|
return;
|
|
16
22
|
}
|
|
17
23
|
if (existing && (await isPurged(tx, chat.id))) {
|
|
18
24
|
log?.debug('contract', 'put-chat dropped: chat is purged', { id: chat.id });
|
|
19
25
|
return;
|
|
20
26
|
}
|
|
21
|
-
|
|
27
|
+
const row = { ...chat, readThrough };
|
|
28
|
+
await tx.insert(CHATS, row);
|
|
22
29
|
log?.debug('contract', existing ? 'chat updated' : 'chat created', { id: chat.id });
|
|
23
|
-
return
|
|
30
|
+
return row;
|
|
24
31
|
}));
|
|
25
32
|
router.add('@qvac/purge-chat', trackActivity(async ({ chatId, at }, { tx, log }) => {
|
|
26
33
|
const chat = await tx.get(CHATS, { id: chatId });
|