import { b as getNexusDb } from './connections2-D22b0xbS.js';
import { json } from '@sveltejs/kit';
import './dual-scope-db-ATrwq0LH.js';
import './paths-2M_UxD_H.js';
import 'node:fs';
import 'node:path';
import 'node:os';
import 'node:events';
import 'node:diagnostics_channel';
import 'fs';
import 'events';
import 'util';
import 'path';
import 'assert';
import 'worker_threads';
import 'module';
import 'node:url';
import 'url';
import 'buffer';
import 'node:module';
import 'node:child_process';
import 'node:crypto';
import 'node:process';
import 'node:async_hooks';
import './indexes-aYlULWG3.js';
import './utils-BvHPJOVk.js';
import './dist4-CiQ5cizO.js';
import './adapters-D2gEs_5L.js';
import './registry2-BSyCTA3q.js';
import './data-accessor-CVbz8X_7.js';
import './tasks-CnwUAUXf.js';
import './conduit-Ca_OFWR_.js';
import './unique-constraint-BM-Apx1H.js';
import './chunk-DDP5xfzh.js';
import './sqlite-Dsbe0wec.js';
import './memory-schema-Bi7cChwo.js';
import './agent-registry-BtE5uhMO.js';
import './nexus-sqlite2-DgTuv9BQ.js';
import './nexus-schema2-BEd-ol6e.js';
import './logger-ChCwlV5k.js';
import 'node:sqlite';
import './lock-BoHF25mx.js';
import './index-IVoIz4D5.js';
import 'constants';
import 'stream';
import 'node:fs/promises';
import 'jsonc-parser';
import '@cleocode/cant';
import 'node:util';
import 'node:buffer';
import 'child_process';
import './branch-lock-qP1EkZ7p.js';
import './src2-DK8DKufK.js';
import 'llmtxt/identity';
import './sessions-j73dkbCI.js';
import './index-Ca4C2M45.js';
import './mvi-helpers-BNsJ8ZpQ.js';
import './session-store-OwQWMSf_.js';
import './session-manifest-ZHrj54LR.js';
import './storage-B9UA3BHR.js';
import './config-B0nEjgSh.js';
import './json-DXl7iDYg.js';
import './data-safety-central-vmfu_Y4J.js';
import './sqlite-data-accessor-C59wZ0zp.js';
import './cross-db-cleanup-C_FLyd-6.js';
import './query-ops-BDMaTdYw.js';
import 'node:net';
import './src3-CMSGYxDI.js';
import './local-model-fit2-J1xCIhC_.js';
import './credential-pool-B04qO8at.js';
import './catalog-model-resolver2-Cexk2TN0.js';
import './role-resolver-DF9BQ_U6.js';
import './identity2-DeAB5RXE.js';
import './role-executor-C4-3bmgC.js';
import 'node:stream';
import 'crypto';
import 'os';
import 'node:http2';
import 'fs/promises';
import './models-catalog-DG3aPok8.js';
import './catalog-resolver2-c0qfF34B.js';
import './providers-CmIcBfg-.js';
import './brain-maintenance-bSR6GwAG.js';
import './graph-auto-populate2-DYsUNGSL.js';
import './temporal-supersession-BZ46j30w.js';
import './typed-query-l1D_QElt.js';
import './llm-backend-resolver-BPbvttS4.js';
import '@ai-sdk/provider-utils';
import './observer-reflector2-D8nxuglX.js';
import './learnings2-2m2p7lzT.js';
import './memory-accessor2-BzlgmY-Z.js';
import './quality-scoring-CCPuRQmJ.js';
import './patterns2-DYKfsbwN.js';
import './graph-memory-bridge2-C7Y32Mk4.js';
import './sigil2-DftKm7Um.js';
import './services-Dlf3Gefq.js';
import './audit4-S87oN-BC.js';
import 'process';
import './cleo-home-BCqJ5rg1.js';

