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/docs/security.md CHANGED
@@ -278,6 +278,91 @@ and the request is not sent again. A reply made of many events has no cap on its
278
278
  time while it keeps arriving. An endpoint you do not trust, such as a gateway run by someone else,
279
279
  can still take the memory of your server.
280
280
 
281
+ ## Tool results: `onToolResult`
282
+
283
+ New in 0.10.0. `AskOptions.onToolResult` sees the result of every tool call that ran before the
284
+ model does, and before the evidence, the steps, `toolTurns` and the events. It can let the result
285
+ through (undefined), send a masked copy (`{ result }`, sent with `redacted: true`), or send an error
286
+ in its place (`{ reject: "why" }`). Use it for data loss prevention: Israeli ID numbers (ת.ז.) and
287
+ card numbers that a file holds, and that a user of the chat should not get through the model.
288
+
289
+ ```ts
290
+ import { askWithFiles, type AskOptions, type AskResult, type ToolResult } from "llm-large-files";
291
+
292
+ /** An Israeli ID number (9 digits, with its check digit), as it may be written in a file. */
293
+ const ID_CANDIDATE = /(?<!\d)\d{5,9}(?!\d)/g;
294
+ /** A card number: 13 to 19 digits, maybe in groups. */
295
+ const CARD_CANDIDATE = /(?<!\d)\d(?:[ -]?\d){12,18}(?!\d)/g;
296
+
297
+ const israeliId = (digits: string): boolean => {
298
+ const id = digits.padStart(9, "0");
299
+ let sum = 0;
300
+ for (let index = 0; index < 9; index++) {
301
+ const step = Number(id[index]) * (index % 2 === 0 ? 1 : 2);
302
+ sum += step > 9 ? step - 9 : step;
303
+ }
304
+ return sum % 10 === 0;
305
+ };
306
+ const luhn = (digits: string): boolean => {
307
+ let sum = 0;
308
+ for (let index = 0; index < digits.length; index++) {
309
+ let digit = Number(digits[digits.length - 1 - index]);
310
+ if (index % 2 === 1) digit = digit * 2 > 9 ? digit * 2 - 9 : digit * 2;
311
+ sum += digit;
312
+ }
313
+ return sum % 10 === 0;
314
+ };
315
+ const mask = (text: string): string => text
316
+ .replace(CARD_CANDIDATE, (found) => (luhn(found.replace(/\D/g, "")) ? "[מספר כרטיס]" : found))
317
+ .replace(ID_CANDIDATE, (found) => (found.length >= 8 && israeliId(found) ? "[ת.ז.]" : found));
318
+ /** Every string of a result masked; numbers and keys as they are. */
319
+ const masked = (value: unknown): unknown =>
320
+ typeof value === "string" ? mask(value)
321
+ : Array.isArray(value) ? value.map(masked)
322
+ : value !== null && typeof value === "object" ? Object.fromEntries(Object.entries(value).map(([key, field]) => [key, masked(field)]))
323
+ : value;
324
+
325
+ // options are those of askWithFiles.
326
+ export function askWithDlp(options: AskOptions): Promise<AskResult> {
327
+ return askWithFiles({
328
+ ...options,
329
+ onToolResult: ({ result }) => {
330
+ const clean = masked(result) as ToolResult;
331
+ return JSON.stringify(clean) === JSON.stringify(result) ? undefined : { result: clean };
332
+ },
333
+ });
334
+ }
335
+ ```
336
+
337
+ - **It may be async.** A call to a DLP service of your own gets the context's `signal`, which
338
+ aborts when the question is stopped or fails; the question does not wait for the hook once its
339
+ own signal aborts. Each call's hook starts as soon as its result is in, so the checks of one turn
340
+ run at the same time; their verdicts are applied in call order.
341
+ - **It fails closed.** What the hook throws, or a value of another shape than `{ result }`,
342
+ `{ reject }` or undefined, ends the question with that error or a `TypeError`, at once: the other
343
+ calls of the turn stop, and no result of the turn reaches the model. A DLP service that is down
344
+ stops the question; the model never gets the unchecked result.
345
+ - **It sees the whole result.** The hook gets what the tool returned, before it is fitted to the
346
+ room in the request. What it lets through is fitted then, a masked copy as the tool's own result
347
+ would be: a copy larger than the room is cut, and is still marked `redacted: true`.
348
+ - **What the model saw is what is kept.** The evidence, the steps, `toolTurns` (stored with the
349
+ conversation, and sent again in later questions) and `tool.end` tell the masked result. A later
350
+ call is never answered with a pointer to a masked result: it runs again, through the hook. The
351
+ same call made twice in one turn gets the first one's verdict: the same masked copy, or the same
352
+ error.
353
+ - **It sees tool results only.** The model gets other text of the files that no tool returns, and
354
+ the hook does not see it:
355
+ - a document small enough to be sent whole goes into the prompt as it is;
356
+ - the card of a searched document holds its first 25 lines, up to 40 outline headings, and for a
357
+ log up to 8 message templates;
358
+ - the parts of a whole-file read (`analyze_whole_document`) go to the model that reads them, in
359
+ full, through `generateText`; only the read's answer is a tool result;
360
+ - the pages of `view_pages` are a PDF next to the result.
361
+
362
+ For data that must never reach a model, redact it before you ingest the file (or keep it out of
363
+ the documents), and use the hook for what a search or a read brings back. To keep whole-file
364
+ reads off, set `wholeDocumentAnalysis: false`.
365
+
281
366
  ## Prompt injection
