import { getSessionIndex } from "../../utils/session.js";
import { listSessions } from "./sessions.js";
import { renderStreamToTerminal } from "./stream-renderer.js";
//#region src/cli/commands/agent/interactive.ts
/**
* Start interactive chat mode
*/
async function startInteractiveChat(agent, options) {
	const { sessionKey: initialSessionKey, continuingSession } = options;
	let sessionKey = initialSessionKey;
	if (continuingSession) console.log("🧠 Interactive chat mode - Continuing session\n");
	else console.log("🧠 Interactive chat mode (Ctrl+C to exit)\n");
	const rl = (await import("readline")).createInterface({
		input: process.stdin,
		output: process.stdout,
		terminal: true
	});
	rl.on("line", async (input) => {
		const trimmed = input.trim();
		if (trimmed === ":sessions" || trimmed === ":list") {
			rl.pause();
			await listSessions();
			rl.resume();
			rl.prompt();
			return;
		}
		if (trimmed.startsWith(":session ")) {
			const newSessionKey = trimmed.slice(9).trim();
			if (await (await getSessionIndex()).getSessionMetadata(newSessionKey)) {
				sessionKey = newSessionKey;
				console.log(`🔄 Switched to session: ${sessionKey}\n`);
			} else console.log(`❌ Session not found: ${newSessionKey}\n`);
			rl.prompt();
			return;
		}
		if (trimmed === ":help") {
			printHelp();
			rl.prompt();
			return;
		}
		if (trimmed === ":quit" || trimmed === ":exit") {
			rl.close();
			return;
		}
		rl.pause();
		await renderStreamToTerminal(agent, input, sessionKey);
		rl.resume();
		rl.prompt();
	});
	rl.on("close", async () => {
		console.log("\n👋 Goodbye!");
		process.exit(0);
	});
	rl.setPrompt("You: ");
	rl.prompt();
}
function printHelp() {
	console.log(`
📖 Available commands:
  :sessions, :list    - List available sessions
  :session <key>     - Switch to another session
  :quit, :exit       - Exit interactive mode
  :help              - Show this help
`);
}
//#endregion
export { startInteractiveChat };

//# sourceMappingURL=interactive.js.map