Proposed Auto-generated types library for fal-ai/client#204
Open
tombeckenham wants to merge 17 commits intofal-ai:mainfrom
Open
Proposed Auto-generated types library for fal-ai/client#204tombeckenham wants to merge 17 commits intofal-ai:mainfrom
tombeckenham wants to merge 17 commits intofal-ai:mainfrom
Conversation
…api generation Fixes fal-ai#184
…package Create a new @fal-ai/types package to decouple endpoint type definitions from the client, allowing types to update more frequently than the client. - Create libs/types/ with package.json, project.json, and tsconfig files - Move all generated type directories (3d, audio, image, etc.) to types package - Move endpoints.ts, client.ts, schemas.ts aggregation files to types package - Update client to import EndpointType/InputType/OutputType from @fal-ai/types - Add @fal-ai/types as optional peer dependency of @fal-ai/client - Re-export type aliases from client for backwards compatibility - Update openapi-ts.config.ts and generate-endpoint-maps.ts output paths - Update tsconfig.base.json with @fal-ai/types path mappings - Fix pre-existing issue with missing json category references https://claude.ai/code/session_01EudHCRh6N1AjX1RRDG6RJj
Auto-generated documentation update from lint-staged hook. https://claude.ai/code/session_01EudHCRh6N1AjX1RRDG6RJj
…ut-of-sync-with-fal-api and update generation
…/create-types-package-o3Bmg
…3Bmg Types package
…ut-of-sync-with-fal-api
Generate index.ts instead of client.ts as the types package entry point, make @fal-ai/types a required dependency (>=0.1.0 <1.0.0), add nx implicit dependency for build ordering, and coerce mismatched default values in OpenAPI specs to prevent Zod codegen type errors. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
@tombeckenham wow what a massive pull request. Let me know if you need anything from @hey-api! |
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.
This PR provides a new way of generating types for @fal-ai/client by providing an independent @fal-ai/types library that is auto-generated from live Fal OpenAPI specs. Add a FAL_KEY to .env.local then:
I researched type safety extensively on the Fal client while building the TanStack AI adapter for Fal. When the TanStack team built the adapters for other providers, they found it was nearly impossible to have a single endpoint type that covered all models for all content types. See their blog post on why they split the adapters.
Likewise in Fal client, having a single
EndpointTypeMapfor every single model, has already hit the limit of what's possible.I ran an experiment to see if it was possible to do the same by category of output. I forked the fal-js client library, and created a types library that uses HeyApi to generate types & schemas by category. HeyApi is brilliant for this, and is well maintained.
I found it was possible to generate the EndpointTypeMaps per category by combining OpenAPI specs downloaded from Fal. This gives us an
InputTypeandOutputTypeby category. I then found it was possible to provide a single InputType and OutputType using long conditionals like this:Key files:
scripts/fetch-openapi-models.ts- uses aFAL_KEYto download the OpenAPI spec for every model then combine by category into a hidden json folderopenapi-ts.config.ts- HeyApi config that transforms (corrects) and merges OpenAPI specs - then generates types and zod schemas from those specs. Note, it could generate json schemas as well, but you can generate them from the zodscripts/generate-endpoint-maps.ts- Generates the endpoint type maps and discriminatedUnion zod schemas for each category then creates a combined index for the conditional EndpointTypeCloses #184
Closes #195