"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var commands_exports = {};
__export(commands_exports, {
  CLI_COMMANDS: () => CLI_COMMANDS,
  executeCommand: () => executeCommand,
  getAllCommands: () => getAllCommands,
  getAvailableCommands: () => getAvailableCommands
});
module.exports = __toCommonJS(commands_exports);
var import_agent_management = require("@dexto/agent-management");
var import_agent_backend = require("../agent-backend.js");
var import_general_commands = require("./general-commands.js");
var import_session = require("./session/index.js");
var import_export = require("./export/index.js");
var import_model = require("./model/index.js");
var import_mcp = require("./mcp/index.js");
var import_plugin = require("./plugin/index.js");
var import_system = require("./system/index.js");
var import_tool_commands = require("./tool-commands.js");
var import_prompt_commands = require("./prompt-commands.js");
var import_skill_commands = require("./skill-commands.js");
var import_documentation_commands = require("./documentation-commands.js");
var import_auth = require("./auth/index.js");
const CLI_COMMANDS = [];
const baseCommands = [
  // General commands (without help)
  ...import_general_commands.generalCommands,
  // Session management
  import_session.searchCommand,
  // /search - opens search overlay
  import_session.resumeCommand,
  // /resume - opens session selector overlay
  import_session.renameCommand,
  // /rename <title> - rename current session
  import_session.forkCommand,
  // /fork - creates a forked session from current session
  import_export.exportCommand,
  // /export - opens export wizard overlay
  // Model management
  import_model.modelCommands,
  // /model - opens model selector overlay
  // MCP server management
  import_mcp.mcpCommands,
  // /mcp - opens MCP server list overlay
  // Plugin management
  import_plugin.pluginCommands,
  // /plugin - manage Claude Code compatible plugins
  // Tool management commands
  ...import_tool_commands.toolCommands,
  // Prompt management commands
  ...import_prompt_commands.promptCommands,
  // Skill management commands
  ...import_skill_commands.skillCommands,
  // System commands
  ...import_system.systemCommands,
  // Documentation commands
  ...import_documentation_commands.documentationCommands,
  // Auth commands (feature-flagged)
  ...(0, import_agent_management.isDextoAuthEnabled)() ? [import_auth.loginCommand, import_auth.logoutCommand] : [],
  // Model provider auth
  import_auth.connectCommand
];
CLI_COMMANDS.push((0, import_general_commands.createHelpCommand)((agent) => getAvailableCommands(agent)));
CLI_COMMANDS.push(...baseCommands);
async function executeCommand(command, args, agent, sessionId, configFilePath) {
  const ctx = { sessionId: sessionId ?? null, configFilePath: configFilePath ?? null };
  const cmd = CLI_COMMANDS.find(
    (c) => c.name === command || c.aliases && c.aliases.includes(command)
  );
  if (cmd) {
    if (!(0, import_agent_backend.isCommandSupported)(agent, command, cmd)) {
      return `\u26A0\uFE0F  Command /${command} is not available for this chat target.`;
    }
    try {
      const result = await cmd.handler(args, agent, ctx);
      return result;
    } catch (error) {
      const errorMsg2 = `\u274C Error executing command /${command}:
${error instanceof Error ? error.message : String(error)}`;
      agent.logger.error(
        `Error executing command /${command}: ${error instanceof Error ? error.message : String(error)}`
      );
      return errorMsg2;
    }
  }
  try {
    if ((0, import_agent_backend.supportsPrompts)(agent)) {
      const { getDynamicPromptCommands } = await import("./prompt-commands.js");
      const dynamicCommands = await getDynamicPromptCommands(agent);
      const promptCmd = dynamicCommands.find((c) => c.name === command);
      if (promptCmd) {
        try {
          const result = await promptCmd.handler(args, agent, ctx);
          return result;
        } catch (error) {
          const errorMsg2 = `\u274C Error executing prompt /${command}:
${error instanceof Error ? error.message : String(error)}`;
          agent.logger.error(
            `Error executing prompt /${command}: ${error instanceof Error ? error.message : String(error)}`
          );
          return errorMsg2;
        }
      }
    }
  } catch (error) {
    agent.logger.debug(
      `Failed to check dynamic commands for ${command}: ${error instanceof Error ? error.message : String(error)}`
    );
  }
  const errorMsg = `\u274C Unknown command: /${command}
Type / to see available commands, /prompts to add new ones`;
  return errorMsg;
}
function getAllCommands() {
  return CLI_COMMANDS;
}
function getAvailableCommands(agent) {
  return CLI_COMMANDS.filter((command) => (0, import_agent_backend.isCommandDefinitionSupported)(agent, command));
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  CLI_COMMANDS,
  executeCommand,
  getAllCommands,
  getAvailableCommands
});
