@burdenoff/microfe-healthybowl 2026.812.21 → 2026.813.1
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/dist/components/assistant/composer/AssistantAttachmentButton.js +19 -19
- package/dist/components/assistant/composer/AssistantAttachmentButton.js.map +1 -1
- package/dist/hooks/useAssistantAttachments.js +82 -63
- package/dist/hooks/useAssistantAttachments.js.map +1 -1
- package/dist/node_modules/fflate/esm/browser.js +326 -0
- package/dist/node_modules/fflate/esm/browser.js.map +1 -0
- package/dist/node_modules/pdfjs-dist/build/pdf.js +16384 -0
- package/dist/node_modules/pdfjs-dist/build/pdf.js.map +1 -0
- package/dist/node_modules/pdfjs-dist/build/pdf.worker.min.js +52129 -0
- package/dist/node_modules/pdfjs-dist/build/pdf.worker.min.js.map +1 -0
- package/dist/utils/assistantAttachments.js +243 -61
- package/dist/utils/assistantAttachments.js.map +1 -1
- package/dist/utils/documentExtract.js +135 -0
- package/dist/utils/documentExtract.js.map +1 -0
- package/dist/utils/documentText.js +237 -0
- package/dist/utils/documentText.js.map +1 -0
- package/dist/utils/quotaUtils.js +29 -15
- package/dist/utils/quotaUtils.js.map +1 -1
- package/package.json +3 -1
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { MAX_EXTRACTED_CHARS as e, docxXmlToText as t, fitPdfPages as n, joinSheets as r, parseSharedStrings as i, parseWorkbookSheets as a, pdfTextItemsToPage as o, sheetXmlToRows as s } from "./documentText.js";
|
|
2
|
+
import { MAX_INLINE_CHARS_PER_FILE as c } from "./assistantAttachments.js";
|
|
3
|
+
//#region src/utils/documentExtract.ts
|
|
4
|
+
var l = [
|
|
5
|
+
208,
|
|
6
|
+
207,
|
|
7
|
+
17,
|
|
8
|
+
224,
|
|
9
|
+
161,
|
|
10
|
+
177,
|
|
11
|
+
26,
|
|
12
|
+
225
|
|
13
|
+
];
|
|
14
|
+
function u(e) {
|
|
15
|
+
return l.every((t, n) => e[n] === t);
|
|
16
|
+
}
|
|
17
|
+
function d(e) {
|
|
18
|
+
return (e instanceof Error ? e.message : String(e)).replace(/\s+/g, " ").slice(0, 160);
|
|
19
|
+
}
|
|
20
|
+
async function f() {
|
|
21
|
+
let [e, t] = await Promise.all([import("../node_modules/pdfjs-dist/build/pdf.js"), import("../node_modules/pdfjs-dist/build/pdf.worker.min.js")]);
|
|
22
|
+
return globalThis.pdfjsWorker = t, e;
|
|
23
|
+
}
|
|
24
|
+
async function p(e) {
|
|
25
|
+
let t = (await f()).getDocument({
|
|
26
|
+
data: e,
|
|
27
|
+
disableFontFace: !0,
|
|
28
|
+
useSystemFonts: !1
|
|
29
|
+
}), r;
|
|
30
|
+
try {
|
|
31
|
+
r = await t.promise;
|
|
32
|
+
} catch (e) {
|
|
33
|
+
return await t.destroy().catch(() => void 0), (e instanceof Error ? e.name : "") === "PasswordException" ? { extraction: { status: "encrypted" } } : { extraction: {
|
|
34
|
+
status: "corrupt",
|
|
35
|
+
detail: d(e)
|
|
36
|
+
} };
|
|
37
|
+
}
|
|
38
|
+
let i = r.numPages, a = Math.min(i, 100), s = [];
|
|
39
|
+
try {
|
|
40
|
+
let e = 0;
|
|
41
|
+
for (let t = 1; t <= a; t += 1) {
|
|
42
|
+
let n = await r.getPage(t), i = o((await n.getTextContent()).items);
|
|
43
|
+
if (n.cleanup(), s.push(i), e += i.length, e >= 2e5) break;
|
|
44
|
+
}
|
|
45
|
+
} catch (e) {
|
|
46
|
+
if (s.length === 0) return { extraction: {
|
|
47
|
+
status: "corrupt",
|
|
48
|
+
detail: d(e)
|
|
49
|
+
} };
|
|
50
|
+
} finally {
|
|
51
|
+
await t.destroy().catch(() => void 0);
|
|
52
|
+
}
|
|
53
|
+
return n(s, i, a, c);
|
|
54
|
+
}
|
|
55
|
+
async function m(e, t) {
|
|
56
|
+
let { unzipSync: n, strFromU8: r } = await import("../node_modules/fflate/esm/browser.js"), i = n(e, { filter: (e) => t(e.name) }), a = {};
|
|
57
|
+
for (let [e, t] of Object.entries(i)) a[e] = r(t);
|
|
58
|
+
return a;
|
|
59
|
+
}
|
|
60
|
+
async function h(n) {
|
|
61
|
+
if (u(n)) return { extraction: {
|
|
62
|
+
status: "corrupt",
|
|
63
|
+
detail: "not an Office Open XML file — an OLE container, i.e. password-protected or a legacy .doc"
|
|
64
|
+
} };
|
|
65
|
+
let r;
|
|
66
|
+
try {
|
|
67
|
+
r = await m(n, (e) => e === "word/document.xml");
|
|
68
|
+
} catch (e) {
|
|
69
|
+
return { extraction: {
|
|
70
|
+
status: "corrupt",
|
|
71
|
+
detail: d(e)
|
|
72
|
+
} };
|
|
73
|
+
}
|
|
74
|
+
let i = r["word/document.xml"];
|
|
75
|
+
return i ? _(t(i).slice(0, e)) : { extraction: {
|
|
76
|
+
status: "corrupt",
|
|
77
|
+
detail: "no word/document.xml inside the file"
|
|
78
|
+
} };
|
|
79
|
+
}
|
|
80
|
+
async function g(t) {
|
|
81
|
+
if (u(t)) return { extraction: {
|
|
82
|
+
status: "corrupt",
|
|
83
|
+
detail: "not an Office Open XML file — an OLE container, i.e. password-protected or a legacy .xls"
|
|
84
|
+
} };
|
|
85
|
+
let n;
|
|
86
|
+
try {
|
|
87
|
+
n = await m(t, (e) => e === "xl/workbook.xml" || e === "xl/_rels/workbook.xml.rels" || e === "xl/sharedStrings.xml" || e.startsWith("xl/worksheets/"));
|
|
88
|
+
} catch (e) {
|
|
89
|
+
return { extraction: {
|
|
90
|
+
status: "corrupt",
|
|
91
|
+
detail: d(e)
|
|
92
|
+
} };
|
|
93
|
+
}
|
|
94
|
+
let o = n["xl/workbook.xml"];
|
|
95
|
+
if (!o) return { extraction: {
|
|
96
|
+
status: "corrupt",
|
|
97
|
+
detail: "no xl/workbook.xml inside the file"
|
|
98
|
+
} };
|
|
99
|
+
let c = i(n["xl/sharedStrings.xml"] ?? ""), l = a(o, n["xl/_rels/workbook.xml.rels"] ?? "").map((e) => ({
|
|
100
|
+
name: e.name,
|
|
101
|
+
rows: e.path && n[e.path] ? s(n[e.path], c) : []
|
|
102
|
+
})), f = _(r(l).slice(0, e)), p = l.filter((e) => e.rows.length > 0).map((e) => e.name);
|
|
103
|
+
return p.length > 0 && (f.extraction.sheetNames = p), f;
|
|
104
|
+
}
|
|
105
|
+
function _(e) {
|
|
106
|
+
if (e.trim() === "") return { extraction: { status: "no-text" } };
|
|
107
|
+
let t = e.length > c, n = e.slice(0, c), r = n.lastIndexOf("\n");
|
|
108
|
+
return {
|
|
109
|
+
extraction: {
|
|
110
|
+
status: "ok",
|
|
111
|
+
sourceChars: e.length
|
|
112
|
+
},
|
|
113
|
+
textContent: t && r > 8e3 * .5 ? n.slice(0, r) : n,
|
|
114
|
+
textTruncated: t
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
async function v(e, t) {
|
|
118
|
+
let n = await y(e, t);
|
|
119
|
+
return n.extraction.format = t, n;
|
|
120
|
+
}
|
|
121
|
+
async function y(e, t) {
|
|
122
|
+
try {
|
|
123
|
+
let n = new Uint8Array(await e.arrayBuffer());
|
|
124
|
+
return t === "pdf" ? await p(n) : t === "docx" ? await h(n) : await g(n);
|
|
125
|
+
} catch (e) {
|
|
126
|
+
return { extraction: {
|
|
127
|
+
status: "corrupt",
|
|
128
|
+
detail: d(e)
|
|
129
|
+
} };
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
//#endregion
|
|
133
|
+
export { v as extractDocumentText };
|
|
134
|
+
|
|
135
|
+
//# sourceMappingURL=documentExtract.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"documentExtract.js","names":[],"sources":["../../src/utils/documentExtract.ts"],"sourcesContent":["/**\n * Reading PDF / DOCX / XLSX in the browser — the IMPURE half (BOFF-6291).\n *\n * ## Why the client, and why this shape\n *\n * The app already has a working path for \"attachment whose text the model\n * reads\": text files are inlined into the prompt under a shared character\n * budget. A document is only different in that its text is locked inside a\n * container. So this module's whole job is to open the container and hand the\n * text to that existing path — no second mechanism, no backend service, and the\n * same `MAX_INLINE_CHARS_PER_FILE` / `MAX_INLINE_CHARS_TOTAL` /\n * `truncateForInline` budget that a `.csv` goes through.\n *\n * ## Bundle discipline\n *\n * This is a microfrontend published to npm; its initial bundle is the app's\n * initial bundle. Every parser is therefore behind a dynamic `import()` inside\n * the function that needs it, so a user who never attaches a PDF never\n * downloads pdf.js. The static cost of this file is the glue only.\n *\n * ## pdf.js without a worker\n *\n * pdf.js normally wants `GlobalWorkerOptions.workerSrc` — a URL to an asset the\n * CONSUMING app has to serve. A published library cannot promise that: the URL\n * depends on the host's build, its base path and its CSP (`worker-src blob:`).\n * pdf.js supports exactly one bundler-agnostic escape hatch — if\n * `globalThis.pdfjsWorker` already holds the worker module's exports, it uses\n * them on the main thread and never touches `workerSrc`\n * (`PDFWorker.#mainThreadWorkerMessageHandler`, pdf.mjs:16191). So we import the\n * worker module as a module and hand it over.\n *\n * The cost is real and worth naming: parsing runs on the main thread, so a very\n * long PDF will jank the UI while it is read. That is bounded by\n * `MAX_PDF_PAGES_SCANNED` and by the character ceiling, and the composer's send\n * button is already disabled for the whole preparation window, so the only\n * consequence is a slow spinner rather than a turn that goes out without its\n * attachment.\n */\n\nimport {\n MAX_EXTRACTED_CHARS,\n MAX_PDF_PAGES_SCANNED,\n docxXmlToText,\n fitPdfPages,\n joinSheets,\n parseSharedStrings,\n parseWorkbookSheets,\n pdfTextItemsToPage,\n sheetXmlToRows,\n type DocumentExtraction,\n} from './documentText';\nimport { MAX_INLINE_CHARS_PER_FILE, type DocumentFormat } from './assistantAttachments';\n// Type-only, so it is erased and pdf.js stays entirely behind the dynamic\n// import below. Verified by `grep pdfjs dist/utils/documentExtract.js`.\nimport type { PDFDocumentProxy } from 'pdfjs-dist';\n\nexport interface ExtractedDocument {\n extraction: DocumentExtraction;\n /** Already trimmed to `MAX_INLINE_CHARS_PER_FILE`. Absent unless status is 'ok'. */\n textContent?: string;\n /** True when `textContent` is a prefix of what the document actually holds. */\n textTruncated?: boolean;\n /** Page-per-entry text, for the shared budget's page-aligned re-trim. PDFs only. */\n documentPages?: string[];\n}\n\n/** OLE/CFB magic — a password-protected OOXML file, or a legacy .doc/.xls. */\nconst OLE_SIGNATURE = [0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1];\n\nfunction isOleContainer(bytes: Uint8Array): boolean {\n return OLE_SIGNATURE.every((byte, index) => bytes[index] === byte);\n}\n\nfunction messageOf(error: unknown): string {\n const raw = error instanceof Error ? error.message : String(error);\n // Parser messages land verbatim in the prompt; keep them to one short clause.\n return raw.replace(/\\s+/g, ' ').slice(0, 160);\n}\n\n// ── PDF ──────────────────────────────────────────────────────────────────────\n\ninterface PdfWorkerGlobal {\n pdfjsWorker?: unknown;\n}\n\nasync function loadPdfjs() {\n const [pdfjs, worker] = await Promise.all([\n import('pdfjs-dist'),\n // Already minified on disk, so the build does not have to chew through\n // 3 MB of worker source; it is only ever pulled in by this import.\n import('pdfjs-dist/build/pdf.worker.min.mjs'),\n ]);\n // Must be set BEFORE the first getDocument(): pdf.js reads it once, when it\n // decides between a real Worker and the main-thread path.\n (globalThis as PdfWorkerGlobal).pdfjsWorker = worker;\n return pdfjs;\n}\n\nasync function extractPdf(bytes: Uint8Array): Promise<ExtractedDocument> {\n const pdfjs = await loadPdfjs();\n\n // We only ever read text, never render, so fonts are dead weight. Switching\n // them off also stops a hostile PDF pulling remote font/standard-font assets.\n const loadingTask = pdfjs.getDocument({ data: bytes, disableFontFace: true, useSystemFonts: false });\n\n let document: PDFDocumentProxy;\n try {\n document = await loadingTask.promise;\n } catch (error) {\n await loadingTask.destroy().catch(() => undefined);\n const name = error instanceof Error ? error.name : '';\n if (name === 'PasswordException') {\n return { extraction: { status: 'encrypted' } };\n }\n return { extraction: { status: 'corrupt', detail: messageOf(error) } };\n }\n\n const pageCount = document.numPages;\n const pagesScanned = Math.min(pageCount, MAX_PDF_PAGES_SCANNED);\n const pages: string[] = [];\n\n try {\n let characters = 0;\n for (let pageNumber = 1; pageNumber <= pagesScanned; pageNumber += 1) {\n const page = await document.getPage(pageNumber);\n const content = await page.getTextContent();\n const text = pdfTextItemsToPage(content.items as { str?: string; hasEOL?: boolean }[]);\n page.cleanup();\n pages.push(text);\n characters += text.length;\n // Stop once we hold far more than any budget can inline. Only ever hit on\n // a document that HAS text, so it never masks a scanned file.\n if (characters >= MAX_EXTRACTED_CHARS) break;\n }\n } catch (error) {\n if (pages.length === 0) {\n return { extraction: { status: 'corrupt', detail: messageOf(error) } };\n }\n // Partial read: keep what we have, and let the page count say the rest.\n } finally {\n await loadingTask.destroy().catch(() => undefined);\n }\n\n // The scanned-vs-read decision, the page-density judgement and the page fit\n // all live in the pure half so they are reachable from this repo's node-only\n // vitest. This function is now only \"get bytes, get pages, hand over\".\n return fitPdfPages(pages, pageCount, pagesScanned, MAX_INLINE_CHARS_PER_FILE);\n}\n\n// ── OOXML (DOCX / XLSX) ──────────────────────────────────────────────────────\n\nasync function unzipEntries(bytes: Uint8Array, wanted: (name: string) => boolean): Promise<Record<string, string>> {\n const { unzipSync, strFromU8 } = await import('fflate');\n const entries = unzipSync(bytes, { filter: (entry) => wanted(entry.name) });\n const out: Record<string, string> = {};\n for (const [name, content] of Object.entries(entries)) {\n out[name] = strFromU8(content);\n }\n return out;\n}\n\nasync function extractDocx(bytes: Uint8Array): Promise<ExtractedDocument> {\n if (isOleContainer(bytes)) {\n return {\n extraction: {\n status: 'corrupt',\n detail: 'not an Office Open XML file — an OLE container, i.e. password-protected or a legacy .doc',\n },\n };\n }\n\n let entries: Record<string, string>;\n try {\n entries = await unzipEntries(bytes, (name) => name === 'word/document.xml');\n } catch (error) {\n return { extraction: { status: 'corrupt', detail: messageOf(error) } };\n }\n\n const xml = entries['word/document.xml'];\n if (!xml) {\n return { extraction: { status: 'corrupt', detail: 'no word/document.xml inside the file' } };\n }\n\n const text = docxXmlToText(xml).slice(0, MAX_EXTRACTED_CHARS);\n return finishFlatText(text);\n}\n\nasync function extractXlsx(bytes: Uint8Array): Promise<ExtractedDocument> {\n if (isOleContainer(bytes)) {\n return {\n extraction: {\n status: 'corrupt',\n detail: 'not an Office Open XML file — an OLE container, i.e. password-protected or a legacy .xls',\n },\n };\n }\n\n let entries: Record<string, string>;\n try {\n entries = await unzipEntries(\n bytes,\n (name) =>\n name === 'xl/workbook.xml' ||\n name === 'xl/_rels/workbook.xml.rels' ||\n name === 'xl/sharedStrings.xml' ||\n name.startsWith('xl/worksheets/')\n );\n } catch (error) {\n return { extraction: { status: 'corrupt', detail: messageOf(error) } };\n }\n\n const workbookXml = entries['xl/workbook.xml'];\n if (!workbookXml) {\n return { extraction: { status: 'corrupt', detail: 'no xl/workbook.xml inside the file' } };\n }\n\n const sharedStrings = parseSharedStrings(entries['xl/sharedStrings.xml'] ?? '');\n const sheets = parseWorkbookSheets(workbookXml, entries['xl/_rels/workbook.xml.rels'] ?? '');\n\n const parsed = sheets.map((sheet) => ({\n name: sheet.name,\n rows: sheet.path && entries[sheet.path] ? sheetXmlToRows(entries[sheet.path], sharedStrings) : [],\n }));\n\n const text = joinSheets(parsed).slice(0, MAX_EXTRACTED_CHARS);\n const result = finishFlatText(text);\n const named = parsed.filter((sheet) => sheet.rows.length > 0).map((sheet) => sheet.name);\n if (named.length > 0) result.extraction.sheetNames = named;\n return result;\n}\n\n/** Shared tail for the formats that produce one flat string rather than pages. */\nfunction finishFlatText(text: string): ExtractedDocument {\n if (text.trim() === '') {\n return { extraction: { status: 'no-text' } };\n }\n const truncated = text.length > MAX_INLINE_CHARS_PER_FILE;\n const head = text.slice(0, MAX_INLINE_CHARS_PER_FILE);\n const lastNewline = head.lastIndexOf('\\n');\n return {\n extraction: { status: 'ok', sourceChars: text.length },\n textContent: truncated && lastNewline > MAX_INLINE_CHARS_PER_FILE * 0.5 ? head.slice(0, lastNewline) : head,\n textTruncated: truncated,\n };\n}\n\n// ── Entry point ──────────────────────────────────────────────────────────────\n\n/**\n * Pull text out of a document, never throwing.\n *\n * A failure here must not fail the ATTACHMENT: the file still uploads, the\n * model still gets its URL, and the reason we could not read it becomes a\n * sentence in the prompt. Throwing would instead surface as the composer's\n * generic 'unreadable' rejection, and the user would lose the file over\n * something that is only a partial loss.\n */\nexport async function extractDocumentText(file: File, format: DocumentFormat): Promise<ExtractedDocument> {\n const result = await runExtractor(file, format);\n // Stamped centrally so no branch can forget it — the failure wording is\n // format-specific, and a missing format silently picks the PDF phrasing.\n result.extraction.format = format;\n return result;\n}\n\nasync function runExtractor(file: File, format: DocumentFormat): Promise<ExtractedDocument> {\n try {\n const bytes = new Uint8Array(await file.arrayBuffer());\n if (format === 'pdf') return await extractPdf(bytes);\n if (format === 'docx') return await extractDocx(bytes);\n return await extractXlsx(bytes);\n } catch (error) {\n return { extraction: { status: 'corrupt', detail: messageOf(error) } };\n }\n}\n"],"mappings":";;;AAmEA,IAAM,IAAgB;CAAC;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CAAK;AAEtE,SAAS,EAAe,GAA4B;AAClD,QAAO,EAAc,OAAO,GAAM,MAAU,EAAM,OAAW,EAAK;;AAGpE,SAAS,EAAU,GAAwB;AAGzC,SAFY,aAAiB,QAAQ,EAAM,UAAU,OAAO,EAAM,EAEvD,QAAQ,QAAQ,IAAI,CAAC,MAAM,GAAG,IAAI;;AAS/C,eAAe,IAAY;CACzB,IAAM,CAAC,GAAO,KAAU,MAAM,QAAQ,IAAI,CACxC,OAAO,4CAGP,OAAO,sDACR,CAAC;AAIF,QADC,WAA+B,cAAc,GACvC;;AAGT,eAAe,EAAW,GAA+C;CAKvE,IAAM,KAJQ,MAAM,GAAW,EAIL,YAAY;EAAE,MAAM;EAAO,iBAAiB;EAAM,gBAAgB;EAAO,CAAC,EAEhG;AACJ,KAAI;AACF,MAAW,MAAM,EAAY;UACtB,GAAO;AAMd,SALA,MAAM,EAAY,SAAS,CAAC,YAAY,KAAA,EAAU,GACrC,aAAiB,QAAQ,EAAM,OAAO,QACtC,sBACJ,EAAE,YAAY,EAAE,QAAQ,aAAa,EAAE,GAEz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A,MAA0C,KAAM,EAAK,MAAM,GAAG,EAAY,GAAG;EACvG,eAAe;EAChB;;AAcH,eAAsB,EAAoB,GAAY,GAAoD;CACxG,IAAM,IAAS,MAAM,EAAa,GAAM,EAAO;AAI/C,QADA,EAAO,WAAW,SAAS,GACpB;;AAGT,eAAe,EAAa,GAAY,GAAoD;AAC1F,KAAI;EACF,IAAM,IAAQ,IAAI,WAAW,MAAM,EAAK,aAAa,CAAC;AAGtD,SAFI,MAAW,QAAc,MAAM,EAAW,EAAM,GAChD,MAAW,SAAe,MAAM,EAAY,EAAM,GAC/C,MAAM,EAAY,EAAM;UACxB,GAAO;AACd,SAAO,EAAE,YAAY;GAAE,QAAQ;GAAW,QAAQ,EAAU,EAAM;GAAE,EAAE"}
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
//#region src/utils/documentText.ts
|
|
2
|
+
var e = 2e5, t = .6, n = .5, r = {
|
|
3
|
+
amp: "&",
|
|
4
|
+
lt: "<",
|
|
5
|
+
gt: ">",
|
|
6
|
+
quot: "\"",
|
|
7
|
+
apos: "'"
|
|
8
|
+
};
|
|
9
|
+
function i(e) {
|
|
10
|
+
return e.replace(/&(#x?[0-9a-fA-F]+|[a-zA-Z]+);/g, (e, t) => {
|
|
11
|
+
if (t.startsWith("#x") || t.startsWith("#X")) {
|
|
12
|
+
let n = Number.parseInt(t.slice(2), 16);
|
|
13
|
+
return Number.isFinite(n) ? String.fromCodePoint(n) : e;
|
|
14
|
+
}
|
|
15
|
+
if (t.startsWith("#")) {
|
|
16
|
+
let n = Number.parseInt(t.slice(1), 10);
|
|
17
|
+
return Number.isFinite(n) ? String.fromCodePoint(n) : e;
|
|
18
|
+
}
|
|
19
|
+
return r[t] ?? e;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function a(e) {
|
|
23
|
+
return e.split("\n").map((e) => e.replace(/[ \t]+$/, "")).join("\n").replace(/\n{3,}/g, "\n\n").trim();
|
|
24
|
+
}
|
|
25
|
+
function o(e) {
|
|
26
|
+
let t = e.replace(/<w:instrText[\s\S]*?<\/w:instrText>/g, ""), n = [], r = "", o = /<w:t(?:\s[^>]*)?>([\s\S]*?)<\/w:t>|<w:tab\b[^>]*\/?>|<w:br\b[^>]*\/?>|<\/w:p>/g, s;
|
|
27
|
+
for (; (s = o.exec(t)) !== null;) {
|
|
28
|
+
let [e, t] = s;
|
|
29
|
+
t === void 0 ? e.startsWith("<w:tab") ? r += " " : (e.startsWith("<w:br"), n.push(r), r = "") : r += i(t);
|
|
30
|
+
}
|
|
31
|
+
return r && n.push(r), a(n.join("\n"));
|
|
32
|
+
}
|
|
33
|
+
function s(e) {
|
|
34
|
+
return (e.match(/<si\b[^>]*\/>|<si\b[^>]*>[\s\S]*?<\/si>/g) ?? []).map((e) => (e.match(/<t(?:\s[^>]*)?>([\s\S]*?)<\/t>/g) ?? []).map((e) => i(e.replace(/<t(?:\s[^>]*)?>|<\/t>/g, ""))).join(""));
|
|
35
|
+
}
|
|
36
|
+
function c(e) {
|
|
37
|
+
let t = /^([A-Z]+)/.exec(e.toUpperCase());
|
|
38
|
+
if (!t) return -1;
|
|
39
|
+
let n = 0;
|
|
40
|
+
for (let e of t[1]) n = n * 26 + (e.charCodeAt(0) - 64);
|
|
41
|
+
return n - 1;
|
|
42
|
+
}
|
|
43
|
+
function l(e) {
|
|
44
|
+
return /[",\n]/.test(e) ? `"${e.replace(/"/g, "\"\"")}"` : e;
|
|
45
|
+
}
|
|
46
|
+
function u(e, t) {
|
|
47
|
+
let n = [], r = /<row\b[^>]*\/>|<row\b[^>]*>([\s\S]*?)<\/row>/g, a;
|
|
48
|
+
for (; (a = r.exec(e)) !== null;) {
|
|
49
|
+
let e = a[1] ?? "", r = [], o = /<c\b([^>]*?)(?:\/>|>([\s\S]*?)<\/c>)/g, s;
|
|
50
|
+
for (; (s = o.exec(e)) !== null;) {
|
|
51
|
+
let e = s[1] ?? "", n = s[2] ?? "", a = /\bt="([^"]+)"/.exec(e)?.[1] ?? "n", o = /\br="([^"]+)"/.exec(e)?.[1] ?? "", l = "";
|
|
52
|
+
if (a === "s") {
|
|
53
|
+
let e = /<v(?:\s[^>]*)?>([\s\S]*?)<\/v>/.exec(n)?.[1] ?? "";
|
|
54
|
+
l = t[Number.parseInt(e, 10)] ?? "";
|
|
55
|
+
} else if (a === "inlineStr") l = (n.match(/<t(?:\s[^>]*)?>([\s\S]*?)<\/t>/g) ?? []).map((e) => i(e.replace(/<t(?:\s[^>]*)?>|<\/t>/g, ""))).join("");
|
|
56
|
+
else {
|
|
57
|
+
let e = /<v(?:\s[^>]*)?>([\s\S]*?)<\/v>/.exec(n)?.[1] ?? "";
|
|
58
|
+
l = a === "b" ? e === "1" ? "TRUE" : e === "0" ? "FALSE" : "" : i(e);
|
|
59
|
+
}
|
|
60
|
+
let u = c(o);
|
|
61
|
+
if (u >= 0) {
|
|
62
|
+
for (; r.length < u;) r.push("");
|
|
63
|
+
r[u] = l;
|
|
64
|
+
} else r.push(l);
|
|
65
|
+
}
|
|
66
|
+
for (; r.length > 0 && r[r.length - 1] === "";) r.pop();
|
|
67
|
+
n.push(r.map(l).join(","));
|
|
68
|
+
}
|
|
69
|
+
for (; n.length > 0 && n[n.length - 1] === "";) n.pop();
|
|
70
|
+
return n;
|
|
71
|
+
}
|
|
72
|
+
function d(e, t) {
|
|
73
|
+
let n = /* @__PURE__ */ new Map();
|
|
74
|
+
for (let e of t.match(/<Relationship\b[^>]*\/?>/g) ?? []) {
|
|
75
|
+
let t = /\bId="([^"]+)"/.exec(e)?.[1], r = /\bTarget="([^"]+)"/.exec(e)?.[1];
|
|
76
|
+
if (!t || !r) continue;
|
|
77
|
+
let i = r.replace(/^\/xl\//, "").replace(/^\.\//, "");
|
|
78
|
+
n.set(t, i.startsWith("xl/") ? i : `xl/${i}`);
|
|
79
|
+
}
|
|
80
|
+
return (e.match(/<sheet\b[^>]*\/?>/g) ?? []).map((e) => {
|
|
81
|
+
let t = i(/\bname="([^"]*)"/.exec(e)?.[1] ?? "Sheet"), r = /\br:id="([^"]+)"/.exec(e)?.[1] ?? "";
|
|
82
|
+
return {
|
|
83
|
+
name: t,
|
|
84
|
+
path: n.get(r) ?? null
|
|
85
|
+
};
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
function f(e) {
|
|
89
|
+
return a(e.filter((e) => e.rows.length > 0).map((e) => `## Sheet: ${e.name}\n${e.rows.join("\n")}`).join("\n\n"));
|
|
90
|
+
}
|
|
91
|
+
function p(e) {
|
|
92
|
+
let t = "";
|
|
93
|
+
for (let n of e) typeof n.str == "string" && (t += n.str, n.hasEOL && (t += "\n"));
|
|
94
|
+
return a(t);
|
|
95
|
+
}
|
|
96
|
+
function m(e) {
|
|
97
|
+
return `[page ${e}]`;
|
|
98
|
+
}
|
|
99
|
+
var h = /^\s*(?:page|p\.?|pg\.?)?\s*\d+(?:\s*(?:of|\/)\s*\d+)?\s*(?:[-–—|]\s*)?/i, g = /\s*(?:[-–—|]\s*)?(?:page|p\.?|pg\.?)?\s*\d+(?:\s*(?:of|\/)\s*\d+)?\s*$/i;
|
|
100
|
+
function _(e) {
|
|
101
|
+
let t = e.replace(/\s+/g, " ").trim().toLowerCase();
|
|
102
|
+
return (t.replace(h, "") || t).replace(g, "").trim();
|
|
103
|
+
}
|
|
104
|
+
function v(e) {
|
|
105
|
+
let n = e.map((e) => {
|
|
106
|
+
let t = /* @__PURE__ */ new Set();
|
|
107
|
+
for (let n of e.split("\n")) {
|
|
108
|
+
let e = _(n);
|
|
109
|
+
e !== "" && t.add(e);
|
|
110
|
+
}
|
|
111
|
+
return t;
|
|
112
|
+
}), r = /* @__PURE__ */ new Map();
|
|
113
|
+
for (let e of n) for (let t of e) r.set(t, (r.get(t) ?? 0) + 1);
|
|
114
|
+
let i = Math.max(2, Math.ceil(e.length * t)), a = /* @__PURE__ */ new Set();
|
|
115
|
+
for (let [e, t] of r) t >= i && e.length <= 80 && a.add(e);
|
|
116
|
+
let o = [], s = [];
|
|
117
|
+
return e.forEach((e, t) => {
|
|
118
|
+
(e.split("\n").filter((e) => {
|
|
119
|
+
let t = _(e);
|
|
120
|
+
return t !== "" && !a.has(t);
|
|
121
|
+
}).join("\n").trim().length >= 24 ? o : s).push(t + 1);
|
|
122
|
+
}), {
|
|
123
|
+
textPages: o,
|
|
124
|
+
imagePages: s,
|
|
125
|
+
boilerplate: [...a]
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
function y(e, t) {
|
|
129
|
+
return t <= 0 ? !1 : e < t * n;
|
|
130
|
+
}
|
|
131
|
+
function b(e, t, n, r) {
|
|
132
|
+
let i = v(e);
|
|
133
|
+
if (i.textPages.length === 0) return { extraction: {
|
|
134
|
+
status: "no-text",
|
|
135
|
+
pageCount: t,
|
|
136
|
+
pagesScanned: n
|
|
137
|
+
} };
|
|
138
|
+
let a = new Set(i.textPages), o = S(e.map((e, t) => a.has(t + 1) ? e : ""), r);
|
|
139
|
+
return o.text === "" ? { extraction: {
|
|
140
|
+
status: "no-text",
|
|
141
|
+
pageCount: t,
|
|
142
|
+
pagesScanned: n
|
|
143
|
+
} } : {
|
|
144
|
+
extraction: {
|
|
145
|
+
status: "ok",
|
|
146
|
+
pageCount: t,
|
|
147
|
+
pagesScanned: n,
|
|
148
|
+
pagesIncluded: o.pagesIncluded,
|
|
149
|
+
pageNumbers: o.pageNumbers,
|
|
150
|
+
imagePages: i.imagePages,
|
|
151
|
+
textPageCount: i.textPages.length,
|
|
152
|
+
sourceChars: o.sourceChars
|
|
153
|
+
},
|
|
154
|
+
textContent: o.text,
|
|
155
|
+
documentPages: o.pages,
|
|
156
|
+
textTruncated: o.truncated || n < t
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
function x(e) {
|
|
160
|
+
let t = [...new Set(e)].sort((e, t) => e - t), n = [], r = null, i = 0, a = () => {
|
|
161
|
+
r !== null && n.push(r === i ? `${r}` : `${r}-${i}`);
|
|
162
|
+
};
|
|
163
|
+
for (let e of t) {
|
|
164
|
+
if (r === null) {
|
|
165
|
+
r = i = e;
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
if (e === i + 1) {
|
|
169
|
+
i = e;
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
a(), r = i = e;
|
|
173
|
+
}
|
|
174
|
+
return a(), n.join(", ");
|
|
175
|
+
}
|
|
176
|
+
function S(e, t) {
|
|
177
|
+
let n = (e, t) => `${m(t + 1)}\n${e}`, r = e.map((e, t) => ({
|
|
178
|
+
index: t,
|
|
179
|
+
page: e,
|
|
180
|
+
rendered: n(e, t)
|
|
181
|
+
})).filter((e) => e.page.trim() !== ""), i = r.map((e) => e.rendered).join("\n\n").length;
|
|
182
|
+
if (r.length === 0) return {
|
|
183
|
+
text: "",
|
|
184
|
+
truncated: !1,
|
|
185
|
+
pagesIncluded: e.length,
|
|
186
|
+
pageNumbers: [],
|
|
187
|
+
sourceChars: 0,
|
|
188
|
+
pages: []
|
|
189
|
+
};
|
|
190
|
+
let a = [], o = 0, s = 0, c = !1;
|
|
191
|
+
for (let r = 0; r < e.length; r += 1) {
|
|
192
|
+
if (e[r].trim() === "") {
|
|
193
|
+
s = r + 1;
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
let i = n(e[r], r), l = a.length === 0 ? i.length : i.length + 2;
|
|
197
|
+
if (o + l > t) {
|
|
198
|
+
c = !0;
|
|
199
|
+
break;
|
|
200
|
+
}
|
|
201
|
+
a.push({
|
|
202
|
+
index: r,
|
|
203
|
+
page: e[r],
|
|
204
|
+
rendered: i
|
|
205
|
+
}), o += l, s = r + 1;
|
|
206
|
+
}
|
|
207
|
+
if (a.length > 0) return {
|
|
208
|
+
text: a.map((e) => e.rendered).join("\n\n"),
|
|
209
|
+
truncated: c,
|
|
210
|
+
pagesIncluded: s,
|
|
211
|
+
pageNumbers: a.map((e) => e.index + 1),
|
|
212
|
+
sourceChars: i,
|
|
213
|
+
pages: e.slice(0, s)
|
|
214
|
+
};
|
|
215
|
+
let l = r[0], u = l.rendered.slice(0, Math.max(0, t)), d = u.lastIndexOf("\n"), f = d > t * .5 ? u.slice(0, d) : u, p = f.slice(m(l.index + 1).length + 1);
|
|
216
|
+
if (p.trim() === "") return {
|
|
217
|
+
text: "",
|
|
218
|
+
truncated: !0,
|
|
219
|
+
pagesIncluded: 0,
|
|
220
|
+
pageNumbers: [],
|
|
221
|
+
sourceChars: i,
|
|
222
|
+
pages: []
|
|
223
|
+
};
|
|
224
|
+
let h = e.slice(0, l.index + 1);
|
|
225
|
+
return h[l.index] = p, {
|
|
226
|
+
text: f,
|
|
227
|
+
truncated: !0,
|
|
228
|
+
pagesIncluded: l.index + 1,
|
|
229
|
+
pageNumbers: [l.index + 1],
|
|
230
|
+
sourceChars: i,
|
|
231
|
+
pages: h
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
//#endregion
|
|
235
|
+
export { e as MAX_EXTRACTED_CHARS, o as docxXmlToText, b as fitPdfPages, x as formatPageRanges, y as isMostlyImagePages, f as joinSheets, s as parseSharedStrings, d as parseWorkbookSheets, p as pdfTextItemsToPage, u as sheetXmlToRows, S as truncatePagesForInline };
|
|
236
|
+
|
|
237
|
+
//# sourceMappingURL=documentText.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"documentText.js","names":[],"sources":["../../src/utils/documentText.ts"],"sourcesContent":["/**\n * Turning a PDF / DOCX / XLSX into plain text — the PURE half (BOFF-6291).\n *\n * Everything in this file is a string-in/string-out function with no imports,\n * no DOM and no parser dependency, which is what makes it testable under the\n * repo's `environment: 'node'` vitest config. The browser-only half — reading\n * the File, lazily importing pdf.js / fflate, unzipping — lives in\n * `documentExtract.ts` and calls into here.\n *\n * ## Why regex and not DOMParser\n *\n * DOCX and XLSX are ZIPs of XML, and the obvious tool is `DOMParser`. It is\n * browser-only, so every one of these functions would then be untestable here\n * and the extraction logic would ship unverified. We are pulling *text* out of\n * a machine-generated, schema-fixed document part — not rendering untrusted\n * markup — so a targeted scan over the tags Word/Excel actually emit is both\n * sufficient and checkable. The output is inlined into a prompt as text; it is\n * never interpreted as markup, so a mis-parse costs fidelity, not safety.\n */\n\n/** Upper bound on characters pulled out of one document before we stop. */\nexport const MAX_EXTRACTED_CHARS = 200_000;\n\n/** Upper bound on PDF pages we will even look at, however long the document. */\nexport const MAX_PDF_PAGES_SCANNED = 100;\n\n/**\n * How many characters of PAGE-SPECIFIC text a page must yield before we are\n * willing to say we read it.\n *\n * A scanned page is not empty — its scanner stamps a footer on every page, and\n * `page.trim() !== ''` is therefore true for a document containing no readable\n * content whatsoever. 24 characters is below any real page of a soil report or\n * an audit (those run to thousands) and above the watermarks that defeat an\n * all-or-nothing check.\n */\nexport const MIN_PAGE_TEXT_CHARS = 24;\n\n/**\n * A line repeated on at least this share of pages is a running head/footer or a\n * scanner watermark, not content.\n *\n * Used ONLY to judge whether a page carries its own text; the line is never\n * removed from the text handed to the model. So a false positive here costs\n * nothing but a slightly more cautious disclosure, while a false negative is the\n * failure this whole notion exists to stop.\n */\nexport const BOILERPLATE_PAGE_SHARE = 0.6;\n\n/**\n * Boilerplate detection only ever applies to short lines, never to content.\n *\n * Named trade-off: a running footer LONGER than this — a full confidentiality\n * paragraph stamped on every page of a scan — is not recognised, and the scan\n * is then treated as readable. That is the safe direction to be wrong in only\n * because the model still sees exactly the text the file contains; it is not a\n * claim the heuristic is exact.\n */\nexport const MAX_BOILERPLATE_LINE_CHARS = 80;\n\n/**\n * Below this share of pages carrying a text layer, a document is \"mostly\n * images\" and must be presented as unread rather than as extracted.\n */\nexport const MIN_TEXT_PAGE_SHARE = 0.5;\n\n/**\n * What happened when we tried to read a document.\n *\n * Every value other than `ok` MUST reach the model as a sentence — a document\n * we could not read has to look different from a document that was empty, and\n * both have to look different from one we never tried. Silence here is what\n * makes an assistant answer confidently about a file it never saw.\n */\nexport type DocumentExtractionStatus =\n | 'ok'\n | 'no-text'\n | 'encrypted'\n | 'corrupt'\n /** No extractor for this type — we did not even try. */\n | 'unsupported';\n\n/** Document formats we can turn into text in the browser. */\nexport type DocumentFormat = 'pdf' | 'docx' | 'xlsx';\n\nexport interface DocumentExtraction {\n status: DocumentExtractionStatus;\n /**\n * Which extractor produced this. Carried so the failure wording can be\n * true rather than merely plausible: \"appears to be scanned images\" is the\n * right sentence for a PDF and a wrong one for an empty .docx.\n */\n format?: DocumentFormat;\n /** Total pages in a PDF (not how many we read — see `pagesScanned`). */\n pageCount?: number;\n /** How many pages we actually looked at; capped by MAX_PDF_PAGES_SCANNED. */\n pagesScanned?: number;\n /** How far into the document `textContent` reaches: pages 1..N were processed. */\n pagesIncluded?: number;\n /**\n * The 1-indexed pages whose text is ACTUALLY in `textContent`.\n *\n * Distinct from `pagesIncluded` on purpose: a 40-page certificate with 3 text\n * pages and 37 image pages processes all 40 and reads 3, and saying \"40 pages\"\n * there is the exact falsehood this feature must not tell.\n */\n pageNumbers?: number[];\n /**\n * The 1-indexed pages within `pagesScanned` that yielded no page-specific\n * text — image or blank pages. Counted so they can be DISCLOSED rather than\n * silently folded into a page total.\n */\n imagePages?: number[];\n /** How many scanned pages carried a text layer at all. */\n textPageCount?: number;\n /** Characters of text the document yielded before the inline budget cut it. */\n sourceChars?: number;\n /** Worksheet names, in workbook order. XLSX only. */\n sheetNames?: string[];\n /** Parser detail for the `corrupt` case — shown to the model verbatim. */\n detail?: string;\n}\n\n// ── XML helpers ──────────────────────────────────────────────────────────────\n\nconst XML_ENTITIES: Record<string, string> = {\n amp: '&',\n lt: '<',\n gt: '>',\n quot: '\"',\n apos: \"'\",\n};\n\n/** Resolve the five XML entities plus numeric character references. */\nexport function decodeXmlEntities(value: string): string {\n return value.replace(/&(#x?[0-9a-fA-F]+|[a-zA-Z]+);/g, (whole, body: string) => {\n if (body.startsWith('#x') || body.startsWith('#X')) {\n const code = Number.parseInt(body.slice(2), 16);\n return Number.isFinite(code) ? String.fromCodePoint(code) : whole;\n }\n if (body.startsWith('#')) {\n const code = Number.parseInt(body.slice(1), 10);\n return Number.isFinite(code) ? String.fromCodePoint(code) : whole;\n }\n return XML_ENTITIES[body] ?? whole;\n });\n}\n\n/** Collapse the runs of blank lines a paragraph-per-line walk tends to leave. */\nfunction tidy(text: string): string {\n return text\n .split('\\n')\n .map((line) => line.replace(/[ \\t]+$/, ''))\n .join('\\n')\n .replace(/\\n{3,}/g, '\\n\\n')\n .trim();\n}\n\n// ── DOCX ─────────────────────────────────────────────────────────────────────\n\n/**\n * `word/document.xml` → plain text.\n *\n * Word's body is a flat list of `<w:p>` paragraphs holding `<w:t>` runs, with\n * `<w:tab/>` and `<w:br/>` as explicit whitespace. Table cells are paragraphs\n * too, so a table comes out one cell per line — lossy for layout, faithful for\n * content, and the model reads it fine.\n *\n * `<w:instrText>` (field codes such as a HYPERLINK target or a MERGEFIELD name)\n * is deliberately skipped: it is markup the reader never sees, and inlining it\n * puts strings in front of the model that are not in the document.\n */\nexport function docxXmlToText(xml: string): string {\n const body = xml.replace(/<w:instrText[\\s\\S]*?<\\/w:instrText>/g, '');\n const out: string[] = [];\n let line = '';\n\n const token = /<w:t(?:\\s[^>]*)?>([\\s\\S]*?)<\\/w:t>|<w:tab\\b[^>]*\\/?>|<w:br\\b[^>]*\\/?>|<\\/w:p>/g;\n let match: RegExpExecArray | null;\n while ((match = token.exec(body)) !== null) {\n const [whole, textRun] = match;\n if (textRun !== undefined) {\n line += decodeXmlEntities(textRun);\n } else if (whole.startsWith('<w:tab')) {\n line += '\\t';\n } else if (whole.startsWith('<w:br')) {\n out.push(line);\n line = '';\n } else {\n out.push(line);\n line = '';\n }\n }\n if (line) out.push(line);\n\n return tidy(out.join('\\n'));\n}\n\n// ── XLSX ─────────────────────────────────────────────────────────────────────\n\n/** `xl/sharedStrings.xml` → the string table, indexed as the sheets index it. */\nexport function parseSharedStrings(xml: string): string[] {\n // Self-closing alternative FIRST: `[^>]*` happily eats the `/` of `<si/>`, so\n // the open-tag branch would otherwise swallow everything up to the next\n // `</si>` and silently merge two entries into one.\n const items = xml.match(/<si\\b[^>]*\\/>|<si\\b[^>]*>[\\s\\S]*?<\\/si>/g) ?? [];\n return items.map((item) => {\n const runs = item.match(/<t(?:\\s[^>]*)?>([\\s\\S]*?)<\\/t>/g) ?? [];\n return runs.map((run) => decodeXmlEntities(run.replace(/<t(?:\\s[^>]*)?>|<\\/t>/g, ''))).join('');\n });\n}\n\n/** `A` → 0, `Z` → 25, `AA` → 26. Returns -1 for anything that is not a column. */\nexport function columnLetterToIndex(reference: string): number {\n const letters = /^([A-Z]+)/.exec(reference.toUpperCase());\n if (!letters) return -1;\n let index = 0;\n for (const character of letters[1]) {\n index = index * 26 + (character.charCodeAt(0) - 64);\n }\n return index - 1;\n}\n\n/** Quote a cell only when it would otherwise break the CSV-ish row we emit. */\nfunction csvCell(value: string): string {\n return /[\",\\n]/.test(value) ? `\"${value.replace(/\"/g, '\"\"')}\"` : value;\n}\n\n/**\n * One worksheet's XML → CSV-ish rows.\n *\n * Sparse cells are padded from their `r=\"C7\"` reference so column alignment\n * survives, which is the whole reason a spreadsheet is worth inlining at all.\n * Numbers come out exactly as stored — an Excel date is a serial number, and\n * guessing at a display format would put dates in front of the model that the\n * file does not contain.\n */\nexport function sheetXmlToRows(xml: string, sharedStrings: string[]): string[] {\n const rows: string[] = [];\n // Self-closing first — see `parseSharedStrings`. A `<row r=\"2\"/>` matched by\n // the open-tag branch swallows the following row and the sheet loses a line.\n const rowPattern = /<row\\b[^>]*\\/>|<row\\b[^>]*>([\\s\\S]*?)<\\/row>/g;\n let rowMatch: RegExpExecArray | null;\n\n while ((rowMatch = rowPattern.exec(xml)) !== null) {\n const inner = rowMatch[1] ?? '';\n const cells: string[] = [];\n const cellPattern = /<c\\b([^>]*?)(?:\\/>|>([\\s\\S]*?)<\\/c>)/g;\n let cellMatch: RegExpExecArray | null;\n\n while ((cellMatch = cellPattern.exec(inner)) !== null) {\n const attributes = cellMatch[1] ?? '';\n const content = cellMatch[2] ?? '';\n const type = /\\bt=\"([^\"]+)\"/.exec(attributes)?.[1] ?? 'n';\n const reference = /\\br=\"([^\"]+)\"/.exec(attributes)?.[1] ?? '';\n\n let value = '';\n if (type === 's') {\n const raw = /<v(?:\\s[^>]*)?>([\\s\\S]*?)<\\/v>/.exec(content)?.[1] ?? '';\n value = sharedStrings[Number.parseInt(raw, 10)] ?? '';\n } else if (type === 'inlineStr') {\n const runs = content.match(/<t(?:\\s[^>]*)?>([\\s\\S]*?)<\\/t>/g) ?? [];\n value = runs.map((run) => decodeXmlEntities(run.replace(/<t(?:\\s[^>]*)?>|<\\/t>/g, ''))).join('');\n } else {\n const raw = /<v(?:\\s[^>]*)?>([\\s\\S]*?)<\\/v>/.exec(content)?.[1] ?? '';\n value = type === 'b' ? (raw === '1' ? 'TRUE' : raw === '0' ? 'FALSE' : '') : decodeXmlEntities(raw);\n }\n\n const column = columnLetterToIndex(reference);\n if (column >= 0) {\n while (cells.length < column) cells.push('');\n cells[column] = value;\n } else {\n cells.push(value);\n }\n }\n\n // Trailing empties carry no information and cost budget.\n while (cells.length > 0 && cells[cells.length - 1] === '') cells.pop();\n rows.push(cells.map(csvCell).join(','));\n }\n\n // Same for trailing blank rows — Excel emits them freely.\n while (rows.length > 0 && rows[rows.length - 1] === '') rows.pop();\n return rows;\n}\n\n/**\n * `xl/workbook.xml` (+ its rels) → the sheets in workbook order.\n *\n * The rels file is what maps `r:id=\"rId3\"` to `worksheets/sheet1.xml`; the\n * common assumption that `sheetN.xml` matches tab order is simply false in any\n * workbook whose sheets have been reordered or deleted.\n */\nexport function parseWorkbookSheets(workbookXml: string, relsXml: string): { name: string; path: string | null }[] {\n const targets = new Map<string, string>();\n for (const rel of relsXml.match(/<Relationship\\b[^>]*\\/?>/g) ?? []) {\n const id = /\\bId=\"([^\"]+)\"/.exec(rel)?.[1];\n const target = /\\bTarget=\"([^\"]+)\"/.exec(rel)?.[1];\n if (!id || !target) continue;\n const normalised = target.replace(/^\\/xl\\//, '').replace(/^\\.\\//, '');\n targets.set(id, normalised.startsWith('xl/') ? normalised : `xl/${normalised}`);\n }\n\n return (workbookXml.match(/<sheet\\b[^>]*\\/?>/g) ?? []).map((sheet) => {\n const name = decodeXmlEntities(/\\bname=\"([^\"]*)\"/.exec(sheet)?.[1] ?? 'Sheet');\n const relationship = /\\br:id=\"([^\"]+)\"/.exec(sheet)?.[1] ?? '';\n return { name, path: targets.get(relationship) ?? null };\n });\n}\n\n/** Stitch the parsed sheets into one document, headed by the sheet name. */\nexport function joinSheets(sheets: { name: string; rows: string[] }[]): string {\n return tidy(\n sheets\n .filter((sheet) => sheet.rows.length > 0)\n .map((sheet) => `## Sheet: ${sheet.name}\\n${sheet.rows.join('\\n')}`)\n .join('\\n\\n')\n );\n}\n\n// ── PDF ──────────────────────────────────────────────────────────────────────\n\n/**\n * pdf.js text items → one page of text.\n *\n * `hasEOL` is pdf.js' own end-of-line marker, so line structure comes from the\n * library rather than from us guessing at coordinates. Marked-content items\n * carry no `str` and are skipped.\n */\nexport function pdfTextItemsToPage(items: { str?: string; hasEOL?: boolean }[]): string {\n let text = '';\n for (const item of items) {\n if (typeof item.str !== 'string') continue;\n text += item.str;\n if (item.hasEOL) text += '\\n';\n }\n return tidy(text);\n}\n\n/** Header a page gets when several of them are inlined together. */\nexport function pageMarker(pageNumber: number): string {\n return `[page ${pageNumber}]`;\n}\n\n/**\n * Which pages of a PDF actually carry text, and which are images.\n *\n * ## Why an all-or-nothing check is not enough\n *\n * The obvious test — \"did ANY page yield a non-empty string\" — is defeated by\n * every scanner on the market, because scanners stamp a text footer onto each\n * page image. A 12-page scanned soil report whose only text layer is\n * `Scanned with CamScanner 1` passes that test, and the document is then handed\n * to the model as `Extracted text (12 pages):` with no hint that not one word of\n * the report is in it. The model answers confidently about a file nobody read.\n *\n * So the unit of judgement is the PAGE, and the question per page is whether it\n * holds text SPECIFIC TO IT. Two signals, deliberately both cheap and pure:\n *\n * 1. **Repetition.** A line that appears on most pages, once digits are\n * normalised away so page numbers compare equal, is a running head/footer or\n * a scan watermark. Only short lines are eligible, so this can never strike\n * out a paragraph of content.\n * 2. **Volume.** What is left after (1) must reach `MIN_PAGE_TEXT_CHARS`.\n *\n * Boilerplate is subtracted only for this JUDGEMENT — the text handed to the\n * model is untouched, so mis-classifying a sparse page costs a more cautious\n * sentence rather than lost content.\n */\nexport interface PageTextSummary {\n /** 1-indexed pages carrying page-specific text. */\n textPages: number[];\n /** 1-indexed pages carrying nothing but blanks or repeated boilerplate. */\n imagePages: number[];\n /** The normalised lines judged to be running heads/footers or watermarks. */\n boilerplate: string[];\n}\n\n/**\n * Normalise a line so a running head/footer compares equal across pages.\n *\n * Only a leading or trailing PAGE NUMBER is removed — `3`, `page 3`, `p. 3`,\n * `3 of 12`, optionally behind a dash or pipe. Deliberately not \"collapse every\n * digit\": a soil report's `Bed 1: pH 6.4, N 12 ppm, P 22 ppm` carries all of its\n * page-specific information in its numbers, and collapsing them made every page\n * of a real report compare equal to every other — the classifier then called a\n * perfectly readable document a stack of images. Caught by\n * `does NOT strike out real pages that merely share a running header`.\n */\nconst PAGE_NUMBER_HEAD = /^\\s*(?:page|p\\.?|pg\\.?)?\\s*\\d+(?:\\s*(?:of|\\/)\\s*\\d+)?\\s*(?:[-–—|]\\s*)?/i;\nconst PAGE_NUMBER_TAIL = /\\s*(?:[-–—|]\\s*)?(?:page|p\\.?|pg\\.?)?\\s*\\d+(?:\\s*(?:of|\\/)\\s*\\d+)?\\s*$/i;\n\nfunction normaliseLine(line: string): string {\n const collapsed = line.replace(/\\s+/g, ' ').trim().toLowerCase();\n // Head first, then tail, and never to the point of emptying the line: a line\n // that is ONLY a page number normalises to '' and is dropped as blank.\n const withoutHead = collapsed.replace(PAGE_NUMBER_HEAD, '');\n const withoutTail = (withoutHead || collapsed).replace(PAGE_NUMBER_TAIL, '');\n return withoutTail.trim();\n}\n\nexport function summarisePageText(pages: string[]): PageTextSummary {\n const linesPerPage = pages.map((page) => {\n const seen = new Set<string>();\n for (const line of page.split('\\n')) {\n const normalised = normaliseLine(line);\n if (normalised !== '') seen.add(normalised);\n }\n return seen;\n });\n\n const pagesHoldingLine = new Map<string, number>();\n for (const seen of linesPerPage) {\n for (const line of seen) pagesHoldingLine.set(line, (pagesHoldingLine.get(line) ?? 0) + 1);\n }\n\n // Two pages minimum: a line that appears once is by definition not repeated.\n const threshold = Math.max(2, Math.ceil(pages.length * BOILERPLATE_PAGE_SHARE));\n const boilerplate = new Set<string>();\n for (const [line, count] of pagesHoldingLine) {\n if (count >= threshold && line.length <= MAX_BOILERPLATE_LINE_CHARS) boilerplate.add(line);\n }\n\n const textPages: number[] = [];\n const imagePages: number[] = [];\n pages.forEach((page, index) => {\n const specific = page\n .split('\\n')\n .filter((line) => {\n const normalised = normaliseLine(line);\n return normalised !== '' && !boilerplate.has(normalised);\n })\n .join('\\n')\n .trim();\n (specific.length >= MIN_PAGE_TEXT_CHARS ? textPages : imagePages).push(index + 1);\n });\n\n return { textPages, imagePages, boilerplate: [...boilerplate] };\n}\n\n/**\n * Is this document mostly images — i.e. must it be presented as UNREAD?\n *\n * Takes the counts rather than the extraction so it stays pure and is the same\n * function whether it is asked at extraction time or at prompt-building time.\n */\nexport function isMostlyImagePages(textPageCount: number, pagesScanned: number): boolean {\n if (pagesScanned <= 0) return false;\n return textPageCount < pagesScanned * MIN_TEXT_PAGE_SHARE;\n}\n\n/**\n * Everything `extractPdf` does once pdf.js has handed over the page strings.\n *\n * Pulled out of the browser half deliberately: pdf.js needs a DOM and this\n * repo's vitest is `environment: 'node'`, so leaving the scanned-vs-read\n * decision inside `extractPdf` left the most dangerous logic in the feature —\n * \"may the model treat this document as read\" — with no test that could reach\n * it. Here it is a string-array-in, extraction-out function.\n */\nexport interface PdfPageFit {\n extraction: DocumentExtraction;\n textContent?: string;\n documentPages?: string[];\n textTruncated?: boolean;\n}\n\nexport function fitPdfPages(pages: string[], pageCount: number, pagesScanned: number, limit: number): PdfPageFit {\n // Which pages actually carry text, page by page. `pages.every(p => p === '')`\n // was the old test and every scanner defeats it: a scanned report whose only\n // text layer is a per-page `Scanned with CamScanner 3` footer passed it, and\n // the model was then told it had read twelve pages of a soil report.\n const density = summarisePageText(pages);\n\n if (density.textPages.length === 0) {\n return { extraction: { status: 'no-text', pageCount, pagesScanned } };\n }\n\n // Image pages are blanked BEFORE fitting so they are neither rendered as an\n // empty `[page N]` nor counted as pages we read. Their numbers survive in\n // `imagePages`, which is what the prompt block discloses.\n const hasText = new Set(density.textPages);\n const readable = pages.map((page, index) => (hasText.has(index + 1) ? page : ''));\n const fitted = truncatePagesForInline(readable, limit);\n\n if (fitted.text === '') {\n return { extraction: { status: 'no-text', pageCount, pagesScanned } };\n }\n\n return {\n extraction: {\n status: 'ok',\n pageCount,\n pagesScanned,\n pagesIncluded: fitted.pagesIncluded,\n pageNumbers: fitted.pageNumbers,\n imagePages: density.imagePages,\n textPageCount: density.textPages.length,\n sourceChars: fitted.sourceChars,\n },\n textContent: fitted.text,\n // The pages the fit actually KEPT, already trimmed to the per-file cap —\n // including a hard-sliced first page. Storing the untruncated pages here is\n // what let the shared budget re-expand a document past its own cap.\n documentPages: fitted.pages,\n textTruncated: fitted.truncated || pagesScanned < pageCount,\n };\n}\n\n/** `[1,2,3,7,9,10]` → `\"1-3, 7, 9-10\"`. Empty in, empty out. */\nexport function formatPageRanges(pages: number[]): string {\n const sorted = [...new Set(pages)].sort((a, b) => a - b);\n const parts: string[] = [];\n let start: number | null = null;\n let previous = 0;\n\n const flush = () => {\n if (start === null) return;\n parts.push(start === previous ? `${start}` : `${start}-${previous}`);\n };\n\n for (const page of sorted) {\n if (start === null) {\n start = previous = page;\n continue;\n }\n if (page === previous + 1) {\n previous = page;\n continue;\n }\n flush();\n start = previous = page;\n }\n flush();\n\n return parts.join(', ');\n}\n\nexport interface FittedPages {\n text: string;\n truncated: boolean;\n /** How far into the document `text` reaches: pages 1..N were processed. */\n pagesIncluded: number;\n /** The 1-indexed pages whose text is actually in `text`. */\n pageNumbers: number[];\n /** Rendered length of every page that HAS text, before the cut. */\n sourceChars: number;\n /**\n * `pages` trimmed to exactly what `text` holds, indices preserved.\n *\n * This is what makes the per-file cap an INVARIANT rather than a hope: the\n * caller stores this array, so a later re-fit against the shared budget can\n * only ever shrink it. Storing the untruncated pages instead let the shared\n * pass re-expand a document to 20,000 characters — 2.5x the per-file cap —\n * and starve the file attached beside it.\n */\n pages: string[];\n}\n\n/**\n * Fit whole PDF pages into a character budget, preferring a PAGE boundary.\n *\n * A page is the unit a reader — and a citation — thinks in, so cutting mid-page\n * is a worse lie than dropping the tail entirely. Falls back to a hard character\n * cut only when the first page with text will not fit on its own, because\n * \"0 pages included\" is useless to the model.\n *\n * Blank entries are pages the caller has judged to carry no text (see\n * `summarisePageText`). They are skipped rather than rendered as an empty\n * `[page N]`, which would both waste budget and read to the model as a page it\n * had seen and found empty.\n */\nexport function truncatePagesForInline(pages: string[], limit: number): FittedPages {\n const render = (page: string, index: number) => `${pageMarker(index + 1)}\\n${page}`;\n const withText = pages\n .map((page, index) => ({ index, page, rendered: render(page, index) }))\n .filter((entry) => entry.page.trim() !== '');\n const sourceChars = withText.map((entry) => entry.rendered).join('\\n\\n').length;\n\n if (withText.length === 0) {\n return { text: '', truncated: false, pagesIncluded: pages.length, pageNumbers: [], sourceChars: 0, pages: [] };\n }\n\n const kept: typeof withText = [];\n let used = 0;\n let considered = 0;\n let stopped = false;\n\n for (let index = 0; index < pages.length; index += 1) {\n if (pages[index].trim() === '') {\n considered = index + 1;\n continue;\n }\n const rendered = render(pages[index], index);\n const cost = kept.length === 0 ? rendered.length : rendered.length + 2;\n if (used + cost > limit) {\n stopped = true;\n break;\n }\n kept.push({ index, page: pages[index], rendered });\n used += cost;\n considered = index + 1;\n }\n\n if (kept.length > 0) {\n return {\n text: kept.map((entry) => entry.rendered).join('\\n\\n'),\n truncated: stopped,\n pagesIncluded: considered,\n pageNumbers: kept.map((entry) => entry.index + 1),\n sourceChars,\n pages: pages.slice(0, considered),\n };\n }\n\n // The first page WITH text is over budget on its own: keep a line-bounded\n // prefix of it. Still reported as that one page, and still flagged truncated,\n // so the model is told both which page it has and that the page is incomplete.\n const first = withText[0];\n const head = first.rendered.slice(0, Math.max(0, limit));\n const lastNewline = head.lastIndexOf('\\n');\n const text = lastNewline > limit * 0.5 ? head.slice(0, lastNewline) : head;\n const body = text.slice(pageMarker(first.index + 1).length + 1);\n\n if (body.trim() === '') {\n // The budget does not even cover the page marker. Say nothing rather than\n // emit a header with no page under it.\n return { text: '', truncated: true, pagesIncluded: 0, pageNumbers: [], sourceChars, pages: [] };\n }\n\n const trimmed = pages.slice(0, first.index + 1);\n trimmed[first.index] = body;\n return {\n text,\n truncated: true,\n pagesIncluded: first.index + 1,\n pageNumbers: [first.index + 1],\n sourceChars,\n pages: trimmed,\n };\n}\n"],"mappings":";AAqBA,IAAa,IAAsB,KA0BtB,IAAyB,IAiBzB,IAAsB,IA6D7B,IAAuC;CAC3C,KAAK;CACL,IAAI;CACJ,IAAI;CACJ,MAAM;CACN,MAAM;CACP;AAGD,SAAgB,EAAkB,GAAuB;AACvD,QAAO,EAAM,QAAQ,mCAAmC,GAAO,MAAiB;AAC9E,MAAI,EAAK,WAAW,KAAK,IAAI,EAAK,WAAW,KAAK,EAAE;GAClD,IAAM,IAAO,OAAO,SAAS,EAAK,MAAM,EAAE,EAAE,GAAG;AAC/C,UAAO,OAAO,SAAS,EAAK,GAAG,OAAO,cAAc,EAAK,GAAG;;AAE9D,MAAI,EAAK,WAAW,IAAI,EAAE;GACxB,IAAM,IAAO,OAAO,SAAS,EAAK,MAAM,EAAE,EAAE,GAAG;AAC/C,UAAO,OAAO,SAAS,EAAK,GAAG,OAAO,cAAc,EAAK,GAAG;;AAE9D,SAAO,EAAa,MAAS;GAC7B;;AAIJ,SAAS,EAAK,GAAsB;AAClC,QAAO,EACJ,MAAM,KAAK,CACX,KAAK,MAAS,EAAK,QAAQ,WAAW,GAAG,CAAC,CAC1C,KAAK,KAAK,CACV,QAAQ,WAAW,OAAO,CAC1B,MAAM;;AAiBX,SAAgB,EAAc,GAAqB;CACjD,IAAM,I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EAAM,EACtC,IAAO,EAAK,WAAW,IAAI,EAAS,SAAS,EAAS,SAAS;AACrE,MAAI,IAAO,IAAO,GAAO;AACvB,OAAU;AACV;;AAIF,EAFA,EAAK,KAAK;GAAE;GAAO,MAAM,EAAM;GAAQ;GAAU,CAAC,EAClD,KAAQ,GACR,IAAa,IAAQ;;AAGvB,KAAI,EAAK,SAAS,EAChB,QAAO;EACL,MAAM,EAAK,KAAK,MAAU,EAAM,SAAS,CAAC,KAAK,OAAO;EACtD,WAAW;EACX,eAAe;EACf,aAAa,EAAK,KAAK,MAAU,EAAM,QAAQ,EAAE;EACjD;EACA,OAAO,EAAM,MAAM,GAAG,EAAW;EAClC;CAMH,IAAM,IAAQ,EAAS,IACjB,IAAO,EAAM,SAAS,MAAM,GAAG,KAAK,IAAI,GAAG,EAAM,CAAC,EAClD,IAAc,EAAK,YAAY,KAAK,EACpC,IAAO,IAAc,IAAQ,KAAM,EAAK,MAAM,GAAG,EAAY,GAAG,GAChE,IAAO,EAAK,MAAM,EAAW,EAAM,QAAQ,EAAE,CAAC,SAAS,EAAE;AAE/D,KAAI,EAAK,MAAM,KAAK,GAGlB,QAAO;EAAE,MAAM;EAAI,WAAW;EAAM,eAAe;EAAG,aAAa,EAAE;EAAE;EAAa,OAAO,EAAE;EAAE;CAGjG,IAAM,IAAU,EAAM,MAAM,GAAG,EAAM,QAAQ,EAAE;AAE/C,QADA,EAAQ,EAAM,SAAS,GAChB;EACL;EACA,WAAW;EACX,eAAe,EAAM,QAAQ;EAC7B,aAAa,CAAC,EAAM,QAAQ,EAAE;EAC9B;EACA,OAAO;EACR"}
|
package/dist/utils/quotaUtils.js
CHANGED
|
@@ -1,24 +1,38 @@
|
|
|
1
1
|
//#region src/utils/quotaUtils.ts
|
|
2
|
-
function e(e) {
|
|
3
|
-
return e?.some((e) => e.extensions?.code === "QUOTA_EXHAUSTED" || e.extensions?.errorCode === "QUOTA_EXHAUSTED" || e.message?.includes("QUOTA_EXHAUSTED")) ?? !1;
|
|
4
|
-
}
|
|
5
|
-
function t(e, t) {
|
|
2
|
+
function e(e, t) {
|
|
6
3
|
if (!e || typeof e != "object") return;
|
|
7
4
|
let n = e[t];
|
|
8
5
|
return Array.isArray(n) ? n : void 0;
|
|
9
6
|
}
|
|
10
|
-
function
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
7
|
+
function t(e) {
|
|
8
|
+
let t = i(e);
|
|
9
|
+
return t ? t === "exhausted" : e instanceof Error && e.message.toLowerCase().includes("quota exhausted");
|
|
10
|
+
}
|
|
11
|
+
var n = {
|
|
12
|
+
QUOTA_EXHAUSTED: "exhausted",
|
|
13
|
+
QUOTA_NOT_PROVISIONED: "not-provisioned"
|
|
14
|
+
};
|
|
15
|
+
function r(t) {
|
|
16
|
+
if (!t || typeof t != "object") return [];
|
|
17
|
+
let r = [
|
|
18
|
+
t,
|
|
19
|
+
t.result,
|
|
20
|
+
t.networkError
|
|
21
|
+
], i = [];
|
|
22
|
+
for (let t of r) for (let n of e(t, "errors") ?? []) n.extensions?.code && i.push(n.extensions.code), n.extensions?.errorCode && i.push(n.extensions.errorCode);
|
|
23
|
+
let a = t.bodyText, o = t instanceof Error ? t.message : void 0;
|
|
24
|
+
for (let e of [a, o]) if (typeof e == "string") for (let t of Object.keys(n)) e.includes(t) && i.push(t);
|
|
25
|
+
return i;
|
|
26
|
+
}
|
|
27
|
+
function i(e) {
|
|
28
|
+
let t = r(e);
|
|
29
|
+
if (t.includes("QUOTA_NOT_PROVISIONED")) return "not-provisioned";
|
|
30
|
+
if (t.includes("QUOTA_EXHAUSTED")) return "exhausted";
|
|
31
|
+
let n = e?.statusCode;
|
|
32
|
+
return typeof n == "number" && n === 429 ? "exhausted" : null;
|
|
19
33
|
}
|
|
20
|
-
var
|
|
34
|
+
var a = "healthybowl:quota-exhausted";
|
|
21
35
|
//#endregion
|
|
22
|
-
export {
|
|
36
|
+
export { a as QUOTA_EXHAUSTED_EVENT, t as isQuotaExhaustedError };
|
|
23
37
|
|
|
24
38
|
//# sourceMappingURL=quotaUtils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quotaUtils.js","names":[],"sources":["../../src/utils/quotaUtils.ts"],"sourcesContent":["/**\n * Quota-error detection for the assistant's raw-fetch transport.\n *\n * The assistant talks to the wspace gateway over `fetch` (not Apollo), so it\n * can't rely on the Apollo error link. `isQuotaExhaustedError` inspects the\n * thrown error for the gateway's 429 / QUOTA_EXHAUSTED signal across the shapes\n * `executeSandboxGraphQL` surfaces (Error.message, `.statusCode`, `.result`).\n *\n * Only the assistant's two quota walls are modelled: `sandbox` (the\n * sandboxes-created @usage limit hit during provisioning) and `ai-credits`\n * (per-token budget).\n */\n\ntype GraphQLErrorLike = {\n message?: string;\n extensions?: {\n code?: string;\n errorCode?: string;\n };\n};\n\nfunction
|
|
1
|
+
{"version":3,"file":"quotaUtils.js","names":[],"sources":["../../src/utils/quotaUtils.ts"],"sourcesContent":["/**\n * Quota-error detection for the assistant's raw-fetch transport.\n *\n * The assistant talks to the wspace gateway over `fetch` (not Apollo), so it\n * can't rely on the Apollo error link. `isQuotaExhaustedError` inspects the\n * thrown error for the gateway's 429 / QUOTA_EXHAUSTED signal across the shapes\n * `executeSandboxGraphQL` surfaces (Error.message, `.statusCode`, `.result`).\n *\n * Only the assistant's two quota walls are modelled: `sandbox` (the\n * sandboxes-created @usage limit hit during provisioning) and `ai-credits`\n * (per-token budget).\n */\n\ntype GraphQLErrorLike = {\n message?: string;\n extensions?: {\n code?: string;\n errorCode?: string;\n };\n};\n\nfunction arrayOfErrorsAt(host: object | undefined, key: 'errors'): GraphQLErrorLike[] | undefined {\n if (!host || typeof host !== 'object') return undefined;\n const value = (host as Record<string, unknown>)[key];\n return Array.isArray(value) ? (value as GraphQLErrorLike[]) : undefined;\n}\n\n/**\n * Whether this error is an EXHAUSTED quota specifically.\n *\n * ★ BOFF-6302 — this used to match any HTTP 429, and a workspace with no assignment row is refused\n * `429 QUOTA_NOT_PROVISIONED`. That is not exhaustion: the farmer has not used anything up, their\n * plan was never granted, and \"you have reached your limit\" sends them to buy an upgrade that would\n * not unblock them. {@link classifyQuotaError} now owns the distinction and this delegates to it.\n */\nexport function isQuotaExhaustedError(error: unknown): boolean {\n const refusal = classifyQuotaError(error);\n if (refusal) return refusal === 'exhausted';\n\n // The one shape the classifier deliberately does not match: prose with no code in it. Kept for the\n // assistant's raw-fetch transport, which can surface a bare \"quota exhausted\" string.\n return error instanceof Error && error.message.toLowerCase().includes('quota exhausted');\n}\n\n/**\n * The two ways the gateway refuses a metered mutation. They are NOT the same thing and must not be\n * shown to a farmer with the same words (BOFF-6302).\n *\n * - `exhausted` — the workspace has the quota and has used it up. Deleting something, or upgrading,\n * fixes it. Actionable by the user.\n * - `not-provisioned` — the workspace has **no assignment row for that quota at all**, so the\n * gateway fails closed. Nothing the user does fixes it: they have not hit a limit, their plan was\n * never granted. Measured in prod 2026-08-13, this is why `createHealthyBowlFarm` returns\n * `429 QUOTA_NOT_PROVISIONED` on several workspaces — the core create path is simply dead there.\n *\n * ★ Keyed on `extensions.code`, never on the HTTP status or the message text. Both refusals are\n * `429`, so status alone cannot tell them apart — which is exactly how \"no active subscription\n * covers this\" would otherwise be reported to a farmer as \"you have reached your limit\".\n */\nexport type QuotaRefusal = 'exhausted' | 'not-provisioned';\n\nconst REFUSAL_BY_CODE: Record<string, QuotaRefusal> = {\n QUOTA_EXHAUSTED: 'exhausted',\n QUOTA_NOT_PROVISIONED: 'not-provisioned',\n};\n\n/** Every `extensions.code` reachable on an error, across the shapes Apollo and raw-fetch produce. */\nfunction codesIn(error: unknown): string[] {\n if (!error || typeof error !== 'object') return [];\n const hosts = [\n error as object,\n (error as { result?: object }).result,\n (error as { networkError?: object }).networkError,\n ];\n const codes: string[] = [];\n for (const host of hosts) {\n for (const e of arrayOfErrorsAt(host, 'errors') ?? []) {\n if (e.extensions?.code) codes.push(e.extensions.code);\n if (e.extensions?.errorCode) codes.push(e.extensions.errorCode);\n }\n }\n const bodyText = (error as { bodyText?: unknown }).bodyText;\n const message = error instanceof Error ? error.message : undefined;\n for (const text of [bodyText, message]) {\n if (typeof text !== 'string') continue;\n for (const code of Object.keys(REFUSAL_BY_CODE)) if (text.includes(code)) codes.push(code);\n }\n return codes;\n}\n\n/**\n * Which refusal this is, or null when the error is not a quota wall at all.\n *\n * `not-provisioned` wins when both appear: it is the more specific and the more serious of the two,\n * and telling someone to upgrade when their plan was never granted sends them to buy something that\n * would not help.\n */\nexport function classifyQuotaError(error: unknown): QuotaRefusal | null {\n const codes = codesIn(error);\n if (codes.includes('QUOTA_NOT_PROVISIONED')) return 'not-provisioned';\n if (codes.includes('QUOTA_EXHAUSTED')) return 'exhausted';\n // A bare 429 with no discernible code: the assistant's raw-fetch transport can surface one, and\n // exhaustion is the likelier cause. Deliberately last, so an explicit code always wins.\n const statusCode = (error as { statusCode?: unknown } | null)?.statusCode;\n if (typeof statusCode === 'number' && statusCode === 429) return 'exhausted';\n return null;\n}\n\nexport type QuotaKind = 'sandbox' | 'ai-credits' | 'generic';\n\n// Event the assistant dispatches on a quota wall. HealthyBowl does not yet\n// mount a listener (the chat area also surfaces the wall inline), so this is a\n// best-effort hook for a future upgrade dialog.\nexport const QUOTA_EXHAUSTED_EVENT = 'healthybowl:quota-exhausted';\n\nexport interface QuotaExhaustedEventDetail {\n kind: QuotaKind;\n message?: string;\n operationName?: string | null;\n}\n"],"mappings":";AAqBA,SAAS,EAAgB,GAA0B,GAA+C;AAChG,KAAI,CAAC,KAAQ,OAAO,KAAS,SAAU;CACvC,IAAM,IAAS,EAAiC;AAChD,QAAO,MAAM,QAAQ,EAAM,GAAI,IAA+B,KAAA;;AAWhE,SAAgB,EAAsB,GAAyB;CAC7D,IAAM,IAAU,EAAmB,EAAM;AAKzC,QAJI,IAAgB,MAAY,cAIzB,aAAiB,SAAS,EAAM,QAAQ,aAAa,CAAC,SAAS,kBAAkB;;AAoB1F,IAAM,IAAgD;CACpD,iBAAiB;CACjB,uBAAuB;CACxB;AAGD,SAAS,EAAQ,GAA0B;AACzC,KAAI,CAAC,KAAS,OAAO,KAAU,SAAU,QAAO,EAAE;CAClD,IAAM,IAAQ;EACZ;EACC,EAA8B;EAC9B,EAAoC;EACtC,EACK,IAAkB,EAAE;AAC1B,MAAK,IAAM,KAAQ,EACjB,MAAK,IAAM,KAAK,EAAgB,GAAM,SAAS,IAAI,EAAE,CAEnD,CADI,EAAE,YAAY,QAAM,EAAM,KAAK,EAAE,WAAW,KAAK,EACjD,EAAE,YAAY,aAAW,EAAM,KAAK,EAAE,WAAW,UAAU;CAGnE,IAAM,IAAY,EAAiC,UAC7C,IAAU,aAAiB,QAAQ,EAAM,UAAU,KAAA;AACzD,MAAK,IAAM,KAAQ,CAAC,GAAU,EAAQ,CAChC,YAAO,KAAS,SACpB,MAAK,IAAM,KAAQ,OAAO,KAAK,EAAgB,CAAE,CAAI,EAAK,SAAS,EAAK,IAAE,EAAM,KAAK,EAAK;AAE5F,QAAO;;AAUT,SAAgB,EAAmB,GAAqC;CACtE,IAAM,IAAQ,EAAQ,EAAM;AAC5B,KAAI,EAAM,SAAS,wBAAwB,CAAE,QAAO;AACpD,KAAI,EAAM,SAAS,kBAAkB,CAAE,QAAO;CAG9C,IAAM,IAAc,GAA2C;AAE/D,QADI,OAAO,KAAe,YAAY,MAAe,MAAY,cAC1D;;AAQT,IAAa,IAAwB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@burdenoff/microfe-healthybowl",
|
|
3
|
-
"version": "2026.
|
|
3
|
+
"version": "2026.813.1",
|
|
4
4
|
"description": "Burdenoff HealthyBowl Microfrontend - Comprehensive organic farming and agro-foods management platform",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -51,9 +51,11 @@
|
|
|
51
51
|
"@tanstack/react-query": "^5.90.16",
|
|
52
52
|
"clsx": "^2.1.1",
|
|
53
53
|
"date-fns": "^4.1.0",
|
|
54
|
+
"fflate": "0.8.3",
|
|
54
55
|
"graphql": "^16.12.0",
|
|
55
56
|
"leaflet": "^1.9.4",
|
|
56
57
|
"lucide-react": "^0.468.0",
|
|
58
|
+
"pdfjs-dist": "6.2.108",
|
|
57
59
|
"qrcode": "^1.5.4",
|
|
58
60
|
"react": "^19.0.0",
|
|
59
61
|
"react-dom": "^19.0.0",
|