@witbitz/sdk 4.3.0 → 4.4.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/README.md +2 -2
- package/a2aCore.js +26 -5
- package/accountErase.js +6 -1
- package/accountRecord.js +2 -2
- package/agentDoorTools.js +28 -0
- package/chatLock.js +16 -0
- package/cloudDevicePins.js +2 -2
- package/codeAttachments.js +100 -0
- package/codeCache.js +149 -0
- package/codeCloud.js +0 -2
- package/codeComputers.js +1 -0
- package/codeFolders.js +116 -0
- package/codeHistory.js +76 -0
- package/codeLanguage.js +54 -0
- package/codeModes.js +2 -0
- package/codeProgress.js +54 -0
- package/codeSent.js +68 -0
- package/codeSubagents.js +107 -0
- package/codeTransport.js +22 -0
- package/connections.js +17 -18
- package/deviceAttest.js +9 -3
- package/idb.js +19 -3
- package/jobAgents.js +2 -2
- package/keptMerge.js +9 -2
- package/l1-worker-src.js +1 -1
- package/l1-worker.js +93 -30
- package/laneAssociation.js +68 -0
- package/laneConfig.js +4 -3
- package/manifest.json +80 -61
- package/memberChange.js +4 -2
- package/mirrorBatch.js +47 -0
- package/opRouting.js +10 -0
- package/package.json +21 -2
- package/pdfOptions.js +13 -0
- package/pdfText.js +107 -0
- package/pdfjs.mjs +28 -0
- package/pdfjs.worker.mjs +28 -0
- package/protectedLocal.js +18 -2
- package/removedMessage.js +1 -1
- package/roomEmbed.js +111 -0
- package/roomName.js +1 -1
- package/roomRoster.js +21 -5
- package/rosterCount.js +6 -3
- package/sdkA2A.js +160 -40
- package/sdkAccount.js +17 -4
- package/sdkAccountDoc.js +11 -3
- package/sdkAccountSections.js +117 -8
- package/sdkBackup.js +35 -8
- package/sdkCloudDevice.js +8 -2
- package/sdkComputers.js +582 -53
- package/sdkDictation.js +114 -24
- package/sdkErase.js +9 -4
- package/sdkExports.js +4 -2
- package/sdkLaneLink.js +3 -3
- package/sdkPlan.js +4 -2
- package/sdkRekey.js +50 -17
- package/sdkReport.js +1 -1
- package/sdkSafeMedia.js +1 -1
- package/sdkSpeech.js +19 -2
- package/sdkTemporaryRooms.js +123 -0
- package/sdkVault.js +66 -10
- package/sentinelRelease.js +1 -0
- package/sharedViews.js +17 -3
- package/siri.js +114 -7
- package/spaceClient.js +16 -5
- package/spaceEmailGate.js +2 -2
- package/spaceTemplates.js +99 -0
- package/speechOut.js +4 -2
- package/store.js +83 -14
- package/sw-notif-core.js +9 -7
- package/turnVerdict.js +1 -0
- package/vault-core.js +480 -112
- package/vault-kit.mjs +2 -2
- package/vault-screens.js +5 -7
- package/vaultAtRest.js +35 -4
- package/vaultKeep.js +9 -3
- package/vaultWorkerHost.js +23 -4
- package/witbitz-admin.mjs +12 -11
- package/witbitz-sdk.d.ts +115 -24
- package/witbitz-sdk.js +572 -149
package/l1-worker.js
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
// room, `auth(room)` round-trips to the main thread via {authReq}. The enclave tier (mkPub/enclave) is
|
|
13
13
|
// read SYNCHRONOUSLY by keyFields, so we keep a pushed snapshot {enclaveKey, enclaveRooms} and read it
|
|
14
14
|
// locally rather than round-trip.
|
|
15
|
+
import { routingIndex } from './opRouting.js'
|
|
15
16
|
import { prefetchUsable, positionOf, prefetchAnswer, prefetchHashKey } from './prefetchPoll.js'
|
|
16
17
|
import { makeSpaceClient, setAttestProvider, setPushSelf, setPushAcct, pushAcctSecretOf, viewingTag } from './spaceClient.js'
|
|
17
18
|
import { idb } from './idb.js'
|
|
@@ -57,12 +58,24 @@ const TEMP_SK = /^[A-Za-z0-9_-]{43}$/
|
|
|
57
58
|
// ROOM STREAMS: room → { s, holders }. The stream client needs mk, so it runs in this realm; only EVENTS go out — the
|
|
58
59
|
// reply text as it grows (the same plaintext a poll's partialText already carries out), "poll now", "the turn ended".
|
|
59
60
|
// Several frames can share this worker (the hoisted vault: the app + a lane panel), hence a holder count.
|
|
61
|
+
const grantsByRoom = new Map()
|
|
60
62
|
const streams = new Map()
|
|
63
|
+
function rekeyStream(room, mk) {
|
|
64
|
+
const held = streams.get(room)
|
|
65
|
+
if (!held?.s || held.mk === mk) return
|
|
66
|
+
held.s.stop()
|
|
67
|
+
grantsByRoom.delete(room)
|
|
68
|
+
held.mk = mk
|
|
69
|
+
held.grants = null
|
|
70
|
+
held.s = openStreamHere(room, mk, null, held.tag)
|
|
71
|
+
}
|
|
61
72
|
const streamFeed = (room, result) => {
|
|
62
73
|
const h = streams.get(room)
|
|
63
|
-
if (!
|
|
64
|
-
if (Array.isArray(result.streamGrants))
|
|
65
|
-
h
|
|
74
|
+
if (!result || result.status !== 200) return
|
|
75
|
+
if (Array.isArray(result.streamGrants)) grantsByRoom.set(room, result.streamGrants)
|
|
76
|
+
if (!h) return
|
|
77
|
+
if (Array.isArray(result.streamGrants)) { h.s?.setGrants(result.streamGrants); h.grants = result.streamGrants }
|
|
78
|
+
h.s?.sync(typeof result.partialText === 'string' ? result.partialText : '')
|
|
66
79
|
}
|
|
67
80
|
const mks = new Map() // room → mk — the worker's authoritative key store (A2b); mk never posts back out
|
|
68
81
|
// §9 SPLIT-KEY (confinement mode): a split room's key store is the user's userShare + the commit. resolveMk fetches the
|
|
@@ -111,7 +124,7 @@ const backwards = (room, held, incoming, ep) => held !== incoming && (Number(ep)
|
|
|
111
124
|
// never hands the frame or the next worker the old one. Only a key with an epoch, only when it changed. The vault page is
|
|
112
125
|
// this worker's owner and already holds every key; the regular app's page ignores the message.
|
|
113
126
|
const tellEpoch = (room, ep, key) => { if (volatile.has(room) || String(room).startsWith('tmp-')) return; try { self.postMessage({ t: 'keyEpoch', room, ep, ...key }) } catch { /* */ } } // never a memory-only (attested) or temporary room's key: the vault would keep it in its account cache
|
|
114
|
-
const keep = (room, mk, ep) => { if (backwards(room, mks.get(room), mk, ep)) return false; if ((Number(ep) || 0) > 0 && (mks.get(room) !== mk || Number(ep) > (eps.get(room) || 0))) tellEpoch(room, Number(ep), { mk }); if (ep) noteEp(room, ep); mks.set(room, mk); persist('mk:' + room, mk); deriveNotifKey(mk).then((nk) => persistNk(room, nk)).catch(() => {}) } // + NK mirror: every mk the kernel holds (normal OR reconstructed-split) yields a push-preview key, so a background notification for THIS room shows sender+text (vault-sw.js notifPreview), not the generic nudge
|
|
127
|
+
const keep = (room, mk, ep) => { if (backwards(room, mks.get(room), mk, ep)) return false; if ((Number(ep) || 0) > 0 && (mks.get(room) !== mk || Number(ep) > (eps.get(room) || 0))) tellEpoch(room, Number(ep), { mk }); if (ep) noteEp(room, ep); mks.set(room, mk); rekeyStream(room, mk); persist('mk:' + room, mk); deriveNotifKey(mk).then((nk) => persistNk(room, nk)).catch(() => {}) } // + NK mirror: every mk the kernel holds (normal OR reconstructed-split) yields a push-preview key, so a background notification for THIS room shows sender+text (vault-sw.js notifPreview), not the generic nudge
|
|
115
128
|
// WHY a room has no key, per room — the worker's own verdict rides the no_key answer (the owner's trail said only "no key on
|
|
116
129
|
// this device" while the index held a share for every room, 2026-10-03).
|
|
117
130
|
const APPSHARE_URL = (() => { try { const o = self.location && self.location.origin; return (o && o !== 'null') ? o + '/api/appshare' : '/api/appshare' } catch (e) { return '/api/appshare' } })()
|
|
@@ -138,17 +151,18 @@ async function heldMatchesShare (room, have) {
|
|
|
138
151
|
if (ok) { heldOk.set(room, have); return true }
|
|
139
152
|
dropOldKey(room); return false
|
|
140
153
|
}
|
|
141
|
-
const dropOldKey = (room) => { if (!mks.has(room)) return; mks.delete(room); keysReady.then(() => idb.del('mk:' + room)).catch(() => {}) }
|
|
154
|
+
const dropOldKey = (room) => { if (!mks.has(room)) return; const h = streams.get(room); if (h) { h.s?.stop(); h.mk = null; h.grants = null }; grantsByRoom.delete(room); mks.delete(room); keysReady.then(() => idb.del('mk:' + room)).catch(() => {}) }
|
|
142
155
|
const keepSplit = (room, sp, ep) => { if (backwards(room, splits.get(room) && splits.get(room).userShare, sp.userShare, ep)) return false; if ((Number(ep) || 0) > 0 && ((splits.get(room) || {}).userShare !== sp.userShare || Number(ep) > (eps.get(room) || 0))) { tellEpoch(room, Number(ep), { split: { userShare: sp.userShare, commit: sp.commit || '' } }); if (Number(ep) > (eps.get(room) || 0) || (splits.get(room) || {}).userShare !== sp.userShare) dropOldKey(room) } if (ep) noteEp(room, ep); const held = splits.get(room); if (held && held.userShare !== sp.userShare) { const alts = splitAlts.get(room) || []; if (!alts.some((a) => a.userShare === held.userShare)) splitAlts.set(room, [held, ...alts].slice(0, 4)) } splits.set(room, sp); persist('us:' + room, sp) }
|
|
143
156
|
// The mirror of keep/keepSplit, and the thing that makes "delete this Space" mean anything: without it the app cleared
|
|
144
157
|
// localStorage while the WORKER kept the key — in memory AND in idb, from which a freshly-created worker reloads it at
|
|
145
158
|
// boot (the idb.entries('mk:') restore below). So a deleted room's key came BACK on the next page load. Clears every
|
|
146
159
|
// trace: the live maps, the persisted mk, the derived notification key, and the split half.
|
|
147
160
|
const forget = (room) => {
|
|
161
|
+
grantsByRoom.delete(room); streams.get(room)?.s?.stop(); streams.delete(room)
|
|
148
162
|
mks.delete(room); splits.delete(room); eps.delete(room)
|
|
149
163
|
for (const prefix of ['mk:', 'us:', 'nk:']) parked.delete(prefix + room)
|
|
150
164
|
lastPos.delete(room); heldOk.delete(room); splitAlts.delete(room)
|
|
151
|
-
return Promise.all([
|
|
165
|
+
return Promise.all(['mk:', 'nk:', 'us:', 'ep:', 'cnt:'].map(prefix => idb.delStrict(prefix + room)))
|
|
152
166
|
}
|
|
153
167
|
async function resolveMk(room) {
|
|
154
168
|
// ⚑ WAIT for the idb key map. EVERY page load starts a FRESH worker (plus browsers evict them), and the map loads
|
|
@@ -252,7 +266,7 @@ setAttestProvider(attestShim)
|
|
|
252
266
|
// push handler leaves a PREFETCHED poll answer here and reads the room's position from here. Every call is bounded —
|
|
253
267
|
// a hung database must never hold a poll.
|
|
254
268
|
const IDB_WAIT = 2500
|
|
255
|
-
const idbOpen = () => new Promise((res) => { const t = setTimeout(() => res(null), IDB_WAIT); try { const r = indexedDB.open('spaces', 1); r.onupgradeneeded = () => { try { r.result.createObjectStore('kv') } catch { /* */ } }; r.onsuccess = () => { clearTimeout(t);
|
|
269
|
+
const idbOpen = () => new Promise((res) => { const t = setTimeout(() => res(null), IDB_WAIT); try { const r = indexedDB.open('spaces', 1); r.onupgradeneeded = () => { try { r.result.createObjectStore('kv') } catch { /* */ } }; r.onsuccess = () => { clearTimeout(t); const db = r.result; db.onversionchange = () => db.close(); res(db) }; r.onerror = () => { clearTimeout(t); res(null) } } catch { clearTimeout(t); res(null) } })
|
|
256
270
|
const idbGet = async (k) => { try { const db = await idbOpen(); if (!db) return null; return await new Promise((res) => { const t = setTimeout(() => res(null), IDB_WAIT); const q = db.transaction('kv', 'readonly').objectStore('kv').get(k); q.onsuccess = () => { clearTimeout(t); res(q.result || null) }; q.onerror = () => { clearTimeout(t); res(null) } }) } catch { return null } }
|
|
257
271
|
const idbSet = async (k, v) => { try { const db = await idbOpen(); if (!db) return false; return await new Promise((res) => { const t = setTimeout(() => res(false), IDB_WAIT); const q = db.transaction('kv', 'readwrite').objectStore('kv').put(v, k); q.onsuccess = () => { clearTimeout(t); res(true) }; q.onerror = () => { clearTimeout(t); res(false) } }) } catch { return false } }
|
|
258
272
|
const idbDel = async (k) => { try { const db = await idbOpen(); if (!db) return false; return await new Promise((res) => { const t = setTimeout(() => res(false), IDB_WAIT); const q = db.transaction('kv', 'readwrite').objectStore('kv').delete(k); q.onsuccess = () => { clearTimeout(t); res(true) }; q.onerror = () => { clearTimeout(t); res(false) } }) } catch { return false } }
|
|
@@ -377,10 +391,13 @@ self.onmessage = async (e) => {
|
|
|
377
391
|
case 'wipeKeys': { // root-vault only: parked/opaque keys count even when no room list can name them
|
|
378
392
|
storageWiped = true; storageEpoch++
|
|
379
393
|
await keysReady
|
|
394
|
+
for (const h of streams.values()) h.s?.stop()
|
|
395
|
+
streams.clear(); grantsByRoom.clear()
|
|
380
396
|
mks.clear(); splits.clear(); parked.clear(); splitAlts.clear(); eps.clear(); heldOk.clear(); lastPos.clear()
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
self.postMessage({ id: m.id,
|
|
397
|
+
ids.clear()
|
|
398
|
+
try { await idb.clearStrict(); self.postMessage({ id: m.id, result: true }) }
|
|
399
|
+
catch (error) { self.postMessage({ id: m.id, error: String(error?.message || error) }) }
|
|
400
|
+
finally { publishPresence() }
|
|
384
401
|
return
|
|
385
402
|
}
|
|
386
403
|
case 'volatile': { // {rooms} → these rooms' keys are memory-only from now on: drop what is stored, write nothing
|
|
@@ -417,9 +434,13 @@ self.onmessage = async (e) => {
|
|
|
417
434
|
case 'forget': { // {room} → DROP the key. AWAITS the idb deletes before replying: the caller holds
|
|
418
435
|
// navigation until it resolves, and a dedicated worker dies with its page — a fire-and-forget delete could be
|
|
419
436
|
// cut off mid-write, leaving the key in idb for the next worker to reload.
|
|
437
|
+
try {
|
|
420
438
|
await keysReady
|
|
421
|
-
if (m.room)
|
|
422
|
-
|
|
439
|
+
if (m.room) await forget(m.room)
|
|
440
|
+
if (m.id != null) self.postMessage({ id: m.id, result: true })
|
|
441
|
+
} catch (error) {
|
|
442
|
+
if (m.id != null) self.postMessage({ id: m.id, error: String(error?.message || error) })
|
|
443
|
+
} finally { publishPresence() }
|
|
423
444
|
return
|
|
424
445
|
}
|
|
425
446
|
case 'setPushAcct': { // {room} = the account's INDEX room → derive the account push secret from ITS key, here,
|
|
@@ -447,7 +468,7 @@ self.onmessage = async (e) => {
|
|
|
447
468
|
// A stream opened before the endpoint arrived carries no viewing tag: reopen it with one (the server then skips this
|
|
448
469
|
// device's tickle for the room on screen). Same room, same key; only the socket's name changes.
|
|
449
470
|
for (const [room, h] of streams) {
|
|
450
|
-
try { const tag = await viewingTag(room); if (tag && tag !== h.tag && h.mk) { h.s
|
|
471
|
+
try { const tag = await viewingTag(room); if (tag && tag !== h.tag && h.mk) { h.s?.stop(); h.s = openStreamHere(room, h.mk, h.grants || null, tag); h.tag = tag } } catch { /* the old socket stays */ }
|
|
451
472
|
}
|
|
452
473
|
if (m.id != null) self.postMessage({ id: m.id, result: true })
|
|
453
474
|
return
|
|
@@ -599,6 +620,15 @@ self.onmessage = async (e) => {
|
|
|
599
620
|
// not leaving one arrival path out.
|
|
600
621
|
// ⛔ …but NEVER to a keyless caller (above): in the hosted app this answer crossed into the app frame and carried every
|
|
601
622
|
// room key and split share of the account on every index sync. It gets `splits` alone.
|
|
623
|
+
if (name === 'index' && st && typeof st === 'object') {
|
|
624
|
+
for (const field of ['pipesRoom', 'msgsRoom']) {
|
|
625
|
+
const ptr = st[field]
|
|
626
|
+
if (!ptr?.room) continue
|
|
627
|
+
if (ptr.mk) keep(ptr.room, ptr.mk)
|
|
628
|
+
if (keylessAsk) st = { ...st, [field]: { room: ptr.room } }
|
|
629
|
+
}
|
|
630
|
+
publishPresence()
|
|
631
|
+
}
|
|
602
632
|
self.postMessage({ id, result: { status: 200, state: st, splits: splitRooms, ...(keylessAsk ? {} : { mkeys: mirror }), ...(Number.isInteger(r.v) ? { v: r.v } : {}) } }) // v: the version a write names (accountStores put ifV)
|
|
603
633
|
} catch (err) { self.postMessage({ id, error: 'indexRead: ' + String((err && err.message) || err) }) }
|
|
604
634
|
return
|
|
@@ -610,6 +640,7 @@ self.onmessage = async (e) => {
|
|
|
610
640
|
await keysReady // NEVER write the index from a half-loaded key map — an empty `mks` would strip every room's key (below)
|
|
611
641
|
if (indexMk && !mks.get(indexRoom)) { keep(indexRoom, indexMk); publishPresence() } // index ROOM key passed by the app (adopted-from-backup case)
|
|
612
642
|
let p = { ...(patch || {}) }
|
|
643
|
+
let previousIndex
|
|
613
644
|
if (p.rooms && typeof p.rooms === 'object') {
|
|
614
645
|
// PRESERVE keys we don't hold. The patch arrives KEYLESS (indexRead strips keys before handing it up), so a room
|
|
615
646
|
// whose key is missing from THIS worker used to be dropped outright — silently deleting that key from the shared
|
|
@@ -619,6 +650,7 @@ self.onmessage = async (e) => {
|
|
|
619
650
|
try {
|
|
620
651
|
let s = null; const rr = await acct.get(indexRoom, mks.get(indexRoom) || indexMk, name, { plainOpen: unzipDoc })
|
|
621
652
|
if (rr && rr.status === 200 && rr.state) s = rr.state
|
|
653
|
+
previousIndex = s
|
|
622
654
|
if (s && s.rooms && typeof s.rooms === 'object') cur = s.rooms
|
|
623
655
|
} catch { /* read failed → fall back to inject-what-we-hold (the pre-existing behaviour) */ }
|
|
624
656
|
const rooms = {}
|
|
@@ -637,6 +669,14 @@ self.onmessage = async (e) => {
|
|
|
637
669
|
publishPresence()
|
|
638
670
|
}
|
|
639
671
|
// ⛔ SEALED on the device — the doc carries every room key (accountStores.js); without the account key nothing is written
|
|
672
|
+
if (name === 'index') for (const field of ['pipesRoom', 'msgsRoom']) {
|
|
673
|
+
const ptr = p[field]
|
|
674
|
+
if (!ptr?.room || ptr.mk) continue
|
|
675
|
+
const saved = previousIndex?.[field]
|
|
676
|
+
const mk = (saved?.room === ptr.room && saved.mk) || mks.get(ptr.room)
|
|
677
|
+
if (!mk) throw new Error('The account room key is unavailable. Retry sync.')
|
|
678
|
+
p[field] = { room: ptr.room, mk }
|
|
679
|
+
}
|
|
640
680
|
const r = await acct.put(indexRoom, mks.get(indexRoom) || indexMk, name, p, summary, by, { ifV }) // ifV: only over the version the app merged
|
|
641
681
|
self.postMessage({ id, result: { status: (r && r.status) || 0, bytes: _jsonBytes(p), z: true, ...(r && r.error ? { error: r.error } : {}) } })
|
|
642
682
|
} catch (err) { self.postMessage({ id, error: 'indexWrite: ' + String((err && err.message) || err) }) }
|
|
@@ -731,23 +771,32 @@ self.onmessage = async (e) => {
|
|
|
731
771
|
})()
|
|
732
772
|
return
|
|
733
773
|
}
|
|
734
|
-
case 'streamOpen': {
|
|
735
|
-
const { room
|
|
736
|
-
const
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
774
|
+
case 'streamOpen': {
|
|
775
|
+
const { room } = m
|
|
776
|
+
const grants = m.grants || grantsByRoom.get(room)
|
|
777
|
+
let held = streams.get(room)
|
|
778
|
+
if (held) {
|
|
779
|
+
held.holders++
|
|
780
|
+
if (Array.isArray(grants)) { held.grants = grants; held.s?.setGrants(grants) }
|
|
781
|
+
return
|
|
782
|
+
}
|
|
783
|
+
held = { holders: 1, mk: null, s: null, tag: '', grants: Array.isArray(grants) ? grants : null }
|
|
784
|
+
streams.set(room, held)
|
|
785
|
+
try {
|
|
786
|
+
await keysReady
|
|
787
|
+
const mk = (typeof m.mk === 'string' && m.mk) || mks.get(room) || await resolveMk(room)
|
|
788
|
+
if (streams.get(room) !== held) return
|
|
789
|
+
if (!mk) { streams.delete(room); return }
|
|
790
|
+
const tag = await viewingTag(room).catch(() => '')
|
|
791
|
+
if (streams.get(room) !== held) return
|
|
792
|
+
held.tag = tag; held.mk = mks.get(room) || mk
|
|
793
|
+
held.s = openStreamHere(room, held.mk, held.grants, tag)
|
|
794
|
+
} catch (error) { if (streams.get(room) === held) streams.delete(room) }
|
|
746
795
|
return
|
|
747
796
|
}
|
|
748
|
-
case 'streamClose': {
|
|
749
|
-
const
|
|
750
|
-
if (
|
|
797
|
+
case 'streamClose': {
|
|
798
|
+
const held = streams.get(m.room)
|
|
799
|
+
if (held && --held.holders <= 0) { held.s?.stop(); streams.delete(m.room) }
|
|
751
800
|
return
|
|
752
801
|
}
|
|
753
802
|
case 'op': { // {id, op, room, args} → client[op](room, mks[room], …args) → {id, result}
|
|
@@ -762,8 +811,22 @@ self.onmessage = async (e) => {
|
|
|
762
811
|
// hold no identity for stays unsigned (open/legacy), unchanged. Only substitutes when the arg is absent — an app
|
|
763
812
|
// that still passes identity (flag off / email turn) is untouched.
|
|
764
813
|
if (op === 'turn' && (aa[1] == null) && ids.has(room)) aa[1] = ids.get(room)
|
|
765
|
-
|
|
766
|
-
|
|
814
|
+
const index = routingIndex(op)
|
|
815
|
+
if (index >= 0 && aa[index] && typeof aa[index] === 'object') {
|
|
816
|
+
const route = { ...aa[index] }
|
|
817
|
+
aa[index] = route
|
|
818
|
+
if (route.bridgeRoom && !route.bridgeMk) {
|
|
819
|
+
const key = mks.get(route.bridgeRoom) || await resolveMk(route.bridgeRoom)
|
|
820
|
+
if (key) route.bridgeMk = key
|
|
821
|
+
}
|
|
822
|
+
if (op === 'turn' && Array.isArray(route.links)) {
|
|
823
|
+
route.links = await Promise.all(route.links.map(async link => {
|
|
824
|
+
if (!link?.room || link.mk) return link
|
|
825
|
+
const key = mks.get(link.room) || await resolveMk(link.room).catch(() => null)
|
|
826
|
+
return key ? { ...link, mk: key } : link
|
|
827
|
+
}))
|
|
828
|
+
}
|
|
829
|
+
}
|
|
767
830
|
const mkHere = await resolveMk(room) // §9: reconstruct a split room's mk (fetch appShare + combine) on demand
|
|
768
831
|
let result = null
|
|
769
832
|
let pfNote = '' // what the prefetch lookup found, for the page's tap timeline ('' = not looked up)
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// Room activity and changes to who a private room is linked to have distinct clocks.
|
|
2
|
+
export function associationTime(record, now = Date.now()) {
|
|
3
|
+
return Math.max(now, (Number(record?.associationAt || record?.at) || 0) + 1)
|
|
4
|
+
}
|
|
5
|
+
// Normalize legacy records before cursor or key maintenance can move their activity time.
|
|
6
|
+
export function reconcilePrivateRooms(pipes) {
|
|
7
|
+
const byRoom = new Map()
|
|
8
|
+
for (const pipe of Object.values(pipes)) {
|
|
9
|
+
if (pipe?.kind === 'lane-lane') { pipe.associationAt ||= Number(pipe.at) || 1; continue }
|
|
10
|
+
if (pipe?.kind !== 'private-lane') continue
|
|
11
|
+
pipe.associationAt ||= Number(pipe.at) || 1
|
|
12
|
+
const room = pipe.lane?.room
|
|
13
|
+
if (!room || pipe.removed) continue
|
|
14
|
+
if (!byRoom.has(room)) byRoom.set(room, [])
|
|
15
|
+
byRoom.get(room).push(pipe)
|
|
16
|
+
}
|
|
17
|
+
const conflicting = new Set()
|
|
18
|
+
for (const parents of byRoom.values()) {
|
|
19
|
+
for (const pipe of parents) {
|
|
20
|
+
const upstream = byRoom.get(pipe.shared?.room)
|
|
21
|
+
if (!upstream) continue
|
|
22
|
+
conflicting.add(pipe)
|
|
23
|
+
for (const other of upstream) conflicting.add(other)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
for (const parents of byRoom.values()) {
|
|
27
|
+
if (parents.length < 2 && !conflicting.has(parents[0])) continue
|
|
28
|
+
const decision = Math.max(...parents.map(p => p.associationAt))
|
|
29
|
+
for (const pipe of parents) {
|
|
30
|
+
pipe.removed = true
|
|
31
|
+
pipe.associationAt = decision
|
|
32
|
+
pipe.cursor = 0
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return pipes
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function preferredAssociation(left, right) {
|
|
39
|
+
if (!left || !right) return left || right
|
|
40
|
+
const explicit = record => Number(record.associationAt) || (record.kind === 'private-lane' || record.kind === 'lane-lane' || record.detachedLane || record.removed ? Number(record.at) || 0 : 0)
|
|
41
|
+
const a = explicit(left), b = explicit(right)
|
|
42
|
+
if (a !== b) return a > b ? left : right
|
|
43
|
+
if (left.detachedLane || left.removed) return left
|
|
44
|
+
if (right.detachedLane || right.removed) return right
|
|
45
|
+
const activity = Number(right.at || 0) - Number(left.at || 0)
|
|
46
|
+
if (activity) return activity > 0 ? right : left
|
|
47
|
+
const destination = record => record.lane?.room || (typeof record.shared === 'string' ? record.shared : '') || ''
|
|
48
|
+
return destination(right) > destination(left) ? right : left
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** A private room cannot itself parent another private room. Suspend both edges of any merged chain. */
|
|
52
|
+
export function reconcileAccountLanes(rooms) {
|
|
53
|
+
const parents = new Map(rooms.filter(r => r.shared && !r.detachedLane).map(r => [r.room, r]))
|
|
54
|
+
const suspend = new Map()
|
|
55
|
+
for (const child of parents.values()) {
|
|
56
|
+
const parent = parents.get(child.shared)
|
|
57
|
+
if (!parent) continue
|
|
58
|
+
const at = Math.max(Number(child.associationAt || child.at) || 1, Number(parent.associationAt || parent.at) || 1)
|
|
59
|
+
for (const r of [parent, child]) suspend.set(r.room, Math.max(at, suspend.get(r.room) || 0))
|
|
60
|
+
}
|
|
61
|
+
return rooms.map(r => {
|
|
62
|
+
if (!suspend.has(r.room)) return r
|
|
63
|
+
const detached = { ...r, kind: 'space', detachedLane: true, associationAt: suspend.get(r.room) }
|
|
64
|
+
delete detached.shared
|
|
65
|
+
delete detached.laneOrigin
|
|
66
|
+
return detached
|
|
67
|
+
})
|
|
68
|
+
}
|
package/laneConfig.js
CHANGED
|
@@ -15,11 +15,12 @@ const toolName = (t) => (t && typeof t === 'object' ? t.name : t)
|
|
|
15
15
|
/** The shared room's tools a lane takes on (the app's lanes do: the member's assistant can search what the room's can). */
|
|
16
16
|
export function inheritToolsFrom (sharedConfig) {
|
|
17
17
|
const c = sharedConfig && typeof sharedConfig === 'object' ? sharedConfig : null
|
|
18
|
-
|
|
18
|
+
const inherited = c && (c.platformTools === false || Array.isArray(c.platformTools)) ? { platformTools: Array.isArray(c.platformTools) ? [...c.platformTools] : false } : {}
|
|
19
|
+
if (!c || !Array.isArray(c.tools)) return inherited
|
|
19
20
|
const tools = c.tools.filter((t) => !LANE_WITHHELD.has(toolName(t)))
|
|
20
|
-
if (!tools.length) return
|
|
21
|
+
if (!tools.length) return inherited
|
|
21
22
|
const immediate = Array.isArray(c.immediateTools) ? c.immediateTools.filter((n) => !LANE_WITHHELD.has(n)) : []
|
|
22
|
-
return { tools, ...(immediate.length ? { immediateTools: immediate } : {}) }
|
|
23
|
+
return { ...inherited, tools, ...(immediate.length ? { immediateTools: immediate } : {}) }
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
/** WHAT A PRIVATE LANE TAKES FROM ITS SPACE: everything but the members (the owner, 2026-10-15: "the private lane inherits
|