"use strict";(self.webpackChunk_kb_labs_agent_entry=self.webpackChunk_kb_labs_agent_entry||[]).push([["669"],{4332(s,e,t){t.r(e),t.d(e,{EventBusProvider:()=>h,StudioEventBus:()=>o,eventBus:()=>n,useEventBusContext:()=>l});var r=t(2913),i=t(4552),o=class{subscriptions=new Map;history=[];devToolsObserver;subscribe(s,e,t,r){let i={event:s,handler:e,pluginId:t,pageId:r};return this.subscriptions.has(s)||this.subscriptions.set(s,new Set),this.subscriptions.get(s).add(i),()=>{this.subscriptions.get(s)?.delete(i)}}publish(s,e,t,r){let i={sourcePluginId:t,sourcePageId:r,timestamp:Date.now()},o={event:s,payload:e,meta:i};this.history.push(o),this.history.length>100&&this.history.shift(),this.devToolsObserver?.(o);let n=this.subscriptions.get(s);if(n)for(let t of n)try{t.handler(e,i)}catch(e){console.error(`[StudioEventBus] Handler error for "${s}" in ${t.pluginId}:${t.pageId}:`,e)}}unsubscribeAll(s,e){for(let[,t]of this.subscriptions)for(let r of t)r.pluginId===s&&r.pageId===e&&t.delete(r)}getHistory(){return this.history}setDevToolsObserver(s){this.devToolsObserver=s}clearDevToolsObserver(){this.devToolsObserver=void 0}reset(){this.subscriptions.clear(),this.history=[]}},n=new o,u=(0,r.createContext)(n);function h({children:s,bus:e}){return(0,i.jsx)(u.Provider,{value:e??n,children:s})}function l(){return(0,r.useContext)(u)}}}]);
//# sourceMappingURL=669.js.map