llm-large-files 0.7.0 → 0.8.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/CHANGELOG.md +319 -1
- package/README.md +10 -8
- package/dist/analyze.d.ts +3 -1
- package/dist/analyze.d.ts.map +1 -1
- package/dist/analyze.js +109 -14
- package/dist/analyze.js.map +1 -1
- package/dist/anthropic/adapter.d.ts.map +1 -1
- package/dist/anthropic/adapter.js +4 -1
- package/dist/anthropic/adapter.js.map +1 -1
- package/dist/ask.d.ts +3 -3
- package/dist/ask.d.ts.map +1 -1
- package/dist/ask.js +72 -17
- package/dist/ask.js.map +1 -1
- package/dist/decode.d.ts +19 -0
- package/dist/decode.d.ts.map +1 -0
- package/dist/decode.js +97 -0
- package/dist/decode.js.map +1 -0
- package/dist/errors.d.ts +55 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +65 -0
- package/dist/errors.js.map +1 -1
- package/dist/events.d.ts +6 -0
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js +5 -1
- package/dist/events.js.map +1 -1
- package/dist/evidence.d.ts.map +1 -1
- package/dist/evidence.js +6 -0
- package/dist/evidence.js.map +1 -1
- package/dist/extract.d.ts +7 -20
- package/dist/extract.d.ts.map +1 -1
- package/dist/extract.js +49 -751
- package/dist/extract.js.map +1 -1
- package/dist/gemini/adapter.d.ts.map +1 -1
- package/dist/gemini/adapter.js +9 -5
- package/dist/gemini/adapter.js.map +1 -1
- package/dist/gemini/endpoints.d.ts +5 -1
- package/dist/gemini/endpoints.d.ts.map +1 -1
- package/dist/gemini/endpoints.js +11 -2
- package/dist/gemini/endpoints.js.map +1 -1
- package/dist/gemini/generate.d.ts.map +1 -1
- package/dist/gemini/generate.js +20 -3
- package/dist/gemini/generate.js.map +1 -1
- package/dist/groups.d.ts +54 -0
- package/dist/groups.d.ts.map +1 -0
- package/dist/groups.js +136 -0
- package/dist/groups.js.map +1 -0
- package/dist/html.d.ts +11 -0
- package/dist/html.d.ts.map +1 -0
- package/dist/html.js +1112 -0
- package/dist/html.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/library.d.ts.map +1 -1
- package/dist/library.js +48 -12
- package/dist/library.js.map +1 -1
- package/dist/limiter.d.ts +2 -1
- package/dist/limiter.d.ts.map +1 -1
- package/dist/limiter.js +3 -2
- package/dist/limiter.js.map +1 -1
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +8 -1
- package/dist/model.js.map +1 -1
- package/dist/node/handlers.d.ts.map +1 -1
- package/dist/node/handlers.js +69 -15
- package/dist/node/handlers.js.map +1 -1
- package/dist/node/index.d.ts +2 -0
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +1 -0
- package/dist/node/index.js.map +1 -1
- package/dist/node/ingest-child.d.ts +38 -0
- package/dist/node/ingest-child.d.ts.map +1 -0
- package/dist/node/ingest-child.js +42 -0
- package/dist/node/ingest-child.js.map +1 -0
- package/dist/node/isolated.d.ts +88 -0
- package/dist/node/isolated.d.ts.map +1 -0
- package/dist/node/isolated.js +381 -0
- package/dist/node/isolated.js.map +1 -0
- package/dist/office.d.ts +105 -0
- package/dist/office.d.ts.map +1 -0
- package/dist/office.js +1092 -0
- package/dist/office.js.map +1 -0
- package/dist/openai/adapter.d.ts.map +1 -1
- package/dist/openai/adapter.js +15 -1
- package/dist/openai/adapter.js.map +1 -1
- package/dist/pdf-pages.d.ts.map +1 -1
- package/dist/pdf-pages.js +2 -6
- package/dist/pdf-pages.js.map +1 -1
- package/dist/peers.d.ts +8 -0
- package/dist/peers.d.ts.map +1 -0
- package/dist/peers.js +32 -0
- package/dist/peers.js.map +1 -0
- package/dist/plan.d.ts.map +1 -1
- package/dist/plan.js +1 -1
- package/dist/plan.js.map +1 -1
- package/dist/ranged.d.ts.map +1 -1
- package/dist/ranged.js +4 -2
- package/dist/ranged.js.map +1 -1
- package/dist/search.d.ts +99 -22
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +744 -140
- package/dist/search.js.map +1 -1
- package/dist/text-index.d.ts +3 -1
- package/dist/text-index.d.ts.map +1 -1
- package/dist/text-index.js +3 -1
- package/dist/text-index.js.map +1 -1
- package/dist/text.d.ts +27 -3
- package/dist/text.d.ts.map +1 -1
- package/dist/text.js +225 -23
- package/dist/text.js.map +1 -1
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +200 -12
- package/dist/tools.js.map +1 -1
- package/dist/types.d.ts +3 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/word-styles.d.ts +102 -0
- package/dist/word-styles.d.ts.map +1 -0
- package/dist/word-styles.js +419 -0
- package/dist/word-styles.js.map +1 -0
- package/dist/xlsx.d.ts +23 -0
- package/dist/xlsx.d.ts.map +1 -0
- package/dist/xlsx.js +511 -0
- package/dist/xlsx.js.map +1 -0
- package/dist/xml-stream.d.ts +55 -0
- package/dist/xml-stream.d.ts.map +1 -0
- package/dist/xml-stream.js +235 -0
- package/dist/xml-stream.js.map +1 -0
- package/docs/README.md +8 -8
- package/docs/getting-started.md +1 -1
- package/docs/guides/costs-and-limits.md +7 -5
- package/docs/guides/deployment.md +95 -29
- package/docs/guides/errors-and-reliability.md +23 -10
- package/docs/guides/pdfs.md +127 -74
- package/docs/guides/storage.md +1 -1
- package/docs/guides/testing.md +5 -1
- package/docs/guides/web-app.md +10 -9
- package/docs/how-it-works.md +73 -50
- package/docs/reference/ask.md +26 -8
- package/docs/reference/errors-and-retries.md +5 -3
- package/docs/reference/events.md +14 -6
- package/docs/reference/gemini.md +6 -2
- package/docs/reference/library.md +205 -74
- package/docs/reference/node.md +200 -22
- package/docs/reference/openai.md +1 -1
- package/docs/reference/tools.md +170 -22
- package/docs/security.md +114 -69
- package/docs/troubleshooting.md +40 -20
- package/package.json +6 -2
- package/src/analyze.ts +117 -13
- package/src/anthropic/adapter.ts +4 -1
- package/src/ask.ts +73 -17
- package/src/decode.ts +89 -0
- package/src/errors.ts +108 -0
- package/src/events.ts +10 -1
- package/src/evidence.ts +6 -0
- package/src/extract.ts +52 -709
- package/src/gemini/adapter.ts +9 -5
- package/src/gemini/endpoints.ts +12 -2
- package/src/gemini/generate.ts +19 -3
- package/src/groups.ts +162 -0
- package/src/html.ts +1071 -0
- package/src/index.ts +2 -1
- package/src/library.ts +43 -12
- package/src/limiter.ts +6 -1
- package/src/model.ts +8 -1
- package/src/node/handlers.ts +66 -16
- package/src/node/index.ts +2 -0
- package/src/node/ingest-child.ts +61 -0
- package/src/node/isolated.ts +464 -0
- package/src/office.ts +1047 -0
- package/src/openai/adapter.ts +14 -1
- package/src/pdf-pages.ts +2 -5
- package/src/peers.ts +29 -0
- package/src/plan.ts +2 -0
- package/src/ranged.ts +4 -2
- package/src/search.ts +738 -146
- package/src/text-index.ts +4 -2
- package/src/text.ts +214 -23
- package/src/tools.ts +192 -12
- package/src/types.ts +3 -3
- package/src/word-styles.ts +420 -0
- package/src/xlsx.ts +478 -0
- package/src/xml-stream.ts +224 -0
package/docs/guides/pdfs.md
CHANGED
|
@@ -7,11 +7,11 @@ own, OCR among them. Exact signatures are in the [library reference](../referenc
|
|
|
7
7
|
|
|
8
8
|
## Formats
|
|
9
9
|
|
|
10
|
-
The readers of DOCX, PPTX and PDF files are optional dependencies. Install the ones you need
|
|
11
|
-
every server that ingests files:
|
|
10
|
+
The readers of DOCX, PPTX, XLSX and PDF files are optional dependencies. Install the ones you need
|
|
11
|
+
on every server that ingests files:
|
|
12
12
|
|
|
13
13
|
```bash
|
|
14
|
-
npm install jszip # DOCX and
|
|
14
|
+
npm install jszip # DOCX, PPTX and XLSX
|
|
15
15
|
npm install unpdf # PDF text (on Node 20 and 22, name a version: see below)
|
|
16
16
|
npm install @cantoo/pdf-lib # PDF picture marks, page check, and view_pages
|
|
17
17
|
```
|
|
@@ -37,40 +37,44 @@ back to llm-large-files 0.5.0 must go back to unpdf 1 in the same command
|
|
|
37
37
|
| Format | Detected by | Needs | What the text holds |
|
|
38
38
|
|---|---|---|---|
|
|
39
39
|
| `text` | Anything not below | | The file decoded as UTF-8, or as UTF-16 with a byte-order mark. Without the mark, only little-endian UTF-16 of mostly ASCII text is recognised. A file that is not UTF-8 is read in windows-1255, windows-1256, windows-1251, Shift_JIS or windows-1252 when its letters show which one (`meta.encoding`), and as UTF-8 otherwise ([Text encodings](#text-encodings)). Characters that are not valid are stored as U+FFFD (�) and counted (`meta.replacedCharacters`). |
|
|
40
|
-
| `log` | `.log`, `.out`, `.err`; or a `text` file in which at least 40% of the first 200 non-empty lines (5 at least) start with a timestamp or a level | | As `text`, plus a log profile: levels, time range, most frequent errors. |
|
|
40
|
+
| `log` | `.log`, `.out`, `.err`; or a `text` file in which at least 40% of the first 200 non-empty lines (5 at least) start with a timestamp or a level, or have the shape of an access log, a JSON log line, klog or logfmt | | As `text`, plus a log profile: levels, time range, most frequent errors. |
|
|
41
41
|
| `markdown` | `.md`, `.markdown`, `text/markdown` | | As `text`. Its `#` headings form the outline. |
|
|
42
42
|
| `json` | `.json`, `.jsonl`, `.ndjson`, `application/json` | | As `text`. Minified JSON becomes lines of at most 2,000 characters. |
|
|
43
43
|
| `csv` | `.csv`, `.tsv`, `text/csv` | | As `text`. |
|
|
44
44
|
| `pdf` | `.pdf`, `application/pdf` | `unpdf`; `@cantoo/pdf-lib` for picture marks, the page check and `view_pages` | A `--- Page N ---` line before each page, tables rebuilt as rows of cells, a line for a page without text and for a page with a picture ([PDF text](#pdf-text)). |
|
|
45
|
-
| `docx` | `.docx`, or the Word MIME type | `jszip` | The body, then the endnotes,
|
|
46
|
-
| `pptx` | `.pptx`, or the PowerPoint MIME type | `jszip` | `## Slide N` before each slide, `## Slide N (hidden, not shown in the slide show)` for a slide that the slide show skips, `[No text on this slide]` for a slide without text. |
|
|
45
|
+
| `docx` | `.docx`, `.docm`, or the Word MIME type | `jszip` | The body, with headings as Markdown headings (`## 2.1 Rent`), list numbers as Word shows them and tables as rows of `\| cell \| cell \| \|`; then the footnotes, endnotes, comments, headers and footers, in that order, each under a heading of its own. Text that Word hides comes after the text of its paragraph that shows, each of its lines starting `[Hidden text, not shown in the document]` ([DOCX and PPTX](#docx-and-pptx)). |
|
|
46
|
+
| `pptx` | `.pptx`, `.pptm`, or the PowerPoint MIME type | `jszip` | `## Slide N` before each slide, in the order of the slide show, with its tables and its speaker notes after `[Speaker notes]`; `## Slide N (hidden, not shown in the slide show)` for a slide that the slide show skips, `[No text on this slide]` for a slide without text. |
|
|
47
|
+
| `xlsx` | `.xlsx`, `.xlsm`, `.xltx`, `.xltm`, or the Excel MIME types | `jszip` | `## Sheet N: name` before each sheet, a `Columns: \| A \| B \|` line, then a line a row, `Row 12: \| East \| 2026-03-01 \| 1200.5 \|`, with the values Excel last computed, dates, times and percentages as Excel shows them. New in 0.8.0 ([XLSX and HTML](#xlsx-and-html)). |
|
|
48
|
+
| `html` | `.html`, `.htm`, `.xhtml`, `text/html`, `application/xhtml+xml` | | The text a browser shows: headings, lists, tables as rows of cells, `text (https://…)` for a link, the alt text of a picture; no scripts or styles. New in 0.8.0. |
|
|
47
49
|
|
|
48
50
|
`detectFormat(name, mimeType)` picks the format: a known extension first, then the MIME type, then
|
|
49
51
|
`text`. So `report` with no extension, sent as `application/pdf`, is a PDF, and `data.txt` sent as
|
|
50
|
-
`application/json` is JSON, since `.txt` is not one of the known extensions.
|
|
51
|
-
|
|
52
|
-
JSON. Send the bare type (or
|
|
53
|
-
`createDocumentHandlers`, which takes it
|
|
52
|
+
`application/json` is JSON, since `.txt` is not one of the known extensions. XML, YAML and source
|
|
53
|
+
code are `text`; HTML is `html` since 0.8.0. The MIME type is compared whole:
|
|
54
|
+
`application/json; charset=utf-8` is not JSON. Send the bare type (or
|
|
55
|
+
`X-File-Type: application/json` to the upload route of `createDocumentHandlers`, which takes it
|
|
56
|
+
before `Content-Type`).
|
|
54
57
|
|
|
55
58
|
Whatever the format, the text is then made uniform: line breaks become `\n`, colour codes and other
|
|
56
59
|
control characters are removed, and lines longer than 2,000 characters are split, so every line can
|
|
57
|
-
be read by its number. Most characters that show nothing are removed too: tag characters,
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
headings: Markdown `#` lines (`## Slide N`
|
|
72
|
-
|
|
73
|
-
|
|
60
|
+
be read by its number. Most characters that show nothing are removed too: tag characters, zero-width
|
|
61
|
+
spaces, word joiners, a soft hyphen inside a line, and the text-direction controls that reorder what
|
|
62
|
+
a person sees. Those that scripts and emoji need are kept: the marks of right-to-left text (U+200E,
|
|
63
|
+
U+200F, U+061C), the joiners of emoji and Persian, variation selectors, Hangul fillers, and the line
|
|
64
|
+
and paragraph separators (U+2028, U+2029). A crafted file can still carry text that a person does
|
|
65
|
+
not see in them ([Security](../security.md#characters-that-show-nothing) lists them all). In a text
|
|
66
|
+
with no other line break, such as a mainframe file converted to UTF-8, U+0085 (next line) ends a
|
|
67
|
+
line, except right after a character from U+0080 to U+00FF, where it is taken for half of a UTF-8
|
|
68
|
+
letter and removed; anywhere else it is removed with the other control characters. That is text in
|
|
69
|
+
UTF-8: the same export converted to ISO-8859-1 is read as windows-1252, where its byte 0x85 is "…",
|
|
70
|
+
and stays one long line, so convert it to UTF-8 instead. No other line break is added or removed,
|
|
71
|
+
but a line of more than 2,000 characters that lost some of these characters can be split into fewer
|
|
72
|
+
pieces than 0.5.0 split it, which moves the lines after it. Since 0.8.0 the text is also composed
|
|
73
|
+
(NFC): "e" and a combining accent become "é". Every format but log, JSON and CSV gets an outline
|
|
74
|
+
from its headings: Markdown `#` lines (`## Slide N` and `## Sheet N: name` among them; not in a
|
|
75
|
+
fenced code block, nor the comments of a text file that reads as code), chapter and numbered section
|
|
76
|
+
lines, and short lines in capitals. `meta.pages` is the number of pages of a PDF, of slides of a
|
|
77
|
+
PPTX and of sheets of an XLSX. [How it works](../how-it-works.md) follows ingest from there.
|
|
74
78
|
|
|
75
79
|
### Text encodings
|
|
76
80
|
|
|
@@ -183,10 +187,23 @@ file again.
|
|
|
183
187
|
|
|
184
188
|
- A text box is read once, after the paragraph it is anchored in. Word stores it twice, the second
|
|
185
189
|
time for older programs.
|
|
186
|
-
- A
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
+
- A heading of Word (a paragraph of a heading style, of the title style, or with an outline level)
|
|
191
|
+
is a Markdown heading, `#` to `######`, also in a Hebrew document, whose styles keep English
|
|
192
|
+
names. A numbered paragraph starts with the number Word shows: `2.1`, `(a)`, roman numerals,
|
|
193
|
+
Hebrew letters and numerals, `-` for a bullet, and lists that restart. So "clause 2.2" can be
|
|
194
|
+
searched, and the document has an outline.
|
|
195
|
+
- A table is a line a row, `| cell | cell | |`, with its empty cells, as PDF tables are
|
|
196
|
+
([PDF tables](#pdf-tables)). A merged cell is followed by an empty cell for each column it
|
|
197
|
+
covers, so every row keeps its columns. Until 0.8.0 a table came out one cell per line.
|
|
198
|
+
- Non-breaking hyphens and the characters of symbol fonts are kept: "555-0199" no longer reads
|
|
199
|
+
"5550199".
|
|
200
|
+
- The footnotes, endnotes, comments, headers and footers come after the body, each under its own
|
|
201
|
+
heading (`# Footnotes`, `# Endnotes`, `# Comments`, `# Header`, `# Footer`); a header or footer
|
|
202
|
+
that repeats one already read is left out.
|
|
203
|
+
- The slides of a PPTX are numbered in the order of the slide show, the list in
|
|
204
|
+
`ppt/presentation.xml`, not in the order of their part names: "Slide 5" is the fifth slide shown.
|
|
205
|
+
A table of a slide is a line a row, and its speaker notes follow a line `[Speaker notes]`.
|
|
206
|
+
- Documents ingested before 0.8.0 keep the text they had until they are uploaded again.
|
|
190
207
|
- Text that Word hides (a run marked `<w:vanish/>`) is kept, after the text of its paragraph that
|
|
191
208
|
shows, and each of its lines starts with `[Hidden text, not shown in the document]`, so the model
|
|
192
209
|
can tell it from what a reader sees. A carriage return, a U+0085 or a line separator in it starts
|
|
@@ -199,31 +216,63 @@ file again.
|
|
|
199
216
|
through a style, a hidden shape on a slide that shows, white or 1-point text, a text box inside a
|
|
200
217
|
hidden run, tags written with a prefix other than `w:` or `p:`, a `show` value written as a
|
|
201
218
|
character reference (`show="0"`), and parts that nothing in the file refers to (an orphan
|
|
202
|
-
header
|
|
203
|
-
`mc:
|
|
204
|
-
|
|
205
|
-
Word shows.
|
|
219
|
+
header; an orphan slide only in a deck whose `ppt/presentation.xml` lists no slide). Of
|
|
220
|
+
`mc:AlternateContent`, the `mc:Choice` is read, where Word may show the `mc:Fallback`. And a
|
|
221
|
+
document's own text can write the mark. A `w:val` written as a character reference does the
|
|
222
|
+
opposite: `<w:vanish w:val="0"/>`, which Word reads as 0, marks text that Word shows.
|
|
206
223
|
- Pictures are not marked, and `view_pages` works on PDFs only. For a deck of charts, the PDF
|
|
207
224
|
export of the deck lets the model look at the slides.
|
|
208
225
|
|
|
226
|
+
### XLSX and HTML
|
|
227
|
+
|
|
228
|
+
New in 0.8.0. An Excel workbook (`.xlsx`, `.xlsm`) is read with `jszip`, as a DOCX is. Each sheet,
|
|
229
|
+
in the order of the workbook, is a section:
|
|
230
|
+
|
|
231
|
+
```text
|
|
232
|
+
## Sheet 1: Sales
|
|
233
|
+
Columns: | A | B | C |
|
|
234
|
+
Row 1: | Region | Date | Amount |
|
|
235
|
+
Row 12: | East | 2026-03-01 | 1200.5 |
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
- A row keeps its number in the sheet, so an answer can name the row a person finds in Excel, and
|
|
239
|
+
its empty cells up to its last value. Empty rows are left out; a sheet without a value says
|
|
240
|
+
`[No values on this sheet]`, and a hidden sheet says ` (hidden sheet)` after its name.
|
|
241
|
+
- A cell holds the value Excel last computed for it; a formula Excel never computed is written as
|
|
242
|
+
`=` and the formula. Dates and times follow their number formats, in the 1900 and the 1904 date
|
|
243
|
+
systems (`2026-03-01`, `2026-03-01 14:30`), percentages read `12.5%`, and numbers have up to 15
|
|
244
|
+
significant digits. Shared and inline strings are both read.
|
|
245
|
+
- Every row of every sheet is read, within `maxTextBytes`. A sheet past 52 columns lists them as
|
|
246
|
+
`Columns: A to BZ`.
|
|
247
|
+
|
|
248
|
+
An HTML page (`.html`, `.htm`) is read as the text a browser shows. Scripts, styles, forms' option
|
|
249
|
+
lists and other content that is not read are dropped. Headings become Markdown headings, list
|
|
250
|
+
items `- item` or `1. item`, each table row `| cell | cell |`, a link `text (https://…)`, and a
|
|
251
|
+
picture its alt text. The page's title is a `#` heading when no heading holds it. Entities are
|
|
252
|
+
decoded, so "AT&T" written `AT&T` is found. A page saved in an older encoding is read as a
|
|
253
|
+
text file is ([Text encodings](#text-encodings)). Until 0.8.0 an HTML file was `text`, tags and
|
|
254
|
+
all, and an XLSX was refused as a ZIP archive.
|
|
255
|
+
|
|
209
256
|
### What is refused
|
|
210
257
|
|
|
211
|
-
`files.ingest` throws an `
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
258
|
+
`files.ingest` throws an [`IngestError`](../reference/library.md#ingesterror) whose message is
|
|
259
|
+
meant for the user, with a `code` for your application. `createDocumentHandlers` answers it with
|
|
260
|
+
HTTP 422 and that message, except a file over `maxUploadBytes`, which the upload route refuses
|
|
261
|
+
before reading it all: HTTP 413, `The file is larger than the 100 MB upload limit.`
|
|
262
|
+
([node reference](../reference/node.md)). For a damaged file the message is the reader's own, from
|
|
263
|
+
pdf.js or jszip, and not written for a user, with the code `"unreadable"`: an application that
|
|
264
|
+
wants friendlier wording maps the codes itself.
|
|
217
265
|
|
|
218
266
|
| What | Message |
|
|
219
267
|
|---|---|
|
|
220
268
|
| An empty file | `report.pdf is empty.` |
|
|
221
269
|
| A file over `maxUploadBytes` (100 MB by default) | `report.pdf is larger than the 100 MB upload limit.` |
|
|
222
270
|
| A gzip file, such as `app.log.gz` | `This file is gzip-compressed. Decompress it, then attach the text file inside.` |
|
|
223
|
-
| A ZIP archive, and the
|
|
224
|
-
|
|
|
271
|
+
| A ZIP archive, and the files other than DOCX, PPTX and XLSX that are ZIPs inside (ODT, ODS) | `This file is a ZIP archive. Extract it, then attach the text file you need.` |
|
|
272
|
+
| A Word, Excel or PowerPoint file of before 2007, an Outlook message, or an Office file with a password | `This is a Word, Excel or PowerPoint file of before 2007 (.doc, .xls, .ppt), an Outlook message (.msg), or an Office file protected by a password and stored that way. None of these can be read: save it as .docx, .xlsx, .pptx, PDF or text, without a password, and attach that.` |
|
|
273
|
+
| Any other binary file: images, audio | `This file looks binary, not text. Attach a text, log, PDF, Word, PowerPoint, Excel or HTML file.` |
|
|
225
274
|
| A file that holds no text once read | `report.docx did not contain any text.` |
|
|
226
|
-
| A DOCX or
|
|
275
|
+
| A DOCX, PPTX or XLSX that unpacks to more than 100 times its size (past the first 16 MB), or to more than 128 MB of XML | `This DOCX unpacks to more than …`, which ends `Save it as text or PDF, and attach that.` |
|
|
227
276
|
| A PDF of more than `maxPdfPages` pages (5,000 by default), before any page is read | `This PDF has 6,200 pages, more than the 5,000 read from one file. Split it, and attach the part you need.` |
|
|
228
277
|
| A PDF whose text passes `maxTextBytes` (100 MB by default, or `maxUploadBytes` when that is larger), counted page by page | `This PDF holds more than 100 MB of text, more than is kept from one file. Split it, and attach the part you need.` |
|
|
229
278
|
| A PDF whose page tree lists one page more than once | `This PDF lists the same page more than once. A file built that way can hold far more text than its size, so it is not read. Print it to a new PDF, and attach that.` |
|
|
@@ -233,7 +282,9 @@ maps these messages itself.
|
|
|
233
282
|
| A PDF with a page whose content is stored with a filter that only images use (JPEG, JPEG 2000, JBIG2, CCITT), or decodes to more than 64 MB through LZW, ASCII85, ASCIIHex or RunLength | `Page 1 of this PDF stores its content in a way that cannot be checked before it is read, so it is not read. Print it to a new PDF, and attach that.` |
|
|
234
283
|
| A DOCX or PPTX of more than 32 million characters of text | `This DOCX holds more than 32 million characters of text, more than is read from one file. Split it, and attach the part you need.` |
|
|
235
284
|
| A DOCX or PPTX whose text passes `maxTextBytes`, when that is below 32 million | `This DOCX holds more than 10 MB of text, more than is kept from one file. Split it, and attach the part you need.` |
|
|
236
|
-
| A DOCX or PPTX of more than 1,000,000 paragraphs with text | `This DOCX has more than 1,000,000 paragraphs, more than a document holds. It may be built to exhaust the server, so it is not read
|
|
285
|
+
| A DOCX or PPTX of more than 1,000,000 paragraphs with text, or of more than 1,000,000 paragraphs and table cells, empty ones included | `This DOCX has more than 1,000,000 paragraphs, more than a document holds. It may be built to exhaust the server, so it is not read.`, or `… paragraphs and table cells, …` |
|
|
286
|
+
| An XLSX of more than 2,097,152 different texts | `This XLSX has more than 2,097,152 different texts, more than a workbook holds. It may be built to exhaust the server, so it is not read.` |
|
|
287
|
+
| An XLSX whose text passes `maxTextBytes`, or 32 million characters | `This XLSX holds more text than is kept from one file. Split it, and attach the part you need.` (`… than is read from one file.` past 32 million characters) |
|
|
237
288
|
| A DOCX or PPTX with paragraphs nested more than 32 deep | `This DOCX nests paragraphs more than 32 deep, which no document does. It may be built to exhaust the server, so it is not read.` |
|
|
238
289
|
| A DOCX or PPTX of more than 20,000 parts, counted the way JSZip will read them, whatever count the file gives | `This DOCX has more than 20,000 parts, more than an Office document has. It may be built to exhaust the server, so it is not read.` |
|
|
239
290
|
| A DOCX or PPTX with more than 80,000 extra fields, or more than 8 MB of names, comments and extra-field data that JSZip would turn into text or go through byte by byte | `This DOCX lists its parts in a way that no Office program does: reading the list would take far more memory or time than an Office document needs. It may be built to exhaust the server, so it is not read.` |
|
|
@@ -241,12 +292,13 @@ maps these messages itself.
|
|
|
241
292
|
| A file of any format whose text, from an extractor of your own or the text extractor, passes `maxTextBytes` | `notes.txt holds more than 100 MB of text, more than is kept from one file. Split it, and attach the part you need.` |
|
|
242
293
|
| A file that takes longer than `ingestTimeoutMs` to read (2 minutes by default) | `report.pdf took too long to read (more than 2 min). Split it, or save it as plain text, and attach that.` |
|
|
243
294
|
| A PDF without text on any page | See [Scanned PDFs](#scanned-pdfs). |
|
|
244
|
-
| A PDF that needs a password to open | `No password given`, the message of pdf.js. |
|
|
295
|
+
| A PDF that needs a password to open | `This PDF is protected by a password, so it cannot be read. Open it, print it to a new PDF without the password, and attach that.` Until 0.8.0, `No password given`, the message of pdf.js. |
|
|
245
296
|
| A damaged PDF | The message of pdf.js, such as `Invalid PDF structure.` |
|
|
246
|
-
| A damaged DOCX or
|
|
297
|
+
| A damaged DOCX, PPTX or XLSX, or one that is not a ZIP | The message of jszip, such as `Can't find end of central directory : is this a zip file ? …` |
|
|
247
298
|
| A DOCX without `word/document.xml` | `This DOCX does not contain word/document.xml.` |
|
|
248
299
|
| A PPTX without slides | `This PPTX does not contain any slides.` |
|
|
249
|
-
|
|
|
300
|
+
| An XLSX without `xl/workbook.xml`, or without sheets | `This XLSX does not contain xl/workbook.xml.`, `This XLSX does not contain any sheets with cells.` |
|
|
301
|
+
| A DOCX, PPTX or XLSX without `jszip` installed | `Reading DOCX, PPTX and XLSX files needs the optional dependency "jszip".` |
|
|
250
302
|
| A PDF without `unpdf` installed | `Reading PDF files needs the optional dependency "unpdf".` |
|
|
251
303
|
| A PDF, with `unpdf` 1.5.0 to 1.6.0 on Node 22 or 23, which would stop the whole process at the first PDF (0.5.0 did stop) | `The unpdf installed would stop the whole server at the first PDF file on Node 22, so PDF files are not read. Install unpdf 1.6.1 or later, or run Node 24 or later.` |
|
|
252
304
|
| The same on Node 20 | `The unpdf installed would stop the whole server at the first PDF file on Node 20, so PDF files are not read. Install unpdf 1.7.0 (npm install unpdf@1.7.0), or run Node 24 or later.` |
|
|
@@ -257,14 +309,14 @@ reaches the user as a 422, a file that cannot be read. Install the dependencies
|
|
|
257
309
|
route runs, in versions that run on its Node ([Formats](#formats)). The messages name the major
|
|
258
310
|
version of Node only.
|
|
259
311
|
|
|
260
|
-
The numbers in the messages are your limits: `maxPdfPages`, `maxTextBytes` and `ingestTimeoutMs`
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
refused past 32 million characters of text even when `maxTextBytes` is larger. The
|
|
265
|
-
of a DOCX or
|
|
266
|
-
the count of parts that the file gives is not used, and the parts are not counted
|
|
267
|
-
([Security](../security.md#uploads)).
|
|
312
|
+
The numbers in the messages are your limits: `maxPdfPages`, `maxTextBytes` and `ingestTimeoutMs` of
|
|
313
|
+
`createLargeFiles` ([`LargeFilesOptions`](../reference/library.md#largefilesoptions)). A size below
|
|
314
|
+
1 MB is given in KB, and below 1 KB in B; a time below a second in ms, below 2 minutes in s, and
|
|
315
|
+
from there in min. An Office message says `PPTX` for a presentation and `XLSX` for a workbook. An
|
|
316
|
+
Office file is refused past 32 million characters of text even when `maxTextBytes` is larger. The
|
|
317
|
+
ZIP directory of a DOCX, PPTX or XLSX is read before JSZip reads it, the way JSZip will read it,
|
|
318
|
+
record by record: the count of parts that the file gives is not used, and the parts are not counted
|
|
319
|
+
past 20,000 ([Security](../security.md#uploads)).
|
|
268
320
|
|
|
269
321
|
What the user can do:
|
|
270
322
|
|
|
@@ -802,14 +854,14 @@ Pass yours in `extractors`, by format. The other formats keep the built-in extra
|
|
|
802
854
|
| `maxTextBytes` | `maxTextBytes` of `createLargeFiles`: the most text kept from one file, in UTF-8 bytes. | Refuse the file as soon as your text passes it, with a message for the user. `ingest` refuses a larger text when you return it, but by then it is all in memory. |
|
|
803
855
|
| `maxPages` | `maxPdfPages` of `createLargeFiles`: the most pages read from one PDF. | In a PDF extractor, refuse a file with more pages before you read them. `ingest` does not check it for you. |
|
|
804
856
|
|
|
805
|
-
The built-in PDF, DOCX and
|
|
806
|
-
OCR example below does, gets them by passing `input` on. The text extractor decodes a valid
|
|
807
|
-
file in one step, and a file in another encoding in steps that stop when `signal` aborts; its
|
|
808
|
-
is checked against `maxTextBytes` when it returns.
|
|
857
|
+
The built-in PDF, DOCX, PPTX and XLSX extractors honour all three, so an extractor that wraps one,
|
|
858
|
+
as the OCR example below does, gets them by passing `input` on. The text extractor decodes a valid
|
|
859
|
+
UTF-8 file in one step, and a file in another encoding in steps that stop when `signal` aborts; its
|
|
860
|
+
text is checked against `maxTextBytes` when it returns.
|
|
809
861
|
|
|
810
|
-
The
|
|
811
|
-
another kind, such as
|
|
812
|
-
the name or the MIME type there ([Other formats](#other-formats)).
|
|
862
|
+
The ten formats are fixed: you can replace the extractor of a format, not add a format. A file of
|
|
863
|
+
another kind, such as XML, RTF or an OpenDocument file, is detected as `text`, so it goes to the
|
|
864
|
+
`text` extractor: check the name or the MIME type there ([Other formats](#other-formats)).
|
|
813
865
|
|
|
814
866
|
What the library does with what you return:
|
|
815
867
|
|
|
@@ -826,7 +878,8 @@ What the library does with what you return:
|
|
|
826
878
|
`toDocumentSummary` ([Text encodings](#text-encodings)).
|
|
827
879
|
- A `text` file whose lines look like a log becomes `log`.
|
|
828
880
|
|
|
829
|
-
An error you throw is the answer to the upload. `
|
|
881
|
+
An error you throw is the answer to the upload. `ingest` throws it as an `IngestError` with the
|
|
882
|
+
same message (and your error as `cause`), and `createDocumentHandlers` answers 422 with its
|
|
830
883
|
message, unless the error has a `status` (or `statusCode`) from 400 to 599: then it answers that
|
|
831
884
|
status, with your message. A status of 413 is answered with the upload-limit message instead of
|
|
832
885
|
yours. An error with a Node system `code` and `syscall` (from `fs` or a socket) is answered 500,
|
|
@@ -932,21 +985,22 @@ background job, and tell the user when the file is ready ([Web app](./web-app.md
|
|
|
932
985
|
|
|
933
986
|
### Other formats
|
|
934
987
|
|
|
935
|
-
A file the library does not know arrives at the `text` extractor.
|
|
936
|
-
|
|
937
|
-
built-in extractor:
|
|
988
|
+
A file the library does not know arrives at the `text` extractor. Since 0.8.0 HTML and XLSX have
|
|
989
|
+
extractors of their own. This one reads OpenDocument text (`.odt`) with a converter of yours, and
|
|
990
|
+
leaves every other file to the built-in extractor:
|
|
938
991
|
|
|
939
992
|
```ts
|
|
940
|
-
import { convert } from "html-to-text";
|
|
941
993
|
import { createLargeFiles, defaultExtractors, FileDocumentStore, type Extractor } from "llm-large-files";
|
|
942
994
|
|
|
995
|
+
// Assumed: odtToText() is your converter of OpenDocument text, with a package or a LibreOffice service.
|
|
996
|
+
declare function odtToText(bytes: Uint8Array, signal?: AbortSignal): Promise<string>;
|
|
997
|
+
|
|
943
998
|
const text: Extractor = async (bytes, input) => {
|
|
999
|
+
// An .odt is a ZIP inside: the built-in extractor would refuse it as a ZIP archive.
|
|
1000
|
+
if (/\.odt$/i.test(input.name)) return { text: await odtToText(bytes, input.signal) };
|
|
944
1001
|
// The built-in extractor decodes UTF-8 and UTF-16, reads Hebrew, Arabic, Cyrillic, Japanese and
|
|
945
1002
|
// Western files in their older encodings, and refuses binary files.
|
|
946
|
-
|
|
947
|
-
const html = /\.html?$/i.test(input.name) || input.mimeType.startsWith("text/html");
|
|
948
|
-
// `...decoded` keeps `encoding` and `replacedCharacters`: the model is told how the file was read.
|
|
949
|
-
return html ? { ...decoded, text: convert(decoded.text, { wordwrap: false }) } : decoded;
|
|
1003
|
+
return defaultExtractors.text(bytes, input);
|
|
950
1004
|
};
|
|
951
1005
|
|
|
952
1006
|
export const files = createLargeFiles({
|
|
@@ -955,8 +1009,7 @@ export const files = createLargeFiles({
|
|
|
955
1009
|
});
|
|
956
1010
|
```
|
|
957
1011
|
|
|
958
|
-
Its format stays `text`.
|
|
959
|
-
extractor, which refuses ZIP files, and write each sheet as lines of text.
|
|
1012
|
+
Its format stays `text`.
|
|
960
1013
|
|
|
961
1014
|
## Your own tool loop
|
|
962
1015
|
|
package/docs/guides/storage.md
CHANGED
|
@@ -579,7 +579,7 @@ export class BlobDocumentStore implements DocumentStore {
|
|
|
579
579
|
async get(id: string): Promise<StoredDocument | undefined> {
|
|
580
580
|
const meta = await this.getMeta(id);
|
|
581
581
|
const bytes = meta && await this.blobs.read(this.key(id, "txt"));
|
|
582
|
-
return meta && bytes ? { meta, text: new TextDecoder().decode(bytes) } : undefined;
|
|
582
|
+
return meta && bytes ? { meta, text: new TextDecoder("utf-8", { ignoreBOM: true }).decode(bytes) } : undefined;
|
|
583
583
|
}
|
|
584
584
|
|
|
585
585
|
/** UTF-8 bytes of the text exactly as `put` wrote it. Called only after getMeta found the document. */
|
package/docs/guides/testing.md
CHANGED
|
@@ -440,7 +440,11 @@ A test that pins the library's exact output breaks when that output changes. The
|
|
|
440
440
|
nothing changed, unless the result is cut to the room it has: the last match then stays, matches
|
|
441
441
|
are dropped from the end of the first ones, and the note is new,
|
|
442
442
|
`Showing 4 of the 10 matching lines to stay within the size limit: the first 3 and the last (line 1000). Narrow the query or read specific lines.`
|
|
443
|
-
where 0.5.0 said `Showing 4 of 10 results to stay within the size limit. …`.
|
|
443
|
+
where 0.5.0 said `Showing 4 of 10 results to stay within the size limit. …`. Since 0.8.0 both
|
|
444
|
+
notes end `To see the ones in between, search again with from_line N, or count them with group_by.`,
|
|
445
|
+
where N is the line after the last of the first ones (below line 15269 in the first note, and
|
|
446
|
+
below line 1000 in the second), and the result has `next_from_line` with that line
|
|
447
|
+
([`search_document`](../reference/tools.md#search_document)).
|
|
444
448
|
- **Steps with a count of one** are singular: ` — 1 matching line`, ` — 1 passage`,
|
|
445
449
|
` — 1 part, 1 relevant`, and `1 more tool call in this turn was not run (at most 8 a turn)`.
|
|
446
450
|
- **A call to a tool that does not exist** has the step `Call “do_magic” — failed: Unknown tool “do_magic”.`,
|
package/docs/guides/web-app.md
CHANGED
|
@@ -203,10 +203,11 @@ A successful upload answers `201` with a `DocumentSummary`:
|
|
|
203
203
|
"expiresAt": "2026-11-22T07:43:14.435Z" }
|
|
204
204
|
```
|
|
205
205
|
|
|
206
|
-
`pages` is there too for a PDF or
|
|
207
|
-
the older encoding it was read in (`"windows-1255"`), and
|
|
208
|
-
characters stored as � ([Text encodings](./pdfs.md#text-encodings)).
|
|
209
|
-
windows-1255", or warn that some characters could not be read and ask
|
|
206
|
+
`pages` is there too for a PDF, a PPTX or an XLSX (its sheets). For a text file that was not valid
|
|
207
|
+
UTF-8, `encoding` names the older encoding it was read in (`"windows-1255"`), and
|
|
208
|
+
`replacedCharacters` counts the characters stored as � ([Text encodings](./pdfs.md#text-encodings)).
|
|
209
|
+
Your page can show "read as windows-1255", or warn that some characters could not be read and ask
|
|
210
|
+
for the file saved as UTF-8.
|
|
210
211
|
|
|
211
212
|
Everything else is JSON `{ "error": "…" }`, with a message you can show: `400` for a missing name or
|
|
212
213
|
a body another middleware already parsed, `413` over `maxUploadBytes`, `422` for a file that cannot
|
|
@@ -253,7 +254,8 @@ input, an [`IngestInput`](../reference/library.md#ingestinput):
|
|
|
253
254
|
Answer the browser with `toDocumentSummary(meta)`, not with `meta`: the summary holds the fields that
|
|
254
255
|
are safe to return to a browser, while `meta` also holds the owner, the outline and the log profile.
|
|
255
256
|
|
|
256
|
-
`ingest` throws a plain `Error
|
|
257
|
+
`ingest` throws an [`IngestError`](../reference/library.md#ingesterror) (a plain `Error` until
|
|
258
|
+
0.8.0), with a message written for the user and a `code`, when it cannot take the file:
|
|
257
259
|
the cases of the `422` above (an empty, binary or compressed file, no text, a missing optional
|
|
258
260
|
dependency, a file past `maxTextBytes` or `maxPdfPages`, one that took longer than
|
|
259
261
|
`ingestTimeoutMs`), and a file larger than `maxUploadBytes` ("app.log is larger than the 100 MB
|
|
@@ -1516,10 +1518,9 @@ GEMINI_API_KEY=... node examples/server.ts # then open http://localhost:3000
|
|
|
1516
1518
|
```
|
|
1517
1519
|
|
|
1518
1520
|
It needs Node 22.18 or a later 22.x, or Node 23.6 or later (24, for example), which run TypeScript
|
|
1519
|
-
files directly. `npm install` also installs the
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
[explorer model](./explorer-model.md).
|
|
1521
|
+
files directly. `npm install` also installs the optional dependencies, which the repository has as
|
|
1522
|
+
dev dependencies, so PDF, DOCX, PPTX and XLSX uploads work. `GEMINI_MODEL` names the model, and
|
|
1523
|
+
`GEMINI_EXPLORER_MODEL`, when set, an [explorer model](./explorer-model.md).
|
|
1523
1524
|
|
|
1524
1525
|
What it does:
|
|
1525
1526
|
|