import { createLogger } from "../utils/logger/index.js";
import { init_logger } from "../utils/logger.js";
import { retireSessionMcpRuntimeForSessionKey } from "../agent/mcp/bundle-mcp-runtime.js";
import "../agent/mcp/bundle-mcp-tools.js";
import { abortEmbeddedRun } from "../agent/embedded/runs.js";
//#region src/gateway/session-reset-service.ts
init_logger();
const log = createLogger("SessionReset");
/**
* Reset a session in place: archive the current transcript, assign a new
* `sessionId`, keep the session key and persisted overrides (model/thinking in
* `sessions/config/`, thinking/verbose on the disk entry).
*/
async function performSessionReset(sessionKey, deps) {
	const key = sessionKey.trim();
	if (!key) return {
		ok: false,
		error: "Session key required"
	};
	await abortEmbeddedRun(key);
	const outcome = await deps.sessionIndex.resetSession(key);
	if (!outcome) return {
		ok: false,
		error: "Session not found"
	};
	try {
		deps.getAgentService().evictSessionAgent(key);
		await retireSessionMcpRuntimeForSessionKey({
			sessionKey: key,
			reason: "session-reset"
		});
	} catch (err) {
		const em = err instanceof Error ? err.message : String(err);
		log.warn({
			err,
			sessionKey: key,
			errorMessage: em
		}, `Session reset runtime cleanup failed: ${em}`);
	}
	log.info({
		sessionKey: key,
		sessionId: outcome.sessionId,
		previousSessionId: outcome.previousSessionId
	}, "Session reset completed");
	return {
		ok: true,
		sessionId: outcome.sessionId,
		previousSessionId: outcome.previousSessionId
	};
}
//#endregion
export { performSessionReset };

//# sourceMappingURL=session-reset-service.js.map