@tanstack/ai-fal 1.1.0 → 1.2.0
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/esm/adapters/audio.d.ts +1 -0
- package/dist/esm/adapters/audio.js +6 -7
- package/dist/esm/adapters/audio.js.map +1 -1
- package/dist/esm/adapters/files.d.ts +1 -0
- package/dist/esm/adapters/files.js +5 -6
- package/dist/esm/adapters/files.js.map +1 -1
- package/dist/esm/adapters/image.d.ts +1 -0
- package/dist/esm/adapters/image.js +6 -7
- package/dist/esm/adapters/image.js.map +1 -1
- package/dist/esm/adapters/live.js +1 -2
- package/dist/esm/adapters/model3d.d.ts +98 -0
- package/dist/esm/adapters/model3d.js +170 -0
- package/dist/esm/adapters/model3d.js.map +1 -0
- package/dist/esm/adapters/motion.d.ts +58 -0
- package/dist/esm/adapters/motion.js +150 -0
- package/dist/esm/adapters/motion.js.map +1 -0
- package/dist/esm/adapters/speech.d.ts +1 -0
- package/dist/esm/adapters/speech.js +6 -7
- package/dist/esm/adapters/speech.js.map +1 -1
- package/dist/esm/adapters/transcription.d.ts +1 -0
- package/dist/esm/adapters/transcription.js +6 -7
- package/dist/esm/adapters/transcription.js.map +1 -1
- package/dist/esm/adapters/video.d.ts +2 -1
- package/dist/esm/adapters/video.js +13 -18
- package/dist/esm/adapters/video.js.map +1 -1
- package/dist/esm/byok.js +1 -2
- package/dist/esm/client/index.d.ts +65 -0
- package/dist/esm/client/index.js +306 -0
- package/dist/esm/client/index.js.map +1 -0
- package/dist/esm/image/generated/image-field-overrides.d.ts +459 -294
- package/dist/esm/image/generated/image-field-overrides.js +312 -190
- package/dist/esm/image/generated/image-field-overrides.js.map +1 -1
- package/dist/esm/image/image-inputs.js +7 -4
- package/dist/esm/image/image-inputs.js.map +1 -1
- package/dist/esm/image/image-provider-options.js +1 -2
- package/dist/esm/image/legacy-image-field-overrides.d.ts +13 -0
- package/dist/esm/image/legacy-image-field-overrides.js +91 -0
- package/dist/esm/image/legacy-image-field-overrides.js.map +1 -0
- package/dist/esm/index.d.ts +6 -2
- package/dist/esm/index.js +5 -2
- package/dist/esm/model-meta.d.ts +49 -0
- package/dist/esm/model3d/generated/mesh-field-overrides.d.ts +20 -0
- package/dist/esm/model3d/generated/mesh-field-overrides.js +20 -0
- package/dist/esm/model3d/generated/mesh-field-overrides.js.map +1 -0
- package/dist/esm/model3d/model3d-inputs.d.ts +39 -0
- package/dist/esm/model3d/model3d-inputs.js +206 -0
- package/dist/esm/model3d/model3d-inputs.js.map +1 -0
- package/dist/esm/model3d/model3d-output.d.ts +25 -0
- package/dist/esm/model3d/model3d-output.js +181 -0
- package/dist/esm/model3d/model3d-output.js.map +1 -0
- package/dist/esm/utils/billing.js +1 -2
- package/dist/esm/utils/client.d.ts +16 -1
- package/dist/esm/utils/client.js +31 -9
- package/dist/esm/utils/client.js.map +1 -1
- package/dist/esm/utils/configure.d.ts +12 -0
- package/dist/esm/utils/configure.js +19 -0
- package/dist/esm/utils/configure.js.map +1 -0
- package/dist/esm/utils/index.d.ts +2 -1
- package/dist/esm/video/video-provider-options.js +20 -31
- package/dist/esm/video/video-provider-options.js.map +1 -1
- package/package.json +8 -7
- package/src/adapters/audio.ts +7 -6
- package/src/adapters/files.ts +5 -4
- package/src/adapters/image.ts +8 -7
- package/src/adapters/model3d.ts +219 -0
- package/src/adapters/motion.ts +237 -0
- package/src/adapters/speech.ts +7 -6
- package/src/adapters/transcription.ts +8 -7
- package/src/adapters/video.ts +16 -18
- package/src/client/index.ts +456 -0
- package/src/image/generated/image-field-overrides.ts +159 -110
- package/src/image/image-inputs.ts +9 -4
- package/src/image/legacy-image-field-overrides.ts +94 -0
- package/src/index.ts +20 -1
- package/src/model-meta.ts +106 -0
- package/src/model3d/generated/mesh-field-overrides.ts +46 -0
- package/src/model3d/model3d-inputs.ts +232 -0
- package/src/model3d/model3d-output.ts +216 -0
- package/src/utils/client.ts +37 -4
- package/src/utils/configure.ts +17 -0
- package/src/utils/index.ts +2 -1
- package/src/video/video-provider-options.ts +9 -27
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { createAdapterFalClient, extractUrlExtension, falValidationMessage } from "../utils/client.js";
|
|
2
|
+
import { buildFalUsage, takeBillableUnits } from "../utils/billing.js";
|
|
3
|
+
import { BaseMotionAdapter } from "@tanstack/ai/adapters";
|
|
4
|
+
// src/adapters/motion.ts
|
|
5
|
+
function isFalFile(value) {
|
|
6
|
+
return typeof value === "object" && value !== null && "url" in value && typeof value.url === "string";
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Every file in a fal motion output becomes an asset. The format comes from
|
|
10
|
+
* the file name or URL extension, then from the field name
|
|
11
|
+
* (`fbx_file` → `fbx`, `motion_json` → `json`).
|
|
12
|
+
*/
|
|
13
|
+
function toMotionAssets(output) {
|
|
14
|
+
const assets = [];
|
|
15
|
+
for (const [field, value] of Object.entries(output)) {
|
|
16
|
+
if (!isFalFile(value)) continue;
|
|
17
|
+
const format = extractUrlExtension(value.file_name ?? value.url)?.toLowerCase() ?? (field === "motion_json" ? "json" : field.replace(/_file$/, ""));
|
|
18
|
+
assets.push({
|
|
19
|
+
url: value.url,
|
|
20
|
+
format,
|
|
21
|
+
...value.content_type ? { contentType: value.content_type } : {},
|
|
22
|
+
...value.file_name ? { fileName: value.file_name } : {},
|
|
23
|
+
...value.file_size !== void 0 ? { fileSize: value.file_size } : {}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
return assets;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* fal motion adapter. Runs text-to-motion models on the fal queue and
|
|
30
|
+
* returns the skeletal animation files they produce.
|
|
31
|
+
*
|
|
32
|
+
* fal file URLs follow the account's media expiry setting, so copy files
|
|
33
|
+
* you want to keep.
|
|
34
|
+
*
|
|
35
|
+
* @experimental Motion generation is an experimental feature and may change.
|
|
36
|
+
*/
|
|
37
|
+
var FalMotionAdapter = class extends BaseMotionAdapter {
|
|
38
|
+
name = "fal";
|
|
39
|
+
client;
|
|
40
|
+
constructor(model, config) {
|
|
41
|
+
super(model);
|
|
42
|
+
this.client = createAdapterFalClient(config);
|
|
43
|
+
}
|
|
44
|
+
async createMotionJob(options) {
|
|
45
|
+
const { logger } = options;
|
|
46
|
+
logger.request(`activity=generateMotion provider=fal model=${this.model}`, {
|
|
47
|
+
provider: "fal",
|
|
48
|
+
model: this.model
|
|
49
|
+
});
|
|
50
|
+
try {
|
|
51
|
+
const { request_id } = await this.client.queue.submit(this.model, {
|
|
52
|
+
input: {
|
|
53
|
+
...options.modelOptions,
|
|
54
|
+
prompt: options.prompt,
|
|
55
|
+
...options.duration !== void 0 ? { duration: options.duration } : {}
|
|
56
|
+
},
|
|
57
|
+
...options.abortSignal ? { abortSignal: options.abortSignal } : {}
|
|
58
|
+
});
|
|
59
|
+
return {
|
|
60
|
+
jobId: request_id,
|
|
61
|
+
model: this.model
|
|
62
|
+
};
|
|
63
|
+
} catch (error) {
|
|
64
|
+
logger.errors("fal.createMotionJob fatal", {
|
|
65
|
+
error,
|
|
66
|
+
source: "fal.createMotionJob"
|
|
67
|
+
});
|
|
68
|
+
throw error;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
async getMotionStatus(jobId, options) {
|
|
72
|
+
const response = await this.client.queue.status(this.model, {
|
|
73
|
+
requestId: jobId,
|
|
74
|
+
logs: false,
|
|
75
|
+
...options?.abortSignal ? { abortSignal: options.abortSignal } : {}
|
|
76
|
+
});
|
|
77
|
+
switch (response.status) {
|
|
78
|
+
case "IN_QUEUE": return {
|
|
79
|
+
jobId,
|
|
80
|
+
status: "pending",
|
|
81
|
+
...response.queue_position != null ? { queuePosition: response.queue_position } : {}
|
|
82
|
+
};
|
|
83
|
+
case "IN_PROGRESS": return {
|
|
84
|
+
jobId,
|
|
85
|
+
status: "processing"
|
|
86
|
+
};
|
|
87
|
+
case "COMPLETED": return response.error ? {
|
|
88
|
+
jobId,
|
|
89
|
+
status: "failed",
|
|
90
|
+
error: response.error
|
|
91
|
+
} : {
|
|
92
|
+
jobId,
|
|
93
|
+
status: "completed"
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
async getMotion(jobId, options) {
|
|
98
|
+
let result;
|
|
99
|
+
try {
|
|
100
|
+
result = await this.client.queue.result(this.model, {
|
|
101
|
+
requestId: jobId,
|
|
102
|
+
...options?.abortSignal ? { abortSignal: options.abortSignal } : {}
|
|
103
|
+
});
|
|
104
|
+
} catch (error) {
|
|
105
|
+
if (options?.abortSignal?.aborted) throw error;
|
|
106
|
+
const validation = falValidationMessage(error);
|
|
107
|
+
if (validation) throw new Error(`Motion generation failed: ${validation}`);
|
|
108
|
+
throw error;
|
|
109
|
+
}
|
|
110
|
+
const output = result.data ?? {};
|
|
111
|
+
const assets = toMotionAssets(output);
|
|
112
|
+
if (assets.length === 0) throw new Error(`fal returned no motion files for request ${jobId}`);
|
|
113
|
+
const usage = buildFalUsage(takeBillableUnits(result.requestId));
|
|
114
|
+
return {
|
|
115
|
+
jobId,
|
|
116
|
+
model: this.model,
|
|
117
|
+
assets,
|
|
118
|
+
...typeof output.seed === "number" ? { seed: output.seed } : {},
|
|
119
|
+
...usage ? { usage } : {}
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Uses the fal queue cancel endpoint. fal removes a queued request. A
|
|
124
|
+
* request that already runs gets a cancel request and may still finish.
|
|
125
|
+
* fal rejects a cancel for a request that already completed.
|
|
126
|
+
*/
|
|
127
|
+
async cancelMotionJob(jobId, options) {
|
|
128
|
+
await this.client.queue.cancel(this.model, {
|
|
129
|
+
requestId: jobId,
|
|
130
|
+
...options?.abortSignal ? { abortSignal: options.abortSignal } : {}
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* Create a fal motion adapter. Reads `config.apiKey`, or `FAL_KEY` from the
|
|
136
|
+
* environment.
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```ts
|
|
140
|
+
* const adapter = falMotion('fal-ai/hunyuan-motion')
|
|
141
|
+
* ```
|
|
142
|
+
*
|
|
143
|
+
* @experimental Motion generation is an experimental feature and may change.
|
|
144
|
+
*/
|
|
145
|
+
function falMotion(model, config) {
|
|
146
|
+
return new FalMotionAdapter(model, config);
|
|
147
|
+
}
|
|
148
|
+
export { FalMotionAdapter, falMotion };
|
|
149
|
+
|
|
150
|
+
//# sourceMappingURL=motion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"motion.js","names":[],"sources":["../../../src/adapters/motion.ts"],"sourcesContent":["import { BaseMotionAdapter } from '@tanstack/ai/adapters'\nimport {\n createAdapterFalClient,\n extractUrlExtension,\n falValidationMessage,\n} from '../utils/client'\nimport { buildFalUsage, takeBillableUnits } from '../utils/billing'\nimport type {\n MotionAsset,\n MotionGenerationOptions,\n MotionGenerationResult,\n MotionJobResult,\n MotionStatusResult,\n} from '@tanstack/ai'\nimport type { FalModelInput } from '../model-meta'\nimport type { FalClientConfig } from '../utils/client'\nimport type { FalClient } from '../client/index'\n\n/**\n * fal motion models. Both Hunyuan Motion endpoints return an FBX file and\n * take the same input. Any other fal endpoint id is accepted as a string.\n */\nexport type FalMotionModel =\n | 'fal-ai/hunyuan-motion'\n | 'fal-ai/hunyuan-motion/fast'\n | (string & {})\n\n/**\n * Hunyuan Motion options: `seed`, `guidance_scale` (1 to 10, default 5), and\n * `output_format` (`'fbx'` default, or `'dict'` for raw JSON). `prompt` and\n * `duration` are top-level `generateMotion()` options.\n */\nexport type FalHunyuanMotionProviderOptions = Omit<\n FalModelInput<'fal-ai/hunyuan-motion'>,\n 'prompt' | 'duration'\n>\n\n/** Provider options for a fal motion model. */\nexport type FalMotionProviderOptions<TModel extends string> = TModel extends\n | 'fal-ai/hunyuan-motion'\n | 'fal-ai/hunyuan-motion/fast'\n ? FalHunyuanMotionProviderOptions\n : Record<string, unknown>\n\ninterface FalQueueStatusResponse {\n status: 'IN_QUEUE' | 'IN_PROGRESS' | 'COMPLETED'\n queue_position?: number\n /** Set on a COMPLETED request that failed */\n error?: string\n}\n\ninterface FalFile {\n url: string\n content_type?: string\n file_name?: string\n file_size?: number\n}\n\nfunction isFalFile(value: unknown): value is FalFile {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'url' in value &&\n typeof value.url === 'string'\n )\n}\n\n/**\n * Every file in a fal motion output becomes an asset. The format comes from\n * the file name or URL extension, then from the field name\n * (`fbx_file` → `fbx`, `motion_json` → `json`).\n */\nfunction toMotionAssets(output: Record<string, unknown>): Array<MotionAsset> {\n const assets: Array<MotionAsset> = []\n for (const [field, value] of Object.entries(output)) {\n if (!isFalFile(value)) continue\n const extension = extractUrlExtension(value.file_name ?? value.url)\n const format =\n extension?.toLowerCase() ??\n (field === 'motion_json' ? 'json' : field.replace(/_file$/, ''))\n assets.push({\n url: value.url,\n format,\n ...(value.content_type ? { contentType: value.content_type } : {}),\n ...(value.file_name ? { fileName: value.file_name } : {}),\n ...(value.file_size !== undefined ? { fileSize: value.file_size } : {}),\n })\n }\n return assets\n}\n\n/**\n * fal motion adapter. Runs text-to-motion models on the fal queue and\n * returns the skeletal animation files they produce.\n *\n * fal file URLs follow the account's media expiry setting, so copy files\n * you want to keep.\n *\n * @experimental Motion generation is an experimental feature and may change.\n */\nexport class FalMotionAdapter<\n TModel extends FalMotionModel,\n> extends BaseMotionAdapter<TModel, FalMotionProviderOptions<TModel>> {\n readonly name = 'fal' as const\n private readonly client: FalClient\n\n constructor(model: TModel, config?: FalClientConfig) {\n super(model)\n this.client = createAdapterFalClient(config)\n }\n\n async createMotionJob(\n options: MotionGenerationOptions<FalMotionProviderOptions<TModel>>,\n ): Promise<MotionJobResult> {\n const { logger } = options\n logger.request(`activity=generateMotion provider=fal model=${this.model}`, {\n provider: 'fal',\n model: this.model,\n })\n try {\n const { request_id } = await this.client.queue.submit(this.model, {\n // The fal SDK keys input types by endpoint id; a generic TModel\n // cannot narrow to one, so the built input is cast like falVideo does.\n input: {\n ...options.modelOptions,\n prompt: options.prompt,\n ...(options.duration !== undefined\n ? { duration: options.duration }\n : {}),\n } as FalModelInput<TModel>,\n ...(options.abortSignal ? { abortSignal: options.abortSignal } : {}),\n })\n return { jobId: request_id, model: this.model }\n } catch (error) {\n logger.errors('fal.createMotionJob fatal', {\n error,\n source: 'fal.createMotionJob',\n })\n throw error\n }\n }\n\n async getMotionStatus(\n jobId: string,\n options?: { abortSignal?: AbortSignal },\n ): Promise<MotionStatusResult> {\n const response = (await this.client.queue.status(this.model, {\n requestId: jobId,\n logs: false,\n ...(options?.abortSignal ? { abortSignal: options.abortSignal } : {}),\n })) as FalQueueStatusResponse\n\n switch (response.status) {\n case 'IN_QUEUE':\n return {\n jobId,\n status: 'pending',\n ...(response.queue_position != null\n ? { queuePosition: response.queue_position }\n : {}),\n }\n case 'IN_PROGRESS':\n return { jobId, status: 'processing' }\n case 'COMPLETED':\n return response.error\n ? { jobId, status: 'failed', error: response.error }\n : { jobId, status: 'completed' }\n }\n }\n\n async getMotion(\n jobId: string,\n options?: { abortSignal?: AbortSignal },\n ): Promise<MotionGenerationResult> {\n let result\n try {\n result = await this.client.queue.result(this.model, {\n requestId: jobId,\n ...(options?.abortSignal ? { abortSignal: options.abortSignal } : {}),\n })\n } catch (error) {\n if (options?.abortSignal?.aborted) throw error\n const validation = falValidationMessage(error)\n if (validation) {\n throw new Error(`Motion generation failed: ${validation}`)\n }\n throw error\n }\n\n const output = (result.data ?? {}) as Record<string, unknown>\n const assets = toMotionAssets(output)\n if (assets.length === 0) {\n throw new Error(`fal returned no motion files for request ${jobId}`)\n }\n const usage = buildFalUsage(takeBillableUnits(result.requestId))\n return {\n jobId,\n model: this.model,\n assets,\n ...(typeof output.seed === 'number' ? { seed: output.seed } : {}),\n ...(usage ? { usage } : {}),\n }\n }\n\n /**\n * Uses the fal queue cancel endpoint. fal removes a queued request. A\n * request that already runs gets a cancel request and may still finish.\n * fal rejects a cancel for a request that already completed.\n */\n async cancelMotionJob(\n jobId: string,\n options?: { abortSignal?: AbortSignal },\n ): Promise<void> {\n await this.client.queue.cancel(this.model, {\n requestId: jobId,\n ...(options?.abortSignal ? { abortSignal: options.abortSignal } : {}),\n })\n }\n}\n\n/**\n * Create a fal motion adapter. Reads `config.apiKey`, or `FAL_KEY` from the\n * environment.\n *\n * @example\n * ```ts\n * const adapter = falMotion('fal-ai/hunyuan-motion')\n * ```\n *\n * @experimental Motion generation is an experimental feature and may change.\n */\nexport function falMotion<TModel extends FalMotionModel>(\n model: TModel,\n config?: FalClientConfig,\n): FalMotionAdapter<TModel> {\n return new FalMotionAdapter(model, config)\n}\n"],"mappings":";;;;AA0DA,SAAS,UAAU,OAAkC;CACnD,OACE,OAAO,UAAU,YACjB,UAAU,QACV,SAAS,SACT,OAAO,MAAM,QAAQ;AAEzB;;;;;;AAOA,SAAS,eAAe,QAAqD;CAC3E,MAAM,SAA6B,CAAC;CACpC,KAAK,MAAM,CAAC,OAAO,UAAU,OAAO,QAAQ,MAAM,GAAG;EACnD,IAAI,CAAC,UAAU,KAAK,GAAG;EAEvB,MAAM,SADY,oBAAoB,MAAM,aAAa,MAAM,GAE7D,CAAA,EAAW,YAAY,MACtB,UAAU,gBAAgB,SAAS,MAAM,QAAQ,UAAU,EAAE;EAChE,OAAO,KAAK;GACV,KAAK,MAAM;GACX;GACA,GAAI,MAAM,eAAe,EAAE,aAAa,MAAM,aAAa,IAAI,CAAC;GAChE,GAAI,MAAM,YAAY,EAAE,UAAU,MAAM,UAAU,IAAI,CAAC;GACvD,GAAI,MAAM,cAAc,KAAA,IAAY,EAAE,UAAU,MAAM,UAAU,IAAI,CAAC;EACvE,CAAC;CACH;CACA,OAAO;AACT;;;;;;;;;;AAWA,IAAa,mBAAb,cAEU,kBAA4D;CACpE,OAAgB;CAChB;CAEA,YAAY,OAAe,QAA0B;EACnD,MAAM,KAAK;EACX,KAAK,SAAS,uBAAuB,MAAM;CAC7C;CAEA,MAAM,gBACJ,S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ACd,IAAI,SAAS,aAAa,SAAS,MAAM;GACzC,MAAM,aAAa,qBAAqB,KAAK;GAC7C,IAAI,YACF,MAAM,IAAI,MAAM,6BAA6B,YAAY;GAE3D,MAAM;EACR;EAEA,MAAM,SAAU,OAAO,QAAQ,CAAC;EAChC,MAAM,SAAS,eAAe,MAAM;EACpC,IAAI,OAAO,WAAW,GACpB,MAAM,IAAI,MAAM,4CAA4C,OAAO;EAErE,MAAM,QAAQ,cAAc,kBAAkB,OAAO,SAAS,CAAC;EAC/D,OAAO;GACL;GACA,OAAO,KAAK;GACZ;GACA,GAAI,OAAO,OAAO,SAAS,WAAW,EAAE,MAAM,OAAO,KAAK,IAAI,CAAC;GAC/D,GAAI,QAAQ,EAAE,MAAM,IAAI,CAAC;EAC3B;CACF;;;;;;CAOA,MAAM,gBACJ,OACA,SACe;EACf,MAAM,KAAK,OAAO,MAAM,OAAO,KAAK,OAAO;GACzC,WAAW;GACX,GAAI,SAAS,cAAc,EAAE,aAAa,QAAQ,YAAY,IAAI,CAAC;EACrE,CAAC;CACH;AACF;;;;;;;;;;;;AAaA,SAAgB,UACd,OACA,QAC0B;CAC1B,OAAO,IAAI,iBAAiB,OAAO,MAAM;AAC3C"}
|
|
@@ -23,6 +23,7 @@ export type FalSpeechProviderOptions<TModel extends string> = Omit<FalModelInput
|
|
|
23
23
|
*/
|
|
24
24
|
export declare class FalSpeechAdapter<TModel extends FalModel> extends BaseTTSAdapter<TModel, FalSpeechProviderOptions<TModel>> {
|
|
25
25
|
readonly name: "fal";
|
|
26
|
+
private readonly client;
|
|
26
27
|
constructor(model: TModel, config?: FalClientConfig);
|
|
27
28
|
generateSpeech(options: TTSOptions<FalSpeechProviderOptions<TModel>>): Promise<TTSResult>;
|
|
28
29
|
private buildInput;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
+
import { arrayBufferToBase64, createAdapterFalClient, extractUrlExtension, generateId } from "../utils/client.js";
|
|
1
2
|
import { buildFalUsage, takeBillableUnits } from "../utils/billing.js";
|
|
2
|
-
import { arrayBufferToBase64, configureFalClient, extractUrlExtension, generateId } from "../utils/client.js";
|
|
3
|
-
import { fal } from "@fal-ai/client";
|
|
4
3
|
import { BaseTTSAdapter } from "@tanstack/ai/adapters";
|
|
5
|
-
|
|
4
|
+
// src/adapters/speech.ts
|
|
6
5
|
/**
|
|
7
6
|
* fal.ai text-to-speech adapter.
|
|
8
7
|
*
|
|
@@ -20,9 +19,10 @@ import { BaseTTSAdapter } from "@tanstack/ai/adapters";
|
|
|
20
19
|
*/
|
|
21
20
|
var FalSpeechAdapter = class extends BaseTTSAdapter {
|
|
22
21
|
name = "fal";
|
|
22
|
+
client;
|
|
23
23
|
constructor(model, config) {
|
|
24
24
|
super(model, {});
|
|
25
|
-
|
|
25
|
+
this.client = createAdapterFalClient(config);
|
|
26
26
|
}
|
|
27
27
|
async generateSpeech(options) {
|
|
28
28
|
const { logger } = options;
|
|
@@ -33,7 +33,7 @@ var FalSpeechAdapter = class extends BaseTTSAdapter {
|
|
|
33
33
|
let requestId;
|
|
34
34
|
try {
|
|
35
35
|
const input = this.buildInput(options);
|
|
36
|
-
const result = await
|
|
36
|
+
const result = await this.client.subscribe(this.model, {
|
|
37
37
|
input,
|
|
38
38
|
...options.abortSignal ? { abortSignal: options.abortSignal } : {},
|
|
39
39
|
onEnqueue: (id) => {
|
|
@@ -42,7 +42,7 @@ var FalSpeechAdapter = class extends BaseTTSAdapter {
|
|
|
42
42
|
});
|
|
43
43
|
return await this.transformResponse(result, options.abortSignal);
|
|
44
44
|
} catch (error) {
|
|
45
|
-
if (requestId && options.abortSignal?.aborted)
|
|
45
|
+
if (requestId && options.abortSignal?.aborted) this.client.queue.cancel(this.model, { requestId }).catch(() => {});
|
|
46
46
|
logger.errors("fal.generateSpeech fatal", {
|
|
47
47
|
error,
|
|
48
48
|
source: "fal.generateSpeech"
|
|
@@ -93,7 +93,6 @@ var FalSpeechAdapter = class extends BaseTTSAdapter {
|
|
|
93
93
|
function falSpeech(model, config) {
|
|
94
94
|
return new FalSpeechAdapter(model, config);
|
|
95
95
|
}
|
|
96
|
-
//#endregion
|
|
97
96
|
export { FalSpeechAdapter, falSpeech };
|
|
98
97
|
|
|
99
98
|
//# sourceMappingURL=speech.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"speech.js","names":[],"sources":["../../../src/adapters/speech.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"speech.js","names":["utilGenerateId"],"sources":["../../../src/adapters/speech.ts"],"sourcesContent":["import { BaseTTSAdapter } from '@tanstack/ai/adapters'\nimport {\n arrayBufferToBase64,\n createAdapterFalClient,\n extractUrlExtension,\n generateId as utilGenerateId,\n} from '../utils/client'\nimport { buildFalUsage, takeBillableUnits } from '../utils/billing'\nimport type { OutputType, Result } from '@fal-ai/client'\nimport type { TTSOptions, TTSResult } from '@tanstack/ai'\nimport type { FalClientConfig } from '../utils/client'\nimport type { FalClient } from '../client/index'\nimport type { FalModel, FalModelInput } from '../model-meta'\n\n/**\n * Provider options for TTS, excluding fields TanStack AI handles.\n */\nexport type FalSpeechProviderOptions<TModel extends string> = Omit<\n FalModelInput<TModel>,\n 'prompt' | 'text'\n>\n\n/**\n * fal.ai text-to-speech adapter.\n *\n * Supports fal.ai TTS models like kokoro, elevenlabs, etc.\n *\n * @example\n * ```typescript\n * const adapter = falSpeech('fal-ai/kokoro/american-english')\n * const result = await generateSpeech({\n * adapter,\n * text: 'Hello, world!',\n * voice: 'af_heart',\n * })\n * ```\n */\nexport class FalSpeechAdapter<TModel extends FalModel> extends BaseTTSAdapter<\n TModel,\n FalSpeechProviderOptions<TModel>\n> {\n readonly name = 'fal' as const\n private readonly client: FalClient\n\n constructor(model: TModel, config?: FalClientConfig) {\n super(model, {})\n this.client = createAdapterFalClient(config)\n }\n\n async generateSpeech(\n options: TTSOptions<FalSpeechProviderOptions<TModel>>,\n ): Promise<TTSResult> {\n const { logger } = options\n logger.request(`activity=generateSpeech provider=fal model=${this.model}`, {\n provider: 'fal',\n model: this.model,\n })\n let requestId: string | undefined\n try {\n const input = this.buildInput(options)\n // Pass the abortSignal per request, not in the client config.\n const result = await this.client.subscribe(this.model, {\n input,\n ...(options.abortSignal ? { abortSignal: options.abortSignal } : {}),\n onEnqueue: (id) => {\n requestId = id\n },\n })\n return await this.transformResponse(result, options.abortSignal)\n } catch (error) {\n // The SDK stops waiting on abort but leaves the queued job running.\n // Cancel it so it stops billing.\n if (requestId && options.abortSignal?.aborted) {\n this.client.queue.cancel(this.model, { requestId }).catch(() => {})\n }\n logger.errors('fal.generateSpeech fatal', {\n error,\n source: 'fal.generateSpeech',\n })\n throw error\n }\n }\n\n private buildInput(\n options: TTSOptions<FalSpeechProviderOptions<TModel>>,\n ): FalModelInput<TModel> {\n const input = {\n ...options.modelOptions,\n // Map text to both prompt and text fields (different models use different fields)\n prompt: options.text,\n text: options.text,\n ...(options.voice ? { voice: options.voice } : {}),\n ...(options.speed ? { speed: options.speed } : {}),\n } as FalModelInput<TModel>\n return input\n }\n\n protected override generateId(): string {\n return utilGenerateId(this.name)\n }\n\n private async transformResponse(\n response: Result<OutputType<TModel>>,\n abortSignal: AbortSignal | undefined,\n ): Promise<TTSResult> {\n const data = response.data as Record<string, unknown>\n\n // fal returns { audio: { url, content_type } } or { audio_url: string }\n let audioUrl: string | undefined\n let contentType: string | undefined\n\n if (\n data['audio'] &&\n typeof data['audio'] === 'object' &&\n 'url' in data['audio']\n ) {\n const audioObj = data['audio'] as { url: string; content_type?: string }\n audioUrl = audioObj.url\n contentType = audioObj.content_type\n } else if (typeof data.audio_url === 'string') {\n audioUrl = data.audio_url\n }\n\n if (!audioUrl) {\n throw new Error('Audio URL not found in fal TTS response')\n }\n\n // Fetch the audio and convert to base64 to match TTSResult contract.\n // Using a chunked helper here — spreading Uint8Array into btoa exceeds\n // V8's argument limit (~65k) for any realistic TTS clip.\n const audioResponse = await fetch(\n audioUrl,\n abortSignal ? { signal: abortSignal } : undefined,\n )\n if (!audioResponse.ok) {\n throw new Error(\n `Failed to fetch audio from ${audioUrl}: ${audioResponse.status} ${audioResponse.statusText}`,\n )\n }\n const arrayBuffer = await audioResponse.arrayBuffer()\n const base64 = arrayBufferToBase64(arrayBuffer)\n\n // Strip parameters like `; charset=...` from contentType, and only use\n // the URL extension as a fallback when it looks like a real extension.\n const contentTypeMime = contentType?.split(';')[0]?.trim()\n const safeUrlExtension = extractUrlExtension(audioUrl)\n // Prefer URL-derived extension when available (more canonical for file\n // consumers), otherwise derive from the content-type mime subtype, then\n // fall back to `wav`. Normalize `mpeg` → `mp3` so the format field is a\n // usable file extension rather than the IANA subtype.\n const rawFormat =\n safeUrlExtension || contentTypeMime?.split('/')[1] || 'wav'\n const format = rawFormat === 'mpeg' ? 'mp3' : rawFormat\n\n const usage = buildFalUsage(takeBillableUnits(response.requestId))\n\n return {\n id: response.requestId || this.generateId(),\n model: this.model,\n audio: base64,\n format,\n contentType: contentTypeMime || `audio/${format}`,\n ...(usage ? { usage } : {}),\n }\n }\n}\n\nexport function falSpeech<TModel extends FalModel>(\n model: TModel,\n config?: FalClientConfig,\n): FalSpeechAdapter<TModel> {\n return new FalSpeechAdapter(model, config)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAqCA,IAAa,mBAAb,cAA+D,eAG7D;CACA,OAAgB;CAChB;CAEA,YAAY,OAAe,QAA0B;EACnD,MAAM,OAAO,CAAC,CAAC;EACf,KAAK,SAAS,uBAAuB,MAAM;CAC7C;CAEA,MAAM,eACJ,SACoB;EACpB,MAAM,EAAE,WAAW;EACnB,OAAO,QAAQ,8CAA8C,KAAK,SAAS;GACzE,UAAU;GACV,OAAO,KAAK;EACd,CAAC;EACD,IAAI;EACJ,IAAI;GACF,MAAM,QAAQ,KAAK,WAAW,OAAO;GAErC,MAAM,SAAS,MAAM,KAAK,OAAO,UAAU,KAAK,OAAO;IACrD;IACA,GAAI,QAAQ,cAAc,EAAE,aAAa,QAAQ,YAAY,IAAI,CAAC;IAClE,YAAY,OAAO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C,KAAoB,iBAAiB,MAAM,GAAG,CAAC,CAAC,MAAM;EACxD,MAAM,SAAS,cAAc,SAAS,QAAQ;EAE9C,MAAM,QAAQ,cAAc,kBAAkB,SAAS,SAAS,CAAC;EAEjE,OAAO;GACL,IAAI,SAAS,aAAa,KAAK,WAAW;GAC1C,OAAO,KAAK;GACZ,OAAO;GACP;GACA,aAAa,mBAAmB,SAAS;GACzC,GAAI,QAAQ,EAAE,MAAM,IAAI,CAAC;EAC3B;CACF;AACF;AAEA,SAAgB,UACd,OACA,QAC0B;CAC1B,OAAO,IAAI,iBAAiB,OAAO,MAAM;AAC3C"}
|
|
@@ -23,6 +23,7 @@ export type FalTranscriptionProviderOptions<TModel extends string> = Omit<FalMod
|
|
|
23
23
|
*/
|
|
24
24
|
export declare class FalTranscriptionAdapter<TModel extends FalModel> extends BaseTranscriptionAdapter<TModel, FalTranscriptionProviderOptions<TModel>> {
|
|
25
25
|
readonly name: "fal";
|
|
26
|
+
private readonly client;
|
|
26
27
|
constructor(model: TModel, config?: FalClientConfig);
|
|
27
28
|
transcribe(options: TranscriptionOptions<FalTranscriptionProviderOptions<TModel>>): Promise<TranscriptionResult>;
|
|
28
29
|
private buildInput;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
+
import { createAdapterFalClient, dataUrlToBlob, generateId } from "../utils/client.js";
|
|
1
2
|
import { buildFalUsage, takeBillableUnits } from "../utils/billing.js";
|
|
2
|
-
import { configureFalClient, dataUrlToBlob, generateId } from "../utils/client.js";
|
|
3
|
-
import { fal } from "@fal-ai/client";
|
|
4
3
|
import { BaseTranscriptionAdapter } from "@tanstack/ai/adapters";
|
|
5
|
-
|
|
4
|
+
// src/adapters/transcription.ts
|
|
6
5
|
/**
|
|
7
6
|
* fal.ai transcription (speech-to-text) adapter.
|
|
8
7
|
*
|
|
@@ -20,9 +19,10 @@ import { BaseTranscriptionAdapter } from "@tanstack/ai/adapters";
|
|
|
20
19
|
*/
|
|
21
20
|
var FalTranscriptionAdapter = class extends BaseTranscriptionAdapter {
|
|
22
21
|
name = "fal";
|
|
22
|
+
client;
|
|
23
23
|
constructor(model, config) {
|
|
24
24
|
super(model, {});
|
|
25
|
-
|
|
25
|
+
this.client = createAdapterFalClient(config);
|
|
26
26
|
}
|
|
27
27
|
async transcribe(options) {
|
|
28
28
|
const { logger } = options;
|
|
@@ -33,7 +33,7 @@ var FalTranscriptionAdapter = class extends BaseTranscriptionAdapter {
|
|
|
33
33
|
let requestId;
|
|
34
34
|
try {
|
|
35
35
|
const input = this.buildInput(options);
|
|
36
|
-
const result = await
|
|
36
|
+
const result = await this.client.subscribe(this.model, {
|
|
37
37
|
input,
|
|
38
38
|
...options.abortSignal ? { abortSignal: options.abortSignal } : {},
|
|
39
39
|
onEnqueue: (id) => {
|
|
@@ -42,7 +42,7 @@ var FalTranscriptionAdapter = class extends BaseTranscriptionAdapter {
|
|
|
42
42
|
});
|
|
43
43
|
return this.transformResponse(result);
|
|
44
44
|
} catch (error) {
|
|
45
|
-
if (requestId && options.abortSignal?.aborted)
|
|
45
|
+
if (requestId && options.abortSignal?.aborted) this.client.queue.cancel(this.model, { requestId }).catch(() => {});
|
|
46
46
|
logger.errors("fal.generateTranscription fatal", {
|
|
47
47
|
error,
|
|
48
48
|
source: "fal.generateTranscription"
|
|
@@ -96,7 +96,6 @@ var FalTranscriptionAdapter = class extends BaseTranscriptionAdapter {
|
|
|
96
96
|
function falTranscription(model, config) {
|
|
97
97
|
return new FalTranscriptionAdapter(model, config);
|
|
98
98
|
}
|
|
99
|
-
//#endregion
|
|
100
99
|
export { FalTranscriptionAdapter, falTranscription };
|
|
101
100
|
|
|
102
101
|
//# sourceMappingURL=transcription.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transcription.js","names":[],"sources":["../../../src/adapters/transcription.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"transcription.js","names":["utilGenerateId"],"sources":["../../../src/adapters/transcription.ts"],"sourcesContent":["import { BaseTranscriptionAdapter } from '@tanstack/ai/adapters'\nimport {\n createAdapterFalClient,\n dataUrlToBlob,\n generateId as utilGenerateId,\n} from '../utils/client'\nimport { buildFalUsage, takeBillableUnits } from '../utils/billing'\nimport type { OutputType, Result } from '@fal-ai/client'\nimport type {\n TranscriptionOptions,\n TranscriptionResult,\n TranscriptionSegment,\n} from '@tanstack/ai'\nimport type { FalClientConfig } from '../utils/client'\nimport type { FalClient } from '../client/index'\nimport type { FalModel, FalModelInput } from '../model-meta'\n\n/**\n * Provider options for transcription, excluding fields TanStack AI handles.\n */\nexport type FalTranscriptionProviderOptions<TModel extends string> = Omit<\n FalModelInput<TModel>,\n 'audio_url'\n>\n\ninterface FalChunk {\n text: string\n timestamp?: [number, number] | null\n speaker?: string\n}\n\n/**\n * fal.ai transcription (speech-to-text) adapter.\n *\n * Supports fal.ai STT models like whisper, wizper, etc.\n *\n * @example\n * ```typescript\n * const adapter = falTranscription('fal-ai/whisper')\n * const result = await generateTranscription({\n * adapter,\n * audio: 'https://example.com/audio.mp3',\n * language: 'en',\n * })\n * ```\n */\nexport class FalTranscriptionAdapter<\n TModel extends FalModel,\n> extends BaseTranscriptionAdapter<\n TModel,\n FalTranscriptionProviderOptions<TModel>\n> {\n readonly name = 'fal' as const\n private readonly client: FalClient\n\n constructor(model: TModel, config?: FalClientConfig) {\n super(model, {})\n this.client = createAdapterFalClient(config)\n }\n\n async transcribe(\n options: TranscriptionOptions<FalTranscriptionProviderOptions<TModel>>,\n ): Promise<TranscriptionResult> {\n const { logger } = options\n logger.request(\n `activity=generateTranscription provider=fal model=${this.model}`,\n {\n provider: 'fal',\n model: this.model,\n },\n )\n let requestId: string | undefined\n try {\n const input = this.buildInput(options)\n // Pass the abortSignal per request, not in the client config.\n const result = await this.client.subscribe(this.model, {\n input,\n ...(options.abortSignal ? { abortSignal: options.abortSignal } : {}),\n onEnqueue: (id) => {\n requestId = id\n },\n })\n return this.transformResponse(result)\n } catch (error) {\n // The SDK stops waiting on abort but leaves the queued job running.\n // Cancel it so it stops billing.\n if (requestId && options.abortSignal?.aborted) {\n this.client.queue.cancel(this.model, { requestId }).catch(() => {})\n }\n logger.errors('fal.generateTranscription fatal', {\n error,\n source: 'fal.generateTranscription',\n })\n throw error\n }\n }\n\n private buildInput(\n options: TranscriptionOptions<FalTranscriptionProviderOptions<TModel>>,\n ): FalModelInput<TModel> {\n // The fal client auto-uploads Blob/File inputs via storage.upload, but\n // passes strings through unchanged — so a `data:` URL would reach fal's\n // API and get rejected with a 422 \"Unsupported data URL\". Decode data\n // URLs to a Blob up front so the auto-upload path handles them.\n let audioInput: string | Blob | File\n if (options.audio instanceof ArrayBuffer) {\n audioInput = new Blob([options.audio])\n } else if (typeof options.audio === 'string') {\n audioInput = dataUrlToBlob(options.audio) ?? options.audio\n } else {\n audioInput = options.audio\n }\n\n const input = {\n ...options.modelOptions,\n audio_url: audioInput,\n ...(options.language ? { language: options.language } : {}),\n ...(options.prompt ? { prompt: options.prompt } : {}),\n } as FalModelInput<TModel>\n return input\n }\n\n protected override generateId(): string {\n return utilGenerateId(this.name)\n }\n\n private transformResponse(\n response: Result<OutputType<TModel>>,\n ): TranscriptionResult {\n const data = response.data as Record<string, unknown>\n\n const text = (data.text as string) || ''\n\n // Map fal chunks to TanStack segments. fal whisper can return\n // `timestamp: null` on some chunks (e.g. when word-level timing is\n // disabled), and the runtime payload is not actually constrained to a\n // 2-tuple — treat it as unknown and validate before indexing.\n let segments: Array<TranscriptionSegment> | undefined\n const chunks = data.chunks as Array<FalChunk> | undefined\n if (chunks && Array.isArray(chunks)) {\n segments = chunks.flatMap((chunk, index) => {\n const ts = chunk.timestamp as unknown\n if (\n !Array.isArray(ts) ||\n ts.length < 2 ||\n typeof ts[0] !== 'number' ||\n typeof ts[1] !== 'number'\n ) {\n return []\n }\n return [\n {\n id: index,\n start: ts[0],\n end: ts[1],\n text: chunk.text,\n ...(chunk.speaker ? { speaker: chunk.speaker } : {}),\n },\n ]\n })\n }\n\n // Extract language from response\n const language =\n (data.language as string) ||\n (data.inferred_languages as Array<string> | undefined)?.[0] ||\n (data.languages as Array<string> | undefined)?.[0]\n\n const usage = buildFalUsage(takeBillableUnits(response.requestId))\n\n return {\n id: response.requestId || this.generateId(),\n model: this.model,\n text,\n ...(language !== undefined ? { language } : {}),\n ...(segments !== undefined ? { segments } : {}),\n ...(usage ? { usage } : {}),\n }\n }\n}\n\nexport function falTranscription<TModel extends FalModel>(\n model: TModel,\n config?: FalClientConfig,\n): FalTranscriptionAdapter<TModel> {\n return new FalTranscriptionAdapter(model, config)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA8CA,IAAa,0BAAb,cAEU,yBAGR;CACA,OAAgB;CAChB;CAEA,YAAY,OAAe,QAA0B;EACnD,MAAM,OAAO,CAAC,CAAC;EACf,KAAK,SAAS,uBAAuB,MAAM;CAC7C;CAEA,MAAM,WACJ,SAC8B;EAC9B,MAAM,EAAE,WAAW;EACnB,OAAO,QACL,qDAAqD,KAAK,SAC1D;GACE,UAAU;GACV,OAAO,KAAK;EACd,CACF;EACA,IAAI;EACJ,IAAI;GACF,MAAM,QAAQ,KAAK,WAAW,OAAO;GAErC,MAAM,SAAS,MAAM,KAAK,OAAO,UAAU,KAAK,OAAO;IACrD;IACA,GAAI,QAAQ,cAAc,EAAE,aAAa,QAAQ,YAAY,IAAI,CAAC;IAClE,YAAY,OAAO;KACjB,YAAY;IACd;GACF,CAAC;GACD,OAAO,KAAK,kBAAkB,MAAM;EACtC,SAAS,OAAO;GAGd,IAAI,aAAa,QAAQ,aAAa,SACpC,KAAK,OAAO,MAAM,OAAO,KAAK,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC;GAEpE,OAAO,OAAO,mCAAmC;IAC/C;IACA,QAAQ;GACV,CAAC;GACD,MAAM;EACR;CACF;CAEA,WACE,SACuB;EAKvB,IAAI;EACJ,IAAI,QAAQ,iBAAiB,aAC3B,aAAa,IAAI,KAAK,CAAC,QAAQ,KAAK,CA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wB,OAAO,MAAM;AAClD"}
|
|
@@ -12,12 +12,13 @@ import { FalClientConfig } from '../utils/client.js';
|
|
|
12
12
|
export declare class FalVideoAdapter<TModel extends FalModel> extends BaseVideoAdapter<TModel, FalVideoProviderOptions<TModel>, Record<TModel, FalVideoProviderOptions<TModel>>, Record<TModel, FalModelVideoSize<TModel>>, Record<TModel, FalVideoPromptModalitiesFor<TModel>>, Record<TModel, FalModelVideoDuration<TModel>>> {
|
|
13
13
|
readonly kind: "video";
|
|
14
14
|
readonly name: "fal";
|
|
15
|
+
private readonly client;
|
|
15
16
|
readonly supportsFileSources = true;
|
|
16
17
|
constructor(model: TModel, config?: FalClientConfig);
|
|
17
18
|
createVideoJob(options: VideoGenerationOptions<FalVideoProviderOptions<TModel>, FalModelVideoSize<TModel>, FalModelVideoDuration<TModel>>): Promise<VideoJobResult>;
|
|
18
19
|
availableDurations(): DurationOptions<FalModelVideoDuration<TModel>>;
|
|
19
20
|
/**
|
|
20
|
-
* Cancels a queued request with
|
|
21
|
+
* Cancels a queued request with the fal queue cancel endpoint. fal can refuse when the
|
|
21
22
|
* request already runs, and then this rejects.
|
|
22
23
|
*/
|
|
23
24
|
cancelVideoJob(jobId: string, options?: {
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
+
import { createAdapterFalClient, falValidationMessage, generateId } from "../utils/client.js";
|
|
1
2
|
import { buildFalUsage, takeBillableUnits } from "../utils/billing.js";
|
|
2
|
-
import { configureFalClient, generateId } from "../utils/client.js";
|
|
3
|
-
import { contentSourceToFalUrl, mapImageInputsToFalVideoFields } from "../image/image-inputs.js";
|
|
4
3
|
import { getFalVideoDurationOptions, mapVideoSizeToFalFormat } from "../video/video-provider-options.js";
|
|
5
|
-
import {
|
|
4
|
+
import { contentSourceToFalUrl, mapImageInputsToFalVideoFields } from "../image/image-inputs.js";
|
|
6
5
|
import { resolveMediaPrompt } from "@tanstack/ai";
|
|
7
6
|
import { BaseVideoAdapter } from "@tanstack/ai/adapters";
|
|
8
|
-
|
|
7
|
+
// src/adapters/video.ts
|
|
9
8
|
/**
|
|
10
9
|
* Map video conditioning inputs onto fal field names.
|
|
11
10
|
* Video-to-video endpoints on fal almost universally use `video_url`; the
|
|
@@ -61,10 +60,11 @@ function mapFalStatusToVideoStatus(falStatus) {
|
|
|
61
60
|
var FalVideoAdapter = class extends BaseVideoAdapter {
|
|
62
61
|
kind = "video";
|
|
63
62
|
name = "fal";
|
|
63
|
+
client;
|
|
64
64
|
supportsFileSources = true;
|
|
65
65
|
constructor(model, config) {
|
|
66
66
|
super({}, model);
|
|
67
|
-
|
|
67
|
+
this.client = createAdapterFalClient(config);
|
|
68
68
|
}
|
|
69
69
|
async createVideoJob(options) {
|
|
70
70
|
const { size, duration, modelOptions, logger } = options;
|
|
@@ -87,7 +87,7 @@ var FalVideoAdapter = class extends BaseVideoAdapter {
|
|
|
87
87
|
...resolved.text ? { prompt: resolved.text } : {},
|
|
88
88
|
...duration !== void 0 ? { duration } : {}
|
|
89
89
|
};
|
|
90
|
-
const { request_id } = await
|
|
90
|
+
const { request_id } = await this.client.queue.submit(this.model, {
|
|
91
91
|
input,
|
|
92
92
|
...options.abortSignal ? { abortSignal: options.abortSignal } : {}
|
|
93
93
|
});
|
|
@@ -107,17 +107,17 @@ var FalVideoAdapter = class extends BaseVideoAdapter {
|
|
|
107
107
|
return getFalVideoDurationOptions(this.model);
|
|
108
108
|
}
|
|
109
109
|
/**
|
|
110
|
-
* Cancels a queued request with
|
|
110
|
+
* Cancels a queued request with the fal queue cancel endpoint. fal can refuse when the
|
|
111
111
|
* request already runs, and then this rejects.
|
|
112
112
|
*/
|
|
113
113
|
async cancelVideoJob(jobId, options) {
|
|
114
|
-
await
|
|
114
|
+
await this.client.queue.cancel(this.model, {
|
|
115
115
|
requestId: jobId,
|
|
116
116
|
...options?.abortSignal ? { abortSignal: options.abortSignal } : {}
|
|
117
117
|
});
|
|
118
118
|
}
|
|
119
119
|
async getVideoStatus(jobId, options) {
|
|
120
|
-
const statusResponse = await
|
|
120
|
+
const statusResponse = await this.client.queue.status(this.model, {
|
|
121
121
|
requestId: jobId,
|
|
122
122
|
logs: true,
|
|
123
123
|
...options?.abortSignal ? { abortSignal: options.abortSignal } : {}
|
|
@@ -131,19 +131,15 @@ var FalVideoAdapter = class extends BaseVideoAdapter {
|
|
|
131
131
|
async getVideo(jobId, options) {
|
|
132
132
|
let result;
|
|
133
133
|
try {
|
|
134
|
-
result = await
|
|
134
|
+
result = await this.client.queue.result(this.model, {
|
|
135
135
|
requestId: jobId,
|
|
136
136
|
...options?.abortSignal ? { abortSignal: options.abortSignal } : {}
|
|
137
137
|
});
|
|
138
138
|
} catch (error) {
|
|
139
139
|
if (options?.abortSignal?.aborted) throw error;
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
const messages = detail.map((d) => d.loc ? `${d.loc.join(".")}: ${d.msg}` : d.msg);
|
|
144
|
-
throw new Error(`Video generation failed: ${messages.join("; ")}`);
|
|
145
|
-
}
|
|
146
|
-
throw new Error(`Failed to retrieve video result: ${err.message || String(error)}`);
|
|
140
|
+
const validation = falValidationMessage(error);
|
|
141
|
+
if (validation) throw new Error(`Video generation failed: ${validation}`);
|
|
142
|
+
throw new Error(`Failed to retrieve video result: ${error.message || String(error)}`);
|
|
147
143
|
}
|
|
148
144
|
const data = result.data;
|
|
149
145
|
const url = data.video?.url || data.video_url;
|
|
@@ -171,7 +167,6 @@ function createFalVideo(model, config) {
|
|
|
171
167
|
function falVideo(model, config) {
|
|
172
168
|
return createFalVideo(model, config);
|
|
173
169
|
}
|
|
174
|
-
//#endregion
|
|
175
170
|
export { FalVideoAdapter, createFalVideo, falVideo };
|
|
176
171
|
|
|
177
172
|
//# sourceMappingURL=video.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"video.js","names":[],"sources":["../../../src/adapters/video.ts"],"sourcesContent":["import { fal } from '@fal-ai/client'\nimport { resolveMediaPrompt } from '@tanstack/ai'\nimport { BaseVideoAdapter } from '@tanstack/ai/adapters'\nimport {\n configureFalClient,\n generateId as utilGenerateId,\n} from '../utils/client'\nimport { buildFalUsage, takeBillableUnits } from '../utils/billing'\nimport {\n getFalVideoDurationOptions,\n mapVideoSizeToFalFormat,\n} from '../video/video-provider-options'\nimport {\n contentSourceToFalUrl,\n mapImageInputsToFalVideoFields,\n} from '../image/image-inputs'\nimport type { DurationOptions } from '@tanstack/ai/adapters'\nimport type {\n AudioPart,\n MediaInputMetadata,\n VideoGenerationOptions,\n VideoJobResult,\n VideoPart,\n VideoStatusResult,\n VideoUrlResult,\n} from '@tanstack/ai'\nimport type {\n FalModel,\n FalModelInput,\n FalModelVideoDuration,\n FalModelVideoSize,\n FalVideoPromptModalitiesFor,\n FalVideoProviderOptions,\n} from '../model-meta'\nimport type { FalClientConfig } from '../utils/client'\n\n/**\n * Map video conditioning inputs onto fal field names.\n * Video-to-video endpoints on fal almost universally use `video_url`; the\n * occasional model takes `video_urls` (rare). Mirror the image-input logic\n * positionally with a `reference` role escape hatch via `reference_video_urls`.\n */\nfunction mapVideoInputsToFalFields(\n videoInputs?: ReadonlyArray<VideoPart<MediaInputMetadata>>,\n): Record<string, unknown> {\n if (!videoInputs || videoInputs.length === 0) return {}\n const references: Array<string> = []\n const sources: Array<string> = []\n for (const part of videoInputs) {\n const url = videoPartToUrl(part)\n if (\n part.metadata?.role === 'reference' ||\n part.metadata?.role === 'character'\n ) {\n references.push(url)\n } else {\n sources.push(url)\n }\n }\n const out: Record<string, unknown> = {}\n if (references.length > 0) out.reference_video_urls = references\n if (sources.length === 1) {\n out.video_url = sources[0]\n } else if (sources.length > 1) {\n out.video_urls = sources\n }\n return out\n}\n\nfunction mapAudioInputsToFalFields(\n audioInputs?: ReadonlyArray<AudioPart<MediaInputMetadata>>,\n): Record<string, unknown> {\n if (!audioInputs || audioInputs.length === 0) return {}\n const [part, ...rest] = audioInputs\n if (!part || rest.length > 0) {\n throw new Error(\n `fal: exactly one audio prompt part is supported (received ${audioInputs.length}).`,\n )\n }\n return {\n audio_url: contentSourceToFalUrl(part.source),\n }\n}\n\nfunction videoPartToUrl(part: VideoPart<MediaInputMetadata>): string {\n return contentSourceToFalUrl(part.source)\n}\n\ntype FalQueueStatus = 'IN_QUEUE' | 'IN_PROGRESS' | 'COMPLETED'\n\ninterface FalStatusResponse {\n status: FalQueueStatus\n queue_position?: number\n logs?: Array<{ message: string }>\n}\n\ninterface FalVideoResultData {\n video?: { url: string }\n video_url?: string\n}\n\n/**\n * Maps fal.ai queue status to TanStack AI video status.\n *\n * Note: fal.ai does not return a FAILED queue status. Errors surface\n * as exceptions when fetching results from a COMPLETED job (e.g. 422\n * validation errors). Those are handled in getVideo().\n */\nfunction mapFalStatusToVideoStatus(\n falStatus: FalQueueStatus,\n): VideoStatusResult['status'] {\n switch (falStatus) {\n case 'IN_QUEUE':\n return 'pending'\n case 'IN_PROGRESS':\n return 'processing'\n case 'COMPLETED':\n return 'completed'\n default:\n return 'processing'\n }\n}\n\n/**\n * fal.ai video generation adapter.\n * Supports MiniMax, Luma, Kling, Hunyuan, and other fal.ai video models.\n *\n * Uses fal.ai's comprehensive type system to provide autocomplete\n * and type safety for all supported video models.\n */\nexport class FalVideoAdapter<TModel extends FalModel> extends BaseVideoAdapter<\n TModel,\n FalVideoProviderOptions<TModel>,\n Record<TModel, FalVideoProviderOptions<TModel>>,\n Record<TModel, FalModelVideoSize<TModel>>,\n Record<TModel, FalVideoPromptModalitiesFor<TModel>>,\n Record<TModel, FalModelVideoDuration<TModel>>\n> {\n override readonly kind = 'video' as const\n readonly name = 'fal' as const\n // Consumes fal storage URLs uploaded via falFiles().\n override readonly supportsFileSources = true\n\n constructor(model: TModel, config?: FalClientConfig) {\n super({}, model)\n configureFalClient(config)\n }\n\n async createVideoJob(\n options: VideoGenerationOptions<\n FalVideoProviderOptions<TModel>,\n FalModelVideoSize<TModel>,\n FalModelVideoDuration<TModel>\n >,\n ): Promise<VideoJobResult> {\n const { size, duration, modelOptions, logger } = options\n\n logger.request(`activity=generateVideo provider=fal model=${this.model}`, {\n provider: 'fal',\n model: this.model,\n })\n\n try {\n const resolved = resolveMediaPrompt(options.prompt)\n const sizeParams = mapVideoSizeToFalFormat(size)\n const inputImageFields = mapImageInputsToFalVideoFields(\n this.model,\n resolved.images,\n )\n const videoFields = mapVideoInputsToFalFields(resolved.videos)\n const audioFields = mapAudioInputsToFalFields(resolved.audios)\n\n const input = {\n ...sizeParams,\n ...inputImageFields,\n ...videoFields,\n ...audioFields,\n // modelOptions applied after derived media fields so explicit user\n // overrides (video_url, reference_video_urls, audio_url, ...) win.\n ...modelOptions,\n // Media-only prompts omit the prompt field rather than sending an\n // empty string (e.g. pure image-to-video endpoints).\n ...(resolved.text ? { prompt: resolved.text } : {}),\n ...(duration !== undefined ? { duration } : {}),\n } as FalModelInput<TModel>\n\n // Submit to queue and get request ID. Request-specific abortSignal only —\n // never via fal.config() (global; would cancel concurrent jobs).\n const { request_id } = await fal.queue.submit(this.model, {\n input,\n ...(options.abortSignal ? { abortSignal: options.abortSignal } : {}),\n })\n\n return {\n jobId: request_id,\n model: this.model,\n }\n } catch (error) {\n logger.errors('fal.createVideoJob fatal', {\n error,\n source: 'fal.createVideoJob',\n })\n throw error\n }\n }\n\n override availableDurations(): DurationOptions<\n FalModelVideoDuration<TModel>\n > {\n return getFalVideoDurationOptions(this.model)\n }\n\n /**\n * Cancels a queued request with `fal.queue.cancel`. fal can refuse when the\n * request already runs, and then this rejects.\n */\n async cancelVideoJob(\n jobId: string,\n options?: { abortSignal?: AbortSignal },\n ): Promise<void> {\n await fal.queue.cancel(this.model, {\n requestId: jobId,\n ...(options?.abortSignal ? { abortSignal: options.abortSignal } : {}),\n })\n }\n\n async getVideoStatus(\n jobId: string,\n options?: { abortSignal?: AbortSignal },\n ): Promise<VideoStatusResult> {\n const statusResponse = (await fal.queue.status(this.model, {\n requestId: jobId,\n logs: true,\n ...(options?.abortSignal ? { abortSignal: options.abortSignal } : {}),\n })) as FalStatusResponse\n\n return {\n jobId,\n status: mapFalStatusToVideoStatus(statusResponse.status),\n ...(statusResponse.queue_position != null\n ? {\n progress: Math.max(0, 100 - statusResponse.queue_position * 10),\n }\n : {}),\n }\n }\n\n override async getVideo(\n jobId: string,\n options?: { abortSignal?: AbortSignal },\n ): Promise<VideoUrlResult> {\n let result\n try {\n result = await fal.queue.result(this.model, {\n requestId: jobId,\n ...(options?.abortSignal ? { abortSignal: options.abortSignal } : {}),\n })\n } catch (error: unknown) {\n // A cancelled call is not a provider failure: keep the abort error.\n if (options?.abortSignal?.aborted) throw error\n // fal.ai may report COMPLETED status but throw on result fetch\n // (e.g. 422 validation errors). Extract the detailed error info.\n const err = error as { body?: { detail?: unknown }; message?: string }\n const detail = err.body?.detail\n if (Array.isArray(detail)) {\n const messages = detail.map(\n (d: { msg?: string; loc?: Array<string> }) =>\n d.loc ? `${d.loc.join('.')}: ${d.msg}` : d.msg,\n )\n throw new Error(`Video generation failed: ${messages.join('; ')}`)\n }\n throw new Error(\n `Failed to retrieve video result: ${err.message || String(error)}`,\n )\n }\n\n const data = result.data as FalVideoResultData\n\n // Different models return video URL in different formats\n const url = data.video?.url || data.video_url\n if (!url) {\n throw new Error('Video URL not found in response')\n }\n\n const usage = buildFalUsage(takeBillableUnits(result.requestId))\n\n return {\n jobId,\n url,\n ...(usage ? { usage } : {}),\n }\n }\n\n protected override generateId(): string {\n return utilGenerateId(this.name)\n }\n}\n\n/**\n * Create a fal.ai video adapter with an explicit API key.\n */\nexport function createFalVideo<TModel extends FalModel>(\n model: TModel,\n config?: FalClientConfig,\n): FalVideoAdapter<TModel> {\n return new FalVideoAdapter(model, config)\n}\n\n/**\n * Create a fal.ai video adapter using config.apiKey or the FAL_KEY environment variable.\n */\nexport function falVideo<TModel extends FalModel>(\n model: TModel,\n config?: FalClientConfig,\n): FalVideoAdapter<TModel> {\n return createFalVideo(model, config)\n}\n"],"mappings":";;;;;;;;;;;;;;AA0CA,SAAS,0BACP,aACyB;CACzB,IAAI,CAAC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ACF;CAEA,MAAe,SACb,OACA,SACyB;EACzB,IAAI;EACJ,IAAI;GACF,SAAS,MAAM,IAAI,MAAM,OAAO,KAAK,OAAO;IAC1C,WAAW;IACX,GAAI,SAAS,cAAc,EAAE,aAAa,QAAQ,YAAY,IAAI,CAAC;GACrE,CAAC;EACH,SAAS,OAAgB;GAEvB,IAAI,SAAS,aAAa,SAAS,MAAM;GAGzC,MAAM,MAAM;GACZ,MAAM,SAAS,IAAI,MAAM;GACzB,IAAI,MAAM,QAAQ,MAAM,GAAG;IACzB,MAAM,WAAW,OAAO,KACrB,MACC,EAAE,MAAM,GAAG,EAAE,IAAI,KAAK,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,GAC/C;IACA,MAAM,IAAI,MAAM,4BAA4B,SAAS,KAAK,IAAI,GAAG;GACnE;GACA,MAAM,IAAI,MACR,oCAAoC,IAAI,WAAW,OAAO,KAAK,GACjE;EACF;EAEA,MAAM,OAAO,OAAO;EAGpB,MAAM,MAAM,KAAK,OAAO,OAAO,KAAK;EACpC,IAAI,CAAC,KACH,MAAM,IAAI,MAAM,iCAAiC;EAGnD,MAAM,QAAQ,cAAc,kBAAkB,OAAO,SAAS,CAAC;EAE/D,OAAO;GACL;GACA;GACA,GAAI,QAAQ,EAAE,MAAM,IAAI,CAAC;EAC3B;CACF;CAEA,aAAwC;EACtC,OAAO,WAAe,KAAK,IAAI;CACjC;AACF;;;;AAKA,SAAgB,eACd,OACA,QACyB;CACzB,OAAO,IAAI,gBAAgB,OAAO,MAAM;AAC1C;;;;AAKA,SAAgB,SACd,OACA,QACyB;CACzB,OAAO,eAAe,OAAO,MAAM;AACrC"}
|
|
1
|
+
{"version":3,"file":"video.js","names":["err","utilGenerateId"],"sources":["../../../src/adapters/video.ts"],"sourcesContent":["import { resolveMediaPrompt } from '@tanstack/ai'\nimport { BaseVideoAdapter } from '@tanstack/ai/adapters'\nimport {\n createAdapterFalClient,\n falValidationMessage,\n generateId as utilGenerateId,\n} from '../utils/client'\nimport { buildFalUsage, takeBillableUnits } from '../utils/billing'\nimport {\n getFalVideoDurationOptions,\n mapVideoSizeToFalFormat,\n} from '../video/video-provider-options'\nimport {\n contentSourceToFalUrl,\n mapImageInputsToFalVideoFields,\n} from '../image/image-inputs'\nimport type { DurationOptions } from '@tanstack/ai/adapters'\nimport type {\n AudioPart,\n MediaInputMetadata,\n VideoGenerationOptions,\n VideoJobResult,\n VideoPart,\n VideoStatusResult,\n VideoUrlResult,\n} from '@tanstack/ai'\nimport type {\n FalModel,\n FalModelInput,\n FalModelVideoDuration,\n FalModelVideoSize,\n FalVideoPromptModalitiesFor,\n FalVideoProviderOptions,\n} from '../model-meta'\nimport type { FalClientConfig } from '../utils/client'\nimport type { FalClient } from '../client/index'\n\n/**\n * Map video conditioning inputs onto fal field names.\n * Video-to-video endpoints on fal almost universally use `video_url`; the\n * occasional model takes `video_urls` (rare). Mirror the image-input logic\n * positionally with a `reference` role escape hatch via `reference_video_urls`.\n */\nfunction mapVideoInputsToFalFields(\n videoInputs?: ReadonlyArray<VideoPart<MediaInputMetadata>>,\n): Record<string, unknown> {\n if (!videoInputs || videoInputs.length === 0) return {}\n const references: Array<string> = []\n const sources: Array<string> = []\n for (const part of videoInputs) {\n const url = videoPartToUrl(part)\n if (\n part.metadata?.role === 'reference' ||\n part.metadata?.role === 'character'\n ) {\n references.push(url)\n } else {\n sources.push(url)\n }\n }\n const out: Record<string, unknown> = {}\n if (references.length > 0) out.reference_video_urls = references\n if (sources.length === 1) {\n out.video_url = sources[0]\n } else if (sources.length > 1) {\n out.video_urls = sources\n }\n return out\n}\n\nfunction mapAudioInputsToFalFields(\n audioInputs?: ReadonlyArray<AudioPart<MediaInputMetadata>>,\n): Record<string, unknown> {\n if (!audioInputs || audioInputs.length === 0) return {}\n const [part, ...rest] = audioInputs\n if (!part || rest.length > 0) {\n throw new Error(\n `fal: exactly one audio prompt part is supported (received ${audioInputs.length}).`,\n )\n }\n return {\n audio_url: contentSourceToFalUrl(part.source),\n }\n}\n\nfunction videoPartToUrl(part: VideoPart<MediaInputMetadata>): string {\n return contentSourceToFalUrl(part.source)\n}\n\ntype FalQueueStatus = 'IN_QUEUE' | 'IN_PROGRESS' | 'COMPLETED'\n\ninterface FalStatusResponse {\n status: FalQueueStatus\n queue_position?: number\n logs?: Array<{ message: string }>\n}\n\ninterface FalVideoResultData {\n video?: { url: string }\n video_url?: string\n}\n\n/**\n * Maps fal.ai queue status to TanStack AI video status.\n *\n * Note: fal.ai does not return a FAILED queue status. Errors surface\n * as exceptions when fetching results from a COMPLETED job (e.g. 422\n * validation errors). Those are handled in getVideo().\n */\nfunction mapFalStatusToVideoStatus(\n falStatus: FalQueueStatus,\n): VideoStatusResult['status'] {\n switch (falStatus) {\n case 'IN_QUEUE':\n return 'pending'\n case 'IN_PROGRESS':\n return 'processing'\n case 'COMPLETED':\n return 'completed'\n default:\n return 'processing'\n }\n}\n\n/**\n * fal.ai video generation adapter.\n * Supports MiniMax, Luma, Kling, Hunyuan, and other fal.ai video models.\n *\n * Uses fal.ai's comprehensive type system to provide autocomplete\n * and type safety for all supported video models.\n */\nexport class FalVideoAdapter<TModel extends FalModel> extends BaseVideoAdapter<\n TModel,\n FalVideoProviderOptions<TModel>,\n Record<TModel, FalVideoProviderOptions<TModel>>,\n Record<TModel, FalModelVideoSize<TModel>>,\n Record<TModel, FalVideoPromptModalitiesFor<TModel>>,\n Record<TModel, FalModelVideoDuration<TModel>>\n> {\n override readonly kind = 'video' as const\n readonly name = 'fal' as const\n private readonly client: FalClient\n // Consumes fal storage URLs uploaded via falFiles().\n override readonly supportsFileSources = true\n\n constructor(model: TModel, config?: FalClientConfig) {\n super({}, model)\n this.client = createAdapterFalClient(config)\n }\n\n async createVideoJob(\n options: VideoGenerationOptions<\n FalVideoProviderOptions<TModel>,\n FalModelVideoSize<TModel>,\n FalModelVideoDuration<TModel>\n >,\n ): Promise<VideoJobResult> {\n const { size, duration, modelOptions, logger } = options\n\n logger.request(`activity=generateVideo provider=fal model=${this.model}`, {\n provider: 'fal',\n model: this.model,\n })\n\n try {\n const resolved = resolveMediaPrompt(options.prompt)\n const sizeParams = mapVideoSizeToFalFormat(size)\n const inputImageFields = mapImageInputsToFalVideoFields(\n this.model,\n resolved.images,\n )\n const videoFields = mapVideoInputsToFalFields(resolved.videos)\n const audioFields = mapAudioInputsToFalFields(resolved.audios)\n\n const input = {\n ...sizeParams,\n ...inputImageFields,\n ...videoFields,\n ...audioFields,\n // modelOptions applied after derived media fields so explicit user\n // overrides (video_url, reference_video_urls, audio_url, ...) win.\n ...modelOptions,\n // Media-only prompts omit the prompt field rather than sending an\n // empty string (e.g. pure image-to-video endpoints).\n ...(resolved.text ? { prompt: resolved.text } : {}),\n ...(duration !== undefined ? { duration } : {}),\n } as FalModelInput<TModel>\n\n // Submit to the queue and get the request ID. Pass the abortSignal per\n // request, not in the client config, so it cannot cancel other jobs.\n const { request_id } = await this.client.queue.submit(this.model, {\n input,\n ...(options.abortSignal ? { abortSignal: options.abortSignal } : {}),\n })\n\n return {\n jobId: request_id,\n model: this.model,\n }\n } catch (error) {\n logger.errors('fal.createVideoJob fatal', {\n error,\n source: 'fal.createVideoJob',\n })\n throw error\n }\n }\n\n override availableDurations(): DurationOptions<\n FalModelVideoDuration<TModel>\n > {\n return getFalVideoDurationOptions(this.model)\n }\n\n /**\n * Cancels a queued request with the fal queue cancel endpoint. fal can refuse when the\n * request already runs, and then this rejects.\n */\n async cancelVideoJob(\n jobId: string,\n options?: { abortSignal?: AbortSignal },\n ): Promise<void> {\n await this.client.queue.cancel(this.model, {\n requestId: jobId,\n ...(options?.abortSignal ? { abortSignal: options.abortSignal } : {}),\n })\n }\n\n async getVideoStatus(\n jobId: string,\n options?: { abortSignal?: AbortSignal },\n ): Promise<VideoStatusResult> {\n const statusResponse = (await this.client.queue.status(this.model, {\n requestId: jobId,\n logs: true,\n ...(options?.abortSignal ? { abortSignal: options.abortSignal } : {}),\n })) as FalStatusResponse\n\n return {\n jobId,\n status: mapFalStatusToVideoStatus(statusResponse.status),\n ...(statusResponse.queue_position != null\n ? {\n progress: Math.max(0, 100 - statusResponse.queue_position * 10),\n }\n : {}),\n }\n }\n\n override async getVideo(\n jobId: string,\n options?: { abortSignal?: AbortSignal },\n ): Promise<VideoUrlResult> {\n let result\n try {\n result = await this.client.queue.result(this.model, {\n requestId: jobId,\n ...(options?.abortSignal ? { abortSignal: options.abortSignal } : {}),\n })\n } catch (error: unknown) {\n // A cancelled call is not a provider failure: keep the abort error.\n if (options?.abortSignal?.aborted) throw error\n // fal.ai may report COMPLETED status but throw on result fetch\n // (e.g. 422 validation errors). Extract the detailed error info.\n const validation = falValidationMessage(error)\n if (validation) {\n throw new Error(`Video generation failed: ${validation}`)\n }\n const err = error as { message?: string }\n throw new Error(\n `Failed to retrieve video result: ${err.message || String(error)}`,\n )\n }\n\n const data = result.data as FalVideoResultData\n\n // Different models return video URL in different formats\n const url = data.video?.url || data.video_url\n if (!url) {\n throw new Error('Video URL not found in response')\n }\n\n const usage = buildFalUsage(takeBillableUnits(result.requestId))\n\n return {\n jobId,\n url,\n ...(usage ? { usage } : {}),\n }\n }\n\n protected override generateId(): string {\n return utilGenerateId(this.name)\n }\n}\n\n/**\n * Create a fal.ai video adapter with an explicit API key.\n */\nexport function createFalVideo<TModel extends FalModel>(\n model: TModel,\n config?: FalClientConfig,\n): FalVideoAdapter<TModel> {\n return new FalVideoAdapter(model, config)\n}\n\n/**\n * Create a fal.ai video adapter using config.apiKey or the FAL_KEY environment variable.\n */\nexport function falVideo<TModel extends FalModel>(\n model: TModel,\n config?: FalClientConfig,\n): FalVideoAdapter<TModel> {\n return createFalVideo(model, config)\n}\n"],"mappings":";;;;;;;;;;;;;AA2CA,SAAS,0BACP,aACyB;CACzB,IAAI,CAAC,eAAe,YAAY,WAAW,GAAG,OAAO,CAAC;CACtD,MAAM,aAA4B,CAAC;CACnC,MAAM,UAAyB,CAAC;CAChC,KAAK,MAAM,QAAQ,aAAa;EAC9B,MAAM,MAAM,eAAe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IAClD,WAAW;IACX,GAAI,SAAS,cAAc,EAAE,aAAa,QAAQ,YAAY,IAAI,CAAC;GACrE,CAAC;EACH,SAAS,OAAgB;GAEvB,IAAI,SAAS,aAAa,SAAS,MAAM;GAGzC,MAAM,aAAa,qBAAqB,KAAK;GAC7C,IAAI,YACF,MAAM,IAAI,MAAM,4BAA4B,YAAY;GAG1D,MAAM,IAAI,MACR,oCAAoCA,MAAI,WAAW,OAAO,KAAK,GACjE;EACF;EAEA,MAAM,OAAO,OAAO;EAGpB,MAAM,MAAM,KAAK,OAAO,OAAO,KAAK;EACpC,IAAI,CAAC,KACH,MAAM,IAAI,MAAM,iCAAiC;EAGnD,MAAM,QAAQ,cAAc,kBAAkB,OAAO,SAAS,CAAC;EAE/D,OAAO;GACL;GACA;GACA,GAAI,QAAQ,EAAE,MAAM,IAAI,CAAC;EAC3B;CACF;CAEA,aAAwC;EACtC,OAAOC,WAAe,KAAK,IAAI;CACjC;AACF;;;;AAKA,SAAgB,eACd,OACA,QACyB;CACzB,OAAO,IAAI,gBAAgB,OAAO,MAAM;AAC1C;;;;AAKA,SAAgB,SACd,OACA,QACyB;CACzB,OAAO,eAAe,OAAO,MAAM;AACrC"}
|
package/dist/esm/byok.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { defineByokProvider } from "@tanstack/ai/byok";
|
|
2
|
-
|
|
2
|
+
// src/byok.ts
|
|
3
3
|
var falByok = defineByokProvider({
|
|
4
4
|
id: "fal",
|
|
5
5
|
label: "fal.ai",
|
|
6
6
|
env: "FAL_KEY"
|
|
7
7
|
});
|
|
8
|
-
//#endregion
|
|
9
8
|
export { falByok };
|
|
10
9
|
|
|
11
10
|
//# sourceMappingURL=byok.js.map
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { FalClient as SdkFalClient, QueueClient, StorageClient, ValidationErrorInfo } from '@fal-ai/client';
|
|
2
|
+
/**
|
|
3
|
+
* Config for {@link createFalClient}. These are the `@fal-ai/client` config
|
|
4
|
+
* fields this package uses.
|
|
5
|
+
*/
|
|
6
|
+
export interface FalClientOptions {
|
|
7
|
+
/** Sent as `Authorization: Key <credentials>`. */
|
|
8
|
+
credentials: string;
|
|
9
|
+
fetch: typeof fetch;
|
|
10
|
+
/** In a browser, requests go here with the real URL in `x-fal-target-url`. */
|
|
11
|
+
proxyUrl?: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The part of the `@fal-ai/client` client that the adapters call. A real SDK
|
|
15
|
+
* client also fits this type.
|
|
16
|
+
*/
|
|
17
|
+
export type FalClient = Pick<SdkFalClient, 'subscribe'> & {
|
|
18
|
+
queue: Pick<QueueClient, 'submit' | 'status' | 'result' | 'cancel'>;
|
|
19
|
+
storage: Pick<StorageClient, 'upload'>;
|
|
20
|
+
};
|
|
21
|
+
interface ApiErrorArgs<Body> {
|
|
22
|
+
message: string;
|
|
23
|
+
status: number;
|
|
24
|
+
body?: Body;
|
|
25
|
+
requestId?: string;
|
|
26
|
+
timeoutType?: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Thrown when fal answers with a status that is not OK. Same name and fields
|
|
30
|
+
* as the `@fal-ai/client` `ApiError`.
|
|
31
|
+
*/
|
|
32
|
+
export declare class ApiError<Body = unknown> extends Error {
|
|
33
|
+
readonly status: number;
|
|
34
|
+
readonly body: Body | undefined;
|
|
35
|
+
readonly requestId: string;
|
|
36
|
+
readonly timeoutType?: string;
|
|
37
|
+
constructor({ message, status, body, requestId, timeoutType, }: ApiErrorArgs<Body>);
|
|
38
|
+
/** True when the request hit the timeout that the caller asked for. */
|
|
39
|
+
get isUserTimeout(): boolean;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Thrown for a 422 answer. Same name and fields as the `@fal-ai/client`
|
|
43
|
+
* `ValidationError`.
|
|
44
|
+
*/
|
|
45
|
+
export declare class ValidationError extends ApiError<{
|
|
46
|
+
detail?: Array<ValidationErrorInfo> | string;
|
|
47
|
+
}> {
|
|
48
|
+
constructor(args: ApiErrorArgs<{
|
|
49
|
+
detail?: Array<ValidationErrorInfo> | string;
|
|
50
|
+
}>);
|
|
51
|
+
get fieldErrors(): Array<ValidationErrorInfo>;
|
|
52
|
+
getFieldErrors(field: string): ValidationErrorInfo[];
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Create a fal client that talks to the fal queue and storage REST API with
|
|
56
|
+
* `fetch`. It has the same method names, arguments, results, and errors as the
|
|
57
|
+
* `@fal-ai/client` methods the adapters use.
|
|
58
|
+
*
|
|
59
|
+
* @param options credentials, the `fetch` to use, and an optional proxy URL.
|
|
60
|
+
* @example
|
|
61
|
+
* const client = createFalClient({ credentials: 'key', fetch })
|
|
62
|
+
* const { data } = await client.subscribe('fal-ai/flux/dev', { input })
|
|
63
|
+
*/
|
|
64
|
+
export declare function createFalClient(options: FalClientOptions): FalClient;
|
|
65
|
+
export {};
|