vargai 0.4.0-alpha50 → 0.4.0-alpha51
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/package.json +1 -1
- package/src/ai-sdk/file.ts +20 -0
package/package.json
CHANGED
package/src/ai-sdk/file.ts
CHANGED
|
@@ -60,6 +60,18 @@ export class File {
|
|
|
60
60
|
return new File({ url, mediaType });
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
+
/** Hydrate a File from the render service response shape */
|
|
64
|
+
static fromRenderFile(input: {
|
|
65
|
+
url: string | null;
|
|
66
|
+
mediaType: string;
|
|
67
|
+
metadata?: FileMetadata;
|
|
68
|
+
}): File | null {
|
|
69
|
+
if (!input.url) return null;
|
|
70
|
+
const file = File.fromUrl(input.url, input.mediaType);
|
|
71
|
+
if (input.metadata) file.withMetadata(input.metadata);
|
|
72
|
+
return file;
|
|
73
|
+
}
|
|
74
|
+
|
|
63
75
|
static fromBuffer(data: Uint8Array, mediaType: string): File {
|
|
64
76
|
return new File({ data, mediaType });
|
|
65
77
|
}
|
|
@@ -202,6 +214,14 @@ export class File {
|
|
|
202
214
|
return btoa(binary);
|
|
203
215
|
}
|
|
204
216
|
|
|
217
|
+
toJSON(): { url: string | null; mediaType: string; metadata: FileMetadata } {
|
|
218
|
+
return {
|
|
219
|
+
url: this._url,
|
|
220
|
+
mediaType: this._mediaType,
|
|
221
|
+
metadata: this._metadata,
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
|
|
205
225
|
async toInput(): Promise<ImageModelV3File> {
|
|
206
226
|
if (this._url) {
|
|
207
227
|
return { type: "url", url: this._url };
|