diff --git a/blocks/blocks/agent.ts b/blocks/blocks/agent.ts index 53892bd42..da8a37ddc 100644 --- a/blocks/blocks/agent.ts +++ b/blocks/blocks/agent.ts @@ -1,5 +1,6 @@ import { AgentIcon } from '@/components/icons' import { BlockConfig } from '../types' +import { ChatResponse } from '@/tools/openai/chat' // Map of models to their tools const MODEL_TOOLS = { @@ -11,9 +12,9 @@ const MODEL_TOOLS = { 'claude-3-5-sonnet-20241022': 'anthropic.chat', 'gemini-pro': 'google.chat', 'grok-2-latest': 'xai.chat' -} as const +} as const -export const AgentBlock: BlockConfig = { +export const AgentBlock: BlockConfig = { type: 'agent', toolbar: { title: 'Agent', @@ -53,20 +54,10 @@ export const AgentBlock: BlockConfig = { outputs: { response: { type: { - text: 'string', + content: 'string', model: 'string', - tokens: 'number' - }, - dependsOn: { - subBlockId: 'responseFormat', - condition: { - whenEmpty: { - response: { type: 'string' } - }, - whenFilled: { - response: { type: 'json' } - } - } + tokens: 'any', + reasoning_tokens: 'any' } } }, diff --git a/blocks/blocks/api.ts b/blocks/blocks/api.ts index 65a6dc0a2..bcb9ae1a7 100644 --- a/blocks/blocks/api.ts +++ b/blocks/blocks/api.ts @@ -1,7 +1,8 @@ import { ApiIcon } from '@/components/icons' import { BlockConfig } from '../types' +import { RequestResponse } from '@/tools/http/request' -export const ApiBlock: BlockConfig = { +export const ApiBlock: BlockConfig = { type: 'api', toolbar: { title: 'API', @@ -23,7 +24,7 @@ export const ApiBlock: BlockConfig = { outputs: { response: { type: { - body: 'any', + data: 'any', status: 'number', headers: 'json' } diff --git a/blocks/blocks/crewai.ts b/blocks/blocks/crewai.ts index 60fd4d2b3..b116a3eae 100644 --- a/blocks/blocks/crewai.ts +++ b/blocks/blocks/crewai.ts @@ -1,7 +1,8 @@ import { BlockConfig } from '../types' import { CrewAIIcon } from '@/components/icons' +import { VisionResponse } from '@/tools/crewai/vision' -export const CrewAIVisionBlock: BlockConfig = { +export const CrewAIVisionBlock: BlockConfig = { type: 'crewaivision', toolbar: { title: 'CrewAI Vision Tool', @@ -23,9 +24,9 @@ export const CrewAIVisionBlock: BlockConfig = { outputs: { response: { type: { - text: 'string', - model: 'string', - tokens: 'number' + content: 'string', + model: 'any', + tokens: 'any' } } }, @@ -55,7 +56,7 @@ export const CrewAIVisionBlock: BlockConfig = { layout: 'full', placeholder: 'Enter your API key', password: true - }, + }, { id: 'prompt', title: 'Custom Prompt', diff --git a/blocks/blocks/firecrawl.ts b/blocks/blocks/firecrawl.ts index a04ba7fbd..95fcbdca1 100644 --- a/blocks/blocks/firecrawl.ts +++ b/blocks/blocks/firecrawl.ts @@ -1,7 +1,8 @@ import { BlockConfig } from '../types' import { FirecrawlIcon } from '@/components/icons' +import { ScrapeResponse } from '@/tools/firecrawl/scrape' -export const FirecrawlScrapeBlock: BlockConfig = { +export const FirecrawlScrapeBlock: BlockConfig = { type: 'firecrawlscrape', toolbar: { title: 'Firecrawl Scraper', @@ -20,10 +21,10 @@ export const FirecrawlScrapeBlock: BlockConfig = { scrapeOptions: { type: 'json', required: false } }, outputs: { - response: { + response: { type: { markdown: 'string', - html: 'string', + html: 'any', metadata: 'json' } } @@ -43,7 +44,7 @@ export const FirecrawlScrapeBlock: BlockConfig = { type: 'short-input', layout: 'full', placeholder: 'Enter the webpage URL to scrape' - }, + }, { id: 'onlyMainContent', title: 'Only Main Content', diff --git a/blocks/blocks/function.ts b/blocks/blocks/function.ts index ec39db41b..216b64e39 100644 --- a/blocks/blocks/function.ts +++ b/blocks/blocks/function.ts @@ -1,7 +1,8 @@ import { CodeIcon } from '@/components/icons' import { BlockConfig } from '../types' - -export const FunctionBlock: BlockConfig = { +import { CodeExecutionOutput } from '@/tools/function/execute' + +export const FunctionBlock: BlockConfig = { type: 'function', toolbar: { title: 'Function', @@ -11,10 +12,7 @@ export const FunctionBlock: BlockConfig = { category: 'advanced', }, tools: { - access: ['function.execute'], - config: { - tool: () => 'function.execute' - } + access: ['function.execute'] }, workflow: { inputs: { @@ -23,7 +21,7 @@ export const FunctionBlock: BlockConfig = { outputs: { response: { type: { - value: 'any', + result: 'any', stdout: 'string' } } @@ -34,8 +32,7 @@ export const FunctionBlock: BlockConfig = { title: 'Code', type: 'code', layout: 'full', - placeholder: 'Enter your code here...' } - ] - } + ], + }, } \ No newline at end of file diff --git a/blocks/types.ts b/blocks/types.ts index 90c25acf8..65c7c7c0d 100644 --- a/blocks/types.ts +++ b/blocks/types.ts @@ -1,5 +1,7 @@ import type { SVGProps } from 'react' import type { JSX } from 'react' +import { ToolResponse } from '@/tools/types' +import { ExtractToolOutput, ToolOutputToValueType } from './utils' export type BlockIcon = (props: SVGProps) => JSX.Element export type BlockCategory = 'basic' | 'advanced' @@ -45,7 +47,7 @@ export interface SubBlockConfig { password?: boolean } -export interface BlockConfig { +export interface BlockConfig { type: string toolbar: { title: string @@ -63,6 +65,10 @@ export interface BlockConfig { workflow: { subBlocks: SubBlockConfig[] inputs: Record - outputs: Record + outputs: { + response: { + type: ToolOutputToValueType> + } + } } } \ No newline at end of file diff --git a/blocks/utils.ts b/blocks/utils.ts index 6919717a4..18105e7d7 100644 --- a/blocks/utils.ts +++ b/blocks/utils.ts @@ -1,11 +1,27 @@ import { BlockState, SubBlockState } from '@/stores/workflow/types' -import { BlockOutput, OutputConfig } from '@/blocks/types' +import { BlockOutput, OutputConfig, PrimitiveValueType } from '@/blocks/types' +import { ToolResponse } from '@/tools/types' interface CodeLine { id: string content: string } +// Tool output type utilities +export type ExtractToolOutput = T extends ToolResponse + ? T['output'] + : never + +export type ToolOutputToValueType = T extends Record + ? { + [K in keyof T]: T[K] extends string ? 'string' + : T[K] extends number ? 'number' + : T[K] extends boolean ? 'boolean' + : T[K] extends object ? 'json' + : 'any' + } + : never + function isEmptyValue(value: SubBlockState['value']): boolean { if (value === null || value === undefined) return true if (typeof value === 'string') return value.trim() === '' diff --git a/lib/workflow.ts b/lib/workflow.ts index f1f84f5fd..f933fb749 100644 --- a/lib/workflow.ts +++ b/lib/workflow.ts @@ -5,7 +5,7 @@ import { Executor } from '@/executor' export interface WorkflowExecutionResult { success: boolean - data?: Record + output?: Record error?: string } @@ -32,10 +32,10 @@ export async function executeWorkflow( // 3. Return result if (result.success) { - console.log('Workflow executed successfully:', result.data) + console.log('Workflow executed successfully:', result.output) return { success: true, - data: result.data + output: result.output } } else { console.error('Workflow execution failed:', result.error) diff --git a/tools/anthropic/chat.ts b/tools/anthropic/chat.ts index 71c237307..65f74f117 100644 --- a/tools/anthropic/chat.ts +++ b/tools/anthropic/chat.ts @@ -1,6 +1,6 @@ import { ToolConfig, ToolResponse } from '../types' -interface ChatParams { +export interface ChatParams { apiKey: string systemPrompt: string context?: string @@ -11,7 +11,7 @@ interface ChatParams { stream?: boolean } -interface ChatResponse extends ToolResponse { +export interface ChatResponse extends ToolResponse { output: { content: string model: string diff --git a/tools/crewai/vision.ts b/tools/crewai/vision.ts index 6a55e931f..ed000e645 100644 --- a/tools/crewai/vision.ts +++ b/tools/crewai/vision.ts @@ -1,13 +1,13 @@ import { ToolConfig, ToolResponse } from '../types' -interface VisionParams { +export interface VisionParams { apiKey: string imageUrl: string model?: string prompt?: string } -interface VisionResponse extends ToolResponse { +export interface VisionResponse extends ToolResponse { output: { content: string model?: string diff --git a/tools/deepseek/chat.ts b/tools/deepseek/chat.ts index 993129aa9..60273cb84 100644 --- a/tools/deepseek/chat.ts +++ b/tools/deepseek/chat.ts @@ -5,7 +5,7 @@ interface Message { content: string } -interface ChatParams { +export interface ChatParams { apiKey: string systemPrompt?: string context?: string @@ -14,7 +14,7 @@ interface ChatParams { responseFormat?: string } -interface ChatResponse extends ToolResponse { +export interface ChatResponse extends ToolResponse { output: { content: string model: string diff --git a/tools/deepseek/reasoner.ts b/tools/deepseek/reasoner.ts index fc00fe1e5..ec73fd07c 100644 --- a/tools/deepseek/reasoner.ts +++ b/tools/deepseek/reasoner.ts @@ -5,7 +5,7 @@ interface Message { content: string } -interface ChatParams { +export interface ChatParams { apiKey: string systemPrompt?: string context?: string @@ -13,7 +13,7 @@ interface ChatParams { temperature?: number } -interface ChatResponse extends ToolResponse { +export interface ChatResponse extends ToolResponse { output: { content: string model: string diff --git a/tools/firecrawl/scrape.ts b/tools/firecrawl/scrape.ts index 06114251c..7d2dfe024 100644 --- a/tools/firecrawl/scrape.ts +++ b/tools/firecrawl/scrape.ts @@ -1,6 +1,6 @@ import { ToolConfig, ToolResponse } from '../types' -interface ScrapeParams { +export interface ScrapeParams { apiKey: string url: string scrapeOptions?: { @@ -9,7 +9,7 @@ interface ScrapeParams { } } -interface ScrapeResponse extends ToolResponse { +export interface ScrapeResponse extends ToolResponse { output: { markdown: string html?: string diff --git a/tools/function/execute.ts b/tools/function/execute.ts index e4439e937..e614ea1da 100644 --- a/tools/function/execute.ts +++ b/tools/function/execute.ts @@ -1,11 +1,11 @@ import { ToolConfig, ToolResponse } from '../types' -interface CodeExecutionInput { +export interface CodeExecutionInput { code: Array<{content: string, id: string}> | string input?: Record } -interface CodeExecutionOutput extends ToolResponse { +export interface CodeExecutionOutput extends ToolResponse { output: { result: any stdout: string diff --git a/tools/google/chat.ts b/tools/google/chat.ts index e12962441..de0846701 100644 --- a/tools/google/chat.ts +++ b/tools/google/chat.ts @@ -1,6 +1,6 @@ import { ToolConfig, ToolResponse } from '../types' -interface ChatParams { +export interface ChatParams { apiKey: string systemPrompt: string context?: string @@ -11,7 +11,7 @@ interface ChatParams { topK?: number } -interface ChatResponse extends ToolResponse { +export interface ChatResponse extends ToolResponse { output: { content: string model: string diff --git a/tools/http/request.ts b/tools/http/request.ts index d01669d71..8e1355997 100644 --- a/tools/http/request.ts +++ b/tools/http/request.ts @@ -1,6 +1,6 @@ import { ToolConfig, HttpMethod, ToolResponse } from '../types' -interface RequestParams { +export interface RequestParams { url: string method?: HttpMethod headers?: Record @@ -12,7 +12,7 @@ interface RequestParams { validateStatus?: (status: number) => boolean } -interface RequestResponse extends ToolResponse { +export interface RequestResponse extends ToolResponse { output: { data: any status: number diff --git a/tools/hubspot/contacts.ts b/tools/hubspot/contacts.ts index 34d7e64ab..89039da71 100644 --- a/tools/hubspot/contacts.ts +++ b/tools/hubspot/contacts.ts @@ -1,6 +1,6 @@ import { ToolConfig, ToolResponse } from '../types' -interface ContactsParams { +export interface ContactsParams { apiKey: string action: 'create' | 'update' | 'search' | 'delete' id?: string @@ -15,7 +15,7 @@ interface ContactsParams { data: Record } -interface ContactsResponse extends ToolResponse { +export interface ContactsResponse extends ToolResponse { output: { contacts: any[] totalResults?: number diff --git a/tools/openai/chat.ts b/tools/openai/chat.ts index d4d941c7b..bb8010b59 100644 --- a/tools/openai/chat.ts +++ b/tools/openai/chat.ts @@ -14,7 +14,7 @@ interface ChatParams { stream?: boolean } -interface ChatResponse extends ToolResponse { +export interface ChatResponse extends ToolResponse { output: { content: string model: string diff --git a/tools/salesforce/opportunities.ts b/tools/salesforce/opportunities.ts index 12c29f5b3..64e5974b1 100644 --- a/tools/salesforce/opportunities.ts +++ b/tools/salesforce/opportunities.ts @@ -1,6 +1,6 @@ import { ToolConfig, ToolResponse } from '../types' -interface OpportunityParams { +export interface OpportunityParams { apiKey: string action: 'create' | 'update' | 'search' | 'delete' id?: string @@ -16,7 +16,7 @@ interface OpportunityParams { data: Record } -interface OpportunityResponse extends ToolResponse { +export interface OpportunityResponse extends ToolResponse { output: { records: any[] totalResults?: number diff --git a/tools/xai/chat.ts b/tools/xai/chat.ts index 69a3f17a4..fd69da3bc 100644 --- a/tools/xai/chat.ts +++ b/tools/xai/chat.ts @@ -1,6 +1,6 @@ import { ToolConfig, ToolResponse } from '../types' -interface ChatParams { +export interface ChatParams { apiKey: string systemPrompt: string context?: string @@ -12,7 +12,7 @@ interface ChatParams { presencePenalty?: number } -interface ChatResponse extends ToolResponse { +export interface ChatResponse extends ToolResponse { output: { content: string model: string