@tanstack/ai-fal 1.1.0 → 1.1.1

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 (42) hide show
  1. package/dist/esm/adapters/audio.d.ts +1 -0
  2. package/dist/esm/adapters/audio.js +5 -5
  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 +4 -4
  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 +5 -5
  9. package/dist/esm/adapters/image.js.map +1 -1
  10. package/dist/esm/adapters/speech.d.ts +1 -0
  11. package/dist/esm/adapters/speech.js +5 -5
  12. package/dist/esm/adapters/speech.js.map +1 -1
  13. package/dist/esm/adapters/transcription.d.ts +1 -0
  14. package/dist/esm/adapters/transcription.js +5 -5
  15. package/dist/esm/adapters/transcription.js.map +1 -1
  16. package/dist/esm/adapters/video.d.ts +2 -1
  17. package/dist/esm/adapters/video.js +8 -8
  18. package/dist/esm/adapters/video.js.map +1 -1
  19. package/dist/esm/client/index.d.ts +65 -0
  20. package/dist/esm/client/index.js +307 -0
  21. package/dist/esm/client/index.js.map +1 -0
  22. package/dist/esm/index.d.ts +2 -1
  23. package/dist/esm/index.js +2 -1
  24. package/dist/esm/utils/client.d.ts +10 -1
  25. package/dist/esm/utils/client.js +13 -7
  26. package/dist/esm/utils/client.js.map +1 -1
  27. package/dist/esm/utils/configure.d.ts +12 -0
  28. package/dist/esm/utils/configure.js +20 -0
  29. package/dist/esm/utils/configure.js.map +1 -0
  30. package/dist/esm/utils/index.d.ts +2 -1
  31. package/package.json +5 -4
  32. package/src/adapters/audio.ts +7 -6
  33. package/src/adapters/files.ts +5 -4
  34. package/src/adapters/image.ts +8 -7
  35. package/src/adapters/speech.ts +7 -6
  36. package/src/adapters/transcription.ts +8 -7
  37. package/src/adapters/video.ts +11 -10
  38. package/src/client/index.ts +456 -0
  39. package/src/index.ts +1 -1
  40. package/src/utils/client.ts +12 -4
  41. package/src/utils/configure.ts +17 -0
  42. package/src/utils/index.ts +2 -1
@@ -1,7 +1,6 @@
1
- import { fal } from '@fal-ai/client'
2
1
  import { BaseAudioAdapter } from '@tanstack/ai/adapters'
3
2
  import {
4
- configureFalClient,
3
+ createAdapterFalClient,
5
4
  deriveAudioContentType,
6
5
  generateId as utilGenerateId,
7
6
  } from '../utils/client'
@@ -12,6 +11,7 @@ import type {
12
11
  AudioGenerationResult,
13
12
  } from '@tanstack/ai'
14
13
  import type { FalClientConfig } from '../utils/client'
14
+ import type { FalClient } from '../client/index'
15
15
  import type { FalModel, FalModelInput } from '../model-meta'
16
16
 
