import { commandRegistry } from "../registry.js";
import { bulletList, code, hint, joinBlocks, kvList, section } from "../format-output.js";
//#region src/chat-commands/builtins/model.ts
const modelsCommand = {
	id: "model.list",
	name: "models",
	aliases: ["model"],
	description: "List models with display names and `provider/model` refs for /switch",
	category: "model",
	scope: [
		"global",
		"private",
		"group"
	],
	handler: async (ctx) => {
		await ctx.setTyping(true);
		const models = await ctx.listModels();
		const currentModel = ctx.getCurrentModel();
		if (models.length === 0) return {
			content: "🤖 No models available. Please check your configuration.",
			success: true
		};
		const byProvider = /* @__PURE__ */ new Map();
		for (const m of models) {
			if (!byProvider.has(m.provider)) byProvider.set(m.provider, []);
			byProvider.get(m.provider).push(m);
		}
		const content = joinBlocks("🤖 Available models (use the `provider/model` ref with `/switch`):", ...Array.from(byProvider.entries()).map(([provider, providerModels]) => {
			const items = providerModels.slice(0, 5).map((m) => {
				return `${m.id === currentModel ? "▶️ " : ""}**${m.name}** — ${code(m.id)}`;
			});
			if (providerModels.length > 5) items.push(hint(`… and ${providerModels.length - 5} more in this provider`));
			return joinBlocks(section(provider), bulletList(items));
		}), hint("Copy the ref in backticks after each name, then: `/switch provider/model-id`."));
		if (ctx.supports("buttons")) return {
			content,
			success: true,
			components: [{
				type: "model-picker",
				providers: Array.from(byProvider.entries()).map(([id, models]) => ({
					id,
					name: id,
					models: models.map((m) => ({
						id: m.id,
						name: m.name,
						provider: m.provider
					}))
				})),
				currentModel
			}]
		};
		return {
			content,
			success: true
		};
	}
};
const switchCommand = {
	id: "model.switch",
	name: "switch",
	description: "Switch model — pass the `provider/model` ref shown by /models",
	category: "model",
	scope: [
		"global",
		"private",
		"group"
	],
	acceptsArgs: true,
	examples: ["/switch openai/gpt-4o", "/switch minimax/minimax-m2.1"],
	handler: async (ctx, args) => {
		if (!args.trim()) return {
			content: joinBlocks("❌ Missing model ref.", "**Usage:** `/switch provider/model-id`", "Run `/models` — each line shows a display name and a `provider/model` ref in backticks. Copy that ref.", "**Example:** `/switch openai/gpt-4o`"),
			success: false
		};
		await ctx.setTyping(true);
		const modelId = args.trim();
		if (await ctx.switchModel(modelId)) {
			const modelName = modelId.split("/").pop() || modelId;
			return {
				content: joinBlocks(`✅ Switched to ${code(modelId)} (${modelName}).`, "This model will be used for your next message."),
				success: true
			};
		}
		return {
			content: joinBlocks(`❌ Could not switch to ${code(modelId)}.`, "Use the exact `provider/model` ref from `/models` (not only the display name).", "**Example:** `/switch anthropic/claude-sonnet-4-20250514`"),
			success: false
		};
	}
};
const usageCommand = {
	id: "model.usage",
	name: "usage",
	description: "Show token usage statistics for current session",
	category: "model",
	scope: [
		"global",
		"private",
		"group"
	],
	handler: async (ctx) => {
		await ctx.setTyping(true);
		const stats = await ctx.getUsage();
		const modelName = ctx.getCurrentModel().split("/").pop() || "Unknown";
		const content = joinBlocks(section("📊 Session Token Usage"), kvList([
			{
				key: "Model",
				value: modelName
			},
			{
				key: "Prompt",
				value: `${stats.promptTokens.toLocaleString()} tokens`
			},
			{
				key: "Completion",
				value: `${stats.completionTokens.toLocaleString()} tokens`
			},
			{
				key: "Total",
				value: `${stats.totalTokens.toLocaleString()} tokens`
			},
			{
				key: "Messages",
				value: String(stats.messageCount)
			}
		]));
		if (ctx.supports("buttons")) return {
			content,
			success: true,
			components: [{
				type: "usage-display",
				stats,
				modelName
			}]
		};
		return {
			content,
			success: true
		};
	}
};
function registerModelCommands() {
	commandRegistry.register(modelsCommand);
	commandRegistry.register(switchCommand);
	commandRegistry.register(usageCommand);
}
//#endregion
export { registerModelCommands };

//# sourceMappingURL=model.js.map