From 5c8bd0551fb6564c1189b7522f514fa4d03c7592 Mon Sep 17 00:00:00 2001 From: Emir Karabeg Date: Sat, 15 Feb 2025 01:21:40 -0800 Subject: [PATCH] Changed id back to type on config --- .../components/sub-block/components/tool-input.tsx | 14 +++++++------- .../components/console-entry/console-entry.tsx | 10 +--------- .../components/toolbar-block/toolbar-block.tsx | 4 ++-- app/w/components/toolbar/toolbar.tsx | 2 +- blocks/blocks/agent.ts | 2 +- blocks/blocks/api.ts | 2 +- blocks/blocks/condition.ts | 2 +- blocks/blocks/crewai.ts | 2 +- blocks/blocks/evaluator.ts | 2 +- blocks/blocks/firecrawl.ts | 2 +- blocks/blocks/function.ts | 2 +- blocks/blocks/github.ts | 2 +- blocks/blocks/gmail.ts | 2 +- blocks/blocks/jina.ts | 2 +- blocks/blocks/notion.ts | 2 +- blocks/blocks/router.ts | 2 +- blocks/blocks/serper.ts | 2 +- blocks/blocks/slack.ts | 2 +- blocks/blocks/starter.ts | 2 +- blocks/blocks/tavily.ts | 2 +- blocks/blocks/translate.ts | 2 +- blocks/blocks/x.ts | 2 +- blocks/blocks/youtube.ts | 2 +- blocks/index.ts | 6 +++--- blocks/types.ts | 2 +- executor/index.ts | 2 +- 26 files changed, 35 insertions(+), 43 deletions(-) diff --git a/app/w/[id]/components/workflow-block/components/sub-block/components/tool-input.tsx b/app/w/[id]/components/workflow-block/components/sub-block/components/tool-input.tsx index 44e51f4c2d..370e623b84 100644 --- a/app/w/[id]/components/workflow-block/components/sub-block/components/tool-input.tsx +++ b/app/w/[id]/components/workflow-block/components/sub-block/components/tool-input.tsx @@ -39,7 +39,7 @@ interface ToolParam { // Assumes the first tool in the access array is the tool to be used // TODO: Switch to getting tools instead of tool blocks once we switch to providers const getToolIdFromBlock = (blockType: string): string | undefined => { - const block = getAllBlocks().find((block) => block.id === blockType) + const block = getAllBlocks().find((block) => block.type === blockType) return block?.tools.access[0] } @@ -71,14 +71,14 @@ export function ToolInput({ blockId, subBlockId }: ToolInputProps) { const handleSelectTool = (toolBlock: (typeof toolBlocks)[0]) => { // Check if tool already exists - if (selectedTools.some((tool) => tool.type === toolBlock.id)) { + if (selectedTools.some((tool) => tool.type === toolBlock.type)) { setOpen(false) return } - const toolId = getToolIdFromBlock(toolBlock.id) + const toolId = getToolIdFromBlock(toolBlock.type) const newTool: StoredTool = { - type: toolBlock.id, + type: toolBlock.type, title: toolBlock.name, params: {}, isExpanded: true, @@ -155,7 +155,7 @@ export function ToolInput({ blockId, subBlockId }: ToolInputProps) { {toolBlocks.map((block) => ( handleSelectTool(block)} className="flex items-center gap-2 cursor-pointer" > @@ -176,7 +176,7 @@ export function ToolInput({ blockId, subBlockId }: ToolInputProps) { ) : (
{selectedTools.map((tool) => { - const toolBlock = toolBlocks.find((block) => block.id === tool.type) + const toolBlock = toolBlocks.find((block) => block.type === tool.type) const toolId = getToolIdFromBlock(tool.type) const requiredParams = toolId ? getRequiredToolParams(toolId) : [] @@ -269,7 +269,7 @@ export function ToolInput({ blockId, subBlockId }: ToolInputProps) { {toolBlocks.map((block) => ( handleSelectTool(block)} className="flex items-center gap-2 cursor-pointer" > diff --git a/app/w/components/console/components/console-entry/console-entry.tsx b/app/w/components/console/components/console-entry/console-entry.tsx index 2a8989c659..349824f763 100644 --- a/app/w/components/console/components/console-entry/console-entry.tsx +++ b/app/w/components/console/components/console-entry/console-entry.tsx @@ -1,5 +1,5 @@ import { useMemo, useState } from 'react' -import { format, formatDistanceToNow } from 'date-fns' +import { format } from 'date-fns' import { AlertCircle, AlertTriangle, Calendar, CheckCircle2, Clock, Terminal } from 'lucide-react' import { ConsoleEntry as ConsoleEntryType } from '@/stores/console/types' import { getBlock } from '@/blocks' @@ -13,14 +13,6 @@ interface ConsoleEntryProps { export function ConsoleEntry({ entry, consoleWidth }: ConsoleEntryProps) { const [isExpanded, setIsExpanded] = useState(false) - const timeAgo = useMemo( - () => - formatDistanceToNow(new Date(entry.startedAt), { - addSuffix: true, - }), - [entry.startedAt] - ) - const blockConfig = useMemo(() => { if (!entry.blockType) return null return getBlock(entry.blockType) diff --git a/app/w/components/toolbar/components/toolbar-block/toolbar-block.tsx b/app/w/components/toolbar/components/toolbar-block/toolbar-block.tsx index 66e8c9c9fe..d31cc768ce 100644 --- a/app/w/components/toolbar/components/toolbar-block/toolbar-block.tsx +++ b/app/w/components/toolbar/components/toolbar-block/toolbar-block.tsx @@ -6,7 +6,7 @@ export type ToolbarBlockProps = { export function ToolbarBlock({ config }: ToolbarBlockProps) { const handleDragStart = (e: React.DragEvent) => { - e.dataTransfer.setData('application/json', JSON.stringify({ type: config.id })) + e.dataTransfer.setData('application/json', JSON.stringify({ type: config.type })) e.dataTransfer.effectAllowed = 'move' } @@ -22,7 +22,7 @@ export function ToolbarBlock({ config }: ToolbarBlockProps) { >
diff --git a/app/w/components/toolbar/toolbar.tsx b/app/w/components/toolbar/toolbar.tsx index af2b618ff4..ed52cc0413 100644 --- a/app/w/components/toolbar/toolbar.tsx +++ b/app/w/components/toolbar/toolbar.tsx @@ -69,7 +69,7 @@ export function Toolbar() {
{blocks.map((block) => ( - + ))}
diff --git a/blocks/blocks/agent.ts b/blocks/blocks/agent.ts index 2e220393bf..8acbd704f2 100644 --- a/blocks/blocks/agent.ts +++ b/blocks/blocks/agent.ts @@ -23,7 +23,7 @@ interface AgentResponse extends ToolResponse { } export const AgentBlock: BlockConfig = { - id: 'agent', + type: 'agent', name: 'Agent', description: 'Build an agent', category: 'blocks', diff --git a/blocks/blocks/api.ts b/blocks/blocks/api.ts index fa99674578..1871fc951f 100644 --- a/blocks/blocks/api.ts +++ b/blocks/blocks/api.ts @@ -3,7 +3,7 @@ import { RequestResponse } from '@/tools/http/request' import { BlockConfig } from '../types' export const ApiBlock: BlockConfig = { - id: 'api', + type: 'api', name: 'API', description: 'Use any API', category: 'blocks', diff --git a/blocks/blocks/condition.ts b/blocks/blocks/condition.ts index b34d17e88d..c5bb403ae3 100644 --- a/blocks/blocks/condition.ts +++ b/blocks/blocks/condition.ts @@ -3,7 +3,7 @@ import { CodeExecutionOutput } from '@/tools/function/execute' import { BlockConfig } from '../types' export const ConditionBlock: BlockConfig = { - id: 'condition', + type: 'condition', name: 'Condition', description: 'Add a condition', longDescription: 'Add a condition to the workflow', diff --git a/blocks/blocks/crewai.ts b/blocks/blocks/crewai.ts index 58b2cef27f..4acca2215c 100644 --- a/blocks/blocks/crewai.ts +++ b/blocks/blocks/crewai.ts @@ -3,7 +3,7 @@ import { VisionResponse } from '@/tools/crewai/vision' import { BlockConfig } from '../types' export const CrewAIVisionBlock: BlockConfig = { - id: 'crewai_vision', + type: 'crewai_vision', name: 'CrewAI Vision', description: 'Analyze images with vision models', category: 'tools', diff --git a/blocks/blocks/evaluator.ts b/blocks/blocks/evaluator.ts index 3fa655b577..7f7715e094 100644 --- a/blocks/blocks/evaluator.ts +++ b/blocks/blocks/evaluator.ts @@ -56,7 +56,7 @@ const generateResponseFormat = (metrics: Metric[]) => ({ }) export const EvaluatorBlock: BlockConfig = { - id: 'evaluator', + type: 'evaluator', name: 'Evaluator', description: 'Evaluate content', category: 'blocks', diff --git a/blocks/blocks/firecrawl.ts b/blocks/blocks/firecrawl.ts index 83a5e5a705..760b33f6d5 100644 --- a/blocks/blocks/firecrawl.ts +++ b/blocks/blocks/firecrawl.ts @@ -3,7 +3,7 @@ import { ScrapeResponse } from '@/tools/firecrawl/scrape' import { BlockConfig } from '../types' export const FirecrawlBlock: BlockConfig = { - id: 'firecrawl', + type: 'firecrawl', name: 'Firecrawl', description: 'Scrape website content', category: 'tools', diff --git a/blocks/blocks/function.ts b/blocks/blocks/function.ts index 550a686c3f..ac736da326 100644 --- a/blocks/blocks/function.ts +++ b/blocks/blocks/function.ts @@ -3,7 +3,7 @@ import { CodeExecutionOutput } from '@/tools/function/execute' import { BlockConfig } from '../types' export const FunctionBlock: BlockConfig = { - id: 'function', + type: 'function', name: 'Function', description: 'Run custom logic', category: 'blocks', diff --git a/blocks/blocks/github.ts b/blocks/blocks/github.ts index d40a6ec05c..8f484f506f 100644 --- a/blocks/blocks/github.ts +++ b/blocks/blocks/github.ts @@ -3,7 +3,7 @@ import { GithubIcon } from '../../components/icons' import { BlockConfig } from '../types' export const GitHubBlock: BlockConfig = { - id: 'github', + type: 'github', name: 'GitHub', description: 'Fetch GitHub repository', category: 'tools', diff --git a/blocks/blocks/gmail.ts b/blocks/blocks/gmail.ts index 601e437e4c..e451a2f177 100644 --- a/blocks/blocks/gmail.ts +++ b/blocks/blocks/gmail.ts @@ -3,7 +3,7 @@ import { GmailToolResponse } from '@/tools/gmail/types' import { BlockConfig } from '../types' export const GmailBlock: BlockConfig = { - id: 'gmail', + type: 'gmail', name: 'Gmail', description: 'Send, read, and search Gmail messages', category: 'tools', diff --git a/blocks/blocks/jina.ts b/blocks/blocks/jina.ts index 5b4ca1ccc9..f4ec5b807a 100644 --- a/blocks/blocks/jina.ts +++ b/blocks/blocks/jina.ts @@ -3,7 +3,7 @@ import { ReadUrlResponse } from '@/tools/jina/reader' import { BlockConfig } from '../types' export const JinaBlock: BlockConfig = { - id: 'jina', + type: 'jina', name: 'Jina', description: 'Convert website content into text', category: 'tools', diff --git a/blocks/blocks/notion.ts b/blocks/blocks/notion.ts index 22878b4608..d4daba89c7 100644 --- a/blocks/blocks/notion.ts +++ b/blocks/blocks/notion.ts @@ -3,7 +3,7 @@ import { NotionResponse } from '@/tools/notion/read' import { BlockConfig } from '../types' export const NotionBlock: BlockConfig = { - id: 'notion', + type: 'notion', name: 'Notion', description: 'Read and write to Notion pages and databases', category: 'tools', diff --git a/blocks/blocks/router.ts b/blocks/blocks/router.ts index e0900b1ee8..7e2995e1dc 100644 --- a/blocks/blocks/router.ts +++ b/blocks/blocks/router.ts @@ -86,7 +86,7 @@ Remember: Your response must be ONLY the block ID - no additional text, formatti } export const RouterBlock: BlockConfig = { - id: 'router', + type: 'router', name: 'Router', description: 'Route workflow', category: 'blocks', diff --git a/blocks/blocks/serper.ts b/blocks/blocks/serper.ts index c684bc2cc4..49fdd9f790 100644 --- a/blocks/blocks/serper.ts +++ b/blocks/blocks/serper.ts @@ -3,7 +3,7 @@ import { SearchResponse } from '@/tools/serper/search' import { BlockConfig } from '../types' export const SerperBlock: BlockConfig = { - id: 'serper', + type: 'serper', name: 'Serper', description: 'Search the web using Serper', category: 'tools', diff --git a/blocks/blocks/slack.ts b/blocks/blocks/slack.ts index 948cc2aa86..01f10757ea 100644 --- a/blocks/blocks/slack.ts +++ b/blocks/blocks/slack.ts @@ -3,7 +3,7 @@ import { SlackMessageResponse } from '@/tools/slack/message' import { BlockConfig } from '../types' export const SlackBlock: BlockConfig = { - id: 'slack', + type: 'slack', name: 'Slack', description: 'Send a message to Slack', category: 'tools', diff --git a/blocks/blocks/starter.ts b/blocks/blocks/starter.ts index 4b97041a48..5eab45eee7 100644 --- a/blocks/blocks/starter.ts +++ b/blocks/blocks/starter.ts @@ -2,7 +2,7 @@ import { StartIcon } from '@/components/icons' import { BlockConfig } from '../types' export const StarterBlock: BlockConfig = { - id: 'starter', + type: 'starter', name: 'Starter', description: 'Start workflow', category: 'blocks', diff --git a/blocks/blocks/tavily.ts b/blocks/blocks/tavily.ts index 25544e5727..5a9ebb7eb2 100644 --- a/blocks/blocks/tavily.ts +++ b/blocks/blocks/tavily.ts @@ -5,7 +5,7 @@ import { BlockConfig } from '../types' type TavilyResponse = TavilySearchResponse | TavilyExtractResponse export const TavilyBlock: BlockConfig = { - id: 'tavily', + type: 'tavily', name: 'Tavily', description: 'Search and extract information using Tavily AI', category: 'tools', diff --git a/blocks/blocks/translate.ts b/blocks/blocks/translate.ts index f848020994..4c3eb542b3 100644 --- a/blocks/blocks/translate.ts +++ b/blocks/blocks/translate.ts @@ -15,7 +15,7 @@ const getTranslationPrompt = ( Only return the translated text without any explanations or notes. The translation should be natural and fluent in ${targetLanguage || 'English'}.` export const TranslateBlock: BlockConfig = { - id: 'translate', + type: 'translate', name: 'Translate', description: 'Translate text to any language', category: 'tools', diff --git a/blocks/blocks/x.ts b/blocks/blocks/x.ts index a4ab0fce22..0e193a402f 100644 --- a/blocks/blocks/x.ts +++ b/blocks/blocks/x.ts @@ -5,7 +5,7 @@ import { BlockConfig } from '../types' type XResponse = XWriteResponse | XReadResponse | XSearchResponse | XUserResponse export const XBlock: BlockConfig = { - id: 'x', + type: 'x', name: 'X', description: 'Interact with X', category: 'tools', diff --git a/blocks/blocks/youtube.ts b/blocks/blocks/youtube.ts index 6a36667bc9..7ef306e42b 100644 --- a/blocks/blocks/youtube.ts +++ b/blocks/blocks/youtube.ts @@ -3,7 +3,7 @@ import { YouTubeSearchResponse } from '@/tools/youtube/search' import { BlockConfig } from '../types' export const YouTubeBlock: BlockConfig = { - id: 'youtube', + type: 'youtube', name: 'YouTube', description: 'Search for videos on YouTube', category: 'tools', diff --git a/blocks/index.ts b/blocks/index.ts index f79f31b889..4d2ea71cd4 100644 --- a/blocks/index.ts +++ b/blocks/index.ts @@ -67,13 +67,13 @@ const blocks: Record = { } // Helper functions -export const getBlock = (id: string): BlockConfig | undefined => blocks[id] +export const getBlock = (type: string): BlockConfig | undefined => blocks[type] export const getBlocksByCategory = (category: 'blocks' | 'tools'): BlockConfig[] => Object.values(blocks).filter((block) => block.category === category) -export const getAllBlockIds = (): string[] => Object.keys(blocks) +export const getAllBlockTypes = (): string[] => Object.keys(blocks) -export const isValidBlockId = (id: string): id is string => id in blocks +export const isValidBlockType = (type: string): type is string => type in blocks export const getAllBlocks = (): BlockConfig[] => Object.values(blocks) diff --git a/blocks/types.ts b/blocks/types.ts index 93eca3edcd..22980fbc26 100644 --- a/blocks/types.ts +++ b/blocks/types.ts @@ -97,7 +97,7 @@ export interface SubBlockConfig { // Main block definition export interface BlockConfig { - id: string + type: string name: string description: string category: BlockCategory diff --git a/executor/index.ts b/executor/index.ts index 006f4a1abf..c6b7c5e433 100644 --- a/executor/index.ts +++ b/executor/index.ts @@ -486,7 +486,7 @@ export class Executor { const formattedTools = Array.isArray(inputs.tools) ? inputs.tools .map((tool: any) => { - const blockFound = getAllBlocks().find((b: BlockConfig) => b.id === tool.type) + const blockFound = getAllBlocks().find((b: BlockConfig) => b.type === tool.type) const toolId = blockFound?.tools.access[0] if (!toolId) return null