import {
  BUILT_IN_TOOL_NAMES
} from "./chunk-7XQLG5P2.js";

// src/sessions/tools.ts
function resolveToolset(tools) {
  const customToolNames = /* @__PURE__ */ new Set();
  let builtInEnabled = new Set(BUILT_IN_TOOL_NAMES);
  let hadAgentToolset = false;
  for (const tool of tools) {
    if (tool.type === "agent_toolset_20260401") {
      hadAgentToolset = true;
      const defaultEnabled = tool.default_config?.enabled ?? true;
      if (!defaultEnabled) {
        builtInEnabled = /* @__PURE__ */ new Set();
      }
      for (const cfg of tool.configs ?? []) {
        const raw = cfg.name;
        const name = BUILT_IN_TOOL_NAMES.find(
          (n) => n.toLowerCase() === raw.toLowerCase()
        ) ?? raw;
        if (!BUILT_IN_TOOL_NAMES.includes(name)) continue;
        if (cfg.enabled === false) {
          builtInEnabled.delete(name);
        } else if (cfg.enabled === true) {
          builtInEnabled.add(name);
        }
      }
    } else if (tool.type === "custom") {
      customToolNames.add(tool.name);
    }
  }
  if (!hadAgentToolset) {
    builtInEnabled = /* @__PURE__ */ new Set();
  }
  const allowedTools = Array.from(builtInEnabled);
  const disallowedTools = BUILT_IN_TOOL_NAMES.filter((n) => !builtInEnabled.has(n));
  return { allowedTools, disallowedTools, customToolNames };
}

export {
  resolveToolset
};
