llm-large-files 0.5.0 → 0.8.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 (285) hide show
  1. package/CHANGELOG.md +1719 -466
  2. package/README.md +190 -60
  3. package/dist/analyze.d.ts +8 -1
  4. package/dist/analyze.d.ts.map +1 -1
  5. package/dist/analyze.js +198 -54
  6. package/dist/analyze.js.map +1 -1
  7. package/dist/anthropic/adapter.d.ts +14 -3
  8. package/dist/anthropic/adapter.d.ts.map +1 -1
  9. package/dist/anthropic/adapter.js +194 -40
  10. package/dist/anthropic/adapter.js.map +1 -1
  11. package/dist/ask.d.ts +63 -7
  12. package/dist/ask.d.ts.map +1 -1
  13. package/dist/ask.js +1131 -214
  14. package/dist/ask.js.map +1 -1
  15. package/dist/decode.d.ts +19 -0
  16. package/dist/decode.d.ts.map +1 -0
  17. package/dist/decode.js +97 -0
  18. package/dist/decode.js.map +1 -0
  19. package/dist/encoding.d.ts +17 -0
  20. package/dist/encoding.d.ts.map +1 -0
  21. package/dist/encoding.js +852 -0
  22. package/dist/encoding.js.map +1 -0
  23. package/dist/errors.d.ts +59 -0
  24. package/dist/errors.d.ts.map +1 -1
  25. package/dist/errors.js +80 -0
  26. package/dist/errors.js.map +1 -1
  27. package/dist/events.d.ts +339 -0
  28. package/dist/events.d.ts.map +1 -0
  29. package/dist/events.js +163 -0
  30. package/dist/events.js.map +1 -0
  31. package/dist/evidence.d.ts +2 -0
  32. package/dist/evidence.d.ts.map +1 -1
  33. package/dist/evidence.js +9 -2
  34. package/dist/evidence.js.map +1 -1
  35. package/dist/extract.d.ts +26 -7
  36. package/dist/extract.d.ts.map +1 -1
  37. package/dist/extract.js +180 -314
  38. package/dist/extract.js.map +1 -1
  39. package/dist/gemini/adapter.d.ts +17 -8
  40. package/dist/gemini/adapter.d.ts.map +1 -1
  41. package/dist/gemini/adapter.js +117 -66
  42. package/dist/gemini/adapter.js.map +1 -1
  43. package/dist/gemini/chat.d.ts +23 -3
  44. package/dist/gemini/chat.d.ts.map +1 -1
  45. package/dist/gemini/chat.js +6 -2
  46. package/dist/gemini/chat.js.map +1 -1
  47. package/dist/gemini/endpoints.d.ts +5 -1
  48. package/dist/gemini/endpoints.d.ts.map +1 -1
  49. package/dist/gemini/endpoints.js +11 -2
  50. package/dist/gemini/endpoints.js.map +1 -1
  51. package/dist/gemini/errors.d.ts +9 -4
  52. package/dist/gemini/errors.d.ts.map +1 -1
  53. package/dist/gemini/errors.js +32 -0
  54. package/dist/gemini/errors.js.map +1 -1
  55. package/dist/gemini/generate.d.ts +10 -2
  56. package/dist/gemini/generate.d.ts.map +1 -1
  57. package/dist/gemini/generate.js +33 -10
  58. package/dist/gemini/generate.js.map +1 -1
  59. package/dist/gemini/index.d.ts +3 -3
  60. package/dist/gemini/index.d.ts.map +1 -1
  61. package/dist/gemini/index.js +2 -2
  62. package/dist/gemini/index.js.map +1 -1
  63. package/dist/gemini/sse.d.ts +1 -1
  64. package/dist/gemini/sse.d.ts.map +1 -1
  65. package/dist/gemini/sse.js +1 -1
  66. package/dist/gemini/sse.js.map +1 -1
  67. package/dist/groups.d.ts +54 -0
  68. package/dist/groups.d.ts.map +1 -0
  69. package/dist/groups.js +136 -0
  70. package/dist/groups.js.map +1 -0
  71. package/dist/html.d.ts +11 -0
  72. package/dist/html.d.ts.map +1 -0
  73. package/dist/html.js +1112 -0
  74. package/dist/html.js.map +1 -0
  75. package/dist/http.d.ts +116 -0
  76. package/dist/http.d.ts.map +1 -1
  77. package/dist/http.js +347 -1
  78. package/dist/http.js.map +1 -1
  79. package/dist/index.d.ts +13 -7
  80. package/dist/index.d.ts.map +1 -1
  81. package/dist/index.js +7 -5
  82. package/dist/index.js.map +1 -1
  83. package/dist/library.d.ts +67 -5
  84. package/dist/library.d.ts.map +1 -1
  85. package/dist/library.js +449 -93
  86. package/dist/library.js.map +1 -1
  87. package/dist/limiter.d.ts +2 -1
  88. package/dist/limiter.d.ts.map +1 -1
  89. package/dist/limiter.js +3 -2
  90. package/dist/limiter.js.map +1 -1
  91. package/dist/map-reduce.d.ts +28 -1
  92. package/dist/map-reduce.d.ts.map +1 -1
  93. package/dist/map-reduce.js +240 -52
  94. package/dist/map-reduce.js.map +1 -1
  95. package/dist/model.d.ts +84 -2
  96. package/dist/model.d.ts.map +1 -1
  97. package/dist/model.js +190 -2
  98. package/dist/model.js.map +1 -1
  99. package/dist/node/handlers.d.ts +20 -4
  100. package/dist/node/handlers.d.ts.map +1 -1
  101. package/dist/node/handlers.js +184 -28
  102. package/dist/node/handlers.js.map +1 -1
  103. package/dist/node/index.d.ts +4 -0
  104. package/dist/node/index.d.ts.map +1 -1
  105. package/dist/node/index.js +2 -0
  106. package/dist/node/index.js.map +1 -1
  107. package/dist/node/ingest-child.d.ts +38 -0
  108. package/dist/node/ingest-child.d.ts.map +1 -0
  109. package/dist/node/ingest-child.js +42 -0
  110. package/dist/node/ingest-child.js.map +1 -0
  111. package/dist/node/isolated.d.ts +88 -0
  112. package/dist/node/isolated.d.ts.map +1 -0
  113. package/dist/node/isolated.js +381 -0
  114. package/dist/node/isolated.js.map +1 -0
  115. package/dist/node/sse.d.ts +59 -0
  116. package/dist/node/sse.d.ts.map +1 -0
  117. package/dist/node/sse.js +174 -0
  118. package/dist/node/sse.js.map +1 -0
  119. package/dist/office.d.ts +105 -0
  120. package/dist/office.d.ts.map +1 -0
  121. package/dist/office.js +1092 -0
  122. package/dist/office.js.map +1 -0
  123. package/dist/openai/adapter.d.ts +29 -5
  124. package/dist/openai/adapter.d.ts.map +1 -1
  125. package/dist/openai/adapter.js +325 -37
  126. package/dist/openai/adapter.js.map +1 -1
  127. package/dist/output-limit.d.ts +14 -2
  128. package/dist/output-limit.d.ts.map +1 -1
  129. package/dist/output-limit.js +39 -10
  130. package/dist/output-limit.js.map +1 -1
  131. package/dist/pause.d.ts +24 -0
  132. package/dist/pause.d.ts.map +1 -0
  133. package/dist/pause.js +38 -0
  134. package/dist/pause.js.map +1 -0
  135. package/dist/pdf-pages.d.ts +32 -2
  136. package/dist/pdf-pages.d.ts.map +1 -1
  137. package/dist/pdf-pages.js +277 -20
  138. package/dist/pdf-pages.js.map +1 -1
  139. package/dist/pdf-pictures.d.ts +30 -3
  140. package/dist/pdf-pictures.d.ts.map +1 -1
  141. package/dist/pdf-pictures.js +50 -8
  142. package/dist/pdf-pictures.js.map +1 -1
  143. package/dist/pdf-work.d.ts +40 -0
  144. package/dist/pdf-work.d.ts.map +1 -0
  145. package/dist/pdf-work.js +734 -0
  146. package/dist/pdf-work.js.map +1 -0
  147. package/dist/peers.d.ts +8 -0
  148. package/dist/peers.d.ts.map +1 -0
  149. package/dist/peers.js +32 -0
  150. package/dist/peers.js.map +1 -0
  151. package/dist/plan.d.ts +22 -4
  152. package/dist/plan.d.ts.map +1 -1
  153. package/dist/plan.js +61 -12
  154. package/dist/plan.js.map +1 -1
  155. package/dist/ranged.d.ts.map +1 -1
  156. package/dist/ranged.js +4 -2
  157. package/dist/ranged.js.map +1 -1
  158. package/dist/retry.d.ts +23 -1
  159. package/dist/retry.d.ts.map +1 -1
  160. package/dist/retry.js +33 -3
  161. package/dist/retry.js.map +1 -1
  162. package/dist/search.d.ts +107 -24
  163. package/dist/search.d.ts.map +1 -1
  164. package/dist/search.js +803 -149
  165. package/dist/search.js.map +1 -1
  166. package/dist/sse.d.ts +35 -2
  167. package/dist/sse.d.ts.map +1 -1
  168. package/dist/sse.js +145 -31
  169. package/dist/sse.js.map +1 -1
  170. package/dist/stores.d.ts.map +1 -1
  171. package/dist/stores.js +5 -2
  172. package/dist/stores.js.map +1 -1
  173. package/dist/text-index.d.ts +9 -1
  174. package/dist/text-index.d.ts.map +1 -1
  175. package/dist/text-index.js +28 -9
  176. package/dist/text-index.js.map +1 -1
  177. package/dist/text.d.ts +87 -3
  178. package/dist/text.d.ts.map +1 -1
  179. package/dist/text.js +526 -24
  180. package/dist/text.js.map +1 -1
  181. package/dist/tools.d.ts +61 -1
  182. package/dist/tools.d.ts.map +1 -1
  183. package/dist/tools.js +461 -46
  184. package/dist/tools.js.map +1 -1
  185. package/dist/types.d.ts +103 -4
  186. package/dist/types.d.ts.map +1 -1
  187. package/dist/word-styles.d.ts +102 -0
  188. package/dist/word-styles.d.ts.map +1 -0
  189. package/dist/word-styles.js +419 -0
  190. package/dist/word-styles.js.map +1 -0
  191. package/dist/xlsx.d.ts +23 -0
  192. package/dist/xlsx.d.ts.map +1 -0
  193. package/dist/xlsx.js +511 -0
  194. package/dist/xlsx.js.map +1 -0
  195. package/dist/xml-stream.d.ts +55 -0
  196. package/dist/xml-stream.d.ts.map +1 -0
  197. package/dist/xml-stream.js +235 -0
  198. package/dist/xml-stream.js.map +1 -0
  199. package/dist/zip-directory.d.ts +43 -0
  200. package/dist/zip-directory.d.ts.map +1 -0
  201. package/dist/zip-directory.js +130 -0
  202. package/dist/zip-directory.js.map +1 -0
  203. package/docs/README.md +288 -0
  204. package/docs/api.md +37 -381
  205. package/docs/configuration.md +28 -558
  206. package/docs/getting-started.md +407 -223
  207. package/docs/guides/anthropic.md +590 -0
  208. package/docs/guides/conversations.md +629 -0
  209. package/docs/guides/costs-and-limits.md +728 -0
  210. package/docs/guides/deployment.md +720 -0
  211. package/docs/guides/errors-and-reliability.md +748 -0
  212. package/docs/guides/explorer-model.md +399 -0
  213. package/docs/guides/openai-compatible.md +602 -0
  214. package/docs/guides/own-adapter-and-loop.md +1169 -0
  215. package/docs/guides/pdfs.md +1024 -0
  216. package/docs/guides/storage.md +731 -0
  217. package/docs/guides/testing.md +1203 -0
  218. package/docs/guides/vertex-and-gemini.md +717 -0
  219. package/docs/guides/web-app.md +1590 -0
  220. package/docs/how-it-works.md +1035 -164
  221. package/docs/measurements.md +881 -0
  222. package/docs/publishing.md +274 -46
  223. package/docs/reference/anthropic.md +427 -0
  224. package/docs/reference/ask.md +910 -0
  225. package/docs/reference/errors-and-retries.md +760 -0
  226. package/docs/reference/events.md +1001 -0
  227. package/docs/reference/gemini.md +827 -0
  228. package/docs/reference/library.md +1598 -0
  229. package/docs/reference/node.md +706 -0
  230. package/docs/reference/openai.md +385 -0
  231. package/docs/reference/tools.md +1031 -0
  232. package/docs/security.md +940 -101
  233. package/docs/troubleshooting.md +1410 -0
  234. package/package.json +7 -3
  235. package/src/analyze.ts +204 -49
  236. package/src/anthropic/adapter.ts +200 -40
  237. package/src/ask.ts +1151 -210
  238. package/src/decode.ts +89 -0
  239. package/src/encoding.ts +850 -0
  240. package/src/errors.ts +125 -0
  241. package/src/events.ts +451 -0
  242. package/src/evidence.ts +11 -2
  243. package/src/extract.ts +191 -308
  244. package/src/gemini/adapter.ts +127 -70
  245. package/src/gemini/chat.ts +28 -4
  246. package/src/gemini/endpoints.ts +12 -2
  247. package/src/gemini/errors.ts +34 -1
  248. package/src/gemini/generate.ts +42 -13
  249. package/src/gemini/index.ts +3 -3
  250. package/src/gemini/sse.ts +1 -1
  251. package/src/groups.ts +162 -0
  252. package/src/html.ts +1071 -0
  253. package/src/http.ts +376 -1
  254. package/src/index.ts +29 -6
  255. package/src/library.ts +498 -93
  256. package/src/limiter.ts +6 -1
  257. package/src/map-reduce.ts +252 -51
  258. package/src/model.ts +244 -4
  259. package/src/node/handlers.ts +196 -31
  260. package/src/node/index.ts +4 -0
  261. package/src/node/ingest-child.ts +61 -0
  262. package/src/node/isolated.ts +464 -0
  263. package/src/node/sse.ts +198 -0
  264. package/src/office.ts +1047 -0
  265. package/src/openai/adapter.ts +319 -38
  266. package/src/output-limit.ts +44 -8
  267. package/src/pause.ts +41 -0
  268. package/src/pdf-pages.ts +270 -20
  269. package/src/pdf-pictures.ts +56 -9
  270. package/src/pdf-work.ts +722 -0
  271. package/src/peers.ts +29 -0
  272. package/src/plan.ts +70 -12
  273. package/src/ranged.ts +4 -2
  274. package/src/retry.ts +49 -5
  275. package/src/search.ts +800 -155
  276. package/src/sse.ts +153 -28
  277. package/src/stores.ts +5 -2
  278. package/src/text-index.ts +30 -9
  279. package/src/text.ts +524 -23
  280. package/src/tools.ts +445 -46
  281. package/src/types.ts +108 -5
  282. package/src/word-styles.ts +420 -0
  283. package/src/xlsx.ts +478 -0
  284. package/src/xml-stream.ts +224 -0
  285. package/src/zip-directory.ts +136 -0
