llm-large-files 0.9.0 → 0.10.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 +446 -0
- package/README.md +13 -7
- package/dist/access.d.ts +45 -3
- package/dist/access.d.ts.map +1 -1
- package/dist/access.js +106 -3
- package/dist/access.js.map +1 -1
- package/dist/aggregate.d.ts +6 -0
- package/dist/aggregate.d.ts.map +1 -1
- package/dist/aggregate.js +86 -13
- package/dist/aggregate.js.map +1 -1
- package/dist/analyze.d.ts +4 -0
- package/dist/analyze.d.ts.map +1 -1
- package/dist/analyze.js +2 -2
- package/dist/analyze.js.map +1 -1
- package/dist/answer-info.d.ts +26 -0
- package/dist/answer-info.d.ts.map +1 -0
- package/dist/answer-info.js +32 -0
- package/dist/answer-info.js.map +1 -0
- package/dist/anthropic/adapter.d.ts +5 -1
- package/dist/anthropic/adapter.d.ts.map +1 -1
- package/dist/anthropic/adapter.js +35 -10
- package/dist/anthropic/adapter.js.map +1 -1
- package/dist/ask.d.ts +115 -14
- package/dist/ask.d.ts.map +1 -1
- package/dist/ask.js +572 -103
- package/dist/ask.js.map +1 -1
- package/dist/citations.d.ts +36 -0
- package/dist/citations.d.ts.map +1 -0
- package/dist/citations.js +291 -0
- package/dist/citations.js.map +1 -0
- package/dist/error-info.d.ts +13 -0
- package/dist/error-info.d.ts.map +1 -1
- package/dist/error-info.js +37 -1
- package/dist/error-info.js.map +1 -1
- package/dist/errors.d.ts +3 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +3 -1
- package/dist/errors.js.map +1 -1
- package/dist/events.d.ts +25 -7
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js.map +1 -1
- package/dist/evidence.d.ts.map +1 -1
- package/dist/evidence.js +21 -2
- package/dist/evidence.js.map +1 -1
- package/dist/extract.d.ts.map +1 -1
- package/dist/extract.js +6 -1
- package/dist/extract.js.map +1 -1
- package/dist/gemini/adapter.d.ts +35 -4
- package/dist/gemini/adapter.d.ts.map +1 -1
- package/dist/gemini/adapter.js +68 -29
- package/dist/gemini/adapter.js.map +1 -1
- package/dist/gemini/chat.d.ts +28 -55
- package/dist/gemini/chat.d.ts.map +1 -1
- package/dist/gemini/chat.js +20 -27
- package/dist/gemini/chat.js.map +1 -1
- package/dist/gemini/endpoints.d.ts +59 -11
- package/dist/gemini/endpoints.d.ts.map +1 -1
- package/dist/gemini/endpoints.js +33 -7
- package/dist/gemini/endpoints.js.map +1 -1
- package/dist/gemini/errors.d.ts +39 -5
- package/dist/gemini/errors.d.ts.map +1 -1
- package/dist/gemini/errors.js +70 -9
- package/dist/gemini/errors.js.map +1 -1
- package/dist/gemini/generate.d.ts +53 -2
- package/dist/gemini/generate.d.ts.map +1 -1
- package/dist/gemini/generate.js +100 -50
- package/dist/gemini/generate.js.map +1 -1
- package/dist/gemini/index.d.ts +3 -3
- package/dist/gemini/index.d.ts.map +1 -1
- package/dist/http.d.ts +41 -3
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +40 -2
- package/dist/http.js.map +1 -1
- package/dist/index.d.ts +6 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/ingest.d.ts +9 -1
- package/dist/ingest.d.ts.map +1 -1
- package/dist/ingest.js +50 -25
- package/dist/ingest.js.map +1 -1
- package/dist/library.d.ts +129 -2
- package/dist/library.d.ts.map +1 -1
- package/dist/library.js +224 -149
- package/dist/library.js.map +1 -1
- package/dist/map-reduce.d.ts +176 -10
- package/dist/map-reduce.d.ts.map +1 -1
- package/dist/map-reduce.js +804 -58
- package/dist/map-reduce.js.map +1 -1
- package/dist/model.d.ts +36 -4
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +17 -1
- package/dist/model.js.map +1 -1
- package/dist/node/handlers.d.ts +29 -8
- package/dist/node/handlers.d.ts.map +1 -1
- package/dist/node/handlers.js +148 -126
- package/dist/node/handlers.js.map +1 -1
- package/dist/node/index.d.ts +1 -1
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js.map +1 -1
- package/dist/node/ingest-child.js +2 -2
- package/dist/node/ingest-child.js.map +1 -1
- package/dist/node/spool.d.ts +9 -5
- package/dist/node/spool.d.ts.map +1 -1
- package/dist/node/spool.js +28 -15
- package/dist/node/spool.js.map +1 -1
- package/dist/node/sse.d.ts +6 -5
- package/dist/node/sse.d.ts.map +1 -1
- package/dist/node/sse.js +8 -7
- package/dist/node/sse.js.map +1 -1
- package/dist/openai/adapter.d.ts +5 -1
- package/dist/openai/adapter.d.ts.map +1 -1
- package/dist/openai/adapter.js +53 -12
- package/dist/openai/adapter.js.map +1 -1
- package/dist/output-limit.d.ts +2 -1
- package/dist/output-limit.d.ts.map +1 -1
- package/dist/output-limit.js +5 -2
- package/dist/output-limit.js.map +1 -1
- package/dist/pdf-outline.d.ts +71 -0
- package/dist/pdf-outline.d.ts.map +1 -0
- package/dist/pdf-outline.js +414 -0
- package/dist/pdf-outline.js.map +1 -0
- package/dist/plan.d.ts +137 -7
- package/dist/plan.d.ts.map +1 -1
- package/dist/plan.js +248 -26
- package/dist/plan.js.map +1 -1
- package/dist/prepare.d.ts +50 -0
- package/dist/prepare.d.ts.map +1 -0
- package/dist/prepare.js +207 -0
- package/dist/prepare.js.map +1 -0
- package/dist/ranged.d.ts +2 -1
- package/dist/ranged.d.ts.map +1 -1
- package/dist/ranged.js +16 -3
- package/dist/ranged.js.map +1 -1
- package/dist/search.d.ts +7 -0
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +72 -10
- package/dist/search.js.map +1 -1
- package/dist/stores.d.ts +6 -0
- package/dist/stores.d.ts.map +1 -1
- package/dist/stores.js +82 -11
- package/dist/stores.js.map +1 -1
- package/dist/tools.d.ts +22 -2
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +323 -76
- package/dist/tools.js.map +1 -1
- package/dist/types.d.ts +49 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/whole-cost.d.ts +37 -0
- package/dist/whole-cost.d.ts.map +1 -0
- package/dist/whole-cost.js +46 -0
- package/dist/whole-cost.js.map +1 -0
- package/docs/README.md +4 -0
- package/docs/guides/anthropic.md +5 -2
- package/docs/guides/conversations.md +1 -1
- package/docs/guides/costs-and-limits.md +132 -36
- package/docs/guides/deployment.md +106 -13
- package/docs/guides/errors-and-reliability.md +157 -45
- package/docs/guides/explorer-model.md +4 -1
- package/docs/guides/openai-compatible.md +47 -7
- package/docs/guides/own-adapter-and-loop.md +33 -6
- package/docs/guides/pdfs.md +96 -7
- package/docs/guides/storage.md +46 -3
- package/docs/guides/testing.md +71 -0
- package/docs/guides/vertex-and-gemini.md +159 -50
- package/docs/guides/web-app.md +10 -6
- package/docs/how-it-works.md +120 -22
- package/docs/measurements.md +172 -5
- package/docs/publishing.md +76 -4
- package/docs/reference/anthropic.md +12 -7
- package/docs/reference/ask.md +262 -35
- package/docs/reference/errors-and-retries.md +30 -2
- package/docs/reference/events.md +27 -10
- package/docs/reference/gemini.md +184 -68
- package/docs/reference/library.md +190 -23
- package/docs/reference/node.md +51 -17
- package/docs/reference/openai.md +21 -10
- package/docs/reference/tools.md +271 -26
- package/docs/security.md +101 -12
- package/docs/troubleshooting.md +14 -12
- package/docs/upgrading-0.10.md +472 -0
- package/package.json +5 -1
- package/src/access.ts +127 -4
- package/src/aggregate.ts +92 -14
- package/src/analyze.ts +2 -2
- package/src/answer-info.ts +45 -0
- package/src/anthropic/adapter.ts +40 -11
- package/src/ask.ts +646 -106
- package/src/citations.ts +294 -0
- package/src/error-info.ts +36 -1
- package/src/errors.ts +3 -1
- package/src/events.ts +29 -6
- package/src/evidence.ts +21 -2
- package/src/extract.ts +6 -1
- package/src/gemini/adapter.ts +99 -32
- package/src/gemini/chat.ts +53 -82
- package/src/gemini/endpoints.ts +89 -16
- package/src/gemini/errors.ts +74 -11
- package/src/gemini/generate.ts +147 -57
- package/src/gemini/index.ts +3 -3
- package/src/http.ts +65 -4
- package/src/index.ts +6 -4
- package/src/ingest.ts +58 -27
- package/src/library.ts +336 -142
- package/src/map-reduce.ts +855 -67
- package/src/model.ts +44 -4
- package/src/node/handlers.ts +159 -118
- package/src/node/index.ts +1 -0
- package/src/node/ingest-child.ts +2 -2
- package/src/node/spool.ts +28 -14
- package/src/node/sse.ts +8 -7
- package/src/openai/adapter.ts +56 -13
- package/src/output-limit.ts +5 -2
- package/src/pdf-outline.ts +400 -0
- package/src/plan.ts +287 -36
- package/src/prepare.ts +253 -0
- package/src/ranged.ts +16 -3
- package/src/search.ts +69 -13
- package/src/stores.ts +76 -11
- package/src/tools.ts +327 -75
- package/src/types.ts +45 -1
- package/src/whole-cost.ts +64 -0
package/docs/reference/node.md
CHANGED
|
@@ -142,7 +142,7 @@ The options of [`createDocumentHandlers()`](#createdocumenthandlersfiles-options
|
|
|
142
142
|
| `maxSpooledUploadBytes` | `number` | ten times `files.maxUploadBytes` (1 GB by default) | New in 0.9.0. The most bytes of the spool's files at once, counted as `maxPendingUploadBytes` counts memory. An upload that would pass it is answered `503` with `Retry-After: 5` before its body is read. `Infinity` for no limit. A value that is not a number above 0 throws a `RangeError`. |
|
|
143
143
|
| `uploadFileMode` | `number` | `0o600` | New in 0.9.0. The mode of the files saved to the `path` of `prepareUpload`, minus the umask of the process. `0o640` lets a group read them: pods of another user that share the volume through a group (`fsGroup`). The spool's files are always `0o600`. |
|
|
144
144
|
| `maxPendingUploadBytes` | `number` | twice `files.maxUploadBytes` (200 MB by default) | The most bytes of uploads these handlers hold in memory at once. Since 0.9.0 a body written to a file (the `path` of `prepareUpload`, or `uploadSpool`) does not count. An upload is held whole in memory from the moment its body is read until its ingest ends (on the event-stream path too, also after its client went away). Since 0.9.0 its room is given back, and the body the handler read is freed, before `onUploaded` runs: a hook that waits on your database holds neither. Its room is taken before its body is read: its `Content-Length`, or, when it declares none, `maxUploadBytes` (at most this limit) until the body is read, then its size. One that would bring the uploads held past the limit, while another is held, is answered `503` with `Retry-After: 5` before its body is read (the body is drained as for a `413`); one upload alone is always taken. A client that sends its headers and then nothing holds its room until `uploadIdleTimeoutMs` ends it. `Infinity` for no limit, as before 0.8.2. A value that is not a number above 0 throws a `RangeError` when the handlers are made. New in 0.8.2. |
|
|
145
|
-
| `uploadIdleTimeoutMs` | `number` | 30,000 | How long the body of an upload may stop arriving. Past it, the upload is answered `408` `{ "error": "The upload stopped arriving: nothing came for 30 s. Send it again." }` with `Connection: close`, the connection is closed, and the upload's room is given back. It bounds the wait for each piece of the body, not the whole upload: Node's `server.requestTimeout` (300 s by default) bounds that. Since 0.9.0, for a body written to a file (the `path` of `prepareUpload`, or `uploadSpool`), it also bounds each call to the disk: the check of its folders for a link (a `path` with a ref), the opening of the file, each write, and its closing. A volume that stops answering then fails the upload with `
|
|
145
|
+
| `uploadIdleTimeoutMs` | `number` | 30,000 | How long the body of an upload may stop arriving. Past it, the upload is answered `408` `{ "error": "The upload stopped arriving: nothing came for 30 s. Send it again." }` with `Connection: close`, the connection is closed, and the upload's room is given back. It bounds the wait for each piece of the body, not the whole upload: Node's `server.requestTimeout` (300 s by default) bounds that. Since 0.9.0, for a body written to a file (the `path` of `prepareUpload`, or `uploadSpool`), it also bounds each call to the disk: the check of its folders for a link (a `path` with a ref), the opening of the file, each write, and its closing. A volume that stops answering then fails the upload with `503` `{ "error": "Upload failed (ETIMEDOUT)." }` and `Retry-After: 5` (since 0.10.0; a `500` before), and its room is given back. A call to the disk past this time counts as stuck in the process until it ends, as a store call past `storeTimeoutMs` does ([`files.stats().stuckStoreCalls`](./library.md#largefilesstats), new in 0.10.0). The removal of the file is waited for no longer either: past it, the removal goes on alone, and the upload is answered all the same. 0 or `Infinity` for no limit. A value below 0 throws a `RangeError`. New in 0.8.2. |
|
|
146
146
|
|
|
147
147
|
What `getOwner` returns decides what each handler does:
|
|
148
148
|
|
|
@@ -229,7 +229,8 @@ const documents = createDocumentHandlers(files, {
|
|
|
229
229
|
event-stream path it is `ingest.finish`'s `app` field. Anything it returns without an `answer`
|
|
230
230
|
(a database's own result) adds nothing.
|
|
231
231
|
- **When it throws,** or returns an `answer` that is not a plain object JSON can hold, the document
|
|
232
|
-
is deleted (best effort: a delete that fails is not told
|
|
232
|
+
is deleted (best effort: a delete that fails is not told; since 0.10.0 it is waited for within the
|
|
233
|
+
library's `storeTimeoutMs`, then goes on alone), and the file saved to the `path` of
|
|
233
234
|
[`prepareUpload`](#saving-the-body-prepareupload) is removed. The upload is then answered as an
|
|
234
235
|
error of `ingest` is ([`uploadAnswerOf`](#uploadansweroferror)): an error with a `status` from
|
|
235
236
|
400 to 599 gives that status and its message, and any other error a `500`
|
|
@@ -359,16 +360,17 @@ With a `path`:
|
|
|
359
360
|
before it reads the body. A link among them is answered `500`
|
|
360
361
|
`{ "error": "Upload failed (ELOOP)." }`, and nothing is written. The root itself may be a link,
|
|
361
362
|
as for `fileOriginals`. A ref that is not the end of the path is not checked. The check is
|
|
362
|
-
waited for no longer than `uploadIdleTimeoutMs`: a volume that stops answering is answered `
|
|
363
|
-
`{ "error": "Upload failed (ETIMEDOUT)." }
|
|
363
|
+
waited for no longer than `uploadIdleTimeoutMs`: a volume that stops answering is answered `503`
|
|
364
|
+
`{ "error": "Upload failed (ETIMEDOUT)." }` with `Retry-After: 5` (a `500` before 0.10.0), and
|
|
365
|
+
nothing is written.
|
|
364
366
|
- **The body is written as it arrives,** under the same limits as in memory: a body over
|
|
365
367
|
`maxUploadBytes` is answered `413`, and one that stops arriving for `uploadIdleTimeoutMs` `408`.
|
|
366
368
|
A disk that is full (`ENOSPC`, `EDQUOT`) is answered `503`
|
|
367
369
|
`{ "error": "The server has no room for this file right now. Try again later." }` with
|
|
368
370
|
`Retry-After: 30`. Each call to the disk (the opening, each write, the closing) is waited for no
|
|
369
|
-
longer than `uploadIdleTimeoutMs`: a volume that stops answering is answered `
|
|
370
|
-
`{ "error": "Upload failed (ETIMEDOUT)." }
|
|
371
|
-
written whole.
|
|
371
|
+
longer than `uploadIdleTimeoutMs`: a volume that stops answering is answered `503`
|
|
372
|
+
`{ "error": "Upload failed (ETIMEDOUT)." }` with `Retry-After: 5` (a `500` before 0.10.0). A body
|
|
373
|
+
a framework already read (`express.raw()`) is written whole.
|
|
372
374
|
- **It is ingested from the file:** `files.ingest({ name, source: { path }, id, original, … })`
|
|
373
375
|
([`IngestFromSource`](./library.md#ingestfromsource)). The body is never held in memory, and the
|
|
374
376
|
upload takes no room of `maxPendingUploadBytes` or `maxSpooledUploadBytes`: it is on your disk.
|
|
@@ -430,7 +432,8 @@ const documents = createDocumentHandlers(files, {
|
|
|
430
432
|
is removed. One that would pass the limit while others hold room is answered `503` with
|
|
431
433
|
`Retry-After: 5` before its body is read; one upload alone is always taken. A disk that is full is
|
|
432
434
|
answered `503` with `Retry-After: 30`, and the file is removed. A disk that does not answer within
|
|
433
|
-
`uploadIdleTimeoutMs` is answered `
|
|
435
|
+
`uploadIdleTimeoutMs` is answered `503` "Upload failed (ETIMEDOUT)." (a `500` before 0.10.0), and
|
|
436
|
+
gives the room back.
|
|
434
437
|
- **Memory.** `maxPendingUploadBytes` then counts only the bodies held in memory. In memory, a body
|
|
435
438
|
without a `Content-Length` takes `maxUploadBytes` of room until it is read, so two of them filled
|
|
436
439
|
the default room and a third was answered `503`. Spooled, they take room on disk.
|
|
@@ -483,11 +486,13 @@ type DocumentHandlers = {
|
|
|
483
486
|
upload(request: IncomingMessage, response: ServerResponse): Promise<void>;
|
|
484
487
|
get(request: IncomingMessage, response: ServerResponse, id: string): Promise<void>;
|
|
485
488
|
remove(request: IncomingMessage, response: ServerResponse, id: string): Promise<void>;
|
|
489
|
+
stats(): DocumentHandlerStats; // new in 0.10.0
|
|
486
490
|
};
|
|
487
491
|
```
|
|
488
492
|
|
|
489
493
|
What [`createDocumentHandlers()`](#createdocumenthandlersfiles-options) returns. Each handler's
|
|
490
|
-
promise resolves once the response is written; none rejects.
|
|
494
|
+
promise resolves once the response is written; none rejects. `stats()` reads counters
|
|
495
|
+
([handlers.stats()](#handlersstats)).
|
|
491
496
|
|
|
492
497
|
| Handler | Route it for | What it does |
|
|
493
498
|
|---|---|---|
|
|
@@ -541,8 +546,9 @@ What it does, in order:
|
|
|
541
546
|
6. Reads the body, up to `files.maxUploadBytes`: into memory, or, new in 0.9.0, into a file as it
|
|
542
547
|
arrives, at the `path` of `prepareUpload` or in the spool (`uploadSpool`). A file is made new
|
|
543
548
|
(`"wx"`): one already at the path is answered `409`, a disk that is full `503` with
|
|
544
|
-
`Retry-After: 30`, and a call to the disk that does not end within `uploadIdleTimeoutMs` `
|
|
545
|
-
"Upload failed (ETIMEDOUT).". On any failure of the body, the file is
|
|
549
|
+
`Retry-After: 30`, and a call to the disk that does not end within `uploadIdleTimeoutMs` `503`
|
|
550
|
+
"Upload failed (ETIMEDOUT)." (a `500` before 0.10.0). On any failure of the body, the file is
|
|
551
|
+
removed.
|
|
546
552
|
- a `Uint8Array` or `Buffer` that a framework left in `request.body` (`express.raw()`) is used
|
|
547
553
|
as the file, with the same limit;
|
|
548
554
|
- an object with fields in `request.body` (`express.json()` on a JSON request) is answered
|
|
@@ -600,8 +606,8 @@ The responses:
|
|
|
600
606
|
| `500` | `{ "error": "Upload failed (no scope)." }` | The library has `requireScope`, and `getScope` returned `undefined`. The body is not read. New in 0.9.0. |
|
|
601
607
|
| `500` | `{ "error": "Upload failed (owner is not a string)." }` | `getOwner` returned, from JavaScript, something that is neither a string nor a finite number: an object such as `req.user`, `true`, `NaN`, an array. The body is not read. New in 0.6.0. |
|
|
602
608
|
| `500` | `{ "error": "Upload failed (ELOOP)." }` | `prepareUpload` gave a `path` that ends with the ref of its `original`, and a folder between that root and the file is a link: `fileOriginals` would never read the file back. Nothing is written, and the body is not read. New in 0.9.0. |
|
|
603
|
-
| `
|
|
604
|
-
| `500` | `{ "error": "Upload failed (
|
|
609
|
+
| `503` | `{ "error": "Upload failed (ETIMEDOUT)." }`, with `Retry-After: 5` | A call to the disk for the file of `prepareUpload` or of the spool (the check of its folders for a link, its opening, a write, its closing) did not end within `uploadIdleTimeoutMs`: the volume stopped answering. The upload's room is given back, and the file is removed at once, or once the volume answers. When the check of the folders did not end, nothing is written. New in 0.9.0, a `503` since 0.10.0 (it was a `500`). Also a path upload whose read did not answer within `ingestTimeoutMs` (new in 0.10.0: it was a `422` "took too long to read"), and any other system error that says the disk or a service could not answer just now ([How errors are answered](#how-errors-are-answered)). |
|
|
610
|
+
| `500` | `{ "error": "Upload failed (EACCES)." }` | An extractor of your own failed with a Node system error, one with a `code` and a `syscall`; or the file of `prepareUpload` or of the spool could not be made, as `"Upload failed (ENOENT)."` for a folder that is not there (new in 0.9.0). Only the code is passed on, and only when it reads as one (capitals, digits and `_`): since 0.9.0 a code that does not, such as a host a driver put in `code`, is left out, and the answer is "Upload failed.". Since 0.10.0 a code that says the disk or a service could not answer just now (`ETIMEDOUT`, `EBUSY`, `ECONNRESET` and the others under [How errors are answered](#how-errors-are-answered)), or a full disk (`ENOSPC`, `EDQUOT`), is a `503` with `Retry-After` instead, in the same words: `{ "error": "Upload failed (ENOSPC)." }` with `Retry-After: 30`. |
|
|
605
611
|
| `500` | `{ "error": "Upload failed." }` | `getOwner`, `getScope` or `prepareUpload` threw an error without a status, or `prepareUpload` returned a value that is not a `PreparedUpload` (a relative path, an ID that is not a string, a ref without a path): the body is not read (`prepareUpload` is new in 0.9.0). Or the request body could not be read: the client went away, or a proxy cut the upload. Node's error for a client that went away has a `code` (`ECONNRESET`) but no `syscall`, so no code is added. An error of one of these kinds that has a `code` and a `syscall` is answered as in the row above, with its code. |
|
|
606
612
|
| `500` | `{ "error": "Upload failed." }` | `files.ingest` or `onUploaded` threw an error that is none of the above: not an `IngestError`, with no status and no system error's `code` and `syscall`. Its message is not sent: it may name a host, as a database driver's does. A `DocumentScopeError` of code `"scope_invalid"` or `"scope_required"`, the server's mistake, is answered so too. New in 0.9.0: an `Error` of a `LargeFiles` of your own was answered `422` with its message (S12). So is a value that is not an `Error` (an extractor of your own that throws a string, say), as before. |
|
|
607
613
|
|
|
@@ -643,7 +649,7 @@ refusal or a bad owner from `getOwner` (its status, `401` or `500`), a refusal o
|
|
|
643
649
|
return (its status, or `500`; new in 0.9.0), a body another middleware parsed (`400`), a file over
|
|
644
650
|
`maxUploadBytes` (`413`), an upload that finds no room (`503`, new in 0.8.2), a file already at the
|
|
645
651
|
path of `prepareUpload` (`409`), a link in the folders of a path with a ref (`500` "ELOOP"), a full
|
|
646
|
-
disk (`503`) or a disk that does not answer (`
|
|
652
|
+
disk (`503`) or a disk that does not answer (`503` "ETIMEDOUT", a `500` before 0.10.0), all new in 0.9.0, and a body that
|
|
647
653
|
stops arriving (`408`, new in 0.8.2). Only a file that passes them is answered `200`
|
|
648
654
|
with the event-stream headers of [`writeSseEvents()`](#writesseeventsresponse-events-options) and
|
|
649
655
|
a `: keep-alive` comment every 15 seconds.
|
|
@@ -739,6 +745,33 @@ which removes it from the store: its text, its index and any kept original, as f
|
|
|
739
745
|
| `500` | `{ "error": "The file could not be deleted (invalid scope)." }` | `getScope` returned a scope that is not valid; "(no scope)" for none under `requireScope`. New in 0.9.0. |
|
|
740
746
|
| `500` | `{ "error": "The file could not be deleted." }` | `getOwner`, `getScope` or `onRemoved` threw an error without a status. |
|
|
741
747
|
|
|
748
|
+
Since 0.10.0 the delete has a time limit: the library's `storeTimeoutMs` (30 s by default), for the
|
|
749
|
+
look-up, the wait for the turn of the library's deletes (one at a time) and the store's `delete`
|
|
750
|
+
together, so that the answer comes within it. A store that does not answer within it is answered
|
|
751
|
+
`503` `{ "error": "The document could not be deleted (ETIMEDOUT). Try again." }` (or "The document
|
|
752
|
+
store could not be read (ETIMEDOUT). Try again." for the look-up), with `Retry-After: 5`; the
|
|
753
|
+
delete goes on alone. While the process has `maxStuckStoreCalls` calls stuck, the answer is the same `503`,
|
|
754
|
+
with code `STORE_STUCK`, at once. Before, a store that never answered left the request unanswered.
|
|
755
|
+
|
|
756
|
+
#### handlers.stats()
|
|
757
|
+
|
|
758
|
+
```ts
|
|
759
|
+
type DocumentHandlerStats = { memoryBytes: number; spooledBytes: number; uploadsInFlight: number };
|
|
760
|
+
```
|
|
761
|
+
|
|
762
|
+
New in 0.10.0. Counters of these handlers, for metrics and alerts. It reads counters only, and
|
|
763
|
+
never waits.
|
|
764
|
+
|
|
765
|
+
| Field | What it holds |
|
|
766
|
+
|---|---|
|
|
767
|
+
| `memoryBytes` | The bytes of the bodies of uploads held in memory now, as counted against `maxPendingUploadBytes` (also when that is `Infinity`). |
|
|
768
|
+
| `spooledBytes` | The bytes of the files of the spool now (`uploadSpool`), as counted against `maxSpooledUploadBytes` (also when that is `Infinity`). A file saved to the `path` of `prepareUpload` is not counted. |
|
|
769
|
+
| `uploadsInFlight` | The uploads these handlers are answering now, from the request to the answer, `onUploaded` included. |
|
|
770
|
+
|
|
771
|
+
With [`files.stats()`](./library.md#filesstats) it feeds a readiness probe: fail it when this pod
|
|
772
|
+
is saturated (uploads in flight past a bound), not when the shared store hangs for a moment
|
|
773
|
+
([Deployment](../guides/deployment.md#a-store-that-stops-answering)).
|
|
774
|
+
|
|
742
775
|
## How errors are answered
|
|
743
776
|
|
|
744
777
|
The three handlers answer an error by one rule, [`uploadAnswerOf`](#uploadansweroferror). Since
|
|
@@ -748,12 +781,13 @@ knows them when another copy of the package made them:
|
|
|
748
781
|
| Error | Status | `{ "error": … }` |
|
|
749
782
|
|---|---|---|
|
|
750
783
|
| [`IngestError`](./library.md#ingesterror): a file that could not be read | Its `status`: 422, 413 for `"too_large"`, 409 for `"exists"`, 503 for `"busy"` (with `Retry-After`, its `retryAfterMs` in seconds) | Its message, written for the user. A `413` gets the size message of `upload`. A file of code `"unreadable"` gets "This file could not be read. It may be damaged, or not of the type its name says.": its message is a parser's, or an extractor's of your own (new in 0.9.0). |
|
|
751
|
-
| [`DocumentStoreError`](./library.md#documentstoreerror): the store failed | 503, with `Retry-After: 5` | Its message, which names what failed and a code, never a path or a host. |
|
|
784
|
+
| [`DocumentStoreError`](./library.md#documentstoreerror): the store failed, did not answer within `storeTimeoutMs` (code `ETIMEDOUT`, new in 0.10.0), or was not called because too many calls are stuck (`STORE_STUCK`, new in 0.10.0) | 503, with `Retry-After: 5` | Its message, which names what failed and a code, never a path or a host. |
|
|
752
785
|
| [`DocumentScopeError`](./library.md#documentscopeerror) `"scope_missing"`: the chat's folder is gone | 404 | "This chat no longer exists." |
|
|
753
786
|
| `DocumentScopeError` `"scope_invalid"` or `"scope_required"`: the server's mistake | 500 | What failed: "Upload failed.", "The file could not be looked up.", "The file could not be deleted." |
|
|
754
787
|
| A model's error (`ModelRequestError`, or any error with a `kind`) | The status of [`errorInfoOf`](./errors-and-retries.md#errorinfooferror) (429 for `"rate_limit"`, with `Retry-After` when the provider named a wait; 502, 503, 504, 413 or 500 for the others) | `errorInfoOf`'s words ("The model was busy (HTTP 429)."), never the provider's, which can name a project or a key. |
|
|
755
788
|
| Any other `Error` whose `status`, or else `statusCode`, is a whole number from 400 to 599 (`http-errors`) | That status. A `503` whose error has a `retryAfterMs` gets `Retry-After`. | Its message, or what failed when it is empty. |
|
|
756
|
-
| A Node system error (a `code` and a `syscall`), such as a path `ingest({ source: { path } })` does not read: a link (`ELOOP`), a folder (`EISDIR`), a pipe (`EINVAL`), a file that is not there (`ENOENT`)
|
|
789
|
+
| A Node system error (a `code` and a `syscall`), such as a path `ingest({ source: { path } })` does not read: a link (`ELOOP`), a folder (`EISDIR`), a pipe (`EINVAL`), a file that is not there (`ENOENT`) | 500 | What failed, with the code: "Upload failed (ELOOP).". Never the path, which Node's own messages name. The code is given only when it reads as one (capitals, digits and `_`); a host a driver put in `code` is left out: "Upload failed." (new in 0.9.0). |
|
|
790
|
+
| A Node system error that says the disk or a service could not answer just now: `ETIMEDOUT` (a volume that did not answer, or a path upload whose read did not answer within `ingestTimeoutMs`), `ECONNRESET`, `ECONNREFUSED`, `EPIPE`, `EAI_AGAIN`, `EAGAIN`, `EBUSY`, `EMFILE`, `ENFILE`, `ESTALE`, `EHOSTUNREACH`, `ENETUNREACH`; or a full disk, `ENOSPC` and `EDQUOT` | 503, with `Retry-After: 5`, or `Retry-After: 30` for a full disk. New in 0.10.0: it was 500 | "Upload failed (ETIMEDOUT).", as for the row above. |
|
|
757
791
|
| Anything else: a plain `Error`, a value that is not an `Error` | 500 | What failed: "Upload failed.". Never the error's own message, which can name paths and hosts of your server. |
|
|
758
792
|
|
|
759
793
|
Until 0.9.0, `upload` answered any `Error` from `files.ingest` without a status `422` with its
|
|
@@ -797,7 +831,7 @@ type UploadAnswer = { status: number; error: string; code?: IngestErrorCode; ret
|
|
|
797
831
|
| `status` | The HTTP status: 400 to 599. |
|
|
798
832
|
| `error` | The message of the JSON body, `{ "error": … }`. Safe to show: it never holds a path, a host or a provider's words. An `"unreadable"` file is told in fixed words, as `errorInfoOf` tells it (new in 0.9.0). What it does hold is the message of an error that has a `status` (one your hooks threw) and of an `IngestError` of another code: keep hosts out of those. |
|
|
799
833
|
| `code` | For an `IngestError`: its code (`"too_large"`, `"busy"`…). |
|
|
800
|
-
| `retryAfterMs` | How long to wait before trying again, for the `Retry-After` header: 5,000 for a store that failed, an `IngestError`'s own for `"busy"`, a model's for a rate limit. |
|
|
834
|
+
| `retryAfterMs` | How long to wait before trying again, for the `Retry-After` header: 5,000 for a store that failed or a transient system error (30,000 for a full disk, since 0.10.0), an `IngestError`'s own for `"busy"`, a model's for a rate limit. |
|
|
801
835
|
|
|
802
836
|
To word an error in your users' language rather than with these messages, use
|
|
803
837
|
[`errorInfoOf`](./errors-and-retries.md#errorinfooferror) from the main entry.
|
package/docs/reference/openai.md
CHANGED
|
@@ -99,12 +99,18 @@ requests are never streamed. Each piece of text goes to `onText` as it arrives.
|
|
|
99
99
|
request whose connection broke after `[DONE]` with status 0, with the whole answer already shown.
|
|
100
100
|
- A server that sends the name of a tool call again with each piece of the call does not make it
|
|
101
101
|
longer (since 0.6.0; it gave `search_documentsearch_document`). A name sent in pieces is joined.
|
|
102
|
+
- A piece of a tool call without `index` starts a new call only when its ID is there and is not the
|
|
103
|
+
last call's; otherwise it adds to the last call (since 0.10.0). A server that sends the ID with
|
|
104
|
+
every piece made a call of each piece before.
|
|
102
105
|
|
|
103
106
|
**The reply** ([`ModelReply`](./ask.md#modelreply)):
|
|
104
107
|
|
|
105
108
|
- `text` is the message's content. When there is none and the model refused, it is the `refusal`,
|
|
106
109
|
which goes to `onText` too.
|
|
107
|
-
- `calls` are the `tool_calls` that have a name.
|
|
110
|
+
- `calls` are the `tool_calls` that have a name. A call that came without an ID, or with an empty
|
|
111
|
+
one, is given `call_` and 24 hexadecimal characters, once: in the call and in `raw`, so the tool
|
|
112
|
+
message that answers it names the same ID (since 0.10.0; before, `raw` went back without it and
|
|
113
|
+
the tool message had a numbered ID). Arguments that are not a JSON object give the call
|
|
108
114
|
a `problem`: the loop answers it with that message instead of running it, and the model can send
|
|
109
115
|
it again. In the turn that goes back, those arguments, and empty ones, become `"{}"`, and
|
|
110
116
|
arguments that came as an object become their JSON text. When
|
|
@@ -121,11 +127,14 @@ requests are never streamed. Each piece of text goes to `onText` as it arrives.
|
|
|
121
127
|
`completion_tokens`; `thoughtTokens` is `completion_tokens_details.reasoning_tokens`. A missing
|
|
122
128
|
number counts 0. `providerUsage` is the `usage` object as it came. A stream reports usage only
|
|
123
129
|
when the server sends it.
|
|
130
|
+
- `responseId` and `responseModel` are the reply's `id` and `model`, when the server gives them
|
|
131
|
+
(new in 0.10.0).
|
|
124
132
|
|
|
125
133
|
**Part reads** (`generateText`, for `analyze_whole_document`) go to the same URL with the same
|
|
126
134
|
headers and are never streamed. The body is `model`, a message of role `systemRole` and a user
|
|
127
135
|
message, the output limit under the name `maxTokensField`, then the fields of
|
|
128
|
-
`analysisBody(limit)`. `body` is not used. Each request may take `timeoutMs` (180 s
|
|
136
|
+
`analysisBody(limit)`. `body` is not used. Each request may take `timeoutMs` (180 s; 0 for none,
|
|
137
|
+
since 0.10.0). A reply cut
|
|
129
138
|
off with nothing written, or with half its limit or more spent thinking, while the limit was below
|
|
130
139
|
32,768, is asked again with 32,768 output tokens
|
|
131
140
|
([`THINKING_OUTPUT_TOKENS`](./gemini.md#thinking_output_tokens)), and later part reads to the same
|
|
@@ -155,13 +164,15 @@ every later question on that model, in that process.
|
|
|
155
164
|
|
|
156
165
|
A part read throws as `send` does for an HTTP error, a connection that failed, an empty body,
|
|
157
166
|
`insufficient_system_resource`, an abort and a body that is not JSON. It has no waits of
|
|
158
|
-
`firstByteTimeoutMs` and `idleTimeoutMs`; instead, a request that ran past `timeoutMs` throws
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
167
|
+
`firstByteTimeoutMs` and `idleTimeoutMs`; instead, a request that ran past `timeoutMs` throws an
|
|
168
|
+
`OpenAiRequestError` "The model took longer than 180 s to answer.", status 0, kind `"timeout"`
|
|
169
|
+
(since 0.10.0; before, the error of its abort, a `TimeoutError` with no status). A whole-file read
|
|
170
|
+
sends it again once, as the retry rule does for a chat request that got nothing back. A reply with
|
|
171
|
+
no text throws `Error("The model returned no text (length).")`, the reason in brackets being
|
|
172
|
+
`finish_reason`; it has no `status`. In a whole-file read, the model is told why a part failed by
|
|
173
|
+
the error's kind and status, never by the server's message: "The model took too long to answer."
|
|
174
|
+
for a timeout, "The model returned no text (length)." for a reply with no text, the reason only
|
|
175
|
+
when it is a plain word (see [`analyze_whole_document`](./tools.md#analyze_whole_document)).
|
|
165
176
|
|
|
166
177
|
```ts
|
|
167
178
|
import { askWithFiles } from "llm-large-files";
|
|
@@ -237,7 +248,7 @@ The options of [`openAiCompatible()`](#openaicompatibleoptions).
|
|
|
237
248
|
| `maxRequestBytes` | `number` | none | The largest request body the endpoint takes, in bytes. Set as `capabilities.maxRequestBytes`, it keeps the budget within it. Without it the library's budget holds: 10,000,000 bytes unless you set another. |
|
|
238
249
|
| `pageTokens` | `number` | `1_000` | Tokens one PDF page shown by `view_pages` costs. The loop sizes the pages a question may look at from it. It matters only with `pdfInput`. |
|
|
239
250
|
| `tokenScale` | `number` | none, counted as 1 | This model's tokens for one token of the library's estimate, which is fitted to Gemini. A model whose tokenizer counts a third more for the same text takes 1.33, and its documents are planned for a window that much smaller. |
|
|
240
|
-
| `timeoutMs` | `number` | `180_000` | The longest a part read's request may take, in milliseconds, each try counted apart, except that a request sent again with the other name of the output limit (see `maxTokensField`) shares the time of the first. A request that runs longer is aborted. Not used for chat requests. |
|
|
251
|
+
| `timeoutMs` | `number` | `180_000` | The longest a part read's request may take, in milliseconds, each try counted apart, except that a request sent again with the other name of the output limit (see `maxTokensField`) shares the time of the first. A request that runs longer is aborted, and is an `OpenAiRequestError` of kind `"timeout"` and status 0 (since 0.10.0). 0 sets no limit (since 0.10.0; before, it aborted every part read at once). Not used for chat requests. |
|
|
241
252
|
| `firstByteTimeoutMs` | `number` | `600_000` | The longest wait, in milliseconds, for the first piece of a chat reply. Headers do not count: a model that thinks sends nothing until it has thought, and a reply that is not streamed comes whole at the end. A request that gets nothing for that long is aborted with an `OpenAiRequestError` (`status` 0, `kind` `"timeout"`), which `askWithFiles` sends again once. 0, a negative or a non-finite number waits without end. The key and headers are resolved before the wait starts. Not used for part reads. |
|
|
242
253
|
| `idleTimeoutMs` | `number` | `300_000` | The longest wait, in milliseconds, between two pieces of a chat reply once it has started to arrive. Any bytes count, keep-alives included. The same error; `askWithFiles` sends the request again once, unless text of it was shown. 0 waits without end. Not used for part reads. |
|
|
243
254
|
| `id` | `string` | `model` | The name of the model in `usage.byModel` and in messages. |
|