Files
openclaw-config/cache/control-ui-assets/d08fd045b9cb86d13f0b4aa403c8a06ddcd32e533058ae463245169e5cff5e85/assets/workboard-card-chip.runtime-CA0GB22y.js
T

12 lines
6.2 KiB
JavaScript

import{n as e}from"./rolldown-runtime-DkW27tQK.js";import{er as t,ti as n}from"./control-ui-foundation-CeFMP1Ly.js";import{Cn as r,Ec as i,bc as a,fl as o,ml as s,wn as c}from"./control-ui-core-pH6nakZ-.js";import{G as l,J as u,W as d,Z as f,at as p,rt as m}from"./lit-runtime-BEtFSUCp.js";import{qn as h,zn as g}from"./control-ui-core-DGVkFhVB.js";import{Ht as _,Lt as v,Rt as y,qt as b}from"./control-ui-core-Br5DB0Zj.js";import{i as x,t as S}from"./normalization-m-N_6hXH.js";function C(e){return i(e.trim())}function w(e){return[e.sessionKey,e.execution?.sessionKey,...e.metadata?.attempts?.map(e=>e.sessionKey)??[],...e.events?.map(e=>e.sessionKey)??[]].filter(e=>typeof e==`string`).map(C).filter(Boolean)}function T(e){return{cardId:e.id,title:e.title,status:e.status,boardId:e.metadata?.automation?.boardId?.trim()||`default`}}function E(e){let t=new Map;for(let n of e.toSorted((e,t)=>t.updatedAt-e.updatedAt)){let e=T(n);for(let r of w(n))t.has(r)||t.set(r,e)}return t}function D(e){if(!e||typeof e!=`object`||!(`attempts`in e))return[];let t=e.attempts;return Array.isArray(t)?t.flatMap(e=>{if(!e||typeof e!=`object`||!(`sessionKey`in e))return[];let t=e.sessionKey;return typeof t==`string`?[C(t)]:[]}):[]}function O(e){let t=j.get(e);t||(t={lookup:new A(e),consumers:0},j.set(e,t));let n=t;n.consumers+=1;let r=!1;return{subscribe:(e,t)=>n.lookup.subscribe(e,t),release:()=>{if(r)return;r=!0;let t=j.get(e);!t||t!==n||(--t.consumers,t.consumers===0&&(j.delete(e),t.lookup.dispose()))}}}var k,A,j;function M(){return(M=e((()=>{a(),r(),S(),n(),k=16,A=class{constructor(e){this.client=e,this.listeners=new Map,this.matches=new Map,this.runCandidates=[],this.runCandidateIndex=0,this.generation=0,this.loaded=!1,this.unsubscribeGateway=e.addEventListener(e=>{e.event===`plugin.workboard.changed`&&this.invalidate()})}subscribe(e,t){let n=C(e),r=this.listeners.get(n);if(r||(r=new Set,this.listeners.set(n,r)),r.add(t),this.loaded){let e=this.matches.get(n)??null;t(e),e||this.scanMissingRunMatches()}return this.loaded||this.refresh(),()=>{r?.delete(t),r?.size===0&&this.listeners.delete(n)}}dispose(){this.generation+=1,this.listeners.clear(),this.matches.clear(),this.refreshPromise=void 0,this.runCandidates=[],this.runCandidateIndex=0,this.runScanPromise=void 0,this.loaded=!1,this.unsubscribeGateway()}invalidate(){this.generation+=1,this.matches.clear(),this.refreshPromise=void 0,this.runCandidates=[],this.runCandidateIndex=0,this.runScanPromise=void 0,this.loaded=!1,this.listeners.size>0&&this.refresh()}refresh(){if(this.loaded)return Promise.resolve();if(this.refreshPromise)return this.refreshPromise;let e=this.generation,t=this.loadMatches().then(t=>{if(e===this.generation){this.matches=t.matches,this.runCandidates=t.runCandidates,this.runCandidateIndex=0,this.loaded=!0;for(let[e,n]of this.listeners){let r=t.matches.get(e)??null;for(let e of n)e(r)}this.scanMissingRunMatches()}}).catch(()=>{if(e===this.generation)for(let e of this.listeners.values())for(let t of e)t(null)});return this.refreshPromise=t,t.finally(()=>{this.refreshPromise===t&&(this.refreshPromise=void 0)}),t}async loadMatches(){let e=await this.client.request(`workboard.cards.list`,{}),t=x(e).cards.filter(c);return{matches:E(t),runCandidates:t.toSorted((e,t)=>t.updatedAt-e.updatedAt).filter(e=>e.metadata?.attempts===void 0&&(e.runId||e.execution?.runId)).slice(0,k)}}missingSessionKeys(){return[...this.listeners.keys()].filter(e=>!this.matches.has(e))}scanMissingRunMatches(){if(!this.loaded||this.runScanPromise||this.missingSessionKeys().length===0)return this.runScanPromise??Promise.resolve();let e=this.generation,t=(async()=>{for(;e===this.generation&&this.runCandidateIndex<this.runCandidates.length&&this.missingSessionKeys().length>0;){let t=this.runCandidates[this.runCandidateIndex];if(this.runCandidateIndex+=1,!t)return;let n;try{n=await this.client.request(`workboard.cards.runs`,{id:t.id})}catch{continue}if(e!==this.generation)return;let r=T(t);for(let e of D(n))if(!this.matches.has(e)){this.matches.set(e,r);for(let t of this.listeners.get(e)??[])t(r)}}})();return this.runScanPromise=t,t.finally(()=>{this.runScanPromise===t&&(this.runScanPromise=void 0,e===this.generation&&this.runCandidateIndex<this.runCandidates.length&&this.missingSessionKeys().length>0&&this.scanMissingRunMatches())}),t}},j=new WeakMap})))()}var N;function P(){return(P=e((()=>{d(),f(),g(),y(),_(),M(),s(),N=class extends o{constructor(...e){super(...e),this.active=!0,this.basePath=``,this.client=null,this.sessionKey=``,this.match=null,this.lease=null,this.observedSessionKey=``,this.unsubscribe=null}connectedCallback(){super.connectedCallback(),this.synchronizeLookup()}updated(){this.isConnected&&this.synchronizeLookup()}disconnectedCallback(){this.releaseLookup(),super.disconnectedCallback()}synchronizeLookup(){let e=this.client,t=this.sessionKey.trim();if(!this.active||!e||!t){this.releaseLookup();return}let n=this.lease;n?.client!==e&&(this.releaseLookup(),n={...O(e),client:e},this.lease=n),this.observedSessionKey!==t&&(this.unsubscribe?.(),this.observedSessionKey=t,this.match=null,this.unsubscribe=n.subscribe(t,e=>{this.lease===n&&this.observedSessionKey===t&&(this.match=e)}))}releaseLookup(){this.unsubscribe?.(),this.unsubscribe=null,this.lease?.release(),this.lease=null,this.observedSessionKey=``,this.match=null}render(){let e=this.match;if(!this.active||!e)return l;let t=b(`workboard.status.${e.status}`),n=`${h(`workboard`,this.basePath)}?${new URLSearchParams({board:e.boardId})}`;return u`
<a
class="board-session-surface__workboard-chip"
href=${n}
aria-label=${b(`chat.board.workboardCard`,{title:e.title,status:t})}
>
${v.kanban}
<span class="board-session-surface__workboard-title">${e.title}</span>
<span class="board-session-surface__workboard-status">${t}</span>
</a>
`}},t([p({type:Boolean})],N.prototype,`active`,void 0),t([p({attribute:!1})],N.prototype,`basePath`,void 0),t([p({attribute:!1})],N.prototype,`client`,void 0),t([p({attribute:!1})],N.prototype,`sessionKey`,void 0),t([m()],N.prototype,`match`,void 0),customElements.get(`openclaw-workboard-card-chip`)||customElements.define(`openclaw-workboard-card-chip`,N)})))()}P();
//# sourceMappingURL=workboard-card-chip.runtime-CA0GB22y.js.map