import { a5 as spread_props, a6 as sanitize_props, a7 as slot, Y as writable } from './internal-B3VUlLoc.js';
import { I as Icon } from './Header-DF-atx4l.js';

//#region ../../node_modules/.pnpm/lucide-svelte@1.0.1_svelte@5.55.5/node_modules/lucide-svelte/dist/icons/rotate-ccw.svelte
function Rotate_ccw($$renderer, $$props) {
	Icon($$renderer, spread_props([
		{ name: "rotate-ccw" },
		sanitize_props($$props),
		{
			/**
			* @component @name RotateCcw
			* @description Lucide SVG icon component, renders SVG Element with children.
			*
			* @preview ![img](data:image/svg+xml;base64,PHN2ZyAgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIgogIHdpZHRoPSIyNCIKICBoZWlnaHQ9IjI0IgogIHZpZXdCb3g9IjAgMCAyNCAyNCIKICBmaWxsPSJub25lIgogIHN0cm9rZT0iIzAwMCIgc3R5bGU9ImJhY2tncm91bmQtY29sb3I6ICNmZmY7IGJvcmRlci1yYWRpdXM6IDJweCIKICBzdHJva2Utd2lkdGg9IjIiCiAgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIgogIHN0cm9rZS1saW5lam9pbj0icm91bmQiCj4KICA8cGF0aCBkPSJNMyAxMmE5IDkgMCAxIDAgOS05IDkuNzUgOS43NSAwIDAgMC02Ljc0IDIuNzRMMyA4IiAvPgogIDxwYXRoIGQ9Ik0zIDN2NWg1IiAvPgo8L3N2Zz4K) - https://lucide.dev/icons/rotate-ccw
			* @see https://lucide.dev/guide/packages/lucide-svelte - Documentation
			*
			* @param {Object} props - Lucide icons props and any valid SVG attribute
			* @returns {FunctionalComponent} Svelte component
			*
			*/
			iconNode: [["path", { "d": "M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8" }], ["path", { "d": "M3 3v5h5" }]],
			children: ($$renderer) => {
				$$renderer.push(`<!--[-->`);
				slot($$renderer, $$props, "default", {});
				$$renderer.push(`<!--]-->`);
			},
			$$slots: { default: true }
		}
	]));
}
//#endregion
//#region src/lib/components/agent/chat-ui.ts
var CUSTOM_MODEL_VALUE = "__custom__";
function providerName(provider) {
	if (!provider) return "Agent";
	return provider.charAt(0).toUpperCase() + provider.slice(1);
}
function sessionSubtitle(session) {
	return [
		providerName(session.provider),
		session.model,
		session.interactionMode,
		session.effort,
		session.permissionMode
	].filter(Boolean).join(" / ");
}
function sessionPreview(session, messagesBySession) {
	const lastMessage = (messagesBySession[session.id] ?? []).at(-1);
	if (session.lastError) return session.lastError;
	if (!lastMessage) return "No messages yet";
	return lastMessage.content.replace(/\s+/g, " ").trim();
}
function threadState(session) {
	if (session.status === "running") return {
		label: "running",
		tone: "running"
	};
	if (session.status === "queued") return {
		label: "queued",
		tone: "running"
	};
	if (session.status === "error") return {
		label: "error",
		tone: "error"
	};
	if (session.status === "cancelled" || session.status === "exited") return {
		label: "stopped",
		tone: "done"
	};
	return {
		label: "idle",
		tone: "waiting"
	};
}
function roleLabel(role) {
	if (role === "user") return "You";
	if (role === "assistant") return "Assistant";
	if (role === "tool") return "Tool";
	if (role === "system") return "System";
	if (role === "error") return "Error";
	return role;
}
function isBusy(session) {
	return session?.status === "running" || session?.status === "queued";
}
function modelOptionsForProvider(provider) {
	if (!provider) return [];
	return provider.models.map((option) => ({
		value: option.value,
		label: option.label
	}));
}
function modelCapabilityForProvider(provider, model) {
	if (!provider) return null;
	const normalized = model?.trim() ?? "";
	if (!normalized) return null;
	return provider.models.find((option) => option.value === normalized) ?? null;
}
function effectiveModelForProvider(provider, model) {
	if (!provider) return model?.trim() ? model.trim() : null;
	const trimmed = model?.trim() ?? "";
	if (trimmed.length > 0) return trimmed;
	return provider.defaultModel ?? null;
}
function effortOptionsForProvider(provider, model) {
	if (!provider) return [""];
	const capability = modelCapabilityForProvider(provider, effectiveModelForProvider(provider, model));
	const options = capability?.effortOptions.length ? capability.effortOptions : provider.fallbackEffortOptions;
	return ["", ...options.filter((option, index) => options.indexOf(option) === index)];
}
function effortDefaultForProvider(provider, model) {
	if (!provider) return "";
	return modelCapabilityForProvider(provider, effectiveModelForProvider(provider, model))?.defaultEffort ?? provider.defaultEffort ?? "";
}
function messageAttachments(message) {
	const value = message.metadata.attachments;
	if (!Array.isArray(value)) return [];
	return value.map((item) => {
		if (!item || typeof item !== "object") return null;
		const record = item;
		if (typeof record.id !== "string" || typeof record.name !== "string" || typeof record.path !== "string") return null;
		return {
			id: record.id,
			kind: record.kind === "project_file" ? "project_file" : "local_upload",
			name: record.name,
			path: record.path,
			size: typeof record.size === "number" ? record.size : null,
			mimeType: typeof record.mimeType === "string" ? record.mimeType : null
		};
	}).filter((item) => item !== null);
}
function isRecord(value) {
	return Boolean(value) && typeof value === "object" && !Array.isArray(value);
}
function stringValue(value) {
	if (typeof value === "string") return value;
	if (value == null) return "";
	if (typeof value === "number" || typeof value === "boolean") return String(value);
	try {
		return JSON.stringify(value, null, 2);
	} catch {
		return String(value);
	}
}
function shortToolName(value) {
	return stringValue(value || "Tool").replace(/([a-z])([A-Z])/g, "$1 $2");
}
function richType(message) {
	const explicit = message.metadata.richType;
	if (typeof explicit === "string") return explicit;
	if (message.eventType === "turn/plan/updated") return "codex_plan_update";
	if (message.eventType.includes("requestApproval")) return "codex_approval";
	if (message.eventType.includes("requestUserInput")) return "codex_user_input";
	return "";
}
function metadataItem(message) {
	if (isRecord(message.metadata.item)) return message.metadata.item;
	if (isRecord(message.metadata.params) && isRecord(message.metadata.params.item)) return message.metadata.params.item;
	return null;
}
function metadataParams(message) {
	return isRecord(message.metadata.params) ? message.metadata.params : message.metadata;
}
function parseQuestions(value) {
	if (!Array.isArray(value)) return [];
	return value.map((rawQuestion) => {
		if (!isRecord(rawQuestion)) return null;
		const options = (Array.isArray(rawQuestion.options) ? rawQuestion.options : []).map((rawOption) => {
			if (!isRecord(rawOption)) return null;
			const label = stringValue(rawOption.label).trim();
			if (!label) return null;
			return {
				label,
				description: stringValue(rawOption.description).trim()
			};
		}).filter((option) => option !== null);
		const question = stringValue(rawQuestion.question).trim();
		if (!question || options.length === 0) return null;
		return {
			header: stringValue(rawQuestion.header).trim() || "Question",
			question,
			multiSelect: rawQuestion.multiSelect === true || rawQuestion.multi_select === true,
			options
		};
	}).filter((question) => question !== null);
}
function parsePlanSteps(value) {
	if (!Array.isArray(value)) return [];
	return value.map((entry) => {
		if (!isRecord(entry)) return null;
		const step = stringValue(entry.step).trim();
		if (!step) return null;
		const rawStatus = stringValue(entry.status || "pending");
		return {
			step,
			status: rawStatus === "inProgress" ? "in progress" : rawStatus
		};
	}).filter((entry) => entry !== null);
}
function parseFileChanges(value) {
	if (!Array.isArray(value)) return [];
	return value.map((entry) => {
		if (!isRecord(entry)) return null;
		const path = stringValue(entry.path).trim();
		if (!path) return null;
		return {
			path,
			kind: stringValue(entry.kind || "changed"),
			diff: stringValue(entry.diff).trim()
		};
	}).filter((entry) => entry !== null);
}
function defaultRichMessage(message) {
	return {
		kind: "generic",
		title: roleLabel(message.role),
		subtitle: message.eventType,
		tone: message.role === "error" ? "danger" : "neutral",
		questions: [],
		planSteps: [],
		changes: [],
		command: "",
		cwd: "",
		status: "",
		body: message.content,
		canRespond: false
	};
}
function richMessage(message) {
	if (message.role !== "tool" && message.role !== "system" && message.role !== "error") return null;
	const rich = defaultRichMessage(message);
	const type = richType(message);
	const item = metadataItem(message);
	const params = metadataParams(message);
	if (type === "claude_tool_use") {
		const toolName = stringValue(message.metadata.toolName);
		const input = isRecord(message.metadata.toolInput) ? message.metadata.toolInput : {};
		if (toolName === "AskUserQuestion") {
			rich.kind = "ask-user";
			rich.title = "Answer requested";
			rich.subtitle = "Claude is asking for input";
			rich.tone = "info";
			rich.questions = parseQuestions(input.questions);
			rich.body = rich.questions.length ? "" : message.content;
			rich.canRespond = rich.questions.length > 0;
			return rich;
		}
		if (toolName === "ExitPlanMode") {
			rich.kind = "plan";
			rich.title = "Plan approval";
			rich.subtitle = "Claude wants to leave plan mode";
			rich.tone = "warning";
			rich.body = stringValue(input.plan ?? input.content ?? input.planContent ?? message.content);
			rich.canRespond = true;
			return rich;
		}
		rich.kind = "tool-call";
		rich.title = shortToolName(toolName);
		rich.subtitle = "Tool call";
		rich.body = isRecord(input) && Object.keys(input).length > 0 ? JSON.stringify(input, null, 2) : message.content;
		return rich;
	}
	if (type === "claude_tool_result") {
		rich.kind = "tool-result";
		rich.title = "Tool result";
		rich.subtitle = message.eventType;
		rich.body = stringValue(message.metadata.toolResult || message.content);
		return rich;
	}
	if (type === "codex_plan_update") {
		rich.kind = "plan";
		rich.title = "Plan updated";
		rich.subtitle = stringValue(params.explanation).trim();
		rich.tone = "info";
		rich.planSteps = parsePlanSteps(params.plan);
		rich.body = rich.planSteps.length ? "" : message.content;
		return rich;
	}
	if (type === "codex_plan") {
		rich.kind = "plan";
		rich.title = "Plan";
		rich.subtitle = "Codex plan mode";
		rich.tone = "info";
		rich.body = stringValue(item?.text ?? item?.content ?? message.content);
		return rich;
	}
	if (type === "codex_user_input") {
		rich.kind = "ask-user";
		rich.title = "Answer requested";
		rich.subtitle = "Codex is waiting for input";
		rich.tone = "info";
		rich.questions = parseQuestions(params.questions);
		rich.body = rich.questions.length ? "" : message.content;
		rich.canRespond = rich.questions.length > 0;
		return rich;
	}
	if (type === "codex_mcp_elicitation") {
		rich.kind = "mcp";
		rich.title = "MCP input requested";
		rich.subtitle = stringValue(params.serverName || params.server || "MCP server");
		rich.tone = "info";
		rich.body = stringValue(params.message || message.content);
		rich.canRespond = true;
		return rich;
	}
	if (type === "codex_approval") {
		rich.kind = "approval";
		rich.title = "Approval requested";
		rich.subtitle = stringValue(params.reason).trim() || "Codex is waiting for a decision";
		rich.tone = "warning";
		rich.command = stringValue(params.command).trim();
		rich.cwd = stringValue(params.cwd).trim();
		rich.body = rich.command || rich.cwd ? "" : message.content;
		rich.canRespond = false;
		return rich;
	}
	if (type === "codex_command") {
		rich.kind = "command";
		rich.title = "Command";
		rich.subtitle = stringValue(item?.status || message.eventType);
		rich.command = stringValue(item?.command ?? message.content.split("\n")[0]?.replace(/^\$ /, "")).trim();
		rich.cwd = stringValue(item?.cwd).trim();
		rich.status = stringValue(item?.status).trim();
		rich.body = stringValue(item?.aggregatedOutput ?? item?.aggregated_output ?? item?.output ?? "");
		return rich;
	}
	if (type === "codex_file_change") {
		rich.kind = "file-change";
		rich.title = "File changes";
		rich.subtitle = stringValue(item?.status || message.eventType);
		rich.status = stringValue(item?.status).trim();
		rich.changes = parseFileChanges(item?.changes);
		rich.body = rich.changes.length ? "" : message.content;
		return rich;
	}
	if (type === "codex_mcpToolCall") {
		rich.kind = "mcp";
		rich.title = "MCP tool";
		rich.subtitle = [stringValue(item?.server), stringValue(item?.tool)].filter(Boolean).join(" / ");
		rich.body = stringValue(item?.input ?? item?.arguments ?? message.content);
		return rich;
	}
	if (type === "codex_collabToolCall") {
		rich.kind = "subagent";
		rich.title = "Subagent";
		rich.subtitle = stringValue(item?.tool || message.eventType);
		rich.body = stringValue(item?.input ?? item?.arguments ?? message.content);
		return rich;
	}
	if (type === "codex_webSearch") {
		rich.kind = "search";
		rich.title = "Web search";
		rich.subtitle = stringValue(item?.query);
		rich.body = stringValue(item?.results ?? message.content);
		return rich;
	}
	if (type === "codex_imageView") {
		rich.kind = "image";
		rich.title = "Image viewed";
		rich.subtitle = stringValue(item?.path);
		rich.body = "";
		return rich;
	}
	if (type === "codex_enteredReviewMode" || type === "codex_exitedReviewMode") {
		rich.kind = "review";
		rich.title = type === "codex_enteredReviewMode" ? "Review started" : "Review completed";
		rich.subtitle = stringValue(item?.review ?? message.eventType);
		rich.tone = "info";
		rich.body = "";
		return rich;
	}
	if (type === "codex_contextCompaction" || type === "codex_compacted") {
		rich.kind = "compaction";
		rich.title = "Context compacted";
		rich.subtitle = "Codex compressed conversation history";
		rich.tone = "info";
		rich.body = "";
		return rich;
	}
	return null;
}
var sessionExtensionsBySession = writable({});

export { CUSTOM_MODEL_VALUE as C, Rotate_ccw as R, sessionSubtitle as a, roleLabel as b, sessionExtensionsBySession as c, modelOptionsForProvider as d, effortDefaultForProvider as e, effectiveModelForProvider as f, effortOptionsForProvider as g, isBusy as i, messageAttachments as m, providerName as p, richMessage as r, sessionPreview as s, threadState as t };
//# sourceMappingURL=extensions-Crd97FJ_.js.map
