import { a as resolveAgentDir, bi as DEFAULT_PROVIDER, k as createSubsystemLogger, l as resolveAgentWorkspaceDir, o as resolveAgentEffectiveModelPrimary, u as resolveDefaultAgentId, ur as parseModelRef, yi as DEFAULT_MODEL } from "./agent-scope-DVw8mi_i.js";
import "./github-copilot-token-DYrFvncE.js";
import "./send-6RE7ZD_B.js";
import "./send-DD6K3WP6.js";
import { t as runEmbeddedPiAgent } from "./pi-embedded-Bapdl5Mb.js";
import "./diagnostic-DWKSfm_q.js";
import "./diagnostic-session-state-CexmAKza.js";
import "./send-BVmNzYrR.js";
import "./media-D4nEnyX9.js";
import "./pi-model-discovery-DpUv4v_r.js";
import "./paths-0bvQb_LS.js";
import "./ssrf-DYsl9qoS.js";
import "./reply-prefix-CteprwTK.js";
import "./path-alias-guards-BgsaoH-B.js";
import "./fs-safe--dkmYAev.js";
import "./skill-commands-_zLgADck.js";
import "./chunk-BFGwq8HC.js";
import "./markdown-tables-7kI-7mng.js";
import "./send-BAtDZt7a.js";
import "./fetch-guard-Ztzfiio9.js";
import "./outbound-attachment-BnC5ITTB.js";
import "./fetch-DyKd0D6V.js";
import "./memory-search-Z2b0d-jA.js";
import "./manager-XJq9ONvb.js";
import "./query-expansion-LNmYRPvI.js";
import "./target-errors-DrHV8jza.js";
import "./render-BRr7caFG.js";
import "./commands-registry-C7qLmjBS.js";
import "./config-eval-CG37crOn.js";
import "./send-BG45zdAY.js";
import "./resolve-route-Twc4mQV7.js";
import "./channel-activity-D2IwnDWk.js";
import "./tables-Dtfop_e5.js";
import "./proxy-DkRPPIHD.js";
import "./config-CtKjZZ4x.js";
import "./replies-D0__mn7d.js";
import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";

//#region src/hooks/llm-slug-generator.ts
/**
* LLM-based slug generator for session memory filenames
*/
const log = createSubsystemLogger("llm-slug-generator");
/**
* Generate a short 1-2 word filename slug from session content using LLM
*/
async function generateSlugViaLLM(params) {
	let tempSessionFile = null;
	try {
		const agentId = resolveDefaultAgentId(params.cfg);
		const workspaceDir = resolveAgentWorkspaceDir(params.cfg, agentId);
		const agentDir = resolveAgentDir(params.cfg, agentId);
		const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "fased-slug-"));
		tempSessionFile = path.join(tempDir, "session.jsonl");
		const prompt = `Based on this conversation, generate a short 1-2 word filename slug (lowercase, hyphen-separated, no file extension).

Conversation summary:
${params.sessionContent.slice(0, 2e3)}

Reply with ONLY the slug, nothing else. Examples: "vendor-pitch", "api-design", "bug-fix"`;
		const modelRef = resolveAgentEffectiveModelPrimary(params.cfg, agentId);
		const parsed = modelRef ? parseModelRef(modelRef, DEFAULT_PROVIDER) : null;
		const provider = parsed?.provider ?? DEFAULT_PROVIDER;
		const model = parsed?.model ?? DEFAULT_MODEL;
		const result = await runEmbeddedPiAgent({
			sessionId: `slug-generator-${Date.now()}`,
			sessionKey: "temp:slug-generator",
			agentId,
			sessionFile: tempSessionFile,
			workspaceDir,
			agentDir,
			config: params.cfg,
			prompt,
			provider,
			model,
			timeoutMs: 15e3,
			runId: `slug-gen-${Date.now()}`
		});
		if (result.payloads && result.payloads.length > 0) {
			const text = result.payloads[0]?.text;
			if (text) return text.trim().toLowerCase().replace(/[^a-z0-9-]/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "").slice(0, 30) || null;
		}
		return null;
	} catch (err) {
		const message = err instanceof Error ? err.stack ?? err.message : String(err);
		log.error(`Failed to generate slug: ${message}`);
		return null;
	} finally {
		if (tempSessionFile) try {
			await fs.rm(path.dirname(tempSessionFile), {
				recursive: true,
				force: true
			});
		} catch {}
	}
}

//#endregion
export { generateSlugViaLLM };