Skip to content

Commit 60e326f

Browse files
committed
edit existing workflow should bring up artifact
1 parent 68909e7 commit 60e326f

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ export function useChat(workspaceId: string, initialChatId?: string): UseChatRet
463463
queryClient.invalidateQueries({ queryKey: tableKeys.rowsRoot(resource.id) })
464464
}
465465
} else if (toolName === 'create_workflow' || toolName === 'edit_workflow') {
466-
resource = extractWorkflowResource(parsed, lastWorkflowId)
466+
resource = extractWorkflowResource(parsed, lastWorkflowId, storedArgs)
467467
if (resource) {
468468
lastWorkflowId = resource.id
469469
const registry = useWorkflowRegistry.getState()

apps/sim/app/workspace/[workspaceId]/home/utils.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,22 @@ export function extractFunctionExecuteResource(
9898

9999
export function extractWorkflowResource(
100100
parsed: SSEPayload,
101-
fallbackWorkflowId: string | null
101+
fallbackWorkflowId: string | null,
102+
storedArgs?: Record<string, unknown>
102103
): MothershipResource | null {
103104
const topResult = getTopResult(parsed)
104105
const data = topResult?.data as Record<string, unknown> | undefined
105106

106107
const workflowId =
107-
(topResult?.workflowId as string) ?? (data?.workflowId as string) ?? fallbackWorkflowId
108+
(topResult?.workflowId as string) ??
109+
(data?.workflowId as string) ??
110+
(storedArgs?.workflowId as string) ??
111+
fallbackWorkflowId
108112
const workflowName =
109-
(topResult?.workflowName as string) ?? (data?.workflowName as string) ?? 'Workflow'
113+
(topResult?.workflowName as string) ??
114+
(data?.workflowName as string) ??
115+
(storedArgs?.workflowName as string) ??
116+
'Workflow'
110117

111118
if (workflowId) return { type: 'workflow', id: workflowId, title: workflowName }
112119

@@ -204,7 +211,7 @@ export function extractResourcesFromHistory(messages: TaskStoredMessage[]): Moth
204211
resource = extractFunctionExecuteResource(payload, args)
205212
if (resource?.type === 'table') lastTableId = resource.id
206213
} else if (tc.name === 'create_workflow' || tc.name === 'edit_workflow') {
207-
resource = extractWorkflowResource(payload, lastWorkflowId)
214+
resource = extractWorkflowResource(payload, lastWorkflowId, args)
208215
if (resource) lastWorkflowId = resource.id
209216
} else if (tc.name === 'knowledge_base') {
210217
resource = extractKnowledgeBaseResource(payload, args)

apps/sim/lib/copilot/tools/server/workflow/edit-workflow/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,18 @@ export const editWorkflowServerTool: BaseServerTool<EditWorkflowParams, unknown>
137137
// Add credential validation errors
138138
validationErrors.push(...credentialErrors)
139139

140-
// Get workspaceId for selector validation
141140
let workspaceId: string | undefined
141+
let workflowName: string | undefined
142142
try {
143143
const [workflowRecord] = await db
144-
.select({ workspaceId: workflowTable.workspaceId })
144+
.select({ workspaceId: workflowTable.workspaceId, name: workflowTable.name })
145145
.from(workflowTable)
146146
.where(eq(workflowTable.id, workflowId))
147147
.limit(1)
148148
workspaceId = workflowRecord?.workspaceId ?? undefined
149+
workflowName = workflowRecord?.name ?? undefined
149150
} catch (error) {
150-
logger.warn('Failed to get workspaceId for selector validation', { error, workflowId })
151+
logger.warn('Failed to get workflow metadata for validation', { error, workflowId })
151152
}
152153

153154
// Validate selector IDs exist in the database
@@ -279,16 +280,15 @@ export const editWorkflowServerTool: BaseServerTool<EditWorkflowParams, unknown>
279280

280281
logger.info('Workflow state persisted to database', { workflowId })
281282

282-
// Return the modified workflow state with autolayout applied
283283
return {
284284
success: true,
285+
workflowId,
286+
workflowName: workflowName ?? 'Workflow',
285287
workflowState: { ...finalWorkflowState, blocks: layoutedBlocks },
286-
// Include input validation errors so the LLM can see what was rejected
287288
...(inputErrors && {
288289
inputValidationErrors: inputErrors,
289290
inputValidationMessage: `${inputErrors.length} input(s) were rejected due to validation errors. The workflow was still updated with valid inputs only. Errors: ${inputErrors.join('; ')}`,
290291
}),
291-
// Include skipped items so the LLM can see what operations were skipped
292292
...(skippedMessages && {
293293
skippedItems: skippedMessages,
294294
skippedItemsMessage: `${skippedItems.length} operation(s) were skipped due to invalid references. Details: ${skippedMessages.join('; ')}`,

0 commit comments

Comments
 (0)