import{i as m,y as h,E as p}from"./index-Cwmuwk3V.js";const w="openchamber-mobile-layout",E=e=>e==="default"?"default":"new",y=()=>{if(typeof window>"u")return"new";try{return E(window.localStorage.getItem(w))}catch{return"new"}},B=e=>{if(typeof window>"u")return!1;try{return window.localStorage.setItem(w,e),!0}catch{return!1}},g=768,b=()=>{if(typeof window>"u")return!1;const e=typeof window.matchMedia=="function"?window.matchMedia("(pointer: coarse)").matches||window.matchMedia("(hover: none)").matches:!1,t=typeof navigator<"u"?navigator.maxTouchPoints??0:0;return e||t>0},f=()=>{if(typeof window>"u")return"desktop";const e=window.__OPENCHAMBER_SURFACE__;if(e==="mobile"||e==="desktop")return e;const t=new URLSearchParams(window.location.search).get("surface");if(t==="mobile"||t==="desktop")return t;if(m())return"mobile";if(h()||p())return"desktop";const n=Math.min(window.innerWidth||Number.POSITIVE_INFINITY,window.screen?.width||Number.POSITIVE_INFINITY);return Number.isFinite(n)&&n<=g&&b()&&y()==="new"?"mobile":"desktop"},k=()=>{const e=f();return typeof window<"u"&&(window.__OPENCHAMBER_SURFACE__=e),e},A=()=>f()==="mobile",S="openchamber:embedded-runtime-bootstrap-request",P="openchamber:embedded-runtime-bootstrap-response",I="openchamber:embedded-visibility-request",C="openchamber:embedded-visibility",T=5e3,_=100,R=e=>e!==null&&typeof e=="object"&&!Array.isArray(e)&&Object.values(e).every(t=>typeof t=="string"),M=e=>{if(!e||typeof e!="object")return!1;const t=e;if(typeof t.apiBaseUrl!="string"||typeof t.clientToken!="string"||typeof t.localOrigin!="string"||typeof t.relayHostId!="string"||t.runtimeHeaders!==void 0&&!R(t.runtimeHeaders))return!1;const n=t.relay;return n===void 0?!0:n!==null&&typeof n=="object"&&!("grant"in n)&&typeof n.relayUrl=="string"&&typeof n.serverId=="string"&&n.hostEncPubJwk!==null&&typeof n.hostEncPubJwk=="object"&&!Array.isArray(n.hostEncPubJwk)},L=()=>{if(!l()||typeof window>"u"||window.parent===window)return Promise.resolve(null);const e=typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`${Date.now()}-${Math.random()}`;return new Promise(t=>{let n=!1,o=0,s=0;const r=i=>{n||(n=!0,window.clearTimeout(s),window.clearInterval(o),window.removeEventListener("message",u),t(i))},u=i=>{if(i.origin!==window.location.origin||i.source!==window.parent)return;const a=i.data;a?.type!==P||a.requestId!==e||r(M(a.payload)?a.payload:null)};s=window.setTimeout(()=>r(null),T);const c=()=>{window.parent.postMessage({type:S,requestId:e},window.location.origin)};o=window.setInterval(c,_),window.addEventListener("message",u),c()})},N=()=>{!l()||typeof window>"u"||!window.parent||window.parent===window||window.parent.postMessage({type:I},window.location.origin)},O=(e,t,n)=>JSON.stringify({sessionID:e,directory:t||"",readOnly:n===!0}),U=(e,t,n,o,s)=>{if(typeof window>"u")return"";const r=new URL(window.location.pathname,window.location.origin);return r.searchParams.set("ocPanel","session-chat"),r.searchParams.set("surface","desktop"),r.searchParams.set("sessionId",e),n?r.searchParams.set("readOnly","1"):r.searchParams.delete("readOnly"),t&&t.trim().length>0?r.searchParams.set("directory",t):r.searchParams.delete("directory"),r.searchParams.set("themeMode",o.mode),r.searchParams.set("lightThemeId",o.lightThemeId),r.searchParams.set("darkThemeId",o.darkThemeId),r.searchParams.set("themeVariant",o.currentTheme.metadata.variant==="dark"?"dark":"light"),s&&r.searchParams.set("allowPromptingSubagentSessions",s.allowPromptingSubagentSessions?"1":"0"),r.hash="",r.toString()},v=(e,t,n,o,s,r,u)=>{const c=O(n,o,s),i=e.get(t);if(i?.signature===c)return i.src;const a=U(n,o,s,r,u);return e.set(t,{signature:c,src:a}),a},H=(e,t)=>t?e.find(n=>n.id===t)??null:null;let d=null;const l=()=>{if(d!==null)return d;if(typeof window>"u")return d=!1,!1;try{return d=new URLSearchParams(window.location.search).get("ocPanel")==="session-chat",d}catch{return d=!1,!1}},q=()=>{if(!l())return null;try{const e=new URLSearchParams(window.location.search).get("sessionId");return e&&e.trim().length>0?e.trim():null}catch{return null}};export{C as E,L as a,v as b,I as c,S as d,P as e,N as f,H as g,A as h,l as i,q as j,y as k,k as r,B as s};
