@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/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
|
+
}
|