Skip to content

Conversation

@kennyu
Copy link

@kennyu kennyu commented Dec 10, 2025

Migrate Chartsmith chat from direct Anthropic SDK to Vercel AI SDK and clean up dead code.

This PR modernizes the frontend chat system by replacing the custom Anthropic SDK integration with Vercel AI SDK,
providing:

  • Native streaming support via HTTP instead of Centrifugo WebSocket for chat
  • Simpler state management with useChat hook
  • Better tool calling integration
  • Provider abstraction for easier future model swaps

Key Changes

  • Add Vercel AI SDK dependencies (ai, @ai-sdk/anthropic, @ai-sdk/react)
  • Create provider configuration with Sonnet 4.5 model
  • Migrate intent classification from @anthropic-ai/sdk to AI SDK generateText
  • Add streaming chat API route (/api/chat/route.ts) with tool support
  • Create useAIChat hook wrapping useChat with workspace-specific logic
  • Add AIStreamingMessage component for rendering streaming responses
  • Enable AI SDK streaming by default in ChatContainer
  • Remove unused @anthropic-ai/sdk npm dependency
  • Remove dead useAIStreaming toggle and associated conditional logic

Architecture

  • AI SDK (TypeScript): Handles intent classification and conversational chat streaming
  • Go + Anthropic SDK: Continues handling plan generation and plan execution (file edits)
  • Centrifugo: Continues handling non-chat real-time events (renders, artifacts, revisions)

Test plan

  • npm run build succeeds
  • npm run lint passes
  • npm run test:unit passes
  • Chat messages stream correctly in the UI
  • Stop button appears during streaming and stops generation when clicked
  • Role selector still works (auto/developer/operator)
  • New chart creation flow still works
  • Tool calling works (get latest versions)
  • Plan intents trigger plan creation via Go backend

kennyu and others added 7 commits December 10, 2025 05:33
Add comprehensive unit tests for the Vercel AI SDK integration:
- prompt-type.test.ts: Tests intent classification (plan vs chat)
- context.test.ts: Tests workspace context builder
- route.test.ts: Tests chat API tools (kubernetes/subchart versions)
- persist-ai-message.test.ts: Tests AI response persistence

All 56 tests pass. Updates plan with test completion status.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Enable AI SDK streaming by default in ChatContainer
- Update TypeScript models to claude-sonnet-4-5-20250929
- Update Go backend models to Sonnet 4.5 for plan execution
- Add TextEditor_Sonnet4 constant for new model

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Remove unused @anthropic-ai/sdk dependency from package.json
- Remove useAIStreaming toggle from ChatContainer (was always true)
- Simplify input bindings and submit handler (remove legacy code path)
- Remove redundant useAIStreaming guards from JSX
- Add missing persist-ai-message.ts action (test existed but impl was missing)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant