llm-large-files 0.8.2 → 0.9.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.
- package/CHANGELOG.md +535 -0
- package/README.md +9 -10
- package/dist/access.d.ts +86 -0
- package/dist/access.d.ts.map +1 -0
- package/dist/access.js +131 -0
- package/dist/access.js.map +1 -0
- package/dist/ask.d.ts +45 -1
- package/dist/ask.d.ts.map +1 -1
- package/dist/ask.js +181 -20
- package/dist/ask.js.map +1 -1
- package/dist/cache.d.ts +12 -3
- package/dist/cache.d.ts.map +1 -1
- package/dist/cache.js +18 -5
- package/dist/cache.js.map +1 -1
- package/dist/encoding.js +5 -3
- package/dist/encoding.js.map +1 -1
- package/dist/error-info.d.ts +57 -0
- package/dist/error-info.d.ts.map +1 -0
- package/dist/error-info.js +217 -0
- package/dist/error-info.js.map +1 -0
- package/dist/errors.d.ts +72 -8
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +102 -15
- package/dist/errors.js.map +1 -1
- package/dist/events.d.ts +35 -9
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js +42 -11
- package/dist/events.js.map +1 -1
- package/dist/evidence.d.ts +4 -2
- package/dist/evidence.d.ts.map +1 -1
- package/dist/evidence.js +14 -3
- package/dist/evidence.js.map +1 -1
- package/dist/extract.d.ts +32 -8
- package/dist/extract.d.ts.map +1 -1
- package/dist/extract.js +46 -35
- package/dist/extract.js.map +1 -1
- package/dist/gemini/adapter.d.ts +19 -3
- package/dist/gemini/adapter.d.ts.map +1 -1
- package/dist/gemini/adapter.js +84 -12
- package/dist/gemini/adapter.js.map +1 -1
- package/dist/gemini/chat.d.ts +18 -6
- package/dist/gemini/chat.d.ts.map +1 -1
- package/dist/gemini/chat.js +2 -0
- package/dist/gemini/chat.js.map +1 -1
- package/dist/gemini/index.d.ts +1 -1
- package/dist/gemini/index.d.ts.map +1 -1
- package/dist/index.d.ts +9 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/ingest.d.ts +70 -0
- package/dist/ingest.d.ts.map +1 -0
- package/dist/ingest.js +868 -0
- package/dist/ingest.js.map +1 -0
- package/dist/library.d.ts +169 -34
- package/dist/library.d.ts.map +1 -1
- package/dist/library.js +324 -591
- package/dist/library.js.map +1 -1
- package/dist/map-reduce.js +3 -3
- package/dist/map-reduce.js.map +1 -1
- package/dist/model.d.ts +43 -2
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +63 -3
- package/dist/model.js.map +1 -1
- package/dist/node/handlers.d.ts +226 -14
- package/dist/node/handlers.d.ts.map +1 -1
- package/dist/node/handlers.js +423 -181
- package/dist/node/handlers.js.map +1 -1
- package/dist/node/index.d.ts +3 -2
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +2 -1
- package/dist/node/index.js.map +1 -1
- package/dist/node/ingest-child.d.ts +7 -1
- package/dist/node/ingest-child.d.ts.map +1 -1
- package/dist/node/ingest-child.js +18 -3
- package/dist/node/ingest-child.js.map +1 -1
- package/dist/node/isolated.d.ts +3 -1
- package/dist/node/isolated.d.ts.map +1 -1
- package/dist/node/isolated.js +11 -4
- package/dist/node/isolated.js.map +1 -1
- package/dist/node/originals.d.ts +19 -0
- package/dist/node/originals.d.ts.map +1 -0
- package/dist/node/originals.js +82 -0
- package/dist/node/originals.js.map +1 -0
- package/dist/node/spool.d.ts +102 -0
- package/dist/node/spool.d.ts.map +1 -0
- package/dist/node/spool.js +365 -0
- package/dist/node/spool.js.map +1 -0
- package/dist/node/sse.d.ts +4 -3
- package/dist/node/sse.d.ts.map +1 -1
- package/dist/node/sse.js +7 -6
- package/dist/node/sse.js.map +1 -1
- package/dist/pdf-layout.d.ts.map +1 -1
- package/dist/pdf-layout.js +71 -12
- package/dist/pdf-layout.js.map +1 -1
- package/dist/ranged.d.ts +15 -11
- package/dist/ranged.d.ts.map +1 -1
- package/dist/ranged.js +42 -11
- package/dist/ranged.js.map +1 -1
- package/dist/retry.d.ts +3 -1
- package/dist/retry.d.ts.map +1 -1
- package/dist/retry.js +6 -2
- package/dist/retry.js.map +1 -1
- package/dist/scope.d.ts +25 -0
- package/dist/scope.d.ts.map +1 -0
- package/dist/scope.js +60 -0
- package/dist/scope.js.map +1 -0
- package/dist/source.d.ts +60 -0
- package/dist/source.d.ts.map +1 -0
- package/dist/source.js +170 -0
- package/dist/source.js.map +1 -0
- package/dist/stores.d.ts +120 -31
- package/dist/stores.d.ts.map +1 -1
- package/dist/stores.js +582 -139
- package/dist/stores.js.map +1 -1
- package/dist/testing/fake-fetch.d.ts +31 -0
- package/dist/testing/fake-fetch.d.ts.map +1 -0
- package/dist/testing/fake-fetch.js +66 -0
- package/dist/testing/fake-fetch.js.map +1 -0
- package/dist/testing/fake-model.d.ts +38 -0
- package/dist/testing/fake-model.d.ts.map +1 -0
- package/dist/testing/fake-model.js +62 -0
- package/dist/testing/fake-model.js.map +1 -0
- package/dist/testing/index.d.ts +7 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +9 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/store-checks.d.ts +72 -0
- package/dist/testing/store-checks.d.ts.map +1 -0
- package/dist/testing/store-checks.js +619 -0
- package/dist/testing/store-checks.js.map +1 -0
- package/dist/tools.d.ts +25 -0
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +135 -13
- package/dist/tools.js.map +1 -1
- package/dist/types.d.ts +116 -13
- package/dist/types.d.ts.map +1 -1
- package/docs/README.md +17 -8
- package/docs/getting-started.md +18 -13
- package/docs/guides/anthropic.md +12 -8
- package/docs/guides/conversations.md +112 -47
- package/docs/guides/costs-and-limits.md +16 -7
- package/docs/guides/deployment.md +284 -83
- package/docs/guides/errors-and-reliability.md +161 -23
- package/docs/guides/own-adapter-and-loop.md +27 -10
- package/docs/guides/pdfs.md +123 -29
- package/docs/guides/storage.md +633 -145
- package/docs/guides/testing.md +78 -129
- package/docs/guides/vertex-and-gemini.md +10 -7
- package/docs/guides/web-app.md +312 -78
- package/docs/how-it-works.md +35 -8
- package/docs/measurements.md +43 -8
- package/docs/publishing.md +112 -36
- package/docs/reference/ask.md +154 -13
- package/docs/reference/errors-and-retries.md +166 -14
- package/docs/reference/events.md +53 -20
- package/docs/reference/gemini.md +70 -21
- package/docs/reference/library.md +706 -165
- package/docs/reference/node.md +624 -110
- package/docs/reference/testing.md +311 -0
- package/docs/reference/tools.md +15 -5
- package/docs/security.md +304 -67
- package/docs/troubleshooting.md +144 -65
- package/docs/upgrading-0.9.md +890 -0
- package/package.json +12 -3
- package/src/access.ts +144 -0
- package/src/ask.ts +230 -19
- package/src/cache.ts +20 -5
- package/src/encoding.ts +6 -4
- package/src/error-info.ts +255 -0
- package/src/errors.ts +129 -15
- package/src/events.ts +86 -21
- package/src/evidence.ts +14 -3
- package/src/extract.ts +50 -33
- package/src/gemini/adapter.ts +97 -11
- package/src/gemini/chat.ts +20 -6
- package/src/gemini/index.ts +1 -1
- package/src/index.ts +9 -6
- package/src/ingest.ts +927 -0
- package/src/library.ts +467 -601
- package/src/map-reduce.ts +3 -3
- package/src/model.ts +69 -5
- package/src/node/handlers.ts +630 -183
- package/src/node/index.ts +13 -2
- package/src/node/ingest-child.ts +23 -5
- package/src/node/isolated.ts +11 -4
- package/src/node/originals.ts +78 -0
- package/src/node/spool.ts +365 -0
- package/src/node/sse.ts +7 -6
- package/src/pdf-layout.ts +69 -11
- package/src/ranged.ts +34 -13
- package/src/retry.ts +6 -2
- package/src/scope.ts +63 -0
- package/src/source.ts +178 -0
- package/src/stores.ts +635 -140
- package/src/testing/fake-fetch.ts +80 -0
- package/src/testing/fake-model.ts +78 -0
- package/src/testing/index.ts +11 -0
- package/src/testing/store-checks.ts +660 -0
- package/src/tools.ts +150 -14
- package/src/types.ts +106 -13
package/CHANGELOG.md
CHANGED
|
@@ -36,6 +36,541 @@ 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.9.0 — 2026-11-24
|
|
40
|
+
|
|
41
|
+
One server process for every user and chat. Every store call carries the scope and the owner of
|
|
42
|
+
the call, `FileDocumentStore` keeps the files of each chat in a folder of its own, documents can
|
|
43
|
+
take your application's IDs, and the uploads your application keeps are read where they are
|
|
44
|
+
instead of copied into the store. The upload handlers can save each upload where you keep it,
|
|
45
|
+
record it in your database and hold large uploads on disk; errors are typed, and `errorInfoOf`
|
|
46
|
+
puts them in your users' words. The text sent to the model is the same as in 0.8.2 for ordinary
|
|
47
|
+
chats, so conversations keep the provider's prompt cache at the upgrade.
|
|
48
|
+
[Upgrading to 0.9](docs/upgrading-0.9.md) takes an application from 0.8.x step by step, with a
|
|
49
|
+
worked example of a chatbot on a shared volume.
|
|
50
|
+
|
|
51
|
+
### Upgrading: what you need to change
|
|
52
|
+
|
|
53
|
+
Code written for 0.8.2 compiles with 0.9.0, except in these cases
|
|
54
|
+
([Does my code compile?](docs/upgrading-0.9.md#does-my-code-compile)):
|
|
55
|
+
|
|
56
|
+
- `NoticeCode` has three new members, `"documents_missing"`, `"document_gone"` and
|
|
57
|
+
`"page_looks_busy"`, and `IngestErrorCode` one, `"exists"`. An exhaustive `switch` over either,
|
|
58
|
+
or a `Record` keyed by either, needs them.
|
|
59
|
+
- `EventError.code` is now `IngestErrorCode | DocumentScopeErrorCode`: the `run.error` or
|
|
60
|
+
`ingest.error` of a scope error carries `"scope_missing"`, `"scope_invalid"` or
|
|
61
|
+
`"scope_required"`. Code that indexes a `Record<IngestErrorCode, …>` with it, or passes it where
|
|
62
|
+
an `IngestErrorCode` is expected, must check it first. A `switch` over it with a `never` check
|
|
63
|
+
needs `"exists"` and the three scope codes.
|
|
64
|
+
- `LargeFiles.ingest` takes `IngestInput | IngestFromSource`. Code that reads `input.bytes` of its
|
|
65
|
+
argument fails with TS18048 or TS2532: a `LargeFiles` of your own whose `ingest` parameter is
|
|
66
|
+
inferred (`{ ...files, ingest: (input) => … }`), the calls of a spy or mock of `files.ingest`
|
|
67
|
+
(`spy.mock.calls[0][0].bytes`), and a value typed `Parameters<LargeFiles["ingest"]>[0]`. Code
|
|
68
|
+
that passes `input` to a function that takes `IngestInput` fails with TS2345. Narrow it:
|
|
69
|
+
`if (input.bytes)`, or `"source" in input`. Annotating `(input: IngestInput)` compiles too, but
|
|
70
|
+
only suits a wrapper that is never given a path: `createDocumentHandlers` gives one with
|
|
71
|
+
`uploadSpool` or `prepareUpload`.
|
|
72
|
+
- A store of your own, or a subclass of `FileDocumentStore` or `MemoryDocumentStore`, whose method
|
|
73
|
+
takes a parameter of its own after those of 0.8 (`get(id, options?)`, `sweep(now?, dryRun?)`,
|
|
74
|
+
`readTextRange(id, start, end, signal?)`) fails with TS2322 or TS2416. The new `context` takes
|
|
75
|
+
that place, and the library passes it there. Put your parameter after `context`.
|
|
76
|
+
- A subclass of `DocumentStoreError` that declares its own `status`, or of
|
|
77
|
+
`DocumentsNotFoundError` that declares its own `status` or `code`: these are now `503`, and `404`
|
|
78
|
+
and `"documents_missing"`.
|
|
79
|
+
- A subclass of `IngestError`, `DocumentStoreError`, `DocumentsNotFoundError` or
|
|
80
|
+
`ModelRequestError` whose own static `is` does not fit `(value: unknown) => value is …` (one
|
|
81
|
+
that returns `boolean`, say) fails with TS2417: each of them has a static `is` now. Make yours
|
|
82
|
+
return `value is` your class, or rename it.
|
|
83
|
+
- `fromGeminiContents` passed as a callback (`histories.map(fromGeminiContents)`) fails with
|
|
84
|
+
TS2345: its new second parameter would get the index. Write
|
|
85
|
+
`histories.map((contents) => fromGeminiContents(contents))`.
|
|
86
|
+
- Code that reads the `messages` of an `AskGeminiOptions` back and reads `text` of a turn fails with
|
|
87
|
+
TS2339, and code that passes them where `Array<ChatTurn | ToolTurn>` is expected with TS2345:
|
|
88
|
+
`messages` is now `ChatMessage[]`, as `askWithFiles` takes it, and a turn may have `parts` instead
|
|
89
|
+
of `text`. Type the history `Array<ChatTurn | ToolTurn>`, or check `"text" in turn`.
|
|
90
|
+
|
|
91
|
+
The other changes to the public types add exports, options, fields and optional parameters. Each
|
|
92
|
+
`DocumentStore` method takes a last, optional `context`: a store whose methods take only the
|
|
93
|
+
arguments of 0.8 still implements the interface. The new exports are under **New**.
|
|
94
|
+
|
|
95
|
+
Some behavior is different. Check each point against your app:
|
|
96
|
+
|
|
97
|
+
- **Node.js 22.12 or later.** `engines.node` is `>=22.12` (was `>=20.19`): Node 22.0 to 22.11 cannot
|
|
98
|
+
`require()` the package from CommonJS, which the docs promise. CI runs Node 22, 24 and 26, on
|
|
99
|
+
Ubuntu and Windows, and 22.12.0 on Ubuntu, where it also checks `require()` of every subpath of
|
|
100
|
+
the packed tarball. npm only warns (`EBADENGINE`) unless `engine-strict` is set, so an app on
|
|
101
|
+
Node 20 still installs, untested. There, an `unpdf` that cannot load pdf.js now throws its own
|
|
102
|
+
error, not "The unpdf installed cannot read PDF files on Node 20".
|
|
103
|
+
**What to do:** run Node 22.12 or later, and `@types/node` 22 or later in TypeScript projects.
|
|
104
|
+
- **The upload handler answers 422 only for an `IngestError` (S12).** A plain `Error` from a
|
|
105
|
+
`LargeFiles` of your own, without a `status` or a system `code`, is answered 500
|
|
106
|
+
`{ "error": "Upload failed." }`: it was 422 with its message, which could name a database host.
|
|
107
|
+
A file of code `"unreadable"` gets fixed words ("This file could not be read. It may be damaged,
|
|
108
|
+
or not of the type its name says."), not its parser's or extractor's message. A model's error
|
|
109
|
+
thrown by an ingest of yours gets the status and words of `errorInfoOf`, not the provider's. A
|
|
110
|
+
`DocumentScopeError` is a 404 "This chat no longer exists." for `"scope_missing"`, and a 500 for
|
|
111
|
+
the other codes. Only the handler's own 413s (its size check, and `IngestError` `"too_large"`)
|
|
112
|
+
get the upload-limit message. `Content-Type` is no longer URI-decoded (`X-File-Type` still is).
|
|
113
|
+
**What to do:** throw `new IngestError(code, message)` for a file you refuse, as the
|
|
114
|
+
`ingestInProcess` recipe of [Deployment](docs/guides/deployment.md#uploads-and-ingest) now does. A
|
|
115
|
+
route of your own answers the same way with `uploadAnswerOf`
|
|
116
|
+
([node](docs/reference/node.md#how-errors-are-answered)).
|
|
117
|
+
- **A store that fails is a `DocumentStoreError`, answered 503.** A failed write of `files.ingest`
|
|
118
|
+
throws one with `operation: "write"` (code `"ETIMEDOUT"` for a write that did not end within
|
|
119
|
+
`ingestTimeoutMs`), a failed `files.delete` one with `"delete"`, a failed `files.sweep` one with
|
|
120
|
+
`"sweep"`. Before, the store's own error came out as it was; it is now the `cause`. The upload
|
|
121
|
+
handler answers a failed write 503 with `Retry-After: 5` (it was a 500), and `get` and `remove`
|
|
122
|
+
answer a store that fails 503 with `Retry-After: 5` (it was a 500, such as "The file could not be
|
|
123
|
+
looked up (EIO)."). The `ingest.error` event of a failed write has `name: "DocumentStoreError"`
|
|
124
|
+
and `status: 503`.
|
|
125
|
+
**What to do:** code that catches its own store error class reads `error.cause`. Log
|
|
126
|
+
`error.cause`: the handlers log nothing
|
|
127
|
+
([Store failures](docs/upgrading-0.9.md#store-failures-are-documentstoreerror)).
|
|
128
|
+
- **`DocumentStoreError` has `status: 503`, and `DocumentsNotFoundError` has `status: 404` and
|
|
129
|
+
`code: "documents_missing"`.** Their `run.error` events carry the status too.
|
|
130
|
+
**What to do:** code that takes any error with a numeric `status` for a model's error checks
|
|
131
|
+
these first: `DocumentStoreError.is(error)`, `DocumentsNotFoundError.is(error)`, or
|
|
132
|
+
`errorInfoOf(error)`.
|
|
133
|
+
- **Every store call carries a context.** The library passes `{ scope, owner }` as the last argument
|
|
134
|
+
of every `DocumentStore` method. A wrapper or a subclass that passes only the ID on
|
|
135
|
+
(`super.getMeta(id)`, `(id) => inner.getMeta(id)`) still compiles, but drops it. Over a store that
|
|
136
|
+
keeps scopes apart, such a call does not find the documents stored in a scope. Over a
|
|
137
|
+
`FileDocumentStore` with `scopes`, every call but `sweep` throws a `DocumentScopeError`
|
|
138
|
+
`"scope_required"`. With `unscoped: "root"`, the documents go to the root folder without an error,
|
|
139
|
+
outside the chat's folder, so removing that folder does not erase them. And a `sweep` that drops
|
|
140
|
+
it sweeps every scope: `files.sweep({ scope })` removes the expired documents of every chat. A
|
|
141
|
+
store that ignores the context still keeps scopes apart for the library, through `meta.scope`,
|
|
142
|
+
and then needs application IDs that are unique in the whole store.
|
|
143
|
+
**What to do:** pass the context on (`super.getMeta(id, context)`), and run `documentStoreChecks`
|
|
144
|
+
of `llm-large-files/testing` on your store
|
|
145
|
+
([Stores of your own](docs/upgrading-0.9.md#stores-of-your-own)).
|
|
146
|
+
- **A store that writes the text before the record.** The storage guide's example
|
|
147
|
+
`BlobDocumentStore` wrote the text, then inserted the record under a unique key. When two servers
|
|
148
|
+
ingest one application's ID at the same moment, the ingest that loses has then written its text
|
|
149
|
+
over the winner's. The library now reads the winner's document as missing when the two texts
|
|
150
|
+
differ in length or lines; otherwise it serves the loser's text.
|
|
151
|
+
**What to do:** insert the record first, hidden from `getMeta` until the text is written, as the
|
|
152
|
+
example now does ([Example: object storage and a database](docs/guides/storage.md#example-object-storage-and-a-database)).
|
|
153
|
+
Two ingests of one ID that overlap then both fail with a 503 instead of storing the wrong text.
|
|
154
|
+
With an ID of its own for each upload, as `attach()` and the worked example make, none of this
|
|
155
|
+
happens ([Write the record before the text](docs/upgrading-0.9.md#write-the-record-before-the-text)).
|
|
156
|
+
- **New fields in what you store.** `ingest` writes `metaVersion: 1` and `sha256` into every
|
|
157
|
+
`DocumentMeta`, and `scope` and `original` when it is given them. Every `ToolTurn` that
|
|
158
|
+
`askWithFiles` returns has `version: 1`.
|
|
159
|
+
**What to do:** tests that compare a meta or a round whole expect these fields. A schema that
|
|
160
|
+
refuses fields it does not know (a MongoDB `$jsonSchema` with `additionalProperties: false`, a
|
|
161
|
+
Mongoose schema in strict mode that throws) must allow them, for the metadata a store of yours
|
|
162
|
+
keeps and for the rounds you keep with each question: otherwise every ingest fails with a 503.
|
|
163
|
+
Change it before the first server of 0.9.0 starts
|
|
164
|
+
([Allow the new fields](docs/upgrading-0.9.md#allow-the-new-fields)).
|
|
165
|
+
- **Data written by a newer version is refused, not taken for missing.** Metadata with
|
|
166
|
+
`metaVersion` above 1 makes `getMeta`, `getOriginal`, `delete`, `prepare`, `askWithFiles` and the
|
|
167
|
+
tools throw a `DocumentStoreError` of code `"NEWER_VERSION"`, so that your app does not ingest
|
|
168
|
+
the file again over newer data. A stored `ToolTurn` with `version` above 1 makes `askWithFiles`
|
|
169
|
+
throw a `TypeError`, before any request. Servers of 0.8 ignore both fields.
|
|
170
|
+
**What to do:** nothing now. While servers of 0.9 and a later version share a store, let such a
|
|
171
|
+
call be tried again on a newer server; catch the `TypeError` to ask again without the old rounds.
|
|
172
|
+
- **Servers of 0.8 and 0.9 on one store.** In the flat layout of `FileDocumentStore`, servers of 0.8
|
|
173
|
+
read what 0.9.0 writes under the library's IDs, and ignore the new fields; 0.9.0 reads what 0.8
|
|
174
|
+
wrote. Servers of 0.8 do not see documents under an application's ID, nor the folders of a store
|
|
175
|
+
with `scopes`, nor an original kept by reference, and they do not check `meta.scope`.
|
|
176
|
+
**What to do:** upgrade first with your settings as they are. Turn on `scopes`, application IDs,
|
|
177
|
+
originals by reference, `requireOwner` and `requireScope` in a later deploy: on every server at
|
|
178
|
+
once, or with each chat kept on servers of one setting. Run the sweep from a server of 0.9.0
|
|
179
|
+
([Several servers and rolling deploys](docs/upgrading-0.9.md#several-servers-and-rolling-deploys)).
|
|
180
|
+
- **`requireOwner` and `requireScope`** (new, off by default) make `createDocumentHandlers` throw a
|
|
181
|
+
`TypeError` without `getOwner`, or without `getScope`. Under `requireOwner`, an owner of
|
|
182
|
+
`undefined` or `null` is answered 401 `{ "error": "Sign in first." }` on every route, and `""` a
|
|
183
|
+
500 "(empty owner)". Documents stored without an owner or a scope then read as missing: those of
|
|
184
|
+
0.8, and those that 0.5.0 stored with the owner `""`.
|
|
185
|
+
**What to do:** give `getOwner` and `getScope`, and turn them on once no server writes documents
|
|
186
|
+
without them ([Moving the documents of 0.8](docs/upgrading-0.9.md#moving-the-documents-of-08)).
|
|
187
|
+
- **`FileDocumentStore` writes files `0600` and folders `0700`.** Before, `0666` and `0777` minus the
|
|
188
|
+
umask: `0664` and `0775` under the usual `0002`. Servers, sidecars, and backup or sweep jobs that
|
|
189
|
+
run as other users of one group (a Kubernetes `fsGroup`) read "The document store could not be
|
|
190
|
+
read (EACCES)".
|
|
191
|
+
**What to do:** for those, set `fileMode: 0o640` and `directoryMode: 0o750` on every store. Files
|
|
192
|
+
written before keep their modes: `chmod` them once to narrow them.
|
|
193
|
+
- **`FileDocumentStore` follows no link at a document's file name**, except on Windows, which
|
|
194
|
+
cannot refuse one. A document whose `.json` or `.txt` file is a link (left by a migration or a
|
|
195
|
+
deduplication, say) reads as missing on Linux and macOS, and a kept copy (`.bin`) that is a link
|
|
196
|
+
as not kept.
|
|
197
|
+
**What to do:** replace such links with the files they point to before you upgrade.
|
|
198
|
+
- **`FileDocumentStore.delete` returns true once the metadata is gone.** A text, index or original
|
|
199
|
+
it cannot remove is left for `sweep`; it used to throw. Removals are tried again for about 2.6 s
|
|
200
|
+
on `EPERM`, `EACCES` and `EBUSY`, as renames are.
|
|
201
|
+
**What to do:** for erasure, keep a sweep running, or remove the scope's folder. Tests that mock
|
|
202
|
+
`fs.rm` to make a removal fail must mock `unlink`.
|
|
203
|
+
- **MIME types are cleaned.** `meta.mimeType` is a lowercased type/subtype without parameters
|
|
204
|
+
(`"Text/CSV; charset=x"` is stored as `"text/csv"`). A value that is not a valid type/subtype of at
|
|
205
|
+
most 127 characters, or holds anything but printable ASCII, is stored as
|
|
206
|
+
`application/octet-stream`.
|
|
207
|
+
**What to do:** compare `meta.mimeType` with the clean form.
|
|
208
|
+
- **Looks at pages take turns.** In a library, one `view_pages` look runs at a time
|
|
209
|
+
(`maxConcurrentPageLooks: 1`), and the others wait up to 30 s (`pageLookWaitMs`). Past that the
|
|
210
|
+
model is told the server is busy, and the question gets a `"page_looks_busy"` notice. A look
|
|
211
|
+
holds its turn while its PDF is read for at most `ingestTimeoutMs`.
|
|
212
|
+
**What to do:** nothing. On a server with heap to spare, raise `maxConcurrentPageLooks`;
|
|
213
|
+
`Infinity` runs every look at once, as in 0.8.2 ([PDFs](docs/guides/pdfs.md#view_pages)).
|
|
214
|
+
- **`fromGeminiContents` turns the library's tool rounds back into stored rounds**, and so does
|
|
215
|
+
`askGemini` with `contents`. Pointers and stand-ins then apply, as with `toolTurns`. The first
|
|
216
|
+
request is the same, byte for byte, for rounds that `geminiToolTurns` wrote. Rounds that 0.5.0
|
|
217
|
+
converted hold `tool_turns_left` in their responses: they are now sent without it, so such a
|
|
218
|
+
conversation misses the prompt cache once.
|
|
219
|
+
**What to do:** nothing. `{ rounds: false }` gives the output of 0.8. With `askGemini`, pass it as
|
|
220
|
+
`messages`: `askGemini({ …, messages: fromGeminiContents(contents, { rounds: false }) })`.
|
|
221
|
+
- **Tests of the tool loop.** A first request that stored rounds make too large is shortened before
|
|
222
|
+
it is sent: a test sees a `"results_shortened"` step and one request fewer, not a refused request
|
|
223
|
+
and `"room_made"`. A result that its stand-in would not make smaller (a short grouped search, a
|
|
224
|
+
small `aggregate_table` result) stays whole. An error of an adapter of yours with a `status` and
|
|
225
|
+
no `kind`, as `httpError` of `llm-large-files/testing` makes, gets a `kind` in its `EventError`
|
|
226
|
+
(`"server"` for a 503), and is retried by that kind: a 429 of code `"insufficient_quota"` is a
|
|
227
|
+
quota, and is not sent again. The loop goes by that kind too: an `httpError(413)`, a 429 "Request
|
|
228
|
+
too large … tokens per min" or a 400 of code `context_length_exceeded` is an overflow it mends.
|
|
229
|
+
Older results are shortened and the request is sent again (`"room_made"`), or a first request is
|
|
230
|
+
planned again (`"replanned"`), so a test that expected the question to fail at once sees one more
|
|
231
|
+
request. Thrown plain data with a status is "Something went wrong." in its event.
|
|
232
|
+
**What to do:** update the tests that compare these whole.
|
|
233
|
+
- **`isDocumentId` accepts application IDs.** It tests `APP_DOCUMENT_ID_PATTERN`, which the
|
|
234
|
+
library's `doc_` IDs match too.
|
|
235
|
+
**What to do:** to tell the library's IDs from yours, test `DOCUMENT_ID_PATTERN`.
|
|
236
|
+
- **If you give documents your own IDs** (`IngestInput.id`, new): they reach the model, in what it
|
|
237
|
+
is sent of each document and in its tool calls, so they must hold no personal data. A taken ID is
|
|
238
|
+
an `IngestError` `"exists"` (409), and so is a second ingest of one ID while the first is under way
|
|
239
|
+
in the library. In a folder that `FileDocumentStore` shares with your files, an ingest under the
|
|
240
|
+
ID `report` writes over your `report.txt`.
|
|
241
|
+
**What to do:** use random IDs, or IDs with a prefix per tenant
|
|
242
|
+
([Application IDs](docs/guides/storage.md#application-ids)).
|
|
243
|
+
- **If you keep the uploads yourself:** `keepOriginals` still copies each kept file into the store.
|
|
244
|
+
With `original: { ref }` and `originals` (`fileOriginals(root)` of `llm-large-files/node`), the
|
|
245
|
+
store keeps no copy, and `view_pages` reads your file, checked against the size and SHA-256 it had
|
|
246
|
+
at ingest. The library never writes, moves or deletes it. Documents ingested before keep their
|
|
247
|
+
copy. A server of 0.8 finds no copy of such a file: its `view_pages` answers that the original is
|
|
248
|
+
no longer on the server.
|
|
249
|
+
**What to do:** remove the file with its chat
|
|
250
|
+
([The file your application keeps](docs/guides/storage.md#the-file-your-application-keeps)).
|
|
251
|
+
- **The text sent to the model** is that of 0.8.2 for ordinary chats. Text is new only when its case
|
|
252
|
+
happens: the line for documents left out under `onMissingDocuments: "drop"`, the busy answer of
|
|
253
|
+
`view_pages`, and its answers for a file kept by reference that changed and for a PDF the store
|
|
254
|
+
did not return in time. A document ingested under your ID is named by that ID. A right-to-left
|
|
255
|
+
PDF table ingested from 0.9.0 on can read in another order (LLF-037, under **Fixed**); documents
|
|
256
|
+
ingested before keep their text.
|
|
257
|
+
**What to do:** nothing.
|
|
258
|
+
|
|
259
|
+
### New: what you can add
|
|
260
|
+
|
|
261
|
+
**Owners, scopes and IDs**
|
|
262
|
+
|
|
263
|
+
- **Scopes:** `IngestInput.scope`, `AccessOptions.scope`, `AskOptions.scope` (also in `askStream`
|
|
264
|
+
and `askGemini`) and `files.sweep({ scope })`, with the types `DocumentScope` and
|
|
265
|
+
`DocumentContext`. A document with a scope serves only a caller of the same scope
|
|
266
|
+
([Scopes](docs/guides/storage.md#scopes)).
|
|
267
|
+
- **`requireOwner` and `requireScope`** in `createLargeFiles`, both off: a call without an owner, or
|
|
268
|
+
without a scope, throws a `TypeError`. `files.access` says which are on
|
|
269
|
+
([Storage](docs/guides/storage.md#requiring-an-owner-and-a-scope)).
|
|
270
|
+
- **Application IDs:** `IngestInput.id`, `ifExists` (`"fail"` by default, or `"replace"`) and
|
|
271
|
+
`APP_DOCUMENT_ID_PATTERN` ([Application IDs](docs/guides/storage.md#application-ids)).
|
|
272
|
+
- **A folder per user and chat:** `FileDocumentStore`'s `scopes` option
|
|
273
|
+
(`{ depth, folder, createScopeFolders, unscoped }`) keeps each scope's files in
|
|
274
|
+
`<root>/<user>/<chat>/.llm-large-files/`, under one library for the process. Also its options
|
|
275
|
+
`fileMode`, `directoryMode` and `sweepConcurrency`, the types `FileDocumentStoreOptions` and
|
|
276
|
+
`FileDocumentScopes`, and `isSafeScopeSegment` and `hashedScopeSegment`
|
|
277
|
+
([Files in a folder per user or per chat](docs/guides/storage.md#files-in-a-folder-per-user-or-per-chat)).
|
|
278
|
+
- **`MemoryDocumentStore`** keeps each scope's documents apart.
|
|
279
|
+
- **`ToolOptions.access`:** `files.tools()` checks the owner and scope the store holds, not those
|
|
280
|
+
of the metadata it is given ([Your own loop](docs/guides/own-adapter-and-loop.md#your-own-loop)).
|
|
281
|
+
|
|
282
|
+
**Ingest**
|
|
283
|
+
|
|
284
|
+
- **Ingest from a path:** `files.ingest({ name, source: { path } })` (`IngestFromSource`,
|
|
285
|
+
`IngestSource`). The file is looked at with `lstat` at the call, and read once at its turn, so
|
|
286
|
+
ingests that wait hold none of their files: 100 ingests of 2 MB waiting for their turn held 73 MB
|
|
287
|
+
as paths, against 282 to 286 MB with their bytes
|
|
288
|
+
([IngestFromSource](docs/reference/library.md#ingestfromsource)).
|
|
289
|
+
- **Originals by reference:** `IngestInput.original: { ref }`, `LargeFilesOptions.originals`
|
|
290
|
+
(`OriginalsReader`, `OriginalReadContext`), and `fileOriginals(root)` in `llm-large-files/node`.
|
|
291
|
+
`meta.original` records the ref, the size and the SHA-256
|
|
292
|
+
([Storage](docs/guides/storage.md#the-file-your-application-keeps)).
|
|
293
|
+
- **`DocumentMeta.sha256`:** the SHA-256 of each upload, to find the same file twice in a chat. The
|
|
294
|
+
library does not dedupe.
|
|
295
|
+
- **`Extractor.readsPath`**, with `ExtractInput.path`, `ExtractInput.maxUploadBytes` and
|
|
296
|
+
`ExtractedText.file`: an extractor that reads the file itself. `createIsolatedExtractors` sets it
|
|
297
|
+
([Extractor](docs/reference/library.md#extractor)).
|
|
298
|
+
|
|
299
|
+
**Upload handlers** (`llm-large-files/node`)
|
|
300
|
+
|
|
301
|
+
- **`getScope(request)`:** the scope of each upload, get and delete
|
|
302
|
+
([node](docs/reference/node.md#what-getscope-returns)).
|
|
303
|
+
- **`onUploaded` and `onRemoved`:** record an upload in your database before it is answered, and a
|
|
304
|
+
removal after it. `{ answer }` joins the 201 and `ingest.finish.app`. Types `UploadedContext`,
|
|
305
|
+
`UploadedResult` and `RemovedContext`
|
|
306
|
+
([hooks](docs/reference/node.md#the-hooks-onuploaded-and-onremoved)).
|
|
307
|
+
- **`prepareUpload(request, { name, owner, scope })`:** the upload's ID, and a path where its body
|
|
308
|
+
is saved as it arrives, kept by reference with `original`. Types `PrepareUploadInfo` and
|
|
309
|
+
`PreparedUpload`, and `uploadFileMode` (`0o600`)
|
|
310
|
+
([Web app](docs/guides/web-app.md#save-each-upload-where-you-keep-it-prepareupload)).
|
|
311
|
+
- **`uploadSpool`** (`true`, or `UploadSpoolOptions`; off by default) and `maxSpooledUploadBytes`
|
|
312
|
+
(ten times `maxUploadBytes`): bodies over 1 MiB, or without a `Content-Length`, wait for their
|
|
313
|
+
ingest on disk ([spooling](docs/reference/node.md#spooling-uploadspool)).
|
|
314
|
+
- **`uploadAnswerOf(error)`** and `UploadAnswer`: how the handlers answer an error, for a route of
|
|
315
|
+
your own ([node](docs/reference/node.md#how-errors-are-answered)).
|
|
316
|
+
|
|
317
|
+
**Questions**
|
|
318
|
+
|
|
319
|
+
- **`onMissingDocuments`** in `askWithFiles`, `askStream` and `askGemini`: `"throw"` (the default),
|
|
320
|
+
`"drop"`, or a function that can ingest them again (`{ retry: true }`, `{ replace }`). Also
|
|
321
|
+
`AskResult.missing`, and the types `MissingDocumentsAction` and `MissingDocumentsContext`
|
|
322
|
+
([missing documents](docs/reference/ask.md#missing-documents)).
|
|
323
|
+
- **Notices** `"documents_missing"`, `"document_gone"` and `"page_looks_busy"`, and `documentIds`
|
|
324
|
+
on the `notice` event ([events](docs/reference/events.md#noticecode-and-noticedisplay)).
|
|
325
|
+
- **`maxConcurrentPageLooks`** (1) and **`pageLookWaitMs`** (30,000) in `createLargeFiles`. For
|
|
326
|
+
loops of your own: `ToolCallLimits.maxWaitMs`, and `ToolCallHooks.onDocumentGone` and
|
|
327
|
+
`onPagesBusy` ([library](docs/reference/library.md#largefilesoptions)).
|
|
328
|
+
- **`fromGeminiContents(contents, { rounds })`** and `FromGeminiContentsOptions`
|
|
329
|
+
([gemini](docs/reference/gemini.md#fromgeminicontentscontents-options)).
|
|
330
|
+
- **`AskGeminiOptions.messages` takes what `askWithFiles` takes (`ChatMessage[]`):** plain turns,
|
|
331
|
+
stored tool rounds, and turns with parts, such as `fromGeminiContents(contents, { rounds: false })`
|
|
332
|
+
gives. It was `Array<ChatTurn | ToolTurn>` ([gemini](docs/reference/gemini.md#askgeminioptions)).
|
|
333
|
+
|
|
334
|
+
**Errors and versions**
|
|
335
|
+
|
|
336
|
+
- **`errorInfoOf(error)`**, with `ErrorInfo` and `ErrorCategory`: one record for any error of the
|
|
337
|
+
library, or its `EventError`: a category, a code, the HTTP status, whether to retry and after how
|
|
338
|
+
long, and an English message that is safe to show. One `switch` maps it to your users' language
|
|
339
|
+
([Errors and reliability](docs/guides/errors-and-reliability.md#your-users-words-errorinfoof)).
|
|
340
|
+
- **`DocumentScopeError`** (`"scope_required"`, `"scope_invalid"`, `"scope_missing"`) and
|
|
341
|
+
`DocumentScopeErrorCode`. `DocumentStoreError` takes `{ operation, code }`, and has `operation`
|
|
342
|
+
(`DocumentStoreOperation`). `IngestErrorCode` `"exists"` (409).
|
|
343
|
+
- **A static `is(value)`** on `DocumentStoreError`, `DocumentScopeError`, `DocumentsNotFoundError`,
|
|
344
|
+
`IngestError` and `ModelRequestError`, which works across two copies of the package
|
|
345
|
+
([errors](docs/reference/errors-and-retries.md#telling-errors-apart-across-copies-of-the-package)).
|
|
346
|
+
- **`DOCUMENT_META_VERSION`** and **`TOOL_TURN_VERSION`**, and the fields `DocumentMeta.metaVersion`
|
|
347
|
+
and `ToolTurn.version` ([library](docs/reference/library.md#document_meta_version)).
|
|
348
|
+
|
|
349
|
+
**Testing**
|
|
350
|
+
|
|
351
|
+
- **`llm-large-files/testing`:** `fakeModel` (with `says`, `calls` and `httpError`), `fakeFetch`
|
|
352
|
+
(with `sse`), the test documents `utf8` and `serviceLog`, and `documentStoreChecks`, the checks a
|
|
353
|
+
store of your own must pass. It needs no test framework
|
|
354
|
+
([reference](docs/reference/testing.md), [guide](docs/guides/testing.md)).
|
|
355
|
+
|
|
356
|
+
One library for a chat server, with a folder per user and chat:
|
|
357
|
+
|
|
358
|
+
```ts
|
|
359
|
+
import { createLargeFiles, FileDocumentStore, hashedScopeSegment } from "llm-large-files";
|
|
360
|
+
import { createDocumentHandlers } from "llm-large-files/node";
|
|
361
|
+
|
|
362
|
+
const VOLUME = "/mnt/documents";
|
|
363
|
+
|
|
364
|
+
export const files = createLargeFiles({
|
|
365
|
+
store: new FileDocumentStore(VOLUME, { scopes: { depth: 2 } }), // <user>/<chat>/.llm-large-files/
|
|
366
|
+
keepOriginals: ["pdf"],
|
|
367
|
+
requireOwner: true,
|
|
368
|
+
requireScope: true,
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
// The scope is [hashedScopeSegment(userId), chatId]: a user ID may hold capitals or an "@", which
|
|
372
|
+
// cannot name a folder. Make the folder <VOLUME>/<user>/<chat> when you create the chat: the store
|
|
373
|
+
// makes only .llm-large-files inside it (createScopeFolders is off).
|
|
374
|
+
export const documents = createDocumentHandlers(files, {
|
|
375
|
+
getOwner: (request) => userIdOf(request),
|
|
376
|
+
getScope: (request) => [hashedScopeSegment(userIdOf(request)!), chatIdOf(request)],
|
|
377
|
+
});
|
|
378
|
+
// Ask with the same owner and scope: askGemini({ files, endpoint, owner: userId, scope: [hashedScopeSegment(userId), chatId], … }).
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
`userIdOf` is your sign-in, and `chatIdOf` one of the user's own chats, as an ID that passes
|
|
382
|
+
`isSafeScopeSegment`. To save each upload where you keep it and read it there, add
|
|
383
|
+
`prepareUpload` and `originals`, as the
|
|
384
|
+
[worked example](docs/upgrading-0.9.md#a-worked-example-a-hebrew-chatbot-on-gemini-mongodb-and-a-shared-volume)
|
|
385
|
+
does.
|
|
386
|
+
|
|
387
|
+
### Changed: what works differently
|
|
388
|
+
|
|
389
|
+
**Storage**
|
|
390
|
+
|
|
391
|
+
- One ID in two scopes is two documents everywhere, in memory too. The cache, the decoded pieces
|
|
392
|
+
and the documents being opened are kept per scope, and a copy is checked against the owner the
|
|
393
|
+
store holds. A delete or a re-ingest of an ID forgets its copies in every scope.
|
|
394
|
+
- An owner or a scope of `null` from a store (MongoDB writes left-out fields that way) counts as
|
|
395
|
+
absent. Metadata that a store returns for another ID than the one asked for reads as missing. So
|
|
396
|
+
does a text read whole whose length or number of lines is not what its metadata says, and a text
|
|
397
|
+
read by range whose index, built again, does not match its metadata: the index is built again
|
|
398
|
+
when none is saved, or when the text does not end where the saved one says. A store that writes
|
|
399
|
+
the text and the metadata apart can give one document's metadata with another's text, when two
|
|
400
|
+
servers ingest one ID at the same moment. Before, a text read whole was not checked, and an index
|
|
401
|
+
built again from a text that did not match its metadata was used. A text of the same length and
|
|
402
|
+
lines is not caught. Opening a document through its saved index reads one byte across the end of
|
|
403
|
+
its text: one `readTextRange` call more.
|
|
404
|
+
- The reads of a document's text (`get`, `readTextRange`, `getIndex`, and `putIndex` when an index
|
|
405
|
+
is built again) carry the caller's scope and the document's owner. `getMeta`, `getOriginal` and
|
|
406
|
+
`delete` carry the caller's ([Writing a store of your own](docs/guides/storage.md#writing-a-store-of-your-own)).
|
|
407
|
+
- After a tool call or `prepare` reads a document by range, and after `getOriginal` or `view_pages`
|
|
408
|
+
reads an original, the library calls `getMeta` once more. The read is missing unless the store
|
|
409
|
+
still describes the same document, of the same owner and scope. A kept original must also have
|
|
410
|
+
the document's size and, for documents of 0.9.0 and later, its SHA-256.
|
|
411
|
+
- `MemoryDocumentStore.getOriginal` returns a copy of the bytes (S7).
|
|
412
|
+
- `FileDocumentStore.sweep` reads 16 files at once (`sweepConcurrency`): 5,000 documents took about
|
|
413
|
+
1.1 s instead of 2.5 s on a local SSD. It counts only the documents whose metadata it removed
|
|
414
|
+
itself, and follows no link. In a folder shared with your files, it removes files of no document
|
|
415
|
+
only under the library's IDs, or temporary files.
|
|
416
|
+
- `FileDocumentStore` follows no link at a file name: such a document counts as missing. Windows
|
|
417
|
+
cannot refuse such a link, so there it is followed.
|
|
418
|
+
|
|
419
|
+
**Ingest**
|
|
420
|
+
|
|
421
|
+
- Every ingest hashes its upload with SHA-256, in 1 MB slices between other work: a few
|
|
422
|
+
milliseconds of CPU for each MB. 100 ingests of 2 MB logs took the same time in all as without it.
|
|
423
|
+
- `createIsolatedExtractors` reads a file ingested from a path in its child process, and the
|
|
424
|
+
server reads none of it, unless the store keeps a copy (`keepOriginals` with a store that has
|
|
425
|
+
`putOriginal`, and no `original`).
|
|
426
|
+
- `keepOriginals`, the acceptance of a scanned PDF and the offer of `view_pages` count a file kept
|
|
427
|
+
by reference when the library has `originals`.
|
|
428
|
+
|
|
429
|
+
**Upload handlers**
|
|
430
|
+
|
|
431
|
+
- `maxPendingUploadBytes` counts only the bodies held in memory: a body written to a file (the
|
|
432
|
+
spool, or the path of `prepareUpload`) takes no room of it.
|
|
433
|
+
- `uploadIdleTimeoutMs` (30 s) also bounds each disk call for a body written to a file: the check
|
|
434
|
+
of the folders of a ref, the opening, each write and the closing. A volume that stops answering
|
|
435
|
+
fails the upload with 500 `{ "error": "Upload failed (ETIMEDOUT)." }` and gives its room back. A
|
|
436
|
+
removal of such a file is waited for no longer than that, and then goes on alone. On a slow
|
|
437
|
+
network volume, raise `uploadIdleTimeoutMs`: a close can wait for the writes the system held back.
|
|
438
|
+
- An upload whose `request.body` holds an object with fields (`express.json()` in front) gets its
|
|
439
|
+
400 before the check of room.
|
|
440
|
+
- An ingest of your own that sends `ingest.finish` and then fails ends the event stream with
|
|
441
|
+
`ingest.error`.
|
|
442
|
+
- The `ingest.error` of the handlers names a store that failed (`"DocumentStoreError"`), documents
|
|
443
|
+
that are gone (`"DocumentsNotFoundError"`) and a scope error (`"DocumentScopeError"`, with its
|
|
444
|
+
code), and carries the `kind` of a model's error, so `errorInfoOf` reads it as the error.
|
|
445
|
+
- `sseMessageOf` sends `missing` in the result of `run.finish` and in the partial of `run.error`.
|
|
446
|
+
|
|
447
|
+
**Questions**
|
|
448
|
+
|
|
449
|
+
- Stored rounds that would make the first request larger than its room in tokens are shortened
|
|
450
|
+
before it is sent, for every model, Claude included. The request is what 0.8.2 sent after the
|
|
451
|
+
provider refused it, without the refused request.
|
|
452
|
+
- A function part kept in Gemini's own form is sized by the JSON of its call or response, a thought
|
|
453
|
+
signature included in bytes, not as media. A chat whose history is in `contents` may plan a file
|
|
454
|
+
as a card one question earlier.
|
|
455
|
+
- A result is not replaced by a stand-in as large as itself or larger.
|
|
456
|
+
- A tool call that finds a document gone during the question gives a `"document_gone"` notice.
|
|
457
|
+
- With `eventResults: true`, the full `DocumentMeta` in events also holds `scope`, `sha256` and
|
|
458
|
+
`original`, with its ref, as `AskResult.plan` does. Keep such events on your server.
|
|
459
|
+
|
|
460
|
+
**Errors**
|
|
461
|
+
|
|
462
|
+
- A model's `EventError` always has its `kind`. An error with a `status` of 0 or 400 to 599 and no
|
|
463
|
+
`kind` of its own gets the one `classifyModelError` gives its status, message and code. The
|
|
464
|
+
library's own errors with a status (`DocumentStoreError`, `DocumentsNotFoundError`, `IngestError`,
|
|
465
|
+
`DocumentScopeError`) get none.
|
|
466
|
+
- `withRetry` sends such an error again by that kind: a 429 of code `"insufficient_quota"` (a quota)
|
|
467
|
+
or a 429 "Request too large … tokens per min" (an overflow) is not sent again. Before, both were
|
|
468
|
+
sent again by their status. The library's own adapters do not change.
|
|
469
|
+
- The loop acts on that kind too. For such an error of kind `"context_overflow"` (an
|
|
470
|
+
`httpError(413)`, a 429 for the tokens a minute, a 400 of code `context_length_exceeded`), it makes
|
|
471
|
+
the request smaller, plans the documents again, or reads a part of a whole-file read as two
|
|
472
|
+
halves, with the numbers its message gives, as for a `ModelRequestError` of that kind. Before, the
|
|
473
|
+
question failed. The message of an error that is not an `Error` (an SDK's own class) gives its
|
|
474
|
+
kind too, in its event as in the loop and `errorInfoOf`.
|
|
475
|
+
- The `EventError` message of thrown plain data with a status, or of a status that is not a model's,
|
|
476
|
+
is "Something went wrong.".
|
|
477
|
+
- An extractor's own subclass of `IngestError` is named `"IngestError"` in its `EventError`, and a
|
|
478
|
+
store's subclass of `DocumentStoreError` `"DocumentStoreError"`, so `errorInfoOf` reads their
|
|
479
|
+
events.
|
|
480
|
+
|
|
481
|
+
**Release**
|
|
482
|
+
|
|
483
|
+
- Each release publishes the tarball CI checked, byte for byte. A job without npm's identity token
|
|
484
|
+
builds, tests and packs it, then checks it as npm installs it: with and without the optional
|
|
485
|
+
dependencies, `import` and `require()` of every subpath, an ingest in a child process of
|
|
486
|
+
`createIsolatedExtractors`, a consumer compiled under NodeNext, Bundler and Node10 with
|
|
487
|
+
`skipLibCheck: false`, publint and arethetypeswrong. A second job, the only one with the token,
|
|
488
|
+
stages that file with `npm stage publish` and provenance
|
|
489
|
+
([Publishing](docs/publishing.md#what-the-release-workflow-does)).
|
|
490
|
+
- The package is type-checked without the DOM library (`lib: ["ES2023"]`), as a server app compiles:
|
|
491
|
+
its declarations need only `@types/node`.
|
|
492
|
+
|
|
493
|
+
### Fixed
|
|
494
|
+
|
|
495
|
+
**Access and storage**
|
|
496
|
+
|
|
497
|
+
- **S3:** `files.tools()` given metadata read straight from the store (`await store.getMeta(id)`)
|
|
498
|
+
could read another user's document. With `access` it cannot, and `askWithFiles` always passes it.
|
|
499
|
+
- **S12:** a `LargeFiles` of your own whose `ingest` threw a database driver's error sent that
|
|
500
|
+
error's host to the browser, in a 422. An error that your store gave its own `status` reached the
|
|
501
|
+
client with its message too; it is now the `cause` of a `DocumentStoreError`.
|
|
502
|
+
- **A Node system error whose `code` is not a code** (a driver may put "db-prod.internal:27017"
|
|
503
|
+
there) gave that host in the upload answer, in its `ingest.error` and `run.error`, and in a tool
|
|
504
|
+
result sent to the model. A code is now told only when it reads as one: capitals, digits and `_`.
|
|
505
|
+
- **S11:** an upload's MIME type with CRLF, U+202E, tag characters or 8 KB of text was stored as
|
|
506
|
+
given, and reached the metadata, the summaries, `ingest.finish` and logs. The handler also
|
|
507
|
+
URI-decoded a `Content-Type` such as `text/plain%0D%0A…` into a line break.
|
|
508
|
+
- **S10:** `FileDocumentStore` files were readable by every user of the machine (`0664` under umask
|
|
509
|
+
`0002`).
|
|
510
|
+
- **S8:** `FileDocumentStore.getMeta`, `get` and `getOriginal` threw when an expired document could
|
|
511
|
+
not be removed, on every try, for a document that was gone. They return undefined, and `sweep`
|
|
512
|
+
tries again.
|
|
513
|
+
- **S9, LLF-027:** `files.delete` failed on Windows while another process held a file open for a
|
|
514
|
+
moment (`EBUSY`, `EPERM`), and threw when the metadata was gone but the text could not be removed.
|
|
515
|
+
- **An ingest whose caller left during the store write** still stored the document, never cleaned
|
|
516
|
+
under `ttlMs: Infinity`. Once the writes end, what they stored is now removed, and `ingest` throws
|
|
517
|
+
`signal.reason`. With the upload handlers, a client that leaves before its ingest ends leaves
|
|
518
|
+
nothing stored, and `onUploaded` is not called.
|
|
519
|
+
- **An owner of `null` from a store** read as missing in `getMeta`, and as open to all in the tools.
|
|
520
|
+
- **LLF-055:** the docs said renames are tried again for about three seconds; the pauses add up to
|
|
521
|
+
2.63 s.
|
|
522
|
+
- **LLF-022:** `examples/server.ts` listened on every interface, gave uploads no owner, so any
|
|
523
|
+
browser could read any upload by its ID, and kept chats by chat ID alone. It listens on 127.0.0.1
|
|
524
|
+
unless `HOST` is set, gives each browser a random `HttpOnly`, `SameSite=Strict` cookie as its
|
|
525
|
+
owner, runs with `requireOwner`, keeps chats by owner and chat, reads PDF and Office files with
|
|
526
|
+
`createIsolatedExtractors`, and says it is not for production as is. It also no longer crashes on
|
|
527
|
+
an unhandled rejection when the body of a chat request is cut off.
|
|
528
|
+
|
|
529
|
+
**Questions**
|
|
530
|
+
|
|
531
|
+
- A first request whose stored rounds were over the token limit was sent before anything was
|
|
532
|
+
shortened: one refused request per question on most models, and a failed question on Claude,
|
|
533
|
+
whose conversation may not be shortened.
|
|
534
|
+
- Function parts in a `contents` history were sized as media: about 15,000 tokens short in a test
|
|
535
|
+
of two calls, so planning left too little room.
|
|
536
|
+
- A stand-in could be larger than the result it replaced: 845 characters grew to 1,073, and 877 to
|
|
537
|
+
1,041.
|
|
538
|
+
- Six looks at pages at once ran together: each about four times slower, and 352 MB more than one
|
|
539
|
+
look (P10).
|
|
540
|
+
- A document that expired (`ttlMs`, 72 hours by default) failed the whole next question. With
|
|
541
|
+
`onMissingDocuments: "drop"`, the question is answered without it.
|
|
542
|
+
- The docs gave `tool_turns_left` as the only reason why the first request of a follow-up misses
|
|
543
|
+
the prompt cache. Stored rounds also drop the model's thought signatures and thinking blocks: the
|
|
544
|
+
docs say so now, and the change in code waits for 0.10.0.
|
|
545
|
+
|
|
546
|
+
**PDFs**
|
|
547
|
+
|
|
548
|
+
- **LLF-037:** in a right-to-left PDF table (Hebrew, Arabic), a Latin name or number that pdf.js
|
|
549
|
+
gives as several items was written backwards: a city cell of "New" and "York" read "York New", a
|
|
550
|
+
model "AB" + "-12" read "-12AB", and "8,300" + ",000" read ",0008,300". Each run of words in a
|
|
551
|
+
cell now reads in its own direction, and the runs follow the direction of the table. A Hebrew
|
|
552
|
+
phrase in several items inside a left-to-right table, also reversed before, reads right too. A
|
|
553
|
+
number before its unit or currency ("16 GB", "1,000 USD") reads as before. Documents ingested
|
|
554
|
+
before keep their text: upload such a PDF again.
|
|
555
|
+
|
|
556
|
+
**Uploads**
|
|
557
|
+
|
|
558
|
+
- Without a `Content-Length`, an upload took `maxUploadBytes` of room until it was read, so two
|
|
559
|
+
filled the default `maxPendingUploadBytes`, and a third got a 503 while they arrived. With
|
|
560
|
+
`uploadSpool` they wait on disk, and three or more fit.
|
|
561
|
+
- A client that left while `getOwner` ran, when a framework had already read the body
|
|
562
|
+
(`express.raw()` in front), was not noticed: its upload was ingested and stored for nobody. It now
|
|
563
|
+
stores nothing, as for a client that leaves later.
|
|
564
|
+
|
|
565
|
+
**Docs**
|
|
566
|
+
|
|
567
|
+
- [Deployment](docs/guides/deployment.md#memory-on-each-server) sized an ingest from figures
|
|
568
|
+
recorded before 0.6.0 (five to seven times the log above the upload), and gave 34 ms as its
|
|
569
|
+
longest stall, for a 99 MB log. Measured again on 0.9.0 with Node 22 on Linux, over a
|
|
570
|
+
`FileDocumentStore`, on a busy laptop: three and a half to five and a half times the log (135 MB
|
|
571
|
+
for 25 MB, 345 MB for 95 MB), and a longest stall of 56 to 64 ms for 25 MB and 0.23 to 0.36 s for
|
|
572
|
+
95 MB. The old figures stay in [Measurements](docs/measurements.md#the-server), marked as history.
|
|
573
|
+
|
|
39
574
|
## 0.8.2 — 2026-11-23
|
|
40
575
|
|
|
41
576
|
Memory when many users upload at once. A review of how the library holds files found that every
|
package/README.md
CHANGED
|
@@ -205,7 +205,7 @@ A large PDF goes to the model as text, and text cannot show a chart. Keep the up
|
|
|
205
205
|
the model gets a tool, `view_pages`, that hands it the pages it asks for as a small PDF:
|
|
206
206
|
|
|
207
207
|
```bash
|
|
208
|
-
npm install unpdf @cantoo/pdf-lib # Node 24; for Node
|
|
208
|
+
npm install unpdf @cantoo/pdf-lib # Node 24; for Node 22, see Requirements
|
|
209
209
|
```
|
|
210
210
|
|
|
211
211
|
```ts
|
|
@@ -306,6 +306,7 @@ Reference, one page per module:
|
|
|
306
306
|
- [`llm-large-files/openai`](docs/reference/openai.md): `openAiCompatible()` and its options.
|
|
307
307
|
- [`llm-large-files/anthropic`](docs/reference/anthropic.md): `anthropic()` and its options.
|
|
308
308
|
- [`llm-large-files/node`](docs/reference/node.md): `createDocumentHandlers`, its routes and responses, `createIsolatedExtractors`.
|
|
309
|
+
- [`llm-large-files/testing`](docs/reference/testing.md): `fakeModel` and `fakeFetch`, for your tests (new in 0.9.0).
|
|
309
310
|
|
|
310
311
|
[Changelog](CHANGELOG.md): what each version changed, and what to change in your code when you upgrade.
|
|
311
312
|
|
|
@@ -315,21 +316,19 @@ maintainers: [Contributing](https://github.com/renanbazinin/llm-large-files/blob
|
|
|
315
316
|
|
|
316
317
|
## Requirements
|
|
317
318
|
|
|
318
|
-
Node.js
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
319
|
+
Node.js 22.12 or newer. The package is ESM, and CommonJS code can `require()` it. For DOCX, PPTX
|
|
320
|
+
and XLSX install `jszip`, for PDF install `unpdf`, and to mark and show the pages of a PDF, and
|
|
321
|
+
refuse a page built to hold the server before it is read, install `@cantoo/pdf-lib`. All three are
|
|
322
|
+
optional:
|
|
322
323
|
|
|
323
324
|
```bash
|
|
324
325
|
npm install jszip unpdf @cantoo/pdf-lib # Node 24 and later
|
|
325
326
|
npm install jszip unpdf@1 @cantoo/pdf-lib # Node 22
|
|
326
|
-
npm install jszip unpdf@1.7.0 @cantoo/pdf-lib # Node 20
|
|
327
327
|
```
|
|
328
328
|
|
|
329
|
-
On Node 24 and later, `npm install unpdf` installs unpdf 2, which asks for Node 24. On Node
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
what to install.
|
|
329
|
+
On Node 24 and later, `npm install unpdf` installs unpdf 2, which asks for Node 24. On Node 22, the
|
|
330
|
+
pdf.js of unpdf 1.5.0 to 1.6.0 would stop the whole process. Such an unpdf is refused at the first
|
|
331
|
+
PDF, with a message that says what to install.
|
|
333
332
|
|
|
334
333
|
## License
|
|
335
334
|
|