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>
20 lines
577 B
TypeScript
20 lines
577 B
TypeScript
import { z } from 'zod';
|
|
|
|
/**
|
|
* This Zod schema defines the *only* structured output
|
|
* we want the AI to be able to generate. We will pass
|
|
* this to the Vercel AI SDK to guarantee the AI's output
|
|
* conforms to this shape.
|
|
*/
|
|
export const NodeSuggestionSchema = z.object({
|
|
action: z.literal('suggest_node'),
|
|
title: z
|
|
.string()
|
|
.describe('A concise, descriptive title for the thought node.'),
|
|
body: z
|
|
.string()
|
|
.describe('The full, well-structured content of the thought node.'),
|
|
});
|
|
|
|
export type NodeSuggestion = z.infer<typeof NodeSuggestionSchema>;
|