var R=Object.defineProperty;var g=(i,r)=>R(i,"name",{value:r,configurable:!0});import{r as c,b as p}from"./HostCapabilitiesProvider-30w3CGIu.js";import{c as l,p as v,e as E,d as U,t as x}from"./mermaid-GHXKKRXX-IUK0bIya.js";function b(i,r){const d=typeof r=="function"?{onOrphaned:r}:r??{},{onOrphaned:f,onCreate:u}=d,t=c.useRef(new Map).current,o=new Set(i.map(e=>e.id));for(const e of i){if(t.has(e.id))continue;const n=e.adoptedFrom!==void 0?t.get(e.adoptedFrom):void 0;if(e.adoptedFrom!==void 0&&n)t.delete(e.adoptedFrom),t.set(e.id,n);else{const S=l(e.id);t.set(e.id,S),u?.(e.id,S)}}const s=c.useRef(new Set);c.useEffect(()=>{const e=s.current;s.current=o;for(const n of e)!o.has(n)&&t.has(n)&&(t.delete(n),f?.(n))});const a=new Map;for(const e of o){const n=t.get(e);n&&a.set(e,n)}return a}g(b,"useStoreMap");function h(i,r){const d=c.useRef(i);d.current=i;const f=c.useRef(r);f.current=r;const u=[...i.keys()].sort().join(",");c.useLayoutEffect(()=>{const m=[];for(const[t,o]of d.current)t!==f.current&&m.push(p(t,"onSessionUpdate",s=>{const{update:a}=s;v(o,a),E(a)?.turnEnd&&o.getState().setHasUnseenUpdates(!0)}),p(t,"onPermissionRequest",s=>{U(o,s)}),p(t,"onConfigOptionsUpdate",s=>{const a=s;o.getState().setConfigOptions(a);const e=x(a);e&&o.getState().setAvailableAgents(e)}),p(t,"onExperimentsUpdate",s=>{o.getState().setExperiments(s)}));return()=>{for(const t of m)t.dispose()}},[u,r])}g(h,"useBackgroundEventWiring");export{h as a,b as u};
