@witbitz/sdk 4.3.0 → 4.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/README.md +2 -2
  2. package/a2aCore.js +26 -5
  3. package/accountErase.js +6 -1
  4. package/accountRecord.js +2 -2
  5. package/agentDoorTools.js +28 -0
  6. package/chatLock.js +16 -0
  7. package/cloudDevicePins.js +2 -2
  8. package/codeAttachments.js +100 -0
  9. package/codeCache.js +149 -0
  10. package/codeCloud.js +0 -2
  11. package/codeComputers.js +1 -0
  12. package/codeFolders.js +116 -0
  13. package/codeHistory.js +76 -0
  14. package/codeLanguage.js +54 -0
  15. package/codeModes.js +2 -0
  16. package/codeProgress.js +54 -0
  17. package/codeSent.js +68 -0
  18. package/codeSubagents.js +107 -0
  19. package/codeTransport.js +22 -0
  20. package/connections.js +17 -18
  21. package/deviceAttest.js +9 -3
  22. package/idb.js +19 -3
  23. package/jobAgents.js +2 -2
  24. package/keptMerge.js +9 -2
  25. package/l1-worker-src.js +1 -1
  26. package/l1-worker.js +93 -30
  27. package/laneAssociation.js +68 -0
  28. package/laneConfig.js +4 -3
  29. package/manifest.json +80 -61
  30. package/memberChange.js +4 -2
  31. package/mirrorBatch.js +47 -0
  32. package/opRouting.js +10 -0
  33. package/package.json +21 -2
  34. package/pdfOptions.js +13 -0
  35. package/pdfText.js +107 -0
  36. package/pdfjs.mjs +28 -0
  37. package/pdfjs.worker.mjs +28 -0
  38. package/protectedLocal.js +18 -2
  39. package/removedMessage.js +1 -1
  40. package/roomEmbed.js +111 -0
  41. package/roomName.js +1 -1
  42. package/roomRoster.js +21 -5
  43. package/rosterCount.js +6 -3
  44. package/sdkA2A.js +160 -40
  45. package/sdkAccount.js +17 -4
  46. package/sdkAccountDoc.js +11 -3
  47. package/sdkAccountSections.js +117 -8
  48. package/sdkBackup.js +35 -8
  49. package/sdkCloudDevice.js +8 -2
  50. package/sdkComputers.js +582 -53
  51. package/sdkDictation.js +114 -24
  52. package/sdkErase.js +9 -4
  53. package/sdkExports.js +4 -2
  54. package/sdkLaneLink.js +3 -3
  55. package/sdkPlan.js +4 -2
  56. package/sdkRekey.js +50 -17
  57. package/sdkReport.js +1 -1
  58. package/sdkSafeMedia.js +1 -1
  59. package/sdkSpeech.js +19 -2
  60. package/sdkTemporaryRooms.js +123 -0
  61. package/sdkVault.js +66 -10
  62. package/sentinelRelease.js +1 -0
  63. package/sharedViews.js +17 -3
  64. package/siri.js +114 -7
  65. package/spaceClient.js +16 -5
  66. package/spaceEmailGate.js +2 -2
  67. package/spaceTemplates.js +99 -0
  68. package/speechOut.js +4 -2
  69. package/store.js +83 -14
  70. package/sw-notif-core.js +9 -7
  71. package/turnVerdict.js +1 -0
  72. package/vault-core.js +480 -112
  73. package/vault-kit.mjs +2 -2
  74. package/vault-screens.js +5 -7
  75. package/vaultAtRest.js +35 -4
  76. package/vaultKeep.js +9 -3
  77. package/vaultWorkerHost.js +23 -4
  78. package/witbitz-admin.mjs +12 -11
  79. package/witbitz-sdk.d.ts +115 -24
  80. package/witbitz-sdk.js +572 -149
