@qvac/core 1.0.0-rc.6 → 1.0.0-rc.8
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 +8 -1
- package/dist-lib/lib/api/agents.js +5 -2
- package/dist-lib/lib/api/approval-rules.js +8 -5
- package/dist-lib/lib/api/chat.d.ts +1 -2
- package/dist-lib/lib/api/chat.js +4 -18
- package/dist-lib/lib/api/device-routes.d.ts +6 -1
- package/dist-lib/lib/api/device-routes.js +20 -1
- package/dist-lib/lib/api/index.d.ts +0 -1
- package/dist-lib/lib/api/index.js +1 -2
- package/dist-lib/lib/api/mesh.d.ts +1 -1
- package/dist-lib/lib/api/mesh.js +1 -1
- package/dist-lib/lib/api/rag.js +2 -5
- package/dist-lib/lib/api/sync.js +12 -2
- package/dist-lib/lib/assistant/model-round.d.ts +7 -1
- package/dist-lib/lib/assistant/model-round.js +33 -11
- package/dist-lib/lib/assistant-tree.js +7 -0
- package/dist-lib/lib/assistant.d.ts +3 -2
- package/dist-lib/lib/assistant.js +20 -19
- package/dist-lib/lib/core/archived-mesh.d.ts +1 -0
- package/dist-lib/lib/core/archived-mesh.js +11 -14
- package/dist-lib/lib/core/chat-copy.d.ts +0 -1
- package/dist-lib/lib/core/chat-copy.js +1 -2
- package/dist-lib/lib/core/chat-move.d.ts +3 -1
- package/dist-lib/lib/core/chat-move.js +5 -2
- package/dist-lib/lib/core/contract/joined-meshes.js +2 -1
- package/dist-lib/lib/core/local/index.d.ts +2 -1
- package/dist-lib/lib/core/local/index.js +3 -2
- package/dist-lib/lib/core/public-mesh.d.ts +6 -8
- package/dist-lib/lib/core/public-mesh.js +19 -29
- package/dist-lib/lib/core/sync/index.js +1 -1
- package/dist-lib/lib/core.d.ts +21 -8
- package/dist-lib/lib/core.js +233 -204
- package/dist-lib/lib/errors.d.ts +8 -12
- package/dist-lib/lib/errors.js +8 -12
- package/dist-lib/lib/model-download.d.ts +6 -1
- package/dist-lib/lib/model-download.js +16 -3
- package/dist-lib/lib/oauth/resolve.js +29 -8
- package/dist-lib/lib/oauth/token-exchange-core.js +11 -0
- package/dist-lib/schema/engine.js +10 -3
- package/dist-lib/schema/local.js +4 -2
- package/dist-lib/schema/qvac.js +2 -1
- package/dist-lib/spec/capabilities.d.ts +2 -2
- package/dist-lib/spec/hrpc/hrpc.json +1 -1
- package/dist-lib/spec/hrpc/index.js +1 -1
- package/dist-lib/spec/hrpc/messages.js +273 -250
- package/dist-lib/spec/hyperschema/index.js +273 -250
- package/dist-lib/spec/hyperschema/schema.json +27 -6
- package/dist-lib/spec/hyperschema/types.d.ts +7 -1
- package/dist-lib/spec/local/hyperdb/messages.js +26 -12
- package/dist-lib/spec/local/hyperschema/index.js +13 -6
- package/dist-lib/spec/local/hyperschema/schema.json +10 -0
- package/dist-lib/spec/local/hyperschema/types.d.ts +2 -0
- package/dist-lib/spec/mesh/hyperdb/messages.js +30 -6
- package/dist-lib/spec/mesh/hyperdispatch/messages.js +15 -3
- package/dist-lib/spec/mesh/hyperschema/index.js +15 -3
- package/dist-lib/spec/mesh/hyperschema/schema.json +5 -0
- package/dist-lib/spec/mesh/hyperschema/types.d.ts +1 -0
- package/package.json +10 -4
- package/tui/README.md +51 -0
- package/tui/app.mjs +88 -17
- package/tui/boot.mjs +23 -6
- package/tui/cli.mjs +93 -0
- package/tui/index.mjs +2 -87
- package/tui/lib/updater.mjs +86 -0
- package/tui/main.mjs +26 -15
- package/dist-lib/lib/core/chat-project.d.ts +0 -2
- package/dist-lib/lib/core/chat-project.js +0 -15
package/dist-lib/lib/core.js
CHANGED
|
@@ -36,7 +36,7 @@ import { cancelDeletedAgentRuns } from './core/deleted-agent-runs.js';
|
|
|
36
36
|
import { devicesOfMember } from './core/contract/activity.js';
|
|
37
37
|
import { followPickedAgents, followSharedAgents, ownerOf, liveSharedAgent, pickAgent, shareAgent, unpickAgent } from './core/shared-agents.js';
|
|
38
38
|
import { inRole, publicRoute } from './core/contract/roles.js';
|
|
39
|
-
import { freshPublicRecord,
|
|
39
|
+
import { freshPublicRecord, isPublicRecord, leftPublicRecordKey, derivedSeed, oldChats, ourRows, publicMeshKey, publicRecordKey, publicSeed, servesAgents, servesChat, servesChunk } from './core/public-mesh.js';
|
|
40
40
|
import { memberBoxKeyPair, openSealedToMember } from './core/member-key.js';
|
|
41
41
|
import { dueProjectDeviceKeys, dueProjectHostKey, dueProjectKey, seedFingerprint, seedOpens } from './core/project-keys.js';
|
|
42
42
|
import { projectDeviceKeys } from './core/contract/project-device-keys.js';
|
|
@@ -150,6 +150,7 @@ export class Core extends ReadyResource {
|
|
|
150
150
|
_modelCatalogWatch;
|
|
151
151
|
_modelCatalogWatchSource = new ReadyGuard();
|
|
152
152
|
_retryModelDownload;
|
|
153
|
+
_siblingDownloads;
|
|
153
154
|
_transcribe;
|
|
154
155
|
_detectLanguage;
|
|
155
156
|
_previewModelSource;
|
|
@@ -213,14 +214,16 @@ export class Core extends ReadyResource {
|
|
|
213
214
|
_publicBoots = new Map();
|
|
214
215
|
_meshNames = new Map();
|
|
215
216
|
_ownWorkspaceId = null;
|
|
217
|
+
_ownDecided = null;
|
|
216
218
|
_publicWriters = new WeakMap();
|
|
217
219
|
_leftPublic = new WeakSet();
|
|
218
220
|
_publicWaiters = new Set();
|
|
219
221
|
_publicFollow = new ScopeLock({ debounce: true });
|
|
220
222
|
_publicMerges = new Map();
|
|
221
|
-
|
|
222
|
-
_ownCarries = new Map();
|
|
223
|
+
_publicDrops = new Map();
|
|
223
224
|
_publicMigration = null;
|
|
225
|
+
_copyAgain = false;
|
|
226
|
+
_accountCopied = null;
|
|
224
227
|
_agentCopies = new ScopeLock({ debounce: true });
|
|
225
228
|
_sharedAgents = new ScopeLock({ debounce: true });
|
|
226
229
|
_memberKeyWrites = new WeakMap();
|
|
@@ -240,6 +243,7 @@ export class Core extends ReadyResource {
|
|
|
240
243
|
_backfill = Promise.resolve();
|
|
241
244
|
_leaving;
|
|
242
245
|
_kickedMeshes = new Set();
|
|
246
|
+
_haltedMeshes = new Set();
|
|
243
247
|
_kickCloses = new Map();
|
|
244
248
|
_retiredMeshes = new Set();
|
|
245
249
|
_retiredAccount = null;
|
|
@@ -312,6 +316,7 @@ export class Core extends ReadyResource {
|
|
|
312
316
|
this._openModelCatalogWatchSource();
|
|
313
317
|
void this._modelCatalogWatchSource.ready().catch(noop);
|
|
314
318
|
this._retryModelDownload = retryModelDownload ?? null;
|
|
319
|
+
this._siblingDownloads = null;
|
|
315
320
|
this._transcribe = transcribe ?? null;
|
|
316
321
|
this._detectLanguage = detectLanguage ?? null;
|
|
317
322
|
this._previewModelSource = previewModelSource ?? null;
|
|
@@ -472,7 +477,8 @@ export class Core extends ReadyResource {
|
|
|
472
477
|
deviceId,
|
|
473
478
|
log: this._log,
|
|
474
479
|
account: () => this._accountMesh(),
|
|
475
|
-
agents: this._agentPicks()
|
|
480
|
+
agents: this._agentPicks(),
|
|
481
|
+
meshIdOf: (key) => this._workspaceOfPublic(b4a.toHex(key))
|
|
476
482
|
})
|
|
477
483
|
: null;
|
|
478
484
|
const api = createApi({
|
|
@@ -522,11 +528,6 @@ export class Core extends ReadyResource {
|
|
|
522
528
|
const id = b4a.toHex(projectKey);
|
|
523
529
|
return this._pooled(id)?.name ?? this._meshNames.get(id) ?? null;
|
|
524
530
|
},
|
|
525
|
-
workspaceOf: async (projectId) => {
|
|
526
|
-
const key = (await this.local.readMeshSession(this._meshKeyOf(projectId)))?.workspaceKey;
|
|
527
|
-
const workspaceId = key ? b4a.toHex(key) : null;
|
|
528
|
-
return workspaceId === this._ownWorkspaceId ? null : workspaceId;
|
|
529
|
-
},
|
|
530
531
|
pushSkillSecret: (request) => this.pushSkillSecret(request),
|
|
531
532
|
beforeConfigSet: (entry) => validateVaultManagedSkill(this._vaultManagedSkills, entry),
|
|
532
533
|
onConfigSet: async (entry) => {
|
|
@@ -660,7 +661,10 @@ export class Core extends ReadyResource {
|
|
|
660
661
|
: null
|
|
661
662
|
});
|
|
662
663
|
api.skillOauth = (request) => this._skillOauth(request);
|
|
663
|
-
this._servedToSiblings = servedToSiblings(api
|
|
664
|
+
this._servedToSiblings = servedToSiblings(api, {
|
|
665
|
+
asked: (name) => this._siblingDownloads?.asked(name),
|
|
666
|
+
resumed: (name) => this._siblingDownloads?.resumed(name)
|
|
667
|
+
});
|
|
664
668
|
this._api = {
|
|
665
669
|
...api,
|
|
666
670
|
...forwardToDevices(api, {
|
|
@@ -1239,7 +1243,7 @@ export class Core extends ReadyResource {
|
|
|
1239
1243
|
const session = await this.local.resolveSession(this._requireDeviceKeyPair().publicKey, opts);
|
|
1240
1244
|
return this._openMeshSession(session, opts);
|
|
1241
1245
|
}
|
|
1242
|
-
async _openMeshSession(session, { blindPeerKeys, account, sharing, workspace, project } = {}) {
|
|
1246
|
+
async _openMeshSession(session, { blindPeerKeys, account, initial, sharing, workspace, project } = {}) {
|
|
1243
1247
|
const deviceId = this._requireDeviceKeyPair().publicKey;
|
|
1244
1248
|
const mesh = this._newMesh(session, session.role ?? (account ? 'account' : 'project'), blindPeerKeys);
|
|
1245
1249
|
try {
|
|
@@ -1258,6 +1262,7 @@ export class Core extends ReadyResource {
|
|
|
1258
1262
|
await this._appendOwnBirth(mesh, session, {
|
|
1259
1263
|
deviceId,
|
|
1260
1264
|
account,
|
|
1265
|
+
initial,
|
|
1261
1266
|
sharing,
|
|
1262
1267
|
workspace,
|
|
1263
1268
|
project
|
|
@@ -1265,8 +1270,8 @@ export class Core extends ReadyResource {
|
|
|
1265
1270
|
}
|
|
1266
1271
|
}
|
|
1267
1272
|
catch (err) {
|
|
1268
|
-
if (mesh.opened && mesh.interrupted
|
|
1269
|
-
this.
|
|
1273
|
+
if (mesh.opened && mesh.interrupted) {
|
|
1274
|
+
this._markHalted(mesh);
|
|
1270
1275
|
}
|
|
1271
1276
|
await mesh.close().catch(noop);
|
|
1272
1277
|
throw err;
|
|
@@ -1292,7 +1297,7 @@ export class Core extends ReadyResource {
|
|
|
1292
1297
|
});
|
|
1293
1298
|
return mesh;
|
|
1294
1299
|
}
|
|
1295
|
-
async _appendOwnBirth(mesh, session, { deviceId, account, sharing, workspace, project }) {
|
|
1300
|
+
async _appendOwnBirth(mesh, session, { deviceId, account, initial, sharing, workspace, project }) {
|
|
1296
1301
|
await raceResource(mesh.autobee, (async () => {
|
|
1297
1302
|
const birth = sharing
|
|
1298
1303
|
? await this._accountBirthMember(mesh, session)
|
|
@@ -1304,7 +1309,7 @@ export class Core extends ReadyResource {
|
|
|
1304
1309
|
workspace,
|
|
1305
1310
|
project
|
|
1306
1311
|
});
|
|
1307
|
-
await this.local.recordMesh(mesh.key, session, { deviceId, account });
|
|
1312
|
+
await this.local.recordMesh(mesh.key, session, { deviceId, account, initial });
|
|
1308
1313
|
if (account && birth?.mnemonic) {
|
|
1309
1314
|
await this._publishRecovery(birth.mnemonic, {
|
|
1310
1315
|
meshKey: mesh.key,
|
|
@@ -1325,8 +1330,8 @@ export class Core extends ReadyResource {
|
|
|
1325
1330
|
return appended.catch((err) => {
|
|
1326
1331
|
if (this.closing || mesh.closing)
|
|
1327
1332
|
return;
|
|
1328
|
-
if (mesh.interrupted
|
|
1329
|
-
this.
|
|
1333
|
+
if (mesh.interrupted) {
|
|
1334
|
+
this._markHalted(mesh);
|
|
1330
1335
|
}
|
|
1331
1336
|
this._log?.warn(['p2p', 'mesh'], 'appending the join failed', err);
|
|
1332
1337
|
});
|
|
@@ -1715,9 +1720,9 @@ export class Core extends ReadyResource {
|
|
|
1715
1720
|
throw new CoreError('AGENT_NOT_OURS');
|
|
1716
1721
|
}
|
|
1717
1722
|
if (request.operation === 'target') {
|
|
1718
|
-
const mesh =
|
|
1719
|
-
route: 'put-chat'
|
|
1720
|
-
|
|
1723
|
+
const mesh = request.meshId
|
|
1724
|
+
? await requireMesh(this._meshPool(), request.meshId, { route: 'put-chat' })
|
|
1725
|
+
: account;
|
|
1721
1726
|
const runner = await pickRunner(mesh, {
|
|
1722
1727
|
deviceId,
|
|
1723
1728
|
peers: this.peerDeviceIds,
|
|
@@ -2131,6 +2136,7 @@ export class Core extends ReadyResource {
|
|
|
2131
2136
|
await this.local.dropMesh(key, { keepDeparture: true, cores });
|
|
2132
2137
|
this._meshNames.delete(b4a.toHex(key));
|
|
2133
2138
|
this._kickedMeshes.delete(b4a.toHex(key));
|
|
2139
|
+
this._haltedMeshes.delete(b4a.toHex(key));
|
|
2134
2140
|
this._notifyStatus();
|
|
2135
2141
|
}
|
|
2136
2142
|
if (cores) {
|
|
@@ -2160,14 +2166,22 @@ export class Core extends ReadyResource {
|
|
|
2160
2166
|
_withdrawFromMesh(mesh, err) {
|
|
2161
2167
|
if (this.closing)
|
|
2162
2168
|
return;
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
this._setUpgradeRequired('halt');
|
|
2166
|
-
}
|
|
2169
|
+
this._log?.error(['p2p', 'mesh'], 'mesh needs a newer build - withdrawing from it', err);
|
|
2170
|
+
this._markHalted(mesh);
|
|
2167
2171
|
this._retirePooledMesh(mesh).catch((retireErr) => {
|
|
2168
2172
|
this._log?.warn(['p2p', 'mesh'], 'retiring the stalled mesh failed', retireErr);
|
|
2169
2173
|
});
|
|
2170
2174
|
}
|
|
2175
|
+
_markHalted(mesh) {
|
|
2176
|
+
if (mesh.role === 'account' || this._isOwnPublic(mesh)) {
|
|
2177
|
+
if (!this._upgradeRequired) {
|
|
2178
|
+
this._setUpgradeRequired('halt');
|
|
2179
|
+
}
|
|
2180
|
+
return;
|
|
2181
|
+
}
|
|
2182
|
+
this._haltedMeshes.add(this._meshIdOf(mesh));
|
|
2183
|
+
this._notifyStatus();
|
|
2184
|
+
}
|
|
2171
2185
|
async _reviewKick(mesh) {
|
|
2172
2186
|
const entry = this._meshes.get(this._meshIdOf(mesh));
|
|
2173
2187
|
if (entry?.mesh !== mesh || !(await entry.kickLock.lock())) {
|
|
@@ -2354,12 +2368,12 @@ export class Core extends ReadyResource {
|
|
|
2354
2368
|
}
|
|
2355
2369
|
}
|
|
2356
2370
|
async _dropOwnMint(fresh) {
|
|
2357
|
-
const
|
|
2358
|
-
for (const
|
|
2359
|
-
|
|
2371
|
+
const minted = new Set((await this.local.listMeshes()).filter((row) => row.initial).map((row) => b4a.toHex(row.key)));
|
|
2372
|
+
for (const joined of await fresh.view.find(JOINED_MESHES).toArray()) {
|
|
2373
|
+
const id = b4a.toHex(joined.meshKey);
|
|
2374
|
+
if (!minted.has(id)) {
|
|
2360
2375
|
continue;
|
|
2361
2376
|
}
|
|
2362
|
-
const id = b4a.toHex(row.key);
|
|
2363
2377
|
const own = this._publicMesh(id);
|
|
2364
2378
|
if (own) {
|
|
2365
2379
|
await this._teardownMesh(own, { purge: true });
|
|
@@ -2507,7 +2521,9 @@ export class Core extends ReadyResource {
|
|
|
2507
2521
|
if (!invite) {
|
|
2508
2522
|
throw new CoreError('INVITE_INVALID');
|
|
2509
2523
|
}
|
|
2510
|
-
|
|
2524
|
+
if (!this.opened) {
|
|
2525
|
+
await this.ready();
|
|
2526
|
+
}
|
|
2511
2527
|
this._requireLocalDevice();
|
|
2512
2528
|
await this._meshTransitionLock.lock();
|
|
2513
2529
|
let ownsTransition = false;
|
|
@@ -3395,10 +3411,6 @@ export class Core extends ReadyResource {
|
|
|
3395
3411
|
void this._followPublicMesh(mesh);
|
|
3396
3412
|
void this._followSkillSecrets();
|
|
3397
3413
|
}
|
|
3398
|
-
const account = this._accountMesh();
|
|
3399
|
-
if (account && this._meshIdOf(mesh) === this._ownWorkspaceId) {
|
|
3400
|
-
void this._followPublicMesh(account);
|
|
3401
|
-
}
|
|
3402
3414
|
if (this._isOwnPublic(mesh)) {
|
|
3403
3415
|
void this._followAgentCopies();
|
|
3404
3416
|
}
|
|
@@ -3482,7 +3494,7 @@ export class Core extends ReadyResource {
|
|
|
3482
3494
|
return;
|
|
3483
3495
|
void this._followAccountName(mesh);
|
|
3484
3496
|
});
|
|
3485
|
-
mesh.on('meshes-dirty', (changed, groupsChanged = false) => this._onMeshesDirty(entry, { changed, groupsChanged }));
|
|
3497
|
+
mesh.on('meshes-dirty', (changed, groupsChanged = false, chatsChanged = true) => this._onMeshesDirty(entry, { changed, groupsChanged, chatsChanged }));
|
|
3486
3498
|
mesh.on('joined', () => {
|
|
3487
3499
|
if (entry.meshesPending) {
|
|
3488
3500
|
void this._followJoinedMeshes(mesh);
|
|
@@ -3511,10 +3523,10 @@ export class Core extends ReadyResource {
|
|
|
3511
3523
|
this._listenMesh(mesh, handlers);
|
|
3512
3524
|
this._startMeshServices(entry);
|
|
3513
3525
|
this._startEntryIndexing(entry);
|
|
3514
|
-
this._onMeshesDirty(entry, { changed: true, groupsChanged: true });
|
|
3526
|
+
this._onMeshesDirty(entry, { changed: true, groupsChanged: true, chatsChanged: true });
|
|
3515
3527
|
this._reviewKick(mesh).catch((err) => this._log?.warn(['p2p', 'mesh'], 'reviewing a kick failed', err));
|
|
3516
3528
|
}
|
|
3517
|
-
_onMeshesDirty(entry, { changed, groupsChanged }) {
|
|
3529
|
+
_onMeshesDirty(entry, { changed, groupsChanged, chatsChanged }) {
|
|
3518
3530
|
const { mesh } = entry;
|
|
3519
3531
|
if (this._isHidden(this._meshIdOf(mesh), mesh.workspaceKey)) {
|
|
3520
3532
|
return;
|
|
@@ -3532,9 +3544,14 @@ export class Core extends ReadyResource {
|
|
|
3532
3544
|
if ((changed || groupsChanged) && mesh.role === 'workspace') {
|
|
3533
3545
|
this._followGroups(mesh);
|
|
3534
3546
|
}
|
|
3535
|
-
|
|
3547
|
+
const opening = this._ownWorkspaceId !== null && !this._publicMesh();
|
|
3548
|
+
if (this._isAccount(mesh) && (changed || entry.publicPending || opening)) {
|
|
3536
3549
|
void this._followPublicMesh(mesh);
|
|
3537
3550
|
}
|
|
3551
|
+
const copying = chatsChanged || this._accountCopied === null;
|
|
3552
|
+
if (copying && this._isAccount(mesh) && this._ownWorkspaceId && this._publicMesh()) {
|
|
3553
|
+
this._migrateIntoPublic(mesh, b4a.from(this._ownWorkspaceId, 'hex'));
|
|
3554
|
+
}
|
|
3538
3555
|
}
|
|
3539
3556
|
_listenMesh(mesh, handlers) {
|
|
3540
3557
|
mesh.autobee.on('writable', handlers.writable);
|
|
@@ -3590,18 +3607,16 @@ export class Core extends ReadyResource {
|
|
|
3590
3607
|
this._log?.warn(['mesh'], 'backfilling the model pick failed', err);
|
|
3591
3608
|
}
|
|
3592
3609
|
}
|
|
3593
|
-
_publicMesh(workspaceId = this.
|
|
3610
|
+
_publicMesh(workspaceId = this._ownWorkspaceId) {
|
|
3594
3611
|
return this._pooled(this._publicIdOf(workspaceId));
|
|
3595
3612
|
}
|
|
3596
|
-
_publicIdOf(
|
|
3597
|
-
const workspaceId = meshId !== null && meshId === this._accountId ? this._ownWorkspaceId : meshId;
|
|
3613
|
+
_publicIdOf(workspaceId) {
|
|
3598
3614
|
return workspaceId === null ? null : (this._publicIds.get(workspaceId) ?? null);
|
|
3599
3615
|
}
|
|
3600
3616
|
_workspaceOfPublic(meshId) {
|
|
3601
3617
|
for (const [workspaceId, publicId] of this._publicIds) {
|
|
3602
|
-
if (publicId
|
|
3603
|
-
|
|
3604
|
-
return workspaceId === this._ownWorkspaceId ? (this._accountId ?? workspaceId) : workspaceId;
|
|
3618
|
+
if (publicId === meshId)
|
|
3619
|
+
return workspaceId;
|
|
3605
3620
|
}
|
|
3606
3621
|
return meshId;
|
|
3607
3622
|
}
|
|
@@ -3669,14 +3684,11 @@ export class Core extends ReadyResource {
|
|
|
3669
3684
|
}
|
|
3670
3685
|
await workspace.dispatch('put-member-key', { memberId, boxKey });
|
|
3671
3686
|
}
|
|
3672
|
-
_contentMesh() {
|
|
3673
|
-
return this._publicMesh() ?? this._accountMesh();
|
|
3674
|
-
}
|
|
3675
3687
|
_devicesOf(mesh) {
|
|
3676
3688
|
return this._isOwnPublic(mesh) ? (this._accountMesh() ?? mesh) : mesh;
|
|
3677
3689
|
}
|
|
3678
3690
|
_hasPublic(mesh) {
|
|
3679
|
-
return
|
|
3691
|
+
return mesh.role === 'workspace' && this._isPooled(mesh);
|
|
3680
3692
|
}
|
|
3681
3693
|
async _publicOf(scope, { follow = false } = {}) {
|
|
3682
3694
|
const workspaceId = this._meshIdOf(scope);
|
|
@@ -3782,34 +3794,72 @@ export class Core extends ReadyResource {
|
|
|
3782
3794
|
return settled;
|
|
3783
3795
|
}
|
|
3784
3796
|
async _settleOwnWorkspace(account) {
|
|
3785
|
-
|
|
3786
|
-
|
|
3787
|
-
|
|
3788
|
-
|
|
3789
|
-
|
|
3790
|
-
|
|
3791
|
-
const
|
|
3797
|
+
if (this._localDevice && !account.ourMemberId) {
|
|
3798
|
+
return;
|
|
3799
|
+
}
|
|
3800
|
+
const local = (await this.local.listMeshes()).filter((row) => !b4a.equals(row.key, account.key) &&
|
|
3801
|
+
!row.workspaceKey &&
|
|
3802
|
+
!this._isHidden(b4a.toHex(row.key)));
|
|
3803
|
+
const rows = await ourRows(account);
|
|
3804
|
+
const ours = local.filter((row) => !row.joinedAt || rows.some((joined) => b4a.equals(joined.meshKey, row.key)));
|
|
3805
|
+
const own = ours
|
|
3806
|
+
.filter((row) => row.initial && !row.kicked)
|
|
3807
|
+
.sort((a, b) => (b.joinedAt || Infinity) - (a.joinedAt || Infinity))[0];
|
|
3808
|
+
const mints = !own &&
|
|
3809
|
+
!(await this._markDerivedInitial(account, rows)) &&
|
|
3810
|
+
(await this._mintsOwnWorkspace(account, { rows, local: ours }));
|
|
3792
3811
|
if (!this._isAccount(account)) {
|
|
3793
3812
|
return;
|
|
3794
3813
|
}
|
|
3795
|
-
|
|
3796
|
-
|
|
3797
|
-
|
|
3814
|
+
this._setOwnWorkspace(own ? b4a.toHex(own.key) : null);
|
|
3815
|
+
if (mints) {
|
|
3816
|
+
await this._mintOwnWorkspace(account);
|
|
3817
|
+
}
|
|
3818
|
+
if (account.writable && this._ownDecided !== account) {
|
|
3819
|
+
this._ownDecided = account;
|
|
3820
|
+
this._notifyStatus();
|
|
3798
3821
|
}
|
|
3799
|
-
await this._mintOwnWorkspace(account);
|
|
3800
3822
|
}
|
|
3801
|
-
async
|
|
3802
|
-
|
|
3803
|
-
|
|
3804
|
-
|
|
3805
|
-
|
|
3806
|
-
|
|
3823
|
+
async _mintsOwnWorkspace(account, { rows, local }) {
|
|
3824
|
+
if (!rows.length && !local.length) {
|
|
3825
|
+
return account.minted || !(await bornUnderRules(account.view));
|
|
3826
|
+
}
|
|
3827
|
+
return !rows.some((row) => row.initial) && !!(await oldChats(account))?.messages;
|
|
3828
|
+
}
|
|
3829
|
+
async _markDerivedInitial(account, rows) {
|
|
3830
|
+
if (rows.some((row) => row.initial)) {
|
|
3831
|
+
return false;
|
|
3832
|
+
}
|
|
3833
|
+
const derived = derivedSeed(account);
|
|
3834
|
+
for (const { meshKey, memberId, joinedAt } of rows) {
|
|
3835
|
+
const held = await account.view.get(MESH_SEEDS, { meshKey });
|
|
3836
|
+
if (held && b4a.equals(held.seed, derived)) {
|
|
3837
|
+
if (account.writable) {
|
|
3838
|
+
await account.dispatch('put-joined-mesh', {
|
|
3839
|
+
room: { meshKey, memberId, joinedAt, initial: true }
|
|
3840
|
+
});
|
|
3841
|
+
}
|
|
3842
|
+
return true;
|
|
3843
|
+
}
|
|
3807
3844
|
}
|
|
3845
|
+
return false;
|
|
3846
|
+
}
|
|
3847
|
+
async _mintOwnWorkspace(account) {
|
|
3808
3848
|
if (!account.writable || !account.ourMemberId) {
|
|
3809
3849
|
return;
|
|
3810
3850
|
}
|
|
3811
3851
|
const workspace = { name: await this._defaultWorkspaceName(account) };
|
|
3812
|
-
|
|
3852
|
+
const minted = await this._mintMesh({
|
|
3853
|
+
shared: false,
|
|
3854
|
+
workspace,
|
|
3855
|
+
registry: account,
|
|
3856
|
+
initial: true
|
|
3857
|
+
});
|
|
3858
|
+
if (!this._isAccount(account)) {
|
|
3859
|
+
await this._teardownMesh(this._pooled(minted) ?? b4a.from(minted, 'hex'));
|
|
3860
|
+
return;
|
|
3861
|
+
}
|
|
3862
|
+
this._setOwnWorkspace(minted);
|
|
3813
3863
|
}
|
|
3814
3864
|
_setOwnWorkspace(workspaceId) {
|
|
3815
3865
|
if (this._ownWorkspaceId !== workspaceId) {
|
|
@@ -3828,13 +3878,13 @@ export class Core extends ReadyResource {
|
|
|
3828
3878
|
}
|
|
3829
3879
|
const held = this._pooled(publicId);
|
|
3830
3880
|
this._publicIds.delete(workspaceId);
|
|
3831
|
-
const
|
|
3832
|
-
if (held && !
|
|
3881
|
+
const recorded = held?.workspaceKey && (await this._publicRecord(account, held.workspaceKey))?.key;
|
|
3882
|
+
if (held && !recorded) {
|
|
3833
3883
|
await this._teardownMesh(held);
|
|
3834
3884
|
}
|
|
3835
3885
|
}
|
|
3836
3886
|
for (const workspaceKey of await this._leftWorkspaces(account)) {
|
|
3837
|
-
this.
|
|
3887
|
+
this._dropLeftPublic(account, workspaceKey);
|
|
3838
3888
|
}
|
|
3839
3889
|
}
|
|
3840
3890
|
async _leftWorkspaces(account) {
|
|
@@ -3848,120 +3898,31 @@ export class Core extends ReadyResource {
|
|
|
3848
3898
|
}
|
|
3849
3899
|
return keys;
|
|
3850
3900
|
}
|
|
3851
|
-
|
|
3852
|
-
const lostId = b4a.toHex(joined.meshKey);
|
|
3853
|
-
if (this._ownCarries.has(lostId)) {
|
|
3854
|
-
return;
|
|
3855
|
-
}
|
|
3856
|
-
const carry = (async () => {
|
|
3857
|
-
const lost = await this._heldMesh(joined.meshKey);
|
|
3858
|
-
const own = lost && (await this._heldMesh(ownKey));
|
|
3859
|
-
if (!lost || !own) {
|
|
3860
|
-
return;
|
|
3861
|
-
}
|
|
3862
|
-
await own.waitForWritable();
|
|
3863
|
-
if (!this._isAccount(account) || !this._isPooled(own) || !this._isPooled(lost)) {
|
|
3864
|
-
return;
|
|
3865
|
-
}
|
|
3866
|
-
await lost.autobee.update();
|
|
3867
|
-
await this._carryProjects(account, { lost, own }, joined.memberId);
|
|
3868
|
-
if (!joined.leftAt) {
|
|
3869
|
-
await this._releaseJoinedMesh(joined.meshKey, account);
|
|
3870
|
-
}
|
|
3871
|
-
this._log?.info(['p2p', 'mesh'], 'carried a lost mint of your own workspace into the winner', {
|
|
3872
|
-
lost: lostId.slice(0, 8),
|
|
3873
|
-
winner: this._meshIdOf(own).slice(0, 8)
|
|
3874
|
-
});
|
|
3875
|
-
await this._teardownMesh(lost);
|
|
3876
|
-
})()
|
|
3877
|
-
.catch((err) => {
|
|
3878
|
-
if (!this.closing) {
|
|
3879
|
-
this._log?.warn(['p2p', 'mesh'], 'carrying a lost mint of your own workspace failed', err);
|
|
3880
|
-
}
|
|
3881
|
-
})
|
|
3882
|
-
.finally(() => {
|
|
3883
|
-
this._ownCarries.delete(lostId);
|
|
3884
|
-
});
|
|
3885
|
-
this._ownCarries.set(lostId, carry);
|
|
3886
|
-
}
|
|
3887
|
-
async _carryProjects(account, mints, ours) {
|
|
3888
|
-
const { lost, own } = mints;
|
|
3889
|
-
const deviceId = this._requireDeviceKeyPair().publicKey;
|
|
3890
|
-
const rows = await lost.view.find(PROJECTS).toArray();
|
|
3891
|
-
for (const row of rows.filter((listed) => listedProject(listed, ours))) {
|
|
3892
|
-
const session = await this.local.readMeshSession(row.id);
|
|
3893
|
-
const seed = session?.seed ?? (await this._ownProjectSeed(lost, row.id));
|
|
3894
|
-
if (!seed) {
|
|
3895
|
-
continue;
|
|
3896
|
-
}
|
|
3897
|
-
const { createdAt, updatedAt } = row;
|
|
3898
|
-
await this._listProject(own, { key: row.id, seed }, { createdAt, updatedAt });
|
|
3899
|
-
if (session && (await this._isProjectOf(lost.key, row.id))) {
|
|
3900
|
-
await this.local.recordMesh(row.id, { ...session, workspaceKey: own.key }, { deviceId });
|
|
3901
|
-
}
|
|
3902
|
-
await this._carryAgentUsers(account, mints, row.id);
|
|
3903
|
-
}
|
|
3904
|
-
}
|
|
3905
|
-
async _carryAgentUsers(account, { lost, own }, projectId) {
|
|
3906
|
-
const batch = own.batch();
|
|
3907
|
-
for (const { agentId, userId } of await lost.view.find(AGENT_USERS).toArray()) {
|
|
3908
|
-
if (!b4a.equals(userId, projectId) || !(await liveSharedAgent(lost, agentId))) {
|
|
3909
|
-
continue;
|
|
3910
|
-
}
|
|
3911
|
-
try {
|
|
3912
|
-
await shareAgent(account, own, agentId);
|
|
3913
|
-
}
|
|
3914
|
-
catch (err) {
|
|
3915
|
-
if (!(err instanceof CoreError)) {
|
|
3916
|
-
throw err;
|
|
3917
|
-
}
|
|
3918
|
-
this._log?.warn(['p2p', 'mesh'], 'a lost mint kept a shared agent the winner refuses', {
|
|
3919
|
-
agentId,
|
|
3920
|
-
code: err.code
|
|
3921
|
-
});
|
|
3922
|
-
continue;
|
|
3923
|
-
}
|
|
3924
|
-
if (!(await own.view.get(AGENT_USERS, { agentId, userId }))) {
|
|
3925
|
-
batch.dispatch('put-agent-user', { agentId, projectId });
|
|
3926
|
-
}
|
|
3927
|
-
}
|
|
3928
|
-
await batch.flush();
|
|
3929
|
-
}
|
|
3930
|
-
_carryLeftPublic(account, workspaceKey) {
|
|
3901
|
+
_dropLeftPublic(account, workspaceKey) {
|
|
3931
3902
|
const workspaceId = b4a.toHex(workspaceKey);
|
|
3932
|
-
if (this.
|
|
3903
|
+
if (this._publicDrops.has(workspaceId)) {
|
|
3933
3904
|
return;
|
|
3934
3905
|
}
|
|
3935
|
-
const
|
|
3906
|
+
const drop = (async () => {
|
|
3936
3907
|
const record = await this._publicRecord(account, workspaceKey);
|
|
3937
|
-
|
|
3938
|
-
if (!record?.key || !into || into === account) {
|
|
3908
|
+
if (!record?.key || !this._isAccount(account)) {
|
|
3939
3909
|
return;
|
|
3940
3910
|
}
|
|
3941
|
-
const from = this._pooled(record.key) ?? (await this._openPublicMesh(account, { workspaceKey, record }));
|
|
3942
|
-
await into.waitForWritable();
|
|
3943
|
-
if (!this._isAccount(account) || !this._isPooled(into) || !this._isPooled(from)) {
|
|
3944
|
-
return;
|
|
3945
|
-
}
|
|
3946
|
-
const deviceId = this._requireDeviceKeyPair().publicKey;
|
|
3947
|
-
const unlinkProjects = !(await onOwnSeed(account, workspaceKey));
|
|
3948
|
-
await copyContent({ from, into, deviceId, unlinkProjects });
|
|
3949
3911
|
await this.local.deleteAll([publicRecordKey(account.key, workspaceKey)]);
|
|
3950
|
-
this._log?.info(['p2p', 'mesh'], "
|
|
3951
|
-
workspace: workspaceId.slice(0, 8)
|
|
3952
|
-
into: this._meshIdOf(into).slice(0, 8)
|
|
3912
|
+
this._log?.info(['p2p', 'mesh'], "dropped a left workspace's private chats", {
|
|
3913
|
+
workspace: workspaceId.slice(0, 8)
|
|
3953
3914
|
});
|
|
3954
|
-
await this._teardownMesh(from);
|
|
3915
|
+
await this._teardownMesh(this._pooled(record.key) ?? b4a.from(record.key, 'hex'));
|
|
3955
3916
|
})()
|
|
3956
3917
|
.catch((err) => {
|
|
3957
3918
|
if (!this.closing) {
|
|
3958
|
-
this._log?.warn(['p2p', 'mesh'], "
|
|
3919
|
+
this._log?.warn(['p2p', 'mesh'], "dropping a left workspace's chats failed", err);
|
|
3959
3920
|
}
|
|
3960
3921
|
})
|
|
3961
3922
|
.finally(() => {
|
|
3962
|
-
this.
|
|
3923
|
+
this._publicDrops.delete(workspaceId);
|
|
3963
3924
|
});
|
|
3964
|
-
this.
|
|
3925
|
+
this._publicDrops.set(workspaceId, drop);
|
|
3965
3926
|
}
|
|
3966
3927
|
async _settlePublicMesh(account, workspaceKey) {
|
|
3967
3928
|
const workspaceId = b4a.toHex(workspaceKey);
|
|
@@ -4110,12 +4071,24 @@ export class Core extends ReadyResource {
|
|
|
4110
4071
|
this._publicMerges.set(workspaceId, merge);
|
|
4111
4072
|
}
|
|
4112
4073
|
_migrateIntoPublic(account, workspaceKey) {
|
|
4113
|
-
if (this._publicMigration)
|
|
4074
|
+
if (this._publicMigration) {
|
|
4075
|
+
this._copyAgain = true;
|
|
4114
4076
|
return;
|
|
4077
|
+
}
|
|
4115
4078
|
this._publicMigration = (async () => {
|
|
4116
|
-
const record = await this._publicRecord(account, workspaceKey);
|
|
4117
4079
|
const into = this._publicMesh(b4a.toHex(workspaceKey));
|
|
4118
|
-
|
|
4080
|
+
const workspace = into && (await this._heldMesh(workspaceKey));
|
|
4081
|
+
if (!into || !workspace?.minted) {
|
|
4082
|
+
return;
|
|
4083
|
+
}
|
|
4084
|
+
const chats = await oldChats(account);
|
|
4085
|
+
const copied = `${this._meshIdOf(account)}:${chats?.mark}`;
|
|
4086
|
+
if (this._accountCopied === copied) {
|
|
4087
|
+
return;
|
|
4088
|
+
}
|
|
4089
|
+
if (!chats) {
|
|
4090
|
+
await this._recordCopied(account, workspaceKey);
|
|
4091
|
+
this._accountCopied = copied;
|
|
4119
4092
|
return;
|
|
4120
4093
|
}
|
|
4121
4094
|
await into.waitForWritable();
|
|
@@ -4128,8 +4101,10 @@ export class Core extends ReadyResource {
|
|
|
4128
4101
|
deviceId: this._requireDeviceKeyPair().publicKey,
|
|
4129
4102
|
endsOpenRuns: true
|
|
4130
4103
|
});
|
|
4131
|
-
|
|
4132
|
-
await this.
|
|
4104
|
+
await this._recordCopied(account, workspaceKey);
|
|
4105
|
+
if (await this._markCopied(account, workspaceKey)) {
|
|
4106
|
+
this._accountCopied = copied;
|
|
4107
|
+
}
|
|
4133
4108
|
this._log?.info(['p2p', 'mesh'], 'copied the account into its public mesh', {
|
|
4134
4109
|
mesh: this._meshIdOf(into).slice(0, 8)
|
|
4135
4110
|
});
|
|
@@ -4141,8 +4116,31 @@ export class Core extends ReadyResource {
|
|
|
4141
4116
|
})
|
|
4142
4117
|
.finally(() => {
|
|
4143
4118
|
this._publicMigration = null;
|
|
4119
|
+
if (this._copyAgain && !this.closing) {
|
|
4120
|
+
this._copyAgain = false;
|
|
4121
|
+
this._migrateIntoPublic(account, workspaceKey);
|
|
4122
|
+
}
|
|
4144
4123
|
});
|
|
4145
4124
|
}
|
|
4125
|
+
async _recordCopied(account, workspaceKey) {
|
|
4126
|
+
const record = await this._publicRecord(account, workspaceKey);
|
|
4127
|
+
if (record && !record.migrated) {
|
|
4128
|
+
await this._savePublicRecord(account, workspaceKey, { ...record, migrated: true });
|
|
4129
|
+
}
|
|
4130
|
+
}
|
|
4131
|
+
async _markCopied(account, workspaceKey) {
|
|
4132
|
+
const row = await account.view.get(JOINED_MESHES, { meshKey: workspaceKey });
|
|
4133
|
+
if (!row || !account.writable) {
|
|
4134
|
+
return false;
|
|
4135
|
+
}
|
|
4136
|
+
if (!row.initial) {
|
|
4137
|
+
const { meshKey, memberId, joinedAt } = row;
|
|
4138
|
+
await account.dispatch('put-joined-mesh', {
|
|
4139
|
+
room: { meshKey, memberId, joinedAt, initial: true }
|
|
4140
|
+
});
|
|
4141
|
+
}
|
|
4142
|
+
return true;
|
|
4143
|
+
}
|
|
4146
4144
|
async _followAgentCopies(agentId) {
|
|
4147
4145
|
if (!agentId && !(await this._agentCopies.lock()))
|
|
4148
4146
|
return;
|
|
@@ -4895,9 +4893,6 @@ export class Core extends ReadyResource {
|
|
|
4895
4893
|
requireWorkspace(departing, meshId);
|
|
4896
4894
|
}
|
|
4897
4895
|
const account = this._accountMesh();
|
|
4898
|
-
if (account && isOwnWorkspace(account, departing)) {
|
|
4899
|
-
throw new CoreError('OWN_WORKSPACE_LEAVE_REFUSED');
|
|
4900
|
-
}
|
|
4901
4896
|
const kicked = this._kickedMeshes.has(meshId) && departing !== account;
|
|
4902
4897
|
const member = departing.role === 'workspace' && !kicked ? await this._leavingMember(departing) : null;
|
|
4903
4898
|
const leavingAccount = await this._isStoredAccount(departing);
|
|
@@ -5115,7 +5110,7 @@ export class Core extends ReadyResource {
|
|
|
5115
5110
|
const counts = await this._withArchivedMesh(row, (mesh, archived) => countContents(mesh, account, archived));
|
|
5116
5111
|
return { meshId, ...counts };
|
|
5117
5112
|
}
|
|
5118
|
-
async migrateArchivedMesh(meshId) {
|
|
5113
|
+
async migrateArchivedMesh(meshId, workspaceId) {
|
|
5119
5114
|
if (!this.opened)
|
|
5120
5115
|
await this.ready();
|
|
5121
5116
|
await this._meshTransitionLock.lock();
|
|
@@ -5126,22 +5121,33 @@ export class Core extends ReadyResource {
|
|
|
5126
5121
|
const row = await this._archivedRow(meshId);
|
|
5127
5122
|
if (row.migratedAt) {
|
|
5128
5123
|
const none = { chats: 0, agents: 0, knowledge: 0 };
|
|
5129
|
-
return { meshId, migrated: false, migratedAt: row.migratedAt, ...none };
|
|
5124
|
+
return { meshId, workspaceId, migrated: false, migratedAt: row.migratedAt, ...none };
|
|
5130
5125
|
}
|
|
5131
5126
|
const account = await this._writableAccount();
|
|
5132
5127
|
if (!account) {
|
|
5133
5128
|
throw new CoreError('ACCOUNT_NOT_WRITABLE');
|
|
5134
5129
|
}
|
|
5135
|
-
const into = await this.
|
|
5130
|
+
const into = await this._archiveDestination(workspaceId);
|
|
5136
5131
|
const counts = await this._withArchivedMesh(row, (mesh, archived) => migrateContents(mesh, into, { from: archived, into: account }));
|
|
5137
5132
|
const migratedAt = Date.now();
|
|
5138
5133
|
await this.local.markMeshMigrated(row.key, migratedAt);
|
|
5139
|
-
return { meshId, migrated: true, migratedAt, ...counts };
|
|
5134
|
+
return { meshId, workspaceId, migrated: true, migratedAt, ...counts };
|
|
5140
5135
|
}
|
|
5141
5136
|
finally {
|
|
5142
5137
|
this._meshTransitionLock.unlock();
|
|
5143
5138
|
}
|
|
5144
5139
|
}
|
|
5140
|
+
async _archiveDestination(workspaceId) {
|
|
5141
|
+
const workspace = await this._heldMesh(this._meshKeyOf(workspaceId));
|
|
5142
|
+
if (workspace?.role !== 'workspace' || this._isHidden(workspaceId)) {
|
|
5143
|
+
throw new CoreError('MESH_NOT_FOUND', [workspaceId]);
|
|
5144
|
+
}
|
|
5145
|
+
const into = await this._publicOf(workspace);
|
|
5146
|
+
if (into.role !== 'public' || !into.writable) {
|
|
5147
|
+
throw new CoreError('MESH_STILL_JOINING');
|
|
5148
|
+
}
|
|
5149
|
+
return into;
|
|
5150
|
+
}
|
|
5145
5151
|
async _archivedRow(meshId) {
|
|
5146
5152
|
const key = this._meshKeyOf(meshId);
|
|
5147
5153
|
const row = (await this.local.listArchivedMeshes()).find((row) => b4a.equals(row.key, key));
|
|
@@ -5433,7 +5439,7 @@ export class Core extends ReadyResource {
|
|
|
5433
5439
|
});
|
|
5434
5440
|
}
|
|
5435
5441
|
async _mintMesh(opts) {
|
|
5436
|
-
const { shared, workspace,
|
|
5442
|
+
const { shared, workspace, initial } = opts;
|
|
5437
5443
|
if (this.closing) {
|
|
5438
5444
|
throw new CoreError('CORE_CLOSING', ['Core']);
|
|
5439
5445
|
}
|
|
@@ -5451,7 +5457,7 @@ export class Core extends ReadyResource {
|
|
|
5451
5457
|
throw new CoreError('ACCOUNT_MEMBER_UNKNOWN');
|
|
5452
5458
|
}
|
|
5453
5459
|
const role = workspace ? 'workspace' : undefined;
|
|
5454
|
-
const mesh = await this._openMesh({ new: true, sharing: true, role, workspace,
|
|
5460
|
+
const mesh = await this._openMesh({ new: true, sharing: true, role, workspace, initial });
|
|
5455
5461
|
this._wireMesh(this._poolEntry(mesh));
|
|
5456
5462
|
this._bringMeshOnline(mesh, { new: true });
|
|
5457
5463
|
try {
|
|
@@ -5599,11 +5605,12 @@ export class Core extends ReadyResource {
|
|
|
5599
5605
|
const mesh = this._pooled(meshId);
|
|
5600
5606
|
const account = !!accountKey && b4a.equals(accountKey, row.key);
|
|
5601
5607
|
const joined = meshes.get(meshId);
|
|
5602
|
-
const state = this._meshEntryState(mesh, account);
|
|
5608
|
+
const state = this._meshEntryState(meshId, mesh, account);
|
|
5609
|
+
const content = row.role !== 'workspace' || !this._accountMesh()?.ourMemberId;
|
|
5603
5610
|
return {
|
|
5604
5611
|
meshId,
|
|
5605
5612
|
state,
|
|
5606
|
-
writable: mesh?.writable
|
|
5613
|
+
writable: !!mesh?.writable && (content || !!this._publicMesh(meshId)?.writable),
|
|
5607
5614
|
open: mesh !== null,
|
|
5608
5615
|
account,
|
|
5609
5616
|
label: joined?.label || undefined,
|
|
@@ -5614,10 +5621,12 @@ export class Core extends ReadyResource {
|
|
|
5614
5621
|
workspace: row.role === 'workspace'
|
|
5615
5622
|
};
|
|
5616
5623
|
}
|
|
5617
|
-
_meshEntryState(mesh, account) {
|
|
5624
|
+
_meshEntryState(meshId, mesh, account) {
|
|
5618
5625
|
if (account) {
|
|
5619
5626
|
return this._statusState();
|
|
5620
5627
|
}
|
|
5628
|
+
if (this._haltedMeshes.has(meshId))
|
|
5629
|
+
return 'needs-upgrade';
|
|
5621
5630
|
if (!mesh)
|
|
5622
5631
|
return 'idle';
|
|
5623
5632
|
return mesh.writable ? 'joined' : 'joining';
|
|
@@ -5784,8 +5793,7 @@ export class Core extends ReadyResource {
|
|
|
5784
5793
|
return {
|
|
5785
5794
|
meshId: key ? b4a.toHex(key) : undefined,
|
|
5786
5795
|
writable: this._accountWritable(),
|
|
5787
|
-
displayName: (await this.displayName()) ?? undefined
|
|
5788
|
-
ownWorkspace: this._ownWorkspaceId ?? undefined
|
|
5796
|
+
displayName: (await this.displayName()) ?? undefined
|
|
5789
5797
|
};
|
|
5790
5798
|
}
|
|
5791
5799
|
async displayName() {
|
|
@@ -5876,9 +5884,6 @@ export class Core extends ReadyResource {
|
|
|
5876
5884
|
if (!isOwnMesh) {
|
|
5877
5885
|
throw new CoreError(mesh.writable ? 'MEMBER_INVITE_ACCOUNT_REFUSED' : 'MESH_STILL_JOINING');
|
|
5878
5886
|
}
|
|
5879
|
-
if (isOwnWorkspace(registry, mesh)) {
|
|
5880
|
-
throw new CoreError('OWN_WORKSPACE_INVITE_REFUSED');
|
|
5881
|
-
}
|
|
5882
5887
|
if (workspace) {
|
|
5883
5888
|
await requireOurAdmin(mesh, 'invite a member');
|
|
5884
5889
|
}
|
|
@@ -5934,8 +5939,7 @@ export class Core extends ReadyResource {
|
|
|
5934
5939
|
}
|
|
5935
5940
|
async _publicHeads() {
|
|
5936
5941
|
const heads = [];
|
|
5937
|
-
const
|
|
5938
|
-
for (const meshId of ids) {
|
|
5942
|
+
for (const meshId of new Set(this._publicIds.values())) {
|
|
5939
5943
|
const mesh = this._pooled(meshId);
|
|
5940
5944
|
const head = mesh && (await inviteHead(mesh));
|
|
5941
5945
|
if (head) {
|
|
@@ -6138,9 +6142,6 @@ export class Core extends ReadyResource {
|
|
|
6138
6142
|
}
|
|
6139
6143
|
const held = this._pooled(meshId);
|
|
6140
6144
|
const failed = await this._trackFollow(meshId, async () => {
|
|
6141
|
-
if (await lostMint(memberMesh, joined.meshKey)) {
|
|
6142
|
-
return;
|
|
6143
|
-
}
|
|
6144
6145
|
if (joined.kicked && !joined.leftAt) {
|
|
6145
6146
|
await this._followKick(meshId, held);
|
|
6146
6147
|
return;
|
|
@@ -6168,6 +6169,7 @@ export class Core extends ReadyResource {
|
|
|
6168
6169
|
}
|
|
6169
6170
|
if (await this.local.readMeshSession(joined.meshKey)) {
|
|
6170
6171
|
if (this._upgradeRequired !== 'halt' &&
|
|
6172
|
+
!this._haltedMeshes.has(meshId) &&
|
|
6171
6173
|
(await this.local.awaitsAdmission(joined.meshKey))) {
|
|
6172
6174
|
tally.readmitted++;
|
|
6173
6175
|
await this._openPooledMesh(meshId, 'readmit');
|
|
@@ -6235,10 +6237,13 @@ export class Core extends ReadyResource {
|
|
|
6235
6237
|
}
|
|
6236
6238
|
}
|
|
6237
6239
|
async _openFollowedMesh(memberMesh, joined) {
|
|
6238
|
-
|
|
6240
|
+
const { meshKey } = joined;
|
|
6241
|
+
if (this._blockedByMinVersion() ||
|
|
6242
|
+
this._upgradeRequired ||
|
|
6243
|
+
this._haltedMeshes.has(b4a.toHex(meshKey)) ||
|
|
6244
|
+
!this._mayFollow(memberMesh)) {
|
|
6239
6245
|
return 'skipped';
|
|
6240
6246
|
}
|
|
6241
|
-
const { meshKey } = joined;
|
|
6242
6247
|
const held = await memberMesh.view.get(MESH_SEEDS, { meshKey });
|
|
6243
6248
|
if (!held) {
|
|
6244
6249
|
return 'no-seed';
|
|
@@ -6732,6 +6737,9 @@ export class Core extends ReadyResource {
|
|
|
6732
6737
|
if (pooled && this._definesAgents(pooled, request)) {
|
|
6733
6738
|
return this._accountMesh() ?? pooled;
|
|
6734
6739
|
}
|
|
6740
|
+
if (pooled) {
|
|
6741
|
+
this._refuseAccountContent(pooled, request);
|
|
6742
|
+
}
|
|
6735
6743
|
if (pooled && !this._routesToPublic(pooled, request)) {
|
|
6736
6744
|
return pooled;
|
|
6737
6745
|
}
|
|
@@ -6785,18 +6793,29 @@ export class Core extends ReadyResource {
|
|
|
6785
6793
|
};
|
|
6786
6794
|
}
|
|
6787
6795
|
_definesAgents(mesh, { route }) {
|
|
6788
|
-
return ((route === 'put-agent' || route === 'put-tool-configs') &&
|
|
6796
|
+
return ((route === 'put-agent' || route === 'put-tool-configs' || route === 'put-approval-rule') &&
|
|
6789
6797
|
mesh.role === 'workspace' &&
|
|
6790
6798
|
this._hasPublic(mesh));
|
|
6791
6799
|
}
|
|
6800
|
+
_refuseAccountContent(mesh, { route }) {
|
|
6801
|
+
if (route && publicRoute(route) && this._isAccount(mesh)) {
|
|
6802
|
+
throw new CoreError('ROUTE_NEEDS_WORKSPACE', [route]);
|
|
6803
|
+
}
|
|
6804
|
+
}
|
|
6792
6805
|
_routesToPublic(mesh, { route }) {
|
|
6793
6806
|
return !!route && publicRoute(route) && this._hasPublic(mesh);
|
|
6794
6807
|
}
|
|
6795
6808
|
async _routedMesh(pooled, meshId, request) {
|
|
6796
6809
|
const mesh = pooled ?? (await this._publicById(meshId)) ?? (await this._openPooledMesh(meshId));
|
|
6797
|
-
|
|
6810
|
+
this._refuseAccountContent(mesh, request);
|
|
6811
|
+
const admitted = mesh.writable && !!this._accountMesh()?.writable;
|
|
6812
|
+
const follow = request.follow || admitted || (await this._holdsPublic(mesh));
|
|
6798
6813
|
return this._routesToPublic(mesh, request) ? this._publicOf(mesh, { ...request, follow }) : mesh;
|
|
6799
6814
|
}
|
|
6815
|
+
async _holdsPublic(workspace) {
|
|
6816
|
+
const account = this._accountMesh();
|
|
6817
|
+
return !!account && !!(await this._publicRecord(account, workspace.key))?.key;
|
|
6818
|
+
}
|
|
6800
6819
|
async _publicById(meshId) {
|
|
6801
6820
|
const account = this._accountMesh();
|
|
6802
6821
|
if (!account) {
|
|
@@ -6806,9 +6825,9 @@ export class Core extends ReadyResource {
|
|
|
6806
6825
|
if ((await this._publicRecord(account, workspaceKey))?.key !== meshId) {
|
|
6807
6826
|
continue;
|
|
6808
6827
|
}
|
|
6809
|
-
const
|
|
6810
|
-
const scope =
|
|
6811
|
-
const mesh = scope && (await this._publicOf(scope));
|
|
6828
|
+
const hidden = this._isHidden(b4a.toHex(workspaceKey));
|
|
6829
|
+
const scope = hidden ? null : await this._heldMesh(workspaceKey);
|
|
6830
|
+
const mesh = scope && (await this._publicOf(scope, { follow: true }));
|
|
6812
6831
|
return mesh && this._meshIdOf(mesh) === meshId ? mesh : null;
|
|
6813
6832
|
}
|
|
6814
6833
|
return null;
|
|
@@ -6849,7 +6868,7 @@ export class Core extends ReadyResource {
|
|
|
6849
6868
|
createProject: (workspaceId, opts) => this.createProject(workspaceId, opts),
|
|
6850
6869
|
listArchived: () => this.listArchivedMeshes(),
|
|
6851
6870
|
archivedContents: (meshId) => this.archivedMeshContents(meshId),
|
|
6852
|
-
migrateArchived: (meshId) => this.migrateArchivedMesh(meshId),
|
|
6871
|
+
migrateArchived: (meshId, workspaceId) => this.migrateArchivedMesh(meshId, workspaceId),
|
|
6853
6872
|
recoverable: () => this.accountRecoverable(),
|
|
6854
6873
|
publishRecovery: async (phrase) => void (await this.publishAccountRecovery(phrase)),
|
|
6855
6874
|
recover: (phrase, timeout) => this.recoverAccount(phrase, { timeout }),
|
|
@@ -7062,6 +7081,14 @@ export class Core extends ReadyResource {
|
|
|
7062
7081
|
this._modelCatalogWatchSource = new ReadyGuard();
|
|
7063
7082
|
void this._modelCatalogWatchSource.ready().catch(noop);
|
|
7064
7083
|
}
|
|
7084
|
+
registerSiblingDownloads(hooks) {
|
|
7085
|
+
this._siblingDownloads = hooks;
|
|
7086
|
+
return () => {
|
|
7087
|
+
if (this._siblingDownloads === hooks) {
|
|
7088
|
+
this._siblingDownloads = null;
|
|
7089
|
+
}
|
|
7090
|
+
};
|
|
7091
|
+
}
|
|
7065
7092
|
registerRetryModelDownload(hook) {
|
|
7066
7093
|
this._retryModelDownload = hook;
|
|
7067
7094
|
return () => {
|
|
@@ -7375,12 +7402,14 @@ export class Core extends ReadyResource {
|
|
|
7375
7402
|
return 'joining';
|
|
7376
7403
|
}
|
|
7377
7404
|
if (this._accountMesh()) {
|
|
7378
|
-
return this._accountWritable()
|
|
7405
|
+
return this._accountWritable() && this._ownDecided === this._accountMesh()
|
|
7406
|
+
? 'joined'
|
|
7407
|
+
: 'joining';
|
|
7379
7408
|
}
|
|
7380
7409
|
return 'idle';
|
|
7381
7410
|
}
|
|
7382
7411
|
_accountWritable() {
|
|
7383
|
-
return !!this._accountMesh()?.writable
|
|
7412
|
+
return !!this._accountMesh()?.writable;
|
|
7384
7413
|
}
|
|
7385
7414
|
async _chatSenders(meshId) {
|
|
7386
7415
|
const project = this._pooled(meshId);
|