@ai-sdk/fal 2.0.9 → 2.0.11

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.
@@ -0,0 +1,189 @@
1
+ export type FalTranscriptionAPITypes = {
2
+ /**
3
+ * URL of the audio file to transcribe. Supported formats: mp3, mp4, mpeg, mpga, m4a, wav or webm.
4
+ */
5
+ audio_url: string;
6
+
7
+ /**
8
+ * Task to perform on the audio file. Either transcribe or translate. Default value: "transcribe"
9
+ */
10
+ task?: 'transcribe' | 'translate';
11
+
12
+ /**
13
+ * Language of the audio file. If set to null, the language will be automatically detected. Defaults to null.
14
+ *
15
+ * If translate is selected as the task, the audio will be translated to English, regardless of the language selected.
16
+ */
17
+ language?:
18
+ | 'af'
19
+ | 'am'
20
+ | 'ar'
21
+ | 'as'
22
+ | 'az'
23
+ | 'ba'
24
+ | 'be'
25
+ | 'bg'
26
+ | 'bn'
27
+ | 'bo'
28
+ | 'br'
29
+ | 'bs'
30
+ | 'ca'
31
+ | 'cs'
32
+ | 'cy'
33
+ | 'da'
34
+ | 'de'
35
+ | 'el'
36
+ | 'en'
37
+ | 'es'
38
+ | 'et'
39
+ | 'eu'
40
+ | 'fa'
41
+ | 'fi'
42
+ | 'fo'
43
+ | 'fr'
44
+ | 'gl'
45
+ | 'gu'
46
+ | 'ha'
47
+ | 'haw'
48
+ | 'he'
49
+ | 'hi'
50
+ | 'hr'
51
+ | 'ht'
52
+ | 'hu'
53
+ | 'hy'
54
+ | 'id'
55
+ | 'is'
56
+ | 'it'
57
+ | 'ja'
58
+ | 'jw'
59
+ | 'ka'
60
+ | 'kk'
61
+ | 'km'
62
+ | 'kn'
63
+ | 'ko'
64
+ | 'la'
65
+ | 'lb'
66
+ | 'ln'
67
+ | 'lo'
68
+ | 'lt'
69
+ | 'lv'
70
+ | 'mg'
71
+ | 'mi'
72
+ | 'mk'
73
+ | 'ml'
74
+ | 'mn'
75
+ | 'mr'
76
+ | 'ms'
77
+ | 'mt'
78
+ | 'my'
79
+ | 'ne'
80
+ | 'nl'
81
+ | 'nn'
82
+ | 'no'
83
+ | 'oc'
84
+ | 'pa'
85
+ | 'pl'
86
+ | 'ps'
87
+ | 'pt'
88
+ | 'ro'
89
+ | 'ru'
90
+ | 'sa'
91
+ | 'sd'
92
+ | 'si'
93
+ | 'sk'
94
+ | 'sl'
95
+ | 'sn'
96
+ | 'so'
97
+ | 'sq'
98
+ | 'sr'
99
+ | 'su'
100
+ | 'sv'
101
+ | 'sw'
102
+ | 'ta'
103
+ | 'te'
104
+ | 'tg'
105
+ | 'th'
106
+ | 'tk'
107
+ | 'tl'
108
+ | 'tr'
109
+ | 'tt'
110
+ | 'uk'
111
+ | 'ur'
112
+ | 'uz'
113
+ | 'vi'
114
+ | 'yi'
115
+ | 'yo'
116
+ | 'yue'
117
+ | 'zh'
118
+ | null;
119
+
120
+ /**
121
+ * Whether to diarize the audio file. Defaults to true.
122
+ */
123
+ diarize?: boolean;
124
+
125
+ /**
126
+ * Level of the chunks to return. Either segment or word. Default value: "segment"
127
+ */
128
+ chunk_level?: 'segment' | 'word';
129
+
130
+ /**
131
+ * Version of the model to use. All of the models are the Whisper large variant. Default value: "3"
132
+ */
133
+ version?: '3';
134
+
135
+ /**
136
+ * Default value: 64
137
+ */
138
+ batch_size?: number;
139
+
140
+ /**
141
+ * Prompt to use for generation. Defaults to an empty string. Default value: ""
142
+ */
143
+ prompt?: string;
144
+
145
+ /**
146
+ * Number of speakers in the audio file. Defaults to null. If not provided, the number of speakers will be automatically detected.
147
+ */
148
+ num_speakers?: number | null;
149
+ };
150
+
151
+ export const FAL_LANGUAGE_BOOSTS = [
152
+ 'Chinese',
153
+ 'Chinese,Yue',
154
+ 'English',
155
+ 'Arabic',
156
+ 'Russian',
157
+ 'Spanish',
158
+ 'French',
159
+ 'Portuguese',
160
+ 'German',
161
+ 'Turkish',
162
+ 'Dutch',
163
+ 'Ukrainian',
164
+ 'Vietnamese',
165
+ 'Indonesian',
166
+ 'Japanese',
167
+ 'Italian',
168
+ 'Korean',
169
+ 'Thai',
170
+ 'Polish',
171
+ 'Romanian',
172
+ 'Greek',
173
+ 'Czech',
174
+ 'Finnish',
175
+ 'Hindi',
176
+ 'auto',
177
+ ] as const;
178
+ export type FalLanguageBoost = (typeof FAL_LANGUAGE_BOOSTS)[number];
179
+
180
+ export const FAL_EMOTIONS = [
181
+ 'happy',
182
+ 'sad',
183
+ 'angry',
184
+ 'fearful',
185
+ 'disgusted',
186
+ 'surprised',
187
+ 'neutral',
188
+ ] as const;
189
+ export type FalEmotion = (typeof FAL_EMOTIONS)[number];
@@ -0,0 +1,9 @@
1
+ import { FetchFunction } from '@ai-sdk/provider-utils';
2
+
3
+ export type FalConfig = {
4
+ provider: string;
5
+ url: (options: { modelId: string; path: string }) => string;
6
+ headers: () => Record<string, string | undefined>;
7
+ fetch?: FetchFunction;
8
+ generateId?: () => string;
9
+ };
@@ -0,0 +1,34 @@
1
+ import { safeParseJSON } from '@ai-sdk/provider-utils';
2
+ import { falErrorDataSchema } from './fal-error';
3
+ import { describe, it, expect } from 'vitest';
4
+
5
+ describe('falErrorDataSchema', () => {
6
+ it('should parse Fal resource exhausted error', async () => {
7
+ const error = `
8
+ {"error":{"message":"{\\n \\"error\\": {\\n \\"code\\": 429,\\n \\"message\\": \\"Resource has been exhausted (e.g. check quota).\\",\\n \\"status\\": \\"RESOURCE_EXHAUSTED\\"\\n }\\n}\\n","code":429}}
9
+ `;
10
+
11
+ const result = await safeParseJSON({
12
+ text: error,
13
+ schema: falErrorDataSchema,
14
+ });
15
+
16
+ expect(result).toStrictEqual({
17
+ success: true,
18
+ value: {
19
+ error: {
20
+ message:
21
+ '{\n "error": {\n "code": 429,\n "message": "Resource has been exhausted (e.g. check quota).",\n "status": "RESOURCE_EXHAUSTED"\n }\n}\n',
22
+ code: 429,
23
+ },
24
+ },
25
+ rawValue: {
26
+ error: {
27
+ message:
28
+ '{\n "error": {\n "code": 429,\n "message": "Resource has been exhausted (e.g. check quota).",\n "status": "RESOURCE_EXHAUSTED"\n }\n}\n',
29
+ code: 429,
30
+ },
31
+ },
32
+ });
33
+ });
34
+ });
@@ -0,0 +1,16 @@
1
+ import { z } from 'zod/v4';
2
+ import { createJsonErrorResponseHandler } from '@ai-sdk/provider-utils';
3
+
4
+ export const falErrorDataSchema = z.object({
5
+ error: z.object({
6
+ message: z.string(),
7
+ code: z.number(),
8
+ }),
9
+ });
10
+
11
+ export type FalErrorData = z.infer<typeof falErrorDataSchema>;
12
+
13
+ export const falFailedResponseHandler = createJsonErrorResponseHandler({
14
+ errorSchema: falErrorDataSchema,
15
+ errorToMessage: data => data.error.message,
16
+ });