mirror of
https://github.com/simstudioai/sim.git
synced 2026-04-06 03:00:16 -04:00
edit existing workflow should bring up artifact
This commit is contained in:
@@ -463,7 +463,7 @@ export function useChat(workspaceId: string, initialChatId?: string): UseChatRet
|
||||
queryClient.invalidateQueries({ queryKey: tableKeys.rowsRoot(resource.id) })
|
||||
}
|
||||
} else if (toolName === 'create_workflow' || toolName === 'edit_workflow') {
|
||||
resource = extractWorkflowResource(parsed, lastWorkflowId)
|
||||
resource = extractWorkflowResource(parsed, lastWorkflowId, storedArgs)
|
||||
if (resource) {
|
||||
lastWorkflowId = resource.id
|
||||
const registry = useWorkflowRegistry.getState()
|
||||
|
||||
@@ -98,15 +98,22 @@ export function extractFunctionExecuteResource(
|
||||
|
||||
export function extractWorkflowResource(
|
||||
parsed: SSEPayload,
|
||||
fallbackWorkflowId: string | null
|
||||
fallbackWorkflowId: string | null,
|
||||
storedArgs?: Record<string, unknown>
|
||||
): MothershipResource | null {
|
||||
const topResult = getTopResult(parsed)
|
||||
const data = topResult?.data as Record<string, unknown> | undefined
|
||||
|
||||
const workflowId =
|
||||
(topResult?.workflowId as string) ?? (data?.workflowId as string) ?? fallbackWorkflowId
|
||||
(topResult?.workflowId as string) ??
|
||||
(data?.workflowId as string) ??
|
||||
(storedArgs?.workflowId as string) ??
|
||||
fallbackWorkflowId
|
||||
const workflowName =
|
||||
(topResult?.workflowName as string) ?? (data?.workflowName as string) ?? 'Workflow'
|
||||
(topResult?.workflowName as string) ??
|
||||
(data?.workflowName as string) ??
|
||||
(storedArgs?.workflowName as string) ??
|
||||
'Workflow'
|
||||
|
||||
if (workflowId) return { type: 'workflow', id: workflowId, title: workflowName }
|
||||
|
||||
@@ -204,7 +211,7 @@ export function extractResourcesFromHistory(messages: TaskStoredMessage[]): Moth
|
||||
resource = extractFunctionExecuteResource(payload, args)
|
||||
if (resource?.type === 'table') lastTableId = resource.id
|
||||
} else if (tc.name === 'create_workflow' || tc.name === 'edit_workflow') {
|
||||
resource = extractWorkflowResource(payload, lastWorkflowId)
|
||||
resource = extractWorkflowResource(payload, lastWorkflowId, args)
|
||||
if (resource) lastWorkflowId = resource.id
|
||||
} else if (tc.name === 'knowledge_base') {
|
||||
resource = extractKnowledgeBaseResource(payload, args)
|
||||
|
||||
@@ -137,17 +137,18 @@ export const editWorkflowServerTool: BaseServerTool<EditWorkflowParams, unknown>
|
||||
// Add credential validation errors
|
||||
validationErrors.push(...credentialErrors)
|
||||
|
||||
// Get workspaceId for selector validation
|
||||
let workspaceId: string | undefined
|
||||
let workflowName: string | undefined
|
||||
try {
|
||||
const [workflowRecord] = await db
|
||||
.select({ workspaceId: workflowTable.workspaceId })
|
||||
.select({ workspaceId: workflowTable.workspaceId, name: workflowTable.name })
|
||||
.from(workflowTable)
|
||||
.where(eq(workflowTable.id, workflowId))
|
||||
.limit(1)
|
||||
workspaceId = workflowRecord?.workspaceId ?? undefined
|
||||
workflowName = workflowRecord?.name ?? undefined
|
||||
} catch (error) {
|
||||
logger.warn('Failed to get workspaceId for selector validation', { error, workflowId })
|
||||
logger.warn('Failed to get workflow metadata for validation', { error, workflowId })
|
||||
}
|
||||
|
||||
// Validate selector IDs exist in the database
|
||||
@@ -279,16 +280,15 @@ export const editWorkflowServerTool: BaseServerTool<EditWorkflowParams, unknown>
|
||||
|
||||
logger.info('Workflow state persisted to database', { workflowId })
|
||||
|
||||
// Return the modified workflow state with autolayout applied
|
||||
return {
|
||||
success: true,
|
||||
workflowId,
|
||||
workflowName: workflowName ?? 'Workflow',
|
||||
workflowState: { ...finalWorkflowState, blocks: layoutedBlocks },
|
||||
// Include input validation errors so the LLM can see what was rejected
|
||||
...(inputErrors && {
|
||||
inputValidationErrors: inputErrors,
|
||||
inputValidationMessage: `${inputErrors.length} input(s) were rejected due to validation errors. The workflow was still updated with valid inputs only. Errors: ${inputErrors.join('; ')}`,
|
||||
}),
|
||||
// Include skipped items so the LLM can see what operations were skipped
|
||||
...(skippedMessages && {
|
||||
skippedItems: skippedMessages,
|
||||
skippedItemsMessage: `${skippedItems.length} operation(s) were skipped due to invalid references. Details: ${skippedMessages.join('; ')}`,
|
||||
|
||||
Reference in New Issue
Block a user