mirror of
https://github.com/simstudioai/sim.git
synced 2026-01-10 07:27:57 -05:00
59 lines
1.7 KiB
TypeScript
59 lines
1.7 KiB
TypeScript
import { BlockConfig } from './types'
|
|
|
|
// Import blocks
|
|
import { AgentBlock } from './blocks/agent'
|
|
import { ApiBlock } from './blocks/api'
|
|
import { FunctionBlock } from './blocks/function'
|
|
import { CrewAIVisionBlock } from './blocks/crewai'
|
|
import { FirecrawlScrapeBlock } from './blocks/firecrawl'
|
|
import { JinaBlock } from './blocks/jina'
|
|
import { TranslateBlock } from './blocks/translate'
|
|
|
|
// Export blocks for ease of use
|
|
export {
|
|
AgentBlock,
|
|
ApiBlock,
|
|
FunctionBlock,
|
|
CrewAIVisionBlock,
|
|
FirecrawlScrapeBlock,
|
|
JinaBlock,
|
|
TranslateBlock
|
|
}
|
|
|
|
// Registry of all block configurations
|
|
const blocks: Record<string, BlockConfig> = {
|
|
agent: AgentBlock,
|
|
api: ApiBlock,
|
|
function: FunctionBlock,
|
|
crewai_vision: CrewAIVisionBlock,
|
|
firecrawl_scrape: FirecrawlScrapeBlock,
|
|
jina_reader: JinaBlock,
|
|
translate: TranslateBlock
|
|
}
|
|
|
|
// Build a reverse mapping of tools to block types
|
|
const toolToBlockType = Object.entries(blocks).reduce((acc, [blockType, config]) => {
|
|
config.tools.access.forEach(toolId => {
|
|
acc[toolId] = blockType
|
|
})
|
|
return acc
|
|
}, {} as Record<string, string>)
|
|
|
|
// Helper functions
|
|
export const getBlock = (type: string): BlockConfig | undefined =>
|
|
blocks[type]
|
|
|
|
export const getBlockTypeForTool = (toolId: string): string | undefined =>
|
|
toolToBlockType[toolId]
|
|
|
|
export const getBlocksByCategory = (category: 'basic' | 'advanced'): BlockConfig[] =>
|
|
Object.values(blocks).filter(block => block.toolbar.category === category)
|
|
|
|
export const getAllBlockTypes = (): string[] =>
|
|
Object.keys(blocks)
|
|
|
|
export const isValidBlockType = (type: string): type is string =>
|
|
type in blocks
|
|
|
|
export const getAllBlocks = (): BlockConfig[] =>
|
|
Object.values(blocks) |