llm-large-files 0.2.0 → 0.3.5

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 (81) hide show
  1. package/CHANGELOG.md +101 -0
  2. package/README.md +52 -6
  3. package/dist/extract.d.ts +13 -6
  4. package/dist/extract.d.ts.map +1 -1
  5. package/dist/extract.js +27 -6
  6. package/dist/extract.js.map +1 -1
  7. package/dist/gemini/chat.d.ts +48 -4
  8. package/dist/gemini/chat.d.ts.map +1 -1
  9. package/dist/gemini/chat.js +108 -24
  10. package/dist/gemini/chat.js.map +1 -1
  11. package/dist/gemini/endpoints.d.ts +17 -0
  12. package/dist/gemini/endpoints.d.ts.map +1 -1
  13. package/dist/gemini/endpoints.js +16 -2
  14. package/dist/gemini/endpoints.js.map +1 -1
  15. package/dist/gemini/generate.d.ts +34 -4
  16. package/dist/gemini/generate.d.ts.map +1 -1
  17. package/dist/gemini/generate.js +47 -7
  18. package/dist/gemini/generate.js.map +1 -1
  19. package/dist/gemini/index.d.ts +3 -3
  20. package/dist/gemini/index.d.ts.map +1 -1
  21. package/dist/gemini/index.js +2 -2
  22. package/dist/gemini/index.js.map +1 -1
  23. package/dist/index.d.ts +2 -2
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +1 -1
  26. package/dist/index.js.map +1 -1
  27. package/dist/library.d.ts +31 -1
  28. package/dist/library.d.ts.map +1 -1
  29. package/dist/library.js +44 -6
  30. package/dist/library.js.map +1 -1
  31. package/dist/pdf-layout.d.ts +7 -0
  32. package/dist/pdf-layout.d.ts.map +1 -1
  33. package/dist/pdf-layout.js +32 -2
  34. package/dist/pdf-layout.js.map +1 -1
  35. package/dist/pdf-pages.d.ts +45 -0
  36. package/dist/pdf-pages.d.ts.map +1 -0
  37. package/dist/pdf-pages.js +336 -0
  38. package/dist/pdf-pages.js.map +1 -0
  39. package/dist/pdf-pictures.d.ts +20 -0
  40. package/dist/pdf-pictures.d.ts.map +1 -0
  41. package/dist/pdf-pictures.js +336 -0
  42. package/dist/pdf-pictures.js.map +1 -0
  43. package/dist/plan.d.ts +13 -3
  44. package/dist/plan.d.ts.map +1 -1
  45. package/dist/plan.js +22 -17
  46. package/dist/plan.js.map +1 -1
  47. package/dist/search.d.ts +9 -0
  48. package/dist/search.d.ts.map +1 -1
  49. package/dist/search.js +41 -0
  50. package/dist/search.js.map +1 -1
  51. package/dist/stores.d.ts +7 -1
  52. package/dist/stores.d.ts.map +1 -1
  53. package/dist/stores.js +37 -5
  54. package/dist/stores.js.map +1 -1
  55. package/dist/tools.d.ts +11 -0
  56. package/dist/tools.d.ts.map +1 -1
  57. package/dist/tools.js +145 -13
  58. package/dist/tools.js.map +1 -1
  59. package/dist/types.d.ts +57 -3
  60. package/dist/types.d.ts.map +1 -1
  61. package/docs/api.md +59 -17
  62. package/docs/configuration.md +351 -5
  63. package/docs/getting-started.md +50 -3
  64. package/docs/how-it-works.md +73 -4
  65. package/docs/security.md +39 -4
  66. package/package.json +7 -2
  67. package/src/extract.ts +34 -8
  68. package/src/gemini/chat.ts +145 -30
  69. package/src/gemini/endpoints.ts +34 -2
  70. package/src/gemini/generate.ts +63 -9
  71. package/src/gemini/index.ts +3 -3
  72. package/src/index.ts +2 -2
  73. package/src/library.ts +74 -7
  74. package/src/pdf-layout.ts +37 -1
  75. package/src/pdf-pages.ts +315 -0
  76. package/src/pdf-pictures.ts +324 -0
  77. package/src/plan.ts +36 -16
  78. package/src/search.ts +37 -0
  79. package/src/stores.ts +39 -6
  80. package/src/tools.ts +147 -13
  81. package/src/types.ts +57 -3
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,UAAU,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,KAAK,GAAG,MAAM,GAAG,MAAM,CAAC;AAEpG,MAAM,MAAM,YAAY,GAAG;IACzB,iDAAiD;IACj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,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC;CAC1B,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;AAEtB,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,EAAE,KAAK,GAAG,QAAQ,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;AAE9D,MAAM,MAAM,YAAY,GAAG;IACzB,sDAAsD;IACtD,MAAM,EAAE,YAAY,EAAE,CAAC;IACvB,sDAAsD;IACtD,UAAU,EAAE,YAAY,EAAE,CAAC;IAC3B,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,YAAY,CAAC;IACnB,iGAAiG;IACjG,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5B,mGAAmG;IACnG,WAAW,EAAE,MAAM,CAAC;IACpB,qEAAqE;IACrE,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB;;;OAGG;IACH,QAAQ,EAAE,YAAY,EAAE,CAAC;CAC1B,CAAC"}
package/docs/api.md CHANGED
@@ -20,6 +20,8 @@ Three entry points:
20
20
  | `maxUploadBytes` | `number` | 100 MB |
21
21
  | `extractors` | `Partial<Record<DocumentFormat, Extractor>>` | built-ins |
22
22
  | `cacheSize` | `number` | 6 parsed documents in memory |
