@framers/agentos 0.1.113 → 0.1.114
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.
- package/README.md +39 -5
- package/dist/api/AgentOS.d.ts +45 -12
- package/dist/api/AgentOS.d.ts.map +1 -1
- package/dist/api/AgentOS.js +225 -78
- package/dist/api/AgentOS.js.map +1 -1
- package/dist/api/AgentOSOrchestrator.d.ts +8 -0
- package/dist/api/AgentOSOrchestrator.d.ts.map +1 -1
- package/dist/api/AgentOSOrchestrator.js +350 -59
- package/dist/api/AgentOSOrchestrator.js.map +1 -1
- package/dist/api/StreamChunkEmitter.d.ts.map +1 -1
- package/dist/api/StreamChunkEmitter.js +2 -0
- package/dist/api/StreamChunkEmitter.js.map +1 -1
- package/dist/api/agency.d.ts.map +1 -1
- package/dist/api/agency.js +47 -1
- package/dist/api/agency.js.map +1 -1
- package/dist/api/agent.d.ts +18 -5
- package/dist/api/agent.d.ts.map +1 -1
- package/dist/api/agent.js +48 -9
- package/dist/api/agent.js.map +1 -1
- package/dist/api/agentExport.d.ts +202 -0
- package/dist/api/agentExport.d.ts.map +1 -0
- package/dist/api/agentExport.js +323 -0
- package/dist/api/agentExport.js.map +1 -0
- package/dist/api/editImage.d.ts +119 -0
- package/dist/api/editImage.d.ts.map +1 -0
- package/dist/api/editImage.js +150 -0
- package/dist/api/editImage.js.map +1 -0
- package/dist/api/embedText.d.ts +137 -0
- package/dist/api/embedText.d.ts.map +1 -0
- package/dist/api/embedText.js +229 -0
- package/dist/api/embedText.js.map +1 -0
- package/dist/api/externalToolRegistry.d.ts +44 -0
- package/dist/api/externalToolRegistry.d.ts.map +1 -0
- package/dist/api/externalToolRegistry.js +245 -0
- package/dist/api/externalToolRegistry.js.map +1 -0
- package/dist/api/generateImage.d.ts +1 -1
- package/dist/api/generateImage.d.ts.map +1 -1
- package/dist/api/generateImage.js +17 -13
- package/dist/api/generateImage.js.map +1 -1
- package/dist/api/generateObject.d.ts +185 -0
- package/dist/api/generateObject.d.ts.map +1 -0
- package/dist/api/generateObject.js +249 -0
- package/dist/api/generateObject.js.map +1 -0
- package/dist/api/generateText.d.ts +13 -3
- package/dist/api/generateText.d.ts.map +1 -1
- package/dist/api/generateText.js +20 -5
- package/dist/api/generateText.js.map +1 -1
- package/dist/api/interfaces/IAgentOS.d.ts +29 -1
- package/dist/api/interfaces/IAgentOS.d.ts.map +1 -1
- package/dist/api/model.d.ts +7 -7
- package/dist/api/model.d.ts.map +1 -1
- package/dist/api/model.js +22 -16
- package/dist/api/model.js.map +1 -1
- package/dist/api/processRequestWithExternalTools.d.ts +26 -0
- package/dist/api/processRequestWithExternalTools.d.ts.map +1 -0
- package/dist/api/processRequestWithExternalTools.js +52 -0
- package/dist/api/processRequestWithExternalTools.js.map +1 -0
- package/dist/api/processRequestWithRegisteredTools.d.ts +56 -0
- package/dist/api/processRequestWithRegisteredTools.d.ts.map +1 -0
- package/dist/api/processRequestWithRegisteredTools.js +125 -0
- package/dist/api/processRequestWithRegisteredTools.js.map +1 -0
- package/dist/api/provider-defaults.d.ts.map +1 -1
- package/dist/api/provider-defaults.js +28 -0
- package/dist/api/provider-defaults.js.map +1 -1
- package/dist/api/resumeExternalToolRequestWithRegisteredTools.d.ts +71 -0
- package/dist/api/resumeExternalToolRequestWithRegisteredTools.d.ts.map +1 -0
- package/dist/api/resumeExternalToolRequestWithRegisteredTools.js +159 -0
- package/dist/api/resumeExternalToolRequestWithRegisteredTools.js.map +1 -0
- package/dist/api/strategies/agentGraphBuilder.d.ts +170 -0
- package/dist/api/strategies/agentGraphBuilder.d.ts.map +1 -0
- package/dist/api/strategies/agentGraphBuilder.js +299 -0
- package/dist/api/strategies/agentGraphBuilder.js.map +1 -0
- package/dist/api/strategies/graphCompiler.d.ts +84 -0
- package/dist/api/strategies/graphCompiler.d.ts.map +1 -0
- package/dist/api/strategies/graphCompiler.js +617 -0
- package/dist/api/strategies/graphCompiler.js.map +1 -0
- package/dist/api/strategies/hierarchical.d.ts.map +1 -1
- package/dist/api/strategies/hierarchical.js +2 -1
- package/dist/api/strategies/hierarchical.js.map +1 -1
- package/dist/api/strategies/index.d.ts +3 -0
- package/dist/api/strategies/index.d.ts.map +1 -1
- package/dist/api/strategies/index.js +2 -0
- package/dist/api/strategies/index.js.map +1 -1
- package/dist/api/strategies/shared.d.ts +1 -1
- package/dist/api/strategies/shared.d.ts.map +1 -1
- package/dist/api/strategies/shared.js +3 -2
- package/dist/api/strategies/shared.js.map +1 -1
- package/dist/api/streamObject.d.ts +166 -0
- package/dist/api/streamObject.d.ts.map +1 -0
- package/dist/api/streamObject.js +268 -0
- package/dist/api/streamObject.js.map +1 -0
- package/dist/api/streamText.d.ts +1 -1
- package/dist/api/streamText.d.ts.map +1 -1
- package/dist/api/streamText.js +26 -8
- package/dist/api/streamText.js.map +1 -1
- package/dist/api/toolAdapter.d.ts +44 -8
- package/dist/api/toolAdapter.d.ts.map +1 -1
- package/dist/api/toolAdapter.js +224 -45
- package/dist/api/toolAdapter.js.map +1 -1
- package/dist/api/types/AgentOSExternalToolRequest.d.ts +35 -0
- package/dist/api/types/AgentOSExternalToolRequest.d.ts.map +1 -0
- package/dist/api/types/AgentOSExternalToolRequest.js +2 -0
- package/dist/api/types/AgentOSExternalToolRequest.js.map +1 -0
- package/dist/api/types/AgentOSResponse.d.ts +25 -0
- package/dist/api/types/AgentOSResponse.d.ts.map +1 -1
- package/dist/api/types/AgentOSResponse.js +20 -0
- package/dist/api/types/AgentOSResponse.js.map +1 -1
- package/dist/api/types/AgentOSToolResult.d.ts +11 -0
- package/dist/api/types/AgentOSToolResult.d.ts.map +1 -0
- package/dist/api/types/AgentOSToolResult.js +2 -0
- package/dist/api/types/AgentOSToolResult.js.map +1 -0
- package/dist/api/types.d.ts +28 -4
- package/dist/api/types.d.ts.map +1 -1
- package/dist/api/types.js.map +1 -1
- package/dist/api/upscaleImage.d.ts +92 -0
- package/dist/api/upscaleImage.d.ts.map +1 -0
- package/dist/api/upscaleImage.js +133 -0
- package/dist/api/upscaleImage.js.map +1 -0
- package/dist/api/variateImage.d.ts +102 -0
- package/dist/api/variateImage.d.ts.map +1 -0
- package/dist/api/variateImage.js +154 -0
- package/dist/api/variateImage.js.map +1 -0
- package/dist/cognitive_substrate/GMI.d.ts +16 -2
- package/dist/cognitive_substrate/GMI.d.ts.map +1 -1
- package/dist/cognitive_substrate/GMI.js +188 -56
- package/dist/cognitive_substrate/GMI.js.map +1 -1
- package/dist/cognitive_substrate/IGMI.d.ts +10 -0
- package/dist/cognitive_substrate/IGMI.d.ts.map +1 -1
- package/dist/cognitive_substrate/IGMI.js.map +1 -1
- package/dist/config/AgentOSConfig.d.ts +19 -2
- package/dist/config/AgentOSConfig.d.ts.map +1 -1
- package/dist/config/AgentOSConfig.js +46 -29
- package/dist/config/AgentOSConfig.js.map +1 -1
- package/dist/core/guardrails/IGuardrailService.d.ts +1 -1
- package/dist/core/images/IImageProvider.d.ts +93 -0
- package/dist/core/images/IImageProvider.d.ts.map +1 -1
- package/dist/core/images/IImageProvider.js.map +1 -1
- package/dist/core/images/ImageOperationError.d.ts +52 -0
- package/dist/core/images/ImageOperationError.d.ts.map +1 -0
- package/dist/core/images/ImageOperationError.js +58 -0
- package/dist/core/images/ImageOperationError.js.map +1 -0
- package/dist/core/images/imageToBuffer.d.ts +41 -0
- package/dist/core/images/imageToBuffer.d.ts.map +1 -0
- package/dist/core/images/imageToBuffer.js +95 -0
- package/dist/core/images/imageToBuffer.js.map +1 -0
- package/dist/core/images/index.d.ts +4 -0
- package/dist/core/images/index.d.ts.map +1 -1
- package/dist/core/images/index.js +8 -0
- package/dist/core/images/index.js.map +1 -1
- package/dist/core/images/providers/FalImageProvider.d.ts +208 -0
- package/dist/core/images/providers/FalImageProvider.d.ts.map +1 -0
- package/dist/core/images/providers/FalImageProvider.js +301 -0
- package/dist/core/images/providers/FalImageProvider.js.map +1 -0
- package/dist/core/images/providers/FluxImageProvider.d.ts +197 -0
- package/dist/core/images/providers/FluxImageProvider.d.ts.map +1 -0
- package/dist/core/images/providers/FluxImageProvider.js +271 -0
- package/dist/core/images/providers/FluxImageProvider.js.map +1 -0
- package/dist/core/images/providers/OpenAIImageProvider.d.ts +33 -1
- package/dist/core/images/providers/OpenAIImageProvider.d.ts.map +1 -1
- package/dist/core/images/providers/OpenAIImageProvider.js +125 -0
- package/dist/core/images/providers/OpenAIImageProvider.js.map +1 -1
- package/dist/core/images/providers/ReplicateImageProvider.d.ts +26 -1
- package/dist/core/images/providers/ReplicateImageProvider.d.ts.map +1 -1
- package/dist/core/images/providers/ReplicateImageProvider.js +118 -0
- package/dist/core/images/providers/ReplicateImageProvider.js.map +1 -1
- package/dist/core/images/providers/StabilityImageProvider.d.ts +41 -1
- package/dist/core/images/providers/StabilityImageProvider.d.ts.map +1 -1
- package/dist/core/images/providers/StabilityImageProvider.js +180 -7
- package/dist/core/images/providers/StabilityImageProvider.js.map +1 -1
- package/dist/core/images/providers/StableDiffusionLocalProvider.d.ts +29 -1
- package/dist/core/images/providers/StableDiffusionLocalProvider.d.ts.map +1 -1
- package/dist/core/images/providers/StableDiffusionLocalProvider.js +124 -0
- package/dist/core/images/providers/StableDiffusionLocalProvider.js.map +1 -1
- package/dist/core/llm/IPromptEngine.d.ts +2 -2
- package/dist/core/llm/IPromptEngine.d.ts.map +1 -1
- package/dist/core/llm/IPromptEngine.js +2 -2
- package/dist/core/llm/IPromptEngine.js.map +1 -1
- package/dist/core/llm/providers/AIModelProviderManager.d.ts +7 -1
- package/dist/core/llm/providers/AIModelProviderManager.d.ts.map +1 -1
- package/dist/core/llm/providers/AIModelProviderManager.js +24 -0
- package/dist/core/llm/providers/AIModelProviderManager.js.map +1 -1
- package/dist/core/llm/providers/errors/AnthropicProviderError.d.ts +42 -0
- package/dist/core/llm/providers/errors/AnthropicProviderError.d.ts.map +1 -0
- package/dist/core/llm/providers/errors/AnthropicProviderError.js +45 -0
- package/dist/core/llm/providers/errors/AnthropicProviderError.js.map +1 -0
- package/dist/core/llm/providers/errors/GeminiProviderError.d.ts +45 -0
- package/dist/core/llm/providers/errors/GeminiProviderError.d.ts.map +1 -0
- package/dist/core/llm/providers/errors/GeminiProviderError.js +46 -0
- package/dist/core/llm/providers/errors/GeminiProviderError.js.map +1 -0
- package/dist/core/llm/providers/errors/OllamaProviderError.d.ts +1 -1
- package/dist/core/llm/providers/errors/OllamaProviderError.d.ts.map +1 -1
- package/dist/core/llm/providers/errors/OllamaProviderError.js +1 -1
- package/dist/core/llm/providers/errors/OllamaProviderError.js.map +1 -1
- package/dist/core/llm/providers/errors/OpenAIProviderError.d.ts +1 -1
- package/dist/core/llm/providers/errors/OpenAIProviderError.js +1 -1
- package/dist/core/llm/providers/errors/OpenRouterProviderError.d.ts +1 -1
- package/dist/core/llm/providers/errors/OpenRouterProviderError.js +1 -1
- package/dist/core/llm/providers/implementations/AnthropicProvider.d.ts +340 -0
- package/dist/core/llm/providers/implementations/AnthropicProvider.d.ts.map +1 -0
- package/dist/core/llm/providers/implementations/AnthropicProvider.js +959 -0
- package/dist/core/llm/providers/implementations/AnthropicProvider.js.map +1 -0
- package/dist/core/llm/providers/implementations/GeminiProvider.d.ts +339 -0
- package/dist/core/llm/providers/implementations/GeminiProvider.d.ts.map +1 -0
- package/dist/core/llm/providers/implementations/GeminiProvider.js +1004 -0
- package/dist/core/llm/providers/implementations/GeminiProvider.js.map +1 -0
- package/dist/core/llm/providers/implementations/GroqProvider.d.ts +105 -0
- package/dist/core/llm/providers/implementations/GroqProvider.d.ts.map +1 -0
- package/dist/core/llm/providers/implementations/GroqProvider.js +134 -0
- package/dist/core/llm/providers/implementations/GroqProvider.js.map +1 -0
- package/dist/core/llm/providers/implementations/MistralProvider.d.ts +105 -0
- package/dist/core/llm/providers/implementations/MistralProvider.d.ts.map +1 -0
- package/dist/core/llm/providers/implementations/MistralProvider.js +146 -0
- package/dist/core/llm/providers/implementations/MistralProvider.js.map +1 -0
- package/dist/core/llm/providers/implementations/TogetherProvider.d.ts +107 -0
- package/dist/core/llm/providers/implementations/TogetherProvider.d.ts.map +1 -0
- package/dist/core/llm/providers/implementations/TogetherProvider.js +138 -0
- package/dist/core/llm/providers/implementations/TogetherProvider.js.map +1 -0
- package/dist/core/llm/providers/implementations/XAIProvider.d.ts +102 -0
- package/dist/core/llm/providers/implementations/XAIProvider.d.ts.map +1 -0
- package/dist/core/llm/providers/implementations/XAIProvider.js +123 -0
- package/dist/core/llm/providers/implementations/XAIProvider.js.map +1 -0
- package/dist/core/orchestration/AgentOrchestrator.d.ts.map +1 -1
- package/dist/core/orchestration/AgentOrchestrator.js +26 -5
- package/dist/core/orchestration/AgentOrchestrator.js.map +1 -1
- package/dist/core/tools/IToolOrchestrator.d.ts +2 -2
- package/dist/core/tools/IToolOrchestrator.d.ts.map +1 -1
- package/dist/core/tools/ToolExecutor.d.ts +3 -0
- package/dist/core/tools/ToolExecutor.d.ts.map +1 -1
- package/dist/core/tools/ToolExecutor.js +2 -1
- package/dist/core/tools/ToolExecutor.js.map +1 -1
- package/dist/core/tools/ToolOrchestrator.d.ts +7 -7
- package/dist/core/tools/ToolOrchestrator.d.ts.map +1 -1
- package/dist/core/tools/ToolOrchestrator.js +135 -36
- package/dist/core/tools/ToolOrchestrator.js.map +1 -1
- package/dist/core/tools/permissions/ToolPermissionManager.d.ts +6 -5
- package/dist/core/tools/permissions/ToolPermissionManager.d.ts.map +1 -1
- package/dist/core/tools/permissions/ToolPermissionManager.js +47 -21
- package/dist/core/tools/permissions/ToolPermissionManager.js.map +1 -1
- package/dist/core/vision/VisionPipeline.d.ts +437 -0
- package/dist/core/vision/VisionPipeline.d.ts.map +1 -0
- package/dist/core/vision/VisionPipeline.js +1113 -0
- package/dist/core/vision/VisionPipeline.js.map +1 -0
- package/dist/core/vision/index.d.ts +97 -0
- package/dist/core/vision/index.d.ts.map +1 -0
- package/dist/core/vision/index.js +182 -0
- package/dist/core/vision/index.js.map +1 -0
- package/dist/core/vision/providers/LLMVisionProvider.d.ts +135 -0
- package/dist/core/vision/providers/LLMVisionProvider.d.ts.map +1 -0
- package/dist/core/vision/providers/LLMVisionProvider.js +136 -0
- package/dist/core/vision/providers/LLMVisionProvider.js.map +1 -0
- package/dist/core/vision/providers/PipelineVisionProvider.d.ts +154 -0
- package/dist/core/vision/providers/PipelineVisionProvider.d.ts.map +1 -0
- package/dist/core/vision/providers/PipelineVisionProvider.js +160 -0
- package/dist/core/vision/providers/PipelineVisionProvider.js.map +1 -0
- package/dist/core/vision/types.d.ts +286 -0
- package/dist/core/vision/types.d.ts.map +1 -0
- package/dist/core/vision/types.js +24 -0
- package/dist/core/vision/types.js.map +1 -0
- package/dist/discovery/CapabilityDiscoveryEngine.d.ts +1 -1
- package/dist/discovery/CapabilityDiscoveryEngine.d.ts.map +1 -1
- package/dist/discovery/CapabilityDiscoveryEngine.js +1 -1
- package/dist/discovery/CapabilityDiscoveryEngine.js.map +1 -1
- package/dist/emergent/ComposableToolBuilder.d.ts +15 -4
- package/dist/emergent/ComposableToolBuilder.d.ts.map +1 -1
- package/dist/emergent/ComposableToolBuilder.js +29 -14
- package/dist/emergent/ComposableToolBuilder.js.map +1 -1
- package/dist/emergent/EmergentCapabilityEngine.d.ts +3 -3
- package/dist/emergent/EmergentCapabilityEngine.d.ts.map +1 -1
- package/dist/emergent/EmergentCapabilityEngine.js +15 -12
- package/dist/emergent/EmergentCapabilityEngine.js.map +1 -1
- package/dist/emergent/EmergentJudge.d.ts +20 -0
- package/dist/emergent/EmergentJudge.d.ts.map +1 -1
- package/dist/emergent/EmergentJudge.js +121 -26
- package/dist/emergent/EmergentJudge.js.map +1 -1
- package/dist/emergent/EmergentToolRegistry.d.ts +17 -0
- package/dist/emergent/EmergentToolRegistry.d.ts.map +1 -1
- package/dist/emergent/EmergentToolRegistry.js +26 -0
- package/dist/emergent/EmergentToolRegistry.js.map +1 -1
- package/dist/emergent/ForgeToolMetaTool.d.ts +1 -1
- package/dist/emergent/ForgeToolMetaTool.d.ts.map +1 -1
- package/dist/emergent/ForgeToolMetaTool.js +15 -2
- package/dist/emergent/ForgeToolMetaTool.js.map +1 -1
- package/dist/emergent/SandboxedToolForge.d.ts +2 -2
- package/dist/emergent/SandboxedToolForge.d.ts.map +1 -1
- package/dist/emergent/SandboxedToolForge.js +13 -23
- package/dist/emergent/SandboxedToolForge.js.map +1 -1
- package/dist/emergent/SkillExporter.d.ts +119 -0
- package/dist/emergent/SkillExporter.d.ts.map +1 -0
- package/dist/emergent/SkillExporter.js +344 -0
- package/dist/emergent/SkillExporter.js.map +1 -0
- package/dist/emergent/index.d.ts +1 -0
- package/dist/emergent/index.d.ts.map +1 -1
- package/dist/emergent/index.js +1 -0
- package/dist/emergent/index.js.map +1 -1
- package/dist/emergent/types.d.ts +4 -4
- package/dist/index.d.ts +30 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -2
- package/dist/index.js.map +1 -1
- package/dist/memory/index.d.ts +10 -8
- package/dist/memory/index.d.ts.map +1 -1
- package/dist/memory/index.js +2 -0
- package/dist/memory/index.js.map +1 -1
- package/dist/memory/ingestion/DoclingLoader.d.ts +3 -3
- package/dist/memory/ingestion/DoclingLoader.d.ts.map +1 -1
- package/dist/memory/ingestion/DoclingLoader.js +12 -8
- package/dist/memory/ingestion/DoclingLoader.js.map +1 -1
- package/dist/memory/ingestion/FolderScanner.d.ts +7 -7
- package/dist/memory/ingestion/FolderScanner.d.ts.map +1 -1
- package/dist/memory/ingestion/FolderScanner.js +6 -6
- package/dist/memory/ingestion/FolderScanner.js.map +1 -1
- package/dist/memory/ingestion/LoaderRegistry.d.ts +8 -8
- package/dist/memory/ingestion/LoaderRegistry.d.ts.map +1 -1
- package/dist/memory/ingestion/LoaderRegistry.js +9 -11
- package/dist/memory/ingestion/LoaderRegistry.js.map +1 -1
- package/dist/memory/ingestion/MultimodalAggregator.d.ts +1 -1
- package/dist/memory/ingestion/MultimodalAggregator.js +1 -1
- package/dist/memory/ingestion/OcrPdfLoader.d.ts +2 -2
- package/dist/memory/ingestion/OcrPdfLoader.d.ts.map +1 -1
- package/dist/memory/ingestion/OcrPdfLoader.js +12 -8
- package/dist/memory/ingestion/OcrPdfLoader.js.map +1 -1
- package/dist/memory/ingestion/PdfLoader.d.ts +8 -8
- package/dist/memory/ingestion/PdfLoader.d.ts.map +1 -1
- package/dist/memory/ingestion/PdfLoader.js +13 -10
- package/dist/memory/ingestion/PdfLoader.js.map +1 -1
- package/dist/memory/io/MarkdownExporter.d.ts +1 -1
- package/dist/memory/io/MarkdownExporter.d.ts.map +1 -1
- package/dist/memory/io/MarkdownExporter.js +1 -1
- package/dist/memory/io/MarkdownExporter.js.map +1 -1
- package/dist/memory/tools/MemoryAddTool.d.ts +2 -2
- package/dist/memory/tools/MemoryAddTool.d.ts.map +1 -1
- package/dist/memory/tools/MemoryAddTool.js +8 -3
- package/dist/memory/tools/MemoryAddTool.js.map +1 -1
- package/dist/memory/tools/MemorySearchTool.d.ts +3 -3
- package/dist/memory/tools/MemorySearchTool.d.ts.map +1 -1
- package/dist/memory/tools/MemorySearchTool.js +11 -9
- package/dist/memory/tools/MemorySearchTool.js.map +1 -1
- package/dist/memory/tools/scopeContext.d.ts +11 -0
- package/dist/memory/tools/scopeContext.d.ts.map +1 -0
- package/dist/memory/tools/scopeContext.js +46 -0
- package/dist/memory/tools/scopeContext.js.map +1 -0
- package/dist/orchestration/builders/AgentGraph.d.ts +12 -11
- package/dist/orchestration/builders/AgentGraph.d.ts.map +1 -1
- package/dist/orchestration/builders/AgentGraph.js +12 -11
- package/dist/orchestration/builders/AgentGraph.js.map +1 -1
- package/dist/orchestration/builders/VoiceNodeBuilder.d.ts +2 -2
- package/dist/orchestration/builders/VoiceNodeBuilder.d.ts.map +1 -1
- package/dist/orchestration/builders/VoiceNodeBuilder.js +2 -2
- package/dist/orchestration/builders/VoiceNodeBuilder.js.map +1 -1
- package/dist/orchestration/builders/WorkflowBuilder.d.ts +1 -1
- package/dist/orchestration/builders/WorkflowBuilder.d.ts.map +1 -1
- package/dist/orchestration/builders/WorkflowBuilder.js +1 -1
- package/dist/orchestration/builders/WorkflowBuilder.js.map +1 -1
- package/dist/orchestration/checkpoint/InMemoryCheckpointStore.d.ts +7 -54
- package/dist/orchestration/checkpoint/InMemoryCheckpointStore.d.ts.map +1 -1
- package/dist/orchestration/checkpoint/InMemoryCheckpointStore.js +8 -56
- package/dist/orchestration/checkpoint/InMemoryCheckpointStore.js.map +1 -1
- package/dist/orchestration/events/GraphEvent.d.ts +12 -12
- package/dist/orchestration/events/GraphEvent.d.ts.map +1 -1
- package/dist/orchestration/events/GraphEvent.js.map +1 -1
- package/dist/orchestration/runtime/GraphRuntime.d.ts.map +1 -1
- package/dist/orchestration/runtime/GraphRuntime.js +151 -1
- package/dist/orchestration/runtime/GraphRuntime.js.map +1 -1
- package/dist/orchestration/runtime/LoopController.d.ts +3 -3
- package/dist/orchestration/runtime/LoopController.d.ts.map +1 -1
- package/dist/orchestration/runtime/LoopController.js.map +1 -1
- package/dist/orchestration/runtime/StateManager.d.ts +3 -3
- package/dist/orchestration/runtime/StateManager.js +3 -3
- package/dist/orchestration/runtime/VoiceNodeExecutor.d.ts +6 -6
- package/dist/orchestration/runtime/VoiceNodeExecutor.d.ts.map +1 -1
- package/dist/orchestration/runtime/VoiceNodeExecutor.js +27 -10
- package/dist/orchestration/runtime/VoiceNodeExecutor.js.map +1 -1
- package/dist/orchestration/runtime/VoiceTransportAdapter.d.ts +5 -5
- package/dist/orchestration/runtime/VoiceTransportAdapter.js +5 -5
- package/dist/orchestration/runtime/VoiceTurnCollector.d.ts +2 -2
- package/dist/orchestration/runtime/VoiceTurnCollector.js +2 -2
- package/dist/query-router/KeywordFallback.d.ts +70 -0
- package/dist/query-router/KeywordFallback.d.ts.map +1 -0
- package/dist/query-router/KeywordFallback.js +132 -0
- package/dist/query-router/KeywordFallback.js.map +1 -0
- package/dist/query-router/QueryClassifier.d.ts +140 -0
- package/dist/query-router/QueryClassifier.d.ts.map +1 -0
- package/dist/query-router/QueryClassifier.js +223 -0
- package/dist/query-router/QueryClassifier.js.map +1 -0
- package/dist/query-router/QueryDispatcher.d.ts +139 -0
- package/dist/query-router/QueryDispatcher.d.ts.map +1 -0
- package/dist/query-router/QueryDispatcher.js +297 -0
- package/dist/query-router/QueryDispatcher.js.map +1 -0
- package/dist/query-router/QueryGenerator.d.ts +184 -0
- package/dist/query-router/QueryGenerator.d.ts.map +1 -0
- package/dist/query-router/QueryGenerator.js +241 -0
- package/dist/query-router/QueryGenerator.js.map +1 -0
- package/dist/query-router/QueryRouter.d.ts +292 -0
- package/dist/query-router/QueryRouter.d.ts.map +1 -0
- package/dist/query-router/QueryRouter.js +803 -0
- package/dist/query-router/QueryRouter.js.map +1 -0
- package/dist/query-router/TopicExtractor.d.ts +73 -0
- package/dist/query-router/TopicExtractor.d.ts.map +1 -0
- package/dist/query-router/TopicExtractor.js +95 -0
- package/dist/query-router/TopicExtractor.js.map +1 -0
- package/dist/query-router/index.d.ts +40 -0
- package/dist/query-router/index.d.ts.map +1 -0
- package/dist/query-router/index.js +46 -0
- package/dist/query-router/index.js.map +1 -0
- package/dist/query-router/types.d.ts +508 -0
- package/dist/query-router/types.d.ts.map +1 -0
- package/dist/query-router/types.js +39 -0
- package/dist/query-router/types.js.map +1 -0
- package/dist/rag/index.d.ts +5 -0
- package/dist/rag/index.d.ts.map +1 -1
- package/dist/rag/index.js +7 -0
- package/dist/rag/index.js.map +1 -1
- package/dist/rag/multimodal/LLMVisionAdapter.d.ts +43 -0
- package/dist/rag/multimodal/LLMVisionAdapter.d.ts.map +1 -0
- package/dist/rag/multimodal/LLMVisionAdapter.js +46 -0
- package/dist/rag/multimodal/LLMVisionAdapter.js.map +1 -0
- package/dist/rag/multimodal/MultimodalIndexer.d.ts +244 -0
- package/dist/rag/multimodal/MultimodalIndexer.d.ts.map +1 -0
- package/dist/rag/multimodal/MultimodalIndexer.js +411 -0
- package/dist/rag/multimodal/MultimodalIndexer.js.map +1 -0
- package/dist/rag/multimodal/MultimodalMemoryBridge.d.ts +448 -0
- package/dist/rag/multimodal/MultimodalMemoryBridge.d.ts.map +1 -0
- package/dist/rag/multimodal/MultimodalMemoryBridge.js +941 -0
- package/dist/rag/multimodal/MultimodalMemoryBridge.js.map +1 -0
- package/dist/rag/multimodal/SpeechProviderAdapter.d.ts +139 -0
- package/dist/rag/multimodal/SpeechProviderAdapter.d.ts.map +1 -0
- package/dist/rag/multimodal/SpeechProviderAdapter.js +143 -0
- package/dist/rag/multimodal/SpeechProviderAdapter.js.map +1 -0
- package/dist/rag/multimodal/createMultimodalIndexerFromResolver.d.ts +172 -0
- package/dist/rag/multimodal/createMultimodalIndexerFromResolver.d.ts.map +1 -0
- package/dist/rag/multimodal/createMultimodalIndexerFromResolver.js +152 -0
- package/dist/rag/multimodal/createMultimodalIndexerFromResolver.js.map +1 -0
- package/dist/rag/multimodal/index.d.ts +44 -0
- package/dist/rag/multimodal/index.d.ts.map +1 -0
- package/dist/rag/multimodal/index.js +42 -0
- package/dist/rag/multimodal/index.js.map +1 -0
- package/dist/rag/multimodal/types.d.ts +276 -0
- package/dist/rag/multimodal/types.d.ts.map +1 -0
- package/dist/rag/multimodal/types.js +26 -0
- package/dist/rag/multimodal/types.js.map +1 -0
- package/dist/social-posting/SocialPostManager.d.ts +3 -3
- package/dist/social-posting/SocialPostManager.d.ts.map +1 -1
- package/dist/social-posting/SocialPostManager.js +3 -5
- package/dist/social-posting/SocialPostManager.js.map +1 -1
- package/dist/speech/FallbackProxy.d.ts +6 -6
- package/dist/speech/FallbackProxy.d.ts.map +1 -1
- package/dist/speech/FallbackProxy.js +3 -3
- package/dist/speech/FallbackProxy.js.map +1 -1
- package/dist/speech/SpeechProviderResolver.d.ts +8 -8
- package/dist/speech/SpeechProviderResolver.d.ts.map +1 -1
- package/dist/speech/SpeechProviderResolver.js +22 -11
- package/dist/speech/SpeechProviderResolver.js.map +1 -1
- package/dist/speech/SpeechRuntime.d.ts +1 -5
- package/dist/speech/SpeechRuntime.d.ts.map +1 -1
- package/dist/speech/SpeechRuntime.js +17 -9
- package/dist/speech/SpeechRuntime.js.map +1 -1
- package/dist/speech/providers/AssemblyAISTTProvider.d.ts +4 -4
- package/dist/speech/providers/AssemblyAISTTProvider.js +4 -4
- package/dist/speech/providers/AzureSpeechTTSProvider.d.ts +3 -3
- package/dist/speech/providers/AzureSpeechTTSProvider.js +2 -2
- package/dist/speech/providers/AzureSpeechTTSProvider.js.map +1 -1
- package/dist/speech/providers/BuiltInAdaptiveVadProvider.d.ts +9 -9
- package/dist/speech/providers/BuiltInAdaptiveVadProvider.d.ts.map +1 -1
- package/dist/speech/providers/BuiltInAdaptiveVadProvider.js +5 -5
- package/dist/speech/providers/BuiltInAdaptiveVadProvider.js.map +1 -1
- package/dist/speech/providers/DeepgramBatchSTTProvider.d.ts +2 -2
- package/dist/speech/providers/DeepgramBatchSTTProvider.js +2 -2
- package/dist/speech/providers/OpenAITextToSpeechProvider.d.ts +3 -3
- package/dist/speech/providers/OpenAITextToSpeechProvider.js +2 -2
- package/dist/speech/providers/OpenAIWhisperSpeechToTextProvider.d.ts +1 -1
- package/dist/speech/providers/OpenAIWhisperSpeechToTextProvider.d.ts.map +1 -1
- package/dist/speech/providers/OpenAIWhisperSpeechToTextProvider.js +1 -1
- package/dist/speech/providers/OpenAIWhisperSpeechToTextProvider.js.map +1 -1
- package/dist/voice/TelephonyStreamTransport.d.ts +6 -6
- package/dist/voice/TelephonyStreamTransport.d.ts.map +1 -1
- package/dist/voice/TelephonyStreamTransport.js +5 -5
- package/dist/voice/TelephonyStreamTransport.js.map +1 -1
- package/dist/voice-pipeline/AcousticEndpointDetector.d.ts +4 -4
- package/dist/voice-pipeline/AcousticEndpointDetector.d.ts.map +1 -1
- package/dist/voice-pipeline/AcousticEndpointDetector.js +4 -4
- package/dist/voice-pipeline/AcousticEndpointDetector.js.map +1 -1
- package/dist/voice-pipeline/HardCutBargeinHandler.d.ts +3 -3
- package/dist/voice-pipeline/HardCutBargeinHandler.js +3 -3
- package/dist/voice-pipeline/HeuristicEndpointDetector.d.ts +3 -3
- package/dist/voice-pipeline/HeuristicEndpointDetector.d.ts.map +1 -1
- package/dist/voice-pipeline/HeuristicEndpointDetector.js +3 -3
- package/dist/voice-pipeline/HeuristicEndpointDetector.js.map +1 -1
- package/dist/voice-pipeline/SoftFadeBargeinHandler.d.ts +5 -5
- package/dist/voice-pipeline/SoftFadeBargeinHandler.js +1 -1
- package/dist/voice-pipeline/VoiceInterruptError.d.ts +6 -6
- package/dist/voice-pipeline/VoiceInterruptError.d.ts.map +1 -1
- package/dist/voice-pipeline/VoiceInterruptError.js +4 -4
- package/dist/voice-pipeline/VoiceInterruptError.js.map +1 -1
- package/dist/voice-pipeline/VoicePipelineOrchestrator.d.ts +9 -9
- package/dist/voice-pipeline/VoicePipelineOrchestrator.d.ts.map +1 -1
- package/dist/voice-pipeline/VoicePipelineOrchestrator.js +8 -8
- package/dist/voice-pipeline/VoicePipelineOrchestrator.js.map +1 -1
- package/dist/voice-pipeline/WebRTCStreamTransport.d.ts +421 -0
- package/dist/voice-pipeline/WebRTCStreamTransport.d.ts.map +1 -0
- package/dist/voice-pipeline/WebRTCStreamTransport.js +573 -0
- package/dist/voice-pipeline/WebRTCStreamTransport.js.map +1 -0
- package/dist/voice-pipeline/WebSocketStreamTransport.d.ts +8 -8
- package/dist/voice-pipeline/WebSocketStreamTransport.js +5 -5
- package/dist/voice-pipeline/index.d.ts +1 -0
- package/dist/voice-pipeline/index.d.ts.map +1 -1
- package/dist/voice-pipeline/index.js +2 -0
- package/dist/voice-pipeline/index.js.map +1 -1
- package/dist/voice-pipeline/types.d.ts +43 -43
- package/dist/voice-pipeline/types.d.ts.map +1 -1
- package/package.json +19 -1
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file imageToBuffer.ts
|
|
3
|
+
* Shared utility for normalising heterogeneous image inputs into a `Buffer`.
|
|
4
|
+
*
|
|
5
|
+
* Image editing, upscaling, and variation APIs accept images in multiple
|
|
6
|
+
* formats (base64 data URLs, raw base64 strings, `Buffer` instances, local
|
|
7
|
+
* file paths, and remote HTTP/HTTPS URLs). This helper unifies them into
|
|
8
|
+
* a single `Buffer` so that downstream provider code never has to worry
|
|
9
|
+
* about the input shape.
|
|
10
|
+
*/
|
|
11
|
+
import * as fs from 'node:fs/promises';
|
|
12
|
+
/**
|
|
13
|
+
* Converts an image input from any of the supported formats into a `Buffer`.
|
|
14
|
+
*
|
|
15
|
+
* Supported input formats:
|
|
16
|
+
* - **`Buffer`** — returned as-is.
|
|
17
|
+
* - **Base64 data URL** — e.g. `data:image/png;base64,iVBOR...`. The base64
|
|
18
|
+
* payload is extracted and decoded.
|
|
19
|
+
* - **Raw base64 string** — a string that does not look like a URL or file
|
|
20
|
+
* path is assumed to be raw base64 data.
|
|
21
|
+
* - **`file://` URL** — resolved to a local filesystem path and read.
|
|
22
|
+
* - **HTTP/HTTPS URL** — fetched via `globalThis.fetch` and buffered.
|
|
23
|
+
* - **Local file path** — any other string is treated as an absolute or
|
|
24
|
+
* relative filesystem path and read with `fs.readFile`.
|
|
25
|
+
*
|
|
26
|
+
* @param input - The image in any supported format.
|
|
27
|
+
* @returns A `Buffer` containing the raw image bytes.
|
|
28
|
+
*
|
|
29
|
+
* @throws {TypeError} When `input` is neither a string nor a Buffer.
|
|
30
|
+
* @throws {Error} When a remote URL fetch fails or the file cannot be read.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* const buf1 = await imageToBuffer('data:image/png;base64,iVBOR...');
|
|
35
|
+
* const buf2 = await imageToBuffer(fs.readFileSync('photo.png'));
|
|
36
|
+
* const buf3 = await imageToBuffer('https://example.com/photo.png');
|
|
37
|
+
* const buf4 = await imageToBuffer('/absolute/path/to/image.jpg');
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export async function imageToBuffer(input) {
|
|
41
|
+
// Already a Buffer — nothing to do.
|
|
42
|
+
if (Buffer.isBuffer(input)) {
|
|
43
|
+
return input;
|
|
44
|
+
}
|
|
45
|
+
if (typeof input !== 'string') {
|
|
46
|
+
throw new TypeError('imageToBuffer: expected a string (base64, URL, or file path) or Buffer.');
|
|
47
|
+
}
|
|
48
|
+
const trimmed = input.trim();
|
|
49
|
+
// Base64 data URL (e.g. "data:image/png;base64,iVBOR...")
|
|
50
|
+
if (trimmed.startsWith('data:')) {
|
|
51
|
+
const commaIdx = trimmed.indexOf(',');
|
|
52
|
+
if (commaIdx === -1) {
|
|
53
|
+
throw new Error('imageToBuffer: malformed data URL — missing comma separator.');
|
|
54
|
+
}
|
|
55
|
+
// Everything after the comma is the base64 payload.
|
|
56
|
+
return Buffer.from(trimmed.slice(commaIdx + 1), 'base64');
|
|
57
|
+
}
|
|
58
|
+
// file:// URL — convert to local path and read.
|
|
59
|
+
if (trimmed.startsWith('file://')) {
|
|
60
|
+
const filePath = new URL(trimmed).pathname;
|
|
61
|
+
return fs.readFile(filePath);
|
|
62
|
+
}
|
|
63
|
+
// Remote HTTP(S) URL — fetch and buffer.
|
|
64
|
+
if (trimmed.startsWith('http://') || trimmed.startsWith('https://')) {
|
|
65
|
+
const response = await globalThis.fetch(trimmed);
|
|
66
|
+
if (!response.ok) {
|
|
67
|
+
throw new Error(`imageToBuffer: failed to fetch image from ${trimmed} (${response.status} ${response.statusText}).`);
|
|
68
|
+
}
|
|
69
|
+
return Buffer.from(await response.arrayBuffer());
|
|
70
|
+
}
|
|
71
|
+
// Heuristic: if the string contains path separators or a file extension,
|
|
72
|
+
// treat it as a filesystem path. Otherwise assume raw base64.
|
|
73
|
+
const looksLikePath = trimmed.includes('/') || trimmed.includes('\\') || /\.\w{2,5}$/.test(trimmed);
|
|
74
|
+
if (looksLikePath) {
|
|
75
|
+
return fs.readFile(trimmed);
|
|
76
|
+
}
|
|
77
|
+
// Fallback: raw base64 string (no data URL prefix).
|
|
78
|
+
return Buffer.from(trimmed, 'base64');
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Converts a Node.js `Buffer` into a DOM-compatible `BlobPart`.
|
|
82
|
+
*
|
|
83
|
+
* Recent TypeScript DOM typings require `BlobPart` byte views to be backed by a
|
|
84
|
+
* concrete `ArrayBuffer`, while `Buffer` is typed as `ArrayBufferLike`. Returning
|
|
85
|
+
* a plain `Uint8Array` avoids that mismatch for multipart image uploads.
|
|
86
|
+
*
|
|
87
|
+
* @param input - Raw image bytes stored in a Node.js `Buffer`.
|
|
88
|
+
* @returns An `ArrayBuffer` safe to pass into `new Blob([...])`.
|
|
89
|
+
*/
|
|
90
|
+
export function bufferToBlobPart(input) {
|
|
91
|
+
const bytes = new ArrayBuffer(input.byteLength);
|
|
92
|
+
new Uint8Array(bytes).set(input);
|
|
93
|
+
return bytes;
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=imageToBuffer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"imageToBuffer.js","sourceRoot":"","sources":["../../../src/core/images/imageToBuffer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEvC;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,KAAsB;IACxD,oCAAoC;IACpC,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QAC3B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,MAAM,IAAI,SAAS,CAAC,yEAAyE,CAAC,CAAC;IACjG,CAAC;IAED,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAE7B,0DAA0D;IAC1D,IAAI,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QAChC,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QACtC,IAAI,QAAQ,KAAK,CAAC,CAAC,EAAE,CAAC;YACpB,MAAM,IAAI,KAAK,CAAC,8DAA8D,CAAC,CAAC;QAClF,CAAC;QACD,oDAAoD;QACpD,OAAO,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,GAAG,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;IAC5D,CAAC;IAED,gDAAgD;IAChD,IAAI,OAAO,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;QAClC,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC;QAC3C,OAAO,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAC/B,CAAC;IAED,yCAAyC;IACzC,IAAI,OAAO,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;QACpE,MAAM,QAAQ,GAAG,MAAM,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACjD,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CACb,6CAA6C,OAAO,KAAK,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,UAAU,IAAI,CACpG,CAAC;QACJ,CAAC;QACD,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,QAAQ,CAAC,WAAW,EAAE,CAAC,CAAC;IACnD,CAAC;IAED,yEAAyE;IACzE,+DAA+D;IAC/D,MAAM,aAAa,GACjB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAChF,IAAI,aAAa,EAAE,CAAC;QAClB,OAAO,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAC9B,CAAC;IAED,oDAAoD;IACpD,OAAO,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;AACxC,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAa;IAC5C,MAAM,KAAK,GAAG,IAAI,WAAW,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IAChD,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACjC,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import type { IImageProvider } from './IImageProvider.js';
|
|
2
2
|
export * from './IImageProvider.js';
|
|
3
|
+
export * from './imageToBuffer.js';
|
|
4
|
+
export * from './ImageOperationError.js';
|
|
3
5
|
export * from './providers/OpenAIImageProvider.js';
|
|
4
6
|
export * from './providers/OpenRouterImageProvider.js';
|
|
5
7
|
export * from './providers/ReplicateImageProvider.js';
|
|
6
8
|
export * from './providers/StabilityImageProvider.js';
|
|
7
9
|
export * from './providers/StableDiffusionLocalProvider.js';
|
|
10
|
+
export * from './providers/FluxImageProvider.js';
|
|
11
|
+
export * from './providers/FalImageProvider.js';
|
|
8
12
|
export type ImageProviderFactory = () => IImageProvider;
|
|
9
13
|
export declare function registerImageProviderFactory(providerId: string, factory: ImageProviderFactory): void;
|
|
10
14
|
export declare function unregisterImageProviderFactory(providerId: string): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/images/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/images/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAS1D,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC;AACzC,cAAc,oCAAoC,CAAC;AACnD,cAAc,wCAAwC,CAAC;AACvD,cAAc,uCAAuC,CAAC;AACtD,cAAc,uCAAuC,CAAC;AACtD,cAAc,6CAA6C,CAAC;AAC5D,cAAc,kCAAkC,CAAC;AACjD,cAAc,iCAAiC,CAAC;AAEhD,MAAM,MAAM,oBAAoB,GAAG,MAAM,cAAc,CAAC;AAYxD,wBAAgB,4BAA4B,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,oBAAoB,GAAG,IAAI,CAEpG;AAED,wBAAgB,8BAA8B,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAEvE;AAED,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAEnE;AAED,wBAAgB,0BAA0B,IAAI,MAAM,EAAE,CAErD;AAED,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,MAAM,GAAG,cAAc,CAMtE"}
|
|
@@ -3,18 +3,26 @@ import { OpenRouterImageProvider } from './providers/OpenRouterImageProvider.js'
|
|
|
3
3
|
import { ReplicateImageProvider } from './providers/ReplicateImageProvider.js';
|
|
4
4
|
import { StabilityImageProvider } from './providers/StabilityImageProvider.js';
|
|
5
5
|
import { StableDiffusionLocalProvider } from './providers/StableDiffusionLocalProvider.js';
|
|
6
|
+
import { FluxImageProvider } from './providers/FluxImageProvider.js';
|
|
7
|
+
import { FalImageProvider } from './providers/FalImageProvider.js';
|
|
6
8
|
export * from './IImageProvider.js';
|
|
9
|
+
export * from './imageToBuffer.js';
|
|
10
|
+
export * from './ImageOperationError.js';
|
|
7
11
|
export * from './providers/OpenAIImageProvider.js';
|
|
8
12
|
export * from './providers/OpenRouterImageProvider.js';
|
|
9
13
|
export * from './providers/ReplicateImageProvider.js';
|
|
10
14
|
export * from './providers/StabilityImageProvider.js';
|
|
11
15
|
export * from './providers/StableDiffusionLocalProvider.js';
|
|
16
|
+
export * from './providers/FluxImageProvider.js';
|
|
17
|
+
export * from './providers/FalImageProvider.js';
|
|
12
18
|
const imageProviderFactories = new Map([
|
|
13
19
|
['openai', () => new OpenAIImageProvider()],
|
|
14
20
|
['openrouter', () => new OpenRouterImageProvider()],
|
|
15
21
|
['stability', () => new StabilityImageProvider()],
|
|
16
22
|
['replicate', () => new ReplicateImageProvider()],
|
|
17
23
|
['stable-diffusion-local', () => new StableDiffusionLocalProvider()],
|
|
24
|
+
['bfl', () => new FluxImageProvider()],
|
|
25
|
+
['fal', () => new FalImageProvider()],
|
|
18
26
|
]);
|
|
19
27
|
export function registerImageProviderFactory(providerId, factory) {
|
|
20
28
|
imageProviderFactories.set(providerId.toLowerCase(), factory);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/images/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,EAAE,uBAAuB,EAAE,MAAM,wCAAwC,CAAC;AACjF,OAAO,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AAC/E,OAAO,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AAC/E,OAAO,EAAE,4BAA4B,EAAE,MAAM,6CAA6C,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/images/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,EAAE,uBAAuB,EAAE,MAAM,wCAAwC,CAAC;AACjF,OAAO,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AAC/E,OAAO,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AAC/E,OAAO,EAAE,4BAA4B,EAAE,MAAM,6CAA6C,CAAC;AAC3F,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAEnE,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC;AACzC,cAAc,oCAAoC,CAAC;AACnD,cAAc,wCAAwC,CAAC;AACvD,cAAc,uCAAuC,CAAC;AACtD,cAAc,uCAAuC,CAAC;AACtD,cAAc,6CAA6C,CAAC;AAC5D,cAAc,kCAAkC,CAAC;AACjD,cAAc,iCAAiC,CAAC;AAIhD,MAAM,sBAAsB,GAAG,IAAI,GAAG,CAA+B;IACnE,CAAC,QAAQ,EAAE,GAAG,EAAE,CAAC,IAAI,mBAAmB,EAAE,CAAC;IAC3C,CAAC,YAAY,EAAE,GAAG,EAAE,CAAC,IAAI,uBAAuB,EAAE,CAAC;IACnD,CAAC,WAAW,EAAE,GAAG,EAAE,CAAC,IAAI,sBAAsB,EAAE,CAAC;IACjD,CAAC,WAAW,EAAE,GAAG,EAAE,CAAC,IAAI,sBAAsB,EAAE,CAAC;IACjD,CAAC,wBAAwB,EAAE,GAAG,EAAE,CAAC,IAAI,4BAA4B,EAAE,CAAC;IACpE,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,IAAI,iBAAiB,EAAE,CAAC;IACtC,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,IAAI,gBAAgB,EAAE,CAAC;CACtC,CAAC,CAAC;AAEH,MAAM,UAAU,4BAA4B,CAAC,UAAkB,EAAE,OAA6B;IAC5F,sBAAsB,CAAC,GAAG,CAAC,UAAU,CAAC,WAAW,EAAE,EAAE,OAAO,CAAC,CAAC;AAChE,CAAC;AAED,MAAM,UAAU,8BAA8B,CAAC,UAAkB;IAC/D,sBAAsB,CAAC,MAAM,CAAC,UAAU,CAAC,WAAW,EAAE,CAAC,CAAC;AAC1D,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,UAAkB;IACxD,OAAO,sBAAsB,CAAC,GAAG,CAAC,UAAU,CAAC,WAAW,EAAE,CAAC,CAAC;AAC9D,CAAC;AAED,MAAM,UAAU,0BAA0B;IACxC,OAAO,KAAK,CAAC,IAAI,CAAC,sBAAsB,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;AAC1D,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,UAAkB;IACpD,MAAM,OAAO,GAAG,sBAAsB,CAAC,GAAG,CAAC,UAAU,CAAC,WAAW,EAAE,CAAC,CAAC;IACrE,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,mDAAmD,UAAU,IAAI,CAAC,CAAC;IACrF,CAAC;IACD,OAAO,OAAO,EAAE,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module core/images/providers/FalImageProvider
|
|
3
|
+
*
|
|
4
|
+
* Image generation provider for the Fal.ai platform, a popular serverless
|
|
5
|
+
* GPU host that offers fast inference for Flux and other diffusion models.
|
|
6
|
+
*
|
|
7
|
+
* ## Supported models
|
|
8
|
+
*
|
|
9
|
+
* | Model ID | Description |
|
|
10
|
+
* |-----------------------------|----------------------------------------------|
|
|
11
|
+
* | `fal-ai/flux/dev` | Flux Dev — fast iteration, open weights |
|
|
12
|
+
* | `fal-ai/flux-pro` | Flux Pro — highest quality |
|
|
13
|
+
* | `fal-ai/flux/schnell` | Flux Schnell — optimised for speed |
|
|
14
|
+
*
|
|
15
|
+
* ## API flow (queue-based)
|
|
16
|
+
*
|
|
17
|
+
* 1. **Submit** — `POST https://queue.fal.run/{model}` with prompt/params.
|
|
18
|
+
* Returns `{ request_id }` immediately.
|
|
19
|
+
* 2. **Poll** — `GET https://queue.fal.run/{model}/requests/{request_id}/status`
|
|
20
|
+
* until `status === 'COMPLETED'` and `images` array is populated.
|
|
21
|
+
*
|
|
22
|
+
* ## Authentication
|
|
23
|
+
*
|
|
24
|
+
* Requires a `FAL_API_KEY` environment variable. The key is sent as
|
|
25
|
+
* `Authorization: Key ${FAL_API_KEY}`.
|
|
26
|
+
*
|
|
27
|
+
* @see {@link IImageProvider} for the provider interface contract.
|
|
28
|
+
* @see {@link FluxImageProvider} for direct BFL API access.
|
|
29
|
+
* @see {@link ReplicateImageProvider} for Flux via Replicate.
|
|
30
|
+
*/
|
|
31
|
+
import { type IImageProvider, type ImageGenerationRequest, type ImageGenerationResult, type ImageModelInfo } from '../IImageProvider.js';
|
|
32
|
+
/**
|
|
33
|
+
* Configuration for the Fal.ai image provider.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* const config: FalImageProviderConfig = {
|
|
38
|
+
* apiKey: process.env.FAL_API_KEY!,
|
|
39
|
+
* defaultModelId: 'fal-ai/flux/dev',
|
|
40
|
+
* };
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export interface FalImageProviderConfig {
|
|
44
|
+
/**
|
|
45
|
+
* Fal.ai API key. Sent as `Authorization: Key ${apiKey}`.
|
|
46
|
+
* Obtain from https://fal.ai/dashboard/keys
|
|
47
|
+
*/
|
|
48
|
+
apiKey: string;
|
|
49
|
+
/**
|
|
50
|
+
* Base URL for the Fal.ai queue API. Override for testing or proxy setups.
|
|
51
|
+
* @default 'https://queue.fal.run'
|
|
52
|
+
*/
|
|
53
|
+
baseURL?: string;
|
|
54
|
+
/**
|
|
55
|
+
* Default model to use when the request doesn't specify one.
|
|
56
|
+
* @default 'fal-ai/flux/dev'
|
|
57
|
+
*/
|
|
58
|
+
defaultModelId?: string;
|
|
59
|
+
/**
|
|
60
|
+
* Milliseconds between status polls while waiting for generation.
|
|
61
|
+
* @default 1000
|
|
62
|
+
*/
|
|
63
|
+
pollIntervalMs?: number;
|
|
64
|
+
/**
|
|
65
|
+
* Maximum milliseconds to wait for generation before timing out.
|
|
66
|
+
* @default 120000
|
|
67
|
+
*/
|
|
68
|
+
timeoutMs?: number;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Provider-specific options for Fal.ai image generation.
|
|
72
|
+
*
|
|
73
|
+
* Pass via `request.providerOptions.fal` when calling
|
|
74
|
+
* {@link FalImageProvider.generateImage}.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```typescript
|
|
78
|
+
* const result = await provider.generateImage({
|
|
79
|
+
* modelId: 'fal-ai/flux/dev',
|
|
80
|
+
* prompt: 'A sunset over mountains',
|
|
81
|
+
* providerOptions: {
|
|
82
|
+
* fal: { num_images: 2, seed: 42 },
|
|
83
|
+
* },
|
|
84
|
+
* });
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
export interface FalImageProviderOptions {
|
|
88
|
+
/** Number of images to generate. Default: 1. */
|
|
89
|
+
num_images?: number;
|
|
90
|
+
/** Image size string (e.g. 'landscape_16_9', 'square_hd', 'portrait_4_3'). */
|
|
91
|
+
image_size?: string;
|
|
92
|
+
/** Random seed for reproducible generation. */
|
|
93
|
+
seed?: number;
|
|
94
|
+
/** Number of inference steps. */
|
|
95
|
+
num_inference_steps?: number;
|
|
96
|
+
/** Guidance scale for classifier-free guidance. */
|
|
97
|
+
guidance_scale?: number;
|
|
98
|
+
/** Whether to enable the safety checker. Default: true. */
|
|
99
|
+
enable_safety_checker?: boolean;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Image generation provider connecting to the Fal.ai serverless platform.
|
|
103
|
+
*
|
|
104
|
+
* Implements the queue-based submit-then-poll pattern: a generation request
|
|
105
|
+
* returns a request ID immediately, and the provider polls the status
|
|
106
|
+
* endpoint until completion or timeout.
|
|
107
|
+
*
|
|
108
|
+
* @implements {IImageProvider}
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```typescript
|
|
112
|
+
* const provider = new FalImageProvider();
|
|
113
|
+
* await provider.initialize({ apiKey: process.env.FAL_API_KEY! });
|
|
114
|
+
*
|
|
115
|
+
* const result = await provider.generateImage({
|
|
116
|
+
* modelId: 'fal-ai/flux/dev',
|
|
117
|
+
* prompt: 'A photorealistic astronaut riding a horse on Mars',
|
|
118
|
+
* });
|
|
119
|
+
* console.log(result.images[0].url);
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
export declare class FalImageProvider implements IImageProvider {
|
|
123
|
+
/** @inheritdoc */
|
|
124
|
+
readonly providerId = "fal";
|
|
125
|
+
/** @inheritdoc */
|
|
126
|
+
isInitialized: boolean;
|
|
127
|
+
/** @inheritdoc */
|
|
128
|
+
defaultModelId?: string;
|
|
129
|
+
/** Internal resolved configuration. */
|
|
130
|
+
private _config;
|
|
131
|
+
/**
|
|
132
|
+
* Initialize the provider with API credentials and optional configuration.
|
|
133
|
+
*
|
|
134
|
+
* @param config - Configuration object. Must include `apiKey`.
|
|
135
|
+
* @throws {Error} If `apiKey` is missing or empty.
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```typescript
|
|
139
|
+
* await provider.initialize({ apiKey: 'fal_xxx' });
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
initialize(config: Record<string, unknown>): Promise<void>;
|
|
143
|
+
/**
|
|
144
|
+
* Generate an image using the Fal.ai queue API.
|
|
145
|
+
*
|
|
146
|
+
* Submits the generation task to the queue, then polls the status
|
|
147
|
+
* endpoint until the result is ready or the timeout is reached.
|
|
148
|
+
*
|
|
149
|
+
* @param request - Image generation request with prompt and optional params.
|
|
150
|
+
* @returns The generated image result with URL(s).
|
|
151
|
+
*
|
|
152
|
+
* @throws {Error} If the provider is not initialized.
|
|
153
|
+
* @throws {Error} If the API returns an error or times out.
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```typescript
|
|
157
|
+
* const result = await provider.generateImage({
|
|
158
|
+
* modelId: 'fal-ai/flux/dev',
|
|
159
|
+
* prompt: 'A serene Japanese garden in autumn',
|
|
160
|
+
* n: 2,
|
|
161
|
+
* });
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
generateImage(request: ImageGenerationRequest): Promise<ImageGenerationResult>;
|
|
165
|
+
/**
|
|
166
|
+
* List available Flux models on the Fal.ai platform.
|
|
167
|
+
*
|
|
168
|
+
* @returns Static list of known Fal.ai model identifiers.
|
|
169
|
+
*/
|
|
170
|
+
listAvailableModels(): Promise<ImageModelInfo[]>;
|
|
171
|
+
/**
|
|
172
|
+
* Submit a generation task to the Fal.ai queue.
|
|
173
|
+
*
|
|
174
|
+
* @param model - Full model path (e.g. 'fal-ai/flux/dev').
|
|
175
|
+
* @param body - Request body with prompt and generation params.
|
|
176
|
+
* @returns The request_id for status polling.
|
|
177
|
+
*
|
|
178
|
+
* @throws {Error} If the submission request fails.
|
|
179
|
+
* @internal
|
|
180
|
+
*/
|
|
181
|
+
private _submitTask;
|
|
182
|
+
/**
|
|
183
|
+
* Poll the Fal.ai status endpoint until the task completes or times out.
|
|
184
|
+
*
|
|
185
|
+
* @param model - Full model path.
|
|
186
|
+
* @param requestId - The request ID from submission.
|
|
187
|
+
*
|
|
188
|
+
* @throws {Error} If the generation fails or times out.
|
|
189
|
+
* @internal
|
|
190
|
+
*/
|
|
191
|
+
private _pollStatus;
|
|
192
|
+
/**
|
|
193
|
+
* Fetch the completed generation result from the Fal.ai result endpoint.
|
|
194
|
+
*
|
|
195
|
+
* Called after polling confirms the task is COMPLETED. The result
|
|
196
|
+
* endpoint is separate from the status endpoint because Fal.ai
|
|
197
|
+
* returns the full payload (including image URLs) only here.
|
|
198
|
+
*
|
|
199
|
+
* @param model - Full model path.
|
|
200
|
+
* @param requestId - The request ID from submission.
|
|
201
|
+
* @returns The generation result with image URLs.
|
|
202
|
+
*
|
|
203
|
+
* @throws {Error} If the result fetch fails.
|
|
204
|
+
* @internal
|
|
205
|
+
*/
|
|
206
|
+
private _fetchResult;
|
|
207
|
+
}
|
|
208
|
+
//# sourceMappingURL=FalImageProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FalImageProvider.d.ts","sourceRoot":"","sources":["../../../../src/core/images/providers/FalImageProvider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,KAAK,cAAc,EAGpB,MAAM,sBAAsB,CAAC;AAM9B;;;;;;;;;;GAUG;AACH,MAAM,WAAW,sBAAsB;IACrC;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAoDD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,WAAW,uBAAuB;IACtC,gDAAgD;IAChD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,8EAA8E;IAC9E,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,+CAA+C;IAC/C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,iCAAiC;IACjC,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,mDAAmD;IACnD,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,2DAA2D;IAC3D,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACjC;AAqBD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,gBAAiB,YAAW,cAAc;IACrD,kBAAkB;IAClB,SAAgB,UAAU,SAAS;IAEnC,kBAAkB;IACX,aAAa,UAAS;IAE7B,kBAAkB;IACX,cAAc,CAAC,EAAE,MAAM,CAAC;IAE/B,uCAAuC;IACvC,OAAO,CAAC,OAAO,CAA0H;IAEzI;;;;;;;;;;OAUG;IACG,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IA8BhE;;;;;;;;;;;;;;;;;;;;OAoBG;IACG,aAAa,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAmEpF;;;;OAIG;IACG,mBAAmB,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;IAYtD;;;;;;;;;OASG;YACW,WAAW;IAyBzB;;;;;;;;OAQG;YACW,WAAW;IAkCzB;;;;;;;;;;;;;OAaG;YACW,YAAY;CAgB3B"}
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module core/images/providers/FalImageProvider
|
|
3
|
+
*
|
|
4
|
+
* Image generation provider for the Fal.ai platform, a popular serverless
|
|
5
|
+
* GPU host that offers fast inference for Flux and other diffusion models.
|
|
6
|
+
*
|
|
7
|
+
* ## Supported models
|
|
8
|
+
*
|
|
9
|
+
* | Model ID | Description |
|
|
10
|
+
* |-----------------------------|----------------------------------------------|
|
|
11
|
+
* | `fal-ai/flux/dev` | Flux Dev — fast iteration, open weights |
|
|
12
|
+
* | `fal-ai/flux-pro` | Flux Pro — highest quality |
|
|
13
|
+
* | `fal-ai/flux/schnell` | Flux Schnell — optimised for speed |
|
|
14
|
+
*
|
|
15
|
+
* ## API flow (queue-based)
|
|
16
|
+
*
|
|
17
|
+
* 1. **Submit** — `POST https://queue.fal.run/{model}` with prompt/params.
|
|
18
|
+
* Returns `{ request_id }` immediately.
|
|
19
|
+
* 2. **Poll** — `GET https://queue.fal.run/{model}/requests/{request_id}/status`
|
|
20
|
+
* until `status === 'COMPLETED'` and `images` array is populated.
|
|
21
|
+
*
|
|
22
|
+
* ## Authentication
|
|
23
|
+
*
|
|
24
|
+
* Requires a `FAL_API_KEY` environment variable. The key is sent as
|
|
25
|
+
* `Authorization: Key ${FAL_API_KEY}`.
|
|
26
|
+
*
|
|
27
|
+
* @see {@link IImageProvider} for the provider interface contract.
|
|
28
|
+
* @see {@link FluxImageProvider} for direct BFL API access.
|
|
29
|
+
* @see {@link ReplicateImageProvider} for Flux via Replicate.
|
|
30
|
+
*/
|
|
31
|
+
import { parseImageSize, } from '../IImageProvider.js';
|
|
32
|
+
// ---------------------------------------------------------------------------
|
|
33
|
+
// Helpers
|
|
34
|
+
// ---------------------------------------------------------------------------
|
|
35
|
+
/**
|
|
36
|
+
* Sleep for the specified number of milliseconds.
|
|
37
|
+
* Used between poll requests to avoid rate-limiting.
|
|
38
|
+
* @param ms - Duration in milliseconds.
|
|
39
|
+
* @returns Resolves after the delay.
|
|
40
|
+
* @internal
|
|
41
|
+
*/
|
|
42
|
+
function sleep(ms) {
|
|
43
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
44
|
+
}
|
|
45
|
+
// ---------------------------------------------------------------------------
|
|
46
|
+
// Implementation
|
|
47
|
+
// ---------------------------------------------------------------------------
|
|
48
|
+
/**
|
|
49
|
+
* Image generation provider connecting to the Fal.ai serverless platform.
|
|
50
|
+
*
|
|
51
|
+
* Implements the queue-based submit-then-poll pattern: a generation request
|
|
52
|
+
* returns a request ID immediately, and the provider polls the status
|
|
53
|
+
* endpoint until completion or timeout.
|
|
54
|
+
*
|
|
55
|
+
* @implements {IImageProvider}
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* const provider = new FalImageProvider();
|
|
60
|
+
* await provider.initialize({ apiKey: process.env.FAL_API_KEY! });
|
|
61
|
+
*
|
|
62
|
+
* const result = await provider.generateImage({
|
|
63
|
+
* modelId: 'fal-ai/flux/dev',
|
|
64
|
+
* prompt: 'A photorealistic astronaut riding a horse on Mars',
|
|
65
|
+
* });
|
|
66
|
+
* console.log(result.images[0].url);
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export class FalImageProvider {
|
|
70
|
+
constructor() {
|
|
71
|
+
/** @inheritdoc */
|
|
72
|
+
this.providerId = 'fal';
|
|
73
|
+
/** @inheritdoc */
|
|
74
|
+
this.isInitialized = false;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Initialize the provider with API credentials and optional configuration.
|
|
78
|
+
*
|
|
79
|
+
* @param config - Configuration object. Must include `apiKey`.
|
|
80
|
+
* @throws {Error} If `apiKey` is missing or empty.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* await provider.initialize({ apiKey: 'fal_xxx' });
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
async initialize(config) {
|
|
88
|
+
const apiKey = typeof config.apiKey === 'string' ? config.apiKey.trim() : '';
|
|
89
|
+
if (!apiKey) {
|
|
90
|
+
throw new Error('Fal.ai image provider requires apiKey (FAL_API_KEY).');
|
|
91
|
+
}
|
|
92
|
+
this._config = {
|
|
93
|
+
apiKey,
|
|
94
|
+
baseURL: typeof config.baseURL === 'string' && config.baseURL.trim()
|
|
95
|
+
? config.baseURL.trim()
|
|
96
|
+
: 'https://queue.fal.run',
|
|
97
|
+
defaultModelId: typeof config.defaultModelId === 'string' && config.defaultModelId.trim()
|
|
98
|
+
? config.defaultModelId.trim()
|
|
99
|
+
: 'fal-ai/flux/dev',
|
|
100
|
+
pollIntervalMs: typeof config.pollIntervalMs === 'number' && config.pollIntervalMs > 0
|
|
101
|
+
? config.pollIntervalMs
|
|
102
|
+
: 1000,
|
|
103
|
+
timeoutMs: typeof config.timeoutMs === 'number' && config.timeoutMs > 0
|
|
104
|
+
? config.timeoutMs
|
|
105
|
+
: 120000,
|
|
106
|
+
};
|
|
107
|
+
this.defaultModelId = this._config.defaultModelId;
|
|
108
|
+
this.isInitialized = true;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Generate an image using the Fal.ai queue API.
|
|
112
|
+
*
|
|
113
|
+
* Submits the generation task to the queue, then polls the status
|
|
114
|
+
* endpoint until the result is ready or the timeout is reached.
|
|
115
|
+
*
|
|
116
|
+
* @param request - Image generation request with prompt and optional params.
|
|
117
|
+
* @returns The generated image result with URL(s).
|
|
118
|
+
*
|
|
119
|
+
* @throws {Error} If the provider is not initialized.
|
|
120
|
+
* @throws {Error} If the API returns an error or times out.
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```typescript
|
|
124
|
+
* const result = await provider.generateImage({
|
|
125
|
+
* modelId: 'fal-ai/flux/dev',
|
|
126
|
+
* prompt: 'A serene Japanese garden in autumn',
|
|
127
|
+
* n: 2,
|
|
128
|
+
* });
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
async generateImage(request) {
|
|
132
|
+
if (!this.isInitialized) {
|
|
133
|
+
throw new Error('Fal.ai image provider is not initialized. Call initialize() first.');
|
|
134
|
+
}
|
|
135
|
+
const model = request.modelId || this.defaultModelId || 'fal-ai/flux/dev';
|
|
136
|
+
// Extract Fal-specific options from the provider options bag.
|
|
137
|
+
const providerOpts = request.providerOptions?.fal;
|
|
138
|
+
// Build the request body matching Fal.ai's API schema.
|
|
139
|
+
const body = {
|
|
140
|
+
prompt: request.prompt,
|
|
141
|
+
};
|
|
142
|
+
// Map standard request fields to Fal.ai parameters.
|
|
143
|
+
// Fal.ai uses `image_size` which can be a named preset or dimensions.
|
|
144
|
+
const { width, height } = parseImageSize(request.size);
|
|
145
|
+
if (providerOpts?.image_size) {
|
|
146
|
+
body.image_size = providerOpts.image_size;
|
|
147
|
+
}
|
|
148
|
+
else if (width && height) {
|
|
149
|
+
// Fal.ai accepts object-style dimensions for some models
|
|
150
|
+
body.image_size = { width, height };
|
|
151
|
+
}
|
|
152
|
+
if (request.n)
|
|
153
|
+
body.num_images = request.n;
|
|
154
|
+
if (providerOpts?.num_images !== undefined)
|
|
155
|
+
body.num_images = providerOpts.num_images;
|
|
156
|
+
if (request.seed !== undefined)
|
|
157
|
+
body.seed = request.seed;
|
|
158
|
+
if (providerOpts?.seed !== undefined)
|
|
159
|
+
body.seed = providerOpts.seed;
|
|
160
|
+
if (providerOpts?.num_inference_steps !== undefined)
|
|
161
|
+
body.num_inference_steps = providerOpts.num_inference_steps;
|
|
162
|
+
if (providerOpts?.guidance_scale !== undefined)
|
|
163
|
+
body.guidance_scale = providerOpts.guidance_scale;
|
|
164
|
+
if (providerOpts?.enable_safety_checker !== undefined)
|
|
165
|
+
body.enable_safety_checker = providerOpts.enable_safety_checker;
|
|
166
|
+
// Step 1: Submit to the queue
|
|
167
|
+
const requestId = await this._submitTask(model, body);
|
|
168
|
+
// Step 2: Poll until complete
|
|
169
|
+
await this._pollStatus(model, requestId);
|
|
170
|
+
// Step 3: Fetch the result
|
|
171
|
+
const result = await this._fetchResult(model, requestId);
|
|
172
|
+
if (!result.images || result.images.length === 0) {
|
|
173
|
+
throw new Error('Fal.ai generation completed but returned no images.');
|
|
174
|
+
}
|
|
175
|
+
const images = result.images.map((img) => ({
|
|
176
|
+
url: img.url,
|
|
177
|
+
mimeType: img.content_type,
|
|
178
|
+
providerMetadata: {
|
|
179
|
+
width: img.width,
|
|
180
|
+
height: img.height,
|
|
181
|
+
seed: result.seed,
|
|
182
|
+
},
|
|
183
|
+
}));
|
|
184
|
+
return {
|
|
185
|
+
created: Math.floor(Date.now() / 1000),
|
|
186
|
+
modelId: model,
|
|
187
|
+
providerId: this.providerId,
|
|
188
|
+
images,
|
|
189
|
+
usage: {
|
|
190
|
+
totalImages: images.length,
|
|
191
|
+
},
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* List available Flux models on the Fal.ai platform.
|
|
196
|
+
*
|
|
197
|
+
* @returns Static list of known Fal.ai model identifiers.
|
|
198
|
+
*/
|
|
199
|
+
async listAvailableModels() {
|
|
200
|
+
return [
|
|
201
|
+
{ providerId: this.providerId, modelId: 'fal-ai/flux/dev', displayName: 'Flux Dev (Fal.ai)' },
|
|
202
|
+
{ providerId: this.providerId, modelId: 'fal-ai/flux-pro', displayName: 'Flux Pro (Fal.ai)' },
|
|
203
|
+
{ providerId: this.providerId, modelId: 'fal-ai/flux/schnell', displayName: 'Flux Schnell (Fal.ai)' },
|
|
204
|
+
];
|
|
205
|
+
}
|
|
206
|
+
// -------------------------------------------------------------------------
|
|
207
|
+
// Private helpers
|
|
208
|
+
// -------------------------------------------------------------------------
|
|
209
|
+
/**
|
|
210
|
+
* Submit a generation task to the Fal.ai queue.
|
|
211
|
+
*
|
|
212
|
+
* @param model - Full model path (e.g. 'fal-ai/flux/dev').
|
|
213
|
+
* @param body - Request body with prompt and generation params.
|
|
214
|
+
* @returns The request_id for status polling.
|
|
215
|
+
*
|
|
216
|
+
* @throws {Error} If the submission request fails.
|
|
217
|
+
* @internal
|
|
218
|
+
*/
|
|
219
|
+
async _submitTask(model, body) {
|
|
220
|
+
const url = `${this._config.baseURL}/${model}`;
|
|
221
|
+
const response = await fetch(url, {
|
|
222
|
+
method: 'POST',
|
|
223
|
+
headers: {
|
|
224
|
+
Authorization: `Key ${this._config.apiKey}`,
|
|
225
|
+
'Content-Type': 'application/json',
|
|
226
|
+
},
|
|
227
|
+
body: JSON.stringify(body),
|
|
228
|
+
});
|
|
229
|
+
if (!response.ok) {
|
|
230
|
+
const errorText = await response.text();
|
|
231
|
+
throw new Error(`Fal.ai image generation submission failed (${response.status}): ${errorText}`);
|
|
232
|
+
}
|
|
233
|
+
const data = (await response.json());
|
|
234
|
+
if (!data.request_id) {
|
|
235
|
+
throw new Error('Fal.ai submission response missing request_id.');
|
|
236
|
+
}
|
|
237
|
+
return data.request_id;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Poll the Fal.ai status endpoint until the task completes or times out.
|
|
241
|
+
*
|
|
242
|
+
* @param model - Full model path.
|
|
243
|
+
* @param requestId - The request ID from submission.
|
|
244
|
+
*
|
|
245
|
+
* @throws {Error} If the generation fails or times out.
|
|
246
|
+
* @internal
|
|
247
|
+
*/
|
|
248
|
+
async _pollStatus(model, requestId) {
|
|
249
|
+
const startedAt = Date.now();
|
|
250
|
+
while (Date.now() - startedAt < this._config.timeoutMs) {
|
|
251
|
+
const url = `${this._config.baseURL}/${model}/requests/${requestId}/status`;
|
|
252
|
+
const response = await fetch(url, {
|
|
253
|
+
headers: {
|
|
254
|
+
Authorization: `Key ${this._config.apiKey}`,
|
|
255
|
+
},
|
|
256
|
+
});
|
|
257
|
+
if (!response.ok) {
|
|
258
|
+
const errorText = await response.text();
|
|
259
|
+
throw new Error(`Fal.ai status polling failed (${response.status}): ${errorText}`);
|
|
260
|
+
}
|
|
261
|
+
const data = (await response.json());
|
|
262
|
+
if (data.status === 'COMPLETED') {
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
if (data.status === 'FAILED') {
|
|
266
|
+
throw new Error(`Fal.ai image generation failed for request ${requestId}.`);
|
|
267
|
+
}
|
|
268
|
+
// 'IN_QUEUE' or 'IN_PROGRESS' — wait before next poll
|
|
269
|
+
await sleep(this._config.pollIntervalMs);
|
|
270
|
+
}
|
|
271
|
+
throw new Error(`Fal.ai image generation timed out after ${this._config.timeoutMs}ms for request ${requestId}.`);
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Fetch the completed generation result from the Fal.ai result endpoint.
|
|
275
|
+
*
|
|
276
|
+
* Called after polling confirms the task is COMPLETED. The result
|
|
277
|
+
* endpoint is separate from the status endpoint because Fal.ai
|
|
278
|
+
* returns the full payload (including image URLs) only here.
|
|
279
|
+
*
|
|
280
|
+
* @param model - Full model path.
|
|
281
|
+
* @param requestId - The request ID from submission.
|
|
282
|
+
* @returns The generation result with image URLs.
|
|
283
|
+
*
|
|
284
|
+
* @throws {Error} If the result fetch fails.
|
|
285
|
+
* @internal
|
|
286
|
+
*/
|
|
287
|
+
async _fetchResult(model, requestId) {
|
|
288
|
+
const url = `${this._config.baseURL}/${model}/requests/${requestId}`;
|
|
289
|
+
const response = await fetch(url, {
|
|
290
|
+
headers: {
|
|
291
|
+
Authorization: `Key ${this._config.apiKey}`,
|
|
292
|
+
},
|
|
293
|
+
});
|
|
294
|
+
if (!response.ok) {
|
|
295
|
+
const errorText = await response.text();
|
|
296
|
+
throw new Error(`Fal.ai result fetch failed (${response.status}): ${errorText}`);
|
|
297
|
+
}
|
|
298
|
+
return (await response.json());
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
//# sourceMappingURL=FalImageProvider.js.map
|