Merge pull request #264 from rowboatlabs/fix_image_fr

moved generate_image from being attached to the workflow
This commit is contained in:
Ramnique Singh 2025-09-16 17:15:22 +05:30 committed by GitHub
commit 726559de76
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 209 additions and 136 deletions

View file

@ -0,0 +1,36 @@
import { z } from 'zod';
// Returns the list of built-in tools that should appear by default
// in the workflow editor and be usable at runtime without attaching
// them to the workflow. These are displayed as read-only library tools.
// Note: avoid importing WorkflowTool here to prevent circular deps.
// Return a structurally compatible object instead.
export function getDefaultTools(): Array<any> {
// Show built-in tools only when a public, non-secret flag is set.
// Avoids exposing real secrets in client bundles.
const hasGoogleKeyFlag = (process.env.NEXT_PUBLIC_HAS_GOOGLE_API_KEY || '').toLowerCase() === 'true';
if (!hasGoogleKeyFlag) return [];
return [
{
name: 'Generate Image',
description:
'Generate an image using Google Gemini given a text prompt. Returns base64-encoded image data and any text parts.',
isGeminiImage: true,
isLibrary: true,
parameters: {
type: 'object',
properties: {
prompt: {
type: 'string',
description: 'Text prompt describing the image to generate',
},
modelName: { type: 'string', description: 'Optional Gemini model override' },
},
required: ['prompt'],
additionalProperties: true,
},
},
];
}

View file

@ -3,7 +3,6 @@ import { z } from 'zod';
// Provide a minimal default template to satisfy legacy code paths that
// still reference `templates.default`. Real templates are DB-backed.
const includeGeminiImageTool = !!process.env.GOOGLE_API_KEY;
const defaultTemplate: z.infer<typeof WorkflowTemplate> = {
name: 'Blank Template',
@ -11,22 +10,7 @@ const defaultTemplate: z.infer<typeof WorkflowTemplate> = {
startAgent: "",
agents: [],
prompts: [],
tools: includeGeminiImageTool ? [
{
name: "Generate Image",
description: "Generate an image using Google Gemini given a text prompt. Returns base64-encoded image data and any text parts.",
isGeminiImage: true,
parameters: {
type: 'object',
properties: {
prompt: { type: 'string', description: 'Text prompt describing the image to generate' },
modelName: { type: 'string', description: 'Optional Gemini model override' },
},
required: ['prompt'],
additionalProperties: true,
},
},
] : [],
tools: [],
pipelines: [],
};

View file

@ -1,4 +1,5 @@
import { z } from "zod";
import { getDefaultTools } from "@/app/lib/default_tools";
export const WorkflowAgent = z.object({
name: z.string(),
order: z.number().int().optional(),
@ -165,7 +166,10 @@ export function sanitizeTextWithMentions(
const agent = workflow.agents.find(a => a.name === entity.name);
return agent && agent.type !== 'pipeline';
} else if (entity.type === 'tool') {
return workflow.tools.some(t => t.name === entity.name);
// Allow referencing workflow tools or default library tools
const inWorkflow = workflow.tools.some(t => t.name === entity.name);
const inDefaults = getDefaultTools().some(t => t.name === entity.name);
return inWorkflow || inDefaults;
} else if (entity.type === 'prompt') {
return workflow.prompts.some(p => p.name === entity.name);
} else if (entity.type === 'pipeline') {