@ai-sdk/fal 3.0.0-beta.19 → 3.0.0-beta.20
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 +12 -0
- package/dist/index.js +234 -215
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
- package/dist/index.d.mts +0 -156
- package/dist/index.mjs +0 -1126
- package/dist/index.mjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,72 +1,60 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
VERSION: () => VERSION,
|
|
24
|
-
createFal: () => createFal,
|
|
25
|
-
fal: () => fal
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(index_exports);
|
|
28
|
-
|
|
29
1
|
// src/fal-provider.ts
|
|
30
|
-
|
|
31
|
-
|
|
2
|
+
import {
|
|
3
|
+
NoSuchModelError
|
|
4
|
+
} from "@ai-sdk/provider";
|
|
5
|
+
import {
|
|
6
|
+
withoutTrailingSlash,
|
|
7
|
+
withUserAgentSuffix
|
|
8
|
+
} from "@ai-sdk/provider-utils";
|
|
32
9
|
|
|
33
10
|
// src/fal-image-model.ts
|
|
34
|
-
|
|
35
|
-
|
|
11
|
+
import {
|
|
12
|
+
combineHeaders,
|
|
13
|
+
convertImageModelFileToDataUri,
|
|
14
|
+
createBinaryResponseHandler,
|
|
15
|
+
createJsonErrorResponseHandler,
|
|
16
|
+
createJsonResponseHandler,
|
|
17
|
+
createStatusCodeErrorResponseHandler,
|
|
18
|
+
getFromApi,
|
|
19
|
+
parseProviderOptions,
|
|
20
|
+
postJsonToApi,
|
|
21
|
+
resolve
|
|
22
|
+
} from "@ai-sdk/provider-utils";
|
|
23
|
+
import { z as z2 } from "zod/v4";
|
|
36
24
|
|
|
37
25
|
// src/fal-image-options.ts
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
var falImageModelOptionsSchema =
|
|
41
|
-
() =>
|
|
42
|
-
|
|
26
|
+
import { lazySchema, zodSchema } from "@ai-sdk/provider-utils";
|
|
27
|
+
import { z } from "zod/v4";
|
|
28
|
+
var falImageModelOptionsSchema = lazySchema(
|
|
29
|
+
() => zodSchema(
|
|
30
|
+
z.object({
|
|
43
31
|
/** @deprecated use prompt.images instead */
|
|
44
|
-
imageUrl:
|
|
32
|
+
imageUrl: z.string().nullish().meta({
|
|
45
33
|
deprecated: true,
|
|
46
34
|
description: "Use `prompt.images` instead"
|
|
47
35
|
}),
|
|
48
|
-
maskUrl:
|
|
49
|
-
guidanceScale:
|
|
50
|
-
numInferenceSteps:
|
|
51
|
-
enableSafetyChecker:
|
|
52
|
-
outputFormat:
|
|
53
|
-
syncMode:
|
|
54
|
-
strength:
|
|
55
|
-
acceleration:
|
|
56
|
-
safetyTolerance:
|
|
36
|
+
maskUrl: z.string().nullish().meta({ deprecated: true, description: "Use `prompt.mask` instead" }),
|
|
37
|
+
guidanceScale: z.number().min(1).max(20).nullish(),
|
|
38
|
+
numInferenceSteps: z.number().min(1).max(50).nullish(),
|
|
39
|
+
enableSafetyChecker: z.boolean().nullish(),
|
|
40
|
+
outputFormat: z.enum(["jpeg", "png"]).nullish(),
|
|
41
|
+
syncMode: z.boolean().nullish(),
|
|
42
|
+
strength: z.number().nullish(),
|
|
43
|
+
acceleration: z.enum(["none", "regular", "high"]).nullish(),
|
|
44
|
+
safetyTolerance: z.enum(["1", "2", "3", "4", "5", "6"]).or(z.number().min(1).max(6)).nullish(),
|
|
57
45
|
/**
|
|
58
46
|
* When true, converts multiple input images to `image_urls` array instead of `image_url` string.
|
|
59
47
|
*/
|
|
60
|
-
useMultipleImages:
|
|
48
|
+
useMultipleImages: z.boolean().nullish(),
|
|
61
49
|
// Deprecated snake_case versions
|
|
62
|
-
image_url:
|
|
63
|
-
mask_url:
|
|
64
|
-
guidance_scale:
|
|
65
|
-
num_inference_steps:
|
|
66
|
-
enable_safety_checker:
|
|
67
|
-
output_format:
|
|
68
|
-
sync_mode:
|
|
69
|
-
safety_tolerance:
|
|
50
|
+
image_url: z.string().nullish(),
|
|
51
|
+
mask_url: z.string().nullish(),
|
|
52
|
+
guidance_scale: z.number().min(1).max(20).nullish(),
|
|
53
|
+
num_inference_steps: z.number().min(1).max(50).nullish(),
|
|
54
|
+
enable_safety_checker: z.boolean().nullish(),
|
|
55
|
+
output_format: z.enum(["jpeg", "png"]).nullish(),
|
|
56
|
+
sync_mode: z.boolean().nullish(),
|
|
57
|
+
safety_tolerance: z.enum(["1", "2", "3", "4", "5", "6"]).or(z.number().min(1).max(6)).nullish()
|
|
70
58
|
}).passthrough().transform((data) => {
|
|
71
59
|
const result = {};
|
|
72
60
|
const deprecatedKeys = [];
|
|
@@ -162,7 +150,7 @@ var FalImageModel = class {
|
|
|
162
150
|
} else if (aspectRatio) {
|
|
163
151
|
imageSize = convertAspectRatioToSize(aspectRatio);
|
|
164
152
|
}
|
|
165
|
-
const falOptions = await
|
|
153
|
+
const falOptions = await parseProviderOptions({
|
|
166
154
|
provider: "fal",
|
|
167
155
|
providerOptions,
|
|
168
156
|
schema: falImageModelOptionsSchema
|
|
@@ -177,10 +165,10 @@ var FalImageModel = class {
|
|
|
177
165
|
const useMultipleImages = (falOptions == null ? void 0 : falOptions.useMultipleImages) === true;
|
|
178
166
|
if (useMultipleImages) {
|
|
179
167
|
requestBody.image_urls = files.map(
|
|
180
|
-
(file) =>
|
|
168
|
+
(file) => convertImageModelFileToDataUri(file)
|
|
181
169
|
);
|
|
182
170
|
} else {
|
|
183
|
-
requestBody.image_url =
|
|
171
|
+
requestBody.image_url = convertImageModelFileToDataUri(files[0]);
|
|
184
172
|
if (files.length > 1) {
|
|
185
173
|
warnings.push({
|
|
186
174
|
type: "other",
|
|
@@ -190,7 +178,7 @@ var FalImageModel = class {
|
|
|
190
178
|
}
|
|
191
179
|
}
|
|
192
180
|
if (mask != null) {
|
|
193
|
-
requestBody.mask_url =
|
|
181
|
+
requestBody.mask_url = convertImageModelFileToDataUri(mask);
|
|
194
182
|
}
|
|
195
183
|
if (falOptions) {
|
|
196
184
|
const deprecatedKeys = "__deprecatedKeys" in falOptions ? falOptions.__deprecatedKeys : void 0;
|
|
@@ -231,15 +219,15 @@ var FalImageModel = class {
|
|
|
231
219
|
var _a, _b, _c;
|
|
232
220
|
const { requestBody, warnings } = await this.getArgs(options);
|
|
233
221
|
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
234
|
-
const { value, responseHeaders } = await
|
|
222
|
+
const { value, responseHeaders } = await postJsonToApi({
|
|
235
223
|
url: `${this.config.baseURL}/${this.modelId}`,
|
|
236
|
-
headers:
|
|
237
|
-
await
|
|
224
|
+
headers: combineHeaders(
|
|
225
|
+
await resolve(this.config.headers),
|
|
238
226
|
options.headers
|
|
239
227
|
),
|
|
240
228
|
body: requestBody,
|
|
241
229
|
failedResponseHandler: falFailedResponseHandler,
|
|
242
|
-
successfulResponseHandler:
|
|
230
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
243
231
|
falImageResponseSchema
|
|
244
232
|
),
|
|
245
233
|
abortSignal: options.abortSignal,
|
|
@@ -298,13 +286,13 @@ var FalImageModel = class {
|
|
|
298
286
|
};
|
|
299
287
|
}
|
|
300
288
|
async downloadImage(url, abortSignal) {
|
|
301
|
-
const { value: response } = await
|
|
289
|
+
const { value: response } = await getFromApi({
|
|
302
290
|
url,
|
|
303
291
|
// No specific headers should be needed for this request as it's a
|
|
304
292
|
// generated image provided by fal.ai.
|
|
305
293
|
abortSignal,
|
|
306
|
-
failedResponseHandler:
|
|
307
|
-
successfulResponseHandler:
|
|
294
|
+
failedResponseHandler: createStatusCodeErrorResponseHandler(),
|
|
295
|
+
successfulResponseHandler: createBinaryResponseHandler(),
|
|
308
296
|
fetch: this.config.fetch
|
|
309
297
|
});
|
|
310
298
|
return response;
|
|
@@ -338,60 +326,60 @@ function convertAspectRatioToSize(aspectRatio) {
|
|
|
338
326
|
}
|
|
339
327
|
return void 0;
|
|
340
328
|
}
|
|
341
|
-
var falValidationErrorSchema =
|
|
342
|
-
detail:
|
|
343
|
-
|
|
344
|
-
loc:
|
|
345
|
-
msg:
|
|
346
|
-
type:
|
|
329
|
+
var falValidationErrorSchema = z2.object({
|
|
330
|
+
detail: z2.array(
|
|
331
|
+
z2.object({
|
|
332
|
+
loc: z2.array(z2.string()),
|
|
333
|
+
msg: z2.string(),
|
|
334
|
+
type: z2.string()
|
|
347
335
|
})
|
|
348
336
|
)
|
|
349
337
|
});
|
|
350
|
-
var falHttpErrorSchema =
|
|
351
|
-
message:
|
|
338
|
+
var falHttpErrorSchema = z2.object({
|
|
339
|
+
message: z2.string()
|
|
352
340
|
});
|
|
353
|
-
var falErrorSchema =
|
|
354
|
-
var falImageSchema =
|
|
355
|
-
url:
|
|
356
|
-
width:
|
|
357
|
-
height:
|
|
341
|
+
var falErrorSchema = z2.union([falValidationErrorSchema, falHttpErrorSchema]);
|
|
342
|
+
var falImageSchema = z2.object({
|
|
343
|
+
url: z2.string(),
|
|
344
|
+
width: z2.number().nullish(),
|
|
345
|
+
height: z2.number().nullish(),
|
|
358
346
|
// e.g. https://fal.ai/models/fal-ai/fashn/tryon/v1.6/api#schema-output
|
|
359
|
-
content_type:
|
|
347
|
+
content_type: z2.string().nullish(),
|
|
360
348
|
// e.g. https://fal.ai/models/fal-ai/flowedit/api#schema-output
|
|
361
|
-
file_name:
|
|
362
|
-
file_data:
|
|
363
|
-
file_size:
|
|
349
|
+
file_name: z2.string().nullish(),
|
|
350
|
+
file_data: z2.string().optional(),
|
|
351
|
+
file_size: z2.number().nullish()
|
|
364
352
|
});
|
|
365
|
-
var loraFileSchema =
|
|
366
|
-
url:
|
|
367
|
-
content_type:
|
|
368
|
-
file_name:
|
|
369
|
-
file_data:
|
|
370
|
-
file_size:
|
|
353
|
+
var loraFileSchema = z2.object({
|
|
354
|
+
url: z2.string(),
|
|
355
|
+
content_type: z2.string().optional(),
|
|
356
|
+
file_name: z2.string().nullable().optional(),
|
|
357
|
+
file_data: z2.string().optional(),
|
|
358
|
+
file_size: z2.number().nullable().optional()
|
|
371
359
|
});
|
|
372
|
-
var commonResponseSchema =
|
|
373
|
-
timings:
|
|
374
|
-
inference:
|
|
360
|
+
var commonResponseSchema = z2.object({
|
|
361
|
+
timings: z2.object({
|
|
362
|
+
inference: z2.number().optional()
|
|
375
363
|
}).optional(),
|
|
376
|
-
seed:
|
|
377
|
-
has_nsfw_concepts:
|
|
378
|
-
prompt:
|
|
364
|
+
seed: z2.number().optional(),
|
|
365
|
+
has_nsfw_concepts: z2.array(z2.boolean()).optional(),
|
|
366
|
+
prompt: z2.string().optional(),
|
|
379
367
|
// https://fal.ai/models/fal-ai/lcm/api#schema-output
|
|
380
|
-
nsfw_content_detected:
|
|
381
|
-
num_inference_steps:
|
|
368
|
+
nsfw_content_detected: z2.array(z2.boolean()).optional(),
|
|
369
|
+
num_inference_steps: z2.number().optional(),
|
|
382
370
|
// https://fal.ai/models/fal-ai/lora/api#schema-output
|
|
383
371
|
debug_latents: loraFileSchema.optional(),
|
|
384
372
|
debug_per_pass_latents: loraFileSchema.optional()
|
|
385
373
|
});
|
|
386
|
-
var base =
|
|
387
|
-
var falImageResponseSchema =
|
|
388
|
-
base.extend({ images:
|
|
374
|
+
var base = z2.looseObject(commonResponseSchema.shape);
|
|
375
|
+
var falImageResponseSchema = z2.union([
|
|
376
|
+
base.extend({ images: z2.array(falImageSchema) }),
|
|
389
377
|
base.extend({ image: falImageSchema })
|
|
390
|
-
]).transform((v) => "images" in v ? v : { ...v, images: [v.image] }).pipe(base.extend({ images:
|
|
378
|
+
]).transform((v) => "images" in v ? v : { ...v, images: [v.image] }).pipe(base.extend({ images: z2.array(falImageSchema) }));
|
|
391
379
|
function isValidationError(error) {
|
|
392
380
|
return falValidationErrorSchema.safeParse(error).success;
|
|
393
381
|
}
|
|
394
|
-
var falFailedResponseHandler =
|
|
382
|
+
var falFailedResponseHandler = createJsonErrorResponseHandler({
|
|
395
383
|
errorSchema: falErrorSchema,
|
|
396
384
|
errorToMessage: (error) => {
|
|
397
385
|
var _a;
|
|
@@ -403,52 +391,63 @@ var falFailedResponseHandler = (0, import_provider_utils2.createJsonErrorRespons
|
|
|
403
391
|
});
|
|
404
392
|
|
|
405
393
|
// src/fal-transcription-model.ts
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
394
|
+
import {
|
|
395
|
+
AISDKError
|
|
396
|
+
} from "@ai-sdk/provider";
|
|
397
|
+
import {
|
|
398
|
+
combineHeaders as combineHeaders2,
|
|
399
|
+
convertUint8ArrayToBase64,
|
|
400
|
+
createJsonErrorResponseHandler as createJsonErrorResponseHandler3,
|
|
401
|
+
createJsonResponseHandler as createJsonResponseHandler2,
|
|
402
|
+
delay,
|
|
403
|
+
getFromApi as getFromApi2,
|
|
404
|
+
parseProviderOptions as parseProviderOptions2,
|
|
405
|
+
postJsonToApi as postJsonToApi2
|
|
406
|
+
} from "@ai-sdk/provider-utils";
|
|
407
|
+
import { z as z4 } from "zod/v4";
|
|
409
408
|
|
|
410
409
|
// src/fal-error.ts
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
var falErrorDataSchema =
|
|
414
|
-
error:
|
|
415
|
-
message:
|
|
416
|
-
code:
|
|
410
|
+
import { z as z3 } from "zod/v4";
|
|
411
|
+
import { createJsonErrorResponseHandler as createJsonErrorResponseHandler2 } from "@ai-sdk/provider-utils";
|
|
412
|
+
var falErrorDataSchema = z3.object({
|
|
413
|
+
error: z3.object({
|
|
414
|
+
message: z3.string(),
|
|
415
|
+
code: z3.number()
|
|
417
416
|
})
|
|
418
417
|
});
|
|
419
|
-
var falFailedResponseHandler2 = (
|
|
418
|
+
var falFailedResponseHandler2 = createJsonErrorResponseHandler2({
|
|
420
419
|
errorSchema: falErrorDataSchema,
|
|
421
420
|
errorToMessage: (data) => data.error.message
|
|
422
421
|
});
|
|
423
422
|
|
|
424
423
|
// src/fal-transcription-model.ts
|
|
425
|
-
var falTranscriptionModelOptionsSchema =
|
|
424
|
+
var falTranscriptionModelOptionsSchema = z4.object({
|
|
426
425
|
/**
|
|
427
426
|
* Language of the audio file. If set to null, the language will be automatically detected. Defaults to null.
|
|
428
427
|
*
|
|
429
428
|
* If translate is selected as the task, the audio will be translated to English, regardless of the language selected.
|
|
430
429
|
*/
|
|
431
|
-
language:
|
|
430
|
+
language: z4.union([z4.enum(["en"]), z4.string()]).nullish().default("en"),
|
|
432
431
|
/**
|
|
433
432
|
* Whether to diarize the audio file. Defaults to true.
|
|
434
433
|
*/
|
|
435
|
-
diarize:
|
|
434
|
+
diarize: z4.boolean().nullish().default(true),
|
|
436
435
|
/**
|
|
437
436
|
* Level of the chunks to return. Either segment or word. Default value: "segment"
|
|
438
437
|
*/
|
|
439
|
-
chunkLevel:
|
|
438
|
+
chunkLevel: z4.enum(["segment", "word"]).nullish().default("segment"),
|
|
440
439
|
/**
|
|
441
440
|
* Version of the model to use. All of the models are the Whisper large variant. Default value: "3"
|
|
442
441
|
*/
|
|
443
|
-
version:
|
|
442
|
+
version: z4.enum(["3"]).nullish().default("3"),
|
|
444
443
|
/**
|
|
445
444
|
* Default value: 64
|
|
446
445
|
*/
|
|
447
|
-
batchSize:
|
|
446
|
+
batchSize: z4.number().nullish().default(64),
|
|
448
447
|
/**
|
|
449
448
|
* Number of speakers in the audio file. Defaults to null. If not provided, the number of speakers will be automatically detected.
|
|
450
449
|
*/
|
|
451
|
-
numSpeakers:
|
|
450
|
+
numSpeakers: z4.number().nullable().nullish()
|
|
452
451
|
});
|
|
453
452
|
var FalTranscriptionModel = class {
|
|
454
453
|
constructor(modelId, config) {
|
|
@@ -464,7 +463,7 @@ var FalTranscriptionModel = class {
|
|
|
464
463
|
}) {
|
|
465
464
|
var _a, _b, _c;
|
|
466
465
|
const warnings = [];
|
|
467
|
-
const falOptions = await (
|
|
466
|
+
const falOptions = await parseProviderOptions2({
|
|
468
467
|
provider: "fal",
|
|
469
468
|
providerOptions,
|
|
470
469
|
schema: falTranscriptionModelOptionsSchema
|
|
@@ -495,20 +494,20 @@ var FalTranscriptionModel = class {
|
|
|
495
494
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
496
495
|
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
497
496
|
const { body, warnings } = await this.getArgs(options);
|
|
498
|
-
const base64Audio = typeof options.audio === "string" ? options.audio :
|
|
497
|
+
const base64Audio = typeof options.audio === "string" ? options.audio : convertUint8ArrayToBase64(options.audio);
|
|
499
498
|
const audioUrl = `data:${options.mediaType};base64,${base64Audio}`;
|
|
500
|
-
const { value: queueResponse } = await (
|
|
499
|
+
const { value: queueResponse } = await postJsonToApi2({
|
|
501
500
|
url: this.config.url({
|
|
502
501
|
path: `https://queue.fal.run/fal-ai/${this.modelId}`,
|
|
503
502
|
modelId: this.modelId
|
|
504
503
|
}),
|
|
505
|
-
headers: (
|
|
504
|
+
headers: combineHeaders2(this.config.headers(), options.headers),
|
|
506
505
|
body: {
|
|
507
506
|
...body,
|
|
508
507
|
audio_url: audioUrl
|
|
509
508
|
},
|
|
510
509
|
failedResponseHandler: falFailedResponseHandler2,
|
|
511
|
-
successfulResponseHandler: (
|
|
510
|
+
successfulResponseHandler: createJsonResponseHandler2(falJobResponseSchema),
|
|
512
511
|
abortSignal: options.abortSignal,
|
|
513
512
|
fetch: this.config.fetch
|
|
514
513
|
});
|
|
@@ -524,12 +523,12 @@ var FalTranscriptionModel = class {
|
|
|
524
523
|
value: statusResponse,
|
|
525
524
|
responseHeaders: statusHeaders,
|
|
526
525
|
rawValue: statusRawResponse
|
|
527
|
-
} = await (
|
|
526
|
+
} = await getFromApi2({
|
|
528
527
|
url: this.config.url({
|
|
529
528
|
path: `https://queue.fal.run/fal-ai/${this.modelId}/requests/${queueResponse.request_id}`,
|
|
530
529
|
modelId: this.modelId
|
|
531
530
|
}),
|
|
532
|
-
headers: (
|
|
531
|
+
headers: combineHeaders2(this.config.headers(), options.headers),
|
|
533
532
|
failedResponseHandler: async ({
|
|
534
533
|
requestBodyValues,
|
|
535
534
|
response: response2,
|
|
@@ -544,12 +543,12 @@ var FalTranscriptionModel = class {
|
|
|
544
543
|
responseHeaders: {}
|
|
545
544
|
};
|
|
546
545
|
}
|
|
547
|
-
return (
|
|
546
|
+
return createJsonErrorResponseHandler3({
|
|
548
547
|
errorSchema: falErrorDataSchema,
|
|
549
548
|
errorToMessage: (data) => data.error.message
|
|
550
549
|
})({ requestBodyValues, response: response2, url });
|
|
551
550
|
},
|
|
552
|
-
successfulResponseHandler: (
|
|
551
|
+
successfulResponseHandler: createJsonResponseHandler2(
|
|
553
552
|
falTranscriptionResponseSchema
|
|
554
553
|
),
|
|
555
554
|
abortSignal: options.abortSignal,
|
|
@@ -566,13 +565,13 @@ var FalTranscriptionModel = class {
|
|
|
566
565
|
}
|
|
567
566
|
}
|
|
568
567
|
if (Date.now() - startTime > timeoutMs) {
|
|
569
|
-
throw new
|
|
568
|
+
throw new AISDKError({
|
|
570
569
|
message: "Transcription request timed out after 60 seconds",
|
|
571
570
|
name: "TranscriptionRequestTimedOut",
|
|
572
571
|
cause: response
|
|
573
572
|
});
|
|
574
573
|
}
|
|
575
|
-
await
|
|
574
|
+
await delay(pollIntervalMs);
|
|
576
575
|
}
|
|
577
576
|
return {
|
|
578
577
|
text: response.text,
|
|
@@ -596,23 +595,31 @@ var FalTranscriptionModel = class {
|
|
|
596
595
|
};
|
|
597
596
|
}
|
|
598
597
|
};
|
|
599
|
-
var falJobResponseSchema =
|
|
600
|
-
request_id:
|
|
598
|
+
var falJobResponseSchema = z4.object({
|
|
599
|
+
request_id: z4.string().nullish()
|
|
601
600
|
});
|
|
602
|
-
var falTranscriptionResponseSchema =
|
|
603
|
-
text:
|
|
604
|
-
chunks:
|
|
605
|
-
|
|
606
|
-
text:
|
|
607
|
-
timestamp:
|
|
601
|
+
var falTranscriptionResponseSchema = z4.object({
|
|
602
|
+
text: z4.string(),
|
|
603
|
+
chunks: z4.array(
|
|
604
|
+
z4.object({
|
|
605
|
+
text: z4.string(),
|
|
606
|
+
timestamp: z4.array(z4.number()).nullish()
|
|
608
607
|
})
|
|
609
608
|
).nullish(),
|
|
610
|
-
inferred_languages:
|
|
609
|
+
inferred_languages: z4.array(z4.string()).nullish()
|
|
611
610
|
});
|
|
612
611
|
|
|
613
612
|
// src/fal-speech-model.ts
|
|
614
|
-
|
|
615
|
-
|
|
613
|
+
import {
|
|
614
|
+
combineHeaders as combineHeaders3,
|
|
615
|
+
createBinaryResponseHandler as createBinaryResponseHandler2,
|
|
616
|
+
createJsonResponseHandler as createJsonResponseHandler3,
|
|
617
|
+
createStatusCodeErrorResponseHandler as createStatusCodeErrorResponseHandler2,
|
|
618
|
+
getFromApi as getFromApi3,
|
|
619
|
+
parseProviderOptions as parseProviderOptions3,
|
|
620
|
+
postJsonToApi as postJsonToApi3
|
|
621
|
+
} from "@ai-sdk/provider-utils";
|
|
622
|
+
import { z as z5 } from "zod/v4";
|
|
616
623
|
|
|
617
624
|
// src/fal-api-types.ts
|
|
618
625
|
var FAL_LANGUAGE_BOOSTS = [
|
|
@@ -653,18 +660,18 @@ var FAL_EMOTIONS = [
|
|
|
653
660
|
];
|
|
654
661
|
|
|
655
662
|
// src/fal-speech-model.ts
|
|
656
|
-
var falSpeechModelOptionsSchema =
|
|
657
|
-
voice_setting:
|
|
658
|
-
speed:
|
|
659
|
-
vol:
|
|
660
|
-
voice_id:
|
|
661
|
-
pitch:
|
|
662
|
-
english_normalization:
|
|
663
|
-
emotion:
|
|
663
|
+
var falSpeechModelOptionsSchema = z5.looseObject({
|
|
664
|
+
voice_setting: z5.object({
|
|
665
|
+
speed: z5.number().nullish(),
|
|
666
|
+
vol: z5.number().nullish(),
|
|
667
|
+
voice_id: z5.string().nullish(),
|
|
668
|
+
pitch: z5.number().nullish(),
|
|
669
|
+
english_normalization: z5.boolean().nullish(),
|
|
670
|
+
emotion: z5.enum(FAL_EMOTIONS).nullish()
|
|
664
671
|
}).partial().nullish(),
|
|
665
|
-
audio_setting:
|
|
666
|
-
language_boost:
|
|
667
|
-
pronunciation_dict:
|
|
672
|
+
audio_setting: z5.record(z5.string(), z5.unknown()).nullish(),
|
|
673
|
+
language_boost: z5.enum(FAL_LANGUAGE_BOOSTS).nullish(),
|
|
674
|
+
pronunciation_dict: z5.record(z5.string(), z5.string()).nullish()
|
|
668
675
|
});
|
|
669
676
|
var FalSpeechModel = class {
|
|
670
677
|
constructor(modelId, config) {
|
|
@@ -684,7 +691,7 @@ var FalSpeechModel = class {
|
|
|
684
691
|
providerOptions
|
|
685
692
|
}) {
|
|
686
693
|
const warnings = [];
|
|
687
|
-
const falOptions = await (
|
|
694
|
+
const falOptions = await parseProviderOptions3({
|
|
688
695
|
provider: "fal",
|
|
689
696
|
providerOptions,
|
|
690
697
|
schema: falSpeechModelOptionsSchema
|
|
@@ -720,25 +727,25 @@ var FalSpeechModel = class {
|
|
|
720
727
|
value: json,
|
|
721
728
|
responseHeaders,
|
|
722
729
|
rawValue
|
|
723
|
-
} = await (
|
|
730
|
+
} = await postJsonToApi3({
|
|
724
731
|
url: this.config.url({
|
|
725
732
|
path: `https://fal.run/${this.modelId}`,
|
|
726
733
|
modelId: this.modelId
|
|
727
734
|
}),
|
|
728
|
-
headers: (
|
|
735
|
+
headers: combineHeaders3(this.config.headers(), options.headers),
|
|
729
736
|
body: requestBody,
|
|
730
737
|
failedResponseHandler: falFailedResponseHandler2,
|
|
731
|
-
successfulResponseHandler: (
|
|
738
|
+
successfulResponseHandler: createJsonResponseHandler3(
|
|
732
739
|
falSpeechResponseSchema
|
|
733
740
|
),
|
|
734
741
|
abortSignal: options.abortSignal,
|
|
735
742
|
fetch: this.config.fetch
|
|
736
743
|
});
|
|
737
744
|
const audioUrl = json.audio.url;
|
|
738
|
-
const { value: audio } = await (
|
|
745
|
+
const { value: audio } = await getFromApi3({
|
|
739
746
|
url: audioUrl,
|
|
740
|
-
failedResponseHandler: (
|
|
741
|
-
successfulResponseHandler: (
|
|
747
|
+
failedResponseHandler: createStatusCodeErrorResponseHandler2(),
|
|
748
|
+
successfulResponseHandler: createBinaryResponseHandler2(),
|
|
742
749
|
abortSignal: options.abortSignal,
|
|
743
750
|
fetch: this.config.fetch
|
|
744
751
|
});
|
|
@@ -757,31 +764,44 @@ var FalSpeechModel = class {
|
|
|
757
764
|
};
|
|
758
765
|
}
|
|
759
766
|
};
|
|
760
|
-
var falSpeechResponseSchema =
|
|
761
|
-
audio:
|
|
762
|
-
duration_ms:
|
|
763
|
-
request_id:
|
|
767
|
+
var falSpeechResponseSchema = z5.object({
|
|
768
|
+
audio: z5.object({ url: z5.string() }),
|
|
769
|
+
duration_ms: z5.number().optional(),
|
|
770
|
+
request_id: z5.string().optional()
|
|
764
771
|
});
|
|
765
772
|
|
|
766
773
|
// src/fal-video-model.ts
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
774
|
+
import {
|
|
775
|
+
AISDKError as AISDKError2
|
|
776
|
+
} from "@ai-sdk/provider";
|
|
777
|
+
import {
|
|
778
|
+
combineHeaders as combineHeaders4,
|
|
779
|
+
convertImageModelFileToDataUri as convertImageModelFileToDataUri2,
|
|
780
|
+
createJsonErrorResponseHandler as createJsonErrorResponseHandler4,
|
|
781
|
+
createJsonResponseHandler as createJsonResponseHandler4,
|
|
782
|
+
delay as delay2,
|
|
783
|
+
getFromApi as getFromApi4,
|
|
784
|
+
lazySchema as lazySchema2,
|
|
785
|
+
parseProviderOptions as parseProviderOptions4,
|
|
786
|
+
postJsonToApi as postJsonToApi4,
|
|
787
|
+
zodSchema as zodSchema2
|
|
788
|
+
} from "@ai-sdk/provider-utils";
|
|
789
|
+
import { z as z6 } from "zod/v4";
|
|
790
|
+
var falVideoModelOptionsSchema = lazySchema2(
|
|
791
|
+
() => zodSchema2(
|
|
792
|
+
z6.object({
|
|
773
793
|
// Video loop - only for Luma models
|
|
774
|
-
loop:
|
|
794
|
+
loop: z6.boolean().nullish(),
|
|
775
795
|
// Motion strength (provider-specific)
|
|
776
|
-
motionStrength:
|
|
796
|
+
motionStrength: z6.number().min(0).max(1).nullish(),
|
|
777
797
|
// Polling configuration
|
|
778
|
-
pollIntervalMs:
|
|
779
|
-
pollTimeoutMs:
|
|
798
|
+
pollIntervalMs: z6.number().positive().nullish(),
|
|
799
|
+
pollTimeoutMs: z6.number().positive().nullish(),
|
|
780
800
|
// Resolution (model-specific, e.g., '480p', '720p', '1080p')
|
|
781
|
-
resolution:
|
|
801
|
+
resolution: z6.string().nullish(),
|
|
782
802
|
// Model-specific parameters
|
|
783
|
-
negativePrompt:
|
|
784
|
-
promptOptimizer:
|
|
803
|
+
negativePrompt: z6.string().nullish(),
|
|
804
|
+
promptOptimizer: z6.boolean().nullish()
|
|
785
805
|
}).passthrough()
|
|
786
806
|
)
|
|
787
807
|
);
|
|
@@ -803,7 +823,7 @@ var FalVideoModel = class {
|
|
|
803
823
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
804
824
|
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
805
825
|
const warnings = [];
|
|
806
|
-
const falOptions = await (
|
|
826
|
+
const falOptions = await parseProviderOptions4({
|
|
807
827
|
provider: "fal",
|
|
808
828
|
providerOptions: options.providerOptions,
|
|
809
829
|
schema: falVideoModelOptionsSchema
|
|
@@ -816,7 +836,7 @@ var FalVideoModel = class {
|
|
|
816
836
|
if (options.image.type === "url") {
|
|
817
837
|
body.image_url = options.image.url;
|
|
818
838
|
} else {
|
|
819
|
-
body.image_url = (
|
|
839
|
+
body.image_url = convertImageModelFileToDataUri2(options.image);
|
|
820
840
|
}
|
|
821
841
|
}
|
|
822
842
|
if (options.aspectRatio) {
|
|
@@ -859,21 +879,21 @@ var FalVideoModel = class {
|
|
|
859
879
|
}
|
|
860
880
|
}
|
|
861
881
|
}
|
|
862
|
-
const { value: queueResponse } = await (
|
|
882
|
+
const { value: queueResponse } = await postJsonToApi4({
|
|
863
883
|
url: this.config.url({
|
|
864
884
|
path: `https://queue.fal.run/fal-ai/${this.normalizedModelId}`,
|
|
865
885
|
modelId: this.modelId
|
|
866
886
|
}),
|
|
867
|
-
headers: (
|
|
887
|
+
headers: combineHeaders4(this.config.headers(), options.headers),
|
|
868
888
|
body,
|
|
869
889
|
failedResponseHandler: falFailedResponseHandler2,
|
|
870
|
-
successfulResponseHandler: (
|
|
890
|
+
successfulResponseHandler: createJsonResponseHandler4(falJobResponseSchema2),
|
|
871
891
|
abortSignal: options.abortSignal,
|
|
872
892
|
fetch: this.config.fetch
|
|
873
893
|
});
|
|
874
894
|
const responseUrl = queueResponse.response_url;
|
|
875
895
|
if (!responseUrl) {
|
|
876
|
-
throw new
|
|
896
|
+
throw new AISDKError2({
|
|
877
897
|
name: "FAL_VIDEO_GENERATION_ERROR",
|
|
878
898
|
message: "No response URL returned from queue endpoint"
|
|
879
899
|
});
|
|
@@ -885,12 +905,12 @@ var FalVideoModel = class {
|
|
|
885
905
|
let responseHeaders;
|
|
886
906
|
while (true) {
|
|
887
907
|
try {
|
|
888
|
-
const { value: statusResponse, responseHeaders: statusHeaders } = await (
|
|
908
|
+
const { value: statusResponse, responseHeaders: statusHeaders } = await getFromApi4({
|
|
889
909
|
url: this.config.url({
|
|
890
910
|
path: responseUrl,
|
|
891
911
|
modelId: this.modelId
|
|
892
912
|
}),
|
|
893
|
-
headers: (
|
|
913
|
+
headers: combineHeaders4(this.config.headers(), options.headers),
|
|
894
914
|
failedResponseHandler: async ({
|
|
895
915
|
response: response2,
|
|
896
916
|
url,
|
|
@@ -904,12 +924,12 @@ var FalVideoModel = class {
|
|
|
904
924
|
responseHeaders: {}
|
|
905
925
|
};
|
|
906
926
|
}
|
|
907
|
-
return (
|
|
927
|
+
return createJsonErrorResponseHandler4({
|
|
908
928
|
errorSchema: falErrorDataSchema,
|
|
909
929
|
errorToMessage: (data) => data.error.message
|
|
910
930
|
})({ response: response2, url, requestBodyValues });
|
|
911
931
|
},
|
|
912
|
-
successfulResponseHandler: (
|
|
932
|
+
successfulResponseHandler: createJsonResponseHandler4(
|
|
913
933
|
falVideoResponseSchema
|
|
914
934
|
),
|
|
915
935
|
abortSignal: options.abortSignal,
|
|
@@ -925,14 +945,14 @@ var FalVideoModel = class {
|
|
|
925
945
|
}
|
|
926
946
|
}
|
|
927
947
|
if (Date.now() - startTime > pollTimeoutMs) {
|
|
928
|
-
throw new
|
|
948
|
+
throw new AISDKError2({
|
|
929
949
|
name: "FAL_VIDEO_GENERATION_TIMEOUT",
|
|
930
950
|
message: `Video generation request timed out after ${pollTimeoutMs}ms`
|
|
931
951
|
});
|
|
932
952
|
}
|
|
933
|
-
await (
|
|
953
|
+
await delay2(pollIntervalMs);
|
|
934
954
|
if ((_f = options.abortSignal) == null ? void 0 : _f.aborted) {
|
|
935
|
-
throw new
|
|
955
|
+
throw new AISDKError2({
|
|
936
956
|
name: "FAL_VIDEO_GENERATION_ABORTED",
|
|
937
957
|
message: "Video generation request was aborted"
|
|
938
958
|
});
|
|
@@ -940,7 +960,7 @@ var FalVideoModel = class {
|
|
|
940
960
|
}
|
|
941
961
|
const videoUrl = (_g = response.video) == null ? void 0 : _g.url;
|
|
942
962
|
if (!videoUrl || !response.video) {
|
|
943
|
-
throw new
|
|
963
|
+
throw new AISDKError2({
|
|
944
964
|
name: "FAL_VIDEO_GENERATION_ERROR",
|
|
945
965
|
message: "No video URL in response"
|
|
946
966
|
});
|
|
@@ -980,29 +1000,29 @@ var FalVideoModel = class {
|
|
|
980
1000
|
};
|
|
981
1001
|
}
|
|
982
1002
|
};
|
|
983
|
-
var falJobResponseSchema2 =
|
|
984
|
-
request_id:
|
|
985
|
-
response_url:
|
|
1003
|
+
var falJobResponseSchema2 = z6.object({
|
|
1004
|
+
request_id: z6.string().nullish(),
|
|
1005
|
+
response_url: z6.string().nullish()
|
|
986
1006
|
});
|
|
987
|
-
var falVideoResponseSchema =
|
|
988
|
-
video:
|
|
989
|
-
url:
|
|
990
|
-
width:
|
|
991
|
-
height:
|
|
992
|
-
duration:
|
|
993
|
-
fps:
|
|
994
|
-
content_type:
|
|
1007
|
+
var falVideoResponseSchema = z6.object({
|
|
1008
|
+
video: z6.object({
|
|
1009
|
+
url: z6.string(),
|
|
1010
|
+
width: z6.number().nullish(),
|
|
1011
|
+
height: z6.number().nullish(),
|
|
1012
|
+
duration: z6.number().nullish(),
|
|
1013
|
+
fps: z6.number().nullish(),
|
|
1014
|
+
content_type: z6.string().nullish()
|
|
995
1015
|
}).nullish(),
|
|
996
|
-
seed:
|
|
997
|
-
timings:
|
|
998
|
-
inference:
|
|
1016
|
+
seed: z6.number().nullish(),
|
|
1017
|
+
timings: z6.object({
|
|
1018
|
+
inference: z6.number().nullish()
|
|
999
1019
|
}).nullish(),
|
|
1000
|
-
has_nsfw_concepts:
|
|
1001
|
-
prompt:
|
|
1020
|
+
has_nsfw_concepts: z6.array(z6.boolean()).nullish(),
|
|
1021
|
+
prompt: z6.string().nullish()
|
|
1002
1022
|
});
|
|
1003
1023
|
|
|
1004
1024
|
// src/version.ts
|
|
1005
|
-
var VERSION = true ? "3.0.0-beta.
|
|
1025
|
+
var VERSION = true ? "3.0.0-beta.20" : "0.0.0-test";
|
|
1006
1026
|
|
|
1007
1027
|
// src/fal-provider.ts
|
|
1008
1028
|
var defaultBaseURL = "https://fal.run";
|
|
@@ -1039,8 +1059,8 @@ function loadFalApiKey({
|
|
|
1039
1059
|
}
|
|
1040
1060
|
function createFal(options = {}) {
|
|
1041
1061
|
var _a;
|
|
1042
|
-
const baseURL =
|
|
1043
|
-
const getHeaders = () =>
|
|
1062
|
+
const baseURL = withoutTrailingSlash((_a = options.baseURL) != null ? _a : defaultBaseURL);
|
|
1063
|
+
const getHeaders = () => withUserAgentSuffix(
|
|
1044
1064
|
{
|
|
1045
1065
|
Authorization: `Key ${loadFalApiKey({
|
|
1046
1066
|
apiKey: options.apiKey
|
|
@@ -1074,7 +1094,7 @@ function createFal(options = {}) {
|
|
|
1074
1094
|
fetch: options.fetch
|
|
1075
1095
|
});
|
|
1076
1096
|
const embeddingModel = (modelId) => {
|
|
1077
|
-
throw new
|
|
1097
|
+
throw new NoSuchModelError({
|
|
1078
1098
|
modelId,
|
|
1079
1099
|
modelType: "embeddingModel"
|
|
1080
1100
|
});
|
|
@@ -1084,7 +1104,7 @@ function createFal(options = {}) {
|
|
|
1084
1104
|
imageModel: createImageModel,
|
|
1085
1105
|
image: createImageModel,
|
|
1086
1106
|
languageModel: (modelId) => {
|
|
1087
|
-
throw new
|
|
1107
|
+
throw new NoSuchModelError({
|
|
1088
1108
|
modelId,
|
|
1089
1109
|
modelType: "languageModel"
|
|
1090
1110
|
});
|
|
@@ -1098,10 +1118,9 @@ function createFal(options = {}) {
|
|
|
1098
1118
|
};
|
|
1099
1119
|
}
|
|
1100
1120
|
var fal = createFal();
|
|
1101
|
-
|
|
1102
|
-
0 && (module.exports = {
|
|
1121
|
+
export {
|
|
1103
1122
|
VERSION,
|
|
1104
1123
|
createFal,
|
|
1105
1124
|
fal
|
|
1106
|
-
}
|
|
1125
|
+
};
|
|
1107
1126
|
//# sourceMappingURL=index.js.map
|