llm-large-files 0.7.0 → 0.8.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.
Files changed (196) hide show
  1. package/CHANGELOG.md +370 -1
  2. package/README.md +12 -8
  3. package/dist/aggregate.d.ts +103 -0
  4. package/dist/aggregate.d.ts.map +1 -0
  5. package/dist/aggregate.js +651 -0
  6. package/dist/aggregate.js.map +1 -0
  7. package/dist/analyze.d.ts +3 -1
  8. package/dist/analyze.d.ts.map +1 -1
  9. package/dist/analyze.js +109 -14
  10. package/dist/analyze.js.map +1 -1
  11. package/dist/anthropic/adapter.d.ts.map +1 -1
  12. package/dist/anthropic/adapter.js +4 -1
  13. package/dist/anthropic/adapter.js.map +1 -1
  14. package/dist/ask.d.ts +3 -3
  15. package/dist/ask.d.ts.map +1 -1
  16. package/dist/ask.js +72 -17
  17. package/dist/ask.js.map +1 -1
  18. package/dist/decode.d.ts +19 -0
  19. package/dist/decode.d.ts.map +1 -0
  20. package/dist/decode.js +97 -0
  21. package/dist/decode.js.map +1 -0
  22. package/dist/errors.d.ts +55 -0
  23. package/dist/errors.d.ts.map +1 -1
  24. package/dist/errors.js +65 -0
  25. package/dist/errors.js.map +1 -1
  26. package/dist/events.d.ts +6 -0
  27. package/dist/events.d.ts.map +1 -1
  28. package/dist/events.js +5 -1
  29. package/dist/events.js.map +1 -1
  30. package/dist/evidence.d.ts.map +1 -1
  31. package/dist/evidence.js +23 -0
  32. package/dist/evidence.js.map +1 -1
  33. package/dist/extract.d.ts +12 -18
  34. package/dist/extract.d.ts.map +1 -1
  35. package/dist/extract.js +82 -746
  36. package/dist/extract.js.map +1 -1
  37. package/dist/gemini/adapter.d.ts.map +1 -1
  38. package/dist/gemini/adapter.js +9 -5
  39. package/dist/gemini/adapter.js.map +1 -1
  40. package/dist/gemini/endpoints.d.ts +5 -1
  41. package/dist/gemini/endpoints.d.ts.map +1 -1
  42. package/dist/gemini/endpoints.js +11 -2
  43. package/dist/gemini/endpoints.js.map +1 -1
  44. package/dist/gemini/generate.d.ts.map +1 -1
  45. package/dist/gemini/generate.js +20 -3
  46. package/dist/gemini/generate.js.map +1 -1
  47. package/dist/groups.d.ts +54 -0
  48. package/dist/groups.d.ts.map +1 -0
  49. package/dist/groups.js +136 -0
  50. package/dist/groups.js.map +1 -0
  51. package/dist/html.d.ts +11 -0
  52. package/dist/html.d.ts.map +1 -0
  53. package/dist/html.js +1112 -0
  54. package/dist/html.js.map +1 -0
  55. package/dist/index.d.ts +2 -1
  56. package/dist/index.d.ts.map +1 -1
  57. package/dist/index.js +1 -1
  58. package/dist/index.js.map +1 -1
  59. package/dist/library.d.ts.map +1 -1
  60. package/dist/library.js +57 -14
  61. package/dist/library.js.map +1 -1
  62. package/dist/limiter.d.ts +2 -1
  63. package/dist/limiter.d.ts.map +1 -1
  64. package/dist/limiter.js +3 -2
  65. package/dist/limiter.js.map +1 -1
  66. package/dist/model.d.ts.map +1 -1
  67. package/dist/model.js +8 -1
  68. package/dist/model.js.map +1 -1
  69. package/dist/node/handlers.d.ts.map +1 -1
  70. package/dist/node/handlers.js +69 -15
  71. package/dist/node/handlers.js.map +1 -1
  72. package/dist/node/index.d.ts +2 -0
  73. package/dist/node/index.d.ts.map +1 -1
  74. package/dist/node/index.js +1 -0
  75. package/dist/node/index.js.map +1 -1
  76. package/dist/node/ingest-child.d.ts +38 -0
  77. package/dist/node/ingest-child.d.ts.map +1 -0
  78. package/dist/node/ingest-child.js +42 -0
  79. package/dist/node/ingest-child.js.map +1 -0
  80. package/dist/node/isolated.d.ts +88 -0
  81. package/dist/node/isolated.d.ts.map +1 -0
  82. package/dist/node/isolated.js +381 -0
  83. package/dist/node/isolated.js.map +1 -0
  84. package/dist/office.d.ts +105 -0
  85. package/dist/office.d.ts.map +1 -0
  86. package/dist/office.js +1092 -0
  87. package/dist/office.js.map +1 -0
  88. package/dist/openai/adapter.d.ts.map +1 -1
  89. package/dist/openai/adapter.js +15 -1
  90. package/dist/openai/adapter.js.map +1 -1
  91. package/dist/pdf-pages.d.ts.map +1 -1
  92. package/dist/pdf-pages.js +2 -6
  93. package/dist/pdf-pages.js.map +1 -1
  94. package/dist/peers.d.ts +8 -0
  95. package/dist/peers.d.ts.map +1 -0
  96. package/dist/peers.js +32 -0
  97. package/dist/peers.js.map +1 -0
  98. package/dist/plan.d.ts +3 -1
  99. package/dist/plan.d.ts.map +1 -1
  100. package/dist/plan.js +17 -1
  101. package/dist/plan.js.map +1 -1
  102. package/dist/quality.d.ts +16 -0
  103. package/dist/quality.d.ts.map +1 -0
  104. package/dist/quality.js +157 -0
  105. package/dist/quality.js.map +1 -0
  106. package/dist/ranged.d.ts.map +1 -1
  107. package/dist/ranged.js +4 -2
  108. package/dist/ranged.js.map +1 -1
  109. package/dist/search.d.ts +99 -22
  110. package/dist/search.d.ts.map +1 -1
  111. package/dist/search.js +744 -140
  112. package/dist/search.js.map +1 -1
  113. package/dist/text-index.d.ts +3 -1
  114. package/dist/text-index.d.ts.map +1 -1
  115. package/dist/text-index.js +3 -1
  116. package/dist/text-index.js.map +1 -1
  117. package/dist/text.d.ts +27 -3
  118. package/dist/text.d.ts.map +1 -1
  119. package/dist/text.js +225 -23
  120. package/dist/text.js.map +1 -1
  121. package/dist/tools.d.ts +9 -0
  122. package/dist/tools.d.ts.map +1 -1
  123. package/dist/tools.js +457 -16
  124. package/dist/tools.js.map +1 -1
  125. package/dist/types.d.ts +23 -3
  126. package/dist/types.d.ts.map +1 -1
  127. package/dist/word-styles.d.ts +102 -0
  128. package/dist/word-styles.d.ts.map +1 -0
  129. package/dist/word-styles.js +419 -0
  130. package/dist/word-styles.js.map +1 -0
  131. package/dist/xlsx.d.ts +23 -0
  132. package/dist/xlsx.d.ts.map +1 -0
  133. package/dist/xlsx.js +511 -0
  134. package/dist/xlsx.js.map +1 -0
  135. package/dist/xml-stream.d.ts +55 -0
  136. package/dist/xml-stream.d.ts.map +1 -0
  137. package/dist/xml-stream.js +235 -0
  138. package/dist/xml-stream.js.map +1 -0
  139. package/docs/README.md +8 -8
  140. package/docs/getting-started.md +1 -1
  141. package/docs/guides/costs-and-limits.md +7 -5
  142. package/docs/guides/deployment.md +95 -29
  143. package/docs/guides/errors-and-reliability.md +23 -10
  144. package/docs/guides/pdfs.md +127 -74
  145. package/docs/guides/storage.md +1 -1
  146. package/docs/guides/testing.md +5 -1
  147. package/docs/guides/web-app.md +10 -9
  148. package/docs/how-it-works.md +80 -50
  149. package/docs/reference/ask.md +26 -8
  150. package/docs/reference/errors-and-retries.md +5 -3
  151. package/docs/reference/events.md +14 -6
  152. package/docs/reference/gemini.md +6 -2
  153. package/docs/reference/library.md +221 -79
  154. package/docs/reference/node.md +201 -23
  155. package/docs/reference/openai.md +1 -1
  156. package/docs/reference/tools.md +269 -23
  157. package/docs/security.md +114 -69
  158. package/docs/troubleshooting.md +40 -20
  159. package/package.json +6 -2
  160. package/src/aggregate.ts +674 -0
  161. package/src/analyze.ts +117 -13
  162. package/src/anthropic/adapter.ts +4 -1
  163. package/src/ask.ts +73 -17
  164. package/src/decode.ts +89 -0
  165. package/src/errors.ts +108 -0
  166. package/src/events.ts +10 -1
  167. package/src/evidence.ts +23 -0
  168. package/src/extract.ts +79 -701
  169. package/src/gemini/adapter.ts +9 -5
  170. package/src/gemini/endpoints.ts +12 -2
  171. package/src/gemini/generate.ts +19 -3
  172. package/src/groups.ts +162 -0
  173. package/src/html.ts +1071 -0
  174. package/src/index.ts +2 -1
  175. package/src/library.ts +52 -14
  176. package/src/limiter.ts +6 -1
  177. package/src/model.ts +8 -1
  178. package/src/node/handlers.ts +66 -16
  179. package/src/node/index.ts +2 -0
  180. package/src/node/ingest-child.ts +61 -0
  181. package/src/node/isolated.ts +464 -0
  182. package/src/office.ts +1047 -0
  183. package/src/openai/adapter.ts +14 -1
  184. package/src/pdf-pages.ts +2 -5
  185. package/src/peers.ts +29 -0
  186. package/src/plan.ts +19 -1
  187. package/src/quality.ts +146 -0
  188. package/src/ranged.ts +4 -2
  189. package/src/search.ts +738 -146
  190. package/src/text-index.ts +4 -2
  191. package/src/text.ts +214 -23
  192. package/src/tools.ts +440 -16
  193. package/src/types.ts +20 -3
  194. package/src/word-styles.ts +420 -0
  195. package/src/xlsx.ts +478 -0
  196. package/src/xml-stream.ts +224 -0
