@qvac/core 0.6.3 → 0.6.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 +78 -1
- package/README.md +24 -16
- package/dist-lib/lib/api/chat-move.d.ts +3 -0
- package/dist-lib/lib/api/chat-move.js +7 -0
- package/dist-lib/lib/api/chat.d.ts +1 -1
- package/dist-lib/lib/api/chat.js +2 -1
- package/dist-lib/lib/api/chunk-delta.d.ts +7 -0
- package/dist-lib/lib/api/chunk-delta.js +33 -0
- package/dist-lib/lib/api/chunks.d.ts +1 -1
- package/dist-lib/lib/api/chunks.js +6 -3
- package/dist-lib/lib/api/index.d.ts +2 -0
- package/dist-lib/lib/api/index.js +2 -0
- package/dist-lib/lib/api/mesh.d.ts +2 -1
- package/dist-lib/lib/api/mesh.js +4 -0
- package/dist-lib/lib/assistant/harness.d.ts +8 -10
- package/dist-lib/lib/assistant.js +1 -1
- package/dist-lib/lib/constants.d.ts +1 -0
- package/dist-lib/lib/constants.js +1 -0
- package/dist-lib/lib/core/archived-mesh.js +3 -42
- package/dist-lib/lib/core/chat-activity.js +23 -10
- package/dist-lib/lib/core/chat-copy.d.ts +24 -0
- package/dist-lib/lib/core/chat-copy.js +115 -0
- package/dist-lib/lib/core/chat-move.d.ts +65 -0
- package/dist-lib/lib/core/chat-move.js +525 -0
- package/dist-lib/lib/core/chat.d.ts +6 -0
- package/dist-lib/lib/core/chat.js +11 -3
- package/dist-lib/lib/core/collections.d.ts +2 -0
- package/dist-lib/lib/core/collections.js +2 -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 +2 -0
- package/dist-lib/lib/core/contract/invites.d.ts +1 -0
- package/dist-lib/lib/core/contract/invites.js +1 -1
- package/dist-lib/lib/core/contract/mesh-name.d.ts +3 -0
- package/dist-lib/lib/core/contract/mesh-name.js +26 -0
- package/dist-lib/lib/core/contract/writers.js +10 -3
- package/dist-lib/lib/core/files/index.d.ts +1 -1
- package/dist-lib/lib/core/files/index.js +1 -1
- package/dist-lib/lib/core/files/preview/index.js +4 -1
- package/dist-lib/lib/core/files/processing/source.js +4 -1
- package/dist-lib/lib/core/files/rag/limits.d.ts +0 -1
- package/dist-lib/lib/core/files/rag/limits.js +0 -1
- package/dist-lib/lib/core/files/store/index.d.ts +2 -1
- package/dist-lib/lib/core/files/store/index.js +2 -1
- package/dist-lib/lib/core/files/store/reference.d.ts +3 -0
- package/dist-lib/lib/core/files/store/reference.js +8 -0
- package/dist-lib/lib/core/files/store/sweep.js +3 -1
- package/dist-lib/lib/core/local/index.d.ts +4 -1
- package/dist-lib/lib/core/local/index.js +14 -1
- package/dist-lib/lib/core/mesh-seed-handoff.d.ts +3 -1
- package/dist-lib/lib/core/mesh-seed-handoff.js +1 -0
- package/dist-lib/lib/core/mesh.d.ts +5 -1
- package/dist-lib/lib/core/mesh.js +16 -1
- package/dist-lib/lib/core/sync/index.js +9 -1
- package/dist-lib/lib/core.d.ts +9 -0
- package/dist-lib/lib/core.js +156 -32
- package/dist-lib/lib/custom-model-pusher.js +9 -5
- package/dist-lib/lib/mesh-scoped-engine.js +5 -0
- package/dist-lib/schema/config.d.ts +1 -1
- package/dist-lib/schema/config.js +1 -1
- package/dist-lib/schema/engine.js +80 -1
- package/dist-lib/schema/local.js +17 -0
- package/dist-lib/schema/qvac.d.ts +2 -0
- package/dist-lib/schema/qvac.js +16 -0
- package/dist-lib/spec/bind.js +25 -0
- package/dist-lib/spec/calls.js +5 -0
- package/dist-lib/spec/capabilities.d.ts +10 -0
- package/dist-lib/spec/config/hyperconf/index.js +1 -1
- package/dist-lib/spec/hrpc/hrpc.json +65 -0
- package/dist-lib/spec/hrpc/index.js +66 -4
- package/dist-lib/spec/hrpc/messages.js +1398 -1154
- package/dist-lib/spec/hyperschema/index.js +1398 -1154
- package/dist-lib/spec/hyperschema/schema.json +204 -0
- package/dist-lib/spec/hyperschema/types.d.ts +47 -0
- package/dist-lib/spec/local/hyperdb/db.json +17 -1
- package/dist-lib/spec/local/hyperdb/index.js +83 -2
- package/dist-lib/spec/local/hyperdb/messages.js +340 -136
- package/dist-lib/spec/local/hyperschema/index.js +107 -2
- package/dist-lib/spec/local/hyperschema/schema.json +78 -1
- package/dist-lib/spec/local/hyperschema/types.d.ts +18 -1
- 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 +454 -228
- package/dist-lib/spec/mesh/hyperdispatch/dispatch.json +7 -1
- package/dist-lib/spec/mesh/hyperdispatch/index.js +18 -1
- package/dist-lib/spec/mesh/hyperdispatch/messages.js +150 -2
- package/dist-lib/spec/mesh/hyperschema/index.js +150 -2
- package/dist-lib/spec/mesh/hyperschema/schema.json +76 -1
- package/dist-lib/spec/mesh/hyperschema/types.d.ts +21 -1
- package/package.json +5 -8
- package/tui/app.mjs +89 -3
- package/tui/lib/move-command.mjs +17 -0
- package/dist-lib/lib/collabora/convert.d.ts +0 -9
- package/dist-lib/lib/collabora/convert.js +0 -65
- package/dist-lib/lib/collabora/entry.d.ts +0 -1
- package/dist-lib/lib/collabora/entry.js +0 -42
- package/dist-lib/lib/collabora/protocol.d.ts +0 -15
- package/dist-lib/lib/collabora/protocol.js +0 -31
- package/dist-lib/lib/collabora/worker.d.ts +0 -5
- package/dist-lib/lib/collabora/worker.js +0 -177
- package/dist-lib/lib/core/files/rag/extract/office-collabora.d.ts +0 -2
- package/dist-lib/lib/core/files/rag/extract/office-collabora.js +0 -8
package/dist-lib/lib/core.js
CHANGED
|
@@ -12,7 +12,8 @@ import ReadyGuard from 'ready-guard';
|
|
|
12
12
|
import ReadyResource from 'ready-resource';
|
|
13
13
|
import ScopeLock from 'scope-lock';
|
|
14
14
|
import { createApi } from './api/index.js';
|
|
15
|
-
import { NO_SUCH_MESH } from './api/current-mesh.js';
|
|
15
|
+
import { NO_SUCH_MESH, requireMesh } from './api/current-mesh.js';
|
|
16
|
+
import { ChatMoves } from './core/chat-move.js';
|
|
16
17
|
import { asEncoded, watchModels } from './models-watch.js';
|
|
17
18
|
import { BLIND_PEER_KEYS, BLIND_RELAY_KEYS } from './core/blind-peers.js';
|
|
18
19
|
import { CoreBlobServer, MemoryVectorIndex } from './core/files/index.js';
|
|
@@ -20,13 +21,13 @@ import { getChat, removeChatAttachments, removeChatKnowledge } from './core/chat
|
|
|
20
21
|
import { rebuildChatOrder, refreshChatOrder } from './core/chat-order.js';
|
|
21
22
|
import { createFsDriveHost } from './core/fs-drives.js';
|
|
22
23
|
import { sweepDriveStaging } from './fs-drive-bridge.js';
|
|
23
|
-
import { closeCollaboraWorker } from './collabora/worker.js';
|
|
24
24
|
import { decodeMeshInvite, encodeMeshInvite } from './core/invite.js';
|
|
25
25
|
import { fileKeyOf, knownFile, referencedFile } from './core/files/local-index.js';
|
|
26
26
|
import { grantKeyPair, inviteGrantTermsRefusal } from './core/invite-grants.js';
|
|
27
|
-
import { belongsToAnotherMember, inviteStanding, memberStanding } from './core/contract/invites.js';
|
|
27
|
+
import { belongsToAnotherMember, inviteStanding, memberStanding, removedBy } from './core/contract/invites.js';
|
|
28
28
|
import { syncStatusSnapshot } from './core/sync-status.js';
|
|
29
29
|
import { openLocalStore } from './core/local/index.js';
|
|
30
|
+
import { MAX_MESH_NAME_CHARS, meshNameWithinBounds } from '../schema/qvac.js';
|
|
30
31
|
import { getAgent } from './core/agent.js';
|
|
31
32
|
import { countContents, migrateContents, withArchivedMesh } from './core/archived-mesh.js';
|
|
32
33
|
import { HostedAgents } from './core/hosted-agents.js';
|
|
@@ -34,7 +35,7 @@ import { HarnessLoan } from './core/harness-loan.js';
|
|
|
34
35
|
import { duplexPair } from '@qvac/harness/transport';
|
|
35
36
|
import { signMemberWriterClaim, signWriterClaim, verifyMemberWriterClaim, verifyWriterClaim } from './core/device-attestation.js';
|
|
36
37
|
import { HOST_SILENT, HOST_UNREACHABLE } from './core/handoff-channel.js';
|
|
37
|
-
import { MeshSeedHandoff, SEED_REFUSED, SEED_ASKER_UNSEEN } from './core/mesh-seed-handoff.js';
|
|
38
|
+
import { MeshSeedHandoff, SEED_REFUSED, ADMISSION_DEFERRED, SEED_ASKER_UNSEEN } from './core/mesh-seed-handoff.js';
|
|
38
39
|
import { SecretHandoff } from './core/secret-handoff.js';
|
|
39
40
|
import { InferenceCallsHandoff } from './core/inference-calls-handoff.js';
|
|
40
41
|
import { createInferenceCallsReceiver, NO_RECORD_STORE } from './core/inference-calls-receiver.js';
|
|
@@ -71,7 +72,6 @@ const MESH_JOIN_CANCELED = 'Mesh join canceled';
|
|
|
71
72
|
const GRANT_JOIN_TIMED_OUT = 'Join did not complete in time - the invite may already be spent, expired or revoked';
|
|
72
73
|
const MESH_ID = /^[0-9a-f]{64}$/;
|
|
73
74
|
const MESH_BELOW_FLOOR = 'Build is below the mesh floor';
|
|
74
|
-
const LEAVE_HOME_REFUSED = 'Your account cannot be left while other meshes remain';
|
|
75
75
|
const MESH_WITHOUT_ACCOUNT = 'Recording a mesh needs the account mesh';
|
|
76
76
|
export const ACCOUNT_MEMBER_UNKNOWN = 'This device is not part of its account yet';
|
|
77
77
|
export const AWAITING_ADMISSION = 'awaiting-admission';
|
|
@@ -86,6 +86,7 @@ const RECOVERY_DEVICE_REMOVED = 'This device was removed from the account, so it
|
|
|
86
86
|
const RECOVERY_WAIT_MS = 30_000;
|
|
87
87
|
export const MEMBER_INVITE_HOME_REFUSED = 'An account mesh cannot be invited into';
|
|
88
88
|
export const DEVICE_INVITE_MESH_REFUSED = 'Only an account mesh can take a device invite';
|
|
89
|
+
export const MESH_NAME_ACCOUNT_REFUSED = 'An account mesh has no shared name';
|
|
89
90
|
export const INVITE_ACCOUNT_UNREADABLE = 'This device cannot reach its account to check';
|
|
90
91
|
export const MESH_HELD_BY_SIBLING = 'Another of your devices holds this mesh: bring that device online, or invite from it instead';
|
|
91
92
|
export const INVITE_GRANT_REVOKED = 'This invite was revoked';
|
|
@@ -109,6 +110,7 @@ const DIAGNOSTICS_SAMPLE_MS = 2000;
|
|
|
109
110
|
const ACCOUNT_WRITABLE_MS = 15_000;
|
|
110
111
|
const GRANT_WRITABLE_MS = 60_000;
|
|
111
112
|
const INVITER_RETRY_MS = 1_000;
|
|
113
|
+
const ADMISSION_RETRIES = 60;
|
|
112
114
|
export class Core extends ReadyResource {
|
|
113
115
|
_storagePath;
|
|
114
116
|
store;
|
|
@@ -186,6 +188,7 @@ export class Core extends ReadyResource {
|
|
|
186
188
|
_rpcs = new Set();
|
|
187
189
|
_stream;
|
|
188
190
|
_api;
|
|
191
|
+
_chatMoves = null;
|
|
189
192
|
_clients;
|
|
190
193
|
_deviceKeyPair;
|
|
191
194
|
_identityPhrase = null;
|
|
@@ -199,6 +202,8 @@ export class Core extends ReadyResource {
|
|
|
199
202
|
_harnessLoan;
|
|
200
203
|
_serveLoanedHarness = null;
|
|
201
204
|
_following = new Map();
|
|
205
|
+
_admissionRetries = new Map();
|
|
206
|
+
_admissionRetryPending = new Set();
|
|
202
207
|
_revokingInMeshes = null;
|
|
203
208
|
_revokeInMeshesAgain = false;
|
|
204
209
|
_sweepUnknownEverywhere = false;
|
|
@@ -402,6 +407,12 @@ export class Core extends ReadyResource {
|
|
|
402
407
|
await this._openBootMesh();
|
|
403
408
|
this._systemInfo = createSystemInfoSampler();
|
|
404
409
|
const meshStatus = this._meshStatusSource();
|
|
410
|
+
const deviceId = this.devicePublicKey;
|
|
411
|
+
this._chatMoves = deviceId
|
|
412
|
+
? new ChatMoves((meshId) => requireMesh(this._meshPool(), meshId), this.local, {
|
|
413
|
+
deviceId
|
|
414
|
+
})
|
|
415
|
+
: null;
|
|
405
416
|
this._api = createApi({
|
|
406
417
|
state: this.local,
|
|
407
418
|
mesh: this._meshPool(),
|
|
@@ -413,6 +424,7 @@ export class Core extends ReadyResource {
|
|
|
413
424
|
forget: async (chatId) => void (await this._inferenceCalls?.forget(chatId))
|
|
414
425
|
},
|
|
415
426
|
logs: this._logSource(),
|
|
427
|
+
chatMoves: this._chatMoves,
|
|
416
428
|
deviceId: this.devicePublicKey,
|
|
417
429
|
lifecycle: this._apiLifecycle,
|
|
418
430
|
ragIndex: (meshId) => this._meshes.get(meshId)?.vectorIndex ?? null,
|
|
@@ -543,6 +555,9 @@ export class Core extends ReadyResource {
|
|
|
543
555
|
this._rpcs.add(rpc);
|
|
544
556
|
this._offlineBoot.exit();
|
|
545
557
|
void this._pushIdentityPhrase();
|
|
558
|
+
this._chatMoves
|
|
559
|
+
?.resume()
|
|
560
|
+
.catch((err) => logger.warn('chat-move', 'unfinished moves not resumed', { err }));
|
|
546
561
|
return;
|
|
547
562
|
}
|
|
548
563
|
catch (err) {
|
|
@@ -918,9 +933,10 @@ export class Core extends ReadyResource {
|
|
|
918
933
|
await this._stopHostedAgents(entry);
|
|
919
934
|
}
|
|
920
935
|
await this._stopIndexing();
|
|
921
|
-
closeCollaboraWorker();
|
|
922
936
|
await this._blobServer?.close();
|
|
923
937
|
this._blobServer = null;
|
|
938
|
+
await this._chatMoves?.close();
|
|
939
|
+
this._chatMoves = null;
|
|
924
940
|
for (const entry of this._meshes.values()) {
|
|
925
941
|
this._unwireMesh(entry);
|
|
926
942
|
await entry.mesh.close();
|
|
@@ -2425,6 +2441,7 @@ export class Core extends ReadyResource {
|
|
|
2425
2441
|
});
|
|
2426
2442
|
mesh.on('mesh-kind', () => void this._refuseSealedReader(mesh));
|
|
2427
2443
|
mesh.on('membership-tallied', () => this._notifyStatus());
|
|
2444
|
+
mesh.on('mesh-named', () => this._notifyStatus());
|
|
2428
2445
|
mesh.on('membership', (membership) => {
|
|
2429
2446
|
void this._recordMemberProof(mesh, membership);
|
|
2430
2447
|
void this._followJoinedMeshes(mesh);
|
|
@@ -2663,6 +2680,10 @@ export class Core extends ReadyResource {
|
|
|
2663
2680
|
void mesh.refreshMembership().catch((error) => {
|
|
2664
2681
|
this._log?.warn(['p2p', 'mesh'], 'tallying membership failed', error);
|
|
2665
2682
|
});
|
|
2683
|
+
void mesh
|
|
2684
|
+
.refreshName()
|
|
2685
|
+
.then(() => this._notifyStatus())
|
|
2686
|
+
.catch((error) => this._log?.warn(['p2p', 'mesh'], 'reading the mesh name failed', error));
|
|
2666
2687
|
mesh.on('chat-tombstone', (chatId, deletedAt) => {
|
|
2667
2688
|
void this.local
|
|
2668
2689
|
.clearChatNotify(chatId)
|
|
@@ -2786,14 +2807,18 @@ export class Core extends ReadyResource {
|
|
|
2786
2807
|
throw new Error('Mesh transition already in progress');
|
|
2787
2808
|
}
|
|
2788
2809
|
const departing = await this._openPooledMesh(meshId);
|
|
2789
|
-
const others = (await this.local.listMeshes()).filter((row) => !b4a.equals(row.key, departing.key));
|
|
2790
2810
|
const leavingAccount = await this._isStoredAccount(departing);
|
|
2791
|
-
if (others.length > 0 && leavingAccount) {
|
|
2792
|
-
throw new Error(LEAVE_HOME_REFUSED);
|
|
2793
|
-
}
|
|
2794
2811
|
this._leaving = meshId;
|
|
2795
2812
|
this._notifyStatus();
|
|
2796
2813
|
try {
|
|
2814
|
+
if (leavingAccount) {
|
|
2815
|
+
await Promise.allSettled([...this._following.values()]);
|
|
2816
|
+
const others = (await this.local.listMeshes()).filter((row) => !b4a.equals(row.key, departing.key));
|
|
2817
|
+
await Promise.all(others.map((row) => this._departOnLogout(row.key)));
|
|
2818
|
+
if (this.closing) {
|
|
2819
|
+
return;
|
|
2820
|
+
}
|
|
2821
|
+
}
|
|
2797
2822
|
if (await this._departureHasAudience(departing)) {
|
|
2798
2823
|
await this.local.recordDeparture(departing.key, { creator: departing.minted });
|
|
2799
2824
|
}
|
|
@@ -2817,6 +2842,31 @@ export class Core extends ReadyResource {
|
|
|
2817
2842
|
this._notifyStatus();
|
|
2818
2843
|
}
|
|
2819
2844
|
}
|
|
2845
|
+
async _departOnLogout(key) {
|
|
2846
|
+
try {
|
|
2847
|
+
const mesh = await this._openPooledMesh(b4a.toHex(key));
|
|
2848
|
+
if (!(await this.local.awaitsAdmission(key))) {
|
|
2849
|
+
await mesh.waitForWritable(this._accountWritableMs);
|
|
2850
|
+
}
|
|
2851
|
+
if (await this._departureHasAudience(mesh)) {
|
|
2852
|
+
await this.local.recordDeparture(mesh.key, { creator: mesh.minted });
|
|
2853
|
+
}
|
|
2854
|
+
await this._announceDeparture(mesh);
|
|
2855
|
+
await this._archiveMembership(mesh);
|
|
2856
|
+
await this._retirePooledMesh(mesh);
|
|
2857
|
+
}
|
|
2858
|
+
catch (error) {
|
|
2859
|
+
this._log?.warn(['p2p', 'mesh'], 'departing a mesh on logout failed', error);
|
|
2860
|
+
if (this.closing) {
|
|
2861
|
+
return;
|
|
2862
|
+
}
|
|
2863
|
+
const held = this._pooled(b4a.toHex(key));
|
|
2864
|
+
if (held) {
|
|
2865
|
+
await this._retirePooledMesh(held).catch(noop);
|
|
2866
|
+
}
|
|
2867
|
+
await this.local.archiveMesh(key).catch(noop);
|
|
2868
|
+
}
|
|
2869
|
+
}
|
|
2820
2870
|
async _isStoredAccount(mesh) {
|
|
2821
2871
|
const key = await this._storedAccountKey();
|
|
2822
2872
|
return key !== undefined && b4a.equals(key, mesh.key);
|
|
@@ -2965,6 +3015,19 @@ export class Core extends ReadyResource {
|
|
|
2965
3015
|
});
|
|
2966
3016
|
this._notifyStatus();
|
|
2967
3017
|
}
|
|
3018
|
+
async setMeshName(meshId, name) {
|
|
3019
|
+
if (!this.opened)
|
|
3020
|
+
await this.ready();
|
|
3021
|
+
const trimmed = name.trim();
|
|
3022
|
+
if (!meshNameWithinBounds(trimmed)) {
|
|
3023
|
+
throw new Error(`mesh name must be at most ${MAX_MESH_NAME_CHARS} characters`);
|
|
3024
|
+
}
|
|
3025
|
+
const mesh = await requireMesh(this._meshPool(), meshId);
|
|
3026
|
+
if (this._isAccount(mesh)) {
|
|
3027
|
+
throw new Error(MESH_NAME_ACCOUNT_REFUSED);
|
|
3028
|
+
}
|
|
3029
|
+
await mesh.setName(trimmed);
|
|
3030
|
+
}
|
|
2968
3031
|
async createMesh({ shared = false, compute = false } = {}) {
|
|
2969
3032
|
if (!this.opened)
|
|
2970
3033
|
await this.ready();
|
|
@@ -3181,6 +3244,7 @@ export class Core extends ReadyResource {
|
|
|
3181
3244
|
open: mesh !== null,
|
|
3182
3245
|
account,
|
|
3183
3246
|
label: joined?.label || undefined,
|
|
3247
|
+
name: mesh?.name?.name || undefined,
|
|
3184
3248
|
members: mesh?.membership.members ?? 0,
|
|
3185
3249
|
shared: joined?.shared ?? false,
|
|
3186
3250
|
sharedAt: joined?.shared ? joined.sharedAt : undefined,
|
|
@@ -3231,7 +3295,9 @@ export class Core extends ReadyResource {
|
|
|
3231
3295
|
if (!target) {
|
|
3232
3296
|
throw new Error('this device holds no account mesh');
|
|
3233
3297
|
}
|
|
3234
|
-
await
|
|
3298
|
+
const paired = await this._accountMesh()?.view.get(DEVICES, { id: deviceId });
|
|
3299
|
+
const revokedAt = Math.max(Date.now(), (paired?.joinedAt ?? 0) + 1);
|
|
3300
|
+
await target.dispatch('remove-writer', { writerKey, deviceId, revokedAt });
|
|
3235
3301
|
await target.autobee.update();
|
|
3236
3302
|
if (target === this._accountMesh()) {
|
|
3237
3303
|
this._sweepUnknownEverywhere = true;
|
|
@@ -3585,8 +3651,11 @@ export class Core extends ReadyResource {
|
|
|
3585
3651
|
async _followMeshRows(memberMesh, ours) {
|
|
3586
3652
|
let pending = false;
|
|
3587
3653
|
for await (const joined of memberMesh.view.find(JOINED_MESHES)) {
|
|
3588
|
-
if (this.closing ||
|
|
3654
|
+
if (this.closing ||
|
|
3655
|
+
!this._isPooled(memberMesh) ||
|
|
3656
|
+
this._leaving === this._meshIdOf(memberMesh)) {
|
|
3589
3657
|
return pending;
|
|
3658
|
+
}
|
|
3590
3659
|
if (!b4a.equals(joined.memberId, ours))
|
|
3591
3660
|
continue;
|
|
3592
3661
|
const meshId = b4a.toHex(joined.meshKey);
|
|
@@ -3757,7 +3826,8 @@ export class Core extends ReadyResource {
|
|
|
3757
3826
|
return;
|
|
3758
3827
|
}
|
|
3759
3828
|
const moving = this._joinCancellation ? this._joinCancellation.account : this._minting;
|
|
3760
|
-
|
|
3829
|
+
const leaving = this._leaving === this._meshIdOf(memberMesh);
|
|
3830
|
+
if (moving || leaving || !this._isAccount(memberMesh)) {
|
|
3761
3831
|
return;
|
|
3762
3832
|
}
|
|
3763
3833
|
const session = this.local.createCandidateSession(seed, meshKey);
|
|
@@ -3803,7 +3873,7 @@ export class Core extends ReadyResource {
|
|
|
3803
3873
|
}
|
|
3804
3874
|
const { publicKey: deviceId, secretKey } = this._requireDeviceKeyPair();
|
|
3805
3875
|
const own = await mesh.view.get(DEVICES, { id: deviceId });
|
|
3806
|
-
if (own &&
|
|
3876
|
+
if (own && (await this._removedFor(mesh, own))) {
|
|
3807
3877
|
return this.local.markAwaitingAdmission(mesh.key, { awaitingAdmission: false });
|
|
3808
3878
|
}
|
|
3809
3879
|
const binding = {
|
|
@@ -3819,24 +3889,60 @@ export class Core extends ReadyResource {
|
|
|
3819
3889
|
memberSignature: signMemberWriterClaim(secretKey, { ...binding, memberId: ours })
|
|
3820
3890
|
};
|
|
3821
3891
|
const known = await mesh.bornKind();
|
|
3822
|
-
|
|
3823
|
-
|
|
3824
|
-
|
|
3825
|
-
if (mesh.writable)
|
|
3826
|
-
break;
|
|
3827
|
-
if (!(await this._meshSeedHandoff.admit(sibling, mesh.key, claim).catch(noop))) {
|
|
3828
|
-
continue;
|
|
3829
|
-
}
|
|
3830
|
-
await mesh.waitForWritable(this._accountWritableMs);
|
|
3892
|
+
const deferred = known !== null && (await this._askSiblingsToAdmit(memberMesh, mesh, { ours, claim }));
|
|
3893
|
+
if (this.closing) {
|
|
3894
|
+
return;
|
|
3831
3895
|
}
|
|
3832
3896
|
if (!mesh.writable && (await mesh.waitForGenesis(this._accountWritableMs)) === null) {
|
|
3833
3897
|
await mesh.appendBirthOp(this._requireDeviceKeyPair(), this._localDevice ?? undefined);
|
|
3834
3898
|
await mesh.waitForWritable(this._accountWritableMs);
|
|
3835
3899
|
}
|
|
3900
|
+
const meshId = this._meshIdOf(mesh);
|
|
3901
|
+
if (deferred && !mesh.writable) {
|
|
3902
|
+
this._retryAdmission(memberMesh, meshId);
|
|
3903
|
+
return;
|
|
3904
|
+
}
|
|
3905
|
+
this._admissionRetries.delete(meshId);
|
|
3836
3906
|
if (mesh.writable) {
|
|
3837
3907
|
await this.local.markAwaitingAdmission(mesh.key, { awaitingAdmission: false });
|
|
3838
3908
|
}
|
|
3839
3909
|
}
|
|
3910
|
+
async _askSiblingsToAdmit(memberMesh, mesh, { ours, claim }) {
|
|
3911
|
+
let deferred = false;
|
|
3912
|
+
for (const sibling of await this._liveSiblings(memberMesh, ours)) {
|
|
3913
|
+
if (this.closing || mesh.writable)
|
|
3914
|
+
break;
|
|
3915
|
+
const admitted = await this._meshSeedHandoff
|
|
3916
|
+
.admit(sibling, mesh.key, claim)
|
|
3917
|
+
.catch((error) => {
|
|
3918
|
+
deferred ||= error.message === ADMISSION_DEFERRED;
|
|
3919
|
+
return false;
|
|
3920
|
+
});
|
|
3921
|
+
if (admitted) {
|
|
3922
|
+
await mesh.waitForWritable(this._accountWritableMs);
|
|
3923
|
+
}
|
|
3924
|
+
}
|
|
3925
|
+
return deferred && !mesh.writable;
|
|
3926
|
+
}
|
|
3927
|
+
_retryAdmission(memberMesh, meshId) {
|
|
3928
|
+
const tries = this._admissionRetries.get(meshId) ?? 0;
|
|
3929
|
+
if (tries >= ADMISSION_RETRIES) {
|
|
3930
|
+
return;
|
|
3931
|
+
}
|
|
3932
|
+
this._admissionRetries.set(meshId, tries + 1);
|
|
3933
|
+
const memberId = this._meshIdOf(memberMesh);
|
|
3934
|
+
if (this._admissionRetryPending.has(memberId)) {
|
|
3935
|
+
return;
|
|
3936
|
+
}
|
|
3937
|
+
this._admissionRetryPending.add(memberId);
|
|
3938
|
+
Promise.race([after(INVITER_RETRY_MS), this._closeSignal])
|
|
3939
|
+
.then(() => {
|
|
3940
|
+
this._admissionRetryPending.delete(memberId);
|
|
3941
|
+
const current = this.closing ? null : this._pooled(memberId);
|
|
3942
|
+
return current ? this._followJoinedMeshes(current) : undefined;
|
|
3943
|
+
})
|
|
3944
|
+
.catch(noop);
|
|
3945
|
+
}
|
|
3840
3946
|
async _liveSiblings(memberMesh, ours) {
|
|
3841
3947
|
const self = this._deviceKeyPair?.publicKey;
|
|
3842
3948
|
const siblings = [];
|
|
@@ -3927,7 +4033,7 @@ export class Core extends ReadyResource {
|
|
|
3927
4033
|
}
|
|
3928
4034
|
const mesh = this._pooled(b4a.toHex(request.meshKey));
|
|
3929
4035
|
const row = mesh ? await mesh.view.get(DEVICES, { id: asker }) : null;
|
|
3930
|
-
if (row
|
|
4036
|
+
if (mesh && row && (await this._removedFor(mesh, row))) {
|
|
3931
4037
|
this._log?.warn(['p2p', 'mesh'], 'seed request refused: removed from this mesh');
|
|
3932
4038
|
return null;
|
|
3933
4039
|
}
|
|
@@ -3955,8 +4061,9 @@ export class Core extends ReadyResource {
|
|
|
3955
4061
|
return null;
|
|
3956
4062
|
}
|
|
3957
4063
|
async _admitIntoMesh(request, asker) {
|
|
3958
|
-
if (this._meshTransitionLock.locked)
|
|
3959
|
-
|
|
4064
|
+
if (this._meshTransitionLock.locked) {
|
|
4065
|
+
throw new Error(ADMISSION_DEFERRED);
|
|
4066
|
+
}
|
|
3960
4067
|
await this._meshTransitionLock.lock();
|
|
3961
4068
|
try {
|
|
3962
4069
|
return await this._admitIntoMeshLocked(request, asker);
|
|
@@ -3966,8 +4073,11 @@ export class Core extends ReadyResource {
|
|
|
3966
4073
|
}
|
|
3967
4074
|
}
|
|
3968
4075
|
async _admitIntoMeshLocked(request, asker) {
|
|
3969
|
-
if (this._leaving
|
|
4076
|
+
if (this._leaving)
|
|
3970
4077
|
return null;
|
|
4078
|
+
if (this._minting) {
|
|
4079
|
+
throw new Error(ADMISSION_DEFERRED);
|
|
4080
|
+
}
|
|
3971
4081
|
const account = await this._accountMesh();
|
|
3972
4082
|
const ours = account?.ourMemberId;
|
|
3973
4083
|
const row = ours ? await account.view.get(DEVICES, { id: asker }) : null;
|
|
@@ -4003,7 +4113,7 @@ export class Core extends ReadyResource {
|
|
|
4003
4113
|
const mesh = await this._openPooledMesh(b4a.toHex(request.meshKey));
|
|
4004
4114
|
await mesh.autobee.update();
|
|
4005
4115
|
if (!mesh.writable) {
|
|
4006
|
-
|
|
4116
|
+
throw new Error(ADMISSION_DEFERRED);
|
|
4007
4117
|
}
|
|
4008
4118
|
if ((await mesh.bornKind()) !== 'shared') {
|
|
4009
4119
|
this._log?.warn(['p2p', 'mesh'], 'admission refused: a sibling joins this mesh by its seed');
|
|
@@ -4019,14 +4129,17 @@ export class Core extends ReadyResource {
|
|
|
4019
4129
|
return null;
|
|
4020
4130
|
}
|
|
4021
4131
|
const current = await mesh.view.get(DEVICES, { id: asker });
|
|
4022
|
-
if (current &&
|
|
4132
|
+
if (current && (await this._removedFor(mesh, current))) {
|
|
4023
4133
|
this._log?.warn(['p2p', 'mesh'], 'admission refused: removed from this mesh');
|
|
4024
4134
|
return null;
|
|
4025
4135
|
}
|
|
4026
4136
|
if (current && !current.revoked) {
|
|
4027
|
-
|
|
4028
|
-
|
|
4029
|
-
|
|
4137
|
+
if (current.writerKey && b4a.equals(current.writerKey, writerKey)) {
|
|
4138
|
+
return { admitted: true };
|
|
4139
|
+
}
|
|
4140
|
+
if (!(row.joinedAt > current.joinedAt)) {
|
|
4141
|
+
throw new Error(ADMISSION_DEFERRED);
|
|
4142
|
+
}
|
|
4030
4143
|
}
|
|
4031
4144
|
await mesh.dispatch('vouched-join', {
|
|
4032
4145
|
signature: mesh.sign(writerKey),
|
|
@@ -4058,6 +4171,16 @@ export class Core extends ReadyResource {
|
|
|
4058
4171
|
}
|
|
4059
4172
|
return false;
|
|
4060
4173
|
}
|
|
4174
|
+
async _removedFor(mesh, row) {
|
|
4175
|
+
if (!row.revoked)
|
|
4176
|
+
return false;
|
|
4177
|
+
const by = await removedBy(mesh.view, row);
|
|
4178
|
+
if (by !== 'own-member') {
|
|
4179
|
+
return by === 'another-member';
|
|
4180
|
+
}
|
|
4181
|
+
const paired = await this._accountMesh()?.view.get(DEVICES, { id: row.id });
|
|
4182
|
+
return !(paired && !paired.revoked && row.revokedAt && paired.joinedAt > row.revokedAt);
|
|
4183
|
+
}
|
|
4061
4184
|
async _askerStanding(deviceId) {
|
|
4062
4185
|
const account = this._accountMesh();
|
|
4063
4186
|
const ours = account?.ourMemberId;
|
|
@@ -4331,6 +4454,7 @@ export class Core extends ReadyResource {
|
|
|
4331
4454
|
open: (meshId) => this.openMesh(meshId),
|
|
4332
4455
|
close: (meshId) => this.closeMesh(meshId),
|
|
4333
4456
|
label: (meshId, label) => this.setMeshLabel(meshId, label),
|
|
4457
|
+
name: (meshId, name) => this.setMeshName(meshId, name),
|
|
4334
4458
|
createMesh: (opts) => this.createMesh(opts),
|
|
4335
4459
|
listArchived: () => this.listArchivedMeshes(),
|
|
4336
4460
|
archivedContents: (meshId) => this.archivedMeshContents(meshId),
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { errorMessage } from './guards.js';
|
|
2
|
+
import { snapshotEquals } from './api/watchable.js';
|
|
2
3
|
export function startCustomModelPusher(harness, state, opts = {}) {
|
|
3
4
|
const { logger, onPushed } = opts;
|
|
4
5
|
let disposed = false;
|
|
5
6
|
let tail = Promise.resolve();
|
|
6
7
|
let queued = false;
|
|
8
|
+
let pushed = null;
|
|
7
9
|
const push = async () => {
|
|
8
10
|
const rows = await state.getCustomModelRows();
|
|
9
|
-
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
await harness.setCustomModels?.(rows.map((row) => ({
|
|
11
|
+
const entries = rows.map((row) => ({
|
|
13
12
|
name: row.name,
|
|
14
13
|
src: row.src,
|
|
15
14
|
projectionSrc: row.mmprojSrc ?? undefined,
|
|
@@ -17,7 +16,12 @@ export function startCustomModelPusher(harness, state, opts = {}) {
|
|
|
17
16
|
expectedSize: row.expectedSize || undefined,
|
|
18
17
|
label: row.label || undefined,
|
|
19
18
|
contextLength: row.contextLength || undefined
|
|
20
|
-
}))
|
|
19
|
+
}));
|
|
20
|
+
if (disposed || snapshotEquals(entries, pushed)) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
await harness.setCustomModels?.(entries);
|
|
24
|
+
pushed = entries;
|
|
21
25
|
if (!disposed) {
|
|
22
26
|
onPushed?.();
|
|
23
27
|
}
|
|
@@ -12,10 +12,14 @@ export const MESH_SCOPED = new Set([
|
|
|
12
12
|
'getChat',
|
|
13
13
|
'renameChat',
|
|
14
14
|
'markChatRead',
|
|
15
|
+
'setChatAgent',
|
|
16
|
+
'moveChatToMesh',
|
|
17
|
+
'chatMoveWatch',
|
|
15
18
|
'setChatRagEnabled',
|
|
16
19
|
'setChatWebSearchEnabled',
|
|
17
20
|
'deleteChat',
|
|
18
21
|
'chatsWatch',
|
|
22
|
+
'setMeshName',
|
|
19
23
|
'listChatActivity',
|
|
20
24
|
'chatActivityWatch',
|
|
21
25
|
'searchChats',
|
|
@@ -32,6 +36,7 @@ export const MESH_SCOPED = new Set([
|
|
|
32
36
|
'resolveApproval',
|
|
33
37
|
'listChunks',
|
|
34
38
|
'chunksWatch',
|
|
39
|
+
'chunksDeltaWatch',
|
|
35
40
|
'listAttachmentsByKind',
|
|
36
41
|
'runRequestsWatch',
|
|
37
42
|
'uploadAttachment',
|
|
@@ -323,6 +323,43 @@ export function registerEngineTypes(ns) {
|
|
|
323
323
|
{ name: 'config', type: '@assistant/chat-config', required: true }
|
|
324
324
|
]
|
|
325
325
|
});
|
|
326
|
+
ns.register({
|
|
327
|
+
name: 'chat-move-state',
|
|
328
|
+
enum: ['carrying', 'leaving', 'complete', 'failed'],
|
|
329
|
+
strings: true
|
|
330
|
+
});
|
|
331
|
+
ns.register({
|
|
332
|
+
name: 'move-chat-to-mesh-request',
|
|
333
|
+
fields: [
|
|
334
|
+
{ name: 'chatId', type: 'string', required: true },
|
|
335
|
+
{ name: 'meshId', type: 'string', required: true },
|
|
336
|
+
{ name: 'targetMeshId', type: 'string', required: true },
|
|
337
|
+
{ name: 'agentId', type: 'string' }
|
|
338
|
+
]
|
|
339
|
+
});
|
|
340
|
+
ns.register({
|
|
341
|
+
name: 'chat-move',
|
|
342
|
+
fields: [
|
|
343
|
+
{ name: 'meshId', type: 'string', required: true },
|
|
344
|
+
{ name: 'chatId', type: 'string', required: true },
|
|
345
|
+
{ name: 'targetMeshId', type: 'string', required: true },
|
|
346
|
+
{ name: 'targetChatId', type: 'string', required: true },
|
|
347
|
+
{ name: 'state', type: '@assistant/chat-move-state', required: true },
|
|
348
|
+
{ name: 'files', type: 'uint', required: true },
|
|
349
|
+
{ name: 'carried', type: 'uint', required: true },
|
|
350
|
+
{ name: 'waiting', type: 'string', array: true },
|
|
351
|
+
{ name: 'restarted', type: 'bool', required: true },
|
|
352
|
+
{ name: 'failure', type: 'string' }
|
|
353
|
+
]
|
|
354
|
+
});
|
|
355
|
+
ns.register({
|
|
356
|
+
name: 'set-chat-agent-request',
|
|
357
|
+
fields: [
|
|
358
|
+
{ name: 'chatId', type: 'string', required: true },
|
|
359
|
+
{ name: 'agentId', type: 'string', required: true },
|
|
360
|
+
{ name: 'meshId', type: 'string', required: true }
|
|
361
|
+
]
|
|
362
|
+
});
|
|
326
363
|
ns.register({
|
|
327
364
|
name: 'set-chat-flag-request',
|
|
328
365
|
fields: [
|
|
@@ -1760,7 +1797,8 @@ export function registerEngineTypes(ns) {
|
|
|
1760
1797
|
{ name: 'sharedAt', type: 'uint' },
|
|
1761
1798
|
{ name: 'compute', type: 'bool' },
|
|
1762
1799
|
{ name: 'reason', type: 'string' },
|
|
1763
|
-
{ name: 'awaitingFrom', type: 'string' }
|
|
1800
|
+
{ name: 'awaitingFrom', type: 'string' },
|
|
1801
|
+
{ name: 'name', type: 'string' }
|
|
1764
1802
|
]
|
|
1765
1803
|
});
|
|
1766
1804
|
ns.register({
|
|
@@ -1770,6 +1808,13 @@ export function registerEngineTypes(ns) {
|
|
|
1770
1808
|
{ name: 'label', type: 'string' }
|
|
1771
1809
|
]
|
|
1772
1810
|
});
|
|
1811
|
+
ns.register({
|
|
1812
|
+
name: 'mesh-name-request',
|
|
1813
|
+
fields: [
|
|
1814
|
+
{ name: 'meshId', type: 'string', required: true },
|
|
1815
|
+
{ name: 'name', type: 'string' }
|
|
1816
|
+
]
|
|
1817
|
+
});
|
|
1773
1818
|
ns.register({
|
|
1774
1819
|
name: 'mesh-list',
|
|
1775
1820
|
fields: [{ name: 'meshes', type: '@assistant/mesh-entry', array: true }]
|
|
@@ -2020,6 +2065,15 @@ export function registerEngineTypes(ns) {
|
|
|
2020
2065
|
name: 'model-users',
|
|
2021
2066
|
fields: [{ name: 'agents', type: '@assistant/model-user', array: true }]
|
|
2022
2067
|
});
|
|
2068
|
+
ns.register({
|
|
2069
|
+
name: 'chunk-delta',
|
|
2070
|
+
fields: [
|
|
2071
|
+
{ name: 'reset', type: 'bool', required: true },
|
|
2072
|
+
{ name: 'chunks', type: '@assistant/chunk', array: true },
|
|
2073
|
+
{ name: 'removed', type: 'string', array: true },
|
|
2074
|
+
{ name: 'count', type: 'uint', required: true }
|
|
2075
|
+
]
|
|
2076
|
+
});
|
|
2023
2077
|
}
|
|
2024
2078
|
export function registerEngineApi(api) {
|
|
2025
2079
|
api.register({
|
|
@@ -2782,4 +2836,29 @@ export function registerEngineApi(api) {
|
|
|
2782
2836
|
request: { name: '@assistant/list-models-request', stream: false },
|
|
2783
2837
|
response: { name: '@assistant/model-info-list', stream: true }
|
|
2784
2838
|
});
|
|
2839
|
+
api.register({
|
|
2840
|
+
name: 'set-mesh-name',
|
|
2841
|
+
request: { name: '@assistant/mesh-name-request', stream: false },
|
|
2842
|
+
response: { name: '@assistant/ok-response', stream: false }
|
|
2843
|
+
});
|
|
2844
|
+
api.register({
|
|
2845
|
+
name: 'set-chat-agent',
|
|
2846
|
+
request: { name: '@assistant/set-chat-agent-request', stream: false },
|
|
2847
|
+
response: { name: '@assistant/chat', stream: false }
|
|
2848
|
+
});
|
|
2849
|
+
api.register({
|
|
2850
|
+
name: 'move-chat-to-mesh',
|
|
2851
|
+
request: { name: '@assistant/move-chat-to-mesh-request', stream: false },
|
|
2852
|
+
response: { name: '@assistant/chat-move', stream: false }
|
|
2853
|
+
});
|
|
2854
|
+
api.register({
|
|
2855
|
+
name: 'chat-move-watch',
|
|
2856
|
+
request: { name: '@assistant/chat-id', stream: false },
|
|
2857
|
+
response: { name: '@assistant/chat-move', stream: true }
|
|
2858
|
+
});
|
|
2859
|
+
api.register({
|
|
2860
|
+
name: 'chunks-delta-watch',
|
|
2861
|
+
request: { name: '@assistant/chunks-by-chat-request', stream: false },
|
|
2862
|
+
response: { name: '@assistant/chunk-delta', stream: true }
|
|
2863
|
+
});
|
|
2785
2864
|
}
|
package/dist-lib/schema/local.js
CHANGED
|
@@ -148,6 +148,18 @@ export function registerLocalTypes(ns) {
|
|
|
148
148
|
{ name: 'cleared', type: 'bool', required: true },
|
|
149
149
|
{ name: 'deletedAt', type: 'uint' }
|
|
150
150
|
]);
|
|
151
|
+
versioned('chat-move', [
|
|
152
|
+
{ name: 'meshKey', type: 'fixed32', required: true },
|
|
153
|
+
{ name: 'chatId', type: 'string', required: true },
|
|
154
|
+
{ name: 'targetMeshKey', type: 'fixed32', required: true },
|
|
155
|
+
{ name: 'targetChatId', type: 'string', required: true },
|
|
156
|
+
{ name: 'agentId', type: 'string', required: true },
|
|
157
|
+
{ name: 'carried', type: 'uint', required: true },
|
|
158
|
+
{ name: 'restartRunId', type: 'string' },
|
|
159
|
+
{ name: 'startedAt', type: 'uint', required: true },
|
|
160
|
+
{ name: 'completedAt', type: 'uint' },
|
|
161
|
+
{ name: 'failure', type: 'string' }
|
|
162
|
+
]);
|
|
151
163
|
ns.register({ name: 'capability-profile', enum: CAPABILITY_PROFILES, strings: true });
|
|
152
164
|
}
|
|
153
165
|
export function registerLocalCollections(dbns, helpersPath) {
|
|
@@ -250,4 +262,9 @@ export function registerLocalCollections(dbns, helpersPath) {
|
|
|
250
262
|
map: 'liveFilesMap'
|
|
251
263
|
}
|
|
252
264
|
});
|
|
265
|
+
dbns.collections.register({
|
|
266
|
+
name: 'chat-moves',
|
|
267
|
+
schema: '@local/chat-move',
|
|
268
|
+
key: ['meshKey', 'chatId']
|
|
269
|
+
});
|
|
253
270
|
}
|
|
@@ -23,6 +23,8 @@ export declare function capToolActivityArguments(args: unknown): unknown;
|
|
|
23
23
|
export declare const MAX_DEVICE_NAME_CHARS = 100;
|
|
24
24
|
export declare function deviceNameWithinBounds(name: string): boolean;
|
|
25
25
|
export declare function capDeviceName(name: string): string;
|
|
26
|
+
export declare const MAX_MESH_NAME_CHARS = 100;
|
|
27
|
+
export declare function meshNameWithinBounds(name: string): boolean;
|
|
26
28
|
export declare function registerQvacTypes(ns: Registry): void;
|
|
27
29
|
export declare function registerQvacCollections(dbns: CollectionRegistry, helpersPath: string): void;
|
|
28
30
|
export declare function registerQvacDispatch(ds: Registry): void;
|