Initial commit: RA-H Open Source Edition

Local-first knowledge management system with BYO API keys.

Features:
- 3-panel UI (Nodes | Focus | Helpers)
- SQLite + sqlite-vec for vector search
- Agent system (Easy/Hard mode orchestrators)
- Content extraction (YouTube, PDF, web)
- Integrate workflow for connection discovery
- Dimension system with auto-assignment

Tech stack:
- Next.js 15 + TypeScript + Tailwind CSS
- Anthropic (Claude) + OpenAI (GPT) via Vercel AI SDK

Setup:
  npm install && npm rebuild better-sqlite3
  scripts/dev/bootstrap-local.sh
  npm run dev

MIT License
This commit is contained in:
“BeeRad”
2025-12-15 16:14:28 +11:00
commit 733d1c3407
226 changed files with 46231 additions and 0 deletions
+35
View File
@@ -0,0 +1,35 @@
import { NextRequest, NextResponse } from 'next/server';
import { chunkService } from '@/services/database';
export const runtime = 'nodejs';
export async function GET(
request: NextRequest,
{ params }: { params: Promise<{ id: string }> }
) {
try {
const { id } = await params;
const nodeId = parseInt(id, 10);
if (isNaN(nodeId)) {
return NextResponse.json({
success: false,
error: 'Invalid node ID'
}, { status: 400 });
}
const chunks = await chunkService.getChunksByNodeId(nodeId);
return NextResponse.json({
success: true,
chunks: chunks
});
} catch (error) {
console.error('Error fetching chunks:', error);
return NextResponse.json({
success: false,
error: error instanceof Error ? error.message : 'Failed to fetch chunks'
}, { status: 500 });
}
}
+37
View File
@@ -0,0 +1,37 @@
import { NextRequest, NextResponse } from 'next/server';
import { edgeService } from '@/services/database';
export const runtime = 'nodejs';
export async function GET(
request: NextRequest,
{ params }: { params: Promise<{ id: string }> }
) {
try {
const { id } = await params;
const nodeId = parseInt(id, 10);
if (isNaN(nodeId)) {
return NextResponse.json({
success: false,
error: 'Invalid node ID'
}, { status: 400 });
}
const connections = await edgeService.getNodeConnections(nodeId);
console.log('[api/nodes/[id]/edges] node', nodeId, 'returned connections:', connections.length);
return NextResponse.json({
success: true,
data: connections,
count: connections.length
});
} catch (error) {
console.error('Error fetching node edges:', error);
return NextResponse.json({
success: false,
error: error instanceof Error ? error.message : 'Failed to fetch node edges'
}, { status: 500 });
}
}
+150
View File
@@ -0,0 +1,150 @@
import { NextRequest, NextResponse } from 'next/server';
import { nodeService } from '@/services/database';
import { autoEmbedQueue } from '@/services/embedding/autoEmbedQueue';
import { hasSufficientContent } from '@/services/embedding/constants';
export const runtime = 'nodejs';
export async function GET(
request: NextRequest,
{ params }: { params: Promise<{ id: string }> }
) {
try {
const { id } = await params;
const nodeId = parseInt(id, 10);
if (isNaN(nodeId)) {
return NextResponse.json({
success: false,
error: 'Invalid node ID'
}, { status: 400 });
}
const node = await nodeService.getNodeById(nodeId);
if (!node) {
return NextResponse.json({
success: false,
error: 'Node not found'
}, { status: 404 });
}
return NextResponse.json({
success: true,
node: node
});
} catch (error) {
console.error('Error fetching node:', error);
return NextResponse.json({
success: false,
error: error instanceof Error ? error.message : 'Failed to fetch node'
}, { status: 500 });
}
}
export async function PUT(
request: NextRequest,
{ params }: { params: Promise<{ id: string }> }
) {
try {
const { id } = await params;
const nodeId = parseInt(id, 10);
if (isNaN(nodeId)) {
return NextResponse.json({
success: false,
error: 'Invalid node ID'
}, { status: 400 });
}
const body = await request.json();
const existingNode = await nodeService.getNodeById(nodeId);
if (!existingNode) {
return NextResponse.json({
success: false,
error: 'Node not found'
}, { status: 404 });
}
if (body && Object.prototype.hasOwnProperty.call(body, 'is_pinned')) {
console.warn(`[nodes/${nodeId}] Ignoring legacy is_pinned payload`);
delete body.is_pinned;
}
const updates: Record<string, unknown> = { ...body };
let shouldQueueEmbed = false;
const incomingChunk = typeof body.chunk === 'string' ? body.chunk : undefined;
const incomingContent = typeof body.content === 'string' ? body.content : undefined;
const existingChunk = existingNode.chunk ?? '';
if (incomingChunk !== undefined) {
const trimmedIncoming = incomingChunk.trim();
const trimmedExisting = existingChunk.trim();
if (!trimmedIncoming) {
updates.chunk_status = null;
} else if (trimmedIncoming !== trimmedExisting) {
updates.chunk_status = 'not_chunked';
shouldQueueEmbed = hasSufficientContent(trimmedIncoming);
} else {
delete updates.chunk_status;
}
} else if (!existingChunk.trim() && hasSufficientContent(incomingContent)) {
updates.chunk = incomingContent;
updates.chunk_status = 'not_chunked';
shouldQueueEmbed = true;
}
const node = await nodeService.updateNode(nodeId, updates);
if (shouldQueueEmbed) {
autoEmbedQueue.enqueue(nodeId, { reason: 'node_updated' });
}
return NextResponse.json({
success: true,
node: node,
message: `Node updated successfully`
});
} catch (error) {
console.error('Error updating node:', error);
return NextResponse.json({
success: false,
error: error instanceof Error ? error.message : 'Failed to update node'
}, { status: 500 });
}
}
export async function DELETE(
request: NextRequest,
{ params }: { params: Promise<{ id: string }> }
) {
try {
const { id } = await params;
const nodeId = parseInt(id, 10);
if (isNaN(nodeId)) {
return NextResponse.json({
success: false,
error: 'Invalid node ID'
}, { status: 400 });
}
await nodeService.deleteNode(nodeId);
return NextResponse.json({
success: true,
message: `Node ${nodeId} deleted successfully`
});
} catch (error) {
console.error('Error deleting node:', error);
return NextResponse.json({
success: false,
error: error instanceof Error ? error.message : 'Failed to delete node'
}, { status: 500 });
}
}
+117
View File
@@ -0,0 +1,117 @@
import { NextRequest, NextResponse } from 'next/server';
import { nodeService } from '@/services/database';
import { Node, NodeFilters } from '@/types/database';
import { autoEmbedQueue } from '@/services/embedding/autoEmbedQueue';
import { hasSufficientContent } from '@/services/embedding/constants';
import { DimensionService } from '@/services/database/dimensionService';
export const runtime = 'nodejs';
export async function GET(request: NextRequest) {
try {
const searchParams = request.nextUrl.searchParams;
const filters: NodeFilters = {
search: searchParams.get('search') || undefined,
limit: searchParams.get('limit') ? parseInt(searchParams.get('limit')!) : 100,
offset: searchParams.get('offset') ? parseInt(searchParams.get('offset')!) : 0
};
// Handle dimensions parameter (comma-separated)
const dimensionsParam = searchParams.get('dimensions');
if (dimensionsParam) {
filters.dimensions = dimensionsParam.split(',').map(dim => dim.trim()).filter(Boolean);
}
// Handle sortBy parameter
const sortByParam = searchParams.get('sortBy');
if (sortByParam === 'edges' || sortByParam === 'updated') {
filters.sortBy = sortByParam;
}
const nodes = await nodeService.getNodes(filters);
return NextResponse.json({
success: true,
data: nodes,
count: nodes.length
});
} catch (error) {
console.error('Error fetching nodes:', error);
return NextResponse.json({
success: false,
error: error instanceof Error ? error.message : 'Failed to fetch nodes'
}, { status: 500 });
}
}
export async function POST(request: NextRequest) {
try {
const body = await request.json();
// Validate required fields
if (!body.title) {
return NextResponse.json({
success: false,
error: 'Missing required field: title is required'
}, { status: 400 });
}
const rawContent = typeof body.content === 'string' ? body.content : null;
const providedDimensions = Array.isArray(body.dimensions) ? body.dimensions : [];
const trimmedProvidedDimensions = providedDimensions
.map((dim: unknown) => typeof dim === 'string' ? dim.trim() : '')
.filter(Boolean)
.slice(0, 5);
// Auto-assign locked dimensions for all new nodes
const autoAssignedDimensions = await DimensionService.assignLockedDimensions({
title: body.title,
content: rawContent || undefined,
link: body.link
});
// Combine provided and auto-assigned dimensions, remove duplicates
const finalDimensions = [...new Set([...trimmedProvidedDimensions, ...autoAssignedDimensions])]
.slice(0, 5); // Ensure we don't exceed 5 total dimensions
const rawChunk = typeof body.chunk === 'string' ? body.chunk : null;
let chunkToStore = rawChunk;
let chunkStatus: Node['chunk_status'];
if (chunkToStore && chunkToStore.trim().length > 0) {
chunkStatus = 'not_chunked';
} else if (!chunkToStore && hasSufficientContent(rawContent)) {
chunkToStore = rawContent;
chunkStatus = 'not_chunked';
}
const node = await nodeService.createNode({
title: body.title,
content: rawContent ?? undefined,
link: body.link,
dimensions: finalDimensions,
chunk: chunkToStore ?? undefined,
chunk_status: chunkStatus,
metadata: body.metadata || {}
});
if (chunkStatus === 'not_chunked' && node.id) {
autoEmbedQueue.enqueue(node.id, { reason: 'node_created' });
}
return NextResponse.json({
success: true,
data: node,
message: `Node created successfully with dimensions: ${finalDimensions.join(', ')}`
}, { status: 201 });
} catch (error) {
console.error('Error creating node:', error);
return NextResponse.json({
success: false,
error: error instanceof Error ? error.message : 'Failed to create node'
}, { status: 500 });
}
}
+49
View File
@@ -0,0 +1,49 @@
import { NextRequest, NextResponse } from 'next/server';
import { nodeService } from '@/services/database';
export const runtime = 'nodejs';
export async function GET(request: NextRequest) {
try {
const searchParams = request.nextUrl.searchParams;
const query = searchParams.get('q');
const limit = parseInt(searchParams.get('limit') || '10');
if (!query || query.trim() === '') {
return NextResponse.json({
success: false,
error: 'Missing required parameter: q (search query)'
}, { status: 400 });
}
if (query.length < 2) {
return NextResponse.json({
success: false,
error: 'Search query must be at least 2 characters long'
}, { status: 400 });
}
const nodes = await nodeService.searchNodes(query.trim(), Math.min(limit, 50));
// Return minimal data for edge creation UI
const results = nodes.map(node => ({
id: node.id,
title: node.title,
dimensions: node.dimensions
}));
return NextResponse.json({
success: true,
data: results,
count: results.length,
query: query.trim()
});
} catch (error) {
console.error('Error searching nodes:', error);
return NextResponse.json({
success: false,
error: error instanceof Error ? error.message : 'Failed to search nodes'
}, { status: 500 });
}
}