@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.
Files changed (82) hide show
  1. package/dist/esm/adapters/audio.d.ts +1 -0
  2. package/dist/esm/adapters/audio.js +6 -7
  3. package/dist/esm/adapters/audio.js.map +1 -1
  4. package/dist/esm/adapters/files.d.ts +1 -0
  5. package/dist/esm/adapters/files.js +5 -6
  6. package/dist/esm/adapters/files.js.map +1 -1
  7. package/dist/esm/adapters/image.d.ts +1 -0
  8. package/dist/esm/adapters/image.js +6 -7
  9. package/dist/esm/adapters/image.js.map +1 -1
  10. package/dist/esm/adapters/live.js +1 -2
  11. package/dist/esm/adapters/model3d.d.ts +98 -0
  12. package/dist/esm/adapters/model3d.js +170 -0
  13. package/dist/esm/adapters/model3d.js.map +1 -0
  14. package/dist/esm/adapters/motion.d.ts +58 -0
  15. package/dist/esm/adapters/motion.js +150 -0
  16. package/dist/esm/adapters/motion.js.map +1 -0
  17. package/dist/esm/adapters/speech.d.ts +1 -0
  18. package/dist/esm/adapters/speech.js +6 -7
  19. package/dist/esm/adapters/speech.js.map +1 -1
  20. package/dist/esm/adapters/transcription.d.ts +1 -0
  21. package/dist/esm/adapters/transcription.js +6 -7
  22. package/dist/esm/adapters/transcription.js.map +1 -1
  23. package/dist/esm/adapters/video.d.ts +2 -1
  24. package/dist/esm/adapters/video.js +13 -18
  25. package/dist/esm/adapters/video.js.map +1 -1
  26. package/dist/esm/byok.js +1 -2
  27. package/dist/esm/client/index.d.ts +65 -0
  28. package/dist/esm/client/index.js +306 -0
  29. package/dist/esm/client/index.js.map +1 -0
  30. package/dist/esm/image/generated/image-field-overrides.d.ts +459 -294
  31. package/dist/esm/image/generated/image-field-overrides.js +312 -190
  32. package/dist/esm/image/generated/image-field-overrides.js.map +1 -1
  33. package/dist/esm/image/image-inputs.js +7 -4
  34. package/dist/esm/image/image-inputs.js.map +1 -1
  35. package/dist/esm/image/image-provider-options.js +1 -2
  36. package/dist/esm/image/legacy-image-field-overrides.d.ts +13 -0
  37. package/dist/esm/image/legacy-image-field-overrides.js +91 -0
  38. package/dist/esm/image/legacy-image-field-overrides.js.map +1 -0
  39. package/dist/esm/index.d.ts +6 -2
  40. package/dist/esm/index.js +5 -2
  41. package/dist/esm/model-meta.d.ts +49 -0
  42. package/dist/esm/model3d/generated/mesh-field-overrides.d.ts +20 -0
  43. package/dist/esm/model3d/generated/mesh-field-overrides.js +20 -0
  44. package/dist/esm/model3d/generated/mesh-field-overrides.js.map +1 -0
  45. package/dist/esm/model3d/model3d-inputs.d.ts +39 -0
  46. package/dist/esm/model3d/model3d-inputs.js +206 -0
  47. package/dist/esm/model3d/model3d-inputs.js.map +1 -0
  48. package/dist/esm/model3d/model3d-output.d.ts +25 -0
  49. package/dist/esm/model3d/model3d-output.js +181 -0
  50. package/dist/esm/model3d/model3d-output.js.map +1 -0
  51. package/dist/esm/utils/billing.js +1 -2
  52. package/dist/esm/utils/client.d.ts +16 -1
  53. package/dist/esm/utils/client.js +31 -9
  54. package/dist/esm/utils/client.js.map +1 -1
  55. package/dist/esm/utils/configure.d.ts +12 -0
  56. package/dist/esm/utils/configure.js +19 -0
  57. package/dist/esm/utils/configure.js.map +1 -0
  58. package/dist/esm/utils/index.d.ts +2 -1
  59. package/dist/esm/video/video-provider-options.js +20 -31
  60. package/dist/esm/video/video-provider-options.js.map +1 -1
  61. package/package.json +8 -7
  62. package/src/adapters/audio.ts +7 -6
  63. package/src/adapters/files.ts +5 -4
  64. package/src/adapters/image.ts +8 -7
  65. package/src/adapters/model3d.ts +219 -0
  66. package/src/adapters/motion.ts +237 -0
  67. package/src/adapters/speech.ts +7 -6
  68. package/src/adapters/transcription.ts +8 -7
  69. package/src/adapters/video.ts +16 -18
  70. package/src/client/index.ts +456 -0
  71. package/src/image/generated/image-field-overrides.ts +159 -110
  72. package/src/image/image-inputs.ts +9 -4
  73. package/src/image/legacy-image-field-overrides.ts +94 -0
  74. package/src/index.ts +20 -1
  75. package/src/model-meta.ts +106 -0
  76. package/src/model3d/generated/mesh-field-overrides.ts +46 -0
  77. package/src/model3d/model3d-inputs.ts +232 -0
  78. package/src/model3d/model3d-output.ts +216 -0
  79. package/src/utils/client.ts +37 -4
  80. package/src/utils/configure.ts +17 -0
  81. package/src/utils/index.ts +2 -1
  82. package/src/video/video-provider-options.ts +9 -27
