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.
Files changed (184) hide show
  1. package/CHANGELOG.md +319 -1
  2. package/README.md +10 -8
  3. package/dist/analyze.d.ts +3 -1
  4. package/dist/analyze.d.ts.map +1 -1
  5. package/dist/analyze.js +109 -14
  6. package/dist/analyze.js.map +1 -1
  7. package/dist/anthropic/adapter.d.ts.map +1 -1
  8. package/dist/anthropic/adapter.js +4 -1
  9. package/dist/anthropic/adapter.js.map +1 -1
  10. package/dist/ask.d.ts +3 -3
  11. package/dist/ask.d.ts.map +1 -1
  12. package/dist/ask.js +72 -17
  13. package/dist/ask.js.map +1 -1
  14. package/dist/decode.d.ts +19 -0
  15. package/dist/decode.d.ts.map +1 -0
  16. package/dist/decode.js +97 -0
  17. package/dist/decode.js.map +1 -0
  18. package/dist/errors.d.ts +55 -0
  19. package/dist/errors.d.ts.map +1 -1
  20. package/dist/errors.js +65 -0
  21. package/dist/errors.js.map +1 -1
  22. package/dist/events.d.ts +6 -0
  23. package/dist/events.d.ts.map +1 -1
  24. package/dist/events.js +5 -1
  25. package/dist/events.js.map +1 -1
  26. package/dist/evidence.d.ts.map +1 -1
  27. package/dist/evidence.js +6 -0
  28. package/dist/evidence.js.map +1 -1
  29. package/dist/extract.d.ts +7 -20
  30. package/dist/extract.d.ts.map +1 -1
  31. package/dist/extract.js +49 -751
  32. package/dist/extract.js.map +1 -1
  33. package/dist/gemini/adapter.d.ts.map +1 -1
  34. package/dist/gemini/adapter.js +9 -5
  35. package/dist/gemini/adapter.js.map +1 -1
  36. package/dist/gemini/endpoints.d.ts +5 -1
  37. package/dist/gemini/endpoints.d.ts.map +1 -1
  38. package/dist/gemini/endpoints.js +11 -2
  39. package/dist/gemini/endpoints.js.map +1 -1
  40. package/dist/gemini/generate.d.ts.map +1 -1
  41. package/dist/gemini/generate.js +20 -3
  42. package/dist/gemini/generate.js.map +1 -1
  43. package/dist/groups.d.ts +54 -0
  44. package/dist/groups.d.ts.map +1 -0
  45. package/dist/groups.js +136 -0
  46. package/dist/groups.js.map +1 -0
  47. package/dist/html.d.ts +11 -0
  48. package/dist/html.d.ts.map +1 -0
  49. package/dist/html.js +1112 -0
  50. package/dist/html.js.map +1 -0
  51. package/dist/index.d.ts +2 -1
  52. package/dist/index.d.ts.map +1 -1
  53. package/dist/index.js +1 -1
  54. package/dist/index.js.map +1 -1
  55. package/dist/library.d.ts.map +1 -1
  56. package/dist/library.js +48 -12
  57. package/dist/library.js.map +1 -1
  58. package/dist/limiter.d.ts +2 -1
  59. package/dist/limiter.d.ts.map +1 -1
  60. package/dist/limiter.js +3 -2
  61. package/dist/limiter.js.map +1 -1
  62. package/dist/model.d.ts.map +1 -1
  63. package/dist/model.js +8 -1
  64. package/dist/model.js.map +1 -1
  65. package/dist/node/handlers.d.ts.map +1 -1
  66. package/dist/node/handlers.js +69 -15
  67. package/dist/node/handlers.js.map +1 -1
  68. package/dist/node/index.d.ts +2 -0
  69. package/dist/node/index.d.ts.map +1 -1
  70. package/dist/node/index.js +1 -0
  71. package/dist/node/index.js.map +1 -1
  72. package/dist/node/ingest-child.d.ts +38 -0
  73. package/dist/node/ingest-child.d.ts.map +1 -0
  74. package/dist/node/ingest-child.js +42 -0
  75. package/dist/node/ingest-child.js.map +1 -0
  76. package/dist/node/isolated.d.ts +88 -0
  77. package/dist/node/isolated.d.ts.map +1 -0
  78. package/dist/node/isolated.js +381 -0
  79. package/dist/node/isolated.js.map +1 -0
  80. package/dist/office.d.ts +105 -0
  81. package/dist/office.d.ts.map +1 -0
  82. package/dist/office.js +1092 -0
  83. package/dist/office.js.map +1 -0
  84. package/dist/openai/adapter.d.ts.map +1 -1
  85. package/dist/openai/adapter.js +15 -1
  86. package/dist/openai/adapter.js.map +1 -1
  87. package/dist/pdf-pages.d.ts.map +1 -1
  88. package/dist/pdf-pages.js +2 -6
  89. package/dist/pdf-pages.js.map +1 -1
  90. package/dist/peers.d.ts +8 -0
  91. package/dist/peers.d.ts.map +1 -0
  92. package/dist/peers.js +32 -0
  93. package/dist/peers.js.map +1 -0
  94. package/dist/plan.d.ts.map +1 -1
  95. package/dist/plan.js +1 -1
  96. package/dist/plan.js.map +1 -1
  97. package/dist/ranged.d.ts.map +1 -1
  98. package/dist/ranged.js +4 -2
  99. package/dist/ranged.js.map +1 -1
  100. package/dist/search.d.ts +99 -22
  101. package/dist/search.d.ts.map +1 -1
  102. package/dist/search.js +744 -140
  103. package/dist/search.js.map +1 -1
  104. package/dist/text-index.d.ts +3 -1
  105. package/dist/text-index.d.ts.map +1 -1
  106. package/dist/text-index.js +3 -1
  107. package/dist/text-index.js.map +1 -1
  108. package/dist/text.d.ts +27 -3
  109. package/dist/text.d.ts.map +1 -1
  110. package/dist/text.js +225 -23
  111. package/dist/text.js.map +1 -1
  112. package/dist/tools.d.ts.map +1 -1
  113. package/dist/tools.js +200 -12
  114. package/dist/tools.js.map +1 -1
  115. package/dist/types.d.ts +3 -3
  116. package/dist/types.d.ts.map +1 -1
  117. package/dist/word-styles.d.ts +102 -0
  118. package/dist/word-styles.d.ts.map +1 -0
  119. package/dist/word-styles.js +419 -0
  120. package/dist/word-styles.js.map +1 -0
  121. package/dist/xlsx.d.ts +23 -0
  122. package/dist/xlsx.d.ts.map +1 -0
  123. package/dist/xlsx.js +511 -0
  124. package/dist/xlsx.js.map +1 -0
  125. package/dist/xml-stream.d.ts +55 -0
  126. package/dist/xml-stream.d.ts.map +1 -0
  127. package/dist/xml-stream.js +235 -0
  128. package/dist/xml-stream.js.map +1 -0
  129. package/docs/README.md +8 -8
  130. package/docs/getting-started.md +1 -1
  131. package/docs/guides/costs-and-limits.md +7 -5
  132. package/docs/guides/deployment.md +95 -29
  133. package/docs/guides/errors-and-reliability.md +23 -10
  134. package/docs/guides/pdfs.md +127 -74
  135. package/docs/guides/storage.md +1 -1
  136. package/docs/guides/testing.md +5 -1
  137. package/docs/guides/web-app.md +10 -9
  138. package/docs/how-it-works.md +73 -50
  139. package/docs/reference/ask.md +26 -8
  140. package/docs/reference/errors-and-retries.md +5 -3
  141. package/docs/reference/events.md +14 -6
  142. package/docs/reference/gemini.md +6 -2
  143. package/docs/reference/library.md +205 -74
  144. package/docs/reference/node.md +200 -22
  145. package/docs/reference/openai.md +1 -1
  146. package/docs/reference/tools.md +170 -22
  147. package/docs/security.md +114 -69
  148. package/docs/troubleshooting.md +40 -20
  149. package/package.json +6 -2
  150. package/src/analyze.ts +117 -13
  151. package/src/anthropic/adapter.ts +4 -1
  152. package/src/ask.ts +73 -17
  153. package/src/decode.ts +89 -0
  154. package/src/errors.ts +108 -0
  155. package/src/events.ts +10 -1
  156. package/src/evidence.ts +6 -0
  157. package/src/extract.ts +52 -709
  158. package/src/gemini/adapter.ts +9 -5
  159. package/src/gemini/endpoints.ts +12 -2
  160. package/src/gemini/generate.ts +19 -3
  161. package/src/groups.ts +162 -0
  162. package/src/html.ts +1071 -0
  163. package/src/index.ts +2 -1
  164. package/src/library.ts +43 -12
  165. package/src/limiter.ts +6 -1
  166. package/src/model.ts +8 -1
  167. package/src/node/handlers.ts +66 -16
  168. package/src/node/index.ts +2 -0
  169. package/src/node/ingest-child.ts +61 -0
  170. package/src/node/isolated.ts +464 -0
  171. package/src/office.ts +1047 -0
  172. package/src/openai/adapter.ts +14 -1
  173. package/src/pdf-pages.ts +2 -5
  174. package/src/peers.ts +29 -0
  175. package/src/plan.ts +2 -0
  176. package/src/ranged.ts +4 -2
  177. package/src/search.ts +738 -146
  178. package/src/text-index.ts +4 -2
  179. package/src/text.ts +214 -23
  180. package/src/tools.ts +192 -12
  181. package/src/types.ts +3 -3
  182. package/src/word-styles.ts +420 -0
  183. package/src/xlsx.ts +478 -0
  184. package/src/xml-stream.ts +224 -0
