Files
app/tests/magnitude/07-chat.mag.ts
Albert bc9bbe12de feat: Update Step 7 with tool-based AI + Fix auth callback
Step 7 Updates (AI Chat with Structured Output):
- Created lib/ai-schemas.ts with Zod schema for NodeSuggestion
- Updated app/api/chat/route.ts:
  - Changed import from 'ai' to '@ai-sdk/react' for streamText
  - Added tools configuration with 'suggest_node' tool using NodeSuggestionSchema
  - Added persona support with dynamic system prompts
  - Extracts persona from request data object
- Rewrote app/chat/page.tsx:
  - Changed from server component to client component ('use client')
  - Uses useChat from '@ai-sdk/react' (fixes broken 'ai/react' import)
  - Added experimental_onToolCall handler for node suggestions
  - Redirects to /editor/new with AI-generated title/body as query params
  - Integrated MicrophoneRecorder for voice input
  - Added persona support (currently hardcoded to 'Socratic')
- Added tests/magnitude/07-chat.mag.ts with tests for:
  - Basic chat functionality
  - AI-triggered node suggestions with redirect to editor

Auth Callback Fixes:
- Fixed app/api/auth/callback/route.ts:
  - Changed to use agent.api.com.atproto.server.getSession() to fetch session
  - Previously used agent.getSession() which returned empty did/handle
  - Added user upsert to SurrealDB (INSERT...ON DUPLICATE KEY UPDATE)
  - Fixed variable references (session.did -> did, session.handle -> handle)
  - Properly creates user record before minting JWT

CLAUDE.md Updates:
- Added git commit HEREDOC syntax documentation for proper quote escaping
- Clarified that this project allows direct git commits (no PGP signatures)

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-09 01:03:36 +00:00

56 lines
1.9 KiB
TypeScript

import { test } from 'magnitude-test';
test('[Happy Path] User can chat with AI', async (agent) => {
// Act: Go to chat page
await agent.act('Navigate to /chat');
// Check: Ensure the initial state is correct
await agent.check('The title "Ponderants Interview" is visible');
await agent.check('The chat input field is empty');
// Act: Send a message
await agent.act(
'Enter "I have an idea about decentralized social media" into the chat input'
);
await agent.act('Click the "Send" button');
// Check: User's message appears
await agent.check(
'The message "I have an idea about decentralized social media" appears in the chat list'
);
// Check: AI response appears (mocked)
// We mock the /api/chat response to return a simple text stream
await agent.check(
'A new message from "AI" appears in the chat list with a response'
);
});
test('[Happy Path] AI can trigger a node suggestion', async (agent) => {
// Act: Go to chat page
await agent.act('Navigate to /chat');
// Act: Send a message that should trigger a node
await agent.act(
'Enter "I think I have a fully formed thought: ATproto is the future of the internet because it separates data from the application." into the chat input'
);
// We mock the /api/chat response to return the 'suggest_node' tool call
// with specific 'title' and 'body' arguments.
await agent.act('Click the "Send" button');
// Check: The 'experimental_onToolCall' handler should fire
// and redirect the user to the editor.
await agent.check(
'The browser URL is now "http://localhost:3000/editor/new"'
);
// Check: The editor page is pre-filled with the AI-generated content
await agent.check(
'The page URL contains the query parameter "title=ATproto: The Future of the Internet"'
);
await agent.check(
'The page URL contains the query parameter "body=ATproto is the future..."'
);
});