17
17
  /**
@@ -68,10 +68,11 @@ export class FalAudioAdapter<TModel extends FalModel> extends BaseAudioAdapter<
68
68
  FalAudioProviderOptions<TModel>
69
69
  > {
70
70
  readonly name = 'fal' as const
71
+ private readonly client: FalClient
71
72
 
72
73
  constructor(model: TModel, config?: FalClientConfig) {
73
74
  super(model, {})
74
- configureFalClient(config)
75
+ this.client = createAdapterFalClient(config)
75
76
  }
76
77
 
77
78
  async generateAudio(
@@ -85,8 +86,8 @@ export class FalAudioAdapter<TModel extends FalModel> extends BaseAudioAdapter<
85
86
  let requestId: string | undefined
86
87
  try {
87
88
  const input = this.buildInput(options)
88
- // Request-specific abortSignal only — not fal.config() (global).
89
- const result = await fal.subscribe(this.model, {
89
+ // Pass the abortSignal per request, not in the client config.
90
+ const result = await this.client.subscribe(this.model, {
90
91
  input,
91
92
  ...(options.abortSignal ? { abortSignal: options.abortSignal } : {}),
92
93
  onEnqueue: (id) => {
@@ -98,7 +99,7 @@ export class FalAudioAdapter<TModel extends FalModel> extends BaseAudioAdapter<
98
99
  // The SDK stops waiting on abort but leaves the queued job running.
99
100
  // Cancel it so it stops billing.
100
101
  if (requestId && options.abortSignal?.aborted) {
101
- fal.queue.cancel(this.model, { requestId }).catch(() => {})
102
+ this.client.queue.cancel(this.model, { requestId }).catch(() => {})
102
103
  }
103
104
  logger.errors('fal.generateAudio fatal', {
104
105
  error,
@@ -1,12 +1,12 @@
1
- import { fal } from '@fal-ai/client'
2
1
  import {
3
2
  BaseFilesAdapter,
4
3
  normalizeFileUploadInput,
5
4
  } from '@tanstack/ai/adapters'
6
- import { configureFalClient } from '../utils/client'
5
+ import { createAdapterFalClient } from '../utils/client'
7
6
  import type { StorageSettings } from '@fal-ai/client'
8
7
  import type { FileHandle, FileUploadInput } from '@tanstack/ai/adapters'
9
8
  import type { FalClientConfig } from '../utils/client'
9
+ import type { FalClient } from '../client/index'
10
10
 
11
11
  export interface FalFilesConfig extends FalClientConfig {
12
12
  /**
@@ -25,17 +25,18 @@ export interface FalFilesConfig extends FalClientConfig {
25
25
  */
