@vertesia/client 1.6.0-dev.20261019.172735Z → 1.6.0-dev.20261120.123957Z
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/lib/AccountApi.d.ts +2 -0
- package/lib/AccountApi.d.ts.map +1 -1
- package/lib/AccountApi.js +3 -0
- package/lib/AccountApi.js.map +1 -1
- package/lib/AccountRolesApi.d.ts +11 -0
- package/lib/AccountRolesApi.d.ts.map +1 -0
- package/lib/AccountRolesApi.js +22 -0
- package/lib/AccountRolesApi.js.map +1 -0
- package/lib/ApiKeysApi.d.ts +4 -7
- package/lib/ApiKeysApi.d.ts.map +1 -1
- package/lib/ApiKeysApi.js +5 -4
- package/lib/ApiKeysApi.js.map +1 -1
- package/lib/AppsApi.d.ts +18 -3
- package/lib/AppsApi.d.ts.map +1 -1
- package/lib/AppsApi.js +34 -4
- package/lib/AppsApi.js.map +1 -1
- package/lib/AuditTrailApi.d.ts +6 -1
- package/lib/AuditTrailApi.d.ts.map +1 -1
- package/lib/AuditTrailApi.js +8 -0
- package/lib/AuditTrailApi.js.map +1 -1
- package/lib/IamApi.d.ts +1 -1
- package/lib/IamApi.js +1 -1
- package/lib/InteractionCatalogApi.d.ts +19 -1
- package/lib/InteractionCatalogApi.d.ts.map +1 -1
- package/lib/InteractionCatalogApi.js +30 -0
- package/lib/InteractionCatalogApi.js.map +1 -1
- package/lib/InteractionsApi.d.ts +6 -13
- package/lib/InteractionsApi.d.ts.map +1 -1
- package/lib/InteractionsApi.js +4 -24
- package/lib/InteractionsApi.js.map +1 -1
- package/lib/OAuthClientsApi.d.ts +3 -1
- package/lib/OAuthClientsApi.d.ts.map +1 -1
- package/lib/OAuthClientsApi.js +4 -0
- package/lib/OAuthClientsApi.js.map +1 -1
- package/lib/OAuthProvidersApi.d.ts +6 -2
- package/lib/OAuthProvidersApi.d.ts.map +1 -1
- package/lib/OAuthProvidersApi.js +6 -2
- package/lib/OAuthProvidersApi.js.map +1 -1
- package/lib/RunsApi.d.ts +3 -2
- package/lib/RunsApi.d.ts.map +1 -1
- package/lib/RunsApi.js +3 -2
- package/lib/RunsApi.js.map +1 -1
- package/lib/StreamSource.d.ts +19 -1
- package/lib/StreamSource.d.ts.map +1 -1
- package/lib/StreamSource.js +31 -1
- package/lib/StreamSource.js.map +1 -1
- package/lib/UsersApi.d.ts +7 -1
- package/lib/UsersApi.d.ts.map +1 -1
- package/lib/UsersApi.js +8 -0
- package/lib/UsersApi.js.map +1 -1
- package/lib/client.d.ts +14 -2
- package/lib/client.d.ts.map +1 -1
- package/lib/client.js +55 -8
- package/lib/client.js.map +1 -1
- package/lib/execute.d.ts +16 -2
- package/lib/execute.d.ts.map +1 -1
- package/lib/execute.js +16 -3
- package/lib/execute.js.map +1 -1
- package/lib/idempotency-key.d.ts +19 -0
- package/lib/idempotency-key.d.ts.map +1 -0
- package/lib/idempotency-key.js +34 -0
- package/lib/idempotency-key.js.map +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/nodejs/NodeStreamSource.d.ts +11 -1
- package/lib/nodejs/NodeStreamSource.d.ts.map +1 -1
- package/lib/nodejs/NodeStreamSource.js +56 -16
- package/lib/nodejs/NodeStreamSource.js.map +1 -1
- package/lib/store/AgentsApi.d.ts +3 -0
- package/lib/store/AgentsApi.d.ts.map +1 -1
- package/lib/store/AgentsApi.js +10 -1
- package/lib/store/AgentsApi.js.map +1 -1
- package/lib/store/ContentSourcesApi.d.ts +52 -0
- package/lib/store/ContentSourcesApi.d.ts.map +1 -0
- package/lib/store/ContentSourcesApi.js +85 -0
- package/lib/store/ContentSourcesApi.js.map +1 -0
- package/lib/store/CostApi.d.ts +6 -1
- package/lib/store/CostApi.d.ts.map +1 -1
- package/lib/store/CostApi.js +7 -0
- package/lib/store/CostApi.js.map +1 -1
- package/lib/store/DashboardApi.d.ts +61 -19
- package/lib/store/DashboardApi.d.ts.map +1 -1
- package/lib/store/DashboardApi.js +75 -19
- package/lib/store/DashboardApi.js.map +1 -1
- package/lib/store/DataApi.d.ts +9 -9
- package/lib/store/DataApi.d.ts.map +1 -1
- package/lib/store/DataApi.js +14 -10
- package/lib/store/DataApi.js.map +1 -1
- package/lib/store/FilesApi.d.ts +15 -1
- package/lib/store/FilesApi.d.ts.map +1 -1
- package/lib/store/FilesApi.js +54 -69
- package/lib/store/FilesApi.js.map +1 -1
- package/lib/store/IndexingApi.d.ts +0 -6
- package/lib/store/IndexingApi.d.ts.map +1 -1
- package/lib/store/IndexingApi.js +3 -17
- package/lib/store/IndexingApi.js.map +1 -1
- package/lib/store/NotificationsApi.d.ts +39 -0
- package/lib/store/NotificationsApi.d.ts.map +1 -0
- package/lib/store/NotificationsApi.js +68 -0
- package/lib/store/NotificationsApi.js.map +1 -0
- package/lib/store/ObjectsApi.d.ts +6 -7
- package/lib/store/ObjectsApi.d.ts.map +1 -1
- package/lib/store/ObjectsApi.js +25 -46
- package/lib/store/ObjectsApi.js.map +1 -1
- package/lib/store/RenderingApi.d.ts.map +1 -1
- package/lib/store/RenderingApi.js +1 -0
- package/lib/store/RenderingApi.js.map +1 -1
- package/lib/store/WorkflowsApi.d.ts +19 -1
- package/lib/store/WorkflowsApi.d.ts.map +1 -1
- package/lib/store/WorkflowsApi.js +21 -0
- package/lib/store/WorkflowsApi.js.map +1 -1
- package/lib/store/chunked-upload.d.ts +71 -0
- package/lib/store/chunked-upload.d.ts.map +1 -0
- package/lib/store/chunked-upload.js +206 -0
- package/lib/store/chunked-upload.js.map +1 -0
- package/lib/store/client.d.ts +9 -1
- package/lib/store/client.d.ts.map +1 -1
- package/lib/store/client.js +15 -1
- package/lib/store/client.js.map +1 -1
- package/lib/store/index.d.ts +3 -0
- package/lib/store/index.d.ts.map +1 -1
- package/lib/store/index.js +3 -0
- package/lib/store/index.js.map +1 -1
- package/lib/store/node-request.browser.d.ts +14 -0
- package/lib/store/node-request.browser.d.ts.map +1 -0
- package/lib/store/node-request.browser.js +20 -0
- package/lib/store/node-request.browser.js.map +1 -0
- package/lib/store/node-request.d.ts +20 -0
- package/lib/store/node-request.d.ts.map +1 -0
- package/lib/store/node-request.js +116 -0
- package/lib/store/node-request.js.map +1 -0
- package/lib/store/node-sessions.browser.d.ts +3 -0
- package/lib/store/node-sessions.browser.d.ts.map +1 -0
- package/lib/store/node-sessions.browser.js +15 -0
- package/lib/store/node-sessions.browser.js.map +1 -0
- package/lib/store/node-sessions.d.ts +14 -0
- package/lib/store/node-sessions.d.ts.map +1 -0
- package/lib/store/node-sessions.js +88 -0
- package/lib/store/node-sessions.js.map +1 -0
- package/lib/store/signed-url.d.ts +12 -16
- package/lib/store/signed-url.d.ts.map +1 -1
- package/lib/store/signed-url.js +111 -71
- package/lib/store/signed-url.js.map +1 -1
- package/lib/store/stream-bytes.d.ts +16 -0
- package/lib/store/stream-bytes.d.ts.map +1 -0
- package/lib/store/stream-bytes.js +70 -0
- package/lib/store/stream-bytes.js.map +1 -0
- package/lib/store/upload-body.d.ts +21 -0
- package/lib/store/upload-body.d.ts.map +1 -0
- package/lib/store/upload-body.js +32 -0
- package/lib/store/upload-body.js.map +1 -0
- package/lib/store/upload-content.d.ts +21 -0
- package/lib/store/upload-content.d.ts.map +1 -0
- package/lib/store/upload-content.js +113 -0
- package/lib/store/upload-content.js.map +1 -0
- package/lib/store/upload-runtime.d.ts +21 -0
- package/lib/store/upload-runtime.d.ts.map +1 -0
- package/lib/store/upload-runtime.js +40 -0
- package/lib/store/upload-runtime.js.map +1 -0
- package/lib/store/zeno-bulk.d.ts +9 -0
- package/lib/store/zeno-bulk.d.ts.map +1 -0
- package/lib/store/zeno-bulk.js +26 -0
- package/lib/store/zeno-bulk.js.map +1 -0
- package/lib/vertesia-client.js +10 -9
- package/lib/vertesia-client.js.map +1 -1
- package/package.json +38 -9
- package/src/AccountApi.ts +3 -0
- package/src/AccountRolesApi.ts +29 -0
- package/src/ApiKeysApi.ts +4 -12
- package/src/AppsApi.ts +58 -4
- package/src/AuditTrailApi.ts +11 -0
- package/src/IamApi.ts +1 -1
- package/src/InteractionCatalogApi.ts +44 -1
- package/src/InteractionsApi.ts +11 -33
- package/src/OAuthClientsApi.ts +6 -0
- package/src/OAuthProvidersApi.ts +7 -2
- package/src/RunsApi.ts +7 -2
- package/src/StreamSource.ts +29 -0
- package/src/UsersApi.ts +10 -1
- package/src/client.ts +72 -8
- package/src/execute.ts +33 -4
- package/src/idempotency-key.ts +34 -0
- package/src/index.ts +1 -0
- package/src/nodejs/NodeStreamSource.ts +63 -24
- package/src/store/AgentsApi.ts +13 -1
- package/src/store/ContentSourcesApi.ts +126 -0
- package/src/store/CostApi.ts +10 -0
- package/src/store/DashboardApi.ts +93 -18
- package/src/store/DataApi.ts +14 -10
- package/src/store/FilesApi.ts +84 -72
- package/src/store/IndexingApi.ts +3 -18
- package/src/store/NotificationsApi.ts +103 -0
- package/src/store/ObjectsApi.ts +32 -51
- package/src/store/RenderingApi.ts +1 -0
- package/src/store/WorkflowsApi.ts +25 -0
- package/src/store/chunked-upload.ts +272 -0
- package/src/store/client.ts +21 -1
- package/src/store/index.ts +3 -0
- package/src/store/node-request.browser.ts +22 -0
- package/src/store/node-request.ts +120 -0
- package/src/store/node-sessions.browser.ts +16 -0
- package/src/store/node-sessions.ts +109 -0
- package/src/store/signed-url.ts +126 -72
- package/src/store/stream-bytes.ts +79 -0
- package/src/store/upload-body.ts +37 -0
- package/src/store/upload-content.ts +129 -0
- package/src/store/upload-runtime.ts +42 -0
- package/src/store/zeno-bulk.ts +30 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The browser build of `node-sessions.ts`, which the `browser` field of `package.json` substitutes for it, so that
|
|
3
|
+
* browser bundles never resolve the storage SDKs. Uploads only open a session when `hasNodeHttp()` is true, which it
|
|
4
|
+
* never is in a browser.
|
|
5
|
+
*/
|
|
6
|
+
function nodeOnly() {
|
|
7
|
+
throw new Error('Uploading in parts is only available in Node.js');
|
|
8
|
+
}
|
|
9
|
+
export function uploadGcsResumable() {
|
|
10
|
+
return nodeOnly();
|
|
11
|
+
}
|
|
12
|
+
export function uploadAzureBlocks() {
|
|
13
|
+
return nodeOnly();
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=node-sessions.browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-sessions.browser.js","sourceRoot":"","sources":["../../src/store/node-sessions.browser.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,SAAS,QAAQ;IACb,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;AACvE,CAAC;AAED,MAAM,UAAU,kBAAkB;IAC9B,OAAO,QAAQ,EAAE,CAAC;AACtB,CAAC;AAED,MAAM,UAAU,iBAAiB;IAC7B,OAAO,QAAQ,EAAE,CAAC;AACtB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The upload-session writers that run on the storage services' own SDKs: Google Cloud Storage resumable uploads and
|
|
3
|
+
* Azure block blobs (see `chunked-upload.ts`). The SDKs are optional peer dependencies, loaded on first use.
|
|
4
|
+
*
|
|
5
|
+
* Node.js only. Browser bundles get `node-sessions.browser.ts` instead, through the `browser` field of
|
|
6
|
+
* `package.json`, so they never resolve the SDKs or Node's `stream` module.
|
|
7
|
+
*/
|
|
8
|
+
import type { GcsResumableUploadSession } from '@vertesia/common';
|
|
9
|
+
import type { PartsBody } from './chunked-upload.js';
|
|
10
|
+
/** Writes the content to a GCS resumable session. Returns the object's MD5 in hex, the ETag a single PUT gives. */
|
|
11
|
+
export declare function uploadGcsResumable(session: GcsResumableUploadSession, parts: PartsBody): Promise<string | undefined>;
|
|
12
|
+
/** Uploads the content as blocks of `blockSize` bytes, one at a time, then commits them. Returns the blob's ETag. */
|
|
13
|
+
export declare function uploadAzureBlocks(url: string, blockSize: number, contentType: string | undefined, parts: PartsBody): Promise<string | undefined>;
|
|
14
|
+
//# sourceMappingURL=node-sessions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-sessions.d.ts","sourceRoot":"","sources":["../../src/store/node-sessions.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AAClE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AA0CrD,mHAAmH;AACnH,wBAAsB,kBAAkB,CACpC,OAAO,EAAE,yBAAyB,EAClC,KAAK,EAAE,SAAS,GACjB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CA+B7B;AAED,qHAAqH;AACrH,wBAAsB,iBAAiB,CACnC,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,GAAG,SAAS,EAC/B,KAAK,EAAE,SAAS,GACjB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAe7B"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { exactLength } from './node-request.js';
|
|
2
|
+
import { UploadSessionUnavailableError } from './upload-runtime.js';
|
|
3
|
+
/**
|
|
4
|
+
* The `catch` handler of an optional package's `import()`: a missing package means uploads in parts are unavailable.
|
|
5
|
+
*
|
|
6
|
+
* Each `import()` of an optional package carries webpack's `webpackIgnore` comment and chains this handler directly,
|
|
7
|
+
* the forms webpack and esbuild leave to run time, so a consumer's Node.js bundle builds without the packages.
|
|
8
|
+
*/
|
|
9
|
+
function missingPackage(name) {
|
|
10
|
+
return (err) => {
|
|
11
|
+
const code = err?.code;
|
|
12
|
+
if (code === 'ERR_MODULE_NOT_FOUND' || code === 'MODULE_NOT_FOUND') {
|
|
13
|
+
throw new UploadSessionUnavailableError(`the optional package ${name}`, err);
|
|
14
|
+
}
|
|
15
|
+
throw err;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/** The content as a Node stream that fails, before it ends, when it does not match its declared length. */
|
|
19
|
+
async function nodeReadable(parts) {
|
|
20
|
+
const { Readable, Transform } = await import('node:stream');
|
|
21
|
+
const { pipeline } = await import('node:stream/promises');
|
|
22
|
+
const web = parts.body instanceof Blob ? parts.body.stream() : parts.body;
|
|
23
|
+
const source = Readable.fromWeb(web);
|
|
24
|
+
if (parts.size === undefined)
|
|
25
|
+
return source;
|
|
26
|
+
const counted = exactLength(parts.size, Transform);
|
|
27
|
+
// The pipeline forwards an error of the source to `counted`, which is what the SDK reads.
|
|
28
|
+
pipeline(source, counted).catch(() => undefined);
|
|
29
|
+
return counted;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The SDK's ceiling on retrying, counted from the start of the upload. A session URI expires a week after it is
|
|
33
|
+
* created, so a later retry could not succeed. The retry count is what normally ends the retries, within minutes.
|
|
34
|
+
* See https://cloud.google.com/storage/docs/resumable-uploads
|
|
35
|
+
*/
|
|
36
|
+
const GCS_SESSION_LIFETIME_SECONDS = 7 * 24 * 60 * 60;
|
|
37
|
+
/** Retries of failed chunks across the whole upload: the SDK does not reset its count after a chunk succeeds. */
|
|
38
|
+
const GCS_SESSION_MAX_RETRIES = 10;
|
|
39
|
+
/** Writes the content to a GCS resumable session. Returns the object's MD5 in hex, the ETag a single PUT gives. */
|
|
40
|
+
export async function uploadGcsResumable(session, parts) {
|
|
41
|
+
const [{ IdempotencyStrategy, Storage }, { PassThroughClient }] = await Promise.all([
|
|
42
|
+
import(/* webpackIgnore: true */ '@google-cloud/storage').catch(missingPackage('@google-cloud/storage')),
|
|
43
|
+
import(/* webpackIgnore: true */ 'google-auth-library').catch(missingPackage('google-auth-library')),
|
|
44
|
+
]);
|
|
45
|
+
const { pipeline } = await import('node:stream/promises');
|
|
46
|
+
const slash = session.path.indexOf('/');
|
|
47
|
+
// The session URI is the only credential the upload needs, so requests carry no other.
|
|
48
|
+
const file = new Storage({
|
|
49
|
+
authClient: new PassThroughClient(),
|
|
50
|
+
retryOptions: {
|
|
51
|
+
// The default strategy retries only uploads with a precondition, which leaves a session with no retries.
|
|
52
|
+
// Resending a chunk is safe: the SDK first asks the session for the offset it persisted.
|
|
53
|
+
idempotencyStrategy: IdempotencyStrategy.RetryAlways,
|
|
54
|
+
// Both limits count from the start of the upload, not per chunk, so the defaults (3 retries within 600
|
|
55
|
+
// seconds) would leave a long upload with none.
|
|
56
|
+
maxRetries: GCS_SESSION_MAX_RETRIES,
|
|
57
|
+
totalTimeout: GCS_SESSION_LIFETIME_SECONDS,
|
|
58
|
+
},
|
|
59
|
+
})
|
|
60
|
+
.bucket(session.path.slice(0, slash))
|
|
61
|
+
.file(session.path.slice(slash + 1));
|
|
62
|
+
const writable = file.createWriteStream({
|
|
63
|
+
uri: session.url,
|
|
64
|
+
resumable: true,
|
|
65
|
+
chunkSize: session.part_size,
|
|
66
|
+
metadata: { contentType: session.mime_type },
|
|
67
|
+
});
|
|
68
|
+
await pipeline(await nodeReadable(parts), writable);
|
|
69
|
+
const md5 = file.metadata?.md5Hash;
|
|
70
|
+
return typeof md5 === 'string' ? Buffer.from(md5, 'base64').toString('hex') : undefined;
|
|
71
|
+
}
|
|
72
|
+
/** Uploads the content as blocks of `blockSize` bytes, one at a time, then commits them. Returns the blob's ETag. */
|
|
73
|
+
export async function uploadAzureBlocks(url, blockSize, contentType, parts) {
|
|
74
|
+
const { BlockBlobClient } = await import(/* webpackIgnore: true */ '@azure/storage-blob').catch(missingPackage('@azure/storage-blob'));
|
|
75
|
+
const readable = await nodeReadable(parts);
|
|
76
|
+
try {
|
|
77
|
+
const response = await new BlockBlobClient(url).uploadStream(readable, blockSize, 1, {
|
|
78
|
+
blobHTTPHeaders: { blobContentType: contentType },
|
|
79
|
+
});
|
|
80
|
+
return response.etag;
|
|
81
|
+
}
|
|
82
|
+
catch (err) {
|
|
83
|
+
// The SDK stops reading but leaves the stream open; destroying it cancels the source.
|
|
84
|
+
readable.destroy();
|
|
85
|
+
throw err;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=node-sessions.js.map
|
|
@@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|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
* (GCS, S3, Azure Blob) with retry + backoff on transient failures.
|
|
4
|
-
*
|
|
5
|
-
* Signed-URL transfers go straight to the storage backend and therefore bypass
|
|
6
|
-
* the Vertesia API client (`AbstractFetchClient`), which means they normally get
|
|
7
|
-
* none of its retry policy. A single transient `503 Service Unavailable` from the
|
|
8
|
-
* storage backend would otherwise fail the whole upload/download. This helper
|
|
9
|
-
* restores retry behaviour for those storage hops.
|
|
10
|
-
*
|
|
11
|
-
* Note on streamed bodies: a `ReadableStream` body cannot be replayed once it has
|
|
12
|
-
* been consumed, so it is buffered into memory before the first attempt to make
|
|
13
|
-
* retries safe. Callers transferring very large streams should be aware of this
|
|
14
|
-
* memory cost.
|
|
15
|
-
*/
|
|
1
|
+
/** The most of a stream body that is buffered to allow retries: 16 MiB. */
|
|
2
|
+
export declare const MAX_BUFFERED_STREAM_BYTES: number;
|
|
16
3
|
export interface SignedUrlFetchOptions {
|
|
17
4
|
method?: string;
|
|
18
5
|
headers?: Record<string, string>;
|
|
@@ -26,7 +13,10 @@ export interface SignedUrlFetchOptions {
|
|
|
26
13
|
/** HTTP statuses to retry on. Defaults to 429, 500, 502, 503, 504. */
|
|
27
14
|
retryableStatuses?: ReadonlySet<number>;
|
|
28
15
|
}
|
|
29
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* Whether a signed URL points at Azure Blob Storage: a SAS URL on `<account>.blob.core.windows.net`, or
|
|
18
|
+
* `<account>.blob.core.usgovcloudapi.net` in Azure Government.
|
|
19
|
+
*/
|
|
30
20
|
export declare function isAzureBlobUrl(url: string): boolean;
|
|
31
21
|
/**
|
|
32
22
|
* The headers for a `PUT` of file content to a signed upload URL.
|
|
@@ -36,6 +26,12 @@ export declare function isAzureBlobUrl(url: string): boolean;
|
|
|
36
26
|
* by the bucket's CORS policy, and a header those backends do not expect would fail the preflight.
|
|
37
27
|
*/
|
|
38
28
|
export declare function signedUrlUploadHeaders(url: string, headers?: Record<string, string>): Record<string, string> | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Whether a signed URL's storage service accepts an upload of unknown length, sent with chunked transfer encoding
|
|
31
|
+
* and no `Content-Length`. Google Cloud Storage does; Amazon S3 (`MissingContentLength`) and Azure Blob Storage
|
|
32
|
+
* (411 Length Required) need the length up front.
|
|
33
|
+
*/
|
|
34
|
+
export declare function acceptsStreamedUpload(url: string): boolean;
|
|
39
35
|
/**
|
|
40
36
|
* `fetch()` a cloud-storage signed URL, retrying transient failures (connection
|
|
41
37
|
* errors and retryable HTTP statuses) with exponential backoff. Honors a
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signed-url.d.ts","sourceRoot":"","sources":["../../src/store/signed-url.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"signed-url.d.ts","sourceRoot":"","sources":["../../src/store/signed-url.ts"],"names":[],"mappings":"AAsCA,2EAA2E;AAC3E,eAAO,MAAM,yBAAyB,QAAmB,CAAC;AAE1D,MAAM,WAAW,qBAAqB;IAClC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,IAAI,CAAC,EAAE,QAAQ,GAAG,IAAI,CAAC;IACvB,oEAAoE;IACpE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,4EAA4E;IAC5E,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,4GAA4G;IAC5G,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,sEAAsE;IACtE,iBAAiB,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;CAC3C;AAKD;;;GAGG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAOnD;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAClC,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACjC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAIpC;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAO1D;AAkGD;;;;;;;;;;;;GAYG;AACH,wBAAsB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,qBAA0B,GAAG,OAAO,CAAC,QAAQ,CAAC,CA+DxG"}
|
package/lib/store/signed-url.js
CHANGED
|
@@ -9,21 +9,42 @@
|
|
|
9
9
|
* restores retry behaviour for those storage hops.
|
|
10
10
|
*
|
|
11
11
|
* Note on streamed bodies: a `ReadableStream` body cannot be replayed once it has
|
|
12
|
-
* been consumed
|
|
13
|
-
* retries
|
|
14
|
-
* memory
|
|
12
|
+
* been consumed. Up to {@link MAX_BUFFERED_STREAM_BYTES} of it is buffered so that
|
|
13
|
+
* small bodies keep their retries. In Node.js, a longer stream is never held whole in
|
|
14
|
+
* memory: where the storage service accepts a body of unknown length it is sent once,
|
|
15
|
+
* as a stream, without retries (see {@link acceptsStreamedUpload}). Send a `Blob` backed
|
|
16
|
+
* by a local file (Node's `fs.openAsBlob`) to keep retries for large files without a
|
|
17
|
+
* copy in memory. A browser buffers a stream whole, as most browsers cannot send one.
|
|
18
|
+
*
|
|
19
|
+
* A stream whose length the caller declares in a `Content-Length` header is, in Node.js,
|
|
20
|
+
* streamed with that length to any service, and fails if it ends short of it or runs
|
|
21
|
+
* past it.
|
|
22
|
+
*
|
|
23
|
+
* In Node.js, a body over that size, or a streamed one, is sent with Node's `http`
|
|
24
|
+
* client rather than `fetch`, which holds a streamed request body in memory until the
|
|
25
|
+
* request completes (see {@link nodeRequest}).
|
|
15
26
|
*/
|
|
27
|
+
import { hasNodeHttp, nodeRequest } from './node-request.js';
|
|
28
|
+
import { chunkToBlobPart, continueStream } from './stream-bytes.js';
|
|
29
|
+
import { ContentLengthMismatchError, contentLengthHeader } from './upload-runtime.js';
|
|
16
30
|
/** HTTP statuses that storage backends return for transient, retryable conditions. */
|
|
17
31
|
const DEFAULT_RETRYABLE_STATUSES = new Set([429, 500, 502, 503, 504]);
|
|
18
32
|
const DEFAULT_ATTEMPTS = 4;
|
|
19
33
|
const DEFAULT_BASE_DELAY_MS = 500;
|
|
20
34
|
const DEFAULT_MAX_DELAY_MS = 8_000;
|
|
21
35
|
const MAX_RETRY_AFTER_MS = 60_000;
|
|
22
|
-
|
|
23
|
-
|
|
36
|
+
/** The most of a stream body that is buffered to allow retries: 16 MiB. */
|
|
37
|
+
export const MAX_BUFFERED_STREAM_BYTES = 16 * 1024 * 1024;
|
|
38
|
+
/** Blob Storage host suffixes of the public Azure cloud and Azure Government. */
|
|
39
|
+
const AZURE_BLOB_HOST_SUFFIXES = ['.blob.core.windows.net', '.blob.core.usgovcloudapi.net'];
|
|
40
|
+
/**
|
|
41
|
+
* Whether a signed URL points at Azure Blob Storage: a SAS URL on `<account>.blob.core.windows.net`, or
|
|
42
|
+
* `<account>.blob.core.usgovcloudapi.net` in Azure Government.
|
|
43
|
+
*/
|
|
24
44
|
export function isAzureBlobUrl(url) {
|
|
25
45
|
try {
|
|
26
|
-
|
|
46
|
+
const hostname = new URL(url).hostname.toLowerCase();
|
|
47
|
+
return AZURE_BLOB_HOST_SUFFIXES.some((suffix) => hostname.endsWith(suffix));
|
|
27
48
|
}
|
|
28
49
|
catch {
|
|
29
50
|
return false;
|
|
@@ -43,6 +64,28 @@ export function signedUrlUploadHeaders(url, headers) {
|
|
|
43
64
|
return headers;
|
|
44
65
|
return { ...headers, 'x-ms-blob-type': 'BlockBlob' };
|
|
45
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Whether a signed URL's storage service accepts an upload of unknown length, sent with chunked transfer encoding
|
|
69
|
+
* and no `Content-Length`. Google Cloud Storage does; Amazon S3 (`MissingContentLength`) and Azure Blob Storage
|
|
70
|
+
* (411 Length Required) need the length up front.
|
|
71
|
+
*/
|
|
72
|
+
export function acceptsStreamedUpload(url) {
|
|
73
|
+
try {
|
|
74
|
+
const hostname = new URL(url).hostname.toLowerCase();
|
|
75
|
+
return hostname === 'storage.googleapis.com' || hostname.endsWith('.storage.googleapis.com');
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function isStream(body) {
|
|
82
|
+
return typeof ReadableStream !== 'undefined' && body instanceof ReadableStream;
|
|
83
|
+
}
|
|
84
|
+
function withoutContentLength(headers) {
|
|
85
|
+
if (!headers)
|
|
86
|
+
return headers;
|
|
87
|
+
return Object.fromEntries(Object.entries(headers).filter(([name]) => name.toLowerCase() !== 'content-length'));
|
|
88
|
+
}
|
|
46
89
|
function sleep(ms) {
|
|
47
90
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
48
91
|
}
|
|
@@ -70,75 +113,52 @@ function backoffMs(attempt, baseDelayMs, maxDelayMs, res) {
|
|
|
70
113
|
const capped = Math.min(maxDelayMs, baseDelayMs * 2 ** attempt);
|
|
71
114
|
return Math.floor(Math.random() * capped);
|
|
72
115
|
}
|
|
73
|
-
const textEncoder = new TextEncoder();
|
|
74
116
|
/**
|
|
75
|
-
*
|
|
117
|
+
* Make a body safe to send. Bodies other than a `ReadableStream` (`Blob`/`File`, `ArrayBuffer`, typed arrays,
|
|
118
|
+
* strings, `URLSearchParams`) are already replayable and pass through unchanged.
|
|
76
119
|
*
|
|
77
|
-
* A
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
* "TypeError: Received non-Uint8Array chunk", which breaks every signed-URL upload of
|
|
81
|
-
* a text/JSON body (extracted text previews, agent artifacts, tool storage). Encoding
|
|
82
|
-
* chunks ourselves keeps both string and binary bodies uploadable.
|
|
83
|
-
*/
|
|
84
|
-
function chunkToBlobPart(chunk) {
|
|
85
|
-
if (typeof chunk === 'string') {
|
|
86
|
-
return textEncoder.encode(chunk);
|
|
87
|
-
}
|
|
88
|
-
if (chunk instanceof Blob) {
|
|
89
|
-
return chunk;
|
|
90
|
-
}
|
|
91
|
-
if (chunk instanceof ArrayBuffer) {
|
|
92
|
-
return new Uint8Array(chunk);
|
|
93
|
-
}
|
|
94
|
-
// Covers Uint8Array and every other typed-array / DataView view.
|
|
95
|
-
if (ArrayBuffer.isView(chunk)) {
|
|
96
|
-
return new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength);
|
|
97
|
-
}
|
|
98
|
-
// Fail loud rather than uploading e.g. "[object Object]" from an accidental
|
|
99
|
-
// object-mode stream — silently corrupting the stored content is worse than a clear error.
|
|
100
|
-
throw new TypeError(`Unsupported signed-URL upload chunk of type "${typeof chunk}"; ` +
|
|
101
|
-
`body streams must yield string or binary (Uint8Array/ArrayBuffer/DataView/Blob) chunks.`);
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Buffer a `ReadableStream` body into a `Blob` so the request can be safely
|
|
105
|
-
* replayed across retries. Other body types (`Blob`/`File`, `ArrayBuffer`,
|
|
106
|
-
* typed arrays, strings, `URLSearchParams`) are already replayable and pass
|
|
107
|
-
* through unchanged.
|
|
120
|
+
* A stream is read until it ends or passes `maxBufferedBytes`. A stream that ends first is returned as a `Blob`, so
|
|
121
|
+
* it can be retried. A longer one is returned as a stream that yields the bytes read so far and then the rest,
|
|
122
|
+
* unless `bufferWhole` is set, in which case the rest is buffered too.
|
|
108
123
|
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
124
|
+
* Chunks are normalized one by one (rather than `new Response(stream).blob()`) so that string chunks are encoded to
|
|
125
|
+
* bytes — see {@link chunkToBlobPart}.
|
|
111
126
|
*/
|
|
112
|
-
async function
|
|
127
|
+
async function prepareBody(body, maxBufferedBytes, bufferWhole) {
|
|
113
128
|
if (body == null) {
|
|
114
|
-
return undefined;
|
|
129
|
+
return { body: undefined, replayable: true };
|
|
115
130
|
}
|
|
116
|
-
if (typeof ReadableStream
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
// chunkToBlobPart) so a malformed stream fails loudly instead of
|
|
127
|
-
// silently uploading a truncated body.
|
|
128
|
-
parts.push(chunkToBlobPart(value));
|
|
131
|
+
if (typeof ReadableStream === 'undefined' || !(body instanceof ReadableStream)) {
|
|
132
|
+
return { body, replayable: true };
|
|
133
|
+
}
|
|
134
|
+
const reader = body.getReader();
|
|
135
|
+
const parts = [];
|
|
136
|
+
let buffered = 0;
|
|
137
|
+
try {
|
|
138
|
+
for (;;) {
|
|
139
|
+
if (!bufferWhole && buffered > maxBufferedBytes) {
|
|
140
|
+
return { body: continueStream(parts, reader), replayable: false };
|
|
129
141
|
}
|
|
142
|
+
const { done, value } = await reader.read();
|
|
143
|
+
if (done) {
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
// Normalize every chunk (a stray null/undefined is rejected by
|
|
147
|
+
// chunkToBlobPart) so a malformed stream fails loudly instead of
|
|
148
|
+
// silently uploading a truncated body.
|
|
149
|
+
const part = chunkToBlobPart(value);
|
|
150
|
+
parts.push(part);
|
|
151
|
+
buffered += part instanceof Blob ? part.size : part.byteLength;
|
|
130
152
|
}
|
|
131
|
-
catch (err) {
|
|
132
|
-
// Signal the producer to stop and release its resources before propagating.
|
|
133
|
-
await reader.cancel(err).catch(() => undefined);
|
|
134
|
-
throw err;
|
|
135
|
-
}
|
|
136
|
-
finally {
|
|
137
|
-
reader.releaseLock();
|
|
138
|
-
}
|
|
139
|
-
return new Blob(parts);
|
|
140
153
|
}
|
|
141
|
-
|
|
154
|
+
catch (err) {
|
|
155
|
+
// Signal the producer to stop and release its resources before propagating.
|
|
156
|
+
await reader.cancel(err).catch(() => undefined);
|
|
157
|
+
reader.releaseLock();
|
|
158
|
+
throw err;
|
|
159
|
+
}
|
|
160
|
+
reader.releaseLock();
|
|
161
|
+
return { body: new Blob(parts), replayable: true };
|
|
142
162
|
}
|
|
143
163
|
/**
|
|
144
164
|
* `fetch()` a cloud-storage signed URL, retrying transient failures (connection
|
|
@@ -155,13 +175,33 @@ async function toReplayableBody(body) {
|
|
|
155
175
|
*/
|
|
156
176
|
export async function fetchSignedUrl(url, options = {}) {
|
|
157
177
|
const { method = 'GET', headers, attempts = DEFAULT_ATTEMPTS, baseDelayMs = DEFAULT_BASE_DELAY_MS, maxDelayMs = DEFAULT_MAX_DELAY_MS, retryableStatuses = DEFAULT_RETRYABLE_STATUSES, } = options;
|
|
158
|
-
|
|
159
|
-
|
|
178
|
+
// In Node.js, a stream longer than the buffer is sent once as a stream where that works: to a service that
|
|
179
|
+
// accepts a body of unknown length, or with the length the caller declared. Elsewhere it is still buffered
|
|
180
|
+
// whole: S3 and Azure reject a body without a length, and browsers can neither set one nor, in most of them,
|
|
181
|
+
// send a stream at all.
|
|
182
|
+
const declaredLength = isStream(options.body) ? contentLengthHeader(headers) : undefined;
|
|
183
|
+
const streamable = hasNodeHttp() && (acceptsStreamedUpload(url) || declaredLength !== undefined);
|
|
184
|
+
const { body, replayable } = await prepareBody(options.body, MAX_BUFFERED_STREAM_BYTES, !streamable);
|
|
185
|
+
let sendHeaders = headers;
|
|
186
|
+
if (declaredLength !== undefined && body instanceof Blob) {
|
|
187
|
+
if (body.size !== declaredLength) {
|
|
188
|
+
throw new ContentLengthMismatchError(declaredLength, body.size, body.size < declaredLength ? 'short' : 'long');
|
|
189
|
+
}
|
|
190
|
+
// the buffered body sets its own length
|
|
191
|
+
sendHeaders = withoutContentLength(headers);
|
|
192
|
+
}
|
|
193
|
+
const requestHeaders = method.toUpperCase() === 'PUT' ? signedUrlUploadHeaders(url, sendHeaders) : sendHeaders;
|
|
194
|
+
const maxAttempts = replayable ? attempts : 1;
|
|
195
|
+
// Only Node.js streams a body (`streamable`), and always with Node's http client, so fetch only gets buffered ones.
|
|
196
|
+
const large = !replayable || (body instanceof Blob && body.size > MAX_BUFFERED_STREAM_BYTES);
|
|
197
|
+
const send = large && hasNodeHttp()
|
|
198
|
+
? () => nodeRequest(url, { method, headers: requestHeaders, body: body })
|
|
199
|
+
: () => fetch(url, { method, headers: requestHeaders, body });
|
|
160
200
|
let lastError;
|
|
161
|
-
for (let attempt = 0; attempt <
|
|
162
|
-
const isLastAttempt = attempt ===
|
|
201
|
+
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
202
|
+
const isLastAttempt = attempt === maxAttempts - 1;
|
|
163
203
|
try {
|
|
164
|
-
const res = await
|
|
204
|
+
const res = await send();
|
|
165
205
|
if (res.ok || !retryableStatuses.has(res.status) || isLastAttempt) {
|
|
166
206
|
return res;
|
|
167
207
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signed-url.js","sourceRoot":"","sources":["../../src/store/signed-url.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"signed-url.js","sourceRoot":"","sources":["../../src/store/signed-url.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAAE,0BAA0B,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAEtF,sFAAsF;AACtF,MAAM,0BAA0B,GAAwB,IAAI,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;AAE3F,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAC3B,MAAM,qBAAqB,GAAG,GAAG,CAAC;AAClC,MAAM,oBAAoB,GAAG,KAAK,CAAC;AACnC,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAElC,2EAA2E;AAC3E,MAAM,CAAC,MAAM,yBAAyB,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AAgB1D,iFAAiF;AACjF,MAAM,wBAAwB,GAAG,CAAC,wBAA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;QACrD,MAAM,aAAa,GAAG,OAAO,KAAK,WAAW,GAAG,CAAC,CAAC;QAClD,IAAI,CAAC;YACD,MAAM,GAAG,GAAG,MAAM,IAAI,EAAE,CAAC;YACzB,IAAI,GAAG,CAAC,EAAE,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,aAAa,EAAE,CAAC;gBAChE,OAAO,GAAG,CAAC;YACf,CAAC;YACD,kFAAkF;YAClF,2EAA2E;YAC3E,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,kBAAkB;gBAAE,OAAO,GAAG,CAAC;YAC9D,mFAAmF;YACnF,MAAM,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;YAChD,MAAM,KAAK,CAAC,SAAS,CAAC,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,GAAG,CAAC,CAAC,CAAC;QAClE,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACX,SAAS,GAAG,GAAG,CAAC;YAChB,IAAI,aAAa,EAAE,CAAC;gBAChB,MAAM,GAAG,CAAC;YACd,CAAC;YACD,MAAM,KAAK,CAAC,SAAS,CAAC,OAAO,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC,CAAC;QAC7D,CAAC;IACL,CAAC;IAED,iFAAiF;IACjF,MAAM,SAAS,YAAY,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,+BAA+B,GAAG,EAAE,CAAC,CAAC;AACnG,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Byte handling for upload bodies read from a `ReadableStream`. Internal: not exported from the package. */
|
|
2
|
+
/**
|
|
3
|
+
* Normalize one `ReadableStream` chunk to a byte-backed `BlobPart`.
|
|
4
|
+
*
|
|
5
|
+
* A web stream produced from a Node `Readable.from(<string>)` (e.g. via
|
|
6
|
+
* `Readable.toWeb`, which `NodeStreamSource` uses) yields *string* chunks. Buffering
|
|
7
|
+
* such a stream with `new Response(stream).blob()` throws under undici with
|
|
8
|
+
* "TypeError: Received non-Uint8Array chunk", which breaks every signed-URL upload of
|
|
9
|
+
* a text/JSON body (extracted text previews, agent artifacts, tool storage). Encoding
|
|
10
|
+
* chunks ourselves keeps both string and binary bodies uploadable.
|
|
11
|
+
*/
|
|
12
|
+
export declare function chunkToBlobPart(chunk: unknown): BlobPart;
|
|
13
|
+
/** A byte stream of `head`, the parts already read, then what is left in `reader`. */
|
|
14
|
+
export declare function continueStream(head: BlobPart[], reader: ReadableStreamDefaultReader<unknown>): ReadableStream<Uint8Array>;
|
|
15
|
+
export declare function partToBytes(part: BlobPart): Promise<Uint8Array>;
|
|
16
|
+
//# sourceMappingURL=stream-bytes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream-bytes.d.ts","sourceRoot":"","sources":["../../src/store/stream-bytes.ts"],"names":[],"mappings":"AAAA,6GAA6G;AAI7G;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,QAAQ,CAoBxD;AAED,sFAAsF;AACtF,wBAAgB,cAAc,CAC1B,IAAI,EAAE,QAAQ,EAAE,EAChB,MAAM,EAAE,2BAA2B,CAAC,OAAO,CAAC,GAC7C,cAAc,CAAC,UAAU,CAAC,CAkC5B;AAED,wBAAsB,WAAW,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC,CAErE"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/** Byte handling for upload bodies read from a `ReadableStream`. Internal: not exported from the package. */
|
|
2
|
+
const textEncoder = new TextEncoder();
|
|
3
|
+
/**
|
|
4
|
+
* Normalize one `ReadableStream` chunk to a byte-backed `BlobPart`.
|
|
5
|
+
*
|
|
6
|
+
* A web stream produced from a Node `Readable.from(<string>)` (e.g. via
|
|
7
|
+
* `Readable.toWeb`, which `NodeStreamSource` uses) yields *string* chunks. Buffering
|
|
8
|
+
* such a stream with `new Response(stream).blob()` throws under undici with
|
|
9
|
+
* "TypeError: Received non-Uint8Array chunk", which breaks every signed-URL upload of
|
|
10
|
+
* a text/JSON body (extracted text previews, agent artifacts, tool storage). Encoding
|
|
11
|
+
* chunks ourselves keeps both string and binary bodies uploadable.
|
|
12
|
+
*/
|
|
13
|
+
export function chunkToBlobPart(chunk) {
|
|
14
|
+
if (typeof chunk === 'string') {
|
|
15
|
+
return textEncoder.encode(chunk);
|
|
16
|
+
}
|
|
17
|
+
if (chunk instanceof Blob) {
|
|
18
|
+
return chunk;
|
|
19
|
+
}
|
|
20
|
+
if (chunk instanceof ArrayBuffer) {
|
|
21
|
+
return new Uint8Array(chunk);
|
|
22
|
+
}
|
|
23
|
+
// Covers Uint8Array and every other typed-array / DataView view.
|
|
24
|
+
if (ArrayBuffer.isView(chunk)) {
|
|
25
|
+
return new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength);
|
|
26
|
+
}
|
|
27
|
+
// Fail loud rather than uploading e.g. "[object Object]" from an accidental
|
|
28
|
+
// object-mode stream — silently corrupting the stored content is worse than a clear error.
|
|
29
|
+
throw new TypeError(`Unsupported signed-URL upload chunk of type "${typeof chunk}"; ` +
|
|
30
|
+
`body streams must yield string or binary (Uint8Array/ArrayBuffer/DataView/Blob) chunks.`);
|
|
31
|
+
}
|
|
32
|
+
/** A byte stream of `head`, the parts already read, then what is left in `reader`. */
|
|
33
|
+
export function continueStream(head, reader) {
|
|
34
|
+
const pending = [...head];
|
|
35
|
+
return new ReadableStream({
|
|
36
|
+
async pull(controller) {
|
|
37
|
+
const next = pending.shift();
|
|
38
|
+
if (next !== undefined) {
|
|
39
|
+
controller.enqueue(await partToBytes(next));
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
43
|
+
const { done, value } = await reader.read();
|
|
44
|
+
if (done) {
|
|
45
|
+
reader.releaseLock();
|
|
46
|
+
controller.close();
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
controller.enqueue(await partToBytes(chunkToBlobPart(value)));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
// An error in pull errors this stream without calling cancel, so the source is cancelled here.
|
|
54
|
+
pending.length = 0;
|
|
55
|
+
await reader.cancel(err).catch(() => undefined);
|
|
56
|
+
reader.releaseLock();
|
|
57
|
+
throw err;
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
async cancel(reason) {
|
|
61
|
+
pending.length = 0;
|
|
62
|
+
await reader.cancel(reason);
|
|
63
|
+
reader.releaseLock();
|
|
64
|
+
},
|
|
65
|
+
}, { highWaterMark: 0 });
|
|
66
|
+
}
|
|
67
|
+
export async function partToBytes(part) {
|
|
68
|
+
return part instanceof Blob ? new Uint8Array(await part.arrayBuffer()) : part;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=stream-bytes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream-bytes.js","sourceRoot":"","sources":["../../src/store/stream-bytes.ts"],"names":[],"mappings":"AAAA,6GAA6G;AAE7G,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC;AAEtC;;;;;;;;;GASG;AACH,MAAM,UAAU,eAAe,CAAC,KAAc;IAC1C,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC5B,OAAO,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACrC,CAAC;IACD,IAAI,KAAK,YAAY,IAAI,EAAE,CAAC;QACxB,OAAO,KAAK,CAAC;IACjB,CAAC;IACD,IAAI,KAAK,YAAY,WAAW,EAAE,CAAC;QAC/B,OAAO,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC;IACjC,CAAC;IACD,iEAAiE;IACjE,IAAI,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5B,OAAO,I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ACL,CAAC;QACD,KAAK,CAAC,MAAM,CAAC,MAAM;YACf,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;YACnB,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAC5B,MAAM,CAAC,WAAW,EAAE,CAAC;QACzB,CAAC;KACJ,EACD,EAAE,aAAa,EAAE,CAAC,EAAE,CACvB,CAAC;AACN,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,IAAc;IAC5C,OAAO,IAAI,YAAY,IAAI,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC,MAAM,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,CAAE,IAAmB,CAAC;AAClG,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { StreamSource } from '../StreamSource.js';
|
|
2
|
+
/** What to send to upload a source: the body, and the declared length of a stream body. */
|
|
3
|
+
export interface UploadBody {
|
|
4
|
+
body: Blob | ReadableStream;
|
|
5
|
+
/** Sent as `Content-Length` with a stream body whose length is known; a `Blob` carries its own. */
|
|
6
|
+
contentLength?: number;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The request body for uploading a source to a signed URL.
|
|
10
|
+
*
|
|
11
|
+
* A `File` is sent as it is. A stream source with a {@link StreamSource.replayableBody} (e.g. a local file) sends
|
|
12
|
+
* that instead, so a retry re-reads it rather than needing a buffered copy; its stream is cancelled, which releases
|
|
13
|
+
* what the stream holds, such as a file descriptor. Any other stream source sends its stream, with its
|
|
14
|
+
* {@link StreamSource.size} when known.
|
|
15
|
+
*/
|
|
16
|
+
export declare function getUploadBody(source: StreamSource | File): Promise<UploadBody>;
|
|
17
|
+
/** Headers for an upload: the content type, and `Content-Length` when the body declares one. */
|
|
18
|
+
export declare function uploadHeaders(upload: UploadBody, contentType: string | undefined): Record<string, string> | undefined;
|
|
19
|
+
/** An ETag without the quotes HTTP puts around it (RFC 9110), as the upload methods return it. */
|
|
20
|
+
export declare function unquoteEtag(etag: string | undefined): string | undefined;
|
|
21
|
+
//# sourceMappingURL=upload-body.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upload-body.d.ts","sourceRoot":"","sources":["../../src/store/upload-body.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,2FAA2F;AAC3F,MAAM,WAAW,UAAU;IACvB,IAAI,EAAE,IAAI,GAAG,cAAc,CAAC;IAC5B,mGAAmG;IACnG,aAAa,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;;;GAOG;AACH,wBAAsB,aAAa,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI,GAAG,OAAO,CAAC,UAAU,CAAC,CAMpF;AAED,gGAAgG;AAChG,wBAAgB,aAAa,CAAC,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAKrH;AAED,kGAAkG;AAClG,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAExE"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { StreamSource } from '../StreamSource.js';
|
|
2
|
+
/**
|
|
3
|
+
* The request body for uploading a source to a signed URL.
|
|
4
|
+
*
|
|
5
|
+
* A `File` is sent as it is. A stream source with a {@link StreamSource.replayableBody} (e.g. a local file) sends
|
|
6
|
+
* that instead, so a retry re-reads it rather than needing a buffered copy; its stream is cancelled, which releases
|
|
7
|
+
* what the stream holds, such as a file descriptor. Any other stream source sends its stream, with its
|
|
8
|
+
* {@link StreamSource.size} when known.
|
|
9
|
+
*/
|
|
10
|
+
export async function getUploadBody(source) {
|
|
11
|
+
if (!(source instanceof StreamSource))
|
|
12
|
+
return { body: source };
|
|
13
|
+
const body = await source.replayableBody();
|
|
14
|
+
if (!body)
|
|
15
|
+
return { body: source.stream, contentLength: source.size };
|
|
16
|
+
await source.stream.cancel().catch(() => undefined);
|
|
17
|
+
return { body };
|
|
18
|
+
}
|
|
19
|
+
/** Headers for an upload: the content type, and `Content-Length` when the body declares one. */
|
|
20
|
+
export function uploadHeaders(upload, contentType) {
|
|
21
|
+
const headers = {};
|
|
22
|
+
if (contentType)
|
|
23
|
+
headers['Content-Type'] = contentType;
|
|
24
|
+
if (upload.contentLength !== undefined)
|
|
25
|
+
headers['Content-Length'] = String(upload.contentLength);
|
|
26
|
+
return Object.keys(headers).length > 0 ? headers : undefined;
|
|
27
|
+
}
|
|
28
|
+
/** An ETag without the quotes HTTP puts around it (RFC 9110), as the upload methods return it. */
|
|
29
|
+
export function unquoteEtag(etag) {
|
|
30
|
+
return etag?.replace(/^"(.*)"$/, '$1');
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=upload-body.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upload-body.js","sourceRoot":"","sources":["../../src/store/upload-body.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AASlD;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,MAA2B;IAC3D,IAAI,CAAC,CAAC,MAAM,YAAY,YAAY,CAAC;QAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;IAC/D,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,cAAc,EAAE,CAAC;IAC3C,IAAI,CAAC,IAAI;QAAE,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;IACtE,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IACpD,OAAO,EAAE,IAAI,EAAE,CAAC;AACpB,CAAC;AAED,gGAAgG;AAChG,MAAM,UAAU,aAAa,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