@witbitz/sdk 4.4.0 → 4.5.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 +15 -0
- package/accountErase.js +9 -3
- package/accountIndexDoc.js +24 -7
- package/accountRecord.js +6 -2
- package/accountStores.js +21 -5
- package/acctV2App.js +111 -12
- package/acctV2Client.js +11 -1
- package/acctV2UiCore.js +27 -7
- package/awsKey.js +3 -1
- package/backupRecord.js +3 -0
- package/codeAttachments.js +1 -0
- package/codeCache.js +27 -3
- package/codeCloud.js +2 -0
- package/codeComputers.js +8 -0
- package/codeSent.js +43 -2
- package/codeTransport.js +24 -5
- package/connections.js +21 -3
- package/decrypt.html +69 -9
- package/eraseFile.js +15 -0
- package/idbSeal.js +5 -2
- package/inviteReceive.js +44 -0
- package/inviteSend.js +8 -2
- package/l1-worker-src.js +1 -1
- package/l1-worker.js +30 -14
- package/laneAssociation.js +11 -1
- package/laneLinkCore.js +9 -0
- package/ledgerView.js +30 -4
- package/manifest.json +78 -72
- package/offlineBundle.js +21 -0
- package/package.json +8 -2
- package/protectedLocal.js +34 -11
- package/reactionHolders.js +86 -0
- package/roomIntake.js +324 -0
- package/roomRoster.js +9 -2
- package/scheduleNext.js +60 -0
- package/sdkA2A.js +46 -8
- package/sdkAccount.js +71 -14
- package/sdkAccountDoc.js +3 -3
- package/sdkAccountSections.js +58 -18
- package/sdkAgui.js +33 -6
- package/sdkBackup.js +21 -6
- package/sdkBackupV2.js +15 -3
- package/sdkCloudDevice.js +12 -3
- package/sdkComputers.js +118 -17
- package/sdkDictation.js +1 -1
- package/sdkErase.js +3 -1
- package/sdkExports.js +15 -6
- package/sdkInvitations.js +4 -2
- package/sdkKeptAgent.js +19 -3
- package/sdkKeptIntake.js +100 -0
- package/sdkLaneLink.js +5 -6
- package/sdkRekey.js +72 -5
- package/sdkSchedules.js +8 -1
- package/sdkSpeech.js +14 -1
- package/sdkTemporaryRooms.js +2 -1
- package/sdkTurn.js +12 -4
- package/sharedViews.js +17 -1
- package/siri.js +29 -5
- package/spaceClient.js +96 -12
- package/spaceExport.js +50 -5
- package/spaceFork.js +15 -7
- package/spaceTemplates.js +2 -2
- package/speechOut.js +17 -3
- package/store.js +51 -13
- package/sw-notif-core.js +2 -1
- package/tapTrail.js +58 -0
- package/usageReceipts.js +12 -5
- package/vault-core.js +90 -16
- package/vault-kit.mjs +2 -2
- package/vault-screens.js +25 -11
- package/vaultAtRest.js +3 -2
- package/vaultCoreLock.js +3 -1
- package/vaultCorePush.js +58 -7
- package/vaultWorkerHost.js +9 -3
- package/witbitz-admin.d.ts +3 -0
- package/witbitz-admin.mjs +10 -10
- package/witbitz-sdk.d.ts +59 -23
- package/witbitz-sdk.js +271 -64
package/spaceTemplates.js
CHANGED
|
@@ -30,7 +30,7 @@ export const SPACE_TEMPLATES = [
|
|
|
30
30
|
{
|
|
31
31
|
id: 'team-decision',
|
|
32
32
|
display: 'Team — decide together',
|
|
33
|
-
blurb: 'A small team
|
|
33
|
+
blurb: 'A small team works toward a decision together; the facilitator notes where you agree and the question still open.', // no approval step: a template is a name + persona (side sweep: sdk-template-preview-promises-group-approval)
|
|
34
34
|
keyModel: { k: 2, n: 3 }, // any 2 of the team's members can open it (Shamir k-of-n) — the generalized key model
|
|
35
35
|
agentName: 'Facilitator',
|
|
36
36
|
persona:
|
|
@@ -45,7 +45,7 @@ export const SPACE_TEMPLATES = [
|
|
|
45
45
|
{
|
|
46
46
|
id: 'mediation',
|
|
47
47
|
display: 'Mediation — two parties + a neutral',
|
|
48
|
-
blurb: 'Two parties and a neutral mediator work toward a written agreement
|
|
48
|
+
blurb: 'Two parties and a neutral mediator work toward a written agreement, drafted in plain language once you converge.',
|
|
49
49
|
keyModel: '2-of-2', // both parties present to open (the money-attached vertical the roadmap flags)
|
|
50
50
|
agentName: 'Mediator',
|
|
51
51
|
persona:
|
package/speechOut.js
CHANGED
|
@@ -83,13 +83,27 @@ export function createTtsPlayer ({ getKey, checkKey = checkSpeechKey, fetchImpl
|
|
|
83
83
|
const mine = ++session; ctrl = new AbortController(); const signal = ctrl.signal
|
|
84
84
|
self.playing = true
|
|
85
85
|
try {
|
|
86
|
-
|
|
86
|
+
let k = await freshKey()
|
|
87
87
|
if (session !== mine) return
|
|
88
|
-
|
|
88
|
+
// ⛔ A KEY'S CAP IS NOT THE END OF THE READING (side sweep: read-aloud-key-cap-restarts-long-reply): every chunk of one reading
|
|
89
|
+
// used one capped key; its 402 cleared the key and ended playback, and the next Play started again at chunk one — a reply
|
|
90
|
+
// longer than one key's allowance stopped at the same place every time. A 402 now takes a NEW key (op 'tts' — its own hourly
|
|
91
|
+
// limit bounds this) once, and the same chunk is asked again; a chunk asked with an older key just goes again on the new one.
|
|
92
|
+
let renewing = null
|
|
93
|
+
const fetchRenewing = async (text) => {
|
|
94
|
+
const used = k
|
|
95
|
+
try { return await fetchChunk(text, used, signal) } catch (e) {
|
|
96
|
+
if (!(e && e.code === 'http_402') || session !== mine) throw e
|
|
97
|
+
if (k === used) { renewing = renewing || freshKey().then((nk) => { k = nk; renewing = null; return nk }, (er) => { renewing = null; throw er }); await renewing }
|
|
98
|
+
if (session !== mine) throw Object.assign(new Error('stopped'), { code: 'stopped' })
|
|
99
|
+
return fetchChunk(text, k, signal)
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
let next = fetchRenewing(chunks[0])
|
|
89
103
|
for (let i = 0; i < chunks.length; i++) {
|
|
90
104
|
const blob = await next
|
|
91
105
|
if (session !== mine) return
|
|
92
|
-
next = i + 1 < chunks.length ?
|
|
106
|
+
next = i + 1 < chunks.length ? fetchRenewing(chunks[i + 1]) : null // one ahead, while this one plays
|
|
93
107
|
if (next) next.catch(() => {}) // judged when awaited; never an unhandled rejection
|
|
94
108
|
await playBlob(blob, signal)
|
|
95
109
|
if (session !== mine) return
|
package/store.js
CHANGED
|
@@ -96,22 +96,39 @@ export const isCloudKept = (r) => !!r && !!((recentOf(r) || {}).alwaysOn)
|
|
|
96
96
|
/** Set or clear a Space's always-on mark in the account's room list (→ synced to every device). Only a change is written. */
|
|
97
97
|
export function setAlwaysOn (r, on, now = Date.now()) {
|
|
98
98
|
if (!r || isCloudKept(r) === !!on) return false
|
|
99
|
-
mutateRecent(r, (it) => { it.alwaysOn = !!on; it.alwaysOnAt = now })
|
|
99
|
+
mutateRecent(r, (it) => { it.alwaysOn = !!on; it.alwaysOnAt = Math.max(now, (Number(it.alwaysOnAt) || 0) + 1) }) // after the mark it replaces (side sweep 2026-11-28: a Keep dated ahead of this clock won the sync over a later release here), as the SDK does
|
|
100
100
|
return isCloudKept(r) === !!on
|
|
101
101
|
}
|
|
102
102
|
/** The cloud device was signed out (here, or from the hosted vault's account screen): no Space is kept any more. */
|
|
103
103
|
export function clearAlwaysOn (now = Date.now()) { for (const r of loadRecents()) if (r && r.alwaysOn) setAlwaysOn(r.room, false, now) }
|
|
104
104
|
/** The cloud device answered which Spaces it holds (its card): a Space it runs is kept, so its mark is set (a Space kept before the
|
|
105
105
|
* mark existed arrives here). A Space it does NOT hold keeps its mark: that is the card's warning to show (the device let it go, or
|
|
106
|
-
* was signed out) — never a silent change. The old one-device list is dropped.
|
|
107
|
-
|
|
108
|
-
|
|
106
|
+
* was signed out) — never a silent change. The old one-device list is dropped. `readAt` = when the device was asked: a Space taken
|
|
107
|
+
* off AFTER that (here or on another device, synced meanwhile) keeps its Off — the answer is older than the release (side sweep:
|
|
108
|
+
* always-on-delayed-status-restores-released-mark). */
|
|
109
|
+
export function adoptCloudKept (rooms, now = Date.now(), readAt = 0) {
|
|
110
|
+
const releasedSince = (r) => { const it = recentOf(r); return !!readAt && !!it && it.alwaysOn === false && (Number(it.alwaysOnAt) || 0) > readAt }
|
|
111
|
+
for (const r of new Set((rooms || []).filter((x) => typeof x === 'string'))) if (!releasedSince(r)) setAlwaysOn(r, true, now)
|
|
109
112
|
try { localStorage.removeItem(CD_KEPT_OLD) } catch { /* */ }
|
|
110
113
|
}
|
|
111
114
|
export const KEPT_NO_LINKS = 'Your cloud device keeps this Space always on, and it takes only a Space with no private lane of its own. Stop keeping it always on first (⋯ → Assistant → Always on).'
|
|
112
115
|
export const KEPT_NO_PEOPLE = 'Your cloud device keeps this Space always on, and it takes only a Space that is yours alone. Stop keeping it always on first (⋯ → Assistant → Always on).'
|
|
113
116
|
export const wantsLanes = (r) => { try { return localStorage.getItem(lanesKey(r)) === '1' } catch { return false } }
|
|
114
117
|
export const CONTACTS_KEY = 'space:contacts'
|
|
118
|
+
// ⛔ A FIELD CLEARED IN THE EDITOR STAYS CLEARED (side sweep: contact-sync-restores-cleared-fields). The editor's row simply lacked a
|
|
119
|
+
// removed phone or @username, so a merge (Object.assign) onto another device's row kept the old value, and an older row refilled a
|
|
120
|
+
// name deliberately emptied. The editor names what it emptied — `cleared`, an ADDITIVE field (an older app ignores it and merges as
|
|
121
|
+
// before) — and mergeContactLists / dedupePeople honour it: a newer row's cleared field is removed, and no older row refills it.
|
|
122
|
+
const CLEARABLE = ['fn', 'tel', 'username']
|
|
123
|
+
/** The fields `prior` (the row being edited) had and the edited `rec` no longer has — what the person cleared — and the ones an
|
|
124
|
+
* EARLIER edit cleared that are still empty: a later rename replaced the row with one that named only its own clears, and a device
|
|
125
|
+
* that missed the first edit kept the removed phone (side sweep cycle 165, contact-sync-restores-cleared-fields revised). */
|
|
126
|
+
export function clearedFields(prior, rec) {
|
|
127
|
+
if (!prior || typeof prior !== 'object') return []
|
|
128
|
+
const empty = (f) => !String((rec && rec[f]) || '').trim()
|
|
129
|
+
return CLEARABLE.filter((f) => empty(f) && (String(prior[f] || '').trim() || isCleared(prior, f)))
|
|
130
|
+
}
|
|
131
|
+
const isCleared = (c, f) => !!(c && Array.isArray(c.cleared) && c.cleared.includes(f))
|
|
115
132
|
export function normContact(c) {
|
|
116
133
|
if (!c || typeof c !== 'object') return null
|
|
117
134
|
if (c.kind === 'agent') {
|
|
@@ -124,7 +141,8 @@ export function normContact(c) {
|
|
|
124
141
|
const email = (typeof c.email === 'string' && c.email.indexOf('@') > 0) ? c.email.trim().toLowerCase() : ''
|
|
125
142
|
const username = (typeof c.username === 'string' && /^[a-z0-9][a-z0-9_]{2,29}$/.test(String(c.username).trim().toLowerCase().replace(/^@/, ''))) ? String(c.username).trim().toLowerCase().replace(/^@/, '') : ''
|
|
126
143
|
if (!email && !username) return null
|
|
127
|
-
|
|
144
|
+
const cleared = Array.isArray(c.cleared) ? CLEARABLE.filter((f) => c.cleared.includes(f)) : [] // what the editor emptied (contact-sync-restores-cleared-fields)
|
|
145
|
+
return { kind: 'person', fn: typeof c.fn === 'string' ? c.fn.trim().slice(0, 80) : '', ...(email ? { email } : {}), ...(username ? { username } : {}), ...(typeof c.handle === 'string' && /^[A-Za-z0-9_-]{43}$/.test(c.handle) ? { handle: c.handle } : {}), ...(c.tel ? { tel: String(c.tel).slice(0, 40) } : {}), ...(c.at ? { at: +c.at || 0 } : {}), ...(cleared.length ? { cleared } : {}), deleted: !!c.deleted } // `deleted` = a TOMBSTONE for a removed person; `at` gives persons LWW so a delete/edit survives the union merge
|
|
128
146
|
}
|
|
129
147
|
// The one key a contact is deduped and merged by: an agent by id, a person by email, else by "@username".
|
|
130
148
|
export const contactKey = (c) => c && (c.kind === 'agent' ? 'a:' + c.id : (c.email || (c.username ? '@' + c.username : undefined)))
|
|
@@ -155,9 +173,10 @@ export function dedupePeople(list) {
|
|
|
155
173
|
for (const [r, g] of groups) {
|
|
156
174
|
if (g.length === 1) { merged.set(r, g[0]); continue }
|
|
157
175
|
const by = g.slice().sort((a, b) => (b.at || 0) - (a.at || 0)) // newest first
|
|
158
|
-
const pick = (f) => (by
|
|
176
|
+
const pick = (f) => { for (const c of by) { if (c[f]) return c[f]; if (isCleared(c, f)) return undefined } return undefined } // a newer row that CLEARED it: no older row fills it
|
|
159
177
|
const out = { kind: 'person', fn: pick('fn') || '' }
|
|
160
178
|
for (const f of ['email', 'username', 'handle', 'tel']) { const v = pick(f); if (v) out[f] = v }
|
|
179
|
+
if (Array.isArray(by[0].cleared) && by[0].cleared.length) out.cleared = by[0].cleared.slice()
|
|
161
180
|
const at = by[0].at || 0; if (at) out.at = at
|
|
162
181
|
out.deleted = !!by[0].deleted
|
|
163
182
|
merged.set(r, out)
|
|
@@ -474,6 +493,10 @@ export function mergeSiriRecords(cur, inc) {
|
|
|
474
493
|
}
|
|
475
494
|
export function loadSiri() { try { return normSiri(JSON.parse(lsGet(SIRI_KEY) || 'null')) } catch { return normSiri(null) } }
|
|
476
495
|
export function saveSiri(o) { const n = normSiri(o); try { localStorage.setItem(SIRI_KEY, JSON.stringify(n)) } catch { /* private mode */ } try { dispatchEvent(new CustomEvent('wb-siri-changed')) } catch { /* no window (the SDK, tests) */ } return n } // the change event: the iPhone app's Siri list follows (siriHeld.js syncSiriToNative)
|
|
496
|
+
/** A Siri capture for `room` said BEFORE the Space was last taken off Siri (`gone[room]`, kept across a re-enable): Stop promised to
|
|
497
|
+
* discard it, so it is never posted — turning Siri back on before it expired posted the old words (side sweep: siri-intake-capture-
|
|
498
|
+
* survives-room-removal). No time on the capture, or never stopped: false (as before). */
|
|
499
|
+
export const siriCaptureStopped = (room, at, o = loadSiri()) => { const g = o && o.gone && Number(o.gone[room]); return !!(g && Number(at) > 0 && Number(at) <= g) }
|
|
477
500
|
export const siriConfigured = (o = loadSiri()) => !!((o.token || o.tokenHash) && Object.keys(o.rooms).length)
|
|
478
501
|
/** Union a synced/restored copy in — the newer entry per Space (mergeSiriRecords). Returns true on a change. */
|
|
479
502
|
export function mergeSiri(incoming) {
|
|
@@ -551,8 +574,17 @@ export function mergeContactLists(list, incoming) {
|
|
|
551
574
|
const c = normContact(raw); if (!c) continue; const k = contactKey(c); const ex = byKey.get(k)
|
|
552
575
|
if (!ex) { out.push(c); byKey.set(k, c); changed = true }
|
|
553
576
|
else if (c.kind === 'agent') { if ((c.at || 0) >= (ex.at || 0)) { Object.assign(ex, c); changed = true } } // adopt a newer saved-assistant edit (LWW)
|
|
554
|
-
else if ((c.at || 0) > (ex.at || 0)) {
|
|
555
|
-
|
|
577
|
+
else if ((c.at || 0) > (ex.at || 0)) { // person LWW: a newer edit / tombstone wins (equal-or-older at-less persons fall through to fill-name)
|
|
578
|
+
Object.assign(ex, c)
|
|
579
|
+
// A TOMBSTONE IS ONLY WHAT IT NAMES (side sweep cycle 165, contact-email-clear-rejoined-by-username): an edit that removed the
|
|
580
|
+
// email but kept the @username writes a tombstone for the email alone; kept here with the old row's username, the one-person
|
|
581
|
+
// merge (dedupePeople) joined it to the live row by that username and copied the removed email back onto it.
|
|
582
|
+
if (c.deleted) for (const f of ['email', 'username', 'handle', 'tel']) { if (!c[f]) delete ex[f] }
|
|
583
|
+
for (const f of c.cleared || []) { if (f === 'fn') ex.fn = ''; else delete ex[f] } // what that edit cleared goes here too
|
|
584
|
+
if (!c.cleared) delete ex.cleared
|
|
585
|
+
changed = true
|
|
586
|
+
}
|
|
587
|
+
else if (c.fn && !ex.fn && !isCleared(ex, 'fn')) { ex.fn = c.fn; changed = true } // learned a name for a known address — not one the person emptied
|
|
556
588
|
}
|
|
557
589
|
return { list: out, changed }
|
|
558
590
|
}
|
|
@@ -583,13 +615,19 @@ export const personalAgentUI = () => { try { return localStorage.getItem('space:
|
|
|
583
615
|
export const agentLinks = () => { try { const a = JSON.parse(localStorage.getItem(AGENT_LINKS_KEY) || '[]'); return Array.isArray(a) ? a : [] } catch { return [] } }
|
|
584
616
|
export const inAgentLinks = (r) => agentLinks().includes(r)
|
|
585
617
|
export const toggleAgentLink = (r) => { const s = new Set(agentLinks()); s.has(r) ? s.delete(r) : s.add(r); try { localStorage.setItem(AGENT_LINKS_KEY, JSON.stringify([...s].slice(0, 24))) } catch { /* */ } }
|
|
586
|
-
|
|
618
|
+
// WHEN THE NAME WAS SET (side sweep app-index-push-reverts-account-display-name): `at` = the time a person TYPED it (nameGate), or
|
|
619
|
+
// the account index's `nameAt` for a name taken from there. The index carries it as `nameAt`, so a device still holding an older
|
|
620
|
+
// name no longer writes it back over a rename made on another device. 0 = not known (an older device, a restored name).
|
|
621
|
+
const NAME_AT_KEY = 'space:myname-at'
|
|
622
|
+
export const loadNameAt = () => { try { const n = Number(localStorage.getItem(NAME_AT_KEY)); return Number.isFinite(n) && n > 0 ? n : 0 } catch { return 0 } }
|
|
623
|
+
export const saveName = (n, { at } = {}) => { state.myName = String(n || '').trim().slice(0, 24); try { localStorage.setItem('space:myname', state.myName); if (Number(at) > 0) localStorage.setItem(NAME_AT_KEY, String(Number(at))) } catch { /* */ } }
|
|
587
624
|
/** A name learned from the account — the backup or the account's room list — not typed here: saved, and a "What's your name?"
|
|
588
625
|
* already waiting is answered with it (nameGate.nameArrived, wired in space.js; the owner, 2026-10-25: "Why is your name still
|
|
589
|
-
* required after restore?"). */
|
|
590
|
-
export const adoptName = (n) => {
|
|
591
|
-
const v = String(n || '').trim(); if (!v
|
|
592
|
-
|
|
626
|
+
* required after restore?"). `at`: the account's time for it — a NEWER one than this device's replaces a name held here. */
|
|
627
|
+
export const adoptName = (n, at = 0) => {
|
|
628
|
+
const v = String(n || '').trim(); if (!v) return false
|
|
629
|
+
if (state.myName && !(Number(at) > loadNameAt() && v !== state.myName)) return false
|
|
630
|
+
saveName(v, { at })
|
|
593
631
|
try { if (typeof dispatchEvent === 'function' && typeof CustomEvent === 'function') dispatchEvent(new CustomEvent('wb-name-arrived', { detail: { name: state.myName } })) } catch { /* */ }
|
|
594
632
|
return true
|
|
595
633
|
}
|
package/sw-notif-core.js
CHANGED
|
@@ -367,7 +367,8 @@ self.wbxWirePush = (cfg) => self.addEventListener('push', (e) => {
|
|
|
367
367
|
await self.wbxNoteShown(room, tag, id)
|
|
368
368
|
await self.registration.showNotification(d ? d.title : cfg.generic.title, { body: d ? d.body : cfg.generic.body, tag, data: { room, id }, ...art, silent, renotify: !silent })
|
|
369
369
|
// …and iOS ignores `silent`: the room on screen is closed at once (it was shown, which is what iOS requires).
|
|
370
|
-
|
|
370
|
+
// closed here, not by the person: forgotten, or the vault later reads it as a tap and reopens this room (side sweep 2026-11-28)
|
|
371
|
+
if (viewing && await self.wbxQuietIfViewing(room, tag)) { await self.wbxForgetShown(tag, id); await self.wbxNoteSw('closed at once — the room is on screen') }
|
|
371
372
|
else if (room) await self.wbxBadgeAdd(room) // the number on the app's icon counts it until it is read (appBadge.js)
|
|
372
373
|
// The push carried the preview, so describe() did not run: run it now for its PREFETCH — after the notification is up,
|
|
373
374
|
// so a slow or refused fetch never delays or blanks what is shown.
|
package/tapTrail.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// spaces/public/tapTrail.js — a device-only log of what happened to each tapped notification (2026-10-01).
|
|
2
|
+
//
|
|
3
|
+
// A tap crosses up to four hands — the service worker, the vault page, the app frame, the room opener — and every one
|
|
4
|
+
// of them failed SILENTLY: the owner's "I press it and it doesn't open the room" could be any of them, an iPhone push
|
|
5
|
+
// can't be reproduced off the device, and the only on-device log showed only when the app failed to boot. So each hand
|
|
6
|
+
// writes one line here, and the crash-trail view (Settings → five taps on the build line) shows them. The vault keeps
|
|
7
|
+
// its own copy under its own origin and hands it to the app on request. Never sent anywhere. Leaf: localStorage only.
|
|
8
|
+
export function makeTapTrail(key, max = 24) {
|
|
9
|
+
const read = () => { try { const a = JSON.parse(localStorage.getItem(key) || '[]'); return Array.isArray(a) ? a : [] } catch { return [] } }
|
|
10
|
+
// A REPEAT IS ONE LINE, COUNTED (the owner's boot log, 2026-10-20): "worker: index read: 7 rooms …" every few seconds filled
|
|
11
|
+
// the vault's 24 lines, so the slow launch the log was opened to explain had already rotated out. The same line again is
|
|
12
|
+
// folded into the last one — its first time kept, "×N, last <time>" appended — so what is different keeps its place.
|
|
13
|
+
const STAMP = /^\S+(?: [AP]M)? /
|
|
14
|
+
const REPEAT = / \(×(\d+), last [^)]*\)$/
|
|
15
|
+
const note = (line) => {
|
|
16
|
+
try {
|
|
17
|
+
const a = read()
|
|
18
|
+
const now = new Date().toLocaleTimeString([], { hour: '2-digit', minute: '2-digit', second: '2-digit' })
|
|
19
|
+
const msg = String(line).slice(0, 500) // 500: the boot line carries every mark of the open (bootReport) — at 200 the ones that explain a slow open (index sync, room entered, cache drawn) were cut off (2026-10-21)
|
|
20
|
+
const prev = a.length ? a[a.length - 1] : ''
|
|
21
|
+
const head = prev.match(STAMP)
|
|
22
|
+
const body = head ? prev.slice(head[0].length) : ''
|
|
23
|
+
if (head && body.replace(REPEAT, '') === msg) {
|
|
24
|
+
const m = body.match(REPEAT)
|
|
25
|
+
a[a.length - 1] = head[0] + msg + ` (×${m ? Number(m[1]) + 1 : 2}, last ${now})`
|
|
26
|
+
localStorage.setItem(key, JSON.stringify(a))
|
|
27
|
+
return
|
|
28
|
+
}
|
|
29
|
+
a.push(now + ' ' + msg)
|
|
30
|
+
while (a.length > max) a.shift()
|
|
31
|
+
localStorage.setItem(key, JSON.stringify(a))
|
|
32
|
+
} catch { /* a diagnostic must never be the thing that breaks the tap */ }
|
|
33
|
+
}
|
|
34
|
+
const clear = () => { try { localStorage.removeItem(key) } catch { /* */ } }
|
|
35
|
+
return { note, read, clear }
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** A room id as the trail shows it — enough to tell two rooms apart on a screenshot, not the whole id. */
|
|
39
|
+
export const roomTag = (r) => (r ? String(r).slice(0, 10) : '-')
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Keep looking for a tapped room for a while after a launch or a foreground, instead of at one instant.
|
|
43
|
+
* On an iPhone, tapping a notification resumes the page (visibilitychange fires at once) and wakes the service worker in
|
|
44
|
+
* parallel; the worker writes the tapped room only once it has booted, often a beat AFTER the page looked. A single look
|
|
45
|
+
* missed it and the app stayed on its last room (the owner, 2026-10-01). `check()` resolves truthy once a tap was
|
|
46
|
+
* routed, which ends the watch; `start()` (re)opens a window of `forMs`, looking every `everyMs`.
|
|
47
|
+
*/
|
|
48
|
+
export function watchForTap(check, { everyMs = 500, forMs = 15000, now = Date.now, setT = setTimeout } = {}) {
|
|
49
|
+
let until = 0, running = false
|
|
50
|
+
const tick = async () => {
|
|
51
|
+
let hit = false
|
|
52
|
+
try { hit = !!(await check()) } catch { /* a failed look is just a miss */ }
|
|
53
|
+
if (hit) until = 0
|
|
54
|
+
if (now() < until) setT(tick, everyMs); else running = false
|
|
55
|
+
}
|
|
56
|
+
const start = () => { until = now() + forMs; if (!running) { running = true; tick() } }
|
|
57
|
+
return { start }
|
|
58
|
+
}
|
package/usageReceipts.js
CHANGED
|
@@ -58,7 +58,10 @@ export async function receiptFor (key, room) { return key ? { drop: await dropFo
|
|
|
58
58
|
// ── the sidecar: `usage-YYYY-MM` = { v:1, r: { <receipt id>: [day, payer, costMicros, in, out] } } ──
|
|
59
59
|
export const monthOf = (ts) => { const d = new Date(ts); return d.getUTCFullYear() + '-' + String(d.getUTCMonth() + 1).padStart(2, '0') }
|
|
60
60
|
export const docNameFor = (month) => 'usage-' + month
|
|
61
|
-
|
|
61
|
+
// A sixth field, 1, when the reply's total counts only its priced calls (receipt `source` 'provider-partial' or 'none'): ADDITIVE —
|
|
62
|
+
// a reader that knows five fields reads the first five (side sweep: account-usage-drops-partial-price)
|
|
63
|
+
const unpricedSource = (s) => s === 'provider-partial' || s === 'none'
|
|
64
|
+
const row = (b) => [new Date(b.ts).getUTCDate(), Math.max(0, PAYERS.indexOf(b.payer)), Math.max(0, Math.round(Number(b.costMicros) || 0)), Math.max(0, Math.round(Number(b.in) || 0)), Math.max(0, Math.round(Number(b.out) || 0)), ...(unpricedSource(b.source) ? [1] : [])]
|
|
62
65
|
|
|
63
66
|
/** Merge receipts into a month doc (idempotent by receipt id). */
|
|
64
67
|
export function foldInto (doc, bodies) {
|
|
@@ -68,12 +71,14 @@ export function foldInto (doc, bodies) {
|
|
|
68
71
|
}
|
|
69
72
|
/** A month doc → totals: costMicros overall and by payer, replies, tokens, and per day. */
|
|
70
73
|
export function usageTotals (doc) {
|
|
71
|
-
|
|
74
|
+
// unpriced: replies whose cost counts only their priced calls — the total is then a floor, as the room's Usage says
|
|
75
|
+
const t = { costMicros: 0, replies: 0, in: 0, out: 0, unpriced: 0, byPayer: Object.fromEntries(PAYERS.map((p) => [p, 0])), byDay: {} }
|
|
72
76
|
for (const v of Object.values((doc && doc.r) || {})) {
|
|
73
77
|
if (!Array.isArray(v)) continue
|
|
74
|
-
const [day, pi, cost, i, o] = v
|
|
78
|
+
const [day, pi, cost, i, o, partial] = v
|
|
75
79
|
const payer = PAYERS[pi] || 'witbitz'
|
|
76
80
|
t.costMicros += cost; t.replies++; t.in += i; t.out += o; t.byPayer[payer] += cost
|
|
81
|
+
if (partial === 1) t.unpriced++
|
|
77
82
|
t.byDay[day] = (t.byDay[day] || 0) + cost
|
|
78
83
|
}
|
|
79
84
|
return t
|
|
@@ -127,10 +132,12 @@ export async function collectUsage ({ key, rooms, read, ack, readDoc, writeDoc,
|
|
|
127
132
|
}
|
|
128
133
|
}
|
|
129
134
|
await Promise.all(Array.from({ length: Math.min(READS_AT_ONCE, rooms.length) }, (_, w) => worker(w)))
|
|
135
|
+
let unread = 0 // Spaces whose receipts could not be read now (no answer, a server error, a limit) — said to the reader, not passed over (side sweep: account-usage-unread-room-looks-current)
|
|
130
136
|
for (const f of fetched) {
|
|
131
137
|
if (!f) continue
|
|
132
138
|
const { room, drop, ck, c, r } = f
|
|
133
|
-
if (!r || r.status
|
|
139
|
+
if (!r || r.status >= 500 || r.status === 429) { unread++; continue }
|
|
140
|
+
if (r.status !== 200 || !Array.isArray(r.boxes)) continue
|
|
134
141
|
const items = []
|
|
135
142
|
for (let i = 0; i < r.boxes.length; i++) {
|
|
136
143
|
let b = null
|
|
@@ -172,5 +179,5 @@ export async function collectUsage ({ key, rooms, read, ack, readDoc, writeDoc,
|
|
|
172
179
|
const pos = Number.isInteger(p.end) ? p.end : p.c.pos
|
|
173
180
|
if (pos !== p.c.pos || keep.length !== p.c.pend.length) cursor.set(p.ck, { pos, pend: keep }) // a quiet room costs no write
|
|
174
181
|
}
|
|
175
|
-
return { folded, rooms: perRoom.filter((p) => p.items.length).length, cleared }
|
|
182
|
+
return { folded, rooms: perRoom.filter((p) => p.items.length).length, cleared, unread }
|
|
176
183
|
}
|
package/vault-core.js
CHANGED
|
@@ -77,6 +77,7 @@ export const ACCOUNT_CALLS = {
|
|
|
77
77
|
// (SERVICE_CALLS, below: the three that need an account on the service — checked before their confirm)
|
|
78
78
|
account: { repairNames: {}, previewEmptySpaces: {}, removeEmptySpaces: {}, listDevices: {}, signOutDevice: {}, sync: {}, start: {}, stop: {}, archive: {}, pin: {}, rename: {}, forget: { confirm: true }, signOut: { confirm: true }, noteLink: {}, dropLink: {}, section: {}, usage: {} }, // section: wb.account.contacts / .name / .roomDefaults (sdkAccountSections.js — the person's own data, no key; plan phase 5) // usage: what the account used, from its receipts (2026-10-23) // noteLink/dropLink: lane.link() across devices (sync sweep, 10-17 #6)
|
|
79
79
|
erasure: { file: {}, status: {} },
|
|
80
|
+
invite: { collect: {} }, // the invitations delivered to this account: the vault asks before joining, the page gets rooms only (inviteCollect)
|
|
80
81
|
}
|
|
81
82
|
/** The backup calls that need an account on the Witbitz account service (sync sweep 11-16 #15). */
|
|
82
83
|
const SERVICE_CALLS = new Set(['manageSecurityKeys', 'signOutOthers', 'newRecoveryCode', 'emailMove', 'requestMoveTime', 'cancelEmailMove'])
|
|
@@ -141,6 +142,15 @@ export function vaultSignInWords(e) {
|
|
|
141
142
|
return e
|
|
142
143
|
}
|
|
143
144
|
|
|
145
|
+
/** A JOB AGENT'S TRIGGER for a key adopted after a lost reply (side sweep: sdk-recovered-job-connection-loses-trigger-settings): the
|
|
146
|
+
* Sentinel's listing names a one-path trigger under `rules` and holds no job settings — those were kept with the pending key, as the
|
|
147
|
+
* direct SDK's `connections.recover` reads them. A row that already carries `webhook` is taken as it is. */
|
|
148
|
+
export function adoptedHook(row, k) {
|
|
149
|
+
if (row && typeof row.webhook === 'string') return { webhook: row.webhook, ...(row.webhook && row.job && typeof row.job === 'object' ? { job: row.job } : {}) }
|
|
150
|
+
const path = row && row.sign && Array.isArray(row.rules?.paths) && row.rules.paths.length === 1 ? row.rules.paths[0] : ''
|
|
151
|
+
return path ? { webhook: path, ...(k && k.job && typeof k.job === 'object' ? { job: k.job } : {}) } : {}
|
|
152
|
+
}
|
|
153
|
+
|
|
144
154
|
export function configForPage(cfg) {
|
|
145
155
|
if (!cfg || typeof cfg !== 'object') return cfg
|
|
146
156
|
const out = { ...cfg }
|
|
@@ -207,7 +217,7 @@ export async function startVault(o = {}) {
|
|
|
207
217
|
hide: () => { frameHidden = true; if (frameEl) frameEl.style.display = 'none' },
|
|
208
218
|
show: () => { frameHidden = false; if (frameEl) frameEl.style.display = 'block' },
|
|
209
219
|
onState: (lock) => { if (frameEl) { emit({ ev: 'lock', lock }); queuePushPrivacy() } },
|
|
210
|
-
confirm: (q) => (typeof screens.confirm === 'function' ? screens.confirm(q) : Promise.resolve(window.confirm(q.title))),
|
|
220
|
+
confirm: (q) => (typeof screens.confirm === 'function' ? screens.confirm(q) : Promise.resolve(window.confirm(q.text ? q.title + '\n\n' + q.text : q.title))), // the warning goes with the question, never the title alone (side sweep 11-28)
|
|
211
221
|
onUnprotected: () => workerAtRest(), // protection off: the worker's store goes back under the device key, never clear
|
|
212
222
|
beforeProtect: async () => { if (workerDeviceKey) { await unprotectIdb(idb, workerDeviceKey); await wcall({ t: 'unprotect', key: workerDeviceKey }) } }, // remove the old device-key copies before resealing with the passkey
|
|
213
223
|
})
|
|
@@ -229,13 +239,18 @@ export async function startVault(o = {}) {
|
|
|
229
239
|
const roomPassClient = { fieldsFor: (b, o) => (roomPass ? roomPass.client.fieldsFor(b, o) : Promise.resolve({})), /* o: { ts } — the request's time (roomPass.js sign; sync sweep 11-16 #8) */ renew: (b) => (roomPass ? roomPass.client.renew(b) : Promise.resolve()) }
|
|
230
240
|
// A SIGN-IN THAT NAMES NO APP (docs/device-gate-design.md § 12.1, `pass: app_unnamed` — a session token from before `asc`): the
|
|
231
241
|
// session is renewed once, quietly (its /refresh names this vault's tenant), and the request sent again. One renewal at a time.
|
|
232
|
-
|
|
242
|
+
// A request sent with the old sign-in and refused just AFTER a renewal finished is answered with that renewal, not another one
|
|
243
|
+
// (a burst of refused requests renewed three times under load, 2026-11-28): the session it gave names the app already.
|
|
244
|
+
let renewing = null, renewedAt = 0
|
|
245
|
+
const RENEWED_FRESH_MS = 30000
|
|
233
246
|
const renewSession = () => {
|
|
247
|
+
if (!renewing && renewedAt && Date.now() - renewedAt < RENEWED_FRESH_MS && signedIn() && sdk.session) return Promise.resolve({ idToken: sdk.session.idToken, spk: sdk.session.sign.pub })
|
|
234
248
|
if (!renewing) renewing = (async () => {
|
|
235
249
|
try {
|
|
236
250
|
if (!signedIn()) return null
|
|
237
251
|
const renewed = await sdk.refreshSession()
|
|
238
252
|
if (sdk._session !== renewed) return null
|
|
253
|
+
renewedAt = Date.now()
|
|
239
254
|
keepSession(); emit({ ev: 'session', keyId: sessionKeyId() }); scheduleRefresh()
|
|
240
255
|
return { idToken: sdk.session.idToken, spk: sdk.session.sign.pub }
|
|
241
256
|
} catch (err) {
|
|
@@ -489,6 +504,37 @@ export async function startVault(o = {}) {
|
|
|
489
504
|
joined = inv.room
|
|
490
505
|
emit({ ev: 'rooms', rooms: publicRooms() })
|
|
491
506
|
}
|
|
507
|
+
// THE INVITATIONS DELIVERED TO THIS ACCOUNT (side sweep: sdk-missing-inbox-invite-acceptance): the page's wb.invite.collect() threw
|
|
508
|
+
// vault_unsupported. The vault opens its inbox with ITS invite key, asks the person before joining a Space it does not hold (as an
|
|
509
|
+
// invite link: nothing is joined silently), keeps the links, and tells the page the rooms only — no link, no key; the page opens
|
|
510
|
+
// each with wb.vault.openRoom(room). A held room's key is never replaced by an invitation (as joinInvite).
|
|
511
|
+
async function inviteCollect() {
|
|
512
|
+
const epoch = privacyEpoch, owner = who()
|
|
513
|
+
const changed = () => epoch !== privacyEpoch || owner !== who()
|
|
514
|
+
const gone = () => Object.assign(new Error('the account changed while collecting invitations'), { code: 'account_changed' })
|
|
515
|
+
const got = await sdk.invite.collect()
|
|
516
|
+
if (changed()) throw gone()
|
|
517
|
+
const fresh = got.filter((x) => !held(x.room) && linkParts(x.link) && linkParts(x.link).room === x.room)
|
|
518
|
+
if (fresh.length) {
|
|
519
|
+
const ok = await confirmWith({ title: fresh.length === 1 ? 'Join the Space shared with you?' : 'Join the ' + fresh.length + ' Spaces shared with you?', text: 'Someone invited your account. Join on this device?', ok: 'Join', cancel: 'Not now' }).catch(() => false)
|
|
520
|
+
if (changed()) throw gone()
|
|
521
|
+
if (ok) {
|
|
522
|
+
const joinedNow = []
|
|
523
|
+
for (const x of fresh) {
|
|
524
|
+
if (held(x.room)) continue
|
|
525
|
+
const p = linkParts(x.link)
|
|
526
|
+
rooms = [{ room: x.room, ...joinedMark(x.room), link: x.link, title: '', at: Date.now(), ...(/[?#&]enc=1(?:[&#?]|$)/.test(x.link) ? { enc: true } : {}), ...(p.split ? { split: true } : {}) }, ...rooms]
|
|
527
|
+
holdLink(worker, p); seedIdentity(x.room); joinedNow.push(x.room)
|
|
528
|
+
}
|
|
529
|
+
if (joinedNow.length) {
|
|
530
|
+
await saveRooms(); pushEnclave()
|
|
531
|
+
for (const r of joinedNow) noteRoom(r).catch(() => {})
|
|
532
|
+
emit({ ev: 'rooms', rooms: publicRooms() })
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
return got.filter((x) => held(x.room)).map(({ room, title, from, at }) => ({ room, link: '', title, from, at }))
|
|
537
|
+
}
|
|
492
538
|
|
|
493
539
|
// ── the sign-in, kept and renewed here ────────────────────────────────────────────────────────────────────────────
|
|
494
540
|
const keepSession = () => { write(st, KEYS.session, sdk.session); for (const r of rooms) seedIdentity(r.room); prefetchWorker() }
|
|
@@ -651,7 +697,7 @@ export async function startVault(o = {}) {
|
|
|
651
697
|
for (const [id, k] of r.adopt) {
|
|
652
698
|
if (!conns.some(c => c.account === acct && c.id === id && c.callKey)) {
|
|
653
699
|
const row = byId.get(id)
|
|
654
|
-
conns = [{ id, label: row.label || k.label || '', host: row.host || k.host || '', callKey: k.callKey, account: acct, ...(row.mcp ? { mcp: true } : {}), ...(row.provider ? { provider: row.provider } : {}), ...
|
|
700
|
+
conns = [{ id, label: row.label || k.label || '', host: row.host || k.host || '', callKey: k.callKey, account: acct, ...(row.mcp ? { mcp: true } : {}), ...(row.provider ? { provider: row.provider } : {}), ...adoptedHook(row, k) }, ...conns]
|
|
655
701
|
}
|
|
656
702
|
}
|
|
657
703
|
let changed = false
|
|
@@ -1104,6 +1150,15 @@ export async function startVault(o = {}) {
|
|
|
1104
1150
|
return { announced: false }
|
|
1105
1151
|
}
|
|
1106
1152
|
const titleOf = (room) => { const it = rooms.find((x) => x.room === room); return it && it.title ? '“' + it.title + '”' : 'this Space' }
|
|
1153
|
+
// TWO ROOMS IN ONE PROMPT are each named, titled or not (side sweep: builder-vault-kept-link-confirmation-omits-rooms): the vault makes
|
|
1154
|
+
// rooms and lanes with no title, and two "this Space" left the pair unidentified. A lane of a titled Space is named by it; else the id.
|
|
1155
|
+
const pairName = (room) => {
|
|
1156
|
+
const it = rooms.find((x) => x.room === room)
|
|
1157
|
+
if (it && it.title) return '“' + it.title + '”'
|
|
1158
|
+
const parent = it && it.lane && rooms.find((x) => x.room === it.lane)
|
|
1159
|
+
if (parent && parent.title) return 'your lane of “' + parent.title + '”'
|
|
1160
|
+
return 'the untitled ' + (it && it.lane ? 'lane ' : 'Space ') + String(room).slice(0, 40)
|
|
1161
|
+
}
|
|
1107
1162
|
// the device whose index entry names its key (spk), on an account on the service: signed out THERE too (accountCall's signOut)
|
|
1108
1163
|
const revokesAtService = (id) => { const b = sdk.backup, d = sdk.account._devices && sdk.account._devices[id]; return !!(d && typeof d.spk === 'string' && d.spk && b._v2 && b.service === 'account' && b.enabled) }
|
|
1109
1164
|
const confirmCall = async (ns, m, args, room, kept = false) => {
|
|
@@ -1125,7 +1180,9 @@ export async function startVault(o = {}) {
|
|
|
1125
1180
|
'account.signOut': { title: 'Sign that device out of your account?', text: (revokesAtService(a) ? 'It is signed out of your account at once — we email you a code to confirm — and forgets ' : 'It forgets your account and ') + 'your Spaces the next time it is online.' + recoveryNotice(), ok: 'Sign out' },
|
|
1126
1181
|
'backup.signOutOthers': { title: 'Sign out all your other devices?', text: 'Every other device forgets your account and its Spaces the next time it opens. This device stays signed in. We email you a code to confirm.' + recoveryNotice(), ok: 'Sign them out' },
|
|
1127
1182
|
'backup.newRecoveryCode': { title: 'Make a new recovery code?', text: 'Your current code stops working, and every other device is signed out. We email you a code to confirm, then show the new recovery code once.', ok: 'New code' },
|
|
1128
|
-
|
|
1183
|
+
// a move already under way resumes in ITS saved mode, whatever this call asks (sdkBackupV2.js migrate) — the words say what it will do
|
|
1184
|
+
// (side sweep 2026-11-28: a resumed emailed-code move promised that devices could join, then signed them out)
|
|
1185
|
+
'backup.migrate': (sdk.backup._s?.v2?.moving ? (sdk.backup._s.v2.moveMode === 'signed' || sdk.backup._s.v2.svc?.silent === 'moved') : a?.silent === true) ? { title: 'Move this account with its signing key?', text: 'Your Spaces and recovery code stay the same. Other eligible devices can join using their existing account keys.', ok: 'Move account' } : { title: 'Move to the new account service?', text: 'Your Spaces and recovery code stay the same. Other devices are signed out and can restore on the new service. This legacy backup has no account key, so it moves with email-only trust; Advanced Backup remains unavailable.', ok: 'Move account' },
|
|
1129
1186
|
'cloudDevice.enroll': { title: 'Sign the cloud device in?', text: 'We email a code so this secure cloud device can sign in to this app’s account. No Space is handed over yet.', ok: 'Send code' },
|
|
1130
1187
|
'cloudDevice.register': { title: 'Add the cloud device to your account?', text: 'Register its public device key on the account service. You can sign it out later from Your devices. We email a code to confirm.', ok: 'Add device' },
|
|
1131
1188
|
'cloudDevice.setBuilds': { title: 'Update the cloud device’s secure builds?', text: 'The cloud device will follow this account’s accepted secure-build list and automatic-acceptance choice.', ok: 'Update' },
|
|
@@ -1134,15 +1191,16 @@ export async function startVault(o = {}) {
|
|
|
1134
1191
|
'alwaysOn.disable': { title: 'Stop keeping this Space always on?', text: 'The cloud device stops its schedules and linked assistants disconnect. The Space and history stay.', ok: 'Stop keeping' },
|
|
1135
1192
|
'privateRoom.link': { title: 'Link this private room?', text: 'Messages from this Space can be copied into the selected room on your account. People in that room can read them.', ok: 'Link rooms' },
|
|
1136
1193
|
'privateRoom.unlink': { title: 'Unlink this private room?', text: 'Both rooms stay in your account. New messages stop being copied between them.', ok: 'Unlink rooms' },
|
|
1137
|
-
|
|
1138
|
-
'keptAgent.
|
|
1194
|
+
// both rooms named from the vault's own list (side sweep 2026-11-28: every pair read the same)
|
|
1195
|
+
'keptAgent.link': { title: 'Link the kept assistant in ' + pairName(a) + '?', text: 'Your private assistant in ' + pairName(room) + ' can send it jobs you approve. The always-on Space ' + pairName(a) + ' reports results back through your private assistant’s agent door. Both credentials stay in this vault.', ok: 'Link assistants' },
|
|
1196
|
+
'keptAgent.unlink': { title: 'Disconnect these assistants?', text: 'The private assistant in ' + pairName(room) + ' and the kept assistant in ' + pairName(a) + ': both peer credentials and the connection are revoked. Rooms and history stay.', ok: 'Disconnect' },
|
|
1139
1197
|
'backup.beginEmailMove': { title: 'Move your email to a new account?', text: 'Use this if you lost your recovery code and all your devices. After a waiting period you can start an empty account. Your old Spaces stay with the old account.', ok: 'Start email move' },
|
|
1140
1198
|
'backup.finishEmailMove': { title: 'Create your new account?', text: 'Your address will move to an empty account. Keep the new recovery code shown on this device.', ok: 'Finish email move' },
|
|
1141
1199
|
'backup.cancelPendingEmailMove': { title: 'Cancel this device’s email move?', text: 'The email address stays with the original account.', ok: 'Cancel move' },
|
|
1142
1200
|
'backup.requestMoveTime': { title: 'Ask for more time on the email move?', text: 'The move waits until 30 days after it started, so you can recover your inbox. This can be done once and does not cancel the move.', ok: 'Ask for more time' },
|
|
1143
1201
|
'backup.cancelEmailMove': { title: 'Cancel the email move?', text: 'We email a code to the account address. Proving you can read it cancels the move.', ok: 'Send code' },
|
|
1144
1202
|
'invitations.resend': { title: 'Resend this Space’s invitation?', text: 'Send the current invitation to ' + String(a && (a.email || a.username) || 'this recipient').slice(0, 254) + '. This does not change who is admitted.', ok: 'Send invitation' },
|
|
1145
|
-
'backup.deleteAccount': { title: 'Delete your account?', text: 'Your account and its backup are deleted for good, and every device is signed out — this one too: it forgets your Spaces. We email you a code to confirm.', ok: 'Delete' },
|
|
1203
|
+
'backup.deleteAccount': { title: 'Delete your account?', text: 'Your account and its backup are deleted for good. Spaces only you used are deleted, with their messages and files; in Spaces you share, you leave. Your cloud computers are destroyed with every file on them. Every device is signed out — this one too: it forgets your Spaces. We email you a code to confirm.', ok: 'Delete' },
|
|
1146
1204
|
// an MCP server's chosen tools may run WITHOUT asking (`auto`; the SDK's recommended ones when none are named) — the prompt
|
|
1147
1205
|
// says so instead of "always with your approval" (sweep 10-24 #7)
|
|
1148
1206
|
'connections.grant': { title: 'Let the assistant in ' + titleOf(room) + ' use ' + (conns.find((c) => c.id === (a && a.id ? a.id : a)) || {}).label + '?', text: (conns.find((c) => c.id === (a && a.id ? a.id : a)) || {}).mcp && !(args[1] && Array.isArray(args[1].auto) && !args[1].auto.length) ? 'It can use this server\'s tools — some may run without asking you (the ones marked so) — and never sees the secret.' : 'It can call it — always with your approval — and never sees the secret.', ok: 'Allow' },
|
|
@@ -1165,7 +1223,7 @@ export async function startVault(o = {}) {
|
|
|
1165
1223
|
const syncError = a.lastError || (lastKeepFailure?.owner === who() && lastKeepFailure?.master === b._s?.master ? lastKeepFailure?.error : null)
|
|
1166
1224
|
return {
|
|
1167
1225
|
enabled: b.enabled, format: b.format, service: b.service, deviceId: a.deviceId, // service: 'account' (the Witbitz account service) | 'legacy' | null
|
|
1168
|
-
rooms: b.rooms.map(({ room, kind, label, shared, detachedLane, archived, pinned }) => ({ room, kind, ...(detachedLane ? { detachedLane: true } : {}), ...(pinned ? { pinned: true } : {}), ...(label ? { label } : {}), ...(shared ? { shared } : {}), ...(archived ? { archived: true } : {}) })),
|
|
1226
|
+
rooms: b.rooms.map(({ room, kind, label, shared, detachedLane, archived, pinned, lastOpenedAt }) => ({ room, kind, ...(detachedLane ? { detachedLane: true } : {}), ...(pinned ? { pinned: true } : {}), ...(label ? { label } : {}), ...(shared ? { shared } : {}), ...(archived ? { archived: true } : {}), ...(lastOpenedAt > 0 ? { lastOpenedAt } : {}), ...(a._keptMarks && a._keptMarks.has(room) ? { alwaysOn: true } : {}) })), // lastOpenedAt: read-only, as the direct SDK (side sweep: sdk-account-room-list-omits-recency)
|
|
1169
1227
|
devices: a.devices, links: a.links, lastError: syncError ? { message: String(syncError.message || syncError).slice(0, 200), ...(typeof syncError.code === 'string' ? { code: syncError.code.slice(0, 60) } : {}), ...(Number.isInteger(syncError.status) ? { status: syncError.status } : {}) } : null,
|
|
1170
1228
|
erasure: sdk.erasure.available,
|
|
1171
1229
|
gated: !!b.gated, // a restore and deleting the account need the emailed code as well (sync sweep 11-09 #24)
|
|
@@ -1234,8 +1292,7 @@ export async function startVault(o = {}) {
|
|
|
1234
1292
|
async function withdrawPushEverywhere(endpoints) {
|
|
1235
1293
|
const eps = (endpoints || []).filter((x) => typeof x === 'string' && /^https:\/\//.test(x))
|
|
1236
1294
|
let failed = 0
|
|
1237
|
-
for (const e of eps) for (const { room } of rooms) {
|
|
1238
|
-
if (/^tmp-/.test(room)) continue
|
|
1295
|
+
for (const e of eps) for (const { room } of rooms) { // temporary Spaces too: opening one registers there as well (side sweep: device-signout-prunes-only-listed-rooms)
|
|
1239
1296
|
let ok = false
|
|
1240
1297
|
try { const r = await fetch(endpoint, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ op: 'pushdrop', room, subscription: { endpoint: e } }) }); ok = r.status === 200 } catch { ok = false }
|
|
1241
1298
|
if (!ok) failed++
|
|
@@ -1267,7 +1324,15 @@ export async function startVault(o = {}) {
|
|
|
1267
1324
|
backupMem = { ...backupMem, [w]: state }
|
|
1268
1325
|
await atRest.putBackup(KEYS.backup, w, state)
|
|
1269
1326
|
const back = (await atRest.loadBackups(KEYS.backup))[w]
|
|
1270
|
-
|
|
1327
|
+
if (!(!!back && back.master === state.master && JSON.stringify(back.v2) === JSON.stringify(state.v2))) return false
|
|
1328
|
+
// ON A PROTECTED DEVICE THE READ-BACK ABOVE IS MEMORY (protectedLocal's overlay answers it even when a full store refused the sealed
|
|
1329
|
+
// write): the disk itself must hold what was written (side sweep: builder-restore-success-before-local-save)
|
|
1330
|
+
// (only where the lock is offered — storage protection exists only there, and a vault without `lock` loads none of it)
|
|
1331
|
+
if (!o.storage && vlock) {
|
|
1332
|
+
const { protectedLocalActive, durableEntry } = await import('./protectedLocal.js') // vaultCoreLock.js's specifier: the same module
|
|
1333
|
+
if (protectedLocalActive()) { const v = localStorage.getItem(KEYS.backup); if (v == null || !(await durableEntry(KEYS.backup, v))) return false }
|
|
1334
|
+
}
|
|
1335
|
+
return true
|
|
1271
1336
|
}
|
|
1272
1337
|
sdk.backup._v2 = o.accountService === false ? null : accountService({ tenant: o.tenant, legacyRecovery: async email => {
|
|
1273
1338
|
const session = sdk._session
|
|
@@ -1278,7 +1343,7 @@ export async function startVault(o = {}) {
|
|
|
1278
1343
|
return sdk._session === session ? held : null
|
|
1279
1344
|
}, ...(typeof o.accountService === 'string' && o.accountService ? { base: o.accountService } : {}), fetch: (...a) => fetch(...a), keyStore: idbKeyStore('wbvault-acct'), persistNow, onRevoked: () => accountStatus(true), afterSignOut: (address) => { if (roomPass) roomPass.renewNow(address) },
|
|
1280
1345
|
// the endpoint once the subscription is KNOWN (vpush.ready) — not known within 15 s: undefined, and nothing is sent (Codex 11-16 #2)
|
|
1281
|
-
...(vpush ? { pushEndpoint: async () => ((await Promise.race([vpush.ready.then(() => true), new Promise((r) => setTimeout(() => r(false), 15000))])) ? (
|
|
1346
|
+
...(vpush ? { pushEndpoint: async () => ((await Promise.race([vpush.ready.then(() => true), new Promise((r) => setTimeout(() => r(false), 15000))])) ? ((e) => (e === undefined ? undefined : e || null))(vpush.endpoint()) : undefined), /* undefined = not known (on, but not loaded): nothing is sent (side sweep 2026-11-28) */ withdrawPush: withdrawPushEverywhere } : {}) }) // § 8.8, only where this vault sends notifications (sync sweep 11-16 #14)
|
|
1282
1347
|
roomPass = makeRoomPassHolder({
|
|
1283
1348
|
on: () => roomPassSwitchOn(st),
|
|
1284
1349
|
note: (line) => { try { console.info('witbitz vault: ' + line) } catch { /* */ } }, // why a request went without a pass, at most once a while (roomPass.js makeNoter; sync sweep 2026-11-23: this vault said nothing)
|
|
@@ -1467,14 +1532,14 @@ export async function startVault(o = {}) {
|
|
|
1467
1532
|
if (selection && (selection.size > 1000 || [...selection].some(id => typeof id !== 'string' || !id || id.length > 160))) throw Object.assign(new Error('Invalid room selection'), { code: 'invalid_argument' })
|
|
1468
1533
|
const heldById = new Map(rooms.map(r => [r.room, r]))
|
|
1469
1534
|
const selected = (selection ? [...selection].map(id => heldById.get(id) || { room: id }) : rooms.slice()).filter(r => !r.room.startsWith('tmp-'))
|
|
1470
|
-
return saveAccountArchive(selected, async (r, keysOnly) => {
|
|
1535
|
+
return saveAccountArchive(selected, async (r, keysOnly, attachments) => {
|
|
1471
1536
|
if (!r.link) return {}
|
|
1472
1537
|
const parts = linkParts(r.link)
|
|
1473
1538
|
const key = parts?.split ? (await backupRoom(r))?.mk : parts?.mk
|
|
1474
1539
|
if (!key || keysOnly) return { key }
|
|
1475
|
-
const saved = await workerClient.exportSealed(r.room, null)
|
|
1540
|
+
const saved = await workerClient.exportSealed(r.room, null, { attachments }) // + the stored attachments, sealed (sdkExports.js)
|
|
1476
1541
|
if (saved?.status !== 200) throw new Error('unavailable')
|
|
1477
|
-
return { key, ledger: saved.sealed, count: saved.count }
|
|
1542
|
+
return { key, ledger: saved.sealed, count: saved.count, attachments: saved.attachments }
|
|
1478
1543
|
}, args[0] === true, () => epoch === privacyEpoch && generation === sdk._archiveGeneration && owner === who() && selected.every(r => !r.link || rooms.some(held => held.room === r.room && held.link === r.link)), args[2])
|
|
1479
1544
|
}
|
|
1480
1545
|
if (m === 'protectRecoveryEmail') {
|
|
@@ -1554,6 +1619,9 @@ export async function startVault(o = {}) {
|
|
|
1554
1619
|
if (!b.enabled || restoredIdentity !== b._restoreIdentity()) throw Object.assign(new Error('not restored'), { code: 'cancelled' })
|
|
1555
1620
|
noteDeviceSpk() // as after enable (sync sweep 11-22 #16)
|
|
1556
1621
|
await fromBackup()
|
|
1622
|
+
// read back from this device's storage before saying it is restored (side sweep 2026-11-28: a full store refused the write silently,
|
|
1623
|
+
// and the next launch asked for recovery again) — as a new recovery code is
|
|
1624
|
+
if (restoredIdentity === b._restoreIdentity() && !(await persistNow(JSON.parse(JSON.stringify(b._s))))) throw Object.assign(new Error('Your Spaces were recovered for now, but this device could not keep the account. Free some storage and restore again.'), { code: 'save_failed' })
|
|
1557
1625
|
if (restoredIdentity !== b._restoreIdentity()) throw Object.assign(new Error('The account changed during recovery'), { code: 'account_changed' })
|
|
1558
1626
|
emitAccount()
|
|
1559
1627
|
accountStatus()
|
|
@@ -1758,6 +1826,7 @@ export async function startVault(o = {}) {
|
|
|
1758
1826
|
if (ns === 'cloudDevice' && (m === 'enroll' || m === 'register')) return sdk.cloudDevice[m]({ getCode: await emailCodeAsker('cloud-device', accountAddress) })
|
|
1759
1827
|
if (ns === 'backup') return backupCall(m, args)
|
|
1760
1828
|
if (ns === 'account') return accountCall(m, args)
|
|
1829
|
+
if (ns === 'invite' && m === 'collect') return inviteCollect()
|
|
1761
1830
|
if (ns === 'siri' && m === 'shortcut') return siriShortcut()
|
|
1762
1831
|
if (ns === 'siri' && m === 'showKey') {
|
|
1763
1832
|
const s = sdk.siri.shortcut
|
|
@@ -1880,6 +1949,7 @@ export async function startVault(o = {}) {
|
|
|
1880
1949
|
if (ns === 'invitations') {
|
|
1881
1950
|
await sp._gateConfig() // heal a stale worker key before reading the vault's current link
|
|
1882
1951
|
const it = rooms.find((x) => x.room === room)
|
|
1952
|
+
if (it.detachedLane) sp._detachedLane = true // a detached lane is still one member's room: no invitation with its saved link (side sweep: sdk-resend-forgets-private-lane-status)
|
|
1883
1953
|
sp.shareLink = it.link
|
|
1884
1954
|
sp._title = it.title ? { title: it.title } : null
|
|
1885
1955
|
return await sp.resendInvite(args[0])
|
|
@@ -1889,6 +1959,7 @@ export async function startVault(o = {}) {
|
|
|
1889
1959
|
if (m === 'enable') { await sp._gateConfig(); sp.shareLink = rooms.find((x) => x.room === room).link }
|
|
1890
1960
|
const result = await sp.alwaysOn[m](...args)
|
|
1891
1961
|
if (m === 'enable' && args[0]?.disconnectLanes) await CALLS.op('getConfig', room, { plainMark: true })
|
|
1962
|
+
if (m === 'enable' || m === 'disable') emitAccount() // the account view's saved mark moved (rooms[].alwaysOn)
|
|
1892
1963
|
return result
|
|
1893
1964
|
}
|
|
1894
1965
|
if (c) return await sp.connections.grant(c, args[1] || {})
|
|
@@ -1943,7 +2014,10 @@ export async function startVault(o = {}) {
|
|
|
1943
2014
|
const held0 = rooms.map((r) => r.room)
|
|
1944
2015
|
rooms = []
|
|
1945
2016
|
write(st, KEYS.session, null)
|
|
1946
|
-
|
|
2017
|
+
// OFF, as the person's own Off does (side sweep: builder-signout-retains-push-subscription): every held Space takes this device off its
|
|
2018
|
+
// list, the browser's subscription goes and the device's On is cleared — as the regular app's sign-out (devices.js). It kept the
|
|
2019
|
+
// subscription and On: a Space that missed the removal still tickled the device, and the next account's Spaces listed it unasked.
|
|
2020
|
+
if (vpush) await Promise.race([vpush.disable(), new Promise((r) => setTimeout(r, WIPE_PUSH_MS))]).catch(() => {}) // while the worker still holds the keys
|
|
1947
2021
|
// ★ THE WORKER'S KEYS GO WHATEVER THE SAVE DOES (second review, 2026-11-27). A strict save that could not be confirmed threw
|
|
1948
2022
|
// here, before the forgets and wipeKeys below — "signed out", with every room key still in the worker's memory and store until
|
|
1949
2023
|
// a retry got through. Its error is kept and thrown at the end, with the key store's (the wipe marker stays, so launch retries).
|
package/vault-kit.mjs
CHANGED
|
@@ -20,7 +20,7 @@ import { createHash } from 'node:crypto'
|
|
|
20
20
|
import { join, dirname } from 'node:path'
|
|
21
21
|
|
|
22
22
|
export const DEFAULTS = { endpoint: 'https://api.witbitz.chat/v1/space', loginBase: 'https://witbitz-spaces.pages.dev', from: 'https://witbitz.chat/sdk/latest/', enclaveClaim: 'https://witbitz-spaces.pages.dev/enclave-claim.json', accountService: 'https://api.witbitz.chat/v1' } // enclaveClaim: the confidential tier's published measurement (and its policy text, beside it)
|
|
23
|
-
export const KIT_RELEASE = '4.
|
|
23
|
+
export const KIT_RELEASE = '4.5.0' // tools/sdk-release.mjs stamps the version here, so a downloaded copy builds from ITS release
|
|
24
24
|
export function stampSdkAuth(src) {
|
|
25
25
|
return src.replaceAll('__' + 'SPACE_AUTH_BROKER' + '__', 'https://auth.witbitz.chat').replaceAll('__' + 'SPACE_AUTH_FORCE_BROKER' + '__', '0')
|
|
26
26
|
}
|
|
@@ -185,7 +185,7 @@ self.addEventListener('activate', (e) => e.waitUntil(self.clients.claim()))
|
|
|
185
185
|
// no read of its own: the push carries the sealed preview (opened with the room's notification key), else the generic line
|
|
186
186
|
self.wbxWirePush({ describe: async () => null, generic: { title: BRAND, body: 'Something new in your Spaces — open ' + BRAND + ' to see it.' }, testBody: 'You’ll get a nudge here when someone posts in your Spaces.', intakeBody: 'Your assistant has a new message — open ' + BRAND + ' to read it.' })
|
|
187
187
|
// a tap: the open vault is focused and told the room (it tells your page: wb.vault.on('notifOpen')); none open → the vault at ?room=…&tap=1
|
|
188
|
-
self.wbxWireNotifClick({ coldUrl: (room) => (room ? '/?room=' + encodeURIComponent(room) + '&tap=1' : '/'), stashTap:
|
|
188
|
+
self.wbxWireNotifClick({ coldUrl: (room) => (room ? '/?room=' + encodeURIComponent(room) + '&tap=1' : '/'), stashTap: true }) // stashed: a resuming vault that missed the post still opens it (vaultCorePush.js)
|
|
189
189
|
`
|
|
190
190
|
}
|
|
191
191
|
|