@qvac/core 0.7.3 → 0.7.5
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 +97 -1
- package/README.md +4 -3
- package/dist-lib/lib/api/device-routes.d.ts +11 -0
- package/dist-lib/lib/api/device-routes.js +124 -0
- package/dist-lib/lib/assistant.d.ts +4 -0
- package/dist-lib/lib/assistant.js +45 -12
- package/dist-lib/lib/core/agent.js +6 -2
- package/dist-lib/lib/core/device-control.d.ts +23 -0
- package/dist-lib/lib/core/device-control.js +92 -0
- package/dist-lib/lib/core/mesh.d.ts +14 -0
- package/dist-lib/lib/core/mesh.js +100 -4
- package/dist-lib/lib/core/peer-duplex.d.ts +2 -0
- package/dist-lib/lib/core/peer-duplex.js +11 -2
- package/dist-lib/lib/core/tool-configs.js +1 -1
- package/dist-lib/lib/core.d.ts +3 -0
- package/dist-lib/lib/core.js +41 -1
- package/dist-lib/lib/log.js +4 -1
- package/dist-lib/lib/suspend-lifecycle.js +15 -5
- package/dist-lib/schema/build.js +1 -0
- package/dist-lib/schema/engine.js +45 -15
- package/dist-lib/spec/capabilities.d.ts +6 -6
- package/dist-lib/spec/hrpc/hrpc.json +3 -3
- package/dist-lib/spec/hrpc/index.js +3 -3
- package/dist-lib/spec/hrpc/messages.js +105 -20
- package/dist-lib/spec/hyperschema/index.js +105 -20
- package/dist-lib/spec/hyperschema/schema.json +81 -8
- package/dist-lib/spec/hyperschema/types.d.ts +17 -0
- package/package.json +2 -1
- package/tui/README.md +8 -4
- package/tui/app.mjs +273 -66
- package/tui/boot.mjs +46 -3
- package/tui/index.mjs +5 -1
- package/tui/lib/device-target.mjs +64 -0
|
@@ -24,6 +24,8 @@ import { errorMessage, isRecord } from '../guards.js';
|
|
|
24
24
|
import { ACTIVE_AGENTS, ACTIVE_CHATS, DEVICES, LIVE_WRITERS_BY_MOST_RECENT, MEMBERS, MESH_NAMES } from './collections.js';
|
|
25
25
|
const [MESH_KEYPAIR, MESH_ENCRYPTION, MESH_DEVICE] = crypto.namespace('qvac-assistant/mesh', 3);
|
|
26
26
|
export const MESH_JOINING = 'This mesh is still joining: it accepts writes once it is joined';
|
|
27
|
+
const SLOW_WRITE_MS = 5000;
|
|
28
|
+
const SLOW_DRAIN_MS = 15_000;
|
|
27
29
|
export function meshPublicKeyFromSeed(seed) {
|
|
28
30
|
return crypto.keyPair(crypto.hash([MESH_KEYPAIR, seed])).publicKey;
|
|
29
31
|
}
|
|
@@ -88,6 +90,9 @@ export class Mesh extends ReadyResource {
|
|
|
88
90
|
revoked: 0
|
|
89
91
|
};
|
|
90
92
|
_deviceId;
|
|
93
|
+
_slowWriteMs;
|
|
94
|
+
_slowDrainMs;
|
|
95
|
+
_stallReported = false;
|
|
91
96
|
_admitted = false;
|
|
92
97
|
_birth = null;
|
|
93
98
|
_autobee = null;
|
|
@@ -221,6 +226,8 @@ export class Mesh extends ReadyResource {
|
|
|
221
226
|
this._key = opts.key ?? null;
|
|
222
227
|
this._writerSeed = opts.writerSeed;
|
|
223
228
|
this._log = opts.logger ?? null;
|
|
229
|
+
this._slowWriteMs = opts.slowWriteMs ?? SLOW_WRITE_MS;
|
|
230
|
+
this._slowDrainMs = opts.slowDrainMs ?? SLOW_DRAIN_MS;
|
|
224
231
|
this._blindPeerKeys = opts.blindPeerKeys ?? [];
|
|
225
232
|
this._blindPeeringOpts = opts.blindPeeringOpts;
|
|
226
233
|
this._bootFrom = opts.bootFrom;
|
|
@@ -342,7 +349,7 @@ export class Mesh extends ReadyResource {
|
|
|
342
349
|
async _sweepOrphanedBlobs(blobLength) {
|
|
343
350
|
this._orphanedBlobSweepStatus = { state: 'running' };
|
|
344
351
|
try {
|
|
345
|
-
await this.autobee.update();
|
|
352
|
+
await this._watchStall(this.autobee.update(), { what: 'mesh drain', ms: this._slowDrainMs });
|
|
346
353
|
await this.files.sweepOrphans(blobLength);
|
|
347
354
|
this._orphanedBlobSweepStatus = { state: 'succeeded' };
|
|
348
355
|
this._log?.info(this._scope, 'orphaned blob sweep finished');
|
|
@@ -385,10 +392,93 @@ export class Mesh extends ReadyResource {
|
|
|
385
392
|
async dispatch(name, payload, opts) {
|
|
386
393
|
assertComputeRoute(this._compute, name);
|
|
387
394
|
assertJoined(this.autobee, opts);
|
|
388
|
-
|
|
395
|
+
const write = this.autobee.append(encode(`@qvac/${name}`, payload), opts);
|
|
396
|
+
await this._watchStall(write, { what: 'mesh write', op: name, ms: this._slowWriteMs });
|
|
397
|
+
}
|
|
398
|
+
async _watchStall(pending, watch) {
|
|
399
|
+
const started = Date.now();
|
|
400
|
+
let reported = false;
|
|
401
|
+
const timer = setTimeout(() => {
|
|
402
|
+
if (this._stallReported) {
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
this._stallReported = true;
|
|
406
|
+
reported = true;
|
|
407
|
+
this._reportStall(watch, started).catch(noop);
|
|
408
|
+
}, watch.ms);
|
|
409
|
+
try {
|
|
410
|
+
await pending;
|
|
411
|
+
this._endStall(watch, { reported, started, failed: false });
|
|
412
|
+
}
|
|
413
|
+
catch (err) {
|
|
414
|
+
this._endStall(watch, { reported, started, failed: true, err });
|
|
415
|
+
throw err;
|
|
416
|
+
}
|
|
417
|
+
finally {
|
|
418
|
+
clearTimeout(timer);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
_endStall({ what, op }, { reported, started, failed, err }) {
|
|
422
|
+
if (!reported) {
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
425
|
+
this._stallReported = false;
|
|
426
|
+
const ms = Date.now() - started;
|
|
427
|
+
if (failed) {
|
|
428
|
+
this._log?.warn(this._scope, `${what} failed`, { op, ms, err });
|
|
429
|
+
}
|
|
430
|
+
else {
|
|
431
|
+
this._log?.info(this._scope, `${what} settled`, { op, ms });
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
async _reportStall({ what, op }, started) {
|
|
435
|
+
const { stats, system } = this.autobee;
|
|
436
|
+
const missing = await this._coresNotHeld([system.bee, this.autobee.bee]).catch(noop);
|
|
437
|
+
this._log?.warn(this._scope, `${what} still pending`, {
|
|
438
|
+
op,
|
|
439
|
+
afterMs: Date.now() - started,
|
|
440
|
+
writable: this.autobee.writable,
|
|
441
|
+
interrupted: !!this.autobee.interrupted,
|
|
442
|
+
drains: stats.drains,
|
|
443
|
+
applies: stats.applies,
|
|
444
|
+
appends: stats.appends,
|
|
445
|
+
fastForwards: stats.fastForwards,
|
|
446
|
+
localLength: this.autobee.local.length,
|
|
447
|
+
missing,
|
|
448
|
+
blindPeers: this.blindPeerStats()
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
async _coresNotHeld(views) {
|
|
452
|
+
const keys = new Map();
|
|
453
|
+
for (const { context } of views) {
|
|
454
|
+
for (const { key } of [context.core, ...context.cores]) {
|
|
455
|
+
keys.set(b4a.toHex(key), key);
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
const held = await Promise.all([...keys.values()].map((key) => this._coreHeld(key)));
|
|
459
|
+
return held.filter((core) => core.held < core.length);
|
|
460
|
+
}
|
|
461
|
+
async _coreHeld(key) {
|
|
462
|
+
const core = this._store.get({ key, active: false });
|
|
463
|
+
try {
|
|
464
|
+
await core.ready();
|
|
465
|
+
return {
|
|
466
|
+
key: b4a.toHex(key).slice(0, 8),
|
|
467
|
+
length: core.length,
|
|
468
|
+
held: core.contiguousLength,
|
|
469
|
+
peers: core.peers.length
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
finally {
|
|
473
|
+
await core.close();
|
|
474
|
+
}
|
|
389
475
|
}
|
|
390
476
|
batch() {
|
|
391
|
-
return new MeshBatch(this.autobee, {
|
|
477
|
+
return new MeshBatch(this.autobee, {
|
|
478
|
+
compute: this._compute,
|
|
479
|
+
joined: true,
|
|
480
|
+
watch: (op, write) => this._watchStall(write, { what: 'mesh write', op, ms: this._slowWriteMs })
|
|
481
|
+
});
|
|
392
482
|
}
|
|
393
483
|
appendBirthOp(identity, device, opts = {}) {
|
|
394
484
|
this._birth ??= (async () => {
|
|
@@ -663,11 +753,14 @@ export class MeshBatch {
|
|
|
663
753
|
_autobee;
|
|
664
754
|
_compute;
|
|
665
755
|
_joined;
|
|
756
|
+
_watch;
|
|
666
757
|
_ops = [];
|
|
758
|
+
_names = [];
|
|
667
759
|
constructor(autobee, opts = {}) {
|
|
668
760
|
this._autobee = autobee;
|
|
669
761
|
this._compute = opts.compute ?? false;
|
|
670
762
|
this._joined = opts.joined ?? false;
|
|
763
|
+
this._watch = opts.watch ?? ((_op, write) => write);
|
|
671
764
|
}
|
|
672
765
|
get size() {
|
|
673
766
|
return this._ops.length;
|
|
@@ -675,6 +768,7 @@ export class MeshBatch {
|
|
|
675
768
|
dispatch(name, payload) {
|
|
676
769
|
assertComputeRoute(this._compute, name);
|
|
677
770
|
this._ops.push(encode(`@qvac/${name}`, payload));
|
|
771
|
+
this._names.push(name);
|
|
678
772
|
}
|
|
679
773
|
async flush(opts) {
|
|
680
774
|
if (this._ops.length === 0)
|
|
@@ -683,8 +777,10 @@ export class MeshBatch {
|
|
|
683
777
|
assertJoined(this._autobee, opts);
|
|
684
778
|
}
|
|
685
779
|
const ops = this._ops;
|
|
780
|
+
const names = this._names;
|
|
686
781
|
this._ops = [];
|
|
687
|
-
|
|
782
|
+
this._names = [];
|
|
783
|
+
await this._watch(names.join(','), this._autobee.append(ops, opts));
|
|
688
784
|
}
|
|
689
785
|
}
|
|
690
786
|
function noop() { }
|
|
@@ -19,7 +19,9 @@ export declare class PeerDuplexChannel {
|
|
|
19
19
|
private readonly _pairing;
|
|
20
20
|
constructor(opts: PeerDuplexOptions);
|
|
21
21
|
addStream(stream: PeerStream): void;
|
|
22
|
+
openIds(): string[];
|
|
22
23
|
isOpen(deviceId: string): boolean;
|
|
24
|
+
closeDialled(deviceId: string, reason: string): void;
|
|
23
25
|
dial(deviceId: string): Duplex;
|
|
24
26
|
revalidate(allowed: (deviceId: Uint8Array) => Promise<boolean>): Promise<void>;
|
|
25
27
|
destroy(): void;
|
|
@@ -84,9 +84,17 @@ export class PeerDuplexChannel {
|
|
|
84
84
|
});
|
|
85
85
|
channel.open();
|
|
86
86
|
}
|
|
87
|
+
openIds() {
|
|
88
|
+
return [...this._peers].filter(([, peer]) => peer.opened).map(([deviceId]) => deviceId);
|
|
89
|
+
}
|
|
87
90
|
isOpen(deviceId) {
|
|
88
91
|
return this._peers.get(deviceId)?.opened === true;
|
|
89
92
|
}
|
|
93
|
+
closeDialled(deviceId, reason) {
|
|
94
|
+
for (const stream of [...(this._peers.get(deviceId)?.dialled.values() ?? [])]) {
|
|
95
|
+
stream.destroy(new Error(reason));
|
|
96
|
+
}
|
|
97
|
+
}
|
|
90
98
|
dial(deviceId) {
|
|
91
99
|
const peer = this._peers.get(deviceId);
|
|
92
100
|
if (!peer) {
|
|
@@ -157,12 +165,13 @@ export class PeerDuplexChannel {
|
|
|
157
165
|
return;
|
|
158
166
|
}
|
|
159
167
|
const stream = this._attach(peer, id, { mine: false });
|
|
168
|
+
stream.on('error', noop);
|
|
160
169
|
const served = await this._opts.onaccept(peer.remoteKey).catch(noop);
|
|
161
|
-
if (!served) {
|
|
170
|
+
if (!served || peer.served.get(id) !== stream) {
|
|
171
|
+
served?.destroy();
|
|
162
172
|
stream.destroy();
|
|
163
173
|
return;
|
|
164
174
|
}
|
|
165
|
-
stream.on('error', noop);
|
|
166
175
|
served.on('error', noop);
|
|
167
176
|
stream.pipe(served).pipe(stream);
|
|
168
177
|
}
|
|
@@ -136,7 +136,7 @@ export async function softDeleteToolConfigsForAgent(store, agentId) {
|
|
|
136
136
|
return;
|
|
137
137
|
const now = Date.now();
|
|
138
138
|
await store.dispatch('put-tool-configs', {
|
|
139
|
-
settings: { ...row, deletedAt: now, updatedAt: now }
|
|
139
|
+
settings: { ...row, deletedAt: now, updatedAt: Math.max(now, row.updatedAt + 1) }
|
|
140
140
|
});
|
|
141
141
|
}
|
|
142
142
|
}
|
package/dist-lib/lib/core.d.ts
CHANGED
|
@@ -240,6 +240,8 @@ export declare class Core extends ReadyResource {
|
|
|
240
240
|
private _inferenceCalls;
|
|
241
241
|
private _modelResidency;
|
|
242
242
|
private _modelUsers;
|
|
243
|
+
private readonly _deviceControl;
|
|
244
|
+
private _servedToSiblings;
|
|
243
245
|
private _systemInfo;
|
|
244
246
|
private _statusError;
|
|
245
247
|
private _upgradeRequired;
|
|
@@ -454,6 +456,7 @@ export declare class Core extends ReadyResource {
|
|
|
454
456
|
registerLoanableHarness(serve: (stream: LoanStreamDuplex) => void): () => void;
|
|
455
457
|
borrowHarness(deviceId: string): LoanStreamDuplex;
|
|
456
458
|
private _lendHarness;
|
|
459
|
+
private _isOwnLiveDevice;
|
|
457
460
|
private _revalidateLoans;
|
|
458
461
|
private _computeLender;
|
|
459
462
|
private _sharesComputeMesh;
|
package/dist-lib/lib/core.js
CHANGED
|
@@ -44,6 +44,8 @@ import { claimOwnMembership, legacyNameStamp, namedAt, renameFoundedMember } fro
|
|
|
44
44
|
import { runMigrations } from './core/migrations/index.js';
|
|
45
45
|
import { backfillFileIndex } from './core/migrations/file-index.js';
|
|
46
46
|
import { advertiseDeviceVersion, retractInventory } from './core/devices.js';
|
|
47
|
+
import { DeviceControl } from './core/device-control.js';
|
|
48
|
+
import { forwardToDevices, servedToSiblings } from './api/device-routes.js';
|
|
47
49
|
import { OtaConfigReader, configCoreFor, resolveConfigChannel, vendoredMinSupportedVersion } from './core/ota-config.js';
|
|
48
50
|
import { updateRequired } from './core/min-version.js';
|
|
49
51
|
import { PendingDepartures } from './core/departures.js';
|
|
@@ -205,6 +207,8 @@ export class Core extends ReadyResource {
|
|
|
205
207
|
_inferenceCalls = null;
|
|
206
208
|
_modelResidency = null;
|
|
207
209
|
_modelUsers = null;
|
|
210
|
+
_deviceControl;
|
|
211
|
+
_servedToSiblings;
|
|
208
212
|
_systemInfo;
|
|
209
213
|
_statusError;
|
|
210
214
|
_upgradeRequired;
|
|
@@ -314,6 +318,11 @@ export class Core extends ReadyResource {
|
|
|
314
318
|
this._inferenceCallsHandoff = new InferenceCallsHandoff({
|
|
315
319
|
onrequest: (request, from) => this._serveInferenceCalls(request, from)
|
|
316
320
|
});
|
|
321
|
+
this._deviceControl = new DeviceControl({
|
|
322
|
+
allowed: (deviceId) => this._isOwnLiveDevice(b4a.from(deviceId)),
|
|
323
|
+
served: () => this._servedToSiblings
|
|
324
|
+
});
|
|
325
|
+
this._servedToSiblings = null;
|
|
317
326
|
this._minting = false;
|
|
318
327
|
this._leaving = null;
|
|
319
328
|
this._kicked = false;
|
|
@@ -403,7 +412,7 @@ export class Core extends ReadyResource {
|
|
|
403
412
|
deviceId
|
|
404
413
|
})
|
|
405
414
|
: null;
|
|
406
|
-
|
|
415
|
+
const api = createApi({
|
|
407
416
|
state: this.local,
|
|
408
417
|
mesh: this._meshPool(),
|
|
409
418
|
meshStatus,
|
|
@@ -539,6 +548,14 @@ export class Core extends ReadyResource {
|
|
|
539
548
|
})
|
|
540
549
|
: null
|
|
541
550
|
});
|
|
551
|
+
this._servedToSiblings = servedToSiblings(api);
|
|
552
|
+
this._api = {
|
|
553
|
+
...api,
|
|
554
|
+
...forwardToDevices(api, {
|
|
555
|
+
deviceId: this._requireDeviceKeyPair().publicKey,
|
|
556
|
+
remote: (deviceId) => this._deviceControl.engine(deviceId)
|
|
557
|
+
})
|
|
558
|
+
};
|
|
542
559
|
this._stream = await this._transport();
|
|
543
560
|
const { bindApi, HRPC } = await this._spec();
|
|
544
561
|
const rpc = settleOnClose(new HRPC(this._stream));
|
|
@@ -942,6 +959,8 @@ export class Core extends ReadyResource {
|
|
|
942
959
|
if (this.state === QvacState.SUSPEND) {
|
|
943
960
|
await this.storage.resume();
|
|
944
961
|
}
|
|
962
|
+
this._servedToSiblings = null;
|
|
963
|
+
this._deviceControl.destroy();
|
|
945
964
|
this._catalogHooks.destroy(new Error('core is closing'));
|
|
946
965
|
this._modelCatalogWatchSource.destroy(new Error('core is closing'));
|
|
947
966
|
this._offlineBoot.destroy(new Error('core is closing'));
|
|
@@ -2489,6 +2508,7 @@ export class Core extends ReadyResource {
|
|
|
2489
2508
|
this._onMeshSeedDue(mesh);
|
|
2490
2509
|
}
|
|
2491
2510
|
mesh.on('members-dirty', () => void this._revalidateLoans());
|
|
2511
|
+
mesh.on('members-dirty', () => void this._deviceControl.revalidate());
|
|
2492
2512
|
mesh.on('members-dirty', () => {
|
|
2493
2513
|
if (!this._isAccount(mesh))
|
|
2494
2514
|
return;
|
|
@@ -2521,6 +2541,7 @@ export class Core extends ReadyResource {
|
|
|
2521
2541
|
await this.local.setAccountMesh(this._requireDeviceKeyPair().publicKey, mesh.key);
|
|
2522
2542
|
this._wireMesh(this._poolEntry(mesh));
|
|
2523
2543
|
this._accountId = this._meshIdOf(mesh);
|
|
2544
|
+
void this._deviceControl.revalidate();
|
|
2524
2545
|
void this._dialSiblings(mesh).catch(noop);
|
|
2525
2546
|
this._statusError = null;
|
|
2526
2547
|
this._upgradeRequired = null;
|
|
@@ -2693,6 +2714,7 @@ export class Core extends ReadyResource {
|
|
|
2693
2714
|
this._candidateMesh = null;
|
|
2694
2715
|
}
|
|
2695
2716
|
if (wasAccount) {
|
|
2717
|
+
void this._deviceControl.revalidate();
|
|
2696
2718
|
this._notifyStatus();
|
|
2697
2719
|
}
|
|
2698
2720
|
}
|
|
@@ -2859,6 +2881,10 @@ export class Core extends ReadyResource {
|
|
|
2859
2881
|
}
|
|
2860
2882
|
const departing = await this._openPooledMesh(meshId);
|
|
2861
2883
|
const leavingAccount = await this._isStoredAccount(departing);
|
|
2884
|
+
this._log?.info(['p2p', 'mesh'], 'leaving a mesh', {
|
|
2885
|
+
meshId: meshId.slice(0, 8),
|
|
2886
|
+
account: leavingAccount
|
|
2887
|
+
});
|
|
2862
2888
|
this._leaving = meshId;
|
|
2863
2889
|
this._notifyStatus();
|
|
2864
2890
|
try {
|
|
@@ -3269,6 +3295,9 @@ export class Core extends ReadyResource {
|
|
|
3269
3295
|
throw halted;
|
|
3270
3296
|
}
|
|
3271
3297
|
this._wireMesh(this._poolEntry(mesh));
|
|
3298
|
+
if (this._isAccount(mesh)) {
|
|
3299
|
+
void this._deviceControl.revalidate();
|
|
3300
|
+
}
|
|
3272
3301
|
if (this._isAccount(mesh) && this._statusError?.startsWith(MESH_DIED)) {
|
|
3273
3302
|
this._statusError = null;
|
|
3274
3303
|
}
|
|
@@ -3624,6 +3653,7 @@ export class Core extends ReadyResource {
|
|
|
3624
3653
|
this._wakeup.destroy();
|
|
3625
3654
|
}
|
|
3626
3655
|
this._harnessLoan.destroy();
|
|
3656
|
+
this._deviceControl.destroy();
|
|
3627
3657
|
this._secretHandoff.destroy();
|
|
3628
3658
|
this._skillOverlayHandoff.destroy();
|
|
3629
3659
|
this._inferenceCallsHandoff.destroy();
|
|
@@ -3840,6 +3870,15 @@ export class Core extends ReadyResource {
|
|
|
3840
3870
|
serve(ours);
|
|
3841
3871
|
return theirs;
|
|
3842
3872
|
}
|
|
3873
|
+
async _isOwnLiveDevice(deviceId) {
|
|
3874
|
+
const account = this._accountMesh();
|
|
3875
|
+
const ours = account?.ourMemberId;
|
|
3876
|
+
if (!account || !ours) {
|
|
3877
|
+
return false;
|
|
3878
|
+
}
|
|
3879
|
+
const device = await account.view.get(DEVICES, { id: deviceId });
|
|
3880
|
+
return !!device?.memberId && !device.revoked && b4a.equals(device.memberId, ours);
|
|
3881
|
+
}
|
|
3843
3882
|
_revalidateLoans() {
|
|
3844
3883
|
return this._harnessLoan.revalidate((device) => this._sharesComputeMesh(b4a.from(device)));
|
|
3845
3884
|
}
|
|
@@ -4068,6 +4107,7 @@ export class Core extends ReadyResource {
|
|
|
4068
4107
|
this._secretHandoff.addStream(conn);
|
|
4069
4108
|
this._skillOverlayHandoff.addStream(conn);
|
|
4070
4109
|
this._harnessLoan.addStream(conn);
|
|
4110
|
+
this._deviceControl.addStream(conn);
|
|
4071
4111
|
this._inferenceCallsHandoff.addStream(conn);
|
|
4072
4112
|
if (this._ownsSwarm) {
|
|
4073
4113
|
this._wakeup.addStream(conn);
|
package/dist-lib/lib/log.js
CHANGED
|
@@ -150,9 +150,12 @@ function formatArg(value) {
|
|
|
150
150
|
return value.stack ?? value.message;
|
|
151
151
|
}
|
|
152
152
|
try {
|
|
153
|
-
return JSON.stringify(value) ?? String(value);
|
|
153
|
+
return JSON.stringify(value, errorsAsText) ?? String(value);
|
|
154
154
|
}
|
|
155
155
|
catch {
|
|
156
156
|
return String(value);
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
|
+
function errorsAsText(_key, value) {
|
|
160
|
+
return value instanceof Error ? (value.stack ?? value.message) : value;
|
|
161
|
+
}
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import Suspendify from 'suspendify';
|
|
2
2
|
export const ASSISTANT_WAKEUP_LINGER_MS = 6_000;
|
|
3
|
+
const SUSPENDIFY_TARGET_RESUME = 0;
|
|
3
4
|
export function createAssistantSuspendLifecycle(supervisor, options = {}) {
|
|
4
5
|
const { wakeupLinger = ASSISTANT_WAKEUP_LINGER_MS, pollLinger, onSuspended = noop } = options;
|
|
6
|
+
const resume = async () => {
|
|
7
|
+
if (!supervisor.opened) {
|
|
8
|
+
await supervisor.ready();
|
|
9
|
+
}
|
|
10
|
+
await supervisor.resume();
|
|
11
|
+
};
|
|
5
12
|
const lifecycle = new Suspendify({
|
|
6
13
|
wakeupLinger,
|
|
7
14
|
pollLinger,
|
|
@@ -26,13 +33,16 @@ export function createAssistantSuspendLifecycle(supervisor, options = {}) {
|
|
|
26
33
|
}
|
|
27
34
|
await supervisor.wakeup();
|
|
28
35
|
},
|
|
29
|
-
|
|
30
|
-
if (
|
|
31
|
-
await
|
|
36
|
+
suspendCancelled: async () => {
|
|
37
|
+
if (resuming(lifecycle)) {
|
|
38
|
+
await resume();
|
|
32
39
|
}
|
|
33
|
-
|
|
34
|
-
|
|
40
|
+
},
|
|
41
|
+
resume
|
|
35
42
|
});
|
|
36
43
|
return lifecycle;
|
|
37
44
|
}
|
|
45
|
+
function resuming(lifecycle) {
|
|
46
|
+
return 'target' in lifecycle && lifecycle.target === SUSPENDIFY_TARGET_RESUME;
|
|
47
|
+
}
|
|
38
48
|
function noop() { }
|
package/dist-lib/schema/build.js
CHANGED
|
@@ -67,6 +67,7 @@ writeBind(builder, path.join(SPEC_DIR, 'bind.js'));
|
|
|
67
67
|
const callSites = {
|
|
68
68
|
optionalRequests: new Set([
|
|
69
69
|
'@assistant/empty',
|
|
70
|
+
'@assistant/device-scope',
|
|
70
71
|
'@assistant/create-room-request',
|
|
71
72
|
'@assistant/local-files-request',
|
|
72
73
|
'@assistant/create-mesh-request'
|
|
@@ -22,13 +22,20 @@ export function registerEngineTypes(ns) {
|
|
|
22
22
|
const versioned = versionedRegistrar(ns, 'assistant');
|
|
23
23
|
ns.register({ name: 'empty', fields: [] });
|
|
24
24
|
ns.register({ name: 'ok-response', fields: [{ name: 'ok', type: 'bool', required: true }] });
|
|
25
|
-
ns.register({
|
|
25
|
+
ns.register({
|
|
26
|
+
name: 'config-key',
|
|
27
|
+
fields: [
|
|
28
|
+
{ name: 'key', type: 'string', required: true },
|
|
29
|
+
{ name: 'deviceId', type: 'fixed32' }
|
|
30
|
+
]
|
|
31
|
+
});
|
|
26
32
|
ns.register({ name: 'config-value', fields: [{ name: 'value', type: 'json' }] });
|
|
27
33
|
ns.register({
|
|
28
34
|
name: 'config-set-request',
|
|
29
35
|
fields: [
|
|
30
36
|
{ name: 'key', type: 'string', required: true },
|
|
31
|
-
{ name: 'value', type: 'json', required: true }
|
|
37
|
+
{ name: 'value', type: 'json', required: true },
|
|
38
|
+
{ name: 'deviceId', type: 'fixed32' }
|
|
32
39
|
]
|
|
33
40
|
});
|
|
34
41
|
ns.register({
|
|
@@ -994,7 +1001,8 @@ export function registerEngineTypes(ns) {
|
|
|
994
1001
|
{ name: 'cachedOnly', type: 'bool' },
|
|
995
1002
|
{ name: 'fullRegistry', type: 'bool' },
|
|
996
1003
|
{ name: 'taskType', type: '@assistant/model-task-type' },
|
|
997
|
-
{ name: 'excludeCustom', type: 'bool' }
|
|
1004
|
+
{ name: 'excludeCustom', type: 'bool' },
|
|
1005
|
+
{ name: 'deviceId', type: 'fixed32' }
|
|
998
1006
|
]
|
|
999
1007
|
});
|
|
1000
1008
|
ns.register({
|
|
@@ -1023,7 +1031,10 @@ export function registerEngineTypes(ns) {
|
|
|
1023
1031
|
});
|
|
1024
1032
|
ns.register({
|
|
1025
1033
|
name: 'delete-model-request',
|
|
1026
|
-
fields: [
|
|
1034
|
+
fields: [
|
|
1035
|
+
{ name: 'name', type: 'string', required: true },
|
|
1036
|
+
{ name: 'deviceId', type: 'fixed32' }
|
|
1037
|
+
]
|
|
1027
1038
|
});
|
|
1028
1039
|
ns.register({
|
|
1029
1040
|
name: 'delete-model-response',
|
|
@@ -1126,7 +1137,8 @@ export function registerEngineTypes(ns) {
|
|
|
1126
1137
|
name: 'set-model-paused-request',
|
|
1127
1138
|
fields: [
|
|
1128
1139
|
{ name: 'name', type: 'string', required: true },
|
|
1129
|
-
{ name: 'paused', type: 'bool', required: true }
|
|
1140
|
+
{ name: 'paused', type: 'bool', required: true },
|
|
1141
|
+
{ name: 'deviceId', type: 'fixed32' }
|
|
1130
1142
|
]
|
|
1131
1143
|
});
|
|
1132
1144
|
ns.register({
|
|
@@ -1176,7 +1188,10 @@ export function registerEngineTypes(ns) {
|
|
|
1176
1188
|
});
|
|
1177
1189
|
ns.register({
|
|
1178
1190
|
name: 'clear-model-download-request',
|
|
1179
|
-
fields: [
|
|
1191
|
+
fields: [
|
|
1192
|
+
{ name: 'name', type: 'string', required: true },
|
|
1193
|
+
{ name: 'deviceId', type: 'fixed32' }
|
|
1194
|
+
]
|
|
1180
1195
|
});
|
|
1181
1196
|
ns.register({
|
|
1182
1197
|
name: 'custom-model',
|
|
@@ -1208,7 +1223,8 @@ export function registerEngineTypes(ns) {
|
|
|
1208
1223
|
{ name: 'supportsTools', type: 'bool' },
|
|
1209
1224
|
{ name: 'supportsThinking', type: 'bool' },
|
|
1210
1225
|
{ name: 'supportsVision', type: 'bool' },
|
|
1211
|
-
{ name: 'expectedSize', type: 'uint' }
|
|
1226
|
+
{ name: 'expectedSize', type: 'uint' },
|
|
1227
|
+
{ name: 'deviceId', type: 'fixed32' }
|
|
1212
1228
|
]
|
|
1213
1229
|
});
|
|
1214
1230
|
ns.register({
|
|
@@ -1217,13 +1233,17 @@ export function registerEngineTypes(ns) {
|
|
|
1217
1233
|
});
|
|
1218
1234
|
ns.register({
|
|
1219
1235
|
name: 'remove-custom-model-request',
|
|
1220
|
-
fields: [
|
|
1236
|
+
fields: [
|
|
1237
|
+
{ name: 'name', type: 'string', required: true },
|
|
1238
|
+
{ name: 'deviceId', type: 'fixed32' }
|
|
1239
|
+
]
|
|
1221
1240
|
});
|
|
1222
1241
|
ns.register({
|
|
1223
1242
|
name: 'preview-custom-model-request',
|
|
1224
1243
|
fields: [
|
|
1225
1244
|
{ name: 'src', type: 'string', required: true },
|
|
1226
|
-
{ name: 'mmprojSrc', type: 'string' }
|
|
1245
|
+
{ name: 'mmprojSrc', type: 'string' },
|
|
1246
|
+
{ name: 'deviceId', type: 'fixed32' }
|
|
1227
1247
|
]
|
|
1228
1248
|
});
|
|
1229
1249
|
ns.register({
|
|
@@ -2065,7 +2085,10 @@ export function registerEngineTypes(ns) {
|
|
|
2065
2085
|
});
|
|
2066
2086
|
ns.register({
|
|
2067
2087
|
name: 'load-model-request',
|
|
2068
|
-
fields: [
|
|
2088
|
+
fields: [
|
|
2089
|
+
{ name: 'name', type: 'string', required: true },
|
|
2090
|
+
{ name: 'deviceId', type: 'fixed32' }
|
|
2091
|
+
]
|
|
2069
2092
|
});
|
|
2070
2093
|
ns.register({
|
|
2071
2094
|
name: 'load-model-response',
|
|
@@ -2076,7 +2099,10 @@ export function registerEngineTypes(ns) {
|
|
|
2076
2099
|
});
|
|
2077
2100
|
ns.register({
|
|
2078
2101
|
name: 'unload-model-request',
|
|
2079
|
-
fields: [
|
|
2102
|
+
fields: [
|
|
2103
|
+
{ name: 'name', type: 'string', required: true },
|
|
2104
|
+
{ name: 'deviceId', type: 'fixed32' }
|
|
2105
|
+
]
|
|
2080
2106
|
});
|
|
2081
2107
|
ns.register({
|
|
2082
2108
|
name: 'unload-model-response',
|
|
@@ -2089,7 +2115,10 @@ export function registerEngineTypes(ns) {
|
|
|
2089
2115
|
});
|
|
2090
2116
|
ns.register({
|
|
2091
2117
|
name: 'model-users-request',
|
|
2092
|
-
fields: [
|
|
2118
|
+
fields: [
|
|
2119
|
+
{ name: 'name', type: 'string', required: true },
|
|
2120
|
+
{ name: 'deviceId', type: 'fixed32' }
|
|
2121
|
+
]
|
|
2093
2122
|
});
|
|
2094
2123
|
ns.register({
|
|
2095
2124
|
name: 'model-user',
|
|
@@ -2123,6 +2152,7 @@ export function registerEngineTypes(ns) {
|
|
|
2123
2152
|
{ name: 'overCap', type: 'bool', required: true }
|
|
2124
2153
|
]
|
|
2125
2154
|
});
|
|
2155
|
+
ns.register({ name: 'device-scope', fields: [{ name: 'deviceId', type: 'fixed32' }] });
|
|
2126
2156
|
}
|
|
2127
2157
|
export function registerEngineApi(api) {
|
|
2128
2158
|
api.register({
|
|
@@ -2262,7 +2292,7 @@ export function registerEngineApi(api) {
|
|
|
2262
2292
|
});
|
|
2263
2293
|
api.register({
|
|
2264
2294
|
name: 'model-downloads-watch',
|
|
2265
|
-
request: { name: '@assistant/
|
|
2295
|
+
request: { name: '@assistant/device-scope', stream: false },
|
|
2266
2296
|
response: { name: '@assistant/model-download-list', stream: true }
|
|
2267
2297
|
});
|
|
2268
2298
|
api.register({
|
|
@@ -2277,7 +2307,7 @@ export function registerEngineApi(api) {
|
|
|
2277
2307
|
});
|
|
2278
2308
|
api.register({
|
|
2279
2309
|
name: 'custom-models-watch',
|
|
2280
|
-
request: { name: '@assistant/
|
|
2310
|
+
request: { name: '@assistant/device-scope', stream: false },
|
|
2281
2311
|
response: { name: '@assistant/custom-model-list', stream: true }
|
|
2282
2312
|
});
|
|
2283
2313
|
api.register({
|
|
@@ -2472,7 +2502,7 @@ export function registerEngineApi(api) {
|
|
|
2472
2502
|
});
|
|
2473
2503
|
api.register({
|
|
2474
2504
|
name: 'model-catalog-watch',
|
|
2475
|
-
request: { name: '@assistant/
|
|
2505
|
+
request: { name: '@assistant/device-scope', stream: false },
|
|
2476
2506
|
response: { name: '@assistant/model-catalog-revision', stream: true }
|
|
2477
2507
|
});
|
|
2478
2508
|
api.register({
|
|
@@ -55,10 +55,10 @@ export interface Capabilities {
|
|
|
55
55
|
listDevices(input: T.AssistantMeshScope): Promise<T.AssistantDeviceList>
|
|
56
56
|
devicesWatch(input: T.AssistantMeshScope): WatchStream<T.AssistantDeviceList>
|
|
57
57
|
saveDeviceCapabilities(input: T.AssistantSaveDeviceCapabilitiesRequest): Promise<T.AssistantOkResponse>
|
|
58
|
-
modelDownloadsWatch(input?: T.
|
|
58
|
+
modelDownloadsWatch(input?: T.AssistantDeviceScope): WatchStream<T.AssistantModelDownloadList>
|
|
59
59
|
setModelDownloadStatus(input: T.AssistantSetModelDownloadStatusRequest): Promise<T.AssistantOkResponse>
|
|
60
60
|
clearModelDownload(input: T.AssistantClearModelDownloadRequest): Promise<T.AssistantOkResponse>
|
|
61
|
-
customModelsWatch(input?: T.
|
|
61
|
+
customModelsWatch(input?: T.AssistantDeviceScope): WatchStream<T.AssistantCustomModelList>
|
|
62
62
|
addCustomModel(input: T.AssistantAddCustomModelRequest): Promise<T.AssistantAddCustomModelResponse>
|
|
63
63
|
removeCustomModel(input: T.AssistantRemoveCustomModelRequest): Promise<T.AssistantDeleteModelResponse>
|
|
64
64
|
removeDevice(input: T.AssistantDeviceId): Promise<T.AssistantOkResponse>
|
|
@@ -97,7 +97,7 @@ export interface Capabilities {
|
|
|
97
97
|
runRequestsWatch(input: T.AssistantMeshScope): WatchStream<T.AssistantChunkList>
|
|
98
98
|
listModels(input: T.AssistantListModelsRequest): Promise<T.AssistantModelInfoList>
|
|
99
99
|
deleteModel(input: T.AssistantDeleteModelRequest): Promise<T.AssistantDeleteModelResponse>
|
|
100
|
-
modelCatalogWatch(input?: T.
|
|
100
|
+
modelCatalogWatch(input?: T.AssistantDeviceScope): WatchStream<T.AssistantModelCatalogRevision>
|
|
101
101
|
skills(input: T.AssistantSkillRequest): Promise<T.AssistantSkillResponse>
|
|
102
102
|
downloadKnowledge(input: T.AssistantDownloadKnowledgeRequest): WatchStream<T.AssistantDownloadKnowledgeResponse>
|
|
103
103
|
getConfig(input?: T.AssistantEmpty): Promise<T.AssistantAppConfig>
|
|
@@ -219,10 +219,10 @@ export interface CapabilityHandlers {
|
|
|
219
219
|
listDevices(input: T.AssistantMeshScope): T.AssistantDeviceList | Promise<T.AssistantDeviceList>
|
|
220
220
|
devicesWatch(input: T.AssistantMeshScope): AsyncIterable<T.AssistantDeviceList>
|
|
221
221
|
saveDeviceCapabilities(input: T.AssistantSaveDeviceCapabilitiesRequest): T.AssistantOkResponse | Promise<T.AssistantOkResponse>
|
|
222
|
-
modelDownloadsWatch(input?: T.
|
|
222
|
+
modelDownloadsWatch(input?: T.AssistantDeviceScope): AsyncIterable<T.AssistantModelDownloadList>
|
|
223
223
|
setModelDownloadStatus(input: T.AssistantSetModelDownloadStatusRequest): T.AssistantOkResponse | Promise<T.AssistantOkResponse>
|
|
224
224
|
clearModelDownload(input: T.AssistantClearModelDownloadRequest): T.AssistantOkResponse | Promise<T.AssistantOkResponse>
|
|
225
|
-
customModelsWatch(input?: T.
|
|
225
|
+
customModelsWatch(input?: T.AssistantDeviceScope): AsyncIterable<T.AssistantCustomModelList>
|
|
226
226
|
addCustomModel(input: T.AssistantAddCustomModelRequest): T.AssistantAddCustomModelResponse | Promise<T.AssistantAddCustomModelResponse>
|
|
227
227
|
removeCustomModel(input: T.AssistantRemoveCustomModelRequest): T.AssistantDeleteModelResponse | Promise<T.AssistantDeleteModelResponse>
|
|
228
228
|
removeDevice(input: T.AssistantDeviceId): T.AssistantOkResponse | Promise<T.AssistantOkResponse>
|
|
@@ -261,7 +261,7 @@ export interface CapabilityHandlers {
|
|
|
261
261
|
runRequestsWatch(input: T.AssistantMeshScope): AsyncIterable<T.AssistantChunkList>
|
|
262
262
|
listModels(input: T.AssistantListModelsRequest): T.AssistantModelInfoList | Promise<T.AssistantModelInfoList>
|
|
263
263
|
deleteModel(input: T.AssistantDeleteModelRequest): T.AssistantDeleteModelResponse | Promise<T.AssistantDeleteModelResponse>
|
|
264
|
-
modelCatalogWatch(input?: T.
|
|
264
|
+
modelCatalogWatch(input?: T.AssistantDeviceScope): AsyncIterable<T.AssistantModelCatalogRevision>
|
|
265
265
|
skills(input: T.AssistantSkillRequest): T.AssistantSkillResponse | Promise<T.AssistantSkillResponse>
|
|
266
266
|
downloadKnowledge(input: T.AssistantDownloadKnowledgeRequest): AsyncIterable<T.AssistantDownloadKnowledgeResponse>
|
|
267
267
|
getConfig(input?: T.AssistantEmpty): T.AssistantAppConfig | Promise<T.AssistantAppConfig>
|
|
@@ -356,7 +356,7 @@
|
|
|
356
356
|
"id": 27,
|
|
357
357
|
"name": "@assistant/model-downloads-watch",
|
|
358
358
|
"request": {
|
|
359
|
-
"name": "@assistant/
|
|
359
|
+
"name": "@assistant/device-scope",
|
|
360
360
|
"stream": false
|
|
361
361
|
},
|
|
362
362
|
"response": {
|
|
@@ -395,7 +395,7 @@
|
|
|
395
395
|
"id": 30,
|
|
396
396
|
"name": "@assistant/custom-models-watch",
|
|
397
397
|
"request": {
|
|
398
|
-
"name": "@assistant/
|
|
398
|
+
"name": "@assistant/device-scope",
|
|
399
399
|
"stream": false
|
|
400
400
|
},
|
|
401
401
|
"response": {
|
|
@@ -902,7 +902,7 @@
|
|
|
902
902
|
"id": 69,
|
|
903
903
|
"name": "@assistant/model-catalog-watch",
|
|
904
904
|
"request": {
|
|
905
|
-
"name": "@assistant/
|
|
905
|
+
"name": "@assistant/device-scope",
|
|
906
906
|
"stream": false
|
|
907
907
|
},
|
|
908
908
|
"response": {
|