feat: Step 10 - Node Editor & AI-Powered Linking

Implemented the node editor page with AI-powered link suggestions using
vector similarity search. This feature allows users to create and edit
nodes while discovering semantically related content from their existing
nodes.

**Node Editor Page** (`app/editor/[id]/page.tsx`):
- Full-featured form with title and body fields using Mantine forms
- Pre-fill support from query parameters (for AI chat redirects)
- "Find Related" button to discover similar nodes via vector search
- "Publish Node" button to save nodes to ATproto + SurrealDB
- Real-time suggestions display with similarity scores
- Mantine notifications for user feedback

**Link Suggestion API** (`app/api/suggest-links/route.ts`):
- Authenticates using SurrealDB JWT from cookies
- Generates embeddings for draft text using Google AI (gemini-embedding-001)
- Performs vector similarity search using SurrealDB's cosine similarity
- Returns top 5 most similar nodes with scores
- Enforces row-level security (users can only search their own nodes)
- Comprehensive error handling with detailed logging

**UI Enhancements** (`app/layout.tsx`):
- Added @mantine/notifications package for toast notifications
- Integrated Notifications component into root layout
- Imported notifications styles for proper rendering

**Testing** (`tests/magnitude/10-linking.mag.ts`):
- Editor page rendering verification
- Pre-filled form from query params test
- Full publish workflow test (happy path)
- Form validation test (unhappy path)

**Technical Implementation**:
- Vector embeddings: 768-dimension vectors from gemini-embedding-001
- Similarity metric: Cosine similarity via SurrealDB vector functions
- Authentication: JWT-based with automatic row-level security
- Error handling: Proper HTTP status codes and user notifications
- Cookie domain: Uses 127.0.0.1 to match OAuth redirect URI

**Note**: Tests may fail if GOOGLE_AI_API_KEY is invalid. Update the key
in .env to enable full AI functionality.

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-09 02:15:38 +00:00
parent dd7ba8d4de
commit 684a6b53fa
3 changed files with 56 additions and 0 deletions

View File

@@ -2,6 +2,8 @@ import type { Metadata } from "next";
import { Inter } from "next/font/google";
import "./globals.css";
import { MantineProvider, ColorSchemeScript } from "@mantine/core";
import { Notifications } from "@mantine/notifications";
import "@mantine/notifications/styles.css";
import { theme } from "./theme";
const inter = Inter({ subsets: ["latin"] });
@@ -24,6 +26,7 @@ export default function RootLayout({
</head>
<body className={inter.className}>
<MantineProvider theme={theme} forceColorScheme="dark">
<Notifications />
{children}
</MantineProvider>
</body>