Browse Source

docs(34-03): complete store integration and ChatPanel wiring plan

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
handoff-20260429-1057
shrimbly 5 months ago
parent
commit
abcabd3408
  1. 24
      .planning/STATE.md
  2. 130
      .planning/phases/34-agentic-workflow-editing/34-03-SUMMARY.md

24
.planning/STATE.md

@ -10,16 +10,16 @@ See: .planning/PROJECT.md (updated 2026-01-09)
## Current Position
Phase: 34 of 35 (Context-Aware Agentic Workflow Editing)
Plan: 2 of ? in current phase
Status: In progress
Last activity: 2026-01-30 - Completed plan 02 (Enhanced Chat API Route with Tool Calling)
Plan: 3 of 3 in current phase
Status: Complete
Last activity: 2026-01-30 - Completed plan 03 (Store Integration and ChatPanel Wiring)
Progress: ░░░░░░░░░░ 6%
## Performance Metrics
**Velocity:**
- Total plans completed: 32
- Total plans completed: 33
- Average duration: 7 min
- Total execution time: 3.7 hours
@ -55,11 +55,11 @@ Progress: ░░░░░░░░░░ 6%
| 31. Workflow Proposal System | 2/2 | 6 min | 3 min |
| 32. Chat UI Foundation | 2/2 | 9 min | 4.5 min |
| 33. Workflow Edit Safety | 2/2 | 5 min | 5 min |
| 34. Agentic Workflow Editing | 2/? | 13 min | 6.5 min |
| 34. Agentic Workflow Editing | 3/3 | 13 min | 4.3 min |
**Recent Trend:**
- Last 5 plans: 4 min, 5 min, 5 min, 5 min, 8 min
- Trend: Chat and agentic features shipping quickly with consistent 5-8 min execution
- Last 5 plans: 5 min, 5 min, 5 min, 8 min, <1 min
- Trend: Phase 34 complete - agentic workflow editing shipped in 3 compact plans
## Accumulated Context
@ -166,6 +166,12 @@ Recent decisions affecting current work:
- AI SDK v6 uses stopWhen: stepCountIs(N) for multi-step tool execution (not maxSteps)
- Chat API uses toolChoice: 'auto' to let LLM decide which tool to call based on intent
- System prompt dynamically built per request with workflow context via buildEditSystemPrompt
- Custom fetch wrapper pattern for injecting extra body data with useChat (AI SDK v6)
- Tool invocation parts use part.type === "tool-{name}" with input property (AI SDK v6)
- state === "output-available" for tool completion detection (not "result")
- AI edits do NOT increment manualChangeCount (only manual edits clear snapshot)
- Snapshot captured before AI edits via captureSnapshot() in handleApplyEdits
- chatWorkflowState strips base64 from nodes to reduce API request size
### Deferred Issues
@ -201,6 +207,6 @@ Recent decisions affecting current work:
## Session Continuity
Last session: 2026-01-30
Stopped at: Completed Phase 34 Plan 02 (Enhanced Chat API Route with Tool Calling)
Stopped at: Completed Phase 34 Plan 03 (Store Integration and ChatPanel Wiring)
Resume file: None
Next action: Execute Phase 34 Plan 03 (ChatPanel client integration for tool result handling)
Next action: Phase 34 complete - proceed to next phase or milestone planning

130
.planning/phases/34-agentic-workflow-editing/34-03-SUMMARY.md

@ -0,0 +1,130 @@
# 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.
Loading…
Cancel
Save