@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/ownerPolicy.js
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// spaces/public/ownerPolicy.js — CLIENT-side peer verification of the owner rule (docs/the-owner-rule.md).
|
|
2
|
+
//
|
|
3
|
+
// The render enforces the owner policy server-side; this is the peer half: the OWNER'S APP verifies a room's policy
|
|
4
|
+
// independently, against an owner key it PINS itself (baked into the app / a well-known URL) — so it never takes the
|
|
5
|
+
// server's word for who governs a room, and won't join one whose policy is missing, swapped, or foreign. It also
|
|
6
|
+
// resolves the local member's tier for the UI. Wire-compatible with agent/ownerPolicy.mjs: ECDSA P-256 / SHA-256 over
|
|
7
|
+
// the SAME canonical (sorted-key) JSON, so a policy the server signs verifies here byte-for-byte, and vice-versa.
|
|
8
|
+
//
|
|
9
|
+
// Isomorphic (browser + node): uses global crypto.subtle / TextEncoder / btoa / atob only. No bundler, no deps.
|
|
10
|
+
const enc = new TextEncoder()
|
|
11
|
+
const ECDSA = { name: 'ECDSA', namedCurve: 'P-256' }
|
|
12
|
+
const SIGN = { name: 'ECDSA', hash: 'SHA-256' }
|
|
13
|
+
|
|
14
|
+
const bytesToB64u = (bytes) => { let s = ''; for (const b of bytes) s += String.fromCharCode(b); return btoa(s).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '') }
|
|
15
|
+
const b64uToBytes = (str) => { const bin = atob(String(str).replace(/-/g, '+').replace(/_/g, '/')); const u = new Uint8Array(bin.length); for (let i = 0; i < bin.length; i++) u[i] = bin.charCodeAt(i); return u }
|
|
16
|
+
|
|
17
|
+
// Canonical sorted-key JSON — MUST match agent/ownerPolicy.mjs canon (and spaceEntrySig) so signatures interoperate.
|
|
18
|
+
function canon(o) {
|
|
19
|
+
if (o === null || typeof o !== 'object') return JSON.stringify(o)
|
|
20
|
+
if (Array.isArray(o)) return '[' + o.map(canon).join(',') + ']'
|
|
21
|
+
return '{' + Object.keys(o).sort().map((k) => JSON.stringify(k) + ':' + canon(o[k])).join(',') + '}'
|
|
22
|
+
}
|
|
23
|
+
const sha256b64u = async (s) => bytesToB64u(new Uint8Array(await crypto.subtle.digest('SHA-256', enc.encode(s))))
|
|
24
|
+
const sameKey = (a, b) => !!a && !!b && canon({ kty: a.kty, crv: a.crv, x: a.x, y: a.y }) === canon({ kty: b.kty, crv: b.crv, x: b.x, y: b.y })
|
|
25
|
+
|
|
26
|
+
// SIGNING (B8, docs/tenant-releases.md): a builder's SERVER signs its rooms' policy and genesis with its owner key
|
|
27
|
+
// (WitbitzAdmin.owner) — the same bytes agent/ownerPolicy.mjs signs and checks. Never in a page: the private key is the app's.
|
|
28
|
+
export async function signPolicy(policy, ownerPrivJwk) {
|
|
29
|
+
const key = await crypto.subtle.importKey('jwk', ownerPrivJwk, ECDSA, false, ['sign'])
|
|
30
|
+
return { policy, sig: bytesToB64u(new Uint8Array(await crypto.subtle.sign(SIGN, key, enc.encode(canon(policy))))) }
|
|
31
|
+
}
|
|
32
|
+
export async function signRoomAuth(room, app, ownerPrivJwk) {
|
|
33
|
+
const key = await crypto.subtle.importKey('jwk', ownerPrivJwk, ECDSA, false, ['sign'])
|
|
34
|
+
const core = canon({ app: String(app), room: String(room) })
|
|
35
|
+
return { room: String(room), app: String(app), sig: bytesToB64u(new Uint8Array(await crypto.subtle.sign(SIGN, key, enc.encode(core)))) }
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export async function ownerKeyId(jwk) { return (await sha256b64u(canon({ kty: jwk.kty, crv: jwk.crv, x: jwk.x, y: jwk.y }))).slice(0, 22) }
|
|
39
|
+
export async function policyHash(policy) { return sha256b64u(canon(policy)) }
|
|
40
|
+
|
|
41
|
+
export async function verifyPolicy(signed, { ownerKey = null, now = Date.now() } = {}) {
|
|
42
|
+
const policy = signed && typeof signed === 'object' ? signed.policy : null
|
|
43
|
+
if (!policy || typeof policy !== 'object' || typeof signed.sig !== 'string') return { ok: false, reason: 'malformed' }
|
|
44
|
+
const declared = policy.ownerKey
|
|
45
|
+
if (!declared || typeof declared !== 'object') return { ok: false, reason: 'no_owner_key' }
|
|
46
|
+
if (ownerKey && !sameKey(declared, ownerKey)) return { ok: false, reason: 'owner_mismatch' }
|
|
47
|
+
let valid = false
|
|
48
|
+
try { valid = await crypto.subtle.verify(SIGN, await crypto.subtle.importKey('jwk', ownerKey || declared, ECDSA, false, ['verify']), b64uToBytes(signed.sig), enc.encode(canon(policy))) } catch { valid = false }
|
|
49
|
+
if (!valid) return { ok: false, reason: 'bad_sig' }
|
|
50
|
+
const nowSec = Math.floor(now / 1000)
|
|
51
|
+
if (typeof policy.notBefore === 'number' && nowSec < policy.notBefore) return { ok: false, reason: 'not_yet_valid' }
|
|
52
|
+
if (typeof policy.notAfter === 'number' && nowSec >= policy.notAfter) return { ok: false, reason: 'expired' }
|
|
53
|
+
return { ok: true, policy }
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** The peer check: the room's cleartext `marker` and its `sealed` signed policy (the app opens it with mk) must agree
|
|
57
|
+
* and verify against the app's PINNED `ownerKey`. Returns { ok, governed, policy?, reason? }. Refuse to join on !ok. */
|
|
58
|
+
export async function verifyRoomPolicy({ marker = null, sealed = null, ownerKey = null, required = false, now = Date.now() } = {}) {
|
|
59
|
+
if (!marker) return required ? { ok: false, governed: true, reason: 'policy_required' } : { ok: true, governed: false }
|
|
60
|
+
if (!sealed || !sealed.policy) return { ok: false, governed: true, reason: 'policy_missing' }
|
|
61
|
+
const v = await verifyPolicy(sealed, { ownerKey, now })
|
|
62
|
+
if (!v.ok) return { ok: false, governed: true, reason: v.reason }
|
|
63
|
+
if (String(v.policy.app || '') !== String(marker.app || '')) return { ok: false, governed: true, reason: 'app_mismatch' }
|
|
64
|
+
if ((await policyHash(v.policy)) !== marker.policyHash) return { ok: false, governed: true, reason: 'hash_mismatch' }
|
|
65
|
+
if ((await ownerKeyId(v.policy.ownerKey)) !== marker.ownerKeyId) return { ok: false, governed: true, reason: 'owner_mismatch' }
|
|
66
|
+
return { ok: true, governed: true, policy: v.policy }
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Tier resolution for the UI — mirror of agent/ownerPolicy.mjs (so the app can show "you're on the gold tier").
|
|
70
|
+
export function qualifies(admit, { authenticated = false, issuer = null, claims = {} } = {}) {
|
|
71
|
+
if (admit === 'anonymous' || (admit && admit.anonymous)) return true
|
|
72
|
+
if (!admit || typeof admit !== 'object' || !admit.issuer) return false
|
|
73
|
+
if (!authenticated || issuer !== admit.issuer) return false
|
|
74
|
+
if (admit.any) return true
|
|
75
|
+
if (admit.claim && typeof admit.claim === 'object') {
|
|
76
|
+
return Object.entries(admit.claim).every(([k, val]) => {
|
|
77
|
+
const c = claims && claims[k]
|
|
78
|
+
if (Array.isArray(c)) return c.includes(val)
|
|
79
|
+
if (k === 'group' && Array.isArray(claims && claims.groups)) return claims.groups.includes(val)
|
|
80
|
+
return c === val
|
|
81
|
+
})
|
|
82
|
+
}
|
|
83
|
+
return false
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function resolveTier(policy, { authenticated = false, issuer = null, claims = {}, roomTier = null } = {}) {
|
|
87
|
+
const tiers = Array.isArray(policy && policy.tiers) ? policy.tiers : []
|
|
88
|
+
if (!tiers.length) return { tier: null }
|
|
89
|
+
const ceilingName = roomTier || (policy.roomTiers && policy.roomTiers.default) || tiers[tiers.length - 1].name
|
|
90
|
+
const ceilingRank = Math.max(0, tiers.findIndex((t) => t.name === ceilingName))
|
|
91
|
+
let best = -1
|
|
92
|
+
for (let i = 0; i <= ceilingRank && i < tiers.length; i++) if (qualifies(tiers[i].admit, { authenticated, issuer, claims })) best = i
|
|
93
|
+
return best < 0 ? { tier: null } : { tier: tiers[best].name, caps: tiers[best].caps || {}, limits: tiers[best].limits || null }
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* The JOIN-flow peer check (docs/the-owner-rule.md): verify a room's governance against the app's PINNED owner key
|
|
98
|
+
* before trusting it, instead of taking the server's word. Fetches the room's marker + sealed config (op:'policy'),
|
|
99
|
+
* opens the config with mk to get the owner-signed policy, and verifies. Deps are injected so this stays self-contained:
|
|
100
|
+
* fetchPolicy(room) → { policy: marker, configSealed } · openConfig(configSealed, mk) → the decrypted config
|
|
101
|
+
* Returns { ok, governed, policy?, tier?, reason? }. No pinned key, or an ungoverned room ⇒ { ok:true, governed:false }.
|
|
102
|
+
*/
|
|
103
|
+
export async function verifyRoomGovernance({ room, mk, ownerKey = null, fetchPolicy, openConfig, member = null, now = Date.now() } = {}) {
|
|
104
|
+
// fetchPolicy (op:'policy') returns { policy: marker, configSealed, ownerKey? }. A PINNED deployment passes its own
|
|
105
|
+
// ownerKey (authoritative); otherwise fall back to the app's registry-resolved key the server hands back — enough to
|
|
106
|
+
// enforce the owner's embed allow-list on the hosted multi-tenant PWA (the caller only BLOCKS entry when pinned).
|
|
107
|
+
let marker = null, configSealed = null, key = ownerKey
|
|
108
|
+
try { const r = (await fetchPolicy(room)) || {}; marker = r.policy; configSealed = r.configSealed; if (!key) key = r.ownerKey || null } catch { return { ok: false, governed: true, reason: 'fetch_failed' } }
|
|
109
|
+
if (!marker) return { ok: true, governed: false } // ungoverned room
|
|
110
|
+
if (!key) return { ok: true, governed: false } // governed but no key resolvable (registry off / unknown) ⇒ can't verify here
|
|
111
|
+
let sealed = null
|
|
112
|
+
try { const cfg = await openConfig(configSealed, mk); sealed = cfg && cfg.ownerPolicy } catch { /* undecodable ⇒ verifyRoomPolicy reports it */ }
|
|
113
|
+
const rp = await verifyRoomPolicy({ marker, sealed, ownerKey: key, now })
|
|
114
|
+
if (!rp.ok) return { ok: false, governed: true, reason: rp.reason }
|
|
115
|
+
const tier = member ? resolveTier(rp.policy, { ...member }).tier : undefined
|
|
116
|
+
return { ok: true, governed: true, policy: rp.policy, ...(tier ? { tier } : {}) }
|
|
117
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,275 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@witbitz/sdk",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "4.4.0",
|
|
4
|
+
"description": "The Witbitz SDK: Spaces — end-to-end encrypted rooms with an AI assistant — in your own app. The same bytes as https://witbitz.chat/sdk/4.4.0/",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./witbitz-sdk.js",
|
|
7
|
+
"types": "./witbitz-sdk.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./witbitz-sdk.d.ts",
|
|
11
|
+
"default": "./witbitz-sdk.js"
|
|
12
|
+
},
|
|
13
|
+
"./admin": {
|
|
14
|
+
"types": "./witbitz-admin.d.ts",
|
|
15
|
+
"default": "./witbitz-admin.mjs"
|
|
16
|
+
},
|
|
17
|
+
"./package.json": "./package.json",
|
|
18
|
+
"./*": "./*"
|
|
19
|
+
},
|
|
20
|
+
"bin": {
|
|
21
|
+
"witbitz-vault-kit": "vault-kit.mjs"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"a2aCore.js",
|
|
25
|
+
"a2aShared.js",
|
|
26
|
+
"accountErase.js",
|
|
27
|
+
"accountIndexDoc.js",
|
|
28
|
+
"accountOwner.js",
|
|
29
|
+
"accountRecord.js",
|
|
30
|
+
"accountScope.js",
|
|
31
|
+
"accountSeal.js",
|
|
32
|
+
"accountStores.js",
|
|
33
|
+
"acctV2App.js",
|
|
34
|
+
"acctV2Check.js",
|
|
35
|
+
"acctV2Client.js",
|
|
36
|
+
"acctV2Keys.js",
|
|
37
|
+
"acctV2Legacy.js",
|
|
38
|
+
"acctV2Switch.js",
|
|
39
|
+
"acctV2UiCore.js",
|
|
40
|
+
"acctV2WebAuthn.js",
|
|
41
|
+
"acctV2Wire.js",
|
|
42
|
+
"address.js",
|
|
43
|
+
"agentDoorTools.js",
|
|
44
|
+
"attestedBox.js",
|
|
45
|
+
"attestedRooms.js",
|
|
46
|
+
"awsKey.js",
|
|
47
|
+
"backupRecord.js",
|
|
48
|
+
"backupVault.js",
|
|
49
|
+
"blocks.js",
|
|
50
|
+
"blocksPush.js",
|
|
51
|
+
"browseSeal.js",
|
|
52
|
+
"cbor.js",
|
|
53
|
+
"changePush.js",
|
|
54
|
+
"chatLock.js",
|
|
55
|
+
"chatLockSw.js",
|
|
56
|
+
"cloudDeviceBuilds.js",
|
|
57
|
+
"cloudDevicePins.js",
|
|
58
|
+
"cloudDeviceSeal.js",
|
|
59
|
+
"codeAttachments.js",
|
|
60
|
+
"codeBrowse.js",
|
|
61
|
+
"codeCache.js",
|
|
62
|
+
"codeCloud.js",
|
|
63
|
+
"codeCloudKeys.js",
|
|
64
|
+
"codeCommands.js",
|
|
65
|
+
"codeComputers.js",
|
|
66
|
+
"codeEgress.js",
|
|
67
|
+
"codeFilesRoutes.js",
|
|
68
|
+
"codeFolders.js",
|
|
69
|
+
"codeHistory.js",
|
|
70
|
+
"codeLanguage.js",
|
|
71
|
+
"codeMkdir.js",
|
|
72
|
+
"codeModes.js",
|
|
73
|
+
"codeOrphanKeys.js",
|
|
74
|
+
"codeOutputs.js",
|
|
75
|
+
"codeProgress.js",
|
|
76
|
+
"codeRelay.js",
|
|
77
|
+
"codeSent.js",
|
|
78
|
+
"codeSentinel.js",
|
|
79
|
+
"codeSubagents.js",
|
|
80
|
+
"codeTransport.js",
|
|
81
|
+
"codeUndo.js",
|
|
82
|
+
"compress.js",
|
|
83
|
+
"config.js",
|
|
84
|
+
"connCatalog.js",
|
|
85
|
+
"connDisp.js",
|
|
86
|
+
"connOtherWays.js",
|
|
87
|
+
"connPending.js",
|
|
88
|
+
"connWrap.js",
|
|
89
|
+
"connectionEntry.js",
|
|
90
|
+
"connections.js",
|
|
91
|
+
"credits.js",
|
|
92
|
+
"csAttest.js",
|
|
93
|
+
"decrypt.html",
|
|
94
|
+
"deviceAttest.js",
|
|
95
|
+
"deviceCall.js",
|
|
96
|
+
"deviceKeyCore.js",
|
|
97
|
+
"deviceSeal.js",
|
|
98
|
+
"e2ee.js",
|
|
99
|
+
"eat.js",
|
|
100
|
+
"emailFork.js",
|
|
101
|
+
"emailSignIn.js",
|
|
102
|
+
"emptySpaces.js",
|
|
103
|
+
"encSource.js",
|
|
104
|
+
"enclaveAccept.js",
|
|
105
|
+
"enclaveClaim.js",
|
|
106
|
+
"enclaveRoute.js",
|
|
107
|
+
"enclaveSnapshotMerge.js",
|
|
108
|
+
"entrySig.js",
|
|
109
|
+
"env.js",
|
|
110
|
+
"eraseFile.js",
|
|
111
|
+
"followImage.js",
|
|
112
|
+
"healNames.js",
|
|
113
|
+
"idb.js",
|
|
114
|
+
"idbSeal.js",
|
|
115
|
+
"indexGone.js",
|
|
116
|
+
"invite.js",
|
|
117
|
+
"inviteEnroll.js",
|
|
118
|
+
"inviteSend.js",
|
|
119
|
+
"jobAgents.js",
|
|
120
|
+
"keptMerge.js",
|
|
121
|
+
"l1-worker-src.js",
|
|
122
|
+
"l1-worker.js",
|
|
123
|
+
"laneAssociation.js",
|
|
124
|
+
"laneConfig.js",
|
|
125
|
+
"laneLinkCore.js",
|
|
126
|
+
"ledgerView.js",
|
|
127
|
+
"manifest.json",
|
|
128
|
+
"mcpRecommended.js",
|
|
129
|
+
"memberChange.js",
|
|
130
|
+
"mirrorBatch.js",
|
|
131
|
+
"mkseal.js",
|
|
132
|
+
"nativePush.js",
|
|
133
|
+
"nitroVerify.js",
|
|
134
|
+
"noble-p256.js",
|
|
135
|
+
"notice.js",
|
|
136
|
+
"notifKey.js",
|
|
137
|
+
"offlineBundle.js",
|
|
138
|
+
"ohttp.js",
|
|
139
|
+
"opRouting.js",
|
|
140
|
+
"opencodeWire.js",
|
|
141
|
+
"oprf.js",
|
|
142
|
+
"ownAgentLink.js",
|
|
143
|
+
"ownerPolicy.js",
|
|
144
|
+
"pdfOptions.js",
|
|
145
|
+
"pdfText.js",
|
|
146
|
+
"pdfjs.mjs",
|
|
147
|
+
"pdfjs.worker.mjs",
|
|
148
|
+
"pollVerdict.js",
|
|
149
|
+
"prefetchPoll.js",
|
|
150
|
+
"protectedLocal.js",
|
|
151
|
+
"pushCore.js",
|
|
152
|
+
"recovery.js",
|
|
153
|
+
"regions.js",
|
|
154
|
+
"removedMessage.js",
|
|
155
|
+
"renameRefusal.js",
|
|
156
|
+
"replyQuote.js",
|
|
157
|
+
"reqEnvelope.js",
|
|
158
|
+
"roomDefaultPrefs.js",
|
|
159
|
+
"roomDelete.js",
|
|
160
|
+
"roomEmbed.js",
|
|
161
|
+
"roomName.js",
|
|
162
|
+
"roomPass.js",
|
|
163
|
+
"roomRoster.js",
|
|
164
|
+
"roomSettings.js",
|
|
165
|
+
"roomState.js",
|
|
166
|
+
"roomStreamClient.js",
|
|
167
|
+
"rosterCount.js",
|
|
168
|
+
"rosterHash.js",
|
|
169
|
+
"rowSchema.js",
|
|
170
|
+
"safeMedia.js",
|
|
171
|
+
"safeMediaPins.js",
|
|
172
|
+
"schedulesDoc.js",
|
|
173
|
+
"sdkA2A.js",
|
|
174
|
+
"sdkAccount.js",
|
|
175
|
+
"sdkAccountDoc.js",
|
|
176
|
+
"sdkAccountSections.js",
|
|
177
|
+
"sdkAgui.js",
|
|
178
|
+
"sdkAttest.js",
|
|
179
|
+
"sdkBackup.js",
|
|
180
|
+
"sdkBackupV2.js",
|
|
181
|
+
"sdkBrowserPrivate.js",
|
|
182
|
+
"sdkBuilds.js",
|
|
183
|
+
"sdkCloudDevice.js",
|
|
184
|
+
"sdkComputers.js",
|
|
185
|
+
"sdkDictation.js",
|
|
186
|
+
"sdkErase.js",
|
|
187
|
+
"sdkExports.js",
|
|
188
|
+
"sdkInvitations.js",
|
|
189
|
+
"sdkKeptAgent.js",
|
|
190
|
+
"sdkLaneLink.js",
|
|
191
|
+
"sdkPlan.js",
|
|
192
|
+
"sdkProtect.js",
|
|
193
|
+
"sdkRedact.js",
|
|
194
|
+
"sdkRekey.js",
|
|
195
|
+
"sdkReport.js",
|
|
196
|
+
"sdkSafeMedia.js",
|
|
197
|
+
"sdkSchedules.js",
|
|
198
|
+
"sdkSpeech.js",
|
|
199
|
+
"sdkTemporaryRooms.js",
|
|
200
|
+
"sdkTurn.js",
|
|
201
|
+
"sdkVault.js",
|
|
202
|
+
"sealShare.js",
|
|
203
|
+
"sealedNames.js",
|
|
204
|
+
"sealedReceipt.js",
|
|
205
|
+
"sentinelRelease.js",
|
|
206
|
+
"shamir.js",
|
|
207
|
+
"sharedViews.js",
|
|
208
|
+
"sheetChrome.js",
|
|
209
|
+
"siri.js",
|
|
210
|
+
"spaceClient.js",
|
|
211
|
+
"spaceConfig.js",
|
|
212
|
+
"spaceEmailGate.js",
|
|
213
|
+
"spaceExport.js",
|
|
214
|
+
"spaceFork.js",
|
|
215
|
+
"spaceLock.js",
|
|
216
|
+
"spacePasskey.js",
|
|
217
|
+
"spaceTemplates.js",
|
|
218
|
+
"speechOut.js",
|
|
219
|
+
"splitKeyClient.js",
|
|
220
|
+
"store.js",
|
|
221
|
+
"streamHint.js",
|
|
222
|
+
"sttCloud.js",
|
|
223
|
+
"sttWorklet.js",
|
|
224
|
+
"sw-notif-core.js",
|
|
225
|
+
"tempList.js",
|
|
226
|
+
"tinfoilVerifier.js",
|
|
227
|
+
"toolBooks.js",
|
|
228
|
+
"toolRules.js",
|
|
229
|
+
"turnCerts.js",
|
|
230
|
+
"turnFeed.js",
|
|
231
|
+
"turnVerdict.js",
|
|
232
|
+
"usageReceipts.js",
|
|
233
|
+
"usageSummary.js",
|
|
234
|
+
"util.js",
|
|
235
|
+
"vault-core.js",
|
|
236
|
+
"vault-kit.mjs",
|
|
237
|
+
"vault-screens.js",
|
|
238
|
+
"vaultAtRest.js",
|
|
239
|
+
"vaultCoreLock.js",
|
|
240
|
+
"vaultCorePush.js",
|
|
241
|
+
"vaultDeviceKey.js",
|
|
242
|
+
"vaultEnclaveHandoff.js",
|
|
243
|
+
"vaultKeep.js",
|
|
244
|
+
"vaultSealedStore.js",
|
|
245
|
+
"vaultWorkerHost.js",
|
|
246
|
+
"vcWorker.js",
|
|
247
|
+
"voiceAttest.js",
|
|
248
|
+
"voiceCert.js",
|
|
249
|
+
"witbitz-admin.d.ts",
|
|
250
|
+
"witbitz-admin.js",
|
|
251
|
+
"witbitz-admin.mjs",
|
|
252
|
+
"witbitz-sdk.d.ts",
|
|
253
|
+
"witbitz-sdk.js",
|
|
254
|
+
"workerClient.js",
|
|
255
|
+
"workerLiveness.js",
|
|
256
|
+
"x509.js"
|
|
257
|
+
],
|
|
258
|
+
"license": "MIT",
|
|
259
|
+
"homepage": "https://witbitz.chat/docs/sdk",
|
|
260
|
+
"repository": {
|
|
261
|
+
"type": "git",
|
|
262
|
+
"url": "git+https://github.com/witbitzchat/witbitz-sdk.git"
|
|
263
|
+
},
|
|
264
|
+
"keywords": [
|
|
265
|
+
"witbitz",
|
|
266
|
+
"spaces",
|
|
267
|
+
"end-to-end encryption",
|
|
268
|
+
"ai",
|
|
269
|
+
"chat",
|
|
270
|
+
"sdk"
|
|
271
|
+
],
|
|
272
|
+
"engines": {
|
|
273
|
+
"node": ">=18"
|
|
274
|
+
}
|
|
275
|
+
}
|
package/pdfOptions.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// pdfOptions.js — THE OPTIONS EVERY pdf.js getDocument() IN THE APP TAKES (2026-10-26; the owner: "isEvalSupported: false
|
|
2
|
+
// everywhere we call pdf.js, as defense in depth" + "Update the bundled pdf.js to the server's version").
|
|
3
|
+
//
|
|
4
|
+
// • isEvalSupported: false — pdf.js can compile a font's glyph programs into JavaScript (`new Function`); that path is what
|
|
5
|
+
// CVE-2024-4367 used to run a crafted PDF's script in the page. Our CSP has no 'unsafe-eval', so it is blocked today; this
|
|
6
|
+
// keeps it off if the CSP ever changes. pdf.js then interprets the glyphs instead — the same pictures, a little slower.
|
|
7
|
+
// • wasmUrl — pdf.js 5 fetches its JPEG 2000 / JBIG2 / colour-profile decoders from here (pdfjs-wasm/, vendored with it);
|
|
8
|
+
// relative to the PAGE, so a build in its own folder (/b/<build>/) finds its own copy. No URL → those images do not draw.
|
|
9
|
+
export function pdfOpts () {
|
|
10
|
+
const o = { isEvalSupported: false }
|
|
11
|
+
try { o.wasmUrl = new URL('pdfjs-wasm/', document.baseURI).href } catch { /* no document (a test): pdf.js does without */ }
|
|
12
|
+
return o
|
|
13
|
+
}
|
package/pdfText.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
// pdfText — a PDF's readable text, extracted IN THE BROWSER with our own vendored pdf.js.
|
|
2
|
+
//
|
|
3
|
+
// ★ Why this exists. MEASURED against TrustedRouter (2026-09-12): a PDF cannot traverse its chat-completions
|
|
4
|
+
// surface. opencode sends the standard OpenAI file part — {type:'file',file:{filename,file_data}} — and TR answers
|
|
5
|
+
// 502 `provider error` for EVERY model, with and without cache_control, data: URL or bare base64. The identical PDF
|
|
6
|
+
// read perfectly through TR's /v1/messages (Anthropic-native `document` block), so the gap is the TRANSPORT, not
|
|
7
|
+
// the models. Extracting the text ourselves makes a PDF answerable on all 18 models instead of none, and it is the
|
|
8
|
+
// same thing agent/fileText.mjs already does server-side.
|
|
9
|
+
//
|
|
10
|
+
// ★ The item-join is the whole trick, and it was learned the hard way (see fileText.mjs): pdf.js splits a line into
|
|
11
|
+
// PER-WORD items. Concatenating them — which is what unpdf's merged extractText does — runs the words together,
|
|
12
|
+
// and in Hebrew that produces one unreadable string. Joining with a space restores the word boundaries.
|
|
13
|
+
// ★ …but not with a BLANKET space (the owner's Witbitz_Overview_2.pdf, 2026-09-13: "AI a ge nts a r e on l y",
|
|
14
|
+
// "T R U S T E D I N F R A S T R U C T U R E"). Dumped from this vendored pdf.js in Chromium: a word can arrive in
|
|
15
|
+
// TOUCHING pieces ("a" ends at 90.9, "ge" starts at 90.4) with the real spaces as their own " " items, and a
|
|
16
|
+
// letter-spaced heading arrives with pdf.js's spaces INSIDE the string ("T R U S T E D") and the word gap as a " " item
|
|
17
|
+
// 1.2× the font size wide. So the join reads the positions: a space where the PDF has one or the gap is a word's,
|
|
18
|
+
// nothing between touching pieces, and a letter-spaced line is read as words. Items without positions (and items out
|
|
19
|
+
// of reading order) keep the plain space join.
|
|
20
|
+
//
|
|
21
|
+
// Keyless and local: the bytes never leave the page except as the text the model is asked about.
|
|
22
|
+
|
|
23
|
+
import { pdfOpts } from './pdfOptions.js' // isEvalSupported: false + the decoders' folder
|
|
24
|
+
let _lib = null
|
|
25
|
+
/** The vendored pdf.js, loaded ONLY when a PDF is actually attached (it is large). Same module fileViewer.js uses. */
|
|
26
|
+
async function defaultLib() {
|
|
27
|
+
if (_lib) return _lib
|
|
28
|
+
const lib = await import('./pdfjs.mjs')
|
|
29
|
+
// against THIS module (the SDK on a builder's page loads it from Witbitz's address — d3d0526fb), except where the module runs from
|
|
30
|
+
// a blob: (the hosted app's code from the vault): nothing resolves against a blob:, so against the page, as sttCloud.js does
|
|
31
|
+
const base = String(import.meta.url).startsWith('blob:') ? location.href : import.meta.url
|
|
32
|
+
try { lib.GlobalWorkerOptions.workerSrc = new URL('./pdfjs.worker.mjs', base).href } catch { /* falls back to main-thread parsing */ }
|
|
33
|
+
_lib = lib
|
|
34
|
+
return lib
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export const PDF_TEXT_MAX = 60_000 // matches agent/fileText.mjs — a big document is truncated, never the file
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @param {Uint8Array} bytes
|
|
41
|
+
* @returns {Promise<{text: string, pages: number, truncated: boolean}>}
|
|
42
|
+
*/
|
|
43
|
+
export async function pdfToText(bytes, { maxChars = PDF_TEXT_MAX, getLib = defaultLib } = {}) {
|
|
44
|
+
const lib = await getLib()
|
|
45
|
+
const doc = await lib.getDocument({ data: bytes, ...pdfOpts() }).promise
|
|
46
|
+
const out = []
|
|
47
|
+
for (let i = 1; i <= doc.numPages; i++) {
|
|
48
|
+
const page = await doc.getPage(i)
|
|
49
|
+
const tc = await page.getTextContent()
|
|
50
|
+
const lines = [[]]
|
|
51
|
+
for (const it of tc.items) { lines[lines.length - 1].push(it); if (it.hasEOL) lines.push([]) }
|
|
52
|
+
const s = lines.map(joinLine).join('\n')
|
|
53
|
+
out.push(s.replace(/[ \t]+/g, ' ').replace(/ *\n */g, '\n').trim())
|
|
54
|
+
}
|
|
55
|
+
const text = out.filter(Boolean).join('\n\n')
|
|
56
|
+
return { text: text.slice(0, maxChars), pages: doc.numPages, truncated: text.length > maxChars }
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const hasGeo = (it) => Array.isArray(it.transform) && it.transform.length >= 6 && typeof it.width === 'number'
|
|
60
|
+
const sizeOf = (it) => (hasGeo(it) && Math.abs(it.transform[3])) || it.height || 0
|
|
61
|
+
const LETTER_RUN = /^\S( \S)+$/ // "T R U S T E D": pdf.js's own spaces between the letters of a tracked heading
|
|
62
|
+
/** The gap from one item to the next, in reading order (null when either has no position). */
|
|
63
|
+
function gapBetween(a, b) {
|
|
64
|
+
if (!hasGeo(a) || !hasGeo(b)) return null
|
|
65
|
+
return a.dir === 'rtl' || b.dir === 'rtl' ? a.transform[4] - (b.transform[4] + b.width) : b.transform[4] - (a.transform[4] + a.width)
|
|
66
|
+
}
|
|
67
|
+
/** One line's items → its text (see the header for what the positions are used for). */
|
|
68
|
+
function joinLine(items) {
|
|
69
|
+
const words = items.filter((it) => (it.str || '').trim())
|
|
70
|
+
if (!words.length) return ''
|
|
71
|
+
const geo = words.every(hasGeo)
|
|
72
|
+
// letter-spaced: every piece is one character or a run of spaced letters, and there are a few of them
|
|
73
|
+
const letters = words.reduce((n, it) => n + it.str.trim().split(/\s+/).length, 0)
|
|
74
|
+
const spaced = geo && (letters >= 3 || words.some((it) => LETTER_RUN.test(it.str.trim()))) && words.every((it) => [...it.str.trim()].length === 1 || LETTER_RUN.test(it.str.trim()))
|
|
75
|
+
let s = '', prev = null, spaceItem = false
|
|
76
|
+
for (const it of items) {
|
|
77
|
+
const str = it.str || ''
|
|
78
|
+
if (!str.trim()) { if (str) spaceItem = true; continue }
|
|
79
|
+
if (prev) {
|
|
80
|
+
const gap = gapBetween(prev, it), size = Math.max(sizeOf(prev), sizeOf(it)) || 1
|
|
81
|
+
if (spaced) s += gap >= 0.6 * size ? ' ' : ''
|
|
82
|
+
else if (gap == null || gap < -size) s += ' ' // no positions, or out of reading order: the plain join
|
|
83
|
+
else s += spaceItem || gap > 0.15 * size ? ' ' : ''
|
|
84
|
+
}
|
|
85
|
+
s += spaced ? str.trim().replace(/ /g, '') : str
|
|
86
|
+
prev = it; spaceItem = false
|
|
87
|
+
}
|
|
88
|
+
return s
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** The extracted text as the model should SEE it: named, page-counted, and honest about truncation. */
|
|
92
|
+
export function pdfTextBlock({ name = 'document.pdf', text = '', pages = 0, truncated = false }) {
|
|
93
|
+
const head = `--- ${name} (PDF, ${pages} page${pages === 1 ? '' : 's'}, text extracted in the browser` +
|
|
94
|
+
`${truncated ? `, TRUNCATED to the first ${PDF_TEXT_MAX} characters` : ''}) ---`
|
|
95
|
+
return `${head}\n${text}\n--- end of ${name} ---`
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* A message that carries extracted PDFs → what was typed, and the PDFs by name. The transcript shows the typed text and a
|
|
100
|
+
* chip per PDF instead of the whole extracted text (the model still gets all of it). Anything else is left as it is.
|
|
101
|
+
*/
|
|
102
|
+
export function splitPdfBlocks(message) {
|
|
103
|
+
const pdfs = []
|
|
104
|
+
const text = String(message || '').replace(/(^|\n\n)--- (.+?) \(PDF, (\d+) pages?, text extracted in the browser(, TRUNCATED to the first \d+ characters)?\) ---\n[\s\S]*?\n--- end of \2 ---/g,
|
|
105
|
+
(m, lead, name, pages, truncated) => { pdfs.push({ name, pages: Number(pages), truncated: !!truncated }); return '' })
|
|
106
|
+
return { text: pdfs.length ? text.trim() : String(message || ''), pdfs }
|
|
107
|
+
}
|