282
367
 
283
368
  The model reads text you do not control: the content of the files, their names, the pages it looks
@@ -1004,7 +1089,7 @@ New in 0.9.0. `createDocumentHandlers` writes no file unless it is asked to: by
1004
1089
  ([Stopping a server](./guides/deployment.md#stopping-a-server)).
1005
1090
  - **Bounded.** A body written to a file has the same limits as one in memory: `maxUploadBytes` and
1006
1091
  `uploadIdleTimeoutMs`, which also bounds each call to the disk (a volume that stops answering is
1007
- a `500` "Upload failed (ETIMEDOUT).", and gives the upload's room back). `maxSpooledUploadBytes`
1092
+ a `503` "Upload failed (ETIMEDOUT).", a `500` before 0.10.0, and gives the upload's room back). `maxSpooledUploadBytes`
1008
1093
  (ten times `maxUploadBytes`) bounds the spool's files at once. A full disk (`ENOSPC`, `EDQUOT`) is
1009
1094
  answered `503`, and the file removed. The files of `prepareUpload` are bounded by your disk only.
1010
1095
  - **Not sent.** The path of a file and its ref are never in an answer, an event, a summary, or a
@@ -1055,10 +1140,11 @@ question, whatever the model:
1055
1140
 
1056
1141
  - **Chat requests:** `limits.toolTurns` (12), counting the answer. Tools run in all but the last,
1057
1142
  with at most `limits.callsPerTurn` (8) calls run in each.
1058
- - **Whole-file reads:** one of each document (`limits.wholeDocumentReads`). A read is up to
1059
- `maxMapChunks` (30) part requests of up to `mapChunkTokens` each (100,000 at the default window of
1060
- 1M tokens: 3M input tokens), plus the requests that merge the notes and write the read's answer.
1061
- With an explorer model, that model reads the parts.
1143
+ - **Whole-file reads:** one of each document (`limits.wholeDocumentReads`), and 2 in all
1144
+ (`limits.wholeReadsPerQuestion`, since 0.10.0). A read is up to `maxMapChunks` (30) part
1145
+ requests of up to `mapChunkTokens` each (100,000 at the default window of 1M tokens: 3M input
1146
+ tokens), plus the requests that merge the notes and write the read's answer. With an explorer
1147
+ model, that model reads the parts.
1062
1148
  - **Pages:** at most 5 a call, and for the question what half of `reservedTokens` holds at the
1063
1149
  adapter's `pageTokens`. They stay in the later requests of the question, which bills them again,
1064
1150
  unless room runs out and older results are replaced by a note of what they showed (never for a
@@ -1068,11 +1154,13 @@ question, whatever the model:
1068
1154
  model whose conversation may only grow, as Claude's), and a question whose first request is too
1069
1155
  large, before any tool ran, is planned again once. None of these takes a tool turn. A retried
1070
1156
  request counts once in the usage.
1071
- - **Ceilings, unset by default:** `limits.inputTokens` and `limits.requests` cover the whole question,
1072
- part reads included. A whole-file read that would pass one is refused before it starts. Once
1073
- `inputTokens` is reached, no more tools run, but the request that crosses it has already been
1074
- sent, and the answer request is still sent with the whole conversation: a question can pass the
1075
- ceiling by up to about two requests (the one that crosses it, and the answer). `requests` counts
1157
+ - **Ceilings:** `limits.inputTokens` and `limits.requests` cover the whole question, part reads
1158
+ included. A whole-file read that would pass one is refused before it starts. Since 0.10.0
1159
+ `inputTokens` has a default: the larger of 1,000,000 and `toolTurns` times the first request,
1160
+ with room for the whole-file reads the question may make (`Infinity` for none). It is checked
1161
+ before each tool request, looking ahead: when the next tool request and the answer would pass it,
1162
+ no more tools run. So a question passes it by about one request at most, the answer. A request
1163
+ that reports no usage counts by the library's estimate. `requests`, unset by default, counts
1076
1164
  answered requests and keeps one for the answer.
1077
1165
 
1078
1166
  `result.usage` is what a question used, in all and for each model. A question that fails or is
@@ -1087,8 +1175,9 @@ piece and 300 s between pieces, and is retried after waits of up to 60 s
1087
1175
  ([Errors and reliability](./guides/errors-and-reliability.md#waits-on-a-silent-model)). A question
1088
1176
  is up to 12 chat requests, not counting retries, and part reads besides, so it can run for many
1089
1177
  minutes. Give it a deadline with `signal`, and abort it too when the client goes away
1090
- ([Web app](./guides/web-app.md)). This sample sets a deadline and logs what each question used,
1091
- failed ones included:
1178
+ ([Web app](./guides/web-app.md)). Since 0.10.0 the question stops at once when its signal aborts,
1179
+ also while it waits for a store that does not answer, in planning or in a tool call. This sample
1180
+ sets a deadline and logs what each question used, failed ones included:
1092
1181
 
1093
1182
  ```ts
1094
1183
  import { askWithFiles, partialResultOf, type UsageTotals } from "llm-large-files";
@@ -285,16 +285,17 @@ the client's connection stalled, or a proxy held the body. The connection is clo
285
285
  the file again. For users on slow or unsteady links, raise `uploadIdleTimeoutMs` of
286
286
  `createDocumentHandlers`.
287
287
 
288
- ### `500`: "Upload failed (ETIMEDOUT)." or "Upload failed (ELOOP)."
288
+ ### `503`: "Upload failed (ETIMEDOUT)." and `500`: "Upload failed (ELOOP)."
289
289
 
290
290
  New in 0.9.0, for a body written to a file (the `path` of `prepareUpload`, or `uploadSpool`).
291
291
 
292
- - **"ETIMEDOUT".** A call to the disk (checking the folders of a path with a ref, opening the file,
293
- a write, closing it) did not end within `uploadIdleTimeoutMs` (30 s): the volume stopped
294
- answering, such as a network volume whose server is gone. The upload's room is given back, and
295
- the file is removed once the volume answers. **Fix.** Check the volume. A slow network volume can
296
- take long to close a file it held writes for: raise `uploadIdleTimeoutMs`.
297
- - **"ELOOP".** `prepareUpload` gave a path that ends with the ref of its `original`, and a folder
292
+ - **"ETIMEDOUT"**, a `503` with `Retry-After: 5` (a `500` before 0.10.0). A call to the disk
293
+ (checking the folders of a path with a ref, opening the file, a write, closing it) did not end
294
+ within `uploadIdleTimeoutMs` (30 s): the volume stopped answering, such as a network volume whose
295
+ server is gone. The upload's room is given back, and the file is removed once the volume answers.
296
+ **Fix.** Check the volume. The client may send the file again after `Retry-After`. A slow network
297
+ volume can take long to close a file it held writes for: raise `uploadIdleTimeoutMs`.
298
+ - **"ELOOP"**, a `500`. `prepareUpload` gave a path that ends with the ref of its `original`, and a folder
298
299
  between that root and the file is a link. `fileOriginals` would never read the file back through
299
300
  it, so nothing is written. **Fix.** Replace the link with the folder itself, or mount the other
300
301
  disk there. The root itself may be a link.
@@ -1116,7 +1117,7 @@ import { askGemini } from "llm-large-files/gemini";
1116
1117
  const result = await askGemini({
1117
1118
  files, endpoint, documentIds, messages, owner,
1118
1119
  limits: {
1119
- inputTokens: 1_000_000, // no more tools once the question has sent this many input tokens
1120
+ inputTokens: 1_000_000, // no tool request that, with the answer, would pass it
1120
1121
  requests: 20, // chat requests and part reads together
1121
1122
  wholeDocumentReads: 0, // no whole-file reads
1122
1123
  },
@@ -1126,10 +1127,11 @@ const { inputTokens, cachedInputTokens, outputTokens, requests, byModel } = resu
1126
1127
  console.log({ owner, inputTokens, cachedInputTokens, outputTokens, requests, byModel });
1127
1128
  ```
1128
1129
 
1129
- The ceilings are checked before each request that may use tools. Once one is reached, the next
1130
- request is the answer, which is still made: a question can pass `inputTokens` by about two
1131
- requests (the one that crossed it, and the answer): set it that far below what must not be passed
1132
- ([Costs and limits](./guides/costs-and-limits.md#inputtokens-and-requests-are-checked-between-turns)). A
1130
+ The ceilings are checked before each request that may use tools, looking ahead: when what the
1131
+ question spent, the next tool request and the answer would pass `inputTokens`, the next request is
1132
+ the answer. So a question can pass `inputTokens` by about one request, the answer's, with the
1133
+ results of the last tool turn in it: set it that far below what must not be passed
1134
+ ([Costs and limits](./guides/costs-and-limits.md#the-ceiling-looks-ahead)). A
1133
1135
  cheaper [explorer model](./guides/explorer-model.md) takes the searching and the part reads off the
1134
1136
  model that answers.
1135
1137