//#region src/routes/api/nexus/symbol/[name]/+server.ts
/**
* GET /api/nexus/symbol/:name
*
* Returns an ego network (2-hop) around the named symbol.
* The center node plus all nodes directly connected (hop 1) and their
* immediate neighbours (hop 2) are included. Edges within the subgraph
* are also returned.
*/
var GET = ({ params }) => {
	const db = getNexusDb();
	if (!db) return json({ error: "nexus.db not available" }, { status: 503 });
	const name = decodeURIComponent(params.name);
	const centerRow = db.prepare(`SELECT id, label, kind, file_path, community_id
       FROM nexus_nodes
       WHERE label = ? OR id = ?
       ORDER BY CASE WHEN label = ? THEN 0 ELSE 1 END
       LIMIT 1`).get(name, name, name);
	if (!centerRow) return json({ error: `Symbol "${name}" not found` }, { status: 404 });
	const centerId = centerRow.id;
	const hop1Rows = db.prepare(`SELECT DISTINCT n.id, n.label, n.kind, n.file_path, n.community_id
       FROM nexus_relations r
       JOIN nexus_nodes n ON (r.target_id = n.id OR r.source_id = n.id)
       WHERE (r.source_id = ? OR r.target_id = ?)
         AND n.id != ?
       LIMIT 100`).all(centerId, centerId, centerId);
	const hop1Ids = hop1Rows.map((n) => n.id);
	let hop2Rows = [];
	if (hop1Ids.length > 0) {
		const placeholders = hop1Ids.map(() => "?").join(",");
		const excludeIds = [centerId, ...hop1Ids];
		const excludePlaceholders = excludeIds.map(() => "?").join(",");
		hop2Rows = db.prepare(`SELECT DISTINCT n.id, n.label, n.kind, n.file_path, n.community_id
         FROM nexus_relations r
         JOIN nexus_nodes n ON (r.target_id = n.id OR r.source_id = n.id)
         WHERE (r.source_id IN (${placeholders}) OR r.target_id IN (${placeholders}))
           AND n.id NOT IN (${excludePlaceholders})
         LIMIT 200`).all(...hop1Ids, ...hop1Ids, ...excludeIds);
	}
	const allIds = [
		centerId,
		...hop1Ids,
		...hop2Rows.map((n) => n.id)
	];
	const callerCounts = /* @__PURE__ */ new Map();
	if (allIds.length > 0) {
		const placeholders = allIds.map(() => "?").join(",");
		const ccRows = db.prepare(`SELECT target_id, COUNT(*) AS cnt
         FROM nexus_relations
         WHERE target_id IN (${placeholders}) AND type = 'calls'
         GROUP BY target_id`).all(...allIds);
		for (const row of ccRows) callerCounts.set(row.target_id, row.cnt);
	}
	const subgraphEdges = allIds.length > 0 ? db.prepare(`SELECT source_id, target_id, type
           FROM nexus_relations
           WHERE source_id IN (${allIds.map(() => "?").join(",")})
             AND target_id IN (${allIds.map(() => "?").join(",")})
           LIMIT 1000`).all(...allIds, ...allIds) : [];
	return json({
		center: centerId,
		nodes: [
			{
				id: centerRow.id,
				label: centerRow.label,
				kind: centerRow.kind,
				filePath: centerRow.file_path ?? "",
				hop: 0,
				callerCount: callerCounts.get(centerRow.id) ?? 0,
				communityId: centerRow.community_id
			},
			...hop1Rows.map((n) => ({
				id: n.id,
				label: n.label,
				kind: n.kind,
				filePath: n.file_path ?? "",
				hop: 1,
				callerCount: callerCounts.get(n.id) ?? 0,
				communityId: n.community_id
			})),
			...hop2Rows.map((n) => ({
				id: n.id,
				label: n.label,
				kind: n.kind,
				filePath: n.file_path ?? "",
				hop: 2,
				callerCount: callerCounts.get(n.id) ?? 0,
				communityId: n.community_id
			}))
		],
		edges: subgraphEdges.map((e) => ({
			source: e.source_id,
			target: e.target_id,
			type: e.type
		}))
	});
};

export { GET };
//# sourceMappingURL=_server.ts-CbnGhRJm.js.map
