mirror of
https://github.com/simstudioai/sim.git
synced 2026-09-24 15:45:35 +08:00
feature(console): stream console messages back from executor
This commit is contained in:
@@ -14,7 +14,7 @@ export function useWorkflowExecution() {
|
||||
const { blocks, edges, loops } = useWorkflowStore()
|
||||
const { activeWorkflowId } = useWorkflowRegistry()
|
||||
const { addNotification } = useNotificationStore()
|
||||
const { addConsole, toggleConsole, isOpen } = useConsoleStore()
|
||||
const { toggleConsole, isOpen } = useConsoleStore()
|
||||
const { getAllVariables } = useEnvironmentStore()
|
||||
|
||||
const handleRunWorkflow = useCallback(async () => {
|
||||
@@ -52,42 +52,11 @@ export function useWorkflowExecution() {
|
||||
// Execute workflow
|
||||
const workflow = new Serializer().serializeWorkflow(blocks, edges, loops)
|
||||
const executor = new Executor(workflow, currentBlockStates, envVarValues)
|
||||
const result = await executor.execute(activeWorkflowId)
|
||||
|
||||
const result = await executor.execute('my-run-id')
|
||||
setExecutionResult(result)
|
||||
|
||||
// Add console entries for each block execution
|
||||
if (result.logs) {
|
||||
result.logs.forEach((log) => {
|
||||
addConsole({
|
||||
output: log.output,
|
||||
error: log.error,
|
||||
durationMs: log.durationMs,
|
||||
startedAt: log.startedAt,
|
||||
endedAt: log.endedAt,
|
||||
workflowId: activeWorkflowId,
|
||||
timestamp: log.startedAt,
|
||||
blockName: log.blockName,
|
||||
blockType: log.blockType,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
if (result.logs) {
|
||||
console.group('Detailed Block Logs')
|
||||
result.logs.forEach((log) => {
|
||||
console.log(`Block ${log.blockName}: Success=${log.success}`, {
|
||||
output: log.output,
|
||||
error: log.error,
|
||||
durationMs: log.durationMs,
|
||||
startedAt: log.startedAt,
|
||||
endedAt: log.endedAt,
|
||||
})
|
||||
})
|
||||
console.groupEnd()
|
||||
}
|
||||
|
||||
// Show execution result with workflowId
|
||||
// Show execution result notification
|
||||
addNotification(
|
||||
result.success ? 'console' : 'error',
|
||||
result.success
|
||||
@@ -95,7 +64,7 @@ export function useWorkflowExecution() {
|
||||
: `Workflow execution failed: ${result.error}`,
|
||||
activeWorkflowId
|
||||
)
|
||||
} catch (error) {
|
||||
} catch (error: any) {
|
||||
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
||||
setExecutionResult({
|
||||
success: false,
|
||||
@@ -104,18 +73,6 @@ export function useWorkflowExecution() {
|
||||
logs: [],
|
||||
})
|
||||
|
||||
// Add error entry to console
|
||||
addConsole({
|
||||
output: {},
|
||||
error: errorMessage,
|
||||
durationMs: -1,
|
||||
startedAt: new Date().toISOString(),
|
||||
endedAt: new Date().toISOString(),
|
||||
workflowId: activeWorkflowId,
|
||||
timestamp: new Date().toISOString(),
|
||||
blockName: 'Error',
|
||||
})
|
||||
|
||||
addNotification('error', `Workflow execution failed: ${errorMessage}`, activeWorkflowId)
|
||||
} finally {
|
||||
setIsExecuting(false)
|
||||
@@ -124,8 +81,8 @@ export function useWorkflowExecution() {
|
||||
activeWorkflowId,
|
||||
blocks,
|
||||
edges,
|
||||
loops,
|
||||
addNotification,
|
||||
addConsole,
|
||||
isOpen,
|
||||
toggleConsole,
|
||||
getAllVariables,
|
||||
|
||||
+31
-1
@@ -1,3 +1,4 @@
|
||||
import { useConsoleStore } from '@/stores/console/store'
|
||||
import { getAllBlocks } from '@/blocks'
|
||||
import { generateRouterPrompt } from '@/blocks/blocks/router'
|
||||
import { BlockOutput } from '@/blocks/types'
|
||||
@@ -433,6 +434,7 @@ export class Executor {
|
||||
}
|
||||
|
||||
const blockLog = this.startBlockLog(block)
|
||||
const addConsole = useConsoleStore.getState().addConsole
|
||||
|
||||
try {
|
||||
let output: BlockOutput
|
||||
@@ -579,18 +581,46 @@ export class Executor {
|
||||
output = { response: result.output }
|
||||
}
|
||||
|
||||
// Log success
|
||||
blockLog.success = true
|
||||
blockLog.output = output
|
||||
this.finalizeBlockLog(blockLog)
|
||||
context.blockLogs.push(blockLog)
|
||||
|
||||
// Add to console immediately
|
||||
addConsole({
|
||||
output: blockLog.output,
|
||||
durationMs: blockLog.durationMs,
|
||||
startedAt: blockLog.startedAt,
|
||||
endedAt: blockLog.endedAt,
|
||||
workflowId: context.workflowId,
|
||||
timestamp: blockLog.startedAt,
|
||||
blockName: block.metadata?.name || 'Unnamed Block',
|
||||
blockType: block.metadata?.id || 'unknown',
|
||||
})
|
||||
|
||||
context.blockStates.set(block.id, output)
|
||||
return output
|
||||
} catch (error: any) {
|
||||
// Log error
|
||||
blockLog.success = false
|
||||
blockLog.error = error.message || 'Block execution failed'
|
||||
blockLog.error = error.message
|
||||
this.finalizeBlockLog(blockLog)
|
||||
context.blockLogs.push(blockLog)
|
||||
|
||||
// Add error to console immediately
|
||||
addConsole({
|
||||
output: {},
|
||||
error: error.message,
|
||||
durationMs: blockLog.durationMs,
|
||||
startedAt: blockLog.startedAt,
|
||||
endedAt: blockLog.endedAt,
|
||||
workflowId: context.workflowId,
|
||||
timestamp: blockLog.startedAt,
|
||||
blockName: block.metadata?.name || 'Unnamed Block',
|
||||
blockType: block.metadata?.id || 'unknown',
|
||||
})
|
||||
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user