const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./channel-avatar-CNP_6012.js","./rolldown-runtime-DkW27tQK.js","./control-ui-foundation-CeFMP1Ly.js","./control-ui-core-pH6nakZ-.js","./lit-runtime-BEtFSUCp.js","./control-ui-core-DGVkFhVB.js","./control-ui-core-Br5DB0Zj.js","./gateway-runtime-DUNO4Mi1.js","./control-ui-core-C8H8-RSs.css","./control-ui-boot-Cdpgu1Gm.js","./control-ui-boot-wpHCbPL9.js","./control-ui-boot-gfE6fZcA.js","./config-runtime-C4gfjhZc.js","./control-ui-boot-CKTkvwFZ.js","./control-ui-boot-BPFwXC8p.js","./control-ui-boot-DdPrPuw0.js","./control-ui-boot-9_2QGLIL.js","./control-ui-boot-J-x6DHHT.js","./control-ui-boot-B1lcIXow.js","./control-ui-boot-Clhp68JE.js","./control-ui-boot-D1DWJlBr.js","./control-ui-boot-CQvujP8f.js","./control-ui-boot-BW_XZcbY.js","./control-ui-boot-__AsqpzJ.css","./markdown-runtime-BcrsAQtF.js"])))=>i.map(i=>d[i]);
import{n as e}from"./rolldown-runtime-DkW27tQK.js";import{Ai as t,Ci as n,En as r,Gt as i,Nr as a,Pr as o,mi as s,pi as c,wn as l}from"./control-ui-foundation-CeFMP1Ly.js";import{Dc as u,bc as d,hc as f,jc as p,mc as m}from"./control-ui-core-pH6nakZ-.js";import{G as h,J as g,K as _,W as v,ct as y}from"./lit-runtime-BEtFSUCp.js";import{At as b,Tt as x,Xt as S,Zt as ee,jt as te,wt as ne}from"./control-ui-core-DGVkFhVB.js";import{Gt as C,Ht as w,Lt as T,Rt as re,qt as E}from"./control-ui-core-Br5DB0Zj.js";import{Dr as ie,Er as ae,Gc as oe,Hc as se,Jo as D,Kc as ce,Nc as le,Or as ue,Pc as de,Rc as fe,Ss as pe,Tr as me,Uc as O,Vc as he,Wc as k,Xo as ge,Yo as _e,Zo as A,bs as ve,qc as j,xs as ye}from"./control-ui-boot-Cdpgu1Gm.js";import{Bn as be,zn as xe}from"./control-ui-boot-D1DWJlBr.js";import{n as Se,r as Ce,t as we}from"./portaled-hovercard-Cn6SxKYU.js";function M(e){return e.label?.trim()||e.identity.id}function N(e,t,n){return e.identity.type===`profile`&&e.identity.id===n||JSON.stringify(e.identity)===JSON.stringify(t?.identity)}function Te(){Le??=a(()=>import(`./channel-avatar-CNP_6012.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24]),import.meta.url)}function Ee(e){return E(`sessionHovercard.states.${e}`)}function De(e){switch(e.state){case`passing`:return E(`sessionHovercard.checks.passing`);case`failing`:return E(`sessionHovercard.checks.failing`);case`pending`:return E(`sessionHovercard.checks.pending`);default:return e.state}}function Oe(e){switch(e){case`open`:return T.gitPullRequest;case`draft`:return T.gitPullRequestDraft;case`merged`:return T.gitMerge;case`closed`:return T.gitPullRequestClosed;default:return e}}function P(e){return E(e===1?`sessionHovercard.changedFile`:`sessionHovercard.changedFiles`,{count:String(e)})}function F(e){return e.additions===void 0&&e.deletions===void 0&&e.changedFiles===void 0?h:g`<span class="session-hovercard__diff">
    ${e.changedFiles===void 0?h:g`<span class="session-hovercard__files">${P(e.changedFiles)}</span>`}
    ${e.additions===void 0?h:g`<span class="session-hovercard__additions">+${e.additions.toLocaleString()}</span>`}
    ${e.deletions===void 0?h:g`<span class="session-hovercard__deletions">−${e.deletions.toLocaleString()}</span>`}
  </span>`}function ke(e){let t=Math.abs(e)/864e5;return t>=365?{value:Math.max(1,Math.round(t/365)),unit:`year`}:t>=28?{value:Math.max(1,Math.round(t/30)),unit:`month`}:t>=7?{value:Math.max(1,Math.round(t/7)),unit:`week`}:t>=1?{value:Math.max(1,Math.round(t)),unit:`day`}:r(Math.abs(e))}function I(e,t){if(typeof e!=`number`||!Number.isFinite(e))return``;let n=e-Date.now(),{value:r,unit:i}=ke(n);if(t)return i===`second`&&n<=0?E(`common.justNow`):new Intl.RelativeTimeFormat(C.getLocale(),{numeric:`always`,style:`narrow`}).format(n<=0?-r:r,i);if(C.getLocale().toLowerCase().startsWith(`en`)){let e={day:`d`,week:`w`,month:`mo`,year:`y`}[i];if(e)return`${r}${e}`}return new Intl.NumberFormat(C.getLocale(),{style:`unit`,unit:i,unitDisplay:`short`,maximumFractionDigits:0}).format(r)}function Ae(e){let t=typeof e.createdAt==`number`&&Number.isFinite(e.createdAt),n=t?I(e.createdAt,!0):``,r=t?I(e.createdAt,!1):``,i=I(e.updatedAt,!0);return g`<header class="session-hovercard__header">
    <span class="session-hovercard__heading">
      <span class="session-hovercard__title">${de(e.color)}${e.label}</span>
      ${i?g`<span class="session-hovercard__meta"
            >${E(`channels.hub.updatedAgo`,{ago:i})}</span
          >`:h}
    </span>
    ${r?g`<span class="session-hovercard__created-age" title=${n}>${r}</span>`:h}
  </header>`}function je(e,t,n){let[r,i]=E(`sessionsView.withParticipant`).split(`{name}`);if(i===void 0)return E(`sessionsView.withParticipant`,{name:t});let a=e.map(e=>e.identity.type===`profile`?k(e.identity.id,n):null),o=new Intl.ListFormat(C.getLocale(),{style:`long`,type:`unit`}).formatToParts(e.map(M)),s=[],c=0;for(let e of o){if(e.type===`literal`){s.push(e.value);continue}s.push(j(e.value,a[c]??null,`session-hovercard__participant-name`)),c+=1}return g`${r}${s}${i}`}function Me({row:e,selfUserId:t,avatarAuth:n,personActivity:r}){let i=e?.createdActor,a=i?.label?.trim()||i?.id?.trim(),o=i?he(i):``,s=o?g`<span class="session-hovercard__creator-avatar-fallback" aria-hidden="true"
        >${o}</span
      >`:h,c=e?.workContext,l=e?.placementProviderId&&e.placementProfileId?{label:`${e.placementProviderId} · ${e.placementProfileId}`,title:E(`sessionHovercard.runsOn`,{providerId:e.placementProviderId,profileId:e.placementProfileId})}:void 0,u=new Set,d=0,f=(e?.participants??[]).filter(e=>{let n=JSON.stringify(e.identity);return!u.has(n)&&(u.add(n),!N(e,i,t)||(d+=1,!1))}),p=f.slice(0,R),m=p.map(M),_=new Intl.ListFormat(C.getLocale(),{style:`long`,type:`unit`}).format(m),v=Math.max(0,Math.max(f.length,(e?.participantCount??0)-d)-p.length),y=[_,v>0?E(`sessionHovercard.moreParticipantsLabel`,{count:String(v)}):``].filter(Boolean).join(` `);if(!a&&!c&&!l&&p.length===0&&e?.boardFace!==`dashboard`&&e?.hasAutomation!==!0)return h;e?.channelAvatarUrl&&Te();let b=i?.id,x=i?.identity?.type===`profile`?k(i.identity.id,r):null,S=e?.channelAvatarUrl?g`<openclaw-channel-avatar
        class="session-hovercard__creator-avatar"
        .routeUrl=${e.channelAvatarUrl}
        .authTokens=${n?.authTokens??[]}
        .authReady=${n?.authReady??!1}
        .fallback=${s}
        aria-hidden="true"
      ></openclaw-channel-avatar>`:b?g`<openclaw-viewer-avatar
          class="session-hovercard__creator-avatar"
          .user=${{id:b,name:i?.label,avatarUrl:i?.avatarUrl,watchedSessions:[]}}
          .markAsViewer=${!1}
          .identity=${i?.identity}
          variant="session"
          aria-hidden="true"
        ></openclaw-viewer-avatar>`:g`<span class="session-hovercard__context-icon" aria-hidden="true"
          >${T.users}</span
        >`;return g`<div class="session-hovercard__context">
    ${a||p.length>0?g`<div
          class="session-hovercard__context-row session-hovercard__identity-row"
          aria-label=${[a,y].filter(Boolean).join(`, `)}
        >
          ${ce(S,x)}
          <span class="session-hovercard__identity-copy">
            ${a?j(a,x,`session-hovercard__identity-name`):h}
            ${a&&p.length>0?g`<span class="session-hovercard__identity-separator" aria-hidden="true"
                  >·</span
                >`:h}
            ${p.length>0?g`<span class="session-hovercard__participants">
                  <span class="session-hovercard__participant"
                    >${je(p,_,r)}</span
                  >
                  ${v>0?g`<span class="session-hovercard__participants-more"
                        >${E(`sessionHovercard.moreParticipants`,{count:String(v)})}</span
                      >`:h}
                </span>`:h}
          </span>
        </div>`:h}
    ${c?g`<div
            class="session-hovercard__context-row"
            aria-label=${`${E(c.kind===`project`?`sessionHovercard.projectLabel`:`sessionHovercard.workspaceLabel`)}: ${c.name}`}
            title=${`${E(c.kind===`project`?`sessionHovercard.projectLabel`:`sessionHovercard.workspaceLabel`)}: ${c.path}`}
          >
            <span class="session-hovercard__context-icon" aria-hidden="true">${T.folder}</span>
            <span
              class="session-hovercard__context-value session-hovercard__context-text"
              title=${c.path}
              >${c.name}</span
            >
          </div>
          ${c.kind===`project`&&c.branch?g`<div
                class="session-hovercard__context-row"
                aria-label=${`${E(`sessionHovercard.branchLabel`)}: ${c.branch}`}
                title=${`${E(`sessionHovercard.branchLabel`)}: ${c.branch}`}
              >
                <span class="session-hovercard__context-icon" aria-hidden="true"
                  >${T.gitBranch}</span
                >
                <span
                  class="session-hovercard__context-value session-hovercard__context-text"
                  title=${c.branch}
                  >${c.branch}</span
                >
              </div>`:h}`:h}
    ${l?g`<div
          class="session-hovercard__context-row"
          aria-label=${l.title}
          title=${l.title}
        >
          <span class="session-hovercard__context-icon" aria-hidden="true">${T.server}</span>
          <span class="session-hovercard__context-value session-hovercard__context-text"
            >${l.label}</span
          >
        </div>`:h}
    ${e?.boardFace===`dashboard`?g`<div
          class="session-hovercard__context-row"
          aria-label=${E(`sessionsView.opensAsDashboard`)}
        >
          <span class="session-hovercard__context-icon" aria-hidden="true"
            >${T.layoutDashboard}</span
          >
          <span class="session-hovercard__context-value session-hovercard__context-text"
            >${E(`sessionsView.opensAsDashboard`)}</span
          >
        </div>`:h}
    ${e?.hasAutomation===!0?g`<div
          class="session-hovercard__context-row"
          aria-label=${E(`sessionsView.automationAttached`)}
        >
          <span class="session-hovercard__context-icon" aria-hidden="true">${T.clock}</span>
          <span class="session-hovercard__context-value session-hovercard__context-text"
            >${E(`sessionsView.automationAttached`)}</span
          >
        </div>`:h}
  </div>`}function Ne(e){return e?g`<span
    class="session-hovercard__pr-author"
    title=${E(`sessionHovercard.pullRequestAuthorLabel`,{login:e.login})}
    >${e.login}</span
  >`:g`<span class="session-hovercard__pr-author"></span>`}function Pe(e){let t=Ee(e.state),n=e.checks?De(e.checks):null,r=[e.author?E(`sessionHovercard.pullRequestAuthorLabel`,{login:e.author.login}):null,n,e.changedFiles===void 0?null:P(e.changedFiles),e.additions===void 0?null:`+${e.additions.toLocaleString()}`,e.deletions===void 0?null:`−${e.deletions.toLocaleString()}`].filter(e=>!!e);return g`<a
    class="session-hovercard__pr-row"
    data-state=${e.state}
    href=${e.url}
    target="_blank"
    rel="noopener noreferrer"
    aria-label=${`${E(`sessionHovercard.pullRequestLabel`,{number:String(e.number),state:t})}${r.length>0?`, ${r.join(`, `)}`:``}`}
  >
    <span
      class="session-hovercard__pr-state-icon"
      role="img"
      data-checks=${e.checks?.state??h}
      aria-label=${n?`${t} · ${n}`:t}
      title=${n?`${t} · ${n}`:t}
      >${Oe(e.state)}</span
    >
    <span class="session-hovercard__pr-number">#${e.number}</span>
    ${Ne(e.author)}${F(e)}
  </a>`}function Fe(e){if(!e)return h;if(e.pullRequests.length>0){let t=e.pullRequests.slice(0,L),n=e.pullRequests.length-t.length;return g`<div class="session-hovercard__pr-list">
      ${t.map(Pe)}
      ${n>0?g`<span class="session-hovercard__more"
            >${E(`sessionHovercard.more`,{count:String(n)})}</span
          >`:h}
    </div>`}let t=e.branch;if(!t)return h;let n=E(`chat.pullRequests.createPr`);return g`
    <div class="session-hovercard__branch-row">
      <span class="session-hovercard__branch-icon" aria-hidden="true">${T.gitBranch}</span>
      <span class="session-hovercard__branch-name"
        >${t.owner}/${t.repo} · ${t.branch}</span
      >
      ${F(t)}
    </div>
    ${t.createUrl?g`<div class="session-hovercard__no-pr">
          <a href=${t.createUrl} target="_blank" rel="noopener noreferrer"
            >${n}</a
          >
        </div>`:h}
  `}function Ie(e){let t=!!(e.pullRequests&&(e.pullRequests.pullRequests.length>0||e.pullRequests.branch)),n=e.row?.participants?.some(t=>!N(t,e.row?.createdActor,e.selfUserId)),r=!!(e.row?.channelAvatarUrl||e.row?.createdActor||e.row?.workContext||e.row?.placementProviderId&&e.row.placementProfileId||e.row?.boardFace===`dashboard`||e.row?.hasAutomation===!0||n),i=e.progressCard?void 0:e.row?.lastMessagePreview?.trim()||void 0;return!e.row&&!t&&!e.progressCard?h:g`<div class="session-hovercard">
    ${e.row?g`<section class="session-hovercard__section session-hovercard__section--header">
          ${Ae(e.row)}
        </section>`:h}
    ${r?g`<section class="session-hovercard__section session-hovercard__section--metadata">
          ${Me(e)}
        </section>`:h}
    ${t?g`<section class="session-hovercard__section session-hovercard__section--prs">
          ${Fe(e.pullRequests)}
        </section>`:h}
    ${i?g`<section class="session-hovercard__section session-hovercard__section--optional">
          <div class="session-hovercard__excerpt">${i}</div>
        </section>`:h}
    ${e.progressCard?g`<footer class="session-hovercard__section session-hovercard__progress-footer">
          ${ae(e.progressCard,`hovercard`,void 0,e.row?.status,e.row?.startedAt,e.row?.endedAt)}
        </footer>`:h}
  </div>`}var L,R,Le;function z(){return(z=e((()=>{i(),v(),w(),re(),O(),le(),fe(),me(),se(),o(),L=4,R=3})))()}function Re(e){if(!l(e)||e.status!==`ok`)throw Error(`Session title unavailable`);let n=t(e.sessionKey),r=t(e.agentId);if(!n||!r)throw Error(`Session title response was incomplete`);return{sessionKey:n,agentId:r,namespace:`chat`,title:t(e.title)??t(e.derivedTitle)}}function ze(e,t){return{...t,sessionKey:e.key,agentId:e.agentId??u(e.key)?.agentId??t.agentId,title:e.displayName??e.derivedTitle}}var B,V,H,U,W;function G(){return(G=e((()=>{s(),S(),b(),d(),xe(),B=`a.markdown-session-link`,V=3e5,H=3e4,U=100,W=class{constructor(e){this.host=e,this.client=null,this.context=null,this.cache=new Map,this.observer=new MutationObserver(e=>{for(let t of e)for(let e of t.addedNodes)if(e instanceof Element){e instanceof HTMLAnchorElement&&e.matches(B)&&this.decorate(e);for(let t of e.querySelectorAll(B))this.decorate(t)}})}connect(){this.observer.observe(this.host,{childList:!0,subtree:!0}),this.refresh()}refresh(){for(let e of this.host.querySelectorAll(B))this.decorate(e)}disconnect(){this.observer.disconnect()}async decorate(e,t=!1){let n=this.targetForAnchor(e);if(!n)return;let r=this.cachedOrSeededEntry(n);if(this.stampAnchor(e,n,r?.value),!(!t||r?.value))try{this.stampAnchor(e,n,await this.loadTitle(n))}catch{}}mainKey(){let e=this.context;return e?p({agentsList:e.agents.state.agentsList,hello:e.gateway.snapshot.hello}):`main`}resolveShortTarget(e){let t=this.context?.sessions.state.result?.sessions??[];for(let r of t){let t=u(r.key),i=be(r.key);if(t&&n(t.agentId)===n(e.agentId)&&i?.startsWith(e.shortId.toLowerCase().replaceAll(`-`,``))&&(!e.slugHint||c(r.displayName)===e.slugHint))return r.key}return null}targetForAnchor(e){let t=e.dataset.sessionKey?.trim();if(t){let e=u(t);return e?{sessionKey:t,agentId:e.agentId,namespace:`chat`}:null}let n;try{n=new URL(e.href,globalThis.location?.href??`http://localhost/`)}catch{return null}if(n.origin!==globalThis.location?.origin)return null;let r=te(n.pathname,this.context?.basePath??``,this.mainKey());if(!r)return null;let i=r.kind===`main`?f({agentId:r.agentId,mainKey:this.mainKey()}):r.kind===`literal`?r.sessionKey:this.resolveShortTarget(r);return i?{sessionKey:i,agentId:r.agentId,namespace:r.namespace}:null}findSeedRow(e){return this.context?.sessions.state.result?.sessions.find(t=>m(t.key,e.sessionKey))}setCacheEntry(e,t){for(this.cache.delete(e),this.cache.set(e,t);this.cache.size>U;){let e=this.cache.keys().next().value;if(!e)break;this.cache.delete(e)}}cachedOrSeededEntry(e){let t=Date.now(),n=this.cache.get(e.sessionKey);if(n&&n.expiresAt>t)return this.setCacheEntry(e.sessionKey,n),n;n&&this.cache.delete(e.sessionKey);let r=this.findSeedRow(e);if(!r)return;let i=ze(r,e),a={expiresAt:t+V,promise:Promise.resolve(i),value:i};return this.setCacheEntry(e.sessionKey,a),a}loadTitle(e){let t=this.cachedOrSeededEntry(e);if(t)return t.promise;let n={expiresAt:Date.now()+V,promise:Promise.resolve().then(async()=>{if(!this.client)throw Error(`Session title requires a connected Gateway`);return{...Re(await this.client.request(`controlUi.sessionPreview`,{sessionKey:e.sessionKey})),namespace:e.namespace}})};return n.promise=n.promise.then(e=>(n.value=e,e),e=>{throw n.expiresAt=Date.now()+H,e}),this.setCacheEntry(e.sessionKey,n),n.promise}stampAnchor(e,t,n){let r=n?.title,i=ee(t.namespace,t.agentId,t.sessionKey,this.context?.basePath,{displayName:r,exactKey:!0,mainKey:this.mainKey()});i&&e.getAttribute(`href`)!==i&&e.setAttribute(`href`,i),!(!r||e.classList.contains(`markdown-session-link--titled`))&&(e.classList.add(`markdown-session-link--titled`),e.textContent=r,e.title=t.sessionKey)}}})))()}function K(e){return e.querySelector(`[data-session-menu][aria-expanded="true"], [data-catalog-session-menu][aria-expanded="true"]`)!==null}var q,J,Y,X,Z,Q,Be;function $(){return($=e((()=>{v(),ne(),w(),ie(),ve(),d(),O(),Ce(),z(),G(),_e(),q=450,J=80,Y=300,X=100,Z=100,Q=0,Be=class extends y{constructor(...e){super(...e),this.applicationClient=null,this.applicationContext=null,this.applicationGateway=null,this.progressCards=null,this.stopProgressCardUpdates=null,this.stopSessionUpdates=null,this.pullRequests=null,this.stopPullRequestUpdates=null,this.activeTarget=null,this.activeTrigger=null,this.activeSessionKey=null,this.activePullRequestKey=null,this.suppressFocusOpen=!1,this.open=!1,this.delayed=!0,this.animateNextOpen=!0,this.skipDelayTimer=null,this.lastProgressCard=null,this.hovercard=new we(()=>this.close(!0),X),this.sessionLinkTitler=new W(this),this.loadGeneration=0,this.activeTargetObserver=new MutationObserver(()=>{if(this.activeTarget&&(!this.contains(this.activeTarget)||K(this))){this.close();return}this.open&&this.showCurrent()}),this.handleProgressCardUpdate=()=>{let e=this.activeSessionKey;if(!e||!this.open||!this.hovercard.held)return;let t=this.progressCards?.get(e);t!==void 0&&(this.lastProgressCard=t),this.showCurrent()},this.handleSessionUpdate=()=>{this.open&&this.hovercard.held&&this.showCurrent()},this.handlePullRequestUpdate=()=>{this.open&&this.hovercard.held&&this.showCurrent()},this.handlePointerOver=e=>{if(e.pointerType===`touch`||!globalThis.matchMedia?.(`(hover: hover)`).matches)return;let t=A(e);if(!t||K(this))return;let n=this.delayed;this.activate(t,t,n?q:J,n),this.hovercard.pointerInside=!0},this.handlePointerOut=e=>{let t=A(e);!t||t!==this.activeTarget||e.relatedTarget instanceof Node&&t.contains(e.relatedTarget)||this.hovercard.schedulePointerExit(e,t)},this.handleFocusIn=e=>{if(this.suppressFocusOpen)return;let t=A(e),n=e.target instanceof HTMLElement?e.target:null,r=t?.matches(`.sidebar-recent-session`)?n?.closest(`a.sidebar-recent-session__link`):n;!t||!r||K(this)||(this.activate(t,r,0,!1),this.hovercard.focusInside=!0)},this.handleFocusOut=e=>{this.activeTarget&&(e.relatedTarget instanceof Node&&this.activeTarget.contains(e.relatedTarget)||(this.hovercard.focusInside=!1,this.hovercard.scheduleClose()))},this.handleKeyDown=e=>{if(e.key===`Escape`){this.close();return}if(e.key!==`Tab`||e.shiftKey||e.target!==this.activeTrigger)return;let t=this.cardFocusables()[0];t&&(e.preventDefault(),t.focus())},this.handleClick=e=>{A(e)&&this.close()},this.handleSessionMenuOpen=()=>{this.close()},this.handleCardPointerEnter=()=>{this.hovercard.pointerOverCard=!0,this.hovercard.clearClose()},this.handleCardPointerLeave=()=>{this.hovercard.pointerOverCard=!1,this.hovercard.scheduleClose()},this.handleCardFocusIn=()=>{this.hovercard.cardFocusInside=!0,this.hovercard.clearClose()},this.handleCardFocusOut=e=>{e.relatedTarget instanceof Node&&this.hovercard.card?.contains(e.relatedTarget)||(this.hovercard.cardFocusInside=!1,this.hovercard.scheduleClose())},this.handleCardKeyDown=e=>{if(e.key!==`Escape`&&e.key!==`Tab`)return;let t=this.cardFocusables(),n=e.shiftKey?t[0]:t.at(-1);if(e.key===`Tab`&&document.activeElement!==n)return;e.preventDefault();let r=this.activeTrigger;this.close(),this.suppressFocusOpen=!0,r?.focus({preventScroll:!0}),this.suppressFocusOpen=!1}}get client(){return this.applicationClient}set client(e){this.applicationClient=e,this.sessionLinkTitler.client=e}get context(){return this.applicationContext}set context(e){this.stopSessionUpdates?.(),this.stopSessionUpdates=null,this.applicationContext=e,this.sessionLinkTitler.context=e,this.isConnected&&(this.sessionLinkTitler.refresh(),this.connectStore())}get gateway(){return this.applicationGateway}set gateway(e){e!==this.applicationGateway&&(this.disconnectStore(),this.applicationGateway=e,this.close(),this.isConnected&&this.connectStore())}createRenderRoot(){return this}connectedCallback(){super.connectedCallback(),this.style.display=`contents`,this.addEventListener(`pointerover`,this.handlePointerOver),this.addEventListener(`pointerout`,this.handlePointerOut),this.addEventListener(`focusin`,this.handleFocusIn),this.addEventListener(`focusout`,this.handleFocusOut),this.addEventListener(`keydown`,this.handleKeyDown),this.addEventListener(`click`,this.handleClick),this.addEventListener(D,this.handleSessionMenuOpen),this.sessionLinkTitler.connect(),this.connectStore()}disconnectedCallback(){this.removeEventListener(`pointerover`,this.handlePointerOver),this.removeEventListener(`pointerout`,this.handlePointerOut),this.removeEventListener(`focusin`,this.handleFocusIn),this.removeEventListener(`focusout`,this.handleFocusOut),this.removeEventListener(`keydown`,this.handleKeyDown),this.removeEventListener(`click`,this.handleClick),this.removeEventListener(D,this.handleSessionMenuOpen),this.sessionLinkTitler.disconnect(),this.disconnectStore(),this.close(),this.clearSkipDelayTimer(),super.disconnectedCallback()}connectStore(){this.applicationContext&&!this.stopSessionUpdates&&(this.stopSessionUpdates=this.applicationContext.sessions.subscribe(this.handleSessionUpdate)),!(!this.applicationGateway||this.progressCards)&&(this.progressCards=ue(this.applicationGateway),this.stopProgressCardUpdates=this.progressCards.subscribe(this.handleProgressCardUpdate))}disconnectStore(){this.progressCards?.unwatch(this),this.stopProgressCardUpdates?.(),this.stopProgressCardUpdates=null,this.stopSessionUpdates?.(),this.stopSessionUpdates=null,this.progressCards=null,this.releasePullRequestStore()}activate(e,t,n,r){let i=e.dataset.sessionKey;if(!i)return;if(e===this.activeTarget&&i===this.activeSessionKey){if(t!==this.activeTrigger){if(this.hovercard.reset(),this.activeTrigger=t,this.hovercard.markTrigger(t),this.open)this.showCurrent();else{this.animateNextOpen=r;let e=++this.loadGeneration;this.hovercard.scheduleOpen(n,()=>void this.loadAndShow(i,e))}}return}this.close(n>0),this.activeTarget=e,this.activeTrigger=t,this.activeSessionKey=i,this.open=!1,this.animateNextOpen=r,this.lastProgressCard=null,this.progressCards?.watch(this,[i]),this.hovercard.markTrigger(t),this.activeTargetObserver.observe(this,{attributes:!0,attributeFilter:[`aria-expanded`],childList:!0,subtree:!0});let a=++this.loadGeneration;this.hovercard.scheduleOpen(n,()=>void this.loadAndShow(i,a))}async loadAndShow(e,t){let n=this.activeTarget;if(n instanceof HTMLAnchorElement&&n.dataset.sessionKey===e&&this.sessionLinkTitler.decorate(n,!0),!(t!==this.loadGeneration||this.activeSessionKey!==e||!n||K(this)||!this.hovercard.held)){this.open=!0,this.delayed=!1,this.clearSkipDelayTimer(),this.watchPullRequests(e),this.showCurrent();try{await this.progressCards?.load(e)}catch{}t===this.loadGeneration&&this.activeSessionKey===e&&this.hovercard.held&&this.showCurrent()}}watchPullRequests(e){let t=this.applicationGateway;if(!t)return;this.releasePullRequestStore();let n=u(e)?.agentId??t.snapshot.assistantAgentId;this.activePullRequestKey=ye(e,n??void 0),this.pullRequests=pe(t),this.stopPullRequestUpdates=this.pullRequests.subscribe(this.handlePullRequestUpdate),this.pullRequests.watch(this,[this.activePullRequestKey],{foreground:!0})}releasePullRequestStore(){this.pullRequests?.unwatch(this),this.stopPullRequestUpdates?.(),this.stopPullRequestUpdates=null,this.pullRequests=null,this.activePullRequestKey=null}showCurrent(){let e=this.activeTarget,t=this.activeSessionKey;if(!e||!t||!this.open)return;let n=this.querySelector(`openclaw-app-sidebar`)?.findSidebarHovercardRowByKey(t),r=this.activePullRequestKey?this.pullRequests?.get(this.activePullRequestKey):void 0,i=this.progressCards?.get(t);i!==void 0&&(this.lastProgressCard=i);let a=this.applicationGateway,o={authTokens:a?x({hello:a.snapshot.hello,settings:{token:a.connection.token},password:a.connection.password}):[],authReady:!!(a&&(a.snapshot.hello||a.connection.token.trim()||a.connection.password.trim()))},s=JSON.stringify({progress:this.lastProgressCard?.revision??null,pullRequests:r?{branch:r.branch,pullRequests:r.pullRequests}:null,row:n?{label:n.label,boardFace:n.boardFace,hasAutomation:n.hasAutomation,channelAvatarUrl:n.channelAvatarUrl,lastMessagePreview:n.lastMessagePreview,createdActor:n.createdActor,participants:n.participants,participantCount:n.participantCount,workContext:n.workContext,createdAt:n.createdAt,startedAt:n.startedAt,updatedAt:n.updatedAt,status:n.status,endedAt:n.endedAt}:null});if(this.hovercard.card?.dataset.revision===s)return;let c=this.hovercard.card,l=c?.contains(document.activeElement)&&document.activeElement instanceof HTMLElement?document.activeElement:null,u=l?this.cardFocusables().indexOf(l):-1,d=l instanceof HTMLAnchorElement?l.href:null,f=!c&&this.animateNextOpen,p=c;if(p||(Q+=1,p=Se(`openclaw-session-progress-hovercard-${Q}`,`session-progress-hovercard`),this.animateNextOpen=!1,f?p.dataset.open=`false`:p.dataset.instant=`true`),p.dataset.revision=s,p.setAttribute(`aria-label`,E(`sessionHovercard.ariaLabel`)),_(Ie({row:n,selfUserId:this.applicationContext?.gateway.snapshot.selfUser?.id,avatarAuth:o,personActivity:this.personActivity(),pullRequests:r,progressCard:this.lastProgressCard}),p),!p.firstElementChild){this.hovercard.clearCard(),this.hovercard.pointerOverCard=!1,this.hovercard.cardFocusInside=!1;return}if(c){if(l&&!p.contains(document.activeElement)){let e=this.cardFocusables(),t=(d?e.find(e=>e instanceof HTMLAnchorElement&&e.href===d):void 0)??e[u];t?t.focus({preventScroll:!0}):(this.hovercard.cardFocusInside=!1,this.suppressFocusOpen=!0,this.activeTrigger?.focus({preventScroll:!0}),this.suppressFocusOpen=!1,this.hovercard.focusInside=document.activeElement===this.activeTrigger)}this.hovercard.position();return}p.addEventListener(`pointerenter`,this.handleCardPointerEnter),p.addEventListener(`pointerleave`,this.handleCardPointerLeave),p.addEventListener(`focusin`,this.handleCardFocusIn),p.addEventListener(`focusout`,this.handleCardFocusOut),p.addEventListener(`keydown`,this.handleCardKeyDown),this.hovercard.mount(e,p,ge(e),!1,()=>_(h,p)),f&&(p.offsetWidth,window.setTimeout(()=>{this.hovercard.card===p&&this.open&&(p.dataset.open=`true`)},0))}cardFocusables(){return this.hovercard.focusables()}personActivity(){let e=this.applicationContext;return e?oe(e,()=>this.close()):void 0}close(e=!1){let t=this.open;this.hovercard.reset(e?Z:0),this.loadGeneration+=1,this.open=!1,this.animateNextOpen=!0,this.lastProgressCard=null,this.activeTargetObserver.disconnect(),this.progressCards?.unwatch(this),this.releasePullRequestStore(),this.activeTarget=null,this.activeTrigger=null,this.activeSessionKey=null,t&&(this.clearSkipDelayTimer(),this.skipDelayTimer=window.setTimeout(()=>{this.skipDelayTimer=null,this.delayed=!0},Y))}clearSkipDelayTimer(){this.skipDelayTimer!==null&&(window.clearTimeout(this.skipDelayTimer),this.skipDelayTimer=null)}}})))()}$();export{Be as SessionProgressHovercardProvider};
//# sourceMappingURL=session-progress-hovercard.runtime-C62MSXJB.js.map