llm-large-files 0.4.1 → 0.5.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 (121) hide show
  1. package/CHANGELOG.md +127 -0
  2. package/README.md +48 -8
  3. package/dist/anthropic/adapter.d.ts +106 -0
  4. package/dist/anthropic/adapter.d.ts.map +1 -0
  5. package/dist/anthropic/adapter.js +391 -0
  6. package/dist/anthropic/adapter.js.map +1 -0
  7. package/dist/anthropic/index.d.ts +3 -0
  8. package/dist/anthropic/index.d.ts.map +1 -0
  9. package/dist/anthropic/index.js +2 -0
  10. package/dist/anthropic/index.js.map +1 -0
  11. package/dist/ask.d.ts +144 -0
  12. package/dist/ask.d.ts.map +1 -0
  13. package/dist/ask.js +540 -0
  14. package/dist/ask.js.map +1 -0
  15. package/dist/budget.d.ts +23 -0
  16. package/dist/budget.d.ts.map +1 -0
  17. package/dist/budget.js +64 -0
  18. package/dist/budget.js.map +1 -0
  19. package/dist/evidence.d.ts +40 -0
  20. package/dist/evidence.d.ts.map +1 -0
  21. package/dist/evidence.js +137 -0
  22. package/dist/evidence.js.map +1 -0
  23. package/dist/gemini/adapter.d.ts +50 -0
  24. package/dist/gemini/adapter.d.ts.map +1 -0
  25. package/dist/gemini/adapter.js +179 -0
  26. package/dist/gemini/adapter.js.map +1 -0
  27. package/dist/gemini/chat.d.ts +31 -75
  28. package/dist/gemini/chat.d.ts.map +1 -1
  29. package/dist/gemini/chat.js +38 -300
  30. package/dist/gemini/chat.js.map +1 -1
  31. package/dist/gemini/errors.d.ts +11 -0
  32. package/dist/gemini/errors.d.ts.map +1 -0
  33. package/dist/gemini/errors.js +14 -0
  34. package/dist/gemini/errors.js.map +1 -0
  35. package/dist/gemini/generate.d.ts +9 -20
  36. package/dist/gemini/generate.d.ts.map +1 -1
  37. package/dist/gemini/generate.js +43 -92
  38. package/dist/gemini/generate.js.map +1 -1
  39. package/dist/gemini/index.d.ts +3 -1
  40. package/dist/gemini/index.d.ts.map +1 -1
  41. package/dist/gemini/index.js +2 -1
  42. package/dist/gemini/index.js.map +1 -1
  43. package/dist/gemini/sse.d.ts +1 -2
  44. package/dist/gemini/sse.d.ts.map +1 -1
  45. package/dist/gemini/sse.js +1 -38
  46. package/dist/gemini/sse.js.map +1 -1
  47. package/dist/http.d.ts +20 -0
  48. package/dist/http.d.ts.map +1 -0
  49. package/dist/http.js +55 -0
  50. package/dist/http.js.map +1 -0
  51. package/dist/index.d.ts +13 -2
  52. package/dist/index.d.ts.map +1 -1
  53. package/dist/index.js +11 -4
  54. package/dist/index.js.map +1 -1
  55. package/dist/library.d.ts +29 -3
  56. package/dist/library.d.ts.map +1 -1
  57. package/dist/library.js +10 -12
  58. package/dist/library.js.map +1 -1
  59. package/dist/map-reduce.d.ts +9 -0
  60. package/dist/map-reduce.d.ts.map +1 -1
  61. package/dist/map-reduce.js +25 -19
  62. package/dist/map-reduce.js.map +1 -1
  63. package/dist/model.d.ts +196 -0
  64. package/dist/model.d.ts.map +1 -0
  65. package/dist/model.js +41 -0
  66. package/dist/model.js.map +1 -0
  67. package/dist/openai/adapter.d.ts +85 -0
  68. package/dist/openai/adapter.d.ts.map +1 -0
  69. package/dist/openai/adapter.js +293 -0
  70. package/dist/openai/adapter.js.map +1 -0
  71. package/dist/openai/index.d.ts +3 -0
  72. package/dist/openai/index.d.ts.map +1 -0
  73. package/dist/openai/index.js +2 -0
  74. package/dist/openai/index.js.map +1 -0
  75. package/dist/output-limit.d.ts +30 -0
  76. package/dist/output-limit.d.ts.map +1 -0
  77. package/dist/output-limit.js +92 -0
  78. package/dist/output-limit.js.map +1 -0
  79. package/dist/retry.d.ts +54 -0
  80. package/dist/retry.d.ts.map +1 -0
  81. package/dist/retry.js +111 -0
  82. package/dist/retry.js.map +1 -0
  83. package/dist/sse.d.ts +3 -0
  84. package/dist/sse.d.ts.map +1 -0
  85. package/dist/sse.js +39 -0
  86. package/dist/sse.js.map +1 -0
  87. package/dist/tools.d.ts +11 -0
  88. package/dist/tools.d.ts.map +1 -1
  89. package/dist/tools.js +85 -31
  90. package/dist/tools.js.map +1 -1
  91. package/dist/types.d.ts +28 -3
  92. package/dist/types.d.ts.map +1 -1
  93. package/docs/api.md +245 -27
  94. package/docs/configuration.md +83 -9
  95. package/docs/getting-started.md +67 -16
  96. package/docs/how-it-works.md +38 -2
  97. package/docs/security.md +18 -0
  98. package/package.json +21 -3
  99. package/src/anthropic/adapter.ts +454 -0
  100. package/src/anthropic/index.ts +2 -0
  101. package/src/ask.ts +675 -0
  102. package/src/budget.ts +71 -0
  103. package/src/evidence.ts +162 -0
  104. package/src/gemini/adapter.ts +218 -0
  105. package/src/gemini/chat.ts +61 -353
  106. package/src/gemini/errors.ts +15 -0
  107. package/src/gemini/generate.ts +50 -90
  108. package/src/gemini/index.ts +3 -1
  109. package/src/gemini/sse.ts +1 -34
  110. package/src/http.ts +59 -0
  111. package/src/index.ts +33 -4
  112. package/src/library.ts +39 -13
  113. package/src/map-reduce.ts +22 -16
  114. package/src/model.ts +200 -0
  115. package/src/openai/adapter.ts +345 -0
  116. package/src/openai/index.ts +2 -0
  117. package/src/output-limit.ts +99 -0
  118. package/src/retry.ts +132 -0
  119. package/src/sse.ts +34 -0
  120. package/src/tools.ts +91 -34
  121. package/src/types.ts +24 -3
