@witbitz/sdk 4.3.0 → 4.5.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/README.md +2 -2
- package/a2aCore.js +41 -5
- package/accountErase.js +15 -4
- package/accountIndexDoc.js +24 -7
- package/accountRecord.js +6 -2
- package/accountStores.js +21 -5
- package/acctV2App.js +111 -12
- package/acctV2Client.js +11 -1
- package/acctV2UiCore.js +27 -7
- package/agentDoorTools.js +28 -0
- package/awsKey.js +3 -1
- package/backupRecord.js +3 -0
- package/chatLock.js +16 -0
- package/cloudDevicePins.js +2 -2
- package/codeAttachments.js +101 -0
- package/codeCache.js +173 -0
- package/codeCloud.js +2 -2
- package/codeComputers.js +9 -0
- package/codeFolders.js +116 -0
- package/codeHistory.js +76 -0
- package/codeLanguage.js +54 -0
- package/codeModes.js +2 -0
- package/codeProgress.js +54 -0
- package/codeSent.js +109 -0
- package/codeSubagents.js +107 -0
- package/codeTransport.js +46 -5
- package/connections.js +37 -20
- package/decrypt.html +69 -9
- package/deviceAttest.js +9 -3
- package/eraseFile.js +15 -0
- package/idb.js +19 -3
- package/idbSeal.js +5 -2
- package/inviteReceive.js +44 -0
- package/inviteSend.js +8 -2
- package/jobAgents.js +2 -2
- package/keptMerge.js +9 -2
- package/l1-worker-src.js +1 -1
- package/l1-worker.js +122 -43
- package/laneAssociation.js +78 -0
- package/laneConfig.js +4 -3
- package/laneLinkCore.js +9 -0
- package/ledgerView.js +30 -4
- package/manifest.json +112 -87
- package/memberChange.js +4 -2
- package/mirrorBatch.js +47 -0
- package/offlineBundle.js +21 -0
- package/opRouting.js +10 -0
- package/package.json +27 -2
- package/pdfOptions.js +13 -0
- package/pdfText.js +107 -0
- package/pdfjs.mjs +28 -0
- package/pdfjs.worker.mjs +28 -0
- package/protectedLocal.js +52 -13
- package/reactionHolders.js +86 -0
- package/removedMessage.js +1 -1
- package/roomEmbed.js +111 -0
- package/roomIntake.js +324 -0
- package/roomName.js +1 -1
- package/roomRoster.js +30 -7
- package/rosterCount.js +6 -3
- package/scheduleNext.js +60 -0
- package/sdkA2A.js +200 -42
- package/sdkAccount.js +88 -18
- package/sdkAccountDoc.js +13 -5
- package/sdkAccountSections.js +172 -23
- package/sdkAgui.js +33 -6
- package/sdkBackup.js +53 -11
- package/sdkBackupV2.js +15 -3
- package/sdkCloudDevice.js +20 -5
- package/sdkComputers.js +695 -65
- package/sdkDictation.js +115 -25
- package/sdkErase.js +12 -5
- package/sdkExports.js +19 -8
- package/sdkInvitations.js +4 -2
- package/sdkKeptAgent.js +19 -3
- package/sdkKeptIntake.js +100 -0
- package/sdkLaneLink.js +8 -9
- package/sdkPlan.js +4 -2
- package/sdkRekey.js +122 -22
- package/sdkReport.js +1 -1
- package/sdkSafeMedia.js +1 -1
- package/sdkSchedules.js +8 -1
- package/sdkSpeech.js +32 -2
- package/sdkTemporaryRooms.js +124 -0
- package/sdkTurn.js +12 -4
- package/sdkVault.js +66 -10
- package/sentinelRelease.js +1 -0
- package/sharedViews.js +34 -4
- package/siri.js +140 -9
- package/spaceClient.js +112 -17
- package/spaceEmailGate.js +2 -2
- package/spaceExport.js +50 -5
- package/spaceFork.js +15 -7
- package/spaceTemplates.js +99 -0
- package/speechOut.js +21 -5
- package/store.js +134 -27
- package/sw-notif-core.js +11 -8
- package/tapTrail.js +58 -0
- package/turnVerdict.js +1 -0
- package/usageReceipts.js +12 -5
- package/vault-core.js +568 -126
- package/vault-kit.mjs +3 -3
- package/vault-screens.js +30 -18
- package/vaultAtRest.js +38 -6
- package/vaultCoreLock.js +3 -1
- package/vaultCorePush.js +58 -7
- package/vaultKeep.js +9 -3
- package/vaultWorkerHost.js +32 -7
- package/witbitz-admin.d.ts +3 -0
- package/witbitz-admin.mjs +12 -11
- package/witbitz-sdk.d.ts +170 -43
- package/witbitz-sdk.js +833 -203
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
|
+
}
|