ai 7.0.88 → 7.0.89
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 +10 -0
- package/dist/index.d.ts +27 -5
- package/dist/index.js +32 -13
- package/dist/index.js.map +1 -1
- package/dist/internal/index.js +1 -1
- package/docs/03-ai-sdk-core/39-file-uploads.mdx +25 -0
- package/docs/07-reference/01-ai-sdk-core/14-upload-file.mdx +37 -4
- package/package.json +12 -12
- package/src/upload-file/upload-file-result.ts +12 -0
- package/src/upload-file/upload-file.ts +63 -22
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# ai
|
|
2
2
|
|
|
3
|
+
## 7.0.89
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 5190b67: feat(provider): extend the FilesV4 interface with optional `getFileMetadata`, `downloadFile` (streaming), and `deleteFile` operations, plus `abortSignal`/`headers` call options and a `{ type: 'stream' }` upload data variant; upload results now expose `byteSize`, `createdAt`, and `expiresAt` (also surfaced by the core `uploadFile()` helper, which now forwards `abortSignal`/`headers`); add `postMultipartStreamToApi` (streaming multipart uploads with deterministic part ordering and failure-path stream teardown), `deleteFromApi`, and `createBinaryStreamResponseHandler` to provider-utils
|
|
8
|
+
- Updated dependencies [5190b67]
|
|
9
|
+
- @ai-sdk/provider@4.0.10
|
|
10
|
+
- @ai-sdk/provider-utils@5.0.35
|
|
11
|
+
- @ai-sdk/gateway@4.0.71
|
|
12
|
+
|
|
3
13
|
## 7.0.88
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -9609,6 +9609,18 @@ interface UploadFileResult {
|
|
|
9609
9609
|
readonly providerReference: ProviderReference;
|
|
9610
9610
|
readonly mediaType?: string;
|
|
9611
9611
|
readonly filename?: string;
|
|
9612
|
+
/**
|
|
9613
|
+
* The size of the uploaded file in bytes, if reported by the provider.
|
|
9614
|
+
*/
|
|
9615
|
+
readonly byteSize?: number;
|
|
9616
|
+
/**
|
|
9617
|
+
* When the file was created, if reported by the provider.
|
|
9618
|
+
*/
|
|
9619
|
+
readonly createdAt?: Date;
|
|
9620
|
+
/**
|
|
9621
|
+
* When the provider will delete the file (retention expiry), if reported.
|
|
9622
|
+
*/
|
|
9623
|
+
readonly expiresAt?: Date;
|
|
9612
9624
|
readonly providerMetadata?: ProviderMetadata;
|
|
9613
9625
|
readonly warnings: Array<Warning>;
|
|
9614
9626
|
}
|
|
@@ -9617,15 +9629,25 @@ interface UploadFileResult {
|
|
|
9617
9629
|
* Uploads a file using a files API interface.
|
|
9618
9630
|
*
|
|
9619
9631
|
* @param api - The Files API interface to use for uploading.
|
|
9620
|
-
* @param data - The file data to upload (tagged `{ type: 'data' | 'text' }`).
|
|
9632
|
+
* @param data - The file data to upload (tagged `{ type: 'data' | 'text' | 'stream' }`).
|
|
9633
|
+
* Stream data is sent without buffering by providers that support streaming
|
|
9634
|
+
* uploads (others reject with `UnsupportedFunctionalityError`); the provider
|
|
9635
|
+
* consumes the stream — any failed upload, including validation failures
|
|
9636
|
+
* before a request is made, cancels it. Do not reuse it.
|
|
9621
9637
|
* @param mediaType - Optional IANA media type. Auto-detected from file bytes
|
|
9622
|
-
* when omitted (falls back to `text/plain` for the `text` variant
|
|
9623
|
-
*
|
|
9638
|
+
* when omitted (falls back to `text/plain` for the `text` variant and
|
|
9639
|
+
* `application/octet-stream` for the `stream` variant, which cannot be sniffed).
|
|
9640
|
+
* @param filename - Optional filename for the uploaded file. Multipart-based
|
|
9641
|
+
* providers default it to `"blob"` when omitted.
|
|
9642
|
+
* @param abortSignal - Optional signal to cancel the upload.
|
|
9643
|
+
* @param headers - Optional additional HTTP headers for the request.
|
|
9624
9644
|
* @param providerOptions - Additional provider-specific options.
|
|
9625
9645
|
*
|
|
9626
|
-
* @returns A result object containing the provider reference
|
|
9646
|
+
* @returns A result object containing the provider reference, optional
|
|
9647
|
+
* metadata, and — when reported by the provider — `byteSize`, `createdAt`,
|
|
9648
|
+
* and `expiresAt` (the provider-applied retention expiry).
|
|
9627
9649
|
*/
|
|
9628
|
-
declare function uploadFile({ api, data: dataArg, mediaType: mediaTypeArg, filename, providerOptions, }: {
|
|
9650
|
+
declare function uploadFile({ api, data: dataArg, mediaType: mediaTypeArg, filename, abortSignal, headers, providerOptions, }: {
|
|
9629
9651
|
/**
|
|
9630
9652
|
* The files API interface to use for uploading.
|
|
9631
9653
|
* Can be a `FilesV4` instance or a `ProviderV4` instance with a `files()` method.
|
package/dist/index.js
CHANGED
|
@@ -1176,7 +1176,7 @@ import {
|
|
|
1176
1176
|
} from "@ai-sdk/provider-utils";
|
|
1177
1177
|
|
|
1178
1178
|
// src/version.ts
|
|
1179
|
-
var VERSION = true ? "7.0.
|
|
1179
|
+
var VERSION = true ? "7.0.89" : "0.0.0-test";
|
|
1180
1180
|
|
|
1181
1181
|
// src/util/download/download.ts
|
|
1182
1182
|
var download = async ({
|
|
@@ -19017,26 +19017,42 @@ async function uploadFile({
|
|
|
19017
19017
|
data: dataArg,
|
|
19018
19018
|
mediaType: mediaTypeArg,
|
|
19019
19019
|
filename,
|
|
19020
|
+
abortSignal,
|
|
19021
|
+
headers,
|
|
19020
19022
|
providerOptions
|
|
19021
19023
|
}) {
|
|
19022
19024
|
var _a25;
|
|
19023
19025
|
const data = dataArg instanceof Uint8Array || typeof dataArg === "string" ? { type: "data", data: dataArg } : dataArg;
|
|
19024
|
-
const mediaType = mediaTypeArg != null ? mediaTypeArg : data.type === "text" ? "text/plain" : (_a25 = detectMediaType6({ data: data.data })) != null ? _a25 : isLikelyText(data.data) ? "text/plain" : "application/octet-stream";
|
|
19025
|
-
|
|
19026
|
-
|
|
19027
|
-
|
|
19028
|
-
|
|
19029
|
-
|
|
19030
|
-
|
|
19031
|
-
|
|
19032
|
-
|
|
19033
|
-
|
|
19034
|
-
|
|
19035
|
-
|
|
19026
|
+
const mediaType = mediaTypeArg != null ? mediaTypeArg : data.type === "text" ? "text/plain" : data.type === "stream" ? "application/octet-stream" : (_a25 = detectMediaType6({ data: data.data })) != null ? _a25 : isLikelyText(data.data) ? "text/plain" : "application/octet-stream";
|
|
19027
|
+
let result;
|
|
19028
|
+
try {
|
|
19029
|
+
const filesApi = "uploadFile" in api ? api : typeof api.files === "function" ? api.files() : (() => {
|
|
19030
|
+
throw new Error(
|
|
19031
|
+
"The provider does not support file uploads. Make sure it exposes a files() method."
|
|
19032
|
+
);
|
|
19033
|
+
})();
|
|
19034
|
+
result = await filesApi.uploadFile({
|
|
19035
|
+
data,
|
|
19036
|
+
mediaType,
|
|
19037
|
+
filename,
|
|
19038
|
+
abortSignal,
|
|
19039
|
+
headers,
|
|
19040
|
+
providerOptions
|
|
19041
|
+
});
|
|
19042
|
+
} catch (error) {
|
|
19043
|
+
if (data.type === "stream") {
|
|
19044
|
+
await data.stream.cancel(error).catch(() => {
|
|
19045
|
+
});
|
|
19046
|
+
}
|
|
19047
|
+
throw error;
|
|
19048
|
+
}
|
|
19036
19049
|
return new DefaultUploadFileResult({
|
|
19037
19050
|
providerReference: result.providerReference,
|
|
19038
19051
|
mediaType: result.mediaType,
|
|
19039
19052
|
filename: result.filename,
|
|
19053
|
+
byteSize: result.byteSize,
|
|
19054
|
+
createdAt: result.createdAt,
|
|
19055
|
+
expiresAt: result.expiresAt,
|
|
19040
19056
|
providerMetadata: result.providerMetadata,
|
|
19041
19057
|
warnings: result.warnings
|
|
19042
19058
|
});
|
|
@@ -19046,6 +19062,9 @@ var DefaultUploadFileResult = class {
|
|
|
19046
19062
|
this.providerReference = options.providerReference;
|
|
19047
19063
|
this.mediaType = options.mediaType;
|
|
19048
19064
|
this.filename = options.filename;
|
|
19065
|
+
this.byteSize = options.byteSize;
|
|
19066
|
+
this.createdAt = options.createdAt;
|
|
19067
|
+
this.expiresAt = options.expiresAt;
|
|
19049
19068
|
this.providerMetadata = options.providerMetadata;
|
|
19050
19069
|
this.warnings = options.warnings;
|
|
19051
19070
|
}
|