package/CHANGELOG.md CHANGED
@@ -4,6 +4,133 @@ All notable changes to this package are recorded here. The format follows
4
4
  [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and versions follow
5
5
  [semantic versioning](https://semver.org).
6
6
 
7
+ ## [0.5.0] - 2026-11-13
8
+
9
+ One tool loop for every model. What `askGemini` did (plan the documents, offer the tools, run the
10
+ calls, end with an answer) is now `askWithFiles` in the core, and a model provider is an adapter.
11
+ Three come with the package: Gemini and Vertex AI, any OpenAI-compatible endpoint, and Claude. The
12
+ loop also learned to send a failed request again, to count what a question costs, and to keep a
13
+ growing request inside the model's window.
14
+
15
+ `askGemini` is still there and takes the options it took. Read **Changed** before you upgrade:
16
+ six of its points can need a change in your code.
17
+
18
+ ### Added
19
+
20
+ - **`askWithFiles({ files, model, explorer?, documentIds, messages, … })`** in `llm-large-files`.
21
+ `model` and `explorer` are adapters, and need not be of the same provider: a cheap model behind
22
+ an OpenAI-compatible endpoint can explore while Gemini or Claude writes the answer.
23
+ - **Adapters.** `gemini(endpoint, options)` in `llm-large-files/gemini`,
24
+ `openAiCompatible({ baseUrl, apiKey, model })` in `llm-large-files/openai` (OpenAI, Azure OpenAI,
25
+ DeepSeek, LiteLLM, vLLM, Ollama, OpenRouter, Gemini's OpenAI layer), and
26
+ `anthropic({ apiKey, model })` in `llm-large-files/anthropic`. None needs an SDK. An adapter of
27
+ your own is an object with `id`, `capabilities`, `send` and, for whole-file reads,
28
+ `generateText`: see `ModelAdapter` in the API reference.
29
+ - **A request that failed is sent again.** HTTP 408, 409, 429, any 5xx, and a connection that
30
+ failed are retried up to three times, after a wait that doubles (at most 0.5, 1 and 2 seconds,
31
+ with jitter), or after the wait the provider asks for (`Retry-After`, `retry-after-ms`, and the
32
+ `retryDelay` of Gemini's `RetryInfo`). A request the model refused (400, 401, 403, 404) is not retried, and nothing is
33
+ retried once text of the reply was shown, or after the caller stopped the question. A wait the
34
+ provider asks for that is longer than `retry.maxDelayMs` (one minute) is not waited for. The
35
+ part reads of a whole-file read follow the same rule: a 429 was retried 0.2 ms later before.
36
+ Set it with `retry: { retries, baseDelayMs, maxDelayMs }`.
37
+ - **`usage` is the whole question.** `{ requests, inputTokens, cachedInputTokens, outputTokens,
38
+ thoughtTokens, byModel }`, summed over every request that was answered, the part reads of a
39
+ whole-file read included. In a live run of 0.4.0, 13,687 prompt tokens were billed and 6,398
40
+ reported.
41
+ - **Ceilings for one question**, in `limits`: `wholeDocumentReads` (1 for each document: the
42
+ model asked for the same file to be read whole six times in one probe), `inputTokens` and
43
+ `requests` (no more tools once they are reached, and a whole-file read that would pass them is
44
+ refused with the numbers), next to `toolTurns` and `callsPerTurn`.
45
+ - **The request is kept inside the window.** The loop counts the request as it grows. Before it
46
+ runs the calls of a turn it gives each one the room that is left: a result is cut to it and says
47
+ where to go on, and a call that finds no room is answered "no room left, answer now", after
48
+ which the next request is the answer. When the room runs short, the results of all but the last
49
+ three tool rounds are replaced by short stand-ins that keep the document and the lines or pages
50
+ they showed. A turn of sixty reads built a request of 491,000 tokens against a window of 128,000
51
+ before; the same run now peaks at about 100,000.
52
+ - **The tool calls of one turn run together**, four at a time, and are answered in the order they
53
+ were made. Looks at pages still run one after another, because each is given the room the one
54
+ before it left, and so do regex searches, which share their time. Six whole-file reads, two in
55
+ each of three turns, took 841 ms one after another against a fake model, and take about 540 ms.
56
+ - **Headers are asked for with every request**, the part reads included, so a token that
57
+ `vertexAi({ accessToken })` renews is used. They were asked for once a question.
58
+ - **The budget follows the model.** `reservedTokens`, `inlineTokens`, `mapChunkTokens` and
59
+ `toolResultCharacters` are worked out from `contextTokens` when they are left out
60
+ (`resolveBudget`): setting only `contextTokens: 64_000` made a nine-token note a card with tools
61
+ before. An adapter can say what its model takes (`contextTokens`, `maxRequestBytes`,
62
+ `outputTokens`, `pageTokens`, and `tokenScale` for a tokenizer that counts more than the
63
+ library's estimate), and the budget of a question is made to fit it. `budget` in `askWithFiles`,
64
+ `prepare` and `tools` changes fields for one question, and `files.budgetFor()` shows the result.
65
+ - **`evidence`** in the result: for each tool call, the document and the lines or pages the model
66
+ was shown.
67
+ - **`toolTurns`** in the result: the tool rounds of the question as plain JSON. Kept with the
68
+ conversation and passed back in `messages` between the question and its answer, they let a
69
+ follow-up question be answered from what was already read. In a live check the follow-up took
70
+ one request and no search. `geminiToolTurns`, `openAiToolTurns` and `anthropicToolTurns` give
71
+ them in a provider's own form, and `fromGeminiContents`, `fromOpenAiMessages` and
72
+ `fromAnthropicMessages` turn a history kept in that form into `messages`.
73
+ - **A tool call that did not arrive whole is not run.** Arguments that are not JSON, or a call cut
74
+ off at the output limit, are answered with what was wrong, and the model can send the call again.
75
+ - **The output limit of a part read is raised for any model that thinks**, not only Gemini: the
76
+ rule of 0.4.1 is shared by the three adapters.
77
+ - For Claude: the model's turn goes back exactly as it came, thinking blocks included; the tools
78
+ stay listed in the request that must be answered in text (`tool_choice: none`); the conversation
79
+ is never rewritten, so old results are not shortened for it; pages go into the tool result as a
80
+ document block; prompt caching is on; a refusal is reported as `blockReason`; and `fallbacks`
81
+ turns on the API's own fallback to another model.
82
+
83
+ ### Changed
84
+
85
+ What can need a change in your code:
86
+
87
+ - **`result.usage` is no longer Gemini's `usageMetadata` of the last response.** That object is
88
+ now `result.lastUsage`. If you forward `usage` to a browser or a log, read `lastUsage` for the
89
+ old shape, or use the totals.
90
+ - **A failure can take longer to reach you**, because the request is tried again first: up to
91
+ three and a half seconds of waiting by default for a model that stays down, and up to a minute
92
+ when the provider names a wait. `retry: { retries: 0 }` gives the old behaviour.
93
+ - **A connection that failed throws `GeminiRequestError` with `status` 0**, not the `TypeError` of
94
+ `fetch`. The original error is its `cause`.
95
+ - **A second whole-file read of the same document in one question is refused.** Set
96
+ `limits.wholeDocumentReads` (or `maxWholeDocumentReads` in `files.tools()`) to allow more. Make
97
+ one tool set for each question: the count is the tool set's.
98
+ - **Budget values that cannot work together throw at `createLargeFiles`**: `reservedTokens` or
99
+ `mapChunkTokens` at or above `contextTokens`. And with `contextTokens` below 400,000, fields you
100
+ left out are now smaller than the fixed defaults they had.
101
+ - **`onActivity` and `onStep` can interleave differently.** Calls of one turn start together, so
102
+ the "Searching…" lines of several calls can come before the first finished step. Steps still
103
+ arrive in call order.
104
+
105
+ What needs none, unless you built on it:
106
+
107
+ - Old tool results can be replaced by stand-ins (`{ dropped: true, lines, note }`) late in a long
108
+ question. `steps` then holds "Older tool results were shortened to make room in the request".
109
+ - `ToolSet` has a new member, `resultCharacters(name)`, and `LargeFiles` has `budgetFor()`: a mock
110
+ of either needs them to type-check.
111
+ - `createGeminiGenerateText` throws `GeminiRequestError` (it threw an `Error` with a `status`),
112
+ and takes `headers` as a function too.
113
+ - `GeminiFunctionCall` and `GeminiToolAnswer` are now the core's `ToolCall` and `ToolAnswer`, and
114
+ `ToolFileLimits` is `ToolCallLimits` (the old name is kept).
115
+ - `maxToolTurns` and `maxToolCallsPerTurn` of `askGemini` still work. Their new home is
116
+ `limits.toolTurns` and `limits.callsPerTurn`.
117
+ - Tool results are those of 0.4.1, compared call by call with 0.3.6 over 40 documents, except
118
+ that a repeated whole-file read is refused.
119
+
120
+ ### Checked
121
+
122
+ - 331 tests, 65 of them new. The requests `askGemini` sends are the ones 0.4.1 sent: its 44 tests
123
+ pass unchanged but for one that now turns the retry off.
124
+ - Live, on the Gemini API: `askWithFiles` with `gemini()` and with `openAiCompatible()` on Gemini's
125
+ OpenAI layer (streamed, a 5.2 MB log), an explorer behind the OpenAI layer with a thinking Gemini
126
+ model answering, `askGemini` on a thinking model alone and with an explorer, a follow-up
127
+ question from stored tool rounds, and a part read through the OpenAI adapter. In each, the usage
128
+ the library returned was what the provider reported, request by request.
129
+ - **Not run against a real server:** the Claude adapter (there was no key: it is tested against
130
+ the request and response shapes of the Messages API documentation), and `pdfInput` of the OpenAI
131
+ adapter, which sends the pages of a PDF as a `file` part. Gemini's OpenAI layer refuses that part
132
+ (HTTP 400), so it is off by default and follows OpenAI's documented shape untested.
133
+
7
134
  ## [0.4.1] - 2026-11-13
8
135
 
9
136
  Fixes from a review of 0.4.0. Nothing to change in your code. Tool results are those of 0.4.0
package/README.md CHANGED
@@ -12,8 +12,9 @@ and 1M tokens of context. This package bridges the gap:
12
12
  - **Pictures in a PDF** are not in its text. The model can **look at the real pages** when it
13
13
  needs to: a chart, a photo, a scan.
14
14
 
15
- It's a small library, not a framework: no model SDK, no server, and no UI are required. A drop-in
16
- Gemini / Vertex AI helper and Node HTTP handlers are included for the common case.
15
+ It's a small library, not a framework: no model SDK, no server, and no UI are required. One tool
16
+ loop, `askWithFiles`, works with any model through an adapter. Adapters for **Gemini and Vertex
17
+ AI**, **any OpenAI-compatible endpoint** and **Claude** are included, and so are Node HTTP handlers.
17
18
 
18
19
  ```bash
19
20
  npm install llm-large-files
@@ -53,6 +54,43 @@ const endpoint = vertexAi({ project: "my-project", model: "gemini-3.8-flash", ac
53
54
  const endpoint = { url: "https://llm-gw.corp/v1/gemini:generateContent", headers: { Authorization: `Bearer ${key}` } };
54
55
  ```
55
56
 
57
+ ## Any model
58
+
59
+ `askGemini` is `askWithFiles` with a Gemini model. With another provider, name the model yourself:
60
+
61
+ ```ts
62
+ import { askWithFiles } from "llm-large-files";
63
+ import { openAiCompatible } from "llm-large-files/openai";
64
+ import { anthropic } from "llm-large-files/anthropic";
65
+
66
+ // OpenAI, Azure OpenAI, DeepSeek, LiteLLM, vLLM, Ollama, OpenRouter: anything that speaks Chat Completions.
67
+ const deepseek = openAiCompatible({ baseUrl: "https://api.deepseek.com/v1", apiKey: process.env.DEEPSEEK_API_KEY!, model: "deepseek-v4-pro" });
68
+ // Claude. `fallbacks` lets another model answer when a safety classifier declines the request.
69
+ const claude = anthropic({ apiKey: process.env.ANTHROPIC_API_KEY!, model: "claude-opus-5-5", fallbacks: "default" });
70
+
71
+ const result = await askWithFiles({
72
+ files,
73
+ model: claude, // writes the answer
74
+ explorer: deepseek, // optional: a second model, of any provider, that searches and reads
75
+ documentIds: [doc.id],
76
+ messages: [{ role: "user", text: "What caused the outage, and when? Cite lines." }],
77
+ onText: (delta) => process.stdout.write(delta),
78
+ });
79
+ ```
80
+
81
+ Every model gets the same loop: a request that failed is sent again, the request is kept inside
82
+ the model's window, and one question cannot read a file whole twice. The result says what it cost
83
+ and what it read:
84
+
85
+ ```ts
86
+ result.usage; // { requests: 5, inputTokens: 32662, cachedInputTokens: 6086, outputTokens: 750, byModel: { … } }
87
+ result.evidence; // [{ tool: "read_document", documentId, document: "prod.log", lines: [[34100, 34110]] }, …]
88
+ result.toolTurns; // keep these with the conversation: a follow-up question then needs no new search
89
+ ```
90
+
91
+ A model that has no adapter needs one object with a `send` method:
92
+ [your own adapter](docs/api.md#your-own-adapter).
93
+
56
94
  ## Add it to a web app
57
95
 
58
96
  ```ts
@@ -126,7 +164,9 @@ What each model gets, and what it costs: [An explorer model](docs/configuration.
126
164
  | **Formats** | Text, Markdown, logs (UTF-8 and UTF-16), JSON/JSONL, CSV/TSV, DOCX, PPTX, PDF (text layer, with tables rebuilt so empty cells stay empty; pages with a picture are marked, and the model can look at the pages themselves; scans of up to 30 pages) |
127
165
  | **Logs** | Detected automatically; the card shows level counts, the time range, and the most frequent errors grouped by shape (`timeout after <n>ms to <ip>`) |
128
166
  | **Books and documents** | An outline of headings with line numbers, including Markdown, "Chapter 12", numbered sections, and Hebrew chapter titles |
129
- | **Limits** | One budget covers tokens *and* request bytes, so files fit both your context window and your connector's payload limit |
167
+ | **Limits** | One budget covers tokens *and* request bytes, so files fit both your context window and your connector's payload limit. It follows the model: set `contextTokens`, or let the adapter say it |
168
+ | **Models** | Gemini and Vertex AI, any OpenAI-compatible endpoint, Claude, or an adapter of your own. Two models of different providers can share a question |
169
+ | **Cost** | Usage summed over every request of a question, for each model, with ceilings on whole-file reads, requests and tokens |
130
170
  | **Privacy** | Documents can belong to an `owner`; other users can't plan, read, or delete them |
131
171
  | **Storage** | In memory, on disk with expiry, or your own store (Redis, S3, a database) |
132
172
 
@@ -143,11 +183,11 @@ With `gemini-3.8-flash` on the Gemini API:
143
183
 
144
184
  ## Documentation
145
185
 
146
- - [Integration guide](docs/getting-started.md): Express, plain Node, browser upload, streaming, Vertex AI, gateways, existing chat history
147
- - [API reference](docs/api.md)
148
- - [Configuration](docs/configuration.md): budget, an explorer model, stores, formats, extractors, pictures in PDFs
149
- - [How it works](docs/how-it-works.md): planner, cards, tools, map-reduce, looking at pages, and the Gemini quirks it handles
150
- - [Security](docs/security.md): owners, tool scoping, retention, original files, regex safety
186
+ - [Integration guide](docs/getting-started.md): Express, plain Node, browser upload, streaming, Vertex AI, gateways, other models, existing chat history
187
+ - [API reference](docs/api.md): `askWithFiles`, the three adapters, and what an adapter of your own must do
188
+ - [Configuration](docs/configuration.md): budget, limits and retries, an explorer model, stores, formats, extractors, pictures in PDFs
189
+ - [How it works](docs/how-it-works.md): planner, cards, tools, map-reduce, looking at pages, the loop, and the provider quirks it handles
190
+ - [Security](docs/security.md): owners, tool scoping, retention, original files, regex safety, what a question can cost
151
191
 
152
192
  ## Requirements
153
193
 
@@ -0,0 +1,106 @@
1
+ import { type HeaderSource, type SecretSource } from "../http.js";
2
+ import { ModelRequestError, type ChatMessage, type ModelAdapter, type ToolTurn } from "../model.js";
3
+ /** The API answered with an HTTP error, or could not be reached (`status` 0). `type` is the API's own word: "rate_limit_error". */
4
+ export declare class AnthropicRequestError extends ModelRequestError {
5
+ readonly type?: string;
6
+ constructor(message: string, status: number, options?: {
7
+ retryAfterMs?: number;
8
+ cause?: unknown;
9
+ type?: string;
10
+ });
11
+ }
12
+ /** A message of the Messages API, as it takes and returns it. */
13
+ export type AnthropicMessage = {
14
+ role: "user" | "assistant";
15
+ content: string | Array<Record<string, unknown>>;
16
+ };
17
+ /** The API version the requests are written for. */
18
+ export declare const ANTHROPIC_VERSION = "2026-10-21";
19
+ export type AnthropicOptions = {
20
+ /** The model ID: "claude-opus-5-5". */
21
+ model: string;
22
+ /** Sent as `x-api-key`. A function is called for each request. */
23
+ apiKey?: SecretSource | undefined;
24
+ /** Sent as `Authorization: Bearer …`, for an OAuth token or a gateway. A function is called for each request. */
25
+ authToken?: SecretSource | undefined;
26
+ /** The base of the API: `/v1/messages` is added to it. Defaults to https://api.anthropic.com. */
27
+ baseUrl?: string | undefined;
28
+ /** The whole Messages URL, when it is not `baseUrl` + `/v1/messages`. */
29
+ url?: string | undefined;
30
+ /** More headers. A function is called for each request. */
31
+ headers?: HeaderSource | undefined;
32
+ /** The `anthropic-version` header. Defaults to `ANTHROPIC_VERSION`. */
33
+ version?: string | undefined;
34
+ /** Values for the `anthropic-beta` header. */
35
+ betas?: string[] | undefined;
36
+ /**
37
+ * `max_tokens` of a chat request: the most the model may write, thoughts included. Defaults to
38
+ * 64,000. It comes out of the context window, so the budget of a question keeps it free.
39
+ */
40
+ maxTokens?: number | undefined;
41
+ /** More fields for the body of every chat request: `thinking`, `output_config`, `context_management`, `metadata`, and so on. */
42
+ body?: Record<string, unknown> | undefined;
43
+ /** More fields for the body of a whole-document part read, given the `max_tokens` it is sent with. */
44
+ analysisBody?: ((maxOutputTokens: number) => Record<string, unknown>) | undefined;
45
+ /**
46
+ * Have another model answer when this one's safety classifiers decline a request: "default", or
47
+ * a list of `{ model }`. It adds the `fallbacks` field and its beta header. Off unless set: it
48
+ * is offered on the Claude API, not on Amazon Bedrock, Vertex AI or Microsoft Foundry, and not
49
+ * for every model.
50
+ */
51
+ fallbacks?: "default" | Array<Record<string, unknown> & {
52
+ model: string;
53
+ }> | undefined;
54
+ /**
55
+ * Prompt caching: a top-level `cache_control`, which caches the request up to its last block, so
56
+ * each request of a tool loop, and a follow-up question, reads what the one before wrote.
57
+ * `true` (the default) keeps it five minutes, "1h" an hour, `false` sends none.
58
+ */
59
+ cache?: boolean | "5m" | "1h" | undefined;
60
+ /**
61
+ * Where the pages of `view_pages` go: "inside" the tool result as a document block (the
62
+ * default), "beside" it as a document block after the tool results, or "none" to not offer
63
+ * `view_pages`.
64
+ */
65
+ toolFilePlacement?: "inside" | "beside" | "none" | undefined;
66
+ /** Chat requests are streamed, which keeps a long reply from timing out. False for a gateway without streaming. */
67
+ stream?: boolean | undefined;
68
+ /**
69
+ * Set `eager_input_streaming` on the tools of a streamed request, so tool input arrives as it
70
+ * is written. Defaults to true for api.anthropic.com and false for any other URL, which may
71
+ * refuse the field.
72
+ */
73
+ eagerInputStreaming?: boolean | undefined;
74
+ /** The model's context window in tokens, when the budget of a question should follow it. */
75
+ contextTokens?: number | undefined;
76
+ /** The largest request body in bytes. Defaults to 32 MB, the limit of the Claude API. */
77
+ maxRequestBytes?: number | undefined;
78
+ /** Tokens billed for one PDF page: its text and its picture. Defaults to 3,500. */
79
+ pageTokens?: number | undefined;
80
+ /**
81
+ * This model's tokens for one token of the library's estimate, which is fitted to Gemini.
82
+ * Defaults to 1.35, a cautious guess for the tokenizer of the current models: the count the API
83
+ * reports with each reply corrects it during a question.
84
+ */
85
+ tokenScale?: number | undefined;
86
+ /** Milliseconds a part read may take. Defaults to 180,000. */
87
+ timeoutMs?: number | undefined;
88
+ /** Names the model in usage totals. Defaults to `model`. */
89
+ id?: string | undefined;
90
+ fetch?: typeof fetch | undefined;
91
+ };
92
+ /**
93
+ * Messages of the Messages API as the conversation of `askWithFiles`: text blocks as text, a turn
94
+ * of `tool_use` blocks and the `tool_result` blocks that answer it as one stored tool round, and
95
+ * every other block (an image, a document) as it is. Thinking blocks are left out: they belong to
96
+ * the conversation they were written in.
97
+ */
98
+ export declare function fromAnthropicMessages(history: AnthropicMessage[]): ChatMessage[];
99
+ /**
100
+ * The tool rounds a question returned (`AskResult.toolTurns`) as messages of the Messages API, for
101
+ * an application that keeps its history in that form: put them between the question and its answer.
102
+ */
103
+ export declare function anthropicToolTurns(turns: ToolTurn[]): AnthropicMessage[];
104
+ /** A Claude model for `askWithFiles`. */
105
+ export declare function anthropic(options: AnthropicOptions): ModelAdapter;
106
+ //# sourceMappingURL=adapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../src/anthropic/adapter.ts"],"names":[],"mappings":"AAEA,OAAO,EAAiE,KAAK,YAAY,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AACjI,OAAO,EAAE,iBAAiB,EAAE,KAAK,WAAW,EAAE,KAAK,YAAY,EAA6G,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAC;AAM/M,mIAAmI;AACnI,qBAAa,qBAAsB,SAAQ,iBAAiB;IAC1D,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;gBACX,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE;QAAE,YAAY,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,CAAC;QAAC,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