You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

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 EditOperation import from lib/chat/editOperations
  • Added applyEditOperations action method that wraps the library function
  • Applies edit operations with access to store state (nodes, edges, updateNodeData, etc.)
  • Returns ApplyEditResult with applied count and skipped operations

ChatPanel.tsx:

  • Added onApplyEdits prop: (operations: EditOperation[], explanation: string) => void
  • Added workflowState prop: { nodes: Node[], edges: Edge[] } for context-aware requests
  • Created custom fetch wrapper to inject workflowState into POST body
    • Merges workflowState with request body from AI SDK
    • Preserves AI SDK's default fetch behavior for all other requests
  • Added useEffect to process tool invocations when state === "output-available"
    • Extracts tool parts using part.type === "tool-{name}" pattern (AI SDK v6)
    • Handles createWorkflow tool: calls /api/quickstart with description
    • Handles editWorkflow tool: calls onApplyEdits(operations, explanation)
  • Enhanced message rendering:
    • Tool invocation parts display with green/blue text indicators
    • Shows tool name and formatted arguments inline

WorkflowCanvas.tsx:

  • Added chatWorkflowState memo that strips base64 data from nodes/edges
    • Uses buildWorkflowContext logic to remove image/outputImage fields
    • Keeps workflow structure for LLM context without payload bloat
  • Added handleApplyEdits callback:
    • Captures workflow snapshot via captureSnapshot() before applying AI edits
    • Calls workflowStore.applyEditOperations(operations)
    • Logs applied/skipped operations to console
  • Passes onApplyEdits={handleApplyEdits} and workflowState={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

  1. src/store/workflowStore.ts

    • Added EditOperation import
    • Added applyEditOperations action method
  2. src/components/ChatPanel.tsx

    • Added onApplyEdits and workflowState props
    • Custom fetch wrapper for workflowState injection
    • Tool invocation processing via useEffect
    • Enhanced message rendering for tool display
  3. src/components/WorkflowCanvas.tsx

    • Added chatWorkflowState memo (strips base64)
    • Added handleApplyEdits callback (captures snapshot)
    • Passes new props to ChatPanel

Deviations

Custom fetch wrapper instead of body option:

  • Plan specified using body option with useChat hook
  • AI SDK v6 DefaultChatTransport doesn't support body directly
  • 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 toolName and args properties
  • AI SDK v6 uses part.type === "tool-{name}" pattern with input property
  • 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

  1. 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.

  2. Snapshot timing: Captured BEFORE AI edits via captureSnapshot(), not after. This preserves pre-AI state for potential rollback.

  3. Custom fetch pattern: Wrapper function checks for POST requests with body, merges workflowState, passes through everything else unchanged.

  4. Tool invocation rendering: Inline display with color-coded indicators (green for createWorkflow, blue for editWorkflow) using JSON.stringify for args.

  5. Base64 stripping: chatWorkflowState memo removes image/outputImage fields from all nodes to keep API request size reasonable while preserving structure.

  6. 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 → answerQuestion tool
  • Request new workflows → createWorkflow tool → quickstart API
  • Request workflow edits → editWorkflow tool → applyEditOperations

Next Steps

Phase 34 (Context-Aware Agentic Workflow Editing) is complete. Proceed to next phase in milestone v1.4 or other priorities.