mirror of
https://github.com/simstudioai/sim.git
synced 2026-04-06 03:00:16 -04:00
v0.5.9: add backwards compatibility for agent messages array
This commit is contained in:
@@ -961,5 +961,58 @@ describe('Serializer', () => {
|
||||
// Unknown fields are filtered out (no subblock config found, so shouldIncludeField is not called)
|
||||
expect(slackBlock?.config.params.unknownField).toBeUndefined()
|
||||
})
|
||||
|
||||
it.concurrent(
|
||||
'should preserve legacy agent fields (systemPrompt, userPrompt, memories) for backward compatibility',
|
||||
() => {
|
||||
const serializer = new Serializer()
|
||||
|
||||
// Simulate an old workflow with legacy agent block format (before messages array migration)
|
||||
const legacyAgentBlock: any = {
|
||||
id: 'agent-1',
|
||||
type: 'agent',
|
||||
name: 'Legacy Agent',
|
||||
position: { x: 0, y: 0 },
|
||||
advancedMode: false,
|
||||
subBlocks: {
|
||||
systemPrompt: {
|
||||
id: 'systemPrompt',
|
||||
type: 'long-input',
|
||||
value: 'You are a helpful assistant.',
|
||||
},
|
||||
userPrompt: {
|
||||
id: 'userPrompt',
|
||||
type: 'long-input',
|
||||
value: 'What is the weather today?',
|
||||
},
|
||||
memories: {
|
||||
id: 'memories',
|
||||
type: 'short-input',
|
||||
value: [{ role: 'user', content: 'My name is Alice' }],
|
||||
},
|
||||
model: {
|
||||
id: 'model',
|
||||
type: 'combobox',
|
||||
value: 'gpt-4',
|
||||
},
|
||||
},
|
||||
outputs: {},
|
||||
enabled: true,
|
||||
}
|
||||
|
||||
const serialized = serializer.serializeWorkflow({ 'agent-1': legacyAgentBlock }, [], {})
|
||||
|
||||
const agentBlock = serialized.blocks.find((b) => b.id === 'agent-1')
|
||||
expect(agentBlock).toBeDefined()
|
||||
|
||||
// Legacy fields should be preserved even though they're not in the current block config
|
||||
expect(agentBlock?.config.params.systemPrompt).toBe('You are a helpful assistant.')
|
||||
expect(agentBlock?.config.params.userPrompt).toBe('What is the weather today?')
|
||||
expect(agentBlock?.config.params.memories).toEqual([
|
||||
{ role: 'user', content: 'My name is Alice' },
|
||||
])
|
||||
expect(agentBlock?.config.params.model).toBe('gpt-4')
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -422,6 +422,7 @@ export class Serializer {
|
||||
const params: Record<string, any> = {}
|
||||
const isAdvancedMode = block.advancedMode ?? false
|
||||
const isStarterBlock = block.type === 'starter'
|
||||
const isAgentBlock = block.type === 'agent'
|
||||
|
||||
// First collect all current values from subBlocks, filtering by mode
|
||||
Object.entries(block.subBlocks).forEach(([id, subBlock]) => {
|
||||
@@ -435,9 +436,15 @@ export class Serializer {
|
||||
Array.isArray(subBlock.value) &&
|
||||
subBlock.value.length > 0
|
||||
|
||||
// Include legacy agent block fields (systemPrompt, userPrompt, memories) even if not in current config
|
||||
// This ensures backward compatibility with old workflows that were exported before the messages array migration
|
||||
const isLegacyAgentField =
|
||||
isAgentBlock && ['systemPrompt', 'userPrompt', 'memories'].includes(id)
|
||||
|
||||
if (
|
||||
subBlockConfig &&
|
||||
(shouldIncludeField(subBlockConfig, isAdvancedMode) || hasStarterInputFormatValues)
|
||||
(subBlockConfig &&
|
||||
(shouldIncludeField(subBlockConfig, isAdvancedMode) || hasStarterInputFormatValues)) ||
|
||||
isLegacyAgentField
|
||||
) {
|
||||
params[id] = subBlock.value
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user