llm-large-files 0.8.2 → 0.10.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 (288) hide show
  1. package/CHANGELOG.md +981 -0
  2. package/README.md +22 -17
  3. package/dist/access.d.ts +128 -0
  4. package/dist/access.d.ts.map +1 -0
  5. package/dist/access.js +234 -0
  6. package/dist/access.js.map +1 -0
  7. package/dist/aggregate.d.ts +6 -0
  8. package/dist/aggregate.d.ts.map +1 -1
  9. package/dist/aggregate.js +86 -13
  10. package/dist/aggregate.js.map +1 -1
  11. package/dist/analyze.d.ts +4 -0
  12. package/dist/analyze.d.ts.map +1 -1
  13. package/dist/analyze.js +2 -2
  14. package/dist/analyze.js.map +1 -1
  15. package/dist/answer-info.d.ts +26 -0
  16. package/dist/answer-info.d.ts.map +1 -0
  17. package/dist/answer-info.js +32 -0
  18. package/dist/answer-info.js.map +1 -0
  19. package/dist/anthropic/adapter.d.ts +5 -1
  20. package/dist/anthropic/adapter.d.ts.map +1 -1
  21. package/dist/anthropic/adapter.js +35 -10
  22. package/dist/anthropic/adapter.js.map +1 -1
  23. package/dist/ask.d.ts +159 -14
  24. package/dist/ask.d.ts.map +1 -1
  25. package/dist/ask.js +743 -113
  26. package/dist/ask.js.map +1 -1
  27. package/dist/cache.d.ts +12 -3
  28. package/dist/cache.d.ts.map +1 -1
  29. package/dist/cache.js +18 -5
  30. package/dist/cache.js.map +1 -1
  31. package/dist/citations.d.ts +36 -0
  32. package/dist/citations.d.ts.map +1 -0
  33. package/dist/citations.js +291 -0
  34. package/dist/citations.js.map +1 -0
  35. package/dist/encoding.js +5 -3
  36. package/dist/encoding.js.map +1 -1
  37. package/dist/error-info.d.ts +70 -0
  38. package/dist/error-info.d.ts.map +1 -0
  39. package/dist/error-info.js +253 -0
  40. package/dist/error-info.js.map +1 -0
  41. package/dist/errors.d.ts +74 -8
  42. package/dist/errors.d.ts.map +1 -1
  43. package/dist/errors.js +104 -15
  44. package/dist/errors.js.map +1 -1
  45. package/dist/events.d.ts +57 -13
  46. package/dist/events.d.ts.map +1 -1
  47. package/dist/events.js +42 -11
  48. package/dist/events.js.map +1 -1
  49. package/dist/evidence.d.ts +4 -2
  50. package/dist/evidence.d.ts.map +1 -1
  51. package/dist/evidence.js +35 -5
  52. package/dist/evidence.js.map +1 -1
  53. package/dist/extract.d.ts +32 -8
  54. package/dist/extract.d.ts.map +1 -1
  55. package/dist/extract.js +52 -36
  56. package/dist/extract.js.map +1 -1
  57. package/dist/gemini/adapter.d.ts +54 -7
  58. package/dist/gemini/adapter.d.ts.map +1 -1
  59. package/dist/gemini/adapter.js +152 -41
  60. package/dist/gemini/adapter.js.map +1 -1
  61. package/dist/gemini/chat.d.ts +38 -53
  62. package/dist/gemini/chat.d.ts.map +1 -1
  63. package/dist/gemini/chat.js +20 -25
  64. package/dist/gemini/chat.js.map +1 -1
  65. package/dist/gemini/endpoints.d.ts +59 -11
  66. package/dist/gemini/endpoints.d.ts.map +1 -1
  67. package/dist/gemini/endpoints.js +33 -7
  68. package/dist/gemini/endpoints.js.map +1 -1
  69. package/dist/gemini/errors.d.ts +39 -5
  70. package/dist/gemini/errors.d.ts.map +1 -1
  71. package/dist/gemini/errors.js +70 -9
  72. package/dist/gemini/errors.js.map +1 -1
  73. package/dist/gemini/generate.d.ts +53 -2
  74. package/dist/gemini/generate.d.ts.map +1 -1
  75. package/dist/gemini/generate.js +100 -50
  76. package/dist/gemini/generate.js.map +1 -1
  77. package/dist/gemini/index.d.ts +4 -4
  78. package/dist/gemini/index.d.ts.map +1 -1
  79. package/dist/http.d.ts +41 -3
  80. package/dist/http.d.ts.map +1 -1
  81. package/dist/http.js +40 -2
  82. package/dist/http.js.map +1 -1
  83. package/dist/index.d.ts +13 -8
  84. package/dist/index.d.ts.map +1 -1
  85. package/dist/index.js +8 -5
  86. package/dist/index.js.map +1 -1
  87. package/dist/ingest.d.ts +78 -0
  88. package/dist/ingest.d.ts.map +1 -0
  89. package/dist/ingest.js +893 -0
  90. package/dist/ingest.js.map +1 -0
  91. package/dist/library.d.ts +295 -33
  92. package/dist/library.d.ts.map +1 -1
  93. package/dist/library.js +458 -650
  94. package/dist/library.js.map +1 -1
  95. package/dist/map-reduce.d.ts +176 -10
  96. package/dist/map-reduce.d.ts.map +1 -1
  97. package/dist/map-reduce.js +807 -61
  98. package/dist/map-reduce.js.map +1 -1
  99. package/dist/model.d.ts +79 -6
  100. package/dist/model.d.ts.map +1 -1
  101. package/dist/model.js +80 -4
  102. package/dist/model.js.map +1 -1
  103. package/dist/node/handlers.d.ts +247 -14
  104. package/dist/node/handlers.d.ts.map +1 -1
  105. package/dist/node/handlers.js +491 -227
  106. package/dist/node/handlers.js.map +1 -1
  107. package/dist/node/index.d.ts +3 -2
  108. package/dist/node/index.d.ts.map +1 -1
  109. package/dist/node/index.js +2 -1
  110. package/dist/node/index.js.map +1 -1
  111. package/dist/node/ingest-child.d.ts +7 -1
  112. package/dist/node/ingest-child.d.ts.map +1 -1
  113. package/dist/node/ingest-child.js +19 -4
  114. package/dist/node/ingest-child.js.map +1 -1
  115. package/dist/node/isolated.d.ts +3 -1
  116. package/dist/node/isolated.d.ts.map +1 -1
  117. package/dist/node/isolated.js +11 -4
  118. package/dist/node/isolated.js.map +1 -1
  119. package/dist/node/originals.d.ts +19 -0
  120. package/dist/node/originals.d.ts.map +1 -0
  121. package/dist/node/originals.js +82 -0
  122. package/dist/node/originals.js.map +1 -0
  123. package/dist/node/spool.d.ts +106 -0
  124. package/dist/node/spool.d.ts.map +1 -0
  125. package/dist/node/spool.js +378 -0
  126. package/dist/node/spool.js.map +1 -0
  127. package/dist/node/sse.d.ts +6 -4
  128. package/dist/node/sse.d.ts.map +1 -1
  129. package/dist/node/sse.js +9 -7
  130. package/dist/node/sse.js.map +1 -1
  131. package/dist/openai/adapter.d.ts +5 -1
  132. package/dist/openai/adapter.d.ts.map +1 -1
  133. package/dist/openai/adapter.js +53 -12
  134. package/dist/openai/adapter.js.map +1 -1
  135. package/dist/output-limit.d.ts +2 -1
  136. package/dist/output-limit.d.ts.map +1 -1
  137. package/dist/output-limit.js +5 -2
  138. package/dist/output-limit.js.map +1 -1
  139. package/dist/pdf-layout.d.ts.map +1 -1
  140. package/dist/pdf-layout.js +71 -12
  141. package/dist/pdf-layout.js.map +1 -1
  142. package/dist/pdf-outline.d.ts +71 -0
  143. package/dist/pdf-outline.d.ts.map +1 -0
  144. package/dist/pdf-outline.js +414 -0
  145. package/dist/pdf-outline.js.map +1 -0
  146. package/dist/plan.d.ts +137 -7
  147. package/dist/plan.d.ts.map +1 -1
  148. package/dist/plan.js +248 -26
  149. package/dist/plan.js.map +1 -1
  150. package/dist/prepare.d.ts +50 -0
  151. package/dist/prepare.d.ts.map +1 -0
  152. package/dist/prepare.js +207 -0
  153. package/dist/prepare.js.map +1 -0
  154. package/dist/ranged.d.ts +16 -11
  155. package/dist/ranged.d.ts.map +1 -1
  156. package/dist/ranged.js +56 -12
  157. package/dist/ranged.js.map +1 -1
  158. package/dist/retry.d.ts +3 -1
  159. package/dist/retry.d.ts.map +1 -1
  160. package/dist/retry.js +6 -2
  161. package/dist/retry.js.map +1 -1
  162. package/dist/scope.d.ts +25 -0
  163. package/dist/scope.d.ts.map +1 -0
  164. package/dist/scope.js +60 -0
  165. package/dist/scope.js.map +1 -0
  166. package/dist/search.d.ts +7 -0
  167. package/dist/search.d.ts.map +1 -1
  168. package/dist/search.js +72 -10
  169. package/dist/search.js.map +1 -1
  170. package/dist/source.d.ts +60 -0
  171. package/dist/source.d.ts.map +1 -0
  172. package/dist/source.js +170 -0
  173. package/dist/source.js.map +1 -0
  174. package/dist/stores.d.ts +126 -31
  175. package/dist/stores.d.ts.map +1 -1
  176. package/dist/stores.js +655 -141
  177. package/dist/stores.js.map +1 -1
  178. package/dist/testing/fake-fetch.d.ts +31 -0
  179. package/dist/testing/fake-fetch.d.ts.map +1 -0
  180. package/dist/testing/fake-fetch.js +66 -0
  181. package/dist/testing/fake-fetch.js.map +1 -0
  182. package/dist/testing/fake-model.d.ts +38 -0
  183. package/dist/testing/fake-model.d.ts.map +1 -0
  184. package/dist/testing/fake-model.js +62 -0
  185. package/dist/testing/fake-model.js.map +1 -0
  186. package/dist/testing/index.d.ts +7 -0
  187. package/dist/testing/index.d.ts.map +1 -0
  188. package/dist/testing/index.js +9 -0
  189. package/dist/testing/index.js.map +1 -0
  190. package/dist/testing/store-checks.d.ts +72 -0
  191. package/dist/testing/store-checks.d.ts.map +1 -0
  192. package/dist/testing/store-checks.js +619 -0
  193. package/dist/testing/store-checks.js.map +1 -0
  194. package/dist/tools.d.ts +47 -2
  195. package/dist/tools.d.ts.map +1 -1
  196. package/dist/tools.js +440 -71
  197. package/dist/tools.js.map +1 -1
  198. package/dist/types.d.ts +165 -14
  199. package/dist/types.d.ts.map +1 -1
  200. package/dist/whole-cost.d.ts +37 -0
  201. package/dist/whole-cost.d.ts.map +1 -0
  202. package/dist/whole-cost.js +46 -0
  203. package/dist/whole-cost.js.map +1 -0
  204. package/docs/README.md +21 -8
  205. package/docs/getting-started.md +18 -13
  206. package/docs/guides/anthropic.md +17 -10
  207. package/docs/guides/conversations.md +112 -47
  208. package/docs/guides/costs-and-limits.md +147 -42
  209. package/docs/guides/deployment.md +380 -86
  210. package/docs/guides/errors-and-reliability.md +317 -67
  211. package/docs/guides/explorer-model.md +4 -1
  212. package/docs/guides/openai-compatible.md +47 -7
  213. package/docs/guides/own-adapter-and-loop.md +60 -16
  214. package/docs/guides/pdfs.md +219 -36
  215. package/docs/guides/storage.md +676 -145
  216. package/docs/guides/testing.md +149 -129
  217. package/docs/guides/vertex-and-gemini.md +169 -57
  218. package/docs/guides/web-app.md +318 -80
  219. package/docs/how-it-works.md +155 -30
  220. package/docs/measurements.md +215 -13
  221. package/docs/publishing.md +185 -37
  222. package/docs/reference/anthropic.md +12 -7
  223. package/docs/reference/ask.md +415 -47
  224. package/docs/reference/errors-and-retries.md +194 -14
  225. package/docs/reference/events.md +77 -27
  226. package/docs/reference/gemini.md +252 -87
  227. package/docs/reference/library.md +886 -178
  228. package/docs/reference/node.md +659 -111
  229. package/docs/reference/openai.md +21 -10
  230. package/docs/reference/testing.md +311 -0
  231. package/docs/reference/tools.md +285 -30
  232. package/docs/security.md +404 -78
  233. package/docs/troubleshooting.md +151 -70
  234. package/docs/upgrading-0.10.md +472 -0
  235. package/docs/upgrading-0.9.md +890 -0
  236. package/package.json +16 -3
  237. package/src/access.ts +267 -0
  238. package/src/aggregate.ts +92 -14
  239. package/src/analyze.ts +2 -2
  240. package/src/answer-info.ts +45 -0
  241. package/src/anthropic/adapter.ts +40 -11
  242. package/src/ask.ts +866 -115
  243. package/src/cache.ts +20 -5
  244. package/src/citations.ts +294 -0
  245. package/src/encoding.ts +6 -4
  246. package/src/error-info.ts +290 -0
  247. package/src/errors.ts +131 -15
  248. package/src/events.ts +112 -24
  249. package/src/evidence.ts +35 -5
  250. package/src/extract.ts +56 -34
  251. package/src/gemini/adapter.ts +196 -43
  252. package/src/gemini/chat.ts +63 -78
  253. package/src/gemini/endpoints.ts +89 -16
  254. package/src/gemini/errors.ts +74 -11
  255. package/src/gemini/generate.ts +147 -57
  256. package/src/gemini/index.ts +4 -4
  257. package/src/http.ts +65 -4
  258. package/src/index.ts +13 -8
  259. package/src/ingest.ts +958 -0
  260. package/src/library.ts +711 -651
  261. package/src/map-reduce.ts +858 -70
  262. package/src/model.ts +113 -9
  263. package/src/node/handlers.ts +709 -221
  264. package/src/node/index.ts +14 -2
  265. package/src/node/ingest-child.ts +24 -6
  266. package/src/node/isolated.ts +11 -4
  267. package/src/node/originals.ts +78 -0
  268. package/src/node/spool.ts +379 -0
  269. package/src/node/sse.ts +9 -7
  270. package/src/openai/adapter.ts +56 -13
  271. package/src/output-limit.ts +5 -2
  272. package/src/pdf-layout.ts +69 -11
  273. package/src/pdf-outline.ts +400 -0
  274. package/src/plan.ts +287 -36
  275. package/src/prepare.ts +253 -0
  276. package/src/ranged.ts +48 -14
  277. package/src/retry.ts +6 -2
  278. package/src/scope.ts +63 -0
  279. package/src/search.ts +69 -13
  280. package/src/source.ts +178 -0
  281. package/src/stores.ts +702 -142
  282. package/src/testing/fake-fetch.ts +80 -0
  283. package/src/testing/fake-model.ts +78 -0
  284. package/src/testing/index.ts +11 -0
  285. package/src/testing/store-checks.ts +660 -0
  286. package/src/tools.ts +461 -73
  287. package/src/types.ts +151 -14
  288. package/src/whole-cost.ts +64 -0
