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
package/CHANGELOG.md CHANGED
@@ -36,6 +36,324 @@ 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.0 — 2026-11-23
40
+
41
+ Files from an enterprise, read with their structure, and counted exactly. Word files keep their
42
+ headings, clause numbers and tables; PowerPoint decks their order, tables and speaker notes; Excel
43
+ workbooks and HTML pages are read for the first time. Search works in every script (Hebrew with
44
+ its prefix letters, Hindi, Thai, Chinese, text composed or decomposed), can search part of a file,
45
+ show the last matches, and count matching lines per hour, per code or per message shape in one
46
+ call. Untrusted PDF and Office files can be read in child processes with a memory limit and a kill
47
+ timer, and every refusal says why with a code. 0.7.1 was never published: its fifteen fixes ship
48
+ here, and its points are part of this entry. Checked live with the Gemini API on
49
+ `gemini-3.5-flash-lite` and `gemini-3.8-flash`: hourly counts and the last line of a log in one
50
+ search, a clause of a Hebrew lease answered in Hebrew, a row of a workbook, a table of an HTML page.
51
+
52
+ ### Upgrading: what you need to change
53
+
54
+ Code written for 0.7.0 compiles with 0.8.0, with one exception: `DocumentFormat` has two new
55
+ members, `"xlsx"` and `"html"`. An exhaustive `switch` on a document's format, or a
56
+ `Record<DocumentFormat, …>` of your own, needs the two cases. Every other change to the public
57
+ types is an addition: `IngestError`, `ingestErrorCodeOf` and the type `IngestErrorCode` in
58
+ `llm-large-files`; `createIsolatedExtractors` and the types `IsolatedExtractorOptions` and
59
+ `IsolatedExtractors` in `llm-large-files/node`; an optional `code` in `EventError`.
60
+
61
+ Some behavior is different. Check each point against your app:
62
+
63
+ - **Excel and HTML files are read.** An `.xlsx` (and `.xlsm`) upload was refused with "This file is
64
+ a ZIP archive"; it is now a document of format `"xlsx"`. An `.html` or `.htm` file was read as
65
+ text, tags and all, with format `"text"`; it is now format `"html"`, with the text a browser
66
+ shows. Both need nothing new: XLSX uses the optional `jszip`, as DOCX does.
67
+ **What to do:** if your app lists the formats it accepts, add them. See
68
+ [formats](docs/reference/library.md#documentformat).
69
+ - **Word and PowerPoint files are read with their structure.** A DOCX heading is written as a
70
+ Markdown heading, a numbered paragraph with its number (`## 2.1 Rent`, `(a) the flat`), a table
71
+ as rows of `| cell | cell | |` with its empty cells, and the footnotes, endnotes, comments,
72
+ headers and footers each under a heading of its own (a repeated header once). A PPTX is numbered
73
+ in the order of its slide show, with its tables and its speaker notes. Documents ingested by
74
+ 0.7.0 keep the text they have until they are uploaded again.
75
+ **What to do:** nothing, unless your tests compare the text of a DOCX or PPTX: update them.
76
+ - **`ingest` throws `IngestError` for a file it cannot read.** It is an `Error` with the same
77
+ message as before, a `code` (`"too_large"`, `"no_text"`, `"hostile"`…), the HTTP `status` the
78
+ upload handler answers with, and the extractor's error as `cause`. A store that failed, a caller
79
+ that gave up, a listener that threw and a system error from an extractor of your own are thrown
80
+ as before. `ingest.error` events carry the `code`, and name `"IngestError"` where they named
81
+ `"Error"`.
82
+ **What to do:** nothing; to tell users in your own words (another language), map `error.code`.
83
+ A test that expects `name: "Error"` in an `ingest.error` event needs `"IngestError"`.
84
+ - **The answer is asked for in the language of the question.** The three closing requests
85
+ (`FINAL_ANSWER_REQUEST`, `FINAL_ANSWER_AFTER_PAGES`, `FINAL_ANSWER_WITHOUT_TOOLS`) end with
86
+ "Answer in the language of my question." A model asked in Hebrew answered in English after an
87
+ English closing request.
88
+ **What to do:** nothing; to have answers in one language whatever the question, say so in
89
+ `system`.
90
+ - **The text the model is sent changed:** the description of `search_document` (its new
91
+ arguments), the tool guide (two lines: counts by group and paging; searching the bare form of a
92
+ word), and the closing requests. The provider's prompt cache misses once after the upgrade.
93
+ **What to do:** nothing. See **Changed** for what models now do.
94
+ - **Text is composed (NFC) at ingest.** "e" followed by a combining accent becomes "é". Line counts
95
+ do not change; `characters` and the sizes of such a text can be a little smaller. A run of more
96
+ than 30 marks on one letter, which no script writes, gets an invisible combining grapheme joiner
97
+ (U+034F) after each 30, as Unicode's stream-safe form does: composing such a run took time by its
98
+ square, and 600 KB of them held the server 80 seconds.
99
+ **What to do:** nothing.
100
+ - **More files are taken for logs.** A `.txt` of nginx or Apache access lines, JSON log lines,
101
+ klog or logfmt is now format `"log"`, with a log profile; levels in lower case, in brackets,
102
+ after `level=`, in a JSON field or as pino numbers are counted.
103
+ **What to do:** nothing, unless your app switches on `format === "text"` for such files.
104
+ - **From 0.7.1** (never published), some values that were taken in silence and did not work are
105
+ refused:
106
+
107
+ - **NaN in a number option of `createLargeFiles` throws.** `ttlMs`, `maxUploadBytes`,
108
+ `scannedPdfPages`, `cacheBytes`, `cacheSize`, `wholeDocumentBytes`, `scanChunkBytes` and
109
+ `maxConcurrentScans` throw a `RangeError` for NaN (what `Number(process.env.X)` gives for a
110
+ variable that is not set), and a `TypeError` for a value that is not a number, such as a string
111
+ read from the environment. `scanChunkBytes: Infinity` throws too. With NaN, `maxConcurrentScans`
112
+ made every search of a document read by range wait forever, `ttlMs` failed every upload with
113
+ "Invalid time value", and `maxUploadBytes` took off the upload limit.
114
+ **What to do:** nothing, unless you pass such values. Leave an option out for its default, or
115
+ read a variable with a fallback: `Number(process.env.SCANS ?? 4)`.
116
+ - **NaN in `AskOptions.limits` throws, before any request.** A field of `limits` that is NaN throws
117
+ a `RangeError` ("limits.toolTurns must be a number, and is NaN. Leave it out for the default."),
118
+ and one that is not a number a `TypeError`. NaN used to give a question with no tool, refuse
119
+ every call, or take off the cap on whole-file reads and the ceilings on tokens and requests.
120
+ `ToolOptions.maxWholeDocumentReads` is checked the same way. `Infinity` still means no ceiling.
121
+ **What to do:** as above.
122
+ - **`partialResultOf(error)` gives `undefined` for an error that several questions threw.** Questions
123
+ stopped by one shared signal all throw its one reason (`AbortSignal.any` passes it on as it is).
124
+ `partialResultOf` gave each the result of whichever failed last: another user's tool rounds and
125
+ usage. Now it gives none, and each question's `run.error` event still carries its own `partial`.
126
+ **What to do:** if you stop many questions with one signal and keep their partial results, give
127
+ each question an `AbortController` of its own that the shared signal aborts with a new reason.
128
+ See [`partialResultOf`](docs/reference/ask.md#partialresultoferror).
129
+ - **`vertexAi()` and `vertexHost()` check `location`.** One that is not lowercase letters and digits
130
+ joined by single hyphens (`"global"`, `"us"`, `"europe-west4"`) throws a `TypeError`. With `/`,
131
+ `?`, `#` or `@`, it named another host, which got the access token.
132
+ **What to do:** nothing, unless a location comes from a user; then expect the `TypeError`.
133
+ - **An upload answered before its body was read drains the rest, up to 8 MB.** The `413` of an
134
+ upload over `maxUploadBytes` (and every answer sent before the body was read to its end) is
135
+ written at once, and ends once the rest of the body has been read and dropped. A body that goes
136
+ on more than 8 MB past the limit is cut off by closing the connection.
137
+ **What to do:** nothing. See [`node`](docs/reference/node.md).
138
+ - **An adapter of your own whose `capabilities` lack `pageTokens` or `toolFiles`.** A `pageTokens`
139
+ that is missing, NaN or negative counts as 1,000, and a `toolFiles` that is none of `"inside"`,
140
+ `"beside"` and `"none"` counts as `"none"`, so `view_pages` is not offered to that model. Both
141
+ fields are required by the type, so this concerns only an adapter written in JavaScript or cast.
142
+ **What to do:** declare both.
143
+
144
+ ### New: what you can add
145
+
146
+ - **`createIsolatedExtractors(options?)`** in `llm-large-files/node`: PDF, DOCX, PPTX and XLSX files
147
+ read in child processes, each with a heap flag (`maxHeapMb`, 512), a kill timer (120 s), at most
148
+ `concurrency` (2) at once and `maxQueue` (8) waiting. A file that exhausts its child's memory is
149
+ refused (`"out_of_memory"`) and the server goes on; a full queue refuses at once (`"busy"`), and
150
+ the upload handler answers that with 503 and `Retry-After`. Children are replaced after 50 files
151
+ and stopped when idle. A reader that cannot start (a missing `childScript`, an `execArgv` Node
152
+ does not know) is the server's trouble: an `Error` with `status` 500, not an `IngestError`; one
153
+ that cannot be started for want of process slots is `"busy"`. For a server that bundles its code,
154
+ `llm-large-files/node/ingest-child.js` is exported, and `childScript` takes a path or a file
155
+ URL. See [isolated ingest](docs/reference/node.md#createisolatedextractorsoptions).
156
+
157
+ ```ts
158
+ import { createLargeFiles, FileDocumentStore } from "llm-large-files";
159
+ import { createIsolatedExtractors } from "llm-large-files/node";
160
+
161
+ const isolated = createIsolatedExtractors({ maxHeapMb: 512, concurrency: 2 });
162
+ const files = createLargeFiles({ store: new FileDocumentStore("./data"), extractors: isolated.extractors });
163
+ // A SIGTERM listener replaces Node's own exit: stop your HTTP server there too, or it goes on serving.
164
+ process.once("SIGTERM", () => {
165
+ server.close();
166
+ void isolated.close();
167
+ });
168
+ ```
169
+
170
+ - **`IngestError`**, with `code`, `status` and, for `"busy"`, `retryAfterMs`; and
171
+ `ingestErrorCodeOf(message)`. The codes: `empty`, `too_large`, `too_much_text`,
172
+ `too_many_pages`, `not_text`, `compressed`, `legacy_office`, `encrypted`, `no_text`, `hostile`,
173
+ `timeout`, `out_of_memory`, `busy`, `missing_dependency`, `unreadable`. See
174
+ [`IngestError`](docs/reference/library.md#ingesterror).
175
+
176
+ ```ts
177
+ import { IngestError, type IngestErrorCode } from "llm-large-files";
178
+
179
+ // Your own words for some refusals; the library's message for the rest.
180
+ const hebrew: Partial<Record<IngestErrorCode, string>> = {
181
+ too_large: "הקובץ גדול מדי.",
182
+ no_text: "אין בקובץ טקסט לקריאה (ייתכן שהוא סרוק).",
183
+ busy: "השרת עסוק. נסו שוב בעוד רגע.",
184
+ };
185
+
186
+ try {
187
+ await files.ingest({ name, bytes, owner });
188
+ } catch (error) {
189
+ if (!(error instanceof IngestError)) throw error; // the store, or your own code
190
+ console.log(error.status, hebrew[error.code] ?? error.message);
191
+ }
192
+ ```
193
+
194
+ - **`search_document` arguments** (see [`search_document`](docs/reference/tools.md#search_document)):
195
+ - `from_line` and `to_line`: search part of a file, in every mode; the result says
196
+ `searched_lines`.
197
+ - `next_from_line` in a result of exact or regex search that shows the first matches of more:
198
+ search again from it for the ones after.
199
+ - `order: "last"`: the last `max_results` matching lines, in file order.
200
+ - `group_by`: count the matching lines by group and show none: `"capture"` (the regex's first
201
+ group), `"minute"`, `"hour"`, `"day"` (the timestamp of the line: ISO, nginx, Apache, syslog,
202
+ klog, epoch times of JSON logs) or `"shape"` (the line with its numbers and IDs taken out). The
203
+ result has `groups` of `{ key, count, first_line, last_line }`, `total_groups`, and the lines
204
+ of further groups or with no key apart. Up to 200 groups are shown (`max_results`, default 50).
205
+ - `whole_word`: exact text only as a whole word, letters of every script counted.
206
+ - **`EventError.code`**: the `IngestError` code in `ingest.error` events and in the
207
+ `ingest.error` of an upload with `Accept: text/event-stream`.
208
+
209
+ ### Changed: what works differently
210
+
211
+ Search:
212
+
213
+ - **Every script.** Keyword terms keep a mark with its letter (Hindi, Bengali, Tamil, Thai and
214
+ pointed Hebrew lost their words), split Chinese, Japanese and Thai into words, and drop the
215
+ points of a Hebrew query word, which then finds the word with or without points in the text
216
+ (בראשית finds בְּרֵאשִׁית). A Hebrew word with prefix letters (בחוזה, והחוזה) also searches its
217
+ stem (חוזה), and one that ends in a final letter its plain form too (כסף finds כספים); an acronym
218
+ keeps its gershayim or geresh (ש״ח, עו״ד are one term each).
219
+ - **One way to write a character.** Queries are composed as the text is; a search that ignores
220
+ case also folds Greek final sigma, curly quotes and primes, dashes and the minus sign, no-break
221
+ and thin spaces, Hebrew geresh, gershayim and maqaf, and full-width forms: "don't" finds
222
+ "don’t", צה"ל finds צה״ל.
223
+ - **Regex `\w`, `\W`, `\b` and `\B` know the letters of every script**: `\bחוזה\b` matched
224
+ nothing, and `\w+` stopped at "é". Emoji variation selectors and enclosing marks are not word
225
+ characters, for them and for `whole_word`. A repeated group whose repeats a literal character separates,
226
+ as in `(\d{1,3}\.){3}\d{1,3}` or `(\w+\.)+com`, is no longer refused as a nested quantifier.
227
+ - **Exact search counts every line where a text across lines starts** ("a\na" in "a\na\na" was
228
+ counted once), and skips the rest of a line once it is counted: a short common text costs what
229
+ its lines do, not its occurrences. It runs in slices with pauses, as a regex search does, and
230
+ its count stays whole; with `whole_word` or `group_by`, whose work grows with each occurrence,
231
+ it stops after 3 seconds (the result then says the counts are lower bounds). A document held in
232
+ memory is scanned in pieces too.
233
+ - **`case_sensitive` and `whole_word` given as text or as 1** ("true", "1", 1) are read as true; in
234
+ 0.7.0, `case_sensitive: "true"` searched ignoring case. A search of this kind stored by 0.7.0 is
235
+ run again, not answered from what was stored.
236
+ - **A cut list of matches says how to see the rest**: "search again with from_line 1941, or count
237
+ them with group_by", where it said "narrow the search".
238
+ - **Models count by group.** Live, asked for PAY-5031 errors per hour and the last one, both models
239
+ made one search with `group_by: "hour"` and gave every hourly count and the last line right.
240
+
241
+ Documents:
242
+
243
+ - **Word:** headings from paragraph styles (also in documents written in Hebrew, whose styles keep
244
+ English names), list numbers in Word's formats (decimal, letters, roman numerals, Hebrew letters
245
+ and numerals, bullets as "-", restarted lists), tables with empty and merged cells kept in their
246
+ columns (text another program left in a continued merged cell is kept), lists defined through a
247
+ list style, legal numbering (`w:isLgl`: "Section 1.01"), non-breaking hyphens ("555-0199" read
248
+ "5550199") and symbol characters.
249
+ - **PowerPoint:** slides in the order of `presentation.xml`, numbered by position ("Slide 5" for the
250
+ third slide is gone); tables; speaker notes after `[Speaker notes]`, the notes' own text only (not
251
+ the slide number, date and footer of the notes page).
252
+ - **Excel:** each sheet a section, `## Sheet 1: Sales`, then `Columns: | A | B | C |` and a line a
253
+ row, `Row 12: | East | 2026-03-01 | 1200.5 |`, with shared and inline strings, the values Excel
254
+ last computed for formulas, dates and times from number formats (1900 and 1904 systems),
255
+ percentages, durations of a day or more (`[h]:mm`: 36:00), Excel's `_x000D_` escapes, and hidden
256
+ sheets marked. Every row of every sheet is read, within the text limit.
257
+ - **HTML:** scripts and styles dropped, headings, lists, tables (`colspan` and `rowspan` keep the
258
+ cells in their columns), `text (https://…)` for links, alt text for images, entities decoded
259
+ ("AT&T" is found), text a page hides (`hidden`, an inline `display: none`) marked as Word's hidden
260
+ text is, older encodings read as text files are.
261
+ - **Logs:** the profile reads more timestamps (nginx's error log, access logs, syslog) and levels
262
+ (see **Upgrading**).
263
+ - **Outlines** take no heading from a fenced code block, nor from the `#` comments of a text file
264
+ that reads as code (a script, a configuration file).
265
+ - **Refusals in words for the person:** an Office file of before 2007, an Outlook message or an
266
+ Office file with a password ("This is a Word, Excel or PowerPoint file of before 2007…"), where
267
+ it said "looks binary"; and a PDF with a password, where pdf.js said "No password given".
268
+
269
+ ### Fixed
270
+
271
+ Search and documents:
272
+
273
+ - **Keyword queries in scripts with marks found nothing** (LLF-014): see **Changed**.
274
+ - **A common query word no longer skews keyword ranking toward the start of a file** (LLF-015). A
275
+ term counted only up to 200,000 hits gave passages before the cap a score passages after it
276
+ could not get; such a term is now not scored.
277
+ - **Overlapping texts across lines are all counted** (LLF-042), and repeated occurrences on a
278
+ counted line cost nothing (LLF-044, exact search).
279
+ - **Common safe regexes are accepted** (LLF-043): IPv4 addresses, domains, dashed numbers.
280
+ - **Case-insensitive search finds what case-sensitive search finds** (LLF-045): an upper-case
281
+ word that ends in Σ, and composed against decomposed text.
282
+ - **`#` comments in code blocks and scripts are no longer headings** (LLF-016).
283
+ - **Logs with lower-case levels get a profile** (LLF-017).
284
+ - **Slides are numbered in the order of the show** (LLF-023), **non-breaking hyphens and symbols of
285
+ Word are kept** (LLF-024).
286
+ - **Page text can no longer forge a page line** (LLF-025): a line of a PDF page that reads
287
+ "--- Page 3 ---", or one of the extractor's notes, is moved by a space, so search, page numbers
288
+ and `view_pages` are not sent to the wrong page.
289
+ - **A saved line index whose text size is not the document's is not used** (LLF-047): the last line
290
+ read cut short, without an error.
291
+ - **An optional dependency that fails to load is not reported as missing** (LLF-054): the message
292
+ says it is installed but could not be loaded, with the reason, and keeps the failure as `cause`.
293
+ - **A long run of spaces is counted in the token estimate** (LLF-046): about a token for each 16
294
+ spaces after the first. 10,000 spaces were estimated at 0 tokens, so a padded or fixed-width
295
+ report could be planned inline and refused by the provider. Indentation is priced as before.
296
+ - Unused code in `search.ts` is gone (LLF-060).
297
+
298
+ From 0.7.1:
299
+
300
+ Models:
301
+
302
+ - **A Claude stream no longer loses its input counts** (LLF-006). The input fields of the usage in
303
+ `message_delta` may be null, and replaced the numbers of `message_start`: `inputTokens` and
304
+ `cachedInputTokens` read 0, which also took `limits.inputTokens` and the room estimate off. Only
305
+ the numbers of `message_delta` are taken now.
306
+ - **An OpenAI-compatible reply of 200 that holds an error throws it** (LLF-009). A body
307
+ `{ "error": { "code": 502, … } }` with no `choices` (OpenRouter, once generation has started)
308
+ was a reply with no text, and the question could end with no answer and no error. It is now an
309
+ `OpenAiRequestError` with the status the error names, sent again like any 502, in a chat request
310
+ and in a part read, as the same error in a stream already was.
311
+ - **Gemini gets no empty text parts** (LLF-028). A stored answer that came back empty became
312
+ `{ "text": "" }`, which Vertex AI refuses with HTTP 400, so every later question of that
313
+ conversation failed. Empty text parts are left out, and a turn left with none.
314
+ - **A whole-file part that Gemini blocks says why, and is not sent again** (LLF-030). A prompt
315
+ blocked with `promptFeedback.blockReason` failed with "The model returned no text." and was sent
316
+ once more; now "The model returned no text (PROHIBITED_CONTENT).", once.
317
+ - **An adapter class whose `generateText` is a method can read whole files** (LLF-051). It was
318
+ called without its adapter, so a method that used `this` failed on every part.
319
+
320
+ The loop:
321
+
322
+ - **What a refusal showed lasts for the rest of the question** (LLF-040). After a request refused
323
+ as too large, the loop raises its estimate up to 8 times what it counted; the next good reply
324
+ brought it back to twice, the next turns filled the window again, and a question whose provider
325
+ counts more than twice the estimate could fail after two such refusals. The estimate no longer
326
+ falls below what the refusal showed, as [how it works](docs/how-it-works.md#a-request-too-large-for-the-model)
327
+ says.
328
+ - **`limits` and the number options of `createLargeFiles` are checked** (LLF-007, LLF-008), and a
329
+ queue of scans always has at least one slot, whatever it is given: see **Upgrading**.
330
+ - **A missing `pageTokens` no longer takes away the page limit and the room count** (LLF-041).
331
+ - **Questions stopped by one signal no longer get each other's partial result** (LLF-010).
332
+ - **`UsageMeter` keeps any adapter id as an entry of its own** (LLF-050). An id of `"__proto__"`
333
+ counted the usage into `Object.prototype`, which set `requests` and the token counts of every
334
+ object in the process to NaN; `"constructor"` and `"toString"` lost their usage.
335
+
336
+ Documents and uploads:
337
+
338
+ - **A document read by range whose line starts with U+FEFF can be searched** (LLF-013). Each range
339
+ was decoded as a stream of its own, which dropped a U+FEFF at its start: when such a line began a
340
+ piece, every search of the document failed ("did not match its index") and rebuilt the index in
341
+ vain. Ingest has dropped such characters since 0.6.0, so this concerned documents stored by
342
+ 0.5.0. The store example in the [storage guide](docs/guides/storage.md) decodes the same way.
343
+ - **An upload over the limit no longer holds its connection** (LLF-033). The handler stopped
344
+ reading at the limit and answered `413`, but the connection stayed open, with a client still
345
+ sending into it. The comment said the rest was drained, and now it is, up to 8 MB: the client
346
+ reads the `413` and can send its next request on the same connection. Past 8 MB the connection
347
+ is closed. Closing it at once was tried, and lost the answer on Windows, which resets a
348
+ connection closed while data still arrives.
349
+ - **`vertexAi()` checks its location** (LLF-029): see **Upgrading**.
350
+ - **The JSDoc of `ToolCallLimits.maxFileBytes`** gives its default as 3/8 of
351
+ (`maxRequestBytes` − 262,144), 3,651,696 bytes for the default budget, which the code uses
352
+ (LLF-062). It read as 3/8 of `maxRequestBytes`, less 262,144.
353
+
354
+ Tests: vitest 4.1.12 in place of 3.2.7, whose advisories are fixed (LLF-019); `npm audit` is
355
+ clean. The tests run only from `test/`.
356
+
39
357
  ## 0.7.0 — 2026-11-22
40
358
 
41
359
  A question and an ingest now say what they do as typed events, in order: the plan, each model
@@ -1148,7 +1466,7 @@ Ingest:
1148
1466
  million characters of a DOCX. The mark is a hint, not a filter: text hidden through a style,
1149
1467
  white or 1-point text, and a few rarer forms are read as ordinary text, and a document's own
1150
1468
  text can write the mark. See
1151
- [Hidden text in Word and PowerPoint](docs/security.md#hidden-text-in-word-and-powerpoint).
1469
+ [Hidden text in Word and PowerPoint](docs/security.md#hidden-text-in-word-powerpoint-and-html).
1152
1470
  - **A hidden slide says so.** The heading of a slide that the slide show skips (`show="0"`) reads
1153
1471
  `## Slide 2 (hidden, not shown in the slide show)`. Its text is kept. Shapes hidden on a slide
1154
1472
  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,7 +254,7 @@ 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 |
258
260
  | **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) |
@@ -260,7 +262,7 @@ What each model gets, and what it costs: [An explorer model](docs/guides/explore
260
262
  | **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
263
  | **Cost** | Usage summed over every request of a question, for each model, with ceilings on whole-file reads, requests and input tokens |
262
264
  | **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)) |
265
+ | **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
266
  | **Storage** | In memory, on disk with expiry, or your own store (Redis, S3, a database) |
265
267
 
266
268
  ## Live results
@@ -301,7 +303,7 @@ Reference, one page per module:
301
303
  - [`llm-large-files/gemini`](docs/reference/gemini.md): `askGemini`, `gemini()`, `geminiApi()`, `vertexAi()`.
302
304
  - [`llm-large-files/openai`](docs/reference/openai.md): `openAiCompatible()` and its options.
303
305
  - [`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.
306
+ - [`llm-large-files/node`](docs/reference/node.md): `createDocumentHandlers`, its routes and responses, `createIsolatedExtractors`.
305
307
 
306
308
  [Changelog](CHANGELOG.md): what each version changed, and what to change in your code when you upgrade.
307
309
 
@@ -312,9 +314,9 @@ maintainers: [Contributing](https://github.com/renanbazinin/llm-large-files/blob
312
314
  ## Requirements
313
315
 
314
316
  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:
317
+ 22.12+. For DOCX, PPTX and XLSX install `jszip`, for PDF install `unpdf`, and to mark and show the
318
+ pages of a PDF, and refuse a page built to hold the server before it is read, install
319
+ `@cantoo/pdf-lib`. All three are optional:
318
320
 
319
321
  ```bash
320
322
  npm install jszip unpdf @cantoo/pdf-lib # Node 24 and later
package/dist/analyze.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  import type { TimeSlicer } from "./pause.js";
2
2
  import type { DocumentFormat, LogProfile, OutlineEntry } from "./types.js";
3
- /** Treats text as a log when most early lines start with a timestamp or a level. */
3
+ /** The level of a log line, in upper case ("ERROR", "WARN"), or undefined. */
4
+ export declare function levelOf(line: string): string | undefined;
5
+ /** Treats text as a log when most early lines start with a timestamp or a level, or have the shape of a log line. */
4
6
  export declare function looksLikeLog(lines: string[]): boolean;
5
7
  /** Headings with line numbers: Markdown, slide/page markers, and common book and report patterns. */
6
8
  export declare function buildOutline(lines: string[], format: DocumentFormat): OutlineEntry[];
@@ -1 +1 @@
1
- {"version":3,"file":"analyze.d.ts","sourceRoot":"","sources":["../src/analyze.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,OAAO,KAAK,EAAE,cAAc,EAAY,UAAU,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AASrF,oFAAoF;AACpF,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAMrD;AAED,qGAAqG;AACrG,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,cAAc,GAAG,YAAY,EAAE,CAQpF;AAED,kGAAkG;AAClG,wBAAsB,oBAAo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AAuB,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAOtG"}
package/dist/analyze.js CHANGED
@@ -1,11 +1,38 @@
1
1
  import { sliceWhole } from "./text.js";
2
2
  const MAX_OUTLINE_ENTRIES = 400;
3
3
  const MAX_TEMPLATES = 50_000;
4
- const TIMESTAMP = /\b\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}(?:[.,]\d+)?(?:Z|[+-]\d{2}:?\d{2})?/;
5
- const LINE_START_TIMESTAMP = /^\[?(?:\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}|\d{2}\/\d{2}\/\d{4}|\w{3} {1,2}\d{1,2} \d{2}:\d{2}:\d{2}|\d{2}:\d{2}:\d{2})/;
4
+ /**
5
+ * Timestamps of logs: ISO 8601 (2026-11-10T14:03:17.120Z), nginx's error log (2026/11/10
6
+ * 14:03:17), the access logs of Apache and nginx (10/Nov/2026:14:03:17 +0000), and syslog (Nov 10
7
+ * 14:03:17).
8
+ */
9
+ const TIMESTAMP = /\b\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}(?:[.,]\d+)?(?:Z|[+-]\d{2}:?\d{2})?|\b\d{4}\/\d{2}\/\d{2} \d{2}:\d{2}:\d{2}|\b\d{2}\/[A-Z][a-z]{2}\/\d{4}:\d{2}:\d{2}:\d{2}(?: [+-]\d{4})?|\b[A-Z][a-z]{2} {1,2}\d{1,2} \d{2}:\d{2}:\d{2}/;
10
+ const LINE_START_TIMESTAMP = /^\[?(?:\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}|\d{4}\/\d{2}\/\d{2} \d{2}:\d{2}|\d{2}\/\d{2}\/\d{4}|\d{2}\.\d{2}\.\d{4} \d{2}:\d{2}|\w{3} {1,2}\d{1,2} \d{2}:\d{2}:\d{2}|\d{2}:\d{2}:\d{2})/;
11
+ /** Other shapes of log lines: an access log, a JSON log, klog, logfmt. */
12
+ const LOG_LINE = /^(?:\d{1,3}(?:\.\d{1,3}){3} \S+ \S+ \[\d{2}\/\w{3}\/\d{4}:|\{.*"(?:level|severity|time|timestamp|ts|@timestamp)"\s*:|[IWEF]\d{4} \d{2}:\d{2}:\d{2}|(?:time|ts|level|lvl)=)/;
13
+ /** A level word in upper case, anywhere on the line. */
6
14
  const LEVEL = /\b(FATAL|CRITICAL|ERROR|ERR|WARN|WARNING|INFO|DEBUG|TRACE)\b/;
7
- const LEVEL_NAMES = { ERR: "ERROR", WARNING: "WARN", CRITICAL: "FATAL" };
8
- /** Treats text as a log when most early lines start with a timestamp or a level. */
15
+ /**
16
+ * A level in lower or mixed case, where logs put one: in brackets as nginx and Apache do
17
+ * ("[error]"), after `level=` as logfmt, zap and logrus do, or in a JSON field ("level":"warn").
18
+ */
19
+ const MARKED_LEVEL = /(?:\[|\b(?:level|lvl|severity)=\s*"?|"(?:level|severity)"\s*:\s*")(fatal|critical|crit|emerg|alert|error|err|warning|warn|notice|info|debug|trace)\b/i;
20
+ /** pino and bunyan write the level as a number. */
21
+ const NUMBER_LEVEL = /"level"\s*:\s*(10|20|30|40|50|60)\b/;
22
+ const NUMBER_LEVELS = { 10: "TRACE", 20: "DEBUG", 30: "INFO", 40: "WARN", 50: "ERROR", 60: "FATAL" };
23
+ /** klog and glog start a line with the level's letter, then the month and day. */
24
+ const LETTER_LEVEL = /^([IWEF])\d{4} \d{2}:\d{2}:\d{2}/;
25
+ const LETTER_LEVELS = { I: "INFO", W: "WARN", E: "ERROR", F: "FATAL" };
26
+ const LEVEL_NAMES = { ERR: "ERROR", WARNING: "WARN", CRITICAL: "FATAL", CRIT: "FATAL", EMERG: "FATAL", ALERT: "FATAL", NOTICE: "INFO" };
27
+ /** The level of a log line, in upper case ("ERROR", "WARN"), or undefined. */
28
+ export function levelOf(line) {
29
+ const raw = LEVEL.exec(line)?.[1]
30
+ ?? MARKED_LEVEL.exec(line)?.[1]?.toUpperCase()
31
+ ?? NUMBER_LEVELS[NUMBER_LEVEL.exec(line)?.[1] ?? ""]
32
+ ?? LETTER_LEVELS[LETTER_LEVEL.exec(line)?.[1] ?? ""];
33
+ return raw === undefined ? undefined : LEVEL_NAMES[raw] ?? raw;
34
+ }
35
+ /** Treats text as a log when most early lines start with a timestamp or a level, or have the shape of a log line. */
9
36
  export function looksLikeLog(lines) {
10
37
  const sample = [];
11
38
  for (let index = 0; index < lines.length && sample.length < 200; index++)
@@ -13,16 +40,46 @@ export function looksLikeLog(lines) {
13
40
  sample.push(lines[index]);
14
41
  if (sample.length < 5)
15
42
  return false;
16
- const hits = sample.filter((line) => LINE_START_TIMESTAMP.test(line.trim()) || /^\[?(FATAL|ERROR|WARN|WARNING|INFO|DEBUG|TRACE)\b/.test(line.trim())).length;
43
+ const hits = sample.filter((line) => {
44
+ const trimmed = line.trim();
45
+ return LINE_START_TIMESTAMP.test(trimmed) || LOG_LINE.test(trimmed) || /^\[?(FATAL|ERROR|WARN|WARNING|INFO|DEBUG|TRACE)\b/i.test(trimmed);
46
+ }).length;
17
47
  return hits / sample.length >= 0.4;
18
48
  }
49
+ /** A line that opens or closes a fenced code block of Markdown: ``` or ~~~. */
50
+ const FENCE = /^\s{0,3}(`{3,}|~{3,})/;
51
+ /**
52
+ * Follows fenced code blocks line by line: a "# comment" in a block of shell or Python is not a
53
+ * heading. A fence closes with the same character, at least as long.
54
+ */
55
+ class Fences {
56
+ open;
57
+ /** Whether line `line` is inside a block, its fences included. */
58
+ inside(line) {
59
+ const fence = FENCE.exec(line)?.[1];
60
+ if (this.open !== undefined) {
61
+ if (fence && fence[0] === this.open[0] && fence.length >= this.open.length && line.trim() === fence)
62
+ this.open = undefined;
63
+ return true;
64
+ }
65
+ if (fence) {
66
+ this.open = fence;
67
+ return true;
68
+ }
69
+ return false;
70
+ }
71
+ }
19
72
  /** Headings with line numbers: Markdown, slide/page markers, and common book and report patterns. */
20
73
  export function buildOutline(lines, format) {
21
74
  if (format === "log" || format === "json" || format === "csv")
22
75
  return [];
23
76
  const entries = [];
77
+ const fences = new Fences();
78
+ const hashes = hashHeadings(lines, format);
24
79
  for (let index = 0; index < lines.length; index++) {
25
- const entry = outlineEntry(lines, index);
80
+ if (fences.inside(lines[index] ?? ""))
81
+ continue;
82
+ const entry = outlineEntry(lines, index, hashes);
26
83
  if (entry)
27
84
  entries.push(entry);
28
85
  }
@@ -33,24 +90,63 @@ export async function buildOutlineInSlices(lines, format, slicer) {
33
90
  if (format === "log" || format === "json" || format === "csv")
34
91
  return [];
35
92
  const entries = [];
93
+ const fences = new Fences();
94
+ const hashes = hashHeadings(lines, format);
36
95
  for (let index = 0; index < lines.length; index++) {
37
- const entry = outlineEntry(lines, index);
38
- if (entry)
39
- entries.push(entry);
40
96
  if ((index & 4095) === 4095)
41
97
  await slicer.maybePause();
98
+ if (fences.inside(lines[index] ?? ""))
99
+ continue;
100
+ const entry = outlineEntry(lines, index, hashes);
101
+ if (entry)
102
+ entries.push(entry);
42
103
  }
43
104
  return pickOutline(entries);
44
105
  }
106
+ /** Whether a line is a "# " line: a Markdown heading, or a comment of a script or a configuration file. */
107
+ const hashLine = (line) => /^\s*#{1,6}\s/.test(line ?? "");
108
+ /**
109
+ * A line only code has: a shebang, an include, an import, a definition. One is enough. No two
110
+ * repeats in a row can match the same characters: `function\s*\w*\s*\(` split a run of spaces
111
+ * after "function" between its two `\s*` in as many ways as it is long, and a line of "function",
112
+ * 2,000 spaces and "x" took 20 ms; 300 of them held the server 8 seconds.
113
+ */
114
+ const CODE_LINE = /^(?:#!\/|#include\b|import\s+[\w{*"']|from\s+[\w.]+\s+import\b|def\s+\w+\s*\(|class\s+\w+[\s:({]|function\s*(?:\w+\s*)?\(|package\s+[\w.]+;?\s*$|using\s+[\w.]+;\s*$)/;
115
+ /** A line common in code and configuration files, and rarer in prose: three are needed. */
116
+ const CODE_LIKE_LINE = /^(?:(?:const|let|var|export|public|private|return)\s|(?:if|for|while)\s*\(|echo\s|set\s+-\w|[A-Za-z_][\w.-]*\s*=\s*\S|[}\])];?$)/;
117
+ /**
118
+ * Whether a plain text file is a script, source code or a configuration file, where "# " starts
119
+ * a comment, not a heading: one of its first lines only code has, or three that code often has.
120
+ */
121
+ function looksLikeCode(lines) {
122
+ let likely = 0;
123
+ for (let index = 0; index < lines.length && index < 300; index++) {
124
+ // Trimmed first, and the end looked at apart: a regex over the leading spaces backtracked by their square.
125
+ const line = (lines[index] ?? "").trim();
126
+ if (CODE_LINE.test(line))
127
+ return true;
128
+ if ((CODE_LIKE_LINE.test(line) || line.endsWith("{") || line.endsWith(";")) && ++likely >= 3)
129
+ return true;
130
+ }
131
+ return false;
132
+ }
133
+ function hashHeadings(lines, format) {
134
+ if (format !== "text")
135
+ return "all";
136
+ return looksLikeCode(lines) ? "none" : "strict";
137
+ }
45
138
  /** The heading on line `index` (0-based), if it is one. */
46
- function outlineEntry(lines, index) {
139
+ function outlineEntry(lines, index, hashes = "all") {
47
140
  const line = (lines[index] ?? "").trim();
48
141
  if (!line || line.length > 120)
49
142
  return undefined;
50
143
  const previousBlank = index === 0 || !(lines[index - 1] ?? "").trim();
51
144
  const markdown = /^(#{1,6})\s+(.+)$/.exec(line);
52
- if (markdown)
145
+ if (markdown) {
146
+ if (hashes === "none" || (hashes === "strict" && (!previousBlank || hashLine(lines[index + 1]))))
147
+ return undefined;
53
148
  return { line: index + 1, level: markdown[1].length, title: markdown[2].trim() };
149
+ }
54
150
  // A lookahead, not \b: JavaScript's \b does not treat Hebrew letters as word characters.
55
151
  if (/^(chapter|part|book|section|appendix|פרק|חלק|נספח)(?=[\s:.\d]|$)/iu.test(line) && previousBlank) {
56
152
  return { line: index + 1, level: /^(part|book|חלק)(?=[\s:.\d]|$)/iu.test(line) ? 1 : 2, title: line };
@@ -125,10 +221,9 @@ class LogProfiler {
125
221
  this.firstTimestamp ??= stamp;
126
222
  this.lastTimestamp = stamp;
127
223
  }
128
- const raw = LEVEL.exec(line)?.[1];
129
- if (!raw)
224
+ const level = levelOf(line);
225
+ if (!level)
130
226
  return;
131
- const level = LEVEL_NAMES[raw] ?? raw;
132
227
  this.levels[level] = (this.levels[level] ?? 0) + 1;
133
228
  if (level !== "ERROR" && level !== "FATAL" && level !== "WARN")
134
229
  return;
@@ -1 +1 @@
1
- {"version":3,"file":"analyze.js","sourceRoot":"","sources":["../src/analyze.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAGvC,MAAM,mBAAmB,GAAG,GAAG,CAAC;AAChC,MAAM,aAAa,GAAG,MAAM,CAAC;AAC7B,MAAM,SAAS,GAAG,6EAA6E,CAAC;AAChG,MAAM,oBAAoB,GAAG,qHAAqH,CAAC;AACnJ,MAAM,KAAK,GAAG,8DAA8D,CAAC;AAC7E,MAAM,WAAW,GAA2B,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC;AAEjG,oFAAoF;AACpF,MAAM,UAAU,YAAY,CAAC,KAAe;IAC1C,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,GAAG,GAAG,EAAE,KAAK,EAAE;QAAE,IAAI,KAAK,CAAC,KAAK,CAAE,CAAC,IAAI,EAAE;YAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAE,CAAC,CAAC;IAC/H,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,KAAK,CAAC;IACpC,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,IAAI,mDAAmD,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;IAC7J,OAAO,IAAI,GAAG,MAAM,CAAC,MAAM,I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