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
@@ -32,8 +32,9 @@ sees them:
32
32
  read whose parts all failed) returns its error to the model, which tries another way. Nothing is
33
33
  thrown. See [Failures inside tools](#failures-inside-tools).
34
34
 
35
- What is left for you: catch what the question throws, show your own words for it, keep what a
36
- failed question found, check `answered`, and set an overall deadline.
35
+ What is left for you: catch what the question throws, show your own words for it (one switch over
36
+ [`errorInfoOf`](#your-users-words-errorinfoof) does it), keep what a failed question found, check
37
+ `answered`, and set an overall deadline.
37
38
 
38
39
  ## What a question can throw
39
40
 
@@ -41,7 +42,7 @@ failed question found, check `answered`, and set an overall deadline.
41
42
 
42
43
  | Error | When | Fields to use | `partialResultOf` |
43
44
  |---|---|---|---|
44
- | `DocumentsNotFoundError` | A document ID was never uploaded, has expired, was deleted, or belongs to another `owner`. Thrown before any model request. | `ids`: the IDs that are missing. | No |
45
+ | `DocumentsNotFoundError` | A document ID was never uploaded, has expired, was deleted, or belongs to another `owner` or scope. Thrown before any model request, unless `onMissingDocuments` says to answer without it or brings it back (new in 0.9.0, [below](#documents-that-are-gone)). | `ids`: the IDs that are missing. | No |
45
46
  | `DocumentStoreError` | The store could not be read while the question planned its documents: a volume that did not answer, a database that is down. The documents are not gone, and the same question may work a moment later. | `code` (`EIO`, `EMFILE`) and `syscall` when a system error is behind it; `cause`, the error that was caught. | No |
46
47
  | `ModelRequestError`: a `GeminiRequestError`, `OpenAiRequestError` or `AnthropicRequestError` | A model request failed in a way that was not worth sending again, or still failed after the retries. A reply of HTTP 200 whose body is not JSON (a gateway's page in the model's place) is one too, of kind `invalid`, with status 200 and the `SyntaxError` as `cause`; it is not sent again. A reply of HTTP 200 whose body is empty is of kind `unreachable`, status 0, and is sent again first. | `kind`, `status` (0 when no answer came, or the reply stopped on its way), `retryAfterMs`, `limitTokens`, `requestedTokens`, `cause`. `OpenAiRequestError` adds `param` and `code`; `AnthropicRequestError` adds `type`. | Yes |
47
48
  | The reason of your `signal` | You stopped the question, or your deadline ran out. See [An overall deadline](#an-overall-deadline). | Test your signals, not the error. | Yes, for a reason that is an object |
@@ -78,12 +79,13 @@ Whose words each message is:
78
79
 
79
80
  Use `instanceof` for the classes, and `errorKindOf(error)` for the kind. `errorKindOf` reads the
80
81
  `kind` field of any error that has one, so it also works when two copies of the package are
81
- installed side by side, where `instanceof` fails. The four model error classes are all
82
- `ModelRequestError`.
82
+ installed side by side, where `instanceof` fails; so do the classes' own `is(value)` methods, new
83
+ in 0.9.0. The four model error classes are all `ModelRequestError`. Or let
84
+ [`errorInfoOf`](#your-users-words-errorinfoof) tell them apart for you (new in 0.9.0).
83
85
 
84
86
  | Export | Entry point |
85
87
  |---|---|
86
- | `ModelRequestError`, `errorKindOf`, `classifyModelError`, `DocumentsNotFoundError`, `DocumentStoreError`, `partialResultOf` | `llm-large-files` |
88
+ | `ModelRequestError`, `errorKindOf`, `classifyModelError`, `DocumentsNotFoundError`, `DocumentStoreError`, `partialResultOf`, `errorInfoOf` | `llm-large-files` |
87
89
  | `GeminiRequestError`, and `DocumentsNotFoundError` and `partialResultOf` again | `llm-large-files/gemini` |
88
90
  | `OpenAiRequestError` | `llm-large-files/openai` |
89
91
  | `AnthropicRequestError` | `llm-large-files/anthropic` |
@@ -264,29 +266,30 @@ is quiet for less: see [Deployment](./deployment.md).
264
266
  ### Part reads have a time limit of their own
265
267
 
266
268
  The waits cover chat requests. Each request of a whole-file read (a part read) has a limit on its
267
- whole time instead: `timeoutMs` of `openAiCompatible()` and `anthropic()`, 180,000 by default. For
268
- Gemini it is 180 s, and neither `gemini()` nor `askGemini` has an option for it. A part read that
269
- runs out of time is tried once more, at once. If it fails again, the tool's result says the part
270
- could not be read (`parts_that_failed`), and the question goes on.
271
-
272
- To give Gemini part reads more time, replace the adapter's `generateText` and call
273
- `askWithFiles`:
269
+ whole time instead: `timeoutMs` of `gemini()`, `askGemini`, `openAiCompatible()` and
270
+ `anthropic()`, 180,000 by default. 0 sets none. A part read that runs out of time is an error of
271
+ kind `timeout` and status 0, in every adapter. It is tried once more, after the first wait of
272
+ `retry` (250 to 500 ms by default). If it fails again, the tool's result says the part could not be
273
+ read (`parts_that_failed`), and the question goes on.
274
274
 
275
275
  ```ts
276
- import { askWithFiles, type ModelAdapter } from "llm-large-files";
277
- import { createGeminiGenerateText, gemini } from "llm-large-files/gemini";
276
+ import { askGemini, gemini } from "llm-large-files/gemini";
278
277
 
279
- const patient: ModelAdapter = {
280
- ...gemini(endpoint),
281
- // Each part read may take 5 minutes.
282
- generateText: createGeminiGenerateText({ url: endpoint.url, headers: endpoint.headers, timeoutMs: 300_000 }),
283
- };
284
- const result = await askWithFiles({ files, model: patient, documentIds, messages, owner });
278
+ // Each part read may take 5 minutes.
279
+ const answer = await askGemini({ files, endpoint, documentIds, messages, owner, timeoutMs: 300_000 });
280
+
281
+ // The same option on an adapter, for askWithFiles.
282
+ const model = gemini(endpoint, { timeoutMs: 300_000 });
285
283
  ```
286
284
 
287
- `analysisConfig` of `gemini()` is `generationConfig` here, if you set one. With an
288
- [explorer model](./explorer-model.md), the part reads are the explorer's: replace its
289
- `generateText`.
285
+ `askGemini`'s `timeoutMs` covers the part reads of both models. With `askWithFiles` and an
286
+ [explorer model](./explorer-model.md), the part reads are the explorer's: set `timeoutMs` on its
287
+ adapter.
288
+
289
+ Before 0.10.0, `gemini()` and `askGemini` had no option for it: a Gemini part read had 180 s. A
290
+ part read that ran out of time threw the timer's abort error, with no status, and was tried once
291
+ more at once. `timeoutMs: 0` of `openAiCompatible()` and `anthropic()` aborted every part read at
292
+ once.
290
293
 
291
294
  ## An overall deadline
292
295
 
@@ -341,7 +344,9 @@ How the client side cancels a streamed answer is in [Web app](./web-app.md).
341
344
  When the provider refuses a request as larger than the model takes (kind `context_overflow`), the
342
345
  loop does not give up at once. The same holds for a request larger than the tokens the provider
343
346
  lets through in a minute (OpenAI's and Groq's TPM, or a day's allowance): that allowance then
344
- stands for the window.
347
+ stands for the window. Since 0.9.0 the loop reads the kind as the events report it: an error
348
+ without a `kind` of its own that has a model's status (an adapter of your own, `httpError(413)`)
349
+ has the kind `classifyModelError` gives its status, message and `code`.
345
350
 
346
351
  1. It takes the provider's count and window for the rest of the question, replaces tool results
347
352
  with stand-ins (those of all but the last three tool rounds, then all but the last two, then all
@@ -398,8 +403,10 @@ that says what was wrong:
398
403
  `UNEXPECTED_TOOL_CALL`. The step says "The model's tool call could not be read: it was asked to
399
404
  send it again".
400
405
  - **A first reply with nothing in it**: no text and no tool call, before any tool call of the
401
- question was answered, and not cut off at the output limit or stopped by a filter. The step says
402
- "The model's first reply was empty: it was asked again".
406
+ question was answered, and not cut off at the output limit, stopped by a filter, or ended for
407
+ another reason that asking again does not mend (`finish: "other"`: Gemini's `OTHER`,
408
+ `LANGUAGE` and the like, since 0.10.0). The step says "The model's first reply was empty: it was
409
+ asked again".
403
410
 
404
411
  Without the second try, the answer would be written from the document cards alone and look like any
405
412
  other. At most two such second tries are made in a question, and each takes one of
@@ -407,6 +414,10 @@ other. At most two such second tries are made in a question, and each takes one
407
414
  [How it works](../how-it-works.md#empty-or-broken-turns). When the second try is empty too, the
408
415
  loop asks for the answer, as it does at the end of every question.
409
416
 
417
+ A turn whose tool call could not be read is never the answer, even with a remark in it ("Let me
418
+ look at the error lines."): on the last tool turn, or when its second try could not be read either,
419
+ the loop asks for the answer (new in 0.10.0; before, the remark was taken for the answer).
420
+
410
421
  **The answer's second try.** The request for the answer (`toolChoice: "none"`) is asked for once
411
422
  more when its reply has no text: when it is empty, or holds a tool call the model was told not to
412
423
  make (Gemini's `UNEXPECTED_TOOL_CALL` or `MALFORMED_FUNCTION_CALL`, or calls from an adapter of
@@ -415,8 +426,10 @@ called in this reply: write the answer now, in text, from what is above.", and i
415
426
  step says "The model's answer was empty: it was asked again", or "The model called a tool instead
416
427
  of answering: it was asked again for the answer". It is one of the two second tries of the
417
428
  question, and it can be one request past `limits.toolTurns`. It is not made after a refusal, a
418
- filter, or a reply cut off at the output limit with nothing in it, nor once `limits.requests` or
419
- `limits.inputTokens` is reached. When its reply has no text either, `answered` is false.
429
+ filter, another reason that asking again does not mend (`"other"`), or a reply cut off at the
430
+ output limit with nothing in it, nor once `limits.requests` or the ceiling of input tokens is
431
+ reached. When its reply has no text either, `answered` is false. So a reply that Gemini ends with
432
+ `MODEL_ARMOR`, `OTHER` or `LANGUAGE` costs 2 requests, not 4 (once the adapter maps them).
420
433
 
421
434
  A single call that cannot be run is not a broken turn: arguments that are not a JSON object, a call
422
435
  cut off at the output limit, a Claude call whose block never closed. It is answered with an error
@@ -485,6 +498,11 @@ whose parts all failed. The question goes on, and can still be answered. A faile
485
498
  - in `toolTurns`, as a call whose `result.error` is a string;
486
499
  - not in `evidence`, which lists only what was shown.
487
500
 
501
+ A tool call that rejects, instead of answering with an error, ends the question with that error
502
+ (`run.error`): a tool set of your own whose `executeWithFiles` throws, or `onToolResult` when it
503
+ throws. The model gets nothing of it. Since 0.10.0 a question also stops at once when its signal
504
+ aborts while a tool call, or the planning of the documents, waits for a store that does not answer.
505
+
488
506
  A whole-file read tells the model why a model request failed by the error's kind, its HTTP status
489
507
  or the code of a connection that failed, never by the error's words: the provider's message, or an
490
508
  HTTP client's, can name a project, a host, a masked key, or a URL with a key in it. The same words
@@ -526,46 +544,108 @@ for (const call of failed) console.warn(`Tool ${call.name} failed: ${String(call
526
544
 
527
545
  ## When there is no answer: `answered` and `finishReason`
528
546
 
529
- A question can end without an error and without an answer. `answered` is false when the model's
530
- last turn had no text:
547
+ A question can end without an error and without an answer. `answered` is false when the reply that
548
+ should be the answer had no text:
531
549
 
532
550
  - **The provider refused the prompt.** `blockReason` says why: Gemini's `promptFeedback.blockReason`
533
551
  (such as "SAFETY"), "refusal" or "refusal: " and its category for Claude, "content_filter" for an
534
552
  OpenAI-compatible reply that was filtered with nothing in it. Nothing more is asked after it.
535
553
  - **The last reply ended without text**: cut off at the output limit before its first word, stopped
536
554
  by a filter, or an answer with no text (empty, or a tool call) after its one second try.
555
+ - **The answer was filtered, and `filteredAnswer` is `"drop"`** (new in 0.10.0): `text` is `""`.
537
556
 
538
557
  `text` may then be empty, hold only a remark the model wrote before a tool call, or the start of a
539
558
  reply the provider then refused. Show your own message instead.
540
559
 
541
560
  `finishReason` is the provider's own word for how the last chat reply ended: "STOP", "MAX_TOKENS"
542
561
  or "SAFETY" from Gemini, "stop", "length" or "content_filter" from an OpenAI-compatible server,
543
- "end_turn", "max_tokens" or "refusal" from Claude. An answer can be `answered: true` and still be
544
- cut off at the output limit. Tell the user, or raise the model's output limit (`maxOutputTokens` in
545
- Gemini's `generationConfig`, the limit in `body` of `openAiCompatible()`, `maxTokens` of
546
- `anthropic()`). Claude's `model_context_window_exceeded` means its window filled: shorten the chat
547
- rather than raise the output limit.
562
+ "end_turn", "max_tokens" or "refusal" from Claude. Since 0.10.0 `finish` says the same in the
563
+ library's words, the same for every provider: `"complete"`, `"cut"` (the output limit),
564
+ `"filtered"`, `"malformed_call"` or `"other"`. An answer can be `answered: true` and still be cut off
565
+ at the output limit, or stopped by a filter part-way. Tell the user, or raise the model's output
566
+ limit (`maxOutputTokens` in Gemini's `generationConfig`, the limit in `body` of
567
+ `openAiCompatible()`, `maxTokens` of `anthropic()`). Claude's `model_context_window_exceeded` means
568
+ its window filled: shorten the chat rather than raise the output limit.
569
+
570
+ ## Filtered and cut answers
571
+
572
+ New in 0.10.0. A reply that a filter stopped part-way was an answer like any other in 0.9: "The
573
+ employee's medical leave was", with `answered: true`. Now:
574
+
575
+ - **`result.finish`** is the `finish` of the reply whose text is the answer, or of the last reply when
576
+ none answered. Absent when the adapter does not say.
577
+ - **An `answer_filtered` notice** comes when a filter stopped the answer, with or without text, and
578
+ **an `answer_cut` notice** when the answer stopped at the output limit. Both come before
579
+ `run.finish`, with `display: "none"`: no callback of earlier versions gets them.
580
+ - **`filteredAnswer: "drop"`** drops a filtered answer: `answered: false`, `text: ""`. The default,
581
+ `"keep"`, keeps its text, as 0.9 did. A cut answer is kept either way: it is not wrong, only
582
+ short.
583
+
584
+ **Text already streamed cannot be taken back.** With `onText`, `streamText` or `askStream`, the
585
+ filtered reply's text may have reached the page before the filter's word came. Under `"drop"`, the
586
+ `answer_filtered` notice then has `discardText: true`: the page takes away the text it showed for
587
+ the question, and shows your message instead. Text of a reply that was not streamed is never sent
588
+ when it is to be dropped. Earlier remarks of the question (before a tool call) are dropped with it,
589
+ and `discardText` covers them too.
548
590
 
549
591
  ```ts
550
- import type { AskResult } from "llm-large-files";
592
+ import type { AskEvent } from "llm-large-files";
593
+
594
+ /** The answer as the page shows it, from the events of the question as they come. */
595
+ export function answerView(render: (text: string) => void): (event: AskEvent) => void {
596
+ let shown = "";
597
+ return (event) => {
598
+ if (event.type === "text") render((shown += event.delta));
599
+ // A filter stopped the answer, and the server dropped it: take back what was shown.
600
+ if (event.type === "notice" && event.code === "answer_filtered" && event.discardText) render((shown = ""));
601
+ };
602
+ }
603
+ ```
551
604
 
552
- /** The words of the output limit, as each provider says them. */
553
- const CUT_OFF = new Set(["MAX_TOKENS", "length", "max_tokens"]);
605
+ **`answerInfoOf(result)`** gives the reason in one value, as `errorInfoOf` does for errors:
606
+ `complete`, and `reason` one of `"filtered"`, `"cut"`, `"blocked"`, `"language"`, `"no_answer"` or
607
+ `"other"`, with `finish` and the provider's `finishReason`. `"language"` is Gemini's `LANGUAGE`: the
608
+ model does not take the language of the question. It is not a filter, and a user should not be told
609
+ that one stopped the answer. It reads `answered`, `finish`, `finishReason` and `blockReason`, so it
610
+ works on `run.finish`'s result in the browser too.
554
611
 
555
- export function shownAnswer(result: AskResult): { text: string; note?: string } {
556
- if (!result.answered) {
557
- return { text: result.blockReason ? "This question was blocked by the model's safety filters." : "No answer this time. Ask again, or ask more precisely." };
558
- }
559
- if (result.finishReason === "model_context_window_exceeded") {
560
- return { text: result.text, note: "The answer was cut off: the chat filled the model's window." };
561
- }
562
- if (result.finishReason !== undefined && CUT_OFF.has(result.finishReason)) {
563
- return { text: result.text, note: "The answer was cut off at the model's output limit." };
564
- }
565
- return { text: result.text };
612
+ The messages of a chatbot for Hebrew speakers, with the English beside each:
613
+
614
+ | `reason` | Hebrew | English |
615
+ |---|---|---|
616
+ | `"filtered"` | התשובה נעצרה על ידי מסנן התוכן, ולכן היא לא מוצגת. | A content filter stopped the answer, so it is not shown. |
617
+ | `"cut"` | התשובה נקטעה כי הייתה ארוכה מדי. אפשר לבקש את ההמשך, או לשאול שאלה ממוקדת יותר. | The answer was cut off because it was too long. Ask for the rest, or ask a narrower question. |
618
+ | `"blocked"` | אי אפשר לענות על השאלה הזו. נסו לנסח אותה אחרת. | This question cannot be answered. Try putting it another way. |
619
+ | `"language"` | לא הצלחנו לענות בשפה של השאלה. נסו לנסח אותה שוב. | We could not answer in the language of the question. Try putting it again. |
620
+ | `"no_answer"` | לא התקבלה תשובה הפעם. נסו לשאול שוב, או לשאול בצורה מדויקת יותר. | No answer this time. Ask again, or ask more precisely. |
621
+ | `"other"` | משהו השתבש בזמן כתיבת התשובה. נסו שוב. | Something went wrong while the answer was written. Try again. |
622
+
623
+ ```ts
624
+ import { answerInfoOf, type AnswerInfo, type AskResult } from "llm-large-files";
625
+
626
+ const HEBREW: Record<NonNullable<AnswerInfo["reason"]>, string> = {
627
+ filtered: "התשובה נעצרה על ידי מסנן התוכן, ולכן היא לא מוצגת.",
628
+ cut: "התשובה נקטעה כי הייתה ארוכה מדי. אפשר לבקש את ההמשך, או לשאול שאלה ממוקדת יותר.",
629
+ blocked: "אי אפשר לענות על השאלה הזו. נסו לנסח אותה אחרת.",
630
+ language: "לא הצלחנו לענות בשפה של השאלה. נסו לנסח אותה שוב.",
631
+ no_answer: "לא התקבלה תשובה הפעם. נסו לשאול שוב, או לשאול בצורה מדויקת יותר.",
632
+ other: "משהו השתבש בזמן כתיבת התשובה. נסו שוב.",
633
+ };
634
+
635
+ /** The answer to show, and the note under it. Asked with filteredAnswer: "drop". */
636
+ export function shownAnswer(result: Pick<AskResult, "answered" | "text" | "finish" | "finishReason" | "blockReason">): { text: string; note?: string } {
637
+ const info = answerInfoOf(result);
638
+ if (info.complete) return { text: result.text };
639
+ // A reason of a later version reads as "other".
640
+ const message = HEBREW[info.reason ?? "other"] ?? HEBREW.other;
641
+ // A cut answer has text worth reading: the message goes under it.
642
+ return result.answered && result.text ? { text: result.text, note: message } : { text: message };
566
643
  }
567
644
  ```
568
645
 
646
+ The Gemini reasons behind each `finish`, and which of them a Vertex AI project can see (Model Armor
647
+ is Vertex only), are in [Vertex AI and Gemini](./vertex-and-gemini.md).
648
+
569
649
  ## Keeping what a failed question found
570
650
 
571
651
  `askWithFiles` throws the error as it came, and what the question did until then is not lost.
@@ -608,8 +688,8 @@ written for the user and a `code` for your app, when it cannot take a file: it i
608
688
  (`"no_text"`), is a gzip or ZIP archive (`"compressed"`), is binary (`"not_text"`), is an Office
609
689
  file of before 2007 or with a password (`"legacy_office"`), needs an optional dependency that is not
610
690
  installed (`jszip` for DOCX, PPTX and XLSX, `unpdf` for PDF) or an `unpdf` that runs on this Node
611
- (`"missing_dependency"`: the setup of the server, not the file, as in "The unpdf installed cannot
612
- read PDF files on Node 20 (…). …"), or is a PDF without a text layer (see [PDFs](./pdfs.md)). Show
691
+ (`"missing_dependency"`: the setup of the server, not the file, as in "The unpdf installed would
692
+ stop the whole server at the first PDF file on Node 22, …"), or is a PDF without a text layer (see [PDFs](./pdfs.md)). Show
613
693
  its message, or words of your own for its `code`. Until 0.8.0 it was a plain `Error`, with the same
614
694
  message. A text file is never refused for its encoding: one that is
615
695
  not UTF-8 is read in the encoding it was saved in, or as UTF-8 with the characters that are not
@@ -624,30 +704,199 @@ A file the parser cannot read (a damaged DOCX, PPTX, XLSX or PDF) throws an `Ing
624
704
  `"unreadable"` with the parser's message (jszip's, or that of pdf.js's `InvalidPDFException`), and
625
705
  the parser's error as `cause`; an extractor of your own that throws an `Error` gets the same, with
626
706
  the code its message gives. Those messages are not written for users: show "This file could not
627
- be read." for the code `"unreadable"`. With `createIsolatedExtractors`, a file whose reader ran out
707
+ be read." for the code `"unreadable"`. Since 0.9.0 the upload handlers, `uploadAnswerOf` and
708
+ `errorInfoOf` do: "This file could not be read. It may be damaged, or not of the type its name
709
+ says.". With `createIsolatedExtractors`, a file whose reader ran out
628
710
  of memory or time is `"out_of_memory"` or `"timeout"`, readers that are all busy give `"busy"`,
629
711
  answered `503` with `Retry-After`, and a reader that could not start at all (a `childScript` that
630
712
  is not there) is not an `IngestError`, but an `Error` with `status` 500
631
713
  ([node reference](../reference/node.md#createisolatedextractorsoptions)).
632
714
 
633
- A store that fails while it writes throws its own error, as it came: its message may name a path or
634
- a host, so log it and show a general message. `createDocumentHandlers` answers a file it cannot take
635
- with 422 and the error's message, and a Node system error of the store (one with a `code` and a
636
- `syscall`) with 500 and only its code ("Upload failed (ENOSPC)."). Any other store error, one
637
- without a `status` (or `statusCode`) from 400 to 599, is answered 500 "Upload failed.", without its
638
- message, and so is a thrown value that is not an `Error`. The handlers log nothing: log the error in
639
- your store before you throw it. Two paths still answer a store's error 422 with its message, which
640
- may name a host: an `ingest` of your own that throws a new error in its place, as `ingestInProcess`
641
- in [Deployment](./deployment.md#uploads-and-ingest) does, and a route of your own, as in
642
- [Web app](./web-app.md#filesingest-and-its-errors). So a custom store should throw an error with a
643
- `status` and a message fit for the user (both are sent as they are): every path keeps that status.
644
- See [the node reference](../reference/node.md#uploadrequest-response).
715
+ A store that fails while it writes is a `DocumentStoreError` since 0.9.0: operation `"write"` in
716
+ `ingest` (code `"ETIMEDOUT"` for a write that did not end in time), `"delete"` in `files.delete`,
717
+ `"sweep"` in `files.sweep`. Its status is 503, its message ("The document could not be stored
718
+ (EIO). Try again.") names no path or host and can be shown, and the store's own error is `cause`:
719
+ log that one. Before 0.9.0 the store's error came out as it was. The `ingest.error` event of a
720
+ failed write says "The document could not be stored. Try again later.", with `name`
721
+ `"DocumentStoreError"` and `status` 503 (new in 0.9.0), and `errorInfoOf` reads it as the error.
722
+ `createDocumentHandlers` answers a
723
+ file it cannot take (an `IngestError`) with 422 and the error's message (fixed words for
724
+ `"unreadable"`), and a store that failed
725
+ with 503, `Retry-After: 5` and the `DocumentStoreError`'s message (it was a 500). Since 0.9.0 any
726
+ other error without a status is answered 500 "Upload failed.", without its message: a `LargeFiles`
727
+ of your own whose `ingest` throws a plain `Error` no longer sends its words, which may name a host,
728
+ as a 422 (S12). Throw `new IngestError(code, message)` for a file you refuse, as `ingestInProcess`
729
+ in [Deployment](./deployment.md#uploads-and-ingest) does. A route of your own answers the same way
730
+ with `uploadAnswerOf` from `llm-large-files/node` ([Web app](./web-app.md#filesingest-and-its-errors)).
731
+ The handlers log nothing: log `error.cause`. See
732
+ [the node reference](../reference/node.md#how-errors-are-answered).
645
733
 
646
734
  Every read of the store goes through the library: `prepare`, `getMeta`, `getOriginal`, the tools.
647
735
  What the store throws there becomes a `DocumentStoreError`, which does not mean the document is
648
736
  gone. A store's own `delete` and `sweep` pass on its error as it came. A document that is gone, or
649
737
  of another owner, is not an error of the store: `prepare` lists it in `missing`, and `askWithFiles`
650
- throws `DocumentsNotFoundError` for it. What a store must do is in [Storage](./storage.md).
738
+ throws `DocumentsNotFoundError` for it, unless `onMissingDocuments` says otherwise (below). What a
739
+ store must do is in [Storage](./storage.md).
740
+
741
+ ### Transient errors: a store or a disk that does not answer
742
+
743
+ New in 0.10.0. A store that stops answering no longer holds a question forever. Every store call of
744
+ the library has a time limit, `storeTimeoutMs` (30 s by default): past it, the call is a
745
+ `DocumentStoreError` of code `"ETIMEDOUT"`, a 503 to retry. In a question it ends the question with
746
+ `run.error`, and the model sees no new text. While too many calls of the process are stuck past
747
+ their limit (`maxStuckStoreCalls`, half of `UV_THREADPOOL_SIZE`), store calls fail at once with code
748
+ `"STORE_STUCK"`, 503 too, so that the server keeps its threads for everything else. Both are
749
+ category `"store"` for `errorInfoOf`: the words of the `"store"` case above fit them ("try again in
750
+ a moment"). [Deployment](./deployment.md#a-store-that-stops-answering) says how to size the limits
751
+ and what to alert on.
752
+
753
+ A Node system error that says the server, or a service it needs, could not answer just now is now
754
+ retryable too: `ETIMEDOUT`, `ECONNRESET`, `ECONNREFUSED`, `EPIPE`, `EAI_AGAIN`, `EAGAIN`, `EBUSY`,
755
+ `EMFILE`, `ENFILE`, `ESTALE`, `EHOSTUNREACH` and `ENETUNREACH`. `errorInfoOf` gives them category
756
+ `"unknown"`, their code, status 503, `retryable: true` and 5 s to wait; a full disk (`ENOSPC`,
757
+ `EDQUOT`) the same with 30 s. The upload handlers answer them `503` with `Retry-After`. Before, they
758
+ were 500 and not retryable: a user was told "something went wrong" for a volume that hung a moment.
759
+ A path upload whose read does not answer within `ingestTimeoutMs` is such an error, `ETIMEDOUT`,
760
+ not the `IngestError` `"timeout"` (422, "split the file") it was: the trouble is the server's, not
761
+ the file's. The full list is in
762
+ [the reference](../reference/errors-and-retries.md#transient-system-errors).
763
+
764
+ Tell your users to try again when `retryable` is true, whatever the category:
765
+
766
+ ```ts
767
+ import { errorInfoOf } from "llm-large-files";
768
+
769
+ /** The Hebrew words for an error the user can retry: a store, a disk or a service that did not answer. */
770
+ export function retryWords(error: unknown): string | undefined {
771
+ const info = errorInfoOf(error);
772
+ if (!info.retryable || info.category === "model") return undefined; // a model's error has words of its own
773
+ return info.code === "ENOSPC" || info.code === "EDQUOT" ? "אין כרגע מקום בשרת. נסו שוב מאוחר יותר." : "השרת לא הגיב כרגע. נסו שוב בעוד רגע.";
774
+ }
775
+ ```
776
+
777
+ ## Documents that are gone
778
+
779
+ A document expires `ttlMs` after its upload (72 hours by default), and a chat can outlive it. By
780
+ default the next question then fails whole, before any model request, with
781
+ `DocumentsNotFoundError`. New in 0.9.0, `onMissingDocuments` settles it in the question
782
+ ([missing documents](../reference/ask.md#missing-documents)):
783
+
784
+ | `onMissingDocuments` | What the question does |
785
+ |---|---|
786
+ | `"throw"` (the default) | Throws `DocumentsNotFoundError`, as before. |
787
+ | `"drop"` | Answers without them. One line of the system instruction tells the model how many files are no longer available. `result.missing` lists their IDs; take them off the chat, and tell the user. |
788
+ | A function | Gets the missing IDs, with the question's `owner`, `scope` and `signal`, and returns `"throw"`, `"drop"`, `{ retry: true }` after it ingested them again under the same IDs, or `{ replace: { [oldId]: newId } }`. A retry or a replace plans the question again once; an ID still missing then throws `DocumentsNotFoundError`. What it throws fails the question. |
789
+
790
+ A document deleted while a question runs is not an error of the question: the tool tells the model
791
+ it is no longer available, and the question gets a `document_gone` notice.
792
+
793
+ ## Your users' words: `errorInfoOf`
794
+
795
+ New in 0.9.0. `errorInfoOf(error)` tells what any error of the library means, in one record: a
796
+ `category`, a `code`, the HTTP `status` to answer with, whether it is `retryable` and after how
797
+ long (`retryAfterMs`), and an English `message` that is safe to show. It never throws, and it reads
798
+ the errors of another copy of the package too. Every row is in
799
+ [the reference](../reference/errors-and-retries.md#errorinfooferror).
800
+
801
+ | `category` | What failed | `code` |
802
+ |---|---|---|
803
+ | `"ingest"` | A file the library refused (`IngestError`). | Its `IngestErrorCode`: `"too_large"`, `"no_text"`, `"busy"`… |
804
+ | `"store"` | The store, just now (`DocumentStoreError`). Retry. | The system error's code, when there is one. |
805
+ | `"missing"` | Documents that are gone (`DocumentsNotFoundError`), or the chat's folder (`DocumentScopeError` `"scope_missing"`). | `"documents_missing"`, `"scope_missing"`. |
806
+ | `"model"` | A model request (`ModelRequestError`). | Its [kind](#the-kind-of-a-model-error). |
807
+ | `"aborted"` | A signal stopped it: the user left, or a deadline. | `"aborted"`, `"timeout"`. |
808
+ | `"input"` | A mistake in the call: a bug of your server, not of the user. | A scope error's code. |
809
+ | `"unknown"` | Anything else. Since 0.10.0 a system error that says the server could not answer just now (`ETIMEDOUT`, `ECONNRESET`…) is 503 and retryable ([transient errors](#transient-errors-a-store-or-a-disk-that-does-not-answer)). | A system error's code. |
810
+
811
+ One switch turns them into your users' words. A chatbot for Hebrew speakers:
812
+
813
+ ```ts
814
+ import { errorInfoOf, type ErrorInfo } from "llm-large-files";
815
+
816
+ /** What to answer a Hebrew-speaking user: the status, the words, and when to try again. */
817
+ export function hebrewAnswer(error: unknown): { status: number; message: string; retryAfterMs?: number } {
818
+ const info = errorInfoOf(error);
819
+ return { status: info.status, message: hebrewMessage(info), ...(info.retryAfterMs !== undefined ? { retryAfterMs: info.retryAfterMs } : {}) };
820
+ }
821
+
822
+ function hebrewMessage(info: ErrorInfo): string {
823
+ switch (info.category) {
824
+ case "ingest":
825
+ switch (info.code) {
826
+ case "empty": return "הקובץ ריק.";
827
+ case "too_large": return "הקובץ גדול מדי.";
828
+ case "too_much_text": return "יש בקובץ יותר מדי טקסט.";
829
+ case "too_many_pages": return "יש בקובץ יותר מדי עמודים.";
830
+ case "not_text": return "לא ניתן לקרוא קובץ מסוג זה. צרפו קובץ טקסט, PDF, Word, PowerPoint או Excel.";
831
+ case "compressed": return "הקובץ דחוס. חלצו אותו וצרפו את הקובץ שבתוכו.";
832
+ case "legacy_office": return "זהו קובץ Office ישן או מוגן בסיסמה. שמרו אותו מחדש וצרפו שוב.";
833
+ case "encrypted": return "קובץ ה-PDF מוגן בסיסמה.";
834
+ case "no_text": return "לא נמצא טקסט בקובץ. ייתכן שזהו מסמך סרוק.";
835
+ case "busy": return "השרת עמוס כרגע. נסו שוב בעוד רגע.";
836
+ case "exists": return "הקובץ הזה כבר צורף.";
837
+ default: return "לא ניתן לקרוא את הקובץ.";
838
+ }
839
+ case "store":
840
+ return "לא ניתן לגשת לקבצים כרגע. נסו שוב בעוד רגע.";
841
+ case "missing":
842
+ return info.code === "scope_missing" ? "השיחה הזו כבר לא קיימת." : "אחד הקבצים כבר לא זמין. צרפו אותו שוב.";
843
+ case "model":
844
+ switch (info.code) {
845
+ case "context_overflow": return "השיחה ארוכה מדי. פתחו שיחה חדשה, או שאלו על פחות קבצים.";
846
+ case "rate_limit": return "העוזר עמוס כרגע. נסו שוב בעוד דקה.";
847
+ case "timeout": return "התשובה התעכבה יותר מדי. נסו שוב.";
848
+ case "unreachable":
849
+ case "server": return "לא ניתן לקבל תשובה כרגע. נסו שוב.";
850
+ default: return "העוזר אינו זמין כרגע.";
851
+ }
852
+ case "aborted":
853
+ return info.code === "timeout" ? "השאלה ארכה יותר מדי זמן ונעצרה. נסו שוב." : "השאלה נעצרה.";
854
+ default:
855
+ // "input", "unknown", and categories of a later version.
856
+ return "משהו השתבש. נסו שוב מאוחר יותר.";
857
+ }
858
+ }
859
+ ```
860
+
861
+ A page that renders these messages sets `dir="rtl"` on their element (or `dir="auto"`), so that a
862
+ file name in Latin letters inside a sentence stays in its place.
863
+
864
+ Use it where an error reaches your code: the `catch` of a question, and a route of your own that
865
+ ingests files. It also reads the `error` of a `run.error` or `ingest.error` event, which is plain
866
+ data (`EventError`), so a stream to the browser can carry the same words. It reads such data by its
867
+ `code` (a refused file, a scope), its `name` (a store, documents or a scope) and its `kind` (a
868
+ model). A model's error always has its `kind` there: an error of an adapter of your own that has a
869
+ `status` (0, or 400 to 599) and no `kind` gets the kind its status, message and `code` give, as
870
+ `errorInfoOf` gives it for the error itself (`"rate_limit"` for a 429, `"quota"` for a 429 of code
871
+ `"insufficient_quota"`, `"server"` for a 503, `"auth"` for a 401). A system error's event (a path
872
+ `ingest` could not read: "The file could not be read from storage (ELOOP).") gives its code, as the
873
+ error does. Data with none of them
874
+ is `"unknown"`, with its `status` kept when it is 400 to 599 (a hook of yours that threw a `409`),
875
+ and `retryable` for 429, 502, 503 and 504:
876
+
877
+ ```ts
878
+ import type { ServerResponse } from "node:http";
879
+ import { askStream, errorInfoOf, type AskOptions } from "llm-large-files";
880
+ import { sseMessageOf, writeSseEvents } from "llm-large-files/node";
881
+
882
+ export async function streamInHebrew(res: ServerResponse, options: AskOptions): Promise<void> {
883
+ await writeSseEvents(res, askStream(options), {
884
+ map: (event) => sseMessageOf(event.type === "run.error"
885
+ ? { ...event, error: { ...event.error, message: hebrewMessage(errorInfoOf(event.error)) } }
886
+ : event),
887
+ });
888
+ }
889
+ ```
890
+
891
+ The upload handlers of `llm-large-files/node` answer in English. To answer in Hebrew there, ingest
892
+ in a route of your own and answer with `hebrewAnswer(error)`, or word the `error` of the JSON answer
893
+ and of `ingest.error` in the browser, by its status and `code`. The `ingest.error` of the handlers
894
+ also has the `name` of a store that failed (`"DocumentStoreError"`) and of a scope error
895
+ (`"DocumentScopeError"`, with `code` `"scope_missing"` for a deleted chat), and the `kind` of a
896
+ model's error (a `ModelRequestError` that an ingest or a hook of yours threw). So `errorInfoOf`
897
+ reads it as the handler answered the error, with the status of the JSON answer: a deleted chat is
898
+ `"missing"` and 404, a model that was busy `"model"`, `"rate_limit"` and 429. The event has no
899
+ `retryAfterMs`: the JSON answer sends the wait as `Retry-After`.
651
900
 
652
901
  ## Putting it together: a chat route
653
902
 
@@ -664,6 +913,7 @@ type Failure = { status: number; message: string; retryAfterSeconds?: number };
664
913
 
665
914
  /** What to tell the user about an error of a question, and the HTTP status to answer with. */
666
915
  export function toUserError(error: unknown): Failure {
916
+ // With onMissingDocuments: "drop", a question answers without its missing files instead.
667
917
  if (error instanceof DocumentsNotFoundError) {
668
918
  return { status: 404, message: "A file of this chat is no longer available. Attach it again." };
669
919
  }
@@ -741,7 +991,7 @@ throws them: see [Testing](./testing.md).
741
991
  `ModelErrorKind`, `classifyModelError`, `errorKindOf`, `withRetry`, `RetryOptions`,
742
992
  `RetryNotice`, `isRetryableStatus`, `retryAfterMs`, the default waits.
743
993
  - [The tool loop](../reference/ask.md): `askWithFiles`, `AskResult`, `partialResultOf`,
744
- `DocumentsNotFoundError`.
994
+ `DocumentsNotFoundError`, `answerInfoOf` and `AnswerInfo`.
745
995
  - [The library](../reference/library.md): `DocumentStoreError`, `ingest`, `prepare`.
746
996
  - The adapters and their options: [Gemini](../reference/gemini.md),
747
997
  [OpenAI-compatible](../reference/openai.md), [Claude](../reference/anthropic.md).
@@ -92,7 +92,10 @@ What `askGemini` gives each model:
92
92
  `firstByteTimeoutMs`, `idleTimeoutMs` and `fetch` apply to both models. `analysisConfig` is the
93
93
  `generationConfig` of the part reads of a whole-file read, which the explorer makes: write it for
94
94
  the explorer. `toolFilePlacement: "inside"` is read by Gemini 3 models; if either model is
95
- Gemini 2.5, use `"beside"`, which both read (see [PDFs](./pdfs.md)).
95
+ Gemini 2.5, use `"beside"`, which both read (see [PDFs](./pdfs.md)). Since 0.10.0,
96
+ `timeoutMs` (the time of one part read), `analysisBody`, `functionCallingMode` and
97
+ `answerWithoutTools` apply to both models too. `body` goes to the chat requests of both, unless
98
+ `explorerBody` is set for the explorer.
96
99
  - **The defaults of `gemini()`.** `askGemini` has no option for `contextTokens`,
97
100
  `maxRequestBytes`, `pageTokens` or `id`, so both of its models keep the defaults of `gemini()`:
98
101
  no window and no request size declared, 530 tokens a page, and the model's name from its URL in