@qvac/core 0.6.6 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +185 -1
- package/README.md +2 -0
- package/dist-lib/lib/api/app-config.d.ts +3 -1
- package/dist-lib/lib/api/app-config.js +15 -4
- package/dist-lib/lib/assistant/fake-models.d.ts +22 -0
- package/dist-lib/lib/assistant/fake-models.js +112 -0
- package/dist-lib/lib/assistant/harness.d.ts +10 -0
- package/dist-lib/lib/assistant/harness.js +26 -0
- package/dist-lib/lib/assistant/history.d.ts +5 -1
- package/dist-lib/lib/assistant/history.js +14 -2
- package/dist-lib/lib/assistant-tree.d.ts +4 -0
- package/dist-lib/lib/assistant-tree.js +45 -7
- package/dist-lib/lib/assistant.d.ts +16 -2
- package/dist-lib/lib/assistant.js +184 -44
- package/dist-lib/lib/constants.d.ts +6 -0
- package/dist-lib/lib/constants.js +6 -0
- package/dist-lib/lib/core/chat-activity.d.ts +1 -1
- package/dist-lib/lib/core/chat-activity.js +3 -0
- package/dist-lib/lib/core/collections.d.ts +1 -0
- package/dist-lib/lib/core/collections.js +1 -0
- package/dist-lib/lib/core/contract/compute.d.ts +1 -1
- package/dist-lib/lib/core/contract/compute.js +2 -1
- package/dist-lib/lib/core/contract/index.js +6 -1
- package/dist-lib/lib/core/contract/invites.d.ts +1 -11
- package/dist-lib/lib/core/contract/invites.js +3 -3
- package/dist-lib/lib/core/contract/mesh-seeds.d.ts +2 -0
- package/dist-lib/lib/core/contract/mesh-seeds.js +26 -0
- package/dist-lib/lib/core/contract/open-join.d.ts +2 -0
- package/dist-lib/lib/core/contract/open-join.js +57 -0
- package/dist-lib/lib/core/departures.d.ts +3 -0
- package/dist-lib/lib/core/departures.js +44 -1
- package/dist-lib/lib/core/fs-drives.js +9 -6
- package/dist-lib/lib/core/handoff-channel.d.ts +1 -0
- package/dist-lib/lib/core/handoff-channel.js +7 -2
- package/dist-lib/lib/core/harness-loan.d.ts +1 -0
- package/dist-lib/lib/core/harness-loan.js +7 -2
- package/dist-lib/lib/core/identity.d.ts +1 -1
- package/dist-lib/lib/core/identity.js +6 -4
- package/dist-lib/lib/core/invite.d.ts +2 -0
- package/dist-lib/lib/core/invite.js +6 -2
- package/dist-lib/lib/core/membership.d.ts +1 -12
- package/dist-lib/lib/core/membership.js +1 -94
- package/dist-lib/lib/core/mesh.d.ts +8 -13
- package/dist-lib/lib/core/mesh.js +41 -87
- package/dist-lib/lib/core/protocol-pairing.d.ts +11 -0
- package/dist-lib/lib/core/protocol-pairing.js +22 -0
- package/dist-lib/lib/core/sync/index.js +2 -16
- package/dist-lib/lib/core.d.ts +43 -49
- package/dist-lib/lib/core.js +451 -909
- package/dist-lib/lib/diagnostics.d.ts +7 -0
- package/dist-lib/lib/diagnostics.js +22 -0
- package/dist-lib/lib/doctor/checks.d.ts +15 -0
- package/dist-lib/lib/doctor/checks.js +269 -0
- package/dist-lib/lib/doctor/redact.d.ts +4 -0
- package/dist-lib/lib/doctor/redact.js +31 -0
- package/dist-lib/lib/doctor/render.d.ts +8 -0
- package/dist-lib/lib/doctor/render.js +83 -0
- package/dist-lib/lib/doctor/tree.d.ts +5 -0
- package/dist-lib/lib/doctor/tree.js +167 -0
- package/dist-lib/lib/downloads-allowed-pusher.d.ts +10 -0
- package/dist-lib/lib/downloads-allowed-pusher.js +37 -0
- package/dist-lib/lib/guards.d.ts +1 -0
- package/dist-lib/lib/guards.js +4 -0
- package/dist-lib/lib/inference-calls.js +1 -5
- package/dist-lib/lib/kv-cache-reclaim.d.ts +2 -1
- package/dist-lib/lib/kv-cache-reclaim.js +24 -0
- package/dist-lib/lib/mesh-scoped-engine.js +1 -0
- package/dist-lib/lib/model-download-status.d.ts +1 -1
- package/dist-lib/lib/model-download.d.ts +9 -1
- package/dist-lib/lib/model-download.js +48 -3
- package/dist-lib/lib/model-memory-cap.d.ts +29 -0
- package/dist-lib/lib/model-memory-cap.js +69 -0
- package/dist-lib/lib/models-watch.d.ts +1 -1
- package/dist-lib/lib/models-watch.js +4 -4
- package/dist-lib/lib/oauth/flow.js +1 -1
- package/dist-lib/lib/oauth/loopback.js +16 -2
- package/dist-lib/lib/oauth/redirect-types.d.ts +1 -0
- package/dist-lib/lib/run-replay.d.ts +26 -0
- package/dist-lib/lib/run-replay.js +107 -0
- package/dist-lib/schema/config.d.ts +1 -1
- package/dist-lib/schema/config.js +1 -1
- package/dist-lib/schema/content.js +9 -1
- package/dist-lib/schema/engine.js +30 -5
- package/dist-lib/schema/local.js +3 -2
- package/dist-lib/schema/qvac.js +18 -1
- package/dist-lib/spec/bind.js +3 -0
- package/dist-lib/spec/calls.js +1 -0
- package/dist-lib/spec/capabilities.d.ts +2 -0
- package/dist-lib/spec/config/hyperconf/index.js +1 -1
- package/dist-lib/spec/hrpc/hrpc.json +13 -0
- package/dist-lib/spec/hrpc/index.js +15 -3
- package/dist-lib/spec/hrpc/messages.js +646 -557
- package/dist-lib/spec/hyperschema/index.js +646 -557
- package/dist-lib/spec/hyperschema/schema.json +80 -0
- package/dist-lib/spec/hyperschema/types.d.ts +20 -3
- package/dist-lib/spec/local/hyperdb/messages.js +22 -10
- package/dist-lib/spec/local/hyperschema/index.js +16 -7
- package/dist-lib/spec/local/hyperschema/schema.json +10 -1
- package/dist-lib/spec/local/hyperschema/types.d.ts +3 -2
- package/dist-lib/spec/mesh/hyperdb/db.json +16 -1
- package/dist-lib/spec/mesh/hyperdb/index.js +71 -2
- package/dist-lib/spec/mesh/hyperdb/messages.js +477 -240
- package/dist-lib/spec/mesh/hyperdispatch/dispatch.json +13 -1
- package/dist-lib/spec/mesh/hyperdispatch/index.js +35 -1
- package/dist-lib/spec/mesh/hyperdispatch/messages.js +180 -7
- package/dist-lib/spec/mesh/hyperschema/index.js +180 -7
- package/dist-lib/spec/mesh/hyperschema/schema.json +98 -1
- package/dist-lib/spec/mesh/hyperschema/types.d.ts +26 -2
- package/package.json +9 -17
- package/tui/README.md +7 -1
- package/tui/app.mjs +245 -11
- package/tui/boot.mjs +1 -0
- package/tui/index.mjs +1 -0
- package/tui/lib/render.mjs +25 -1
- package/worker/assistant-sidecar.mjs +5 -2
- package/dist-lib/lib/core/device-invites.d.ts +0 -11
- package/dist-lib/lib/core/device-invites.js +0 -63
- package/dist-lib/lib/core/grant-expiry.d.ts +0 -11
- package/dist-lib/lib/core/grant-expiry.js +0 -66
- package/dist-lib/lib/core/mesh-seed-handoff.d.ts +0 -27
- package/dist-lib/lib/core/mesh-seed-handoff.js +0 -53
- package/dist-lib/lib/oauth/loopback.stub.d.ts +0 -3
- package/dist-lib/lib/oauth/loopback.stub.js +0 -6
|
@@ -13,9 +13,6 @@ import { syncChanges } from './sync/index.js';
|
|
|
13
13
|
import { buildDefaultSeed, isOwnKickedRow, isOwnRevokedRow } from './helpers/index.js';
|
|
14
14
|
import { raceResource } from '../race-resource.js';
|
|
15
15
|
import { signDeviceAttestation, signWriterClaim } from './device-attestation.js';
|
|
16
|
-
import { attestMemberClaim, claimAttestation, deviceInviteToken } from './identity.js';
|
|
17
|
-
import { GrantExpiry } from './grant-expiry.js';
|
|
18
|
-
import { grantKeyPair, signInviteClaim } from './invite-grants.js';
|
|
19
16
|
import { liveDeviceForWriter } from './contract/activity.js';
|
|
20
17
|
import { assertComputeRoute } from './contract/compute.js';
|
|
21
18
|
import { MESH_NAME_ROW } from './contract/mesh-name.js';
|
|
@@ -24,12 +21,12 @@ import { createSyncActivity } from './sync-status.js';
|
|
|
24
21
|
import { buildHealthAssistant } from './health-assistant.js';
|
|
25
22
|
import b4a from 'b4a';
|
|
26
23
|
import { errorMessage, isRecord } from '../guards.js';
|
|
27
|
-
import { ACTIVE_AGENTS, ACTIVE_CHATS, DEVICES, LIVE_WRITERS_BY_MOST_RECENT, MEMBERS,
|
|
24
|
+
import { ACTIVE_AGENTS, ACTIVE_CHATS, DEVICES, LIVE_WRITERS_BY_MOST_RECENT, MEMBERS, MESH_NAMES } from './collections.js';
|
|
28
25
|
const [MESH_KEYPAIR, MESH_ENCRYPTION, MESH_DEVICE] = crypto.namespace('qvac-assistant/mesh', 3);
|
|
26
|
+
export const MESH_JOINING = 'This mesh is still joining: it accepts writes once it is joined';
|
|
29
27
|
export function meshPublicKeyFromSeed(seed) {
|
|
30
28
|
return crypto.keyPair(crypto.hash([MESH_KEYPAIR, seed])).publicKey;
|
|
31
29
|
}
|
|
32
|
-
const GENESIS_POLL_MS = 250;
|
|
33
30
|
const WARMUP_COLLECTIONS = [
|
|
34
31
|
'@qvac/devices',
|
|
35
32
|
'@qvac/active-agents',
|
|
@@ -91,8 +88,8 @@ export class Mesh extends ReadyResource {
|
|
|
91
88
|
revoked: 0
|
|
92
89
|
};
|
|
93
90
|
_deviceId;
|
|
94
|
-
_grantExpiry;
|
|
95
91
|
_admitted = false;
|
|
92
|
+
_birth = null;
|
|
96
93
|
_autobee = null;
|
|
97
94
|
_blobs = null;
|
|
98
95
|
_syncActivity = null;
|
|
@@ -210,28 +207,6 @@ export class Mesh extends ReadyResource {
|
|
|
210
207
|
namedAt: Math.max(Date.now(), (current?.namedAt ?? 0) + 1)
|
|
211
208
|
});
|
|
212
209
|
}
|
|
213
|
-
refreshGrantExpiry() {
|
|
214
|
-
return this._grantExpiry.refresh();
|
|
215
|
-
}
|
|
216
|
-
async bornKind() {
|
|
217
|
-
for await (const _device of this.view.find(DEVICES)) {
|
|
218
|
-
return (await this.view.get(MESH_KINDS, { id: 'mesh' }))?.kind ?? null;
|
|
219
|
-
}
|
|
220
|
-
return undefined;
|
|
221
|
-
}
|
|
222
|
-
async waitForGenesis(timeout) {
|
|
223
|
-
const deadline = Date.now() + timeout;
|
|
224
|
-
let kind = await this.bornKind();
|
|
225
|
-
while (kind === undefined && Date.now() < deadline) {
|
|
226
|
-
await new Promise((resolve) => setTimeout(resolve, GENESIS_POLL_MS));
|
|
227
|
-
if (this.closing) {
|
|
228
|
-
return undefined;
|
|
229
|
-
}
|
|
230
|
-
await this.autobee.update();
|
|
231
|
-
kind = await this.bornKind();
|
|
232
|
-
}
|
|
233
|
-
return kind;
|
|
234
|
-
}
|
|
235
210
|
sign(message) {
|
|
236
211
|
return crypto.sign(message, this._keyPair.secretKey);
|
|
237
212
|
}
|
|
@@ -260,7 +235,6 @@ export class Mesh extends ReadyResource {
|
|
|
260
235
|
this.discoveryKey = crypto.discoveryKey(this._keyPair.publicKey);
|
|
261
236
|
this._scope = ['p2p', 'mesh', b4a.toHex(this._keyPair.publicKey).slice(0, 8)];
|
|
262
237
|
registerRoutes(this.router, { compute: this._compute });
|
|
263
|
-
this._grantExpiry = new GrantExpiry(this, (err) => this._log?.warn(this._scope, 'revoking expired invite grants failed', err));
|
|
264
238
|
}
|
|
265
239
|
async _open() {
|
|
266
240
|
this._log?.info(this._scope, 'opening');
|
|
@@ -296,7 +270,6 @@ export class Mesh extends ReadyResource {
|
|
|
296
270
|
fastForwards: this.autobee.stats.fastForwards
|
|
297
271
|
}));
|
|
298
272
|
this.autobee.on('interrupt', (err) => this._log?.warn(this._scope, 'autobee interrupt', err));
|
|
299
|
-
this.autobee.on('writable', () => void this._grantExpiry.refresh());
|
|
300
273
|
if (this._bootInterrupted) {
|
|
301
274
|
void this.autobee.close().catch(noop);
|
|
302
275
|
}
|
|
@@ -312,7 +285,6 @@ export class Mesh extends ReadyResource {
|
|
|
312
285
|
});
|
|
313
286
|
this._syncActivity = createSyncActivity(this);
|
|
314
287
|
void this.refreshOurMember().catch((err) => this._log?.warn(this._scope, 'reading our member failed', err));
|
|
315
|
-
void this._grantExpiry.refresh();
|
|
316
288
|
this._log?.info(this._scope, 'autobee opened', {
|
|
317
289
|
writable: this.autobee.writable,
|
|
318
290
|
creator: this._key === null
|
|
@@ -353,7 +325,6 @@ export class Mesh extends ReadyResource {
|
|
|
353
325
|
}
|
|
354
326
|
async _close() {
|
|
355
327
|
this._log?.info(this._scope, 'closing');
|
|
356
|
-
this._grantExpiry.close();
|
|
357
328
|
await this._files?.close();
|
|
358
329
|
await Promise.all([this.autobee.close(), this.blobs.close(), this._blindPeering?.close()]);
|
|
359
330
|
this._blindPeering = null;
|
|
@@ -398,14 +369,30 @@ export class Mesh extends ReadyResource {
|
|
|
398
369
|
get localLength() {
|
|
399
370
|
return this.autobee.local.length;
|
|
400
371
|
}
|
|
372
|
+
get joining() {
|
|
373
|
+
return this._birth !== null;
|
|
374
|
+
}
|
|
401
375
|
async dispatch(name, payload, opts) {
|
|
402
376
|
assertComputeRoute(this._compute, name);
|
|
377
|
+
assertJoined(this.autobee, opts);
|
|
403
378
|
await this.autobee.append(encode(`@qvac/${name}`, payload), opts);
|
|
404
379
|
}
|
|
405
380
|
batch() {
|
|
406
|
-
return new MeshBatch(this.autobee, { compute: this._compute });
|
|
381
|
+
return new MeshBatch(this.autobee, { compute: this._compute, joined: true });
|
|
382
|
+
}
|
|
383
|
+
appendBirthOp(identity, device, opts = {}) {
|
|
384
|
+
this._birth ??= (async () => {
|
|
385
|
+
await this._appendBirthOp(identity, device, typeof opts === 'function' ? await opts() : opts);
|
|
386
|
+
})().finally(() => {
|
|
387
|
+
this._birth = null;
|
|
388
|
+
});
|
|
389
|
+
return this._birth.then(() => this._settleBirth());
|
|
390
|
+
}
|
|
391
|
+
async _settleBirth() {
|
|
392
|
+
await this.autobee.update();
|
|
393
|
+
this.throwIfInterrupted();
|
|
407
394
|
}
|
|
408
|
-
async
|
|
395
|
+
async _appendBirthOp(identity, device, { member, sharing = false } = {}) {
|
|
409
396
|
if (this.autobee.local.length > 0)
|
|
410
397
|
return;
|
|
411
398
|
const { publicKey: deviceId, secretKey } = 'secretKey' in identity ? identity : { publicKey: identity, secretKey: null };
|
|
@@ -415,7 +402,7 @@ export class Mesh extends ReadyResource {
|
|
|
415
402
|
: undefined;
|
|
416
403
|
const deviceSignature = secretKey && row ? this.signDeviceClaim(secretKey, deviceId, row.joinedAt) : undefined;
|
|
417
404
|
if (this._key === null) {
|
|
418
|
-
const birth = this.
|
|
405
|
+
const birth = new MeshBatch(this.autobee, { compute: this._compute });
|
|
419
406
|
birth.dispatch('add-writer', { writerKey: localKey, device: row, deviceSignature });
|
|
420
407
|
if (sharing) {
|
|
421
408
|
birth.dispatch('mint-mesh-kind', { id: 'mesh', kind: 'shared' });
|
|
@@ -432,63 +419,21 @@ export class Mesh extends ReadyResource {
|
|
|
432
419
|
}
|
|
433
420
|
await birth.flush();
|
|
434
421
|
}
|
|
435
|
-
else if (!this.autobee.writable
|
|
436
|
-
const
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
deviceSignature,
|
|
446
|
-
grantKey: pair.publicKey,
|
|
447
|
-
inviteSignature: signInviteClaim(pair.secretKey, {
|
|
448
|
-
meshPublicKey: this.publicKey,
|
|
449
|
-
grantKey: pair.publicKey,
|
|
450
|
-
deviceId,
|
|
451
|
-
writerKey: localKey
|
|
452
|
-
}),
|
|
453
|
-
member: member?.member,
|
|
454
|
-
memberClaim: member?.proof
|
|
455
|
-
});
|
|
456
|
-
}
|
|
457
|
-
else if (recovery) {
|
|
458
|
-
if (!device || !secretKey) {
|
|
459
|
-
throw new Error('A recovery needs this device row and its key');
|
|
460
|
-
}
|
|
461
|
-
join.dispatch('recover-device', {
|
|
462
|
-
signature,
|
|
463
|
-
deviceId,
|
|
464
|
-
device,
|
|
465
|
-
deviceSignature,
|
|
466
|
-
memberId: recovery.memberId,
|
|
467
|
-
proof: await attestMemberClaim(claimAttestation(this.publicKey, deviceId, localKey), { publicKey: deviceId, secretKey }, recovery.proof)
|
|
468
|
-
});
|
|
469
|
-
}
|
|
470
|
-
else {
|
|
471
|
-
join.dispatch('join', {
|
|
472
|
-
signature,
|
|
473
|
-
deviceId,
|
|
474
|
-
device,
|
|
475
|
-
claimedMemberId: claim?.memberId,
|
|
476
|
-
inviteToken: claim?.inviteNonce
|
|
477
|
-
? deviceInviteToken(claim.inviteNonce, deviceId)
|
|
478
|
-
: undefined,
|
|
479
|
-
deviceSignature
|
|
480
|
-
});
|
|
481
|
-
}
|
|
422
|
+
else if (!this.autobee.writable) {
|
|
423
|
+
const join = new MeshBatch(this.autobee, { compute: this._compute });
|
|
424
|
+
join.dispatch('open-join', {
|
|
425
|
+
signature: this.sign(localKey),
|
|
426
|
+
deviceId,
|
|
427
|
+
device: row ? claimableDevice(row) : undefined,
|
|
428
|
+
deviceSignature,
|
|
429
|
+
member: member?.member,
|
|
430
|
+
memberClaim: member?.proof
|
|
431
|
+
});
|
|
482
432
|
if (row) {
|
|
483
433
|
join.dispatch('attest-device', this.attestDevice(deviceId));
|
|
484
434
|
}
|
|
485
|
-
if (row && member && !grantSecret) {
|
|
486
|
-
join.dispatch('join-member', member);
|
|
487
|
-
}
|
|
488
435
|
await join.flush({ optimistic: true });
|
|
489
436
|
}
|
|
490
|
-
await this.autobee.update();
|
|
491
|
-
this.throwIfInterrupted();
|
|
492
437
|
}
|
|
493
438
|
get interrupted() {
|
|
494
439
|
return this.autobee.interrupted;
|
|
@@ -707,10 +652,12 @@ export class Mesh extends ReadyResource {
|
|
|
707
652
|
export class MeshBatch {
|
|
708
653
|
_autobee;
|
|
709
654
|
_compute;
|
|
655
|
+
_joined;
|
|
710
656
|
_ops = [];
|
|
711
657
|
constructor(autobee, opts = {}) {
|
|
712
658
|
this._autobee = autobee;
|
|
713
659
|
this._compute = opts.compute ?? false;
|
|
660
|
+
this._joined = opts.joined ?? false;
|
|
714
661
|
}
|
|
715
662
|
get size() {
|
|
716
663
|
return this._ops.length;
|
|
@@ -722,12 +669,19 @@ export class MeshBatch {
|
|
|
722
669
|
async flush(opts) {
|
|
723
670
|
if (this._ops.length === 0)
|
|
724
671
|
return;
|
|
672
|
+
if (this._joined) {
|
|
673
|
+
assertJoined(this._autobee, opts);
|
|
674
|
+
}
|
|
725
675
|
const ops = this._ops;
|
|
726
676
|
this._ops = [];
|
|
727
677
|
await this._autobee.append(ops, opts);
|
|
728
678
|
}
|
|
729
679
|
}
|
|
730
680
|
function noop() { }
|
|
681
|
+
function assertJoined(autobee, opts) {
|
|
682
|
+
if (!opts?.optimistic && !autobee.writable)
|
|
683
|
+
throw new Error(MESH_JOINING);
|
|
684
|
+
}
|
|
731
685
|
function openedPart(part, name) {
|
|
732
686
|
if (part === null)
|
|
733
687
|
throw new Error(`mesh ${name} read before open`);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import Protomux from 'protomux';
|
|
2
|
+
export interface PairedStream {
|
|
3
|
+
readonly noiseStream: {
|
|
4
|
+
userData: unknown;
|
|
5
|
+
};
|
|
6
|
+
}
|
|
7
|
+
export interface ProtocolPairing {
|
|
8
|
+
mux(stream: PairedStream, onopen: () => void): Protomux;
|
|
9
|
+
destroy(): void;
|
|
10
|
+
}
|
|
11
|
+
export declare function createProtocolPairing(protocol: string): ProtocolPairing;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import Protomux from 'protomux';
|
|
2
|
+
export function createProtocolPairing(protocol) {
|
|
3
|
+
const muxes = new Map();
|
|
4
|
+
function mux(stream, onopen) {
|
|
5
|
+
const paired = Protomux.from(stream.noiseStream);
|
|
6
|
+
if (!muxes.has(paired)) {
|
|
7
|
+
const onclose = () => muxes.delete(paired);
|
|
8
|
+
muxes.set(paired, onclose);
|
|
9
|
+
paired.pair({ protocol }, onopen);
|
|
10
|
+
paired.stream.once('close', onclose);
|
|
11
|
+
}
|
|
12
|
+
return paired;
|
|
13
|
+
}
|
|
14
|
+
function destroy() {
|
|
15
|
+
for (const [paired, onclose] of muxes) {
|
|
16
|
+
paired.unpair({ protocol });
|
|
17
|
+
paired.stream.off('close', onclose);
|
|
18
|
+
}
|
|
19
|
+
muxes.clear();
|
|
20
|
+
}
|
|
21
|
+
return { mux, destroy };
|
|
22
|
+
}
|
|
@@ -2,7 +2,7 @@ import { FileChanges } from './files.js';
|
|
|
2
2
|
import { syncDeviceRevocation, syncOwnMember } from './devices.js';
|
|
3
3
|
import { syncChatTombstone } from './chats.js';
|
|
4
4
|
import { syncNotificationChunk } from './chunks.js';
|
|
5
|
-
import { AGENTS, CHATS, CHUNKS, CHUNK_COUNTERS, DEVICES, KNOWLEDGE, KNOWLEDGE_ARTIFACTS, MEMBERS, MESH_NAMES, PURGED_CHATS } from '../collections.js';
|
|
5
|
+
import { AGENTS, CHATS, CHUNKS, CHUNK_COUNTERS, DEVICES, KNOWLEDGE, KNOWLEDGE_ARTIFACTS, MEMBERS, MESH_NAMES, MESH_SEEDS, PURGED_CHATS } from '../collections.js';
|
|
6
6
|
export async function syncChanges(mesh, view, from) {
|
|
7
7
|
if (mesh.closing)
|
|
8
8
|
return;
|
|
@@ -11,10 +11,8 @@ export async function syncChanges(mesh, view, from) {
|
|
|
11
11
|
let membershipMoved = false;
|
|
12
12
|
let agentsDirty = false;
|
|
13
13
|
let meshesChanged = false;
|
|
14
|
-
let grantsChanged = false;
|
|
15
14
|
const orderDirty = new Set();
|
|
16
15
|
const purged = new Map();
|
|
17
|
-
let kindChanged = false;
|
|
18
16
|
let nameChanged = false;
|
|
19
17
|
const snap = view.db.snapshot();
|
|
20
18
|
const files = new FileChanges(snap, from);
|
|
@@ -58,15 +56,9 @@ export async function syncChanges(mesh, view, from) {
|
|
|
58
56
|
else if (changed(change, PURGED_CHATS)) {
|
|
59
57
|
purged.set(change.value.chatId, change.value.at);
|
|
60
58
|
}
|
|
61
|
-
else if (change.collection === '@qvac/joined-meshes') {
|
|
59
|
+
else if (change.collection === '@qvac/joined-meshes' || change.collection === MESH_SEEDS) {
|
|
62
60
|
meshesChanged = true;
|
|
63
61
|
}
|
|
64
|
-
else if (change.collection === '@qvac/mesh-invite-grants') {
|
|
65
|
-
grantsChanged = true;
|
|
66
|
-
}
|
|
67
|
-
else if (change.collection === '@qvac/mesh-kinds') {
|
|
68
|
-
kindChanged = true;
|
|
69
|
-
}
|
|
70
62
|
else if (change.collection === MESH_NAMES) {
|
|
71
63
|
nameChanged = true;
|
|
72
64
|
}
|
|
@@ -100,12 +92,6 @@ export async function syncChanges(mesh, view, from) {
|
|
|
100
92
|
await mesh.syncChatOrder(orderDirty);
|
|
101
93
|
}
|
|
102
94
|
mesh.emit('meshes-dirty', meshesChanged);
|
|
103
|
-
if (grantsChanged) {
|
|
104
|
-
void mesh.refreshGrantExpiry();
|
|
105
|
-
}
|
|
106
|
-
if (kindChanged) {
|
|
107
|
-
mesh.emit('mesh-kind');
|
|
108
|
-
}
|
|
109
95
|
if (nameChanged) {
|
|
110
96
|
await mesh.refreshName();
|
|
111
97
|
mesh.emit('mesh-named');
|
package/dist-lib/lib/core.d.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import Corestore from 'corestore';
|
|
2
2
|
import CorestoreStorage from 'hypercore-storage';
|
|
3
3
|
import type { BootstrapNode } from 'hyperswarm';
|
|
4
|
+
import Hyperswarm from 'hyperswarm';
|
|
5
|
+
import Wakeup from 'protomux-wakeup';
|
|
4
6
|
import ReadyGuard from 'ready-guard';
|
|
5
7
|
import ReadyResource from 'ready-resource';
|
|
6
8
|
import type { Logger } from '../index.ts';
|
|
7
9
|
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
10
|
import type { InferenceCallSource } from './api/inference-calls.ts';
|
|
9
11
|
import { type SkillOptions } from './api/index.ts';
|
|
12
|
+
import type { ModelMemoryUse } from './model-memory-cap.ts';
|
|
10
13
|
import { type BlindPeeringOpts } from './core/blind-peers.ts';
|
|
11
14
|
import { type IndexingEmbedder, type RagExtractors, type VectorIndex } from './core/files/index.ts';
|
|
12
15
|
import { type DriveHost } from './core/fs-drives.ts';
|
|
@@ -32,6 +35,9 @@ export interface FileGcOptions {
|
|
|
32
35
|
}
|
|
33
36
|
export interface CoreOptions {
|
|
34
37
|
storagePath: string;
|
|
38
|
+
store?: Corestore;
|
|
39
|
+
swarm?: Hyperswarm;
|
|
40
|
+
wakeup?: Wakeup;
|
|
35
41
|
logger?: Logger | null;
|
|
36
42
|
spec?: () => Promise<CoreSpec>;
|
|
37
43
|
bootstrapNodes?: ReadonlyArray<BootstrapNode>;
|
|
@@ -42,6 +48,7 @@ export interface CoreOptions {
|
|
|
42
48
|
blindPeerKeys?: ReadonlyArray<Buffer>;
|
|
43
49
|
blindPeeringOpts?: BlindPeeringOpts;
|
|
44
50
|
fileGc?: FileGcOptions | null;
|
|
51
|
+
autoDownloadModels?: boolean;
|
|
45
52
|
meshSeed?: Buffer;
|
|
46
53
|
meshKey?: Buffer;
|
|
47
54
|
additionalNodes?: ReadonlyArray<{
|
|
@@ -73,27 +80,15 @@ export interface CoreOptions {
|
|
|
73
80
|
readonly suspend: () => Promise<void>;
|
|
74
81
|
readonly resume: () => Promise<void>;
|
|
75
82
|
};
|
|
76
|
-
grantWritableMs?: number;
|
|
77
|
-
accountWritableMs?: number;
|
|
78
|
-
grantVisibleMs?: number;
|
|
79
83
|
}
|
|
80
84
|
export declare const ACCOUNT_MEMBER_UNKNOWN = "This device is not part of its account yet";
|
|
81
|
-
export declare const
|
|
85
|
+
export declare const DEVICE_UNKNOWN = "This device has no device details: pass `device` when creating Core";
|
|
82
86
|
export declare const MEMBER_INVITE_HOME_REFUSED = "An account mesh cannot be invited into";
|
|
83
87
|
export declare const DEVICE_INVITE_MESH_REFUSED = "Only an account mesh can take a device invite";
|
|
84
88
|
export declare const MESH_NAME_ACCOUNT_REFUSED = "An account mesh has no shared name";
|
|
85
89
|
export declare const INVITE_ACCOUNT_UNREADABLE = "This device cannot reach its account to check";
|
|
90
|
+
export declare const DEVICE_INVITE_CHAIN_TOO_LONG = "This device cannot invite another one: invite from another of your devices, or recover from your phrase";
|
|
86
91
|
export declare const MESH_HELD_BY_SIBLING = "Another of your devices holds this mesh: bring that device online, or invite from it instead";
|
|
87
|
-
export declare const INVITE_GRANT_REVOKED = "This invite was revoked";
|
|
88
|
-
export declare const MESH_ALREADY_JOINED = "This device is already in this mesh";
|
|
89
|
-
export declare const MESH_ADMISSION_PENDING = "This mesh has not admitted this device yet: try again in a moment";
|
|
90
|
-
export declare const MEMBER_ALREADY_IN_MESH = "Another of your devices is already in this mesh: join through it once it is online";
|
|
91
|
-
export declare const DEVICE_OF_ANOTHER_MEMBER = "This device belongs to another member in this mesh";
|
|
92
|
-
export declare const MEMBER_REMOVED_SINCE_INVITE = "You were removed from this mesh after this invite was made: ask for a new one";
|
|
93
|
-
export declare const INVITE_GRANT_EXPIRED = "This invite has expired";
|
|
94
|
-
export declare const INVITE_GRANT_EXHAUSTED = "This invite has already been used";
|
|
95
|
-
export declare const SEALED_ACCOUNT_READER = "This account admits no device by its seed alone: pair this device with a device invite";
|
|
96
|
-
export declare const INVITER_OFFLINE = "The device that made this invite is not online: bring it online and try again";
|
|
97
92
|
export interface SharedMesh {
|
|
98
93
|
readonly meshId: string;
|
|
99
94
|
readonly notice?: string;
|
|
@@ -133,8 +128,10 @@ export declare class Core extends ReadyResource {
|
|
|
133
128
|
store: Corestore;
|
|
134
129
|
rootCorestore: Corestore;
|
|
135
130
|
storage: CorestoreStorage;
|
|
131
|
+
private readonly _ownsStore;
|
|
132
|
+
private readonly _ownsSwarm;
|
|
133
|
+
private readonly _ownsWakeup;
|
|
136
134
|
local: ReturnType<typeof openLocalStore>;
|
|
137
|
-
private readonly _deviceInvites;
|
|
138
135
|
state: LocalQvacState;
|
|
139
136
|
private readonly _transport;
|
|
140
137
|
private readonly _apiLifecycle;
|
|
@@ -154,15 +151,14 @@ export declare class Core extends ReadyResource {
|
|
|
154
151
|
private readonly _blindPeerKeys;
|
|
155
152
|
private readonly _blindPeeringOpts;
|
|
156
153
|
private readonly _fileGc;
|
|
154
|
+
private readonly _autoDownloadModels;
|
|
157
155
|
private _fileGcTimer;
|
|
158
156
|
private _fileGcRun;
|
|
159
157
|
private readonly _meshSeed;
|
|
160
158
|
private readonly _meshKey;
|
|
161
159
|
private readonly _additionalNodes;
|
|
162
|
-
private readonly _grantWritableMs;
|
|
163
|
-
private readonly _accountWritableMs;
|
|
164
|
-
private readonly _grantVisibleMs;
|
|
165
160
|
private _listModels;
|
|
161
|
+
private _modelMemory;
|
|
166
162
|
private _deleteModel;
|
|
167
163
|
private _clearKvCache;
|
|
168
164
|
private _deleteChatKvCache;
|
|
@@ -211,16 +207,14 @@ export declare class Core extends ReadyResource {
|
|
|
211
207
|
private _identityPhrase;
|
|
212
208
|
private _identityPublicKey;
|
|
213
209
|
private _swarm;
|
|
210
|
+
private readonly _onSwarmConnection;
|
|
214
211
|
private _departures;
|
|
215
212
|
private _fsDrives;
|
|
216
213
|
private _blobServer;
|
|
217
214
|
private readonly _wakeup;
|
|
218
|
-
private readonly _meshSeedHandoff;
|
|
219
215
|
private readonly _harnessLoan;
|
|
220
216
|
private _serveLoanedHarness;
|
|
221
217
|
private readonly _following;
|
|
222
|
-
private readonly _admissionRetries;
|
|
223
|
-
private readonly _admissionRetryPending;
|
|
224
218
|
private _revokingInMeshes;
|
|
225
219
|
private _revokeInMeshesAgain;
|
|
226
220
|
private _sweepUnknownEverywhere;
|
|
@@ -229,10 +223,12 @@ export declare class Core extends ReadyResource {
|
|
|
229
223
|
private readonly _skillOverlayHandoff;
|
|
230
224
|
private readonly _inferenceCallsHandoff;
|
|
231
225
|
private _minting;
|
|
226
|
+
private _backfill;
|
|
232
227
|
private _leaving;
|
|
233
228
|
private _kicked;
|
|
234
229
|
private _kickedPending;
|
|
235
230
|
private readonly _peers;
|
|
231
|
+
private _peerArrivedSuspended;
|
|
236
232
|
private readonly _statusListeners;
|
|
237
233
|
private _listing;
|
|
238
234
|
private readonly _diagnosticsProviders;
|
|
@@ -242,7 +238,7 @@ export declare class Core extends ReadyResource {
|
|
|
242
238
|
private _systemInfo;
|
|
243
239
|
private _statusError;
|
|
244
240
|
private _upgradeRequired;
|
|
245
|
-
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
|
|
241
|
+
constructor(transport: Transport, { storagePath, store, swarm, wakeup, logger, spec, bootstrapNodes, device, app, minSupportedVersion, otaConfigCore, blindPeerKeys, blindPeeringOpts, fileGc, autoDownloadModels, meshSeed, meshKey, additionalNodes, listModels, deleteModel, clearKvCache, deleteChatKvCache, compactChat, modelCatalogWatch, retryModelDownload, transcribe, detectLanguage, previewModelSource, speak, speakStream, embedder, extractors, skills, skillCatalog, tools, hostsModelSource, vectorIndex, apiLifecycle }: CoreOptions);
|
|
246
242
|
get devicePublicKey(): Buffer | null;
|
|
247
243
|
private _requireDeviceKeyPair;
|
|
248
244
|
get fsDrives(): DriveHost | null;
|
|
@@ -271,13 +267,18 @@ export declare class Core extends ReadyResource {
|
|
|
271
267
|
suspend(): Promise<void>;
|
|
272
268
|
resume(): Promise<void>;
|
|
273
269
|
private _refreshTopics;
|
|
270
|
+
private _joinedTopics;
|
|
274
271
|
_close(): Promise<void>;
|
|
272
|
+
private _closeStore;
|
|
275
273
|
private _openSwarm;
|
|
276
274
|
private _resolveBlindPeerKeys;
|
|
277
275
|
private _startMesh;
|
|
278
276
|
private _switchToMesh;
|
|
279
277
|
private _openMesh;
|
|
280
278
|
private _openMeshSession;
|
|
279
|
+
private _appendOwnBirth;
|
|
280
|
+
private _requireLocalDevice;
|
|
281
|
+
private _appendJoinLater;
|
|
281
282
|
private _accountBirthMember;
|
|
282
283
|
private _mintBirthMember;
|
|
283
284
|
publishAccountRecovery(mnemonic: string): Promise<boolean>;
|
|
@@ -287,11 +288,14 @@ export declare class Core extends ReadyResource {
|
|
|
287
288
|
private _openOwnRecoveryCore;
|
|
288
289
|
private _adoptRecoveryCore;
|
|
289
290
|
recoverAccount(mnemonic: string, { timeout }?: RecoverAccountOptions): Promise<void>;
|
|
290
|
-
private
|
|
291
|
+
private _joinRecoveredAccount;
|
|
292
|
+
private _rerootRecovered;
|
|
291
293
|
private _readRecovery;
|
|
292
294
|
private _peerRecoveryCore;
|
|
293
295
|
private _closeRecovery;
|
|
294
296
|
private _joinBirthMember;
|
|
297
|
+
private _knownBirthMember;
|
|
298
|
+
private _recoveryBirthMember;
|
|
295
299
|
private _holdIdentityPhrase;
|
|
296
300
|
private _pushIdentityPhrase;
|
|
297
301
|
private _offerIdentityPhrase;
|
|
@@ -300,12 +304,12 @@ export declare class Core extends ReadyResource {
|
|
|
300
304
|
private _advertiseAppVersion;
|
|
301
305
|
private _retractInventory;
|
|
302
306
|
private _settleMembership;
|
|
303
|
-
private _sealAccount;
|
|
304
307
|
private _renameFoundedMember;
|
|
305
308
|
private _adoptName;
|
|
306
309
|
private _followAccountName;
|
|
307
310
|
private _claimOwnMembership;
|
|
308
311
|
private _knownMember;
|
|
312
|
+
private _recordedMember;
|
|
309
313
|
private _migrationContext;
|
|
310
314
|
private _recordMemberProof;
|
|
311
315
|
private _ensureNotRevoked;
|
|
@@ -330,6 +334,8 @@ export declare class Core extends ReadyResource {
|
|
|
330
334
|
private _reopenOwnAccount;
|
|
331
335
|
private _claimJoin;
|
|
332
336
|
private _joinMeshInvite;
|
|
337
|
+
private _reopenRecordedMesh;
|
|
338
|
+
private _keepsWriter;
|
|
333
339
|
private _runJoinMesh;
|
|
334
340
|
private _joinParkedMesh;
|
|
335
341
|
private _joinCandidate;
|
|
@@ -338,23 +344,21 @@ export declare class Core extends ReadyResource {
|
|
|
338
344
|
private _departIfPooled;
|
|
339
345
|
private _recordJoinedMesh;
|
|
340
346
|
private _registerMesh;
|
|
347
|
+
private _backfillMeshSeeds;
|
|
348
|
+
private _writeMeshSeeds;
|
|
349
|
+
private _registerRecordedMeshes;
|
|
350
|
+
private _seedRowDue;
|
|
341
351
|
private _releaseJoinedMesh;
|
|
342
352
|
private _writableAccount;
|
|
343
|
-
private _awaitGrantRow;
|
|
344
|
-
private _untilDeadline;
|
|
345
|
-
private _refuseIfGrantUnusable;
|
|
346
|
-
private _refuseUnredeemable;
|
|
347
|
-
private _refuseFromOwnCopy;
|
|
348
353
|
private _openCandidateMesh;
|
|
349
|
-
private
|
|
350
|
-
private
|
|
351
|
-
private
|
|
354
|
+
private _candidateBirthMember;
|
|
355
|
+
private _delegatedBirthMember;
|
|
356
|
+
private _onMeshSeedDue;
|
|
352
357
|
private _onMeshWritable;
|
|
353
358
|
private _onMeshDead;
|
|
354
359
|
private _onMeshStalled;
|
|
355
360
|
private _wireMesh;
|
|
356
361
|
private _adoptAccount;
|
|
357
|
-
private _refuseSealedReader;
|
|
358
362
|
private _pooled;
|
|
359
363
|
private _accountMesh;
|
|
360
364
|
private _meshIdOf;
|
|
@@ -375,6 +379,7 @@ export declare class Core extends ReadyResource {
|
|
|
375
379
|
private _startMeshServices;
|
|
376
380
|
private _stopHostedAgents;
|
|
377
381
|
private _discardCandidateMesh;
|
|
382
|
+
private _recordDeparture;
|
|
378
383
|
private _departureHasAudience;
|
|
379
384
|
private _announceDeparture;
|
|
380
385
|
leaveMesh(meshId: string): Promise<void>;
|
|
@@ -404,7 +409,6 @@ export declare class Core extends ReadyResource {
|
|
|
404
409
|
private _openPooledMesh;
|
|
405
410
|
private _openRecordedMesh;
|
|
406
411
|
private _meshEntry;
|
|
407
|
-
private _admission;
|
|
408
412
|
private _meshEntryState;
|
|
409
413
|
private _meshKeyOf;
|
|
410
414
|
removeDeviceWriter(writerKey: Buffer, deviceId: Buffer, mesh?: Mesh): Promise<void>;
|
|
@@ -420,6 +424,7 @@ export declare class Core extends ReadyResource {
|
|
|
420
424
|
waitForWritable(): Promise<void>;
|
|
421
425
|
private _assertMeshIsHere;
|
|
422
426
|
getMeshInvite(opts?: MeshInviteOptions): Promise<MeshInvite | null>;
|
|
427
|
+
private _delegatePairing;
|
|
423
428
|
previewMeshInvite(invite: string): MeshInvitePreview;
|
|
424
429
|
private _closeSwarm;
|
|
425
430
|
pushSkillSecret(request: SecretRequest): Promise<void>;
|
|
@@ -429,28 +434,14 @@ export declare class Core extends ReadyResource {
|
|
|
429
434
|
private _trackFollow;
|
|
430
435
|
private _retireLeftMesh;
|
|
431
436
|
private _archiveLeftMeshRow;
|
|
432
|
-
private _openOwnMesh;
|
|
433
|
-
private _adoptOwnMesh;
|
|
434
|
-
private _refusedInMesh;
|
|
435
437
|
private _openFollowedMesh;
|
|
436
|
-
private
|
|
437
|
-
private _requestMeshAdmission;
|
|
438
|
-
private _askSiblingsToAdmit;
|
|
439
|
-
private _retryAdmission;
|
|
440
|
-
private _liveSiblings;
|
|
438
|
+
private _mayFollow;
|
|
441
439
|
registerLoanableHarness(serve: (stream: LoanStreamDuplex) => void): () => void;
|
|
442
440
|
borrowHarness(deviceId: string): LoanStreamDuplex;
|
|
443
441
|
private _lendHarness;
|
|
444
442
|
private _revalidateLoans;
|
|
445
443
|
private _computeLender;
|
|
446
444
|
private _sharesComputeMesh;
|
|
447
|
-
private _serveMeshSeed;
|
|
448
|
-
private _admitInvitedDevice;
|
|
449
|
-
private _admitIntoMesh;
|
|
450
|
-
private _admitIntoMeshLocked;
|
|
451
|
-
private _isJoinedMeshKey;
|
|
452
|
-
private _removedFor;
|
|
453
|
-
private _askerStanding;
|
|
454
445
|
private _skillOverlayOp;
|
|
455
446
|
private _resolveAgentHost;
|
|
456
447
|
private _listInferenceCalls;
|
|
@@ -462,6 +453,7 @@ export declare class Core extends ReadyResource {
|
|
|
462
453
|
private _setupFields;
|
|
463
454
|
private _hostSkills;
|
|
464
455
|
private _onConnection;
|
|
456
|
+
private _retryOnPeer;
|
|
465
457
|
private _trackPeerConnection;
|
|
466
458
|
private _onPeerChange;
|
|
467
459
|
private _meshPool;
|
|
@@ -476,6 +468,7 @@ export declare class Core extends ReadyResource {
|
|
|
476
468
|
registerModelUsers(users: (name: string) => Promise<AssistantModelUsers>): () => void;
|
|
477
469
|
registerInferenceCalls(source: InferenceCallSource): () => void;
|
|
478
470
|
registerListModels(hook: (options: AssistantListModelsRequest) => Promise<AssistantModelInfoList>): () => void;
|
|
471
|
+
registerModelMemory(hook: () => Promise<ModelMemoryUse | null>): () => void;
|
|
479
472
|
registerDeleteModel(hook: (options: AssistantDeleteModelRequest) => Promise<AssistantDeleteModelResponse>): () => void;
|
|
480
473
|
registerClearKvCache(hook: () => Promise<AssistantKvCacheDeletionResponse>): () => void;
|
|
481
474
|
registerDeleteChatKvCache(hook: (chatId: string) => Promise<AssistantKvCacheDeletionResponse>): () => void;
|
|
@@ -483,6 +476,7 @@ export declare class Core extends ReadyResource {
|
|
|
483
476
|
registerModelCatalogWatch(hook: () => AsyncIterable<AssistantModelCatalogRevision>): () => void;
|
|
484
477
|
private _watchModelCatalog;
|
|
485
478
|
private _modelCatalogRevisions;
|
|
479
|
+
private _readModelList;
|
|
486
480
|
private _readModels;
|
|
487
481
|
private _openModelCatalogWatchSource;
|
|
488
482
|
private _resetModelCatalogWatchSource;
|