package/docs/api.md CHANGED
@@ -1,446 +1,102 @@
1
1
  # API reference
2
2
 
3
- Five entry points:
3
+ The API reference is no longer one page. It is split by module of the package: one page for each
4
+ of the four other entry points, and four for the main entry, `llm-large-files`. This page keeps the headings of the old
5
+ page, so that links to them still work, and each one points to its new home. The guides that
6
+ explain each task are listed in the [documentation index](./README.md).
4
7
 
5
- | Import | Contents |
8
+ | Entry point | Reference |
6
9
  |---|---|
7
- | `llm-large-files` | Core: `createLargeFiles`, `askWithFiles`, stores, types, helpers. Provider-neutral. |
8
- | `llm-large-files/gemini` | `gemini()`, `askGemini`, endpoints, Gemini helpers. |
9
- | `llm-large-files/openai` | `openAiCompatible()` for any Chat Completions endpoint. |
10
- | `llm-large-files/anthropic` | `anthropic()` for Claude. |
11
- | `llm-large-files/node` | `createDocumentHandlers` for Node HTTP servers. |
10
+ | `llm-large-files` | [The library and its documents](./reference/library.md), [the tool loop and the adapter contract](./reference/ask.md), [errors, retries and streams](./reference/errors-and-retries.md), [the tools the model sees](./reference/tools.md) |
11
+ | `llm-large-files/gemini` | [Gemini API and Vertex AI: `gemini()`, `askGemini`, the endpoints](./reference/gemini.md) |
12
+ | `llm-large-files/openai` | [OpenAI-compatible endpoints: `openAiCompatible()`](./reference/openai.md) |
13
+ | `llm-large-files/anthropic` | [Claude: `anthropic()`](./reference/anthropic.md) |
14
+ | `llm-large-files/node` | [Node HTTP handlers: `createDocumentHandlers`](./reference/node.md) |
12
15
 
