"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var agent_backend_exports = {};
__export(agent_backend_exports, {
  getTuiCapabilities: () => getTuiCapabilities,
  isCommandDefinitionSupported: () => isCommandDefinitionSupported,
  isCommandSupported: () => isCommandSupported,
  supportsAttachments: () => supportsAttachments,
  supportsContextStats: () => supportsContextStats,
  supportsPrompts: () => supportsPrompts,
  supportsReasoningCycle: () => supportsReasoningCycle,
  supportsResources: () => supportsResources,
  supportsSkills: () => supportsSkills,
  supportsStartupInfo: () => supportsStartupInfo
});
module.exports = __toCommonJS(agent_backend_exports);
const DEFAULT_CAPABILITIES = {
  prompts: true,
  skills: true,
  resources: true,
  attachments: true,
  reasoningCycle: true,
  contextStats: true,
  startupInfo: true
};
const COMMAND_CAPABILITY_GATES = [
  {
    capability: "prompts",
    commands: ["prompts", "sysprompt"]
  },
  {
    capability: "skills",
    commands: ["skills"]
  },
  {
    capability: "reasoningCycle",
    commands: ["reasoning"]
  },
  {
    capability: "contextStats",
    commands: ["context", "ctx", "tokens"]
  }
];
function normalizeCommandName(command) {
  return command.trim().toLowerCase();
}
function getTuiCapabilities(agent) {
  const mergedCapabilities = {
    ...DEFAULT_CAPABILITIES,
    ...agent.capabilities
  };
  return {
    ...mergedCapabilities,
    skills: mergedCapabilities.skills === false ? false : Boolean(agent.skillManager),
    ...agent.capabilities?.supportedCommands ? {
      supportedCommands: agent.capabilities.supportedCommands.map(normalizeCommandName)
    } : {}
  };
}
function isCommandSupported(agent, command, definition) {
  const capabilities = getTuiCapabilities(agent);
  const supportedCommands = capabilities.supportedCommands;
  const candidates = /* @__PURE__ */ new Set([normalizeCommandName(command)]);
  if (definition?.name) {
    candidates.add(normalizeCommandName(definition.name));
  }
  for (const alias of definition?.aliases ?? []) {
    candidates.add(normalizeCommandName(alias));
  }
  for (const gate of COMMAND_CAPABILITY_GATES) {
    if (capabilities[gate.capability] === false && gate.commands.some((candidate) => candidates.has(candidate))) {
      return false;
    }
  }
  if (!supportedCommands) {
    return true;
  }
  return Array.from(candidates).some((candidate) => supportedCommands.includes(candidate));
}
function isCommandDefinitionSupported(agent, definition) {
  return isCommandSupported(agent, definition.name, definition);
}
function supportsPrompts(agent) {
  return getTuiCapabilities(agent).prompts ?? true;
}
function supportsSkills(agent) {
  return getTuiCapabilities(agent).skills ?? true;
}
function supportsResources(agent) {
  return getTuiCapabilities(agent).resources ?? true;
}
function supportsAttachments(agent) {
  return getTuiCapabilities(agent).attachments ?? true;
}
function supportsReasoningCycle(agent) {
  return getTuiCapabilities(agent).reasoningCycle ?? true;
}
function supportsContextStats(agent) {
  return getTuiCapabilities(agent).contextStats ?? true;
}
function supportsStartupInfo(agent) {
  return getTuiCapabilities(agent).startupInfo ?? true;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  getTuiCapabilities,
  isCommandDefinitionSupported,
  isCommandSupported,
  supportsAttachments,
  supportsContextStats,
  supportsPrompts,
  supportsReasoningCycle,
  supportsResources,
  supportsSkills,
  supportsStartupInfo
});