@@ -1,5 +1,5 @@
1
- import { fal } from '@fal-ai/client'
2
1
  import { generateId as _generateId, getApiKeyFromEnv } from '@tanstack/ai-utils'
2
+ import { createFalClient } from '../client/index'
3
3
  import { createBillingFetch } from './billing'
4
4
 
5
5
  export interface FalClientConfig {
@@ -18,16 +18,49 @@ export function getFalApiKeyFromEnv(): string {
18
18
  return getApiKeyFromEnv('FAL_KEY')
19
19
  }
20
20
 
21
- export function configureFalClient(config?: FalClientConfig): void {
21
+ export function toFalClientOptions(config?: FalClientConfig) {
22
22
  const apiKey = config?.apiKey ?? getFalApiKeyFromEnv()
23
- fal.config({
23
+ return {
24
24
  credentials: apiKey,
25
25
  // Wrap the (optionally overridden) fetch to read fal's
26
26
  // `x-fal-billable-units` header off every response so adapters can surface
27
27
  // the billed quantity as `result.usage`. See ./billing.ts.
28
28
  fetch: createBillingFetch(config?.fetch),
29
29
  ...(config?.proxyUrl ? { proxyUrl: config.proxyUrl } : {}),
30
- })
30
+ }
31
+ }
32
+
33
+ /**
34
+ * Create the fal client for one adapter. Each adapter has its own client, so
35
+ * two adapters with different API keys do not change each other.
36
+ */
37
+ export function createAdapterFalClient(config?: FalClientConfig) {
38
+ return createFalClient(toFalClientOptions(config))
39
+ }
40
+
41
+ /**
42
+ * fal can report a request COMPLETED and then answer the result fetch with a
43
+ * 422. Returns its `detail` text, or joins a detail list as `field: message`
44
+ * pairs. Returns undefined when the error has no detail.
45
+ */
46
+ export function falValidationMessage(error: unknown): string | undefined {
47
+ if (typeof error !== 'object' || error === null || !('body' in error)) {
48
+ return undefined
49
+ }
50
+ const body = error.body
51
+ if (typeof body !== 'object' || body === null || !('detail' in body)) {
52
+ return undefined
53
+ }
54
+ const detail = body.detail
55
+ if (typeof detail === 'string') return detail || undefined
56
+ if (!Array.isArray(detail)) return undefined
57
+ const message = detail
58
+ .map((d: { msg?: string; loc?: Array<string> }) => {
59
+ const msg = d.msg ?? 'invalid value'
60
+ return d.loc ? `${d.loc.join('.')}: ${msg}` : msg
61
+ })
62
+ .join('; ')
63
+ return message || undefined
31
64
  }
32
65
 
33
66
  export function generateId(prefix: string): string {
@@ -0,0 +1,17 @@
1
+ import { fal } from '@fal-ai/client'
2
+ import { toFalClientOptions } from './client'
3
+ import type { FalClientConfig } from './client'
4
+
5
+ /**
6
+ * Configure the global `fal` client of `@fal-ai/client` with this config, for
7
+ * apps that call `fal` themselves. The adapters do not use the global client.
8
+ *
9
+ * ponytail: this file is the only static import of `@fal-ai/client`. It is a
10
+ * separate module, so a bundle that does not import this function drops it.
11
+ *
12
+ * @param config the API key (or `FAL_KEY` from the environment), an optional
13
+ * proxy URL, and an optional `fetch`.
14
+ */
15
+ export function configureFalClient(config?: FalClientConfig): void {
16
+ fal.config(toFalClientOptions(config))
17
+ }
@@ -1,6 +1,5 @@
1
1
  export {
2
2
  getFalApiKeyFromEnv,
3
- configureFalClient,
4
3
  generateId,
5
4
  arrayBufferToBase64,
6
5
  dataUrlToBlob,
@@ -10,3 +9,5 @@ export {
10
9
  } from './client'
11
10
 
12
11
  export { takeBillableUnits, buildFalUsage } from './billing'
12
+
13
+ export { configureFalClient } from './configure'
@@ -41,7 +41,12 @@ function durationMap<
41
41
 
42
42
  const KLING_5_10 = { kind: 'discrete', values: ['5', '10'] } as const
43
43
  const VEO_4_6_8 = { kind: 'discrete', values: ['4s', '6s', '8s'] } as const
44
- const LTX_6_8_10 = { kind: 'discrete', values: ['6', '8', '10'] } as const
44
+ const LTX_6_8_10 = { kind: 'discrete', values: [6, 8, 10] } as const
45
+ // Durations over 10 seconds need 25 FPS and 1080p.
46
+ const LTX_FAST_6_20 = {
47
+ kind: 'discrete',
48
+ values: [6, 8, 10, 12, 14, 16, 18, 20],
49
+ } as const
45
50
  const KLING_3_15 = {
46
51
  kind: 'discrete',
47
52
  values: [
@@ -78,11 +83,6 @@ const FAL_VIDEO_DURATIONS = durationMap({
78
83
  'fal-ai/kling-video/v2.6/pro/image-to-video': KLING_5_10,
79
84
  'fal-ai/kling-video/v3/pro/text-to-video': KLING_3_15,
80
85
  'fal-ai/kling-video/v3/pro/image-to-video': KLING_3_15,
81
- 'fal-ai/pika/v2.2/text-to-video': KLING_5_10,
82
- 'fal-ai/luma-dream-machine/ray-2': {
83
- kind: 'discrete',
84
- values: ['5s', '9s'],
85
- },
86
86
  'fal-ai/veo3': VEO_4_6_8,
87
87
  'fal-ai/veo3/image-to-video': VEO_4_6_8,
88
88
  'fal-ai/veo3.1': VEO_4_6_8,
@@ -90,28 +90,10 @@ const FAL_VIDEO_DURATIONS = durationMap({
90
90
  'fal-ai/veo3.1/fast': VEO_4_6_8,
91
91
  'fal-ai/veo3.1/fast/image-to-video': VEO_4_6_8,
92
92
  'fal-ai/ltx-2.3/text-to-video': LTX_6_8_10,
93
- 'fal-ai/ltx-2.3/text-to-video/fast': LTX_6_8_10,
93
+ 'fal-ai/ltx-2.3/text-to-video/fast': LTX_FAST_6_20,
94
94
  'fal-ai/ltx-2.3/image-to-video': LTX_6_8_10,
95
- 'fal-ai/ltx-2.3/image-to-video/fast': LTX_6_8_10,
96
- 'fal-ai/wan-25-preview/text-to-video': {
97
- kind: 'discrete',
98
- values: [
99
- '2',
100
- '3',
101
- '4',
102
- '5',
103
- '6',
104
- '7',
105
- '8',
106
- '9',
107
- '10',
108
- '11',
109
- '12',
110
- '13',
111
- '14',
112
- '15',
113
- ],
114
- },
95
+ 'fal-ai/ltx-2.3/image-to-video/fast': LTX_FAST_6_20,
96
+ 'fal-ai/wan-25-preview/text-to-video': KLING_5_10,
115
97
  'fal-ai/minimax/video-01': { kind: 'none' },
116
98
  'fal-ai/hunyuan-video-v1.5/text-to-video': { kind: 'none' },
117
99
  })