@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.
Files changed (236) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +20 -2
  3. package/a2aCore.js +221 -0
  4. package/a2aShared.js +27 -0
  5. package/accountErase.js +228 -0
  6. package/accountIndexDoc.js +122 -0
  7. package/accountOwner.js +59 -0
  8. package/accountRecord.js +90 -0
  9. package/accountScope.js +114 -0
  10. package/accountSeal.js +42 -0
  11. package/accountStores.js +173 -0
  12. package/acctV2App.js +619 -0
  13. package/acctV2Check.js +29 -0
  14. package/acctV2Client.js +382 -0
  15. package/acctV2Keys.js +43 -0
  16. package/acctV2Legacy.js +14 -0
  17. package/acctV2Switch.js +80 -0
  18. package/acctV2UiCore.js +857 -0
  19. package/acctV2WebAuthn.js +61 -0
  20. package/acctV2Wire.js +59 -0
  21. package/address.js +42 -0
  22. package/agentDoorTools.js +28 -0
  23. package/attestedBox.js +30 -0
  24. package/attestedRooms.js +78 -0
  25. package/awsKey.js +98 -0
  26. package/backupRecord.js +106 -0
  27. package/backupVault.js +97 -0
  28. package/blocks.js +115 -0
  29. package/blocksPush.js +64 -0
  30. package/browseSeal.js +103 -0
  31. package/cbor.js +225 -0
  32. package/changePush.js +75 -0
  33. package/chatLock.js +165 -0
  34. package/chatLockSw.js +13 -0
  35. package/cloudDeviceBuilds.js +11 -0
  36. package/cloudDevicePins.js +33 -0
  37. package/cloudDeviceSeal.js +53 -0
  38. package/codeAttachments.js +100 -0
  39. package/codeBrowse.js +224 -0
  40. package/codeCache.js +149 -0
  41. package/codeCloud.js +650 -0
  42. package/codeCloudKeys.js +112 -0
  43. package/codeCommands.js +167 -0
  44. package/codeComputers.js +389 -0
  45. package/codeEgress.js +123 -0
  46. package/codeFilesRoutes.js +17 -0
  47. package/codeFolders.js +116 -0
  48. package/codeHistory.js +76 -0
  49. package/codeLanguage.js +54 -0
  50. package/codeMkdir.js +8 -0
  51. package/codeModes.js +59 -0
  52. package/codeOrphanKeys.js +42 -0
  53. package/codeOutputs.js +141 -0
  54. package/codeProgress.js +54 -0
  55. package/codeRelay.js +505 -0
  56. package/codeSent.js +68 -0
  57. package/codeSentinel.js +86 -0
  58. package/codeSubagents.js +107 -0
  59. package/codeTransport.js +317 -0
  60. package/codeUndo.js +48 -0
  61. package/compress.js +24 -0
  62. package/config.js +11 -0
  63. package/connCatalog.js +164 -0
  64. package/connDisp.js +76 -0
  65. package/connOtherWays.js +74 -0
  66. package/connPending.js +16 -0
  67. package/connWrap.js +53 -0
  68. package/connectionEntry.js +89 -0
  69. package/connections.js +561 -0
  70. package/credits.js +30 -0
  71. package/csAttest.js +112 -0
  72. package/decrypt.html +384 -0
  73. package/deviceAttest.js +527 -0
  74. package/deviceCall.js +54 -0
  75. package/deviceKeyCore.js +41 -0
  76. package/deviceSeal.js +59 -0
  77. package/e2ee.js +323 -0
  78. package/eat.js +103 -0
  79. package/emailFork.js +275 -0
  80. package/emailSignIn.js +81 -0
  81. package/emptySpaces.js +111 -0
  82. package/encSource.js +55 -0
  83. package/enclaveAccept.js +214 -0
  84. package/enclaveClaim.js +241 -0
  85. package/enclaveRoute.js +102 -0
  86. package/enclaveSnapshotMerge.js +44 -0
  87. package/entrySig.js +165 -0
  88. package/env.js +73 -0
  89. package/eraseFile.js +58 -0
  90. package/followImage.js +86 -0
  91. package/healNames.js +45 -0
  92. package/idb.js +113 -0
  93. package/idbSeal.js +119 -0
  94. package/indexGone.js +12 -0
  95. package/invite.js +51 -0
  96. package/inviteEnroll.js +67 -0
  97. package/inviteSend.js +68 -0
  98. package/jobAgents.js +87 -0
  99. package/keptMerge.js +91 -0
  100. package/l1-worker-src.js +2 -0
  101. package/l1-worker.js +894 -0
  102. package/laneAssociation.js +68 -0
  103. package/laneConfig.js +58 -0
  104. package/laneLinkCore.js +177 -0
  105. package/ledgerView.js +64 -0
  106. package/manifest.json +239 -0
  107. package/mcpRecommended.js +25 -0
  108. package/memberChange.js +125 -0
  109. package/mirrorBatch.js +47 -0
  110. package/mkseal.js +101 -0
  111. package/nativePush.js +153 -0
  112. package/nitroVerify.js +220 -0
  113. package/noble-p256.js +27 -0
  114. package/notice.js +116 -0
  115. package/notifKey.js +58 -0
  116. package/offlineBundle.js +62 -0
  117. package/ohttp.js +177 -0
  118. package/opRouting.js +10 -0
  119. package/opencodeWire.js +282 -0
  120. package/oprf.js +70 -0
  121. package/ownAgentLink.js +96 -0
  122. package/ownerPolicy.js +117 -0
  123. package/package.json +273 -4
  124. package/pdfOptions.js +13 -0
  125. package/pdfText.js +107 -0
  126. package/pdfjs.mjs +28 -0
  127. package/pdfjs.worker.mjs +28 -0
  128. package/pollVerdict.js +33 -0
  129. package/prefetchPoll.js +60 -0
  130. package/protectedLocal.js +426 -0
  131. package/pushCore.js +42 -0
  132. package/recovery.js +107 -0
  133. package/regions.js +42 -0
  134. package/removedMessage.js +11 -0
  135. package/renameRefusal.js +9 -0
  136. package/replyQuote.js +34 -0
  137. package/reqEnvelope.js +126 -0
  138. package/roomDefaultPrefs.js +76 -0
  139. package/roomDelete.js +109 -0
  140. package/roomEmbed.js +111 -0
  141. package/roomName.js +177 -0
  142. package/roomPass.js +256 -0
  143. package/roomRoster.js +305 -0
  144. package/roomSettings.js +61 -0
  145. package/roomState.js +58 -0
  146. package/roomStreamClient.js +115 -0
  147. package/rosterCount.js +52 -0
  148. package/rosterHash.js +13 -0
  149. package/rowSchema.js +113 -0
  150. package/safeMedia.js +116 -0
  151. package/safeMediaPins.js +17 -0
  152. package/schedulesDoc.js +78 -0
  153. package/sdkA2A.js +524 -0
  154. package/sdkAccount.js +483 -0
  155. package/sdkAccountDoc.js +89 -0
  156. package/sdkAccountSections.js +332 -0
  157. package/sdkAgui.js +141 -0
  158. package/sdkAttest.js +34 -0
  159. package/sdkBackup.js +507 -0
  160. package/sdkBackupV2.js +630 -0
  161. package/sdkBrowserPrivate.js +28 -0
  162. package/sdkBuilds.js +208 -0
  163. package/sdkCloudDevice.js +221 -0
  164. package/sdkComputers.js +1009 -0
  165. package/sdkDictation.js +232 -0
  166. package/sdkErase.js +288 -0
  167. package/sdkExports.js +71 -0
  168. package/sdkInvitations.js +34 -0
  169. package/sdkKeptAgent.js +188 -0
  170. package/sdkLaneLink.js +205 -0
  171. package/sdkPlan.js +96 -0
  172. package/sdkProtect.js +228 -0
  173. package/sdkRedact.js +36 -0
  174. package/sdkRekey.js +340 -0
  175. package/sdkReport.js +68 -0
  176. package/sdkSafeMedia.js +255 -0
  177. package/sdkSchedules.js +39 -0
  178. package/sdkSpeech.js +71 -0
  179. package/sdkTemporaryRooms.js +123 -0
  180. package/sdkTurn.js +117 -0
  181. package/sdkVault.js +180 -0
  182. package/sealShare.js +18 -0
  183. package/sealedNames.js +64 -0
  184. package/sealedReceipt.js +17 -0
  185. package/sentinelRelease.js +155 -0
  186. package/shamir.js +85 -0
  187. package/sharedViews.js +52 -0
  188. package/sheetChrome.js +450 -0
  189. package/siri.js +278 -0
  190. package/spaceClient.js +1429 -0
  191. package/spaceConfig.js +81 -0
  192. package/spaceEmailGate.js +813 -0
  193. package/spaceExport.js +125 -0
  194. package/spaceFork.js +216 -0
  195. package/spaceLock.js +358 -0
  196. package/spacePasskey.js +180 -0
  197. package/spaceTemplates.js +99 -0
  198. package/speechOut.js +102 -0
  199. package/splitKeyClient.js +90 -0
  200. package/store.js +656 -0
  201. package/streamHint.js +36 -0
  202. package/sttCloud.js +220 -0
  203. package/sttWorklet.js +38 -0
  204. package/sw-notif-core.js +540 -0
  205. package/tempList.js +48 -0
  206. package/tinfoilVerifier.js +78 -0
  207. package/toolBooks.js +31 -0
  208. package/toolRules.js +52 -0
  209. package/turnCerts.js +254 -0
  210. package/turnFeed.js +58 -0
  211. package/turnVerdict.js +37 -0
  212. package/usageReceipts.js +176 -0
  213. package/usageSummary.js +90 -0
  214. package/util.js +181 -0
  215. package/vault-core.js +2326 -0
  216. package/vault-kit.mjs +354 -0
  217. package/vault-screens.js +261 -0
  218. package/vaultAtRest.js +208 -0
  219. package/vaultCoreLock.js +111 -0
  220. package/vaultCorePush.js +140 -0
  221. package/vaultDeviceKey.js +95 -0
  222. package/vaultEnclaveHandoff.js +114 -0
  223. package/vaultKeep.js +287 -0
  224. package/vaultSealedStore.js +77 -0
  225. package/vaultWorkerHost.js +117 -0
  226. package/vcWorker.js +34 -0
  227. package/voiceAttest.js +50 -0
  228. package/voiceCert.js +51 -0
  229. package/witbitz-admin.d.ts +135 -0
  230. package/witbitz-admin.js +529 -0
  231. package/witbitz-admin.mjs +1460 -0
  232. package/witbitz-sdk.d.ts +1197 -0
  233. package/witbitz-sdk.js +4258 -0
  234. package/workerClient.js +16 -0
  235. package/workerLiveness.js +21 -0
  236. package/x509.js +218 -0
