@witbitz/sdk 0.0.0-stage → 4.3.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/LICENSE +21 -0
- package/README.md +20 -2
- package/a2aCore.js +200 -0
- package/a2aShared.js +27 -0
- package/accountErase.js +223 -0
- package/accountIndexDoc.js +122 -0
- package/accountOwner.js +59 -0
- package/accountRecord.js +90 -0
- package/accountScope.js +114 -0
- package/accountSeal.js +42 -0
- package/accountStores.js +173 -0
- package/acctV2App.js +619 -0
- package/acctV2Check.js +29 -0
- package/acctV2Client.js +382 -0
- package/acctV2Keys.js +43 -0
- package/acctV2Legacy.js +14 -0
- package/acctV2Switch.js +80 -0
- package/acctV2UiCore.js +857 -0
- package/acctV2WebAuthn.js +61 -0
- package/acctV2Wire.js +59 -0
- package/address.js +42 -0
- package/attestedBox.js +30 -0
- package/attestedRooms.js +78 -0
- package/awsKey.js +98 -0
- package/backupRecord.js +106 -0
- package/backupVault.js +97 -0
- package/blocks.js +115 -0
- package/blocksPush.js +64 -0
- package/browseSeal.js +103 -0
- package/cbor.js +225 -0
- package/changePush.js +75 -0
- package/chatLock.js +149 -0
- package/chatLockSw.js +13 -0
- package/cloudDeviceBuilds.js +11 -0
- package/cloudDevicePins.js +33 -0
- package/cloudDeviceSeal.js +53 -0
- package/codeBrowse.js +224 -0
- package/codeCloud.js +652 -0
- package/codeCloudKeys.js +112 -0
- package/codeCommands.js +167 -0
- package/codeComputers.js +388 -0
- package/codeEgress.js +123 -0
- package/codeFilesRoutes.js +17 -0
- package/codeMkdir.js +8 -0
- package/codeModes.js +57 -0
- package/codeOrphanKeys.js +42 -0
- package/codeOutputs.js +141 -0
- package/codeRelay.js +505 -0
- package/codeSentinel.js +86 -0
- package/codeTransport.js +295 -0
- package/codeUndo.js +48 -0
- package/compress.js +24 -0
- package/config.js +11 -0
- package/connCatalog.js +164 -0
- package/connDisp.js +76 -0
- package/connOtherWays.js +74 -0
- package/connPending.js +16 -0
- package/connWrap.js +53 -0
- package/connectionEntry.js +89 -0
- package/connections.js +562 -0
- package/credits.js +30 -0
- package/csAttest.js +112 -0
- package/decrypt.html +384 -0
- package/deviceAttest.js +521 -0
- package/deviceCall.js +54 -0
- package/deviceKeyCore.js +41 -0
- package/deviceSeal.js +59 -0
- package/e2ee.js +323 -0
- package/eat.js +103 -0
- package/emailFork.js +275 -0
- package/emailSignIn.js +81 -0
- package/emptySpaces.js +111 -0
- package/encSource.js +55 -0
- package/enclaveAccept.js +214 -0
- package/enclaveClaim.js +241 -0
- package/enclaveRoute.js +102 -0
- package/enclaveSnapshotMerge.js +44 -0
- package/entrySig.js +165 -0
- package/env.js +73 -0
- package/eraseFile.js +58 -0
- package/followImage.js +86 -0
- package/healNames.js +45 -0
- package/idb.js +97 -0
- package/idbSeal.js +119 -0
- package/indexGone.js +12 -0
- package/invite.js +51 -0
- package/inviteEnroll.js +67 -0
- package/inviteSend.js +68 -0
- package/jobAgents.js +87 -0
- package/keptMerge.js +84 -0
- package/l1-worker-src.js +2 -0
- package/l1-worker.js +831 -0
- package/laneConfig.js +57 -0
- package/laneLinkCore.js +177 -0
- package/ledgerView.js +64 -0
- package/manifest.json +220 -0
- package/mcpRecommended.js +25 -0
- package/memberChange.js +123 -0
- package/mkseal.js +101 -0
- package/nativePush.js +153 -0
- package/nitroVerify.js +220 -0
- package/noble-p256.js +27 -0
- package/notice.js +116 -0
- package/notifKey.js +58 -0
- package/offlineBundle.js +62 -0
- package/ohttp.js +177 -0
- package/opencodeWire.js +282 -0
- package/oprf.js +70 -0
- package/ownAgentLink.js +96 -0
- package/ownerPolicy.js +117 -0
- package/package.json +254 -4
- package/pollVerdict.js +33 -0
- package/prefetchPoll.js +60 -0
- package/protectedLocal.js +410 -0
- package/pushCore.js +42 -0
- package/recovery.js +107 -0
- package/regions.js +42 -0
- package/removedMessage.js +11 -0
- package/renameRefusal.js +9 -0
- package/replyQuote.js +34 -0
- package/reqEnvelope.js +126 -0
- package/roomDefaultPrefs.js +76 -0
- package/roomDelete.js +109 -0
- package/roomName.js +177 -0
- package/roomPass.js +256 -0
- package/roomRoster.js +289 -0
- package/roomSettings.js +61 -0
- package/roomState.js +58 -0
- package/roomStreamClient.js +115 -0
- package/rosterCount.js +49 -0
- package/rosterHash.js +13 -0
- package/rowSchema.js +113 -0
- package/safeMedia.js +116 -0
- package/safeMediaPins.js +17 -0
- package/schedulesDoc.js +78 -0
- package/sdkA2A.js +404 -0
- package/sdkAccount.js +470 -0
- package/sdkAccountDoc.js +81 -0
- package/sdkAccountSections.js +223 -0
- package/sdkAgui.js +141 -0
- package/sdkAttest.js +34 -0
- package/sdkBackup.js +480 -0
- package/sdkBackupV2.js +630 -0
- package/sdkBrowserPrivate.js +28 -0
- package/sdkBuilds.js +208 -0
- package/sdkCloudDevice.js +215 -0
- package/sdkComputers.js +480 -0
- package/sdkDictation.js +142 -0
- package/sdkErase.js +283 -0
- package/sdkExports.js +69 -0
- package/sdkInvitations.js +34 -0
- package/sdkKeptAgent.js +188 -0
- package/sdkLaneLink.js +205 -0
- package/sdkPlan.js +94 -0
- package/sdkProtect.js +228 -0
- package/sdkRedact.js +36 -0
- package/sdkRekey.js +307 -0
- package/sdkReport.js +68 -0
- package/sdkSafeMedia.js +255 -0
- package/sdkSchedules.js +39 -0
- package/sdkSpeech.js +54 -0
- package/sdkTurn.js +117 -0
- package/sdkVault.js +124 -0
- package/sealShare.js +18 -0
- package/sealedNames.js +64 -0
- package/sealedReceipt.js +17 -0
- package/sentinelRelease.js +154 -0
- package/shamir.js +85 -0
- package/sharedViews.js +38 -0
- package/sheetChrome.js +450 -0
- package/siri.js +171 -0
- package/spaceClient.js +1418 -0
- package/spaceConfig.js +81 -0
- package/spaceEmailGate.js +813 -0
- package/spaceExport.js +125 -0
- package/spaceFork.js +216 -0
- package/spaceLock.js +358 -0
- package/spacePasskey.js +180 -0
- package/speechOut.js +100 -0
- package/splitKeyClient.js +90 -0
- package/store.js +587 -0
- package/streamHint.js +36 -0
- package/sttCloud.js +220 -0
- package/sttWorklet.js +38 -0
- package/sw-notif-core.js +538 -0
- package/tempList.js +48 -0
- package/tinfoilVerifier.js +78 -0
- package/toolBooks.js +31 -0
- package/toolRules.js +52 -0
- package/turnCerts.js +254 -0
- package/turnFeed.js +58 -0
- package/turnVerdict.js +36 -0
- package/usageReceipts.js +176 -0
- package/usageSummary.js +90 -0
- package/util.js +181 -0
- package/vault-core.js +1958 -0
- package/vault-kit.mjs +354 -0
- package/vault-screens.js +263 -0
- package/vaultAtRest.js +177 -0
- package/vaultCoreLock.js +111 -0
- package/vaultCorePush.js +140 -0
- package/vaultDeviceKey.js +95 -0
- package/vaultEnclaveHandoff.js +114 -0
- package/vaultKeep.js +281 -0
- package/vaultSealedStore.js +77 -0
- package/vaultWorkerHost.js +98 -0
- package/vcWorker.js +34 -0
- package/voiceAttest.js +50 -0
- package/voiceCert.js +51 -0
- package/witbitz-admin.d.ts +135 -0
- package/witbitz-admin.js +529 -0
- package/witbitz-admin.mjs +1459 -0
- package/witbitz-sdk.d.ts +1106 -0
- package/witbitz-sdk.js +3835 -0
- package/workerClient.js +16 -0
- package/workerLiveness.js +21 -0
- package/x509.js +218 -0
package/siri.js
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
// siri.js — the page's half of the CONFIDENTIAL VOICE INBOX (docs/siri-inbox.md). A Shortcut posts what you said to
|
|
2
|
+
// siri.witbitz.chat; TLS ends inside the standing Sentinel, which seals the words to the Space's INBOX PUBLIC KEY and
|
|
3
|
+
// keeps the box until one of your devices collects it. This module:
|
|
4
|
+
// · mints the Shortcut's KEY (kept in store.js, riding the account; the Sentinel holds only its hash),
|
|
5
|
+
// · mints a Space's INBOX KEYPAIR when you enable Siri there (the private half never leaves your devices),
|
|
6
|
+
// · sends the account's RECORD to the Sentinel — every alias, every inbox public key, the key hash, the default —
|
|
7
|
+
// sealed to the Sentinel's attested share key exactly as a connection grant is (attest → sealTo → sirigrant),
|
|
8
|
+
// · COLLECTS: pulls the drops, opens this Space's with its private key, posts each as you (🎙 marks the voice), acks.
|
|
9
|
+
// Nothing here reaches the Sentinel except through the Lambda's op:'sentinel' door, which relays ciphertext both ways.
|
|
10
|
+
import { sealTo } from './sealShare.js'
|
|
11
|
+
import { genRecipientKey, openBox } from './e2ee.js'
|
|
12
|
+
import { loadSiri, saveSiri, normSiriAlias } from './store.js'
|
|
13
|
+
|
|
14
|
+
export const SIRI_ENDPOINT = 'https://siri.witbitz.chat/in'
|
|
15
|
+
export class SiriError extends Error { constructor(m, code = '') { super(m); this.code = code } }
|
|
16
|
+
// connections.js (the Sentinel attestation) pulls the Nitro verifier in; loaded only when a record is pushed, so this
|
|
17
|
+
// module — and the collector — stay loadable where there is no verifier (the tests, and one day a lighter surface).
|
|
18
|
+
// ⛑ STAMPED, like every other lazy import here (spaceClient.js, enclave.js, drawer.js). A BARE './connections.js' is a
|
|
19
|
+
// URL that never changes across builds, so a phone's 4-hour HTTP cache hands back the previous build's bytes under this
|
|
20
|
+
// build's signed manifest and the loader refuses the module: "Cannot load script due to integrity mismatch" — which is
|
|
21
|
+
// exactly what the owner's iPhone showed on the first Siri deploy (2026-09-26). spaces/test/stampedImports.test.mjs.
|
|
22
|
+
const attest = async (o) => (await import('./connections.js')).attestStandingSentinel(o)
|
|
23
|
+
export const SIRI_MARK = '🎙 ' // what a collected drop opens with, so everyone (and the assistant) sees it was said, not typed
|
|
24
|
+
const b64url = (u8) => btoa(String.fromCharCode(...new Uint8Array(u8))).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '')
|
|
25
|
+
const b64 = (u8) => btoa(String.fromCharCode(...new Uint8Array(u8)))
|
|
26
|
+
|
|
27
|
+
/** A fresh Shortcut key: 32 random bytes, base64url, prefixed so it is recognisable in the Shortcuts app. */
|
|
28
|
+
export const newSiriKey = () => 'wsk_' + b64url(crypto.getRandomValues(new Uint8Array(32)))
|
|
29
|
+
/** What the Sentinel keeps of the key: sha256, standard base64. */
|
|
30
|
+
export async function siriKeyHash(key) { return b64(await crypto.subtle.digest('SHA-256', new TextEncoder().encode(String(key)))) }
|
|
31
|
+
|
|
32
|
+
/** The account's record as the Sentinel wants it (siri.mjs normSiriRecord), from the store's copy. */
|
|
33
|
+
export async function siriRecordFor(account, s = loadSiri()) {
|
|
34
|
+
const rooms = Object.entries(s.rooms || {})
|
|
35
|
+
return {
|
|
36
|
+
// a key the hosted app's vault holds is here only as its hash (`tokenHash`; vaultAcctSecrets.js, review § 7.6) — the same value
|
|
37
|
+
account, tokenHash: s.token ? await siriKeyHash(s.token) : String(s.tokenHash || ''),
|
|
38
|
+
aliases: rooms.map(([room, r]) => ({ alias: r.alias, room, label: r.label || '', inboxPub: { x: r.pub.x, y: r.pub.y } })),
|
|
39
|
+
defaultAlias: s.defaultRoom && s.rooms[s.defaultRoom] ? s.rooms[s.defaultRoom].alias : '',
|
|
40
|
+
created: Date.now(),
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Send the whole record, sealed to the attested Sentinel. Idempotent: the Sentinel REPLACES what it held. `s`: the record to
|
|
45
|
+
* send — the store's, or a COPY with a change the caller keeps only once the Sentinel took it (pass 9, K#5). */
|
|
46
|
+
export async function pushSiriRecord({ post, auth = {}, account, pins, verify, intake = null, s = loadSiri() } = {}) {
|
|
47
|
+
if (!s.token && !s.tokenHash) throw new SiriError('no Siri key on this device yet', 'no_key')
|
|
48
|
+
const rec = await siriRecordFor(account, s)
|
|
49
|
+
// THE INTAKE (docs/message-intake.md): { room, pub, drop } — the Sentinel then drops what was said into the account's
|
|
50
|
+
// message room, and any device of the account posts it (the app: intakeProducers.js). Without it: kept for a pull, as before.
|
|
51
|
+
if (intake && intake.room && intake.pub && intake.drop) rec.intake = { room: intake.room, pub: { x: intake.pub.x, y: intake.pub.y }, drop: intake.drop }
|
|
52
|
+
const { nonce, key } = await attest({ post, auth, pins, verify })
|
|
53
|
+
const sealed = await sealTo(key, nonce, rec)
|
|
54
|
+
const r = await post({ op: 'sentinel', sentinel: { mode: 'sirigrant', sealed }, ...auth })
|
|
55
|
+
if (!r || r.error || !r.ok) throw new SiriError(`the Sentinel refused the record (${(r && (r.error || r.reason)) || 'no answer'})`, (r && r.error) || 'refused')
|
|
56
|
+
return r
|
|
57
|
+
}
|
|
58
|
+
export async function siriStatus({ post, auth = {} }) {
|
|
59
|
+
const r = await post({ op: 'sentinel', sentinel: { mode: 'siristatus' }, ...auth })
|
|
60
|
+
if (!r || r.error) throw new SiriError(`the Sentinel could not be reached (${(r && r.error) || 'no answer'})`, (r && r.error) || 'unreachable')
|
|
61
|
+
return r
|
|
62
|
+
}
|
|
63
|
+
export async function siriRevoke({ post, auth = {} }) {
|
|
64
|
+
const r = await post({ op: 'sentinel', sentinel: { mode: 'sirirevoke' }, ...auth })
|
|
65
|
+
if (!r || r.error) throw new SiriError(`the Sentinel could not be reached (${(r && r.error) || 'no answer'})`, (r && r.error) || 'unreachable')
|
|
66
|
+
// the setup is DELETED on every device of the account (pass 9, K#3): `rev` outranks any copy that still holds the old key,
|
|
67
|
+
// and each Space is marked taken off, so no other device's copy brings an alias or the key back
|
|
68
|
+
const was = loadSiri(), now = Date.now()
|
|
69
|
+
saveSiri({ token: '', defaultRoom: '', rooms: {}, rev: (was.rev || 0) + 1, gone: { ...(was.gone || {}), ...Object.fromEntries(Object.keys(was.rooms).map((rm) => [rm, now])) } })
|
|
70
|
+
return r
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Enable Siri for a Space on this account: an alias, an inbox keypair (once), optionally the default. Local only —
|
|
74
|
+
* the caller pushes the record. Returns the store's copy. */
|
|
75
|
+
// `mint` / `mintToken` (the hosted app, siriSheet.js — only where the vault holds Siri keys, acctHeld.js): the inbox keypair and
|
|
76
|
+
// the Shortcut key are minted IN THE VAULT (vaultAcctSecrets.js, review § 7.6) → a public half / the key's hash; the room is a
|
|
77
|
+
// held stub ({ alias, label, pub, at, held: 1 }) and the key is kept here as `tokenHash` only.
|
|
78
|
+
export async function enableSiriHere({ room, label = '', alias, makeDefault = false, mint = null, mintToken = null } = {}) {
|
|
79
|
+
const a = normSiriAlias(alias)
|
|
80
|
+
if (!a) throw new SiriError('an alias is needed — the word you will say to Siri', 'alias')
|
|
81
|
+
if (/[,:;]/.test(a)) throw new SiriError('an alias cannot contain , : or ;', 'alias')
|
|
82
|
+
const taken = (st) => { for (const [rm, r] of Object.entries(st.rooms)) if (rm !== room && r.alias === a) throw new SiriError(`"${a}" already names another Space`, 'alias') }
|
|
83
|
+
// THE SLOW PART FIRST, THEN THE CHANGE ON WHAT IS THERE NOW (sync sweep 2026-11-14 #2, as the SDK since 48ddb8733): the vault's mints
|
|
84
|
+
// (up to 8 s each) or the keypair ran on a copy read BEFORE them, and saving that copy dropped another device's merge that landed
|
|
85
|
+
// meanwhile — and the record pushed to the Sentinel lacked it.
|
|
86
|
+
const s0 = loadSiri(); taken(s0)
|
|
87
|
+
const tokenHash = (!s0.token && !s0.tokenHash && mintToken) ? await mintToken() : ''
|
|
88
|
+
const fresh = s0.rooms[room] ? null : mint ? { held: 1, pub: await mint() } : { kp: await genRecipientKey() }
|
|
89
|
+
const s = loadSiri(); taken(s)
|
|
90
|
+
if (!s.token && !s.tokenHash) { if (tokenHash) s.tokenHash = tokenHash; else if (mintToken) s.tokenHash = await mintToken(); else s.token = newSiriKey() }
|
|
91
|
+
const cur = s.rooms[room]
|
|
92
|
+
if (cur) s.rooms[room] = { ...cur, alias: a, label: label || cur.label, at: Date.now() } // `at` moves on a rename: the newer copy leads a merge
|
|
93
|
+
else {
|
|
94
|
+
const f = fresh || (mint ? { held: 1, pub: await mint() } : { kp: await genRecipientKey() }) // removed elsewhere since the first read: made now
|
|
95
|
+
s.rooms[room] = f.held ? { alias: a, label, pub: { x: f.pub.x, y: f.pub.y }, held: 1, at: Date.now() } : { alias: a, label, pub: { x: f.kp.publicJwk.x, y: f.kp.publicJwk.y }, priv: f.kp.privateJwk, at: Date.now() }
|
|
96
|
+
}
|
|
97
|
+
if (makeDefault) s.defaultRoom = room
|
|
98
|
+
else if (s.defaultRoom === room) s.defaultRoom = ''
|
|
99
|
+
return saveSiri(s)
|
|
100
|
+
}
|
|
101
|
+
export function disableSiriHere(room) {
|
|
102
|
+
const s = loadSiri()
|
|
103
|
+
if (!s.rooms[room]) return s
|
|
104
|
+
s.gone = { ...(s.gone || {}), [room]: Math.max(Date.now(), (s.rooms[room].at || 0) + 1) } // recorded: off on the account's other devices too (pass 9, K#3)
|
|
105
|
+
delete s.rooms[room]
|
|
106
|
+
if (s.defaultRoom === room) s.defaultRoom = ''
|
|
107
|
+
return saveSiri(s)
|
|
108
|
+
}
|
|
109
|
+
/** A new key: the old Shortcut stops working the moment the record is pushed. */
|
|
110
|
+
export function rotateSiriKey() { const s = loadSiri(); s.token = newSiriKey(); delete s.tokenHash; return saveSiri(s) }
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* COLLECT: pull the account's drops; open and post the ones for THIS Space (in the order they were said); ack what
|
|
114
|
+
* was posted (and what can no longer be opened — a drop for a key this account no longer has is unrecoverable);
|
|
115
|
+
* report the Spaces that hold the rest, so the caller can say "Siri left a message for Family".
|
|
116
|
+
* `send(text)` posts as the member (composer.js sendNow); a send that throws leaves the drop UNacked, to be collected next time.
|
|
117
|
+
*/
|
|
118
|
+
/**
|
|
119
|
+
* `deliver` — hand each drop to the CALLER instead of posting it (a builder, 2026-09-27: their app files captures into
|
|
120
|
+
* its own inbox verbatim, and posting starts an assistant turn they do not want). Posting was already this collector's
|
|
121
|
+
* one injected step, so `deliver` replaces that call and nothing else moves: same pull, same ack rules, same
|
|
122
|
+
* `elsewhere`. Two deliberate differences from the posting path:
|
|
123
|
+
* • the caller gets the words AS SPOKEN. `SIRI_MARK` exists to tell a ROOM that something was said rather than
|
|
124
|
+
* typed; an inbox has no audience to tell, and a caller that wants the mark can add it.
|
|
125
|
+
* • it gets `{ id, room, alias, at }` — which drop, which Space, the word that was actually said (how an app
|
|
126
|
+
* routes), and when Siri took it, not when we collected it.
|
|
127
|
+
* ★ AT-LEAST-ONCE, and the asymmetry is the point. A `deliver` that throws or rejects is NOT acked, so a failed inbox
|
|
128
|
+
* write never eats a capture — the next collect sees it again. The converse is the cost the caller must design for: a
|
|
129
|
+
* write that SUCCEEDS and whose ack then fails is redelivered, so dedupe on `id`.
|
|
130
|
+
*/
|
|
131
|
+
// ⛔ ONE SPACE'S PULL, AND EACH DROP ACKED AS IT IS POSTED (state machines pass 9, K#6 K#9):
|
|
132
|
+
// · the pull named no Space, so the Sentinel leased EVERY Space's drops to a collector that posts one Space's: for a minute
|
|
133
|
+
// nobody could collect the others — the toast "open Family to deliver it" led to an empty pull, and a collector going Space
|
|
134
|
+
// after Space never reached the later ones. The pull now names the Space; the others come back named, not leased
|
|
135
|
+
// (`elsewhere` — a Sentinel before that names them only by handing them out, as before, and they are still listed);
|
|
136
|
+
// · the lease is fixed at the pull (60 s) and the ack came after the whole loop, each drop a full turn: past a minute
|
|
137
|
+
// another device (or a second collect) pulled the rest — those already posted too — and posted them again. Each drop is
|
|
138
|
+
// now acked as it is posted, and nothing more is posted COLLECT_WINDOW_MS after the pull: the rest wait, unacked, for
|
|
139
|
+
// the next pull (`more: true`).
|
|
140
|
+
export const COLLECT_WINDOW_MS = 45_000
|
|
141
|
+
// `open(drop, rec)` → the plaintext of a drop for a Space whose private key this copy does not hold (a held stub — the hosted
|
|
142
|
+
// app's vault opens it, siriCollect.js; review § 7.6). Without it such a drop is left, unopened, for a device that can.
|
|
143
|
+
export async function collectSiriDrops({ post, auth = {}, room, send, deliver = null, s = loadSiri(), now = Date.now, open = null } = {}) {
|
|
144
|
+
const t0 = now()
|
|
145
|
+
const r = await post({ op: 'sentinel', sentinel: { mode: 'siripull', ...(room ? { room } : {}) }, ...auth })
|
|
146
|
+
if (!r || r.error || !Array.isArray(r.drops)) return { delivered: 0, elsewhere: [], error: (r && r.error) || 'no answer' }
|
|
147
|
+
const elsewhere = new Map()
|
|
148
|
+
const nameElsewhere = (rm) => { const rec = s.rooms[rm]; if (rec && rm !== room) elsewhere.set(rm, { room: rm, label: rec.label || rec.alias, alias: rec.alias }) }
|
|
149
|
+
let delivered = 0, unopened = 0, more = false
|
|
150
|
+
for (const d of r.drops) {
|
|
151
|
+
if (!d || typeof d.id !== 'string') continue
|
|
152
|
+
const rec = s.rooms[d.room]
|
|
153
|
+
if (!rec) continue // enabled on another device and not synced here yet: leave it for that device
|
|
154
|
+
if (d.room !== room) { nameElsewhere(d.room); continue }
|
|
155
|
+
if (now() - t0 > COLLECT_WINDOW_MS) { more = true; continue } // its lease runs out before it could be posted and acked: the next pull takes it
|
|
156
|
+
const text = rec.priv ? await openBox(d.box, rec.priv) : open ? await Promise.resolve().then(() => open(d, rec)).catch(() => null) : null
|
|
157
|
+
// ⛔ NOT OPENED HERE IS NOT UNOPENABLE (2026-11-07, the implicit-state-machine review): this acked — deleted — a drop this
|
|
158
|
+
// device's key could not open, as "sealed to a key this Space no longer has". A device that has not synced a rotated Siri key
|
|
159
|
+
// yet holds the OLD one, and destroyed for good what another of the person's devices could open. Left for that device; the
|
|
160
|
+
// Sentinel drops what nobody collects after DROP_TTL_MS (30 days, infra/cloud-computer/sentinel/siri.mjs).
|
|
161
|
+
if (text == null) { unopened++; continue }
|
|
162
|
+
try {
|
|
163
|
+
if (deliver) await deliver(text, { id: d.id, room: d.room, alias: d.alias, at: d.at })
|
|
164
|
+
else await send(SIRI_MARK + text)
|
|
165
|
+
} catch { continue /* not delivered: not acked; collected next time. A failed write must never cost the member the capture. */ }
|
|
166
|
+
delivered++
|
|
167
|
+
try { await post({ op: 'sentinel', sentinel: { mode: 'siriack', ids: [d.id] }, ...auth }) } catch { /* the next pull sees it again; the room dedupes nothing, so say so in the doc */ }
|
|
168
|
+
}
|
|
169
|
+
for (const e of Array.isArray(r.elsewhere) ? r.elsewhere : []) if (e && typeof e.room === 'string') nameElsewhere(e.room)
|
|
170
|
+
return { delivered, elsewhere: [...elsewhere.values()], ...(unopened ? { unopened } : {}), ...(more ? { more } : {}) }
|
|
171
|
+
}
|