6bf8bebf51
CI / Test and Build (push) Failing after 1s
CI / Migrate Dev DB (push) Has been skipped
CI / Migrate DB (push) Has been skipped
CodeQL / Analyze actions (push) Has been cancelled
CodeQL / Analyze javascript-typescript (push) Has been cancelled
CI / Detect Version (push) Has been cancelled
CI / Detect Desktop Changes (push) Has been cancelled
CI / Build AMD64 (blacksmith-2vcpu-ubuntu-2404, ./docker/cron.Dockerfile, ubuntu-latest, ghcr.io/simstudioai/cron) (push) Has been cancelled
CI / Build AMD64 (blacksmith-2vcpu-ubuntu-2404, ./docker/db.Dockerfile, ECR_MIGRATIONS, ubuntu-latest, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (blacksmith-4vcpu-ubuntu-2404, ./docker/pii.Dockerfile, ECR_PII, ubuntu-latest, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (blacksmith-4vcpu-ubuntu-2404, ./docker/realtime.Dockerfile, ECR_REALTIME, ubuntu-latest, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build AMD64 (blacksmith-8vcpu-ubuntu-2404, ./docker/app.Dockerfile, ECR_APP, linux-x64-8-core, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/cron.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/cron) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/db.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/pii.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/realtime.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-8vcpu-ubuntu-2404-arm, ./docker/app.Dockerfile, linux-arm64-8-core, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
Helm Chart / Lint, test, and validate chart (push) Has been cancelled
Helm Chart / Chart version bumped (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
CI / Build Dev ECR (blacksmith-8vcpu-ubuntu-2404, ./docker/app.Dockerfile, ECR_APP, linux-x64-8-core) (push) Has been cancelled
CI / Promote Images (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/cron) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build Dev ECR (blacksmith-2vcpu-ubuntu-2404, ./docker/db.Dockerfile, ECR_MIGRATIONS, ubuntu-latest) (push) Has been cancelled
CI / Build Dev ECR (blacksmith-4vcpu-ubuntu-2404, ./docker/pii.Dockerfile, ECR_PII, ubuntu-latest) (push) Has been cancelled
CI / Build Dev ECR (blacksmith-4vcpu-ubuntu-2404, ./docker/realtime.Dockerfile, ECR_REALTIME, ubuntu-latest) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Check Desktop Signing Secrets (push) Has been cancelled
CI / Desktop Release (push) Has been cancelled
CI / Create Desktop Prerelease (push) Has been cancelled
CI / Desktop Prerelease Build (push) Has been cancelled
CI / Publish Desktop Prerelease (push) Has been cancelled
CI / Prune Desktop Prereleases (push) Has been cancelled
Helm Chart / Install on kind and run helm test (push) Has been cancelled
279 lines
8.5 KiB
TypeScript
279 lines
8.5 KiB
TypeScript
import { FALAI_HOSTED_KEY_MARKUP_MULTIPLIER } from '@/lib/tools/falai-pricing'
|
|
import { hostedKeyEnabledWhen } from '@/tools/hosting'
|
|
import type { ImageGenerationParams, ImageGenerationResponse } from '@/tools/image/types'
|
|
import type { ToolConfig } from '@/tools/types'
|
|
|
|
export const imageGenerateTool: ToolConfig<ImageGenerationParams, ImageGenerationResponse> = {
|
|
id: 'image_generate',
|
|
name: 'Image Generator',
|
|
description: 'Generate images with OpenAI GPT Image, Google Nano Banana, or Fal.ai image models',
|
|
version: '1.0.0',
|
|
|
|
params: {
|
|
provider: {
|
|
type: 'string',
|
|
required: true,
|
|
visibility: 'user-only',
|
|
description: 'Image generation provider: openai, gemini, or falai',
|
|
},
|
|
apiKey: {
|
|
type: 'string',
|
|
required: true,
|
|
visibility: 'user-only',
|
|
description: 'Provider API key',
|
|
},
|
|
model: {
|
|
type: 'string',
|
|
required: true,
|
|
visibility: 'user-or-llm',
|
|
description:
|
|
'Provider model ID, such as gpt-image-1.5, gemini-3.1-flash-image-preview, or nano-banana-2',
|
|
},
|
|
prompt: {
|
|
type: 'string',
|
|
required: true,
|
|
visibility: 'user-or-llm',
|
|
description: 'Text prompt describing the image to generate',
|
|
},
|
|
size: {
|
|
type: 'string',
|
|
required: false,
|
|
visibility: 'user-or-llm',
|
|
description: 'Provider-specific image size',
|
|
},
|
|
aspectRatio: {
|
|
type: 'string',
|
|
required: false,
|
|
visibility: 'user-or-llm',
|
|
description: 'Aspect ratio, such as auto, 1:1, 16:9, or 9:16',
|
|
},
|
|
resolution: {
|
|
type: 'string',
|
|
required: false,
|
|
visibility: 'user-or-llm',
|
|
description: 'Provider-specific image resolution, such as 1K, 2K, 4K, 1k, or 2k',
|
|
},
|
|
quality: {
|
|
type: 'string',
|
|
required: false,
|
|
visibility: 'user-or-llm',
|
|
description: 'Provider-specific image quality',
|
|
},
|
|
background: {
|
|
type: 'string',
|
|
required: false,
|
|
visibility: 'user-or-llm',
|
|
description: 'Background setting when supported',
|
|
},
|
|
outputFormat: {
|
|
type: 'string',
|
|
required: false,
|
|
visibility: 'user-or-llm',
|
|
description: 'Output image format: png, jpeg, or webp where supported',
|
|
},
|
|
moderation: {
|
|
type: 'string',
|
|
required: false,
|
|
visibility: 'user-or-llm',
|
|
description: 'OpenAI moderation level: auto or low',
|
|
},
|
|
safetyTolerance: {
|
|
type: 'string',
|
|
required: false,
|
|
visibility: 'user-or-llm',
|
|
description: 'Fal.ai safety tolerance when supported',
|
|
},
|
|
numImages: {
|
|
type: 'number',
|
|
required: false,
|
|
visibility: 'user-or-llm',
|
|
description: 'Number of images to generate, subject to provider limits',
|
|
},
|
|
seed: {
|
|
type: 'number',
|
|
required: false,
|
|
visibility: 'user-or-llm',
|
|
description: 'Random seed when supported',
|
|
},
|
|
enableSafetyChecker: {
|
|
type: 'boolean',
|
|
required: false,
|
|
visibility: 'user-or-llm',
|
|
description: 'Enable the Fal.ai safety checker when supported',
|
|
},
|
|
enableWebSearch: {
|
|
type: 'boolean',
|
|
required: false,
|
|
visibility: 'user-or-llm',
|
|
description: 'Enable web search grounding when supported by the selected Fal.ai model',
|
|
},
|
|
thinkingLevel: {
|
|
type: 'string',
|
|
required: false,
|
|
visibility: 'user-or-llm',
|
|
description: 'Fal.ai thinking level when supported: minimal or high',
|
|
},
|
|
},
|
|
|
|
hosting: {
|
|
enabled: hostedKeyEnabledWhen<ImageGenerationParams>({
|
|
field: 'provider',
|
|
operator: 'equals',
|
|
value: 'falai',
|
|
}),
|
|
envKeyPrefix: 'FALAI_API_KEY',
|
|
apiKeyParam: 'apiKey',
|
|
byokProviderId: 'falai',
|
|
pricing: {
|
|
type: 'custom',
|
|
getCost: (_params, output) => {
|
|
const providerCostDollars = output.__falaiCostDollars
|
|
if (typeof providerCostDollars !== 'number' || Number.isNaN(providerCostDollars)) {
|
|
throw new Error('Fal.ai image response missing cost data')
|
|
}
|
|
|
|
return {
|
|
cost: providerCostDollars * FALAI_HOSTED_KEY_MARKUP_MULTIPLIER,
|
|
metadata: {
|
|
...(typeof output.__falaiBilling === 'object' && output.__falaiBilling !== null
|
|
? (output.__falaiBilling as Record<string, unknown>)
|
|
: {}),
|
|
providerCostDollars,
|
|
markupMultiplier: FALAI_HOSTED_KEY_MARKUP_MULTIPLIER,
|
|
},
|
|
}
|
|
},
|
|
},
|
|
rateLimit: {
|
|
mode: 'per_request',
|
|
requestsPerMinute: 40,
|
|
burstMultiplier: 1,
|
|
},
|
|
},
|
|
|
|
request: {
|
|
modelInput: {
|
|
mode: 'project',
|
|
select: (params) => ({ prompt: params.prompt }),
|
|
},
|
|
url: '/api/tools/image',
|
|
method: 'POST',
|
|
headers: () => ({
|
|
'Content-Type': 'application/json',
|
|
}),
|
|
body: (
|
|
params: ImageGenerationParams & {
|
|
_context?: { workspaceId?: string; workflowId?: string; executionId?: string }
|
|
__usingHostedKey?: boolean
|
|
}
|
|
) => ({
|
|
provider: params.provider,
|
|
apiKey: params.apiKey,
|
|
model: params.model,
|
|
prompt: params.prompt,
|
|
size: params.size,
|
|
aspectRatio: params.aspectRatio,
|
|
resolution: params.resolution,
|
|
quality: params.quality,
|
|
background: params.background,
|
|
outputFormat: params.outputFormat,
|
|
moderation: params.moderation,
|
|
safetyTolerance: params.safetyTolerance,
|
|
numImages: params.numImages,
|
|
seed: params.seed,
|
|
enableSafetyChecker: params.enableSafetyChecker,
|
|
enableWebSearch: params.enableWebSearch,
|
|
thinkingLevel: params.thinkingLevel,
|
|
workspaceId: params._context?.workspaceId,
|
|
workflowId: params._context?.workflowId,
|
|
executionId: params._context?.executionId,
|
|
useHostedCostTracking: params.__usingHostedKey === true,
|
|
}),
|
|
},
|
|
|
|
transformResponse: async (response: Response) => {
|
|
const data = (await response.json()) as {
|
|
error?: string
|
|
content?: string
|
|
image?: string
|
|
imageUrl?: string
|
|
imageFile?: unknown
|
|
fileName?: string
|
|
contentType?: string
|
|
provider?: string
|
|
model?: string
|
|
metadata?: ImageGenerationResponse['output']['metadata']
|
|
__falaiCostDollars?: number
|
|
__falaiBilling?: ImageGenerationResponse['output']['__falaiBilling']
|
|
}
|
|
|
|
if (!response.ok || data.error) {
|
|
return {
|
|
success: false,
|
|
error: data.error || 'Image generation failed',
|
|
output: {
|
|
content: '',
|
|
image: '',
|
|
imageUrl: '',
|
|
provider: data.provider || '',
|
|
model: data.model || '',
|
|
metadata: {
|
|
provider: data.provider || '',
|
|
model: data.model || '',
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
const image =
|
|
data.imageFile ||
|
|
data.image ||
|
|
(data.imageUrl
|
|
? {
|
|
name: data.fileName || 'generated-image.png',
|
|
url: data.imageUrl,
|
|
mimeType: data.contentType || 'image/png',
|
|
}
|
|
: '')
|
|
|
|
return {
|
|
success: true,
|
|
output: {
|
|
content: data.content || data.imageUrl || 'direct-image',
|
|
image,
|
|
imageUrl: data.imageUrl || '',
|
|
provider: data.provider || data.metadata?.provider || '',
|
|
model: data.model || data.metadata?.model || '',
|
|
metadata: {
|
|
provider: data.provider || data.metadata?.provider || '',
|
|
model: data.model || data.metadata?.model || '',
|
|
...data.metadata,
|
|
},
|
|
__falaiCostDollars: data.__falaiCostDollars,
|
|
__falaiBilling: data.__falaiBilling,
|
|
},
|
|
}
|
|
},
|
|
|
|
outputs: {
|
|
content: { type: 'string', description: 'Generated image URL or identifier' },
|
|
image: { type: 'file', description: 'Generated image file' },
|
|
imageUrl: { type: 'string', description: 'Generated image URL' },
|
|
provider: { type: 'string', description: 'Provider used' },
|
|
model: { type: 'string', description: 'Model used' },
|
|
metadata: {
|
|
type: 'json',
|
|
description: 'Generation metadata',
|
|
properties: {
|
|
provider: { type: 'string', description: 'Provider used' },
|
|
model: { type: 'string', description: 'Model used' },
|
|
description: { type: 'string', description: 'Provider description', optional: true },
|
|
revisedPrompt: { type: 'string', description: 'Revised prompt', optional: true },
|
|
seed: { type: 'number', description: 'Seed used for generation', optional: true },
|
|
jobId: { type: 'string', description: 'Provider job ID', optional: true },
|
|
contentType: { type: 'string', description: 'Image MIME type', optional: true },
|
|
},
|
|
},
|
|
},
|
|
}
|