feat: add fal.ai as a first-class provider (record + replay)#153
Merged
jpr5 merged 1 commit intoCopilotKit:mainfrom May 5, 2026
Conversation
Adds a general fal.ai handler that supports arbitrary JSON request/response payloads (image, video, motion, music, etc.) — not just audio. Routes by `x-fal-target-host` header to mirror the @fal-ai/client server-side requestMiddleware convention, and falls through to the existing /fal/queue/... and /fal/run/... audio paths for back-compat. Closes CopilotKit#152.
commit: |
Contributor
|
Great work on this — clean routing design, solid test coverage, and the One thing we caught during review: Merging now — thanks! |
Contributor
Author
|
Cool. That was fast! |
Contributor
|
I live to serve! 🙏 |
Contributor
|
Shipped as 1.18.0 FYI. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
src/fal.ts) supporting arbitrary JSON request/response payloads — image, video, motion, music, etc. — alongside the existing audio-onlysrc/fal-audio.ts.x-fal-target-hostheader to mirror the@fal-ai/clientserver-siderequestMiddlewareconvention (sinceproxyUrlis browser-only). Falls through to the legacy/fal/queue/...and/fal/run/...paths for back-compat.mock.onFalQueue(/model/, payload)(primary) andmock.onFalRun(/model/, payload)(sync alias) toLLMock. Queue submit auto-mints a request_id and returns the standard envelope; status/result lookups go through a per-testId TTL+boundedFalQueueStateMap(mirrors theFalJobMappattern fromfal-audio.tsand theVideoStateMapfromvideo.ts).RawJSONResponse({ json: unknown }) variant toFixtureResponseso the recorder can save fal payloads verbatim instead of mis-classifying them asImageResponse/VideoResponse.Closes #152.
Surface
/fal/{owner}/{model}queue.fal.run/fal/{owner}/{model}/requests/{id}/statusqueue.fal.runCOMPLETED)/fal/{owner}/{model}/requests/{id}queue.fal.run/fal/{owner}/{model}/requests/{id}/cancelqueue.fal.runALREADY_COMPLETED/fal/{owner}/{model}fal.run/fal/storage/upload/initiaterest.fal.ai/rest.alpha.fal.ai/fal/queue/submit/{model},/fal/queue/requests/{id}/...,/fal/run/{model}fal-audio.tsUsage
In record mode (
record.providers.fal: 'https://queue.fal.run', or omit and let the header drive it), unmatched requests proxy through to fal.ai and are saved asendpoint: "fal"fixtures with the verbatim JSON payload.Test plan
pnpm test— 2751 passed, 36 skipped, 78 test filespnpm run lint,pnpm run format:check(the only formatting warning is in pre-existing.claude/settings.local.json)src/__tests__/fal.test.ts(12 tests): queue lifecycle, host-mirror routing, sync run, cancel, error fixtures, storage stub, testId isolation, legacy back-compat, record + replaysrc/__tests__/fal-audio.test.tsstill greensrc/__tests__/recorder.test.tsstill green@fal-ai/clientin a downstream app (TanStack Start)Notes
recorder.tsalready tees SSE streams progressively (added in a prior commit), so the streaming-relay concern raised in the issue's first comment is no longer a blocker for fal.onFalQueueas the primary entry point andonFalRunas a thin alias, sincefal.queue.*is how clients actually call fal in modern code.🤖 Generated with Claude Code