llm-large-files 0.10.0 → 0.10.2

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 (62) hide show
  1. package/CHANGELOG.md +136 -7
  2. package/dist/ask.d.ts +16 -0
  3. package/dist/ask.d.ts.map +1 -1
  4. package/dist/ask.js +26 -2
  5. package/dist/ask.js.map +1 -1
  6. package/dist/cache.d.ts +27 -1
  7. package/dist/cache.d.ts.map +1 -1
  8. package/dist/cache.js +96 -21
  9. package/dist/cache.js.map +1 -1
  10. package/dist/citations.d.ts.map +1 -1
  11. package/dist/citations.js +14 -7
  12. package/dist/citations.js.map +1 -1
  13. package/dist/events.d.ts +2 -1
  14. package/dist/events.d.ts.map +1 -1
  15. package/dist/events.js.map +1 -1
  16. package/dist/index.d.ts +3 -3
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +2 -2
  19. package/dist/index.js.map +1 -1
  20. package/dist/ingest.d.ts +12 -1
  21. package/dist/ingest.d.ts.map +1 -1
  22. package/dist/ingest.js +146 -11
  23. package/dist/ingest.js.map +1 -1
  24. package/dist/library.d.ts +55 -5
  25. package/dist/library.d.ts.map +1 -1
  26. package/dist/library.js +74 -4
  27. package/dist/library.js.map +1 -1
  28. package/dist/stores.d.ts +38 -1
  29. package/dist/stores.d.ts.map +1 -1
  30. package/dist/stores.js +184 -6
  31. package/dist/stores.js.map +1 -1
  32. package/dist/testing/store-checks.d.ts +8 -3
  33. package/dist/testing/store-checks.d.ts.map +1 -1
  34. package/dist/testing/store-checks.js +74 -1
  35. package/dist/testing/store-checks.js.map +1 -1
  36. package/dist/types.d.ts +56 -0
  37. package/dist/types.d.ts.map +1 -1
  38. package/docs/guides/costs-and-limits.md +3 -2
  39. package/docs/guides/deployment.md +3 -3
  40. package/docs/guides/errors-and-reliability.md +2 -1
  41. package/docs/guides/storage.md +62 -8
  42. package/docs/guides/vertex-and-gemini.md +1 -1
  43. package/docs/measurements.md +4 -4
  44. package/docs/reference/ask.md +30 -6
  45. package/docs/reference/events.md +1 -1
  46. package/docs/reference/gemini.md +9 -4
  47. package/docs/reference/library.md +106 -11
  48. package/docs/reference/testing.md +10 -4
  49. package/docs/reference/tools.md +4 -2
  50. package/docs/security.md +2 -1
  51. package/docs/upgrading-0.10.md +27 -15
  52. package/package.json +1 -1
  53. package/src/ask.ts +35 -2
  54. package/src/cache.ts +95 -19
  55. package/src/citations.ts +14 -7
  56. package/src/events.ts +2 -1
  57. package/src/index.ts +3 -3
  58. package/src/ingest.ts +144 -12
  59. package/src/library.ts +122 -8
  60. package/src/stores.ts +174 -7
  61. package/src/testing/store-checks.ts +74 -3
  62. package/src/types.ts +55 -0
package/CHANGELOG.md CHANGED
@@ -36,6 +36,126 @@ Grouped by area. One or two lines each, written for an app developer, with the n
36
36
  matter.
37
37
  -->
38
38
 