@@ -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 on
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 PPTX
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, footers, footnotes and headers, in that order. 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`, 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. HTML, XML, YAML and
51
- source code are `text`. The MIME type is compared whole: `application/json; charset=utf-8` is not
52
- JSON. Send the bare type (or `X-File-Type: application/json` to the upload route of
53
- `createDocumentHandlers`, which takes it before `Content-Type`).
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
- zero-width spaces, word joiners, a soft hyphen inside a line, and the text-direction controls that
59
- reorder what a person sees. Those that scripts and emoji need are kept: the marks of right-to-left
60
- text (U+200E, U+200F, U+061C), the joiners of emoji and Persian, variation selectors, Hangul
61
- fillers, and the line and paragraph separators (U+2028, U+2029). A crafted file can still carry
62
- text that a person does not see in them ([Security](../security.md#characters-that-show-nothing)
63
- lists them all). In a text with no other line break, such as a mainframe file converted to UTF-8,
64
- U+0085 (next line) ends a line, except right after a character from U+0080 to U+00FF, where it is
65
- taken for half of a UTF-8 letter and removed; anywhere else it is removed with the other control
66
- characters. That is text in UTF-8: the same export converted to ISO-8859-1 is read as
67
- windows-1252, where its byte 0x85 is "…", and stays one long line, so convert it to UTF-8
68
- instead. No other line break is added or removed, but a line of more than 2,000 characters
69
- that lost some of these characters can be split into fewer pieces than 0.5.0 split it, which
70
- moves the lines after it. Every format but log, JSON and CSV gets an outline from its
71
- headings: Markdown `#` lines (`## Slide N` among them), chapter and numbered section lines, and
72
- short lines in capitals. `meta.pages` is the number of pages of a PDF and of slides of a PPTX.
73
- [How it works](../how-it-works.md) follows ingest from there.
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 table comes out one cell per line, and an empty cell leaves no line at all, so a row with an
187
- empty cell reads like a shorter row. PDF tables are rebuilt with their empty cells
188
- ([PDF tables](#pdf-tables)): if those matter, the PDF of the same document reads better.
189
- - Comments and speaker notes are not read.
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="&#48;"`), and parts that nothing in the file refers to (an orphan
202
- header or slide). Of `mc:AlternateContent`, the `mc:Choice` is read, where Word may show the
203
- `mc:Fallback`. And a document's own text can write the mark. A `w:val` written as a character
204
- reference does the opposite: `<w:vanish w:val="&#48;"/>`, which Word reads as 0, marks text that
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="&#48;"/>`, 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&amp;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 `Error` whose message is meant for the user. `createDocumentHandlers`
212
- answers it with HTTP 422 and that message, except a file over `maxUploadBytes`, which the upload
213
- route refuses before reading it all: HTTP 413, `The file is larger than the 100 MB upload limit.`
214
- ([node reference](../reference/node.md)). For a damaged or locked file the message is the reader's
215
- own, from pdf.js or jszip, and not written for a user: an application that wants friendlier wording
216
- maps these messages itself.
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 Office files other than DOCX and PPTX that are ZIPs inside (XLSX, for example) | `This file is a ZIP archive. Extract it, then attach the text file you need.` |
224
- | Any other binary file: images, legacy `.doc` and `.xls` | `This file looks binary, not text. Attach a text, log, PDF, DOCX, or PPTX file.` |
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 PPTX 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.` |
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 PPTX, 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 ? …` |
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
- | A DOCX or PPTX without `jszip` installed | `Reading DOCX and PPTX files needs the optional dependency "jszip".` |
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
- of `createLargeFiles` ([`LargeFilesOptions`](../reference/library.md#largefilesoptions)). A size
262
- below 1 MB is given in KB, and below 1 KB in B; a time below a second in ms, below 2 minutes in s,
263
- and from there in min. An Office message says `PPTX` for a presentation. An Office file is
264
- refused past 32 million characters of text even when `maxTextBytes` is larger. The ZIP directory
265
- of a DOCX or PPTX is read before JSZip reads it, the way JSZip will read it, record by record:
266
- the count of parts that the file gives is not used, and the parts are not counted past 20,000
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 PPTX extractors honour all three, so an extractor that wraps one, as the
806
- OCR example below does, gets them by passing `input` on. The text extractor decodes a valid UTF-8
807
- file in one step, and a file in another encoding in steps that stop when `signal` aborts; its text
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 eight formats are fixed: you can replace the extractor of a format, not add a format. A file of
811
- another kind, such as HTML or XLSX, is detected as `text`, so it goes to the `text` extractor: check
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. `createDocumentHandlers` answers 422 with its
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. This one converts HTML to text,
936
- with the `html-to-text` package here (any converter works), and leaves every other file to the
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
- const decoded = await defaultExtractors.text(bytes, input);
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`. To read XLSX, test for its name the same way, before the built-in
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
 
@@ -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. */
@@ -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”.`,
@@ -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 a PPTX. For a text file that was not valid UTF-8, `encoding` names
207
- the older encoding it was read in (`"windows-1255"`), and `replacedCharacters` counts the
208
- characters stored as � ([Text encodings](./pdfs.md#text-encodings)). Your page can show "read as
209
- windows-1255", or warn that some characters could not be read and ask for the file saved as UTF-8.
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`, with a message written for the user, when it cannot take the file:
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
- optional dependencies, which the repository has as dev dependencies, so PDF, DOCX and PPTX uploads
1521
- work. `GEMINI_MODEL` names the model, and `GEMINI_EXPLORER_MODEL`, when set, an
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