import{n as e}from"./rolldown-runtime-DkW27tQK.js";import{Ci as t}from"./control-ui-foundation-CeFMP1Ly.js";import{bc as n,r}from"./control-ui-core-pH6nakZ-.js";import{G as i,J as a,W as o}from"./lit-runtime-BEtFSUCp.js";import{Ht as s,Lt as c,Rt as l,qt as u}from"./control-ui-core-Br5DB0Zj.js";function d(e,t,n){return JSON.stringify([e,t,n])}function f(e){return d(e?.requestedAgentId??``,e?.catalogId??``,e?.group??``)}function p(e){let t=r(e);return d(t.agentId,t.catalogId,t.group??``)}function m(e){return!!e?.catalogId}function h(e){return!!(e?.catalogId&&e.model&&e.catalogLabel)}function g(e){return m(e)&&!h(e)||!!(e?.group&&e.groupStatus!==`resolved`)}function _(e){return JSON.stringify([e?.groupStatus??``,e?.groupCwd??``,e?.groupWorktree===!0,e?.groupCatalogGeneration??-1,e?.groupDefaultsStatus??`idle`])}function v(e,t){let n=e?.group?.trim();if(!n)return!1;let r=t.groupsGeneration(),i=t.groupsStatus();if(e?.groupCatalogGeneration!==r||e.groupDefaultsStatus!==i)return!0;if(i!==`ready`)return!1;let a=t.state.groupSettings.find(e=>e.name===n);return a?e.groupStatus!==`resolved`||(e.groupCwd??``)!==(a.cwd??``)||e.groupWorktree!==(a.worktree===!0):e.groupStatus===`resolved`}function y(e,t){let n=t.state.groupSettings.find(t=>t.name===e?.group);return JSON.stringify([e?.group??``,t.groupsGeneration(),t.groupsStatus(),!!n,n?.cwd??``,n?.worktree===!0])}function b(e,t){return!!(e?.group&&(!t||v(e,t)))}function x(e,t){return g(e)||b(e,t)}function S(e,t){return e?.groupStatus===`resolved`&&!b(e,t)?e.group:void 0}function C(e,n,r){let i=e?.agentId?.trim();if(!i)return r&&t(r);let a=t(i);return n.some(e=>t(e.id)===a)?a:r&&t(r)}function w(e,t){return!m(e)||h(e)&&!!t}async function T(e,t,n){try{let r=(await e.request(`sessions.catalog.list`,{...n?{agentId:n}:{},catalogId:t,limitPerHost:1})).catalogs.find(e=>e.id===t),i=r?.capabilities.createSession?.model.trim();return r&&i?{model:i,catalogLabel:r.label,startTerminal:r.capabilities.createSession?.startTerminal===!0}:void 0}catch{return}}function E(e){if(!m(e))return i;let t=h(e),n=e?.catalogLabel||e?.catalogId||``;return a` ${n} `}function D(e){let t=g(e.data)||e.groupPending===!0;return a`