/**
 * VectorDrive Extension for Singularity Forge
 *
 * Integrates the native Rust vectordrive vector database for semantic
 * memory and code search. Works offline with no external services.
 */

import type { ExtensionAPI } from "@singularity-forge/pi-coding-agent";
import { VectordriveManager } from "./manager.js";
import { registerVectordriveInfoTool } from "./tool-info.js";
import { registerVectordriveStoreTool } from "./tool-store.js";
import { registerVectordriveSearchTool } from "./tool-search.js";

export default function (pi: ExtensionAPI) {
	registerVectordriveInfoTool(pi);
	registerVectordriveStoreTool(pi);
	registerVectordriveSearchTool(pi);

	// Pre-warm the connection on session start
	pi.on("session_start", async (_event, ctx) => {
		const manager = VectordriveManager.getInstance();
		const status = await manager.getStatus();

		if (ctx.hasUI && status.backend === "none" && status.error) {
			ctx.ui.notify(
				`VectorDrive unavailable: ${status.error}`,
				"warning",
			);
		}
	});

	pi.on("session_shutdown", async () => {
		const manager = VectordriveManager.getInstance();
		await manager.close();
	});
}
