Moved tools property out of workflows in block definitions, updated serializer & tests accordingly

This commit is contained in:
Waleed Latif
2025-01-19 01:29:48 -08:00
parent 9b59d68209
commit 2f3fa0c059
8 changed files with 125 additions and 80 deletions
+20 -20
View File
@@ -19,6 +19,26 @@ export const AgentBlock: BlockConfig = {
icon: AgentIcon,
category: 'basic',
},
tools: {
access: ['openai.chat', 'anthropic.chat', 'google.chat', 'xai.chat'],
config: {
tool: (params: Record<string, any>) => {
const model = params.model || 'gpt-4o';
if (!model) {
throw new Error('No model selected');
}
const tool = MODEL_TOOLS[model as keyof typeof MODEL_TOOLS];
if (!tool) {
throw new Error(`Invalid model selected: ${model}`);
}
return tool;
}
}
},
workflow: {
outputType: {
default: 'string',
@@ -30,26 +50,6 @@ export const AgentBlock: BlockConfig = {
}
}
},
tools: {
access: ['openai.chat', 'anthropic.chat', 'google.chat', 'xai.chat'],
config: {
tool: (params: Record<string, any>) => {
const model = params.model || 'gpt-4o';
if (!model) {
throw new Error('No model selected');
}
const tool = MODEL_TOOLS[model as keyof typeof MODEL_TOOLS];
if (!tool) {
throw new Error(`Invalid model selected: ${model}`);
}
return tool;
}
}
},
inputs: {
systemPrompt: 'string'
},
+3 -3
View File
@@ -10,11 +10,11 @@ export const ApiBlock: BlockConfig = {
icon: ApiIcon,
category: 'basic',
},
tools: {
access: ['http.request']
},
workflow: {
outputType: 'json',
tools: {
access: ['http.request']
},
inputs: {
url: 'string',
method: 'string',
+3 -3
View File
@@ -10,11 +10,11 @@ export const FunctionBlock: BlockConfig = {
icon: CodeIcon,
category: 'advanced',
},
tools: {
access: ['function']
},
workflow: {
outputType: 'json',
tools: {
access: ['function']
},
inputs: {
code: 'string'
},
+21 -10
View File
@@ -8,22 +8,33 @@ 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,
]
// Registry of all block configurations
const blocks: Record<string, BlockConfig> = {
agent: AgentBlock,
api: ApiBlock,
function: FunctionBlock
}
// 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.find(block => block.type === type)
blocks[type]
export const getBlockTypeForTool = (toolId: string): string | undefined =>
toolToBlockType[toolId]
export const getBlocksByCategory = (category: 'basic' | 'advanced'): BlockConfig[] =>
BLOCKS.filter(block => block.toolbar.category === category)
Object.values(blocks).filter(block => block.toolbar.category === category)
export const getAllBlockTypes = (): string[] =>
BLOCKS.map(block => block.type)
Object.keys(blocks)
export const isValidBlockType = (type: string): type is string =>
BLOCKS.some(block => block.type === type)
type in blocks
+6 -6
View File
@@ -42,15 +42,15 @@ export interface BlockConfig {
icon: BlockIcon
category: BlockCategory
}
tools: {
access: string[]
config?: {
tool: (params: Record<string, any>) => string
}
}
workflow: {
outputType: OutputTypeConfig
subBlocks: SubBlockConfig[]
tools: {
access: string[]
config?: {
tool: (params: Record<string, any>) => string
}
}
inputs?: Record<string, ParamType>
}
}