llm-large-files 0.9.0 → 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 (222) hide show
  1. package/CHANGELOG.md +446 -0
  2. package/README.md +13 -7
  3. package/dist/access.d.ts +45 -3
  4. package/dist/access.d.ts.map +1 -1
  5. package/dist/access.js +106 -3
  6. package/dist/access.js.map +1 -1
  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 +115 -14
  24. package/dist/ask.d.ts.map +1 -1
  25. package/dist/ask.js +572 -103
  26. package/dist/ask.js.map +1 -1
  27. package/dist/citations.d.ts +36 -0
  28. package/dist/citations.d.ts.map +1 -0
  29. package/dist/citations.js +291 -0
  30. package/dist/citations.js.map +1 -0
  31. package/dist/error-info.d.ts +13 -0
  32. package/dist/error-info.d.ts.map +1 -1
  33. package/dist/error-info.js +37 -1
  34. package/dist/error-info.js.map +1 -1
  35. package/dist/errors.d.ts +3 -1
  36. package/dist/errors.d.ts.map +1 -1
  37. package/dist/errors.js +3 -1
  38. package/dist/errors.js.map +1 -1
  39. package/dist/events.d.ts +25 -7
  40. package/dist/events.d.ts.map +1 -1
  41. package/dist/events.js.map +1 -1
  42. package/dist/evidence.d.ts.map +1 -1
  43. package/dist/evidence.js +21 -2
  44. package/dist/evidence.js.map +1 -1
  45. package/dist/extract.d.ts.map +1 -1
  46. package/dist/extract.js +6 -1
  47. package/dist/extract.js.map +1 -1
  48. package/dist/gemini/adapter.d.ts +35 -4
  49. package/dist/gemini/adapter.d.ts.map +1 -1
  50. package/dist/gemini/adapter.js +68 -29
  51. package/dist/gemini/adapter.js.map +1 -1
  52. package/dist/gemini/chat.d.ts +28 -55
  53. package/dist/gemini/chat.d.ts.map +1 -1
  54. package/dist/gemini/chat.js +20 -27
  55. package/dist/gemini/chat.js.map +1 -1
  56. package/dist/gemini/endpoints.d.ts +59 -11
  57. package/dist/gemini/endpoints.d.ts.map +1 -1
  58. package/dist/gemini/endpoints.js +33 -7
  59. package/dist/gemini/endpoints.js.map +1 -1
  60. package/dist/gemini/errors.d.ts +39 -5
  61. package/dist/gemini/errors.d.ts.map +1 -1
  62. package/dist/gemini/errors.js +70 -9
  63. package/dist/gemini/errors.js.map +1 -1
  64. package/dist/gemini/generate.d.ts +53 -2
  65. package/dist/gemini/generate.d.ts.map +1 -1
  66. package/dist/gemini/generate.js +100 -50
  67. package/dist/gemini/generate.js.map +1 -1
  68. package/dist/gemini/index.d.ts +3 -3
  69. package/dist/gemini/index.d.ts.map +1 -1
  70. package/dist/http.d.ts +41 -3
  71. package/dist/http.d.ts.map +1 -1
  72. package/dist/http.js +40 -2
  73. package/dist/http.js.map +1 -1
  74. package/dist/index.d.ts +6 -4
  75. package/dist/index.d.ts.map +1 -1
  76. package/dist/index.js +4 -2
  77. package/dist/index.js.map +1 -1
  78. package/dist/ingest.d.ts +9 -1
  79. package/dist/ingest.d.ts.map +1 -1
  80. package/dist/ingest.js +50 -25
  81. package/dist/ingest.js.map +1 -1
  82. package/dist/library.d.ts +129 -2
  83. package/dist/library.d.ts.map +1 -1
  84. package/dist/library.js +224 -149
  85. package/dist/library.js.map +1 -1
  86. package/dist/map-reduce.d.ts +176 -10
  87. package/dist/map-reduce.d.ts.map +1 -1
  88. package/dist/map-reduce.js +804 -58
  89. package/dist/map-reduce.js.map +1 -1
  90. package/dist/model.d.ts +36 -4
  91. package/dist/model.d.ts.map +1 -1
  92. package/dist/model.js +17 -1
  93. package/dist/model.js.map +1 -1
  94. package/dist/node/handlers.d.ts +29 -8
  95. package/dist/node/handlers.d.ts.map +1 -1
  96. package/dist/node/handlers.js +148 -126
  97. package/dist/node/handlers.js.map +1 -1
  98. package/dist/node/index.d.ts +1 -1
  99. package/dist/node/index.d.ts.map +1 -1
  100. package/dist/node/index.js.map +1 -1
  101. package/dist/node/ingest-child.js +2 -2
  102. package/dist/node/ingest-child.js.map +1 -1
  103. package/dist/node/spool.d.ts +9 -5
  104. package/dist/node/spool.d.ts.map +1 -1
  105. package/dist/node/spool.js +28 -15
  106. package/dist/node/spool.js.map +1 -1
  107. package/dist/node/sse.d.ts +6 -5
  108. package/dist/node/sse.d.ts.map +1 -1
  109. package/dist/node/sse.js +8 -7
  110. package/dist/node/sse.js.map +1 -1
  111. package/dist/openai/adapter.d.ts +5 -1
  112. package/dist/openai/adapter.d.ts.map +1 -1
  113. package/dist/openai/adapter.js +53 -12
  114. package/dist/openai/adapter.js.map +1 -1
  115. package/dist/output-limit.d.ts +2 -1
  116. package/dist/output-limit.d.ts.map +1 -1
  117. package/dist/output-limit.js +5 -2
  118. package/dist/output-limit.js.map +1 -1
  119. package/dist/pdf-outline.d.ts +71 -0
  120. package/dist/pdf-outline.d.ts.map +1 -0
  121. package/dist/pdf-outline.js +414 -0
  122. package/dist/pdf-outline.js.map +1 -0
  123. package/dist/plan.d.ts +137 -7
  124. package/dist/plan.d.ts.map +1 -1
  125. package/dist/plan.js +248 -26
  126. package/dist/plan.js.map +1 -1
  127. package/dist/prepare.d.ts +50 -0
  128. package/dist/prepare.d.ts.map +1 -0
  129. package/dist/prepare.js +207 -0
  130. package/dist/prepare.js.map +1 -0
  131. package/dist/ranged.d.ts +2 -1
  132. package/dist/ranged.d.ts.map +1 -1
  133. package/dist/ranged.js +16 -3
  134. package/dist/ranged.js.map +1 -1
  135. package/dist/search.d.ts +7 -0
  136. package/dist/search.d.ts.map +1 -1
  137. package/dist/search.js +72 -10
  138. package/dist/search.js.map +1 -1
  139. package/dist/stores.d.ts +6 -0
  140. package/dist/stores.d.ts.map +1 -1
  141. package/dist/stores.js +82 -11
  142. package/dist/stores.js.map +1 -1
  143. package/dist/tools.d.ts +22 -2
  144. package/dist/tools.d.ts.map +1 -1
  145. package/dist/tools.js +323 -76
  146. package/dist/tools.js.map +1 -1
  147. package/dist/types.d.ts +49 -1
  148. package/dist/types.d.ts.map +1 -1
  149. package/dist/whole-cost.d.ts +37 -0
  150. package/dist/whole-cost.d.ts.map +1 -0
  151. package/dist/whole-cost.js +46 -0
  152. package/dist/whole-cost.js.map +1 -0
  153. package/docs/README.md +4 -0
  154. package/docs/guides/anthropic.md +5 -2
  155. package/docs/guides/conversations.md +1 -1
  156. package/docs/guides/costs-and-limits.md +132 -36
  157. package/docs/guides/deployment.md +106 -13
  158. package/docs/guides/errors-and-reliability.md +157 -45
  159. package/docs/guides/explorer-model.md +4 -1
  160. package/docs/guides/openai-compatible.md +47 -7
  161. package/docs/guides/own-adapter-and-loop.md +33 -6
  162. package/docs/guides/pdfs.md +96 -7
  163. package/docs/guides/storage.md +46 -3
  164. package/docs/guides/testing.md +71 -0
  165. package/docs/guides/vertex-and-gemini.md +159 -50
  166. package/docs/guides/web-app.md +10 -6
  167. package/docs/how-it-works.md +120 -22
  168. package/docs/measurements.md +172 -5
  169. package/docs/publishing.md +76 -4
  170. package/docs/reference/anthropic.md +12 -7
  171. package/docs/reference/ask.md +262 -35
  172. package/docs/reference/errors-and-retries.md +30 -2
  173. package/docs/reference/events.md +27 -10
  174. package/docs/reference/gemini.md +184 -68
  175. package/docs/reference/library.md +190 -23
  176. package/docs/reference/node.md +51 -17
  177. package/docs/reference/openai.md +21 -10
  178. package/docs/reference/tools.md +271 -26
  179. package/docs/security.md +101 -12
  180. package/docs/troubleshooting.md +14 -12
  181. package/docs/upgrading-0.10.md +472 -0
  182. package/package.json +5 -1
  183. package/src/access.ts +127 -4
  184. package/src/aggregate.ts +92 -14
  185. package/src/analyze.ts +2 -2
  186. package/src/answer-info.ts +45 -0
  187. package/src/anthropic/adapter.ts +40 -11
  188. package/src/ask.ts +646 -106
  189. package/src/citations.ts +294 -0
  190. package/src/error-info.ts +36 -1
  191. package/src/errors.ts +3 -1
  192. package/src/events.ts +29 -6
  193. package/src/evidence.ts +21 -2
  194. package/src/extract.ts +6 -1
  195. package/src/gemini/adapter.ts +99 -32
  196. package/src/gemini/chat.ts +53 -82
  197. package/src/gemini/endpoints.ts +89 -16
  198. package/src/gemini/errors.ts +74 -11
  199. package/src/gemini/generate.ts +147 -57
  200. package/src/gemini/index.ts +3 -3
  201. package/src/http.ts +65 -4
  202. package/src/index.ts +6 -4
  203. package/src/ingest.ts +58 -27
  204. package/src/library.ts +336 -142
  205. package/src/map-reduce.ts +855 -67
  206. package/src/model.ts +44 -4
  207. package/src/node/handlers.ts +159 -118
  208. package/src/node/index.ts +1 -0
  209. package/src/node/ingest-child.ts +2 -2
  210. package/src/node/spool.ts +28 -14
  211. package/src/node/sse.ts +8 -7
  212. package/src/openai/adapter.ts +56 -13
  213. package/src/output-limit.ts +5 -2
  214. package/src/pdf-outline.ts +400 -0
  215. package/src/plan.ts +287 -36
  216. package/src/prepare.ts +253 -0
  217. package/src/ranged.ts +16 -3
  218. package/src/search.ts +69 -13
  219. package/src/stores.ts +76 -11
  220. package/src/tools.ts +327 -75
  221. package/src/types.ts +45 -1
  222. package/src/whole-cost.ts +64 -0
