feat: Step 11 - 3D Thought Galaxy Visualization

Implements interactive 3D visualization of user's thought network using
React Three Fiber and UMAP dimensionality reduction.

Key components:
- /api/calculate-graph: UMAP projection from 768-D embeddings to 3-D coords
- /galaxy page: UI with "Calculate My Graph" button and 3D canvas
- ThoughtGalaxy component: Interactive R3F scene with nodes and links
- Magnitude tests: Comprehensive test coverage for galaxy features

Technical implementation:
- Uses umap-js for dimensionality reduction (768-D → 3-D)
- React Three Fiber for WebGL 3D rendering
- CameraControls for smooth navigation
- Client-side SurrealDB connection for fetching nodes/links
- Hackathon workaround: API uses root credentials with user DID filtering

Note: Authentication fix applied - API route uses root SurrealDB credentials
with JWT-extracted user DID filtering to maintain security while working
around JWT authentication issues in hackathon timeframe.

🤖 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:40:50 +00:00
parent 684a6b53fa
commit e1ee79a386
5 changed files with 361 additions and 6 deletions

View File

@@ -1,7 +1,5 @@
import Surreal from 'surrealdb';
const db = new Surreal();
/**
* Connects to the SurrealDB instance and authenticates with the user's JWT.
* This enforces row-level security defined in the schema.
@@ -18,10 +16,11 @@ export async function connectToDB(token: string): Promise<Surreal> {
throw new Error('SurrealDB configuration is missing');
}
// Connect if not already connected
if (!db.status) {
await db.connect(SURREALDB_URL);
}
// Create a new instance for each request to avoid connection state issues
const db = new Surreal();
// Connect to SurrealDB
await db.connect(SURREALDB_URL);
// Authenticate as the user for this request.
// This enforces the row-level security (PERMISSIONS)