23
+ | `keepOriginals` | `DocumentFormat[]` | `[]`: only text is kept. `["pdf"]` keeps uploaded PDFs, which `view_pages` needs ([details](configuration.md#keeping-the-uploaded-file)) |
24
+ | `scannedPdfPages` | `number` | 30: the longest PDF without any text that is accepted when its original is kept. 0 refuses them all |
23
25
 
24
26
  ### `LargeFiles`
25
27
 
@@ -27,10 +29,11 @@ Three entry points:
27
29
  |---|---|
28
30
  | `ingest({ name, mimeType?, bytes, owner? })` | Extracts, normalizes, profiles, and stores a file. Returns `DocumentMeta`. Throws an `Error` with a user-readable message for empty, oversized, binary, or text-less files. |
29
31
  | `getMeta(id, { owner }?)` | `DocumentMeta`, or `undefined` if unknown, expired, or owned by someone else. |
32
+ | `getOriginal(id, { owner }?)` | The uploaded file as a `Uint8Array`, when it was kept. `undefined` otherwise, and for another owner. |
30
33
  | `delete(id, { owner }?)` | `true` if deleted. |
31
34
  | `sweep()` | Removes expired documents; returns the count. |
32
- | `prepare(ids, base, { owner }?)` | Plans one request. `base` is `{ tokens, bytes }` for everything else in the request. Returns `PreparedContext`. |
33
- | `tools(documents, { generate?, onProgress?, signal? })` | A `ToolSet` scoped to these documents. `generate` enables `analyze_whole_document`. |
35
+ | `prepare(ids, base, { owner?, viewPages? }?)` | Plans one request. `base` is `{ tokens, bytes }` for everything else in the request. Returns `PreparedContext`. `viewPages: true` says that your loop can pass files to the model. |
36
+ | `tools(documents, { generate?, onProgress?, signal?, viewPages? })` | A `ToolSet` scoped to these documents. `generate` enables `analyze_whole_document`. `viewPages` (`true`, or a list of documents such as `prepared.viewable`) enables `view_pages`. |
34
37
  | `budget`, `maxUploadBytes` | The effective settings. |
35
38
 
36
39
  ### `PreparedContext`
@@ -39,8 +42,9 @@ Three entry points:
39
42
  {
40
43
  plan: { inline: DocumentMeta[]; searchable: DocumentMeta[]; inlineTokens: number; inlineBytes: number };
41
44
  blocks: Map<string, string>; // per document ID: full text (inline) or a summary card (searchable)
42
- instruction: string; // add to the system prompt; empty when nothing is searchable
45
+ instruction: string; // add to the system prompt; empty when there is nothing to search or to look at
43
46
  missing: string[]; // IDs not found (never uploaded, expired, or another owner's)
47
+ viewable: DocumentMeta[]; // PDFs whose pages view_pages can show; empty without viewPages: true
44
48
  }
45
49
  ```
46
50
 
@@ -51,22 +55,32 @@ Three entry points:
51
55
  declarations: ToolDeclaration[]; // { name, description, parameters: JSON Schema }
52
56
  has(name): boolean;
53
57
  execute(name, args): Promise<ToolResult>; // errors come back as { error } for the model to read
58
+ executeWithFiles(name, args, { maxFileBytes?, maxPages? }?): Promise<{ result: ToolResult; files: ToolFile[] }>;
54
59
  describe(name, args): string; // "Search app.log (exact) for “timeout”"
55
60
  }
56
61
  ```
57
62
 
63
+ `executeWithFiles` runs any tool. Its `files` (`{ name, mimeType, bytes }`) are empty for all but
64
+ `view_pages`. `execute("view_pages", …)` returns an error, because it has no place for the file.
65
+
58
66
  | Tool | Arguments | Returns |
59
67
  |---|---|---|
60
68
  | `search_document` | `document_id`, `query`, `mode`: `keywords` (default) \| `exact` \| `regex`, `max_results`, `context_lines`, `case_sensitive` | `keywords`: ranked passages with numbered lines. `exact`/`regex`: matching lines and `total_matching_lines`. |
61
69
  | `read_document` | `document_id`, `start_line`, `end_line?` | Up to 600 numbered lines, and `next_start_line` if there's more |
62
70
  | `get_document_overview` | `document_id` | Format, size, outline, log profile, first and last lines |
63
71
  | `analyze_whole_document` | `document_id`, `task` | `answer` from a map-reduce read, plus part counts |
72
+ | `view_pages` | `document_id`, `from_page`, `to_page?` | Up to 5 pages of a PDF as one PDF file, with `pages` ("12-14"), `total_pages`, `file` (its name), and `next_page` when fewer pages were given than asked. Declared only with `viewPages`, for PDFs whose original is kept. |
73
+
74
+ For a PDF that `view_pages` can show, the results of `search_document` and `read_document` also
75
+ carry page numbers: `page` on each matching line, `pages` on a passage and on a range that was read.
64
76
 
65
77
  ### Stores
66
78
 
67
79
  - `new MemoryDocumentStore({ now? })`: in-process, for tests and single-instance demos.
68
- - `new FileDocumentStore(directory, { now? })`: `<id>.txt` and `<id>.json` per document.
69
- - Implement `DocumentStore` (`put`, `get`, `getMeta`, `delete`, `sweep?`) for anything else.
80
+ - `new FileDocumentStore(directory, { now? })`: `<id>.txt` and `<id>.json` per document, and
81
+ `<id>.bin` for a kept original.
82
+ - Implement `DocumentStore` (`put`, `get`, `getMeta`, `delete`, `sweep?`, and `putOriginal?` with
83
+ `getOriginal?` to keep originals) for anything else.
70
84
 
71
85
  ### Helpers
72
86
 
@@ -74,10 +88,12 @@ Three entry points:
74
88
  - `toolResultSummary(label, result)`: `" — 12 matching lines"`, for step lists.
75
89
  - `isDocumentId(value)`, `DOCUMENT_ID_PATTERN`.
76
90
  - `estimateTokens(text)`, `utf8Bytes(text)`, `jsonBytes(text)`.
77
- - `detectFormat(name, mimeType)`, `defaultExtractors`, `TOOL_NAMES`, `DEFAULT_BUDGET`.
78
- - `createPdfExtractor({ tables?: boolean })`: the built-in PDF extractor with an option changed.
79
- `tables: false` gives the text in pdf.js order, without rebuilt tables
80
- (see [PDF tables](configuration.md#pdf-tables)).
91
+ - `detectFormat(name, mimeType)`, `defaultExtractors`, `TOOL_NAMES`, `DEFAULT_BUDGET`,
92
+ `MAX_VIEW_PAGES` (5).
93
+ - `createPdfExtractor({ tables?: boolean, pictures?: boolean })`: the built-in PDF extractor with
94
+ an option changed. `tables: false` gives the text in pdf.js order, without rebuilt tables
95
+ (see [PDF tables](configuration.md#pdf-tables)). `pictures: false` leaves out the line that marks
96
+ a page with a picture (see [Pictures in PDFs](configuration.md#pictures-in-pdfs)).
81
97
 
82
98
  ### Key types
83
99
 
@@ -88,6 +104,7 @@ type DocumentMeta = {
88
104
  id: string; owner?: string; name: string; mimeType: string; format: DocumentFormat;
89
105
  bytes: number; textBytes: number; characters: number; lines: number; estimatedTokens: number;
90
106
  wrappedLines: number; pages?: number;
107
+ originalKept?: boolean; // the uploaded file is in the store next to the text
91
108
  outline: { line: number; level: number; title: string }[];
92
109
  logProfile?: { levels: Record<string, number>; firstTimestamp?: string; lastTimestamp?: string;
93
110
  topIssues: { template: string; level: string; count: number; firstLine: number }[] };
@@ -98,7 +115,10 @@ type GenerateText = (request: {
98
115
  system: string; prompt: string; maxOutputTokens: number; signal?: AbortSignal;
99
116
  onTruncated?: () => void; // call it when the model stopped at maxOutputTokens
100
117
  }) => Promise<string>;
101
- type Extractor = (bytes: Uint8Array, input: { name: string; mimeType: string; format: DocumentFormat }) => Promise<{ text: string; pages?: number }>;
118
+ type Extractor = (bytes: Uint8Array, input: { name: string; mimeType: string; format: DocumentFormat; scannedPages?: number }) => Promise<{ text: string; pages?: number }>;
119
+ // scannedPages: set when a PDF without any text is welcome, with the most pages it may have.
120
+
121
+ type ToolFile = { name: string; mimeType: string; bytes: Uint8Array };
102
122
  ```
103
123
 
104
124
  ## `llm-large-files/gemini`
@@ -112,11 +132,14 @@ type Extractor = (bytes: Uint8Array, input: { name: string; mimeType: string; fo
112
132
  | `contents` | Instead of `messages`: raw Gemini `contents` (images, inline PDFs…). Not mutated. |
113
133
  | `system` | System instruction; the tool guide is appended when needed. |
114
134
  | `generationConfig` | Sent with every chat request. |
135
+ | `explorerGenerationConfig` | The same, for the requests of an [explorer model](configuration.md#an-explorer-model). Defaults to `generationConfig`. Not used without an explorer. |
115
136
  | `owner` | Only documents with this owner (or no owner) are used. |
116
137
  | `documentPlacement` | `"first"` (default): document text and cards go at the start of the first user turn and stay there, so follow-up questions reuse Gemini's prompt cache. `"last"`: appended to the latest user turn, as in 0.1.0. |
117
- | `maxToolTurns` | Default 12. The most requests for one question, counting the answer. If the model is still calling tools on the last one, it is sent with no tools so the model must answer. |
138
+ | `maxToolTurns` | Default 12. The most requests for one question, counting the answer. If the model is still calling tools on the last one, it is sent with no tools so the model must answer. With an explorer model the answer is always the last request, so the explorer has one less. |
118
139
  | `wholeDocumentAnalysis` | Default `true`. Set `false` to withhold the costly whole-file tool. |
119
- | `analysisConfig` | `(maxOutputTokens) => generationConfig` for whole-file part reads. |
140
+ | `viewPages` | Default `true`. Offers `view_pages` for PDFs whose original is kept. It changes nothing for a library that keeps no originals. |
141
+ | `toolFilePlacement` | `"inside"` (default): the pages go in the function response itself, which Gemini 3 models read. `"beside"`: in a user turn of their own after the function responses, for Gemini 2.5, which does not see a file inside a function response. See [Where the pages go](configuration.md#where-the-pages-go-toolfileplacement). |
142
+ | `analysisConfig` | `(maxOutputTokens) => generationConfig` for whole-file part reads. The explorer model reads the parts when there is one, so write it for that model. |
120
143
  | `onText`, `onActivity`, `onStep` | Streaming answer text, transient status, completed steps. |
121
144
  | `fetch`, `signal` | Custom fetch (proxies, tests) and cancellation. |
122
145
 
@@ -135,18 +158,37 @@ if (!result.answered) show(result.blockReason ? "The request was blocked." : "No
135
158
  It throws `DocumentsNotFoundError` (`.ids`) before calling the model, `GeminiRequestError` (`.status`)
136
159
  for HTTP errors, and `Error` when the last message isn't the user's.
137
160
 
161
+ With an [explorer model](configuration.md#an-explorer-model), `text` and `onText` carry only what
162
+ the answering model wrote, `turns` counts the requests of both models, and `usage` and
163
+ `finishReason` are those of the answer. An explorer that fails throws `GeminiRequestError` too.
164
+
138
165
  ### Endpoints
139
166
 
140
- - `geminiApi({ apiKey, model, apiVersion = "v1beta", baseUrl? })`
141
- - `vertexAi({ project, model, location = "global", accessToken, apiVersion = "v1" })`, where
142
- `accessToken` can be a string or `() => string | Promise<string>`.
143
- - Or any `{ url, streamUrl?, headers }` (`headers` can be a function).
167
+ - `geminiApi({ apiKey, model, explorerModel?, apiVersion = "v1beta", baseUrl? })`
168
+ - `vertexAi({ project, model, explorerModel?, location = "global", accessToken, apiVersion = "v1" })`,
169
+ where `accessToken` can be a string or `() => string | Promise<string>`.
170
+ - Or any `{ url, streamUrl?, headers, explorerUrl? }` (`headers` can be a function).
171
+
172
+ `model` is the model that answers. `explorerModel` names a second one that makes the tool calls and
173
+ reads whole files in parts, so that `model` only writes the answer. Left out, empty, or the same as
174
+ `model`, one model does both, as before. In an endpoint of your own it is `explorerUrl`: the
175
+ `...:generateContent` URL of the explorer, called with the same headers. See
176
+ [An explorer model](configuration.md#an-explorer-model).
144
177
 
145
178
  ### Lower-level helpers
146
179
 
147
180
  - `createGeminiGenerateText({ url, headers, fetchImpl?, generationConfig?, timeoutMs? })`: a `GenerateText` for your own loop.
148
181
  - `toGeminiTools(declarations)`: `{ functionDeclarations }`.
149
- - `geminiFunctionResponses([{ call, result }])`: the `user` turn answering function calls.
182
+ - `geminiFunctionResponses([{ call, result, files? }])`: the `user` turn answering function
183
+ calls. Files from `executeWithFiles` go inside their function response, as base64.
184
+ - `geminiFunctionResponseTurns([{ call, result, files? }], { files?: "inside" | "beside" })`: the
185
+ turns to add to `contents`. That is the one turn above, or with `"beside"` the function
186
+ responses followed by a `user` turn that holds the files.
187
+ - `FINAL_ANSWER_REQUEST`, `FINAL_ANSWER_AFTER_PAGES`: the messages `askGemini` adds when the model
188
+ must stop using tools. The second is used when `view_pages` was the only tool.
189
+ - `FINAL_ANSWER_WITHOUT_TOOLS`, `EXPLORER_INSTRUCTION`: the two texts `askGemini` adds for an
190
+ explorer model. The first asks the answering model for the answer when the explorer called no
191
+ tool. The second is the line in the explorer's system instruction that says what its part is.
150
192
  - `parseSseJson(stream)`: async iterator over a Generate Content SSE stream.
151
193
 
152
194
  ## `llm-large-files/node`
@@ -56,6 +56,128 @@ Tokenizers differ between providers. These weights are fitted to Gemini, which c
56
56
  by one. A tokenizer that groups digits will count fewer tokens than this estimate for logs and
57
57
  data, which is the safe direction.
58
58
 
59
+ ## An explorer model
60
+
61
+ The model is yours to choose: it is the `model` you give `geminiApi()` or `vertexAi()`, or the URL
62
+ of your own endpoint. The package has no default. That one model does both halves of the work on a
63
+ large file: it explores the file (searches, reads, looks at pages), and it answers.
64
+ `explorerModel` names a second model for the first half:
65
+
66
+ ```ts
67
+ const endpoint = geminiApi({
68
+ apiKey,
69
+ model: "gemini-3.8-flash", // writes the answer
70
+ explorerModel: process.env.GEMINI_EXPLORER_MODEL, // optional: searches and reads
71
+ });
72
+ // vertexAi({ project, model, explorerModel, accessToken }) takes it the same way.
73
+ ```
74
+
75
+ Left out, empty, or the same as `model`, there is no explorer, and `askGemini` sends exactly the
76
+ requests it sent before. So a setting that may be unset can be passed as it is.
77
+
78
+ With URLs of your own, give the explorer's as `explorerUrl`. It is called with the same headers:
79
+
80
+ ```ts
81
+ const endpoint = {
82
+ url: "https://llm-gateway.corp.example/gemini/models/gemini-3.8-flash:generateContent",
83
+ streamUrl: "https://llm-gateway.corp.example/gemini/models/gemini-3.8-flash:streamGenerateContent?alt=sse",
84
+ explorerUrl: "https://llm-gateway.corp.example/gemini/models/gemini-3.5-flash-lite:generateContent",
85
+ headers,
86
+ };
87
+ ```
88
+
89
+ The reason to use one: a question about a large log can take ten requests of searching and
90
+ reading, each larger than the one before, and a whole-file read adds up to 30 part reads. With an
91
+ explorer those go to a cheaper or faster model, and the model you chose for its answers is called
92
+ once.
93
+
94
+ ### Who does what
95
+
96
+ | | The explorer | `model` |
97
+ |---|---|---|
98
+ | Requests with tools: `search_document`, `read_document`, `get_document_overview`, `view_pages` | All | None |
99
+ | The part reads of `analyze_whole_document` | All | None |
100
+ | The answer | | One request, without tools |
101
+ | A question about files that are sent whole, with no pages to look at | Not called | One request, as before |
102
+
103
+ The answering model gets the conversation, the explorer's tool calls, and what each call
104
+ returned, pages included. It does not get the explorer's thoughts, its thought signatures, or
105
+ anything it wrote: the answer is written from what the files say, not from what the explorer made
106
+ of them. So the answering model can use only what the explorer fetched. It has no tools of its own
107
+ to fetch more.
108
+
109
+ The explorer is told its part, in a line added to its system instruction (`EXPLORER_INSTRUCTION`):
110
+ gather what the answer needs, then reply `DONE`. `gemini-3.5-flash-lite` did exactly that, at one
111
+ output token. A model that writes an answer anyway (`gemini-2.5-flash-lite` did) costs those output
112
+ tokens, and its answer is dropped.
113
+
114
+ ### What changes for your application
115
+
116
+ - **One request more.** The answer is always a request of its own, so a question that one model
117
+ settles in three requests takes four. `maxToolTurns` still counts them all: the explorer has
118
+ `maxToolTurns − 1` requests, and the last one is the answer.
119
+ - **`text` and `onText` carry only the answer.** Without an explorer, a remark that the model makes
120
+ before a tool call ("Let me search…") is part of `text`. The explorer's words are not shown.
121
+ `onActivity` and `onStep` report its tool calls as before, and `turns` counts its requests too.
122
+ `usage` and `finishReason` are those of the answer.
123
+ - **The explorer's requests are not streamed.** Nothing it writes is shown, so each goes to
124
+ `explorerUrl` in one piece. The answer streams as before.
125
+ - **Settings are per model.** `explorerGenerationConfig` is the explorer's `generationConfig`, and
126
+ defaults to yours. Set it when the two models do not take the same settings: given a
127
+ `thinkingLevel`, `gemini-2.5-flash-lite` on Vertex AI answers HTTP 400, "thinking_level is not
128
+ supported by this model". `analysisConfig` is for the part reads, which the explorer does, so
129
+ write it for the explorer.
130
+ - **The budget has to fit both models.** Both get the same conversation and the same tool
131
+ results. Set `contextTokens` and `maxRequestBytes` to the smaller of the two.
132
+ - **Pages have to be readable by both models.** `toolFilePlacement: "inside"` is read by Gemini 3
133
+ models only. If either model is Gemini 2.5, use `"beside"`, which both read
134
+ ([below](#where-the-pages-go-toolfileplacement)).
135
+ - **An explorer that fails is an error.** A model name that does not exist, or a quota that is
136
+ used up, throws `GeminiRequestError`, as it does for `model`. The question is not passed to
137
+ `model` instead: that would hide the mistake, and send the searching to the model you wanted to
138
+ spare.
139
+ - **A PDF whose text is in the prompt**, and whose pages can be looked at, goes to the explorer
140
+ first: it decides whether to look. The text of such a PDF is then sent twice, once to each model.
141
+
142
+ ```ts
143
+ await askGemini({
144
+ files, endpoint, messages, documentIds,
145
+ generationConfig: { thinkingConfig: { thinkingLevel: "high" } }, // for `model`
146
+ explorerGenerationConfig: { thinkingConfig: { thinkingBudget: 0 } }, // for a Gemini 2.5 explorer
147
+ toolFilePlacement: "beside", // one of the two is Gemini 2.5
148
+ });
149
+ ```
150
+
151
+ ### Live results with an explorer
152
+
153
+ Flash-Lite models, November 2026, through `ingest` and `askGemini`. The log has 6,000 lines, 24
154
+ deadlocks and one fatal error. The PDF is the one with a chart and a photo from
155
+ [Pictures in PDFs](#live-results).
156
+
157
+ | Explorer → `model` | Question | Result |
158
+ |---|---|---|
159
+ | `gemini-3.5-flash-lite` → `gemini-3.1-flash-lite`, Gemini API | How many deadlocks, and the line of the first | Two searches, then `DONE`. Answer right. Four requests, 3 s. |
160
+ | | What shut the gateway down, its error code, the warning before it | One search, then `DONE`. Four of four facts, with the right lines. |
161
+ | | The name of the file and its line count, which the card shows | `DONE` at once. Answered from the card, in two requests. |
162
+ | | Every kind of error, from a whole-file read | The explorer read the four parts and wrote up the notes, then searched three times. Answer right. |
163
+ | | The chart and the photo, with the text sent whole | The explorer looked at two pages. The other model got them and had five of five facts right. |
164
+ | | The same, with the PDF searched | A read and a look in one turn. Five of five. |
165
+ | | The gateway and the chart again, both models thinking (`thinkingLevel: "high"`) | Both right. |
166
+ | `gemini-3.1-flash-lite` → `gemini-3.5-flash-lite`, Gemini API | The deadlocks | Answer right. The explorer repeated one search until its eleven requests were used up, as it does when it works alone. |
167
+ | `gemini-2.5-flash-lite` → `gemini-3.5-flash-lite`, Vertex AI | The deadlocks, the gateway, and the chart with pages `"beside"` | All right. This explorer wrote an answer each time instead of `DONE`. |
168
+ | `gemini-3.5-flash-lite` → `gemini-2.5-flash-lite`, Vertex AI | The deadlocks, the chart with pages `"beside"`, and the card | All right. |
169
+ | `gemini-3.1-flash-lite` → `gemini-3.5-flash-lite`, Vertex AI, both thinking | The gateway | Right. |
170
+
171
+ What made the form of the handoff: a Gemini 3 model refuses a request that ends with the result of
172
+ a function call it did not sign (HTTP 400, "Function call is missing a thought_signature"), and a
173
+ thought signature belongs to the model that made the call. When a user message follows the
174
+ results, the same calls are accepted without a signature: by Gemini 3.1 and 3.5 Flash-Lite on the
175
+ Gemini API and on Vertex AI, and by Gemini 2.5 Flash-Lite on Vertex AI. So the answering model's
176
+ request always ends with a user message, and holds no signatures.
177
+
178
+ Not checked: models larger than Flash-Lite, and Gemini 4. The two models have to be reachable with
179
+ the same headers, so one cannot be on the Gemini API and the other on Vertex AI.
180
+
59
181
  ## Stores
60
182
 
61
183
  | Store | Use it for |
@@ -69,14 +191,36 @@ interface DocumentStore {
69
191
  put(document: { meta: DocumentMeta; text: string }): Promise<void>;
70
192
  get(id: string): Promise<{ meta: DocumentMeta; text: string } | undefined>; // undefined if expired
71
193
  getMeta(id: string): Promise<DocumentMeta | undefined>;
72
- delete(id: string): Promise<boolean>;
194
+ delete(id: string): Promise<boolean>; // the original file too
73
195
  sweep?(now?: Date): Promise<number>;
196
+ putOriginal?(id: string, bytes: Uint8Array): Promise<void>; // optional: see below
197
+ getOriginal?(id: string): Promise<Uint8Array | undefined>; // undefined if not kept, or expired
74
198
  }
75
199
  ```
76
200
 
77
201
  Keep `getMeta` cheap (store the metadata separately from the text). Parsed documents are cached
78
202
  in memory (`cacheSize`, default 6), so repeated tool calls don't reload the text.
79
203
 
204
+ ### Keeping the uploaded file
205
+
206
+ By default a store holds only the text of a document. `keepOriginals` also keeps the uploaded file,
207
+ which is what [showing pages of a PDF](#pictures-in-pdfs) needs:
208
+
209
+ ```ts
210
+ createLargeFiles({ store: new FileDocumentStore(dir), keepOriginals: ["pdf"] });
211
+ ```
212
+
213
+ - It is off by default because it costs disk: a kept file is as large as the upload (up to
214
+ `maxUploadBytes`, 100 MB) and stays until the document expires or is deleted.
215
+ - `FileDocumentStore` writes it as `<id>.bin` next to `<id>.txt` and `<id>.json`.
216
+ `MemoryDocumentStore` keeps a copy in memory.
217
+ - A store of your own keeps originals when it has `putOriginal` and `getOriginal`. `putOriginal` is
218
+ called before `put` for the same ID, and `delete` and `sweep` must remove the file. A store
219
+ without the two methods works as before: nothing is kept, and `view_pages` is not offered.
220
+ - `DocumentMeta.originalKept` says whether a document's file is kept. `files.getOriginal(id, { owner })`
221
+ returns it.
222
+ - Documents ingested before you turned it on have no original. Upload them again to get one.
223
+
80
224
  ## Formats
81
225
 
82
226
  | Format | Detected by | Notes |
@@ -85,7 +229,7 @@ in memory (`cacheSize`, default 6), so repeated tool calls don't reload the text
85
229
  | `markdown` | `.md`, `.markdown`, `text/markdown` | Headings form the outline |
86
230
  | `json` | `.json`, `.jsonl`, `.ndjson` | Minified JSON is wrapped into addressable lines |
87
231
  | `csv` | `.csv`, `.tsv` | |
88
- | `pdf` | `.pdf` | Needs `unpdf`. Pages are marked `--- Page N ---`, tables are rebuilt (below), and a page without text says so. Scanned PDFs (no text layer at all) are rejected. |
232
+ | `pdf` | `.pdf` | Needs `unpdf`. Pages are marked `--- Page N ---`, tables are rebuilt (below), and a page without text says so. With `@cantoo/pdf-lib`, a page that shows a picture says so too, and the model can be shown the page itself ([Pictures in PDFs](#pictures-in-pdfs)). A scanned PDF (no text layer at all) is rejected, unless its original is kept and it has at most 30 pages. |
89
233
  | `docx`, `pptx` | extension or MIME type | Needs `jszip`. Slides are marked `## Slide N`. |
90
234
  | `text` | anything else that decodes as text | UTF-8 or UTF-16 (with or without BOM); binary is rejected |
91
235
 
@@ -122,9 +266,9 @@ It is cautious: where the evidence for a table is weak, the text stays as it was
122
266
  - Columns that are closer together than a word space on every line of the table stay together in
123
267
  one cell, on every row alike.
124
268
  - A table whose text is stored column by column in the file is not rebuilt.
125
- - Pictures, charts and scanned pages are still not read. A page with no text at all is written as
269
+ - Pictures and charts are not in the text. A page with no text at all is written as
126
270
  `[No text on this page. It may be a scan, a photo, or a chart.]`, so the model can say that it
127
- cannot see it.
271
+ cannot see it. To let the model look at such pages, see [Pictures in PDFs](#pictures-in-pdfs).
128
272
 
129
273
  The cell marks cost tokens: about one per cell. A bank statement came to 27% more tokens than
130
274
  its text in file order, a report with one table in it to 9% more. Reading 600 pages with 24,600
@@ -139,7 +283,209 @@ createLargeFiles({ store, extractors: { pdf: createPdfExtractor({ tables: false
139
283
  ```
140
284
 
141
285
  Small PDFs are still better sent to Gemini as the file itself, when your payload limit allows:
142
- it then sees the page, including pictures.
286
+ it then sees every page, including pictures. For a PDF that is too large for that, the next section
287
+ gives the model the pages it asks for.
288
+
289
+ ## Pictures in PDFs
290
+
291
+ The text of a PDF does not hold its photos, charts and diagrams. Asked about a bar chart from the
292
+ text alone, a model can only say that it cannot see it, or guess. Two things, both optional and
293
+ both for PDFs only, close that gap:
294
+
295
+ 1. **A line in the text that says where the pictures are.**
296
+ 2. **A tool, `view_pages`, that hands the model the real pages** as a small PDF, when it asks.
297
+
298
+ ```bash
299
+ npm install @cantoo/pdf-lib # optional dependency, needed for both
300
+ ```
301
+
302
+ ```ts
303
+ const files = createLargeFiles({
304
+ store: new FileDocumentStore("./data/large-files"),
305
+ keepOriginals: ["pdf"], // needed for view_pages: it cuts pages out of the uploaded file
306
+ });
307
+ // askGemini then offers view_pages by itself. Nothing else changes in your code.
308
+ ```
309
+
310
+ ### The line that marks a page
311
+
312
+ At ingest, a page that shows a picture or a drawing gets one line under its header:
313
+
314
+ ```
315
+ --- Page 12 ---
316
+ [Picture on this page. This text cannot show it.]
317
+ Figure 3: sales by region.
318
+ ```
319
+
320
+ The words hold whether or not the model can look at the page later. A search for
321
+ `[Picture on this page` lists every such page.
322
+
323
+ What counts:
324
+
325
+ - **A picture:** the images on the page cover 3% of it or more, measured by the size they are
326
+ shown at, not by their pixels. A logo covers about 1%. An image that is on 30% of the pages (and
327
+ on three at least) is taken for a logo, a letterhead or a watermark, and does not count,
328
+ whatever its size.
329
+ - **A drawing:** shapes filled in three or more colours, outside the tables. Greys, rules, dots
330
+ and page backgrounds do not count, and neither does the shading of a table's cells.
331
+ - A page whose drawing instructions are larger than 2 MB: that is a map or a technical drawing.
332
+
333
+ What it gets wrong:
334
+
335
+ - Missed: a chart in one or two colours, and a chart or diagram drawn only with lines.
336
+ - Marked by mistake: a table with cells shaded in three colours, when the table itself was not
337
+ recognised (a table of two columns, for example).
338
+
339
+ The mark is a hint. `view_pages` works on any page, marked or not, and in a live test the model
340
+ looked at a one-colour chart that had only a caption (below).
341
+
342
+ The pages are found from the structure of the file, without decoding any image, so it is cheap:
343
+ a PDF of 200 photos (85 MB) took 0.3 s to ingest without marks and 0.8 s with them. No page is
344
+ marked, and the text is exactly that of version 0.2.0, when:
345
+
346
+ - `@cantoo/pdf-lib` is not installed;
347
+ - you turn it off: `createPdfExtractor({ pictures: false })`;
348
+ - the file declares more than 150,000 objects (reading it would take over two seconds), reading
349
+ took more than five seconds, or the file does not have the pages the text was read from.
350
+
351
+ One cost to know: a PDF whose streams do not state their length up front (Ghostscript writes them
352
+ so) is scanned byte by byte, about 30 ms per MB. A file of 100 MB written that way took 3 s to
353
+ ingest instead of 0.1 s.
354
+
355
+ ### `view_pages`
356
+
357
+ `view_pages(document_id, from_page, to_page)` cuts those pages out of the kept original and
358
+ returns them as one PDF. `askGemini` puts it inside the function response, and Gemini reads it
359
+ like any PDF: text, pictures and layout.
360
+
361
+ It is offered for every PDF whose original is kept, also for one whose text is already in the
362
+ prompt: a slide deck of photos has little text, so its text fits, and without the tool the model
363
+ would see none of its slides. Such a PDF gets `view_pages` and no search tools.
364
+
365
+ For a PDF that the model can look at, search and read results also say which page a line is on
366
+ (`"page": 12`), since a page number is what `view_pages` takes.
367
+
368
+ Limits:
369
+
370
+ | Limit | Value | When it is reached |
371
+ |---|---|---|
372
+ | Pages per call | 5 | The result says where to continue (`next_page`). |
373
+ | Bytes | What is left of `maxRequestBytes`, less a tenth kept free (256 KB at least), times 3/4 for base64 | Pages are left off the end of the call. A page that does not fit by itself gives an error, and the model answers from what it has. |
374
+ | Pages per question | `reservedTokens / 2 / 530`: 60 with the default budget | The tool says that no more pages can be looked at. |
375
+
376
+ Pages stay in the request until the question is answered, so every look makes the later requests
377
+ of that question larger. They are not sent again with the next question.
378
+
379
+ A page costs Gemini about 530 tokens, whatever is on it: 532 for each of 1, 2, 3 and 5 A4 pages,
380
+ and 527 for a 16:9 slide (`gemini-3.5-flash-lite`).
381
+
382
+ A cut holds the pages asked for and little else. Copying pages the simple way does not: a contents
383
+ page links to every section, and those pages came along, so the cut was 89% of the file. Here every
384
+ other page is emptied before copying, and a page that shares its resources with the whole file
385
+ (FPDF, TCPDF and jsPDF write PDFs that way) gets a list of its own.
386
+
387
+ | File | Pages cut | Size of the cut |
388
+ |---|---|---|
389
+ | Chrome, 72 photos, 100 MB | 5 | 7.0 MB (7%) |
390
+ | PowerPoint deck, 40 photos, 9.9 MB | 5 | 1.2 MB (13%) |
391
+ | Word report with a contents page, 7.5 MB | the contents page | 55 KB (0.7%) |
392
+ | All images in one shared list, 12 MB | 2 | 0.6 MB (5%) |
393
+
394
+ What a cut costs the server: the whole file is read into memory on every call.
395
+
396
+ | File | Time | Memory at the peak |
397
+ |---|---|---|
398
+ | 100 MB of photos, 900 objects | 0.06 s | about 300 MB |
399
+ | 100 MB written the way Ghostscript writes | 3 s | about 300 MB |
400
+ | 54 MB, 330,000 objects (a tagged table of 591 pages) | 4 to 5 s | about 700 MB |
401
+
402
+ A file that declares more than a million objects, or more than the free memory can hold, is not
403
+ cut: the tool tells the model that the pages cannot be shown.
404
+
405
+ Also handled: PDFs encrypted only to restrict printing or copying (they open without a password),
406
+ hidden layers (they stay hidden), rotated pages, and links. Not shown: a PDF that needs a password
407
+ to open, a damaged file, and a file in which this reader counts other pages than the text
408
+ extractor did. In each case the model gets a message and answers from the text.
409
+
410
+ ### Scanned PDFs
411
+
412
+ A PDF with no text at all has nothing to search, and is refused: `This PDF has no text layer`. When
413
+ its original is kept, the model can read it by looking at its pages, so a scan of **up to 30
414
+ pages** is accepted. Every page of its text says that it has no text, and the model gets
415
+ `view_pages`. A longer scan is still refused: it could only be read five pages at a time, and it
416
+ could not be searched.
417
+
418
+ ```ts
419
+ createLargeFiles({ store, keepOriginals: ["pdf"], scannedPdfPages: 30 }); // 30 is the default; 0 refuses all scans
420
+ ```
421
+
422
+ A PDF with text on any page was always accepted and still is, however many of its pages are scans.
423
+
424
+ ### Live results
425
+
426
+ `gemini-3.5-flash-lite` on the Gemini API, November 2026, through `ingest` and `askGemini`:
427
+
428
+ | Check | Result |
429
+ |---|---|
430
+ | Which bar of a chart is tallest and shortest, and their colours; a number on a sign in a photo. Text sent whole. | Looked at 2 pages unasked. All five facts right. From the text alone, the model said it could not see the chart. |
431
+ | The same, with the PDF searched instead | One look, all five right. |
432
+ | Ten questions that the text answers, about a PDF with a photo on each of its 60 pages | 0 of 10 looked at a page, with the text sent whole and with the PDF searched. 10 of 10 right both times. |
433
+ | A chart in one colour: a caption, but no mark | The model looked at the page and read the chart correctly. |
434
+ | Five pages in one look (five numbers on five signs) | All five right. 2,660 tokens for the pages. |
435
+ | A slide deck of 41 slides: a number on slide 8, a bar on slide 1 | Two looks, both right. |
436
+ | A PDF encrypted to restrict printing | One look, all right. |
437
+ | A scan of three pages (pictures of text) | One look at the three pages. Four of four facts right. |
438
+ | The request without tools that ends a question, after a look | Accepted, answered correctly, with the pages still in it. |
439
+
440
+ **Vertex AI**, with the same model (locations `global` and `eu`, November 2026): one look, two
441
+ looks in one model turn, one look that decides the next, the request without tools that ends a
442
+ question, and a PDF that is searched. All were accepted and answered correctly, with `vertexAi()`
443
+ and through an application's own URLs, streaming and not. Real files went through too: a number
444
+ on a photo in a 7.5 MB report written by Word, and five numbers from one look at five pages of a
445
+ 25 MB file (a 2.2 MB PDF in the request). A page costs 532 tokens there as well.
446
+
447
+ ### Where the pages go: `toolFilePlacement`
448
+
449
+ | `toolFilePlacement` | What is sent | Gemini 3.5 Flash-Lite, on the Gemini API and on Vertex AI | Gemini 2.5 Flash-Lite, on Vertex AI |
450
+ |---|---|---|---|
451
+ | `"inside"` (default) | The PDF in the `parts` of its function response, which names it as `{ "$ref": "pages-12-14.pdf" }` | Works | Accepted and counted, but the model does not see the pages |
452
+ | `"beside"` | The function responses in one `user` turn, then the PDFs in a `user` turn of their own, each after a line that names it | Works | Works |
453
+
454
+ ```ts
455
+ await askGemini({ ..., toolFilePlacement: "beside" }); // for Gemini 2.5
456
+ ```
457
+
458
+ Keep the default for Gemini 3 models. Use `"beside"` for Gemini 2.5: it takes a file inside a
459
+ function response without an error, counts its tokens, and then answers that it cannot see the
460
+ page. Gemini 2.5 on the Gemini API was not checked (that model is closed to new users there), and
461
+ neither was Gemini 4.
462
+
463
+ With `"beside"` the files have a turn of their own because Vertex AI refuses a turn in which
464
+ anything follows a function response (HTTP 400, "Requests ending with a model turn are not
465
+ supported", seen with Gemini 3.5).
466
+
467
+ ### Your own loop
468
+
469
+ The pages are a file, and a loop that drops the file would tell the model that pages are attached
470
+ with nothing attached. So `view_pages` is declared only when you say that your loop delivers files:
471
+
472
+ ```ts
473
+ const prepared = await files.prepare(documentIds, base, { owner, viewPages: true });
474
+ const tools = files.tools(prepared.plan.searchable, { viewPages: prepared.viewable });
475
+
476
+ const { result, files: attached } = await tools.executeWithFiles(call.name, call.args, {
477
+ maxFileBytes: Math.floor(roomLeftInYourRequest * 3 / 4), // base64 turns three bytes into four
478
+ maxPages: pagesYouStillAllowForThisQuestion,
479
+ });
480
+ // attached: [{ name: "pages-12-14.pdf", mimeType: "application/pdf", bytes }]
481
+ // Send `result` as the tool result and each file as a PDF with it, in your provider's form.
482
+ // For Gemini, once every call of the model's turn is answered:
483
+ contents.push(...geminiFunctionResponseTurns(answers)); // answers: [{ call, result, files: attached }]
484
+ ```
485
+
486
+ `tools.execute("view_pages", ...)` returns only JSON, so it answers with an error instead of
487
+ pretending. `prepared.viewable` also lists PDFs that are not searched, because their text is in
488
+ the prompt: pass it as it is.
143
489
 
144
490
  ### Custom extractors
145
491