Package Exports
- @umituz/react-native-ai-fal-provider
- @umituz/react-native-ai-fal-provider/src/index.ts
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@umituz/react-native-ai-fal-provider) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@umituz/react-native-ai-fal-provider
FAL AI provider service for React Native applications. Provides client wrapper, error handling, and React hooks.
Installation
npm install @umituz/react-native-ai-fal-provider @fal-ai/clientUsage
Initialize the Provider
import { falProvider } from "@umituz/react-native-ai-fal-provider";
falProvider.initialize({
apiKey: "YOUR_FAL_API_KEY",
maxRetries: 3,
defaultTimeoutMs: 300000,
});Using the Hook
import { useFalGeneration } from "@umituz/react-native-ai-fal-provider";
function MyComponent() {
const { data, error, isLoading, generate, retry } = useFalGeneration({
timeoutMs: 120000,
onProgress: (status) => console.log("Progress:", status),
onError: (error) => console.log("Error:", error),
});
const handleGenerate = async () => {
await generate("fal-ai/flux/dev", {
prompt: "A beautiful sunset",
image_size: "landscape_16_9",
});
};
return (
// Your UI
);
}Direct Provider Usage
import { falProvider } from "@umituz/react-native-ai-fal-provider";
const result = await falProvider.subscribe("fal-ai/flux/dev", {
prompt: "A beautiful sunset",
});Error Handling
import { mapFalError, isFalErrorRetryable, falProvider } from "@umituz/react-native-ai-fal-provider";
try {
await falProvider.run("fal-ai/flux/dev", { prompt: "test" });
} catch (error) {
const errorInfo = mapFalError(error);
console.log("Error type:", errorInfo.type);
console.log("Message key:", errorInfo.messageKey);
console.log("Retryable:", errorInfo.retryable);
}API
falProvider
initialize(config)- Initialize the provider with API keysubscribe(model, input, options)- Subscribe to generation jobrun(model, input, options)- Run a generation jobsubmitJob(model, input)- Submit a job to queuegetJobStatus(model, requestId)- Get job statusgetJobResult(model, requestId)- Get job resultisInitialized()- Check if provider is initializedreset()- Reset the providergetCapabilities()- Get provider capabilitiesisFeatureSupported(feature)- Check if feature is supported
useFalGeneration Hook
data- Generation resulterror- Error info if failedisLoading- Loading stateisRetryable- Whether error is retryablegenerate(endpoint, input)- Start generationretry()- Retry last generationreset()- Reset state
Error Utilities
mapFalError(error)- Map error to FalErrorInfoisFalErrorRetryable(error)- Check if error is retryablecategorizeFalError(error)- Get error category
License
MIT