Made reliable type passdown from executor to console

This commit is contained in:
Emir Karabeg
2025-01-31 19:19:03 -08:00
parent 823f89ba74
commit 2b08e2d830
5 changed files with 11 additions and 22 deletions
+4 -14
View File
@@ -15,18 +15,6 @@ jest.mock('@/components/icons', () => ({
// Mock blocks
jest.mock('@/blocks', () => ({
getBlock: jest.fn(),
getBlockTypeForTool: jest.fn((toolId: string) => {
switch (toolId) {
case 'openai.chat':
return 'agent'
case 'http.request':
return 'api'
case 'test-tool':
return 'agent'
default:
return undefined
}
})
}))
describe('Serializer', () => {
@@ -372,8 +360,10 @@ describe('Serializer', () => {
title: 'Agent Block',
description: 'Use any LLM',
category: 'basic',
color: '#7F2FFF'
}
color: '#7F2FFF',
type: 'agent'
},
enabled: true
}
],
connections: []
+5 -4
View File
@@ -1,7 +1,7 @@
import { BlockState, SubBlockState } from '@/stores/workflow/types'
import { Edge } from 'reactflow'
import { SerializedBlock, SerializedConnection, SerializedWorkflow } from './types'
import { getBlock, getBlockTypeForTool } from '@/blocks'
import { getBlock } from '@/blocks'
export class Serializer {
serializeWorkflow(blocks: Record<string, BlockState>, edges: Edge[]): SerializedWorkflow {
@@ -52,7 +52,8 @@ export class Serializer {
title: block.name,
description: blockConfig.toolbar.description,
category: blockConfig.toolbar.category,
color: blockConfig.toolbar.bgColor
color: blockConfig.toolbar.bgColor,
type: block.type
},
enabled: block.enabled
}
@@ -108,9 +109,9 @@ export class Serializer {
}
private deserializeBlock(serializedBlock: SerializedBlock): BlockState {
const blockType = getBlockTypeForTool(serializedBlock.config.tool)
const blockType = serializedBlock.metadata?.type
if (!blockType) {
throw new Error(`Invalid tool ID: ${serializedBlock.config.tool}`)
throw new Error(`Invalid block type: ${serializedBlock.metadata?.type}`)
}
const blockConfig = getBlock(blockType)
+1
View File
@@ -29,6 +29,7 @@ export interface SerializedBlock {
category?: string
icon?: string
color?: string
type: string
}
enabled: boolean
}