import{gi as e,hi as t,li as n}from"./model-selection-p21GBPS6.js";import{n as r}from"./plugins-1aNlpDX7.js";const i=()=>t();function a(e){return i().includes(e)}function o(t){let r=e(t);if(r&&n(r)&&a(r))return r}function s(e){return!e||typeof e!=`object`?!0:e.enabled!==!1}async function c(e,t){let n=e.config.listAccountIds(t);if(n.length===0)return!1;for(let r of n){let n=e.config.resolveAccount(t,r);if((e.config.isEnabled?e.config.isEnabled(n,t):s(n))&&(!e.config.isConfigured||await e.config.isConfigured(n,t)))return!0}return!1}async function l(e){let t=[];for(let n of r())a(n.id)&&await c(n,e)&&t.push(n.id);return t}async function u(t){let n=e(t.channel);if(n){if(!a(n)){let e=o(t.fallbackChannel);if(e)return{channel:e,configured:await l(t.cfg),source:`tool-context-fallback`};throw Error(`Unknown channel: ${String(n)}`)}return{channel:n,configured:await l(t.cfg),source:`explicit`}}let r=o(t.fallbackChannel);if(r)return{channel:r,configured:await l(t.cfg),source:`tool-context-fallback`};let i=await l(t.cfg);if(i.length===1)return{channel:i[0],configured:i,source:`single-configured`};throw i.length===0?Error(`Channel is required (no configured channels detected).`):Error(`Channel is required when multiple channels are configured: ${i.join(`, `)}`)}export{u as n,l as t};
