import { readdir, stat } from "node:fs/promises";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
//#region src/agent/memory/plugin-discovery.ts
async function discoverMemoryPlugins() {
	const pluginsDir = join(dirname(fileURLToPath(import.meta.url)), "..", "..", "plugins", "memory");
	try {
		const entries = await readdir(pluginsDir);
		const plugins = [];
		for (const entry of entries) {
			const fullPath = join(pluginsDir, entry);
			if (!(await stat(fullPath)).isDirectory() || entry.startsWith("_") || entry.startsWith(".")) continue;
			const initPath = join(fullPath, "index.js");
			try {
				await stat(initPath);
				const mod = await import(initPath);
				const available = mod.isAvailable?.() ?? true;
				plugins.push({
					name: entry,
					description: mod.description ?? `${entry} memory plugin`,
					available
				});
			} catch {
				plugins.push({
					name: entry,
					description: `${entry} memory plugin`,
					available: false
				});
			}
		}
		return plugins.sort((a, b) => a.name.localeCompare(b.name));
	} catch {
		return [];
	}
}
//#endregion
export { discoverMemoryPlugins };

//# sourceMappingURL=plugin-discovery.js.map