mirror of
https://github.com/simstudioai/sim.git
synced 2026-09-24 15:45:35 +08:00
Moved tools property out of workflows in block definitions, updated serializer & tests accordingly
This commit is contained in:
+20
-20
@@ -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'
|
||||
},
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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
@@ -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
@@ -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>
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user