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
@@ -6,7 +6,7 @@ loop of your own, show `steps` to users, keep `toolTurns`, or want to know exact
6
6
  was told and what it read.
7
7
 
8
8
  ```ts
9
- import { MAX_VIEW_PAGES, MAX_WHOLE_DOCUMENT_READS, REGEX_BUDGET_MS, TOOL_NAMES, toolResultSummary } from "llm-large-files";
9
+ import { declarationsFor, MAX_VIEW_PAGES, MAX_WHOLE_DOCUMENT_READS, REGEX_BUDGET_MS, TOOL_NAMES, toolResultSummary } from "llm-large-files";
10
10
  import type { JsonSchema, ToolCallLimits, ToolDeclaration, ToolFile, ToolFileLimits, ToolOutput, ToolResult, ToolSet } from "llm-large-files";
11
11
  ```
12
12
 
@@ -19,7 +19,7 @@ Contents:
19
19
  [`analyze_whole_document`](#analyze_whole_document), [`view_pages`](#view_pages)
20
20
  - [The tool guide](#the-tool-guide)
21
21
  - [What `askWithFiles` adds to results](#what-askwithfiles-adds-to-results)
22
- - Exports: [`TOOL_NAMES`](#tool_names), [`MAX_VIEW_PAGES`](#max_view_pages),
22
+ - Exports: [`TOOL_NAMES`](#tool_names), [declarationsFor(names)](#declarationsfornames), [`MAX_VIEW_PAGES`](#max_view_pages),
23
23
  [`MAX_WHOLE_DOCUMENT_READS`](#max_whole_document_reads), [`REGEX_BUDGET_MS`](#regex_budget_ms),
24
24
  [toolResultSummary(label, result)](#toolresultsummarylabel-result), [`ToolSet`](#toolset),
25
25
  [`ToolCallLimits`](#toolcalllimits), [`ToolFileLimits`](#toolfilelimits),
@@ -90,6 +90,24 @@ Through `files.tools(documents, options)` (a loop of your own, see [`ToolSet`](#
90
90
  - `view_pages` is declared when `options.viewPages` names at least one PDF whose `originalKept` is
91
91
  true and the store has `getOriginal`: `true` means every PDF in `documents`, and a list (such as
92
92
  `prepared.viewable`) means exactly those.
93
+ - `options.declare` (new in 0.10.0) declares exactly the tools it names, in place of the rules
94
+ above, always in the order search, read, overview, aggregate, analyze, view, whatever the order
95
+ of the list: what [declarationsFor(names)](#declarationsfornames) gives. `askWithFiles` uses it
96
+ when tables are sent whole (`inlineTables`), to declare exactly the tools of the question: for
97
+ those tables search, read and aggregate, not overview or a whole-file read. A list of your own may
98
+ name a tool that has nothing to work on: each call of it then answers with the reason,
99
+ `No attached file has a table: aggregate_table needs one.` for `aggregate_table` when no document
100
+ may hold a table, `No attached file has pages to look at: view_pages needs a PDF whose original
101
+ file is kept. Answer from the text.` for `view_pages` with no PDF to look at, and
102
+ `Whole-document analysis is not enabled.` for `analyze_whole_document` without `generate`. It
103
+ answers those tools and no other: a call of a tool it does not name gets `Unknown tool “NAME”.`,
104
+ and `has(name)` is false, where without `declare` `aggregate_table` and (with `generate`)
105
+ `analyze_whole_document` are answered when not declared. With today's set, `declare` gives
106
+ today's bytes.
107
+ - `options.inline` (new in 0.10.0) lists the IDs of documents whose text is in the prompt. Pass
108
+ them among `documents` too, so that the text tools can count and search them;
109
+ `analyze_whole_document` refuses them (see [its errors](#analyze_whole_document)), and
110
+ `wholeReadsLeft` is 0 for them.
93
111
 
94
112
  ## Rules for every tool
95
113
 
@@ -123,9 +141,28 @@ storage (EIO). Try the call again.", and a store that could not be read gives th
123
141
  | `document_id is required.` | `document_id` is missing or blank. |
124
142
  | `Unknown document_id ID. Use one of: doc_… ("app.log"), ….` | `search_document`, `read_document`, `get_document_overview`, `analyze_whole_document`: the ID is not one of the tool set's documents. Up to 20 usable IDs are listed, each with its file name, and `…` when there are more. |
125
143
  | `Unknown document_id ID. No attached file is read with this tool in this conversation.` | `search_document`, `read_document`, `get_document_overview`, `analyze_whole_document`: the tool set has no document for these tools. |
126
- | `ID is no longer available on the server. Ask the user to attach the file again.` | The document was deleted or expired after the request was planned. |
144
+ | `ID is no longer available on the server. Ask the user to attach the file again.` | The document was deleted or expired after the request was planned, or its text went while a search or read went through it. Since 0.9.0 the call's hooks are told (`ToolCallHooks.onDocumentGone`), and `askWithFiles` gives a `"document_gone"` notice. |
127
145
  | `Unknown tool “NAME”.` | The name is not a tool of this tool set. The name is cut at 64 characters, never in the middle of a character. Until 0.6.0: `Unknown tool NAME.`, with the whole name. |
128
146
 
147
+ **Store timeouts.** Since 0.10.0 a call does not answer the model when the store did not answer in
148
+ time: a [`DocumentStoreError`](./library.md#documentstoreerror) of code `"ETIMEDOUT"` (a store call
149
+ past `storeTimeoutMs`, or a system error of that code), or of code `"STORE_STUCK"` (refused at once
150
+ because too many store calls of the process are stuck). `execute` and `executeWithFiles` throw it,
151
+ from any tool and from any part of a whole-file read, which would otherwise count as a part that
152
+ could not be read. The other parts of that read stop then: their requests under way are aborted
153
+ through the signal they were sent with, and no part is sent after it. In `askWithFiles` the question then ends with a `run.error`, which
154
+ [errorInfoOf(error)](./errors-and-retries.md#errorinfooferror) reads as a 503 to try again, and the model is sent no
155
+ new text. Until 0.10.0 the model read "The document store could not be read (ETIMEDOUT). Try
156
+ again." and went on, with a store that was not answering. Any other store error is still an error
157
+ result for the model.
158
+
159
+ **A call's own signal.** `ToolCallHooks.signal` (new in 0.10.0, the fourth argument of
160
+ `executeWithFiles`) ends that call alone: its load of the document, its search, its regex time, its
161
+ whole-file read, its wait for a turn to look at pages, its read of the original, and the check made
162
+ once it has read, that the store still holds the document it loaded. It is joined
163
+ with the tool set's `signal`. The call throws the signal's reason, as for the tool set's own; the
164
+ other calls of the tool set go on.
165
+
129
166
  **Size.** One result is at most `toolResultCharacters` characters of JSON (a field of
130
167
  [`Budget`](./library.md#budget): 24,000 with the default budget, less for a model with a small
131
168
  window). The answer of `analyze_whole_document` may have up to the larger of that and 40,000.
@@ -214,14 +251,18 @@ language.
214
251
  matches its plain form, as inside a longer word: כסף finds כספים. New in 0.8.0.
215
252
  - A passage is a run of whole lines of about 1,500 characters, or 40 lines at most. A passage that
216
253
  contains the whole query as a phrase (more than one term, up to 200 characters) is ranked higher.
217
- - Passages come best first. `score` is rounded to two decimals and only orders the results.
254
+ - Passages come best first; of two with the same score, the one nearer the start of the file.
255
+ `score` is rounded to two decimals and only orders the results. Since 0.10.0 the search keeps only
256
+ the best passages as it goes, rather than sorting every passage it scored.
218
257
  - A query with no usable term, or with no hit, returns no passage and the note "No passage contains
219
258
  these keywords. Try other words, synonyms, or exact mode."
220
259
 
221
260
  **`exact`** finds every line that contains the text. A line counts once, however many times it
222
261
  contains the text. A text with a line break matches across lines and counts on each line where it
223
- starts, overlapping ones included: "a\na" counts 2 lines of "a\na\na" (1 until 0.8.0). The scan
224
- stops after 1,000,000 matching lines, and with `whole_word` or `group_by` after 3 seconds. The query is composed (NFC), as the text is at ingest, so
262
+ starts, overlapping ones included: "a\na" counts 2 lines of "a\na\na" (1 until 0.8.0). Past
263
+ 1,000,000 matching lines the scan goes on counting within 3 seconds, the time of a regex search, and
264
+ stops there (until 0.10.0 it stopped at 1,000,000, and a count of 1,200,000 lines read 1,000,000); with
265
+ `whole_word` or `group_by` it stops after 3 seconds in all. The query is composed (NFC), as the text is at ingest, so
225
266
  "é" typed as "e" and an accent finds "é". Without `case_sensitive`, both sides are folded: lower
226
267
  case, Greek final sigma as σ, curly quotes and primes as `'` and `"`, dashes and the minus sign as
227
268
  `-`, no-break and thin spaces as a space, Hebrew geresh, gershayim and maqaf as `'`, `"` and `-`,
@@ -260,7 +301,7 @@ Results of `exact` and `regex`:
260
301
  | `total_matching_lines` | number | Every matching line in the file (or in `searched_lines`), not only those shown. This is the number to count with. |
261
302
  | `order` | `"last"`, optional | With `order: "last"` ([below](#the-last-matches-order-last)). |
262
303
  | `table_headers` | array, optional | When matches are rows of a table: the first row of each such table, as `{ line, text }`, up to 5: line 1 of a CSV file, the first row of each sheet of a workbook a match is in, the first row of each `\| cell \|` table elsewhere (looked for up to 20,000 lines above the match). Absent when no match is a row of a table, or the match is that first row. New in 0.8.1. |
263
- | `note` | string, optional | When more lines match than are shown: "N of the M matching lines are shown: the first K and the last (line L). To see the ones in between, search again with from_line F, or count them with group_by." ("the first and the last" when K is 1). Until 0.8.0 it ended "narrow the search." When the scan stopped (1,000,000 lines, 3 seconds of a `whole_word` or `group_by` search, or a regex limit): "The scan stopped early; the total is a lower bound, and the last match in the file is not known." Or a size-limit note (below). Absent when every match is shown. |
304
+ | `note` | string, optional | When more lines match than are shown: "N of the M matching lines are shown: the first K and the last (line L). To see the ones in between, search again with from_line F, or count them with group_by." ("the first and the last" when K is 1). Until 0.8.0 it ended "narrow the search." When the scan stopped (3 seconds past 1,000,000 lines, 3 seconds of a `whole_word` or `group_by` search, or a regex limit): "The scan stopped early; the total is a lower bound, and the last match in the file is not known." Or a size-limit note (below). Absent when every match is shown. |
264
305
  | `next_from_line` | number, optional | When matches between the first ones and the last one are not shown: the line after the last of the first ones (F above). A search with `from_line` set to it shows the ones after. Absent when every match is shown, when the scan stopped early, with `order: "last"` and with `group_by`. New in 0.8.0. |
265
306
  | `matches` | array | The first `max_results` matching lines, in file order, then the last matching line of the file when it is not among them. A scan that stopped early shows no last line, since it did not reach the end. With `order: "last"`, the last `max_results` matching lines, in file order. |
266
307
  | `matches[].line` | number | The line number. |
@@ -338,7 +379,7 @@ To fit its room, it loses the earliest of them first, and keeps the very last. T
338
379
  file: the last match is on line L, and the first on line F. Narrow the query or read specific
339
380
  lines."
340
381
 
341
- When the scan stopped early (1,000,000 lines, 3 seconds of a `whole_word` or `group_by` search, or a regex limit), the lines shown are the last of
382
+ When the scan stopped early (3 seconds past 1,000,000 lines, 3 seconds of a `whole_word` or `group_by` search, or a regex limit), the lines shown are the last of
342
383
  those it found, and the line of the first match is not named. The note is then "The scan stopped
343
384
  early; the total is a lower bound. These are the last N matching lines it found, in the order of
344
385
  the file. There may be later ones, after line L: search again with from_line F." (F is L + 1;
@@ -455,7 +496,8 @@ The tables it reads:
455
496
 
456
497
  A column is named as in the header (case and spaces ignored), by its letter (`C`) or number (`3`),
457
498
  or by the lower part of a joined header ("הכנסות" for "פברואר / הכנסות") when only one column has
458
- it. Numbers are read as people write them: `1,234.5`, `-12`, `(1,200)` for a negative, `₪4,750`,
499
+ it. A letter or a number names a column only when no column has that name; until 0.10.0 a letter
500
+ named one only in a sheet with no header. Numbers are read as people write them: `1,234.5`, `-12`, `(1,200)` for a negative, `₪4,750`,
459
501
  `$ 12.00`, `12%` (12), `1 234`, `12,5` (a decimal comma), `1.234,56`. A sum or average leaves out
460
502
  cells that are not numbers, and says how many (`values_not_numbers`); `min` and `max` of ISO dates
461
503
  compare them as text. Up to 10,000 groups are counted one by one; rows of further groups are
@@ -475,6 +517,8 @@ Result:
475
517
  | `total_groups` | number, optional | Groups found, with `group_by`. |
476
518
  | `groups` | array | One entry a group: `group` (the value of each group-by column, as its first row writes it), each metric by its name (`count`, `"sum:Revenue"`: null when no row of the group had a number there), `rows` when `count` was not asked, and `lines`, the lines of its first 3 rows. |
477
519
  | `note` | string, optional | "N of the M groups are shown…", when `limit` cut them. |
520
+ | `cite` | string, optional | For a table sent whole (`ToolOptions.inline`), when a group was found: how to cite the lines listed, with the file's name, as "Cite the lines listed in your answer, like (orders-2026.csv L5, L10, L15)." Over a table shown in full, Flash-Lite answered with the count alone. Its last field. New in 0.10.0. |
521
+ | `filter_note` | string, optional | A filter whose value names a column, compared with that column's cell in each row: "Each row's \"Q1 / Actual\" was compared with its own \"Q1 / Budget\" (>), as the filter's value names that column." New in 0.10.0. |
478
522
  | `values_not_numbers`, `other_rows`, `repeated_header_rows`, `irregular_rows` | optional | Cells left out of a metric, rows of groups past 10,000, header rows found again inside the table, and rows with values past the header's columns (a sign that the header was read wrong). |
479
523
 
480
524
  ```json
@@ -498,6 +542,17 @@ names 3 columns of this table: …. Name one of them in full.", "No table \"Budg
498
542
  has 3 sheets…", "This file has no table to aggregate…". `evidence` cites the header line and each
499
543
  group's lines; a result dropped to make room keeps its largest 30 groups.
500
544
 
545
+ A filter that orders a column (`>`, `>=`, `<`, `<=`) against a value that is not a number and
546
+ names a column (its full name, the lower part of a joined header, or a letter when the filter's own
547
+ column is a letter too: `C` > `B`) compares the two cells of each row, since 0.10.0: `{ "column":
548
+ "Q1 / Actual", "op": ">", "value": "Q1 / Budget" }` keeps the rows that spent more than their Q1
549
+ budget. Two numbers compare as numbers and two texts as text; a number against a text, or an empty
550
+ cell, does not match. The result says so in `filter_note`. A value that is the lower part of
551
+ several columns is an error that names them. Before, the value was compared as text: the filter
552
+ matched no row, and said nothing of why. `=`, `!=` and the text filters keep a value that is also a
553
+ column's name as a value ("Department" != "Total"). The description the model sees does not
554
+ mention it: the models write such filters unasked.
555
+
501
556
  ## `read_document`
502
557
 
503
558
  The description the model sees:
@@ -516,6 +571,32 @@ shortened (to 70% of its length, step by step) until it fits, and `next_start_li
516
571
  go on. When one line alone is longer than that, its text is cut to half of that room and
517
572
  `text_cut` is `true`.
518
573
 
574
+ A read cut short of its range that way also says, in `whole_file`, that the whole file can be
575
+ read with `analyze_whole_document`, when all of these hold (new in 0.10.0), so that it points only
576
+ at a read that the tool set and the question's limits would let through on the model's next turn,
577
+ by the read's estimated parts:
578
+
579
+ - the tool set declares `analyze_whole_document` and has a part reader (`generate`);
580
+ - the file can be read whole: it is not sent whole in the prompt (`ToolOptions.inline`), a
581
+ whole read of it is left (`maxWholeDocumentReads`, and no earlier read of it that could read no
582
+ part), and its estimated parts are within `maxMapChunks` (without the margin of 5% that the
583
+ declaration and the card give the estimate: the read counts its parts, and may count one more)
584
+ and within the call's [`ToolCallLimits.maxRequests`](#toolcalllimits), when it has one. In
585
+ `askWithFiles` that is what `limits.requests` leaves once the next turn, which calls the read,
586
+ and the answer of the question have their requests; and 0 when the question would not start a
587
+ whole read of the file on that turn: one that would pass its ceiling on input tokens or requests
588
+ (`limits.inputTokens`, `limits.requests`) with that turn's request counted, or one more than its
589
+ `wholeReadsPerQuestion`;
590
+ - the result, with it, stays within its cap.
591
+
592
+ At a border the hint can still point at a read that is then refused, before it sends any request:
593
+ the read can count one part more than the estimate, and the next turn's request is counted at the
594
+ size of the conversation before this turn's results.
595
+
596
+ A read that shows every line asked for, and one shortened only to 600 lines, have no `whole_file`.
597
+ Gemini 3.5 Flash-Lite and 3.8 Flash read a contract they were asked to summarize in ranges of about
598
+ 16 lines, and answered from those, when a whole read would have given all of it.
599
+
519
600
  | Field | Type | Meaning |
520
601
  |---|---|---|
521
602
  | `document` | string | The file name. |
@@ -526,6 +607,7 @@ go on. When one line alone is longer than that, its text is cut to half of that
526
607
  | `text_cut` | `true`, optional | The one line shown was cut: its end is missing. |
527
608
  | `next_start_line` | number, optional | The first line not shown, when the file goes on. |
528
609
  | `note` | `"End of file."`, optional | Instead of `next_start_line`, when the last line shown is the file's last. |
610
+ | `whole_file` | string, optional | "Only N lines fit here. To read all M lines for a task that needs all of them, such as a full summary or a timeline, use analyze_whole_document." ("Only 1 line fits here" for one; "Not even one line fits here: the text of line N is cut." when `text_cut` is `true`), on a read cut short of its range by the size limit when the file can be read whole (see above). New in 0.10.0. |
529
611
 
530
612
  ```json
531
613
  { "document": "app.log", "lines": "1200-1399", "total_lines": 5000, "text": "1200| ...\n1201| ...", "next_start_line": 1400 }
@@ -571,19 +653,53 @@ The description the model sees:
571
653
  |---|---|---|---|
572
654
  | `document_id` | string | yes | The document. |
573
655
  | `task` | string | yes | What to find or produce from the whole file, stated completely. Not blank (`task is required.`). |
656
+ | `output` | `"answer"` \| `"items"` | no | `"answer"`, the default: one answer written from the notes of every part, for a summary, a timeline, or a description of events. `"items"`: to count the items of a kind that must be judged by meaning, such as the clauses that set a fine; each part lists them, each with its line and a quote checked against the file, and the result counts them, by label ([below](#items-output-items)). Any other value is `"answer"`. New in 0.10.0. |
657
+ | `labels` | string[] | no | With `output: "items"`: the kinds of item to label each one with, such as `["penalty", "deadline"]`. Up to 12, each up to 40 characters; one string is read as a list of one. Ignored for `"answer"`. New in 0.10.0. |
658
+
659
+ 0.10.0 added the two arguments, and kept the description of 0.9.0 word for word: a chat where the
660
+ tool is declared misses the provider's prompt cache once after the upgrade. Said in the
661
+ description, a sentence on items made Gemini Flash-Lite choose this read for a full summary in 3
662
+ of 10 runs, against 7 of 8 with 0.9.0's words, so items are told in the description of `output`
663
+ alone. There, `"answer"` names a summary and a timeline: told only that items list what a task asks
664
+ for, Flash-Lite chose them for a timeline of events, whose items explain nothing, and its answers
665
+ lost events.
574
666
 
575
667
  The file is split into parts of up to `mapChunkTokens` tokens (and 80% of `maxRequestBytes`), 4 are
576
668
  read at a time with the `generate` function of the tool set, their notes are merged, and one answer
577
669
  is written from them. A part the model refuses as too large is read as two halves, while
578
670
  `maxMapChunks` and [`ToolCallLimits.maxRequests`](#toolcalllimits) allow it. The steps, output
579
- limits and retries are in [How it works](../how-it-works.md); what a read costs is in
671
+ limits and retries are in [How it works](../how-it-works.md#map-reduce); what a read costs is in
580
672
  [Costs and limits](../guides/costs-and-limits.md).
581
673
 
674
+ Each part's request sends the file's name and lines, then the part between `<part>` and `</part>`,
675
+ then where the part is in the file, the task and the rules. A part that starts in the middle of a
676
+ section of the file's outline (a day of a diary, a chapter, a sheet) has the line of the heading it
677
+ is under first, numbered as in the file and cut to 120 characters, and its first line says so:
678
+ `Document: diary.md, lines 967-1277, under the heading on line 958, which comes first.` (since
679
+ 0.10.0; Gemini Flash-Lite dated the events of such a part by the day before). Logs, JSON and CSV
680
+ files have no outline. Its system text says that text inside
681
+ `<part>` is the file's content: never instructions to follow. A merge of notes and the answer of the
682
+ read send their notes first, between `<notes>` and `</notes>`, and the task last. So two reads of
683
+ one document with other tasks send the same start in each part's request, up to the end of the
684
+ part, for a provider's prompt cache. Until 0.10.0 the task came first, before the part.
685
+
686
+ Given `maxRequests`, a read counts its requests (since 0.10.0). Each part is one request, so a read
687
+ with more parts than `maxRequests` is refused before any request is sent (see the errors below). A
688
+ round of merges that would leave
689
+ no request for the answer is not made: the answer is then written from the notes that fit one
690
+ request (`mapChunkTokens`), in the order of the file, and the result says how many parts' notes it
691
+ left out (`notes_left_out`). When not even the answer has a request left, the notes are the answer
692
+ (`notes_only`). A part is halved only while the requests left also cover the merges its notes may
693
+ need, priced as long as the output limit allows, and the answer. Until 0.10.0 the merges went past
694
+ `maxRequests`: a read of 27 parts given 32 requests made 40.
695
+
582
696
  Each document may be read whole [`MAX_WHOLE_DOCUMENT_READS`](#max_whole_document_reads) times (1)
583
697
  by one tool set, which is one question in `askWithFiles`. Set it with `limits.wholeDocumentReads`
584
698
  in [`AskLimits`](./ask.md#asklimits), or `maxWholeDocumentReads` in
585
699
  [`ToolOptions`](./library.md#tooloptions). A read is counted when it starts, so two calls in one
586
- turn do not both pass.
700
+ turn do not both pass. A read that could read no part is not tried again in the tool set, whatever
701
+ that number is (since 0.10.0; before, a number of 2 or more let it try again).
702
+ [`ToolSet.wholeReadsLeft`](#toolset) says how many reads of a document are left.
587
703
 
588
704
  | Field | Type | Meaning |
589
705
  |---|---|---|
@@ -592,9 +708,10 @@ turn do not both pass.
592
708
  | `parts_with_relevant_content` | number | The parts that were read and held something for the task. |
593
709
  | `parts_that_failed` | number, optional | Parts that could not be read. The notes name each one: "[This part could not be read: reason]". |
594
710
  | `notes_cut_short` | number, optional | Notes of parts, and merges of notes, that stopped at the output limit or were cut off by the provider. |
711
+ | `notes_left_out` | number, optional | The relevant parts whose notes are not in the answer: the read reached `maxRequests` before it could merge them. New in 0.10.0. |
595
712
  | `answer_cut_short` | `true`, optional | The final answer stopped at its output limit. |
596
- | `notes_only` | `true`, optional | The last step, which writes one answer from the notes, failed: `answer` is the notes of the parts, with their line citations. |
597
- | `note` | string, optional | With `notes_only`: "The last step of this read, which writes one answer from the notes of the parts, failed (REASON). The answer is those notes: answer from them.", plus "Some of them were cut off at the output limit, so they are incomplete: tell the user." when some were. Otherwise, when notes or the answer were cut short: "Incomplete: the model's output limit was reached, so some relevant items are missing from this answer. Tell the user it is incomplete. For a complete list or an exact count, use search_document in exact or regex mode (it returns total_matching_lines), or ask about a narrower part of the file." |
713
+ | `notes_only` | `true`, optional | The last step, which writes one answer from the notes, failed, or (since 0.10.0) had no request left within `maxRequests`: `answer` is the notes of the parts, with their line citations. |
714
+ | `note` | string, optional | With `notes_only`: "The last step of this read, which writes one answer from the notes of the parts, failed (REASON). The answer is those notes: answer from them.", or "This read reached the question's limit on model requests before its last step, which writes one answer from the notes of the parts. The answer is those notes: answer from them.", plus "Some of them were cut off at the output limit, so they are incomplete: tell the user." when some were. With `notes_left_out`: "Incomplete: this read reached the question's limit on model requests before it could combine the notes of every part, so the notes of N of the M relevant parts are not in this answer. Tell the user it is incomplete." and the same pointer to exact search as below. Otherwise, when notes or the answer were cut short: "Incomplete: the model's output limit was reached, so some relevant items are missing from this answer. Tell the user it is incomplete. For a complete list or an exact count, use search_document in exact or regex mode (it returns total_matching_lines), or ask about a narrower part of the file." |
598
715
  | `answer` | string | The answer. When no part held anything relevant: "No part of NAME contained anything relevant to: TASK", with the count of parts that could not be read, if any. |
599
716
  | `answer_shortened` | string, optional | "The rest of this answer did not fit in the room left in this conversation." The answer was cut at its end, which then reads `…`. |
600
717
 
@@ -602,6 +719,100 @@ turn do not both pass.
602
719
  { "document": "novel.txt", "parts_read": 4, "parts_with_relevant_content": 3, "answer": "Ada appears first in chapter 2 (L412) ..." }
603
720
  ```
604
721
 
722
+ ### Items: `output: "items"`
723
+
724
+ New in 0.10.0. Each part replies with one JSON object for each item it finds, on a line of its own:
725
+ `{"line": 123, "label": "penalty", "value": "5%", "quote": "a fine of 5% of the order"}`, the label
726
+ only when the call gave `labels`. The rules ask for a quote of five to twelve words of the line
727
+ that state the item, copied exactly, letter by letter, at most 80 characters: the longer quotes
728
+ asked for at first (200 characters) made Gemini Flash-Lite cut its list at the output limit more
729
+ often, and copy more words wrong; asked for "the few words" of the line, it gave some quotes of 14
730
+ characters, too short for the near check below. Code reads the replies, checks the items and
731
+ counts them. No model merges them, and there is no answer of the read: one request a part.
732
+
733
+ - A reply is read leniently: a line may start with a list mark (`- `, `1. `) and end with a comma,
734
+ or hold several objects (`{…} {…}`), code fences are passed over, and a JSON array of the objects
735
+ is read too, and so is an object that wraps their list (`{"items": […]}`: no `quote` of its own,
736
+ and one array of objects). A line that is not a JSON object is skipped. A reply that says
737
+ `NOTHING RELEVANT` has no item, unless it lists items after it: those are checked as any other.
738
+ - An item counts when its `quote` is on the line it names, within the part that listed it. They
739
+ are compared composed (NFC) and folded as exact search folds text (case, quotes, dashes, spaces),
740
+ without Hebrew points, with final letters as plain ones (כסף is found in כספים), without the
741
+ characters that show nothing (the direction marks U+200E, U+200F and U+061C that Hebrew text
742
+ from Word and PDF files often has next to a number, and the joiners), and with runs of blanks as
743
+ one space. A line number copied with the quote (`12| `) and the quote marks around it
744
+ are left out, and a quote cut with `…` must have each of its pieces on the line, in order.
745
+ - An item whose quote is not on the line it names, but on exactly one line of its part, is given
746
+ that line: in a file whose lines start with numbers ("7| 5. …", clause 5 on line 7), a model may
747
+ name the number in the text.
748
+ - An item whose quote is on no line of its part, but near the line it names, keeps that line: a
749
+ quote of 15 characters or more, compared as above, whose numbers are all numbers of the line,
750
+ and whose pieces are runs of the line with at most one letter in five changed, added or taken
751
+ out in all. Gemini Flash-Lite copies Hebrew quotes with a letter or a word changed (השרים for
752
+ השרתים, מקוזז for לקזז, ש"ץ for ש"ח). A quote with an amount other than the line's is not near
753
+ it, so neither is the quote of the next clause of a contract written to the same pattern. A line
754
+ of up to 2,000 characters, the longest that ingest stores, is compared whole. A longer line, which
755
+ a store of your own may give, is looked at only around the two longest words of each piece of the
756
+ quote that are on it in 1 to 4 places: a piece none of whose words is so counts as wrong in all
757
+ its letters, and a quote none of whose words is so is not near it. Measured along all of a line
758
+ of 118,759 characters, one quote took 688 ms, and one cut with "…" into 41 short pieces 677 ms.
759
+ - An item whose quote is on no line of its part, nor near the line it names, is given the line of
760
+ its part that is near its quote and starts with the number it names ("7| 5. …" for 5), when
761
+ exactly one line is both: Gemini Flash-Lite named the clause for the line and copied a letter of
762
+ the quote wrong (שילם for ישלם). When two lines start with that number and are near the quote,
763
+ as in a file whose numbering starts again, it is not counted. A line that starts with a date or
764
+ a time (`5/11 …`, `5-11-2026 …`, `05:30:12 …`, `5.11.2026 …`) does not start with the number 5.
765
+ New in 0.10.0.
766
+ - Any other item counts in `unverified_items`, not in `total_items`.
767
+ - A backslash that starts no JSON escape (`ש\"\ח`, as Gemini Flash-Lite escapes a Hebrew letter) is
768
+ taken out before a line is read again, and a `\u` with fewer than four hex digits is taken out
769
+ with the digits it has (Flash-Lite wrote ט as `\u05d`, which left "u05d" in the quote).
770
+ - The same item listed twice (the same line, label and value) counts once. So does an item given
771
+ a line other than the one it named (either way above) when that line has an item with its label,
772
+ whatever its value: Gemini Flash-Lite listed a clause once by its line and once by the clause's
773
+ number, with the value written another way (`5,000 ש"ח` and `5000`). The item that named its own
774
+ line is the one kept. New in 0.10.0.
775
+ - A label is matched to `labels` as quotes are compared, and given as the call spelled it. A label
776
+ that is not one of them is kept as the model wrote it.
777
+ - A part whose list stops at the output limit is read again as two halves, and a half as two
778
+ quarters: two levels at most, while `maxRequests` allows it (without it, while the halves take no
779
+ more than `maxMapChunks` requests). A part the model refuses as too large is halved the same way.
780
+ A list still cut is counted as it is, and the result says that items may be missing.
781
+ - The read costs its parts alone, each with the longer rules of a list, which is less than an
782
+ answer read, with its merges and its answer. The ceiling of `askWithFiles` prices it so: in input
783
+ tokens and in requests, an items read is its parts alone, and an answer read its parts, a merge
784
+ and its answer. So an items read can run where an answer read of the same file would pass the
785
+ ceiling.
786
+
787
+ | Field | Type | Meaning |
788
+ |---|---|---|
789
+ | `document` | string | The file name. |
790
+ | `total_items` | number | The items found, each once, whose quote is on their line, or near it as above. Counted by code. |
791
+ | `counts_by_label` | object, optional | The items by label, when they have labels: `{ "penalty": 37 }`. An item with no label among labelled ones counts under `"unlabeled"`. |
792
+ | `items` | array | The first 50 items, in the order of the file, each `{ line, label?, value?, quote }`. The value and the quote are as the model wrote them, up to 200 and 300 characters. |
793
+ | `more_items` | number, optional | The items not shown: past the first 50, or past those kept when the result was cut to its room. |
794
+ | `unverified_items` | number | Items a part listed that are not counted: a quote on no line of the part and not near the line the item names, or on several lines but not on that one. A quote near its line (15 characters or more, at most one letter in five wrong, every number a number of the line) counts there, so it is not among them. |
795
+ | `parts_read` | number | The parts the file was read in, those that could not be read included; a halved part counts as its halves. |
796
+ | `parts_failed` | number, optional | Parts that could not be read: their items are missing. |
797
+ | `parts_cut_short` | number, optional | Parts whose list was still cut at the output limit. |
798
+ | `note` | string, optional | What to tell the user, from these: "No part of NAME listed an item for: TASK." (a stop is added to a task that has none); "No item was found on its line for: TASK." when items were listed and none is counted; "The first 50 items are shown; total_items counts them all.", or "The first K items are shown, to stay within the size limit; total_items counts them all." when the result was cut to its room; "N listed items are not counted: their quote is not on the line they name, nor on just one other line of the part." (an item whose quote is near its line counts, so it is not among them); "N parts could not be read (REASON), so items may be missing: tell the user the count may be incomplete."; "N parts listed more items than fit the model's output limit, even read in smaller pieces, so items may be missing: tell the user the count may be incomplete." |
799
+
800
+ ```json
801
+ {
802
+ "document": "contract.docx",
803
+ "total_items": 37,
804
+ "counts_by_label": { "penalty": 37 },
805
+ "items": [{ "line": 7, "label": "penalty", "value": "1,250", "quote": "קנס בסך 1,250 ש\"ח לכל מקרה" }],
806
+ "unverified_items": 0,
807
+ "parts_read": 5
808
+ }
809
+ ```
810
+
811
+ Cut to its room, it loses items from the end of its list (one is always kept), `more_items` counts
812
+ every item it does not show, and the note says how many it shows. Its counts are kept whole. Its evidence
813
+ ([`evidenceOf`](./ask.md#evidenceofcall-result)) is `whole: true` with the lines of the items it
814
+ shows, and its stand-in keeps the counts and the first 20 items.
815
+
605
816
  Errors:
606
817
 
607
818
  | Error | When | Counted as a read |
@@ -609,9 +820,12 @@ Errors:
609
820
  | `NAME was already read whole for this question, and is not read whole again. Use the answer of that read, or search_document and read_document for the details.` | The document was read whole as often as it may be (" N times" is added when that is more than 1). | no |
610
821
  | `Whole-file reads are turned off for this question. Use search_document and read_document on NAME.` | `maxWholeDocumentReads` (or `limits.wholeDocumentReads`) is 0. | no |
611
822
  | `The whole-file read of NAME failed earlier in this question (REASON), and is not tried again. Use search_document and read_document.` | An earlier read of it could read no part. | no |
612
- | `Reading all of NAME needs N model calls, over the limit of M. Use search_document to narrow the question first.` | The read counted more parts than `maxMapChunks`. Nothing was sent. | no |
823
+ | `NAME is shown in full above: answer from it, and use search_document or aggregate_table for exact counts.` | The document is one of `ToolOptions.inline`: its text is in the prompt. Nothing is sent. New in 0.10.0. | no |
824
+ | `labels takes up to 12 labels, each up to 40 characters.` | `output: "items"` with more labels, or a longer one. New in 0.10.0. | no |
825
+ | `Reading all of NAME needs N model calls, over the limit of M. Use search_document to narrow the question first.` | The read counted more parts than `maxMapChunks` ("1 model call" for one). Nothing was sent. | no |
826
+ | `Reading all of NAME takes N model requests, one for each part, and M are left for it in this question. Use search_document and read_document.` | The read counted more parts than [`ToolCallLimits.maxRequests`](#toolcalllimits) ("1 is left" for one; "takes 1 model request, for its one part" for a file of one part). Nothing was sent. New in 0.10.0: before, the read sent every part whatever its limit. | no |
613
827
  | `Could not read any part of NAME: REASON` | Every part failed at the model. | yes |
614
- | The store's error | No part could be read from the store. Nothing was sent. | no |
828
+ | The store's error | No part could be read from the store. Nothing was sent. A store timeout is thrown instead ([Store timeouts](#rules-for-every-tool)). | no |
615
829
 
616
830
  REASON, in these errors, in the notes of a part that could not be read, and in the note of
617
831
  `notes_only`, says why a model request failed. Since 0.6.0 it is built from the error's kind, its
@@ -658,7 +872,8 @@ The description the model sees:
658
872
 
659
873
  The pages are cut out of the kept original into one small PDF, and returned as a file next to a
660
874
  short JSON result. Only [`ToolSet.executeWithFiles`](#toolset) returns the file; `execute` answers
661
- with an error. Pages are left off the end until the file fits the call's `maxFileBytes`. Cutting
875
+ with an error. Since 0.9.0 the looks of a library take their turns (`maxConcurrentPageLooks`, 1 by
876
+ default): a look waits for its turn before the original is loaded. Pages are left off the end until the file fits the call's `maxFileBytes`. Cutting
662
877
  needs the optional dependency `@cantoo/pdf-lib`. How pages are cut and counted, and what they cost,
663
878
  is in [PDFs](../guides/pdfs.md).
664
879
 
@@ -698,7 +913,10 @@ Errors, besides those of [every tool](#rules-for-every-tool):
698
913
  | `NAME has N pages. There is no page F.` | `from_page` is past the last page. |
699
914
  | `No more pages can be looked at for this question. Answer from the pages and the text you already have.` | The call's `maxPages` is below 1. |
700
915
  | `There is no room left in this request to show more pages. Answer from the pages and the text you already have.` | The call's `maxFileBytes` is below 1,024. |
701
- | `The original file of NAME is no longer on the server, so its pages cannot be shown. Answer from the text.` | The store no longer has the original. |
916
+ | `The original file of NAME is no longer on the server, so its pages cannot be shown. Answer from the text.` | The store no longer has the original, or (0.9.0) what it gave back is not the file that was ingested: of another size or SHA-256; or a file your application keeps (`IngestInput.original`) is not there. When the document itself is gone too (deleted while the look waited for its turn), the call gives `ID is no longer available on the server. Ask the user to attach the file again.` instead, and its hooks are told (`ToolCallHooks.onDocumentGone`; since 0.9.0). |
917
+ | `NAME changed on the server since it was read. Attach it again to look at its pages.` | The file your application keeps for the document (`IngestInput.original`, read through `LargeFilesOptions.originals`) is no longer the one that was ingested: its size or SHA-256 differs. Its pages would not match the text. New in 0.9.0. |
918
+ | `The original file of NAME could not be read in time, so its pages cannot be shown. Answer from the text.` | The store's `getOriginal` did not answer within `ingestTimeoutMs` (2 minutes when that is 0). The look gave its turn back, so the next look runs. The read goes on in the background: give your store's `getOriginal` a time limit of its own. New in 0.9.0. |
919
+ | `NAME: The pages cannot be looked at right now; the server is busy. Answer from the text, or look again later.` | The look waited longer than `pageLookWaitMs` for its turn, or the call's `maxWaitMs` when that is less: other looks of the library held them all (`maxConcurrentPageLooks`, [library](./library.md#largefilesoptions)). It was not run, and its PDF was not loaded. The call's hooks are told (`ToolCallHooks.onPagesBusy`), and `askWithFiles` gives a `"page_looks_busy"` notice. New in 0.9.0. |
702
920
  | `NAME: Page F is 2.1 MB as a file, more than the 1.5 MB that fit in this request.` | The first page alone does not fit `maxFileBytes`. |
703
921
  | `NAME: ` and the reason | The file cannot be cut: it needs a password, is damaged, declares too many objects to cut in memory, has another page count than its text, has no page `from_page` (when its page count was not recorded), or `@cantoo/pdf-lib` is not installed. |
704
922
  | `The pages could not be shown: this application does not pass files from tools to the model. Answer from the text.` | The call was run with `execute`, which has no place for a file. |
@@ -767,8 +985,9 @@ of this unless you write it.
767
985
  - For the same call twice in one turn: `{ "already_shown": true, "note": "Not run: call 1 of this turn is the same call, and its result is next to this one. Use it." }`
768
986
 
769
987
  A result of an earlier turn that failed, was cut (`truncated`, `text_cut`, a note that starts
770
- "Showing "), came from a search that stopped early, or is itself a pointer or a stand-in is never
771
- pointed to: the call runs, and may get more. A search whose note only says how many of its
988
+ "Showing "), came from a search that stopped early, is itself a pointer or a stand-in, or (since
989
+ 0.10.0) was replaced by your `onToolResult` (`redacted: true`) is never pointed to: the call runs,
990
+ and may get more. A search whose note only says how many of its
772
991
  matches are shown ("21 of the 442 matching lines are shown: …") was not cut, and is pointed to.
773
992
  The same call made twice in one turn gets the pointer to the first whatever the first returns (an
774
993
  error, a cut result, a pointer); only when the first is refused for lack of room is the second
@@ -787,7 +1006,9 @@ of this unless you write it.
787
1006
  - **Stand-ins.** When the request runs short of room, the results of older tool rounds are replaced
788
1007
  by the short stand-ins of [`stubResult`](./ask.md#stubresultcall-result-hadfiles), with
789
1008
  `"dropped": true`; when and how is in [How it works](../how-it-works.md), and nothing is replaced
790
- when any model of the question is append-only (Claude). A pointer whose result was replaced
1009
+ during a question when any model of the question is append-only (Claude). Since 0.9.0 the
1010
+ results of stored rounds are replaced before the first request when they make it too large in tokens,
1011
+ for every model, and a result is never replaced by a stand-in as large as itself. A pointer whose result was replaced
791
1012
  becomes
792
1013
  `{ "document": "app.log", "dropped": true, "note": "Not run then: it repeated an earlier call whose result was later dropped from the conversation to make room. Call it again if you need it." }`.
793
1014
  So does every pointer of a stored round when a model of the question declares
@@ -851,6 +1072,23 @@ const TOOL_NAMES = {
851
1072
  Compare a `ToolCall.name` with these rather than with string literals. See
852
1073
  [Your own adapter and loop](../guides/own-adapter-and-loop.md).
853
1074
 
1075
+ ### declarationsFor(names)
1076
+
1077
+ `declarationsFor(names: readonly ToolName[]): ToolDeclaration[]`
1078
+
1079
+ The [declarations](#tooldeclaration) of the tools `names`, in the order a tool set declares them
1080
+ (search, read, overview, aggregate, analyze, view), whatever the order of `names`: the declarations
1081
+ of `files.tools(documents, { declare: names })`, byte for byte. A name that is not a tool's is left
1082
+ out. Use it to plan the size of a request before the tools are made. New in 0.10.0.
1083
+
1084
+ ```ts
1085
+ import { declarationsFor } from "llm-large-files";
1086
+
1087
+ const declared = declarationsFor(["aggregate_table", "search_document", "read_document"]);
1088
+ // search_document, read_document, aggregate_table
1089
+ const bytes = Buffer.byteLength(JSON.stringify(declared));
1090
+ ```
1091
+
854
1092
  ### `MAX_VIEW_PAGES`
855
1093
 
856
1094
  `5`. The most pages one `view_pages` call shows. [`ToolCallLimits.maxPages`](#toolcalllimits)
@@ -883,7 +1121,8 @@ throws.
883
1121
  | `error` | ` — failed:` and the error, as in ` — failed: Unknown tool “do_magic”.` |
884
1122
  | `total_matching_lines` (exact, regex) | ` — 1,203 matching lines` (numbers in en-US form), ` — 1 matching line` for one. With `total_groups` (`group_by`): ` — 214 matching lines in 3 groups`, ` in 1 group` for one |
885
1123
  | `passages` (keywords) | ` — 5 passages`, ` — 1 passage` for one |
886
- | `parts_read` (whole-file read) | ` — 9 parts, 3 relevant` (` — 1 part, 1 relevant` for one), then `, notes only` with `notes_only`, or `, incomplete` with `notes_cut_short` or `answer_cut_short` |
1124
+ | `total_items` and `parts_read` (a whole-file read that lists items, since 0.10.0) | ` — 37 items in 5 parts` (` — 1 item in 1 part` for one), then `, 2 not counted` with `unverified_items`, and `, incomplete` with `parts_failed` or `parts_cut_short` |
1125
+ | `parts_read` (whole-file read) | ` — 9 parts, 3 relevant` (` — 1 part, 1 relevant` for one), then `, notes only` with `notes_only`, or `, incomplete` with `notes_cut_short`, `notes_left_out` (since 0.10.0) or `answer_cut_short` |
887
1126
  | `lines` and `total_lines` (read) | ` — got 1200-1342` when the label does not end with the lines shown, else `""` |
888
1127
  | `pages` and `total_pages` (view_pages) | ` — got page 2` or ` — got pages 2-3` when the label does not end with the pages shown, else `""` |
889
1128
  | anything else (an overview, a cut result) | `""` |
@@ -914,20 +1153,24 @@ type ToolSet = {
914
1153
  executeWithFiles(name: string, args: Record<string, unknown>, limits?: ToolCallLimits, hooks?: ToolCallHooks): Promise<ToolOutput>;
915
1154
  describe(name: string, args: Record<string, unknown>): string;
916
1155
  resultCharacters(name: string): number;
1156
+ wholeReadsLeft?(documentId: string): number; // new in 0.10.0
917
1157
  };
918
1158
  ```
919
1159
 
920
1160
  | Member | What it does |
921
1161
  |---|---|
922
- | `declarations` | The tools to declare to the model, in this order: `search_document`, `read_document`, `get_document_overview`, `analyze_whole_document`, `view_pages`, those that are [offered](#which-tools-are-offered). |
923
- | `has(name)` | `true` for each declared tool. Also `true` for `analyze_whole_document` when `generate` was given and the text tools are declared, even if it is not declared because no document is small enough: a call then gets the reason. Use it to tell the calls of this tool set from others. |
1162
+ | `declarations` | The tools to declare to the model, in this order: `search_document`, `read_document`, `get_document_overview`, `aggregate_table`, `analyze_whole_document`, `view_pages`, those that are [offered](#which-tools-are-offered), or (since 0.10.0) exactly those `ToolOptions.declare` names, in the same order. |
1163
+ | `has(name)` | `true` for each declared tool. Also `true` for `analyze_whole_document` when `generate` was given and the text tools are declared, even if it is not declared because no document is small enough: a call then gets the reason. With `ToolOptions.declare` (since 0.10.0), `true` for the declared tools alone. Use it to tell the calls of this tool set from others. |
924
1164
  | `execute(name, args)` | Runs a call and returns its JSON result, within the tool's own cap. Failures come back as `{ error }`, as listed above. `view_pages` answers with an error here: it returns a file. |
925
- | `executeWithFiles(name, args, limits?, hooks?)` | Runs any call with [`ToolCallLimits`](#toolcalllimits), and returns the result with the files it produced (`files` is empty for every tool but `view_pages`). Use it in a loop that can send files to the model. `hooks` ([`ToolCallHooks`](./library.md#toolcallhooks), new in 0.7.0) are listeners for this call alone: the progress of a whole-file read, in place of `ToolOptions.onProgress`, and each of its model requests with their retries. Only `analyze_whole_document` calls them. |
926
- | `describe(name, args)` | A short line for a progress UI, read from the arguments the way the tool reads them: `Search app.log (exact) for “timeout”` (the query cut to 80 characters; since 0.8.0 followed by ` in lines 1941-end` with `from_line` or `to_line`, and by `, counted by hour` with `group_by` or `, the last ones` with `order: "last"` in exact and regex mode), `Read app.log lines 1200-1260` (`-1260` only when `end_line` is a number not below `start_line`), `Overview of app.log`, `Read all of novel.txt for “list every character”` (the task cut to 100 characters), `Look at report.pdf pages 2-3`. A cut never splits an emoji. A file not yet known is "the file"; an unknown tool is its name, as it came (`askWithFiles` labels it `Call “NAME”` instead). The line quotes the model's words as they are: show it as plain text, or clean it as `askWithFiles` does its steps. In `askWithFiles`, this line, made one line of plain text, is the `label` of the call's `tool.start` event, the line `onActivity` gets with "…", and the start of its step. |
927
- | `resultCharacters(name)` | The most characters of a result of this tool: the larger of `toolResultCharacters` and 40,000 for `analyze_whole_document`, 600 for `view_pages` (its file is counted in bytes), and `toolResultCharacters` for any other name. What a loop sets aside in its request before it runs a call. |
1165
+ | `executeWithFiles(name, args, limits?, hooks?)` | Runs any call with [`ToolCallLimits`](#toolcalllimits), and returns the result with the files it produced (`files` is empty for every tool but `view_pages`). Use it in a loop that can send files to the model. `hooks` ([`ToolCallHooks`](./library.md#toolcallhooks), new in 0.7.0) are listeners for this call alone: the progress of a whole-file read, in place of `ToolOptions.onProgress`, and each of its model requests with their retries; a document found gone, and a look told the server is busy (0.9.0); and its own `signal` (0.10.0, [above](#rules-for-every-tool)). |
1166
+ | `describe(name, args)` | A short line for a progress UI, read from the arguments the way the tool reads them: `Search app.log (exact) for “timeout”` (the query cut to 80 characters; since 0.8.0 followed by ` in lines 1941-end` with `from_line` or `to_line`, and by `, counted by hour` with `group_by` or `, the last ones` with `order: "last"` in exact and regex mode), `Read app.log lines 1200-1260` (`-1260` only when the call gave an `end_line` not below `start_line`, read as the tool reads it: since 0.10.0 an `end_line` sent as text, `"250"`, shows too, and one past the 600 lines a read shows reads as its last line), `Read all of contract.docx for “every penalty”, as a list of items` (with `output: "items"`, since 0.10.0), `Overview of app.log`, `Read all of novel.txt for “list every character”` (the task cut to 100 characters), `Look at report.pdf pages 2-3`. A cut never splits an emoji. A file not yet known is "the file"; an unknown tool is its name, as it came (`askWithFiles` labels it `Call “NAME”` instead). The line quotes the model's words as they are: show it as plain text, or clean it as `askWithFiles` does its steps. In `askWithFiles`, this line, made one line of plain text, is the `label` of the call's `tool.start` event, the line `onActivity` gets with "…", and the start of its step. |
1167
+ | `resultCharacters(name)` | The most characters of a result of this tool: the larger of `toolResultCharacters` and 40,000 for `analyze_whole_document`, 600 for `view_pages` (its file is counted in bytes), 600 for a name the tool set does not answer (its error is a few words; since 0.10.0, before which it was `toolResultCharacters`), 600 for a tool declared with `declare` that cannot run and for `analyze_whole_document` without `generate` (since 0.10.0: they answer their reason), and `toolResultCharacters` for the other tools. What a loop sets aside in its request before it runs a call. |
1168
+ | `wholeReadsLeft(documentId)` | How many more times this tool set may read the document whole: 0 once a read of it could read no part, at the cap (`maxWholeDocumentReads`), for a document sent whole (`inline`), for one that is not among its documents, and without `generate`. `askWithFiles` asks it before it prices a read, so a read the tool would refuse is refused with the tool's reason, not its price. Optional in the type, so a tool set of your own still compiles. New in 0.10.0. |
928
1169
 
929
- `execute` and `executeWithFiles` throw only when the tool set's `signal` was aborted: the error
930
- that ended the call is thrown again instead of being returned to the model.
1170
+ `execute` and `executeWithFiles` throw only when the tool set's `signal`, or (since 0.10.0) the
1171
+ call's own `signal`, was aborted, or the store did not answer in time ([Store
1172
+ timeouts](#rules-for-every-tool), since 0.10.0): the error that ended the call is thrown again
1173
+ instead of being returned to the model.
931
1174
 
932
1175
  A turn of your own loop, run with the tool set. `files` is your
933
1176
  [`LargeFiles`](./library.md#largefiles), created once with
@@ -987,6 +1230,7 @@ type ToolCallLimits = {
987
1230
  maxPages?: number;
988
1231
  maxResultCharacters?: number;
989
1232
  maxRequests?: number;
1233
+ maxWaitMs?: number; // new in 0.9.0
990
1234
  };
991
1235
  ```
992
1236
 
@@ -995,13 +1239,19 @@ type ToolCallLimits = {
995
1239
  | `maxFileBytes` | number | 3/8 of (`maxRequestBytes` − 262,144): 3,651,696 bytes with the default budget | `view_pages`: the most bytes its file may have. Pages are left off the end until the cut fits. Below 1,024 the call fails. Give the room left in your request, times 3/4 when you send files as base64. |
996
1240
  | `maxPages` | number | [`MAX_VIEW_PAGES`](#max_view_pages) (5) | `view_pages`: the most pages this call may show, never more than 5. Below 1 the call fails. Lower it as the pages already shown use up your token budget. |
997
1241
  | `maxResultCharacters` | number | The tool's own cap ([`resultCharacters`](#toolset)) | The most characters of the JSON result, when that is less than the tool's cap: the room left in the request. The result is cut to it and says where to go on. Never below 600. `view_pages` ignores it. |
998
- | `maxRequests` | number | No limit | `analyze_whole_document`: the most model requests the read may make. It does not stop the read: a part the model refuses as too large is read as two halves only while this and `maxMapChunks` allow it (the parts, a merge and the answer must fit). New in 0.6.0. |
1242
+ | `maxRequests` | number | No limit | `analyze_whole_document`: the most model requests the read may make. A part the model refuses as too large is read as two halves only while this and `maxMapChunks` allow it (the parts, their merges and the answer must fit). Since 0.10.0 the read keeps to it: a read with more parts than this is refused before any request, a round of merges that would pass it is not made ([above](#analyze_whole_document)), and a read that lists items reads a cut list again in halves only within it. `read_document` (since 0.10.0): what a whole read of its file may make on the model's next turn, the first it can call one on; a read cut short of its range points at one (`whole_file`) only when the file's estimated parts are within it. New in 0.6.0. |
1243
+ | `maxWaitMs` | number | The library's `pageLookWaitMs` (30,000) | `view_pages`: the most milliseconds the look waits for its turn, when that is less than `pageLookWaitMs`. 0: it runs only when a turn is free now, and is told the server is busy if not. New in 0.9.0. |
999
1244
 
1000
1245
  In `askWithFiles`, `maxFileBytes` is what is left of `maxRequestBytes` after the request so far
1001
1246
  and a tenth kept free (256 KiB at least), times 3/4; `maxPages` is what is left of
1002
1247
  `reservedTokens / 2 / pageTokens` pages for the question (60 with a `reservedTokens` of 64,000 and
1003
1248
  Gemini's 530 tokens a page); `maxRequests`, when `limits.requests` is set, is the read's own
1004
- requests and a share of what the question has left of it. See
1249
+ requests and a share of what the question has left of it (for a `read_document` call, what the
1250
+ question has left of it with one request kept for the answer, one for the next turn, which would
1251
+ call a whole read, and those of the whole reads let through in this turn; 0 when the question
1252
+ would not start a whole read of the file on the next turn: since 0.10.0); `maxWaitMs` is 0 for the looks of a
1253
+ tool turn after one of them was told the server is busy, so that a wait that ends busy comes once
1254
+ in a turn. See
1005
1255
  [Your own adapter and loop](../guides/own-adapter-and-loop.md).
1006
1256
 
1007
1257
  ### `ToolFileLimits`
@@ -1127,3 +1377,8 @@ text, and `view_pages` with its guide when the pages of a PDF can be looked at.
1127
1377
  by group and paging; searching the bare form of a word) and the closing requests
1128
1378
  ([`FINAL_ANSWER_REQUEST`](./ask.md#final_answer_request) and the two others), so the cache misses
1129
1379
  once after upgrading to it too, the same way.
1380
+
1381
+ 0.10.0 changes the arguments of `analyze_whole_document` (`output` and `labels`; its description
1382
+ is 0.9.0's), so a chat where it is declared misses the cache once after the upgrade. The prompts of
1383
+ its part reads, merges and answer changed too: they reach the model that reads the parts, not the
1384
+ chat.