feat: sync open-source context and capsule removal

- remove legacy contexts surfaces from the app, MCP bridge, standalone server, and docs
- keep getContext and retrieveQueryContext while aligning the simplified graph-only contract
- harden dev startup migration behavior and disable the accidental chat surface in open source

Generated with Codex
This commit is contained in:
“BeeRad”
2026-04-17 12:34:51 +10:00
parent 97eeb0789f
commit 07754f5030
87 changed files with 2688 additions and 4861 deletions
+16 -32
View File
@@ -1,8 +1,9 @@
import { NextRequest, NextResponse } from 'next/server';
import { contextService, nodeService } from '@/services/database';
import { nodeService } from '@/services/database';
import { autoEmbedQueue } from '@/services/embedding/autoEmbedQueue';
import { hasSufficientContent } from '@/services/embedding/constants';
import { coerceDescriptionForStorage } from '@/services/database/quality';
import { applyRequestSupabaseAuth, getCurrentSupabaseToken } from '@/services/auth/internalAuth';
import { normalizeNodeLink } from '@/utils/nodeLink';
import { mergeNodeMetadata } from '@/services/nodes/metadata';
@@ -12,6 +13,7 @@ export async function GET(
request: NextRequest,
{ params }: { params: Promise<{ id: string }> }
) {
const cleanupAuth = applyRequestSupabaseAuth(request);
try {
const { id } = await params;
const nodeId = parseInt(id, 10);
@@ -43,6 +45,8 @@ export async function GET(
success: false,
error: error instanceof Error ? error.message : 'Failed to fetch node'
}, { status: 500 });
} finally {
cleanupAuth();
}
}
@@ -50,6 +54,7 @@ export async function PUT(
request: NextRequest,
{ params }: { params: Promise<{ id: string }> }
) {
const cleanupAuth = applyRequestSupabaseAuth(request);
try {
const { id } = await params;
const nodeId = parseInt(id, 10);
@@ -100,34 +105,6 @@ export async function PUT(
updates.metadata = mergeNodeMetadata(existingNode.metadata, body.metadata);
}
const hasContextName = typeof body.context_name === 'string' && body.context_name.trim().length > 0;
const wantsClearContext = body.clear_context === true;
delete updates.context_name;
delete updates.clear_context;
if (hasContextName && wantsClearContext) {
return NextResponse.json({
success: false,
error: 'context_name cannot be combined with clear_context: true.'
}, { status: 400 });
}
if (hasContextName || Object.prototype.hasOwnProperty.call(body, 'context_id') || wantsClearContext) {
try {
const resolvedContextId = await contextService.resolveContextId({
context_id: wantsClearContext ? null : body.context_id,
context_name: hasContextName ? body.context_name : undefined,
});
updates.context_id = resolvedContextId;
} catch (error) {
return NextResponse.json({
success: false,
error: error instanceof Error ? error.message : 'Invalid context input'
}, { status: 400 });
}
}
const incomingSource = typeof body.source === 'string' ? body.source : undefined;
const existingSource = existingNode.source ?? '';
@@ -147,9 +124,11 @@ export async function PUT(
const node = await nodeService.updateNode(nodeId, updates);
if (shouldQueueEmbed) {
autoEmbedQueue.enqueue(nodeId, { reason: 'node_updated' });
}
if (shouldQueueEmbed) {
autoEmbedQueue.enqueue(nodeId, {
reason: 'node_updated',
});
}
return NextResponse.json({
success: true,
@@ -162,6 +141,8 @@ export async function PUT(
success: false,
error: error instanceof Error ? error.message : 'Failed to update node'
}, { status: 500 });
} finally {
cleanupAuth();
}
}
@@ -169,6 +150,7 @@ export async function DELETE(
request: NextRequest,
{ params }: { params: Promise<{ id: string }> }
) {
const cleanupAuth = applyRequestSupabaseAuth(request);
try {
const { id } = await params;
const nodeId = parseInt(id, 10);
@@ -193,5 +175,7 @@ export async function DELETE(
success: false,
error: error instanceof Error ? error.message : 'Failed to delete node'
}, { status: 500 });
} finally {
cleanupAuth();
}
}
+5 -2
View File
@@ -1,9 +1,12 @@
import { NextRequest, NextResponse } from 'next/server';
import { applyRequestSupabaseAuth } from '@/services/auth/internalAuth';
import { directNodeLookup } from '@/services/retrieval/directNodeLookup';
export const runtime = 'nodejs';
export async function POST(request: NextRequest) {
const cleanupAuth = applyRequestSupabaseAuth(request);
try {
const body = await request.json();
const query = typeof body.query === 'string' ? body.query : '';
@@ -18,8 +21,6 @@ export async function POST(request: NextRequest) {
const result = await directNodeLookup({
search: query,
limit: typeof body.limit === 'number' ? body.limit : undefined,
context_name: typeof body.context_name === 'string' ? body.context_name : undefined,
contextId: typeof body.contextId === 'number' ? body.contextId : undefined,
createdAfter: typeof body.createdAfter === 'string' ? body.createdAfter : undefined,
createdBefore: typeof body.createdBefore === 'string' ? body.createdBefore : undefined,
eventAfter: typeof body.eventAfter === 'string' ? body.eventAfter : undefined,
@@ -39,5 +40,7 @@ export async function POST(request: NextRequest) {
success: false,
error: error instanceof Error ? error.message : 'Failed to run direct node lookup',
}, { status: 500 });
} finally {
cleanupAuth();
}
}
+11 -24
View File
@@ -1,15 +1,17 @@
import { NextRequest, NextResponse } from 'next/server';
import { contextService, nodeService } from '@/services/database';
import { nodeService } from '@/services/database';
import { Node, NodeFilters } from '@/types/database';
import { autoEmbedQueue } from '@/services/embedding/autoEmbedQueue';
import { generateDescription } from '@/services/database/descriptionService';
import { coerceDescriptionForStorage } from '@/services/database/quality';
import { applyRequestSupabaseAuth, getCurrentSupabaseToken } from '@/services/auth/internalAuth';
import { normalizeNodeLink } from '@/utils/nodeLink';
import { buildCanonicalNodeMetadata } from '@/services/nodes/metadata';
export const runtime = 'nodejs';
export async function GET(request: NextRequest) {
const cleanupAuth = applyRequestSupabaseAuth(request);
try {
const searchParams = request.nextUrl.searchParams;
@@ -19,14 +21,6 @@ export async function GET(request: NextRequest) {
offset: searchParams.get('offset') ? parseInt(searchParams.get('offset')!) : 0
};
const contextIdParam = searchParams.get('contextId');
if (contextIdParam) {
const parsed = parseInt(contextIdParam, 10);
if (!Number.isNaN(parsed)) {
filters.contextId = parsed;
}
}
// Handle sortBy parameter (sortBy=edges|updated|created)
const sortByParam = searchParams.get('sortBy');
if (sortByParam === 'edges' || sortByParam === 'updated' || sortByParam === 'created' || sortByParam === 'event_date') {
@@ -57,6 +51,8 @@ export async function GET(request: NextRequest) {
success: false,
error: error instanceof Error ? error.message : 'Failed to fetch nodes'
}, { status: 500 });
} finally {
cleanupAuth();
}
}
@@ -75,6 +71,7 @@ function sanitizeTitle(title: string): string {
}
export async function POST(request: NextRequest) {
const cleanupAuth = applyRequestSupabaseAuth(request);
try {
const body = await request.json();
@@ -148,19 +145,6 @@ export async function POST(request: NextRequest) {
? body.metadata.source
: undefined;
let resolvedContextId: number | null | undefined;
try {
resolvedContextId = await contextService.resolveContextId({
context_id: body.context_id,
context_name: body.context_name,
});
} catch (error) {
return NextResponse.json({
success: false,
error: error instanceof Error ? error.message : 'Invalid context input'
}, { status: 400 });
}
const node = await nodeService.createNode({
title: body.title,
description: finalDescription,
@@ -168,7 +152,6 @@ export async function POST(request: NextRequest) {
event_date: eventDate ?? undefined,
link: normalizedLink ?? undefined,
chunk_status: chunkStatus,
context_id: resolvedContextId,
metadata: buildCanonicalNodeMetadata({
metadata: body.metadata || {},
type: inferredType,
@@ -177,7 +160,9 @@ export async function POST(request: NextRequest) {
});
if (chunkStatus === 'not_chunked' && node.id) {
autoEmbedQueue.enqueue(node.id, { reason: 'node_created' });
autoEmbedQueue.enqueue(node.id, {
reason: 'node_created',
});
}
return NextResponse.json({
@@ -192,5 +177,7 @@ export async function POST(request: NextRequest) {
success: false,
error: error instanceof Error ? error.message : 'Failed to create node'
}, { status: 500 });
} finally {
cleanupAuth();
}
}