Implement workflow run event handling and update chat state accordingly
This commit is contained in:
43
src/App.jsx
43
src/App.jsx
@@ -1102,10 +1102,51 @@ export default function App() {
|
|||||||
return buildModelPickerOptions(availableChatModels, model, 'saved model unavailable')
|
return buildModelPickerOptions(availableChatModels, model, 'saved model unavailable')
|
||||||
}, [availableChatModels, model])
|
}, [availableChatModels, model])
|
||||||
|
|
||||||
|
const handleWorkflowRunEvent = React.useCallback((sessionId, event) => {
|
||||||
|
setWorkflowExecutions(previous => {
|
||||||
|
const current = previous[sessionId] || {
|
||||||
|
runId: event.run_id,
|
||||||
|
workflowName: event.payload?.workflow?.name || 'Workflow',
|
||||||
|
status: 'running',
|
||||||
|
startedAt: Date.now(),
|
||||||
|
events: [],
|
||||||
|
}
|
||||||
|
let status = current.status
|
||||||
|
let finishedAt = current.finishedAt
|
||||||
|
if (event.type === 'client_run_started') {
|
||||||
|
status = 'running'
|
||||||
|
} else if (event.type === 'run_completed') {
|
||||||
|
status = 'completed'
|
||||||
|
finishedAt = Date.now()
|
||||||
|
} else if (event.type === 'run_failed') {
|
||||||
|
status = 'failed'
|
||||||
|
finishedAt = Date.now()
|
||||||
|
} else if (event.type === 'run_cancelled') {
|
||||||
|
status = 'cancelled'
|
||||||
|
finishedAt = Date.now()
|
||||||
|
} else if (event.type === 'confirmation_required') {
|
||||||
|
status = 'waiting_confirmation'
|
||||||
|
setPendingWorkflowConfirmation({ ...event, sessionId })
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
...previous,
|
||||||
|
[sessionId]: {
|
||||||
|
...current,
|
||||||
|
runId: event.run_id || current.runId,
|
||||||
|
workflowName: event.payload?.workflow?.name || current.workflowName,
|
||||||
|
status,
|
||||||
|
finishedAt,
|
||||||
|
events: [...(current.events || []), event].slice(-120),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}, [])
|
||||||
|
|
||||||
const { regenerateFromIndex, sendMessage } = createChatGenerationHandlers({
|
const { regenerateFromIndex, sendMessage } = createChatGenerationHandlers({
|
||||||
activeSessionId,
|
activeSessionId,
|
||||||
activeSessionIdRef,
|
activeSessionIdRef,
|
||||||
backendApiUrl,
|
backendApiUrl,
|
||||||
|
attachWorkflowRunToRequest,
|
||||||
beginCancelableRequest,
|
beginCancelableRequest,
|
||||||
canAttachImages,
|
canAttachImages,
|
||||||
chatSessions,
|
chatSessions,
|
||||||
@@ -1113,11 +1154,13 @@ export default function App() {
|
|||||||
createNewChat,
|
createNewChat,
|
||||||
finishCancelableRequest,
|
finishCancelableRequest,
|
||||||
getChatLibraryForSession,
|
getChatLibraryForSession,
|
||||||
|
getChatWorkflowForSession,
|
||||||
imageAttachmentUnavailableReason,
|
imageAttachmentUnavailableReason,
|
||||||
input,
|
input,
|
||||||
isSending,
|
isSending,
|
||||||
model,
|
model,
|
||||||
onMessagesPersisted: fetchHistory,
|
onMessagesPersisted: fetchHistory,
|
||||||
|
onWorkflowRunEvent: handleWorkflowRunEvent,
|
||||||
restoredForRef,
|
restoredForRef,
|
||||||
scrollMessageToTop,
|
scrollMessageToTop,
|
||||||
scrollToBottom,
|
scrollToBottom,
|
||||||
|
|||||||
Reference in New Issue
Block a user