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

View File

@@ -43,8 +43,6 @@ const toolToBlockType = Object.entries(blocks).reduce((acc, [blockType, config])
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)

View File

@@ -18,7 +18,6 @@ import {
BlockLog
} from './types'
import { tools } from '@/tools'
import { getBlockTypeForTool } from '@/blocks'
export class Executor {
constructor(
@@ -126,7 +125,7 @@ export class Executor {
const blockLog: Partial<BlockLog> = {
blockId: block.id,
blockTitle: block.metadata?.title,
blockType: getBlockTypeForTool(block.config.tool || ''),
blockType: block.metadata?.type,
startedAt: new Date().toISOString(),
}

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: []

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)

View File

@@ -29,6 +29,7 @@ export interface SerializedBlock {
category?: string
icon?: string
color?: string
type: string
}
enabled: boolean
}