13
16
  ## `llm-large-files`
14
17
 
18
+ Now four pages: [the library and its documents](./reference/library.md), [the tool loop and the adapter contract](./reference/ask.md), [errors, retries and streams](./reference/errors-and-retries.md), and [the tools the model sees](./reference/tools.md).
19
+
15
20
  ### `createLargeFiles(options): LargeFiles`
16
21
 
17
- | Option | Type | Default |
18
- |---|---|---|
19
- | `store` | `DocumentStore` | required |
20
- | `budget` | `Partial<Budget>` | see [configuration](configuration.md#budget). What is left out follows `contextTokens`; values that cannot work together throw |
21
- | `ttlMs` | `number` | 72 hours. `Infinity` keeps documents until they are deleted (`expiresAt` is then `NEVER_EXPIRES`) |
22
- | `maxUploadBytes` | `number` | 100 MB |
23
- | `extractors` | `Partial<Record<DocumentFormat, Extractor>>` | built-ins |
24
- | `cacheBytes` | `number` | 256 MB: memory that documents kept ready between tool calls may take. Each use checks the store first. 0 keeps none |
25
- | `cacheSize` | `number` | no limit: also caps the number of documents kept. The pieces kept of a document read by range are not counted |
26
- | `wholeDocumentBytes` | `number` | 2 MB: larger documents are read by range when the store can ([details](configuration.md#large-files-many-users-several-servers)). `Infinity` loads all whole |
27
- | `scanChunkBytes` | `number` | 1 MB: text read and searched at a time, reading by range |
28
- | `maxConcurrentScans` | `number` | 4: searches of a document read by range that run at once; the others wait |
29
- | `keepOriginals` | `DocumentFormat[]` | `[]`: only text is kept. `["pdf"]` keeps uploaded PDFs, which `view_pages` needs ([details](configuration.md#keeping-the-uploaded-file)) |
30
- | `scannedPdfPages` | `number` | 30: the longest PDF without any text that is accepted when its original is kept. 0 refuses them all |
22
+ Now [`createLargeFiles`](./reference/library.md#createlargefilesoptions) in the library reference, with every option in [`LargeFilesOptions`](./reference/library.md#largefilesoptions).
31
23
 
32
24
  ### `LargeFiles`
33
25
 
34
- | Member | Description |
35
- |---|---|
36
- | `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. |
37
- | `getMeta(id, { owner }?)` | `DocumentMeta`, or `undefined` if unknown, expired, or owned by someone else. |
38
- | `getOriginal(id, { owner }?)` | The uploaded file as a `Uint8Array`, when it was kept. `undefined` otherwise, and for another owner. |
39
- | `delete(id, { owner }?)` | `true` if deleted. |
40
- | `sweep()` | Removes expired documents; returns the count. |
41
- | `prepare(ids, base, { owner?, viewPages?, budget? }?)` | 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. `budget` changes budget fields for this request. |
42
- | `tools(documents, { generate?, onProgress?, signal?, viewPages?, regexBudgetMs?, maxWholeDocumentReads?, retry?, budget? })` | A `ToolSet` scoped to these documents: make one for each question. `generate` enables `analyze_whole_document`, for documents small enough for it. `viewPages` (`true`, or a list of documents such as `prepared.viewable`) enables `view_pages`. `regexBudgetMs` (default 6,000) is the time the regex searches of the tool set may take together. `maxWholeDocumentReads` (default 1) is how often each document may be read whole. `retry` is how a part read that failed is sent again. |
43
- | `budgetFor(overrides?, limits?)` | The budget for one request: the library's, with `overrides` in place of its fields, made to fit `limits` (`{ contextTokens?, maxRequestBytes? }` of a model). |
44
-
45
- `getMeta`, `getOriginal`, `delete`, `prepare` and the tools read the store. When it cannot be read
46
- (a volume that does not answer, a database that is down) they throw `DocumentStoreError`, and a
47
- tool call answers with its message. That is not "the document is gone": retry. The message names
48
- no path and no host; `error.cause` is what the store threw, for your log.
49
- | `budget`, `maxUploadBytes` | The effective settings. |
26
+ Now [`LargeFiles`](./reference/library.md#largefiles) in the library reference, with the options of its methods and [`DocumentStoreError`](./reference/library.md#documentstoreerror).
50
27
 
51
28
  ### `PreparedContext`
52
29
 
53
- ```ts
54
- {
55
- plan: { inline: DocumentMeta[]; searchable: DocumentMeta[]; inlineTokens: number; inlineBytes: number };
56
- blocks: Map<string, string>; // per document ID: full text (inline) or a summary card (searchable)
57
- instruction: string; // add to the system prompt; empty when there is nothing to search or to look at
58
- missing: string[]; // IDs not found (never uploaded, expired, or another owner's)
59
- viewable: DocumentMeta[]; // PDFs whose pages view_pages can show; empty without viewPages: true
60
- }
61
- ```
30
+ Now [`PreparedContext`](./reference/library.md#preparedcontext) and [`DocumentPlan`](./reference/library.md#documentplan) in the library reference.
62
31
 
63
32
  ### `ToolSet`
64
33
 
65
- ```ts
66
- {
67
- declarations: ToolDeclaration[]; // { name, description, parameters: JSON Schema }
68
- has(name): boolean;
69
- execute(name, args): Promise<ToolResult>; // errors come back as { error } for the model to read
70
- executeWithFiles(name, args, { maxFileBytes?, maxPages?, maxResultCharacters? }?): Promise<{ result: ToolResult; files: ToolFile[] }>;
71
- describe(name, args): string; // "Search app.log (exact) for “timeout”"
72
- resultCharacters(name): number; // the most characters a result of this tool can have
73
- }
74
- ```
75
-
76
- `executeWithFiles` runs any tool. Its `files` (`{ name, mimeType, bytes }`) are empty for all but
77
- `view_pages`. `execute("view_pages", …)` returns an error, because it has no place for the file.
78
- `maxResultCharacters` is the room your request has left for this result, when that is less than
79
- the tool's own cap: the result is cut to it and says where to go on.
80
-
81
- A second `analyze_whole_document` of the same document by one tool set answers with an error that
82
- tells the model to use the first answer (`maxWholeDocumentReads`).
83
-
84
- | Tool | Arguments | Returns |
85
- |---|---|---|
86
- | `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`. |
87
- | `read_document` | `document_id`, `start_line`, `end_line?` | Up to 600 numbered lines, and `next_start_line` if there's more |
88
- | `get_document_overview` | `document_id` | Format, size, outline, log profile, first and last lines |
89
- | `analyze_whole_document` | `document_id`, `task` | `answer` from a map-reduce read, plus part counts |
90
- | `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. |
91
-
92
- For a PDF that `view_pages` can show, the results of `search_document` and `read_document` also
93
- carry page numbers: `page` on each matching line, `pages` on a passage and on a range that was read.
34
+ Now [`ToolSet`](./reference/tools.md#toolset); each tool's arguments, results and limits are in [Tools](./reference/tools.md).
94
35
 
95
36
  ### Stores
96
37
 
97
- - `new MemoryDocumentStore({ now? })`: in-process, for tests and single-instance demos.
98
- - `new FileDocumentStore(directory, { now?, orphanAgeMs? })`: `<id>.txt`, `<id>.json` and the line
99
- index `<id>.idx` per document, and `<id>.bin` for a kept original. Safe for several servers on one
100
- volume: files are written whole, large documents are read by range, and `sweep` leaves files
101
- younger than `orphanAgeMs` (1 hour) that belong to no document yet.
102
- - Implement `DocumentStore` (`put`, `get`, `getMeta`, `delete`, `sweep?`, `putOriginal?` with
103
- `getOriginal?` to keep originals, and `readTextRange?` with `putIndex?` and `getIndex?` to read
104
- large documents by range) for anything else.
38
+ Now [`DocumentStore`](./reference/library.md#documentstore), [`MemoryDocumentStore`](./reference/library.md#memorydocumentstore) and [`FileDocumentStore`](./reference/library.md#filedocumentstore) in the library reference; choosing a store and writing your own are in [Storage](./guides/storage.md).
105
39
 
106
40
  ### Helpers
107
41
 
108
- - `toDocumentSummary(meta)`: the browser-safe fields (`DocumentSummary`).
109
- - `toolResultSummary(label, result)`: `" — 12 matching lines"`, for step lists.
110
- - `isDocumentId(value)`, `DOCUMENT_ID_PATTERN`.
111
- - `estimateTokens(text)`, `utf8Bytes(text)`, `jsonBytes(text)`.
112
- - `detectFormat(name, mimeType)`, `defaultExtractors`, `TOOL_NAMES`, `DEFAULT_BUDGET`,
113
- `MAX_VIEW_PAGES` (5), `MAX_WHOLE_DOCUMENT_READS` (1).
114
- - `resolveBudget(partial?, limits?)`: a whole `Budget` from the fields you give
115
- (see [configuration](configuration.md#budget)).
116
- - `evidenceOf(call, result)`, `stubResult(call, result)`, `mergeRanges(ranges)`: what a tool call
117
- showed, the short stand-in for a result that is dropped, and line ranges made one. For a loop of
118
- your own.
119
- - `withRetry(run, { retry?, signal?, canRetry?, onRetry? })`, `isRetryableStatus(status)`,
120
- `retryAfterMs(headers, body?)`: the retry rule of the loop, for an adapter or a loop of your own.
121
- - `parseSseJson(stream)`: async iterator over the JSON events of a `text/event-stream` body.
122
- - `createPdfExtractor({ tables?: boolean, pictures?: boolean })`: the built-in PDF extractor with
123
- an option changed. `tables: false` gives the text in pdf.js order, without rebuilt tables
124
- (see [PDF tables](configuration.md#pdf-tables)). `pictures: false` leaves out the line that marks
125
- a page with a picture (see [Pictures in PDFs](configuration.md#pictures-in-pdfs)).
42
+ Each helper is now on the page of its module: text sizes, formats, extractors, budgets, document IDs and `toDocumentSummary` in [the library reference](./reference/library.md); `toolResultSummary` and the tool constants in [Tools](./reference/tools.md); `evidenceOf`, `stubResult`, `mergeRanges` and `partialResultOf` in [the tool loop reference](./reference/ask.md); retries, error kinds, `parseSseJson` and the waits of the adapters in [Errors, retries and streams](./reference/errors-and-retries.md).
126
43
 
127
44
  ### Key types
128
45
 
129
- ```ts
130
- type DocumentFormat = "text" | "markdown" | "log" | "json" | "csv" | "pdf" | "docx" | "pptx";
131
-
132
- type DocumentMeta = {
133
- id: string; owner?: string; name: string; mimeType: string; format: DocumentFormat;
134
- bytes: number; textBytes: number; characters: number; lines: number; estimatedTokens: number;
135
- wrappedLines: number; pages?: number;
136
- originalKept?: boolean; // the uploaded file is in the store next to the text
137
- outline: { line: number; level: number; title: string }[];
138
- logProfile?: { levels: Record<string, number>; firstTimestamp?: string; lastTimestamp?: string;
139
- topIssues: { template: string; level: string; count: number; firstLine: number }[] };
140
- createdAt: string; expiresAt: string;
141
- };
142
-
143
- type GenerateText = (request: {
144
- system: string; prompt: string; maxOutputTokens: number; signal?: AbortSignal;
145
- onTruncated?: () => void; // call it when the model stopped at maxOutputTokens
146
- onUsage?: (usage: { inputTokens?: number; cachedInputTokens?: number; outputTokens?: number; thoughtTokens?: number }) => void;
147
- // call it once for every request that was answered
148
- }) => Promise<string>;
149
- type Extractor = (bytes: Uint8Array, input: { name: string; mimeType: string; format: DocumentFormat; scannedPages?: number }) => Promise<{ text: string; pages?: number }>;
150
- // scannedPages: set when a PDF without any text is welcome, with the most pages it may have.
151
-
152
- type ToolFile = { name: string; mimeType: string; bytes: Uint8Array };
153
- ```
46
+ Now [`DocumentMeta`](./reference/library.md#documentmeta), [`DocumentSummary`](./reference/library.md#documentsummary), [`DocumentFormat`](./reference/library.md#documentformat), [`Extractor`](./reference/library.md#extractor) and [`ExtractedText`](./reference/library.md#extractedtext) in the library reference, [`GenerateText`](./reference/ask.md#generatetext) and [`ModelCapabilities`](./reference/ask.md#modelcapabilities) in the tool loop reference, and [`ToolFile`](./reference/tools.md#toolfile) in Tools.
154
47
 
155
48
  ## `askWithFiles(options): Promise<AskResult>`
156
49
 
157
- The tool loop, for any model. It plans the documents, offers the tools, runs the calls within the
158
- limits of the request, and ends with a request that must be answered in text.
159
-
160
- | Option | Description |
161
- |---|---|
162
- | `files`, `model`, `documentIds`, `messages` | Required. `model` is an adapter: `gemini()`, `openAiCompatible()`, `anthropic()`, or [your own](#your-own-adapter). |
163
- | `explorer` | A second adapter, of any provider. It makes the tool calls and reads whole files in parts, and `model` writes the answer from what the tools returned. See [An explorer model](configuration.md#an-explorer-model). |
164
- | `messages` | The conversation; the last must be the user's. Plain turns `{ role: "user" \| "assistant", text }`, the `toolTurns` an earlier question returned, and turns with parts in the provider's own form: `{ role, parts: [{ text }, { native: anImagePart }] }`. |
165
- | `system` | System instruction; the tool guide is appended when needed. |
166
- | `owner` | Only documents with this owner (or no owner) are used. |
167
- | `documentPlacement` | `"first"` (default): document text and cards go at the start of the first user turn and stay there, so follow-up questions reuse the provider's prompt cache. `"last"`: appended to the latest user turn. |
168
- | `limits` | `toolTurns` (12): the most chat requests for one question, counting the answer. `callsPerTurn` (8): the most tool calls of one turn that are run. `wholeDocumentReads` (1): how often each document may be read whole. `inputTokens`, `requests` (none): ceilings for the whole question, part reads included. |
169
- | `retry` | `{ retries = 3, baseDelayMs = 500, maxDelayMs = 60_000 }`. See [Limits and retries](configuration.md#limits-and-retries). |
170
- | `budget` | Budget fields for this question, in place of the library's. |
171
- | `wholeDocumentAnalysis` | Default `true`. Set `false` to withhold the costly whole-file tool. |
172
- | `viewPages` | Default `true`. Offers `view_pages` for PDFs whose original is kept, when every model of the question can be sent a file. |
173
- | `onText`, `onActivity`, `onStep` | Answer text as it arrives, transient status, completed steps. |
174
- | `signal` | Stops the question. |
175
-
176
- Returns:
177
-
178
- ```ts
179
- {
180
- text: string; // everything the answering model wrote
181
- answered: boolean; // false when its last turn had no text, or the prompt was refused
182
- blockReason?: string;
183
- steps: string[]; // "Search app.log (exact) for “timeout” — 12 matching lines"
184
- evidence: Evidence[]; // per tool call: { tool, documentId, document, lines?, pages?, query?, mode?, totalMatchingLines?, whole? }
185
- toolTurns: ToolTurn[]; // the tool rounds as plain JSON, to keep with the conversation
186
- plan: DocumentPlan; // which documents went in whole and which were searched
187
- budget: Budget; // the budget the question ran with
188
- turns: number; // chat requests, an explorer's among them; part reads are not counted
189
- finishReason?: string;
190
- usage: { // every request that was answered, part reads included
191
- requests: number; inputTokens: number; cachedInputTokens: number; outputTokens: number; thoughtTokens: number;
192
- byModel: Record<string, { requests; inputTokens; cachedInputTokens; outputTokens; thoughtTokens }>;
193
- };
194
- lastUsage?: Record<string, unknown>; // the provider's own usage object of the last chat response
195
- }
196
- ```
197
-
198
- `inputTokens` counts every token of the prompts, those read from a cache included, and
199
- `cachedInputTokens` is the part that was. `outputTokens` includes thoughts.
200
-
201
- `answered` is `false` when the model's last turn had no text: the prompt was blocked
202
- (`blockReason` says why), the reply was cut off before any text, or the model produced a malformed
203
- tool call and the request for the answer came back empty too. `text` is then empty or holds only a
204
- remark the model made before a tool call, so show your own message:
205
-
206
- ```ts
207
- const result = await askWithFiles({ ... });
208
- if (!result.answered) show(result.blockReason ? "The request was blocked." : "No answer this time. Try again.");
209
- ```
210
-
211
- It throws `DocumentsNotFoundError` (`.ids`) before calling the model, `DocumentStoreError` when the
212
- store could not be read (retry: the documents are not gone), `ModelRequestError` (`.status`, and
213
- `.retryAfterMs` when the provider named a wait) for an HTTP error that another try did not mend,
214
- and `Error` when the last message isn't the user's. `status` is 0 for a connection that failed.
215
- Each adapter throws its own subclass: `GeminiRequestError`, `OpenAiRequestError`,
216
- `AnthropicRequestError`.
50
+ Now [`askWithFiles`](./reference/ask.md#askwithfilesoptions), [`AskOptions`](./reference/ask.md#askoptions), [`AskLimits`](./reference/ask.md#asklimits) and [`AskResult`](./reference/ask.md#askresult). What it throws ([`DocumentsNotFoundError`](./reference/ask.md#documentsnotfounderror), [`DocumentStoreError`](./reference/library.md#documentstoreerror), and [`ModelRequestError`](./reference/errors-and-retries.md#modelrequesterror) with its [`ModelErrorKind`](./reference/errors-and-retries.md#modelerrorkind)) and [`partialResultOf`](./reference/ask.md#partialresultoferror) are on those pages; what to show a user is in [Errors and reliability](./guides/errors-and-reliability.md).
217
51
 
218
52
  ### Keeping what a question read
219
53
 
220
- `toolTurns` are the tool rounds of the question, with each result as the model had it. Store them
221
- between the question and its answer, and pass them back:
222
-
223
- ```ts
224
- const first = await askWithFiles({ files, model, documentIds, messages: [{ role: "user", text: question }] });
225
- await saveTurn(sessionId, { question, toolTurns: first.toolTurns, answer: first.text });
226
-
227
- // The next question of the conversation:
228
- const messages = [
229
- { role: "user", text: question }, ...first.toolTurns, { role: "assistant", text: first.text },
230
- { role: "user", text: "And how long did recovery take?" },
231
- ];
232
- ```
233
-
234
- The model then sees what it read before, and a follow-up is often answered without a new search.
235
- The rounds are plain JSON and belong to no provider. The pages of a PDF are not in them: a stored
236
- round says that they were shown. They count against the budget like any other part of the
237
- conversation, and late in a long question the oldest are shortened first.
54
+ Now in [Conversations](./guides/conversations.md); the type is [`ToolTurn`](./reference/ask.md#toolturn).
238
55
 
239
56
  ### Your own adapter
240
57
 
241
- ```ts
242
- import type { ModelAdapter } from "llm-large-files";
243
-
244
- const model: ModelAdapter = {
245
- id: "my-model", // names the model in usage totals
246
- capabilities: { toolFiles: "none", pageTokens: 0 }, // and, when you know them: contextTokens, maxRequestBytes, outputTokens, tokenScale, appendOnly
247
- async send(request, hooks) {
248
- // request: { system, messages, tools?, toolChoice? }
249
- // messages: { role: "user" | "assistant", parts: [{ text } | { native }] }
250
- // | { role: "tools", calls, answers: [{ call, result, files? }], raw? }
251
- // Turn them into your provider's request, post it with hooks.signal, and call hooks.onText
252
- // with the text as it arrives.
253
- return { text, calls: [{ id, name, args }], raw: theTurnAsYourProviderSentIt, finishReason, usage: { inputTokens, outputTokens } };
254
- },
255
- generateText: async ({ system, prompt, maxOutputTokens, signal, onUsage, onTruncated }) => "…", // optional: enables whole-file reads
256
- };
257
- ```
258
-
259
- - A `tools` message is one round: the model's calls and the results, in call order. `raw` is the
260
- turn as your `send` returned it, given back only to the adapter that produced it. Without `raw`
261
- (an explorer of another provider made the calls, or the round was stored), build the turn from
262
- `calls`.
263
- - `toolChoice: "none"` means the model must answer in text. The tools are still in `tools`, for a
264
- provider that wants them declared next to earlier calls.
265
- - Throw `ModelRequestError(message, status, { retryAfterMs })` for an HTTP error, with status 0
266
- for a connection that failed. The loop retries the ones worth retrying.
267
- - Give a call whose arguments did not parse a `problem`: the loop answers it with that message and
268
- does not run it.
269
- - `capabilities.toolFiles` says where a file from a tool goes (`"inside"` the result, `"beside"`
270
- it, or `"none"`: `view_pages` is then not offered). `appendOnly: true` tells the loop never to
271
- rewrite an earlier turn of the conversation.
58
+ Now in [Your own adapter and loop](./guides/own-adapter-and-loop.md); the contract is [`ModelAdapter`](./reference/ask.md#modeladapter).
272
59
 
273
60
  ## `llm-large-files/gemini`
274
61
 
275
- ### `gemini(endpoint, options?): ModelAdapter`
62
+ Now [the `llm-large-files/gemini` reference](./reference/gemini.md); setting up the Gemini API or Vertex AI is in [Gemini API and Vertex AI](./guides/vertex-and-gemini.md).
276
63
 
277
- A Gemini model for `askWithFiles`. `endpoint` is `geminiApi()`, `vertexAi()`, or your own
278
- `{ url, streamUrl?, headers }`; its `explorerUrl` is not used here, because an explorer is an
279
- adapter of its own.
64
+ ### `gemini(endpoint, options?): ModelAdapter`
280
65
 
281
- | Option | Description |
282
- |---|---|
283
- | `generationConfig` | Sent with every chat request. |
284
- | `toolFilePlacement` | `"inside"` (default) or `"beside"`: see [Where the pages go](configuration.md#where-the-pages-go-toolfileplacement). |
285
- | `analysisConfig` | `(maxOutputTokens) => generationConfig` for whole-file part reads. |
286
- | `contextTokens`, `maxRequestBytes` | The model's window and the largest request, when the budget of a question should follow them. |
287
- | `pageTokens` | Tokens billed for one PDF page. Default 530. |
288
- | `id`, `fetch` | The name in usage totals (default: the model in the URL), and a custom fetch. |
289
-
290
- ```ts
291
- const model = gemini(geminiApi({ apiKey, model: "gemini-3.8-flash" }), { generationConfig: { temperature: 0.3 } });
292
- const explorer = gemini(geminiApi({ apiKey, model: "gemini-3.5-flash-lite" }));
293
- await askWithFiles({ files, model, explorer, documentIds, messages });
294
- ```
295
-
296
- `fromGeminiContents(contents)` turns Gemini `contents` into `messages`, and
297
- `geminiToolTurns(toolTurns)` gives stored tool rounds as `contents`.
66
+ Now in [the `llm-large-files/gemini` reference](./reference/gemini.md), with its options.
298
67
 
299
68
  ### `askGemini(options): Promise<AskGeminiResult>`
300
69
 
301
- `askWithFiles` with a `gemini()` model for the endpoint, and a second one for its explorer model
302
- when it names one. It takes Gemini `contents` as well as `messages`.
303
-
304
- | Option | Description |
305
- |---|---|
306
- | `files`, `endpoint`, `documentIds` | Required. |
307
- | `messages` | `{ role: "user" \| "model" \| "assistant", text }[]`; the last must be the user's. |
308
- | `contents` | Instead of `messages`: raw Gemini `contents` (images, inline PDFs…). Not mutated. |
309
- | `system` | System instruction; the tool guide is appended when needed. |
310
- | `generationConfig` | Sent with every chat request. |
311
- | `explorerGenerationConfig` | The same, for the requests of an [explorer model](configuration.md#an-explorer-model). Defaults to `generationConfig`. Not used without an explorer. |
312
- | `owner` | Only documents with this owner (or no owner) are used. |
313
- | `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. |
314
- | `limits`, `retry`, `budget` | As in `askWithFiles`. |
315
- | `maxToolTurns` | `limits.toolTurns` under its older name. 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. |
316
- | `maxToolCallsPerTurn` | `limits.callsPerTurn` under its older name. Default 8. The most tool calls of one model turn that are run. The others are answered with an error that tells the model to send them again if it still needs them. |
317
- | `wholeDocumentAnalysis` | Default `true`. Set `false` to withhold the costly whole-file tool. |
318
- | `viewPages` | Default `true`. Offers `view_pages` for PDFs whose original is kept. It changes nothing for a library that keeps no originals. |
319
- | `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). |
320
- | `analysisConfig` | `(maxOutputTokens) => generationConfig` for whole-file part reads. The explorer model reads the parts when there is one, so write it for that model. Without it a part is asked for with `{ maxOutputTokens, temperature: 0.2 }`. A model that thinks counts its thoughts in that limit: a reply that it cut off that way is asked for again with 32,768, and later parts start there. |
321
- | `onText`, `onActivity`, `onStep` | Streaming answer text, transient status, completed steps. |
322
- | `fetch`, `signal` | Custom fetch (proxies, tests) and cancellation. |
323
-
324
- Returns what `askWithFiles` returns. **`usage` is the total of the question since 0.5.0**; Gemini's
325
- own `usageMetadata` of the last response, which `usage` was before, is `lastUsage`.
326
-
327
- It throws what `askWithFiles` throws; the model's errors are `GeminiRequestError` (`.status`, 0
328
- for a connection that failed).
329
-
330
- With an [explorer model](configuration.md#an-explorer-model), `text` and `onText` carry only what
331
- the answering model wrote, `turns` counts the requests of both models, `usage.byModel` has an
332
- entry for each, and `finishReason` and `lastUsage` are those of the answer. An explorer that
333
- fails throws `GeminiRequestError` too.
70
+ Now in [the `llm-large-files/gemini` reference](./reference/gemini.md), with its options and its result.
334
71
 
335
72
  ### Endpoints
336
73
 
337
- - `geminiApi({ apiKey, model, explorerModel?, apiVersion = "v1beta", baseUrl? })`
338
- - `vertexAi({ project, model, explorerModel?, location = "global", accessToken, apiVersion = "v1" })`,
339
- where `accessToken` can be a string or `() => string | Promise<string>`.
340
- - Or any `{ url, streamUrl?, headers, explorerUrl? }` (`headers` can be a function).
341
-
342
- `model` is the model that answers. `explorerModel` names a second one that makes the tool calls and
343
- reads whole files in parts, so that `model` only writes the answer. Left out, empty, or the same as
344
- `model`, one model does both, as before. In an endpoint of your own it is `explorerUrl`: the
345
- `...:generateContent` URL of the explorer, called with the same headers. See
346
- [An explorer model](configuration.md#an-explorer-model).
74
+ `geminiApi`, `vertexAi`, `vertexHost` and the `GeminiEndpoint` type (an endpoint of your own) are now in [the `llm-large-files/gemini` reference](./reference/gemini.md); access tokens and gateways are in [Gemini API and Vertex AI](./guides/vertex-and-gemini.md).
347
75
 
348
76
  ### Lower-level helpers
349
77
 
350
- - `createGeminiGenerateText({ url, headers, fetchImpl?, generationConfig?, timeoutMs? })`: a `GenerateText` for your own loop. `headers` can be a function, called for every request.
351
- - `toGeminiTools(declarations)`: `{ functionDeclarations }`.
352
- - `geminiFunctionResponses([{ call, result, files? }])`: the `user` turn answering function
353
- calls. Files from `executeWithFiles` go inside their function response, as base64.
354
- - `geminiFunctionResponseTurns([{ call, result, files? }], { files?: "inside" | "beside" })`: the
355
- turns to add to `contents`. That is the one turn above, or with `"beside"` the function
356
- responses followed by a `user` turn that holds the files.
357
- - `FINAL_ANSWER_REQUEST`, `FINAL_ANSWER_AFTER_PAGES`: the messages `askGemini` adds when the model
358
- must stop using tools. The second is used when `view_pages` was the only tool.
359
- - `FINAL_ANSWER_WITHOUT_TOOLS`, `EXPLORER_INSTRUCTION`: the two texts `askGemini` adds for an
360
- explorer model. The first asks the answering model for the answer when the explorer called no
361
- tool. The second is the line in the explorer's system instruction that says what its part is.
362
- - `parseSseJson(stream)`: async iterator over a Generate Content SSE stream.
78
+ `createGeminiGenerateText`, `toGeminiTools`, `geminiFunctionResponses` and `geminiFunctionResponseTurns` are now in [the `llm-large-files/gemini` reference](./reference/gemini.md); `FINAL_ANSWER_REQUEST`, `FINAL_ANSWER_AFTER_PAGES`, `FINAL_ANSWER_WITHOUT_TOOLS` and `EXPLORER_INSTRUCTION` in [the tool loop reference](./reference/ask.md); `parseSseJson` in [Errors, retries and streams](./reference/errors-and-retries.md); `llm-large-files/gemini` still exports them all, as [its reference](./reference/gemini.md) lists.
363
79
 
364
80
  ## `llm-large-files/openai`
365
81
 
366
- ### `openAiCompatible(options): ModelAdapter`
82
+ Now [the `llm-large-files/openai` reference](./reference/openai.md); recipes for OpenAI, Azure OpenAI, DeepSeek, OpenRouter, vLLM, Ollama, LiteLLM and llama.cpp are in [OpenAI-compatible endpoints](./guides/openai-compatible.md).
367
83
 
368
- Any Chat Completions endpoint: OpenAI, Azure OpenAI, DeepSeek, LiteLLM, vLLM, Ollama, OpenRouter,
369
- Gemini's OpenAI layer.
84
+ ### `openAiCompatible(options): ModelAdapter`
370
85
 
371
- | Option | Description |
372
- |---|---|
373
- | `model` | Required: the model name the endpoint knows. |
374
- | `baseUrl` | `/chat/completions` is added to it. Default `https://api.openai.com/v1`. |
375
- | `url` | The whole URL, when it is not `baseUrl` + `/chat/completions` (Azure, a gateway). |
376
- | `apiKey`, `headers` | `Authorization: Bearer …`, and more headers. A function is called for each request. |
377
- | `body` | More fields for every chat request: `temperature`, `reasoning_effort`, `max_completion_tokens`. |
378
- | `analysisBody` | `(maxOutputTokens) => fields` for whole-file part reads. |
379
- | `maxTokensField` | The name of the output limit in a part read. Default `max_completion_tokens` for api.openai.com and Azure OpenAI, `max_tokens` elsewhere. |
380
- | `answerWithoutTools` | `"tool_choice"` (default): the request for the answer keeps the tools and sends `tool_choice: "none"`. `"omit"`: it leaves them out, for a server that does not know `tool_choice`. |
381
- | `pdfInput` | Default `false`. Send the pages of `view_pages` as a `file` part in a user message after the tool results. For a model that reads PDF input: many servers behind this API do not (Gemini's layer answers HTTP 400). Not run against OpenAI itself. |
382
- | `stream`, `systemRole` | `false` for a server without streaming; `"developer"` for one that wants the newer role name. |
383
- | `contextTokens`, `maxRequestBytes`, `tokenScale`, `pageTokens` | What the model takes, when the budget should follow it. |
384
- | `id`, `timeoutMs`, `fetch` | The name in usage totals, the time a part read may take (180 s), a custom fetch. |
385
-
386
- The model's own message goes back to it as it came (a server may want its `reasoning_content` or a
387
- signature again). `fromOpenAiMessages(history)` returns `{ system, messages }` for a history kept
388
- as Chat Completions messages, and `openAiToolTurns(toolTurns)` gives stored rounds in that form.
86
+ Now in [the `llm-large-files/openai` reference](./reference/openai.md), with its options.
389
87
 
390
88
  ## `llm-large-files/anthropic`
391
89
 
90
+ Now [the `llm-large-files/anthropic` reference](./reference/anthropic.md); setting up Claude is in [Claude](./guides/anthropic.md).
91
+
392
92
  ### `anthropic(options): ModelAdapter`
393
93
 
394
- Claude through the Messages API. Not run against the API for this release: it is tested against
395
- the request and response shapes of its documentation.
396
-
397
- | Option | Description |
398
- |---|---|
399
- | `model` | Required: `"claude-opus-5-5"`. |
400
- | `apiKey`, `authToken` | `x-api-key`, or `Authorization: Bearer …`. A function is called for each request. |
401
- | `baseUrl`, `url`, `headers`, `version`, `betas` | For a gateway that speaks the same API: `/v1/messages` is added to `baseUrl`. `version` is the `anthropic-version` header (default `2026-10-21`). |
402
- | `maxTokens` | `max_tokens` of a chat request. Default 64,000. It comes out of the context window, so the budget of a question keeps it free. |
403
- | `body` | More fields for every chat request: `thinking`, `output_config`, `context_management`. |
404
- | `analysisBody` | `(maxOutputTokens) => fields` for whole-file part reads, such as `{ output_config: { effort: "low" } }`. |
405
- | `fallbacks` | `"default"`, or a list of `{ model }`: another model answers when a safety classifier declines the request. Off unless set: it adds a beta header that Bedrock, Vertex AI and Foundry do not take. |
406
- | `cache` | Prompt caching. `true` (default) for five minutes, `"1h"`, or `false`. A cache write costs a quarter more than plain input, and a read a tenth. |
407
- | `toolFilePlacement` | `"inside"` (default): pages go into the tool result as a document block. `"beside"`: after the tool results. `"none"`: `view_pages` is not offered. |
408
- | `stream` | Default `true`: chat requests are streamed, which keeps a long reply from timing out. |
409
- | `contextTokens`, `maxRequestBytes`, `pageTokens`, `tokenScale` | Defaults: none, 32 MB, 3,500, and 1.35 (a guess for the current tokenizer, corrected during a question by the count the API reports). |
410
- | `id`, `timeoutMs`, `fetch` | As above. |
411
-
412
- What the adapter takes care of:
413
-
414
- - The model's turn goes back exactly as it came, thinking blocks included, and the conversation is
415
- never rewritten: Claude checks its thinking blocks against the conversation they were written
416
- in. So old tool results are not shortened for Claude. When the room runs out, the next request is
417
- the answer. For long conversations, turn on the API's own clearing of old tool results with
418
- `body: { context_management: … }` and its beta in `betas`.
419
- - The request for the answer keeps the tools and sends `tool_choice: { type: "none" }`.
420
- - A refusal (`stop_reason: "refusal"`) is `blockReason: "refusal: <category>"`.
421
- - No sampling settings are sent: the API of this version refuses `temperature`.
422
-
423
- `fromAnthropicMessages(history)` and `anthropicToolTurns(toolTurns)` convert a history kept as
424
- Messages API messages.
94
+ Now in [the `llm-large-files/anthropic` reference](./reference/anthropic.md), with its options.
425
95
 
426
96
  ## `llm-large-files/node`
427
97
 
428
- ### `createDocumentHandlers(files, { getOwner? })`
429
-
430
- Returns `{ upload(req, res), get(req, res, id), remove(req, res, id) }`.
98
+ Now [the `llm-large-files/node` reference](./reference/node.md); uploads and streamed answers are in [Web app](./guides/web-app.md).
431
99
 
432
- - **upload**: the body is the raw file. Name it with an `X-File-Name` header (URI-encoded) or a
433
- `?name=` query parameter, and optionally set `X-File-Type`. Responds 201 with a `DocumentSummary`,
434
- or 400/413/422/500 with `{ error }`. If a framework already parsed the body into a `Buffer`
435
- (`express.raw()`), that buffer is used.
436
- - **get**: 200 with a `DocumentSummary`, or 404.
437
- - **remove**: `{ deleted: boolean }`.
438
-
439
- Each handler answers its errors itself and never rejects, so it needs no `catch`. 422 is a file
440
- that cannot be read. 500 is the server's trouble, such as a store that fails: the message says
441
- what failed and gives a system error's code (`Upload failed (ENOSPC).`), never a path or a host.
100
+ ### `createDocumentHandlers(files, { getOwner? })`
442
101
 
443
- `getOwner` runs before the upload is read. To refuse a request, throw an error with a `status`
444
- (or `statusCode`) between 400 and 599, as the `http-errors` package makes:
445
- `throw Object.assign(new Error("Sign in first."), { status: 401 })`. The handler answers with that
446
- status and message. Any other error from `getOwner` is a 500 that does not repeat its message.
102
+ Now in [the `llm-large-files/node` reference](./reference/node.md), with its options, routes and statuses.