MCPcopy Index your code
hub / github.com/simstudioai/sim / migrateAgentParamsToMessages

Function migrateAgentParamsToMessages

apps/sim/serializer/index.ts:95–145  ·  view source on GitHub ↗

* Helper function to migrate agent block params from old format to messages array * Transforms systemPrompt/userPrompt into messages array format * Only migrates if old format exists and new format doesn't (idempotent)

(
  params: Record<string, any>,
  subBlocks: Record<string, any>,
  blockId: string
)

Source from the content-addressed store, hash-verified

93 * Only migrates if old format exists and new format doesn't (idempotent)
94 */
95function migrateAgentParamsToMessages(
96 params: Record<string, any>,
97 subBlocks: Record<string, any>,
98 blockId: string
99): void {
100 // Only migrate if old format exists and new format doesn't
101 if ((params.systemPrompt || params.userPrompt) && !params.messages) {
102 logger.info('Migrating agent block from legacy format to messages array', {
103 blockId,
104 hasSystemPrompt: !!params.systemPrompt,
105 hasUserPrompt: !!params.userPrompt,
106 })
107
108 const messages: any[] = []
109
110 // Add system message first (industry standard)
111 if (params.systemPrompt) {
112 messages.push({
113 role: 'system',
114 content: params.systemPrompt,
115 })
116 }
117
118 // Add user message
119 if (params.userPrompt) {
120 let userContent = params.userPrompt
121
122 // Handle object format (e.g., { input: "..." })
123 if (typeof userContent === 'object' && userContent !== null) {
124 if ('input' in userContent) {
125 userContent = userContent.input
126 } else {
127 // If it's an object but doesn't have 'input', stringify it
128 userContent = JSON.stringify(userContent)
129 }
130 }
131
132 messages.push({
133 role: 'user',
134 content: String(userContent),
135 })
136 }
137
138 // Set the migrated messages in subBlocks
139 subBlocks.messages = {
140 id: 'messages',
141 type: 'messages-input',
142 value: messages,
143 }
144 }
145}
146
147export class Serializer {
148 serializeWorkflow(

Callers 1

deserializeBlockMethod · 0.85

Calls 2

infoMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected