@qvac/core 0.6.1 → 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.
- package/CHANGELOG.md +94 -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/dist-lib/lib/core.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { BootstrapNode } from 'hyperswarm';
|
|
|
4
4
|
import ReadyGuard from 'ready-guard';
|
|
5
5
|
import ReadyResource from 'ready-resource';
|
|
6
6
|
import type { Logger } from '../index.ts';
|
|
7
|
-
import type { AssistantArchivedMeshList, AssistantCompactChatResponse, AssistantCopySkillResponse, AssistantDeleteModelRequest, AssistantDeleteModelResponse, AssistantDeleteSkillResponse, AssistantKvCacheDeletionResponse, AssistantListModelsRequest, AssistantLoadModelResponse, AssistantManagedSkillsResponse, AssistantMeshList, AssistantAccount, AssistantModelCatalogRevision, AssistantModelInfoList, AssistantOkResponse, AssistantSkillCatalogResponse, AssistantSkillFileResponse, AssistantSpeakRequest, AssistantSpeakResponse, AssistantToolCatalogResponse, AssistantDetectLanguageRequest, AssistantDetectLanguageResponse, AssistantTranscribeRequest, AssistantTranscribeResponse, AssistantUnloadModelResponse, AssistantCustomModelPreview, AssistantPreviewCustomModelRequest } from '../spec/index.d.ts';
|
|
7
|
+
import type { AssistantArchivedMeshList, AssistantCompactChatResponse, AssistantCopySkillResponse, AssistantDeleteModelRequest, AssistantDeleteModelResponse, AssistantDeleteSkillResponse, AssistantKvCacheDeletionResponse, AssistantListModelsRequest, AssistantLoadModelResponse, AssistantManagedSkillsResponse, AssistantMeshList, AssistantAccount, AssistantModelCatalogRevision, AssistantModelInfoList, AssistantOkResponse, AssistantSkillCatalogResponse, AssistantSkillFileResponse, AssistantSpeakRequest, AssistantSpeakResponse, AssistantToolCatalogResponse, AssistantDetectLanguageRequest, AssistantDetectLanguageResponse, AssistantTranscribeRequest, AssistantTranscribeResponse, AssistantUnloadModelResponse, AssistantModelUsers, AssistantCustomModelPreview, AssistantPreviewCustomModelRequest } from '../spec/index.d.ts';
|
|
8
8
|
import type { InferenceCallSource } from './api/inference-calls.ts';
|
|
9
9
|
import { type SkillOptions } from './api/index.ts';
|
|
10
10
|
import { type BlindPeeringOpts } from './core/blind-peers.ts';
|
|
@@ -73,6 +73,9 @@ export interface CoreOptions {
|
|
|
73
73
|
readonly suspend: () => Promise<void>;
|
|
74
74
|
readonly resume: () => Promise<void>;
|
|
75
75
|
};
|
|
76
|
+
grantWritableMs?: number;
|
|
77
|
+
accountWritableMs?: number;
|
|
78
|
+
grantVisibleMs?: number;
|
|
76
79
|
}
|
|
77
80
|
export declare const ACCOUNT_MEMBER_UNKNOWN = "This device is not part of its account yet";
|
|
78
81
|
export declare const AWAITING_ADMISSION = "awaiting-admission";
|
|
@@ -155,6 +158,9 @@ export declare class Core extends ReadyResource {
|
|
|
155
158
|
private readonly _meshSeed;
|
|
156
159
|
private readonly _meshKey;
|
|
157
160
|
private readonly _additionalNodes;
|
|
161
|
+
private readonly _grantWritableMs;
|
|
162
|
+
private readonly _accountWritableMs;
|
|
163
|
+
private readonly _grantVisibleMs;
|
|
158
164
|
private _listModels;
|
|
159
165
|
private _deleteModel;
|
|
160
166
|
private _clearKvCache;
|
|
@@ -228,10 +234,11 @@ export declare class Core extends ReadyResource {
|
|
|
228
234
|
private readonly _diagnosticsProviders;
|
|
229
235
|
private _inferenceCalls;
|
|
230
236
|
private _modelResidency;
|
|
237
|
+
private _modelUsers;
|
|
231
238
|
private _systemInfo;
|
|
232
239
|
private _statusError;
|
|
233
240
|
private _upgradeRequired;
|
|
234
|
-
constructor(transport: Transport, { storagePath, logger, spec, bootstrapNodes, device, app, minSupportedVersion, otaConfigCore, blindPeerKeys, blindPeeringOpts, fileGc, meshSeed, meshKey, additionalNodes, listModels, deleteModel, clearKvCache, deleteChatKvCache, compactChat, modelCatalogWatch, retryModelDownload, transcribe, detectLanguage, previewModelSource, speak, speakStream, embedder, extractors, skills, skillCatalog, tools, hostsModelSource, vectorIndex, apiLifecycle }: CoreOptions);
|
|
241
|
+
constructor(transport: Transport, { storagePath, logger, spec, bootstrapNodes, device, app, minSupportedVersion, otaConfigCore, blindPeerKeys, blindPeeringOpts, fileGc, meshSeed, meshKey, additionalNodes, listModels, deleteModel, clearKvCache, deleteChatKvCache, compactChat, modelCatalogWatch, retryModelDownload, transcribe, detectLanguage, previewModelSource, speak, speakStream, embedder, extractors, skills, skillCatalog, tools, hostsModelSource, vectorIndex, apiLifecycle, grantWritableMs, accountWritableMs, grantVisibleMs }: CoreOptions);
|
|
235
242
|
get devicePublicKey(): Buffer | null;
|
|
236
243
|
private _requireDeviceKeyPair;
|
|
237
244
|
get fsDrives(): DriveHost | null;
|
|
@@ -457,6 +464,7 @@ export declare class Core extends ReadyResource {
|
|
|
457
464
|
compact(force?: boolean): Promise<void>;
|
|
458
465
|
registerDiagnostics(provider: () => object): () => void;
|
|
459
466
|
registerModelResidency(residency: ModelResidency): () => void;
|
|
467
|
+
registerModelUsers(users: (name: string) => Promise<AssistantModelUsers>): () => void;
|
|
460
468
|
registerInferenceCalls(source: InferenceCallSource): () => void;
|
|
461
469
|
registerListModels(hook: (options: AssistantListModelsRequest) => Promise<AssistantModelInfoList>): () => void;
|
|
462
470
|
registerDeleteModel(hook: (options: AssistantDeleteModelRequest) => Promise<AssistantDeleteModelResponse>): () => void;
|
|
@@ -465,6 +473,8 @@ export declare class Core extends ReadyResource {
|
|
|
465
473
|
registerCompactChat(hook: (chatId: string, meshId: string) => Promise<AssistantCompactChatResponse>): () => void;
|
|
466
474
|
registerModelCatalogWatch(hook: () => AsyncIterable<AssistantModelCatalogRevision>): () => void;
|
|
467
475
|
private _watchModelCatalog;
|
|
476
|
+
private _modelCatalogRevisions;
|
|
477
|
+
private _readModels;
|
|
468
478
|
private _openModelCatalogWatchSource;
|
|
469
479
|
private _resetModelCatalogWatchSource;
|
|
470
480
|
registerRetryModelDownload(hook: (name: string) => Promise<void>): () => void;
|
package/dist-lib/lib/core.js
CHANGED
|
@@ -13,6 +13,7 @@ import ReadyResource from 'ready-resource';
|
|
|
13
13
|
import ScopeLock from 'scope-lock';
|
|
14
14
|
import { createApi } from './api/index.js';
|
|
15
15
|
import { NO_SUCH_MESH } from './api/current-mesh.js';
|
|
16
|
+
import { asEncoded, watchModels } from './models-watch.js';
|
|
16
17
|
import { BLIND_PEER_KEYS, BLIND_RELAY_KEYS } from './core/blind-peers.js';
|
|
17
18
|
import { CoreBlobServer, MemoryVectorIndex } from './core/files/index.js';
|
|
18
19
|
import { getChat, removeChatAttachments, removeChatKnowledge } from './core/chat.js';
|
|
@@ -139,6 +140,9 @@ export class Core extends ReadyResource {
|
|
|
139
140
|
_meshSeed;
|
|
140
141
|
_meshKey;
|
|
141
142
|
_additionalNodes;
|
|
143
|
+
_grantWritableMs;
|
|
144
|
+
_accountWritableMs;
|
|
145
|
+
_grantVisibleMs;
|
|
142
146
|
_listModels;
|
|
143
147
|
_deleteModel;
|
|
144
148
|
_clearKvCache;
|
|
@@ -212,10 +216,11 @@ export class Core extends ReadyResource {
|
|
|
212
216
|
_diagnosticsProviders;
|
|
213
217
|
_inferenceCalls = null;
|
|
214
218
|
_modelResidency = null;
|
|
219
|
+
_modelUsers = null;
|
|
215
220
|
_systemInfo;
|
|
216
221
|
_statusError;
|
|
217
222
|
_upgradeRequired;
|
|
218
|
-
constructor(transport, { storagePath, logger = null, spec = openLocalSpec, bootstrapNodes = undefined, device = undefined, app = undefined, minSupportedVersion = undefined, otaConfigCore = undefined, blindPeerKeys = undefined, blindPeeringOpts = undefined, fileGc = null, meshSeed = undefined, meshKey = undefined, additionalNodes = undefined, listModels = undefined, deleteModel = undefined, clearKvCache = undefined, deleteChatKvCache = undefined, compactChat = undefined, modelCatalogWatch = undefined, retryModelDownload = undefined, transcribe = undefined, detectLanguage = undefined, previewModelSource = undefined, speak = undefined, speakStream = undefined, embedder = undefined, extractors = undefined, skills = undefined, skillCatalog = undefined, tools = undefined, hostsModelSource = false, vectorIndex = undefined, apiLifecycle = undefined }) {
|
|
223
|
+
constructor(transport, { storagePath, logger = null, spec = openLocalSpec, bootstrapNodes = undefined, device = undefined, app = undefined, minSupportedVersion = undefined, otaConfigCore = undefined, blindPeerKeys = undefined, blindPeeringOpts = undefined, fileGc = null, meshSeed = undefined, meshKey = undefined, additionalNodes = undefined, listModels = undefined, deleteModel = undefined, clearKvCache = undefined, deleteChatKvCache = undefined, compactChat = undefined, modelCatalogWatch = undefined, retryModelDownload = undefined, transcribe = undefined, detectLanguage = undefined, previewModelSource = undefined, speak = undefined, speakStream = undefined, embedder = undefined, extractors = undefined, skills = undefined, skillCatalog = undefined, tools = undefined, hostsModelSource = false, vectorIndex = undefined, apiLifecycle = undefined, grantWritableMs = GRANT_WRITABLE_MS, accountWritableMs = ACCOUNT_WRITABLE_MS, grantVisibleMs = GRANT_VISIBLE_MS }) {
|
|
219
224
|
super();
|
|
220
225
|
this._transport = transport;
|
|
221
226
|
this._apiLifecycle = apiLifecycle ?? {
|
|
@@ -257,6 +262,9 @@ export class Core extends ReadyResource {
|
|
|
257
262
|
this._meshSeed = meshSeed;
|
|
258
263
|
this._meshKey = meshKey;
|
|
259
264
|
this._additionalNodes = additionalNodes;
|
|
265
|
+
this._grantWritableMs = grantWritableMs;
|
|
266
|
+
this._accountWritableMs = accountWritableMs;
|
|
267
|
+
this._grantVisibleMs = grantVisibleMs;
|
|
260
268
|
this._listModels = listModels ?? null;
|
|
261
269
|
this._deleteModel = deleteModel ?? null;
|
|
262
270
|
this._clearKvCache = clearKvCache ?? null;
|
|
@@ -413,7 +421,7 @@ export class Core extends ReadyResource {
|
|
|
413
421
|
computeLender: () => this._computeLender(),
|
|
414
422
|
pushSkillSecret: (request) => this.pushSkillSecret(request),
|
|
415
423
|
listModels: this._hostsModelSource || this._listModels
|
|
416
|
-
? (
|
|
424
|
+
? async (request) => ({ models: (await this._readModels(request)) ?? [] })
|
|
417
425
|
: null,
|
|
418
426
|
deleteModel: this._hostsModelSource || this._deleteModel
|
|
419
427
|
? (options) => this._deleteModel?.(options) ??
|
|
@@ -427,6 +435,9 @@ export class Core extends ReadyResource {
|
|
|
427
435
|
? ({ name }) => this._modelResidency?.unload(name) ??
|
|
428
436
|
Promise.reject(new Error('no model runtime is bound'))
|
|
429
437
|
: null,
|
|
438
|
+
modelUsers: this._hostsModelSource
|
|
439
|
+
? ({ name }) => this._modelUsers?.(name) ?? Promise.reject(new Error('no model runtime is bound'))
|
|
440
|
+
: null,
|
|
430
441
|
clearKvCache: () => this._clearKvCache?.() ??
|
|
431
442
|
Promise.resolve({
|
|
432
443
|
status: 'unsupported',
|
|
@@ -442,6 +453,9 @@ export class Core extends ReadyResource {
|
|
|
442
453
|
modelCatalogWatch: this._hostsModelSource || this._modelCatalogWatch
|
|
443
454
|
? () => this._watchModelCatalog()
|
|
444
455
|
: null,
|
|
456
|
+
modelsWatch: this._hostsModelSource || this._modelCatalogWatch
|
|
457
|
+
? (request) => watchModels(() => this._modelCatalogRevisions(), () => this._readModels(request))
|
|
458
|
+
: null,
|
|
445
459
|
retryModelDownload: this._hostsModelSource || this._retryModelDownload
|
|
446
460
|
? ({ name }) => this._retryModelDownload?.(name) ??
|
|
447
461
|
Promise.reject(new Error('no model download source bound'))
|
|
@@ -1789,7 +1803,7 @@ export class Core extends ReadyResource {
|
|
|
1789
1803
|
const cancellation = {
|
|
1790
1804
|
canceled: false,
|
|
1791
1805
|
accepting: true,
|
|
1792
|
-
deadline: Date.now() +
|
|
1806
|
+
deadline: Date.now() + this._grantVisibleMs,
|
|
1793
1807
|
account: !invite.memberInvite
|
|
1794
1808
|
};
|
|
1795
1809
|
this._joinCancellation = cancellation;
|
|
@@ -1981,7 +1995,11 @@ export class Core extends ReadyResource {
|
|
|
1981
1995
|
return;
|
|
1982
1996
|
}
|
|
1983
1997
|
try {
|
|
1984
|
-
await Promise.race([
|
|
1998
|
+
await Promise.race([
|
|
1999
|
+
mesh.waitForWritable(),
|
|
2000
|
+
this._closeSignal,
|
|
2001
|
+
after(this._accountWritableMs)
|
|
2002
|
+
]);
|
|
1985
2003
|
if (!mesh.writable) {
|
|
1986
2004
|
this._log?.warn(['p2p', 'mesh'], `the old ${kind} never went writable, so its writer was not revoked`, { meshId });
|
|
1987
2005
|
return;
|
|
@@ -2045,7 +2063,11 @@ export class Core extends ReadyResource {
|
|
|
2045
2063
|
const held = key ? this._pooled(b4a.toHex(key)) : null;
|
|
2046
2064
|
const mesh = key ? await this._openPooledMesh(b4a.toHex(key)).catch(noop) : null;
|
|
2047
2065
|
if (mesh && !mesh.writable) {
|
|
2048
|
-
await Promise.race([
|
|
2066
|
+
await Promise.race([
|
|
2067
|
+
mesh.waitForWritable(),
|
|
2068
|
+
this._closeSignal,
|
|
2069
|
+
after(this._accountWritableMs)
|
|
2070
|
+
]);
|
|
2049
2071
|
}
|
|
2050
2072
|
if (mesh && !mesh.ourMemberId) {
|
|
2051
2073
|
await mesh.refreshOurMember();
|
|
@@ -2343,7 +2365,7 @@ export class Core extends ReadyResource {
|
|
|
2343
2365
|
? setTimeout(() => {
|
|
2344
2366
|
cleanup();
|
|
2345
2367
|
reject(new Error(GRANT_JOIN_TIMED_OUT));
|
|
2346
|
-
},
|
|
2368
|
+
}, this._grantWritableMs)
|
|
2347
2369
|
: undefined;
|
|
2348
2370
|
this._cancelCandidateJoin = onCanceled;
|
|
2349
2371
|
candidate.autobee.on('writable', onWritable);
|
|
@@ -3805,11 +3827,11 @@ export class Core extends ReadyResource {
|
|
|
3805
3827
|
if (!(await this._meshSeedHandoff.admit(sibling, mesh.key, claim).catch(noop))) {
|
|
3806
3828
|
continue;
|
|
3807
3829
|
}
|
|
3808
|
-
await mesh.waitForWritable(
|
|
3830
|
+
await mesh.waitForWritable(this._accountWritableMs);
|
|
3809
3831
|
}
|
|
3810
|
-
if (!mesh.writable && (await mesh.waitForGenesis(
|
|
3832
|
+
if (!mesh.writable && (await mesh.waitForGenesis(this._accountWritableMs)) === null) {
|
|
3811
3833
|
await mesh.appendBirthOp(this._requireDeviceKeyPair(), this._localDevice ?? undefined);
|
|
3812
|
-
await mesh.waitForWritable(
|
|
3834
|
+
await mesh.waitForWritable(this._accountWritableMs);
|
|
3813
3835
|
}
|
|
3814
3836
|
if (mesh.writable) {
|
|
3815
3837
|
await this.local.markAwaitingAdmission(mesh.key, { awaitingAdmission: false });
|
|
@@ -4394,6 +4416,14 @@ export class Core extends ReadyResource {
|
|
|
4394
4416
|
}
|
|
4395
4417
|
};
|
|
4396
4418
|
}
|
|
4419
|
+
registerModelUsers(users) {
|
|
4420
|
+
this._modelUsers = users;
|
|
4421
|
+
return () => {
|
|
4422
|
+
if (this._modelUsers === users) {
|
|
4423
|
+
this._modelUsers = null;
|
|
4424
|
+
}
|
|
4425
|
+
};
|
|
4426
|
+
}
|
|
4397
4427
|
registerInferenceCalls(source) {
|
|
4398
4428
|
this._inferenceCalls = source;
|
|
4399
4429
|
return () => {
|
|
@@ -4455,21 +4485,34 @@ export class Core extends ReadyResource {
|
|
|
4455
4485
|
};
|
|
4456
4486
|
}
|
|
4457
4487
|
async *_watchModelCatalog() {
|
|
4488
|
+
const revisions = await this._modelCatalogRevisions();
|
|
4489
|
+
if (revisions) {
|
|
4490
|
+
yield* revisions;
|
|
4491
|
+
}
|
|
4492
|
+
}
|
|
4493
|
+
async _modelCatalogRevisions() {
|
|
4458
4494
|
while (!this.closing) {
|
|
4459
4495
|
const source = this._modelCatalogWatchSource;
|
|
4460
4496
|
try {
|
|
4461
4497
|
await source.ready();
|
|
4462
4498
|
}
|
|
4463
4499
|
catch {
|
|
4464
|
-
return;
|
|
4500
|
+
return null;
|
|
4465
4501
|
}
|
|
4466
4502
|
const watch = this._modelCatalogWatch;
|
|
4467
|
-
if (
|
|
4468
|
-
|
|
4503
|
+
if (watch) {
|
|
4504
|
+
return watch();
|
|
4469
4505
|
}
|
|
4470
|
-
yield* watch();
|
|
4471
|
-
return;
|
|
4472
4506
|
}
|
|
4507
|
+
return null;
|
|
4508
|
+
}
|
|
4509
|
+
async _readModels({ excludeCustom, ...options }) {
|
|
4510
|
+
const list = await this._listModels?.(options);
|
|
4511
|
+
if (!list) {
|
|
4512
|
+
return null;
|
|
4513
|
+
}
|
|
4514
|
+
const models = list.models ?? [];
|
|
4515
|
+
return asEncoded(excludeCustom ? models.filter((model) => model.registrySource !== 'custom') : models);
|
|
4473
4516
|
}
|
|
4474
4517
|
_openModelCatalogWatchSource() {
|
|
4475
4518
|
if (!this._modelCatalogWatch || !this._modelCatalogWatchSource.enter()) {
|
|
@@ -11,6 +11,7 @@ export const MESH_SCOPED = new Set([
|
|
|
11
11
|
'listChats',
|
|
12
12
|
'getChat',
|
|
13
13
|
'renameChat',
|
|
14
|
+
'markChatRead',
|
|
14
15
|
'setChatRagEnabled',
|
|
15
16
|
'setChatWebSearchEnabled',
|
|
16
17
|
'deleteChat',
|
|
@@ -102,7 +103,9 @@ const DEVICE_LOCAL = new Set([
|
|
|
102
103
|
'deleteModel',
|
|
103
104
|
'loadModel',
|
|
104
105
|
'unloadModel',
|
|
106
|
+
'modelUsers',
|
|
105
107
|
'modelCatalogWatch',
|
|
108
|
+
'modelsWatch',
|
|
106
109
|
'clearKvCache',
|
|
107
110
|
'deleteChatKvCache',
|
|
108
111
|
'transcribe',
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type AbortSignal } from 'bare-abort-controller';
|
|
2
|
-
import { type AgentSkillModelInput } from '@qvac/harness/lib/models/model-catalog.ts';
|
|
2
|
+
import { type AgentSkillModelInput, type HostCapability } from '@qvac/harness/lib/models/model-catalog.ts';
|
|
3
|
+
import { type MusicModelChoice } from '@qvac/harness/music-catalog';
|
|
3
4
|
import type { AssistantAppConfig } from '../spec/hyperschema/types.d.ts';
|
|
4
5
|
import { type ModelProgressFrame } from '@qvac/harness/model-progress';
|
|
5
|
-
import { type HostCapability } from './model-clamp.ts';
|
|
6
6
|
import { type StatusRow } from './model-download-status.ts';
|
|
7
7
|
import type { Logger } from './log.ts';
|
|
8
8
|
export interface DownloadArgs {
|
|
@@ -33,9 +33,14 @@ interface DownloadHarness {
|
|
|
33
33
|
name: string;
|
|
34
34
|
addon: string;
|
|
35
35
|
}>>;
|
|
36
|
-
capability?(): Promise<
|
|
36
|
+
capability?(): Promise<ProbedCapability>;
|
|
37
37
|
download?(args: DownloadArgs): DownloadEventStream;
|
|
38
38
|
}
|
|
39
|
+
type ProbedCapability = Omit<HostCapability, 'mobile'>;
|
|
40
|
+
interface ToolConfigRow {
|
|
41
|
+
toolName?: string | null;
|
|
42
|
+
settings?: unknown;
|
|
43
|
+
}
|
|
39
44
|
interface ModelTransfer {
|
|
40
45
|
readonly name: string;
|
|
41
46
|
readonly transferId: string;
|
|
@@ -68,10 +73,7 @@ interface DownloadEngine {
|
|
|
68
73
|
agentId: string;
|
|
69
74
|
meshId: string;
|
|
70
75
|
}): Promise<{
|
|
71
|
-
configs?: ReadonlyArray<
|
|
72
|
-
toolName?: string | null;
|
|
73
|
-
settings?: unknown;
|
|
74
|
-
}> | null;
|
|
76
|
+
configs?: ReadonlyArray<ToolConfigRow> | null;
|
|
75
77
|
}>;
|
|
76
78
|
toolConfigsWatch(request: {
|
|
77
79
|
agentId: string;
|
|
@@ -198,6 +200,7 @@ export declare class ModelDownloadReconciler {
|
|
|
198
200
|
private _deviceProfile;
|
|
199
201
|
private _hostCapability;
|
|
200
202
|
private _refreshLocalAgentModels;
|
|
203
|
+
private _adoptLocalModels;
|
|
201
204
|
private _musicModelChoice;
|
|
202
205
|
private _begin;
|
|
203
206
|
private _removeDemandWaiter;
|
|
@@ -207,4 +210,5 @@ export declare class ModelDownloadReconciler {
|
|
|
207
210
|
private _stopActive;
|
|
208
211
|
private _download;
|
|
209
212
|
}
|
|
213
|
+
export declare function musicModelChoiceOf(configs: ReadonlyArray<ToolConfigRow | null>): MusicModelChoice | undefined;
|
|
210
214
|
export {};
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { AbortController } from 'bare-abort-controller';
|
|
2
|
-
import {
|
|
3
|
-
import { GENERATE_MUSIC_TOOL
|
|
2
|
+
import { modelsForAgent, musicModelChoiceFrom } from '@qvac/harness/lib/models/model-catalog.ts';
|
|
3
|
+
import { GENERATE_MUSIC_TOOL } from '@qvac/harness/music-catalog';
|
|
4
4
|
import { DeadlineScheduler } from './deadline.js';
|
|
5
5
|
import { DownloadSpeedSampler, progressBytes, transferProgress } from '@qvac/harness/model-progress';
|
|
6
|
-
import { runnableModelName } from './model-clamp.js';
|
|
7
6
|
import { ModelDownloadStatus } from './model-download-status.js';
|
|
8
7
|
import { RetryBudget } from './retry-budget.js';
|
|
9
8
|
import { unref } from './unref.js';
|
|
@@ -641,8 +640,8 @@ export class ModelDownloadReconciler {
|
|
|
641
640
|
if (!probed?.recommendedModelName) {
|
|
642
641
|
return null;
|
|
643
642
|
}
|
|
644
|
-
this._capability = probed;
|
|
645
|
-
return
|
|
643
|
+
this._capability = { ...probed, mobile: this._mobileClass };
|
|
644
|
+
return this._capability;
|
|
646
645
|
}
|
|
647
646
|
catch (err) {
|
|
648
647
|
this._log?.warn('model-download', 'capability probe failed', err);
|
|
@@ -662,14 +661,22 @@ export class ModelDownloadReconciler {
|
|
|
662
661
|
if (!agent.providerDeviceId || !b4a.equals(agent.providerDeviceId, this._deviceId)) {
|
|
663
662
|
return;
|
|
664
663
|
}
|
|
665
|
-
const
|
|
664
|
+
const host = await this._hostCapability();
|
|
666
665
|
const music = await this._musicModelChoice(activeAgentId);
|
|
667
666
|
if (this._config?.activeAgentId !== activeAgentId) {
|
|
668
667
|
return;
|
|
669
668
|
}
|
|
670
|
-
if (
|
|
669
|
+
if (music.ok) {
|
|
670
|
+
this._musicChoice = music.choice;
|
|
671
|
+
}
|
|
672
|
+
const models = modelsForAgent({ ...agent, musicModelChoice: this._musicChoice }, host);
|
|
673
|
+
this._adoptLocalModels(agent.modelName, models);
|
|
674
|
+
}
|
|
675
|
+
_adoptLocalModels(requested, models) {
|
|
676
|
+
const model = models.find((entry) => entry.use === 'chat')?.name ?? requested;
|
|
677
|
+
if (model !== requested) {
|
|
671
678
|
this._log?.warn('model-download', 'model clamped to what this device can run', {
|
|
672
|
-
requested
|
|
679
|
+
requested,
|
|
673
680
|
model
|
|
674
681
|
});
|
|
675
682
|
}
|
|
@@ -677,10 +684,9 @@ export class ModelDownloadReconciler {
|
|
|
677
684
|
this._preemptLlm = model;
|
|
678
685
|
}
|
|
679
686
|
this._localLlm = model;
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
this._localSkillModels = skillModelsForAgent({ ...agent, musicModelChoice: this._musicChoice });
|
|
687
|
+
this._localSkillModels = models
|
|
688
|
+
.filter((entry) => entry.use !== 'chat')
|
|
689
|
+
.map(({ name, addon }) => ({ name, addon }));
|
|
684
690
|
}
|
|
685
691
|
async _musicModelChoice(agentId) {
|
|
686
692
|
const meshId = this._meshId();
|
|
@@ -694,13 +700,7 @@ export class ModelDownloadReconciler {
|
|
|
694
700
|
if (!configs) {
|
|
695
701
|
return { ok: false };
|
|
696
702
|
}
|
|
697
|
-
|
|
698
|
-
const settings = row?.settings;
|
|
699
|
-
if (!settings || typeof settings !== 'object') {
|
|
700
|
-
return { ok: true, choice: undefined };
|
|
701
|
-
}
|
|
702
|
-
const choice = 'modelChoice' in settings ? settings.modelChoice : undefined;
|
|
703
|
-
return { ok: true, choice: isMusicModelChoice(choice) ? choice : undefined };
|
|
703
|
+
return { ok: true, choice: musicModelChoiceOf(configs) };
|
|
704
704
|
}
|
|
705
705
|
_begin({ name, addon, total }) {
|
|
706
706
|
const controller = new AbortController();
|
|
@@ -901,7 +901,8 @@ function shouldFlush(previous, { at, percentage }) {
|
|
|
901
901
|
at - previous.at >= LOCAL_PROGRESS_INTERVAL_MS ||
|
|
902
902
|
percentage - previous.percentage >= LOCAL_PROGRESS_PERCENTAGE_STEP);
|
|
903
903
|
}
|
|
904
|
-
function
|
|
905
|
-
|
|
904
|
+
export function musicModelChoiceOf(configs) {
|
|
905
|
+
const music = configs.find((entry) => entry?.toolName === GENERATE_MUSIC_TOOL);
|
|
906
|
+
return musicModelChoiceFrom(music?.settings);
|
|
906
907
|
}
|
|
907
908
|
function noop() { }
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { AssistantModelCatalogRevision, AssistantModelInfo, AssistantModelInfoList } from '../spec/hyperschema/types.d.ts';
|
|
2
|
+
type Catalog = () => Promise<AsyncIterable<AssistantModelCatalogRevision> | null>;
|
|
3
|
+
type Read = () => Promise<AssistantModelInfo[] | null>;
|
|
4
|
+
export declare function watchModels(catalog: Catalog, read: Read): AsyncIterable<AssistantModelInfoList>;
|
|
5
|
+
export declare function asEncoded(models: AssistantModelInfo[]): AssistantModelInfo[];
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { decode, encode } from '../spec/hyperschema/index.js';
|
|
2
|
+
import { snapshotEquals } from './api/watchable.js';
|
|
3
|
+
class ModelsWatch {
|
|
4
|
+
_catalog;
|
|
5
|
+
_read;
|
|
6
|
+
_revisions = null;
|
|
7
|
+
_opening = null;
|
|
8
|
+
_closed = false;
|
|
9
|
+
_last = null;
|
|
10
|
+
constructor(catalog, read) {
|
|
11
|
+
this._catalog = catalog;
|
|
12
|
+
this._read = read;
|
|
13
|
+
}
|
|
14
|
+
async next() {
|
|
15
|
+
this._opening ??= this._open();
|
|
16
|
+
const revisions = await this._opening;
|
|
17
|
+
while (revisions && !this._closed && !(await revisions.next()).done) {
|
|
18
|
+
const models = this._closed ? null : await this._read();
|
|
19
|
+
if (models === null || this._closed || snapshotEquals(models, this._last)) {
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
this._last = models;
|
|
23
|
+
return { value: { models }, done: false };
|
|
24
|
+
}
|
|
25
|
+
return { value: undefined, done: true };
|
|
26
|
+
}
|
|
27
|
+
async return() {
|
|
28
|
+
this._closed = true;
|
|
29
|
+
await this._revisions?.return?.();
|
|
30
|
+
return { value: undefined, done: true };
|
|
31
|
+
}
|
|
32
|
+
async _open() {
|
|
33
|
+
this._revisions = (await this._catalog())?.[Symbol.asyncIterator]() ?? null;
|
|
34
|
+
if (this._closed) {
|
|
35
|
+
await this._revisions?.return?.();
|
|
36
|
+
}
|
|
37
|
+
return this._revisions;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export function watchModels(catalog, read) {
|
|
41
|
+
return { [Symbol.asyncIterator]: () => new ModelsWatch(catalog, read) };
|
|
42
|
+
}
|
|
43
|
+
export function asEncoded(models) {
|
|
44
|
+
return models.map((model) => decode('@assistant/model-info', encode('@assistant/model-info', model)));
|
|
45
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { type Registry } from './content.ts';
|
|
2
|
+
export declare const MODEL_TASK_TYPES: readonly ['llm', 'embeddings', 'speech-to-text', 'text-to-speech', 'image-generation', 'audio-generation', 'translation', 'text-recognition', 'other'];
|
|
2
3
|
export declare function registerEngineTypes(ns: Registry): void;
|
|
3
4
|
export declare function registerEngineApi(api: Registry): void;
|
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import { registerContentTypes, versionedRegistrar } from './content.js';
|
|
2
2
|
import { MEDIA_KINDS } from './media-kind.js';
|
|
3
3
|
import { APP_CHANNELS, CAPABILITY_PROFILES, INDEXING_STATES } from './qvac.js';
|
|
4
|
+
export const MODEL_TASK_TYPES = [
|
|
5
|
+
'llm',
|
|
6
|
+
'embeddings',
|
|
7
|
+
'speech-to-text',
|
|
8
|
+
'text-to-speech',
|
|
9
|
+
'image-generation',
|
|
10
|
+
'audio-generation',
|
|
11
|
+
'translation',
|
|
12
|
+
'text-recognition',
|
|
13
|
+
'other'
|
|
14
|
+
];
|
|
4
15
|
const rangeBounds = () => [
|
|
5
16
|
{ name: 'gt', type: 'uint' },
|
|
6
17
|
{ name: 'gte', type: 'uint' },
|
|
@@ -194,7 +205,8 @@ export function registerEngineTypes(ns) {
|
|
|
194
205
|
{ name: 'webSearchEnabled', type: 'bool' },
|
|
195
206
|
{ name: 'updatedAt', type: 'uint' },
|
|
196
207
|
{ name: 'lastActivityAt', type: 'uint' },
|
|
197
|
-
{ name: 'groupId', type: 'string' }
|
|
208
|
+
{ name: 'groupId', type: 'string' },
|
|
209
|
+
{ name: 'readThrough', type: 'uint' }
|
|
198
210
|
]
|
|
199
211
|
});
|
|
200
212
|
ns.register({
|
|
@@ -907,12 +919,15 @@ export function registerEngineTypes(ns) {
|
|
|
907
919
|
name: 'join-mesh-request',
|
|
908
920
|
fields: [{ name: 'invite', type: 'string', required: true }]
|
|
909
921
|
});
|
|
922
|
+
ns.register({ name: 'model-task-type', enum: [...MODEL_TASK_TYPES], strings: true });
|
|
910
923
|
ns.register({
|
|
911
924
|
name: 'list-models-request',
|
|
912
925
|
fields: [
|
|
913
926
|
{ name: 'type', type: 'string' },
|
|
914
927
|
{ name: 'cachedOnly', type: 'bool' },
|
|
915
|
-
{ name: 'fullRegistry', type: 'bool' }
|
|
928
|
+
{ name: 'fullRegistry', type: 'bool' },
|
|
929
|
+
{ name: 'taskType', type: '@assistant/model-task-type' },
|
|
930
|
+
{ name: 'excludeCustom', type: 'bool' }
|
|
916
931
|
]
|
|
917
932
|
});
|
|
918
933
|
ns.register({
|
|
@@ -926,7 +941,9 @@ export function registerEngineTypes(ns) {
|
|
|
926
941
|
{ name: 'isLoaded', type: 'bool', required: true },
|
|
927
942
|
{ name: 'expectedSize', type: 'uint', required: true },
|
|
928
943
|
{ name: 'actualSize', type: 'uint' },
|
|
929
|
-
{ name: 'supportsImages', type: 'bool' }
|
|
944
|
+
{ name: 'supportsImages', type: 'bool' },
|
|
945
|
+
{ name: 'taskType', type: '@assistant/model-task-type' },
|
|
946
|
+
{ name: 'isLoading', type: 'bool' }
|
|
930
947
|
]
|
|
931
948
|
});
|
|
932
949
|
ns.register({
|
|
@@ -1981,6 +1998,28 @@ export function registerEngineTypes(ns) {
|
|
|
1981
1998
|
name: 'unload-model-response',
|
|
1982
1999
|
fields: [{ name: 'unloaded', type: 'bool', required: true }]
|
|
1983
2000
|
});
|
|
2001
|
+
ns.register({
|
|
2002
|
+
name: 'model-use',
|
|
2003
|
+
enum: ['chat', 'image', 'music'],
|
|
2004
|
+
strings: true
|
|
2005
|
+
});
|
|
2006
|
+
ns.register({
|
|
2007
|
+
name: 'model-users-request',
|
|
2008
|
+
fields: [{ name: 'name', type: 'string', required: true }]
|
|
2009
|
+
});
|
|
2010
|
+
ns.register({
|
|
2011
|
+
name: 'model-user',
|
|
2012
|
+
fields: [
|
|
2013
|
+
{ name: 'agentId', type: 'string', required: true },
|
|
2014
|
+
{ name: 'meshId', type: 'string', required: true },
|
|
2015
|
+
{ name: 'agentName', type: 'string', required: true },
|
|
2016
|
+
{ name: 'via', type: '@assistant/model-use', required: true }
|
|
2017
|
+
]
|
|
2018
|
+
});
|
|
2019
|
+
ns.register({
|
|
2020
|
+
name: 'model-users',
|
|
2021
|
+
fields: [{ name: 'agents', type: '@assistant/model-user', array: true }]
|
|
2022
|
+
});
|
|
1984
2023
|
}
|
|
1985
2024
|
export function registerEngineApi(api) {
|
|
1986
2025
|
api.register({
|
|
@@ -2728,4 +2767,19 @@ export function registerEngineApi(api) {
|
|
|
2728
2767
|
request: { name: '@assistant/preview-custom-model-request', stream: false },
|
|
2729
2768
|
response: { name: '@assistant/custom-model-preview', stream: false }
|
|
2730
2769
|
});
|
|
2770
|
+
api.register({
|
|
2771
|
+
name: 'model-users',
|
|
2772
|
+
request: { name: '@assistant/model-users-request', stream: false },
|
|
2773
|
+
response: { name: '@assistant/model-users', stream: false }
|
|
2774
|
+
});
|
|
2775
|
+
api.register({
|
|
2776
|
+
name: 'mark-chat-read',
|
|
2777
|
+
request: { name: '@assistant/chat-id', stream: false },
|
|
2778
|
+
response: { name: '@assistant/chat', stream: false }
|
|
2779
|
+
});
|
|
2780
|
+
api.register({
|
|
2781
|
+
name: 'models-watch',
|
|
2782
|
+
request: { name: '@assistant/list-models-request', stream: false },
|
|
2783
|
+
response: { name: '@assistant/model-info-list', stream: true }
|
|
2784
|
+
});
|
|
2731
2785
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import fs from 'bare-fs';
|
|
2
2
|
import { spawnSync } from 'bare-subprocess';
|
|
3
|
-
const EXEMPT = {
|
|
3
|
+
const EXEMPT = {
|
|
4
|
+
'@qvac/seed-defaults-operation-v1.chat': 'seedableChat (lib/core/helpers/index.ts) allowlists the seed chat and leaves readThrough off it'
|
|
5
|
+
};
|
|
4
6
|
export function assertFieldOrder(root, schemaFile, tags) {
|
|
5
7
|
const current = index(JSON.parse(fs.readFileSync(schemaFile, 'utf8')).schema);
|
|
6
8
|
const seen = new Set();
|
package/dist-lib/schema/qvac.js
CHANGED
|
@@ -191,7 +191,8 @@ export function registerQvacTypes(ns) {
|
|
|
191
191
|
{ name: 'updatedAt', type: 'uint' },
|
|
192
192
|
{ name: 'groupId', type: 'string' },
|
|
193
193
|
{ name: 'rank', type: 'float64' },
|
|
194
|
-
{ name: 'rankedAt', type: 'uint' }
|
|
194
|
+
{ name: 'rankedAt', type: 'uint' },
|
|
195
|
+
{ name: 'readThrough', type: 'uint' }
|
|
195
196
|
]);
|
|
196
197
|
ns.register({
|
|
197
198
|
name: 'tool-report-entry',
|
package/dist-lib/spec/bind.js
CHANGED
|
@@ -634,4 +634,18 @@ export function bindApi(rpc, api) {
|
|
|
634
634
|
if (api.previewCustomModel) {
|
|
635
635
|
rpc.onPreviewCustomModel((req) => api.previewCustomModel(req));
|
|
636
636
|
}
|
|
637
|
+
if (api.modelUsers) {
|
|
638
|
+
rpc.onModelUsers((req) => api.modelUsers(req));
|
|
639
|
+
}
|
|
640
|
+
if (api.markChatRead) {
|
|
641
|
+
rpc.onMarkChatRead((req) => api.markChatRead(req));
|
|
642
|
+
}
|
|
643
|
+
if (api.modelsWatch) {
|
|
644
|
+
rpc.onModelsWatch((out) => {
|
|
645
|
+
const src = Readable.from(api.modelsWatch(out.data));
|
|
646
|
+
src.on("error", (err) => out.writeStream?.destroy(err));
|
|
647
|
+
pipeline(src, out, noop);
|
|
648
|
+
out.writeStream?.on("close", () => src.destroy());
|
|
649
|
+
});
|
|
650
|
+
}
|
|
637
651
|
}
|
package/dist-lib/spec/calls.js
CHANGED
|
@@ -159,5 +159,8 @@ export function engineClient(rpc) {
|
|
|
159
159
|
unloadModel: (input) => rpc.unloadModel(input),
|
|
160
160
|
setModelReleased: (input) => rpc.setModelReleased(input),
|
|
161
161
|
previewCustomModel: (input) => rpc.previewCustomModel(input),
|
|
162
|
+
modelUsers: (input) => rpc.modelUsers(input),
|
|
163
|
+
markChatRead: (input) => rpc.markChatRead(input),
|
|
164
|
+
modelsWatch: (input) => armed(rpc.modelsWatch(input)),
|
|
162
165
|
};
|
|
163
166
|
}
|
|
@@ -177,6 +177,9 @@ export interface Capabilities {
|
|
|
177
177
|
unloadModel(input: T.AssistantUnloadModelRequest): Promise<T.AssistantUnloadModelResponse>
|
|
178
178
|
setModelReleased(input: T.AssistantSetModelReleasedRequest): Promise<T.AssistantAppConfig>
|
|
179
179
|
previewCustomModel(input: T.AssistantPreviewCustomModelRequest): Promise<T.AssistantCustomModelPreview>
|
|
180
|
+
modelUsers(input: T.AssistantModelUsersRequest): Promise<T.AssistantModelUsers>
|
|
181
|
+
markChatRead(input: T.AssistantChatId): Promise<T.AssistantChat>
|
|
182
|
+
modelsWatch(input: T.AssistantListModelsRequest): WatchStream<T.AssistantModelInfoList>
|
|
180
183
|
}
|
|
181
184
|
|
|
182
185
|
export interface CapabilityHandlers {
|
|
@@ -329,4 +332,7 @@ export interface CapabilityHandlers {
|
|
|
329
332
|
unloadModel(input: T.AssistantUnloadModelRequest): T.AssistantUnloadModelResponse | Promise<T.AssistantUnloadModelResponse>
|
|
330
333
|
setModelReleased(input: T.AssistantSetModelReleasedRequest): T.AssistantAppConfig | Promise<T.AssistantAppConfig>
|
|
331
334
|
previewCustomModel(input: T.AssistantPreviewCustomModelRequest): T.AssistantCustomModelPreview | Promise<T.AssistantCustomModelPreview>
|
|
335
|
+
modelUsers(input: T.AssistantModelUsersRequest): T.AssistantModelUsers | Promise<T.AssistantModelUsers>
|
|
336
|
+
markChatRead(input: T.AssistantChatId): T.AssistantChat | Promise<T.AssistantChat>
|
|
337
|
+
modelsWatch(input: T.AssistantListModelsRequest): AsyncIterable<T.AssistantModelInfoList>
|
|
332
338
|
}
|