package/CHANGELOG.md CHANGED
@@ -36,6 +36,452 @@ Grouped by area. One or two lines each, written for an app developer, with the n
36
36
  matter.
37
37
  -->
38
38
 
39
+ ## 0.10.0 — 2026-11-25
40
+
41
+ Counts that are right and a cost that is bounded, for a chatbot on Gemini. Tables sent whole get
42
+ exact counts, files sent whole get line numbers, and every question has a ceiling on input tokens
43
+ by default. Answers say how they ended, a store that stops answering no longer holds a question or
44
+ a server, Gemini requests take fields of your own, and a PDF whose headings are set in larger type,
45
+ Hebrew included, gets an outline. The text sent to the model changes on purpose, all at once: each
46
+ chat with files misses the provider's prompt cache once at the upgrade.
47
+ [Upgrading to 0.10](docs/upgrading-0.10.md) takes an application from 0.9.0 step by step, with the
48
+ Hebrew chatbot of the 0.9 guide carried over.
49
+
50
+ ### Upgrading: what you need to change
51
+
52
+ Code written for 0.9.0 compiles with 0.10.0, except in these cases
53
+ ([Does my code compile?](docs/upgrading-0.10.md#does-my-code-compile)):
54
+
55
+ - `NoticeCode` has two new members, `"answer_filtered"` and `"answer_cut"`; `ToolOutcome` one,
56
+ `"redacted"`; and `ModelReply.finish` one, `"other"`, which the `finish` of a `request.end` event
57
+ has too. An exhaustive `switch` over any of them, or a `Record` keyed by it, needs them. The new
58
+ `AskResult.finish` has the same members.
59
+ - The plan of `run.finish` and `run.error` (`EventResult.plan`) holds
60
+ `Omit<DocumentMeta, "owner" | "scope" | "sha256" | "original" | "metaVersion">`, and the result
61
+ of `eventResults: true` leaves those fields out at run time too. Code that reads them there fails
62
+ with TS2339. Read them from `AskResult.plan`.
63
+ - `createLargeFiles` returns `CreatedLargeFiles`, a `LargeFiles` whose `stats()` and `toolsFor()`
64
+ are required. A value typed `ReturnType<typeof createLargeFiles>` and made by hand (a mock), or a
65
+ variable whose type was inferred from it and that you later give a `LargeFiles` of your own,
66
+ fails with TS2322. Type it `LargeFiles`.
67
+ - `DocumentHandlers` has a required `stats()`. A `DocumentHandlers` made by hand (a mock) fails
68
+ with TS2741.
69
+ - `LargeFiles` has two new optional methods, `stats` and `toolsFor`. A `LargeFiles` of your own
70
+ with a member of either name and another type fails with TS2322 or TS2416. Rename it.
71
+ - `vertexAi` takes `VertexAiOptions`, a union of the token form and express mode (`apiKey`), and
72
+ its token function is typed with its `{ refresh }` argument. A value typed
73
+ `Parameters<typeof vertexAi>[0]` whose `project` you read as a string, or whose `accessToken`
74
+ you call with no argument, fails with TS2322 or TS2554. Type it
75
+ `Extract<VertexAiOptions, { project: string }>`, and call `accessToken({ refresh: false })`.
76
+ - A subclass of `UsageMeter` whose `add` takes a parameter of its own after `usage` fails with
77
+ TS2416: `add(model, usage, estimatedInputTokens?)` takes that place. Put yours after it.
78
+
79
+ The other changes to the public types add exports, options, fields and optional members.
80
+ `ModelReply.responseId` and `responseModel`, `ExtractedText.headings`, `ToolSet.wholeReadsLeft` and
81
+ `PreparedContext.toolable` are optional, so an adapter, an extractor, a tool set or a `LargeFiles`
82
+ of your own still compiles, unless it already has a field of the same name and another type. The
83
+ type of `askGemini`'s options is now `Omit<AskOptions, "model" | "explorer" | "messages"> &
84
+ GeminiOwnOptions`: no field was removed, and every option of `askWithFiles` reaches the loop. No
85
+ export was removed or renamed. The new exports are under **New**.
86
+
87
+ Some behavior is different. Check each point against your app:
88
+
89
+ - **One prompt-cache miss for each chat with files at the upgrade.** The text sent changes once:
90
+ files sent whole are numbered (`12| `), and when no file is searched the system text gets the
91
+ line `Cite line numbers like (report.docx L12).`; a table sent whole gets three tool
92
+ declarations, its `document_id` in its frame line, and a line of the system text that says to
93
+ count with them; `analyze_whole_document` is declared with two more arguments, `output` and
94
+ `labels`; the closing request after files shown in full asks for an answer from those files and
95
+ what the tools returned, with line citations, where 0.9's named only what the tools returned; and
96
+ on a card, a size between 999,500 and 999,999 tokens reads "1.0M", and one between 1,048,064 and
97
+ 1,048,575 bytes "1 MB", on a card and in `get_document_overview`'s `size` (LLF-059); error
98
+ messages that print a size in that range (upload and text limits, `view_pages`) read "1 MB" too.
99
+ After that one miss, the cache works across questions as in 0.9: a follow-up still differs from
100
+ its first stored round, which goes back as its calls.
101
+ **What to do:** nothing; the first question of each chat after the deploy costs its full input
102
+ ([Prompt caching](docs/guides/costs-and-limits.md#prompt-caching)).
103
+ - **A ceiling on input tokens by default.** A question that sets no `limits.inputTokens` stops
104
+ calling tools once what it spent, its next tool request and the answer would pass the larger of
105
+ `DEFAULT_INPUT_TOKENS` (1,000,000) and `toolTurns` times the estimate of its first request, plus
106
+ room for the whole-file reads it may make. It looks ahead before each tool request, and a request
107
+ that reports no input counts by its estimate. A question of four tool turns over a 3 MB log uses
108
+ less than half of it.
109
+ **What to do:** nothing, or set your own ceiling. `limits: { inputTokens: Infinity }` gives 0.9's
110
+ behavior ([The default ceiling](docs/guides/costs-and-limits.md#the-default-ceiling)).
111
+ - **At most 2 whole-file reads per question**, over all its documents. A third is refused with its
112
+ reason. **What to do:** `limits: { wholeReadsPerQuestion: Infinity }` gives 0.9's rule.
113
+ - **Tables sent whole get tools** (`inlineTables: "tools"`, the default of `askWithFiles` and
114
+ `askGemini`). A CSV, an XLSX workbook, or a DOCX, PPTX, PDF, HTML or Markdown file with a table of
115
+ at least 3 `| cell |` rows that is sent whole gets `search_document`, `read_document` and
116
+ `aggregate_table`, and the question runs the tool loop. A question with no count stays at one
117
+ request when the model answers at once; a count takes 2 or 3 (live, a median of 2 on both
118
+ models), each sending the table again; at most, about `toolTurns` times the first request (about
119
+ 1.5M input tokens for a CSV of 3,000 invoices), bounded by the ceiling. Live, input tokens on the
120
+ eval's cases shared with 0.9.0 were about 2.3 to 2.4 times 0.9.0's, and counts were right in 24
121
+ of 24 on both models
122
+ ([Measurements](docs/measurements.md#tables-sent-whole-p1s-live-gate)). Gemini 3.5 Flash-Lite
123
+ looks a row up with a tool even when the table is shown in full: 21 of 39 questions with no count
124
+ took one request (Gemini 3.8 Flash: 38 of 39), so a lookup takes 2, each sending the table. This
125
+ is recorded, not tuned. Limits sized for 0.9's one request (`toolTurns: 1`, `requests: 1`, an
126
+ `inputTokens` between one and two requests with the table) leave no tool turn: such a question
127
+ makes 0.9's one request, without tools.
128
+ **What to do:** nothing, or `inlineTables: "text"` for 0.9's cost and counts by eye
129
+ ([Tables sent whole](docs/guides/costs-and-limits.md#tables-sent-whole)).
130
+ - **Files sent whole are numbered** (`numberInline: true`, the default of `askWithFiles` and
131
+ `askGemini`), so that answers cite their lines: about 8% to 16% more tokens for each file, and a
132
+ file at the edge of `inlineTokens` may become a card. When no file is searched, the system text
133
+ gets the line `Cite line numbers like (report.docx L12).`.
134
+ **What to do:** nothing, or `numberInline: false` to send them as 0.9 did.
135
+ - **`AskResult.evidence` lists each file sent whole first**, as
136
+ `{ tool: "inline", documentId, document, lines: [[1, n]], whole: true }`, with no `callId`.
137
+ **What to do:** code that counts tool calls from evidence, or maps it to `tool.end`, skips the
138
+ entries without a `callId`.
139
+ - **What the opt-outs do not give back.** `inlineTables: "text"` and `numberInline: false` each
140
+ give 0.9's bytes for what they cover. With both, these stay: the `whole_file` hint of a
141
+ `read_document` result cut short, and the `filter_note` of `aggregate_table`; the declaration of
142
+ `analyze_whole_document` and the prompts of its part reads (M8); and the card sizes of LLF-059
143
+ ([What has a way back](docs/upgrading-0.10.md#going-back-to-09s-text)).
144
+ - **Rolling deploys.** What 0.10.0 stores is what 0.9 stores, so servers of both versions share a
145
+ store and nothing fails. But they send different text, so a chat answered by 0.9 and 0.10 servers
146
+ in turn misses the prompt cache on every switch.
147
+ **What to do:** deploy every server at once, or route each chat to one version until the rollout
148
+ ends. Run the sweep from a server of 0.10.0
149
+ ([Rolling deploys](docs/upgrading-0.10.md#rolling-deploys)).
150
+ - **Store calls have a time limit.** A `getMeta`, a read of a text, its index or its original, or a
151
+ `delete` that does not end within `storeTimeoutMs` (30 s) fails with a `DocumentStoreError` of
152
+ code `"ETIMEDOUT"` (503, to retry), where it hung. In a question, a store call that times out,
153
+ in a tool call or in a part of a whole-file read too, ends it with `run.error`: `execute` and
154
+ `executeWithFiles` throw it, where they returned an error result, and a page look at a hung
155
+ original is that error, where the model was told the file could not be read in time. While
156
+ `maxStuckStoreCalls` calls of the process are stuck past their limit (half of
157
+ `UV_THREADPOOL_SIZE`: 2 by default), store calls fail at once with code `"STORE_STUCK"` (503).
158
+ **What to do:** on servers that use a network volume, set `UV_THREADPOOL_SIZE=32`. Raise
159
+ `storeTimeoutMs` for a slow store, or set 0 for none
160
+ ([A store that stops answering](docs/guides/deployment.md#a-store-that-stops-answering)).
161
+ - **Transient system errors are 503 and retryable.** `ETIMEDOUT`, `ECONNRESET`, `ECONNREFUSED`,
162
+ `EPIPE`, `EAI_AGAIN`, `EAGAIN`, `EBUSY`, `EMFILE`, `ENFILE`, `ESTALE`, `EHOSTUNREACH` and
163
+ `ENETUNREACH` are 503 with `Retry-After: 5` in `errorInfoOf` and the upload handlers, and
164
+ `ENOSPC` and `EDQUOT` 503 with 30 s. They were 500, not to retry: "Upload failed (ETIMEDOUT)." is
165
+ now a 503. A path upload whose read does not answer within `ingestTimeoutMs` is such an
166
+ `ETIMEDOUT`, not the `IngestError` `"timeout"` (422) it was.
167
+ **What to do:** tell users to try again when `errorInfoOf(error).retryable` is true
168
+ ([Transient errors](docs/guides/errors-and-reliability.md#transient-errors-a-store-or-a-disk-that-does-not-answer)).
169
+ - **Gemini errors inside a stream, or in a reply of HTTP 200, are retried.** One with no numeric
170
+ code gets the status of its `google.rpc` name (`UNAVAILABLE` 503, `RESOURCE_EXHAUSTED` 429,
171
+ `DEADLINE_EXCEEDED` 504, 500 for a name it does not know), and a transient one is sent again up to
172
+ `retry.retries` times (3), unless text was already shown. It had status 200 and was not sent
173
+ again. A daily quota is still `"quota"`, and not sent again.
174
+ **What to do:** nothing.
175
+ - **Part reads that run out of time** are a `ModelRequestError` of kind `"timeout"` and status 0
176
+ in every adapter, sent again once after the first wait of `retry`. Before, it was the timer's
177
+ abort error, with no status. `timeoutMs: 0` now sets no limit; it aborted every part read at once.
178
+ **What to do:** nothing; `gemini({ timeoutMs })` and `askGemini`'s `timeoutMs` set the limit
179
+ ([Part reads](docs/guides/errors-and-reliability.md#part-reads-have-a-time-limit-of-their-own)).
180
+ - **Filtered and cut answers say so.** `result.finish` tells how the answer ended, an
181
+ `answer_filtered` or `answer_cut` notice comes before `run.finish`, and a reply that a filter or
182
+ another reason that asking again cannot mend ended (`finish` `"filtered"` or `"other"`) is not
183
+ asked for again: 2 requests over a searched file, where 0.9 made 4. Gemini's `MODEL_ARMOR`,
184
+ `IMAGE_PROHIBITED_CONTENT`, `IMAGE_RECITATION` and `IMAGE_OTHER` are now `"filtered"` (as
185
+ `IMAGE_SAFETY` was), and `OTHER`, `LANGUAGE` and four more `"other"`; they gave no finish.
186
+ `MALFORMED_RESPONSE` is now `"malformed_call"`: the turn is asked for once more.
187
+ **What to do:** switch on `answerInfoOf(result)` for the message to show. With
188
+ `filteredAnswer: "drop"`, take back streamed text when the notice has `discardText`
189
+ ([Filtered and cut answers](docs/guides/errors-and-reliability.md#filtered-and-cut-answers)).
190
+ - **A PDF ingested from 0.10.0 on** whose text gives fewer than 3 headings gets an outline from its
191
+ lines set at least 15% larger than its body, when 3 or more of them are found in its text. Its
192
+ card gains an "Outline" block, `get_document_overview` lists it, and search hits gain `section`.
193
+ A PDF with a title alone keeps the card and hits of 0.9. Documents already stored keep their
194
+ metadata until they are ingested again; `metaVersion` stays 1. A wrapper around the built-in PDF
195
+ extractor that returns only `text` and `pages` keeps the 0.9 outline.
196
+ **What to do:** pass `headings` on in such a wrapper (`{ ...extracted, text }`)
197
+ ([PDF outline](docs/guides/pdfs.md#pdf-outline)).
198
+ - **Tests that compare results, events or requests whole.** Requests change as the first point
199
+ says. `usage` gains `estimatedInputTokens` and `unmeasuredRequests` when a request reports no
200
+ input. Replies gain `responseId` and `responseModel` where the provider gives them. A malformed
201
+ call on the last tool turn now gets a closing request: one request more (LLF-048). The loop
202
+ answers a call of an unknown tool itself ("Unknown tool “x”. The tools are: …"), with outcome
203
+ `"refused"` and no `onActivity` line, where the tool set returned an `"error"`. A size between
204
+ 1,048,064 and 1,048,575 bytes reads "1 MB" on a card, in `get_document_overview` and in error
205
+ messages (LLF-059).
206
+ **What to do:** update the tests that compare these whole.
207
+
208
+ ### New: what you can add
209
+
210
+ **Answers and costs**
211
+
212
+ - **How an answer ended:** `AskResult.finish`, the notices `"answer_filtered"` and `"answer_cut"`,
213
+ `AskOptions.filteredAnswer` (`"keep"` or `"drop"`, with `discardText` on the notice), and
214
+ `answerInfoOf(result)` with `AnswerInfo`: one value to switch on, `"filtered"`, `"cut"`,
215
+ `"blocked"`, `"language"` (Gemini's `LANGUAGE`, not a filter), `"no_answer"` or `"other"`
216
+ ([Filtered and cut answers](docs/guides/errors-and-reliability.md#filtered-and-cut-answers)).
217
+ - **Citations checked:** `AskResult.citations` and `checkCitations` (`CitationCheck`). They read
218
+ "(name L12)", ranges, "line N", "Row N", and the Hebrew "שורה N" and "שורות N-M", and check each
219
+ against what the tools showed; a workbook's rows are unchecked (S3,
220
+ [CitationCheck](docs/reference/ask.md#citationcheck)).
221
+ - **`onToolResult`** (`ToolResultContext`, `ToolResultVerdict`): see each tool result before the
222
+ model does, and keep it, replace it (outcome `"redacted"`) or refuse it
223
+ ([Security](docs/security.md#tool-results-ontoolresult)).
224
+ - **Limits:** `limits.wholeReadsPerQuestion` and `DEFAULT_INPUT_TOKENS`; `UsageTotals`
225
+ `estimatedInputTokens` and `unmeasuredRequests`, and `UsageMeter.add(model, usage,
226
+ estimatedInputTokens?)` ([Costs and limits](docs/guides/costs-and-limits.md#the-limits-of-a-question)).
227
+ - **Response IDs:** `ModelReply.responseId` and `responseModel` from Gemini, OpenAI-compatible
228
+ servers and Claude, on `request.end` too.
229
+
230
+ **Tables and line numbers**
231
+
232
+ - `AskOptions.inlineTables` (`"tools"` by default) and `AskOptions.numberInline` (`true` by
233
+ default), also in `askGemini`. For loops of your own, `PrepareOptions.inlineTables` and
234
+ `numberInline` (off by default) and `PreparedContext.toolable`; and for the tool set,
235
+ `ToolOptions.inline` (the files sent whole) and `ToolOptions.declare` (exactly these tools), with
236
+ `declarationsFor(names)` and `ToolName`
237
+ ([Numbered lines and tables sent whole](docs/how-it-works.md#numbered-lines-and-tables-sent-whole)).
238
+
239
+ The chat of a Hebrew chatbot on Vertex AI and MongoDB:
240
+
241
+ ```ts
242
+ import { answerInfoOf, hashedScopeSegment } from "llm-large-files";
243
+ import { askGemini, vertexAi } from "llm-large-files/gemini";
244
+
245
+ const turn = { role: "user" as const, text: question };
246
+ const result = await askGemini({
247
+ files,
248
+ endpoint: vertexAi({ project, location: "global", model, accessToken }), // accessToken({ refresh })
249
+ body: { labels: { app: "chatbot", team: "hr" } }, // billing labels: no user IDs
250
+ documentIds: chat.documentIds,
251
+ messages: [...chat.messages, turn], // the stored turns and tool rounds, as in 0.9
252
+ owner: userId,
253
+ scope: [hashedScopeSegment(userId), chatId],
254
+ onMissingDocuments: "drop",
255
+ filteredAnswer: "drop",
256
+ });
257
+ const info = answerInfoOf(result); // complete, or why not: one switch for the Hebrew message
258
+ const answer = result.answered ? [{ role: "assistant" as const, text: result.text }] : [];
259
+ await chats.updateOne({ _id: chatId }, {
260
+ $push: { messages: { $each: [turn, ...result.toolTurns, ...answer] } }, // as in 0.9
261
+ });
262
+ ```
263
+
264
+ **Whole-file reads and tools**
265
+
266
+ - `analyze_whole_document` with `output: "items"` and `labels`: items judged by meaning, each
267
+ checked against its line, and counted by code (`total_items`, `counts_by_label`, `items`,
268
+ `unverified_items`, `parts_failed`, `parts_cut_short`; M9,
269
+ [Items](docs/reference/tools.md#items-output-items)).
270
+ - `notes_left_out` on a whole-read result, and `whole_file` on a `read_document` result cut short
271
+ of its range when a whole read would run.
272
+ - `ToolCallHooks.signal` (I9) and `ToolSet.wholeReadsLeft(documentId)`.
273
+
274
+ **Gemini and Vertex AI**
275
+
276
+ - `gemini()` and `askGemini` take `body`, `analysisBody` and `functionCallingMode` (`"AUTO"` or
277
+ `"VALIDATED"`), and `timeoutMs` for part reads; `askGemini` also `explorerBody`. Types
278
+ `GeminiRequestFields` and `GeminiOwnOptions` (A5,
279
+ [Fields of your own](docs/guides/vertex-and-gemini.md#fields-of-your-own-safety-settings-labels-and-more)).
280
+ - `answerWithoutTools` in `gemini()` and `askGemini`: `"omit"` (the default) or `"mode_none"` for
281
+ the request of the answer (NEW-answer-request-tools).
282
+ - `vertexAi({ headers, host, apiKey })` (`VertexAiOptions`); `apiKey` is Vertex AI express mode
283
+ (NEW-vertex-endpoint-options).
284
+ - `accessToken({ refresh })` and a `HeaderSource` that takes a context: after a 401, the request is
285
+ sent once more with a fresh token. `GeminiEndpoint.refreshable`
286
+ ([Access tokens](docs/guides/vertex-and-gemini.md#access-tokens-for-vertex-ai)).
287
+
288
+ **Operations**
289
+
290
+ - `storeTimeoutMs` (30,000), `sweepTimeoutMs` and `maxStuckStoreCalls` in `createLargeFiles`, and
291
+ the `DocumentStoreError` codes `"ETIMEDOUT"` and `"STORE_STUCK"`
292
+ ([Deployment](docs/guides/deployment.md#a-store-that-stops-answering)).
293
+ - `AccessOptions.signal`: ends the caller's own wait for the store.
294
+ - `files.stats()` (`LargeFilesStats`) and `handlers.stats()` (`DocumentHandlerStats`): counters for
295
+ metrics, alerts and readiness, read without a store call
296
+ ([files.stats()](docs/reference/library.md#filesstats)).
297
+ - `files.toolsFor(ids, options)` (I6), and the type `CreatedLargeFiles`.
298
+ - `sseMessageOf` sends `finish` and `citations` in `run.finish`.
299
+
300
+ **PDFs**
301
+
302
+ - `ExtractedText.headings`: a PDF's lines set larger than its body, with page, level and title,
303
+ and `skip`, how many lines above it on its page read the same (a contents list). The built-in
304
+ extractor returns them; an extractor of your own may too
305
+ ([PDF outline](docs/guides/pdfs.md#pdf-outline)).
306
+
307
+ ### Changed: what works differently
308
+
309
+ **Costs and limits**
310
+
311
+ - The ceiling on input tokens looks ahead before each tool request. A whole-file read is priced
312
+ before it starts by what its requests send: its numbered lines, its prompts, its merges, and the
313
+ heading line a part starts under. An items read is priced at its parts, with a frame of 650
314
+ tokens.
315
+ - A reply ended by a reason that asking again cannot mend (`"filtered"`, `"other"`) is neither
316
+ nudged nor asked for again. Over files sent whole alone (nothing searched or viewed), one with no
317
+ text ends the question without a closing request. Otherwise the closing request is made once, and
318
+ a filtered closing is not asked for again.
319
+ - The room for tool results is shared in tokens, at each document's own characters per token. A
320
+ result that would still pass the room is cut before the model gets it, in call order.
321
+ - A question that is stopped ends at once, even while `files.prepare`, a tool call or
322
+ `onToolResult` waits on a store that hangs.
323
+
324
+ **Tables, numbers and citations**
325
+
326
+ - A file counts as having a table when it has 3 rows of one table.
327
+ - `aggregate_table`: a filter that orders a column (`>`, `>=`, `<`, `<=`) against a value that
328
+ names another column compares the two cells of each row, and says so in `filter_note`. A column
329
+ letter works in every table. Over a table sent whole, a grouped result ends with a `cite` line.
330
+ - With an explorer, a question in which no file is searched, and a table sent whole gets the tools,
331
+ is run by the answering model alone: the files sent whole are not sent to two models.
332
+
333
+ **Whole-file reads, search and tools**
334
+
335
+ - Part reads send the part first and the task last, with the heading line the part starts under
336
+ first, and their system text marks the part as file content. Merges and the read's answer send
337
+ their notes first and the task last (M8).
338
+ - `analyze_whole_document` keeps 0.9.0's description word for word: items are told in `output`
339
+ only. A new description made Gemini 3.5 Flash-Lite skip whole reads.
340
+ - The item check counts a quote near its named line as verified (up to one letter in five
341
+ differs), finds a clause's line by the number it starts with, and repairs short `\u` escapes. The
342
+ rule asks for five to twelve words of the line, copied exactly.
343
+ - A whole read with more parts than `ToolCallLimits.maxRequests` is refused before any request; one
344
+ given `maxRequests` stops merging at it (`notes_left_out`, or `notes_only` when no request is left
345
+ for the answer). A whole read that could read no part is not tried again, even when
346
+ `maxWholeDocumentReads` is above 1.
347
+ - With `declare`, a tool set answers only the declared tools. `ToolSet.resultCharacters` is 600 for
348
+ a name the tool set does not answer.
349
+ - Exact search counts past 1,000,000 matching lines, within the time of a regex search (P8).
350
+ Keyword search keeps its top passages in a heap (P9).
351
+ - Measured live: Gemini 3.5 Flash-Lite's timeline of a diary read whole lost a date in about one
352
+ run in three, when a part replied `NOTHING RELEVANT`. An A/B with 0.9.0, 8 reads each, lost no
353
+ date on either. This is recorded as a limit of Flash-Lite, not tuned
354
+ ([Measurements](docs/measurements.md#whole-file-reads-and-items-package-t)).
355
+
356
+ **Gemini and other providers**
357
+
358
+ - A Gemini part read stopped by a filter or for an `"other"` reason is flagged as incomplete.
359
+ - A Vertex AI 401 with a token from a function is sent once more with a fresh token, in chat
360
+ requests, part reads and the explorer. A second 401 is the error; a refresh that throws keeps the
361
+ 401 as the error, with the refresh's error as its `cause`.
362
+ - A non-streamed Gemini reply that is a list of chunks is read chunk by chunk, and an error inside
363
+ a stream carries its `retryDelay`.
364
+ - `timeoutMs: 0` sets no limit in `openAiCompatible()` and `anthropic()` too.
365
+
366
+ **Storage and operations**
367
+
368
+ - Deletes of one library run one at a time, and one time limit covers a whole delete.
369
+ - `FileDocumentStore` writes a text longer than 1 Mi UTF-16 units in slices: a 50 MB put held the
370
+ event loop for 379 ms, and now for about 20 ms, with the same bytes.
371
+ - `FileDocumentStore` claims a removal by renaming the metadata to a name of its own, and counts
372
+ only its own removals.
373
+ - The upload handlers' calls to the disk past `uploadIdleTimeoutMs`, and ingest's store calls past
374
+ `ingestTimeoutMs`, count as stuck. At the limit, a sweep and ingest's store calls are refused too;
375
+ ingest's clean-up removal is not.
376
+
377
+ **PDFs**
378
+
379
+ - The outline of a PDF from type sizes: levels 1 to 3 from the sizes used by several headings, and
380
+ a title or cover line set larger than all of them is level 1. Not headings: table rows (a gap of
381
+ more than 3 times the type size between pieces), running headers and footers (a line repeated on
382
+ 3 or more pages, or on at least half of them), page numbers (lines that differ only by their
383
+ numbers, on at least half the pages, and that do not count up as section numbers do, on one page
384
+ or from page to page; the same number in a page's header and footer is one page number, while
385
+ headings that count up, such as "פרק 1" to "פרק 5" on the odd pages, are kept; chapters one to a
386
+ page, on pages in a row covering at least half the document, are taken for page numbers), lines
387
+ over 120 characters, and lines with fewer than 3 letters or more digits than letters. A PDF with
388
+ 3 or more text-rule headings keeps its outline, and the text of a PDF does not change.
389
+
390
+ **Release**
391
+
392
+ - The release workflow runs by hand as a dry run, the default: it builds and checks the tarball on
393
+ any branch or tag, then runs `npm publish --dry-run` in a job with no identity token
394
+ ([Publishing](docs/publishing.md#a-dry-run-of-the-release-workflow), LO-6).
395
+ - An eval suite of 48 Hebrew and English cases (in `evals/`, not published) replays its recorded
396
+ requests on every pull request. The prompt changes of this version were gated on it live, on
397
+ Gemini 3.5 Flash-Lite and 3.8 Flash: tables and line numbers by P1's gate (pass^3, at 64a4ec8),
398
+ whole-file reads and items by T's (at c1fbbb5)
399
+ ([Measurements](docs/measurements.md#tables-sent-whole-p1s-live-gate)). Each of its 96
400
+ recordings (48 cases on 2 models) replays against 0.10.0, so 0.10.0 sends the requests that were
401
+ recorded live, byte for byte but for keys and project IDs (T4;
402
+ [Testing](docs/guides/testing.md#the-librarys-own-evals)).
403
+
404
+ ### Fixed
405
+
406
+ **Questions and costs**
407
+
408
+ - **No ceiling by default, and a set one overshot (L5, L7):** a runaway question made 13 requests
409
+ and about 6.9M input tokens; a ceiling of 500,000 let 1,219,683 through, and never tripped when the
410
+ provider reported no usage.
411
+ - **L1:** results over tables of numbers took 2.22 times their room.
412
+ - **LLF-048:** on the last tool turn, the remark of a reply whose tool call could not be read was
413
+ taken for the answer.
414
+ - **LLF-049:** calls of unknown tools took room, and shortened earlier results.
415
+ - **LLF-058:** a whole-file read that had failed was priced again, instead of refused with its
416
+ reason.
417
+ - **N12:** a whole-file read passed `limits.requests`: 40 requests against 32, 42 through
418
+ `askWithFiles`.
419
+ - **A6, NEW-filtered-answer:** a reply that Gemini ended with `MODEL_ARMOR`, `OTHER`, `LANGUAGE` or
420
+ another reason the library did not know cost 4 requests and gave no finish, and a filtered or
421
+ cut answer read as complete ("The employee's medical leave was", `answered: true`).
422
+ - **LO-7:** with `eventResults`, event plans held owner, scope, sha256 and original at run time.
423
+ - `alreadyShown` could point to a result that `onToolResult` replaced.
424
+
425
+ **Tables and citations**
426
+
427
+ - **NEW-inline-table-tools:** a CSV of 3,000 Hebrew invoices went whole with no tools, and its 750
428
+ late invoices were counted by eye. Live, counts over tables were right in 24 of 24 on both
429
+ models.
430
+ - **L12:** files sent whole had no line numbers, citation line or evidence.
431
+ - **LLF-059:** card sizes read "1024 KB" and "1000K", and so did the size of
432
+ `get_document_overview` and of some error messages; they read "1 MB" and "1.0M".
433
+ - **LLF-061:** `describe()` of a `read_document` call left out an end line given as a string
434
+ (`"250"`), which the tool reads: it now says "lines 1-250".
435
+
436
+ **Providers**
437
+
438
+ - **LLF-018:** a Gemini error in a stream or a reply of HTTP 200 with no numeric code had status
439
+ 200; a part read whose body of HTTP 200 held an error reported "The model returned no text".
440
+ - **LLF-034:** an OpenAI call without an ID got an ID in its tool message that the call itself did
441
+ not have.
442
+ - **LLF-035:** a stream without `index` that repeated the ID on every piece made one call per piece.
443
+ - **LLF-036:** an aborted part read waited for another question's request: 1.5 s after an abort at
444
+ 50 ms, now 51 ms.
445
+ - **LLF-056, A11:** the time limit of a Gemini part read (180 s) could not be changed, and a part
446
+ read failed after 6 minutes; a timeout was not of kind `"timeout"`.
447
+ - **LLF-057:** Gemini encoded tool files with its own base64, beside the shared cache.
448
+ - A Gemini part read whose body was a list of chunks kept only the first chunk, and missed an error
449
+ in a later one.
450
+ - A part read's time limit did not end the wait for a `fetch` that ignores its signal, in all three
451
+ adapters.
452
+
453
+ **Storage and operations**
454
+
455
+ - **NEW-store-call-timeout:** a store that did not answer held a question, `files.delete`, the
456
+ DELETE route and the upload handler's rollback delete forever.
457
+ - **Four stuck calls froze a pod:** with the default thread pool, every file call and DNS look-up of
458
+ the process waited.
459
+ - On Windows, two sweeps could count one document twice, and two deletes of one document could both
460
+ return true.
461
+
462
+ **PDFs**
463
+
464
+ - **An unnumbered Hebrew PDF had no outline** (HARNESS-LESSONS item 4): Hebrew has no capitals, and
465
+ pdf.js gives no blank lines. A Hebrew lease now gets its title, sections and subsections, and the
466
+ isolated child returns the same outline as the server.
467
+
468
+ **Docs**
469
+
470
+ - **A1:** the OpenAI recipe uses `reasoning_effort: "none"`, which tool calls on GPT-5.4 and later
471
+ need through Chat Completions.
472
+ - **DeepSeek:** in a request with tools, its thinking mode asks for the reasoning of every earlier
473
+ assistant turn, those of earlier questions included, and refuses a request without it (HTTP 400,
474
+ as DeepSeek's guide says). The library does not keep the reasoning of an earlier question, so the
475
+ guide says to turn thinking off for chat requests in a chat of several questions
476
+ ([DeepSeek](docs/guides/openai-compatible.md#deepseek)).
477
+
478
+ In all, this version fixes LLF-018, -034, -035, -036, -048, -049, -056, -057, -058, -059 and
479
+ -061. It closes the roadmap items A5, A6, A11, I6 (`files.toolsFor`), I9 (`ToolCallHooks.signal`),
480
+ L1, L5, L7, L12, M8, M9, N12, P8, P9, S3 (in part: the citation check), T4, the leftovers of 0.9.0
481
+ (LO-1, LO-2 (the write half), LO-3 to LO-7), NEW-answer-request-tools, NEW-filtered-answer,
482
+ NEW-inline-table-tools, NEW-store-call-timeout and NEW-vertex-endpoint-options, and the Hebrew PDF
483
+ outline (HARNESS-LESSONS item 4).
484
+
39
485
  ## 0.9.0 — 2026-11-24
40
486
 
41
487
  One server process for every user and chat. Every store call carries the scope and the owner of
package/README.md CHANGED
@@ -6,7 +6,8 @@ context window**.
6
6
  Your users upload a 50 MB log or a 900-page book. Your model connector accepts 10 MB per request
7
7
  and 1M tokens of context. This package bridges the gap:
8
8
 
9
- - **Files that fit** go into the prompt whole.
9
+ - **Files that fit** go into the prompt whole, with their lines numbered. A table sent whole still
10
+ gets tools, so its counts and sums are exact.
10
11
  - **Files that don't** become a short summary card, and the model gets tools to **search**,
11
12
  **read line ranges**, or **read the whole file in parts** (map-reduce). Answers cite line numbers.
12
13
  - **Pictures in a PDF** are not in its text. The model can **look at the real pages** when it
@@ -114,7 +115,8 @@ text is asked for again, a repeated call gets a pointer to the result already sh
114
115
  each file is read whole at most once a question.
115
116
 
116
117
  A question that fails throws `DocumentsNotFoundError` for a file that expired, was deleted, or
117
- belongs to another `owner`, `DocumentStoreError` when the store cannot be read, or a
118
+ belongs to another `owner`, `DocumentStoreError` when the store cannot be read or does not answer
119
+ within 30 s (`storeTimeoutMs`), or a
118
120
  `ModelRequestError` whose `kind` (`"rate_limit"`, `"quota"`, `"timeout"`, `"context_overflow"`, …)
119
121
  tells you what to show the user. `partialResultOf(error)` gives what it found and paid for:
120
122
  [Errors and reliability](docs/guides/errors-and-reliability.md).
@@ -256,13 +258,14 @@ What each model gets, and what it costs: [An explorer model](docs/guides/explore
256
258
  |---|---|
257
259
  | **Formats** | Text, Markdown, logs (UTF-8 and UTF-16, and Hebrew, Arabic, Cyrillic, Japanese and Western European text in its older encoding), JSON/JSONL, CSV/TSV, HTML (the text a browser shows), DOCX (headings, clause numbers, tables, notes and comments), PPTX (slides in show order, tables, speaker notes), XLSX (every sheet, a line per row, with its row number), PDF (text layer, with tables rebuilt so empty cells stay empty; pages with a picture are marked, and the model can look at the pages themselves; scans of up to 30 pages when PDFs are kept) |
258
260
  | **Logs** | Detected automatically; the card shows level counts, the time range, and the most frequent errors grouped by shape (`timeout after <n>ms to <ip>`) |
259
- | **Books and documents** | An outline of headings with line numbers, including Markdown, "Chapter 12", numbered sections, and Hebrew chapter titles |
260
- | **Counting** | Exact counts of matching lines, per hour, per code or per message shape, in one search; exact sums, averages and groups over the rows of a CSV, an Excel sheet or a table of a document with `aggregate_table`, which reads every row and runs no code |
261
+ | **Books and documents** | An outline of headings with line numbers, including Markdown, "Chapter 12", numbered sections, and Hebrew chapter titles; for a PDF, Hebrew included, the lines set in larger type (new in 0.10.0) |
262
+ | **Counting** | Exact counts of matching lines, per hour, per code or per message shape, in one search; exact sums, averages and groups over the rows of a CSV, an Excel sheet or a table of a document with `aggregate_table`, which reads every row and runs no code. Since 0.10.0 a table small enough to be sent whole gets these tools too |
263
+ | **Citations** | Answers cite line numbers, of files sent whole too (numbered since 0.10.0); `result.citations` checks each against what the tools showed, Hebrew forms ("שורה 12") included |
261
264
  | **Every language** | Search finds a Hebrew word with any prefix letter, words written with or without accents, quotes or gershayim either way; regex `\w` and `\b` know every script |
262
265
  | **Limits** | One budget covers tokens *and* request bytes, so files fit both your context window and your connector's payload limit. It assumes 1M tokens and 10 MB: set `budget.contextTokens` for your model's window (an adapter's `contextTokens` can only make it smaller) |
263
- | **Reliability** | Retries, waits on a silent model, recovery from a request too large, error kinds: see [Errors and reliability](docs/guides/errors-and-reliability.md) |
266
+ | **Reliability** | Retries, waits on a silent model, recovery from a request too large, error kinds, answers that say when a filter or the output limit stopped them, and a time limit on every store call, so a network volume that hangs does not hold a server: see [Errors and reliability](docs/guides/errors-and-reliability.md) |
264
267
  | **Models** | Gemini and Vertex AI, any OpenAI-compatible endpoint, Claude, or an adapter of your own. Two models of different providers can share a question |
265
- | **Cost** | Usage summed over every request of a question, for each model, with ceilings on whole-file reads, requests and input tokens |
268
+ | **Cost** | Usage summed over every request of a question, for each model, with ceilings on whole-file reads, requests and input tokens; since 0.10.0 every question has a ceiling on input tokens by default |
266
269
  | **Privacy** | Documents can belong to an `owner`; other users can't plan, read, or delete them |
267
270
  | **Hostile uploads** | Limits on the text, pages and time of one file; zip bombs and PDFs built to exhaust a server are refused when the checks recognize them, with a code (`"hostile"`); ingest pauses for other requests between pages and slices. Not every hostile file is refused, and some steps hold the server for a while: read untrusted uploads in child processes with `createIsolatedExtractors`, which refuses a file that runs out of memory or time while the server goes on ([Security](docs/security.md#uploads)) |
268
271
  | **Storage** | In memory, on disk with expiry, or your own store (Redis, S3, a database) |
@@ -271,7 +274,9 @@ What each model gets, and what it costs: [An explorer model](docs/guides/explore
271
274
 
272
275
  With `gemini-3.8-flash` on the Gemini API, a 5 MB log of about 1.27M tokens, over the 1M window,
273
276
  got the right root cause of an outage, citing the right lines, in about 60 s over 11 tool calls.
274
- Every live result with its date, model and setup, and what has not been run live, such as the
277
+ For 0.10.0, an eval of Hebrew and English questions ran three times each on `gemini-3.5-flash-lite`
278
+ and `gemini-3.8-flash`: counts over tables sent whole were right in 24 of 24 on both. Every live
279
+ result with its date, model and setup, and what has not been run live, such as the
275
280
  Claude adapter: [Measurements](docs/measurements.md).
276
281
 
277
282
  ## Documentation
@@ -309,6 +314,7 @@ Reference, one page per module:
309
314
  - [`llm-large-files/testing`](docs/reference/testing.md): `fakeModel` and `fakeFetch`, for your tests (new in 0.9.0).
310
315
 
311
316
  [Changelog](CHANGELOG.md): what each version changed, and what to change in your code when you upgrade.
317
+ [Upgrading to 0.10](docs/upgrading-0.10.md) takes an application from 0.9.0 step by step.
312
318
 
313
319
  Also: [How it works](docs/how-it-works.md), [Security](docs/security.md),
314
320
  [Troubleshooting](docs/troubleshooting.md) and [Measurements](docs/measurements.md). For
package/dist/access.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type DocumentStoreOperation } from "./errors.js";
1
+ import { DocumentStoreError, type DocumentStoreOperation } from "./errors.js";
2
2
  import type { DocumentContext, DocumentMeta, DocumentScope } from "./types.js";
3
3
  /** The TypeError of a call without an owner, when the library requires one (`requireOwner`). */
4
4
  export declare const OWNER_REQUIRED = "owner is required: requireOwner is on";
@@ -23,6 +23,11 @@ export type Caller = {
23
23
  readonly context: DocumentContext;
24
24
  /** The key of the scope (`scopeKey`): what this caller's copies of documents are kept under in memory. */
25
25
  readonly key: string;
26
+ /**
27
+ * Ends this caller's waits for the store (`AccessOptions.signal`), with its reason: never a store
28
+ * call that other callers wait on too. New in 0.10.0.
29
+ */
30
+ readonly signal?: AbortSignal;
26
31
  };
27
32
  /** The context of a store call: a frozen object, without the fields that are absent. */
28
33
  export declare function storeContext(scope: DocumentScope | undefined, owner: string | undefined): DocumentContext;
@@ -30,11 +35,13 @@ export declare function storeContext(scope: DocumentScope | undefined, owner: st
30
35
  * The caller of a call made with `access`. Null is no owner and no scope, as a database gives a
31
36
  * field that was left out. The scope is checked (`checkScope`: a `DocumentScopeError` when it is
32
37
  * not valid). Under `requireOwner`, a call without an owner, or with one that `checkOwner` refuses,
33
- * is a TypeError; under `requireScope`, a call without a scope.
38
+ * is a TypeError; under `requireScope`, a call without a scope. A `signal` that is not an
39
+ * `AbortSignal` is a TypeError (0.10.0).
34
40
  */
35
41
  export declare function callerOf(access: {
36
42
  readonly owner?: unknown;
37
43
  readonly scope?: unknown;
44
+ readonly signal?: unknown;
38
45
  } | undefined, rules: AccessRules): Caller;
39
46
  /**
40
47
  * Whether `caller` may use the document `meta` describes. A document with an owner serves only that
@@ -67,14 +74,49 @@ export declare function documentContext(meta: DocumentMeta, caller: Caller): Doc
67
74
  * field that was left out, is left out.
68
75
  */
69
76
  export declare function metaOf(found: DocumentMeta | undefined, id: string): DocumentMeta | undefined;
77
+ /** Whether `ms` is a time limit a timer can keep: 0, and a time past what a timer can wait, are none. */
78
+ export declare const isTimeLimit: (ms: number) => boolean;
79
+ /** A time limit in the words of a message: "500 ms", "30 s", "2 min". */
80
+ export declare function formatDuration(ms: number): string;
81
+ /** Store calls of this process past their time limit that have not settled, and calls to the disk of the upload handlers. New in 0.10.0. */
82
+ export declare function stuckCalls(): number;
83
+ /**
84
+ * Counts `call` as stuck once it has run `ms` without settling, until it settles: whether or not
85
+ * anyone still waits for it. A call that settles within `ms` never counts, and nothing counts
86
+ * without a time limit (`isTimeLimit`). `late` is called when it passes `ms`. Returns `call`.
87
+ * New in 0.10.0.
88
+ */
89
+ export declare function watchStuck<T>(call: Promise<T>, ms: number, late?: () => void): Promise<T>;
90
+ /** The time limit of a store call, and the limit on calls left stuck, of one library (`storeTimeoutMs`, `maxStuckStoreCalls`). New in 0.10.0. */
91
+ export type StoreCallOptions = {
92
+ /** The most time the call may take, in milliseconds. 0, or a time past what a timer can wait, sets none. */
93
+ timeoutMs?: number;
94
+ /**
95
+ * While this many calls of the process are stuck (`stuckCalls`), the call is refused at once, with
96
+ * a `DocumentStoreError` of code "STORE_STUCK", and the store is not called. Defaults to no limit.
97
+ */
98
+ maxStuck?: number;
99
+ /** Whether the call counts as stuck once past `timeoutMs`. Defaults to true; false for a sweep. */
100
+ counts?: boolean;
101
+ /** Ends the caller's wait with its reason. The call itself goes on: a store call cannot be stopped. */
102
+ signal?: AbortSignal;
103
+ };
104
+ /** Refuses a call of `operation` while `maxStuck` calls of the process are stuck: the store is not answering. New in 0.10.0. */
105
+ export declare function checkStuck(operation: DocumentStoreOperation, maxStuck: number): void;
106
+ /** A store call that did not end within `ms`. */
107
+ export declare const storeTimeout: (operation: DocumentStoreOperation, ms: number) => DocumentStoreError;
70
108
  /**
71
109
  * A call of the store. What it throws is passed on as a `DocumentStoreError` of `operation`, with
72
110
  * the store's error as `cause`: the store's own error may name a path, a host or a bucket, and a
73
111
  * store that failed is not a document that is gone. A `DocumentStoreError` is passed on as it is,
74
112
  * and so is a `DocumentScopeError`: a scope the store cannot use is a mistake of the call, and the
75
113
  * same call would fail again.
114
+ *
115
+ * New in 0.10.0, `options`: a call that does not end within `timeoutMs` is a `DocumentStoreError`
116
+ * of code "ETIMEDOUT", and counts as stuck until it ends; while `maxStuck` calls are stuck, it is
117
+ * refused at once ("STORE_STUCK"); `signal` ends the caller's wait with its reason, as it is.
76
118
  */
77
- export declare function storeCall<T>(operation: DocumentStoreOperation, call: () => Promise<T>): Promise<T>;
119
+ export declare function storeCall<T>(operation: DocumentStoreOperation, call: () => Promise<T>, options?: StoreCallOptions): Promise<T>;
78
120
  /**
79
121
  * Refuses metadata written by a newer version of the package (`metaVersion` above
80
122
  * `DOCUMENT_META_VERSION`), which may mean what this version cannot tell: a `DocumentStoreError`
@@ -1 +1 @@
1
- {"version":3,"file":"access.d.ts","sourceRoot":"","sources":["../src/access.ts"],"names":[],"mappings":"AAEA,OAAO,EAA0C,KAAK,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAGlG,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE/E,gGAAgG;AAChG,eAAO,MAAM,cAAc,0CAA0C,CAAC;AACtE,+FAA+F;AAC/F,eAAO,MAAM,cAAc,0CAA0C,CAAC;AAEtE;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAG/C;AAED,mGAAmG;AACnG,MAAM,MAAM,WAAW,GAAG;IAAE,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAA;CAAE,CAAC;AAE7F,2GAA2G;AAC3G,MAAM,MAAM,MAAM,GAAG;IACnB,QAAQ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