Spaces:
Running
Running
| ;(self.webpackChunk_carbon_ai_chat_examples_web_components_basic=self.webpackChunk_carbon_ai_chat_examples_web_components_basic||[]).push([[9135],{39135:function(t,e,a){a.d(e,{workspaceService:function(){return n}});class s{lastFetchTime=0;cachedData=null;pendingRequest=null;MIN_INTERVAL_MS=3e3;listeners=new Set;constructor(){}static getInstance(){return s.instance||(s.instance=new s),s.instance}subscribe(t){return this.listeners.add(t),this.cachedData&&t(this.cachedData),()=>{this.listeners.delete(t)}}notifyListeners(t){this.listeners.forEach(e=>{try{e(t)}catch(t){}})}async getWorkspaceTree(t=!1){const e=Date.now()-this.lastFetchTime;if(!t&&this.cachedData&&e<this.MIN_INTERVAL_MS)return this.cachedData;if(this.pendingRequest)return this.pendingRequest;if(e<this.MIN_INTERVAL_MS){const t=this.MIN_INTERVAL_MS-e;await new Promise(e=>setTimeout(e,t))}this.pendingRequest=this.fetchWorkspaceData();try{const t=await this.pendingRequest;return this.cachedData=t,this.lastFetchTime=Date.now(),this.notifyListeners(t),t}finally{this.pendingRequest=null}}async fetchWorkspaceData(){try{const t=await fetch("/api/workspace/tree");if(!t.ok)throw new Error(`HTTP error! status: ${t.status}`);return{tree:(await t.json()).tree||[],timestamp:Date.now()}}catch(t){return this.cachedData?this.cachedData:{tree:[],timestamp:Date.now()}}}getCachedData(){return this.cachedData}clearCache(){this.cachedData=null,this.lastFetchTime=0}}const n=s.getInstance()}}]); |