@@ -91,9 +91,9 @@ What each error and `kind` means, and what to tell your user, is in
91
91
  ### `require("llm-large-files")` throws `ERR_REQUIRE_ESM`
92
92
 
93
93
  **Cause.** The package is an ES module only. CommonJS code can load it with `require()` only on the
94
- Node versions that load ES modules that way by default: 20.19 and later in Node 20, 22.12 and later
95
- in Node 22, and 23 and later. Node 21 and Node 22.0 to 22.11 refuse. The library needs Node 20.19
96
- or later in any case.
94
+ Node versions that load ES modules that way by default: 22.12 and later in Node 22, and 23 and
95
+ later. Node 22.0 to 22.11 refuse. The library needs Node 22.12 or later in any case (20.19 until
96
+ 0.9.0).
97
97
 
98
98
  **Fix.** Upgrade Node, or load the package from CommonJS with `await import("llm-large-files")`
99
99
  (and `import("llm-large-files/gemini")` and so on for the other entry points). In TypeScript this
@@ -123,10 +123,9 @@ as `devDependencies` and left out of the production install, or missing from the
123
123
  bundle you deploy.
124
124
 
125
125
  **Fix.** Install them as dependencies of the application that runs the upload route and the
126
- questions: `npm install jszip unpdf @cantoo/pdf-lib` on Node 24 and later. On Node 20 and 22, name
127
- a version of `unpdf` that runs there: `npm install jszip unpdf@1 @cantoo/pdf-lib` on Node 22, and
128
- `npm install jszip unpdf@1.7.0 @cantoo/pdf-lib` on Node 20 (see
129
- [below](#a-pdf-upload-fails-the-unpdf-installed-cannot-read-pdf-files-or-would-stop-the-whole-server)).
126
+ questions: `npm install jszip unpdf @cantoo/pdf-lib` on Node 24 and later. On Node 22, name a
127
+ version of `unpdf` that runs there: `npm install jszip unpdf@1 @cantoo/pdf-lib` (see
128
+ [below](#a-pdf-upload-fails-the-unpdf-installed-would-stop-the-whole-server)).
130
129
  Install `@cantoo/pdf-lib` before PDFs are uploaded: without it nothing fails at upload, but the
131
130
  text of a PDF is written without the line that marks a page with a picture
132
131
  (`[Picture on this page. This text cannot show it.]`), and a document keeps the text it was
@@ -134,41 +133,35 @@ ingested with.
134
133
 
135
134
  See [PDFs and other formats](./guides/pdfs.md).
136
135
 
137
- ### A PDF upload fails: "The unpdf installed cannot read PDF files" or "would stop the whole server"
136
+ ### A PDF upload fails: "The unpdf installed would stop the whole server"
138
137
 
139
- `files.ingest` throws one of these, and the upload handler answers `422` with it:
138
+ `files.ingest` throws this, and the upload handler answers `422` with it:
140
139
 
141
- - `The unpdf installed would stop the whole server at the first PDF file on Node 22, so PDF files are not read. Install unpdf 1.6.1 or later, or run Node 24 or later.`
142
- - `The unpdf installed would stop the whole server at the first PDF file on Node 20, so PDF files are not read. Install unpdf 1.7.0 (npm install unpdf@1.7.0), or run Node 24 or later.`
143
- - `The unpdf installed cannot read PDF files on Node 20 (Serverless PDF.js bundle could not be resolved: ReferenceError: Iterator is not defined). Install unpdf 1.7.0 (npm install unpdf@1.7.0), or run Node 22 or later.`
144
- The text in brackets is unpdf's own message, and differs between its versions.
140
+ `The unpdf installed would stop the whole server at the first PDF file on Node 22, so PDF files are not read. Install unpdf 1.6.1 or later, or run Node 24 or later.`
145
141
 
146
142
  The number is the major version of the Node that runs the server. DOCX, PPTX and text files are
147
143
  read as before.
148
144
 
149
- **Cause.** The version of `unpdf` that is installed cannot read PDFs on this version of Node, and
150
- 0.6.0 checks it before it reads a PDF:
151
-
152
- - unpdf 1.5.0 to 1.6.0 load a pdf.js that calls `Promise.try`, which Node 20 and 22 do not have. In
153
- 0.5.0 the first PDF stopped the whole process, with a `TypeError` that nothing could catch.
154
- - unpdf 1.9 and later, 2.x included, load a pdf.js that needs Node 22. On Node 20, every PDF failed
155
- with unpdf's message alone.
145
+ **Cause.** unpdf 1.5.0 to 1.6.0 load a pdf.js that calls `Promise.try`, which Node 22 does not
146
+ have. In 0.5.0 the first PDF stopped the whole process, with a `TypeError` that nothing could
147
+ catch. Since 0.6.0 the library checks it before it reads a PDF.
156
148
 
157
- unpdf 2 asks for Node 24, and on Node 24 a plain `npm install unpdf` installs it. On Node 22 and
158
- later, a pdf.js that cannot be loaded for another reason fails with unpdf's message, as before.
149
+ unpdf 2 asks for Node 24, and on Node 24 a plain `npm install unpdf` installs it. A pdf.js that
150
+ cannot be loaded for another reason fails with unpdf's own message. (Until 0.9.0, on Node 20, that
151
+ failure came as `The unpdf installed cannot read PDF files on Node 20 (…)`. Node 20 is no longer
152
+ supported.)
159
153
 
160
- **Fix.** Install the `unpdf` that runs on your Node, or move to the Node the message names:
154
+ **Fix.** Install the `unpdf` that runs on your Node, or move to Node 24:
161
155
 
162
156
  | Node | `unpdf` to install |
163
157
  |---|---|
164
- | 20 | 1.4.0, or 1.6.1 to 1.8.1: `npm install unpdf@1.7.0`. 1.7.0 is the last that does not ask for Node 22. |
165
158
  | 22 | 1.4.0, or 1.6.1 or a later 1.x: `npm install unpdf@1`. |
166
159
  | 24 and later | Any version from 1.4.0, 2.x included: `npm install unpdf`. |
167
160
 
168
161
  If the server loads pdf.js when it starts, as [Deployment](./guides/deployment.md#uploads-and-ingest)
169
- shows, an `unpdf` that cannot load pdf.js on that Node (1.9 and later on Node 20) makes the start
170
- fail instead. With unpdf 1.5.0 to 1.6.0 on Node 20 or 22, pdf.js loads and the server starts: PDFs
171
- are then refused at upload, with one of the `would stop the whole server` messages above.
162
+ shows, an `unpdf` that cannot load pdf.js on that Node makes the start fail instead. With unpdf
163
+ 1.5.0 to 1.6.0 on Node 22, pdf.js loads and the server starts: PDFs are then refused at upload,
164
+ with the message above.
172
165
 
173
166
  See [PDFs and other formats](./guides/pdfs.md#formats).
174
167
 
@@ -265,16 +258,25 @@ New in 0.8.2. `createDocumentHandlers` answers `503` with `Retry-After: 5`, befo
265
258
  **Cause.** The handlers already hold uploads, and this one would bring them past
266
259
  `maxPendingUploadBytes` (twice `maxUploadBytes`, 200 MB by default). An upload is held from the
267
260
  reading of its body to the end of its ingest, and its room is taken from its `Content-Length`
268
- before its body arrives. Many users sending files at once, or a few clients that send their
269
- headers and then their bodies slowly, fill it.
261
+ before its body arrives (`maxUploadBytes` for a body sent without a `Content-Length`, until it is
262
+ read: two such uploads fill the default room). Many users sending files at once, or a few clients
263
+ that send their headers and then their bodies slowly, fill it. With `uploadSpool` (new in 0.9.0),
264
+ the same answer comes when the spool's files reach `maxSpooledUploadBytes`.
270
265
 
271
266
  **Fix.** Send the file again after `Retry-After` seconds, as the browser code in
272
267
  [Web app](./guides/web-app.md#upload-from-the-browser) does. To take more at once, raise
273
- `maxPendingUploadBytes` and size the server for it (each upload under way takes about five to seven
274
- times its size while it is ingested; ingests take turns, `maxConcurrentIngests`). Put a proxy that
275
- reads whole bodies before passing them on in front, so that slow clients hold no room. "The server
276
- is reading other files right now." is the other `503`: the readers of `createIsolatedExtractors`
277
- are busy ([Node reference](./reference/node.md#uploadrequest-response)).
268
+ `maxPendingUploadBytes` and size the server for it (each upload under way takes about three and a
269
+ half to five and a half times its size while it is ingested over a `FileDocumentStore`,
270
+ [measurements](./measurements.md#the-server); ingests take turns, `maxConcurrentIngests`). Put a
271
+ proxy that reads whole bodies before passing them on in front, so that slow clients hold no room.
272
+ Or take the bodies off the heap: `uploadSpool` writes the larger ones, and those without a
273
+ `Content-Length`, to temporary files, and `maxPendingUploadBytes` then counts only the bodies kept
274
+ in memory ([Deployment](./guides/deployment.md#uploads-and-ingest)).
275
+ "The server is reading other files right now." is another `503`: the readers of
276
+ `createIsolatedExtractors` are busy ([Node reference](./reference/node.md#uploadrequest-response)).
277
+ So is "The server has no room for this file right now. Try again later." (new in 0.9.0, with
278
+ `Retry-After: 30`): the disk the body was written to, the spool's or the folder of
279
+ `prepareUpload`, is full.
278
280
 
279
281
  ### `408`: "The upload stopped arriving: nothing came for 30 s. Send it again."
280
282
 
@@ -283,6 +285,23 @@ the client's connection stalled, or a proxy held the body. The connection is clo
283
285
  the file again. For users on slow or unsteady links, raise `uploadIdleTimeoutMs` of
284
286
  `createDocumentHandlers`.
285
287
 
288
+ ### `503`: "Upload failed (ETIMEDOUT)." and `500`: "Upload failed (ELOOP)."
289
+
290
+ New in 0.9.0, for a body written to a file (the `path` of `prepareUpload`, or `uploadSpool`).
291
+
292
+ - **"ETIMEDOUT"**, a `503` with `Retry-After: 5` (a `500` before 0.10.0). A call to the disk
293
+ (checking the folders of a path with a ref, opening the file, a write, closing it) did not end
294
+ within `uploadIdleTimeoutMs` (30 s): the volume stopped answering, such as a network volume whose
295
+ server is gone. The upload's room is given back, and the file is removed once the volume answers.
296
+ **Fix.** Check the volume. The client may send the file again after `Retry-After`. A slow network
297
+ volume can take long to close a file it held writes for: raise `uploadIdleTimeoutMs`.
298
+ - **"ELOOP"**, a `500`. `prepareUpload` gave a path that ends with the ref of its `original`, and a folder
299
+ between that root and the file is a link. `fileOriginals` would never read the file back through
300
+ it, so nothing is written. **Fix.** Replace the link with the folder itself, or mount the other
301
+ disk there. The root itself may be a link.
302
+
303
+ See [saving the body](./reference/node.md#saving-the-body-prepareupload).
304
+
286
305
  ### `400`: "Name the file with an X-File-Name header or a ?name= query parameter."
287
306
 
288
307
  **Cause.** The upload request names no file. The name decides the format, and is shown to the
@@ -324,7 +343,10 @@ others. 0.5.0 accepted it.
324
343
  an array.
325
344
 
326
345
  A numeric owner is accepted, as before. `get`, `remove` and questions that pass the owner `""` work
327
- as before, so documents that 0.5.0 stored with that owner stay readable until they expire.
346
+ as before, so documents that 0.5.0 stored with that owner stay readable until they expire. Under
347
+ `requireOwner` the library refuses that owner on every call: `get` and `remove` then answer
348
+ "The file could not be looked up (empty owner)." and "The file could not be deleted (empty owner).",
349
+ also `500` (new in 0.9.0).
328
350
 
329
351
  **Fix.** Return the user's ID, not the user object. Where every upload needs a signed-in user,
330
352
  throw an error with `status: 401` for a request without one. Only where anonymous uploads are
@@ -350,7 +372,7 @@ handler answers `422` with its message. The common ones:
350
372
  | `report.txt is empty.` | A file of 0 bytes. |
351
373
  | `report.docx did not contain any text.` | Nothing left once read: a DOCX of pictures, a file of blank lines. |
352
374
  | `This PDF has no text layer (it may be scanned). It needs OCR before it can be searched.` | A scan, while PDFs are not kept. |
353
- | `The unpdf installed would stop the whole server at the first PDF file on Node 22, …` or `The unpdf installed cannot read PDF files on Node 20 (…). …` | Any PDF, while the `unpdf` installed cannot run on this Node. See [above](#a-pdf-upload-fails-the-unpdf-installed-cannot-read-pdf-files-or-would-stop-the-whole-server). |
375
+ | `The unpdf installed would stop the whole server at the first PDF file on Node 22, …` | Any PDF, while the `unpdf` installed cannot run on this Node. See [above](#a-pdf-upload-fails-the-unpdf-installed-would-stop-the-whole-server). |
354
376
  | `This PDF has 6,200 pages, more than the 5,000 read from one file. Split it, and attach the part you need.` | A PDF of more than `maxPdfPages` pages (5,000 by default). Refused before any page is read. |
355
377
  | `This PDF holds more than 100 MB of text, more than is kept from one file. Split it, and attach the part you need.` | A PDF whose text passes `maxTextBytes` (100 MB by default, or `maxUploadBytes` when that is larger). |
356
378
  | `notes.txt holds more than 100 MB of text, more than is kept from one file. Split it, and attach the part you need.` | The same, from the text extractor or one of your own: a UTF-16 file can grow by half in UTF-8. |
@@ -390,9 +412,12 @@ below 2 minutes ("45 s"), in minutes from there ("2 min").
390
412
  **Cause.** One `ingest` (extracting the text, its line index and its profile) took longer than
391
413
  `ingestTimeoutMs`, 120,000 ms by default. Most often: a PDF with many pages that are slow to read;
392
414
  an extractor of your own that waits on a slow service, such as OCR of a long scan; or a server
393
- busy with other ingests, which each take their share of the same process. Nothing is stored.
415
+ busy with other ingests, which each take their share of the same process. A file read from a path
416
+ (`source: { path }`, an upload of `prepareUpload` or of the spool) gets the same message when its
417
+ volume stops answering while the file is read. Nothing is stored.
394
418
 
395
- **Fix.** For a file that is slow to read, the user splits it, or saves it as plain text. For OCR or
419
+ **Fix.** For a file read from a path, check its volume first: the file may be fine. For a file
420
+ that is slow to read, the user splits it, or saves it as plain text. For OCR or
396
421
  another slow extractor of your own, raise `ingestTimeoutMs` (0 sets no limit), run the ingest in a
397
422
  background job ([Web app](./guides/web-app.md#long-ingests-in-the-background)), and pass
398
423
  `input.signal` on to the service it calls, so that the request stops at the limit too. Bound the
@@ -523,7 +548,10 @@ handler's `get` answers `404` with `This file is no longer available.` for the s
523
548
  **Fix.** Pass the same `owner` to the question as to the upload: the value `getOwner` returned for
524
549
  the same user. Use a store that every server shares and that outlives a restart. Show the user which
525
550
  files to attach again: `error.ids` names the IDs, and your chat knows their file names. A
526
- document's `expiresAt` says when it goes.
551
+ document's `expiresAt` says when it goes. Since 0.9.0 a question can go on without them:
552
+ `onMissingDocuments: "drop"` answers from the other files and lists the missing ones in
553
+ `result.missing`, and a function can ingest them again from uploads you kept
554
+ ([missing documents](./reference/ask.md#missing-documents)).
527
555
 
528
556
  See [Storage](./guides/storage.md) and
529
557
  [`DocumentsNotFoundError`](./reference/ask.md#documentsnotfounderror).
@@ -658,7 +686,8 @@ only what the answering model wrote.
658
686
  **Cause.** The model gets `view_pages` for a PDF only when all of these hold:
659
687
 
660
688
  - `keepOriginals` lists `"pdf"`, and the store has `putOriginal` and `getOriginal`
661
- (`FileDocumentStore` and `MemoryDocumentStore` have both);
689
+ (`FileDocumentStore` and `MemoryDocumentStore` have both), or (0.9.0) the document was ingested
690
+ with `original: { ref }` and the library has `originals`;
662
691
  - the document was ingested after that: one ingested before has no file kept
663
692
  (`meta.originalKept` is not `true`);
664
693
  - every model of the question can be sent a file: not `openAiCompatible()` without `pdfInput`, not
@@ -677,6 +706,19 @@ look fails: install it ([above](#a-pdf-docx-or-pptx-upload-fails-needs-the-optio
677
706
 
678
707
  See [PDFs and other formats](./guides/pdfs.md).
679
708
 
709
+ ### `view_pages` says a file "changed on the server since it was read"
710
+
711
+ The model reads `report.pdf changed on the server since it was read. Attach it again to look at its
712
+ pages.`, and `files.getOriginal` gives `undefined`.
713
+
714
+ **Cause.** The document was ingested with `original: { ref }` (0.9.0), and the file at that ref is
715
+ no longer the one that was ingested: its size or SHA-256 differs from `meta.original`. It was saved
716
+ again under the same name, cut short by a copy that failed, or edited. Its pages would not match the
717
+ text the model has, so none are shown.
718
+
719
+ **Fix.** Keep each upload under a name of its own, and never write over a file a document names.
720
+ To use the new file, ingest it again (`ifExists: "replace"` under the same `id`).
721
+
680
722
  ### Whole-file reads never happen, or are refused
681
723
 
682
724
  `steps` holds no `Read all of …` line, or holds one that failed:
@@ -1052,9 +1094,11 @@ Look at `result.usage`: `inputTokens`, `cachedInputTokens` (read from the provid
1052
1094
  - **`documentPlacement: "last"`.** The documents then move to the latest turn, and a prompt cache
1053
1095
  cannot reuse them: keep the default, `"first"`.
1054
1096
  - **The first request of a follow-up question.** The tool rounds of an earlier question are sent
1055
- again without their `tool_turns_left` (since 0.6.0), so that request reads the cache only up to
1056
- the tool rounds of the question before it: the documents, the cards and the turns before those
1057
- rounds still hit. The later requests of the question hit as before.
1097
+ again without their `tool_turns_left` (since 0.6.0), and as their calls alone: a stored round
1098
+ keeps no thought signatures or thinking blocks, which the requests of its own question sent
1099
+ back. Either one makes that request read the cache only up to the tool rounds of the question
1100
+ before it: the documents, the cards and the turns before those rounds still hit. The later
1101
+ requests of the question hit as before.
1058
1102
  - **The first request after the upgrade to 0.6.0.** The tool guide, the descriptions of
1059
1103
  `search_document` and `analyze_whole_document`, and the frame of every file sent whole changed,
1060
1104
  so the first request of each conversation reads from the cache at most what comes before the
@@ -1073,7 +1117,7 @@ import { askGemini } from "llm-large-files/gemini";
1073
1117
  const result = await askGemini({
1074
1118
  files, endpoint, documentIds, messages, owner,
1075
1119
  limits: {
1076
- inputTokens: 1_000_000, // no more tools once the question has sent this many input tokens
1120
+ inputTokens: 1_000_000, // no tool request that, with the answer, would pass it
1077
1121
  requests: 20, // chat requests and part reads together
1078
1122
  wholeDocumentReads: 0, // no whole-file reads
1079
1123
  },
@@ -1083,10 +1127,11 @@ const { inputTokens, cachedInputTokens, outputTokens, requests, byModel } = resu
1083
1127
  console.log({ owner, inputTokens, cachedInputTokens, outputTokens, requests, byModel });
1084
1128
  ```
1085
1129
 
1086
- The ceilings are checked before each request that may use tools. Once one is reached, the next
1087
- request is the answer, which is still made: a question can pass `inputTokens` by about two
1088
- requests (the one that crossed it, and the answer): set it that far below what must not be passed
1089
- ([Costs and limits](./guides/costs-and-limits.md#inputtokens-and-requests-are-checked-between-turns)). A
1130
+ The ceilings are checked before each request that may use tools, looking ahead: when what the
1131
+ question spent, the next tool request and the answer would pass `inputTokens`, the next request is
1132
+ the answer. So a question can pass `inputTokens` by about one request, the answer's, with the
1133
+ results of the last tool turn in it: set it that far below what must not be passed
1134
+ ([Costs and limits](./guides/costs-and-limits.md#the-ceiling-looks-ahead)). A
1090
1135
  cheaper [explorer model](./guides/explorer-model.md) takes the searching and the part reads off the
1091
1136
  model that answers.
1092
1137
 
@@ -1171,12 +1216,14 @@ See [Security](./security.md) and [Tools](./reference/tools.md).
1171
1216
  ### `DocumentStoreError`: "The document store could not be read (EIO). Try again."
1172
1217
 
1173
1218
  Thrown by a question, `files.getMeta`, `files.getOriginal`, and by `files.delete` when the look-up
1174
- fails (a failure of the store's own `delete` comes as the store's error). When the error behind it
1175
- has no `code`, the message has none. Inside a question's tool call, the model gets it as the
1176
- call's error, and `steps` shows
1177
- `… — failed: The document store could not be read (EIO). Try again.`. The upload
1178
- handler's `get` and `remove` answer `500` with `The file could not be looked up (EIO).` or
1179
- `The file could not be deleted (EIO).`.
1219
+ fails. When the error behind it has no `code`, the message has none. Inside a question's tool call,
1220
+ the model gets it as the call's error, and `steps` shows
1221
+ `… — failed: The document store could not be read (EIO). Try again.`. The upload handler's `get`
1222
+ and `remove` answer `503` with that message (since 0.9.0; they answered `500`). Since 0.9.0 the
1223
+ errors of writes are `DocumentStoreError`s too, with their own messages: "The document could not be
1224
+ stored (EIO). Try again." from `files.ingest`, "The document could not be deleted (EIO). Try
1225
+ again." from the store's own `delete`, "The document store could not be cleaned up (EIO). Try
1226
+ again." from `files.sweep`.
1180
1227
 
1181
1228
  **Cause.** The store failed while it was read: a network volume that did not answer, too many open
1182
1229
  files, a database that is down. The documents are not gone.
@@ -1187,6 +1234,31 @@ them to upload again. Log `error.cause`, the store's own error, and `error.code`
1187
1234
  See [`DocumentStoreError`](./reference/library.md#documentstoreerror) and
1188
1235
  [Storage](./guides/storage.md).
1189
1236
 
1237
+ ### "The document store could not be read (EACCES)" after an upgrade to 0.9.0
1238
+
1239
+ Uploads work on the server that took them, and every other server, or a backup or sweep job,
1240
+ answers `EACCES` for the new documents.
1241
+
1242
+ **Cause.** Since 0.9.0, `FileDocumentStore` writes files `0600` and folders `0700`: only the user
1243
+ that wrote them can read them. The servers or the job run as different users.
1244
+
1245
+ **Fix.** Run them all as one user. Or, for users of one group (a Kubernetes `fsGroup`), give every
1246
+ store `fileMode: 0o640` and `directoryMode: 0o750`, and change the files written since the upgrade
1247
+ once with `chmod`. See [Deployment](./guides/deployment.md#a-shared-store).
1248
+
1249
+ ### `DocumentScopeError`: "The scope no longer exists."
1250
+
1251
+ An upload into a chat fails with a `DocumentScopeError` of code `"scope_missing"`. The upload
1252
+ handler answers it `404` `{ "error": "This chat no longer exists." }`.
1253
+
1254
+ **Cause.** The store is a `FileDocumentStore` with `scopes`, and the folder of the chat is gone:
1255
+ your application removed it when the chat was deleted, or never made it. The store makes its own
1256
+ folder in a chat's folder, never the chat's folder itself, unless `createScopeFolders` is on.
1257
+
1258
+ **Fix.** For a deleted chat, nothing: tell the user the chat no longer exists. For a new chat, make
1259
+ its folder (`mkdir` with `recursive: true`) when the chat starts, or set `createScopeFolders: true`.
1260
+ See [Storage](./guides/storage.md#files-in-a-folder-per-user-or-per-chat).
1261
+
1190
1262
  ### Documents are found on one server and missing on another
1191
1263
 
1192
1264
  `DocumentsNotFoundError` for documents that were just uploaded, on some requests and not others, or
@@ -1214,29 +1286,38 @@ try again.
1214
1286
 
1215
1287
  See [Storage](./guides/storage.md) and [`DocumentStore`](./reference/library.md#documentstore).
1216
1288
 
1217
- ### `500`: "Upload failed.", or `422` with your database's message
1289
+ ### `503`: "The document could not be stored. Try again.", or `500` "Upload failed."
1290
+
1291
+ **Cause.** A store write that fails is a `DocumentStoreError` since 0.9.0 (it was thrown as it
1292
+ came, and answered `500` "Upload failed."). The upload handler answers it `503` with its message,
1293
+ "The document could not be stored (ENOSPC). Try again." when the store's error has a code, and
1294
+ `Retry-After: 5`. Your database's own message is its `cause`, and may name its host, so it is not
1295
+ sent, and the handlers log nothing.
1296
+
1297
+ An `ingest` of your own that throws a new error in its place, without a status, gets `500`
1298
+ "Upload failed." since 0.9.0. Before, it got `422` with that error's message, which could name your
1299
+ database's host (S12). Every case is in the [node reference](./reference/node.md#how-errors-are-answered).
1300
+
1301
+ **Fix.** Log `error.cause` where you catch it, and fix the storage. An `ingest` of your own must
1302
+ pass the `DocumentStoreError` on as it is, or rebuild it, as `ingestInProcess` in
1303
+ [Deployment](./guides/deployment.md#uploads-and-ingest) does. A route of your own answers it with
1304
+ `uploadAnswerOf` ([Web app](./guides/web-app.md#filesingest-and-its-errors)).
1218
1305
 
1219
- **Cause.** A store write that fails is thrown as it came, not as a `DocumentStoreError`. The upload
1220
- handler answers it `500` with `{ "error": "Upload failed." }` when it has no `status` (or
1221
- `statusCode`) from 400 to 599 and is not a Node system error with `code` and `syscall`. Its message
1222
- is your database's own and may name its host, so it is not sent, and the handlers log nothing.
1306
+ ### `500` "Upload failed." for a file your own `ingest` refused
1223
1307
 
1224
- Two paths answer it `422` with your database's message instead, as a file that cannot be read: an
1225
- `ingest` of your own that throws a new error in its place, as `ingestInProcess` in
1226
- [Deployment](./guides/deployment.md#uploads-and-ingest) does, and a route of your own, as in
1227
- [Web app](./guides/web-app.md#filesingest-and-its-errors). Every case is in the
1228
- [node reference](./reference/node.md#uploadrequest-response).
1308
+ **Cause.** Since 0.9.0, the upload handler answers `422` only an `IngestError`. A `LargeFiles` of
1309
+ your own whose `ingest` throws a plain `Error` for a file it refuses gets `500` "Upload failed.",
1310
+ without its message, which could name a host.
1229
1311
 
1230
- **Fix.** In a store of your own, log a write that fails, and throw an error with a `status` (a
1231
- `503`, say) whose message is fit for a user. An `ingest` of your own must copy that status, and a
1232
- system error's `code` and `syscall`, onto the error it throws, as `ingestInProcess` in
1233
- [Deployment](./guides/deployment.md#uploads-and-ingest) does.
1312
+ **Fix.** Throw `new IngestError(code, message)` (exported from `llm-large-files`), with a message
1313
+ written for the user. Its code says why: `"unreadable"`, `"too_large"`, `"no_text"`…
1234
1314
 
1235
1315
  See [Storage](./guides/storage.md) and [`llm-large-files/node` reference](./reference/node.md).
1236
1316
 
1237
- ### `500`: "Upload failed (ENOSPC)."
1317
+ ### `503`: "The document could not be stored (ENOSPC). Try again."
1238
1318
 
1239
- **Cause.** The disk of a `FileDocumentStore` is full. Expired documents are removed when they are
1319
+ **Cause.** The disk of a `FileDocumentStore` is full. (Before 0.9.0 the answer was `500` "Upload
1320
+ failed (ENOSPC).".) Expired documents are removed when they are
1240
1321
  next looked up, or by `files.sweep()`: one that nobody asks for again stays on disk until a sweep.
1241
1322
  Kept originals (`keepOriginals`) take space up to the upload limit each, until they expire.
1242
1323