@ai-sdk/fal 3.0.0-beta.3 → 3.0.0-beta.30

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/dist/index.js CHANGED
@@ -1,72 +1,66 @@
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
- var import_provider3 = require("@ai-sdk/provider");
31
- var import_provider_utils7 = require("@ai-sdk/provider-utils");
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
- var import_provider_utils2 = require("@ai-sdk/provider-utils");
35
- var import_v42 = require("zod/v4");
11
+ import {
12
+ combineHeaders,
13
+ convertImageModelFileToDataUri,
14
+ createBinaryResponseHandler,
15
+ createJsonErrorResponseHandler,
16
+ createJsonResponseHandler,
17
+ createStatusCodeErrorResponseHandler,
18
+ getFromApi,
19
+ parseProviderOptions,
20
+ postJsonToApi,
21
+ resolve,
22
+ serializeModelOptions,
23
+ WORKFLOW_SERIALIZE,
24
+ WORKFLOW_DESERIALIZE
25
+ } from "@ai-sdk/provider-utils";
26
+ import { z as z2 } from "zod/v4";
36
27
 
37
28
  // src/fal-image-options.ts
38
- var import_provider_utils = require("@ai-sdk/provider-utils");
39
- var import_v4 = require("zod/v4");
40
- var falImageModelOptionsSchema = (0, import_provider_utils.lazySchema)(
41
- () => (0, import_provider_utils.zodSchema)(
42
- import_v4.z.object({
29
+ import {
30
+ lazySchema,
31
+ zodSchema
32
+ } from "@ai-sdk/provider-utils";
33
+ import { z } from "zod/v4";
34
+ var falImageModelOptionsSchema = lazySchema(
35
+ () => zodSchema(
36
+ z.object({
43
37
  /** @deprecated use prompt.images instead */
44
- imageUrl: import_v4.z.string().nullish().meta({
38
+ imageUrl: z.string().nullish().meta({
45
39
  deprecated: true,
46
40
  description: "Use `prompt.images` instead"
47
41
  }),
48
- maskUrl: import_v4.z.string().nullish().meta({ deprecated: true, description: "Use `prompt.mask` instead" }),
49
- guidanceScale: import_v4.z.number().min(1).max(20).nullish(),
50
- numInferenceSteps: import_v4.z.number().min(1).max(50).nullish(),
51
- enableSafetyChecker: import_v4.z.boolean().nullish(),
52
- outputFormat: import_v4.z.enum(["jpeg", "png"]).nullish(),
53
- syncMode: import_v4.z.boolean().nullish(),
54
- strength: import_v4.z.number().nullish(),
55
- acceleration: import_v4.z.enum(["none", "regular", "high"]).nullish(),
56
- safetyTolerance: import_v4.z.enum(["1", "2", "3", "4", "5", "6"]).or(import_v4.z.number().min(1).max(6)).nullish(),
42
+ maskUrl: z.string().nullish().meta({ deprecated: true, description: "Use `prompt.mask` instead" }),
43
+ guidanceScale: z.number().min(1).max(20).nullish(),
44
+ numInferenceSteps: z.number().min(1).max(50).nullish(),
45
+ enableSafetyChecker: z.boolean().nullish(),
46
+ outputFormat: z.enum(["jpeg", "png"]).nullish(),
47
+ syncMode: z.boolean().nullish(),
48
+ strength: z.number().nullish(),
49
+ acceleration: z.enum(["none", "regular", "high"]).nullish(),
50
+ safetyTolerance: z.enum(["1", "2", "3", "4", "5", "6"]).or(z.number().min(1).max(6)).nullish(),
57
51
  /**
58
52
  * When true, converts multiple input images to `image_urls` array instead of `image_url` string.
59
53
  */
60
- useMultipleImages: import_v4.z.boolean().nullish(),
54
+ useMultipleImages: z.boolean().nullish(),
61
55
  // Deprecated snake_case versions
62
- image_url: import_v4.z.string().nullish(),
63
- mask_url: import_v4.z.string().nullish(),
64
- guidance_scale: import_v4.z.number().min(1).max(20).nullish(),
65
- num_inference_steps: import_v4.z.number().min(1).max(50).nullish(),
66
- enable_safety_checker: import_v4.z.boolean().nullish(),
67
- output_format: import_v4.z.enum(["jpeg", "png"]).nullish(),
68
- sync_mode: import_v4.z.boolean().nullish(),
69
- safety_tolerance: import_v4.z.enum(["1", "2", "3", "4", "5", "6"]).or(import_v4.z.number().min(1).max(6)).nullish()
56
+ image_url: z.string().nullish(),
57
+ mask_url: z.string().nullish(),
58
+ guidance_scale: z.number().min(1).max(20).nullish(),
59
+ num_inference_steps: z.number().min(1).max(50).nullish(),
60
+ enable_safety_checker: z.boolean().nullish(),
61
+ output_format: z.enum(["jpeg", "png"]).nullish(),
62
+ sync_mode: z.boolean().nullish(),
63
+ safety_tolerance: z.enum(["1", "2", "3", "4", "5", "6"]).or(z.number().min(1).max(6)).nullish()
70
64
  }).passthrough().transform((data) => {
71
65
  const result = {};
72
66
  const deprecatedKeys = [];
@@ -133,16 +127,25 @@ var falImageModelOptionsSchema = (0, import_provider_utils.lazySchema)(
133
127
  );
134
128
 
135
129
  // src/fal-image-model.ts
136
- var FalImageModel = class {
130
+ var FalImageModel = class _FalImageModel {
137
131
  constructor(modelId, config) {
138
132
  this.modelId = modelId;
139
133
  this.config = config;
140
- this.specificationVersion = "v3";
134
+ this.specificationVersion = "v4";
141
135
  this.maxImagesPerCall = 1;
142
136
  }
143
137
  get provider() {
144
138
  return this.config.provider;
145
139
  }
140
+ static [WORKFLOW_SERIALIZE](model) {
141
+ return serializeModelOptions({
142
+ modelId: model.modelId,
143
+ config: model.config
144
+ });
145
+ }
146
+ static [WORKFLOW_DESERIALIZE](options) {
147
+ return new _FalImageModel(options.modelId, options.config);
148
+ }
146
149
  async getArgs({
147
150
  prompt,
148
151
  n,
@@ -162,7 +165,7 @@ var FalImageModel = class {
162
165
  } else if (aspectRatio) {
163
166
  imageSize = convertAspectRatioToSize(aspectRatio);
164
167
  }
165
- const falOptions = await (0, import_provider_utils2.parseProviderOptions)({
168
+ const falOptions = await parseProviderOptions({
166
169
  provider: "fal",
167
170
  providerOptions,
168
171
  schema: falImageModelOptionsSchema
@@ -177,10 +180,10 @@ var FalImageModel = class {
177
180
  const useMultipleImages = (falOptions == null ? void 0 : falOptions.useMultipleImages) === true;
178
181
  if (useMultipleImages) {
179
182
  requestBody.image_urls = files.map(
180
- (file) => (0, import_provider_utils2.convertImageModelFileToDataUri)(file)
183
+ (file) => convertImageModelFileToDataUri(file)
181
184
  );
182
185
  } else {
183
- requestBody.image_url = (0, import_provider_utils2.convertImageModelFileToDataUri)(files[0]);
186
+ requestBody.image_url = convertImageModelFileToDataUri(files[0]);
184
187
  if (files.length > 1) {
185
188
  warnings.push({
186
189
  type: "other",
@@ -190,7 +193,7 @@ var FalImageModel = class {
190
193
  }
191
194
  }
192
195
  if (mask != null) {
193
- requestBody.mask_url = (0, import_provider_utils2.convertImageModelFileToDataUri)(mask);
196
+ requestBody.mask_url = convertImageModelFileToDataUri(mask);
194
197
  }
195
198
  if (falOptions) {
196
199
  const deprecatedKeys = "__deprecatedKeys" in falOptions ? falOptions.__deprecatedKeys : void 0;
@@ -231,15 +234,15 @@ var FalImageModel = class {
231
234
  var _a, _b, _c;
232
235
  const { requestBody, warnings } = await this.getArgs(options);
233
236
  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 (0, import_provider_utils2.postJsonToApi)({
237
+ const { value, responseHeaders } = await postJsonToApi({
235
238
  url: `${this.config.baseURL}/${this.modelId}`,
236
- headers: (0, import_provider_utils2.combineHeaders)(
237
- await (0, import_provider_utils2.resolve)(this.config.headers),
239
+ headers: combineHeaders(
240
+ this.config.headers ? await resolve(this.config.headers) : void 0,
238
241
  options.headers
239
242
  ),
240
243
  body: requestBody,
241
244
  failedResponseHandler: falFailedResponseHandler,
242
- successfulResponseHandler: (0, import_provider_utils2.createJsonResponseHandler)(
245
+ successfulResponseHandler: createJsonResponseHandler(
243
246
  falImageResponseSchema
244
247
  ),
245
248
  abortSignal: options.abortSignal,
@@ -273,7 +276,7 @@ var FalImageModel = class {
273
276
  images: targetImages.map((image, index) => {
274
277
  var _a2;
275
278
  const {
276
- url,
279
+ url: _url,
277
280
  content_type: contentType,
278
281
  file_name: fileName,
279
282
  file_data: fileData,
@@ -298,13 +301,13 @@ var FalImageModel = class {
298
301
  };
299
302
  }
300
303
  async downloadImage(url, abortSignal) {
301
- const { value: response } = await (0, import_provider_utils2.getFromApi)({
304
+ const { value: response } = await getFromApi({
302
305
  url,
303
306
  // No specific headers should be needed for this request as it's a
304
307
  // generated image provided by fal.ai.
305
308
  abortSignal,
306
- failedResponseHandler: (0, import_provider_utils2.createStatusCodeErrorResponseHandler)(),
307
- successfulResponseHandler: (0, import_provider_utils2.createBinaryResponseHandler)(),
309
+ failedResponseHandler: createStatusCodeErrorResponseHandler(),
310
+ successfulResponseHandler: createBinaryResponseHandler(),
308
311
  fetch: this.config.fetch
309
312
  });
310
313
  return response;
@@ -338,60 +341,60 @@ function convertAspectRatioToSize(aspectRatio) {
338
341
  }
339
342
  return void 0;
340
343
  }
341
- var falValidationErrorSchema = import_v42.z.object({
342
- detail: import_v42.z.array(
343
- import_v42.z.object({
344
- loc: import_v42.z.array(import_v42.z.string()),
345
- msg: import_v42.z.string(),
346
- type: import_v42.z.string()
344
+ var falValidationErrorSchema = z2.object({
345
+ detail: z2.array(
346
+ z2.object({
347
+ loc: z2.array(z2.string()),
348
+ msg: z2.string(),
349
+ type: z2.string()
347
350
  })
348
351
  )
349
352
  });
350
- var falHttpErrorSchema = import_v42.z.object({
351
- message: import_v42.z.string()
353
+ var falHttpErrorSchema = z2.object({
354
+ message: z2.string()
352
355
  });
353
- var falErrorSchema = import_v42.z.union([falValidationErrorSchema, falHttpErrorSchema]);
354
- var falImageSchema = import_v42.z.object({
355
- url: import_v42.z.string(),
356
- width: import_v42.z.number().nullish(),
357
- height: import_v42.z.number().nullish(),
356
+ var falErrorSchema = z2.union([falValidationErrorSchema, falHttpErrorSchema]);
357
+ var falImageSchema = z2.object({
358
+ url: z2.string(),
359
+ width: z2.number().nullish(),
360
+ height: z2.number().nullish(),
358
361
  // e.g. https://fal.ai/models/fal-ai/fashn/tryon/v1.6/api#schema-output
359
- content_type: import_v42.z.string().nullish(),
362
+ content_type: z2.string().nullish(),
360
363
  // e.g. https://fal.ai/models/fal-ai/flowedit/api#schema-output
361
- file_name: import_v42.z.string().nullish(),
362
- file_data: import_v42.z.string().optional(),
363
- file_size: import_v42.z.number().nullish()
364
+ file_name: z2.string().nullish(),
365
+ file_data: z2.string().optional(),
366
+ file_size: z2.number().nullish()
364
367
  });
365
- var loraFileSchema = import_v42.z.object({
366
- url: import_v42.z.string(),
367
- content_type: import_v42.z.string().optional(),
368
- file_name: import_v42.z.string().nullable().optional(),
369
- file_data: import_v42.z.string().optional(),
370
- file_size: import_v42.z.number().nullable().optional()
368
+ var loraFileSchema = z2.object({
369
+ url: z2.string(),
370
+ content_type: z2.string().optional(),
371
+ file_name: z2.string().nullable().optional(),
372
+ file_data: z2.string().optional(),
373
+ file_size: z2.number().nullable().optional()
371
374
  });
372
- var commonResponseSchema = import_v42.z.object({
373
- timings: import_v42.z.object({
374
- inference: import_v42.z.number().optional()
375
+ var commonResponseSchema = z2.object({
376
+ timings: z2.object({
377
+ inference: z2.number().optional()
375
378
  }).optional(),
376
- seed: import_v42.z.number().optional(),
377
- has_nsfw_concepts: import_v42.z.array(import_v42.z.boolean()).optional(),
378
- prompt: import_v42.z.string().optional(),
379
+ seed: z2.number().optional(),
380
+ has_nsfw_concepts: z2.array(z2.boolean()).optional(),
381
+ prompt: z2.string().optional(),
379
382
  // https://fal.ai/models/fal-ai/lcm/api#schema-output
380
- nsfw_content_detected: import_v42.z.array(import_v42.z.boolean()).optional(),
381
- num_inference_steps: import_v42.z.number().optional(),
383
+ nsfw_content_detected: z2.array(z2.boolean()).optional(),
384
+ num_inference_steps: z2.number().optional(),
382
385
  // https://fal.ai/models/fal-ai/lora/api#schema-output
383
386
  debug_latents: loraFileSchema.optional(),
384
387
  debug_per_pass_latents: loraFileSchema.optional()
385
388
  });
386
- var base = import_v42.z.looseObject(commonResponseSchema.shape);
387
- var falImageResponseSchema = import_v42.z.union([
388
- base.extend({ images: import_v42.z.array(falImageSchema) }),
389
+ var base = z2.looseObject(commonResponseSchema.shape);
390
+ var falImageResponseSchema = z2.union([
391
+ base.extend({ images: z2.array(falImageSchema) }),
389
392
  base.extend({ image: falImageSchema })
390
- ]).transform((v) => "images" in v ? v : { ...v, images: [v.image] }).pipe(base.extend({ images: import_v42.z.array(falImageSchema) }));
393
+ ]).transform((v) => "images" in v ? v : { ...v, images: [v.image] }).pipe(base.extend({ images: z2.array(falImageSchema) }));
391
394
  function isValidationError(error) {
392
395
  return falValidationErrorSchema.safeParse(error).success;
393
396
  }
394
- var falFailedResponseHandler = (0, import_provider_utils2.createJsonErrorResponseHandler)({
397
+ var falFailedResponseHandler = createJsonErrorResponseHandler({
395
398
  errorSchema: falErrorSchema,
396
399
  errorToMessage: (error) => {
397
400
  var _a;
@@ -403,68 +406,91 @@ var falFailedResponseHandler = (0, import_provider_utils2.createJsonErrorRespons
403
406
  });
404
407
 
405
408
  // src/fal-transcription-model.ts
406
- var import_provider = require("@ai-sdk/provider");
407
- var import_provider_utils4 = require("@ai-sdk/provider-utils");
408
- var import_v44 = require("zod/v4");
409
+ import {
410
+ AISDKError
411
+ } from "@ai-sdk/provider";
412
+ import {
413
+ combineHeaders as combineHeaders2,
414
+ convertUint8ArrayToBase64,
415
+ createJsonErrorResponseHandler as createJsonErrorResponseHandler3,
416
+ createJsonResponseHandler as createJsonResponseHandler2,
417
+ delay,
418
+ getFromApi as getFromApi2,
419
+ parseProviderOptions as parseProviderOptions2,
420
+ postJsonToApi as postJsonToApi2,
421
+ serializeModelOptions as serializeModelOptions2,
422
+ WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE2,
423
+ WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE2
424
+ } from "@ai-sdk/provider-utils";
425
+ import { z as z4 } from "zod/v4";
409
426
 
410
427
  // src/fal-error.ts
411
- var import_v43 = require("zod/v4");
412
- var import_provider_utils3 = require("@ai-sdk/provider-utils");
413
- var falErrorDataSchema = import_v43.z.object({
414
- error: import_v43.z.object({
415
- message: import_v43.z.string(),
416
- code: import_v43.z.number()
428
+ import { z as z3 } from "zod/v4";
429
+ import { createJsonErrorResponseHandler as createJsonErrorResponseHandler2 } from "@ai-sdk/provider-utils";
430
+ var falErrorDataSchema = z3.object({
431
+ error: z3.object({
432
+ message: z3.string(),
433
+ code: z3.number()
417
434
  })
418
435
  });
419
- var falFailedResponseHandler2 = (0, import_provider_utils3.createJsonErrorResponseHandler)({
436
+ var falFailedResponseHandler2 = createJsonErrorResponseHandler2({
420
437
  errorSchema: falErrorDataSchema,
421
438
  errorToMessage: (data) => data.error.message
422
439
  });
423
440
 
424
441
  // src/fal-transcription-model.ts
425
- var falTranscriptionModelOptionsSchema = import_v44.z.object({
442
+ var falTranscriptionModelOptionsSchema = z4.object({
426
443
  /**
427
444
  * Language of the audio file. If set to null, the language will be automatically detected. Defaults to null.
428
445
  *
429
446
  * If translate is selected as the task, the audio will be translated to English, regardless of the language selected.
430
447
  */
431
- language: import_v44.z.union([import_v44.z.enum(["en"]), import_v44.z.string()]).nullish().default("en"),
448
+ language: z4.union([z4.enum(["en"]), z4.string()]).nullish().default("en"),
432
449
  /**
433
450
  * Whether to diarize the audio file. Defaults to true.
434
451
  */
435
- diarize: import_v44.z.boolean().nullish().default(true),
452
+ diarize: z4.boolean().nullish().default(true),
436
453
  /**
437
454
  * Level of the chunks to return. Either segment or word. Default value: "segment"
438
455
  */
439
- chunkLevel: import_v44.z.enum(["segment", "word"]).nullish().default("segment"),
456
+ chunkLevel: z4.enum(["segment", "word"]).nullish().default("segment"),
440
457
  /**
441
458
  * Version of the model to use. All of the models are the Whisper large variant. Default value: "3"
442
459
  */
443
- version: import_v44.z.enum(["3"]).nullish().default("3"),
460
+ version: z4.enum(["3"]).nullish().default("3"),
444
461
  /**
445
462
  * Default value: 64
446
463
  */
447
- batchSize: import_v44.z.number().nullish().default(64),
464
+ batchSize: z4.number().nullish().default(64),
448
465
  /**
449
466
  * Number of speakers in the audio file. Defaults to null. If not provided, the number of speakers will be automatically detected.
450
467
  */
451
- numSpeakers: import_v44.z.number().nullable().nullish()
468
+ numSpeakers: z4.number().nullable().nullish()
452
469
  });
453
- var FalTranscriptionModel = class {
470
+ var FalTranscriptionModel = class _FalTranscriptionModel {
454
471
  constructor(modelId, config) {
455
472
  this.modelId = modelId;
456
473
  this.config = config;
457
- this.specificationVersion = "v3";
474
+ this.specificationVersion = "v4";
458
475
  }
459
476
  get provider() {
460
477
  return this.config.provider;
461
478
  }
479
+ static [WORKFLOW_SERIALIZE2](model) {
480
+ return serializeModelOptions2({
481
+ modelId: model.modelId,
482
+ config: model.config
483
+ });
484
+ }
485
+ static [WORKFLOW_DESERIALIZE2](options) {
486
+ return new _FalTranscriptionModel(options.modelId, options.config);
487
+ }
462
488
  async getArgs({
463
489
  providerOptions
464
490
  }) {
465
491
  var _a, _b, _c;
466
492
  const warnings = [];
467
- const falOptions = await (0, import_provider_utils4.parseProviderOptions)({
493
+ const falOptions = await parseProviderOptions2({
468
494
  provider: "fal",
469
495
  providerOptions,
470
496
  schema: falTranscriptionModelOptionsSchema
@@ -492,23 +518,23 @@ var FalTranscriptionModel = class {
492
518
  };
493
519
  }
494
520
  async doGenerate(options) {
495
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
521
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
496
522
  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
523
  const { body, warnings } = await this.getArgs(options);
498
- const base64Audio = typeof options.audio === "string" ? options.audio : (0, import_provider_utils4.convertUint8ArrayToBase64)(options.audio);
524
+ const base64Audio = typeof options.audio === "string" ? options.audio : convertUint8ArrayToBase64(options.audio);
499
525
  const audioUrl = `data:${options.mediaType};base64,${base64Audio}`;
500
- const { value: queueResponse } = await (0, import_provider_utils4.postJsonToApi)({
526
+ const { value: queueResponse } = await postJsonToApi2({
501
527
  url: this.config.url({
502
528
  path: `https://queue.fal.run/fal-ai/${this.modelId}`,
503
529
  modelId: this.modelId
504
530
  }),
505
- headers: (0, import_provider_utils4.combineHeaders)(this.config.headers(), options.headers),
531
+ headers: combineHeaders2((_e = (_d = this.config).headers) == null ? void 0 : _e.call(_d), options.headers),
506
532
  body: {
507
533
  ...body,
508
534
  audio_url: audioUrl
509
535
  },
510
536
  failedResponseHandler: falFailedResponseHandler2,
511
- successfulResponseHandler: (0, import_provider_utils4.createJsonResponseHandler)(falJobResponseSchema),
537
+ successfulResponseHandler: createJsonResponseHandler2(falJobResponseSchema),
512
538
  abortSignal: options.abortSignal,
513
539
  fetch: this.config.fetch
514
540
  });
@@ -524,12 +550,12 @@ var FalTranscriptionModel = class {
524
550
  value: statusResponse,
525
551
  responseHeaders: statusHeaders,
526
552
  rawValue: statusRawResponse
527
- } = await (0, import_provider_utils4.getFromApi)({
553
+ } = await getFromApi2({
528
554
  url: this.config.url({
529
555
  path: `https://queue.fal.run/fal-ai/${this.modelId}/requests/${queueResponse.request_id}`,
530
556
  modelId: this.modelId
531
557
  }),
532
- headers: (0, import_provider_utils4.combineHeaders)(this.config.headers(), options.headers),
558
+ headers: combineHeaders2((_g = (_f = this.config).headers) == null ? void 0 : _g.call(_f), options.headers),
533
559
  failedResponseHandler: async ({
534
560
  requestBodyValues,
535
561
  response: response2,
@@ -544,12 +570,12 @@ var FalTranscriptionModel = class {
544
570
  responseHeaders: {}
545
571
  };
546
572
  }
547
- return (0, import_provider_utils4.createJsonErrorResponseHandler)({
573
+ return createJsonErrorResponseHandler3({
548
574
  errorSchema: falErrorDataSchema,
549
575
  errorToMessage: (data) => data.error.message
550
576
  })({ requestBodyValues, response: response2, url });
551
577
  },
552
- successfulResponseHandler: (0, import_provider_utils4.createJsonResponseHandler)(
578
+ successfulResponseHandler: createJsonResponseHandler2(
553
579
  falTranscriptionResponseSchema
554
580
  ),
555
581
  abortSignal: options.abortSignal,
@@ -566,26 +592,26 @@ var FalTranscriptionModel = class {
566
592
  }
567
593
  }
568
594
  if (Date.now() - startTime > timeoutMs) {
569
- throw new import_provider.AISDKError({
595
+ throw new AISDKError({
570
596
  message: "Transcription request timed out after 60 seconds",
571
597
  name: "TranscriptionRequestTimedOut",
572
598
  cause: response
573
599
  });
574
600
  }
575
- await (0, import_provider_utils4.delay)(pollIntervalMs);
601
+ await delay(pollIntervalMs);
576
602
  }
577
603
  return {
578
604
  text: response.text,
579
- segments: (_e = (_d = response.chunks) == null ? void 0 : _d.map((chunk) => {
605
+ segments: (_i = (_h = response.chunks) == null ? void 0 : _h.map((chunk) => {
580
606
  var _a2, _b2, _c2, _d2;
581
607
  return {
582
608
  text: chunk.text,
583
609
  startSecond: (_b2 = (_a2 = chunk.timestamp) == null ? void 0 : _a2.at(0)) != null ? _b2 : 0,
584
610
  endSecond: (_d2 = (_c2 = chunk.timestamp) == null ? void 0 : _c2.at(1)) != null ? _d2 : 0
585
611
  };
586
- })) != null ? _e : [],
587
- language: (_g = (_f = response.inferred_languages) == null ? void 0 : _f.at(0)) != null ? _g : void 0,
588
- durationInSeconds: (_k = (_j = (_i = (_h = response.chunks) == null ? void 0 : _h.at(-1)) == null ? void 0 : _i.timestamp) == null ? void 0 : _j.at(1)) != null ? _k : void 0,
612
+ })) != null ? _i : [],
613
+ language: (_k = (_j = response.inferred_languages) == null ? void 0 : _j.at(0)) != null ? _k : void 0,
614
+ durationInSeconds: (_o = (_n = (_m = (_l = response.chunks) == null ? void 0 : _l.at(-1)) == null ? void 0 : _m.timestamp) == null ? void 0 : _n.at(1)) != null ? _o : void 0,
589
615
  warnings,
590
616
  response: {
591
617
  timestamp: currentDate,
@@ -596,23 +622,34 @@ var FalTranscriptionModel = class {
596
622
  };
597
623
  }
598
624
  };
599
- var falJobResponseSchema = import_v44.z.object({
600
- request_id: import_v44.z.string().nullish()
625
+ var falJobResponseSchema = z4.object({
626
+ request_id: z4.string().nullish()
601
627
  });
602
- var falTranscriptionResponseSchema = import_v44.z.object({
603
- text: import_v44.z.string(),
604
- chunks: import_v44.z.array(
605
- import_v44.z.object({
606
- text: import_v44.z.string(),
607
- timestamp: import_v44.z.array(import_v44.z.number()).nullish()
628
+ var falTranscriptionResponseSchema = z4.object({
629
+ text: z4.string(),
630
+ chunks: z4.array(
631
+ z4.object({
632
+ text: z4.string(),
633
+ timestamp: z4.array(z4.number()).nullish()
608
634
  })
609
635
  ).nullish(),
610
- inferred_languages: import_v44.z.array(import_v44.z.string()).nullish()
636
+ inferred_languages: z4.array(z4.string()).nullish()
611
637
  });
612
638
 
613
639
  // src/fal-speech-model.ts
614
- var import_provider_utils5 = require("@ai-sdk/provider-utils");
615
- var import_v45 = require("zod/v4");
640
+ import {
641
+ combineHeaders as combineHeaders3,
642
+ createBinaryResponseHandler as createBinaryResponseHandler2,
643
+ createJsonResponseHandler as createJsonResponseHandler3,
644
+ createStatusCodeErrorResponseHandler as createStatusCodeErrorResponseHandler2,
645
+ getFromApi as getFromApi3,
646
+ parseProviderOptions as parseProviderOptions3,
647
+ postJsonToApi as postJsonToApi3,
648
+ serializeModelOptions as serializeModelOptions3,
649
+ WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE3,
650
+ WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE3
651
+ } from "@ai-sdk/provider-utils";
652
+ import { z as z5 } from "zod/v4";
616
653
 
617
654
  // src/fal-api-types.ts
618
655
  var FAL_LANGUAGE_BOOSTS = [
@@ -653,28 +690,37 @@ var FAL_EMOTIONS = [
653
690
  ];
654
691
 
655
692
  // src/fal-speech-model.ts
656
- var falSpeechModelOptionsSchema = import_v45.z.looseObject({
657
- voice_setting: import_v45.z.object({
658
- speed: import_v45.z.number().nullish(),
659
- vol: import_v45.z.number().nullish(),
660
- voice_id: import_v45.z.string().nullish(),
661
- pitch: import_v45.z.number().nullish(),
662
- english_normalization: import_v45.z.boolean().nullish(),
663
- emotion: import_v45.z.enum(FAL_EMOTIONS).nullish()
693
+ var falSpeechModelOptionsSchema = z5.looseObject({
694
+ voice_setting: z5.object({
695
+ speed: z5.number().nullish(),
696
+ vol: z5.number().nullish(),
697
+ voice_id: z5.string().nullish(),
698
+ pitch: z5.number().nullish(),
699
+ english_normalization: z5.boolean().nullish(),
700
+ emotion: z5.enum(FAL_EMOTIONS).nullish()
664
701
  }).partial().nullish(),
665
- audio_setting: import_v45.z.record(import_v45.z.string(), import_v45.z.unknown()).nullish(),
666
- language_boost: import_v45.z.enum(FAL_LANGUAGE_BOOSTS).nullish(),
667
- pronunciation_dict: import_v45.z.record(import_v45.z.string(), import_v45.z.string()).nullish()
702
+ audio_setting: z5.record(z5.string(), z5.unknown()).nullish(),
703
+ language_boost: z5.enum(FAL_LANGUAGE_BOOSTS).nullish(),
704
+ pronunciation_dict: z5.record(z5.string(), z5.string()).nullish()
668
705
  });
669
- var FalSpeechModel = class {
706
+ var FalSpeechModel = class _FalSpeechModel {
670
707
  constructor(modelId, config) {
671
708
  this.modelId = modelId;
672
709
  this.config = config;
673
- this.specificationVersion = "v3";
710
+ this.specificationVersion = "v4";
674
711
  }
675
712
  get provider() {
676
713
  return this.config.provider;
677
714
  }
715
+ static [WORKFLOW_SERIALIZE3](model) {
716
+ return serializeModelOptions3({
717
+ modelId: model.modelId,
718
+ config: model.config
719
+ });
720
+ }
721
+ static [WORKFLOW_DESERIALIZE3](options) {
722
+ return new _FalSpeechModel(options.modelId, options.config);
723
+ }
678
724
  async getArgs({
679
725
  text,
680
726
  voice,
@@ -684,7 +730,7 @@ var FalSpeechModel = class {
684
730
  providerOptions
685
731
  }) {
686
732
  const warnings = [];
687
- const falOptions = await (0, import_provider_utils5.parseProviderOptions)({
733
+ const falOptions = await parseProviderOptions3({
688
734
  provider: "fal",
689
735
  providerOptions,
690
736
  schema: falSpeechModelOptionsSchema
@@ -713,32 +759,32 @@ var FalSpeechModel = class {
713
759
  return { requestBody, warnings };
714
760
  }
715
761
  async doGenerate(options) {
716
- var _a, _b, _c;
762
+ var _a, _b, _c, _d, _e;
717
763
  const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
718
764
  const { requestBody, warnings } = await this.getArgs(options);
719
765
  const {
720
766
  value: json,
721
767
  responseHeaders,
722
768
  rawValue
723
- } = await (0, import_provider_utils5.postJsonToApi)({
769
+ } = await postJsonToApi3({
724
770
  url: this.config.url({
725
771
  path: `https://fal.run/${this.modelId}`,
726
772
  modelId: this.modelId
727
773
  }),
728
- headers: (0, import_provider_utils5.combineHeaders)(this.config.headers(), options.headers),
774
+ headers: combineHeaders3((_e = (_d = this.config).headers) == null ? void 0 : _e.call(_d), options.headers),
729
775
  body: requestBody,
730
776
  failedResponseHandler: falFailedResponseHandler2,
731
- successfulResponseHandler: (0, import_provider_utils5.createJsonResponseHandler)(
777
+ successfulResponseHandler: createJsonResponseHandler3(
732
778
  falSpeechResponseSchema
733
779
  ),
734
780
  abortSignal: options.abortSignal,
735
781
  fetch: this.config.fetch
736
782
  });
737
783
  const audioUrl = json.audio.url;
738
- const { value: audio } = await (0, import_provider_utils5.getFromApi)({
784
+ const { value: audio } = await getFromApi3({
739
785
  url: audioUrl,
740
- failedResponseHandler: (0, import_provider_utils5.createStatusCodeErrorResponseHandler)(),
741
- successfulResponseHandler: (0, import_provider_utils5.createBinaryResponseHandler)(),
786
+ failedResponseHandler: createStatusCodeErrorResponseHandler2(),
787
+ successfulResponseHandler: createBinaryResponseHandler2(),
742
788
  abortSignal: options.abortSignal,
743
789
  fetch: this.config.fetch
744
790
  });
@@ -757,31 +803,44 @@ var FalSpeechModel = class {
757
803
  };
758
804
  }
759
805
  };
760
- var falSpeechResponseSchema = import_v45.z.object({
761
- audio: import_v45.z.object({ url: import_v45.z.string() }),
762
- duration_ms: import_v45.z.number().optional(),
763
- request_id: import_v45.z.string().optional()
806
+ var falSpeechResponseSchema = z5.object({
807
+ audio: z5.object({ url: z5.string() }),
808
+ duration_ms: z5.number().optional(),
809
+ request_id: z5.string().optional()
764
810
  });
765
811
 
766
812
  // src/fal-video-model.ts
767
- var import_provider2 = require("@ai-sdk/provider");
768
- var import_provider_utils6 = require("@ai-sdk/provider-utils");
769
- var import_v46 = require("zod/v4");
770
- var falVideoModelOptionsSchema = (0, import_provider_utils6.lazySchema)(
771
- () => (0, import_provider_utils6.zodSchema)(
772
- import_v46.z.object({
813
+ import {
814
+ AISDKError as AISDKError2
815
+ } from "@ai-sdk/provider";
816
+ import {
817
+ combineHeaders as combineHeaders4,
818
+ convertImageModelFileToDataUri as convertImageModelFileToDataUri2,
819
+ createJsonErrorResponseHandler as createJsonErrorResponseHandler4,
820
+ createJsonResponseHandler as createJsonResponseHandler4,
821
+ delay as delay2,
822
+ getFromApi as getFromApi4,
823
+ lazySchema as lazySchema2,
824
+ parseProviderOptions as parseProviderOptions4,
825
+ postJsonToApi as postJsonToApi4,
826
+ zodSchema as zodSchema2
827
+ } from "@ai-sdk/provider-utils";
828
+ import { z as z6 } from "zod/v4";
829
+ var falVideoModelOptionsSchema = lazySchema2(
830
+ () => zodSchema2(
831
+ z6.object({
773
832
  // Video loop - only for Luma models
774
- loop: import_v46.z.boolean().nullish(),
833
+ loop: z6.boolean().nullish(),
775
834
  // Motion strength (provider-specific)
776
- motionStrength: import_v46.z.number().min(0).max(1).nullish(),
835
+ motionStrength: z6.number().min(0).max(1).nullish(),
777
836
  // Polling configuration
778
- pollIntervalMs: import_v46.z.number().positive().nullish(),
779
- pollTimeoutMs: import_v46.z.number().positive().nullish(),
837
+ pollIntervalMs: z6.number().positive().nullish(),
838
+ pollTimeoutMs: z6.number().positive().nullish(),
780
839
  // Resolution (model-specific, e.g., '480p', '720p', '1080p')
781
- resolution: import_v46.z.string().nullish(),
840
+ resolution: z6.string().nullish(),
782
841
  // Model-specific parameters
783
- negativePrompt: import_v46.z.string().nullish(),
784
- promptOptimizer: import_v46.z.boolean().nullish()
842
+ negativePrompt: z6.string().nullish(),
843
+ promptOptimizer: z6.boolean().nullish()
785
844
  }).passthrough()
786
845
  )
787
846
  );
@@ -789,7 +848,7 @@ var FalVideoModel = class {
789
848
  constructor(modelId, config) {
790
849
  this.modelId = modelId;
791
850
  this.config = config;
792
- this.specificationVersion = "v3";
851
+ this.specificationVersion = "v4";
793
852
  this.maxVideosPerCall = 1;
794
853
  }
795
854
  // FAL video models support 1 video at a time
@@ -800,10 +859,10 @@ var FalVideoModel = class {
800
859
  return this.modelId.replace(/^fal-ai\//, "").replace(/^fal\//, "");
801
860
  }
802
861
  async doGenerate(options) {
803
- var _a, _b, _c, _d, _e, _f, _g;
862
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
804
863
  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
864
  const warnings = [];
806
- const falOptions = await (0, import_provider_utils6.parseProviderOptions)({
865
+ const falOptions = await parseProviderOptions4({
807
866
  provider: "fal",
808
867
  providerOptions: options.providerOptions,
809
868
  schema: falVideoModelOptionsSchema
@@ -816,7 +875,7 @@ var FalVideoModel = class {
816
875
  if (options.image.type === "url") {
817
876
  body.image_url = options.image.url;
818
877
  } else {
819
- body.image_url = (0, import_provider_utils6.convertImageModelFileToDataUri)(options.image);
878
+ body.image_url = convertImageModelFileToDataUri2(options.image);
820
879
  }
821
880
  }
822
881
  if (options.aspectRatio) {
@@ -859,38 +918,38 @@ var FalVideoModel = class {
859
918
  }
860
919
  }
861
920
  }
862
- const { value: queueResponse } = await (0, import_provider_utils6.postJsonToApi)({
921
+ const { value: queueResponse } = await postJsonToApi4({
863
922
  url: this.config.url({
864
923
  path: `https://queue.fal.run/fal-ai/${this.normalizedModelId}`,
865
924
  modelId: this.modelId
866
925
  }),
867
- headers: (0, import_provider_utils6.combineHeaders)(this.config.headers(), options.headers),
926
+ headers: combineHeaders4((_e = (_d = this.config).headers) == null ? void 0 : _e.call(_d), options.headers),
868
927
  body,
869
928
  failedResponseHandler: falFailedResponseHandler2,
870
- successfulResponseHandler: (0, import_provider_utils6.createJsonResponseHandler)(falJobResponseSchema2),
929
+ successfulResponseHandler: createJsonResponseHandler4(falJobResponseSchema2),
871
930
  abortSignal: options.abortSignal,
872
931
  fetch: this.config.fetch
873
932
  });
874
933
  const responseUrl = queueResponse.response_url;
875
934
  if (!responseUrl) {
876
- throw new import_provider2.AISDKError({
935
+ throw new AISDKError2({
877
936
  name: "FAL_VIDEO_GENERATION_ERROR",
878
937
  message: "No response URL returned from queue endpoint"
879
938
  });
880
939
  }
881
- const pollIntervalMs = (_d = falOptions == null ? void 0 : falOptions.pollIntervalMs) != null ? _d : 2e3;
882
- const pollTimeoutMs = (_e = falOptions == null ? void 0 : falOptions.pollTimeoutMs) != null ? _e : 3e5;
940
+ const pollIntervalMs = (_f = falOptions == null ? void 0 : falOptions.pollIntervalMs) != null ? _f : 2e3;
941
+ const pollTimeoutMs = (_g = falOptions == null ? void 0 : falOptions.pollTimeoutMs) != null ? _g : 3e5;
883
942
  const startTime = Date.now();
884
943
  let response;
885
944
  let responseHeaders;
886
945
  while (true) {
887
946
  try {
888
- const { value: statusResponse, responseHeaders: statusHeaders } = await (0, import_provider_utils6.getFromApi)({
947
+ const { value: statusResponse, responseHeaders: statusHeaders } = await getFromApi4({
889
948
  url: this.config.url({
890
949
  path: responseUrl,
891
950
  modelId: this.modelId
892
951
  }),
893
- headers: (0, import_provider_utils6.combineHeaders)(this.config.headers(), options.headers),
952
+ headers: combineHeaders4((_i = (_h = this.config).headers) == null ? void 0 : _i.call(_h), options.headers),
894
953
  failedResponseHandler: async ({
895
954
  response: response2,
896
955
  url,
@@ -904,12 +963,12 @@ var FalVideoModel = class {
904
963
  responseHeaders: {}
905
964
  };
906
965
  }
907
- return (0, import_provider_utils6.createJsonErrorResponseHandler)({
966
+ return createJsonErrorResponseHandler4({
908
967
  errorSchema: falErrorDataSchema,
909
968
  errorToMessage: (data) => data.error.message
910
969
  })({ response: response2, url, requestBodyValues });
911
970
  },
912
- successfulResponseHandler: (0, import_provider_utils6.createJsonResponseHandler)(
971
+ successfulResponseHandler: createJsonResponseHandler4(
913
972
  falVideoResponseSchema
914
973
  ),
915
974
  abortSignal: options.abortSignal,
@@ -925,22 +984,22 @@ var FalVideoModel = class {
925
984
  }
926
985
  }
927
986
  if (Date.now() - startTime > pollTimeoutMs) {
928
- throw new import_provider2.AISDKError({
987
+ throw new AISDKError2({
929
988
  name: "FAL_VIDEO_GENERATION_TIMEOUT",
930
989
  message: `Video generation request timed out after ${pollTimeoutMs}ms`
931
990
  });
932
991
  }
933
- await (0, import_provider_utils6.delay)(pollIntervalMs);
934
- if ((_f = options.abortSignal) == null ? void 0 : _f.aborted) {
935
- throw new import_provider2.AISDKError({
992
+ await delay2(pollIntervalMs);
993
+ if ((_j = options.abortSignal) == null ? void 0 : _j.aborted) {
994
+ throw new AISDKError2({
936
995
  name: "FAL_VIDEO_GENERATION_ABORTED",
937
996
  message: "Video generation request was aborted"
938
997
  });
939
998
  }
940
999
  }
941
- const videoUrl = (_g = response.video) == null ? void 0 : _g.url;
1000
+ const videoUrl = (_k = response.video) == null ? void 0 : _k.url;
942
1001
  if (!videoUrl || !response.video) {
943
- throw new import_provider2.AISDKError({
1002
+ throw new AISDKError2({
944
1003
  name: "FAL_VIDEO_GENERATION_ERROR",
945
1004
  message: "No video URL in response"
946
1005
  });
@@ -980,29 +1039,29 @@ var FalVideoModel = class {
980
1039
  };
981
1040
  }
982
1041
  };
983
- var falJobResponseSchema2 = import_v46.z.object({
984
- request_id: import_v46.z.string().nullish(),
985
- response_url: import_v46.z.string().nullish()
1042
+ var falJobResponseSchema2 = z6.object({
1043
+ request_id: z6.string().nullish(),
1044
+ response_url: z6.string().nullish()
986
1045
  });
987
- var falVideoResponseSchema = import_v46.z.object({
988
- video: import_v46.z.object({
989
- url: import_v46.z.string(),
990
- width: import_v46.z.number().nullish(),
991
- height: import_v46.z.number().nullish(),
992
- duration: import_v46.z.number().nullish(),
993
- fps: import_v46.z.number().nullish(),
994
- content_type: import_v46.z.string().nullish()
1046
+ var falVideoResponseSchema = z6.object({
1047
+ video: z6.object({
1048
+ url: z6.string(),
1049
+ width: z6.number().nullish(),
1050
+ height: z6.number().nullish(),
1051
+ duration: z6.number().nullish(),
1052
+ fps: z6.number().nullish(),
1053
+ content_type: z6.string().nullish()
995
1054
  }).nullish(),
996
- seed: import_v46.z.number().nullish(),
997
- timings: import_v46.z.object({
998
- inference: import_v46.z.number().nullish()
1055
+ seed: z6.number().nullish(),
1056
+ timings: z6.object({
1057
+ inference: z6.number().nullish()
999
1058
  }).nullish(),
1000
- has_nsfw_concepts: import_v46.z.array(import_v46.z.boolean()).nullish(),
1001
- prompt: import_v46.z.string().nullish()
1059
+ has_nsfw_concepts: z6.array(z6.boolean()).nullish(),
1060
+ prompt: z6.string().nullish()
1002
1061
  });
1003
1062
 
1004
1063
  // src/version.ts
1005
- var VERSION = true ? "3.0.0-beta.3" : "0.0.0-test";
1064
+ var VERSION = true ? "3.0.0-beta.30" : "0.0.0-test";
1006
1065
 
1007
1066
  // src/fal-provider.ts
1008
1067
  var defaultBaseURL = "https://fal.run";
@@ -1039,8 +1098,8 @@ function loadFalApiKey({
1039
1098
  }
1040
1099
  function createFal(options = {}) {
1041
1100
  var _a;
1042
- const baseURL = (0, import_provider_utils7.withoutTrailingSlash)((_a = options.baseURL) != null ? _a : defaultBaseURL);
1043
- const getHeaders = () => (0, import_provider_utils7.withUserAgentSuffix)(
1101
+ const baseURL = withoutTrailingSlash((_a = options.baseURL) != null ? _a : defaultBaseURL);
1102
+ const getHeaders = () => withUserAgentSuffix(
1044
1103
  {
1045
1104
  Authorization: `Key ${loadFalApiKey({
1046
1105
  apiKey: options.apiKey
@@ -1074,17 +1133,17 @@ function createFal(options = {}) {
1074
1133
  fetch: options.fetch
1075
1134
  });
1076
1135
  const embeddingModel = (modelId) => {
1077
- throw new import_provider3.NoSuchModelError({
1136
+ throw new NoSuchModelError({
1078
1137
  modelId,
1079
1138
  modelType: "embeddingModel"
1080
1139
  });
1081
1140
  };
1082
1141
  return {
1083
- specificationVersion: "v3",
1142
+ specificationVersion: "v4",
1084
1143
  imageModel: createImageModel,
1085
1144
  image: createImageModel,
1086
1145
  languageModel: (modelId) => {
1087
- throw new import_provider3.NoSuchModelError({
1146
+ throw new NoSuchModelError({
1088
1147
  modelId,
1089
1148
  modelType: "languageModel"
1090
1149
  });
@@ -1098,10 +1157,9 @@ function createFal(options = {}) {
1098
1157
  };
1099
1158
  }
1100
1159
  var fal = createFal();
1101
- // Annotate the CommonJS export names for ESM import in node:
1102
- 0 && (module.exports = {
1160
+ export {
1103
1161
  VERSION,
1104
1162
  createFal,
1105
1163
  fal
1106
- });
1164
+ };
1107
1165
  //# sourceMappingURL=index.js.map