@witbitz/sdk 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +20 -2
- package/a2aCore.js +221 -0
- package/a2aShared.js +27 -0
- package/accountErase.js +228 -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/agentDoorTools.js +28 -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 +165 -0
- package/chatLockSw.js +13 -0
- package/cloudDeviceBuilds.js +11 -0
- package/cloudDevicePins.js +33 -0
- package/cloudDeviceSeal.js +53 -0
- package/codeAttachments.js +100 -0
- package/codeBrowse.js +224 -0
- package/codeCache.js +149 -0
- package/codeCloud.js +650 -0
- package/codeCloudKeys.js +112 -0
- package/codeCommands.js +167 -0
- package/codeComputers.js +389 -0
- package/codeEgress.js +123 -0
- package/codeFilesRoutes.js +17 -0
- package/codeFolders.js +116 -0
- package/codeHistory.js +76 -0
- package/codeLanguage.js +54 -0
- package/codeMkdir.js +8 -0
- package/codeModes.js +59 -0
- package/codeOrphanKeys.js +42 -0
- package/codeOutputs.js +141 -0
- package/codeProgress.js +54 -0
- package/codeRelay.js +505 -0
- package/codeSent.js +68 -0
- package/codeSentinel.js +86 -0
- package/codeSubagents.js +107 -0
- package/codeTransport.js +317 -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 +561 -0
- package/credits.js +30 -0
- package/csAttest.js +112 -0
- package/decrypt.html +384 -0
- package/deviceAttest.js +527 -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 +113 -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 +91 -0
- package/l1-worker-src.js +2 -0
- package/l1-worker.js +894 -0
- package/laneAssociation.js +68 -0
- package/laneConfig.js +58 -0
- package/laneLinkCore.js +177 -0
- package/ledgerView.js +64 -0
- package/manifest.json +239 -0
- package/mcpRecommended.js +25 -0
- package/memberChange.js +125 -0
- package/mirrorBatch.js +47 -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/opRouting.js +10 -0
- package/opencodeWire.js +282 -0
- package/oprf.js +70 -0
- package/ownAgentLink.js +96 -0
- package/ownerPolicy.js +117 -0
- package/package.json +273 -4
- package/pdfOptions.js +13 -0
- package/pdfText.js +107 -0
- package/pdfjs.mjs +28 -0
- package/pdfjs.worker.mjs +28 -0
- package/pollVerdict.js +33 -0
- package/prefetchPoll.js +60 -0
- package/protectedLocal.js +426 -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/roomEmbed.js +111 -0
- package/roomName.js +177 -0
- package/roomPass.js +256 -0
- package/roomRoster.js +305 -0
- package/roomSettings.js +61 -0
- package/roomState.js +58 -0
- package/roomStreamClient.js +115 -0
- package/rosterCount.js +52 -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 +524 -0
- package/sdkAccount.js +483 -0
- package/sdkAccountDoc.js +89 -0
- package/sdkAccountSections.js +332 -0
- package/sdkAgui.js +141 -0
- package/sdkAttest.js +34 -0
- package/sdkBackup.js +507 -0
- package/sdkBackupV2.js +630 -0
- package/sdkBrowserPrivate.js +28 -0
- package/sdkBuilds.js +208 -0
- package/sdkCloudDevice.js +221 -0
- package/sdkComputers.js +1009 -0
- package/sdkDictation.js +232 -0
- package/sdkErase.js +288 -0
- package/sdkExports.js +71 -0
- package/sdkInvitations.js +34 -0
- package/sdkKeptAgent.js +188 -0
- package/sdkLaneLink.js +205 -0
- package/sdkPlan.js +96 -0
- package/sdkProtect.js +228 -0
- package/sdkRedact.js +36 -0
- package/sdkRekey.js +340 -0
- package/sdkReport.js +68 -0
- package/sdkSafeMedia.js +255 -0
- package/sdkSchedules.js +39 -0
- package/sdkSpeech.js +71 -0
- package/sdkTemporaryRooms.js +123 -0
- package/sdkTurn.js +117 -0
- package/sdkVault.js +180 -0
- package/sealShare.js +18 -0
- package/sealedNames.js +64 -0
- package/sealedReceipt.js +17 -0
- package/sentinelRelease.js +155 -0
- package/shamir.js +85 -0
- package/sharedViews.js +52 -0
- package/sheetChrome.js +450 -0
- package/siri.js +278 -0
- package/spaceClient.js +1429 -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/spaceTemplates.js +99 -0
- package/speechOut.js +102 -0
- package/splitKeyClient.js +90 -0
- package/store.js +656 -0
- package/streamHint.js +36 -0
- package/sttCloud.js +220 -0
- package/sttWorklet.js +38 -0
- package/sw-notif-core.js +540 -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 +37 -0
- package/usageReceipts.js +176 -0
- package/usageSummary.js +90 -0
- package/util.js +181 -0
- package/vault-core.js +2326 -0
- package/vault-kit.mjs +354 -0
- package/vault-screens.js +261 -0
- package/vaultAtRest.js +208 -0
- package/vaultCoreLock.js +111 -0
- package/vaultCorePush.js +140 -0
- package/vaultDeviceKey.js +95 -0
- package/vaultEnclaveHandoff.js +114 -0
- package/vaultKeep.js +287 -0
- package/vaultSealedStore.js +77 -0
- package/vaultWorkerHost.js +117 -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 +1460 -0
- package/witbitz-sdk.d.ts +1197 -0
- package/witbitz-sdk.js +4258 -0
- package/workerClient.js +16 -0
- package/workerLiveness.js +21 -0
- package/x509.js +218 -0
package/util.js
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
// util.js — pure, dep-free leaf helpers (Verified-Client Phase 1). The DOM lookup ($) and formatters,
|
|
2
|
+
// imported by space.js and (going forward) every extracted TCB module, so they need no rewiring.
|
|
3
|
+
|
|
4
|
+
import { env } from './env.js' // leaf: is this frame the vault's (saveTextFile)
|
|
5
|
+
import { attachSheetChrome, BACK_SVG, X_SVG } from './sheetChrome.js' // the one chrome every sheet gets: handle, ✕, pull-down, scrim tap, Escape
|
|
6
|
+
|
|
7
|
+
export const $ = (id) => document.getElementById(id)
|
|
8
|
+
// ★ WHERE A SHEET CAME FROM (the owner, 2026-10-10: "Pressing on x — make it return to the settings … This is true for all
|
|
9
|
+
// x. It should return to the sheet it came from … So maybe the x should be changed to <"). A sheet opened while another
|
|
10
|
+
// is open, or right after its opener closed one (Settings → Back up & recovery closes Settings, then opens), remembers
|
|
11
|
+
// that sheet; its corner button is then ‹ and goes back. Scrim, pull-down and Escape still close outright.
|
|
12
|
+
let lastClosed = null, returning = false, dismissing = false // dismissing: the person closed it (✕, scrim, pull, Escape) — never a hand-off
|
|
13
|
+
const FROM_WINDOW_MS = 1500
|
|
14
|
+
export const closeSheet = (id) => { const n = $(id); const was = !n.classList.contains('hidden'); n.classList.add('hidden'); if (was) lastClosed = dismissing ? null : { id, at: Date.now() } } // only a sheet that was OPEN hands off
|
|
15
|
+
/** The sheet `id` was opened from — '' when none (opened from the chat, the menu, a link). */
|
|
16
|
+
export const sheetFrom = (id) => { try { return $(id).dataset.from || '' } catch { return '' } }
|
|
17
|
+
function noteFrom (root, id) {
|
|
18
|
+
if (returning) { root.dataset.from = root.dataset.from || ''; return } // going BACK keeps the parent's own parent
|
|
19
|
+
let from = ''
|
|
20
|
+
try { const other = [...document.querySelectorAll('.sheet:not(.hidden)')].find((n) => n.id && n.id !== id); if (other) from = other.id } catch { /* */ }
|
|
21
|
+
if (!from && lastClosed && lastClosed.id !== id && Date.now() - lastClosed.at < FROM_WINDOW_MS) {
|
|
22
|
+
// ★ A CHILD HANDING BACK IS A RETURN, NOT A NEW STEP (the owner, 2026-10-20: Contact info → Edit → ✓ "comes back with <
|
|
23
|
+
// instead of x. I think I have it also somewhere else"): the sheet just closed was opened FROM this one, so this one
|
|
24
|
+
// keeps the parent it had — the card is where it was, not one step deeper into the one it opened.
|
|
25
|
+
const child = $(lastClosed.id)
|
|
26
|
+
if (child && child.dataset.opener === id) { root.dataset.from = root.dataset.from || ''; return }
|
|
27
|
+
from = lastClosed.id
|
|
28
|
+
}
|
|
29
|
+
root.dataset.opener = from // where it was opened from, even on a card whose corner is always ✕ (the return check above reads it)
|
|
30
|
+
root.dataset.from = root.dataset.noBack === '1' ? '' : from // a card whose corner is always ✕ (an edit card: ✕ = discard or exit, its own handler asks)
|
|
31
|
+
}
|
|
32
|
+
/** Dress the corner button for where this sheet stands: ‹ back to its parent, or ✕. Its click goes back when there is one. */
|
|
33
|
+
function dressBack (root, card, close) {
|
|
34
|
+
const x = card && card.querySelector(':scope > .sc-head .sc-x, .sc-x')
|
|
35
|
+
if (!x) return
|
|
36
|
+
const back = !!root.dataset.from
|
|
37
|
+
x.innerHTML = back ? BACK_SVG : X_SVG
|
|
38
|
+
x.setAttribute('aria-label', back ? 'Back' : 'Close'); x.title = back ? 'Back' : 'Close'
|
|
39
|
+
if (x.dataset.backWired) return
|
|
40
|
+
x.dataset.backWired = '1'
|
|
41
|
+
x.addEventListener('click', (e) => { // ahead of the chrome's own close (capture): back = close this one, reopen the parent
|
|
42
|
+
const from = root.dataset.from
|
|
43
|
+
if (!from || !document.getElementById(from)) return
|
|
44
|
+
e.stopImmediatePropagation(); e.preventDefault()
|
|
45
|
+
close()
|
|
46
|
+
returning = true
|
|
47
|
+
try { goBackTo(from) } finally { returning = false }
|
|
48
|
+
}, true)
|
|
49
|
+
}
|
|
50
|
+
// A parent reopened the way its own opener would — through its row's click when it has one (it renders its contents), else
|
|
51
|
+
// the plain open.
|
|
52
|
+
const BACK_OPENERS = { settingsSheet: () => { const b = document.getElementById('dwSettings'); if (b) { b.click(); return true } return false } }
|
|
53
|
+
/** A sheet that renders its contents when opened registers how to reopen it, so ‹ back from a child redraws it. */
|
|
54
|
+
export const setBackOpener = (id, fn) => { BACK_OPENERS[id] = () => { fn(); return true } }
|
|
55
|
+
function goBackTo (id) { if (!(BACK_OPENERS[id] && BACK_OPENERS[id]())) openSheet(id) }
|
|
56
|
+
// A bottom sheet is a `.hidden`-toggled element. Its first open dresses it: the 26 sheets of space.html were built by
|
|
57
|
+
// many hands with a Cancel row here and a handle there — the chrome is attached at this one chokepoint, so they all
|
|
58
|
+
// pull down, close on a scrim tap and on Escape, and carry the same handle and ✕ (attach is idempotent).
|
|
59
|
+
export const openSheet = (id) => {
|
|
60
|
+
const root = $(id), card = typeof root.querySelector === 'function' ? root.querySelector('.sheet-card, .csheet-card') : null // a stub DOM (node tests) gets no chrome
|
|
61
|
+
// ✕, pull-down, scrim tap and Escape do exactly what the sheet's own Cancel/Close does — its handler may resolve a
|
|
62
|
+
// promise (the confirm) or stop a camera (the scanner) — and only a sheet with no such button is simply hidden.
|
|
63
|
+
// The sheet's own way out: its `.sheet-cancel` row, or any button that just says Cancel/Close (the views picker's
|
|
64
|
+
// `#vsCancel` is a `.sheet-opt`). "Done" is left alone — on some sheets it finishes a flow rather than dismissing.
|
|
65
|
+
const ownClose = () => card && ([...card.querySelectorAll('button')].find((b) => b.classList.contains('sheet-cancel') || b.classList.contains('csheet-cancel') || /^(cancel|close)$/i.test(b.textContent.trim())) || null)
|
|
66
|
+
const close = () => { dismissing = true; try { const b = ownClose(); if (b) b.click(); else closeSheet(id) } finally { dismissing = false } }
|
|
67
|
+
// The confirm is a centred QUESTION: it gets the ways out (pull, scrim, Escape = "no") but not a handle and ✕ over
|
|
68
|
+
// its two answers.
|
|
69
|
+
const chrome = card && attachSheetChrome(root, { card, close, isOpen: () => !root.classList.contains('hidden'), head: !card.classList.contains('csheet-card') })
|
|
70
|
+
// The Cancel/Close row under a ✕ is the same button twice (the owner: "remove the cancel close"). It stays in the DOM
|
|
71
|
+
// — the chrome's close() clicks it, so a sheet's own close handler still runs — but it is no longer shown. A handle
|
|
72
|
+
// the sheet brought itself (the views picker's `.sheet-grip`) goes the same way: one handle, the chrome's ("sometimes
|
|
73
|
+
// there are two handles" — the owner's screenshot).
|
|
74
|
+
if (chrome && chrome.head) {
|
|
75
|
+
for (const b of card.querySelectorAll('button')) if (b.classList.contains('sheet-cancel') || /^(cancel|close)$/i.test(b.textContent.trim())) b.classList.add('sc-gone')
|
|
76
|
+
for (const g of card.querySelectorAll('.sheet-grip')) g.classList.add('sc-gone')
|
|
77
|
+
}
|
|
78
|
+
noteFrom(root, id)
|
|
79
|
+
if (chrome && chrome.head) dressBack(root, card, close)
|
|
80
|
+
root.classList.remove('hidden')
|
|
81
|
+
}
|
|
82
|
+
export const fmtAgo = (t) => { const s = Math.max(0, (Date.now() - t) / 1000); return s < 90 ? 'just now' : s < 3600 ? Math.round(s / 60) + ' min ago' : s < 86400 ? Math.round(s / 3600) + ' h ago' : Math.round(s / 86400) + ' d ago' }
|
|
83
|
+
export const fmtDay = (t) => { try { return new Date(t).toLocaleDateString(undefined, { month: 'short', day: 'numeric' }) } catch { return '' } }
|
|
84
|
+
export const fmtByteCount = (n) => { n = Number(n) || 0; return n < 1024 ? n + ' B' : n < 1048576 ? Math.round(n / 1024) + ' KB' : (n / 1048576).toFixed(1) + ' MB' }
|
|
85
|
+
export const fmtBytes = (b64) => fmtByteCount(Math.round((b64.length * 3) / 4))
|
|
86
|
+
export const lsGet = (k) => { try { return localStorage.getItem(k) } catch { return null } }
|
|
87
|
+
// ★ DIAGNOSTICS ARE OFF UNTIL SOMEONE ASKS FOR THEM. "Offline readiness" and "Crash trail" are instruments, not
|
|
88
|
+
// features: every person who opens Settings reads them as things they are supposed to understand, and neither has an
|
|
89
|
+
// action attached for an ordinary user (the owner, 2026-09-25). They still RECORD always — only the rows are hidden.
|
|
90
|
+
// ⛑ A URL flag alone cannot be the way in. The installed app opens at its own start_url, and Safari's localStorage is
|
|
91
|
+
// a different store from the installed app's — which is exactly why crashTrail's row exists inside the app at all.
|
|
92
|
+
// So the unlock is also five taps on the build line in Settings (settingsSheet.js), which works with no keyboard,
|
|
93
|
+
// no URL bar, and no second browser.
|
|
94
|
+
export const diagOn = () => {
|
|
95
|
+
try {
|
|
96
|
+
const u = new URLSearchParams(location.search).get('diag')
|
|
97
|
+
if (u === '1') { localStorage.setItem('space:diag', '1'); return true }
|
|
98
|
+
if (u === '0') { localStorage.removeItem('space:diag'); return false }
|
|
99
|
+
return localStorage.getItem('space:diag') === '1'
|
|
100
|
+
} catch { return false }
|
|
101
|
+
}
|
|
102
|
+
export const u8ToB64 = (u8) => { let s = ''; for (let i = 0; i < u8.length; i++) s += String.fromCharCode(u8[i]); return btoa(s) }
|
|
103
|
+
export const mkFp = (mk) => { const s = String(mk || ''); if (!s) return '—'; let h = 5381; for (let i = 0; i < s.length; i++) h = ((h << 5) + h + s.charCodeAt(i)) >>> 0; return h.toString(16).slice(0, 6) } // one-way fingerprint; two devices with the SAME room must share this or they can't read each other's state
|
|
104
|
+
export const b64ToU8 = (s) => { const b = atob(s); const u = new Uint8Array(b.length); for (let i = 0; i < b.length; i++) u[i] = b.charCodeAt(i); return u }
|
|
105
|
+
export const b64url = (u8) => u8ToB64(u8).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '')
|
|
106
|
+
|
|
107
|
+
// A first message that carries NO subject must not become the room's name. The heuristic titler fires on the first
|
|
108
|
+
// message and marks the room `titled`, which is sticky — so "Hi" became a Space's permanent name, replacing the
|
|
109
|
+
// agent's own name and blocking the LLM titler that would have described the conversation.
|
|
110
|
+
// Deliberately conservative: only obvious greetings/acknowledgements, or a message too short to carry a subject.
|
|
111
|
+
// Anything else still titles as before — a wrong-but-descriptive title is better than none, an empty pleasantry is not.
|
|
112
|
+
const TRIVIAL_TITLE = new Set([
|
|
113
|
+
'hi', 'hii', 'hey', 'hello', 'yo', 'sup', 'hiya', 'howdy', 'good morning', 'good evening', 'good afternoon',
|
|
114
|
+
'thanks', 'thank you', 'thx', 'ty', 'ok', 'okay', 'k', 'kk', 'yes', 'yep', 'yeah', 'no', 'nope', 'sure',
|
|
115
|
+
'cool', 'nice', 'great', 'excellent', 'perfect', 'awesome', 'lol', 'test', 'testing', 'ping',
|
|
116
|
+
'שלום', 'היי', 'הי', 'אהלן', 'תודה', 'תודה רבה', 'אוקיי', 'אוקי', 'בסדר', 'כן', 'לא', 'מעולה', 'מצוין', 'בדיקה',
|
|
117
|
+
])
|
|
118
|
+
|
|
119
|
+
/** Would `s` make a useless room title? (a greeting/acknowledgement, or too short to carry a subject) */
|
|
120
|
+
export function isTrivialTitle(s) {
|
|
121
|
+
const t = String(s == null ? '' : s).replace(/\s+/g, ' ').trim().replace(/[?!.,;:…]+$/u, '').toLowerCase()
|
|
122
|
+
if (!t) return true
|
|
123
|
+
if (TRIVIAL_TITLE.has(t)) return true
|
|
124
|
+
// No letters at all (emoji-only, punctuation, digits) says nothing about the subject either.
|
|
125
|
+
if (!/\p{L}/u.test(t)) return true
|
|
126
|
+
// One short word is a greeting in some language we haven't listed; two+ words are allowed to be terse.
|
|
127
|
+
return t.split(' ').length === 1 && t.length <= 4
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// ── small shared pieces the personal views (calendar / tasks / people) and their agent tools have in common ──
|
|
131
|
+
/** An empty-state block for a workspace view: big glyph, title, optional one-liner. */
|
|
132
|
+
export function wsEmpty(icon, title, text) {
|
|
133
|
+
const box = document.createElement('div'); box.className = 'ws-empty'
|
|
134
|
+
const k = document.createElement('div'); k.className = 'ws-empty-k'; k.textContent = icon; box.appendChild(k)
|
|
135
|
+
const t = document.createElement('div'); t.className = 'ws-empty-t'; t.textContent = title; box.appendChild(t)
|
|
136
|
+
if (text) { const p = document.createElement('div'); p.className = 'ws-empty-p'; p.textContent = text; box.appendChild(p) }
|
|
137
|
+
return box
|
|
138
|
+
}
|
|
139
|
+
export const plural = (n, one, many) => n + ' ' + (n === 1 ? one : many)
|
|
140
|
+
/** A fresh local uid for a calendar/task/contact item — random when the platform allows, time-derived otherwise. */
|
|
141
|
+
export const newUid = () => { try { return 'u-' + [...crypto.getRandomValues(new Uint8Array(10))].map((x) => x.toString(36)).join('').slice(0, 14) } catch { return 'u-' + Date.now().toString(36) } }
|
|
142
|
+
/** Hand the user a text file (an .ics / .vcf / .md export) through a transient object URL. */
|
|
143
|
+
// FRAMED? ASK THE VAULT TO SAVE. `<a download>` on a blob is INERT inside a cross-origin iframe on iOS — it throws
|
|
144
|
+
// nothing and does nothing, so an export "succeeds", says so, and no save sheet ever appears. The vault is the
|
|
145
|
+
// top-level document and can actually perform the save, so hand it the bytes. Content only; no key material.
|
|
146
|
+
// Unframed (the standalone app) is unchanged — the link path below still runs.
|
|
147
|
+
export function saveTextFile(name, text, mime) {
|
|
148
|
+
const type = mime || 'text/plain;charset=utf-8'
|
|
149
|
+
try {
|
|
150
|
+
if (typeof window !== 'undefined' && window.top && window.top !== window) {
|
|
151
|
+
// TARGET THE FRAMER EXPLICITLY. This payload is the user's DECRYPTED conversation, so '*' would be careless even
|
|
152
|
+
// though the app's own CSP frame-ancestors admits only the vault. ancestorOrigins names the real top origin;
|
|
153
|
+
// where the browser does not provide it, fall through to the link rather than broadcast.
|
|
154
|
+
const top = (() => { try { return (location.ancestorOrigins && location.ancestorOrigins[location.ancestorOrigins.length - 1]) || '' } catch { return '' } })()
|
|
155
|
+
// ONLY THE VAULT answers saveFile: in the regular app's assistant panel (same origin) or an embed (another host that is
|
|
156
|
+
// not our vault) the bytes went to a page that ignores them, and nothing was saved (2026-10-17) — those take the link.
|
|
157
|
+
if (top && top !== location.origin && env.crossOrigin) { window.top.postMessage({ ch: 'vcHandoff', t: 'saveFile', name, text, mime: type }, top); return }
|
|
158
|
+
}
|
|
159
|
+
} catch (e) { /* cross-origin probe threw → fall through to the link */ }
|
|
160
|
+
const url = URL.createObjectURL(new Blob([text], { type })); const a = document.createElement('a'); a.href = url; a.download = name; document.body.appendChild(a); a.click(); a.remove(); setTimeout(() => URL.revokeObjectURL(url), 4000)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// HTML-escape third-party text before it is interpolated into markup (moved from space.js, verified-client split step 50).
|
|
164
|
+
export function escapeHtml(s) { return String(s).replace(/[&<>"']/g, (c) => ({ '&':'&','<':'<','>':'>','"':'"',"'":''' }[c])) }
|
|
165
|
+
// A ledger entry id, canonical across the mirror: an entry mirrored from a shared room carried a `sh:<room>:` prefix once;
|
|
166
|
+
// pins and captions key on the canonical form (moved from space.js, step 50).
|
|
167
|
+
import { canonId, entryKeyOf } from './ledgerView.js' // the one rule, shared with the SDK (docs/sdk-convergence.md 4d)
|
|
168
|
+
export { canonId }
|
|
169
|
+
|
|
170
|
+
// ★ THE MESSAGE KEY — and the SERVER computes the same string (agent/spaceService.mjs `entryKey`). Keep the two in
|
|
171
|
+
// step or a reaction lands on nothing: the server recomputes this from its own ledger and 404s a target it cannot
|
|
172
|
+
// find, so drift shows up as "the emoji does nothing" rather than as an error. A member's entry `id` is the MEMBER
|
|
173
|
+
// id — two of their messages differ only by `ts` — so neither half identifies a message alone; the pair does.
|
|
174
|
+
export const entryKey = entryKeyOf // ledgerView.js — the SDK keys reactions and replies the same way
|
|
175
|
+
|
|
176
|
+
// A FIELD IS FOCUSED BY ITSELF ONLY WHERE THERE IS A MOUSE (the owner, 2026-10-14: "When I press a contact in android it
|
|
177
|
+
// automatically opens the composer. On iPhone the composer stays closed. On iPhone it is better" → "Sweep for this auto
|
|
178
|
+
// focus"). iOS ignores a focus that runs outside the tap (a timer, after a load); Android raises the keyboard for it. A
|
|
179
|
+
// focus made INSIDE a tap (Reply, Rename, the search icon) is the person asking to type and stays as it is.
|
|
180
|
+
export const hasMouse = () => { try { return matchMedia('(hover:hover) and (pointer:fine)').matches } catch { return false } }
|
|
181
|
+
export function focusIfMouse(el) { if (el && hasMouse()) { try { el.focus() } catch { /* a nicety */ } } }
|