package/CHANGELOG.md CHANGED
@@ -36,6 +36,375 @@ Grouped by area. One or two lines each, written for an app developer, with the n
36
36
  matter.
37
37
  -->
38
38
 
39
+ ## 0.8.1 — 2026-11-23
40
+
41
+ Exact numbers from tables. `aggregate_table` counts, sums, averages and groups the rows of a CSV
42
+ file, a sheet of a workbook or a `| cell |` table of any document, reading every row, with no code
43
+ run; it finds headers of several rows and a title above them. Search hits say which section and
44
+ which table header they belong to. A file whose name says nothing is known by its bytes, and the
45
+ card says which PDF pages have no text or a garbled one. Checked live with the Gemini API on
46
+ `gemini-3.5-flash-lite` and `gemini-3.8-flash`: a sum and a count by region of a workbook, averages
47
+ per region, refunded orders of a CSV with a title row, and a row found by search named by its
48
+ header; all eight answers right, the counts with one `aggregate_table` call.
49
+
50
+ ### Upgrading: what you need to change
51
+
52
+ Code written for 0.8.0 compiles with 0.8.1 as it is: every change to the public types is an
53
+ addition (`TOOL_NAMES.aggregate`, optional fields of `DocumentMeta`, an optional third parameter of
54
+ `detectFormat`). A `Record` of your own keyed by the tool names needs the new one.
55
+
56
+ - **A new tool, `aggregate_table`, is offered with CSV, XLSX, DOCX, PPTX, PDF, HTML and Markdown
57
+ documents**, with one more line in the tool guide. The tool set and the guide the model is sent
58
+ change for those documents, so the provider's prompt cache misses once.
59
+ **What to do:** nothing. A loop of your own that runs `files.tools()` gets it too.
60
+ - **Search results have two more fields:** `section` on a match in a document with an outline, and
61
+ `table_headers` on a result whose matches are rows of a table. Tests that compare whole results
62
+ need them.
63
+ **What to do:** nothing, unless your tests compare search results whole.
64
+
65
+ ### New: what you can add
66
+
67
+ - **`aggregate_table`** (see [`aggregate_table`](docs/reference/tools.md#aggregate_table)): `metrics`
68
+ (`count`, `sum:Column`, `avg:`, `min:`, `max:`, `count_distinct:`), `group_by` (up to 3 columns,
69
+ a date column by `:year`, `:month` or `:day`), `filters` (`=`, `!=`, `>`, `>=`, `<`, `<=`,
70
+ `contains`, `not_contains`, `starts_with`, `empty`, `not_empty`), `order_by`, `limit`, `table` (a
71
+ sheet's name or number, a table's number) and `header_rows`. Numbers are read as people write
72
+ them ("1,234.5", "(1,200)", "₪4,750", "12,5"); cells that are not numbers are counted apart. A
73
+ header of two or three rows is joined ("Q1 / January"), a title row above it is left out, and a
74
+ header repeated inside the table is not a row. Each group cites the lines of its first rows.
75
+ - **`DocumentMeta.pagesWithoutText`, `garbledPages` and `scripts`**, worked out at ingest and shown
76
+ on the card: the PDF pages with no text (scans, photos) and those whose text looks garbled, with
77
+ a pointer to `view_pages` when they can be looked at, and the scripts of a text that is not in
78
+ Latin letters alone ("Written in: Hebrew 81%, Latin 19%").
79
+ - **`detectFormat(name, mimeType, bytes?)`** and `ingest`: a file whose name and type give no format
80
+ is known by its bytes (a PDF header, the parts of a DOCX, PPTX or XLSX, a first `<html>`). A file
81
+ named `.txt` stays text.
82
+
83
+ ### Changed: what works differently
84
+
85
+ - **Search hits say where they sit** (F15): `section` is the heading above a match ("2.1 Rent",
86
+ "Sheet 2: Sales"); `table_headers` gives the first row of each table a match is in (line 1 of a
87
+ CSV file, a sheet's first row, a `| cell |` table's first row), so a hit like `Row 812: | 4,200 |`
88
+ is understood without another read.
89
+
90
+ ## 0.8.0 — 2026-11-23
91
+
92
+ Files from an enterprise, read with their structure, and counted exactly. Word files keep their
93
+ headings, clause numbers and tables; PowerPoint decks their order, tables and speaker notes; Excel
94
+ workbooks and HTML pages are read for the first time. Search works in every script (Hebrew with
95
+ its prefix letters, Hindi, Thai, Chinese, text composed or decomposed), can search part of a file,
96
+ show the last matches, and count matching lines per hour, per code or per message shape in one
97
+ call. Untrusted PDF and Office files can be read in child processes with a memory limit and a kill
98
+ timer, and every refusal says why with a code. 0.7.1 was never published: its fifteen fixes ship
99
+ here, and its points are part of this entry. Checked live with the Gemini API on
100
+ `gemini-3.5-flash-lite` and `gemini-3.8-flash`: hourly counts and the last line of a log in one
101
+ search, a clause of a Hebrew lease answered in Hebrew, a row of a workbook, a table of an HTML page.
102
+
103
+ ### Upgrading: what you need to change
104
+
105
+ Code written for 0.7.0 compiles with 0.8.0, with one exception: `DocumentFormat` has two new
106
+ members, `"xlsx"` and `"html"`. An exhaustive `switch` on a document's format, or a
107
+ `Record<DocumentFormat, …>` of your own, needs the two cases. Every other change to the public
108
+ types is an addition: `IngestError`, `ingestErrorCodeOf` and the type `IngestErrorCode` in
109
+ `llm-large-files`; `createIsolatedExtractors` and the types `IsolatedExtractorOptions` and
110
+ `IsolatedExtractors` in `llm-large-files/node`; an optional `code` in `EventError`.
111
+
112
+ Some behavior is different. Check each point against your app:
113
+
114
+ - **Excel and HTML files are read.** An `.xlsx` (and `.xlsm`) upload was refused with "This file is
115
+ a ZIP archive"; it is now a document of format `"xlsx"`. An `.html` or `.htm` file was read as
116
+ text, tags and all, with format `"text"`; it is now format `"html"`, with the text a browser
117
+ shows. Both need nothing new: XLSX uses the optional `jszip`, as DOCX does.
118
+ **What to do:** if your app lists the formats it accepts, add them. See
119
+ [formats](docs/reference/library.md#documentformat).
120
+ - **Word and PowerPoint files are read with their structure.** A DOCX heading is written as a
121
+ Markdown heading, a numbered paragraph with its number (`## 2.1 Rent`, `(a) the flat`), a table
122
+ as rows of `| cell | cell | |` with its empty cells, and the footnotes, endnotes, comments,
123
+ headers and footers each under a heading of its own (a repeated header once). A PPTX is numbered
124
+ in the order of its slide show, with its tables and its speaker notes. Documents ingested by
125
+ 0.7.0 keep the text they have until they are uploaded again.
126
+ **What to do:** nothing, unless your tests compare the text of a DOCX or PPTX: update them.
127
+ - **`ingest` throws `IngestError` for a file it cannot read.** It is an `Error` with the same
128
+ message as before, a `code` (`"too_large"`, `"no_text"`, `"hostile"`…), the HTTP `status` the
129
+ upload handler answers with, and the extractor's error as `cause`. A store that failed, a caller
130
+ that gave up, a listener that threw and a system error from an extractor of your own are thrown
131
+ as before. `ingest.error` events carry the `code`, and name `"IngestError"` where they named
132
+ `"Error"`.
133
+ **What to do:** nothing; to tell users in your own words (another language), map `error.code`.
134
+ A test that expects `name: "Error"` in an `ingest.error` event needs `"IngestError"`.
135
+ - **The answer is asked for in the language of the question.** The three closing requests
136
+ (`FINAL_ANSWER_REQUEST`, `FINAL_ANSWER_AFTER_PAGES`, `FINAL_ANSWER_WITHOUT_TOOLS`) end with
137
+ "Answer in the language of my question." A model asked in Hebrew answered in English after an
138
+ English closing request.
139
+ **What to do:** nothing; to have answers in one language whatever the question, say so in
140
+ `system`.
141
+ - **The text the model is sent changed:** the description of `search_document` (its new
142
+ arguments), the tool guide (two lines: counts by group and paging; searching the bare form of a
143
+ word), and the closing requests. The provider's prompt cache misses once after the upgrade.
144
+ **What to do:** nothing. See **Changed** for what models now do.
145
+ - **Text is composed (NFC) at ingest.** "e" followed by a combining accent becomes "é". Line counts
146
+ do not change; `characters` and the sizes of such a text can be a little smaller. A run of more
147
+ than 30 marks on one letter, which no script writes, gets an invisible combining grapheme joiner
148
+ (U+034F) after each 30, as Unicode's stream-safe form does: composing such a run took time by its
149
+ square, and 600 KB of them held the server 80 seconds.
150
+ **What to do:** nothing.
151
+ - **More files are taken for logs.** A `.txt` of nginx or Apache access lines, JSON log lines,
152
+ klog or logfmt is now format `"log"`, with a log profile; levels in lower case, in brackets,
153
+ after `level=`, in a JSON field or as pino numbers are counted.
154
+ **What to do:** nothing, unless your app switches on `format === "text"` for such files.
155
+ - **From 0.7.1** (never published), some values that were taken in silence and did not work are
156
+ refused:
157
+
158
+ - **NaN in a number option of `createLargeFiles` throws.** `ttlMs`, `maxUploadBytes`,
159
+ `scannedPdfPages`, `cacheBytes`, `cacheSize`, `wholeDocumentBytes`, `scanChunkBytes` and
160
+ `maxConcurrentScans` throw a `RangeError` for NaN (what `Number(process.env.X)` gives for a
161
+ variable that is not set), and a `TypeError` for a value that is not a number, such as a string
162
+ read from the environment. `scanChunkBytes: Infinity` throws too. With NaN, `maxConcurrentScans`
163
+ made every search of a document read by range wait forever, `ttlMs` failed every upload with
164
+ "Invalid time value", and `maxUploadBytes` took off the upload limit.
165
+ **What to do:** nothing, unless you pass such values. Leave an option out for its default, or
166
+ read a variable with a fallback: `Number(process.env.SCANS ?? 4)`.
167
+ - **NaN in `AskOptions.limits` throws, before any request.** A field of `limits` that is NaN throws
168
+ a `RangeError` ("limits.toolTurns must be a number, and is NaN. Leave it out for the default."),
169
+ and one that is not a number a `TypeError`. NaN used to give a question with no tool, refuse
170
+ every call, or take off the cap on whole-file reads and the ceilings on tokens and requests.
171
+ `ToolOptions.maxWholeDocumentReads` is checked the same way. `Infinity` still means no ceiling.
172
+ **What to do:** as above.
173
+ - **`partialResultOf(error)` gives `undefined` for an error that several questions threw.** Questions
174
+ stopped by one shared signal all throw its one reason (`AbortSignal.any` passes it on as it is).
175
+ `partialResultOf` gave each the result of whichever failed last: another user's tool rounds and
176
+ usage. Now it gives none, and each question's `run.error` event still carries its own `partial`.
177
+ **What to do:** if you stop many questions with one signal and keep their partial results, give
178
+ each question an `AbortController` of its own that the shared signal aborts with a new reason.
179
+ See [`partialResultOf`](docs/reference/ask.md#partialresultoferror).
180
+ - **`vertexAi()` and `vertexHost()` check `location`.** One that is not lowercase letters and digits
181
+ joined by single hyphens (`"global"`, `"us"`, `"europe-west4"`) throws a `TypeError`. With `/`,
182
+ `?`, `#` or `@`, it named another host, which got the access token.
183
+ **What to do:** nothing, unless a location comes from a user; then expect the `TypeError`.
184
+ - **An upload answered before its body was read drains the rest, up to 8 MB.** The `413` of an
185
+ upload over `maxUploadBytes` (and every answer sent before the body was read to its end) is
186
+ written at once, and ends once the rest of the body has been read and dropped. A body that goes
187
+ on more than 8 MB past the limit is cut off by closing the connection.
188
+ **What to do:** nothing. See [`node`](docs/reference/node.md).
189
+ - **An adapter of your own whose `capabilities` lack `pageTokens` or `toolFiles`.** A `pageTokens`
190
+ that is missing, NaN or negative counts as 1,000, and a `toolFiles` that is none of `"inside"`,
191
+ `"beside"` and `"none"` counts as `"none"`, so `view_pages` is not offered to that model. Both
192
+ fields are required by the type, so this concerns only an adapter written in JavaScript or cast.
193
+ **What to do:** declare both.
194
+
195
+ ### New: what you can add
196
+
197
+ - **`createIsolatedExtractors(options?)`** in `llm-large-files/node`: PDF, DOCX, PPTX and XLSX files
198
+ read in child processes, each with a heap flag (`maxHeapMb`, 512), a kill timer (120 s), at most
199
+ `concurrency` (2) at once and `maxQueue` (8) waiting. A file that exhausts its child's memory is
200
+ refused (`"out_of_memory"`) and the server goes on; a full queue refuses at once (`"busy"`), and
201
+ the upload handler answers that with 503 and `Retry-After`. Children are replaced after 50 files
202
+ and stopped when idle. A reader that cannot start (a missing `childScript`, an `execArgv` Node
203
+ does not know) is the server's trouble: an `Error` with `status` 500, not an `IngestError`; one
204
+ that cannot be started for want of process slots is `"busy"`. For a server that bundles its code,
205
+ `llm-large-files/node/ingest-child.js` is exported, and `childScript` takes a path or a file
206
+ URL. See [isolated ingest](docs/reference/node.md#createisolatedextractorsoptions).
207
+
208
+ ```ts
209
+ import { createLargeFiles, FileDocumentStore } from "llm-large-files";
210
+ import { createIsolatedExtractors } from "llm-large-files/node";
211
+
212
+ const isolated = createIsolatedExtractors({ maxHeapMb: 512, concurrency: 2 });
213
+ const files = createLargeFiles({ store: new FileDocumentStore("./data"), extractors: isolated.extractors });
214
+ // A SIGTERM listener replaces Node's own exit: stop your HTTP server there too, or it goes on serving.
215
+ process.once("SIGTERM", () => {
216
+ server.close();
217
+ void isolated.close();
218
+ });
219
+ ```
220
+
221
+ - **`IngestError`**, with `code`, `status` and, for `"busy"`, `retryAfterMs`; and
222
+ `ingestErrorCodeOf(message)`. The codes: `empty`, `too_large`, `too_much_text`,
223
+ `too_many_pages`, `not_text`, `compressed`, `legacy_office`, `encrypted`, `no_text`, `hostile`,
224
+ `timeout`, `out_of_memory`, `busy`, `missing_dependency`, `unreadable`. See
225
+ [`IngestError`](docs/reference/library.md#ingesterror).
226
+
227
+ ```ts
228
+ import { IngestError, type IngestErrorCode } from "llm-large-files";
229
+
230
+ // Your own words for some refusals; the library's message for the rest.
231
+ const hebrew: Partial<Record<IngestErrorCode, string>> = {
232
+ too_large: "הקובץ גדול מדי.",
233
+ no_text: "אין בקובץ טקסט לקריאה (ייתכן שהוא סרוק).",
234
+ busy: "השרת עסוק. נסו שוב בעוד רגע.",
235
+ };
236
+
237
+ try {
238
+ await files.ingest({ name, bytes, owner });
239
+ } catch (error) {
240
+ if (!(error instanceof IngestError)) throw error; // the store, or your own code
241
+ console.log(error.status, hebrew[error.code] ?? error.message);
242
+ }
243
+ ```
244
+
245
+ - **`search_document` arguments** (see [`search_document`](docs/reference/tools.md#search_document)):
246
+ - `from_line` and `to_line`: search part of a file, in every mode; the result says
247
+ `searched_lines`.
248
+ - `next_from_line` in a result of exact or regex search that shows the first matches of more:
249
+ search again from it for the ones after.
250
+ - `order: "last"`: the last `max_results` matching lines, in file order.
251
+ - `group_by`: count the matching lines by group and show none: `"capture"` (the regex's first
252
+ group), `"minute"`, `"hour"`, `"day"` (the timestamp of the line: ISO, nginx, Apache, syslog,
253
+ klog, epoch times of JSON logs) or `"shape"` (the line with its numbers and IDs taken out). The
254
+ result has `groups` of `{ key, count, first_line, last_line }`, `total_groups`, and the lines
255
+ of further groups or with no key apart. Up to 200 groups are shown (`max_results`, default 50).
256
+ - `whole_word`: exact text only as a whole word, letters of every script counted.
257
+ - **`EventError.code`**: the `IngestError` code in `ingest.error` events and in the
258
+ `ingest.error` of an upload with `Accept: text/event-stream`.
259
+
260
+ ### Changed: what works differently
261
+
262
+ Search:
263
+
264
+ - **Every script.** Keyword terms keep a mark with its letter (Hindi, Bengali, Tamil, Thai and
265
+ pointed Hebrew lost their words), split Chinese, Japanese and Thai into words, and drop the
266
+ points of a Hebrew query word, which then finds the word with or without points in the text
267
+ (בראשית finds בְּרֵאשִׁית). A Hebrew word with prefix letters (בחוזה, והחוזה) also searches its
268
+ stem (חוזה), and one that ends in a final letter its plain form too (כסף finds כספים); an acronym
269
+ keeps its gershayim or geresh (ש״ח, עו״ד are one term each).
270
+ - **One way to write a character.** Queries are composed as the text is; a search that ignores
271
+ case also folds Greek final sigma, curly quotes and primes, dashes and the minus sign, no-break
272
+ and thin spaces, Hebrew geresh, gershayim and maqaf, and full-width forms: "don't" finds
273
+ "don’t", צה"ל finds צה״ל.
274
+ - **Regex `\w`, `\W`, `\b` and `\B` know the letters of every script**: `\bחוזה\b` matched
275
+ nothing, and `\w+` stopped at "é". Emoji variation selectors and enclosing marks are not word
276
+ characters, for them and for `whole_word`. A repeated group whose repeats a literal character separates,
277
+ as in `(\d{1,3}\.){3}\d{1,3}` or `(\w+\.)+com`, is no longer refused as a nested quantifier.
278
+ - **Exact search counts every line where a text across lines starts** ("a\na" in "a\na\na" was
279
+ counted once), and skips the rest of a line once it is counted: a short common text costs what
280
+ its lines do, not its occurrences. It runs in slices with pauses, as a regex search does, and
281
+ its count stays whole; with `whole_word` or `group_by`, whose work grows with each occurrence,
282
+ it stops after 3 seconds (the result then says the counts are lower bounds). A document held in
283
+ memory is scanned in pieces too.
284
+ - **`case_sensitive` and `whole_word` given as text or as 1** ("true", "1", 1) are read as true; in
285
+ 0.7.0, `case_sensitive: "true"` searched ignoring case. A search of this kind stored by 0.7.0 is
286
+ run again, not answered from what was stored.
287
+ - **A cut list of matches says how to see the rest**: "search again with from_line 1941, or count
288
+ them with group_by", where it said "narrow the search".
289
+ - **Models count by group.** Live, asked for PAY-5031 errors per hour and the last one, both models
290
+ made one search with `group_by: "hour"` and gave every hourly count and the last line right.
291
+
292
+ Documents:
293
+
294
+ - **Word:** headings from paragraph styles (also in documents written in Hebrew, whose styles keep
295
+ English names), list numbers in Word's formats (decimal, letters, roman numerals, Hebrew letters
296
+ and numerals, bullets as "-", restarted lists), tables with empty and merged cells kept in their
297
+ columns (text another program left in a continued merged cell is kept), lists defined through a
298
+ list style, legal numbering (`w:isLgl`: "Section 1.01"), non-breaking hyphens ("555-0199" read
299
+ "5550199") and symbol characters.
300
+ - **PowerPoint:** slides in the order of `presentation.xml`, numbered by position ("Slide 5" for the
301
+ third slide is gone); tables; speaker notes after `[Speaker notes]`, the notes' own text only (not
302
+ the slide number, date and footer of the notes page).
303
+ - **Excel:** each sheet a section, `## Sheet 1: Sales`, then `Columns: | A | B | C |` and a line a
304
+ row, `Row 12: | East | 2026-03-01 | 1200.5 |`, with shared and inline strings, the values Excel
305
+ last computed for formulas, dates and times from number formats (1900 and 1904 systems),
306
+ percentages, durations of a day or more (`[h]:mm`: 36:00), Excel's `_x000D_` escapes, and hidden
307
+ sheets marked. Every row of every sheet is read, within the text limit.
308
+ - **HTML:** scripts and styles dropped, headings, lists, tables (`colspan` and `rowspan` keep the
309
+ cells in their columns), `text (https://…)` for links, alt text for images, entities decoded
310
+ ("AT&T" is found), text a page hides (`hidden`, an inline `display: none`) marked as Word's hidden
311
+ text is, older encodings read as text files are.
312
+ - **Logs:** the profile reads more timestamps (nginx's error log, access logs, syslog) and levels
313
+ (see **Upgrading**).
314
+ - **Outlines** take no heading from a fenced code block, nor from the `#` comments of a text file
315
+ that reads as code (a script, a configuration file).
316
+ - **Refusals in words for the person:** an Office file of before 2007, an Outlook message or an
317
+ Office file with a password ("This is a Word, Excel or PowerPoint file of before 2007…"), where
318
+ it said "looks binary"; and a PDF with a password, where pdf.js said "No password given".
319
+
320
+ ### Fixed
321
+
322
+ Search and documents:
323
+
324
+ - **Keyword queries in scripts with marks found nothing** (LLF-014): see **Changed**.
325
+ - **A common query word no longer skews keyword ranking toward the start of a file** (LLF-015). A
326
+ term counted only up to 200,000 hits gave passages before the cap a score passages after it
327
+ could not get; such a term is now not scored.
328
+ - **Overlapping texts across lines are all counted** (LLF-042), and repeated occurrences on a
329
+ counted line cost nothing (LLF-044, exact search).
330
+ - **Common safe regexes are accepted** (LLF-043): IPv4 addresses, domains, dashed numbers.
331
+ - **Case-insensitive search finds what case-sensitive search finds** (LLF-045): an upper-case
332
+ word that ends in Σ, and composed against decomposed text.
333
+ - **`#` comments in code blocks and scripts are no longer headings** (LLF-016).
334
+ - **Logs with lower-case levels get a profile** (LLF-017).
335
+ - **Slides are numbered in the order of the show** (LLF-023), **non-breaking hyphens and symbols of
336
+ Word are kept** (LLF-024).
337
+ - **Page text can no longer forge a page line** (LLF-025): a line of a PDF page that reads
338
+ "--- Page 3 ---", or one of the extractor's notes, is moved by a space, so search, page numbers
339
+ and `view_pages` are not sent to the wrong page.
340
+ - **A saved line index whose text size is not the document's is not used** (LLF-047): the last line
341
+ read cut short, without an error.
342
+ - **An optional dependency that fails to load is not reported as missing** (LLF-054): the message
343
+ says it is installed but could not be loaded, with the reason, and keeps the failure as `cause`.
344
+ - **A long run of spaces is counted in the token estimate** (LLF-046): about a token for each 16
345
+ spaces after the first. 10,000 spaces were estimated at 0 tokens, so a padded or fixed-width
346
+ report could be planned inline and refused by the provider. Indentation is priced as before.
347
+ - Unused code in `search.ts` is gone (LLF-060).
348
+
349
+ From 0.7.1:
350
+
351
+ Models:
352
+
353
+ - **A Claude stream no longer loses its input counts** (LLF-006). The input fields of the usage in
354
+ `message_delta` may be null, and replaced the numbers of `message_start`: `inputTokens` and
355
+ `cachedInputTokens` read 0, which also took `limits.inputTokens` and the room estimate off. Only
356
+ the numbers of `message_delta` are taken now.
357
+ - **An OpenAI-compatible reply of 200 that holds an error throws it** (LLF-009). A body
358
+ `{ "error": { "code": 502, … } }` with no `choices` (OpenRouter, once generation has started)
359
+ was a reply with no text, and the question could end with no answer and no error. It is now an
360
+ `OpenAiRequestError` with the status the error names, sent again like any 502, in a chat request
361
+ and in a part read, as the same error in a stream already was.
362
+ - **Gemini gets no empty text parts** (LLF-028). A stored answer that came back empty became
363
+ `{ "text": "" }`, which Vertex AI refuses with HTTP 400, so every later question of that
364
+ conversation failed. Empty text parts are left out, and a turn left with none.
365
+ - **A whole-file part that Gemini blocks says why, and is not sent again** (LLF-030). A prompt
366
+ blocked with `promptFeedback.blockReason` failed with "The model returned no text." and was sent
367
+ once more; now "The model returned no text (PROHIBITED_CONTENT).", once.
368
+ - **An adapter class whose `generateText` is a method can read whole files** (LLF-051). It was
369
+ called without its adapter, so a method that used `this` failed on every part.
370
+
371
+ The loop:
372
+
373
+ - **What a refusal showed lasts for the rest of the question** (LLF-040). After a request refused
374
+ as too large, the loop raises its estimate up to 8 times what it counted; the next good reply
375
+ brought it back to twice, the next turns filled the window again, and a question whose provider
376
+ counts more than twice the estimate could fail after two such refusals. The estimate no longer
377
+ falls below what the refusal showed, as [how it works](docs/how-it-works.md#a-request-too-large-for-the-model)
378
+ says.
379
+ - **`limits` and the number options of `createLargeFiles` are checked** (LLF-007, LLF-008), and a
380
+ queue of scans always has at least one slot, whatever it is given: see **Upgrading**.
381
+ - **A missing `pageTokens` no longer takes away the page limit and the room count** (LLF-041).
382
+ - **Questions stopped by one signal no longer get each other's partial result** (LLF-010).
383
+ - **`UsageMeter` keeps any adapter id as an entry of its own** (LLF-050). An id of `"__proto__"`
384
+ counted the usage into `Object.prototype`, which set `requests` and the token counts of every
385
+ object in the process to NaN; `"constructor"` and `"toString"` lost their usage.
386
+
387
+ Documents and uploads:
388
+
389
+ - **A document read by range whose line starts with U+FEFF can be searched** (LLF-013). Each range
390
+ was decoded as a stream of its own, which dropped a U+FEFF at its start: when such a line began a
391
+ piece, every search of the document failed ("did not match its index") and rebuilt the index in
392
+ vain. Ingest has dropped such characters since 0.6.0, so this concerned documents stored by
393
+ 0.5.0. The store example in the [storage guide](docs/guides/storage.md) decodes the same way.
394
+ - **An upload over the limit no longer holds its connection** (LLF-033). The handler stopped
395
+ reading at the limit and answered `413`, but the connection stayed open, with a client still
396
+ sending into it. The comment said the rest was drained, and now it is, up to 8 MB: the client
397
+ reads the `413` and can send its next request on the same connection. Past 8 MB the connection
398
+ is closed. Closing it at once was tried, and lost the answer on Windows, which resets a
399
+ connection closed while data still arrives.
400
+ - **`vertexAi()` checks its location** (LLF-029): see **Upgrading**.
401
+ - **The JSDoc of `ToolCallLimits.maxFileBytes`** gives its default as 3/8 of
402
+ (`maxRequestBytes` − 262,144), 3,651,696 bytes for the default budget, which the code uses
403
+ (LLF-062). It read as 3/8 of `maxRequestBytes`, less 262,144.
404
+
405
+ Tests: vitest 4.1.12 in place of 3.2.7, whose advisories are fixed (LLF-019); `npm audit` is
406
+ clean. The tests run only from `test/`.
407
+
39
408
  ## 0.7.0 — 2026-11-22
40
409
 
41
410
  A question and an ingest now say what they do as typed events, in order: the plan, each model
@@ -1148,7 +1517,7 @@ Ingest:
1148
1517
  million characters of a DOCX. The mark is a hint, not a filter: text hidden through a style,
1149
1518
  white or 1-point text, and a few rarer forms are read as ordinary text, and a document's own
1150
1519
  text can write the mark. See
1151
- [Hidden text in Word and PowerPoint](docs/security.md#hidden-text-in-word-and-powerpoint).
1520
+ [Hidden text in Word and PowerPoint](docs/security.md#hidden-text-in-word-powerpoint-and-html).
1152
1521
  - **A hidden slide says so.** The heading of a slide that the slide show skips (`show="0"`) reads
1153
1522
  `## Slide 2 (hidden, not shown in the slide show)`. Its text is kept. Shapes hidden on a slide
1154
1523
  that shows are read as ordinary text. See [DOCX and PPTX](docs/guides/pdfs.md#docx-and-pptx).
package/README.md CHANGED
@@ -192,8 +192,10 @@ PDF in one block, about 0.1 to 0.35 s for each MB of it. Neither it nor pdf.js c
192
192
  an object takes before building it: a crafted PDF of 732 bytes, whose object stream unpacks to
193
193
  4 MB of empty dictionaries, ran a heap of 512 MB out of memory at ingest. What a stream unpacks to
194
194
  is outside the heap: one of 1.6 KB took 1.6 GB of memory with 20 MB of heap. If your users can
195
- upload files you do not trust, ingest them in a child process with its own heap limit, memory
196
- limit and timer, as [Deployment](docs/guides/deployment.md#uploads-and-ingest) shows, and do not
195
+ upload files you do not trust, read them in child processes with a heap limit and a kill timer:
196
+ pass `createIsolatedExtractors().extractors`, from `llm-large-files/node`, to `createLargeFiles`
197
+ ([isolated ingest](docs/reference/node.md#createisolatedextractorsoptions)). Give the server a
198
+ memory limit too, as [Deployment](docs/guides/deployment.md#uploads-and-ingest) shows, and do not
197
199
  offer `view_pages` on their documents. What is refused, and what still holds the server:
198
200
  [Security](docs/security.md#uploads).
199
201
 
@@ -252,15 +254,17 @@ What each model gets, and what it costs: [An explorer model](docs/guides/explore
252
254
 
253
255
  | | |
254
256
  |---|---|
255
- | **Formats** | Text, Markdown, logs (UTF-8 and UTF-16, and Hebrew, Arabic, Cyrillic, Japanese and Western European text in its older encoding), JSON/JSONL, CSV/TSV, DOCX, PPTX, PDF (text layer, with tables rebuilt so empty cells stay empty; pages with a picture are marked, and the model can look at the pages themselves; scans of up to 30 pages when PDFs are kept) |
257
+ | **Formats** | Text, Markdown, logs (UTF-8 and UTF-16, and Hebrew, Arabic, Cyrillic, Japanese and Western European text in its older encoding), JSON/JSONL, CSV/TSV, HTML (the text a browser shows), DOCX (headings, clause numbers, tables, notes and comments), PPTX (slides in show order, tables, speaker notes), XLSX (every sheet, a line per row, with its row number), PDF (text layer, with tables rebuilt so empty cells stay empty; pages with a picture are marked, and the model can look at the pages themselves; scans of up to 30 pages when PDFs are kept) |
256
258
  | **Logs** | Detected automatically; the card shows level counts, the time range, and the most frequent errors grouped by shape (`timeout after <n>ms to <ip>`) |
257
259
  | **Books and documents** | An outline of headings with line numbers, including Markdown, "Chapter 12", numbered sections, and Hebrew chapter titles |
260
+ | **Counting** | Exact counts of matching lines, per hour, per code or per message shape, in one search; exact sums, averages and groups over the rows of a CSV, an Excel sheet or a table of a document with `aggregate_table`, which reads every row and runs no code |
261
+ | **Every language** | Search finds a Hebrew word with any prefix letter, words written with or without accents, quotes or gershayim either way; regex `\w` and `\b` know every script |
258
262
  | **Limits** | One budget covers tokens *and* request bytes, so files fit both your context window and your connector's payload limit. It assumes 1M tokens and 10 MB: set `budget.contextTokens` for your model's window (an adapter's `contextTokens` can only make it smaller) |
259
263
  | **Reliability** | Retries, waits on a silent model, recovery from a request too large, error kinds: see [Errors and reliability](docs/guides/errors-and-reliability.md) |
260
264
  | **Models** | Gemini and Vertex AI, any OpenAI-compatible endpoint, Claude, or an adapter of your own. Two models of different providers can share a question |
261
265
  | **Cost** | Usage summed over every request of a question, for each model, with ceilings on whole-file reads, requests and input tokens |
262
266
  | **Privacy** | Documents can belong to an `owner`; other users can't plan, read, or delete them |
263
- | **Hostile uploads** | Limits on the text, pages and time of one file; zip bombs and PDFs built to exhaust a server are refused when the checks recognize them; ingest pauses for other requests between pages and slices. Not every hostile file is refused, parsing shares your server's heap, and some steps hold the server for a while: ingest untrusted uploads in a process of their own ([Security](docs/security.md#uploads)) |
267
+ | **Hostile uploads** | Limits on the text, pages and time of one file; zip bombs and PDFs built to exhaust a server are refused when the checks recognize them, with a code (`"hostile"`); ingest pauses for other requests between pages and slices. Not every hostile file is refused, and some steps hold the server for a while: read untrusted uploads in child processes with `createIsolatedExtractors`, which refuses a file that runs out of memory or time while the server goes on ([Security](docs/security.md#uploads)) |
264
268
  | **Storage** | In memory, on disk with expiry, or your own store (Redis, S3, a database) |
265
269
 
266
270
  ## Live results
@@ -301,7 +305,7 @@ Reference, one page per module:
301
305
  - [`llm-large-files/gemini`](docs/reference/gemini.md): `askGemini`, `gemini()`, `geminiApi()`, `vertexAi()`.
302
306
  - [`llm-large-files/openai`](docs/reference/openai.md): `openAiCompatible()` and its options.
303
307
  - [`llm-large-files/anthropic`](docs/reference/anthropic.md): `anthropic()` and its options.
304
- - [`llm-large-files/node`](docs/reference/node.md): `createDocumentHandlers`, its routes and responses.
308
+ - [`llm-large-files/node`](docs/reference/node.md): `createDocumentHandlers`, its routes and responses, `createIsolatedExtractors`.
305
309
 
306
310
  [Changelog](CHANGELOG.md): what each version changed, and what to change in your code when you upgrade.
307
311
 
@@ -312,9 +316,9 @@ maintainers: [Contributing](https://github.com/renanbazinin/llm-large-files/blob
312
316
  ## Requirements
313
317
 
314
318
  Node.js 20.19 or newer. The package is ESM; CommonJS code can `require()` it on Node 20.19+ and
315
- 22.12+. For DOCX/PPTX install `jszip`, for PDF install `unpdf`, and to mark and show the pages of a
316
- PDF, and refuse a page built to hold the server before it is read, install `@cantoo/pdf-lib`. All
317
- three are optional:
319
+ 22.12+. For DOCX, PPTX and XLSX install `jszip`, for PDF install `unpdf`, and to mark and show the
320
+ pages of a PDF, and refuse a page built to hold the server before it is read, install
321
+ `@cantoo/pdf-lib`. All three are optional:
318
322
 
319
323
  ```bash
320
324
  npm install jszip unpdf @cantoo/pdf-lib # Node 24 and later
@@ -0,0 +1,103 @@
1
+ import { type DocumentSource } from "./search.js";
2
+ /**
3
+ * `aggregate_table`: counts, sums, averages, minimums and maximums over the rows of one table of a
4
+ * document, with filters and groups, exactly, without code and without the model reading the rows.
5
+ * A model that adds up 50,000 rows by reading them needs hundreds of calls and gets it wrong; this
6
+ * reads them once. Every group says the lines of its first rows, so an answer can cite them.
7
+ *
8
+ * The tables it reads:
9
+ * - a CSV or TSV file (format "csv"): the whole file, its first line the header; the separator is
10
+ * found from the first lines (comma, semicolon, tab or "|"), and quoted fields may hold separators,
11
+ * quotes and line breaks;
12
+ * - a sheet of an Excel workbook (format "xlsx"), as the XLSX extractor writes it: `## Sheet 2:
13
+ * name`, `Columns: …`, then `Row 7: | a | b |` lines; its first row is the header unless every
14
+ * value of it is a number, and then the columns are named by their letters;
15
+ * - any run of `| cell | cell |` lines in another document: the tables of DOCX, PPTX, PDF, HTML and
16
+ * Markdown files, numbered in the order of the file. A Markdown separator row (`|---|`) is skipped.
17
+ */
18
+ /** The most groups counted one by one; rows of further groups are counted together. */
19
+ export declare const MAX_AGGREGATE_GROUPS = 10000;
20
+ /** The most groups shown in a result. */
21
+ export declare const MAX_SHOWN_GROUPS = 200;
22
+ /** Distinct values `count_distinct` holds, across all groups: past it, values are no longer told apart. */
23
+ export declare const MAX_DISTINCT_VALUES = 1000000;
24
+ export type AggregateOp = "count" | "sum" | "avg" | "min" | "max" | "count_distinct";
25
+ export declare const AGGREGATE_OPS: readonly AggregateOp[];
26
+ export type FilterOp = "=" | "!=" | ">" | ">=" | "<" | "<=" | "contains" | "not_contains" | "starts_with" | "empty" | "not_empty";
27
+ export declare const FILTER_OPS: readonly FilterOp[];
28
+ /** A date column grouped by a part of its dates: `"Date:month"` groups 2026-03-14 under 2026-03. */
29
+ export type DatePart = "year" | "month" | "day";
30
+ export type AggregateRequest = {
31
+ /** Which table: a sheet's name or number for a workbook, a table's number for other documents. Defaults to the first. */
32
+ table?: string | number;
33
+ filters?: Array<{
34
+ column: string;
35
+ op: FilterOp;
36
+ value?: string | number;
37
+ }>;
38
+ /** Up to 3 columns; each may end in ":year", ":month" or ":day" for a column of dates. */
39
+ groupBy?: string[];
40
+ /** "count", or an op and a column: "sum:Revenue", "avg:Price", "count_distinct:Customer". Defaults to ["count"]. */
41
+ metrics?: string[];
42
+ /** "metric" (the default): the largest value of the first metric first; "key": by the groups' values, in order. */
43
+ orderBy?: "metric" | "key";
44
+ /**
45
+ * How many rows at the top of the table are its header: 0 when it has none (columns are named by
46
+ * their letters in a workbook, "Column 1"… elsewhere), up to 5. Unset: one for a CSV file; for a
47
+ * sheet or a `| cell |` table it is found (see `aggregateTable`).
48
+ */
49
+ headerRows?: number;
50
+ /** Groups shown, at most. Defaults to 50. */
51
+ limit?: number;
52
+ };
53
+ export type AggregateGroup = {
54
+ /** The value of each group-by column, as the first row of the group writes it. */
55
+ key: Record<string, string>;
56
+ count: number;
57
+ /** Each metric by its name ("sum:Revenue"). Null when no row of the group had a number in its column. */
58
+ values: Record<string, number | string | null>;
59
+ /** The lines of the group's first rows. */
60
+ lines: number[];
61
+ };
62
+ export type AggregateResult = {
63
+ /** Which table was read: "Sheet 2: Sales", "table 3 of 5", "the CSV file". */
64
+ table: string;
65
+ /** How many tables the document has: sheets, or `| cell |` tables. */
66
+ tables: number;
67
+ columns: string[];
68
+ headerLine: number;
69
+ rowsRead: number;
70
+ rowsMatched: number;
71
+ groups: AggregateGroup[];
72
+ totalGroups: number;
73
+ /** Rows of groups past `MAX_AGGREGATE_GROUPS`. */
74
+ otherRows: number;
75
+ /** The rows taken for the header, and a title row above them that was left out. */
76
+ headerRows: number;
77
+ title?: string;
78
+ /** Rows the same as the header, found again inside the table (a header a PDF repeats on each page): left out. */
79
+ repeatedHeaders: number;
80
+ /** Rows with another number of cells than the header: read, and counted here, as a sign of a table read wrong. */
81
+ irregularRows: number;
82
+ /** True when `count_distinct` reached `MAX_DISTINCT_VALUES`: its counts are lower bounds. */
83
+ distinctCapped: boolean;
84
+ /** For each numeric metric, how many matched rows had a value in its column that is not a number (left out). */
85
+ notNumbers: Record<string, number>;
86
+ };
87
+ /**
88
+ * A number as a person writes it in a table: "1,234.5", "-12", "(1,200)" for a negative, "₪4,750",
89
+ * "$ 12.00", "12%" (12), "1.5e3", "1 234" with a space or a no-break space between thousands.
90
+ * A value with a comma and no dot is taken for thousands when the comma is followed by three digits
91
+ * ("4,750"), and for a decimal comma otherwise ("12,5"). Undefined for anything else.
92
+ */
93
+ export declare function parseNumber(raw: string): number | undefined;
94
+ /** Splits a `| a | b |` row into its cells, honouring `\|` inside a cell. */
95
+ export declare function pipeCells(line: string): string[];
96
+ /** The separator of a CSV file, from its first lines: the one found the same number of times (above 0) on most of them. */
97
+ export declare function csvSeparator(lines: string[]): string;
98
+ /**
99
+ * Reads the rows of one table and aggregates them. Throws an error the model can act on: no table,
100
+ * a table that does not exist, an unknown column or operation.
101
+ */
102
+ export declare function aggregateTable(source: DocumentSource, request: AggregateRequest, signal?: AbortSignal): Promise<AggregateResult>;
103
+ //# sourceMappingURL=aggregate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aggregate.d.ts","sourceRoot":"","sources":["../src/aggregate.ts"],"names":[],"mappings":"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"}