package/protectedLocal.js CHANGED
@@ -36,7 +36,7 @@ export const PROTECTED_PREFIXES = Object.freeze([
36
36
  'space:awshandle', // THIS device's own AWS key (a handle on the person's AWS budget — acctV2Wiring.js awsHandleStore): its PRIVATE half
37
37
  'space:invitekey', 'space:acctkey', // the invite key, the account-store key
38
38
  'space:attestedBox:', // an attested kind's invite box — its PRIVATE half (attestedBox.js), like the invite key above
39
- 'space:connectionKeys', 'space:siri', 'space:a2a', 'space:code', 'space:clouddevice', // Connections call keys, the Siri inbox key, outside-agent keys, the Code pairing
39
+ 'space:connectionKeys', 'space:siri', 'space:siri-pending-edit', 'space:a2a', 'space:a2a-pending-edit', 'space:a2a-pending-removals', 'space:a2a-delivered', 'space:code', 'space:clouddevice', // Connections call keys, the Siri inbox key, outside-agent keys, the Code pairing
40
40
  'space:connPending', 'space:androidConsent', // pending grants and the short-lived key for an Android connector return
41
41
  'space:contacts', 'space:agentlinks', 'space:recents', // content: people, agent links, the room list with its titles
42
42
  'space:blocks', // the people you blocked (blocks.js) — names and @usernames
@@ -80,7 +80,11 @@ export const cfgSaysProtected = (c) => !!(c && c.on && c.protect && c.protect.on
80
80
  // And a reviewed handful of SETTINGS that name no room, no person and no activity, which modules read ONCE at load — before
81
81
  // the unlock — so sealing them would reset them on every launch: feature flags, the side panel's width, the map language,
82
82
  // the diagnostics switches, the boot counter and the PUBLIC app catalog. Anything naming a room or a person is sealed.
83
- export const STAYS_CLEAR = Object.freeze(['witbitz-builder-reset-pending', 'space:lock', 'vault:lock', FRAMED_MARK,
83
+ // ⚑ THE SIGN-OUT MARKERS STAY CLEAR (second review, 2026-11-27): "a wipe is still to finish" must outlive the wipe itself. Sealed, the
84
+ // marker went with forgetProtectedLocal() in the same wipe (and read as absent while locked, and to the loader, which reads before
85
+ // this wrapper exists) — so on a protected device a wipe whose key clean-up failed was reported clean and never retried, and the
86
+ // previous account's keys could meet the next one. They name no room and no person ('1', 'reset', or the database names to drop).
87
+ export const STAYS_CLEAR = Object.freeze(['witbitz-builder-reset-pending', 'witbitz-spaces-signout-pending', 'witbitz-device-signout-pending', 'witbitz-device-reset-confirmed', 'space:lock', 'vault:lock', FRAMED_MARK,
84
88
  'space:maplang', 'space:maplang.eff', 'space:mapsapp', 'space:settings:open', 'space:side', 'space:side-hidden', 'space:side-w', 'space:assistw',
85
89
  'space:ohttp', 'space:caretdbg', 'space:rotlab', 'space:diag', 'space:notifPreview', 'space:boots', 'space:apps',
86
90
  'space:channel', 'space:runAt', // Official / Beta / Pinned + the newest build time run (channelChoice.js): read before the unlock, or a locked device would fall back to Official
@@ -160,6 +164,18 @@ export async function durableRead (name) {
160
164
 
161
165
  // LOCKED or MEMORY-ONLY, an entry still CLEAR on disk (never migrated: an unsecured computer, or a flag an older build wrote)
162
166
  // reads through — unless it is a secret: those are only ever answered by the overlay.
167
+ /** Return the exact disk entry that still opens to the pending operation. Hosted storage mirrors this entry. */
168
+ export async function durableEntry(name, value) {
169
+ await chain
170
+ if (!active || !raw) return rawGet(name) === value ? [name, value] : null
171
+ if (memoryOnly || !key || !namer) return null
172
+ try {
173
+ const opaque = await namer.opaque(name), stored = raw.getItem.call(localStorage, opaque)
174
+ const blob = stored && parseSealed(stored)
175
+ return blob && String(await open(key, blob)) === value ? [opaque, stored] : null
176
+ } catch { return null }
177
+ }
178
+
163
179
  const readThrough = (n) => { if (isProtectedKey(n)) return null; const v = raw.getItem.call(localStorage, n); return v != null && !parseSealed(v) ? v : null }
164
180
  const enumerate = () => {
165
181
  if (names) return names
package/removedMessage.js CHANGED
@@ -3,7 +3,7 @@ export const SHARED_REMOVED_TEXT = 'Removed in the shared Space'
3
3
  /** Replacement, never a merge: no body, media, tool output or attachment references survive. */
4
4
  export function removedCopy(e) {
5
5
  const { id, ts, name, from, self, verified, user, spk, vspk, sid } = e || {}
6
- return { id, ts, name, from, self, verified, user, spk, vspk, sid, kind: 'text', text: REMOVED_TEXT, removedByWitbitz: true }
6
+ return { id, ts, name, from, self, verified, user, spk, vspk, sid, ...(e?.keyOnly ? { keyOnly: true } : {}), kind: 'text', text: REMOVED_TEXT, removedByWitbitz: true }
7
7
  }
8
8
  export function sharedRemovedCopy(e) {
9
9
  const { id, ts, name, from, self } = e || {}
package/roomEmbed.js ADDED
@@ -0,0 +1,111 @@
1
+ const object = value => value !== null && typeof value === 'object' && !Array.isArray(value)
2
+ const types = new Set(['string', 'number', 'boolean', 'array', 'object'])
3
+ const validName = name => /^[a-zA-Z0-9_]{1,64}$/.test(name) && !Object.hasOwn(Object.prototype, name)
4
+ export function applySkills(config, skills) {
5
+ if (skills === undefined) return
6
+ if (!object(skills) || Object.keys(skills).length > 16 || !Object.entries(skills).every(([name, spec]) => validName(name) && object(spec) &&
7
+ [spec.in, ...(spec.out === undefined ? [] : [spec.out])].every(schema => object(schema) && Object.keys(schema).length <= 16 &&
8
+ Object.entries(schema).every(([key, type]) => validName(key) && types.has(type)))))
9
+ throw Object.assign(new Error('Each skill needs a name and a typed input schema.'), { code: 'invalid_argument' })
10
+ config.skills = Object.fromEntries(Object.entries(skills).map(([name, spec]) => [name, { in: { ...spec.in } }]))
11
+ const protocol = skillProtocol(skills)
12
+ if (protocol) config.persona = (config.persona || '') + '\n' + protocol
13
+ }
14
+
15
+ export function skillProtocol(skills) {
16
+ const names = Object.keys(skills || {})
17
+ if (!names.length) return ''
18
+ const rows = names.map((n) => ' • ' + n + '(' + JSON.stringify((skills[n] || {}).in || {}) + ')')
19
+ return [
20
+ '',
21
+ '--- YOUR MCP SKILLS (the app invokes these on you as TYPED tool calls over the bridge, NOT chat messages) ---',
22
+ ...rows,
23
+ 'When one is invoked you are told exactly which skill and with what arguments. Handle it FULLY — use your platform',
24
+ 'tools (read_url, web_search, the map/photo tools, …) whenever they make the answer better — then reply with the',
25
+ 'finished answer for the reader. Do not just echo the raw arguments back.',
26
+ ].join('\n')
27
+ }
28
+
29
+ export function embeddedInvite(template, link, origin) {
30
+ if (typeof template !== 'string' || template.length > 2000 || template.split('{link}').length !== 2 || !link)
31
+ throw Object.assign(new Error('An invite template needs a single {link} placeholder.'), { code: 'invalid_argument' })
32
+ const base = new URL(origin)
33
+ const url = new URL(template.replace('{link}', encodeURIComponent(link)), base.origin)
34
+ if (!['http:', 'https:'].includes(base.protocol) || url.origin !== base.origin || url.username || url.password)
35
+ throw Object.assign(new Error('The invite must open the embedding application.'), { code: 'invalid_argument' })
36
+ return url.href
37
+ }
38
+
39
+ export function setLiveDoc(docs, name, text) {
40
+ const key = String(name || 'document').slice(0, 80)
41
+ if (typeof text === 'string' && text) docs[key] = text.slice(0, 4000)
42
+ else delete docs[key]
43
+ }
44
+ export function formatLiveDocs(embedLiveDocs, meet = '') {
45
+ const names = Object.keys(embedLiveDocs).filter((n) => embedLiveDocs[n])
46
+ if (!names.length) return meet || undefined
47
+ let body = ''
48
+ for (const n of names) body += '[' + String(n).slice(0, 80) + ']\n' + String(embedLiveDocs[n]) + '\n\n'
49
+ return (meet + '=== LIVE CONTEXT (the CURRENT text of what the user has open right now — e.g. a draft, a call transcript. It updates live; reason over THIS and quote it exactly. It is not a saved file.) ===\n\n' + body + '=== end live context ===').slice(0, 4000) // matches the server's 4KB context cap; large sources get windowed/summarized later
50
+ }
51
+
52
+ export function roomEmbed(space, knownLane = () => false) {
53
+ const docs = Object.create(null), watches = new Set()
54
+ const owner = () => space._wb?.vault ? space._wb._memoryGeneration : space._wb?._archiveGeneration
55
+ const generation = space._memoryOwner ?? owner()
56
+ const active = () => !space._stopped && generation === owner()
57
+ function check() {
58
+ if (!active()) throw Object.assign(new Error('The Space closed or the account changed.'), { code: 'closed' })
59
+ }
60
+ async function state(patch) {
61
+ check()
62
+ const r = patch === undefined ? await space._client.state(space.room, space._mk, 'embed')
63
+ : await space._client.state(space.room, space._mk, 'embed', patch, '', 'embed')
64
+ check()
65
+ if (r?.status !== 200) throw Object.assign(new Error('The embedded state could not be synchronized.'), { code: r?.error || 'unavailable' })
66
+ return r
67
+ }
68
+ return {
69
+ context: () => active() ? formatLiveDocs(docs) : undefined,
70
+ close() { for (const stop of [...watches]) stop(); for (const name of Object.keys(docs)) delete docs[name] },
71
+ api: {
72
+ async invite(template) {
73
+ check()
74
+ if (space._sharedRoom || space._detachedLane || knownLane()) throw Object.assign(new Error('A private lane cannot be shared'), { code: 'private_lane' })
75
+ if (space._wb?.vault) return space._wb.vault.share(space, { hostInviteTemplate: template })
76
+ return embeddedInvite(template, space.shareLink, globalThis.location?.origin)
77
+ },
78
+ async read() { return (await state()).state ?? null },
79
+ async update(patch) {
80
+ if (!object(patch)) throw Object.assign(new Error('A state update needs an object.'), { code: 'invalid_argument' })
81
+ await state(patch)
82
+ },
83
+ watch(fn) {
84
+ check()
85
+ if (typeof fn !== 'function') throw new TypeError('A state listener is required.')
86
+ let timer, stopped = false, version = -1
87
+ const stop = () => { stopped = true; clearTimeout(timer); watches.delete(stop) }
88
+ async function poll() {
89
+ try {
90
+ const r = await state(), v = r.v || 0
91
+ if (!stopped && v > version) { version = v; fn(r.state ?? null) }
92
+ } catch { /* retry when the room becomes available */ }
93
+ if (!stopped && active()) timer = setTimeout(poll, 2500)
94
+ else stop()
95
+ }
96
+ watches.add(stop); void poll()
97
+ return stop
98
+ },
99
+ setLiveDocument(name, text) { check(); setLiveDoc(docs, name, text) },
100
+ },
101
+ }
102
+ }
103
+
104
+ export function roomInviteFlags(link) {
105
+ try {
106
+ const url = new URL(link, 'https://example.invalid/')
107
+ const fragment = new URLSearchParams(url.hash.slice(1))
108
+ const has = (key, value) => url.searchParams.getAll(key).includes(value) || fragment.getAll(key).includes(value)
109
+ return { gated: has('gate', 'email'), lanes: has('lanes', '1') }
110
+ } catch { return { gated: false, lanes: false } }
111
+ }
package/roomName.js CHANGED
@@ -105,7 +105,7 @@ export function peopleIn(entries) {
105
105
  const list = Array.isArray(entries) ? entries : []
106
106
  const personKey = personKeyer(list)
107
107
  for (const e of list) {
108
- if (!e || e.self || e.sys || isLaneCopy(e) || e.kind === 'fork') continue
108
+ if (!e || e.self || e.sys || e.kind === 'safe' || isLaneCopy(e) || e.kind === 'fork') continue
109
109
  if (e.kind === TITLE_KIND && !e.manual) continue
110
110
  const id = personKey(e)
111
111
  if (id) who.add(id)
package/roomRoster.js CHANGED
@@ -1,7 +1,16 @@
1
1
  import { memberHash } from './rosterHash.js'
2
2
 
3
3
  /** Resolve a verified post against the server's signing-key directory. A chosen name alone proves no address. */
4
- export function verifiedPosters(entries, seen) {
4
+ export function verifiedSigningIds(entries) {
5
+ const ids = new Set()
6
+ for (const e of entries || []) {
7
+ const key = e?.spk || e?.vspk
8
+ if (e?.verified === true && !e.keyOnly && !e.self && e.kind !== 'agent' && key?.x && key?.y) ids.add(key.x + '.' + key.y)
9
+ }
10
+ return ids
11
+ }
12
+
13
+ export function verifiedPosters(entries, seen, { withId = false } = {}) {
5
14
  const posters = []
6
15
  for (const e of entries || []) {
7
16
  const point = e?.spk || e?.vspk
@@ -10,9 +19,10 @@ export function verifiedPosters(entries, seen) {
10
19
  const person = Object.prototype.hasOwnProperty.call(seen, id) ? seen[id] : null
11
20
  if (person?.left) continue
12
21
  const owner = person?.swapped ? null : person
13
- const email = owner?.email || (e.emailNameVerified === true ? String(e.name || '').trim().toLowerCase() : '')
22
+ const stampedEmail = (e.kind === 'data' || e.kind === 'title') && typeof e.email === 'string' ? e.email.trim().toLowerCase() : ''
23
+ const email = owner?.email || stampedEmail || (e.emailNameVerified === true ? String(e.name || '').trim().toLowerCase() : '')
14
24
  const user = owner?.user || e.user || ''
15
- if (email || user) posters.push({ email, user })
25
+ if (email || user) posters.push({ email, user, ...(withId && !person?.swapped ? { id } : {}) })
16
26
  }
17
27
  return posters
18
28
  }
@@ -64,6 +74,7 @@ function clean (e) {
64
74
  return out
65
75
  }
66
76
 
77
+ export const hasVerifiedClaim = roster => rows(roster).some(e => e.verified === true)
67
78
  const rows = (roster) => (Array.isArray(roster) ? roster : Array.isArray(roster?.people) ? roster.people : []).map(clean).filter(Boolean)
68
79
  // Join order, with the id as a tiebreak: two devices can stamp the same millisecond, and without this two viewers
69
80
  // could number them oppositely — which would quietly break the one promise a label makes.
@@ -123,8 +134,9 @@ export function membersView ({ allow = {}, rows = [], seenIdentity = () => '', s
123
134
  if (had) { had.email ||= p.email; had.user ||= p.user; had.me ||= p.me; return }
124
135
  people.set(key, { ...p })
125
136
  }
137
+ const postedById = new Map((posters || []).filter(p => p?.id && (p.email || p.user)).map(p => [p.id, p]))
126
138
  for (const r of rows) {
127
- const p = personOf(r.id)
139
+ const p = personOf(r.id) || postedById.get(r.id)
128
140
  const isMe = r.id === mineId || (!!me && !!p && p.email === me)
129
141
  // A verified room lists MEMBERS: a row nobody vouched for (a typed name — a reader with the link, or a device that
130
142
  // announced before it had its key) is not a member and is not shown. The owner read "Tomer · unverified" beside a
@@ -178,7 +190,11 @@ export function membersView ({ allow = {}, rows = [], seenIdentity = () => '', s
178
190
  /** A verified room's guest book does not yet SHOW this row as signed in (`seen`, the server's record of who the email gate
179
191
  * verified): announce again even with nothing changed — a lost write (two members announcing at once) would otherwise leave the
180
192
  * member nameless for ever, and a member change in place cannot reach a hidden member it cannot name. */
181
- export const unseenIn = (seen, id) => !!id && !(seen && typeof seen === 'object' && seen[id] && seen[id].email)
193
+ // ⚑ A RECORD MARKED `left` IS NOT A SIGHTING (the owner, 2026-11-27: removed from a Space and added back, he opened it and the owner's
194
+ // list said "Not yet opened" for good). A removal — or leaving — marks the member's record `left` (roomLeave.markLeft) and every
195
+ // reader skips such a record; it still holds the email, so this said "seen", the device never announced again, and the mark never
196
+ // cleared. The server writes a fresh record over a `left` one (spaceService roster_seen `mine`).
197
+ export const unseenIn = (seen, id) => !!id && !(seen && typeof seen === 'object' && seen[id] && seen[id].email && !seen[id].left)
182
198
  /** Seen, but before the record kept WHICH list entries this person is (2026-10-23, rosterCount samePeople): announced ONCE more
183
199
  * per room and key on this page (never retried — a server that does not keep them yet answers the same) so one person on the list by email and by
184
200
  * @username counts once. */
package/rosterCount.js CHANGED
@@ -12,11 +12,14 @@ const list = (v) => (Array.isArray(v) ? v.map(norm).filter(Boolean) : [])
12
12
  /** Exactly one admitted identity, and it is the signed-in person; no usernames or domains. */
13
13
  export async function isSoloVerified(cfg, room, me, { hash = memberHash } = {}) {
14
14
  const email = norm(me), allow = cfg?.allow
15
- if (!email || cfg?.admission !== 'email' || !allow || allow.users?.length || allow.domains?.length) return false
15
+ if (!email || cfg?.admission !== 'email' || !allow || allow.users?.length || allow.domains?.length || allow.tags?.length) return false
16
16
  const shown = Array.isArray(allow.emails) ? allow.emails.map(norm) : []
17
17
  const hidden = Array.isArray(allow.mh) ? allow.mh : []
18
- if (shown.length + hidden.length !== 1) return false
19
- return shown.length ? shown[0] === email : hidden[0] === await hash(email, room)
18
+ if (!shown.length && !hidden.length) return false
19
+ if (shown.some(address => address !== email)) return false
20
+ if (!hidden.length) return true
21
+ const expected = await hash(email, room)
22
+ return hidden.every(h => h === expected)
20
23
  }
21
24
 
22
25
  export async function rosterParticipants (space, roomSalt, { seen = null } = {}) {