39
+ ## 0.10.2 — 2026-11-25
40
+
41
+ Storage for a chatbot that keeps its files in the library: the files of a chat in one call, an
42
+ expiry counted from the last use, the application's own data on a document, and one document for a
43
+ file uploaded twice. Stored tool rounds can be kept small. A large document over a store without
44
+ `readTextRange` is no longer loaded again for every tool call. The text sent to the model is the
45
+ same as 0.10.1's.
46
+
47
+ ### Upgrading: what you need to change
48
+
49
+ Nothing. Code written for 0.10.1 compiles as it is: the new store methods, library members and
50
+ options are optional, and the requests are byte for byte those of 0.10.1. (A store or a
51
+ `LargeFiles` of your own that already has a member named `list`, `patchMeta`, `touch` or `update`
52
+ with another signature no longer matches the interface: rename it.)
53
+
54
+ - A subclass of `MemoryDocumentStore` or `FileDocumentStore` with its own `put`, `get`, `getMeta` or
55
+ `delete` is used as if it had no `list` and no `patchMeta` until it has its own: the built-in ones
56
+ would go past its own reads and writes. Its conformance checks pass as before.
57
+
58
+ - A store of your own that keeps a fixed list of metadata fields drops `appData`, the new field of
59
+ `DocumentMeta`: keep `meta` whole, as the storage guide says
60
+ ([The methods](docs/guides/storage.md#the-methods)).
61
+ - `documentStoreChecks` checks `list` and `patchMeta` only for a store that has them: your store's
62
+ tests pass as before.
63
+
64
+ ### New: what you can add
65
+
66
+ - **`files.list(access)`**: the documents of exactly the caller's owner and scope, the oldest first,
67
+ for a chat's file panel without a second list in your database. A document without an owner is
68
+ listed only to a caller without one. It needs the store's new optional
69
+ `list(context)`, which `MemoryDocumentStore` and `FileDocumentStore` have
70
+ ([`files.list`](docs/reference/library.md#fileslistaccess)).
71
+ - **`files.touch(id, access)`**: the document's expiry is counted again from now (H5), so `ttlMs`
72
+ becomes the time a file is kept after its last use. Only the expiry is changed, through the
73
+ store's new optional `patchMeta(id, { createdAt, owner?, scope?, expiresAt?, appData? }, context)`:
74
+ field by field, and only in the document of that `createdAt`, owner and scope, so a document
75
+ stored again under the same ID meanwhile is never changed, and a `touch` and an `update` at once
76
+ both stay. `FileDocumentStore` makes them take turns with its `put` and `delete` of the document;
77
+ across servers sharing a folder, see [Storage](docs/guides/storage.md#filedocumentstore)
78
+ ([Expiry from the last use](docs/guides/storage.md#expiry-from-the-last-use)).
79
+ - **`appData`**: the application's own data about a document (`DocumentMeta.appData`, a JSON object
80
+ of at most 16 KB, `MAX_APP_DATA_BYTES`), set with `ingest({ appData })` and changed with
81
+ `files.update(id, { appData }, access)`. Never sent to the model, nor in a summary.
82
+
83
+ ```ts
84
+ const meta = await files.ingest({ name, bytes, owner: userId, scope: [userId, chatId], appData: { rowId } });
85
+ await files.update!(meta.id, { appData: { rowId, label: "contract" } }, { owner: userId, scope: [userId, chatId] });
86
+ ```
87
+ - **`ingest({ dedupe: true })`**: a file uploaded again gives back the document of the same owner
88
+ and scope with the same SHA-256, with its expiry counted again, instead of a second copy (H6). The
89
+ file is read once to hash it, not extracted. Never across owners or scopes; not with `id`. The
90
+ document keeps its `createdAt`, which tells it from a new one
91
+ ([`IngestInput`](docs/reference/library.md#ingestinput)).
92
+ - **`storeRounds: "compact"`** and **`compactToolTurns(turns)`**: stored tool rounds with each large
93
+ result replaced by the stand-in the loop already sends when it drops a result (I2), a few hundred
94
+ bytes a call instead of up to 24,000 characters. A later question sends the stand-ins, and the
95
+ model reads again what it needs ([`compactToolTurns`](docs/reference/ask.md#compacttoolturnsturns)).
96
+ - `documentStoreChecks` checks `list` and `patchMeta`; `StoreCheckPart` has `"list"` and `"meta"`.
97
+
98
+ ### Changed: what works differently
99
+
100
+ - **The last document larger than the whole cache is kept apart** for a minute after its last use
101
+ (P4): over a store without `readTextRange`, the tool calls of a question no longer each load and
102
+ index it again (250 ms a read, and about 2 GB of RSS at 100 MB in the 0.6 review). One at most, on
103
+ top of `cacheBytes`; `cacheBytes: 0` keeps none; `stats().cache.bytes` counts it,
104
+ `stats().cache.entries` does not.
105
+ - **`FileDocumentStore.sweep` removes metadata whose text is gone**, once it is older than
106
+ `orphanAgeMs`, as it removes files of no document: a document changed on one server while another
107
+ deleted it can be left so, and reads already took it as missing.
108
+ - **An ingest's own reads of a path upload count as stuck calls** (the `lstat`, the parts read for
109
+ the format, and, when `ingestTimeoutMs` is a time limit, the read of the file), as its store calls
110
+ do, once they have run the time the ingest gives them: a volume that does not answer now shows in `stats().stuckStoreCalls`, and past
111
+ `maxStuckStoreCalls` store calls fail at once with `"STORE_STUCK"`
112
+ ([A store that stops answering](docs/guides/deployment.md#a-store-that-stops-answering)).
113
+
114
+ ## 0.10.1 — 2026-11-25
115
+
116
+ A patch from the review of 0.10.0 against its code: a few pages said more, or less, than the code
117
+ does, `checkCitations` read a line number written with commas as its first digits, and one test
118
+ failed on a slow runner. The text sent to the model is the same as 0.10.0's.
119
+
120
+ ### Upgrading: what you need to change
121
+
122
+ Nothing. Code written for 0.10.0 compiles as it is, and the requests are byte for byte those of
123
+ 0.10.0.
124
+
125
+ ### New: what you can add
126
+
127
+ - `HeaderSource` and `HeaderContext` are exported: the type of `vertexAi({ headers })` and of a
128
+ headers function that takes `{ refresh }`
129
+ ([VertexAiOptions](docs/reference/gemini.md#vertexaioptions)).
130
+
131
+ ### Fixed
132
+
133
+ - **`checkCitations` read "(app.log L1,200)" as line 1.** A number written in groups of three after
134
+ commas is now one number ("L1,200", "line 12,345", "שורה 1,200"), in `AskResult.citations` too;
135
+ "L1,20" is still line 1.
136
+ - **Docs that did not match the code:**
137
+ - after a whole-file read with `output: "items"`, only the lines of its items count as shown, not
138
+ the whole file ([`CitationCheck`](docs/reference/ask.md#citationcheck));
139
+ - a reply over a table sent whole that ended for a reason asking again cannot mend (`"other"`) is
140
+ not asked for again ([Tables sent whole](docs/guides/costs-and-limits.md#tables-sent-whole));
141
+ - `body` of `askGemini` and `gemini()` reaches the chat requests, not the part reads of a
142
+ whole-file read, which take `analysisBody`: the upgrade guide's worked example labelled only
143
+ the chat requests, and now sets both
144
+ ([The worked example](docs/upgrading-0.10.md#the-worked-example));
145
+ - `has("aggregate_table")` is true while the text tools are declared; of two keyword passages with
146
+ one score, the one met first comes first, not always the earlier in the file;
147
+ `maxStuckStoreCalls` is half the libuv pool, at least 1; a Gemini error in a stream is retried
148
+ for 408 and 409 too; its `code` is its status only from 400 to 599; `location` is not checked
149
+ when `host` is given; the printed `VertexAiOptions` shows the fields it refuses;
150
+ - the 0.10.0 entry below and the upgrade guide: what the opt-outs do not give back (also the
151
+ prompts of merges, the answer to an unknown tool, and results cut in tokens), which finish
152
+ reasons 0.9 already did not ask again for, the 3-row rule (for tables sent whole only), the
153
+ item check (it takes out a short `\u` escape), and the mocks that need `stats` and `toolsFor`;
154
+ - `docs/measurements.md` listed thought signatures of earlier questions as if 0.10.0 sent them:
155
+ it ran them as a probe, and sends none.
156
+ - **Tests:** a search test that stops at a 5 ms budget ran out of time before its first match on a
157
+ Windows runner; it now doubles the budget until a scan finds lines.
158
+
39
159
  ## 0.10.0 — 2026-11-25
40
160
 
41
161
  Counts that are right and a cost that is bounded, for a chatbot on Gemini. Tables sent whole get
@@ -139,7 +259,10 @@ Some behavior is different. Check each point against your app:
139
259
  - **What the opt-outs do not give back.** `inlineTables: "text"` and `numberInline: false` each
140
260
  give 0.9's bytes for what they cover. With both, these stay: the `whole_file` hint of a
141
261
  `read_document` result cut short, and the `filter_note` of `aggregate_table`; the declaration of
142
- `analyze_whole_document` and the prompts of its part reads (M8); and the card sizes of LLF-059
262
+ `analyze_whole_document` and the prompts of its part reads and merges (M8); the card sizes of
263
+ LLF-059; the loop's own answer to a call of an unknown tool ("Unknown tool “x”. The tools are:
264
+ …", LLF-049); and tool results cut to their room in tokens, at each document's own characters per
265
+ token, so a result cut at the room differs from 0.9's
143
266
  ([What has a way back](docs/upgrading-0.10.md#going-back-to-09s-text)).
144
267
  - **Rolling deploys.** What 0.10.0 stores is what 0.9 stores, so servers of both versions share a
145
268
  store and nothing fails. But they send different text, so a chat answered by 0.9 and 0.10 servers
@@ -180,7 +303,8 @@ Some behavior is different. Check each point against your app:
180
303
  - **Filtered and cut answers say so.** `result.finish` tells how the answer ended, an
181
304
  `answer_filtered` or `answer_cut` notice comes before `run.finish`, and a reply that a filter or
182
305
  another reason that asking again cannot mend ended (`finish` `"filtered"` or `"other"`) is not
183
- asked for again: 2 requests over a searched file, where 0.9 made 4. Gemini's `MODEL_ARMOR`,
306
+ asked for again. 0.9 already stopped so after the filters it knew; a reason it did not know made
307
+ 4 requests over a searched file, and now makes 2. Gemini's `MODEL_ARMOR`,
184
308
  `IMAGE_PROHIBITED_CONTENT`, `IMAGE_RECITATION` and `IMAGE_OTHER` are now `"filtered"` (as
185
309
  `IMAGE_SAFETY` was), and `OTHER`, `LANGUAGE` and four more `"other"`; they gave no finish.
186
310
  `MALFORMED_RESPONSE` is now `"malformed_call"`: the turn is asked for once more.
@@ -314,7 +438,7 @@ await chats.updateOne({ _id: chatId }, {
314
438
  tokens.
315
439
  - A reply ended by a reason that asking again cannot mend (`"filtered"`, `"other"`) is neither
316
440
  nudged nor asked for again. Over files sent whole alone (nothing searched or viewed), one with no
317
- text ends the question without a closing request. Otherwise the closing request is made once, and
441
+ text that ended so, or at the output limit, ends the question without a closing request. Otherwise the closing request is made once, and
318
442
  a filtered closing is not asked for again.
319
443
  - The room for tool results is shared in tokens, at each document's own characters per token. A
320
444
  result that would still pass the room is cut before the model gets it, in call order.
@@ -323,7 +447,9 @@ await chats.updateOne({ _id: chatId }, {
323
447
 
324
448
  **Tables, numbers and citations**
325
449
 
326
- - A file counts as having a table when it has 3 rows of one table.
450
+ - A file sent whole counts as having a table, for the tools of `inlineTables: "tools"`, when it has
451
+ 3 rows of one table. Whether a searched file gets `aggregate_table` is decided by its format, as
452
+ in 0.9.
327
453
  - `aggregate_table`: a filter that orders a column (`>`, `>=`, `<`, `<=`) against a value that
328
454
  names another column compares the two cells of each row, and says so in `filter_note`. A column
329
455
  letter works in every table. Over a table sent whole, a grouped result ends with a `cite` line.
@@ -338,7 +464,8 @@ await chats.updateOne({ _id: chatId }, {
338
464
  - `analyze_whole_document` keeps 0.9.0's description word for word: items are told in `output`
339
465
  only. A new description made Gemini 3.5 Flash-Lite skip whole reads.
340
466
  - The item check counts a quote near its named line as verified (up to one letter in five
341
- differs), finds a clause's line by the number it starts with, and repairs short `\u` escapes. The
467
+ differs), finds a clause's line by the number it starts with, and takes out a `\u` escape with
468
+ fewer than four hex digits, which a model writes by mistake (the near check allows for the gap). The
342
469
  rule asks for five to twelve words of the line, copied exactly.
343
470
  - A whole read with more parts than `ToolCallLimits.maxRequests` is refused before any request; one
344
471
  given `maxRequests` stops merging at it (`notes_left_out`, or `notes_only` when no request is left
@@ -417,8 +544,10 @@ await chats.updateOne({ _id: chatId }, {
417
544
  - **N12:** a whole-file read passed `limits.requests`: 40 requests against 32, 42 through
418
545
  `askWithFiles`.
419
546
  - **A6, NEW-filtered-answer:** a reply that Gemini ended with `MODEL_ARMOR`, `OTHER`, `LANGUAGE` or
420
- another reason the library did not know cost 4 requests and gave no finish, and a filtered or
421
- cut answer read as complete ("The employee's medical leave was", `answered: true`).
547
+ another reason 0.9 did not know (the image filters, `NO_IMAGE`, `TOO_MANY_TOOL_CALLS`,
548
+ `MISSING_THOUGHT_SIGNATURE`) cost 4 requests and gave no finish, and a filtered or cut answer
549
+ read as complete ("The employee's medical leave was", `answered: true`). A reason 0.10.0 does not
550
+ know either is still asked for again.
422
551
  - **LO-7:** with `eventResults`, event plans held owner, scope, sha256 and original at run time.
423
552
  - `alreadyShown` could point to a result that `onToolResult` replaced.
424
553
 
package/dist/ask.d.ts CHANGED
@@ -208,6 +208,14 @@ export type AskOptions = {
208
208
  * documents, and events are often sent on to a browser.
209
209
  */
210
210
  eventResults?: boolean;
211
+ /**
212
+ * How `AskResult.toolTurns` holds the results of the question's tool calls. "full" (the default):
213
+ * as the model had them. "compact": each large result replaced by the stand-in the loop sends
214
+ * when it drops a result to make room (`compactToolTurns`), so that a stored question takes a few
215
+ * hundred bytes a call. A later question then sends those stand-ins: the model reads again what it
216
+ * needs, at the price of a tool call. New in 0.10.2.
217
+ */
218
+ storeRounds?: "full" | "compact";
211
219
  signal?: AbortSignal;
212
220
  };
213
221
  export type AskResult = {
@@ -310,6 +318,14 @@ export type MissingDocumentsContext = {
310
318
  scope?: DocumentScope;
311
319
  signal?: AbortSignal;
312
320
  };
321
+ /**
322
+ * Stored tool rounds (`AskResult.toolTurns`) made small: each result that is large is replaced by
323
+ * the stand-in the loop sends when it drops a result to make room (`stubResult`): the document, the
324
+ * lines or pages it showed, a search's query and total, the largest groups of a count, and a note
325
+ * that it was dropped. Errors and small results stay as they are. Copies: the turns given are not
326
+ * changed. For rounds stored by `storeRounds: "full"`, or by an earlier version. New in 0.10.2.
327
+ */
328
+ export declare function compactToolTurns(turns: readonly ToolTurn[]): ToolTurn[];
313
329
  /**
314
330
  * Shares `room` among tool calls whose results may be up to `caps` characters. A character of the
315
331
  * result of call i takes `rates[i]` of the room (1 when `rates` is left out: the room is in
package/dist/ask.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"ask.d.ts","sourceRoot":"","sources":["../src/ask.ts"],"names":[],"mappings":"AAEA,OAAO,EAAqD,KAAK,QAAQ,EAAsC,KAAK,WAAW,EAA4E,MAAM,aAAa,CAAC;AAC/N,OAAO,EAAkB,KA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SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC,MAAM,GAAG,SAAS,CAAC,CAoBnG;AAgCD;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,SAAS,GAAG,SAAS,CAErE;AA6FD;;;;;GAKG;AACH,wBAAsB,YAAY,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC,CA0B1E;AAsBD;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,UAAU,GAAG,WAAW,CAAC,QAAQ,EAAE,SAAS,CAAC,CAa/E"}
package/dist/ask.js CHANGED
@@ -62,6 +62,28 @@ function checkFilteredAnswer(given) {
62
62
  return;
63
63
  throw new TypeError(`filteredAnswer must be "keep" or "drop", and is ${shownValue(given)}.`);
64
64
  }
65
+ /** `storeRounds` checked: "full", "compact" or nothing (0.10.2). */
66
+ function checkStoreRounds(given) {
67
+ if (given === undefined || given === "full" || given === "compact")
68
+ return;
69
+ throw new TypeError(`storeRounds must be "full" or "compact", and is ${shownValue(given)}.`);
70
+ }
71
+ /**
72
+ * Stored tool rounds (`AskResult.toolTurns`) made small: each result that is large is replaced by
73
+ * the stand-in the loop sends when it drops a result to make room (`stubResult`): the document, the
74
+ * lines or pages it showed, a search's query and total, the largest groups of a count, and a note
75
+ * that it was dropped. Errors and small results stay as they are. Copies: the turns given are not
76
+ * changed. For rounds stored by `storeRounds: "full"`, or by an earlier version. New in 0.10.2.
77
+ */
78
+ export function compactToolTurns(turns) {
79
+ return turns.map((turn) => ({
80
+ ...turn,
81
+ calls: turn.calls.map((call) => {
82
+ const { result, ...rest } = call;
83
+ return { ...rest, result: stubResult(rest, result) ?? result };
84
+ }),
85
+ }));
86
+ }
65
87
  /**
66
88
  * `inlineTables` and `numberInline` checked: a value they cannot be ("Text", "false") is an error
67
89
  * before anything is planned, as `prepare` would throw it, but in the words of the question.
@@ -621,6 +643,7 @@ async function ask(options, carried, state) {
621
643
  const limits = checkedLimits(options.limits);
622
644
  checkMissingPolicy(options.onMissingDocuments);
623
645
  checkFilteredAnswer(options.filteredAnswer);
646
+ checkStoreRounds(options.storeRounds);
624
647
  checkInlineOptions(options.inlineTables, options.numberInline);
625
648
  // Since 0.10.0 by default: the tables sent whole get the tools, and the files sent whole have
626
649
  // numbered lines. "text" and false send them as 0.9 did.
@@ -927,13 +950,14 @@ async function ask(options, carried, state) {
927
950
  ...(blockReason ? { blockReason } : {}),
928
951
  steps,
929
952
  evidence,
930
- // The rounds as the model last had them. A file cannot be kept as JSON: what is kept says that it was shown.
953
+ // The rounds as the model last had them, or their stand-ins (`storeRounds: "compact"`). A
954
+ // file cannot be kept as JSON: what is kept says that it was shown.
931
955
  toolTurns: messages.slice(asked).filter(isRound).map((round) => ({
932
956
  role: "tools",
933
957
  version: TOOL_TURN_VERSION,
934
958
  calls: round.answers.map(({ call: { problem: _problem, ...call }, result: returned, files: shownFiles }) => ({
935
959
  ...call,
936
- result: shownFiles?.length ? stubResult(call, returned, true) ?? returned : returned,
960
+ result: shownFiles?.length ? stubResult(call, returned, true) ?? returned : options.storeRounds === "compact" ? stubResult(call, returned) ?? returned : returned,
937
961
  })),
938
962
  })),
939
963
  plan: prepared.plan,