docs/user_guide/en/ws_frontend_logic.md
Variables:
status.value = 'Completed' or 'Cancelled'isWorkflowRunning.value = falseshouldGlow.value = true (set by watch on status)ws = existing WebSocket connection (still open)sessionId = current session IDisConnectionReady.value = trueFunction: watch(selectedFile, (newFile) => {...}) (line 879)
Process:
taskPrompt.value = '' - clears inputfileSearchQuery.value = newFile || '' - updates search queryisFileSearchDirty.value = false - resets search stateFunction: resetConnectionState({ closeSocket: true }) (line 443)
Called at: line 891
What happens:
ws.close() is called (line 446)ws = null (line 452)sessionId = null (line 453)isConnectionReady.value = false (line 454)shouldGlow.value = false (line 455)isWorkflowRunning.value = false (line 456)activeNodes.value = [] (line 457)Status: status.value = 'Connecting...' (line 892)
Function: handleYAMLSelection(newFile) (line 706)
Called at: line 893
What happens:
chatMessages.value = []workflowYaml.valueinitial_instruction as notificationFunction: establishWebSocketConnection() (line 807)
Called at: line 894
What happens:
resetConnectionState() again (line 809) - ensures clean stateconst socket = new WebSocket('ws://localhost:8000/ws') (line 816)ws = socket (line 817)socket.onopen (line 819): Logs "WebSocket connected"socket.onmessage (line 825):
connection message with session_idsessionId (line 832)isConnectionReady.value = true (line 842)shouldGlow.value = true (line 843)status.value = 'Waiting for launch...' (line 844)socket.onerror (line 854): Handles connection errorssocket.onclose (line 864): Handles disconnectionStatus: status.value = 'Waiting for launch...' (after connection message received)
Function: handleButtonClick() (line 740)
Triggered: When Launch button is clicked and status is 'Completed'/'Cancelled'
Condition Check:
else if (status.value === 'Completed' || status.value === 'Cancelled')
Function: resetConnectionState() (line 443)
Called at: line 754
What happens:
ws.close() is calledStatus: status.value = 'Connecting...' (line 755)
Function: handleYAMLSelection(selectedFile.value) (line 706)
Called at: line 756
What happens: Same as Scenario 1, Step 3
Function: establishWebSocketConnection() (line 807)
Called at: line 757
What happens: Same as Scenario 1, Step 4
Status: status.value = 'Waiting for launch...' (after connection message received)
Function: launchWorkflow() (line 1124)
Triggered: When Launch button is clicked and status is 'Waiting for launch...'
Prerequisites Check:
selectedFile.value must existtaskPrompt.value.trim() or attachmentIds.length > 0 must existws, isConnectionReady.value, and sessionId must be validWhat happens:
shouldGlow.value = false (line 1150)status.value = 'Launching...' (line 1151)/api/workflow/execute with:
yaml_file: selected file nametask_prompt: user inputsession_id: current session IDattachments: uploaded attachment IDsstatus.value = 'Running...' (line 1185)isWorkflowRunning.value = true (line 1186)Status: status.value = 'Running...'
| Variable | Type | Purpose | Changes When |
|---|---|---|---|
ws | WebSocket | null | Current WebSocket connection | Set to null on disconnect, new socket on connect |
sessionId | string | null | Current session identifier | Set from connection message, cleared on reset |
isConnectionReady | ref<boolean> | Whether connection is ready for launch | true after connection message, false on reset |
| Variable | Type | Purpose | Values |
|---|---|---|---|
status | ref<string> | Current workflow status | 'Completed', 'Cancelled', 'Connecting...', 'Waiting for launch...', 'Launching...', 'Running...' |
isWorkflowRunning | ref<boolean> | Whether workflow is actively running | true during execution, false otherwise |
shouldGlow | ref<boolean> | UI glow effect state | true when ready for input, false during execution |
| Variable | Type | Purpose |
|---|---|---|
selectedFile | ref<string> | Currently selected YAML file |
workflowYaml | ref<object> | Parsed YAML content |
activeNodes | ref<string[]> | List of currently active node IDs |
chatMessages | ref<array> | All chat messages and notifications |
watch(selectedFile) → resetConnectionState() → ws.close()handleButtonClick() → resetConnectionState() → ws.close()socket.onerror or socket.onclose → resetConnectionState({ closeSocket: false })watch(selectedFile) → establishWebSocketConnection() → new WebSocket()handleButtonClick() → establishWebSocketConnection() → new WebSocket()[Completed/Cancelled]
↓ (File Change or Relaunch)
[Disconnected] → resetConnectionState() closes ws
↓
[Connecting...] → establishWebSocketConnection() creates new ws
↓
[WebSocket.onopen] → socket opened
↓
[WebSocket.onmessage: 'connection'] → sessionId received
↓
[Waiting for launch...] → isConnectionReady = true
↓ (Launch clicked)
[Launching...] → POST /api/workflow/execute
↓
[Running...] → isWorkflowRunning = true
Double Reset Issue: establishWebSocketConnection() calls resetConnectionState() at the start (line 809), which means when called after resetConnectionState() in the caller, it's resetting twice. This is safe but redundant.
Stale Socket Protection: All WebSocket event handlers check if (ws !== socket) return to ignore events from old sockets that were replaced.
Status Transitions: The status goes through these states:
Completed/Cancelled → Connecting... → Waiting for launch... → Launching... → Running...Connection Ready Check: launchWorkflow() verifies ws, isConnectionReady.value, and sessionId before allowing launch.
Automatic Reconnection: Both file change and relaunch automatically establish a new WebSocket connection - no manual reconnection needed.