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/dist/node/handlers.d.ts
CHANGED
|
@@ -1,5 +1,112 @@
|
|
|
1
1
|
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
2
|
+
import { type IngestErrorCode } from "../errors.js";
|
|
2
3
|
import { type LargeFiles } from "../library.js";
|
|
4
|
+
import type { DocumentMeta, DocumentScope } from "../types.js";
|
|
5
|
+
/** What `onUploaded` is told besides the document. New in 0.9.0. */
|
|
6
|
+
export type UploadedContext = {
|
|
7
|
+
/**
|
|
8
|
+
* The upload's request, for its headers and URL. Its body has been read: the bytes are not here,
|
|
9
|
+
* unless a framework left them in `request.body` (`express.raw()`), which keeps them until the
|
|
10
|
+
* request ends.
|
|
11
|
+
*/
|
|
12
|
+
request: IncomingMessage;
|
|
13
|
+
/** What `getOwner` returned, when it returned an owner. */
|
|
14
|
+
owner?: string;
|
|
15
|
+
/** What `getScope` returned, when it returned a scope (a frozen copy). */
|
|
16
|
+
scope?: DocumentScope;
|
|
17
|
+
/**
|
|
18
|
+
* True when the client went away before the hook was called: the document is stored all the
|
|
19
|
+
* same, and nobody gets the answer. Record it, or remove it, as your app needs. With the
|
|
20
|
+
* library's own `ingest`, a client that leaves before the ingest ends leaves nothing stored, and
|
|
21
|
+
* the hook is not called: this is for a client that left after the ingest ended, or for an
|
|
22
|
+
* `ingest` of your own that does not stop on its `signal`.
|
|
23
|
+
*/
|
|
24
|
+
clientGone: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* The path the body was saved to: the `path` that `prepareUpload` returned. Only for such an
|
|
27
|
+
* upload: the file is yours, and stays (unless this hook throws). A file of the spool
|
|
28
|
+
* (`uploadSpool`) is gone by now, and is not told. New in 0.9.0.
|
|
29
|
+
*/
|
|
30
|
+
path?: string;
|
|
31
|
+
};
|
|
32
|
+
/** What `prepareUpload` is told of an upload, before its body is read. New in 0.9.0. */
|
|
33
|
+
export type PrepareUploadInfo = {
|
|
34
|
+
/**
|
|
35
|
+
* The file's name, as the document will have it: the last part of the name sent, without
|
|
36
|
+
* control characters (`cleanFileName`). It is the client's: never build a path from it.
|
|
37
|
+
*/
|
|
38
|
+
name: string;
|
|
39
|
+
/** What `getOwner` returned, when it returned an owner. */
|
|
40
|
+
owner?: string;
|
|
41
|
+
/** What `getScope` returned, when it returned a scope (a frozen copy). */
|
|
42
|
+
scope?: DocumentScope;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* What `prepareUpload` may return for an upload: the document's ID, where to save its body, and
|
|
46
|
+
* the ref of that file for `LargeFilesOptions.originals`. Each is optional. New in 0.9.0.
|
|
47
|
+
*/
|
|
48
|
+
export type PreparedUpload = {
|
|
49
|
+
/**
|
|
50
|
+
* The document's ID (`IngestInput.id`), such as the ID of the upload in your database. A
|
|
51
|
+
* document of that ID that is already stored makes the upload fail with a 409 ("exists").
|
|
52
|
+
*/
|
|
53
|
+
id?: string;
|
|
54
|
+
/**
|
|
55
|
+
* An absolute path where the body is saved as it arrives, then ingested from (`source`). The
|
|
56
|
+
* file must not be there: it is made new (`"wx"`, mode `uploadFileMode`), and never written
|
|
57
|
+
* through a file or a link already at that name (a 409). Its folder must exist: the handler makes
|
|
58
|
+
* no folder. A link in a folder above it is followed, except below the root of a ref (see
|
|
59
|
+
* `original`). The file is yours once the document is stored: the library never removes it, even
|
|
60
|
+
* when the document is deleted or expires. When the upload fails, it is removed.
|
|
61
|
+
*/
|
|
62
|
+
path?: string;
|
|
63
|
+
/**
|
|
64
|
+
* The ref of the saved file for `LargeFilesOptions.originals` (`IngestInput.original`), such as
|
|
65
|
+
* its path under the folder of `fileOriginals`: the store then keeps no copy of it. Give it with
|
|
66
|
+
* `path`: the handler does not make a ref of a path, nor check that the ref names that file.
|
|
67
|
+
* When `path` ends with the ref (`<root>/<ref>`, as `fileOriginals(root)` reads it), a link in a
|
|
68
|
+
* folder below that root, which `fileOriginals` would refuse to read through, fails the upload
|
|
69
|
+
* before its body is read: a 500 "Upload failed (ELOOP).".
|
|
70
|
+
*/
|
|
71
|
+
original?: {
|
|
72
|
+
ref: string;
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
/** Where `uploadSpool` writes the bodies of uploads, and which ones. New in 0.9.0. */
|
|
76
|
+
export type UploadSpoolOptions = {
|
|
77
|
+
/** The folder of the temporary files. It must exist. Defaults to `os.tmpdir()`. */
|
|
78
|
+
directory?: string;
|
|
79
|
+
/**
|
|
80
|
+
* Bodies whose `Content-Length` is this many bytes or fewer are held in memory, as without a
|
|
81
|
+
* spool; larger ones, and those without a `Content-Length`, are written to a temporary file.
|
|
82
|
+
* Defaults to 1 MiB (1,048,576). 0 writes every body to a file.
|
|
83
|
+
*/
|
|
84
|
+
minBytes?: number;
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* What `onUploaded` may return: nothing, or `{ answer }`, whose fields are added to the upload's
|
|
88
|
+
* answer (the `201` JSON, or `ingest.finish.app`). New in 0.9.0.
|
|
89
|
+
*/
|
|
90
|
+
export type UploadedResult = void | {
|
|
91
|
+
answer?: Record<string, unknown>;
|
|
92
|
+
};
|
|
93
|
+
/** What `onRemoved` is told besides the document's ID. New in 0.9.0. */
|
|
94
|
+
export type RemovedContext = {
|
|
95
|
+
request: IncomingMessage;
|
|
96
|
+
owner?: string;
|
|
97
|
+
scope?: DocumentScope;
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* An error as the upload handler answers it (`uploadAnswerOf`): the HTTP status, the message of
|
|
101
|
+
* the JSON body `{ "error": … }`, the `IngestErrorCode` of a file that could not be read, and how
|
|
102
|
+
* long to wait before trying again (the `Retry-After` header of a 503). New in 0.9.0.
|
|
103
|
+
*/
|
|
104
|
+
export type UploadAnswer = {
|
|
105
|
+
status: number;
|
|
106
|
+
error: string;
|
|
107
|
+
code?: IngestErrorCode;
|
|
108
|
+
retryAfterMs?: number;
|
|
109
|
+
};
|
|
3
110
|
export type DocumentHandlerOptions = {
|
|
4
111
|
/**
|
|
5
112
|
* The signed-in user for this request. When set, uploads are owned by that user and other
|
|
@@ -9,6 +116,13 @@ export type DocumentHandlerOptions = {
|
|
|
9
116
|
* JavaScript that is neither a string nor a finite number (`req.user` in place of `req.user.id`,
|
|
10
117
|
* say): `{"error":"Upload failed (owner is not a string)."}`.
|
|
11
118
|
*
|
|
119
|
+
* When the library requires an owner (`requireOwner`), it is required here: the handlers cannot
|
|
120
|
+
* be made without it, and an undefined owner (or null, from JavaScript) is answered 401
|
|
121
|
+
* `{"error":"Sign in first."}` before the body is read, on every route (new in 0.9.0). An empty
|
|
122
|
+
* owner is then a 500 on every route too, without calling the library: `get` answers
|
|
123
|
+
* `{"error":"The file could not be looked up (empty owner)."}`, and `remove`
|
|
124
|
+
* `{"error":"The file could not be deleted (empty owner)."}`.
|
|
125
|
+
*
|
|
12
126
|
* To refuse a request, throw an error with a `status` (or `statusCode`) between 400 and 599, as
|
|
13
127
|
* the `http-errors` package makes: the handler answers with that status and the error's message.
|
|
14
128
|
* Any other error is answered with a 500 that does not repeat its message. It is called before
|
|
@@ -16,18 +130,91 @@ export type DocumentHandlerOptions = {
|
|
|
16
130
|
*/
|
|
17
131
|
getOwner?: (request: IncomingMessage) => string | undefined | Promise<string | undefined>;
|
|
18
132
|
/**
|
|
19
|
-
* The
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
133
|
+
* The scope of this request, such as [userId, chatId] (`DocumentScope`): uploads are stored in
|
|
134
|
+
* it, and `get` and `remove` find only the documents of the same scope. Called after `getOwner`,
|
|
135
|
+
* before the body is read, on every route. Return undefined for no scope. A scope that is not
|
|
136
|
+
* valid is the server's mistake: a 500 `{"error":"Upload failed (invalid scope)."}`. Throw an
|
|
137
|
+
* error with a status to refuse a request, as for `getOwner`. Required when the library requires
|
|
138
|
+
* a scope (`requireScope`); an undefined scope is then a 500 `{"error":"Upload failed (no scope)."}`.
|
|
139
|
+
* New in 0.9.0.
|
|
140
|
+
*/
|
|
141
|
+
getScope?: (request: IncomingMessage) => DocumentScope | undefined | Promise<DocumentScope | undefined>;
|
|
142
|
+
/**
|
|
143
|
+
* Called once an upload is stored, before it is answered: to record the document in your
|
|
144
|
+
* database, say. The `201` is sent, or `ingest.finish` on the event-stream path, once it
|
|
145
|
+
* resolves, with no time limit: bound your own calls. The upload's room
|
|
146
|
+
* (`maxPendingUploadBytes`) is given back, and the body the handler read is freed, before it is
|
|
147
|
+
* called. It is called even when the client went away after the ingest ended (`clientGone`):
|
|
148
|
+
* with the library's own `ingest`, a client that leaves before it ends leaves nothing stored,
|
|
149
|
+
* and no call. Return `{ answer }` to add its fields to the answer: to the `201` JSON (the
|
|
150
|
+
* summary's own fields win), or as `app` in `ingest.finish`. `answer` must be a plain object that
|
|
151
|
+
* JSON can hold.
|
|
152
|
+
*
|
|
153
|
+
* When it throws, or returns an `answer` that is not such an object, the document is deleted
|
|
154
|
+
* (best effort) and the upload is answered as for an error of `ingest`: with the error's status
|
|
155
|
+
* (400 to 599) and message, or a 500 `{"error":"Upload failed."}`. New in 0.9.0.
|
|
156
|
+
*/
|
|
157
|
+
onUploaded?: (document: DocumentMeta, context: UploadedContext) => UploadedResult | Promise<UploadedResult>;
|
|
158
|
+
/**
|
|
159
|
+
* Called after `remove` deleted a document (`{ deleted: true }`), before it answers. When it
|
|
160
|
+
* throws, the answer is the error's status and message, or a 500; the document is deleted all
|
|
161
|
+
* the same, and a second `remove` answers `{ deleted: false }` without calling it. New in 0.9.0.
|
|
162
|
+
*/
|
|
163
|
+
onRemoved?: (id: string, context: RemovedContext) => void | Promise<void>;
|
|
164
|
+
/**
|
|
165
|
+
* Called for each upload after `getOwner` and `getScope`, before its body is read: returns the
|
|
166
|
+
* document's `id`, a `path` to save the body to, and the `original` ref of that file (see
|
|
167
|
+
* `PreparedUpload`), or nothing. With a `path`, the body is written there as it arrives (under
|
|
168
|
+
* the same limits: `maxUploadBytes`, `uploadIdleTimeoutMs`), then ingested from the file, which
|
|
169
|
+
* stays once the document is stored and is removed when the upload fails, whatever the reason
|
|
170
|
+
* (a process that is killed cannot remove it).
|
|
171
|
+
* Such an upload is not held in memory, and takes no room of `maxPendingUploadBytes` or
|
|
172
|
+
* `maxSpooledUploadBytes`. Throw an error with a status to refuse the upload, as for `getOwner`.
|
|
173
|
+
* The upload can still fail after it (no room, too large…): choose here, record in `onUploaded`.
|
|
174
|
+
* New in 0.9.0.
|
|
175
|
+
*/
|
|
176
|
+
prepareUpload?: (request: IncomingMessage, info: PrepareUploadInfo) => PreparedUpload | void | Promise<PreparedUpload | void>;
|
|
177
|
+
/**
|
|
178
|
+
* Writes the bodies of uploads to temporary files, instead of holding them in memory while they
|
|
179
|
+
* are ingested: those over `minBytes` (1 MiB), and those without a `Content-Length`. Each file is
|
|
180
|
+
* made new in `directory` (`os.tmpdir()`), with a random name and mode 0o600, ingested from its
|
|
181
|
+
* path, and removed once the ingest ends, whatever the end. `true` for the defaults. Defaults to
|
|
182
|
+
* false. New in 0.9.0.
|
|
183
|
+
*/
|
|
184
|
+
uploadSpool?: boolean | UploadSpoolOptions;
|
|
185
|
+
/**
|
|
186
|
+
* The most bytes of the spool's files (`uploadSpool`) at once. An upload that would pass it is
|
|
187
|
+
* answered 503 with `Retry-After`, before its body is read, as for `maxPendingUploadBytes`. A
|
|
188
|
+
* disk that is full is answered 503 with `Retry-After` too. `Infinity` for no limit. Defaults to
|
|
189
|
+
* ten times `maxUploadBytes`. New in 0.9.0.
|
|
190
|
+
*/
|
|
191
|
+
maxSpooledUploadBytes?: number;
|
|
192
|
+
/**
|
|
193
|
+
* The mode of the files saved to the `path` of `prepareUpload`, minus the umask of the process.
|
|
194
|
+
* Defaults to 0o600: only the server's user reads them. 0o640 lets a group read them (pods of
|
|
195
|
+
* another user that share the volume through a group). The spool's files are always 0o600. New
|
|
196
|
+
* in 0.9.0.
|
|
197
|
+
*/
|
|
198
|
+
uploadFileMode?: number;
|
|
199
|
+
/**
|
|
200
|
+
* The most bytes of uploads these handlers hold in memory at once: an upload is held whole in
|
|
201
|
+
* memory from the moment its body is read until its ingest ends. An upload that would pass it is
|
|
202
|
+
* answered 503 with `Retry-After` before its body is read, while another upload is held: one
|
|
203
|
+
* upload alone is always taken. An upload counts its `Content-Length` (or `maxUploadBytes`
|
|
204
|
+
* without one, then its size once read). Bodies written to a file (`prepareUpload`'s `path`,
|
|
205
|
+
* `uploadSpool`) do not count, since 0.9.0. `Infinity` for no limit (as before 0.8.2). Defaults
|
|
206
|
+
* to twice `maxUploadBytes`. New in 0.8.2.
|
|
25
207
|
*/
|
|
26
208
|
maxPendingUploadBytes?: number;
|
|
27
209
|
/**
|
|
28
210
|
* An upload whose body stops arriving for this many milliseconds is answered 408, its connection
|
|
29
211
|
* closed and its room given back: a client that sends its headers and then nothing, or stalls,
|
|
30
|
-
* holds its room no longer. 0
|
|
212
|
+
* holds its room no longer. Since 0.9.0 it also bounds each call to the disk for a body written
|
|
213
|
+
* to a file (the check of its folders for a link, its opening, each write, its closing): a volume
|
|
214
|
+
* that stops answering fails the upload with a 500 "Upload failed (ETIMEDOUT).", and its room is
|
|
215
|
+
* given back. The removal of the file is waited for no longer either: past it, the removal goes
|
|
216
|
+
* on alone, and the upload is answered all the same. 0 or `Infinity` for no limit. Defaults to
|
|
217
|
+
* 30,000. New in 0.8.2.
|
|
31
218
|
*/
|
|
32
219
|
uploadIdleTimeoutMs?: number;
|
|
33
220
|
};
|
|
@@ -40,20 +227,45 @@ export type DocumentHandlers = {
|
|
|
40
227
|
/**
|
|
41
228
|
* POST: the body is the raw file. Name it with an `X-File-Name` header (URI-encoded) or `?name=`.
|
|
42
229
|
* A file that cannot be read is answered with a 422 and the reason. A store that fails while it
|
|
43
|
-
* writes is answered with a
|
|
230
|
+
* writes is answered with a 503 and `Retry-After`. Any other error is answered as
|
|
231
|
+
* `uploadAnswerOf` says. The body is held in memory, or, with the `path` of `prepareUpload` or
|
|
232
|
+
* with `uploadSpool`, written to a file as it arrives and ingested from its path (new in 0.9.0).
|
|
44
233
|
*
|
|
45
234
|
* When the request's `Accept` header names `text/event-stream` (not with `q=0`, nor only through a
|
|
46
|
-
* wildcard), a file that passes the checks of the name, the owner and the size (which
|
|
47
|
-
* answer with an HTTP error) is answered with a 200 and Server-Sent Events: the ingest's
|
|
48
|
-
*
|
|
49
|
-
*
|
|
235
|
+
* wildcard), a file that passes the checks of the name, the owner, the scope and the size (which
|
|
236
|
+
* still answer with an HTTP error) is answered with a 200 and Server-Sent Events: the ingest's
|
|
237
|
+
* events (`ingest.start`, `ingest.progress`…), ending with `ingest.finish`, whose data is the
|
|
238
|
+
* summary a 201 would hold (and `onUploaded`'s answer in `app`), or `ingest.error`, whose data is
|
|
239
|
+
* `{ error: { message, status } }` with the message and status a JSON answer would have, the
|
|
240
|
+
* `code` of a refused file, the `name` of a store that failed or of a scope error (with its
|
|
241
|
+
* `code`), and the `kind` of a model's error, for `errorInfoOf`.
|
|
50
242
|
*/
|
|
51
243
|
upload(request: IncomingMessage, response: ServerResponse): Promise<void>;
|
|
52
|
-
/** GET: the document's summary, or 404. */
|
|
244
|
+
/** GET: the document's summary, or 404. With `getScope`, only a document of the request's scope. */
|
|
53
245
|
get(request: IncomingMessage, response: ServerResponse, id: string): Promise<void>;
|
|
54
|
-
/** DELETE: removes the document
|
|
246
|
+
/** DELETE: removes the document, then calls `onRemoved`. Responds `{ deleted: boolean }`. */
|
|
55
247
|
remove(request: IncomingMessage, response: ServerResponse, id: string): Promise<void>;
|
|
56
248
|
};
|
|
249
|
+
/**
|
|
250
|
+
* How the upload handler answers an error, for a route of your own that ingests files and should
|
|
251
|
+
* answer as it does:
|
|
252
|
+
* - an `IngestError` (a file that could not be read): its status (422; 413, 409, or 503 for "busy"
|
|
253
|
+
* with its `retryAfterMs`), its message and its `code`. Only an `IngestError` is a 422. An
|
|
254
|
+
* "unreadable" file is told in fixed words, as `errorInfoOf` tells it: its own message is a
|
|
255
|
+
* parser's, or that of an extractor of your own;
|
|
256
|
+
* - a `DocumentStoreError`: 503, its message (which names no path or host), and 5 s to wait;
|
|
257
|
+
* - a `DocumentScopeError` "scope_missing": 404 "This chat no longer exists."; the other codes
|
|
258
|
+
* are the server's mistake: 500 "Upload failed.";
|
|
259
|
+
* - a model's error (`ModelRequestError`): the status and words of `errorInfoOf`, never the
|
|
260
|
+
* provider's own;
|
|
261
|
+
* - any other error with a `status` (or `statusCode`) from 400 to 599: that status and its message;
|
|
262
|
+
* - a Node system error (a `code` and a `syscall`): 500 "Upload failed (ENOSPC).", or "Upload
|
|
263
|
+
* failed." when its code does not read as one (capitals, digits and "_"), as a host does;
|
|
264
|
+
* - anything else: 500 "Upload failed.", without its message, which may name a host.
|
|
265
|
+
*
|
|
266
|
+
* It reads the errors of every copy of the package, and never throws. New in 0.9.0.
|
|
267
|
+
*/
|
|
268
|
+
export declare function uploadAnswerOf(error: unknown): UploadAnswer;
|
|
57
269
|
/**
|
|
58
270
|
* Upload, get, and delete handlers for any Node HTTP server (node:http, Express, Fastify via
|
|
59
271
|
* `request.raw`/`reply.raw`, Next.js API routes on the Node runtime). Responses are JSON, except an upload that asks for
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handlers.d.ts","sourceRoot":"","sources":["../../src/node/handlers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"handlers.d.ts","sourceRoot":"","sources":["../../src/node/handlers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAIjE,OAAO,EAAoE,KAAK,eAAe,EAAE,MAAM,cAAc,CAAC;AAEtH,OAAO,EAAsF,KAAK,UAAU,EAAE,MAAM,eAAe,CAAC;AAIpI,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAI/D,oEAAoE;AACpE,MAAM,MAAM,eAAe,GAAG;IAC5B;;;;OAIG;IACH,OAAO,EAAE,eAAe,CAAC;IACzB,2DAA2D;IAC3D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,0EAA0E;IAC1E,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB;;;;;;OAMG;IACH,UAAU,EAAE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