package/codeCache.js ADDED
@@ -0,0 +1,149 @@
1
+ // spaces/public/codeCache.js — the Code section's OFFLINE CACHE: the sessions you have opened, kept device-local so the
2
+ // page can show them when the computer is asleep, unpaired, or you have no network at all. The owner, 2026-09-17, after
3
+ // the Spaces airplane-mode work: "Can we make the code sessions also cache".
4
+ //
5
+ // The Code section was entirely LIVE until now — every session list and every message came off the sealed relay, so a
6
+ // computer that was not answering left the page with nothing to draw. Rooms have had this since the beginning
7
+ // (chatCache.js); this is the same idea with one difference that matters: a code transcript is far bigger than a chat.
8
+ // A single session can carry megabytes of tool output and diffs, so what is kept is capped three ways — messages per
9
+ // session, bytes per session (oldest trimmed first), and sessions per computer — and the cache is written from what the
10
+ // page ALREADY holds in memory, never by asking the computer for more.
11
+ //
12
+ // What is stored is what the page was already showing: the connector withholds secret-looking files and oversized
13
+ // patches before they ever reach the phone (codeRelay.js projectResponse), so nothing new crosses that line by being
14
+ // remembered. It is plaintext at rest on YOUR device, the same trust boundary as the room chat cache, and it is dropped
15
+ // with the rest of the app's storage on sign-out.
16
+ import { idb } from './idb.js'
17
+
18
+ const SESS = (cid, sid) => `code:sess:${cid}:${sid}`
19
+ const LIST = (cid) => `code:list:${cid}`
20
+ export const codeSessKey = SESS
21
+ export const codeListKey = LIST
22
+
23
+ export const MAX_MSGS = 150 // a long turn is a few dozen messages; 150 covers a working day of one session
24
+ export const MAX_BYTES = 1_200_000 // ~1.2 MB of JSON per session: enough for real transcripts, small enough to write often
25
+ export const MAX_SESSIONS = 20 // per computer, by last use — the history sheet shows far fewer than this
26
+ export const MAX_OUTPUT = 24_000 // per tool output / patch kept on the device
27
+
28
+ // A step's output and its patch are the heavy part, by a wide margin: codeHistory.js measured ONE real session at
29
+ // 9.7 MB over 136 messages, with a single message carrying 2.5 MB of tool output. Keeping the head of each is what
30
+ // makes a whole transcript fit — you can still read what ran and how it started, and the live copy has the rest
31
+ // whenever the computer is there. The cut is marked so the step sheet can say so rather than imply the output ended.
32
+ const clip = (s) => (typeof s === 'string' && s.length > MAX_OUTPUT ? s.slice(0, MAX_OUTPUT) : s)
33
+ export function trimMessage(m) {
34
+ if (!m || typeof m !== 'object' || !Array.isArray(m.parts)) return m
35
+ let touched = false
36
+ const parts = m.parts.map((p) => {
37
+ const st = p && p.state
38
+ const md = st && st.metadata
39
+ const big = (v) => typeof v === 'string' && v.length > MAX_OUTPUT
40
+ if (!st || !(big(st.output) || (md && (big(md.output) || big(md.diff) || (md.filediff && big(md.filediff.patch)))))) return p
41
+ touched = true
42
+ const next = { ...p, state: { ...st } }
43
+ if (big(st.output)) next.state.output = clip(st.output)
44
+ if (md) {
45
+ next.state.metadata = { ...md, wbClipped: true }
46
+ if (big(md.output)) next.state.metadata.output = clip(md.output)
47
+ if (big(md.diff)) next.state.metadata.diff = clip(md.diff)
48
+ if (md.filediff && big(md.filediff.patch)) next.state.metadata.filediff = { ...md.filediff, patch: clip(md.filediff.patch) }
49
+ } else next.state.metadata = { wbClipped: true }
50
+ return next
51
+ })
52
+ return touched ? { ...m, parts } : m
53
+ }
54
+
55
+ /** Clip each message's heavy parts, then drop messages from the FRONT until the whole thing fits: the newest are the
56
+ * ones worth keeping. */
57
+ export function trimMessages(msgs, { maxMsgs = MAX_MSGS, maxBytes = MAX_BYTES } = {}) {
58
+ let out = (Array.isArray(msgs) ? msgs.slice(-maxMsgs) : []).map(trimMessage)
59
+ while (out.length > 1) {
60
+ let size = 0
61
+ try { size = JSON.stringify(out).length } catch { return out.slice(-10) } // circular/exotic → keep a token tail
62
+ if (size <= maxBytes) break
63
+ out = out.slice(Math.max(1, Math.ceil(out.length * 0.15))) // 15% off the front per pass, so a huge tail converges fast
64
+ }
65
+ return out
66
+ }
67
+
68
+ /** Remember one session's transcript. `msgs` is the page's own message array; meta rides along for the list row. */
69
+ export async function saveSession(cid, sid, msgs, meta = {}, store = idb) {
70
+ if (!cid || !sid) return
71
+ const kept = trimMessages(msgs)
72
+ if (!kept.length) return
73
+ await store.set(SESS(cid, sid), { msgs: kept, at: Date.now(), trimmed: Array.isArray(msgs) && kept.length < msgs.length, ...meta })
74
+ }
75
+
76
+ /** → { msgs, at, trimmed, … } or null. */
77
+ export async function clearSession(cid, sid, store = idb, strict = false) {
78
+ if (strict && cid && sid && store.delStrict) { await store.delStrict(SESS(cid, sid)); return }
79
+ if (cid && sid) await store.del(SESS(cid, sid))
80
+ }
81
+
82
+ export async function removeCachedSession(cid, sid, store = idb, local) {
83
+ await clearSession(cid, sid, store, true)
84
+ const saved = await loadList(cid, store)
85
+ if (saved?.list.some(row => row.id === sid)) {
86
+ await saveList(cid, saved.list.filter(row => row.id !== sid), store, { allowEmpty: true })
87
+ if ((await loadList(cid, store))?.list.some(row => row.id === sid)) throw new Error('The cached session directory could not be updated')
88
+ }
89
+ const raw = local?.getItem('oc.list')
90
+ if (!raw) return
91
+ const directory = JSON.parse(raw)
92
+ const entry = directory?.entries?.find(e => e.key === cid)
93
+ if (entry?.sessions?.some(row => row.id === sid)) {
94
+ entry.sessions = entry.sessions.filter(row => row.id !== sid)
95
+ local.setItem('oc.list', JSON.stringify(directory))
96
+ }
97
+ }
98
+
99
+ export async function loadSession(cid, sid, store = idb) {
100
+ if (!cid || !sid) return null
101
+ const c = await store.get(SESS(cid, sid))
102
+ return c && Array.isArray(c.msgs) && c.msgs.length ? c : null
103
+ }
104
+
105
+ /** The session LIST as the computer last gave it, so the history sheet has something to show when it is away. */
106
+ export async function saveList(cid, list, store = idb, { allowEmpty = false } = {}) {
107
+ if (!cid || !Array.isArray(list) || (!list.length && !allowEmpty)) return // never write an empty list over a good one
108
+ await store.set(LIST(cid), { list: list.slice(0, 200), at: Date.now() })
109
+ }
110
+
111
+ export async function loadList(cid, store = idb) {
112
+ if (!cid) return null
113
+ const c = await store.get(LIST(cid))
114
+ return c && Array.isArray(c.list) ? c : null
115
+ }
116
+
117
+ /** Which sessions this device is holding for a computer, newest first: [{ id, at, msgs, title, dir }]. Enough to draw a
118
+ * drawer row from, so the list survives even when the list itself was never saved. */
119
+ export async function cachedSessions(cid, store = idb) {
120
+ if (!cid) return []
121
+ const pfx = `code:sess:${cid}:`
122
+ const rows = await store.entries(pfx)
123
+ return rows
124
+ .map(([k, v]) => ({ id: k.slice(pfx.length), at: (v && v.at) || 0, msgs: (v && Array.isArray(v.msgs) && v.msgs.length) || 0, title: (v && v.title) || '', dir: (v && v.dir) || '' }))
125
+ .sort((a, b) => b.at - a.at)
126
+ }
127
+
128
+ /** Keep the newest MAX_SESSIONS per computer. Called after a save — cheap, and it bounds a year of use. */
129
+ export async function prune(cid, keep = MAX_SESSIONS, store = idb) {
130
+ const all = await cachedSessions(cid, store)
131
+ for (const s of all.slice(keep)) await store.del(SESS(cid, s.id))
132
+ return all.length - Math.min(all.length, keep)
133
+ }
134
+
135
+ /** Forget one computer entirely (unpaired / removed) — its transcripts have no other home to belong to. */
136
+ export async function forgetComputer(cid) {
137
+ if (!cid) return
138
+ await idb.delPrefix(`code:sess:${cid}:`)
139
+ await idb.del(LIST(cid))
140
+ }
141
+
142
+ export function slimSession(x) {
143
+ const o = { id: x.id }
144
+ for (const f of ['title', 'slug', 'directory', 'path', 'parentID', 'agent', 'projectID']) if (typeof x[f] === 'string') o[f] = x[f]
145
+ const t = x.time || {}
146
+ o.time = {}
147
+ for (const f of ['created', 'updated', 'archived']) if (typeof t[f] === 'number') o.time[f] = t[f]
148
+ return o
149
+ }