26
26
  export class FalFilesAdapter extends BaseFilesAdapter<'fal'> {
27
27
  readonly name = 'fal' as const
28
+ private readonly client: FalClient
28
29
  private readonly expiresIn?: StorageSettings['expiresIn']
29
30
 
30
31
  constructor(config?: FalFilesConfig) {
31
32
  super()
32
- configureFalClient(config)
33
+ this.client = createAdapterFalClient(config)
33
34
  this.expiresIn = config?.expiresIn
34
35
  }
35
36
 
36
37
  async upload(input: FileUploadInput): Promise<FileHandle<'fal'>> {
37
38
  const { blob, mimeType } = normalizeFileUploadInput(input)
38
- const url = await fal.storage.upload(
39
+ const url = await this.client.storage.upload(
39
40
  blob,
40
41
  this.expiresIn !== undefined
41
42
  ? { lifecycle: { expiresIn: this.expiresIn } }
@@ -1,8 +1,7 @@
1
- import { fal } from '@fal-ai/client'
2
1
  import { resolveMediaPrompt } from '@tanstack/ai'
3
2
  import { BaseImageAdapter } from '@tanstack/ai/adapters'
4
3
  import {
5
- configureFalClient,
4
+ createAdapterFalClient,
6
5
  generateId as utilGenerateId,
7
6
  } from '../utils/client'
8
7
  import { buildFalUsage, takeBillableUnits } from '../utils/billing'
@@ -10,6 +9,7 @@ import { mapSizeToFalFormat } from '../image/image-provider-options'
10
9
  import { mapImageInputsToFalFields } from '../image/image-inputs'
11
10
  import type { OutputType, Result } from '@fal-ai/client'
12
11
  import type { FalClientConfig } from '../utils/client'
12
+ import type { FalClient } from '../client/index'
13
13
  import type {
14
14
  GeneratedImage,
15
15
  ImageGenerationOptions,
@@ -53,12 +53,13 @@ export class FalImageAdapter<TModel extends FalModel> extends BaseImageAdapter<
53
53
  > {
54
54
  override readonly kind = 'image' as const
55
55
  readonly name = 'fal' as const
56
+ private readonly client: FalClient
56
57
  // Consumes fal storage URLs uploaded via falFiles().
57
58
  override readonly supportsFileSources = true
58
59
 
59
60
  constructor(model: TModel, config?: FalClientConfig) {
60
61
  super(model, {})
61
- configureFalClient(config)
62
+ this.client = createAdapterFalClient(config)
62
63
  }
63
64
 
64
65
  async generateImages(
@@ -90,9 +91,9 @@ export class FalImageAdapter<TModel extends FalModel> extends BaseImageAdapter<
90
91
  let requestId: string | undefined
91
92
  try {
92
93
  const input = this.buildInput(options, resolved)
93
- // Pass request-specific abortSignal only — never via fal.config(), which
94
- // is global and would cancel concurrent generations from other calls.
95
- const result = await fal.subscribe(this.model, {
94
+ // Pass the abortSignal per request, not in the client config, so it
95
+ // cannot cancel other generations.
96
+ const result = await this.client.subscribe(this.model, {
96
97
  input,
97
98
  ...(options.abortSignal ? { abortSignal: options.abortSignal } : {}),
98
99
  onEnqueue: (id) => {
@@ -104,7 +105,7 @@ export class FalImageAdapter<TModel extends FalModel> extends BaseImageAdapter<
104
105
  // The SDK stops waiting on abort but leaves the queued job running.
105
106
  // Cancel it so it stops billing.
106
107
  if (requestId && options.abortSignal?.aborted) {
107
- fal.queue.cancel(this.model, { requestId }).catch(() => {})
108
+ this.client.queue.cancel(this.model, { requestId }).catch(() => {})
108
109
  }
109
110
  logger.errors('fal.generateImage fatal', {
110
111
  error,
@@ -1,8 +1,7 @@
1
- import { fal } from '@fal-ai/client'
2
1
  import { BaseTTSAdapter } from '@tanstack/ai/adapters'
3
2
  import {
4
3
  arrayBufferToBase64,
5
- configureFalClient,
4
+ createAdapterFalClient,
6
5
  extractUrlExtension,
7
6
  generateId as utilGenerateId,
8
7
  } from '../utils/client'
@@ -10,6 +9,7 @@ import { buildFalUsage, takeBillableUnits } from '../utils/billing'
10
9
  import type { OutputType, Result } from '@fal-ai/client'
11
10
  import type { TTSOptions, TTSResult } from '@tanstack/ai'
12
11
  import type { FalClientConfig } from '../utils/client'
12
+ import type { FalClient } from '../client/index'
13
13
  import type { FalModel, FalModelInput } from '../model-meta'
14
14
 
15
15
  /**
@@ -40,10 +40,11 @@ export class FalSpeechAdapter<TModel extends FalModel> extends BaseTTSAdapter<
40
40
  FalSpeechProviderOptions<TModel>
41
41
  > {
42
42
  readonly name = 'fal' as const
43
+ private readonly client: FalClient
43
44
 
44
45
  constructor(model: TModel, config?: FalClientConfig) {
45
46
  super(model, {})
46
- configureFalClient(config)
47
+ this.client = createAdapterFalClient(config)
47
48
  }
48
49
 
49
50
  async generateSpeech(
@@ -57,8 +58,8 @@ export class FalSpeechAdapter<TModel extends FalModel> extends BaseTTSAdapter<
57
58
  let requestId: string | undefined
58
59
  try {
59
60
  const input = this.buildInput(options)
60
- // Request-specific abortSignal only — not fal.config() (global).
61
- const result = await fal.subscribe(this.model, {
61
+ // Pass the abortSignal per request, not in the client config.
62
+ const result = await this.client.subscribe(this.model, {
62
63
  input,
63
64
  ...(options.abortSignal ? { abortSignal: options.abortSignal } : {}),
64
65
  onEnqueue: (id) => {
@@ -70,7 +71,7 @@ export class FalSpeechAdapter<TModel extends FalModel> extends BaseTTSAdapter<
70
71
  // The SDK stops waiting on abort but leaves the queued job running.
71
72
  // Cancel it so it stops billing.
72
73
  if (requestId && options.abortSignal?.aborted) {
73
- fal.queue.cancel(this.model, { requestId }).catch(() => {})
74
+ this.client.queue.cancel(this.model, { requestId }).catch(() => {})
74
75
  }
75
76
  logger.errors('fal.generateSpeech fatal', {
76
77
  error,
@@ -1,7 +1,6 @@
1
- import { fal } from '@fal-ai/client'
2
1
  import { BaseTranscriptionAdapter } from '@tanstack/ai/adapters'
3
2
  import {
4
- configureFalClient,
3
+ createAdapterFalClient,
5
4
  dataUrlToBlob,
6
5
  generateId as utilGenerateId,
7
6
  } from '../utils/client'
@@ -13,6 +12,7 @@ import type {
13
12
  TranscriptionSegment,
14
13
  } from '@tanstack/ai'
15
14
  import type { FalClientConfig } from '../utils/client'
15
+ import type { FalClient } from '../client/index'
16
16
  import type { FalModel, FalModelInput } from '../model-meta'
17
17
 
18
18
  /**
@@ -51,10 +51,11 @@ export class FalTranscriptionAdapter<
51
51
  FalTranscriptionProviderOptions<TModel>
52
52
  > {
53
53
  readonly name = 'fal' as const
54
+ private readonly client: FalClient
54
55
 
55
56
  constructor(model: TModel, config?: FalClientConfig) {
56
57
  super(model, {})
57
- configureFalClient(config)
58
+ this.client = createAdapterFalClient(config)
58
59
  }
59
60
 
60
61
  async transcribe(
@@ -71,8 +72,8 @@ export class FalTranscriptionAdapter<
71
72
  let requestId: string | undefined
72
73
  try {
73
74
  const input = this.buildInput(options)
74
- // Request-specific abortSignal only — not fal.config() (global).
75
- const result = await fal.subscribe(this.model, {
75
+ // Pass the abortSignal per request, not in the client config.
76
+ const result = await this.client.subscribe(this.model, {
76
77
  input,
77
78
  ...(options.abortSignal ? { abortSignal: options.abortSignal } : {}),
78
79
  onEnqueue: (id) => {
@@ -84,7 +85,7 @@ export class FalTranscriptionAdapter<
84
85
  // The SDK stops waiting on abort but leaves the queued job running.
85
86
  // Cancel it so it stops billing.
86
87
  if (requestId && options.abortSignal?.aborted) {
87
- fal.queue.cancel(this.model, { requestId }).catch(() => {})
88
+ this.client.queue.cancel(this.model, { requestId }).catch(() => {})
88
89
  }
89
90
  logger.errors('fal.generateTranscription fatal', {
90
91
  error,
@@ -97,7 +98,7 @@ export class FalTranscriptionAdapter<
97
98
  private buildInput(
98
99
  options: TranscriptionOptions<FalTranscriptionProviderOptions<TModel>>,
99
100
  ): FalModelInput<TModel> {
100
- // fal-client auto-uploads Blob/File inputs via fal.storage.upload, but
101
+ // The fal client auto-uploads Blob/File inputs via storage.upload, but
101
102
  // passes strings through unchanged — so a `data:` URL would reach fal's
102
103
  // API and get rejected with a 422 "Unsupported data URL". Decode data
103
104
  // URLs to a Blob up front so the auto-upload path handles them.
@@ -1,8 +1,7 @@
1
- import { fal } from '@fal-ai/client'
2
1
  import { resolveMediaPrompt } from '@tanstack/ai'
3
2
  import { BaseVideoAdapter } from '@tanstack/ai/adapters'
4
3
  import {
5
- configureFalClient,
4
+ createAdapterFalClient,
6
5
  generateId as utilGenerateId,
7
6
  } from '../utils/client'
8
7
  import { buildFalUsage, takeBillableUnits } from '../utils/billing'
@@ -33,6 +32,7 @@ import type {
33
32
  FalVideoProviderOptions,
34
33
  } from '../model-meta'
35
34
  import type { FalClientConfig } from '../utils/client'
35
+ import type { FalClient } from '../client/index'
36
36
 
37
37
  /**
38
38
  * Map video conditioning inputs onto fal field names.
@@ -138,12 +138,13 @@ export class FalVideoAdapter<TModel extends FalModel> extends BaseVideoAdapter<
138
138
  > {
139
139
  override readonly kind = 'video' as const
140
140
  readonly name = 'fal' as const
141
+ private readonly client: FalClient
141
142
  // Consumes fal storage URLs uploaded via falFiles().
142
143
  override readonly supportsFileSources = true
143
144
 
144
145
  constructor(model: TModel, config?: FalClientConfig) {
145
146
  super({}, model)
146
- configureFalClient(config)
147
+ this.client = createAdapterFalClient(config)
147
148
  }
148
149
 
149
150
  async createVideoJob(
@@ -184,9 +185,9 @@ export class FalVideoAdapter<TModel extends FalModel> extends BaseVideoAdapter<
184
185
  ...(duration !== undefined ? { duration } : {}),
185
186
  } as FalModelInput<TModel>
186
187
 
187
- // Submit to queue and get request ID. Request-specific abortSignal only —
188
- // never via fal.config() (global; would cancel concurrent jobs).
189
- const { request_id } = await fal.queue.submit(this.model, {
188
+ // Submit to the queue and get the request ID. Pass the abortSignal per
189
+ // request, not in the client config, so it cannot cancel other jobs.
190
+ const { request_id } = await this.client.queue.submit(this.model, {
190
191
  input,
191
192
  ...(options.abortSignal ? { abortSignal: options.abortSignal } : {}),
192
193
  })
@@ -211,14 +212,14 @@ export class FalVideoAdapter<TModel extends FalModel> extends BaseVideoAdapter<
211
212
  }
212
213
 
213
214
  /**
214
- * Cancels a queued request with `fal.queue.cancel`. fal can refuse when the
215
+ * Cancels a queued request with the fal queue cancel endpoint. fal can refuse when the
215
216
  * request already runs, and then this rejects.
216
217
  */
217
218
  async cancelVideoJob(
218
219
  jobId: string,
219
220
  options?: { abortSignal?: AbortSignal },
220
221
  ): Promise<void> {
221
- await fal.queue.cancel(this.model, {
222
+ await this.client.queue.cancel(this.model, {
222
223
  requestId: jobId,
223
224
  ...(options?.abortSignal ? { abortSignal: options.abortSignal } : {}),
224
225
  })
@@ -228,7 +229,7 @@ export class FalVideoAdapter<TModel extends FalModel> extends BaseVideoAdapter<
228
229
  jobId: string,
229
230
  options?: { abortSignal?: AbortSignal },
230
231
  ): Promise<VideoStatusResult> {
231
- const statusResponse = (await fal.queue.status(this.model, {
232
+ const statusResponse = (await this.client.queue.status(this.model, {
232
233
  requestId: jobId,
233
234
  logs: true,
234
235
  ...(options?.abortSignal ? { abortSignal: options.abortSignal } : {}),
@@ -251,7 +252,7 @@ export class FalVideoAdapter<TModel extends FalModel> extends BaseVideoAdapter<
251
252
  ): Promise<VideoUrlResult> {
252
253
  let result
253
254
  try {
254
- result = await fal.queue.result(this.model, {
255
+ result = await this.client.queue.result(this.model, {
255
256
  requestId: jobId,
256
257
  ...(options?.abortSignal ? { abortSignal: options.abortSignal } : {}),
257
258
  })