From a14e9fc8aa5e74f2eb8ca917b4f5072e9e60d2e6 Mon Sep 17 00:00:00 2001 From: Emir Karabeg Date: Fri, 17 Jan 2025 16:20:16 -0800 Subject: [PATCH] Simplified blocks file structure --- app/w/[id]/workflow.tsx | 4 +-- .../toolbar-block/toolbar-block.tsx | 2 +- .../components/sub-block/sub-block.tsx | 2 +- .../workflow-block/workflow-block.tsx | 2 +- blocks/{configs => blocks}/agent.ts | 2 +- blocks/{configs => blocks}/api.ts | 2 +- blocks/{configs => blocks}/function.ts | 2 +- blocks/configs/index.ts | 29 ----------------- blocks/index.ts | 31 +++++++++++++++++-- blocks/{types/block.ts => types.ts} | 0 stores/workflow/types.ts | 2 +- stores/workflow/workflow-store.ts | 2 +- 12 files changed, 39 insertions(+), 41 deletions(-) rename blocks/{configs => blocks}/agent.ts (97%) rename blocks/{configs => blocks}/api.ts (95%) rename blocks/{configs => blocks}/function.ts (91%) delete mode 100644 blocks/configs/index.ts rename blocks/{types/block.ts => types.ts} (100%) diff --git a/app/w/[id]/workflow.tsx b/app/w/[id]/workflow.tsx index ae51ce1f09..7a586d8f03 100644 --- a/app/w/[id]/workflow.tsx +++ b/app/w/[id]/workflow.tsx @@ -18,9 +18,9 @@ import ReactFlow, { getSmoothStepPath, } from 'reactflow' import 'reactflow/dist/style.css' -import { getBlock } from '../../../blocks/configs' +import { getBlock } from '../../../blocks' import { WorkflowBlock } from '../components/workflow-block/workflow-block' -import { BlockConfig } from '../../../blocks/types/block' +import { BlockConfig } from '../../../blocks/types' import { useWorkflowStore } from '@/stores/workflow/workflow-store' import { initializeStateLogger } from '@/stores/workflow/state-logger' import { Serializer } from '@/serializer' diff --git a/app/w/components/toolbar-block/toolbar-block.tsx b/app/w/components/toolbar-block/toolbar-block.tsx index a73327f432..865f63fcf5 100644 --- a/app/w/components/toolbar-block/toolbar-block.tsx +++ b/app/w/components/toolbar-block/toolbar-block.tsx @@ -1,4 +1,4 @@ -import type { BlockConfig } from '../../../../blocks/types/block' +import type { BlockConfig } from '../../../../blocks/types' export type ToolbarBlockProps = { config: BlockConfig diff --git a/app/w/components/workflow-block/components/sub-block/sub-block.tsx b/app/w/components/workflow-block/components/sub-block/sub-block.tsx index 534ceaa800..c4712031b7 100644 --- a/app/w/components/workflow-block/components/sub-block/sub-block.tsx +++ b/app/w/components/workflow-block/components/sub-block/sub-block.tsx @@ -1,4 +1,4 @@ -import { SubBlockConfig } from '../../../../../../blocks/types/block' +import { SubBlockConfig } from '../../../../../../blocks/types' import { Label } from '@/components/ui/label' import { ShortInput } from './components/short-input' import { LongInput } from './components/long-input' diff --git a/app/w/components/workflow-block/workflow-block.tsx b/app/w/components/workflow-block/workflow-block.tsx index 8abeefa2f3..f493526ff0 100644 --- a/app/w/components/workflow-block/workflow-block.tsx +++ b/app/w/components/workflow-block/workflow-block.tsx @@ -1,5 +1,5 @@ import { Card } from '@/components/ui/card' -import { BlockConfig, SubBlockConfig } from '../../../../blocks/types/block' +import { BlockConfig, SubBlockConfig } from '../../../../blocks/types' import { SubBlock } from './components/sub-block/sub-block' import { Handle, Position } from 'reactflow' import { cn } from '@/lib/utils' diff --git a/blocks/configs/agent.ts b/blocks/blocks/agent.ts similarity index 97% rename from blocks/configs/agent.ts rename to blocks/blocks/agent.ts index 7f5ad81661..88c776000b 100644 --- a/blocks/configs/agent.ts +++ b/blocks/blocks/agent.ts @@ -1,5 +1,5 @@ import { AgentIcon } from '@/components/icons' -import { BlockConfig } from '../types/block' +import { BlockConfig } from '../types' export const AgentBlock: BlockConfig = { type: 'agent', diff --git a/blocks/configs/api.ts b/blocks/blocks/api.ts similarity index 95% rename from blocks/configs/api.ts rename to blocks/blocks/api.ts index 3859dc7c09..a94d75fc27 100644 --- a/blocks/configs/api.ts +++ b/blocks/blocks/api.ts @@ -1,5 +1,5 @@ import { ApiIcon } from '@/components/icons' -import { BlockConfig } from '../types/block' +import { BlockConfig } from '../types' export const ApiBlock: BlockConfig = { type: 'api', diff --git a/blocks/configs/function.ts b/blocks/blocks/function.ts similarity index 91% rename from blocks/configs/function.ts rename to blocks/blocks/function.ts index 0a08e70655..efaea96435 100644 --- a/blocks/configs/function.ts +++ b/blocks/blocks/function.ts @@ -1,5 +1,5 @@ import { CodeIcon } from '@/components/icons' -import { BlockConfig } from '../types/block' +import { BlockConfig } from '../types' export const FunctionBlock: BlockConfig = { type: 'function', diff --git a/blocks/configs/index.ts b/blocks/configs/index.ts deleted file mode 100644 index b70c82ae04..0000000000 --- a/blocks/configs/index.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { BlockConfig } from '../types/block' - -// Import blocks -import { AgentBlock } from './agent' -import { ApiBlock } from './api' -import { FunctionBlock } from './function' - -// Export blocks for ease of use -export { AgentBlock, ApiBlock, FunctionBlock } - -// Combined blocks registry -export const BLOCKS: BlockConfig[] = [ - AgentBlock, - ApiBlock, - FunctionBlock, -] - -// Helper functions -export const getBlock = (type: string): BlockConfig | undefined => - BLOCKS.find(block => block.type === type) - -export const getBlocksByCategory = (category: 'basic' | 'advanced'): BlockConfig[] => - BLOCKS.filter(block => block.toolbar.category === category) - -export const getAllBlockTypes = (): string[] => - BLOCKS.map(block => block.type) - -export const isValidBlockType = (type: string): type is string => - BLOCKS.some(block => block.type === type) \ No newline at end of file diff --git a/blocks/index.ts b/blocks/index.ts index 67ec91bbbf..b26c51b2f8 100644 --- a/blocks/index.ts +++ b/blocks/index.ts @@ -1,2 +1,29 @@ -export * from './types/block' -export * from './configs' \ No newline at end of file +import { BlockConfig } from './types' + +// Import blocks +import { AgentBlock } from './blocks/agent' +import { ApiBlock } from './blocks/api' +import { FunctionBlock } from './blocks/function' + +// Export blocks for ease of use +export { AgentBlock, ApiBlock, FunctionBlock } + +// Combined blocks registry +export const BLOCKS: BlockConfig[] = [ + AgentBlock, + ApiBlock, + FunctionBlock, +] + +// Helper functions +export const getBlock = (type: string): BlockConfig | undefined => + BLOCKS.find(block => block.type === type) + +export const getBlocksByCategory = (category: 'basic' | 'advanced'): BlockConfig[] => + BLOCKS.filter(block => block.toolbar.category === category) + +export const getAllBlockTypes = (): string[] => + BLOCKS.map(block => block.type) + +export const isValidBlockType = (type: string): type is string => + BLOCKS.some(block => block.type === type) \ No newline at end of file diff --git a/blocks/types/block.ts b/blocks/types.ts similarity index 100% rename from blocks/types/block.ts rename to blocks/types.ts diff --git a/stores/workflow/types.ts b/stores/workflow/types.ts index ae15a66e99..141db2b1fc 100644 --- a/stores/workflow/types.ts +++ b/stores/workflow/types.ts @@ -1,5 +1,5 @@ import { Node, Edge } from 'reactflow' -import { OutputType, SubBlockType } from '@/blocks/types/block' +import { OutputType, SubBlockType } from '@/blocks/block' export interface Position { x: number diff --git a/stores/workflow/workflow-store.ts b/stores/workflow/workflow-store.ts index 45a3f68648..76618e9e0f 100644 --- a/stores/workflow/workflow-store.ts +++ b/stores/workflow/workflow-store.ts @@ -2,7 +2,7 @@ import { create } from 'zustand' import { devtools } from 'zustand/middleware' import { Edge } from 'reactflow' import { Position, WorkflowStore } from './types' -import { getBlock } from '@/blocks/configs' +import { getBlock } from '@/blocks' const initialState = { blocks: {},