6.0 KiB
Phase 34 Plan 03 - Store Integration and ChatPanel Wiring - Summary
Status: ✅ Complete Date: 2026-01-30 Execution: Human-verified checkpoint (approved)
Objective
Wire applyEditOperations into workflowStore and integrate ChatPanel with tool invocation handling. Enable the chat UI to process LLM tool calls (createWorkflow, editWorkflow) and apply workflow mutations, completing the full agentic workflow editing pipeline.
Tasks Completed
Task 1: Add applyEditOperations to workflowStore and wire ChatPanel ✅
Commit: f5c4830
Modified three files:
workflowStore.ts:
- Added
EditOperationimport fromlib/chat/editOperations - Added
applyEditOperationsaction method that wraps the library function - Applies edit operations with access to store state (nodes, edges, updateNodeData, etc.)
- Returns
ApplyEditResultwith applied count and skipped operations
ChatPanel.tsx:
- Added
onApplyEditsprop:(operations: EditOperation[], explanation: string) => void - Added
workflowStateprop:{ nodes: Node[], edges: Edge[] }for context-aware requests - Created custom
fetchwrapper to injectworkflowStateinto POST body- Merges
workflowStatewith request body from AI SDK - Preserves AI SDK's default fetch behavior for all other requests
- Merges
- Added
useEffectto process tool invocations whenstate === "output-available"- Extracts tool parts using
part.type === "tool-{name}"pattern (AI SDK v6) - Handles
createWorkflowtool: calls/api/quickstartwith description - Handles
editWorkflowtool: callsonApplyEdits(operations, explanation)
- Extracts tool parts using
- Enhanced message rendering:
- Tool invocation parts display with green/blue text indicators
- Shows tool name and formatted arguments inline
WorkflowCanvas.tsx:
- Added
chatWorkflowStatememo that strips base64 data from nodes/edges- Uses
buildWorkflowContextlogic to remove image/outputImage fields - Keeps workflow structure for LLM context without payload bloat
- Uses
- Added
handleApplyEditscallback:- Captures workflow snapshot via
captureSnapshot()before applying AI edits - Calls
workflowStore.applyEditOperations(operations) - Logs applied/skipped operations to console
- Captures workflow snapshot via
- Passes
onApplyEdits={handleApplyEdits}andworkflowState={chatWorkflowState}to ChatPanel
Task 2: Checkpoint human-verify ✅
Status: APPROVED by user
Human verification confirmed:
- Tool invocations display correctly in chat UI
- createWorkflow tool successfully generates workflows via quickstart API
- editWorkflow tool successfully applies edit operations to store
- Workflow context stripped of base64 data in API requests
- Snapshot captured before AI edits (manual changes can still clear it)
Verification
- ✅ Tool invocations render inline with clear indicators
- ✅ createWorkflow tool calls /api/quickstart and loads result
- ✅ editWorkflow tool applies operations via store
- ✅ workflowState passed to API for context-aware routing
- ✅ Snapshot captured before AI edits (not after - AI edits don't count as manual)
- ✅ Custom fetch wrapper preserves AI SDK behavior while injecting extra data
Files Modified
-
src/store/workflowStore.ts- Added
EditOperationimport - Added
applyEditOperationsaction method
- Added
-
src/components/ChatPanel.tsx- Added
onApplyEditsandworkflowStateprops - Custom fetch wrapper for workflowState injection
- Tool invocation processing via useEffect
- Enhanced message rendering for tool display
- Added
-
src/components/WorkflowCanvas.tsx- Added
chatWorkflowStatememo (strips base64) - Added
handleApplyEditscallback (captures snapshot) - Passes new props to ChatPanel
- Added
Deviations
Custom fetch wrapper instead of body option:
- Plan specified using
bodyoption with useChat hook - AI SDK v6
DefaultChatTransportdoesn't supportbodydirectly - Solution: Custom fetch wrapper that merges workflowState into POST body
- Preserves all AI SDK default behavior while injecting extra data
Tool invocation part structure:
- Plan referenced
toolNameandargsproperties - AI SDK v6 uses
part.type === "tool-{name}"pattern withinputproperty - Adapted code to match actual AI SDK v6 message part structure
Tool completion detection:
- Plan referenced checking
state === "result" - AI SDK v6 uses
state === "output-available"for tool completion - Updated useEffect dependency to correct state value
Key Implementation Decisions
-
AI edits do NOT increment manualChangeCount: Only manual user edits (add/remove nodes/edges) clear the snapshot. AI edits preserve the snapshot for undo/comparison.
-
Snapshot timing: Captured BEFORE AI edits via
captureSnapshot(), not after. This preserves pre-AI state for potential rollback. -
Custom fetch pattern: Wrapper function checks for POST requests with body, merges workflowState, passes through everything else unchanged.
-
Tool invocation rendering: Inline display with color-coded indicators (green for createWorkflow, blue for editWorkflow) using
JSON.stringifyfor args. -
Base64 stripping:
chatWorkflowStatememo removes image/outputImage fields from all nodes to keep API request size reasonable while preserving structure. -
Tool state detection: Uses
state === "output-available"and checks for tool parts in final message to trigger processing.
Integration Points
This completes the full agentic workflow editing pipeline:
- ✅ Chat agent library (phase 34 plan 01) - provides tools and edit operations
- ✅ Chat API route (phase 34 plan 02) - handles tool calling via AI SDK
- ✅ Chat UI integration (phase 34 plan 03) - processes tool results and applies edits
Users can now:
- Ask questions about workflow building →
answerQuestiontool - Request new workflows →
createWorkflowtool → quickstart API - Request workflow edits →
editWorkflowtool →applyEditOperations
Next Steps
Phase 34 (Context-Aware Agentic Workflow Editing) is complete. Proceed to next phase in milestone v1.4 or other priorities.