@richhardry/codor 0.10.2 → 0.10.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -11
- package/node_modules/@codor/adapter-antigravity/package.json +2 -2
- package/node_modules/@codor/adapter-claude-code/package.json +2 -2
- package/node_modules/@codor/adapter-codex/package.json +2 -2
- package/node_modules/@codor/adapter-copilot/package.json +2 -2
- package/node_modules/@codor/adapter-cursor/package.json +2 -2
- package/node_modules/@codor/adapter-gemini/package.json +2 -2
- package/node_modules/@codor/adapter-opencode/package.json +2 -2
- package/node_modules/@codor/cli/dist/up.d.ts +2 -0
- package/node_modules/@codor/cli/dist/up.d.ts.map +1 -1
- package/node_modules/@codor/cli/dist/up.js +17 -2
- package/node_modules/@codor/cli/dist/up.js.map +1 -1
- package/node_modules/@codor/cli/package.json +3 -3
- package/node_modules/@codor/cli/runtime/web/assets/{LandingPage-BOmG5kSw.js → LandingPage-oLIz_H3H.js} +1 -1
- package/node_modules/@codor/cli/runtime/web/assets/{LedgerPage-CecuTS8-.js → LedgerPage-CDSjXPp5.js} +1 -1
- package/node_modules/@codor/cli/runtime/web/assets/NoChannels-yL8IGs8_.js +11 -0
- package/node_modules/@codor/cli/runtime/web/assets/{PairingCodeInput-Cr6XDWx-.js → PairingCodeInput-Bh2hzFji.js} +1 -1
- package/node_modules/@codor/cli/runtime/web/assets/{PairingPage-CQBWNA2L.js → PairingPage-CC8sVZit.js} +1 -1
- package/node_modules/@codor/cli/runtime/web/assets/{SettingsPage-DGLbSXE7.js → SettingsPage-Cl3O3UCt.js} +1 -1
- package/node_modules/@codor/cli/runtime/web/assets/{StartupUnavailable-DdQBHip_.js → StartupUnavailable-CHDoG9xu.js} +1 -1
- package/node_modules/@codor/cli/runtime/web/assets/{arrow-left-BOpjMuRi.js → arrow-left-CFyShOnS.js} +1 -1
- package/node_modules/@codor/cli/runtime/web/assets/{browser-BWQYNOsD.js → browser-BHgZ9Kl0.js} +1 -1
- package/node_modules/@codor/cli/runtime/web/assets/{index-DjwJakJC.css → index-BAZeDQCd.css} +1 -1
- package/node_modules/@codor/cli/runtime/web/assets/index-DWQr1Nx3.js +408 -0
- package/node_modules/@codor/cli/runtime/web/index.html +2 -2
- package/node_modules/@codor/cli/runtime/web/sw.js +1 -1
- package/node_modules/@codor/protocol/package.json +1 -1
- package/node_modules/@codor/switchboard/dist/adapter-registry.d.ts +45 -1
- package/node_modules/@codor/switchboard/dist/adapter-registry.d.ts.map +1 -1
- package/node_modules/@codor/switchboard/dist/adapter-registry.js +38 -11
- package/node_modules/@codor/switchboard/dist/adapter-registry.js.map +1 -1
- package/node_modules/@codor/switchboard/dist/daemon.d.ts +10 -0
- package/node_modules/@codor/switchboard/dist/daemon.d.ts.map +1 -1
- package/node_modules/@codor/switchboard/dist/daemon.js +55 -14
- package/node_modules/@codor/switchboard/dist/daemon.js.map +1 -1
- package/node_modules/@codor/switchboard/dist/server.d.ts.map +1 -1
- package/node_modules/@codor/switchboard/dist/server.js +11 -0
- package/node_modules/@codor/switchboard/dist/server.js.map +1 -1
- package/node_modules/@codor/switchboard/dist/store.d.ts +9 -0
- package/node_modules/@codor/switchboard/dist/store.d.ts.map +1 -1
- package/node_modules/@codor/switchboard/dist/store.js +16 -0
- package/node_modules/@codor/switchboard/dist/store.js.map +1 -1
- package/node_modules/@codor/switchboard/package.json +9 -9
- package/package.json +11 -11
- package/node_modules/@codor/cli/runtime/web/assets/NoChannels-CYiBXGQd.js +0 -11
- package/node_modules/@codor/cli/runtime/web/assets/index-Cxi54Xim.js +0 -408
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/SettingsPage-Cl3O3UCt.js","assets/browser-BHgZ9Kl0.js","assets/react-C8w-UNLI.js","assets/qr-DpynCwP9.js","assets/arrow-left-CFyShOnS.js","assets/sodium-DtsvMzX9.js","assets/LedgerPage-CDSjXPp5.js","assets/graph-toBZHlC0.js","assets/PairingPage-CC8sVZit.js","assets/PairingCodeInput-Bh2hzFji.js","assets/LandingPage-oLIz_H3H.js","assets/StartupUnavailable-CHDoG9xu.js","assets/NoChannels-yL8IGs8_.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
var kl=Object.defineProperty;var wl=(e,t,n)=>t in e?kl(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var re=(e,t,n)=>wl(e,typeof t!="symbol"?t+"":t,n);import{r as Xo,g as Sl,a as Qo}from"./react-C8w-UNLI.js";import{t as at}from"./sodium-DtsvMzX9.js";(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const s of document.querySelectorAll('link[rel="modulepreload"]'))r(s);new MutationObserver(s=>{for(const i of s)if(i.type==="childList")for(const a of i.addedNodes)a.tagName==="LINK"&&a.rel==="modulepreload"&&r(a)}).observe(document,{childList:!0,subtree:!0});function n(s){const i={};return s.integrity&&(i.integrity=s.integrity),s.referrerPolicy&&(i.referrerPolicy=s.referrerPolicy),s.crossOrigin==="use-credentials"?i.credentials="include":s.crossOrigin==="anonymous"?i.credentials="omit":i.credentials="same-origin",i}function r(s){if(s.ep)return;s.ep=!0;const i=n(s);fetch(s.href,i)}})();const jl="modulepreload",Nl=function(e){return"/"+e},bi={},Ot=function(t,n,r){let s=Promise.resolve();if(n&&n.length>0){let a=function(d){return Promise.all(d.map(u=>Promise.resolve(u).then(h=>({status:"fulfilled",value:h}),h=>({status:"rejected",reason:h}))))};document.getElementsByTagName("link");const c=document.querySelector("meta[property=csp-nonce]"),l=(c==null?void 0:c.nonce)||(c==null?void 0:c.getAttribute("nonce"));s=a(n.map(d=>{if(d=Nl(d),d in bi)return;bi[d]=!0;const u=d.endsWith(".css"),h=u?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${d}"]${h}`))return;const m=document.createElement("link");if(m.rel=u?"stylesheet":jl,u||(m.as="script"),m.crossOrigin="",m.href=d,l&&m.setAttribute("nonce",l),document.head.appendChild(m),u)return new Promise((p,g)=>{m.addEventListener("load",p),m.addEventListener("error",()=>g(new Error(`Unable to preload CSS for ${d}`)))})}))}function i(a){const c=new Event("vite:preloadError",{cancelable:!0});if(c.payload=a,window.dispatchEvent(c),!c.defaultPrevented)throw a}return s.then(a=>{for(const c of a||[])c.status==="rejected"&&i(c.reason);return t().catch(i)})};var qr={exports:{}},vn={};/**
|
|
3
|
+
* @license React
|
|
4
|
+
* react-jsx-runtime.production.min.js
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
7
|
+
*
|
|
8
|
+
* This source code is licensed under the MIT license found in the
|
|
9
|
+
* LICENSE file in the root directory of this source tree.
|
|
10
|
+
*/var _i;function Tl(){if(_i)return vn;_i=1;var e=Xo(),t=Symbol.for("react.element"),n=Symbol.for("react.fragment"),r=Object.prototype.hasOwnProperty,s=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,i={key:!0,ref:!0,__self:!0,__source:!0};function a(c,l,d){var u,h={},m=null,p=null;d!==void 0&&(m=""+d),l.key!==void 0&&(m=""+l.key),l.ref!==void 0&&(p=l.ref);for(u in l)r.call(l,u)&&!i.hasOwnProperty(u)&&(h[u]=l[u]);if(c&&c.defaultProps)for(u in l=c.defaultProps,l)h[u]===void 0&&(h[u]=l[u]);return{$$typeof:t,type:c,key:m,ref:p,props:h,_owner:s.current}}return vn.Fragment=n,vn.jsx=a,vn.jsxs=a,vn}var vi;function El(){return vi||(vi=1,qr.exports=Tl()),qr.exports}var o=El(),x=Xo();const Gn=Sl(x);var Jn={},yi;function $l(){if(yi)return Jn;yi=1;var e=Qo();return Jn.createRoot=e.createRoot,Jn.hydrateRoot=e.hydrateRoot,Jn}var Rl=$l();const ea="codor-theme";function Cl(e){return e==="system"||e==="dark"||e==="light"}function Al(){try{const e=localStorage.getItem(ea);return Cl(e)?e:"light"}catch{return"light"}}function ta(e=Al()){e==="system"?delete document.documentElement.dataset.theme:document.documentElement.dataset.theme=e}function G_(e){try{localStorage.setItem(ea,e)}catch{}ta(e)}const na="codor-crypto-v1",Rn="state",zl=new TextEncoder().encode("codor-auth-v1\0");let ws;const ki=new Map;function Et(e){let t="";for(const n of e)t+=String.fromCharCode(n);return btoa(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function sn(e){const t=e.replace(/-/g,"+").replace(/_/g,"/").padEnd(Math.ceil(e.length/4)*4,"="),n=atob(t);return Uint8Array.from(n,r=>r.charCodeAt(0))}function Il(...e){const t=new Uint8Array(e.reduce((r,s)=>r+s.length,0));let n=0;for(const r of e)t.set(r,n),n+=r.length;return t}function Ll(e){const t=sn(e.server_nonce),n=sn(e.transcript_hash);if(t.length!==32||n.length!==32)throw new Error("device authentication challenge is malformed");return Il(zl,t,n)}function $n(e){return ws=e,e}function Ol(e=""){return ws??e}function ra(){return new Promise((e,t)=>{const n=indexedDB.open(na,1);n.onupgradeneeded=()=>n.result.createObjectStore(Rn),n.onsuccess=()=>e(n.result),n.onerror=()=>t(n.error??new Error("IndexedDB open failed"))})}async function dn(e){const t=await ra();try{return await new Promise((n,r)=>{const s=t.transaction(Rn).objectStore(Rn).get(e);s.onsuccess=()=>n(s.result),s.onerror=()=>r(s.error??new Error("IndexedDB read failed"))})}finally{t.close()}}async function Cn(e,t){const n=await ra();try{await new Promise((r,s)=>{const i=n.transaction(Rn,"readwrite");i.objectStore(Rn).put(t,e),i.oncomplete=()=>r(),i.onerror=()=>s(i.error??new Error("IndexedDB write failed"))})}finally{n.close()}}async function Ss(){await at.ready;let e=await dn("identity");if(!e){const t=at.crypto_sign_keypair(),n=at.crypto_box_keypair(),r=Et(t.publicKey);e={device_id:r,sign_public_key:r,sign_secret_key:Et(t.privateKey),encryption_public_key:Et(n.publicKey),encryption_secret_key:Et(n.privateKey)},await Cn("identity",e)}return Ul(e)}async function sa(e){await at.ready;const t=await aa();return at.crypto_box_seal_open(sn(e),sn(t.encryption_public_key),sn(t.encryption_secret_key))}async function ia(e,t){await Cn("peer:switchboard",{...e.switchboard,kind:"switchboard"});for(const n of e.room_keys)await Cn(`room:${n.room}`,{room:n.room,generation:n.generation,key:Et(await sa(n.sealed_key))});await oa({origin:new URL(t).origin,authority:"device"})}async function J_(e){const t=e.searchParams.get("endpoint"),n=e.searchParams.get("pairing_token"),r=e.searchParams.get("switchboard_sign_pub");if(!t||!n||!r)throw new Error("pairing link is incomplete");const s=await Ss(),i=await fetch(`${t.replace(/\/$/,"")}/api/pairing/complete`,{method:"POST",headers:{authorization:`Pairing ${n}`,"content-type":"application/json"},body:JSON.stringify({...s,kind:"device",label:navigator.userAgent})});if(!i.ok)throw new Error(`pairing failed: ${String(i.status)}`);const a=await i.json();if(a.switchboard.sign_public_key!==r)throw new Error("Codor signing key does not match the pairing link");return await ia(a,t),a}function Y_(e=window.location.origin){const t=new URL(e).origin,n=ki.get(t);if(n)return n;const r=(async()=>{const s=await fetch(`${t}/api/pairing/status`);if(!s.ok)throw new Error(`trusted pairing status failed: ${String(s.status)}`);if((await s.json()).trusted_enrollment!==!0)return!1;const a=await Ss(),c=await fetch(`${t}/api/pairing/complete`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({...a,kind:"device",label:navigator.userAgent})});if(!c.ok)throw new Error(`trusted pairing failed: ${String(c.status)}`);return await ia(await c.json(),t),!0})();return ki.set(t,r),r}async function Pl(e=window.location.origin){await at.ready;const t=await dn("peer:switchboard");if((t==null?void 0:t.kind)!=="switchboard")return;const n=await aa(),r=await fetch(`${e}/api/auth/challenge`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({device_id:n.device_id})});if(!r.ok)throw new Error(`device authentication failed: ${String(r.status)}`);const s=await r.json();if(s.switchboard_device_id!==t.device_id||!s.challenge)throw new Error("device authentication Codor identity mismatch");const i=s.challenge,a=Et(at.crypto_generichash(at.crypto_generichash_BYTES,new TextEncoder().encode(`codor-browser-session-v1\0${t.device_id}`),null));if(typeof i.challenge_id!="string"||i.challenge_id===""||typeof i.server_nonce!="string"||typeof i.transcript_hash!="string"||i.transcript_hash!==a||typeof i.expires_at!="string"||Date.parse(i.expires_at)<=Date.now())throw new Error("device authentication challenge is invalid");const c=Et(at.crypto_sign_detached(Ll(i),sn(n.sign_secret_key))),l=await fetch(`${e}/api/auth/session`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({challenge_id:i.challenge_id,signature:c})});if(!l.ok)throw new Error(`device authentication failed: ${String(l.status)}`);const d=await l.json();if(typeof d.access_token!="string"||d.access_token===""||d.device_id!==n.device_id||typeof d.expires_at!="string"||Date.parse(d.expires_at)<=Date.now())throw new Error("device authentication session is invalid");return d.access_token}async function Ml(e=window.location.origin){const t=await dn("peer:switchboard");if((t==null?void 0:t.kind)==="switchboard")return await Pl(e)??"";const n=await Fl();return(n==null?void 0:n.origin)===e&&n.authority!=="device"&&typeof n.token=="string"?n.token:""}async function Dl(e){return dn(`room:${e}`)}async function Zl(e,t,n){if(await at.ready,e===""||!Number.isSafeInteger(t)||t<1)throw new Error("channel key metadata is invalid");if(n.length!==at.crypto_aead_xchacha20poly1305_ietf_KEYBYTES)throw new Error("channel key length is invalid");const r=await Dl(e);r&&r.generation>t||await Cn(`room:${e}`,{room:e,generation:t,key:Et(n)})}async function oa(e){if(e.origin===""||e.authority==="operator"&&(typeof e.token!="string"||e.token==="")||e.authority==="device"&&e.token!==void 0)throw new Error("browser access metadata is invalid");await Cn("access:switchboard",e)}async function Fl(){return dn("access:switchboard")}async function K_(){ws="";for(const t of await navigator.serviceWorker.getRegistrations()){const n=await t.pushManager.getSubscription();n&&await n.unsubscribe(),await t.unregister()}for(const t of await caches.keys())await caches.delete(t);localStorage.clear();const e=typeof indexedDB.databases=="function"?await indexedDB.databases():[{name:na}];await Promise.all(e.map(t=>t.name).filter(t=>typeof t=="string"&&t.startsWith("codor-")).map(t=>new Promise((n,r)=>{const s=indexedDB.deleteDatabase(t);s.onsuccess=()=>n(),s.onerror=()=>r(s.error??new Error("IndexedDB delete failed")),s.onblocked=()=>r(new Error("IndexedDB delete was blocked"))})))}function Ul(e){return{device_id:e.device_id,sign_public_key:e.sign_public_key,encryption_public_key:e.encryption_public_key}}async function aa(){await Ss();const e=await dn("identity");if(!e)throw new Error("browser identity disappeared");return e}async function X_(e,t=window.location.origin){const n=new URL(t).origin,r=await fetch(`${n}/api/pairing/exchange`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({code:e})});if(!r.ok)throw new Error("pairing code not found");const s=await r.json(),i=new URL("/pair",s.endpoint);return i.searchParams.set("endpoint",s.endpoint),i.searchParams.set("pairing_token",s.pairing_token),i.searchParams.set("switchboard_sign_pub",s.switchboard_sign_pub),i}async function ca(e){try{const t=await e.json();if(typeof t.error=="string"&&t.error.trim()!=="")return new Error(t.error)}catch{}return new Error(`request failed: ${String(e.status)}`)}async function lt(e,t){const n=t.origin??window.location.origin,r=await fetch(`${n}${e}`,{headers:{authorization:`Bearer ${t.token}`}});if(!r.ok)throw await ca(r);return await r.json()}async function Pn(e,t,n,r){const s=r.origin??window.location.origin,i=await fetch(`${s}${e}`,{method:t,headers:{authorization:`Bearer ${r.token}`,...n!==void 0&&{"content-type":"application/json"}},...n!==void 0&&{body:JSON.stringify(n)}});if(!i.ok)throw await ca(i);if(i.status!==204)return await i.json()}async function wi(e){const t=await lt("/api/adapters",e);return{adapters:t.adapters,discovering:t.discovering===!0}}async function ql(e){return Pn("/api/adapters/refresh","POST",void 0,e)}async function la(e){return(await lt("/api/rooms",e)).rooms}async function Bl(e,t){const n=await Pn("/api/rooms","POST",e,t);if(n.room_key!==void 0){if(n.room_key.room!==n.room.id)throw new Error("created channel key does not match the created channel");const r=await sa(n.room_key.sealed_key);await Zl(n.room_key.room,n.room_key.generation,r)}return n.room}async function Hl(e,t,n){const r=new URLSearchParams;e!==void 0&&r.set("path",e),t&&r.set("hidden","1");const s=r.size===0?"":`?${r.toString()}`;return lt(`/api/local/dirs${s}`,n)}async function Q_(e){return(await lt("/api/devices",e)).devices}async function ev(e,t){return Pn("/api/pairing/offers","POST",{endpoint:e},t)}async function tv(e){return lt("/api/push/config",e)}async function nv(e,t,n){await Pn(`/api/devices/${encodeURIComponent(e)}/push-subscription`,"POST",{subscription:t},n)}async function rv(e,t){await Pn(`/api/devices/${encodeURIComponent(e)}`,"DELETE",void 0,t)}async function Wl(e,t){return(await lt(`/api/rooms/${encodeURIComponent(e)}/members`,t)).members}async function ua(e,t,n){const r=new URLSearchParams;return t.before!==void 0&&r.set("before",String(t.before)),t.limit!==void 0&&r.set("limit",String(t.limit)),lt(`/api/rooms/${encodeURIComponent(e)}/messages?${r.toString()}`,n)}async function Vl(e,t,n){const r=new URLSearchParams({q:t});return(await lt(`/api/rooms/${encodeURIComponent(e)}/search?${r.toString()}`,n)).messages}async function da(e,t,n){return(await lt(`/api/rooms/${encodeURIComponent(e)}/runs/${t}`,n)).events}async function sv(e,t,n){return(await lt(`/api/rooms/${encodeURIComponent(e)}/ledger/${encodeURIComponent(t)}`,n)).note}async function iv(e,t){return(await lt(`/api/rooms/${encodeURIComponent(e)}/ledger`,t)).graph}var Si;function v(e,t,n){function r(c,l){if(c._zod||Object.defineProperty(c,"_zod",{value:{def:l,constr:a,traits:new Set},enumerable:!1}),c._zod.traits.has(e))return;c._zod.traits.add(e),t(c,l);const d=a.prototype,u=Object.keys(d);for(let h=0;h<u.length;h++){const m=u[h];m in c||(c[m]=d[m].bind(c))}}const s=(n==null?void 0:n.Parent)??Object;class i extends s{}Object.defineProperty(i,"name",{value:e});function a(c){var l;const d=n!=null&&n.Parent?new i:this;r(d,c),(l=d._zod).deferred??(l.deferred=[]);for(const u of d._zod.deferred)u();return d}return Object.defineProperty(a,"init",{value:r}),Object.defineProperty(a,Symbol.hasInstance,{value:c=>{var l,d;return n!=null&&n.Parent&&c instanceof n.Parent?!0:(d=(l=c==null?void 0:c._zod)==null?void 0:l.traits)==null?void 0:d.has(e)}}),Object.defineProperty(a,"name",{value:e}),a}class on extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class ha extends Error{constructor(t){super(`Encountered unidirectional transform during encode: ${t}`),this.name="ZodEncodeError"}}(Si=globalThis).__zod_globalConfig??(Si.__zod_globalConfig={});const js=globalThis.__zod_globalConfig;function Dt(e){return js}function fa(e){const t=Object.values(e).filter(r=>typeof r=="number");return Object.entries(e).filter(([r,s])=>t.indexOf(+r)===-1).map(([r,s])=>s)}function es(e,t){return typeof t=="bigint"?t.toString():t}function _r(e){return{get value(){{const t=e();return Object.defineProperty(this,"value",{value:t}),t}}}}function Ns(e){return e==null}function Ts(e){const t=e.startsWith("^")?1:0,n=e.endsWith("$")?e.length-1:e.length;return e.slice(t,n)}function Gl(e,t){const n=e/t,r=Math.round(n),s=Number.EPSILON*Math.max(Math.abs(n),1);return Math.abs(n-r)<s?0:n-r}const ji=Symbol("evaluating");function ne(e,t,n){let r;Object.defineProperty(e,t,{get(){if(r!==ji)return r===void 0&&(r=ji,r=n()),r},set(s){Object.defineProperty(e,t,{value:s})},configurable:!0})}function Bt(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function Rt(...e){const t={};for(const n of e){const r=Object.getOwnPropertyDescriptors(n);Object.assign(t,r)}return Object.defineProperties({},t)}function Ni(e){return JSON.stringify(e)}function Jl(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")}const ma="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function An(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}const Yl=_r(()=>{var e;if(js.jitless||typeof navigator<"u"&&((e=navigator==null?void 0:navigator.userAgent)!=null&&e.includes("Cloudflare")))return!1;try{const t=Function;return new t(""),!0}catch{return!1}});function zn(e){if(An(e)===!1)return!1;const t=e.constructor;if(t===void 0||typeof t!="function")return!0;const n=t.prototype;return!(An(n)===!1||Object.prototype.hasOwnProperty.call(n,"isPrototypeOf")===!1)}function pa(e){return zn(e)?{...e}:Array.isArray(e)?[...e]:e instanceof Map?new Map(e):e instanceof Set?new Set(e):e}const Kl=new Set(["string","number","symbol"]);function an(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Ct(e,t,n){const r=new e._zod.constr(t??e._zod.def);return(!t||n!=null&&n.parent)&&(r._zod.parent=e),r}function D(e){const t=e;if(!t)return{};if(typeof t=="string")return{error:()=>t};if((t==null?void 0:t.message)!==void 0){if((t==null?void 0:t.error)!==void 0)throw new Error("Cannot specify both `message` and `error` params");t.error=t.message}return delete t.message,typeof t.error=="string"?{...t,error:()=>t.error}:t}function Xl(e){return Object.keys(e).filter(t=>e[t]._zod.optin==="optional"&&e[t]._zod.optout==="optional")}const Ql={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function eu(e,t){const n=e._zod.def,r=n.checks;if(r&&r.length>0)throw new Error(".pick() cannot be used on object schemas containing refinements");const i=Rt(e._zod.def,{get shape(){const a={};for(const c in t){if(!(c in n.shape))throw new Error(`Unrecognized key: "${c}"`);t[c]&&(a[c]=n.shape[c])}return Bt(this,"shape",a),a},checks:[]});return Ct(e,i)}function tu(e,t){const n=e._zod.def,r=n.checks;if(r&&r.length>0)throw new Error(".omit() cannot be used on object schemas containing refinements");const i=Rt(e._zod.def,{get shape(){const a={...e._zod.def.shape};for(const c in t){if(!(c in n.shape))throw new Error(`Unrecognized key: "${c}"`);t[c]&&delete a[c]}return Bt(this,"shape",a),a},checks:[]});return Ct(e,i)}function nu(e,t){if(!zn(t))throw new Error("Invalid input to extend: expected a plain object");const n=e._zod.def.checks;if(n&&n.length>0){const i=e._zod.def.shape;for(const a in t)if(Object.getOwnPropertyDescriptor(i,a)!==void 0)throw new Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}const s=Rt(e._zod.def,{get shape(){const i={...e._zod.def.shape,...t};return Bt(this,"shape",i),i}});return Ct(e,s)}function ru(e,t){if(!zn(t))throw new Error("Invalid input to safeExtend: expected a plain object");const n=Rt(e._zod.def,{get shape(){const r={...e._zod.def.shape,...t};return Bt(this,"shape",r),r}});return Ct(e,n)}function su(e,t){var r;if((r=e._zod.def.checks)!=null&&r.length)throw new Error(".merge() cannot be used on object schemas containing refinements. Use .safeExtend() instead.");const n=Rt(e._zod.def,{get shape(){const s={...e._zod.def.shape,...t._zod.def.shape};return Bt(this,"shape",s),s},get catchall(){return t._zod.def.catchall},checks:t._zod.def.checks??[]});return Ct(e,n)}function iu(e,t,n){const s=t._zod.def.checks;if(s&&s.length>0)throw new Error(".partial() cannot be used on object schemas containing refinements");const a=Rt(t._zod.def,{get shape(){const c=t._zod.def.shape,l={...c};if(n)for(const d in n){if(!(d in c))throw new Error(`Unrecognized key: "${d}"`);n[d]&&(l[d]=e?new e({type:"optional",innerType:c[d]}):c[d])}else for(const d in c)l[d]=e?new e({type:"optional",innerType:c[d]}):c[d];return Bt(this,"shape",l),l},checks:[]});return Ct(t,a)}function ou(e,t,n){const r=Rt(t._zod.def,{get shape(){const s=t._zod.def.shape,i={...s};if(n)for(const a in n){if(!(a in i))throw new Error(`Unrecognized key: "${a}"`);n[a]&&(i[a]=new e({type:"nonoptional",innerType:s[a]}))}else for(const a in s)i[a]=new e({type:"nonoptional",innerType:s[a]});return Bt(this,"shape",i),i}});return Ct(t,r)}function rn(e,t=0){var n;if(e.aborted===!0)return!0;for(let r=t;r<e.issues.length;r++)if(((n=e.issues[r])==null?void 0:n.continue)!==!0)return!0;return!1}function au(e,t=0){var n;if(e.aborted===!0)return!0;for(let r=t;r<e.issues.length;r++)if(((n=e.issues[r])==null?void 0:n.continue)===!1)return!0;return!1}function ga(e,t){return t.map(n=>{var r;return(r=n).path??(r.path=[]),n.path.unshift(e),n})}function Yn(e){return typeof e=="string"?e:e==null?void 0:e.message}function Zt(e,t,n){var l,d,u,h,m,p;const r=e.message?e.message:Yn((u=(d=(l=e.inst)==null?void 0:l._zod.def)==null?void 0:d.error)==null?void 0:u.call(d,e))??Yn((h=t==null?void 0:t.error)==null?void 0:h.call(t,e))??Yn((m=n.customError)==null?void 0:m.call(n,e))??Yn((p=n.localeError)==null?void 0:p.call(n,e))??"Invalid input",{inst:s,continue:i,input:a,...c}=e;return c.path??(c.path=[]),c.message=r,t!=null&&t.reportInput&&(c.input=a),c}function Es(e){return Array.isArray(e)?"array":typeof e=="string"?"string":"unknown"}function In(...e){const[t,n,r]=e;return typeof t=="string"?{message:t,code:"custom",input:n,inst:r}:{...t}}const xa=(e,t)=>{e.name="$ZodError",Object.defineProperty(e,"_zod",{value:e._zod,enumerable:!1}),Object.defineProperty(e,"issues",{value:t,enumerable:!1}),e.message=JSON.stringify(t,es,2),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},ba=v("$ZodError",xa),_a=v("$ZodError",xa,{Parent:Error});function cu(e,t=n=>n.message){const n={},r=[];for(const s of e.issues)s.path.length>0?(n[s.path[0]]=n[s.path[0]]||[],n[s.path[0]].push(t(s))):r.push(t(s));return{formErrors:r,fieldErrors:n}}function lu(e,t=n=>n.message){const n={_errors:[]},r=(s,i=[])=>{for(const a of s.issues)if(a.code==="invalid_union"&&a.errors.length)a.errors.map(c=>r({issues:c},[...i,...a.path]));else if(a.code==="invalid_key")r({issues:a.issues},[...i,...a.path]);else if(a.code==="invalid_element")r({issues:a.issues},[...i,...a.path]);else{const c=[...i,...a.path];if(c.length===0)n._errors.push(t(a));else{let l=n,d=0;for(;d<c.length;){const u=c[d];d===c.length-1?(l[u]=l[u]||{_errors:[]},l[u]._errors.push(t(a))):l[u]=l[u]||{_errors:[]},l=l[u],d++}}}};return r(e),n}const $s=e=>(t,n,r,s)=>{const i=r?{...r,async:!1}:{async:!1},a=t._zod.run({value:n,issues:[]},i);if(a instanceof Promise)throw new on;if(a.issues.length){const c=new((s==null?void 0:s.Err)??e)(a.issues.map(l=>Zt(l,i,Dt())));throw ma(c,s==null?void 0:s.callee),c}return a.value},Rs=e=>async(t,n,r,s)=>{const i=r?{...r,async:!0}:{async:!0};let a=t._zod.run({value:n,issues:[]},i);if(a instanceof Promise&&(a=await a),a.issues.length){const c=new((s==null?void 0:s.Err)??e)(a.issues.map(l=>Zt(l,i,Dt())));throw ma(c,s==null?void 0:s.callee),c}return a.value},vr=e=>(t,n,r)=>{const s=r?{...r,async:!1}:{async:!1},i=t._zod.run({value:n,issues:[]},s);if(i instanceof Promise)throw new on;return i.issues.length?{success:!1,error:new(e??ba)(i.issues.map(a=>Zt(a,s,Dt())))}:{success:!0,data:i.value}},uu=vr(_a),yr=e=>async(t,n,r)=>{const s=r?{...r,async:!0}:{async:!0};let i=t._zod.run({value:n,issues:[]},s);return i instanceof Promise&&(i=await i),i.issues.length?{success:!1,error:new e(i.issues.map(a=>Zt(a,s,Dt())))}:{success:!0,data:i.value}},du=yr(_a),hu=e=>(t,n,r)=>{const s=r?{...r,direction:"backward"}:{direction:"backward"};return $s(e)(t,n,s)},fu=e=>(t,n,r)=>$s(e)(t,n,r),mu=e=>async(t,n,r)=>{const s=r?{...r,direction:"backward"}:{direction:"backward"};return Rs(e)(t,n,s)},pu=e=>async(t,n,r)=>Rs(e)(t,n,r),gu=e=>(t,n,r)=>{const s=r?{...r,direction:"backward"}:{direction:"backward"};return vr(e)(t,n,s)},xu=e=>(t,n,r)=>vr(e)(t,n,r),bu=e=>async(t,n,r)=>{const s=r?{...r,direction:"backward"}:{direction:"backward"};return yr(e)(t,n,s)},_u=e=>async(t,n,r)=>yr(e)(t,n,r),vu=/^[cC][0-9a-z]{6,}$/,yu=/^[0-9a-z]+$/,ku=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,wu=/^[0-9a-vA-V]{20}$/,Su=/^[A-Za-z0-9]{27}$/,ju=/^[a-zA-Z0-9_-]{21}$/,Nu=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,Tu=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,Ti=e=>e?new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${e}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/,Eu=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,$u="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";function Ru(){return new RegExp($u,"u")}const Cu=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,Au=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/,zu=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,Iu=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,Lu=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,va=/^[A-Za-z0-9_-]*$/,Ou=/^https?$/,Pu=/^\+[1-9]\d{6,14}$/,ya="(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))",Mu=new RegExp(`^${ya}$`);function ka(e){const t="(?:[01]\\d|2[0-3]):[0-5]\\d";return typeof e.precision=="number"?e.precision===-1?`${t}`:e.precision===0?`${t}:[0-5]\\d`:`${t}:[0-5]\\d\\.\\d{${e.precision}}`:`${t}(?::[0-5]\\d(?:\\.\\d+)?)?`}function Du(e){return new RegExp(`^${ka(e)}$`)}function Zu(e){const t=ka({precision:e.precision}),n=["Z"];e.local&&n.push(""),e.offset&&n.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)");const r=`${t}(?:${n.join("|")})`;return new RegExp(`^${ya}T(?:${r})$`)}const Fu=e=>{const t=e?`[\\s\\S]{${(e==null?void 0:e.minimum)??0},${(e==null?void 0:e.maximum)??""}}`:"[\\s\\S]*";return new RegExp(`^${t}$`)},Uu=/^-?\d+$/,qu=/^-?\d+(?:\.\d+)?$/,Bu=/^(?:true|false)$/i,Hu=/^[^A-Z]*$/,Wu=/^[^a-z]*$/,Be=v("$ZodCheck",(e,t)=>{var n;e._zod??(e._zod={}),e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),wa={number:"number",bigint:"bigint",object:"date"},Sa=v("$ZodCheckLessThan",(e,t)=>{Be.init(e,t);const n=wa[typeof t.value];e._zod.onattach.push(r=>{const s=r._zod.bag,i=(t.inclusive?s.maximum:s.exclusiveMaximum)??Number.POSITIVE_INFINITY;t.value<i&&(t.inclusive?s.maximum=t.value:s.exclusiveMaximum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value<=t.value:r.value<t.value)||r.issues.push({origin:n,code:"too_big",maximum:typeof t.value=="object"?t.value.getTime():t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),ja=v("$ZodCheckGreaterThan",(e,t)=>{Be.init(e,t);const n=wa[typeof t.value];e._zod.onattach.push(r=>{const s=r._zod.bag,i=(t.inclusive?s.minimum:s.exclusiveMinimum)??Number.NEGATIVE_INFINITY;t.value>i&&(t.inclusive?s.minimum=t.value:s.exclusiveMinimum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value>=t.value:r.value>t.value)||r.issues.push({origin:n,code:"too_small",minimum:typeof t.value=="object"?t.value.getTime():t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),Vu=v("$ZodCheckMultipleOf",(e,t)=>{Be.init(e,t),e._zod.onattach.push(n=>{var r;(r=n._zod.bag).multipleOf??(r.multipleOf=t.value)}),e._zod.check=n=>{if(typeof n.value!=typeof t.value)throw new Error("Cannot mix number and bigint in multiple_of check.");(typeof n.value=="bigint"?n.value%t.value===BigInt(0):Gl(n.value,t.value)===0)||n.issues.push({origin:typeof n.value,code:"not_multiple_of",divisor:t.value,input:n.value,inst:e,continue:!t.abort})}}),Gu=v("$ZodCheckNumberFormat",(e,t)=>{var a;Be.init(e,t),t.format=t.format||"float64";const n=(a=t.format)==null?void 0:a.includes("int"),r=n?"int":"number",[s,i]=Ql[t.format];e._zod.onattach.push(c=>{const l=c._zod.bag;l.format=t.format,l.minimum=s,l.maximum=i,n&&(l.pattern=Uu)}),e._zod.check=c=>{const l=c.value;if(n){if(!Number.isInteger(l)){c.issues.push({expected:r,format:t.format,code:"invalid_type",continue:!1,input:l,inst:e});return}if(!Number.isSafeInteger(l)){l>0?c.issues.push({input:l,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:r,inclusive:!0,continue:!t.abort}):c.issues.push({input:l,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:r,inclusive:!0,continue:!t.abort});return}}l<s&&c.issues.push({origin:"number",input:l,code:"too_small",minimum:s,inclusive:!0,inst:e,continue:!t.abort}),l>i&&c.issues.push({origin:"number",input:l,code:"too_big",maximum:i,inclusive:!0,inst:e,continue:!t.abort})}}),Ju=v("$ZodCheckMaxLength",(e,t)=>{var n;Be.init(e,t),(n=e._zod.def).when??(n.when=r=>{const s=r.value;return!Ns(s)&&s.length!==void 0}),e._zod.onattach.push(r=>{const s=r._zod.bag.maximum??Number.POSITIVE_INFINITY;t.maximum<s&&(r._zod.bag.maximum=t.maximum)}),e._zod.check=r=>{const s=r.value;if(s.length<=t.maximum)return;const a=Es(s);r.issues.push({origin:a,code:"too_big",maximum:t.maximum,inclusive:!0,input:s,inst:e,continue:!t.abort})}}),Yu=v("$ZodCheckMinLength",(e,t)=>{var n;Be.init(e,t),(n=e._zod.def).when??(n.when=r=>{const s=r.value;return!Ns(s)&&s.length!==void 0}),e._zod.onattach.push(r=>{const s=r._zod.bag.minimum??Number.NEGATIVE_INFINITY;t.minimum>s&&(r._zod.bag.minimum=t.minimum)}),e._zod.check=r=>{const s=r.value;if(s.length>=t.minimum)return;const a=Es(s);r.issues.push({origin:a,code:"too_small",minimum:t.minimum,inclusive:!0,input:s,inst:e,continue:!t.abort})}}),Ku=v("$ZodCheckLengthEquals",(e,t)=>{var n;Be.init(e,t),(n=e._zod.def).when??(n.when=r=>{const s=r.value;return!Ns(s)&&s.length!==void 0}),e._zod.onattach.push(r=>{const s=r._zod.bag;s.minimum=t.length,s.maximum=t.length,s.length=t.length}),e._zod.check=r=>{const s=r.value,i=s.length;if(i===t.length)return;const a=Es(s),c=i>t.length;r.issues.push({origin:a,...c?{code:"too_big",maximum:t.length}:{code:"too_small",minimum:t.length},inclusive:!0,exact:!0,input:r.value,inst:e,continue:!t.abort})}}),kr=v("$ZodCheckStringFormat",(e,t)=>{var n,r;Be.init(e,t),e._zod.onattach.push(s=>{const i=s._zod.bag;i.format=t.format,t.pattern&&(i.patterns??(i.patterns=new Set),i.patterns.add(t.pattern))}),t.pattern?(n=e._zod).check??(n.check=s=>{t.pattern.lastIndex=0,!t.pattern.test(s.value)&&s.issues.push({origin:"string",code:"invalid_format",format:t.format,input:s.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(r=e._zod).check??(r.check=()=>{})}),Xu=v("$ZodCheckRegex",(e,t)=>{kr.init(e,t),e._zod.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:"string",code:"invalid_format",format:"regex",input:n.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}}),Qu=v("$ZodCheckLowerCase",(e,t)=>{t.pattern??(t.pattern=Hu),kr.init(e,t)}),ed=v("$ZodCheckUpperCase",(e,t)=>{t.pattern??(t.pattern=Wu),kr.init(e,t)}),td=v("$ZodCheckIncludes",(e,t)=>{Be.init(e,t);const n=an(t.includes),r=new RegExp(typeof t.position=="number"?`^.{${t.position}}${n}`:n);t.pattern=r,e._zod.onattach.push(s=>{const i=s._zod.bag;i.patterns??(i.patterns=new Set),i.patterns.add(r)}),e._zod.check=s=>{s.value.includes(t.includes,t.position)||s.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:t.includes,input:s.value,inst:e,continue:!t.abort})}}),nd=v("$ZodCheckStartsWith",(e,t)=>{Be.init(e,t);const n=new RegExp(`^${an(t.prefix)}.*`);t.pattern??(t.pattern=n),e._zod.onattach.push(r=>{const s=r._zod.bag;s.patterns??(s.patterns=new Set),s.patterns.add(n)}),e._zod.check=r=>{r.value.startsWith(t.prefix)||r.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:t.prefix,input:r.value,inst:e,continue:!t.abort})}}),rd=v("$ZodCheckEndsWith",(e,t)=>{Be.init(e,t);const n=new RegExp(`.*${an(t.suffix)}$`);t.pattern??(t.pattern=n),e._zod.onattach.push(r=>{const s=r._zod.bag;s.patterns??(s.patterns=new Set),s.patterns.add(n)}),e._zod.check=r=>{r.value.endsWith(t.suffix)||r.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:t.suffix,input:r.value,inst:e,continue:!t.abort})}}),sd=v("$ZodCheckOverwrite",(e,t)=>{Be.init(e,t),e._zod.check=n=>{n.value=t.tx(n.value)}});class id{constructor(t=[]){this.content=[],this.indent=0,this&&(this.args=t)}indented(t){this.indent+=1,t(this),this.indent-=1}write(t){if(typeof t=="function"){t(this,{execution:"sync"}),t(this,{execution:"async"});return}const r=t.split(`
|
|
11
|
+
`).filter(a=>a),s=Math.min(...r.map(a=>a.length-a.trimStart().length)),i=r.map(a=>a.slice(s)).map(a=>" ".repeat(this.indent*2)+a);for(const a of i)this.content.push(a)}compile(){const t=Function,n=this==null?void 0:this.args,s=[...((this==null?void 0:this.content)??[""]).map(i=>` ${i}`)];return new t(...n,s.join(`
|
|
12
|
+
`))}}const od={major:4,minor:4,patch:3},be=v("$ZodType",(e,t)=>{var s;var n;e??(e={}),e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=od;const r=[...e._zod.def.checks??[]];e._zod.traits.has("$ZodCheck")&&r.unshift(e);for(const i of r)for(const a of i._zod.onattach)a(e);if(r.length===0)(n=e._zod).deferred??(n.deferred=[]),(s=e._zod.deferred)==null||s.push(()=>{e._zod.run=e._zod.parse});else{const i=(c,l,d)=>{let u=rn(c),h;for(const m of l){if(m._zod.def.when){if(au(c)||!m._zod.def.when(c))continue}else if(u)continue;const p=c.issues.length,g=m._zod.check(c);if(g instanceof Promise&&(d==null?void 0:d.async)===!1)throw new on;if(h||g instanceof Promise)h=(h??Promise.resolve()).then(async()=>{await g,c.issues.length!==p&&(u||(u=rn(c,p)))});else{if(c.issues.length===p)continue;u||(u=rn(c,p))}}return h?h.then(()=>c):c},a=(c,l,d)=>{if(rn(c))return c.aborted=!0,c;const u=i(l,r,d);if(u instanceof Promise){if(d.async===!1)throw new on;return u.then(h=>e._zod.parse(h,d))}return e._zod.parse(u,d)};e._zod.run=(c,l)=>{if(l.skipChecks)return e._zod.parse(c,l);if(l.direction==="backward"){const u=e._zod.parse({value:c.value,issues:[]},{...l,skipChecks:!0});return u instanceof Promise?u.then(h=>a(h,c,l)):a(u,c,l)}const d=e._zod.parse(c,l);if(d instanceof Promise){if(l.async===!1)throw new on;return d.then(u=>i(u,r,l))}return i(d,r,l)}}ne(e,"~standard",()=>({validate:i=>{var a;try{const c=uu(e,i);return c.success?{value:c.data}:{issues:(a=c.error)==null?void 0:a.issues}}catch{return du(e,i).then(l=>{var d;return l.success?{value:l.data}:{issues:(d=l.error)==null?void 0:d.issues}})}},vendor:"zod",version:1}))}),Cs=v("$ZodString",(e,t)=>{var n;be.init(e,t),e._zod.pattern=[...((n=e==null?void 0:e._zod.bag)==null?void 0:n.patterns)??[]].pop()??Fu(e._zod.bag),e._zod.parse=(r,s)=>{if(t.coerce)try{r.value=String(r.value)}catch{}return typeof r.value=="string"||r.issues.push({expected:"string",code:"invalid_type",input:r.value,inst:e}),r}}),he=v("$ZodStringFormat",(e,t)=>{kr.init(e,t),Cs.init(e,t)}),ad=v("$ZodGUID",(e,t)=>{t.pattern??(t.pattern=Tu),he.init(e,t)}),cd=v("$ZodUUID",(e,t)=>{if(t.version){const r={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[t.version];if(r===void 0)throw new Error(`Invalid UUID version: "${t.version}"`);t.pattern??(t.pattern=Ti(r))}else t.pattern??(t.pattern=Ti());he.init(e,t)}),ld=v("$ZodEmail",(e,t)=>{t.pattern??(t.pattern=Eu),he.init(e,t)}),ud=v("$ZodURL",(e,t)=>{he.init(e,t),e._zod.check=n=>{var r;try{const s=n.value.trim();if(!t.normalize&&((r=t.protocol)==null?void 0:r.source)===Ou.source&&!/^https?:\/\//i.test(s)){n.issues.push({code:"invalid_format",format:"url",note:"Invalid URL format",input:n.value,inst:e,continue:!t.abort});return}const i=new URL(s);t.hostname&&(t.hostname.lastIndex=0,t.hostname.test(i.hostname)||n.issues.push({code:"invalid_format",format:"url",note:"Invalid hostname",pattern:t.hostname.source,input:n.value,inst:e,continue:!t.abort})),t.protocol&&(t.protocol.lastIndex=0,t.protocol.test(i.protocol.endsWith(":")?i.protocol.slice(0,-1):i.protocol)||n.issues.push({code:"invalid_format",format:"url",note:"Invalid protocol",pattern:t.protocol.source,input:n.value,inst:e,continue:!t.abort})),t.normalize?n.value=i.href:n.value=s;return}catch{n.issues.push({code:"invalid_format",format:"url",input:n.value,inst:e,continue:!t.abort})}}}),dd=v("$ZodEmoji",(e,t)=>{t.pattern??(t.pattern=Ru()),he.init(e,t)}),hd=v("$ZodNanoID",(e,t)=>{t.pattern??(t.pattern=ju),he.init(e,t)}),fd=v("$ZodCUID",(e,t)=>{t.pattern??(t.pattern=vu),he.init(e,t)}),md=v("$ZodCUID2",(e,t)=>{t.pattern??(t.pattern=yu),he.init(e,t)}),pd=v("$ZodULID",(e,t)=>{t.pattern??(t.pattern=ku),he.init(e,t)}),gd=v("$ZodXID",(e,t)=>{t.pattern??(t.pattern=wu),he.init(e,t)}),xd=v("$ZodKSUID",(e,t)=>{t.pattern??(t.pattern=Su),he.init(e,t)}),bd=v("$ZodISODateTime",(e,t)=>{t.pattern??(t.pattern=Zu(t)),he.init(e,t)}),_d=v("$ZodISODate",(e,t)=>{t.pattern??(t.pattern=Mu),he.init(e,t)}),vd=v("$ZodISOTime",(e,t)=>{t.pattern??(t.pattern=Du(t)),he.init(e,t)}),yd=v("$ZodISODuration",(e,t)=>{t.pattern??(t.pattern=Nu),he.init(e,t)}),kd=v("$ZodIPv4",(e,t)=>{t.pattern??(t.pattern=Cu),he.init(e,t),e._zod.bag.format="ipv4"}),wd=v("$ZodIPv6",(e,t)=>{t.pattern??(t.pattern=Au),he.init(e,t),e._zod.bag.format="ipv6",e._zod.check=n=>{try{new URL(`http://[${n.value}]`)}catch{n.issues.push({code:"invalid_format",format:"ipv6",input:n.value,inst:e,continue:!t.abort})}}}),Sd=v("$ZodCIDRv4",(e,t)=>{t.pattern??(t.pattern=zu),he.init(e,t)}),jd=v("$ZodCIDRv6",(e,t)=>{t.pattern??(t.pattern=Iu),he.init(e,t),e._zod.check=n=>{const r=n.value.split("/");try{if(r.length!==2)throw new Error;const[s,i]=r;if(!i)throw new Error;const a=Number(i);if(`${a}`!==i)throw new Error;if(a<0||a>128)throw new Error;new URL(`http://[${s}]`)}catch{n.issues.push({code:"invalid_format",format:"cidrv6",input:n.value,inst:e,continue:!t.abort})}}});function Na(e){if(e==="")return!0;if(/\s/.test(e)||e.length%4!==0)return!1;try{return atob(e),!0}catch{return!1}}const Nd=v("$ZodBase64",(e,t)=>{t.pattern??(t.pattern=Lu),he.init(e,t),e._zod.bag.contentEncoding="base64",e._zod.check=n=>{Na(n.value)||n.issues.push({code:"invalid_format",format:"base64",input:n.value,inst:e,continue:!t.abort})}});function Td(e){if(!va.test(e))return!1;const t=e.replace(/[-_]/g,r=>r==="-"?"+":"/"),n=t.padEnd(Math.ceil(t.length/4)*4,"=");return Na(n)}const Ed=v("$ZodBase64URL",(e,t)=>{t.pattern??(t.pattern=va),he.init(e,t),e._zod.bag.contentEncoding="base64url",e._zod.check=n=>{Td(n.value)||n.issues.push({code:"invalid_format",format:"base64url",input:n.value,inst:e,continue:!t.abort})}}),$d=v("$ZodE164",(e,t)=>{t.pattern??(t.pattern=Pu),he.init(e,t)});function Rd(e,t=null){try{const n=e.split(".");if(n.length!==3)return!1;const[r]=n;if(!r)return!1;const s=JSON.parse(atob(r));return!("typ"in s&&(s==null?void 0:s.typ)!=="JWT"||!s.alg||t&&(!("alg"in s)||s.alg!==t))}catch{return!1}}const Cd=v("$ZodJWT",(e,t)=>{he.init(e,t),e._zod.check=n=>{Rd(n.value,t.alg)||n.issues.push({code:"invalid_format",format:"jwt",input:n.value,inst:e,continue:!t.abort})}}),Ta=v("$ZodNumber",(e,t)=>{be.init(e,t),e._zod.pattern=e._zod.bag.pattern??qu,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=Number(n.value)}catch{}const s=n.value;if(typeof s=="number"&&!Number.isNaN(s)&&Number.isFinite(s))return n;const i=typeof s=="number"?Number.isNaN(s)?"NaN":Number.isFinite(s)?void 0:"Infinity":void 0;return n.issues.push({expected:"number",code:"invalid_type",input:s,inst:e,...i?{received:i}:{}}),n}}),Ad=v("$ZodNumberFormat",(e,t)=>{Gu.init(e,t),Ta.init(e,t)}),zd=v("$ZodBoolean",(e,t)=>{be.init(e,t),e._zod.pattern=Bu,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=!!n.value}catch{}const s=n.value;return typeof s=="boolean"||n.issues.push({expected:"boolean",code:"invalid_type",input:s,inst:e}),n}}),Id=v("$ZodUnknown",(e,t)=>{be.init(e,t),e._zod.parse=n=>n}),Ld=v("$ZodNever",(e,t)=>{be.init(e,t),e._zod.parse=(n,r)=>(n.issues.push({expected:"never",code:"invalid_type",input:n.value,inst:e}),n)});function Ei(e,t,n){e.issues.length&&t.issues.push(...ga(n,e.issues)),t.value[n]=e.value}const Od=v("$ZodArray",(e,t)=>{be.init(e,t),e._zod.parse=(n,r)=>{const s=n.value;if(!Array.isArray(s))return n.issues.push({expected:"array",code:"invalid_type",input:s,inst:e}),n;n.value=Array(s.length);const i=[];for(let a=0;a<s.length;a++){const c=s[a],l=t.element._zod.run({value:c,issues:[]},r);l instanceof Promise?i.push(l.then(d=>Ei(d,n,a))):Ei(l,n,a)}return i.length?Promise.all(i).then(()=>n):n}});function cr(e,t,n,r,s,i){const a=n in r;if(e.issues.length){if(s&&i&&!a)return;t.issues.push(...ga(n,e.issues))}if(!a&&!s){e.issues.length||t.issues.push({code:"invalid_type",expected:"nonoptional",input:void 0,path:[n]});return}e.value===void 0?a&&(t.value[n]=void 0):t.value[n]=e.value}function Ea(e){var r,s,i,a;const t=Object.keys(e.shape);for(const c of t)if(!((a=(i=(s=(r=e.shape)==null?void 0:r[c])==null?void 0:s._zod)==null?void 0:i.traits)!=null&&a.has("$ZodType")))throw new Error(`Invalid element at key "${c}": expected a Zod schema`);const n=Xl(e.shape);return{...e,keys:t,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(n)}}function $a(e,t,n,r,s,i){const a=[],c=s.keySet,l=s.catchall._zod,d=l.def.type,u=l.optin==="optional",h=l.optout==="optional";for(const m in t){if(m==="__proto__"||c.has(m))continue;if(d==="never"){a.push(m);continue}const p=l.run({value:t[m],issues:[]},r);p instanceof Promise?e.push(p.then(g=>cr(g,n,m,t,u,h))):cr(p,n,m,t,u,h)}return a.length&&n.issues.push({code:"unrecognized_keys",keys:a,input:t,inst:i}),e.length?Promise.all(e).then(()=>n):n}const Pd=v("$ZodObject",(e,t)=>{be.init(e,t);const n=Object.getOwnPropertyDescriptor(t,"shape");if(!(n!=null&&n.get)){const c=t.shape;Object.defineProperty(t,"shape",{get:()=>{const l={...c};return Object.defineProperty(t,"shape",{value:l}),l}})}const r=_r(()=>Ea(t));ne(e._zod,"propValues",()=>{const c=t.shape,l={};for(const d in c){const u=c[d]._zod;if(u.values){l[d]??(l[d]=new Set);for(const h of u.values)l[d].add(h)}}return l});const s=An,i=t.catchall;let a;e._zod.parse=(c,l)=>{a??(a=r.value);const d=c.value;if(!s(d))return c.issues.push({expected:"object",code:"invalid_type",input:d,inst:e}),c;c.value={};const u=[],h=a.shape;for(const m of a.keys){const p=h[m],g=p._zod.optin==="optional",_=p._zod.optout==="optional",S=p._zod.run({value:d[m],issues:[]},l);S instanceof Promise?u.push(S.then(C=>cr(C,c,m,d,g,_))):cr(S,c,m,d,g,_)}return i?$a(u,d,c,l,r.value,e):u.length?Promise.all(u).then(()=>c):c}}),Md=v("$ZodObjectJIT",(e,t)=>{Pd.init(e,t);const n=e._zod.parse,r=_r(()=>Ea(t)),s=m=>{var $,I;const p=new id(["shape","payload","ctx"]),g=r.value,_=z=>{const k=Ni(z);return`shape[${k}]._zod.run({ value: input[${k}], issues: [] }, ctx)`};p.write("const input = payload.value;");const S=Object.create(null);let C=0;for(const z of g.keys)S[z]=`key_${C++}`;p.write("const newResult = {};");for(const z of g.keys){const k=S[z],E=Ni(z),L=m[z],J=(($=L==null?void 0:L._zod)==null?void 0:$.optin)==="optional",ce=((I=L==null?void 0:L._zod)==null?void 0:I.optout)==="optional";p.write(`const ${k} = ${_(z)};`),J&&ce?p.write(`
|
|
13
|
+
if (${k}.issues.length) {
|
|
14
|
+
if (${E} in input) {
|
|
15
|
+
payload.issues = payload.issues.concat(${k}.issues.map(iss => ({
|
|
16
|
+
...iss,
|
|
17
|
+
path: iss.path ? [${E}, ...iss.path] : [${E}]
|
|
18
|
+
})));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (${k}.value === undefined) {
|
|
23
|
+
if (${E} in input) {
|
|
24
|
+
newResult[${E}] = undefined;
|
|
25
|
+
}
|
|
26
|
+
} else {
|
|
27
|
+
newResult[${E}] = ${k}.value;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
`):J?p.write(`
|
|
31
|
+
if (${k}.issues.length) {
|
|
32
|
+
payload.issues = payload.issues.concat(${k}.issues.map(iss => ({
|
|
33
|
+
...iss,
|
|
34
|
+
path: iss.path ? [${E}, ...iss.path] : [${E}]
|
|
35
|
+
})));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (${k}.value === undefined) {
|
|
39
|
+
if (${E} in input) {
|
|
40
|
+
newResult[${E}] = undefined;
|
|
41
|
+
}
|
|
42
|
+
} else {
|
|
43
|
+
newResult[${E}] = ${k}.value;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
`):p.write(`
|
|
47
|
+
const ${k}_present = ${E} in input;
|
|
48
|
+
if (${k}.issues.length) {
|
|
49
|
+
payload.issues = payload.issues.concat(${k}.issues.map(iss => ({
|
|
50
|
+
...iss,
|
|
51
|
+
path: iss.path ? [${E}, ...iss.path] : [${E}]
|
|
52
|
+
})));
|
|
53
|
+
}
|
|
54
|
+
if (!${k}_present && !${k}.issues.length) {
|
|
55
|
+
payload.issues.push({
|
|
56
|
+
code: "invalid_type",
|
|
57
|
+
expected: "nonoptional",
|
|
58
|
+
input: undefined,
|
|
59
|
+
path: [${E}]
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (${k}_present) {
|
|
64
|
+
if (${k}.value === undefined) {
|
|
65
|
+
newResult[${E}] = undefined;
|
|
66
|
+
} else {
|
|
67
|
+
newResult[${E}] = ${k}.value;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
`)}p.write("payload.value = newResult;"),p.write("return payload;");const A=p.compile();return(z,k)=>A(m,z,k)};let i;const a=An,c=!js.jitless,d=c&&Yl.value,u=t.catchall;let h;e._zod.parse=(m,p)=>{h??(h=r.value);const g=m.value;return a(g)?c&&d&&(p==null?void 0:p.async)===!1&&p.jitless!==!0?(i||(i=s(t.shape)),m=i(m,p),u?$a([],g,m,p,h,e):m):n(m,p):(m.issues.push({expected:"object",code:"invalid_type",input:g,inst:e}),m)}});function $i(e,t,n,r){for(const i of e)if(i.issues.length===0)return t.value=i.value,t;const s=e.filter(i=>!rn(i));return s.length===1?(t.value=s[0].value,s[0]):(t.issues.push({code:"invalid_union",input:t.value,inst:n,errors:e.map(i=>i.issues.map(a=>Zt(a,r,Dt())))}),t)}const Ra=v("$ZodUnion",(e,t)=>{be.init(e,t),ne(e._zod,"optin",()=>t.options.some(r=>r._zod.optin==="optional")?"optional":void 0),ne(e._zod,"optout",()=>t.options.some(r=>r._zod.optout==="optional")?"optional":void 0),ne(e._zod,"values",()=>{if(t.options.every(r=>r._zod.values))return new Set(t.options.flatMap(r=>Array.from(r._zod.values)))}),ne(e._zod,"pattern",()=>{if(t.options.every(r=>r._zod.pattern)){const r=t.options.map(s=>s._zod.pattern);return new RegExp(`^(${r.map(s=>Ts(s.source)).join("|")})$`)}});const n=t.options.length===1?t.options[0]._zod.run:null;e._zod.parse=(r,s)=>{if(n)return n(r,s);let i=!1;const a=[];for(const c of t.options){const l=c._zod.run({value:r.value,issues:[]},s);if(l instanceof Promise)a.push(l),i=!0;else{if(l.issues.length===0)return l;a.push(l)}}return i?Promise.all(a).then(c=>$i(c,r,e,s)):$i(a,r,e,s)}}),Dd=v("$ZodDiscriminatedUnion",(e,t)=>{t.inclusive=!1,Ra.init(e,t);const n=e._zod.parse;ne(e._zod,"propValues",()=>{const s={};for(const i of t.options){const a=i._zod.propValues;if(!a||Object.keys(a).length===0)throw new Error(`Invalid discriminated union option at index "${t.options.indexOf(i)}"`);for(const[c,l]of Object.entries(a)){s[c]||(s[c]=new Set);for(const d of l)s[c].add(d)}}return s});const r=_r(()=>{var a;const s=t.options,i=new Map;for(const c of s){const l=(a=c._zod.propValues)==null?void 0:a[t.discriminator];if(!l||l.size===0)throw new Error(`Invalid discriminated union option at index "${t.options.indexOf(c)}"`);for(const d of l){if(i.has(d))throw new Error(`Duplicate discriminator value "${String(d)}"`);i.set(d,c)}}return i});e._zod.parse=(s,i)=>{const a=s.value;if(!An(a))return s.issues.push({code:"invalid_type",expected:"object",input:a,inst:e}),s;const c=r.value.get(a==null?void 0:a[t.discriminator]);return c?c._zod.run(s,i):t.unionFallback||i.direction==="backward"?n(s,i):(s.issues.push({code:"invalid_union",errors:[],note:"No matching discriminator",discriminator:t.discriminator,options:Array.from(r.value.keys()),input:a,path:[t.discriminator],inst:e}),s)}}),Zd=v("$ZodIntersection",(e,t)=>{be.init(e,t),e._zod.parse=(n,r)=>{const s=n.value,i=t.left._zod.run({value:s,issues:[]},r),a=t.right._zod.run({value:s,issues:[]},r);return i instanceof Promise||a instanceof Promise?Promise.all([i,a]).then(([l,d])=>Ri(n,l,d)):Ri(n,i,a)}});function ts(e,t){if(e===t)return{valid:!0,data:e};if(e instanceof Date&&t instanceof Date&&+e==+t)return{valid:!0,data:e};if(zn(e)&&zn(t)){const n=Object.keys(t),r=Object.keys(e).filter(i=>n.indexOf(i)!==-1),s={...e,...t};for(const i of r){const a=ts(e[i],t[i]);if(!a.valid)return{valid:!1,mergeErrorPath:[i,...a.mergeErrorPath]};s[i]=a.data}return{valid:!0,data:s}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};const n=[];for(let r=0;r<e.length;r++){const s=e[r],i=t[r],a=ts(s,i);if(!a.valid)return{valid:!1,mergeErrorPath:[r,...a.mergeErrorPath]};n.push(a.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function Ri(e,t,n){const r=new Map;let s;for(const c of t.issues)if(c.code==="unrecognized_keys"){s??(s=c);for(const l of c.keys)r.has(l)||r.set(l,{}),r.get(l).l=!0}else e.issues.push(c);for(const c of n.issues)if(c.code==="unrecognized_keys")for(const l of c.keys)r.has(l)||r.set(l,{}),r.get(l).r=!0;else e.issues.push(c);const i=[...r].filter(([,c])=>c.l&&c.r).map(([c])=>c);if(i.length&&s&&e.issues.push({...s,keys:i}),rn(e))return e;const a=ts(t.value,n.value);if(!a.valid)throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(a.mergeErrorPath)}`);return e.value=a.data,e}const Fd=v("$ZodEnum",(e,t)=>{be.init(e,t);const n=fa(t.entries),r=new Set(n);e._zod.values=r,e._zod.pattern=new RegExp(`^(${n.filter(s=>Kl.has(typeof s)).map(s=>typeof s=="string"?an(s):s.toString()).join("|")})$`),e._zod.parse=(s,i)=>{const a=s.value;return r.has(a)||s.issues.push({code:"invalid_value",values:n,input:a,inst:e}),s}}),Ud=v("$ZodLiteral",(e,t)=>{if(be.init(e,t),t.values.length===0)throw new Error("Cannot create literal schema with no valid values");const n=new Set(t.values);e._zod.values=n,e._zod.pattern=new RegExp(`^(${t.values.map(r=>typeof r=="string"?an(r):r?an(r.toString()):String(r)).join("|")})$`),e._zod.parse=(r,s)=>{const i=r.value;return n.has(i)||r.issues.push({code:"invalid_value",values:t.values,input:i,inst:e}),r}}),qd=v("$ZodTransform",(e,t)=>{be.init(e,t),e._zod.optin="optional",e._zod.parse=(n,r)=>{if(r.direction==="backward")throw new ha(e.constructor.name);const s=t.transform(n.value,n);if(r.async)return(s instanceof Promise?s:Promise.resolve(s)).then(a=>(n.value=a,n.fallback=!0,n));if(s instanceof Promise)throw new on;return n.value=s,n.fallback=!0,n}});function Ci(e,t){return t===void 0&&(e.issues.length||e.fallback)?{issues:[],value:void 0}:e}const Ca=v("$ZodOptional",(e,t)=>{be.init(e,t),e._zod.optin="optional",e._zod.optout="optional",ne(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),ne(e._zod,"pattern",()=>{const n=t.innerType._zod.pattern;return n?new RegExp(`^(${Ts(n.source)})?$`):void 0}),e._zod.parse=(n,r)=>{if(t.innerType._zod.optin==="optional"){const s=n.value,i=t.innerType._zod.run(n,r);return i instanceof Promise?i.then(a=>Ci(a,s)):Ci(i,s)}return n.value===void 0?n:t.innerType._zod.run(n,r)}}),Bd=v("$ZodExactOptional",(e,t)=>{Ca.init(e,t),ne(e._zod,"values",()=>t.innerType._zod.values),ne(e._zod,"pattern",()=>t.innerType._zod.pattern),e._zod.parse=(n,r)=>t.innerType._zod.run(n,r)}),Hd=v("$ZodNullable",(e,t)=>{be.init(e,t),ne(e._zod,"optin",()=>t.innerType._zod.optin),ne(e._zod,"optout",()=>t.innerType._zod.optout),ne(e._zod,"pattern",()=>{const n=t.innerType._zod.pattern;return n?new RegExp(`^(${Ts(n.source)}|null)$`):void 0}),ne(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,null]):void 0),e._zod.parse=(n,r)=>n.value===null?n:t.innerType._zod.run(n,r)}),Wd=v("$ZodDefault",(e,t)=>{be.init(e,t),e._zod.optin="optional",ne(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,r)=>{if(r.direction==="backward")return t.innerType._zod.run(n,r);if(n.value===void 0)return n.value=t.defaultValue,n;const s=t.innerType._zod.run(n,r);return s instanceof Promise?s.then(i=>Ai(i,t)):Ai(s,t)}});function Ai(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}const Vd=v("$ZodPrefault",(e,t)=>{be.init(e,t),e._zod.optin="optional",ne(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,r)=>(r.direction==="backward"||n.value===void 0&&(n.value=t.defaultValue),t.innerType._zod.run(n,r))}),Gd=v("$ZodNonOptional",(e,t)=>{be.init(e,t),ne(e._zod,"values",()=>{const n=t.innerType._zod.values;return n?new Set([...n].filter(r=>r!==void 0)):void 0}),e._zod.parse=(n,r)=>{const s=t.innerType._zod.run(n,r);return s instanceof Promise?s.then(i=>zi(i,e)):zi(s,e)}});function zi(e,t){return!e.issues.length&&e.value===void 0&&e.issues.push({code:"invalid_type",expected:"nonoptional",input:e.value,inst:t}),e}const Jd=v("$ZodCatch",(e,t)=>{be.init(e,t),e._zod.optin="optional",ne(e._zod,"optout",()=>t.innerType._zod.optout),ne(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,r)=>{if(r.direction==="backward")return t.innerType._zod.run(n,r);const s=t.innerType._zod.run(n,r);return s instanceof Promise?s.then(i=>(n.value=i.value,i.issues.length&&(n.value=t.catchValue({...n,error:{issues:i.issues.map(a=>Zt(a,r,Dt()))},input:n.value}),n.issues=[],n.fallback=!0),n)):(n.value=s.value,s.issues.length&&(n.value=t.catchValue({...n,error:{issues:s.issues.map(i=>Zt(i,r,Dt()))},input:n.value}),n.issues=[],n.fallback=!0),n)}}),Yd=v("$ZodPipe",(e,t)=>{be.init(e,t),ne(e._zod,"values",()=>t.in._zod.values),ne(e._zod,"optin",()=>t.in._zod.optin),ne(e._zod,"optout",()=>t.out._zod.optout),ne(e._zod,"propValues",()=>t.in._zod.propValues),e._zod.parse=(n,r)=>{if(r.direction==="backward"){const i=t.out._zod.run(n,r);return i instanceof Promise?i.then(a=>Kn(a,t.in,r)):Kn(i,t.in,r)}const s=t.in._zod.run(n,r);return s instanceof Promise?s.then(i=>Kn(i,t.out,r)):Kn(s,t.out,r)}});function Kn(e,t,n){return e.issues.length?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues,fallback:e.fallback},n)}const Kd=v("$ZodReadonly",(e,t)=>{be.init(e,t),ne(e._zod,"propValues",()=>t.innerType._zod.propValues),ne(e._zod,"values",()=>t.innerType._zod.values),ne(e._zod,"optin",()=>{var n,r;return(r=(n=t.innerType)==null?void 0:n._zod)==null?void 0:r.optin}),ne(e._zod,"optout",()=>{var n,r;return(r=(n=t.innerType)==null?void 0:n._zod)==null?void 0:r.optout}),e._zod.parse=(n,r)=>{if(r.direction==="backward")return t.innerType._zod.run(n,r);const s=t.innerType._zod.run(n,r);return s instanceof Promise?s.then(Ii):Ii(s)}});function Ii(e){return e.value=Object.freeze(e.value),e}const Xd=v("$ZodCustom",(e,t)=>{Be.init(e,t),be.init(e,t),e._zod.parse=(n,r)=>n,e._zod.check=n=>{const r=n.value,s=t.fn(r);if(s instanceof Promise)return s.then(i=>Li(i,n,r,e));Li(s,n,r,e)}});function Li(e,t,n,r){if(!e){const s={code:"custom",input:n,inst:r,path:[...r._zod.def.path??[]],continue:!r._zod.def.abort};r._zod.def.params&&(s.params=r._zod.def.params),t.issues.push(In(s))}}var Oi;class Qd{constructor(){this._map=new WeakMap,this._idmap=new Map}add(t,...n){const r=n[0];return this._map.set(t,r),r&&typeof r=="object"&&"id"in r&&this._idmap.set(r.id,t),this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(t){const n=this._map.get(t);return n&&typeof n=="object"&&"id"in n&&this._idmap.delete(n.id),this._map.delete(t),this}get(t){const n=t._zod.parent;if(n){const r={...this.get(n)??{}};delete r.id;const s={...r,...this._map.get(t)};return Object.keys(s).length?s:void 0}return this._map.get(t)}has(t){return this._map.has(t)}}function eh(){return new Qd}(Oi=globalThis).__zod_globalRegistry??(Oi.__zod_globalRegistry=eh());const Nn=globalThis.__zod_globalRegistry;function th(e,t){return new e({type:"string",...D(t)})}function nh(e,t){return new e({type:"string",format:"email",check:"string_format",abort:!1,...D(t)})}function Pi(e,t){return new e({type:"string",format:"guid",check:"string_format",abort:!1,...D(t)})}function rh(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,...D(t)})}function sh(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...D(t)})}function ih(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...D(t)})}function oh(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...D(t)})}function ah(e,t){return new e({type:"string",format:"url",check:"string_format",abort:!1,...D(t)})}function ch(e,t){return new e({type:"string",format:"emoji",check:"string_format",abort:!1,...D(t)})}function lh(e,t){return new e({type:"string",format:"nanoid",check:"string_format",abort:!1,...D(t)})}function uh(e,t){return new e({type:"string",format:"cuid",check:"string_format",abort:!1,...D(t)})}function dh(e,t){return new e({type:"string",format:"cuid2",check:"string_format",abort:!1,...D(t)})}function Aa(e,t){return new e({type:"string",format:"ulid",check:"string_format",abort:!1,...D(t)})}function hh(e,t){return new e({type:"string",format:"xid",check:"string_format",abort:!1,...D(t)})}function fh(e,t){return new e({type:"string",format:"ksuid",check:"string_format",abort:!1,...D(t)})}function mh(e,t){return new e({type:"string",format:"ipv4",check:"string_format",abort:!1,...D(t)})}function ph(e,t){return new e({type:"string",format:"ipv6",check:"string_format",abort:!1,...D(t)})}function gh(e,t){return new e({type:"string",format:"cidrv4",check:"string_format",abort:!1,...D(t)})}function xh(e,t){return new e({type:"string",format:"cidrv6",check:"string_format",abort:!1,...D(t)})}function bh(e,t){return new e({type:"string",format:"base64",check:"string_format",abort:!1,...D(t)})}function _h(e,t){return new e({type:"string",format:"base64url",check:"string_format",abort:!1,...D(t)})}function vh(e,t){return new e({type:"string",format:"e164",check:"string_format",abort:!1,...D(t)})}function yh(e,t){return new e({type:"string",format:"jwt",check:"string_format",abort:!1,...D(t)})}function kh(e,t){return new e({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...D(t)})}function wh(e,t){return new e({type:"string",format:"date",check:"string_format",...D(t)})}function Sh(e,t){return new e({type:"string",format:"time",check:"string_format",precision:null,...D(t)})}function jh(e,t){return new e({type:"string",format:"duration",check:"string_format",...D(t)})}function Nh(e,t){return new e({type:"number",checks:[],...D(t)})}function Th(e,t){return new e({type:"number",check:"number_format",abort:!1,format:"safeint",...D(t)})}function Eh(e,t){return new e({type:"boolean",...D(t)})}function $h(e){return new e({type:"unknown"})}function Rh(e,t){return new e({type:"never",...D(t)})}function Mi(e,t){return new Sa({check:"less_than",...D(t),value:e,inclusive:!1})}function Br(e,t){return new Sa({check:"less_than",...D(t),value:e,inclusive:!0})}function Di(e,t){return new ja({check:"greater_than",...D(t),value:e,inclusive:!1})}function Hr(e,t){return new ja({check:"greater_than",...D(t),value:e,inclusive:!0})}function Zi(e,t){return new Vu({check:"multiple_of",...D(t),value:e})}function za(e,t){return new Ju({check:"max_length",...D(t),maximum:e})}function lr(e,t){return new Yu({check:"min_length",...D(t),minimum:e})}function Ia(e,t){return new Ku({check:"length_equals",...D(t),length:e})}function Ch(e,t){return new Xu({check:"string_format",format:"regex",...D(t),pattern:e})}function Ah(e){return new Qu({check:"string_format",format:"lowercase",...D(e)})}function zh(e){return new ed({check:"string_format",format:"uppercase",...D(e)})}function Ih(e,t){return new td({check:"string_format",format:"includes",...D(t),includes:e})}function Lh(e,t){return new nd({check:"string_format",format:"starts_with",...D(t),prefix:e})}function Oh(e,t){return new rd({check:"string_format",format:"ends_with",...D(t),suffix:e})}function hn(e){return new sd({check:"overwrite",tx:e})}function Ph(e){return hn(t=>t.normalize(e))}function Mh(){return hn(e=>e.trim())}function Dh(){return hn(e=>e.toLowerCase())}function Zh(){return hn(e=>e.toUpperCase())}function Fh(){return hn(e=>Jl(e))}function Uh(e,t,n){return new e({type:"array",element:t,...D(n)})}function qh(e,t,n){return new e({type:"custom",check:"custom",fn:t,...D(n)})}function Bh(e,t){const n=Hh(r=>(r.addIssue=s=>{if(typeof s=="string")r.issues.push(In(s,r.value,n._zod.def));else{const i=s;i.fatal&&(i.continue=!1),i.code??(i.code="custom"),i.input??(i.input=r.value),i.inst??(i.inst=n),i.continue??(i.continue=!n._zod.def.abort),r.issues.push(In(i))}},e(r.value,r)),t);return n}function Hh(e,t){const n=new Be({check:"custom",...D(t)});return n._zod.check=e,n}function La(e){let t=(e==null?void 0:e.target)??"draft-2020-12";return t==="draft-4"&&(t="draft-04"),t==="draft-7"&&(t="draft-07"),{processors:e.processors??{},metadataRegistry:(e==null?void 0:e.metadata)??Nn,target:t,unrepresentable:(e==null?void 0:e.unrepresentable)??"throw",override:(e==null?void 0:e.override)??(()=>{}),io:(e==null?void 0:e.io)??"output",counter:0,seen:new Map,cycles:(e==null?void 0:e.cycles)??"ref",reused:(e==null?void 0:e.reused)??"inline",external:(e==null?void 0:e.external)??void 0}}function $e(e,t,n={path:[],schemaPath:[]}){var u,h;var r;const s=e._zod.def,i=t.seen.get(e);if(i)return i.count++,n.schemaPath.includes(e)&&(i.cycle=n.path),i.schema;const a={schema:{},count:1,cycle:void 0,path:n.path};t.seen.set(e,a);const c=(h=(u=e._zod).toJSONSchema)==null?void 0:h.call(u);if(c)a.schema=c;else{const m={...n,schemaPath:[...n.schemaPath,e],path:n.path};if(e._zod.processJSONSchema)e._zod.processJSONSchema(t,a.schema,m);else{const g=a.schema,_=t.processors[s.type];if(!_)throw new Error(`[toJSONSchema]: Non-representable type encountered: ${s.type}`);_(e,t,g,m)}const p=e._zod.parent;p&&(a.ref||(a.ref=p),$e(p,t,m),t.seen.get(p).isParent=!0)}const l=t.metadataRegistry.get(e);return l&&Object.assign(a.schema,l),t.io==="input"&&Oe(e)&&(delete a.schema.examples,delete a.schema.default),t.io==="input"&&"_prefault"in a.schema&&((r=a.schema).default??(r.default=a.schema._prefault)),delete a.schema._prefault,t.seen.get(e).schema}function Oa(e,t){var a,c,l,d;const n=e.seen.get(t);if(!n)throw new Error("Unprocessed schema. This is a bug in Zod.");const r=new Map;for(const u of e.seen.entries()){const h=(a=e.metadataRegistry.get(u[0]))==null?void 0:a.id;if(h){const m=r.get(h);if(m&&m!==u[0])throw new Error(`Duplicate schema id "${h}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);r.set(h,u[0])}}const s=u=>{var _;const h=e.target==="draft-2020-12"?"$defs":"definitions";if(e.external){const S=(_=e.external.registry.get(u[0]))==null?void 0:_.id,C=e.external.uri??($=>$);if(S)return{ref:C(S)};const A=u[1].defId??u[1].schema.id??`schema${e.counter++}`;return u[1].defId=A,{defId:A,ref:`${C("__shared")}#/${h}/${A}`}}if(u[1]===n)return{ref:"#"};const p=`#/${h}/`,g=u[1].schema.id??`__schema${e.counter++}`;return{defId:g,ref:p+g}},i=u=>{if(u[1].schema.$ref)return;const h=u[1],{ref:m,defId:p}=s(u);h.def={...h.schema},p&&(h.defId=p);const g=h.schema;for(const _ in g)delete g[_];g.$ref=m};if(e.cycles==="throw")for(const u of e.seen.entries()){const h=u[1];if(h.cycle)throw new Error(`Cycle detected: #/${(c=h.cycle)==null?void 0:c.join("/")}/<root>
|
|
72
|
+
|
|
73
|
+
Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(const u of e.seen.entries()){const h=u[1];if(t===u[0]){i(u);continue}if(e.external){const p=(l=e.external.registry.get(u[0]))==null?void 0:l.id;if(t!==u[0]&&p){i(u);continue}}if((d=e.metadataRegistry.get(u[0]))==null?void 0:d.id){i(u);continue}if(h.cycle){i(u);continue}if(h.count>1&&e.reused==="ref"){i(u);continue}}}function Pa(e,t){var c,l,d,u;const n=e.seen.get(t);if(!n)throw new Error("Unprocessed schema. This is a bug in Zod.");const r=h=>{const m=e.seen.get(h);if(m.ref===null)return;const p=m.def??m.schema,g={...p},_=m.ref;if(m.ref=null,_){r(_);const C=e.seen.get(_),A=C.schema;if(A.$ref&&(e.target==="draft-07"||e.target==="draft-04"||e.target==="openapi-3.0")?(p.allOf=p.allOf??[],p.allOf.push(A)):Object.assign(p,A),Object.assign(p,g),h._zod.parent===_)for(const I in p)I==="$ref"||I==="allOf"||I in g||delete p[I];if(A.$ref&&C.def)for(const I in p)I==="$ref"||I==="allOf"||I in C.def&&JSON.stringify(p[I])===JSON.stringify(C.def[I])&&delete p[I]}const S=h._zod.parent;if(S&&S!==_){r(S);const C=e.seen.get(S);if(C!=null&&C.schema.$ref&&(p.$ref=C.schema.$ref,C.def))for(const A in p)A==="$ref"||A==="allOf"||A in C.def&&JSON.stringify(p[A])===JSON.stringify(C.def[A])&&delete p[A]}e.override({zodSchema:h,jsonSchema:p,path:m.path??[]})};for(const h of[...e.seen.entries()].reverse())r(h[0]);const s={};if(e.target==="draft-2020-12"?s.$schema="https://json-schema.org/draft/2020-12/schema":e.target==="draft-07"?s.$schema="http://json-schema.org/draft-07/schema#":e.target==="draft-04"?s.$schema="http://json-schema.org/draft-04/schema#":e.target,(c=e.external)!=null&&c.uri){const h=(l=e.external.registry.get(t))==null?void 0:l.id;if(!h)throw new Error("Schema is missing an `id` property");s.$id=e.external.uri(h)}Object.assign(s,n.def??n.schema);const i=(d=e.metadataRegistry.get(t))==null?void 0:d.id;i!==void 0&&s.id===i&&delete s.id;const a=((u=e.external)==null?void 0:u.defs)??{};for(const h of e.seen.entries()){const m=h[1];m.def&&m.defId&&(m.def.id===m.defId&&delete m.def.id,a[m.defId]=m.def)}e.external||Object.keys(a).length>0&&(e.target==="draft-2020-12"?s.$defs=a:s.definitions=a);try{const h=JSON.parse(JSON.stringify(s));return Object.defineProperty(h,"~standard",{value:{...t["~standard"],jsonSchema:{input:ur(t,"input",e.processors),output:ur(t,"output",e.processors)}},enumerable:!1,writable:!1}),h}catch{throw new Error("Error converting schema to JSON.")}}function Oe(e,t){const n=t??{seen:new Set};if(n.seen.has(e))return!1;n.seen.add(e);const r=e._zod.def;if(r.type==="transform")return!0;if(r.type==="array")return Oe(r.element,n);if(r.type==="set")return Oe(r.valueType,n);if(r.type==="lazy")return Oe(r.getter(),n);if(r.type==="promise"||r.type==="optional"||r.type==="nonoptional"||r.type==="nullable"||r.type==="readonly"||r.type==="default"||r.type==="prefault")return Oe(r.innerType,n);if(r.type==="intersection")return Oe(r.left,n)||Oe(r.right,n);if(r.type==="record"||r.type==="map")return Oe(r.keyType,n)||Oe(r.valueType,n);if(r.type==="pipe")return e._zod.traits.has("$ZodCodec")?!0:Oe(r.in,n)||Oe(r.out,n);if(r.type==="object"){for(const s in r.shape)if(Oe(r.shape[s],n))return!0;return!1}if(r.type==="union"){for(const s of r.options)if(Oe(s,n))return!0;return!1}if(r.type==="tuple"){for(const s of r.items)if(Oe(s,n))return!0;return!!(r.rest&&Oe(r.rest,n))}return!1}const Wh=(e,t={})=>n=>{const r=La({...n,processors:t});return $e(e,r),Oa(r,e),Pa(r,e)},ur=(e,t,n={})=>r=>{const{libraryOptions:s,target:i}=r??{},a=La({...s??{},target:i,io:t,processors:n});return $e(e,a),Oa(a,e),Pa(a,e)},Vh={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string",regex:""},Gh=(e,t,n,r)=>{const s=n;s.type="string";const{minimum:i,maximum:a,format:c,patterns:l,contentEncoding:d}=e._zod.bag;if(typeof i=="number"&&(s.minLength=i),typeof a=="number"&&(s.maxLength=a),c&&(s.format=Vh[c]??c,s.format===""&&delete s.format,c==="time"&&delete s.format),d&&(s.contentEncoding=d),l&&l.size>0){const u=[...l];u.length===1?s.pattern=u[0].source:u.length>1&&(s.allOf=[...u.map(h=>({...t.target==="draft-07"||t.target==="draft-04"||t.target==="openapi-3.0"?{type:"string"}:{},pattern:h.source}))])}},Jh=(e,t,n,r)=>{const s=n,{minimum:i,maximum:a,format:c,multipleOf:l,exclusiveMaximum:d,exclusiveMinimum:u}=e._zod.bag;typeof c=="string"&&c.includes("int")?s.type="integer":s.type="number";const h=typeof u=="number"&&u>=(i??Number.NEGATIVE_INFINITY),m=typeof d=="number"&&d<=(a??Number.POSITIVE_INFINITY),p=t.target==="draft-04"||t.target==="openapi-3.0";h?p?(s.minimum=u,s.exclusiveMinimum=!0):s.exclusiveMinimum=u:typeof i=="number"&&(s.minimum=i),m?p?(s.maximum=d,s.exclusiveMaximum=!0):s.exclusiveMaximum=d:typeof a=="number"&&(s.maximum=a),typeof l=="number"&&(s.multipleOf=l)},Yh=(e,t,n,r)=>{n.type="boolean"},Kh=(e,t,n,r)=>{n.not={}},Xh=(e,t,n,r)=>{},Qh=(e,t,n,r)=>{const s=e._zod.def,i=fa(s.entries);i.every(a=>typeof a=="number")&&(n.type="number"),i.every(a=>typeof a=="string")&&(n.type="string"),n.enum=i},ef=(e,t,n,r)=>{const s=e._zod.def,i=[];for(const a of s.values)if(a===void 0){if(t.unrepresentable==="throw")throw new Error("Literal `undefined` cannot be represented in JSON Schema")}else if(typeof a=="bigint"){if(t.unrepresentable==="throw")throw new Error("BigInt literals cannot be represented in JSON Schema");i.push(Number(a))}else i.push(a);if(i.length!==0)if(i.length===1){const a=i[0];n.type=a===null?"null":typeof a,t.target==="draft-04"||t.target==="openapi-3.0"?n.enum=[a]:n.const=a}else i.every(a=>typeof a=="number")&&(n.type="number"),i.every(a=>typeof a=="string")&&(n.type="string"),i.every(a=>typeof a=="boolean")&&(n.type="boolean"),i.every(a=>a===null)&&(n.type="null"),n.enum=i},tf=(e,t,n,r)=>{if(t.unrepresentable==="throw")throw new Error("Custom types cannot be represented in JSON Schema")},nf=(e,t,n,r)=>{if(t.unrepresentable==="throw")throw new Error("Transforms cannot be represented in JSON Schema")},rf=(e,t,n,r)=>{const s=n,i=e._zod.def,{minimum:a,maximum:c}=e._zod.bag;typeof a=="number"&&(s.minItems=a),typeof c=="number"&&(s.maxItems=c),s.type="array",s.items=$e(i.element,t,{...r,path:[...r.path,"items"]})},sf=(e,t,n,r)=>{var d;const s=n,i=e._zod.def;s.type="object",s.properties={};const a=i.shape;for(const u in a)s.properties[u]=$e(a[u],t,{...r,path:[...r.path,"properties",u]});const c=new Set(Object.keys(a)),l=new Set([...c].filter(u=>{const h=i.shape[u]._zod;return t.io==="input"?h.optin===void 0:h.optout===void 0}));l.size>0&&(s.required=Array.from(l)),((d=i.catchall)==null?void 0:d._zod.def.type)==="never"?s.additionalProperties=!1:i.catchall?i.catchall&&(s.additionalProperties=$e(i.catchall,t,{...r,path:[...r.path,"additionalProperties"]})):t.io==="output"&&(s.additionalProperties=!1)},of=(e,t,n,r)=>{const s=e._zod.def,i=s.inclusive===!1,a=s.options.map((c,l)=>$e(c,t,{...r,path:[...r.path,i?"oneOf":"anyOf",l]}));i?n.oneOf=a:n.anyOf=a},af=(e,t,n,r)=>{const s=e._zod.def,i=$e(s.left,t,{...r,path:[...r.path,"allOf",0]}),a=$e(s.right,t,{...r,path:[...r.path,"allOf",1]}),c=d=>"allOf"in d&&Object.keys(d).length===1,l=[...c(i)?i.allOf:[i],...c(a)?a.allOf:[a]];n.allOf=l},cf=(e,t,n,r)=>{const s=e._zod.def,i=$e(s.innerType,t,r),a=t.seen.get(e);t.target==="openapi-3.0"?(a.ref=s.innerType,n.nullable=!0):n.anyOf=[i,{type:"null"}]},lf=(e,t,n,r)=>{const s=e._zod.def;$e(s.innerType,t,r);const i=t.seen.get(e);i.ref=s.innerType},uf=(e,t,n,r)=>{const s=e._zod.def;$e(s.innerType,t,r);const i=t.seen.get(e);i.ref=s.innerType,n.default=JSON.parse(JSON.stringify(s.defaultValue))},df=(e,t,n,r)=>{const s=e._zod.def;$e(s.innerType,t,r);const i=t.seen.get(e);i.ref=s.innerType,t.io==="input"&&(n._prefault=JSON.parse(JSON.stringify(s.defaultValue)))},hf=(e,t,n,r)=>{const s=e._zod.def;$e(s.innerType,t,r);const i=t.seen.get(e);i.ref=s.innerType;let a;try{a=s.catchValue(void 0)}catch{throw new Error("Dynamic catch values are not supported in JSON Schema")}n.default=a},ff=(e,t,n,r)=>{const s=e._zod.def,i=s.in._zod.traits.has("$ZodTransform"),a=t.io==="input"?i?s.out:s.in:s.out;$e(a,t,r);const c=t.seen.get(e);c.ref=a},mf=(e,t,n,r)=>{const s=e._zod.def;$e(s.innerType,t,r);const i=t.seen.get(e);i.ref=s.innerType,n.readOnly=!0},Ma=(e,t,n,r)=>{const s=e._zod.def;$e(s.innerType,t,r);const i=t.seen.get(e);i.ref=s.innerType},pf=v("ZodISODateTime",(e,t)=>{bd.init(e,t),pe.init(e,t)});function Da(e){return kh(pf,e)}const gf=v("ZodISODate",(e,t)=>{_d.init(e,t),pe.init(e,t)});function Za(e){return wh(gf,e)}const xf=v("ZodISOTime",(e,t)=>{vd.init(e,t),pe.init(e,t)});function bf(e){return Sh(xf,e)}const _f=v("ZodISODuration",(e,t)=>{yd.init(e,t),pe.init(e,t)});function vf(e){return jh(_f,e)}const yf=(e,t)=>{ba.init(e,t),e.name="ZodError",Object.defineProperties(e,{format:{value:n=>lu(e,n)},flatten:{value:n=>cu(e,n)},addIssue:{value:n=>{e.issues.push(n),e.message=JSON.stringify(e.issues,es,2)}},addIssues:{value:n=>{e.issues.push(...n),e.message=JSON.stringify(e.issues,es,2)}},isEmpty:{get(){return e.issues.length===0}}})},Je=v("ZodError",yf,{Parent:Error}),kf=$s(Je),wf=Rs(Je),Sf=vr(Je),jf=yr(Je),Nf=hu(Je),Tf=fu(Je),Ef=mu(Je),$f=pu(Je),Rf=gu(Je),Cf=xu(Je),Af=bu(Je),zf=_u(Je),Fi=new WeakMap;function Mn(e,t,n){const r=Object.getPrototypeOf(e);let s=Fi.get(r);if(s||(s=new Set,Fi.set(r,s)),!s.has(t)){s.add(t);for(const i in n){const a=n[i];Object.defineProperty(r,i,{configurable:!0,enumerable:!1,get(){const c=a.bind(this);return Object.defineProperty(this,i,{configurable:!0,writable:!0,enumerable:!0,value:c}),c},set(c){Object.defineProperty(this,i,{configurable:!0,writable:!0,enumerable:!0,value:c})}})}}}const _e=v("ZodType",(e,t)=>(be.init(e,t),Object.assign(e["~standard"],{jsonSchema:{input:ur(e,"input"),output:ur(e,"output")}}),e.toJSONSchema=Wh(e,{}),e.def=t,e.type=t.type,Object.defineProperty(e,"_def",{value:t}),e.parse=(n,r)=>kf(e,n,r,{callee:e.parse}),e.safeParse=(n,r)=>Sf(e,n,r),e.parseAsync=async(n,r)=>wf(e,n,r,{callee:e.parseAsync}),e.safeParseAsync=async(n,r)=>jf(e,n,r),e.spa=e.safeParseAsync,e.encode=(n,r)=>Nf(e,n,r),e.decode=(n,r)=>Tf(e,n,r),e.encodeAsync=async(n,r)=>Ef(e,n,r),e.decodeAsync=async(n,r)=>$f(e,n,r),e.safeEncode=(n,r)=>Rf(e,n,r),e.safeDecode=(n,r)=>Cf(e,n,r),e.safeEncodeAsync=async(n,r)=>Af(e,n,r),e.safeDecodeAsync=async(n,r)=>zf(e,n,r),Mn(e,"ZodType",{check(...n){const r=this.def;return this.clone(Rt(r,{checks:[...r.checks??[],...n.map(s=>typeof s=="function"?{_zod:{check:s,def:{check:"custom"},onattach:[]}}:s)]}),{parent:!0})},with(...n){return this.check(...n)},clone(n,r){return Ct(this,n,r)},brand(){return this},register(n,r){return n.add(this,r),this},refine(n,r){return this.check(Nm(n,r))},superRefine(n,r){return this.check(Tm(n,r))},overwrite(n){return this.check(hn(n))},optional(){return Bi(this)},exactOptional(){return fm(this)},nullable(){return Hi(this)},nullish(){return Bi(Hi(this))},nonoptional(n){return _m(this,n)},array(){return je(this)},or(n){return im([this,n])},and(n){return cm(this,n)},transform(n){return Wi(this,dm(n))},default(n){return gm(this,n)},prefault(n){return bm(this,n)},catch(n){return ym(this,n)},pipe(n){return Wi(this,n)},readonly(){return Sm(this)},describe(n){const r=this.clone();return Nn.add(r,{description:n}),r},meta(...n){if(n.length===0)return Nn.get(this);const r=this.clone();return Nn.add(r,n[0]),r},isOptional(){return this.safeParse(void 0).success},isNullable(){return this.safeParse(null).success},apply(n){return n(this)}}),Object.defineProperty(e,"description",{get(){var n;return(n=Nn.get(e))==null?void 0:n.description},configurable:!0}),e)),Fa=v("_ZodString",(e,t)=>{Cs.init(e,t),_e.init(e,t),e._zod.processJSONSchema=(r,s,i)=>Gh(e,r,s);const n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,Mn(e,"_ZodString",{regex(...r){return this.check(Ch(...r))},includes(...r){return this.check(Ih(...r))},startsWith(...r){return this.check(Lh(...r))},endsWith(...r){return this.check(Oh(...r))},min(...r){return this.check(lr(...r))},max(...r){return this.check(za(...r))},length(...r){return this.check(Ia(...r))},nonempty(...r){return this.check(lr(1,...r))},lowercase(r){return this.check(Ah(r))},uppercase(r){return this.check(zh(r))},trim(){return this.check(Mh())},normalize(...r){return this.check(Ph(...r))},toLowerCase(){return this.check(Dh())},toUpperCase(){return this.check(Zh())},slugify(){return this.check(Fh())}})}),If=v("ZodString",(e,t)=>{Cs.init(e,t),Fa.init(e,t),e.email=n=>e.check(nh(Lf,n)),e.url=n=>e.check(ah(Of,n)),e.jwt=n=>e.check(yh(Kf,n)),e.emoji=n=>e.check(ch(Pf,n)),e.guid=n=>e.check(Pi(Ui,n)),e.uuid=n=>e.check(rh(Xn,n)),e.uuidv4=n=>e.check(sh(Xn,n)),e.uuidv6=n=>e.check(ih(Xn,n)),e.uuidv7=n=>e.check(oh(Xn,n)),e.nanoid=n=>e.check(lh(Mf,n)),e.guid=n=>e.check(Pi(Ui,n)),e.cuid=n=>e.check(uh(Df,n)),e.cuid2=n=>e.check(dh(Zf,n)),e.ulid=n=>e.check(Aa(Ua,n)),e.base64=n=>e.check(bh(Gf,n)),e.base64url=n=>e.check(_h(Jf,n)),e.xid=n=>e.check(hh(Uf,n)),e.ksuid=n=>e.check(fh(qf,n)),e.ipv4=n=>e.check(mh(Bf,n)),e.ipv6=n=>e.check(ph(Hf,n)),e.cidrv4=n=>e.check(gh(Wf,n)),e.cidrv6=n=>e.check(xh(Vf,n)),e.e164=n=>e.check(vh(Yf,n)),e.datetime=n=>e.check(Da(n)),e.date=n=>e.check(Za(n)),e.time=n=>e.check(bf(n)),e.duration=n=>e.check(vf(n))});function w(e){return th(If,e)}const pe=v("ZodStringFormat",(e,t)=>{he.init(e,t),Fa.init(e,t)}),Lf=v("ZodEmail",(e,t)=>{ld.init(e,t),pe.init(e,t)}),Ui=v("ZodGUID",(e,t)=>{ad.init(e,t),pe.init(e,t)}),Xn=v("ZodUUID",(e,t)=>{cd.init(e,t),pe.init(e,t)}),Of=v("ZodURL",(e,t)=>{ud.init(e,t),pe.init(e,t)}),Pf=v("ZodEmoji",(e,t)=>{dd.init(e,t),pe.init(e,t)}),Mf=v("ZodNanoID",(e,t)=>{hd.init(e,t),pe.init(e,t)}),Df=v("ZodCUID",(e,t)=>{fd.init(e,t),pe.init(e,t)}),Zf=v("ZodCUID2",(e,t)=>{md.init(e,t),pe.init(e,t)}),Ua=v("ZodULID",(e,t)=>{pd.init(e,t),pe.init(e,t)});function Ff(e){return Aa(Ua,e)}const Uf=v("ZodXID",(e,t)=>{gd.init(e,t),pe.init(e,t)}),qf=v("ZodKSUID",(e,t)=>{xd.init(e,t),pe.init(e,t)}),Bf=v("ZodIPv4",(e,t)=>{kd.init(e,t),pe.init(e,t)}),Hf=v("ZodIPv6",(e,t)=>{wd.init(e,t),pe.init(e,t)}),Wf=v("ZodCIDRv4",(e,t)=>{Sd.init(e,t),pe.init(e,t)}),Vf=v("ZodCIDRv6",(e,t)=>{jd.init(e,t),pe.init(e,t)}),Gf=v("ZodBase64",(e,t)=>{Nd.init(e,t),pe.init(e,t)}),Jf=v("ZodBase64URL",(e,t)=>{Ed.init(e,t),pe.init(e,t)}),Yf=v("ZodE164",(e,t)=>{$d.init(e,t),pe.init(e,t)}),Kf=v("ZodJWT",(e,t)=>{Cd.init(e,t),pe.init(e,t)}),qa=v("ZodNumber",(e,t)=>{Ta.init(e,t),_e.init(e,t),e._zod.processJSONSchema=(r,s,i)=>Jh(e,r,s),Mn(e,"ZodNumber",{gt(r,s){return this.check(Di(r,s))},gte(r,s){return this.check(Hr(r,s))},min(r,s){return this.check(Hr(r,s))},lt(r,s){return this.check(Mi(r,s))},lte(r,s){return this.check(Br(r,s))},max(r,s){return this.check(Br(r,s))},int(r){return this.check(qi(r))},safe(r){return this.check(qi(r))},positive(r){return this.check(Di(0,r))},nonnegative(r){return this.check(Hr(0,r))},negative(r){return this.check(Mi(0,r))},nonpositive(r){return this.check(Br(0,r))},multipleOf(r,s){return this.check(Zi(r,s))},step(r,s){return this.check(Zi(r,s))},finite(){return this}});const n=e._zod.bag;e.minValue=Math.max(n.minimum??Number.NEGATIVE_INFINITY,n.exclusiveMinimum??Number.NEGATIVE_INFINITY)??null,e.maxValue=Math.min(n.maximum??Number.POSITIVE_INFINITY,n.exclusiveMaximum??Number.POSITIVE_INFINITY)??null,e.isInt=(n.format??"").includes("int")||Number.isSafeInteger(n.multipleOf??.5),e.isFinite=!0,e.format=n.format??null});function F(e){return Nh(qa,e)}const Xf=v("ZodNumberFormat",(e,t)=>{Ad.init(e,t),qa.init(e,t)});function qi(e){return Th(Xf,e)}const Qf=v("ZodBoolean",(e,t)=>{zd.init(e,t),_e.init(e,t),e._zod.processJSONSchema=(n,r,s)=>Yh(e,n,r)});function Me(e){return Eh(Qf,e)}const em=v("ZodUnknown",(e,t)=>{Id.init(e,t),_e.init(e,t),e._zod.processJSONSchema=(n,r,s)=>Xh()});function Ft(){return $h(em)}const tm=v("ZodNever",(e,t)=>{Ld.init(e,t),_e.init(e,t),e._zod.processJSONSchema=(n,r,s)=>Kh(e,n,r)});function nm(e){return Rh(tm,e)}const rm=v("ZodArray",(e,t)=>{Od.init(e,t),_e.init(e,t),e._zod.processJSONSchema=(n,r,s)=>rf(e,n,r,s),e.element=t.element,Mn(e,"ZodArray",{min(n,r){return this.check(lr(n,r))},nonempty(n){return this.check(lr(1,n))},max(n,r){return this.check(za(n,r))},length(n,r){return this.check(Ia(n,r))},unwrap(){return this.element}})});function je(e,t){return Uh(rm,e,t)}const sm=v("ZodObject",(e,t)=>{Md.init(e,t),_e.init(e,t),e._zod.processJSONSchema=(n,r,s)=>sf(e,n,r,s),ne(e,"shape",()=>t.shape),Mn(e,"ZodObject",{keyof(){return ae(Object.keys(this._zod.def.shape))},catchall(n){return this.clone({...this._zod.def,catchall:n})},passthrough(){return this.clone({...this._zod.def,catchall:Ft()})},loose(){return this.clone({...this._zod.def,catchall:Ft()})},strict(){return this.clone({...this._zod.def,catchall:nm()})},strip(){return this.clone({...this._zod.def,catchall:void 0})},extend(n){return nu(this,n)},safeExtend(n){return ru(this,n)},merge(n){return su(this,n)},pick(n){return eu(this,n)},omit(n){return tu(this,n)},partial(...n){return iu(Ha,this,n[0])},required(...n){return ou(Wa,this,n[0])}})});function j(e,t){const n={type:"object",shape:e??{},...D(t)};return new sm(n)}const Ba=v("ZodUnion",(e,t)=>{Ra.init(e,t),_e.init(e,t),e._zod.processJSONSchema=(n,r,s)=>of(e,n,r,s),e.options=t.options});function im(e,t){return new Ba({type:"union",options:e,...D(t)})}const om=v("ZodDiscriminatedUnion",(e,t)=>{Ba.init(e,t),Dd.init(e,t)});function wr(e,t,n){return new om({type:"union",options:t,discriminator:e,...D(n)})}const am=v("ZodIntersection",(e,t)=>{Zd.init(e,t),_e.init(e,t),e._zod.processJSONSchema=(n,r,s)=>af(e,n,r,s)});function cm(e,t){return new am({type:"intersection",left:e,right:t})}const ns=v("ZodEnum",(e,t)=>{Fd.init(e,t),_e.init(e,t),e._zod.processJSONSchema=(r,s,i)=>Qh(e,r,s),e.enum=t.entries,e.options=Object.values(t.entries);const n=new Set(Object.keys(t.entries));e.extract=(r,s)=>{const i={};for(const a of r)if(n.has(a))i[a]=t.entries[a];else throw new Error(`Key ${a} not found in enum`);return new ns({...t,checks:[],...D(s),entries:i})},e.exclude=(r,s)=>{const i={...t.entries};for(const a of r)if(n.has(a))delete i[a];else throw new Error(`Key ${a} not found in enum`);return new ns({...t,checks:[],...D(s),entries:i})}});function ae(e,t){const n=Array.isArray(e)?Object.fromEntries(e.map(r=>[r,r])):e;return new ns({type:"enum",entries:n,...D(t)})}const lm=v("ZodLiteral",(e,t)=>{Ud.init(e,t),_e.init(e,t),e._zod.processJSONSchema=(n,r,s)=>ef(e,n,r),e.values=new Set(t.values),Object.defineProperty(e,"value",{get(){if(t.values.length>1)throw new Error("This schema contains multiple valid literal values. Use `.values` instead.");return t.values[0]}})});function O(e,t){return new lm({type:"literal",values:Array.isArray(e)?e:[e],...D(t)})}const um=v("ZodTransform",(e,t)=>{qd.init(e,t),_e.init(e,t),e._zod.processJSONSchema=(n,r,s)=>nf(e,n),e._zod.parse=(n,r)=>{if(r.direction==="backward")throw new ha(e.constructor.name);n.addIssue=i=>{if(typeof i=="string")n.issues.push(In(i,n.value,t));else{const a=i;a.fatal&&(a.continue=!1),a.code??(a.code="custom"),a.input??(a.input=n.value),a.inst??(a.inst=e),n.issues.push(In(a))}};const s=t.transform(n.value,n);return s instanceof Promise?s.then(i=>(n.value=i,n.fallback=!0,n)):(n.value=s,n.fallback=!0,n)}});function dm(e){return new um({type:"transform",transform:e})}const Ha=v("ZodOptional",(e,t)=>{Ca.init(e,t),_e.init(e,t),e._zod.processJSONSchema=(n,r,s)=>Ma(e,n,r,s),e.unwrap=()=>e._zod.def.innerType});function Bi(e){return new Ha({type:"optional",innerType:e})}const hm=v("ZodExactOptional",(e,t)=>{Bd.init(e,t),_e.init(e,t),e._zod.processJSONSchema=(n,r,s)=>Ma(e,n,r,s),e.unwrap=()=>e._zod.def.innerType});function fm(e){return new hm({type:"optional",innerType:e})}const mm=v("ZodNullable",(e,t)=>{Hd.init(e,t),_e.init(e,t),e._zod.processJSONSchema=(n,r,s)=>cf(e,n,r,s),e.unwrap=()=>e._zod.def.innerType});function Hi(e){return new mm({type:"nullable",innerType:e})}const pm=v("ZodDefault",(e,t)=>{Wd.init(e,t),_e.init(e,t),e._zod.processJSONSchema=(n,r,s)=>uf(e,n,r,s),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function gm(e,t){return new pm({type:"default",innerType:e,get defaultValue(){return typeof t=="function"?t():pa(t)}})}const xm=v("ZodPrefault",(e,t)=>{Vd.init(e,t),_e.init(e,t),e._zod.processJSONSchema=(n,r,s)=>df(e,n,r,s),e.unwrap=()=>e._zod.def.innerType});function bm(e,t){return new xm({type:"prefault",innerType:e,get defaultValue(){return typeof t=="function"?t():pa(t)}})}const Wa=v("ZodNonOptional",(e,t)=>{Gd.init(e,t),_e.init(e,t),e._zod.processJSONSchema=(n,r,s)=>lf(e,n,r,s),e.unwrap=()=>e._zod.def.innerType});function _m(e,t){return new Wa({type:"nonoptional",innerType:e,...D(t)})}const vm=v("ZodCatch",(e,t)=>{Jd.init(e,t),_e.init(e,t),e._zod.processJSONSchema=(n,r,s)=>hf(e,n,r,s),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function ym(e,t){return new vm({type:"catch",innerType:e,catchValue:typeof t=="function"?t:()=>t})}const km=v("ZodPipe",(e,t)=>{Yd.init(e,t),_e.init(e,t),e._zod.processJSONSchema=(n,r,s)=>ff(e,n,r,s),e.in=t.in,e.out=t.out});function Wi(e,t){return new km({type:"pipe",in:e,out:t})}const wm=v("ZodReadonly",(e,t)=>{Kd.init(e,t),_e.init(e,t),e._zod.processJSONSchema=(n,r,s)=>mf(e,n,r,s),e.unwrap=()=>e._zod.def.innerType});function Sm(e){return new wm({type:"readonly",innerType:e})}const jm=v("ZodCustom",(e,t)=>{Xd.init(e,t),_e.init(e,t),e._zod.processJSONSchema=(n,r,s)=>tf(e,n)});function Nm(e,t={}){return qh(jm,e,t)}function Tm(e,t){return Bh(e,t)}const se=Ff(),Em=/^[a-z0-9][a-z0-9-]{0,62}$/,Te=w().regex(Em);function $m(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").replace(/-+/g,"-").slice(0,63).replace(/-+$/g,"")||"channel"}const ve=F().int().positive(),st=F().int().nonnegative(),xe=Da(),Sr=ae(["read-only","workspace-write","full-access"]),Va=["low","medium","high"],dr=ae([...Va,"xhigh","max","ultra","ultracode"]),As=ae(["human","agent","extension","system","bridge"]),zs=ae(["idle","running","queued","awaiting_input","paused","dead","unreachable","custody_uncertain"]),Rm=ae(["owned","mirrored"]),Cm=ae(["owner","admin","member","observer"]),Am=/^[a-z0-9][a-z0-9-]{1,30}$/,Ga=["all","switchboard"],jr=w().regex(Am),Mt=jr.refine(e=>!Ga.includes(e),{message:"handle is reserved"});function zm(e){const n=e.normalize("NFKD").replace(/[\u0300-\u036f]/g,"").toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,31).replace(/-+$/g,""),r=n.length>=2?n:"agent";return Mt.safeParse(r).success?r:void 0}const rs=j({inputTokens:F().int().nonnegative().optional(),cachedInputTokens:F().int().nonnegative().optional(),outputTokens:F().int().nonnegative().optional(),totalCostUsd:F().nonnegative().optional(),contextWindowMaxTokens:F().int().positive().optional(),contextWindowUsedTokens:F().int().nonnegative().optional(),estimated:O(!0).optional()}).strict().superRefine((e,t)=>{e.contextWindowMaxTokens===void 0!=(e.contextWindowUsedTokens===void 0)&&t.addIssue({code:"custom",path:["contextWindowUsedTokens"],message:"context window maximum and used tokens must be reported together"})}),Ja=j({window:w().min(1),status:w().min(1).optional(),resets_at:xe.optional(),used_percent:F().min(0).max(100).optional()}).loose(),Vi=j({id:se,kind:As,handle:jr,display_name:w(),purpose:w().optional(),harness:w().min(1).optional(),session_ref:w().min(1).optional(),cwd:w().min(1).optional(),policy:w().min(1).optional(),model:w().min(1).optional(),thinking:dr.optional(),host:w().min(1).optional(),limits:je(Ja).optional(),lastUsage:rs.optional(),state:zs.optional(),custody:Rm.optional(),parent:se.optional(),role:Cm.optional(),conventions_sent:Me().default(!1),misaddressed:Me().default(!1),roster_stale:Me().default(!0),removed_ts:xe.optional(),waiting:j({peers:je(se).min(1),reason:ae(["reply","mention","any"]),since_ts:xe,until_ts:xe}).optional()}).superRefine((e,t)=>{e.kind!=="system"&&Ga.includes(e.handle)&&t.addIssue({code:"custom",path:["handle"],message:`handle '${e.handle}' is reserved for the system member`}),e.kind==="human"&&e.role===void 0?t.addIssue({code:"custom",path:["role"],message:"human members require a role"}):e.kind!=="human"&&e.role!==void 0&&t.addIssue({code:"custom",path:["role"],message:"only human members may have a role"})}),Is=ae(["chat","run","ask","approval","system"]),Im=j({member_id:se,start:F().int().nonnegative(),end:F().int().positive()}).refine(e=>e.start<e.end,{message:"span end must be after start"}),Lm=j({platform:w().min(1),external_id:w().min(1),sender_name:w().min(1)}),ss=j({interaction_id:w().min(1),kind:ae(["ask","approval"]),prompt:w(),options:je(j({label:w().min(1),description:w().optional()})).optional(),multi:Me().optional(),tool:w().optional(),detail:w().optional()}),Ya=j({input_tokens:F().int().nonnegative(),output_tokens:F().int().nonnegative(),cost_usd:F().nonnegative().optional()}),Ka=ae(["running","completed","failed","interrupted"]),Om=j({status:Ka,started_ts:xe,ended_ts:xe.optional(),stalled_since:xe.optional(),tool_calls:F().int().nonnegative(),usage:Ya.optional(),events_ref:w().min(1),final_text:w().optional(),model:w().min(1).optional(),estimated_cost_usd:F().nonnegative().optional(),output_mode:O("messages").optional(),result_message_id:ve.optional(),error:w().min(1).optional()}),Pm=j({id:w().min(1),name:w().min(1),mime:w().min(1),size:F().int().nonnegative()}),hr=j({id:ve,room:Te,author:se,kind:Is,body:w(),mentions:je(Im),refs:je(ve),ledger_refs:je(w()),reply_to:ve.optional(),run:Om.optional(),run_parent_id:ve.optional(),ask:ss.optional(),origin:Lm.optional(),ack:Me().optional(),pinned:Me().optional(),deleted:Me().optional(),attachments:je(Pm).optional(),ts:xe,seq:st}),Mm=j({peers:je(jr).min(1),reason:ae(["reply","mention","any"]),since_ts:xe,until_ts:xe}).strict(),Dm=j({kind:ae(["tool","post"]),title:w().max(500),status:ae(["ok","error"]).optional(),duration_ms:F().nonnegative().optional(),ts:xe}).strict();j({member:j({handle:jr,state:zs,waiting:Mm.optional()}).strict(),current_run:j({message_id:ve,started_ts:xe,elapsed_ms:F().nonnegative(),tool_calls:F().int().nonnegative()}).strict().optional(),recent:je(Dm).max(5)}).strict();j({message_id:ve,item_index:F().int().nonnegative(),kind:ae(["tool_call","tool_result"]),excerpt:w().max(240)}).strict();const Xa=e=>e.kind==="agent"&&e.removed_ts===void 0,Zm=e=>Xa(e)&&e.state!=="dead";function Fm(e){if(e.latestFinalizedAgentId!==void 0){const n=e.members.find(r=>r.id===e.latestFinalizedAgentId&&Xa(r));if(n)return n}const t=e.members.filter(Zm);if(e.startingAgentHandle!==void 0){const n=t.find(r=>r.handle===e.startingAgentHandle);if(n)return n}return t.length===1?t[0]:void 0}const Um=ae(["pending","answered","acked","orphaned"]);j({id:w().min(1),room:Te,member_id:se,message_id:ve,native_id:w().min(1),kind:ae(["ask","approval"]),targets:je(se),state:Um,answer:Ft().optional(),answered_by:se.optional(),answered_ts:xe.optional()});const qm=ae(["queued","delivering","consumed","held"]),is=j({id:w().min(1),room:Te,message_id:ve,recipient:se,state:qm,hop_count:F().int().nonnegative().optional(),attempt_count:F().int().nonnegative().default(0),batch_id:w().min(1).optional(),run_msg_id:ve.optional(),read_ts:xe.optional(),interaction_resolved_ts:xe.optional(),group_id:w().min(1).optional(),group_round:F().int().positive().optional(),ts:xe}).superRefine((e,t)=>{e.group_id===void 0!=(e.group_round===void 0)&&t.addIssue({code:"custom",path:[e.group_id===void 0?"group_id":"group_round"],message:"group_id and group_round must be provided together"})}),Bm=ae(["message","member","inbox","meter","room"]);j({room:Te,seq:st,entity:Bm,entity_id:w().min(1)});const Hm=j({turn_brake:F().int().positive().nullable().default(null),spend_brake_usd:F().positive().nullable().default(null),stall_minutes:F().int().positive().default(30),redaction_enabled:Me().default(!0),color:w().min(1).optional(),cwd:w().min(1).optional(),starting_agent_handle:Mt.optional(),bridged:Me().default(!1)}),Gi=j({id:Te,name:w().min(1),created_ts:xe,config:Hm.prefault({})}),Wm=j({id:F().int().positive(),ts:xe,kind:Is,author_handle:w(),author_kind:As,preview:w().max(140)}),Vm=j({id:Te,name:w().min(1),created_ts:xe,color:w().min(1).optional(),working:Me(),attention:Me(),latest:Wm.optional(),unread:F().int().nonnegative()}),Gm=j({delivery:is,author_id:se,author_handle:w(),author_kind:As,message_kind:Is,preview:w().max(140),ts:xe}),Jm=j({room:Te,summary:Vm,latest_finalized_agent_id:se.optional(),active_runs:je(hr),interactions:je(hr),inbox:je(Gm)}),Ym=j({harness:w().min(1),handle:Mt,display_name:w().min(1).optional(),model:w().optional(),thinking:dr.optional(),policy:Sr.optional()});j({id:Te.optional(),name:w().min(1),owner:j({handle:Mt,display_name:w()}),color:w().min(1).optional(),cwd:w().min(1).optional(),starting_agent:Ym.optional()});const Km=j({room:Te,day:Za(),turns:F().int().nonnegative(),cost_usd:F().nonnegative(),estimated_cost_usd:F().nonnegative().optional(),input_tokens:F().int().nonnegative(),output_tokens:F().int().nonnegative(),uncosted_tokens:F().int().nonnegative().optional()}),Xm=ae(["tool_call","tool_result","reasoning_summary","text_delta","commit","file_change"]),Qa=j({path:w().min(1),unified:w()}).loose(),Qm=j({media_type:w().min(1),data_b64:w()}).loose(),ep=j({call_id:w().min(1),tool:w().min(1),title:w().min(1),detail:w().optional(),input:Ft().optional()}).loose(),tp=j({call_id:w().min(1),status:ae(["ok","error"]),output_text:w().optional(),diff:Qa.optional(),image:Qm.optional(),duration_ms:F().nonnegative().optional(),raw:Ft().optional()}).loose(),np=j({text:w()}).loose(),rp=j({text:w()}).loose(),sp=j({path:w().min(1),change:ae(["created","modified","deleted"]),diff:Qa.optional()}).loose(),ip=j({sha:w().optional(),message:w().optional()}).loose(),op={tool_call:ep,tool_result:tp,reasoning_summary:rp,text_delta:np,commit:ip,file_change:sp};function Kt(e,t){return op[e].safeParse(t)}const Wr=w().min(1),ap=j({type:O("compaction"),status:ae(["loading","completed"]),trigger:ae(["auto","manual"]).optional(),preTokens:F().nonnegative().optional()}).loose(),cp=wr("type",[j({type:O("run.started"),member:se,trigger_msg:ve}),j({type:O("run.item"),item_type:Xm,payload:Ft(),output_message_id:ve.optional(),ts:xe.optional()}),j({type:O("ask.raised"),card:ss}),j({type:O("approval.raised"),card:ss}),j({type:O("timeline"),item:ap,output_message_id:ve.optional()}),j({type:O("usage_updated"),usage:rs}),j({type:O("run.completed"),status:Ka.exclude(["running"]),final_text:w().optional(),output_message_id:ve.optional(),error:w().min(1).optional(),usage:Ya.optional(),agent_usage:rs.optional()}),j({type:O("run.limits"),limits:je(Ja).min(1)}),j({type:O("member.state"),member:se,state:zs}),j({type:O("extension.started"),parent:Wr,ext_member:Wr,description:w().min(1).optional(),agent_type:w().min(1).optional(),transcript_path:w().min(1).optional()}),j({type:O("extension.ended"),ext_member:Wr,summary:w().optional(),transcript_path:w().min(1).optional()})]),sr=2,lp=j({type:O("subscribe"),room:Te,since_seq:st,hydrate_limit:F().int().positive().optional(),room_addressed:O(!0).optional(),browser_protocol:F().int().positive().optional(),client_kind:O("browser").optional()}),up=j({type:O("post"),room:Te,body:w(),reply_to:ve.optional(),attachments:je(w().min(1)).max(8).optional(),awaiting_reply:Me().optional()}),dp=j({type:O("list_rooms")}),hp=wr("act",[j({act:O("answer_interaction"),interaction_id:w().min(1),answer:Ft()}),j({act:O("redeliver"),delivery_id:w().min(1)}),j({act:O("release_hold"),delivery_id:w().min(1)}),j({act:O("mark_read"),delivery_id:w().min(1)}),j({act:O("mark_room_read"),through_seq:st}),j({act:O("join"),harness:w().min(1),handle:Mt,session_ref:w().min(1),cwd:w().min(1),policy:w().optional(),purpose:w().optional()}),j({act:O("adopt"),member_id:se}),j({act:O("attach_acquire"),member_id:se,cli_pid:F().int().positive()}),j({act:O("attach_child"),lease_id:w().min(1),child_pid:F().int().positive(),process_group_id:F().int().positive()}),j({act:O("attach_heartbeat"),lease_id:w().min(1)}),j({act:O("attach_complete"),lease_id:w().min(1)}),j({act:O("configure_room"),turn_brake:F().int().positive().nullable().optional(),spend_brake_usd:F().positive().nullable().optional(),stall_minutes:F().int().positive().optional()}),j({act:O("spawn"),harness:w().min(1),handle:Mt,cwd:w().min(1),model:w().optional(),policy:w().optional(),thinking:dr.optional(),purpose:w().optional()}),j({act:O("rename"),member_id:se,handle:Mt,display_name:w().optional()}),j({act:O("revive"),member_id:se}),j({act:O("kill"),member_id:se}),j({act:O("remove"),member_id:se}),j({act:O("pause"),member_id:se}),j({act:O("unpause"),member_id:se}),j({act:O("interrupt"),member_id:se}),j({act:O("compact_member"),member_id:se}),j({act:O("consume_delivery"),delivery_id:w().uuid()}),j({act:O("wait_begin"),reason:ae(["reply","mention","any"]),peers:je(se).min(1),until_ts:xe}),j({act:O("wait_end")}),j({act:O("configure"),member_id:se,model:w().min(1).nullable().optional(),thinking:dr.nullable().optional(),policy:Sr.optional()}),j({act:O("set_role"),member_id:se,role:ae(["owner","admin","member","observer"])}),j({act:O("pin_message"),message_id:ve,pinned:Me()}),j({act:O("delete_message"),message_id:ve}),j({act:O("retry_run"),message_id:ve})]),fp=j({type:O("act"),room:Te,act:hp}),mp=j({type:O("mirror_turn"),harness:w().min(1),session_ref:w().min(1),native_turn_id:w().min(1),body:w(),transcript_path:w().optional()}),pp=j({type:O("mirror_session_end"),harness:w().min(1),session_ref:w().min(1)});wr("type",[dp,lp,up,fp,mp,pp]);const gp=j({id:w().min(1),room:Te,member_id:se,cli_pid:F().int().positive(),child_pid:F().int().positive().optional(),process_group_id:F().int().positive().optional(),heartbeat_ts:F().int().nonnegative()});wr("type",[j({type:O("upgrade_required"),minimum_browser_protocol:F().int().positive(),current_browser_protocol:F().int().positive()}),j({type:O("rooms"),rooms:je(Gi)}),j({type:O("self"),member_id:se,room:Te.optional()}),j({type:O("attach_lease"),status:ae(["acquired","child_recorded","completed","uncertain"]),lease:gp.optional(),member:Vi}),j({type:O("mirror_ack"),native_turn_id:w().optional(),message_id:ve.optional(),deduped:Me().optional(),adopted:Me().optional()}),j({type:O("message"),seq:st,message:hr}),j({type:O("member"),seq:st,member:Vi,room:Te.optional()}),j({type:O("inbox"),seq:st,delivery:is}),j({type:O("consume_result"),delivery:is,message:hr}),j({type:O("meter"),seq:st,meter:Km}),j({type:O("room"),seq:st,room:Gi}),j({type:O("room_support"),seq:st,support:Jm}),j({type:O("sync_complete"),seq:st,room:Te.optional(),history_floor:ve.optional()}),j({type:O("run_event"),room:Te,message_id:ve,event:cp,index:F().int().nonnegative().optional()}),j({type:O("error"),message:w(),ref:w().optional()})]);const Ji=e=>{let t;const n=new Set,r=(d,u)=>{const h=typeof d=="function"?d(t):d;if(!Object.is(h,t)){const m=t;t=u??(typeof h!="object"||h===null)?h:Object.assign({},t,h),n.forEach(p=>p(t,m))}},s=()=>t,c={setState:r,getState:s,getInitialState:()=>l,subscribe:d=>(n.add(d),()=>n.delete(d))},l=t=e(r,s,c);return c},xp=(e=>e?Ji(e):Ji),bp=e=>e;function _p(e,t=bp){const n=Gn.useSyncExternalStore(e.subscribe,Gn.useCallback(()=>t(e.getState()),[e,t]),Gn.useCallback(()=>t(e.getInitialState()),[e,t]));return Gn.useDebugValue(n),n}const Yi=e=>{const t=xp(e),n=r=>_p(t,r);return Object.assign(n,t),n},ec=(e=>e?Yi(e):Yi),Ki=20,vp=500;let rt;const yp=()=>({members:{},messages:{},inbox:{}});function kp(){rt=void 0}function tc(e,t,n){let r=e??{events:[],dropped_count:0};if(n!==void 0){if(r.events.length===0)r={...r,first_index:n};else if(r.first_index!==void 0){const a=r.first_index+r.events.length;if(n<a)return r;n>a&&(r={...r,events:[],first_index:n})}}const s=[...r.events,t],i=Math.max(0,s.length-vp);return{events:i===0?s:s.slice(i),dropped_count:r.dropped_count+i,...r.first_index!==void 0&&{first_index:r.first_index+i}}}ec((e,t)=>({connected:!1,hydrated:!1,selfMemberId:void 0,room:void 0,seq:0,members:{},memberHistory:{},messages:{},inbox:{},meter:void 0,runEvents:{},latestFinalizedAgentId:void 0,historyCursor:void 0,errors:[],applyFrame:n=>{if(t().seq===0){if(n.type==="self"){rt=yp(),rt.selfMemberId=n.member_id;return}if(rt!==void 0)switch(n.type){case"room":rt.room=n.room;return;case"member":rt.members[n.member.id]=n.member;return;case"message":rt.messages[n.message.id]=n.message;return;case"inbox":rt.inbox[n.delivery.id]=n.delivery;return;case"meter":rt.meter=n.meter;return}}e(r=>{var i,a,c,l,d;const s="seq"in n?Math.max(r.seq,n.seq):r.seq;switch(n.type){case"self":return{selfMemberId:n.member_id};case"room":return{seq:s,room:n.room};case"sync_complete":{if(r.seq!==0)return{seq:s};const u=rt;rt=void 0;const h={...r.members,...u==null?void 0:u.members},m={...r.memberHistory};for(const E of Object.values((u==null?void 0:u.members)??{})){const L=E.state??"idle",J=m[E.id]??[];((i=J.at(-1))==null?void 0:i.state)!==L&&(m[E.id]=[...J,{state:L,ts:new Date().toISOString()}].slice(-12))}const p={...r.messages,...u==null?void 0:u.messages},g={...r.inbox,...u==null?void 0:u.inbox};let _=r.latestFinalizedAgentId;for(const E of Object.values(p).sort((L,J)=>L.id-J.id))E.kind==="run"&&E.run!==void 0&&E.run.status!=="running"&&E.ack!==!0&&((a=h[E.author])==null?void 0:a.kind)==="agent"&&(_=E.author);const S={seq:s,hydrated:!0,members:h,memberHistory:m,inbox:g,latestFinalizedAgentId:_,...(u==null?void 0:u.selfMemberId)!==void 0&&{selfMemberId:u.selfMemberId},...(u==null?void 0:u.room)!==void 0&&{room:u.room},...(u==null?void 0:u.meter)!==void 0&&{meter:u.meter}};if(n.history_floor!==void 0)return{...S,messages:p,historyCursor:n.history_floor};const C=Object.values(p).sort((E,L)=>E.id-L.id);if(C.length<=Ki)return{...S,messages:p,historyCursor:(c=C[0])==null?void 0:c.id};const A=new Set;for(const E of Object.values(p))E.reply_to!==void 0&&A.add(E.reply_to);const $=E=>(E.kind==="ask"||E.kind==="approval")&&E.ask!==void 0&&(E.kind==="approval"?Object.values(g).some(L=>L.message_id===E.id&&L.state==="consumed"&&L.interaction_resolved_ts===void 0):!A.has(E.id)),I=C.slice(-Ki),z=new Map(I.map(E=>[E.id,E]));for(const E of C)$(E)&&z.set(E.id,E);const k=[...z.values()].sort((E,L)=>E.id-L.id);return{...S,messages:Object.fromEntries(k.map(E=>[E.id,E])),historyCursor:(l=I[0])==null?void 0:l.id}}case"member":{const u=n.member.state??"idle",h=r.memberHistory[n.member.id]??[],m=h.at(-1),p=(m==null?void 0:m.state)===u?h:[...h,{state:u,ts:new Date().toISOString()}].slice(-12);return{seq:s,members:{...r.members,[n.member.id]:n.member},memberHistory:{...r.memberHistory,[n.member.id]:p}}}case"message":{const u=n.message.kind==="run"&&n.message.run!==void 0&&n.message.run.status!=="running"&&n.message.ack!==!0&&((d=r.members[n.message.author])==null?void 0:d.kind)==="agent";return{seq:s,messages:{...r.messages,[n.message.id]:n.message},...u&&{latestFinalizedAgentId:n.message.author}}}case"inbox":return{seq:s,inbox:{...r.inbox,[n.delivery.id]:n.delivery}};case"meter":return{seq:s,meter:n.meter};case"run_event":return{runEvents:{...r.runEvents,[n.message_id]:tc(r.runEvents[n.message_id],n.event,n.index)}};case"error":return{errors:[...r.errors,n.message]};default:return{}}})},mergeHistoryPage:n=>e(r=>{const s=n.reduce((i,a)=>i===void 0?a.id:Math.min(i,a.id),void 0);return{messages:{...r.messages,...Object.fromEntries(n.map(i=>[i.id,i]))},...s!==void 0&&{historyCursor:r.historyCursor===void 0?s:Math.min(r.historyCursor,s)}}}),setConnected:n=>e({connected:n}),reset:()=>{kp(),e({hydrated:!1,room:void 0,selfMemberId:void 0,seq:0,members:{},memberHistory:{},messages:{},inbox:{},meter:void 0,runEvents:{},latestFinalizedAgentId:void 0,historyCursor:void 0,errors:[]})}}));const Ln=20,wp={},Sp={},jp={},Np={},Tp={},Ep=[],nc={hydrated:!1,selfMemberId:void 0,room:void 0,seq:0,members:wp,memberHistory:Tp,messages:Sp,inbox:jp,meter:void 0,runEvents:Np,support:void 0,historyCursor:void 0,errors:Ep},Qn=e=>({hydrated:!1,selfMemberId:void 0,room:e,seq:0,members:{},memberHistory:{},messages:{},inbox:{},meter:void 0,runEvents:{},support:void 0,historyCursor:void 0,errors:[]}),yn=new Map,$p=()=>({members:{},messages:{},inbox:{}});function Rp(e,t){switch(e.type){case"self":case"member":case"sync_complete":return e.room??t;case"message":return e.message.room;case"inbox":return e.delivery.room;case"consume_result":return e.message.room;case"meter":return e.meter.room;case"room":return e.room.id;case"room_support":return e.support.room;case"run_event":return e.room;default:return t}}function Xi(e,t){var s;const n=t.state??"idle",r=e[t.id]??[];return((s=r.at(-1))==null?void 0:s.state)===n?e:{...e,[t.id]:[...r,{state:n,ts:new Date().toISOString()}].slice(-12)}}function Cp(e,t){const n={...e,[t.id]:t},r=Object.values(n).sort((s,i)=>s.id-i.id);return r.length<=Ln?n:Object.fromEntries(r.slice(-Ln).map(s=>[s.id,s]))}const H=ec((e,t)=>({connected:!1,activeRoom:"",rooms:{},roomList:[],applyFrame:(n,r)=>{if(n.type==="rooms"){e(c=>{const l={...c.rooms};for(const d of n.rooms)l[d.id]=l[d.id]===void 0?Qn(d):{...l[d.id],room:d};return{roomList:n.rooms,rooms:l}});return}const s=Rp(n,r);if(s===void 0)return;const i=t().rooms[s]??nc;if(n.type==="self"&&!i.hydrated){const c=$p();c.selfMemberId=n.member_id,yn.set(s,c);return}const a=yn.get(s);if(a!==void 0)switch(n.type){case"room":a.room=n.room;return;case"member":a.members[n.member.id]=n.member;return;case"message":a.messages[n.message.id]=n.message;return;case"inbox":a.inbox[n.delivery.id]=n.delivery;return;case"meter":a.meter=n.meter;return;case"room_support":a.support=n.support;return}e(c=>{var h,m;const l=c.rooms[s]??Qn(),d="seq"in n?Math.max(l.seq,n.seq):l.seq;let u=l;switch(n.type){case"self":u={...l,selfMemberId:n.member_id};break;case"room":u={...l,seq:d,room:n.room};break;case"sync_complete":{const p=yn.get(s);if(yn.delete(s),p===void 0){u={...l,seq:d,hydrated:!0};break}const g={...p.members,...l.members},_={...p.messages,...l.messages},S={...p.inbox,...l.inbox};let C=l.memberHistory;for(const A of Object.values(g))C=Xi(C,A);u={...l,hydrated:!0,seq:d,selfMemberId:p.selfMemberId,room:p.room??l.room,members:g,memberHistory:C,messages:_,inbox:S,meter:l.meter??p.meter,support:l.support??p.support,historyCursor:n.history_floor??((h=Object.values(_).sort((A,$)=>A.id-$.id)[0])==null?void 0:h.id)};break}case"member":u={...l,seq:d,members:{...l.members,[n.member.id]:n.member},memberHistory:Xi(l.memberHistory,n.member)};break;case"message":{const p=c.activeRoom===s?{...l.messages,[n.message.id]:n.message}:Cp(l.messages,n.message);u={...l,seq:d,messages:p,...c.activeRoom!==s&&{historyCursor:(m=Object.values(p).sort((g,_)=>g.id-_.id)[0])==null?void 0:m.id}};break}case"inbox":u={...l,seq:d,inbox:{...l.inbox,[n.delivery.id]:n.delivery}};break;case"consume_result":u={...l,messages:{...l.messages,[n.message.id]:n.message},inbox:{...l.inbox,[n.delivery.id]:n.delivery}};break;case"meter":u={...l,seq:d,meter:n.meter};break;case"room_support":u={...l,seq:d,support:n.support};break;case"run_event":if(c.activeRoom!==s)return{};u={...l,runEvents:{...l.runEvents,[n.message_id]:tc(l.runEvents[n.message_id],n.event,n.index)}};break;case"error":u={...l,errors:[...l.errors,n.message]};break;default:return{}}return{rooms:{...c.rooms,[s]:u}}})},mergeHistoryPage:(n,r)=>{e(s=>{const i=s.rooms[n]??Qn(),a=r.reduce((c,l)=>c===void 0?l.id:Math.min(c,l.id),void 0);return{rooms:{...s.rooms,[n]:{...i,messages:{...i.messages,...Object.fromEntries(r.map(c=>[c.id,c]))},...a!==void 0&&{historyCursor:i.historyCursor===void 0?a:Math.min(i.historyCursor,a)}}}}})},setActiveRoom:n=>{e(r=>{if(r.activeRoom===n)return{};const s={...r.rooms},i=s[r.activeRoom];return i!==void 0&&Object.keys(i.runEvents).length>0&&(s[r.activeRoom]={...i,runEvents:{}}),s[n]===void 0&&(s[n]=Qn()),{activeRoom:n,rooms:s}})},setConnected:n=>e({connected:n}),reset:()=>{yn.clear(),e({connected:!1,activeRoom:"",rooms:{},roomList:[]})}})),ie=(e,t)=>e.rooms[t]??nc,Ap=e=>Object.values(e).sort((t,n)=>t.id-n.id),zp=(e,t)=>t!==void 0?e[t]:Object.values(e).find(n=>n.kind==="human"&&n.role==="owner"),Ip=e=>Object.values(e).filter(t=>t.state==="held"),Lp=e=>{var t,n;return Fm({members:Object.values(e.members),latestFinalizedAgentId:(t=e.support)==null?void 0:t.latest_finalized_agent_id,startingAgentHandle:(n=e.room)==null?void 0:n.config.starting_agent_handle})};function rc(){const t=new URLSearchParams(window.location.search).get("room");return t===null||t===""?{}:{room:t}}async function os(){const e=new URL(window.location.href),t=e.searchParams.get("token")??"";if(t!==""){try{await oa({origin:window.location.origin,authority:"operator",token:t}),e.searchParams.delete("token"),window.history.replaceState(null,"",`${e.pathname}${e.search}${e.hash}`)}catch{}return $n(t)}try{return $n(await Ml(window.location.origin))}catch{return $n("")}}const Op=e=>x.useCallback(()=>Ol(e),[e]);function Pp(){return H(e=>e.connected)}function sc(e){const[t,n]=x.useState([]),[r,s]=x.useState(!1),[i,a]=x.useState(),c=x.useRef(!0),l=x.useRef(),d=x.useRef(10),u=x.useCallback(m=>{c.current&&(n(m.adapters),!(!m.discovering||d.current<=0)&&(d.current-=1,l.current!==void 0&&clearTimeout(l.current),l.current=setTimeout(()=>{wi({token:e()}).then(u).catch(()=>{})},500)))},[e]);x.useEffect(()=>(c.current=!0,d.current=10,wi({token:e()}).then(u).catch(()=>{}),()=>{c.current=!1,l.current!==void 0&&clearTimeout(l.current)}),[u,e]);const h=x.useCallback(()=>{r||(s(!0),a(void 0),d.current=10,ql({token:e()}).then(m=>u(m),m=>{c.current&&a(m instanceof Error?m.message:String(m))}).finally(()=>{c.current&&s(!1)}))},[u,r,e]);return{registered:t,installed:t.filter(m=>m.installed!==!1),refreshing:r,...i!==void 0&&{refreshError:i},refresh:h}}function Mp(e,t){const n=Pp(),[r,s]=x.useState({});return x.useEffect(()=>{if(!n)return;let i=!0;return Wl(e,{token:t()}).then(a=>{i&&s(Object.fromEntries(a.map(c=>[c.member.id,c])))}).catch(()=>{}),()=>{i=!1}},[n,e,t]),r}function Nr(){return x.useSyncExternalStore(e=>{const t=window.matchMedia("(max-width: 719px)");return t.addEventListener("change",e),()=>t.removeEventListener("change",e)},()=>window.matchMedia("(max-width: 719px)").matches,()=>!1)}function Dp(){return x.useSyncExternalStore(e=>{const t=setInterval(e,6e4);return()=>clearInterval(t)},()=>Math.floor(Date.now()/6e4),()=>0)}let ir;function Qi(e){ir=e}async function ic(e){const t=await fetch("/api/rooms/summary?read_state=durable",{headers:{authorization:`Bearer ${e}`}});if(!t.ok)throw new Error(`summary failed: ${t.status}`);return(await t.json()).rooms}function Zp(e){const t=H(s=>s.rooms),[n,r]=x.useState(ir??[]);return x.useEffect(()=>{if(ir!==void 0){r(ir);return}let s=!0;return ic(e()).then(i=>{s&&r(i)}).catch(()=>la({token:e()}).then(i=>{s&&r(i.map(a=>({id:a.id,name:a.name,created_ts:a.created_ts,color:a.config.color,working:!1,attention:!1,unread:0})))}).catch(()=>{})),()=>{s=!1}},[e]),x.useMemo(()=>{const s=new Map(n.map(i=>[i.id,i]));for(const i of Object.values(t))i.support!==void 0?s.set(i.support.room,i.support.summary):i.room!==void 0&&!s.has(i.room.id)&&s.set(i.room.id,{id:i.room.id,name:i.room.name,created_ts:i.room.created_ts,color:i.room.config.color,working:!1,attention:!1,unread:0});return[...s.values()]},[n,t])}const Ls="codor:web-next:room";function Fp(e,t){var r;const n=s=>s!==void 0&&e.some(i=>i.id===s)?s:void 0;return n(t.explicit)??n(t.remembered)??((r=Up(e)[0])==null?void 0:r.id)}function Up(e){const t=n=>{var r;return Date.parse(((r=n.latest)==null?void 0:r.ts)??n.created_ts)||0};return[...e].sort((n,r)=>{if(n.working!==r.working)return n.working?-1:1;const s=t(r)-t(n);if(s!==0)return s;const i=(Date.parse(r.created_ts)||0)-(Date.parse(n.created_ts)||0);return i!==0?i:n.id.localeCompare(r.id)})}function er(){try{return window.localStorage.getItem(Ls)??void 0}catch{return}}function fr(e){try{window.localStorage.setItem(Ls,e)}catch{}}function eo(){try{window.localStorage.removeItem(Ls)}catch{}}async function qp(e){try{const t=await ic(e);return Qi(t),t}catch{const n=(await la({token:e})).map(r=>({id:r.id,name:r.name,created_ts:r.created_ts,color:r.config.color,working:!1,attention:!1,unread:0}));return Qi(n),n}}/**
|
|
74
|
+
* @license lucide-react v1.24.0 - ISC
|
|
75
|
+
*
|
|
76
|
+
* This source code is licensed under the ISC license.
|
|
77
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
78
|
+
*/const oc=(...e)=>e.filter((t,n,r)=>!!t&&t.trim()!==""&&r.indexOf(t)===n).join(" ").trim();/**
|
|
79
|
+
* @license lucide-react v1.24.0 - ISC
|
|
80
|
+
*
|
|
81
|
+
* This source code is licensed under the ISC license.
|
|
82
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
83
|
+
*/const Bp=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();/**
|
|
84
|
+
* @license lucide-react v1.24.0 - ISC
|
|
85
|
+
*
|
|
86
|
+
* This source code is licensed under the ISC license.
|
|
87
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
88
|
+
*/const Hp=e=>e.replace(/^([A-Z])|[\s-_]+(\w)/g,(t,n,r)=>r?r.toUpperCase():n.toLowerCase());/**
|
|
89
|
+
* @license lucide-react v1.24.0 - ISC
|
|
90
|
+
*
|
|
91
|
+
* This source code is licensed under the ISC license.
|
|
92
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
93
|
+
*/const to=e=>{const t=Hp(e);return t.charAt(0).toUpperCase()+t.slice(1)};/**
|
|
94
|
+
* @license lucide-react v1.24.0 - ISC
|
|
95
|
+
*
|
|
96
|
+
* This source code is licensed under the ISC license.
|
|
97
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
98
|
+
*/var Vr={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};/**
|
|
99
|
+
* @license lucide-react v1.24.0 - ISC
|
|
100
|
+
*
|
|
101
|
+
* This source code is licensed under the ISC license.
|
|
102
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
103
|
+
*/const Wp=e=>{for(const t in e)if(t.startsWith("aria-")||t==="role"||t==="title")return!0;return!1},Vp=x.createContext({}),Gp=()=>x.useContext(Vp),Jp=x.forwardRef(({color:e,size:t,strokeWidth:n,absoluteStrokeWidth:r,className:s="",children:i,iconNode:a,...c},l)=>{const{size:d=24,strokeWidth:u=2,absoluteStrokeWidth:h=!1,color:m="currentColor",className:p=""}=Gp()??{},g=r??h?Number(n??u)*24/Number(t??d):n??u;return x.createElement("svg",{ref:l,...Vr,width:t??d??Vr.width,height:t??d??Vr.height,stroke:e??m,strokeWidth:g,className:oc("lucide",p,s),...!i&&!Wp(c)&&{"aria-hidden":"true"},...c},[...a.map(([_,S])=>x.createElement(_,S)),...Array.isArray(i)?i:[i]])});/**
|
|
104
|
+
* @license lucide-react v1.24.0 - ISC
|
|
105
|
+
*
|
|
106
|
+
* This source code is licensed under the ISC license.
|
|
107
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
108
|
+
*/const V=(e,t)=>{const n=x.forwardRef(({className:r,...s},i)=>x.createElement(Jp,{ref:i,iconNode:t,className:oc(`lucide-${Bp(to(e))}`,`lucide-${e}`,r),...s}));return n.displayName=to(e),n};/**
|
|
109
|
+
* @license lucide-react v1.24.0 - ISC
|
|
110
|
+
*
|
|
111
|
+
* This source code is licensed under the ISC license.
|
|
112
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
113
|
+
*/const Yp=[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]],Kp=V("arrow-down",Yp);/**
|
|
114
|
+
* @license lucide-react v1.24.0 - ISC
|
|
115
|
+
*
|
|
116
|
+
* This source code is licensed under the ISC license.
|
|
117
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
118
|
+
*/const Xp=[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]],as=V("arrow-up",Xp);/**
|
|
119
|
+
* @license lucide-react v1.24.0 - ISC
|
|
120
|
+
*
|
|
121
|
+
* This source code is licensed under the ISC license.
|
|
122
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
123
|
+
*/const Qp=[["circle",{cx:"12",cy:"12",r:"4",key:"4exip2"}],["path",{d:"M16 8v5a3 3 0 0 0 6 0v-1a10 10 0 1 0-4 8",key:"7n84p3"}]],eg=V("at-sign",Qp);/**
|
|
124
|
+
* @license lucide-react v1.24.0 - ISC
|
|
125
|
+
*
|
|
126
|
+
* This source code is licensed under the ISC license.
|
|
127
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
128
|
+
*/const tg=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M4.929 4.929 19.07 19.071",key:"196cmz"}]],ng=V("ban",tg);/**
|
|
129
|
+
* @license lucide-react v1.24.0 - ISC
|
|
130
|
+
*
|
|
131
|
+
* This source code is licensed under the ISC license.
|
|
132
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
133
|
+
*/const rg=[["path",{d:"M12 8V4H8",key:"hb8ula"}],["rect",{width:"16",height:"12",x:"4",y:"8",rx:"2",key:"enze0r"}],["path",{d:"M2 14h2",key:"vft8re"}],["path",{d:"M20 14h2",key:"4cs60a"}],["path",{d:"M15 13v2",key:"1xurst"}],["path",{d:"M9 13v2",key:"rq6x2g"}]],tn=V("bot",rg);/**
|
|
134
|
+
* @license lucide-react v1.24.0 - ISC
|
|
135
|
+
*
|
|
136
|
+
* This source code is licensed under the ISC license.
|
|
137
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
138
|
+
*/const sg=[["path",{d:"M12 5c.67 0 1.35.09 2 .26 1.78-2 5.03-2.84 6.42-2.26 1.4.58-.42 7-.42 7 .57 1.07 1 2.24 1 3.44C21 17.9 16.97 21 12 21s-9-3-9-7.56c0-1.25.5-2.4 1-3.44 0 0-1.89-6.42-.5-7 1.39-.58 4.72.23 6.5 2.23A9.04 9.04 0 0 1 12 5Z",key:"x6xyqk"}],["path",{d:"M8 14v.5",key:"1nzgdb"}],["path",{d:"M16 14v.5",key:"1lajdz"}],["path",{d:"M11.25 16.25h1.5L12 17l-.75-.75Z",key:"12kq1m"}]],ig=V("cat",sg);/**
|
|
139
|
+
* @license lucide-react v1.24.0 - ISC
|
|
140
|
+
*
|
|
141
|
+
* This source code is licensed under the ISC license.
|
|
142
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
143
|
+
*/const og=[["path",{d:"M18 6 7 17l-5-5",key:"116fxf"}],["path",{d:"m22 10-7.5 7.5L13 16",key:"ke71qq"}]],ag=V("check-check",og);/**
|
|
144
|
+
* @license lucide-react v1.24.0 - ISC
|
|
145
|
+
*
|
|
146
|
+
* This source code is licensed under the ISC license.
|
|
147
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
148
|
+
*/const cg=[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]],Os=V("check",cg);/**
|
|
149
|
+
* @license lucide-react v1.24.0 - ISC
|
|
150
|
+
*
|
|
151
|
+
* This source code is licensed under the ISC license.
|
|
152
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
153
|
+
*/const lg=[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]],ug=V("chevron-left",lg);/**
|
|
154
|
+
* @license lucide-react v1.24.0 - ISC
|
|
155
|
+
*
|
|
156
|
+
* This source code is licensed under the ISC license.
|
|
157
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
158
|
+
*/const dg=[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]],ac=V("chevron-right",dg);/**
|
|
159
|
+
* @license lucide-react v1.24.0 - ISC
|
|
160
|
+
*
|
|
161
|
+
* This source code is licensed under the ISC license.
|
|
162
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
163
|
+
*/const hg=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"10",x2:"10",y1:"15",y2:"9",key:"c1nkhi"}],["line",{x1:"14",x2:"14",y1:"15",y2:"9",key:"h65svq"}]],fg=V("circle-pause",hg);/**
|
|
164
|
+
* @license lucide-react v1.24.0 - ISC
|
|
165
|
+
*
|
|
166
|
+
* This source code is licensed under the ISC license.
|
|
167
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
168
|
+
*/const mg=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 6v6h4",key:"135r8i"}]],pg=V("clock-3",mg);/**
|
|
169
|
+
* @license lucide-react v1.24.0 - ISC
|
|
170
|
+
*
|
|
171
|
+
* This source code is licensed under the ISC license.
|
|
172
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
173
|
+
*/const gg=[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]],xg=V("copy",gg);/**
|
|
174
|
+
* @license lucide-react v1.24.0 - ISC
|
|
175
|
+
*
|
|
176
|
+
* This source code is licensed under the ISC license.
|
|
177
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
178
|
+
*/const bg=[["path",{d:"M14 9 9 4 4 9",key:"1af5af"}],["path",{d:"M20 20h-7a4 4 0 0 1-4-4V4",key:"1blwi3"}]],_g=V("corner-left-up",bg);/**
|
|
179
|
+
* @license lucide-react v1.24.0 - ISC
|
|
180
|
+
*
|
|
181
|
+
* This source code is licensed under the ISC license.
|
|
182
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
183
|
+
*/const vg=[["path",{d:"M12 20v2",key:"1lh1kg"}],["path",{d:"M12 2v2",key:"tus03m"}],["path",{d:"M17 20v2",key:"1rnc9c"}],["path",{d:"M17 2v2",key:"11trls"}],["path",{d:"M2 12h2",key:"1t8f8n"}],["path",{d:"M2 17h2",key:"7oei6x"}],["path",{d:"M2 7h2",key:"asdhe0"}],["path",{d:"M20 12h2",key:"1q8mjw"}],["path",{d:"M20 17h2",key:"1fpfkl"}],["path",{d:"M20 7h2",key:"1o8tra"}],["path",{d:"M7 20v2",key:"4gnj0m"}],["path",{d:"M7 2v2",key:"1i4yhu"}],["rect",{x:"4",y:"4",width:"16",height:"16",rx:"2",key:"1vbyd7"}],["rect",{x:"8",y:"8",width:"8",height:"8",rx:"1",key:"z9xiuo"}]],yg=V("cpu",vg);/**
|
|
184
|
+
* @license lucide-react v1.24.0 - ISC
|
|
185
|
+
*
|
|
186
|
+
* This source code is licensed under the ISC license.
|
|
187
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
188
|
+
*/const kg=[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"12",cy:"5",r:"1",key:"gxeob9"}],["circle",{cx:"12",cy:"19",r:"1",key:"lyex9k"}]],cc=V("ellipsis-vertical",kg);/**
|
|
189
|
+
* @license lucide-react v1.24.0 - ISC
|
|
190
|
+
*
|
|
191
|
+
* This source code is licensed under the ISC license.
|
|
192
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
193
|
+
*/const wg=[["path",{d:"M12 10v6",key:"1bos4e"}],["path",{d:"M9 13h6",key:"1uhe8q"}],["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]],Sg=V("folder-plus",wg);/**
|
|
194
|
+
* @license lucide-react v1.24.0 - ISC
|
|
195
|
+
*
|
|
196
|
+
* This source code is licensed under the ISC license.
|
|
197
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
198
|
+
*/const jg=[["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]],Ng=V("folder",jg);/**
|
|
199
|
+
* @license lucide-react v1.24.0 - ISC
|
|
200
|
+
*
|
|
201
|
+
* This source code is licensed under the ISC license.
|
|
202
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
203
|
+
*/const Tg=[["path",{d:"m12 14 4-4",key:"9kzdfg"}],["path",{d:"M3.34 19a10 10 0 1 1 17.32 0",key:"19p75a"}]],Eg=V("gauge",Tg);/**
|
|
204
|
+
* @license lucide-react v1.24.0 - ISC
|
|
205
|
+
*
|
|
206
|
+
* This source code is licensed under the ISC license.
|
|
207
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
208
|
+
*/const $g=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20",key:"13o1zl"}],["path",{d:"M2 12h20",key:"9i4pu4"}]],Rg=V("globe",$g);/**
|
|
209
|
+
* @license lucide-react v1.24.0 - ISC
|
|
210
|
+
*
|
|
211
|
+
* This source code is licensed under the ISC license.
|
|
212
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
213
|
+
*/const Cg=[["polyline",{points:"22 12 16 12 14 15 10 15 8 12 2 12",key:"o97t9d"}],["path",{d:"M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z",key:"oot6mr"}]],Ag=V("inbox",Cg);/**
|
|
214
|
+
* @license lucide-react v1.24.0 - ISC
|
|
215
|
+
*
|
|
216
|
+
* This source code is licensed under the ISC license.
|
|
217
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
218
|
+
*/const zg=[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]],fn=V("loader-circle",zg);/**
|
|
219
|
+
* @license lucide-react v1.24.0 - ISC
|
|
220
|
+
*
|
|
221
|
+
* This source code is licensed under the ISC license.
|
|
222
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
223
|
+
*/const Ig=[["rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2",key:"1w4ew1"}],["path",{d:"M7 11V7a5 5 0 0 1 10 0v4",key:"fwvmzm"}]],lc=V("lock",Ig);/**
|
|
224
|
+
* @license lucide-react v1.24.0 - ISC
|
|
225
|
+
*
|
|
226
|
+
* This source code is licensed under the ISC license.
|
|
227
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
228
|
+
*/const Lg=[["path",{d:"m14 10 7-7",key:"oa77jy"}],["path",{d:"M20 10h-6V4",key:"mjg0md"}],["path",{d:"m3 21 7-7",key:"tjx5ai"}],["path",{d:"M4 14h6v6",key:"rmj7iw"}]],Og=V("minimize-2",Lg);/**
|
|
229
|
+
* @license lucide-react v1.24.0 - ISC
|
|
230
|
+
*
|
|
231
|
+
* This source code is licensed under the ISC license.
|
|
232
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
233
|
+
*/const Pg=[["rect",{width:"20",height:"14",x:"2",y:"3",rx:"2",key:"48i651"}],["line",{x1:"8",x2:"16",y1:"21",y2:"21",key:"1svkeh"}],["line",{x1:"12",x2:"12",y1:"17",y2:"21",key:"vw1qmm"}]],Mg=V("monitor",Pg);/**
|
|
234
|
+
* @license lucide-react v1.24.0 - ISC
|
|
235
|
+
*
|
|
236
|
+
* This source code is licensed under the ISC license.
|
|
237
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
238
|
+
*/const Dg=[["path",{d:"m16 6-8.414 8.586a2 2 0 0 0 2.829 2.829l8.414-8.586a4 4 0 1 0-5.657-5.657l-8.379 8.551a6 6 0 1 0 8.485 8.485l8.379-8.551",key:"1miecu"}]],cs=V("paperclip",Dg);/**
|
|
239
|
+
* @license lucide-react v1.24.0 - ISC
|
|
240
|
+
*
|
|
241
|
+
* This source code is licensed under the ISC license.
|
|
242
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
243
|
+
*/const Zg=[["path",{d:"M13 21h8",key:"1jsn5i"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}],["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}]],Fg=V("pencil-line",Zg);/**
|
|
244
|
+
* @license lucide-react v1.24.0 - ISC
|
|
245
|
+
*
|
|
246
|
+
* This source code is licensed under the ISC license.
|
|
247
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
248
|
+
*/const Ug=[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]],qg=V("pencil",Ug);/**
|
|
249
|
+
* @license lucide-react v1.24.0 - ISC
|
|
250
|
+
*
|
|
251
|
+
* This source code is licensed under the ISC license.
|
|
252
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
253
|
+
*/const Bg=[["path",{d:"M12 17v5",key:"bb1du9"}],["path",{d:"M15 9.34V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H7.89",key:"znwnzq"}],["path",{d:"m2 2 20 20",key:"1ooewy"}],["path",{d:"M9 9v1.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h11",key:"c9qhm2"}]],uc=V("pin-off",Bg);/**
|
|
254
|
+
* @license lucide-react v1.24.0 - ISC
|
|
255
|
+
*
|
|
256
|
+
* This source code is licensed under the ISC license.
|
|
257
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
258
|
+
*/const Hg=[["path",{d:"M12 17v5",key:"bb1du9"}],["path",{d:"M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z",key:"1nkz8b"}]],On=V("pin",Hg);/**
|
|
259
|
+
* @license lucide-react v1.24.0 - ISC
|
|
260
|
+
*
|
|
261
|
+
* This source code is licensed under the ISC license.
|
|
262
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
263
|
+
*/const Wg=[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]],dc=V("plus",Wg);/**
|
|
264
|
+
* @license lucide-react v1.24.0 - ISC
|
|
265
|
+
*
|
|
266
|
+
* This source code is licensed under the ISC license.
|
|
267
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
268
|
+
*/const Vg=[["path",{d:"M16 3a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2 1 1 0 0 1 1 1v1a2 2 0 0 1-2 2 1 1 0 0 0-1 1v2a1 1 0 0 0 1 1 6 6 0 0 0 6-6V5a2 2 0 0 0-2-2z",key:"rib7q0"}],["path",{d:"M5 3a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2 1 1 0 0 1 1 1v1a2 2 0 0 1-2 2 1 1 0 0 0-1 1v2a1 1 0 0 0 1 1 6 6 0 0 0 6-6V5a2 2 0 0 0-2-2z",key:"1ymkrd"}]],hc=V("quote",Vg);/**
|
|
269
|
+
* @license lucide-react v1.24.0 - ISC
|
|
270
|
+
*
|
|
271
|
+
* This source code is licensed under the ISC license.
|
|
272
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
273
|
+
*/const Gg=[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]],ls=V("refresh-cw",Gg);/**
|
|
274
|
+
* @license lucide-react v1.24.0 - ISC
|
|
275
|
+
*
|
|
276
|
+
* This source code is licensed under the ISC license.
|
|
277
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
278
|
+
*/const Jg=[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}]],fc=V("rotate-ccw",Jg);/**
|
|
279
|
+
* @license lucide-react v1.24.0 - ISC
|
|
280
|
+
*
|
|
281
|
+
* This source code is licensed under the ISC license.
|
|
282
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
283
|
+
*/const Yg=[["path",{d:"M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8",key:"1p45f6"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}]],Kg=V("rotate-cw",Yg);/**
|
|
284
|
+
* @license lucide-react v1.24.0 - ISC
|
|
285
|
+
*
|
|
286
|
+
* This source code is licensed under the ISC license.
|
|
287
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
288
|
+
*/const Xg=[["circle",{cx:"6",cy:"6",r:"3",key:"1lh9wr"}],["path",{d:"M8.12 8.12 12 12",key:"1alkpv"}],["path",{d:"M20 4 8.12 15.88",key:"xgtan2"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}],["path",{d:"M14.8 14.8 20 20",key:"ptml3r"}]],Qg=V("scissors",Xg);/**
|
|
289
|
+
* @license lucide-react v1.24.0 - ISC
|
|
290
|
+
*
|
|
291
|
+
* This source code is licensed under the ISC license.
|
|
292
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
293
|
+
*/const ex=[["path",{d:"m21 21-4.34-4.34",key:"14j7rj"}],["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}]],Tr=V("search",ex);/**
|
|
294
|
+
* @license lucide-react v1.24.0 - ISC
|
|
295
|
+
*
|
|
296
|
+
* This source code is licensed under the ISC license.
|
|
297
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
298
|
+
*/const tx=[["path",{d:"M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915",key:"1i5ecw"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]],mc=V("settings",tx);/**
|
|
299
|
+
* @license lucide-react v1.24.0 - ISC
|
|
300
|
+
*
|
|
301
|
+
* This source code is licensed under the ISC license.
|
|
302
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
303
|
+
*/const nx=[["circle",{cx:"18",cy:"5",r:"3",key:"gq8acd"}],["circle",{cx:"6",cy:"12",r:"3",key:"w7nqdw"}],["circle",{cx:"18",cy:"19",r:"3",key:"1xt0gg"}],["line",{x1:"8.59",x2:"15.42",y1:"13.51",y2:"17.49",key:"47mynk"}],["line",{x1:"15.41",x2:"8.59",y1:"6.51",y2:"10.49",key:"1n3mei"}]],rx=V("share-2",nx);/**
|
|
304
|
+
* @license lucide-react v1.24.0 - ISC
|
|
305
|
+
*
|
|
306
|
+
* This source code is licensed under the ISC license.
|
|
307
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
308
|
+
*/const sx=[["path",{d:"m7 11 2-2-2-2",key:"1lz0vl"}],["path",{d:"M11 13h4",key:"1p7l4v"}],["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2",key:"1m3agn"}]],ix=V("square-terminal",sx);/**
|
|
309
|
+
* @license lucide-react v1.24.0 - ISC
|
|
310
|
+
*
|
|
311
|
+
* This source code is licensed under the ISC license.
|
|
312
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
313
|
+
*/const ox=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]],pc=V("square",ox);/**
|
|
314
|
+
* @license lucide-react v1.24.0 - ISC
|
|
315
|
+
*
|
|
316
|
+
* This source code is licensed under the ISC license.
|
|
317
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
318
|
+
*/const ax=[["path",{d:"M10 11v6",key:"nco0om"}],["path",{d:"M14 11v6",key:"outv1u"}],["path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6",key:"miytrc"}],["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2",key:"e791ji"}]],cx=V("trash-2",ax);/**
|
|
319
|
+
* @license lucide-react v1.24.0 - ISC
|
|
320
|
+
*
|
|
321
|
+
* This source code is licensed under the ISC license.
|
|
322
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
323
|
+
*/const lx=[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["path",{d:"M16 3.128a4 4 0 0 1 0 7.744",key:"16gr8j"}],["path",{d:"M22 21v-2a4 4 0 0 0-3-3.87",key:"kshegd"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}]],ux=V("users",lx);/**
|
|
324
|
+
* @license lucide-react v1.24.0 - ISC
|
|
325
|
+
*
|
|
326
|
+
* This source code is licensed under the ISC license.
|
|
327
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
328
|
+
*/const dx=[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]],$t=V("x",dx);/**
|
|
329
|
+
* @license lucide-react v1.24.0 - ISC
|
|
330
|
+
*
|
|
331
|
+
* This source code is licensed under the ISC license.
|
|
332
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
333
|
+
*/const hx=[["path",{d:"M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z",key:"1xq2db"}]],fx=V("zap",hx);let gc;const us=new Set;function xc(e){gc=e;for(const t of us)t()}const mx=e=>(us.add(e),()=>us.delete(e)),no=()=>gc;function px(e){xc({minimum:e.minimum_browser_protocol,current:e.current_browser_protocol})}async function gx(e){const t=new URLSearchParams({browser_protocol:String(sr),client_kind:"browser"});try{const n=await fetch(`/api/client-compatibility?${t.toString()}`,{cache:"no-store",headers:{authorization:`Bearer ${e}`}});if(n.status!==426)return;const r=await n.json();xc({minimum:r.minimum_browser_protocol??sr+1,current:r.browser_protocol??sr})}catch{}}function xx(){return new Promise(e=>{let t=!1,n;const r=()=>{t||(t=!0,navigator.serviceWorker.removeEventListener("controllerchange",r),n!==void 0&&window.clearTimeout(n),e())};navigator.serviceWorker.addEventListener("controllerchange",r),n=window.setTimeout(r,2e3)})}async function bx(){if("serviceWorker"in navigator){const t=await navigator.serviceWorker.getRegistration("/");if(t!==void 0){const n=xx();await t.update().catch(()=>{}),await n}}const e=new URL(window.location.href);e.searchParams.set("_codor_update",String(Date.now())),window.location.replace(e.toString())}function _x(e){const t=x.useSyncExternalStore(mx,no,no),[n,r]=x.useState(!1);return t===void 0?e.children:o.jsx("main",{className:"nx-upgrade","data-testid":"upgrade-required",children:o.jsxs("section",{className:"nx-upgrade-card","aria-labelledby":"upgrade-title","aria-describedby":"upgrade-copy",children:[o.jsx("span",{className:"nx-upgrade-mark","aria-hidden":"true",children:o.jsx(ls,{size:24})}),o.jsx("p",{className:"nx-eyebrow",children:"Update required"}),o.jsx("h1",{id:"upgrade-title",children:"Codor has been updated"}),o.jsx("p",{id:"upgrade-copy",children:"This installed app is too old to read the current channel format safely. Refresh once to load the new version."}),o.jsx("button",{type:"button",className:"nx-btn is-primary nx-upgrade-action",disabled:n,onClick:()=>{r(!0),bx().catch(()=>r(!1))},children:n?o.jsxs(o.Fragment,{children:[o.jsx(fn,{className:"nx-spin",size:16,"aria-hidden":"true"})," Updating…"]}):o.jsxs(o.Fragment,{children:[o.jsx(ls,{size:16,"aria-hidden":"true"})," Refresh Codor"]})}),o.jsxs("p",{className:"nx-upgrade-version",children:["App protocol ",t.current,"; server requires ",t.minimum,"."]})]})})}const ro=new Set(["connected","disconnected"]),vx=2e4,yx=8e3;function kx(e){const t=window.location.origin.replace(/^http/,"ws"),n=e.socketFactory??(Z=>new WebSocket(Z));let r=e.room,s,i=new Set,a="disconnected",c=500,l,d,u,h=!1,m=e.token,p=0;H.getState().setActiveRoom(r);const g=()=>{l!==void 0&&clearTimeout(l),l=void 0},_=()=>{d!==void 0&&clearInterval(d),u!==void 0&&clearTimeout(u),d=void 0,u=void 0,h=!1},S=Z=>{(s==null?void 0:s.readyState)===WebSocket.OPEN&&s.send(JSON.stringify(Z))},C=Z=>{i.has(Z)||(s==null?void 0:s.readyState)!==WebSocket.OPEN||(i.add(Z),S({type:"subscribe",room:Z,since_seq:ie(H.getState(),Z).seq,hydrate_limit:Ln,room_addressed:!0,browser_protocol:sr,client_kind:"browser"}))},A=Z=>{if(Z!==void 0){Z.onopen=null,Z.onmessage=null,Z.onclose=null,Z.onerror=null;try{Z.close()}catch{}}},$=Z=>{_(),d=setInterval(()=>{Z!==p||a!=="connected"||document.visibilityState==="visible"&&(h||(h=!0,S({type:"list_rooms"}),u=setTimeout(()=>{Z!==p||!h||(h=!1,k())},yx)))},vx)},I=()=>{if(a==="disposed")return;g(),_();const Z=++p;A(s),i=new Set,s=n(`${t}/ws?token=${encodeURIComponent(m)}`);const Y=()=>Z===p&&a!=="disposed";s.onopen=()=>{Y()&&(c=500,a="connected",H.getState().setConnected(!0),C(r),S({type:"list_rooms"}),$(Z))},s.onmessage=G=>{if(!Y())return;const oe=JSON.parse(G.data);if(oe.type==="upgrade_required"){a="parked-upgrade",_(),H.getState().setConnected(!1),px(oe),A(s),s=void 0;return}if(H.getState().applyFrame(oe,r),oe.type==="rooms"){h=!1,u!==void 0&&clearTimeout(u),u=void 0;for(const Ce of oe.rooms)C(Ce.id)}},s.onclose=G=>{if(!Y()||(_(),(a==="connected"||a==="disconnected")&&(a="disconnected"),H.getState().setConnected(!1),a!=="disconnected"))return;if(G.code===4403){a="parked-auth",$n("");return}const oe=()=>{!Y()||a!=="disconnected"||(g(),l=setTimeout(I,c),c=Math.min(c*2,1e4))};G.code===4401&&e.refreshToken?e.refreshToken().then(Ce=>{Y()&&(m=$n(Ce),oe())},oe):oe()}};I();let z=!1;const k=()=>{!ro.has(a)||z||(z=!0,queueMicrotask(()=>{var Z;z=!1,ro.has(a)&&(I(),(Z=e.onResume)==null||Z.call(e,r))}))},E=()=>{document.visibilityState==="visible"&&k()},L=Z=>{Z.persisted&&k()},J=()=>{document.visibilityState==="visible"&&k()};window.addEventListener("visibilitychange",E),window.addEventListener("pageshow",L),window.addEventListener("online",J);const ce={room:()=>r,state:()=>a,post:(Z,Y)=>{var G;return S({type:"post",room:r,body:Z,...(Y==null?void 0:Y.replyTo)!==void 0&&{reply_to:Y.replyTo},...(G=Y==null?void 0:Y.attachments)!=null&&G.length?{attachments:Y.attachments}:{}})},act:Z=>S({type:"act",room:r,act:Z}),disconnect:()=>{a="parked-manual",g(),_(),p+=1,A(s),s=void 0,H.getState().setConnected(!1)},reconnect:()=>{a!=="parked-manual"&&a!=="disconnected"||(a="disconnected",I())},switchRoom:Z=>{Z!==r&&(r=Z,H.getState().setActiveRoom(Z),C(Z))},dispose:()=>{a="disposed",g(),_(),H.getState().setConnected(!1),p+=1,window.removeEventListener("visibilitychange",E),window.removeEventListener("pageshow",L),window.removeEventListener("online",J),A(s),s=void 0}};return window.__codor=ce,ce}const wx=4,Sx=3;let cn="",bc=0;const Ge=new Map,ds=new Set;function _c(){bc+=1;for(const e of ds)e()}function jx(){return{active:0,queue:[],journals:new Map,inflight:new Map,wantTerminal:new Set,wantRefresh:new Set}}function vc(e){const t=Ge.get(e)??jx();for(Ge.delete(e),Ge.set(e,t);Ge.size>Sx;){const n=Ge.keys().next().value;if(n===void 0)break;Ge.delete(n)}return t}function Nx(e){e!==cn&&(cn=e,vc(e),_c())}function mr(e,t){const n=e.queue.findIndex(s=>s.id===t.id);if(n===-1){e.queue.push(t);return}const r=e.queue[n];r.terminal=r.terminal||t.terminal,r.priority=r.priority||t.priority}function Ps(e,t,n){if(!(e!==cn||Ge.get(e)!==t))for(;t.active<wx&&t.queue.length>0;){const r=t.queue.findIndex(i=>i.priority),s=t.queue.splice(r===-1?0:r,1)[0];t.active+=1,t.inflight.set(s.id,s.terminal),da(e,s.id,{token:n()}).then(i=>{Ge.get(e)===t&&t.journals.set(s.id,{events:i,terminal:s.terminal})}).catch(()=>{Ge.get(e)===t&&t.journals.set(s.id,{events:[],terminal:s.terminal})}).finally(()=>{t.active-=1,Ge.get(e)===t&&(t.inflight.delete(s.id),t.wantTerminal.delete(s.id)?mr(t,{id:s.id,terminal:!0,priority:!1}):t.wantRefresh.delete(s.id)&&mr(t,{id:s.id,terminal:!1,priority:!1}),t.wantRefresh.delete(s.id),e===cn&&_c(),Ps(e,t,n))})}}function yc(e,t,n,r){if(e!==cn)return;const s=vc(e),i=s.journals.get(n);if((i==null?void 0:i.terminal)===!0||i!==void 0&&!r.terminal)return;const a=s.inflight.get(n);if(a!==void 0){r.terminal&&!a&&s.wantTerminal.add(n);return}mr(s,{id:n,terminal:r.terminal,priority:r.priority===!0}),Ps(e,s,t)}function Tx(e,t){if(e!==cn)return;const n=Ge.get(e);if(n===void 0)return;const r=new Set;for(const[s,i]of n.journals)i.terminal||r.add(s);for(const[s,i]of n.inflight)i||r.add(s);for(const s of r){if(n.inflight.has(s)){n.wantRefresh.add(s);continue}mr(n,{id:s,terminal:!1,priority:!1})}Ps(e,n,t)}function Ms(e,t){var n,r;return(r=(n=Ge.get(e))==null?void 0:n.journals.get(t))==null?void 0:r.events}function Ex(e){return ds.add(e),()=>{ds.delete(e)}}const so=()=>bc;function kc(){return x.useSyncExternalStore(Ex,so,so)}function $x(e){const t=["",...e.levels],n=t.length-1,r=Math.max(0,t.indexOf(e.value)),s=n===0?0:r/n,i=d=>d===""?"Default":d,a=`calc(8px + ${String(s*100)}% - ${String(s*16)}px)`,c=`calc(${String(s*100)}% - ${String(s*16)}px)`,l=s===0?"translateX(0)":s===1?"translateX(-100%)":"translateX(-50%)";return o.jsxs("div",{className:"nx-slider","data-testid":`${e.idPrefix}-thinking-slider`,children:[o.jsxs("div",{className:"nx-slider-rail",children:[o.jsx("div",{className:"nx-slider-fill",style:{width:c}}),o.jsx("div",{className:"nx-slider-ticks","aria-hidden":"true",children:t.map((d,u)=>o.jsx("span",{className:u<=r?"nx-slider-tick is-on":"nx-slider-tick","data-active":u===r},d===""?"default":d))}),o.jsx("span",{className:"nx-slider-knob",style:{left:a},"aria-hidden":"true"}),o.jsx("span",{className:"nx-slider-tip",style:{left:a,transform:l},"data-testid":`${e.idPrefix}-thinking-value`,children:i(t[r]??"")}),o.jsx("input",{type:"range",className:"nx-slider-input",min:0,max:n,step:1,value:r,disabled:e.disabled===!0||n===0,"aria-label":"Thinking effort","aria-valuetext":i(t[r]??""),"data-testid":`${e.idPrefix}-thinking-range`,onChange:d=>e.onChange(t[Number(d.target.value)]??"")})]}),o.jsxs("div",{className:"nx-slider-ends","aria-hidden":"true","data-testid":`${e.idPrefix}-thinking-ends`,children:[o.jsx("span",{children:i(t[0]??"")}),o.jsx("span",{children:i(t[n]??"")})]})]})}const io=31,Rx="[a-z0-9][a-z0-9\\-]{1,30}",Cx=Sr.options,pr="read-only";function Ds(e){if(e===void 0||e.capabilities.thinking!==!0)return[];const t=e.capabilities.thinking_levels;return t!==void 0&&t.length>0?t:Va}function Er(e,t){return Ds(e).includes(t)?t:void 0}const wc=e=>e!==void 0&&(e.startsWith("/")||/^[A-Za-z]:[\\/]/.test(e)||e.startsWith("\\\\"));function Ax(e){return e.kind==="agent"&&e.removed_ts===void 0&&e.state!=="dead"&&e.state!=="unreachable"&&e.custody!=="mirrored"&&wc(e.cwd)}function zx(e,t){var s;if(wc(e==null?void 0:e.config.cwd))return e.config.cwd;const n=t.filter(Ax).sort((i,a)=>i.id.localeCompare(a.id)),r=e==null?void 0:e.config.starting_agent_handle;if(r!==void 0){const i=n.find(a=>a.handle===r);if((i==null?void 0:i.cwd)!==void 0)return i.cwd}return((s=n[0])==null?void 0:s.cwd)??""}function Sc(e,t){const n=new Set(t.filter(s=>s.removed_ts===void 0).map(s=>s.handle)),r=e.slice(0,io);if(!n.has(r))return r;for(let s=2;s<1e3;s+=1){const i=`-${String(s)}`,a=r.slice(0,io-i.length)+i;if(!n.has(a))return a}return r}function Ix(e){const t=Sr.safeParse(e);return t.success?t.data:""}function Lx(e){return e.find(t=>t.kind==="human"&&t.role==="owner")}function jc(e,t){return t!==void 0&&t.handle===e}const Ox=[{id:"coder",label:"Coder",blurb:"Writes and edits code",handle:"coder",purpose:"Implement the change we agree on, in small reviewable steps.",policy:"workspace-write",thinking:"medium"},{id:"reviewer",label:"Reviewer",blurb:"Reads and critiques",handle:"reviewer",purpose:"Review the diff for correctness and risk. Do not edit files.",policy:"read-only",thinking:"high"},{id:"planner",label:"Planner",blurb:"Breaks work down",handle:"planner",purpose:"Turn the goal into an ordered plan with checkable steps.",policy:"read-only",thinking:"high"},{id:"writer",label:"Writer",blurb:"Docs and prose",handle:"writer",purpose:"Write and revise documentation for this project.",policy:"workspace-write",thinking:"low"},{id:"tester",label:"Tester",blurb:"Runs and fixes tests",handle:"tester",purpose:"Run the suite, diagnose failures, and add missing coverage.",policy:"workspace-write",thinking:"medium"}];function Px(e){const t=e.adapters.find(n=>n.id===e.config.harness);return{config:{...e.config,policy:e.preset.policy,thinking:Er(t,e.preset.thinking)??""},handle:Sc(e.preset.handle,e.members),purpose:e.preset.purpose}}function Nc(e,t,n){if(t===e.harness)return e;const r=n.find(a=>a.id===t),i=Ds(r).includes(e.thinking)?e.thinking:"";return{...e,harness:t,model:"",thinking:i}}function Tc(e,t){var n;return t.some(r=>r.id===e)?e:((n=t[0])==null?void 0:n.id)??""}const Mx=/\b(handle|spawn|harness|agent|reserved)\b/i;function Dx(e,t){return t===""?!1:new RegExp(`(^|[^a-z0-9-])${t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}([^a-z0-9-]|$)`,"i").test(e)}function Zx(e,t){var r;if(Dx(e,t))return!0;const n=(r=/@([a-z0-9][a-z0-9-]*)/i.exec(e))==null?void 0:r[1];return n!==void 0&&n.toLowerCase()!==t.toLowerCase()?!1:Mx.test(e)}function Fx(e){if(e.members.some(s=>s.handle===e.handle&&s.removed_ts===void 0))return{state:"arrived"};const r=e.freshErrors.filter(s=>Zx(s,e.handle)).at(-1);return r===void 0?{state:"pending"}:{state:"failed",message:r}}function Ux(e){return/starting agent|handle/i.test(e)}function qx(e){var i;const t=Tc(e.config.harness,e.adapters),n=e.adapters.find(a=>a.id===t),r=Er(n,e.config.thinking),s=(i=e.purpose)==null?void 0:i.trim();return{harness:t,handle:Sc(e.handle.trim(),e.members),cwd:e.cwd.trim(),policy:e.config.policy===""?pr:e.config.policy,...e.config.model!==""&&{model:e.config.model},...r!==void 0&&{thinking:r},...s!==void 0&&s!==""&&{purpose:s}}}const Ec={"claude-code":{label:"Claude Code",mark:e=>o.jsx("svg",{viewBox:"0 0 94 94",width:e,height:e,fill:"currentColor","aria-hidden":"true",children:o.jsx("path",{d:"M18.7657 62.4437L37.1822 52.1167L37.4857 51.2122L37.1822 50.7085H36.2715L33.1852 50.5208L22.6615 50.2391L13.5545 49.8636L4.70044 49.3942L2.47428 48.9248L0.399902 46.1553L0.602281 44.794L2.47428 43.5266L5.15579 43.7613L11.0754 44.1837L19.98 44.794L26.4055 45.1695L35.9679 46.1553H37.4857L37.6881 45.545L37.1822 45.1695L36.7774 44.794L27.5692 38.5508L17.6021 31.9791L12.3908 28.1769L9.60812 26.2524L8.19147 24.4686L7.58433 20.5256L10.1141 17.7091L13.5545 17.9438L14.4146 18.1785L17.9056 20.8542L25.343 26.6279L35.0572 33.7629L36.4739 34.9364L37.0443 34.5514L37.1316 34.2792L36.4739 33.1996L31.212 23.6706L25.596 13.9539L23.0663 9.91695L22.4086 7.52296C22.1538 6.51831 22.0038 5.68714 22.0038 4.65957L24.8877 0.716544L26.5067 0.200195L30.4025 0.716544L32.0215 2.12477L34.4501 7.66379L38.3458 16.3478L44.4172 28.1769L46.188 31.6975L47.1493 34.9364L47.5035 35.9222H48.1106V35.3589L48.6166 28.6933L49.5273 20.5256L50.438 10.0108L50.7415 7.05356L52.2088 3.48605L55.1433 1.56148L57.42 2.64112L59.292 5.31674L59.039 7.05356L57.926 14.2824L55.7504 25.5952L54.3337 33.1996H55.1433L56.1046 32.2138L59.9497 27.1442L66.3752 19.0704L69.2085 15.8784L72.5478 12.3579L74.6728 10.668H78.7203L81.6548 15.0804L80.3394 19.6337L76.1906 24.8911L72.7502 29.3504L67.8172 35.9595L64.7562 41.2734L65.0307 41.7118L65.7681 41.6489L76.8989 39.255L82.9197 38.1753L90.1041 36.9549L93.3422 38.457L93.6963 40.006L92.4315 43.151L84.7411 45.0287L75.7353 46.8594L62.3244 50.0164L62.1759 50.1358L62.3512 50.3958L68.399 50.9432L70.9794 51.084H77.3037L89.0922 51.9759L92.1785 53.9944L93.9999 56.4822L93.6963 58.4068L88.9404 60.8008L82.5655 59.2987L67.6401 55.7312L62.5301 54.4638H61.8217V54.8862L66.0717 59.064L73.9139 66.1051L83.6786 75.2116L84.1845 77.4648L82.9197 79.2485L81.6042 79.0608L73.0032 72.5829L69.6639 69.6726L62.1759 63.3356H61.67V63.9928L63.3902 66.5276L72.5478 80.2812L73.0032 84.5059L72.3454 85.8672L69.9675 86.7121L67.3871 86.2427L61.9735 78.6852L56.4587 70.2359L52.0064 62.6315L51.4687 62.971L48.8189 91.2654L47.6047 92.7206L44.7714 93.8002L42.3934 92.0164L41.1286 89.1061L42.3934 83.3324L43.9113 75.8219L45.1255 69.8604L46.2386 62.4437L46.9184 59.9661L46.8583 59.8003L46.3153 59.8916L40.7238 67.5603L32.2239 79.0608L25.4948 86.2427L23.8758 86.8999L21.0931 85.4447L21.3461 82.863L22.9145 80.5629L32.2239 68.7338L37.8399 61.3641L41.4594 57.1337L41.4242 56.5218L41.2244 56.5048L16.489 72.6299L12.0873 73.1932L10.1647 71.4094L10.4176 68.4991L11.3283 67.5603L18.7657 62.4437Z"})})},codex:{label:"Codex",mark:e=>o.jsx("svg",{viewBox:"166.30 166.30 383.40 383.40",width:e,height:e,fill:"currentColor","aria-hidden":"true",children:o.jsx("path",{d:"M508.749 317.399C516.777 287.314 508.991 253.884 485.389 230.282C461.788 206.681 428.36 198.895 398.273 206.923C376.231 184.928 343.39 174.956 311.148 183.596C278.906 192.234 255.45 217.292 247.36 247.361C217.291 255.451 192.233 278.91 183.595 311.149C174.957 343.391 184.927 376.232 206.924 398.274C198.896 428.359 206.683 461.789 230.284 485.391C253.885 508.992 287.313 516.779 317.401 508.75C339.442 530.745 372.286 540.717 404.525 532.079C436.767 523.441 460.223 498.384 468.313 468.315C498.383 460.224 523.44 436.766 532.078 404.526C540.716 372.285 530.747 339.443 508.749 317.402V317.399ZM470.899 244.776C486.892 260.77 493.488 282.601 490.687 303.412L415.577 260.046C412.411 258.218 408.509 258.218 405.345 260.046L317.401 310.82V277.526C317.401 275.191 318.652 273.005 320.676 271.837L387.644 233.174C414.178 218.353 448.346 222.223 470.901 244.776H470.899ZM357.837 311.144L398.275 334.491V381.185L357.837 404.532L317.398 381.185V334.491L357.837 311.144ZM264.776 269.693C265.207 239.305 285.644 211.649 316.453 203.393C338.3 197.54 360.505 202.744 377.127 215.573L302.014 258.937C298.848 260.764 296.898 264.144 296.898 267.798V369.346L268.065 352.699C266.043 351.531 264.776 349.353 264.776 347.017V269.691V269.693ZM203.391 316.454C209.244 294.608 224.854 277.978 244.276 269.999V356.73C244.276 360.384 246.226 363.763 249.392 365.591L337.337 416.365L308.503 433.013C306.481 434.181 303.961 434.188 301.939 433.02L234.971 394.357C208.868 378.789 195.138 347.261 203.391 316.454ZM244.775 470.9C228.781 454.906 222.186 433.075 224.986 412.264L300.096 455.63C303.263 457.457 307.164 457.457 310.328 455.63L398.273 404.856V438.149C398.273 440.485 397.022 442.671 394.997 443.839L328.029 482.502C301.495 497.322 267.327 493.452 244.772 470.9H244.775ZM450.897 445.982C450.466 476.371 430.029 504.027 399.22 512.283C377.373 518.136 355.168 512.932 338.547 500.102L413.659 456.738C416.826 454.911 418.775 451.532 418.775 447.877V346.329L447.609 362.977C449.631 364.145 450.897 366.323 450.897 368.659V445.985V445.982ZM512.282 399.221C506.429 421.068 490.819 437.697 471.397 445.676V358.946C471.397 355.292 469.448 351.912 466.281 350.085L378.336 299.311L407.17 282.663C409.192 281.495 411.712 281.487 413.734 282.655L480.702 321.318C506.805 336.887 520.536 368.415 512.282 399.221Z"})})},gemini:{label:"Gemini",mark:e=>o.jsx("svg",{viewBox:"0 0 24 24",width:e,height:e,fill:"currentColor","aria-hidden":"true",children:o.jsx("path",{d:"M12 2c0 5.52-4.48 10-10 10 5.52 0 10 4.48 10 10 0-5.52 4.48-10 10-10-5.52 0-10-4.48-10-10Z"})})},antigravity:{label:"Antigravity",mark:e=>o.jsx(Eg,{width:e,height:e,"aria-hidden":"true"})},copilot:{label:"GitHub Copilot",mark:e=>o.jsx(ig,{width:e,height:e,"aria-hidden":"true"})},opencode:{label:"OpenCode",mark:e=>o.jsx("svg",{viewBox:"0 0 240 300",width:e,height:e,fill:"currentColor",fillRule:"evenodd",clipRule:"evenodd","aria-hidden":"true",children:o.jsx("path",{d:"M180 60H60V240H180V60ZM240 300H0V0H240V300Z"})})},cursor:{label:"Cursor",mark:e=>o.jsx("svg",{viewBox:"0 0 466.73 532.09",width:e,height:e,fill:"currentColor","aria-hidden":"true",children:o.jsx("path",{d:"M457.43,125.94L244.42,2.96c-6.84-3.95-15.28-3.95-22.12,0L9.3,125.94c-5.75,3.32-9.3,9.46-9.3,16.11v247.99c0,6.65,3.55,12.79,9.3,16.11l213.01,122.98c6.84,3.95,15.28,3.95,22.12,0l213.01-122.98c5.75-3.32,9.3-9.46,9.3-16.11v-247.99c0-6.65-3.55-12.79-9.3-16.11h-.01ZM444.05,151.99l-205.63,356.16c-1.39,2.4-5.06,1.42-5.06-1.36v-233.21c0-4.66-2.49-8.97-6.53-11.31L24.87,145.67c-2.4-1.39-1.42-5.06,1.36-5.06h411.26c5.84,0,9.49,6.33,6.57,11.39h-.01Z"})})}};function $c(e){var t;return((t=Ec[e])==null?void 0:t.label)??e}function Bx(e,t=22){const n=Ec[e];return n!==void 0?n.mark(t):o.jsx(yg,{size:t,"aria-hidden":"true"})}const Hx={"read-only":{title:"Read only",icon:lc},"workspace-write":{title:"Edit",icon:Fg},"full-access":{title:"Full access",icon:fx}},Wx=8;function ln(e){const t=e.headingLevel===2?"h2":"h3";return o.jsxs("section",{className:"nx-sec",children:[o.jsxs("div",{className:"nx-sec-head",children:[o.jsx("span",{className:"nx-sec-n","aria-hidden":"true",children:e.n}),o.jsx(t,{className:"nx-sec-title",children:e.title}),o.jsx("span",{className:"nx-sec-rule","aria-hidden":"true"})]}),e.children]})}function Zs(e){const t=e.idPrefix??"agent";return o.jsx(o.Fragment,{children:o.jsxs("div",{className:"nx-field",children:[o.jsxs("div",{className:"nx-harness-head",children:[o.jsxs("span",{className:"nx-label",children:["Harness ",e.optional===!0&&o.jsx("span",{className:"nx-opt",children:"· optional"})]}),e.onRefresh!==void 0&&o.jsxs("button",{type:"button",className:"nx-harness-refresh",disabled:e.refreshing===!0,"data-testid":`${t}-refresh-adapters`,onClick:e.onRefresh,children:[e.refreshing===!0?o.jsx(fn,{size:14,className:"nx-spin","aria-hidden":"true"}):o.jsx(ls,{size:14,"aria-hidden":"true"}),e.refreshing===!0?"Refreshing…":"Refresh"]})]}),e.adapters.length===0&&o.jsx("p",{className:"nx-note",role:"status",children:"No supported harnesses found"}),e.refreshError!==void 0&&o.jsxs("p",{className:"nx-field-note is-error",role:"alert",children:["Refresh failed: ",e.refreshError]}),o.jsxs("div",{className:"nx-harness-grid",role:"group","aria-label":"Harness",children:[e.allowNone===!0&&o.jsxs("button",{type:"button",className:"nx-harness","aria-pressed":e.config.harness==="","data-testid":`${t}-harness-none`,onClick:()=>{e.onChange({...e.config,harness:"",model:"",thinking:""})},children:[o.jsx(ng,{size:22,"aria-hidden":"true"}),o.jsx("span",{className:"nx-harness-name",children:"None"}),o.jsx("span",{className:"nx-check","aria-hidden":"true"})]}),e.adapters.map(n=>o.jsxs("button",{type:"button",className:"nx-harness","aria-pressed":n.id===e.config.harness,disabled:e.lockHarness===!0,"data-testid":`${t}-harness-${n.id}`,onClick:()=>{e.onChange(Nc(e.config,n.id,e.adapters))},children:[Bx(n.id),o.jsx("span",{className:"nx-harness-name",children:$c(n.id)}),n.capabilities.resume===!1&&o.jsx("span",{className:"nx-harness-sub",children:"ephemeral"}),o.jsx("span",{className:"nx-check","aria-hidden":"true"})]},n.id))]})]})})}function Vx(e){const t=e.idPrefix??"agent";return o.jsxs("div",{className:"nx-field",children:[o.jsxs("span",{className:"nx-label",children:["Preset ",o.jsx("span",{className:"nx-opt",children:"· optional"})]}),o.jsx("div",{className:"nx-tile-row",role:"group","aria-label":"Preset",children:Ox.map(n=>o.jsx("button",{type:"button",className:"nx-tile nx-preset","data-testid":`${t}-preset-${n.id}`,onClick:()=>{e.onApply(n)},children:n.label},n.id))})]})}function Fs(e){var g;const{adapters:t,config:n}=e,r=e.idPrefix??"agent",s=t.find(_=>_.id===n.harness),i=(s==null?void 0:s.models)??[],a=Ds(s),[c,l]=x.useState(""),d=_=>{e.onChange({...n,..._})},u=c.trim().toLowerCase(),h=u===""?i:i.filter(_=>_.toLowerCase().includes(u)),m=o.jsxs(o.Fragment,{children:[o.jsxs("div",{className:"nx-field",children:[o.jsx("span",{className:"nx-label",children:"Model"}),i.length===0?o.jsxs(o.Fragment,{children:[o.jsx("input",{className:"nx-input",value:n.model,onChange:_=>{d({model:_.target.value})},placeholder:"harness default","aria-label":"Model","data-testid":`${r}-model-input`}),o.jsx("p",{className:"nx-note",children:"This harness did not report a model list."})]}):o.jsxs(o.Fragment,{children:[i.length>Wx&&o.jsx("input",{className:"nx-input",value:c,onChange:_=>{l(_.target.value)},placeholder:`Search ${String(i.length)} models…`,"aria-label":"Search models","data-testid":`${r}-model-search`}),o.jsxs("div",{className:"nx-list",role:"group","aria-label":"Model","data-testid":`${r}-model-list`,children:[o.jsxs("button",{type:"button","aria-pressed":n.model==="",className:"nx-list-row","data-testid":`${r}-model-default`,onClick:()=>{d({model:""})},children:[o.jsx("span",{children:"Default"}),o.jsx("span",{className:"nx-list-sub",children:"harness pick"}),o.jsx("span",{className:"nx-check","aria-hidden":"true"})]}),h.map(_=>o.jsxs("button",{type:"button","aria-pressed":n.model===_,className:"nx-list-row","data-testid":`${r}-model-${_}`,onClick:()=>{d({model:_})},children:[o.jsx("span",{className:"nx-mono",children:_}),o.jsx("span",{className:"nx-check","aria-hidden":"true"})]},_)),h.length===0&&o.jsx("p",{className:"nx-note",children:"No model matches that search."})]}),o.jsx("input",{className:"nx-input",value:n.model,onChange:_=>{d({model:_.target.value})},placeholder:"or type an exact model id","aria-label":"Custom model","data-testid":`${r}-model-custom`})]})]}),o.jsxs("div",{className:"nx-field",children:[o.jsx("span",{className:"nx-label",children:"Thinking effort"}),a.length===0?o.jsx("p",{className:"nx-note","data-testid":`${r}-thinking-unsupported`,children:"Not supported by this harness."}):o.jsx($x,{levels:a,value:n.thinking,onChange:_=>{d({thinking:_})},idPrefix:r})]})]}),p=o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"nx-perm-row",role:"group","aria-label":"Permissions",children:Cx.map(_=>{var $;const S=Hx[_],C=(S==null?void 0:S.icon)??lc,A=($=s==null?void 0:s.capabilities.policies)==null?void 0:$[_];return o.jsxs("button",{type:"button",className:"nx-perm","aria-pressed":n.policy===_,"data-testid":`${r}-policy-${_}`,onClick:()=>{d({policy:_})},children:[o.jsx(C,{size:16,"aria-hidden":"true"}),o.jsx("span",{className:"nx-perm-title",children:(S==null?void 0:S.title)??_}),o.jsx("span",{className:A==null?"nx-perm-native is-deferred":"nx-perm-native",children:s===void 0?"":A??"not enforced"}),o.jsx("span",{className:"nx-check","aria-hidden":"true"})]},_)})}),s!==void 0&&n.policy!==""&&((g=s.capabilities.policies)==null?void 0:g[n.policy])===null&&o.jsxs("p",{className:"nx-note is-warn",role:"status","data-testid":`${r}-policy-deferred`,children:[$c(s.id)," does not enforce this setting — it defers to however that harness is configured. Only Full access changes anything here."]}),(s==null?void 0:s.capabilities.approvals)==="spawn-time"&&o.jsx("p",{className:"nx-note",role:"status",children:"Approval policy is fixed when this harness starts; in-turn approval cards are unavailable."})]});return o.jsxs(o.Fragment,{children:[e.hideHarness!==!0&&o.jsx(Zs,{adapters:t,config:n,onChange:e.onChange,lockHarness:e.lockHarness,idPrefix:r}),e.embedded===!0?o.jsx("div",{className:"nx-agent-embedded-group",children:m}):o.jsx(ln,{n:e.behaviourSection,title:"Behaviour",children:m}),e.embedded===!0?o.jsx("div",{className:"nx-agent-embedded-group",children:p}):o.jsx(ln,{n:e.permissionsSection,title:"Permissions",children:p})]})}function Rc(e){const[t,n]=x.useState(),[r,s]=x.useState(!1),[i,a]=x.useState(!1),c=(h,m=i,p=!1)=>{Hl(h,m,{token:e.token()}).then(g=>{n(g),s(!1)}).catch(()=>{p&&h!==void 0?c(void 0,m,!1):s(!0)})};if(x.useEffect(()=>{c(e.value===""?void 0:e.value,i,!0)},[]),r)return o.jsxs("div",{className:"nx-picker","data-testid":`${e.idPrefix}-folder-picker`,children:[o.jsxs("div",{className:"nx-picker-foot",children:[o.jsx("span",{className:"nx-note is-error",children:"Couldn’t list folders on this device."}),o.jsx("button",{type:"button",className:"nx-tile is-compact","data-testid":`${e.idPrefix}-folder-retry`,onClick:()=>{s(!1),c(void 0,i,!1)},children:"Retry"})]}),o.jsx("input",{className:"nx-input",value:e.value,onChange:h=>{e.onChange(h.target.value)},placeholder:"or type a path","aria-label":"Folder path","data-testid":`${e.idPrefix}-folder-typed`})]});if(t===void 0)return o.jsx("p",{className:"nx-note",children:"Loading folders…"});const l=t.path.split("/").filter(h=>h!==""),d=l.map((h,m)=>({name:h,path:`/${l.slice(0,m+1).join("/")}`})),u="this device";return o.jsxs("div",{className:"nx-picker","data-testid":`${e.idPrefix}-folder-picker`,children:[o.jsxs("div",{className:"nx-picker-bar",children:[o.jsxs("span",{className:"nx-host",title:String(u),children:[o.jsx(Mg,{size:12,"aria-hidden":"true"}),String(u)]}),o.jsxs("nav",{className:"nx-crumbs","aria-label":"Folder path",children:[o.jsx("button",{type:"button","data-testid":`${e.idPrefix}-crumb-root`,onClick:()=>{c("/")},children:"~"}),d.map((h,m)=>o.jsx("button",{type:"button",className:m===d.length-1?"is-current":void 0,"data-testid":`${e.idPrefix}-crumb-${h.name}`,onClick:()=>{c(h.path)},children:h.name},h.path))]}),o.jsxs("span",{className:"nx-picker-tools",children:[t.parent!==null&&o.jsx("button",{type:"button","aria-label":"Up one folder","data-testid":`${e.idPrefix}-folder-up`,onClick:()=>{c(t.parent??void 0)},children:o.jsx(as,{size:14,"aria-hidden":"true"})}),o.jsx("button",{type:"button","aria-label":"Refresh","data-testid":`${e.idPrefix}-folder-refresh`,onClick:()=>{c(t.path)},children:o.jsx(Kg,{size:14,"aria-hidden":"true"})})]})]}),o.jsxs("ul",{className:"nx-picker-list",children:[t.parent!==null&&o.jsx("li",{children:o.jsxs("button",{type:"button",className:"nx-picker-row is-up","data-testid":`${e.idPrefix}-folder-parent`,onClick:()=>{c(t.parent??void 0)},children:[o.jsx(_g,{size:14,"aria-hidden":"true"}),o.jsx("span",{className:"nx-mono",children:".."})]})}),t.dirs.length===0&&o.jsx("li",{className:"nx-note",children:"no subfolders"}),t.dirs.map(h=>o.jsx("li",{children:o.jsxs("span",{className:"nx-picker-pair",children:[o.jsxs("button",{type:"button",className:"nx-picker-row","aria-pressed":e.value===h.path,"data-testid":`${e.idPrefix}-folder-${h.name}`,onClick:()=>{e.onChange(h.path)},children:[o.jsx(Ng,{size:14,"aria-hidden":"true"}),o.jsx("span",{className:"nx-mono",children:h.name}),o.jsx("span",{className:"nx-check","aria-hidden":"true"})]}),o.jsx("button",{type:"button",className:"nx-picker-open","aria-label":`Open ${h.name}`,"data-testid":`${e.idPrefix}-open-${h.name}`,onClick:()=>{c(h.path)},children:o.jsx(ac,{size:14,"aria-hidden":"true"})})]})},h.path))]}),o.jsxs("div",{className:"nx-picker-foot",children:[o.jsxs("label",{className:"nx-hidden-toggle",children:[o.jsx("input",{type:"checkbox",checked:i,"data-testid":`${e.idPrefix}-folder-hidden`,onChange:h=>{a(h.target.checked),c(t.path,h.target.checked)}}),"Hidden"]}),o.jsx("span",{className:"nx-picker-selected",children:e.value===""?o.jsx("span",{"data-testid":`${e.idPrefix}-folder-selected`,children:"No folder selected"}):o.jsxs(o.Fragment,{children:["Selected ",o.jsx("code",{"data-testid":`${e.idPrefix}-folder-selected`,children:e.value})]})})]}),o.jsx("input",{className:"nx-input",value:e.value,onChange:h=>{e.onChange(h.target.value)},placeholder:"or type a path","aria-label":"Folder path","data-testid":`${e.idPrefix}-folder-typed`})]})}const Gx={tool_call:"Tool call",tool_result:"Tool result",reasoning_summary:"Reasoning",text_delta:"Response",commit:"Commit",file_change:"File change"},Jx=e=>{if(e===void 0)return;const t=typeof e=="string"?e:JSON.stringify(e);if(!(t===void 0||t===""))return t.length>220?`${t.slice(0,217)}...`:t},Yx=e=>{const t=e.toLowerCase();return/bash|shell|terminal|command|exec/.test(t)?"terminal":/edit|write|patch|notebook/.test(t)?"edit":/grep|glob|search|find|read/.test(t)?"search":/web|browser|fetch|http/.test(t)?"web":"tool"};function Us(e){let t=0,n=0;for(const r of e.split(`
|
|
334
|
+
`))r.startsWith("+++ ")||r.startsWith("--- ")||(r.startsWith("+")?t+=1:r.startsWith("-")&&(n+=1));return{added:t,removed:n}}const oo=e=>{if(!e)return;const{added:t,removed:n}=Us(e.unified);return`+${String(t)} -${String(n)}`},It=e=>{const t=e.event,n=t.type==="run.item"?t.item_type:void 0;return{id:`event-${String(e.index)}`,eventIndex:e.index,kind:"tool",icon:"generic",title:n?Gx[n]:"Run event",detail:t.type==="run.item"?Jx(t.payload):void 0,status:"info",event:t,ts:Kx(t)}},Kx=e=>e.type==="run.item"?e.ts:void 0;function Cc(e){const t=[],n=new Map;for(const r of e){const s=r.event;if(s.type!=="run.item")continue;if(s.item_type==="tool_call"){const a=Kt("tool_call",s.payload);if(!a.success){t.push(It(r));continue}n.set(a.data.call_id,t.length),t.push({id:`call-${a.data.call_id}`,eventIndex:r.index,kind:"tool",icon:Yx(a.data.tool),title:a.data.tool,detail:a.data.title,status:"running",event:s,ts:s.ts});continue}if(s.item_type==="tool_result"){const a=Kt("tool_result",s.payload);if(!a.success){t.push(It(r));continue}const c=n.get(a.data.call_id);if(c===void 0){t.push({...It(r),status:a.data.status,duration_ms:a.data.duration_ms,output_text:a.data.output_text,diff:a.data.diff,image:a.data.image});continue}const l=t[c];t[c]={...l,resultEventIndex:r.index,status:a.data.status,duration_ms:a.data.duration_ms,output_text:a.data.output_text,diff:a.data.diff,image:a.data.image,detail:[l.detail,oo(a.data.diff)].filter(Boolean).join(" · "),event:s};continue}if(s.item_type==="text_delta"){const a=Kt("text_delta",s.payload);if(!a.success){t.push(It(r));continue}const c=t.at(-1);(c==null?void 0:c.kind)==="prose"&&c.icon==="text"?(c.text=`${c.text??""}${a.data.text}`,c.event=s):t.push({id:`text-${String(r.index)}`,eventIndex:r.index,kind:"prose",icon:"text",title:"Response",text:a.data.text,status:"info",event:s,ts:s.ts});continue}if(s.item_type==="reasoning_summary"){const a=Kt("reasoning_summary",s.payload);if(!a.success){t.push(It(r));continue}t.push({id:`reasoning-${String(r.index)}`,eventIndex:r.index,kind:"prose",icon:"reasoning",title:"Reasoning",text:a.data.text,status:"info",event:s,ts:s.ts});continue}if(s.item_type==="file_change"){const a=Kt("file_change",s.payload);if(!a.success){t.push(It(r));continue}const c=a.data.change==="created"?"Write":a.data.change==="deleted"?"Delete":"Edit";t.push({id:`file-${String(r.index)}`,eventIndex:r.index,kind:"tool",icon:"edit",title:c,detail:[a.data.path,oo(a.data.diff)].filter(Boolean).join(" · "),status:"ok",diff:a.data.diff,event:s,ts:s.ts});continue}const i=Kt("commit",s.payload);if(!i.success){t.push(It(r));continue}t.push({id:`commit-${String(r.index)}`,eventIndex:r.index,kind:"tool",icon:"commit",title:"Commit",detail:i.data.message??i.data.sha??"Recorded",status:"ok",event:s,ts:s.ts})}return t}function Xx(e,t){const n=new Map;e==null||e.forEach((s,i)=>n.set(i,s));const r=t.first_index??t.dropped_count;return t.events.forEach((s,i)=>n.set(r+i,s)),[...n.entries()].sort(([s],[i])=>s-i).map(([s,i])=>({index:s,event:i}))}function Ac(e){const t=Math.max(0,Math.floor(e/1e3)),n=Math.floor(t/60),r=t%60;return n>0?`${String(n)}m${String(r).padStart(2,"0")}s`:`${String(r)}s`}const Qx=/(^|_|\b)(bash|sh|zsh|shell|exec|command|terminal)(\b|_|$)/i,eb=/(read|glob|grep|search|list_director|ls|webfetch|web_fetch|fetch|view|cat)/i,tb=/(delete|remove|unlink|rm)/i;function ao(e,t=80){const n=[...e];if(n.length<=t)return e;const r=t-1,s=Math.ceil(r/2),i=Math.floor(r/2);return`${n.slice(0,s).join("")}…${n.slice(n.length-i).join("")}`}function co(e){const t=e.trim().replace(/\/+$/,"");return t.slice(t.lastIndexOf("/")+1)||t}function nb(e){return e.replace(/\s·\s\+\d+ -\d+$/,"")}function rb(e){var r,s;const t=e.title,n=nb(((r=e.detail)==null?void 0:r.trim())??"");if(Qx.test(t))return{icon:"terminal",label:ao(n||t),mono:!0};if((s=e.diff)!=null&&s.unified){const{added:i,removed:a}=Us(e.diff.unified),c=co(e.diff.path??n);return tb.test(t)?{icon:"edit",label:`Deleted ${c}`,mono:!0}:{icon:"edit",label:`+${String(i)} −${String(a)} ${c}`,mono:!0}}return eb.test(t)?{icon:"search",label:`Explored ${co(n||t)}`,mono:!1}:{icon:e.icon,label:n===""?t:`${t}: ${ao(n)}`,mono:!1}}const lo=["indigo","green","violet"];function vt(e){if(e.kind==="human")return"user";let t=0;for(const n of e.handle)t=t*31+n.charCodeAt(0)>>>0;return lo[t%lo.length]??"indigo"}function sb(e){const t=e.replace(/^@/,""),n=t.split(/[\s_-]+/).filter(Boolean);return n.length>=2?`${n[0][0]??""}${n[1][0]??""}`:t.slice(0,2)}function ib(e,t=Date.now()){const n=Date.parse(e);if(!Number.isFinite(n))return"";const r=Math.max(0,Math.floor((t-n)/1e3));if(r<45)return"now";const s=Math.floor(r/60);if(s<60)return`${s}m`;const i=Math.floor(s/60);if(i<24)return`${i}h`;const a=Math.floor(i/24);return a===1?"yesterday":a<7?`${a}d`:new Date(n).toLocaleDateString(void 0,{month:"short",day:"numeric"})}function Ut(e){const t=new Date(e);return Number.isNaN(t.getTime())?"":t.toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"})}const ob=new Intl.NumberFormat(void 0,{notation:"compact",maximumFractionDigits:1});function un(e){return ob.format(e)}function hs(e){return`$${e.toFixed(e>0&&e<.01?4:2)}`}var ab=Qo();function ct(e){const t=e.size??34;return o.jsxs("span",{className:`nx-chip is-${e.accent}`,style:{width:t,height:t,fontSize:Math.round(t*.35)},title:e.title,"aria-hidden":"true",children:[sb(e.name),e.presence&&o.jsx("span",{className:`nx-presence is-${e.presence} on-${e.surface??"surface"}`})]})}function qe(e){const{variant:t="secondary",className:n,children:r,...s}=e;return o.jsx("button",{...s,className:`nx-btn is-${t} ${n??""}`,children:r})}function Se(e){const{icon:t,label:n,size:r="md",variant:s="outline",className:i,...a}=e;return o.jsx("button",{...a,"aria-label":n,title:a.title??n,className:`nx-iconbtn is-${s} is-${r} ${i??""}`,children:o.jsx(t,{"aria-hidden":"true",size:r==="sm"?15:17,strokeWidth:1.75})})}function qs(e){return o.jsx("span",{className:`nx-eyebrow ${e.className??""}`,children:e.children})}function zc(e){return o.jsxs("span",{className:`nx-status is-${e.tone}`,children:[o.jsx("span",{className:"nx-status-dot","aria-hidden":"true"}),e.children]})}function cb(e){return o.jsx("div",{role:"tablist","aria-label":e.label,className:"nx-segmented",children:e.options.map(t=>o.jsx("button",{role:"tab","aria-selected":e.value===t.value,"data-testid":t.testid,className:"nx-segment",onClick:()=>e.onChange(t.value),children:t.label},t.value))})}function lb(e){return o.jsxs("span",{className:"nx-typing",role:"img","aria-label":e.label??"typing",children:[o.jsx("span",{}),o.jsx("span",{}),o.jsx("span",{})]})}function yt(e){const t=x.useRef(null),n=x.useRef(e.onClose);return n.current=e.onClose,x.useEffect(()=>{var c,l;const r=document.activeElement,s=t.current,i=()=>[...(s==null?void 0:s.querySelectorAll('button:not([disabled]), [href], input:not([disabled]), textarea:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])'))??[]];(l=((c=e.initialFocus)==null?void 0:c.current)??i()[0]??s)==null||l.focus();const a=d=>{if(d.key==="Escape"){d.preventDefault(),d.stopPropagation(),n.current();return}if(d.key!=="Tab"||!s)return;const u=i(),h=u[0],m=u.at(-1);!h||!m||(d.shiftKey&&document.activeElement===h?(d.preventDefault(),m.focus()):!d.shiftKey&&document.activeElement===m&&(d.preventDefault(),h.focus()))};return document.addEventListener("keydown",a,!0),()=>{document.removeEventListener("keydown",a,!0),r==null||r.focus()}},[]),typeof document>"u"?null:ab.createPortal(o.jsx("div",{className:"nx-scrim",onPointerDown:r=>{r.target===r.currentTarget&&e.onClose()},children:o.jsx("div",{ref:t,role:e.alert?"alertdialog":"dialog","aria-modal":"true","aria-label":e.label,"data-testid":e.testid,tabIndex:-1,className:`nx-modal ${e.wide?"is-wide":""} ${e.structured?"is-structured":""}`,children:e.children})}),document.body)}function uo(e){return o.jsx("code",{className:"nx-code",children:e.children})}function ub(e){const t=e==null?void 0:e.contextWindowMaxTokens,n=e==null?void 0:e.contextWindowUsedTokens;if(!(t===void 0||n===void 0||!Number.isFinite(t)||!Number.isFinite(n)||t<=0||n<0))return n/t*100}function db(e){return e>90?"red":e>=70?"amber":"normal"}function ho(e,t=0){return o.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 14 14","aria-hidden":"true",children:[o.jsx("circle",{className:"nx-context-meter-track",cx:"7",cy:"7",r:"6",fill:"none"}),!e&&o.jsx("circle",{className:"nx-context-meter-progress",cx:"7",cy:"7",r:"6",fill:"none",pathLength:"100",strokeDasharray:"100",strokeDashoffset:100-t})]})}const hb=x.memo(function({usage:t,pending:n=!1,testId:r}){const s=ub(t);if(s===void 0)return n?o.jsx("span",{className:"nx-context-meter is-pending","data-testid":r,"aria-hidden":"true",children:ho(!0)}):null;const i=Math.max(0,Math.min(100,s)),a=Math.round(s),c=(t==null?void 0:t.contextWindowUsedTokens)??0,l=(t==null?void 0:t.contextWindowMaxTokens)??0,d=t==null?void 0:t.totalCostUsd,u=d!==void 0&&Number.isFinite(d)&&d>0?hs(d):void 0,h=(t==null?void 0:t.estimated)===!0,m=[`Context window · ${h?"≈ ":""}${a}% used`,`${un(c)} / ${un(l)} tokens`,...u===void 0?[]:[`Session cost: ${u}`]].join(" · ");return o.jsx("span",{className:`nx-context-meter is-${db(i)}${h?" is-estimated":""}`,role:"img","aria-label":m,title:m,"data-testid":r,"data-percentage":a,children:ho(!1,i)})});async function fb(e,t,n){const r=n!==void 0?`?cwd=${encodeURIComponent(n)}`:"",s=await fetch(`/api/rooms/${encodeURIComponent(e)}/git-diff${r}`,{headers:{authorization:`Bearer ${t}`}});if(!s.ok)throw new Error(`git-diff request failed: ${String(s.status)}`);return s.json()}const mb={modified:"M",added:"A",deleted:"D",renamed:"R",untracked:"?"},pb=e=>mb[e];function gb(e){const t=e.split("/").filter(Boolean);return t.length<=2?e:`…/${t.slice(-2).join("/")}`}const fs=new Map,ms="nx-gitdiff:",xb=1440*60*1e3,bb=15e5,Ic=(e,t)=>`${e}|${t??""}`;function fo(e,t){const n=Ic(e,t),r=fs.get(n);if(r!==void 0)return r;try{const s=localStorage.getItem(ms+n);if(s===null)return;const i=JSON.parse(s);return typeof i.savedAt!="number"||Date.now()-i.savedAt>xb?void 0:(fs.set(n,i.state),i.state)}catch{return}}function _b(e,t,n){const r=Ic(e,t);fs.set(r,n);try{const s=JSON.stringify({savedAt:Date.now(),state:n});s.length<=bb?localStorage.setItem(ms+r,s):localStorage.removeItem(ms+r)}catch{}}function Lc(e){const t=e.estimated_cost_usd??0,n=e.uncosted_tokens??0,r=(e.cost_usd>0?1:0)+(t>0?1:0)+(n>0?1:0)>1,s=[];return(e.cost_usd>0||t===0&&n===0)&&s.push(`${hs(e.cost_usd)}${r?" exact":""}`),t>0&&s.push(`~${hs(t)} est.`),n>0&&s.push(`${un(n)} unpriced tokens`),s.join(" + ")}const ps="nx-open-diff";function Gr(e){const[t,n]=x.useState("members"),[r,s]=x.useState(),i=x.useRef(0);return x.useEffect(()=>{const a=c=>{var d;const l=(d=c.detail)==null?void 0:d.path;l!==void 0&&(i.current+=1,n("diff"),s({path:l,nonce:i.current}))};return window.addEventListener(ps,a),()=>window.removeEventListener(ps,a)},[]),o.jsxs("aside",{className:"nx-context","aria-label":"Channel context",children:[o.jsx("div",{className:"nx-context-tabs",children:o.jsx(cb,{label:"Context",value:t,onChange:n,options:[{value:"members",label:"Members",testid:"context-tab-members"},{value:"diff",label:"Diff",testid:"context-tab-diff"},{value:"preview",label:"Preview",testid:"context-tab-preview"}]})}),t==="members"&&o.jsx(vb,{room:e.room,token:e.token,connection:e.connection}),t==="diff"&&o.jsx($b,{room:e.room,token:e.token,focus:r}),t==="preview"&&o.jsx(Cb,{room:e.room,token:e.token})]})}function vb(e){var A;const t=H($=>ie($,e.room).members),n=H($=>ie($,e.room).selfMemberId),r=Mp(e.room,e.token),s=sc(e.token),[i,a]=x.useState(!1),[c,l]=x.useState(),[d,u]=x.useState(),h=H($=>ie($,e.room).errors),m=H($=>ie($,e.room).room),p=x.useRef(0),g=n!==void 0?(A=t[n])==null?void 0:A.role:void 0,_=g==="owner"||g==="admin",S=g==="owner"||g==="admin";x.useEffect(()=>{if(c===void 0)return;const $=Fx({handle:c,members:Object.values(t),freshErrors:h.slice(p.current)});$.state==="arrived"?(l(void 0),u(void 0),a(!1)):$.state==="failed"&&(u($.message),l(void 0))},[t,h,c]),x.useEffect(()=>{if(c===void 0)return;const $=setTimeout(()=>{u(`No response for @${c}. It may still be starting — check the roster before retrying.`),l(void 0)},2e4);return()=>{clearTimeout($)}},[c]);const C=x.useMemo(()=>{const $=Object.values(t).filter(k=>k.removed_ts===void 0&&(k.kind==="human"||k.kind==="agent")),I=$.filter(k=>k.kind==="human"),z=$.filter(k=>k.kind==="agent");return[...I,...z]},[t]);return o.jsxs("div",{className:"nx-members",children:[o.jsxs("div",{className:"nx-members-head",children:[o.jsx(qs,{children:"People & agents"}),o.jsx(Se,{icon:dc,label:"Spawn agent",size:"sm",variant:"quiet","data-testid":"spawn-agent",onClick:()=>a(!0)})]}),o.jsx("ul",{className:"nx-roster",children:C.map($=>o.jsx(yb,{member:$,detail:r[$.id],adapters:s.registered,canStop:_,canManage:S,connection:e.connection,room:e.room},$.id))}),i&&o.jsx(Nb,{adapters:s.installed,onRefresh:s.refresh,refreshing:s.refreshing,refreshError:s.refreshError,token:e.token,roomId:e.room,room:m,members:C,pending:c!==void 0,failure:d,onClose:()=>{a(!1),l(void 0),u(void 0)},onSpawn:$=>{p.current=h.length,u(void 0),l($.handle),e.connection.act({act:"spawn",...$})}})]})}function yb(e){const{member:t,detail:n}=e,r=t.state==="running",[s,i]=x.useState(!1),[a,c]=x.useState(),[l,d]=x.useState(!1),[u,h]=x.useState(!1),m=x.useRef(null);x.useEffect(()=>{if(!s)return;const $=I=>{var z;(z=m.current)!=null&&z.contains(I.target)||i(!1)};return document.addEventListener("pointerdown",$),()=>document.removeEventListener("pointerdown",$)},[s]);const p=n==null?void 0:n.spend,g=p!==void 0?p.input_tokens+p.output_tokens:void 0,[_,S]=x.useState(!1),C=H($=>ie($,e.room).errors.length),A=x.useRef(null);return x.useEffect(()=>{const $=A.current;!_||$===null||(C>$.errors||t!==$.member)&&(A.current=null,S(!1))},[_,C,t]),o.jsxs("li",{className:"nx-member","data-testid":`member-${t.handle}`,children:[o.jsxs("div",{className:"nx-member-row",children:[o.jsx(ct,{name:t.handle,accent:vt(t),size:32}),o.jsxs("span",{className:"nx-member-id",children:[o.jsxs("strong",{children:["@",t.handle]}),o.jsx("span",{className:"nx-member-sub",children:t.kind==="human"?t.display_name:[t.harness,t.model,t.policy].filter(Boolean).join(" · ")||"agent"})]}),o.jsx("span",{className:"nx-member-state",children:t.kind==="human"?o.jsx(qs,{children:t.role??"human"}):o.jsx(wb,{state:t.state})}),t.kind==="agent"&&o.jsx(hb,{usage:t.lastUsage,pending:t.state==="running",testId:`member-${t.handle}-context-window`}),t.kind==="agent"&&e.canManage&&o.jsx("button",{type:"button",className:"nx-member-compact","aria-label":`Compact @${t.handle}'s context`,"data-testid":`member-${t.handle}-compact`,disabled:t.state!=="idle"||_,title:r?"Stop the run first — compacting mid-turn would race the engine":t.state!=="idle"?`Only an idle agent can be compacted — @${t.handle} is ${t.state}`:_?"Compacting this agent’s engine session…":"Compact this agent’s engine session","data-compacting":_?"true":void 0,onClick:()=>{A.current={errors:C,member:t},S(!0),e.connection.act({act:"compact_member",member_id:t.id})},children:_?o.jsx(fn,{size:13,className:"nx-spin","aria-hidden":"true"}):o.jsx(Og,{size:13,"aria-hidden":"true"})}),t.kind==="agent"&&r&&e.canStop&&o.jsx("button",{type:"button",className:"nx-member-stop","aria-label":`Stop @${t.handle}`,"data-testid":`member-${t.handle}-stop`,title:"Stop this run (the agent stays alive)",onClick:()=>e.connection.act({act:"interrupt",member_id:t.id}),children:o.jsx(pc,{size:13,"aria-hidden":"true"})}),t.kind==="agent"&&e.canManage&&o.jsxs("div",{className:"nx-member-menu",ref:m,children:[o.jsx(Se,{icon:cc,label:`Actions for @${t.handle}`,size:"sm",variant:"quiet","data-testid":`member-${t.handle}-menu`,onClick:()=>i($=>!$)}),s&&o.jsxs("div",{className:"nx-menu",role:"menu","aria-label":`@${t.handle} actions`,children:[o.jsx("button",{role:"menuitem",onClick:()=>{i(!1),d(!0)},children:"Rename…"}),o.jsx("button",{role:"menuitem",onClick:()=>{i(!1),h(!0)},children:"Configure…"}),t.state==="dead"?o.jsx("button",{role:"menuitem","data-testid":`member-${t.handle}-revive`,onClick:()=>{i(!1),e.connection.act({act:"revive",member_id:t.id})},children:"Revive"}):o.jsx("button",{role:"menuitem",className:"is-danger",onClick:()=>{i(!1),c("kill")},children:"Kill…"}),o.jsx("button",{role:"menuitem",className:"is-danger",onClick:()=>{i(!1),c("remove")},children:"Remove…"})]})]})]}),t.kind==="agent"&&(p!==void 0||((n==null?void 0:n.queued_count)??0)>0)&&o.jsxs("p",{className:"nx-member-meter",children:[g!==void 0?`${un(g)} tokens`:"",p!==void 0?` · ${Lc(p)} · ${p.turns} turns`:"",((n==null?void 0:n.queued_count)??0)>0?` · ${n==null?void 0:n.queued_count} queued`:""]}),t.limits!==void 0&&t.limits.length>0&&o.jsx("p",{className:"nx-member-limits","data-testid":`member-${t.handle}-limits`,children:t.limits.map($=>$.used_percent!==void 0?o.jsx(kb,{limit:$},$.window):o.jsxs("span",{className:`nx-limit is-${$.status??"unknown"}`,children:[Oc($.window),": ",($.status??"reported").replace(/_/g," "),$.resets_at!==void 0?` · resets ${Ut($.resets_at)}`:""]},$.window))}),a!==void 0&&o.jsxs(yt,{label:a==="kill"?`Kill @${t.handle}?`:`Remove @${t.handle}?`,onClose:()=>c(void 0),alert:!0,testid:"member-confirm",children:[o.jsx("h2",{className:"nx-dialog-title",children:a==="kill"?`Kill @${t.handle}?`:`Remove @${t.handle}?`}),o.jsx("p",{className:"nx-dialog-body",children:a==="kill"?"The running session ends now; queued work stays queued and the agent can be revived later.":"The member leaves the roster. Queued work addressed to it is consumed."}),o.jsxs("div",{className:"nx-dialog-actions",children:[o.jsx(qe,{variant:"quiet",onClick:()=>c(void 0),children:"Cancel"}),o.jsx(qe,{variant:"danger","data-testid":"member-confirm-go",onClick:()=>{e.connection.act(a==="kill"?{act:"kill",member_id:t.id}:{act:"remove",member_id:t.id}),c(void 0)},children:a==="kill"?"Kill session":"Remove member"})]})]}),l&&o.jsx(Sb,{member:t,onClose:()=>d(!1),onRename:($,I)=>{e.connection.act({act:"rename",member_id:t.id,handle:$,...I!==""&&{display_name:I}}),d(!1)}}),u&&o.jsx(jb,{member:t,adapters:e.adapters,onClose:()=>h(!1),onConfigure:$=>{e.connection.act({act:"configure",member_id:t.id,...$}),h(!1)}})]})}function Oc(e){return e==="five_hour"?"5h":e==="seven_day"||e==="weekly"?"weekly":e.replace(/_/g," ")}function kb(e){const t=Math.max(0,Math.round(100-(e.limit.used_percent??0))),n=t<15?"error":t<40?"warn":"ok";return o.jsxs("span",{className:`nx-gauge is-${n}`,title:e.limit.resets_at!==void 0?`resets ${Ut(e.limit.resets_at)}`:void 0,children:[o.jsx("span",{className:"nx-gauge-label",children:Oc(e.limit.window)}),o.jsx("span",{className:"nx-gauge-track","aria-hidden":"true",children:o.jsx("span",{className:"nx-gauge-fill",style:{width:`${t}%`}})}),o.jsxs("span",{className:"nx-gauge-value",children:[t,"% left"]})]})}function wb(e){const t=e.state==="running"||e.state==="queued"?"live":e.state==="dead"?"error":"neutral",n=e.state==="running"||e.state==="queued"?"Working":e.state==="dead"?"Dead":e.state==="awaiting_input"?"Waiting":"Idle";return o.jsx(zc,{tone:t,children:n})}function Sb(e){const[t,n]=x.useState(e.member.handle),[r,s]=x.useState(e.member.display_name);return o.jsxs(yt,{label:`Rename @${e.member.handle}`,onClose:e.onClose,testid:"rename-dialog",children:[o.jsxs("h2",{className:"nx-dialog-title",children:["Rename @",e.member.handle]}),o.jsxs("label",{className:"nx-field",children:["Handle",o.jsx("input",{value:t,onChange:i=>n(i.target.value),"data-testid":"rename-handle"})]}),o.jsxs("label",{className:"nx-field",children:["Display name",o.jsx("input",{value:r,onChange:i=>s(i.target.value)})]}),o.jsxs("div",{className:"nx-dialog-actions",children:[o.jsx(qe,{variant:"quiet",type:"button",onClick:e.onClose,children:"Cancel"}),o.jsx(qe,{variant:"primary",disabled:t.trim()==="",onClick:()=>e.onRename(t.trim(),r.trim()),children:"Rename"})]})]})}function jb(e){const[t,n]=x.useState({harness:e.member.harness??"",model:e.member.model??"",thinking:e.member.thinking??"",policy:Ix(e.member.policy)}),r=s=>{s.preventDefault();const i=e.adapters.find(a=>a.id===t.harness);e.onConfigure({model:t.model===""?null:t.model,thinking:Er(i,t.thinking)??null,...t.policy!==""&&{policy:t.policy}}),e.onClose()};return o.jsx(yt,{label:"Configure agent",onClose:e.onClose,testid:"configure-dialog",structured:!0,children:o.jsxs("form",{onSubmit:r,children:[o.jsxs("div",{className:"nx-dialog-head",children:[o.jsxs("div",{children:[o.jsxs("h2",{className:"nx-dialog-title",children:["Configure @",e.member.handle]}),o.jsx("p",{className:"nx-dialog-sub",children:"Applies to this agent's next turn."})]}),o.jsx("button",{type:"button",className:"nx-dialog-close","aria-label":"Close configure agent","data-testid":"configure-close",onClick:e.onClose,children:o.jsx($t,{size:16,"aria-hidden":"true"})})]}),o.jsx("div",{className:"nx-dialog-body",children:o.jsx(Fs,{adapters:e.adapters,config:t,onChange:n,lockHarness:!0,behaviourSection:1,permissionsSection:2,idPrefix:"configure"})}),o.jsxs("div",{className:"nx-dialog-actions",children:[o.jsx(qe,{variant:"quiet",type:"button",onClick:e.onClose,children:"Cancel"}),o.jsx(qe,{variant:"primary",type:"submit","data-testid":"configure-go",children:"Save"})]})]})})}function Nb(e){var I;const[t,n]=x.useState({harness:"",model:"",thinking:"",policy:pr}),[r,s]=x.useState(""),i=zx(e.room,e.members),[a,c]=x.useState(i!==""),[l,d]=x.useState(i),u=a?i:l,[h,m]=x.useState(""),p=x.useRef(null),g=Tc(t.harness,e.adapters);x.useEffect(()=>{t.harness!==g&&n(Nc(t,g,e.adapters))},[t,g,e.adapters]);const _=Lx(e.members),S=r.trim(),C=jc(S,_),A=g!==""&&S!==""&&u.trim()!==""&&!C&&!e.pending,$=z=>{z.preventDefault(),A&&e.onSpawn(qx({config:{...t,harness:g},handle:S,cwd:u,purpose:h,adapters:e.adapters,members:e.members}))};return o.jsx(yt,{label:"Spawn agent",onClose:e.onClose,testid:"spawn-dialog",initialFocus:p,structured:!0,children:o.jsxs("form",{onSubmit:$,children:[o.jsxs("div",{className:"nx-dialog-head",children:[o.jsxs("div",{className:"nx-dialog-headings",children:[o.jsx("span",{className:"nx-dialog-icon","aria-hidden":"true",children:o.jsx(tn,{size:19})}),o.jsxs("div",{children:[o.jsx("h2",{className:"nx-dialog-title",children:"Spawn agent"}),o.jsxs("p",{className:"nx-dialog-sub",children:["Into ",o.jsxs("code",{className:"nx-mono",children:["#",((I=e.room)==null?void 0:I.name)??e.roomId]})]})]})]}),o.jsx("button",{type:"button",className:"nx-dialog-close","aria-label":"Close spawn agent","data-testid":"spawn-close",onClick:e.onClose,children:o.jsx($t,{size:16,"aria-hidden":"true"})})]}),o.jsxs("div",{className:"nx-dialog-body",children:[o.jsxs(ln,{n:1,title:"Identity",children:[o.jsx(Zs,{adapters:e.adapters,config:{...t,harness:g},onChange:n,idPrefix:"spawn",onRefresh:e.onRefresh,refreshing:e.refreshing,refreshError:e.refreshError}),o.jsxs("label",{className:"nx-field",children:[o.jsx("span",{className:"nx-label",children:"Handle"}),o.jsx("input",{ref:p,value:r,pattern:Rx,maxLength:31,onChange:z=>s(z.target.value),placeholder:"e.g. scout",required:!0,"data-testid":"spawn-handle"})]}),C&&o.jsxs("p",{className:"nx-field-error",role:"alert","data-testid":"spawn-owner-clash",children:["@",S," is already in use by the channel owner."]}),o.jsxs("div",{className:"nx-field",children:[o.jsx("span",{className:"nx-label",children:"Working directory"}),o.jsxs("label",{className:"nx-switch-row",children:[o.jsx("input",{type:"checkbox",role:"switch",checked:a,onChange:z=>{c(z.target.checked)},"data-testid":"spawn-use-current-dir"}),o.jsx("span",{children:"Use current directory"})]}),a?i!==""&&o.jsxs("span",{className:"nx-field-note","data-testid":"spawn-inherited-cwd",children:["Inherits ",i]}):o.jsx(Rc,{token:e.token,value:l,onChange:d,idPrefix:"spawn"})]}),o.jsx(Vx,{idPrefix:"spawn",onApply:z=>{const k=Px({preset:z,config:{...t,harness:g},adapters:e.adapters,members:e.members});n(k.config),s(k.handle),m(k.purpose)}})]}),o.jsx(Fs,{adapters:e.adapters,config:{...t,harness:g},onChange:n,hideHarness:!0,behaviourSection:2,permissionsSection:3,idPrefix:"spawn"}),o.jsx(ln,{n:4,title:"Purpose",children:o.jsxs("label",{className:"nx-field",children:[o.jsxs("span",{className:"nx-label",children:["Purpose ",o.jsx("span",{className:"nx-opt",children:"· optional"})]}),o.jsx("textarea",{value:h,rows:3,onChange:z=>m(z.target.value),placeholder:"What this agent should focus on…","data-testid":"spawn-purpose"})]})}),e.failure!==void 0&&o.jsx("p",{className:"nx-field-error",role:"alert","data-testid":"spawn-error",children:e.failure})]}),o.jsxs("div",{className:"nx-dialog-actions",children:[o.jsx(qe,{variant:"quiet",type:"button",onClick:e.onClose,children:"Cancel"}),o.jsx(qe,{variant:"primary",type:"submit",disabled:!A,"data-testid":"spawn-go",children:e.pending?"Spawning…":"Spawn agent"})]})]})})}function Tb(e,t){const n=H(c=>ie(c,e).messages),[r,s]=x.useState([]),i=x.useRef(new Set),a=x.useRef(new Map);return x.useEffect(()=>{const c=Ap(n).filter(d=>d.kind==="run"&&d.run!==void 0&&d.run.status!=="running").slice(-20);let l=!1;return(async()=>{let d=!1;for(const h of c)if(!i.current.has(h.id)){i.current.add(h.id);try{const m=await da(e,h.id,{token:t()});a.current.set(h.id,Cc(m.map((p,g)=>({index:g,event:p})))),d=!0}catch{}}if(!d||l)return;const u=[];for(const[h,m]of[...a.current.entries()].sort(([p],[g])=>p-g))for(const p of m)p.image!==void 0&&u.push({msgId:h,...p.image});s(u)})(),()=>{l=!0}},[n,e,t]),{images:r}}function Eb(e,t,n,r){const s=H(m=>ie(m,e).messages),i=x.useMemo(()=>Object.values(s).filter(m=>m.kind==="run"&&m.run!==void 0&&m.run.status!=="running").length,[s]),[a,c]=x.useState(()=>fo(e,n)),[l,d]=x.useState(!1),[u,h]=x.useState(!0);return x.useEffect(()=>{let m=!1;const p=fo(e,n);return c(p),d(!1),h(!0),fb(e,t(),n).then(g=>{m||(_b(e,n,g),c(g),h(!1))}).catch(()=>{m||(h(!1),p===void 0&&d(!0))}),()=>{m=!0}},[e,t,n,r,i]),{state:a,failed:l,refreshing:u}}function $b(e){const[t,n]=x.useState(),[r,s]=x.useState(0),[i,a]=x.useState(),{state:c,failed:l,refreshing:d}=Eb(e.room,e.token,t,r);if(x.useEffect(()=>{e.focus!==void 0&&a(e.focus.path)},[e.focus]),l)return o.jsx(or,{testid:"diff-error",children:"Couldn’t read the repository."});if(c===void 0)return o.jsx(or,{testid:"diff-loading",children:d?"Reading the working tree…":"No repository."});const u=c.files,h=i!==void 0&&!u.some(p=>p.path===i),m=u.find(p=>p.path===i)??u[0];return o.jsxs("div",{className:"nx-diff",children:[d&&o.jsxs("span",{className:"nx-diff-refreshing","data-testid":"diff-refreshing",children:[o.jsx(fn,{className:"nx-spin",size:12,"aria-hidden":"true"})," Refreshing…"]}),o.jsxs("div",{className:"nx-diff-toolbar",children:[c.cwds.length>1&&o.jsx("select",{className:"nx-diff-cwd","data-testid":"diff-cwd","aria-label":"Working directory",value:c.selected??"",onChange:p=>{n(p.target.value),a(void 0)},children:c.cwds.map(p=>o.jsx("option",{value:p,children:gb(p)},p))}),o.jsx("button",{type:"button",className:"nx-diff-refresh","data-testid":"diff-refresh",onClick:()=>s(p=>p+1),children:"Refresh"})]}),u.length===0&&!h&&o.jsx(or,{testid:"diff-clean",children:"Working tree clean — no uncommitted changes."}),u.length>0&&o.jsx("ul",{className:"nx-diff-files","data-testid":"diff-files",children:u.map(p=>o.jsx("li",{children:o.jsxs("button",{className:`nx-diff-file ${p===m&&!h?"is-active":""}`,onClick:()=>a(p.path),children:[o.jsx("span",{className:`nx-diff-status is-${p.status}`,title:p.status,children:pb(p.status)}),o.jsx("span",{className:"nx-diff-path",children:p.path}),o.jsxs("span",{className:"nx-diff-stat",children:[o.jsxs("em",{className:"is-add",children:["+",p.additions]})," ",o.jsxs("em",{className:"is-del",children:["−",p.deletions]})]})]})},p.path))}),h?o.jsxs("p",{className:"nx-diff-note","data-testid":"diff-no-current",children:["No current changes for ",i,"."]}):m!==void 0&&o.jsx(Rb,{diff:{path:m.path,unified:m.diff}})]})}function Rb(e){const t=x.useMemo(()=>e.diff.unified.split(`
|
|
335
|
+
`),[e.diff.unified]);return o.jsx("pre",{className:"nx-diff-view","data-testid":"diff-view",children:t.map((n,r)=>{const s=n.startsWith("@@")?"hunk":n.startsWith("+++")||n.startsWith("---")?"meta":n.startsWith("+")?"add":n.startsWith("-")?"del":"ctx";return o.jsx("span",{className:`nx-diff-line is-${s}`,children:n||" "},r)})})}function Cb(e){const{images:t}=Tb(e.room,e.token),n=t.at(-1);return n===void 0?o.jsx(or,{testid:"preview-empty",children:"Nothing to preview yet — artifacts agents produce appear here."}):o.jsxs("div",{className:"nx-preview",children:[o.jsx("img",{src:`data:${n.media_type};base64,${n.data_b64}`,alt:`Artifact from turn #${n.msgId}`}),o.jsxs("p",{className:"nx-preview-meta",children:["from ",o.jsxs("a",{href:`#${n.msgId}`,children:["#",n.msgId]})]})]})}function or(e){return o.jsxs("div",{className:"nx-context-empty","data-testid":e.testid,children:[o.jsx("div",{className:"nx-dotgrid","aria-hidden":"true"}),o.jsx("p",{children:e.children})]})}const mo=25*1024*1024,po=8;async function Ab(e,t,n){const r=await fetch(`/api/rooms/${encodeURIComponent(e)}/attachments?name=${encodeURIComponent(n.name)}`,{method:"POST",headers:{authorization:`Bearer ${t}`,"content-type":n.type||"application/octet-stream"},body:n});if(!r.ok){const s=await r.json().catch(()=>({}));throw new Error(s.error??`upload failed (${String(r.status)})`)}return r.json()}const zb=(e,t,n)=>`/api/rooms/${encodeURIComponent(e)}/attachments/${encodeURIComponent(t)}?token=${encodeURIComponent(n)}`,Ib=e=>/^image\/(png|jpe?g|gif|webp|avif)$/.test(e);function Pc(e){return e<1024?`${String(e)} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}const Lb=8,go="nx-quote";function Ob(e,t){const n=e.slice(0,t),r=n.lastIndexOf("@");if(r===-1||r>0&&!/[\s(]/.test(n[r-1]??""))return;const s=n.slice(r+1);if(/^[a-z0-9_-]*$/i.test(s))return{start:r,query:s}}function xo(e){const t=Nr(),n=H(T=>T.connected),r=H(T=>ie(T,e.room)),s=r.members,i=r.room,a=r.hydrated,[c,l]=x.useState(""),[d,u]=x.useState(),[h,m]=x.useState(),[p,g]=x.useState(),[_,S]=x.useState(0),[C,A]=x.useState([]),[$,I]=x.useState(!1),z=x.useRef(null),k=x.useRef(null),E=x.useRef(!1),L=x.useRef();x.useLayoutEffect(()=>{Ce()},[c]),x.useLayoutEffect(()=>{const T=L.current;if(T===void 0)return;L.current=void 0;const B=z.current;B&&(B.setSelectionRange(T,T),B.focus(),ut())},[c]);const J=x.useMemo(()=>Object.values(s).filter(T=>T.removed_ts===void 0&&T.kind!=="extension"),[s]),ce=x.useMemo(()=>{if(!p)return[];const T=p.query.toLowerCase();return J.filter(B=>B.handle.toLowerCase().startsWith(T)).slice(0,6)},[p,J]),Z=x.useMemo(()=>Lp(r),[r]);x.useEffect(()=>{if(E.current||Z===void 0)return;const T=`@${Z.handle} `;c!==T&&l(T)},[c,Z]),x.useEffect(()=>{const T=B=>{var Ye;const U=B.detail,le=typeof U=="string"?U:U.text;typeof U!="string"&&u(U.replyTo),E.current=!0,l(Ke=>`${Ke!==""&&!Ke.endsWith(`
|
|
336
|
+
`)?`${Ke}
|
|
337
|
+
`:Ke}${le}
|
|
338
|
+
`),(Ye=z.current)==null||Ye.focus(),requestAnimationFrame(Ce)};return window.addEventListener(go,T),()=>window.removeEventListener(go,T)},[]);const Y=n&&a&&!$&&(c.trim().length>0||C.length>0),G=T=>{if(T.length===0)return;let B=T;B.some(le=>le.size>mo)&&(m("Files must be under 25 MB"),B=B.filter(le=>le.size<=mo));const U=po-C.length;B.length>U&&(m(`Up to ${String(po)} files per message`),B=B.slice(0,Math.max(0,U))),B.length!==0&&(I(!0),(async()=>{try{for(const le of B){const Ye=await Ab(e.room,e.token(),le);A(Ke=>[...Ke,Ye])}}catch(le){m(le instanceof Error?le.message:"Upload failed")}finally{I(!1)}})())},oe=T=>{A(B=>B.filter(U=>U.id!==T))},Ce=()=>{const T=z.current;if(!T)return;T.style.height="auto";const B=getComputedStyle(T),U=parseFloat(B.lineHeight)||24,le=parseFloat(B.paddingTop)+parseFloat(B.paddingBottom),Ye=Math.round(U*Lb+(Number.isFinite(le)?le:0));T.style.height=`${Math.min(T.scrollHeight,Ye)}px`},ut=()=>{const T=z.current;T&&(g(Ob(T.value,T.selectionStart??T.value.length)),S(0))},De=T=>{if(!p)return;E.current=!0;const B=z.current,U=(B==null?void 0:B.selectionStart)??c.length,le=`${c.slice(0,p.start)}@${T.handle} ${c.slice(U)}`;l(le),g(void 0),L.current=p.start+T.handle.length+2},kt=()=>{var U;const T=(((U=z.current)==null?void 0:U.value)??c).trim();if(!n||!a||$||T.length===0&&C.length===0)return;if(!J.some(le=>new RegExp(`@${le.handle}\\b`,"i").test(T))&&J.some(le=>le.kind==="agent")){m(Z?`Say who this is for — try @${Z.handle}`:"Say who this is for — mention someone with @");return}e.connection.post(T,{...d!==void 0&&{replyTo:d},...C.length>0&&{attachments:C.map(le=>le.id)}}),l(""),u(void 0),A([]),m(void 0),E.current=!1,g(void 0),requestAnimationFrame(Ce)};return o.jsxs("footer",{className:"nx-composer",onDragOver:T=>{T.preventDefault()},onDrop:T=>{T.preventDefault(),G(Array.from(T.dataTransfer.files))},children:[d!==void 0&&o.jsxs("p",{className:"nx-composer-reply","data-testid":"composer-reply",children:["Replying to #",d,o.jsx("button",{type:"button","aria-label":"Cancel reply",onClick:()=>u(void 0),children:o.jsx($t,{size:12,"aria-hidden":"true"})})]}),h!==void 0&&o.jsx("p",{className:"nx-composer-hint",role:"alert","data-testid":"composer-hint",children:h}),o.jsx("input",{ref:k,type:"file",multiple:!0,hidden:!0,"data-testid":"composer-file",onChange:T=>{G(Array.from(T.target.files??[])),T.target.value=""}}),C.length>0&&o.jsx("ul",{className:"nx-attach-tray","data-testid":"attach-tray",children:C.map(T=>o.jsxs("li",{className:"nx-attach-chip","data-testid":`pending-${T.id}`,children:[o.jsx("span",{className:"nx-attach-name",children:T.name}),o.jsx("span",{className:"nx-attach-size",children:Pc(T.size)}),o.jsx("button",{type:"button",className:"nx-attach-remove","aria-label":`Remove ${T.name}`,"data-testid":`pending-${T.id}-remove`,onClick:()=>oe(T.id),children:o.jsx($t,{size:13,"aria-hidden":"true"})})]},T.id))}),o.jsxs("div",{className:"nx-composer-bar",children:[p&&ce.length>0&&o.jsx("ul",{className:"nx-mentions",role:"listbox","aria-label":"Mention someone","data-testid":"mention-popover",children:ce.map((T,B)=>o.jsx("li",{role:"presentation",children:o.jsxs("button",{role:"option","aria-selected":B===_,className:`nx-mention ${B===_?"is-active":""}`,onMouseEnter:()=>S(B),onMouseDown:U=>{U.preventDefault(),De(T)},children:[o.jsx(ct,{name:T.handle,accent:vt(T),size:24}),o.jsxs("span",{className:"nx-mention-handle",children:["@",T.handle]}),o.jsx("span",{className:"nx-mention-kind",children:T.kind})]})},T.id))}),o.jsx("textarea",{ref:z,className:"nx-composer-input","data-testid":"composer-input",placeholder:n?`Message ${(i==null?void 0:i.name)??e.room}…`:"Reconnecting…","aria-label":"Message",rows:1,value:c,onBeforeInput:()=>{E.current=!0},onChange:T=>{E.current=!0,l(T.target.value),m(void 0),Ce(),requestAnimationFrame(ut)},onClick:ut,onKeyDown:T=>{if(!(t&&T.key==="Enter")){if(p&&ce.length>0){if(T.key==="ArrowDown"||T.key==="ArrowUp"){T.preventDefault(),S(B=>{const U=T.key==="ArrowDown"?1:-1;return(B+U+ce.length)%ce.length});return}if(T.key==="Enter"||T.key==="Tab"){T.preventDefault(),De(ce[_]??ce[0]);return}if(T.key==="Escape"){g(void 0);return}}T.key==="Enter"&&!T.shiftKey&&!T.nativeEvent.isComposing&&(T.preventDefault(),kt())}},onBlur:()=>g(void 0),onPaste:T=>{const B=Array.from(T.clipboardData.files);B.length>0&&(T.preventDefault(),G(B))}}),t?o.jsxs("div",{className:"nx-composer-row2",children:[o.jsx(Se,{icon:cs,label:"Attach files",variant:"quiet","data-testid":"composer-attach",onClick:()=>{var T;return(T=k.current)==null?void 0:T.click()}}),o.jsx(Se,{icon:eg,label:"Mention someone",variant:"quiet","data-testid":"composer-at",onClick:()=>{const T=z.current;if(!T)return;E.current=!0;const B=T.selectionStart??c.length,U=B===0||/\s/.test(c[B-1]??"")?"":" ";l(`${c.slice(0,B)}${U}@${c.slice(B)}`),L.current=B+U.length+1}}),o.jsx("span",{className:"nx-composer-spacer"}),o.jsx(Se,{icon:as,label:"Send message",variant:"solid",className:"nx-composer-send","data-testid":"composer-send",disabled:!Y,onClick:kt})]}):o.jsxs(o.Fragment,{children:[o.jsx(Se,{icon:cs,label:"Attach files",variant:"quiet",className:"nx-composer-attach","data-testid":"composer-attach",onClick:()=>{var T;return(T=k.current)==null?void 0:T.click()}}),o.jsx(Se,{icon:as,label:"Send message",variant:"solid",className:"nx-composer-send","data-testid":"composer-send",disabled:!Y,onClick:kt})]})]})]})}function Pb(e){const t=H(G=>G.activeRoom),n=H(G=>ie(G,t).members),r=H(G=>ie(G,t).selfMemberId),s=sc(e.token),i=s.installed,[a,c]=x.useState(""),[l,d]=x.useState(""),[u,h]=x.useState({harness:"",model:"",thinking:"",policy:pr}),m=x.useRef(),[p,g]=x.useState("codor"),[_,S]=x.useState(!1),[C,A]=x.useState(),[$,I]=x.useState(),z=zp(n,r),k=u.harness,E=G=>{if(G.harness===""){u.harness!==""&&(m.current=u),h(G);return}const oe=m.current;if(u.harness===""&&(oe==null?void 0:oe.harness)===G.harness){h(oe);return}h(G)};x.useEffect(()=>{u.harness===""||i.some(G=>G.id===u.harness)||(m.current=u,h({...u,harness:"",model:"",thinking:""}))},[i,u]);const L=p.trim()===""?"Agent":p.trim(),J=x.useMemo(()=>zm(L),[L]),ce=k!==""&&J!==void 0&&jc(J,z),Z=a.trim()!==""&&l.trim()!==""&&z!==void 0&&!_&&!ce&&(k===""||J!==void 0),Y=()=>{!Z||z===void 0||(S(!0),A(void 0),I(void 0),Bl({name:a.trim(),owner:{handle:z.handle,display_name:z.display_name},cwd:l.trim(),...k!==""&&J!==void 0&&{starting_agent:{harness:k,handle:J,display_name:L,policy:u.policy===""?pr:u.policy,...u.model!==""&&{model:u.model},...(()=>{const G=Er(i.find(oe=>oe.id===k),u.thinking);return G===void 0?{}:{thinking:G}})()}}},{token:e.token()}).then(G=>e.onCreated(G),G=>{const oe=G instanceof Error?G.message:String(G);Ux(oe)?I(oe):A(oe)}).finally(()=>S(!1)))};return o.jsx(yt,{label:"Create channel",onClose:e.onClose,testid:"create-channel-dialog",structured:!0,children:o.jsxs("form",{onSubmit:G=>{G.preventDefault(),Y()},children:[o.jsxs("div",{className:"nx-dialog-head",children:[o.jsxs("div",{className:"nx-dialog-headings",children:[o.jsx("span",{className:"nx-dialog-icon","aria-hidden":"true",children:o.jsx(Sg,{size:19})}),o.jsxs("div",{children:[o.jsx("h2",{className:"nx-dialog-title",children:"Create channel"}),o.jsx("p",{className:"nx-dialog-sub",children:"A workspace for a task and its agents."})]})]}),o.jsx("button",{type:"button",className:"nx-dialog-close","aria-label":"Close create channel","data-testid":"create-close",onClick:e.onClose,children:o.jsx($t,{size:16,"aria-hidden":"true"})})]}),o.jsxs("div",{className:"nx-dialog-body",children:[o.jsxs(ln,{n:1,title:"Workspace",children:[o.jsxs("label",{className:"nx-field",children:[o.jsx("span",{className:"nx-label",children:"Name"}),o.jsx("input",{value:a,required:!0,onChange:G=>c(G.target.value),placeholder:"e.g. Engineering","data-testid":"create-name"}),a.trim()!==""&&o.jsxs("span",{className:"nx-field-note",children:["id: ",o.jsx(uo,{children:$m(a)})]})]}),o.jsxs("div",{className:"nx-field",children:[o.jsxs("span",{className:"nx-label",children:["Working folder ",o.jsx("span",{className:"nx-req",children:"· required"})]}),o.jsx(Rc,{token:e.token,value:l,onChange:d,idPrefix:"create"})]})]}),o.jsx(ln,{n:2,title:"Starting agent",children:o.jsxs("div",{className:"nx-agent-panel",children:[o.jsx(Zs,{adapters:i,config:u,onChange:E,allowNone:!0,optional:!0,idPrefix:"create",onRefresh:s.refresh,refreshing:s.refreshing,refreshError:s.refreshError}),k===""&&o.jsx("p",{className:"nx-field-note","data-testid":"create-agent-none-note",children:"You can add an agent later."}),k!==""&&o.jsxs(o.Fragment,{children:[o.jsxs("label",{className:"nx-field",children:[o.jsx("span",{className:"nx-label",children:"Agent name"}),o.jsx("input",{value:p,onChange:G=>g(G.target.value),placeholder:"e.g. Scout","data-testid":"create-agent-name"}),$!==void 0&&o.jsx("span",{className:"nx-field-note is-error",role:"alert","data-testid":"create-agent-error",children:$}),p.trim()!==""&&(J!==void 0?o.jsxs("span",{className:"nx-field-note",children:["joins as ",o.jsxs(uo,{children:["@",J]})]}):o.jsx("span",{className:"nx-field-note is-error",children:"that name resolves to a reserved handle — pick another"})),ce&&o.jsxs("span",{className:"nx-field-note is-error","data-testid":"create-owner-clash",children:["@",J," is already in use by the channel owner."]})]}),o.jsx(Fs,{adapters:i,config:u,onChange:h,hideHarness:!0,behaviourSection:3,permissionsSection:4,embedded:!0,idPrefix:"create"})]})]})}),C!==void 0&&o.jsx("p",{className:"nx-field-note is-error",role:"alert",children:C})]}),o.jsxs("div",{className:"nx-dialog-actions",children:[o.jsx(qe,{variant:"quiet",type:"button",onClick:e.onClose,children:"Cancel"}),o.jsx(qe,{variant:"primary",type:"submit",disabled:!Z,"data-testid":"create-go",children:_?"Creating…":"Create channel"})]})]})})}const Mb=[],gs="nx-jump-anchor";async function Bs(e,t,n){const r=ie(H.getState(),e);for(let s=0;s<10&&ie(H.getState(),e).messages[t]===void 0;s++){const i=ie(H.getState(),e).historyCursor??r.historyCursor;if(i===void 0||i<=1)break;try{const a=await ua(e,{before:i,limit:Ln},{token:n()});if(a.messages.length===0)break;H.getState().mergeHistoryPage(e,a.messages)}catch{break}}window.location.hash=`#${t}`;for(let s=0;s<30;s+=1){const i=document.getElementById(String(t));if(i!==null){i.scrollIntoView({block:"center"}),window.dispatchEvent(new CustomEvent(gs,{detail:{room:e,id:t}}));break}await new Promise(a=>requestAnimationFrame(()=>a()))}}function bo(e){const t=H(i=>ie(i,e.room).inbox),n=H(i=>ie(i,e.room).members),r=H(i=>ie(i,e.room).messages),s=x.useMemo(()=>Ip(t),[t]);return s.length===0?null:o.jsx("div",{className:"nx-holds","data-testid":"hold-banner",children:s.map(i=>{const a=n[i.recipient],c=r[i.message_id];return o.jsxs("div",{className:"nx-hold",children:[o.jsx(fg,{size:16,"aria-hidden":"true"}),o.jsxs("span",{className:"nx-hold-text",children:["Held for ",o.jsxs("strong",{children:["@",(a==null?void 0:a.handle)??"…"]}),c!==void 0?` — “${(c.body.split(`
|
|
339
|
+
`,1)[0]??"").slice(0,80)}”`:""]}),o.jsxs("span",{className:"nx-hold-actions",children:[o.jsx(qe,{variant:"secondary","data-testid":`hold-${i.id}-release`,onClick:()=>e.connection.act({act:"release_hold",delivery_id:i.id}),children:"Release"}),o.jsx(qe,{variant:"quiet","data-testid":`hold-${i.id}-redeliver`,onClick:()=>e.connection.act({act:"redeliver",delivery_id:i.id}),children:"Redeliver"})]})]},i.id)})})}function Db(e){const[t,n]=x.useState(!1),r=H(a=>ie(a,e.room).support),s=(r==null?void 0:r.inbox)??Mb,i=s.length;return o.jsxs("span",{className:"nx-inbox-wrap",children:[o.jsxs("span",{className:"nx-badge-anchor",children:[o.jsx(Se,{icon:Ag,label:`Inbox — ${i} unread`,"data-testid":"inbox-toggle",onClick:()=>n(a=>!a)}),i>0&&o.jsx("span",{className:"nx-badge","data-testid":"inbox-badge",children:i>99?"99+":i})]}),t&&o.jsx(Zb,{rows:s,onClose:()=>n(!1),onMarkAllRead:()=>{for(const a of s)e.connection.act({act:"mark_read",delivery_id:a.delivery.id});n(!1)},onOpenRow:a=>{e.connection.act({act:"mark_read",delivery_id:a.delivery.id}),n(!1),Bs(e.room,a.delivery.message_id,e.token)}})]})}function Zb(e){const t=x.useRef(null);return x.useEffect(()=>{const n=s=>{var i;(i=t.current)!=null&&i.contains(s.target)||e.onClose()},r=s=>{s.key==="Escape"&&e.onClose()};return document.addEventListener("pointerdown",n),document.addEventListener("keydown",r),()=>{document.removeEventListener("pointerdown",n),document.removeEventListener("keydown",r)}},[]),o.jsxs("div",{ref:t,className:"nx-inbox",role:"dialog","aria-label":"Inbox","data-testid":"inbox-panel",children:[o.jsxs("header",{className:"nx-inbox-head",children:[o.jsx("strong",{children:"Needs you"}),e.rows.length>0&&o.jsx("button",{className:"nx-inbox-clear","data-testid":"inbox-mark-all",onClick:e.onMarkAllRead,children:"Mark all read"}),o.jsx(Se,{icon:$t,label:"Close inbox",size:"sm",variant:"quiet",onClick:e.onClose})]}),e.rows.length===0?o.jsx("p",{className:"nx-inbox-empty","data-testid":"inbox-empty",children:"Nothing needs you."}):o.jsx("ul",{className:"nx-inbox-list",children:e.rows.map(n=>o.jsx("li",{children:o.jsxs("button",{className:"nx-inbox-row","data-testid":`inbox-row-${n.delivery.id}`,onClick:()=>e.onOpenRow(n),children:[o.jsxs("strong",{children:["@",n.author_handle]}),o.jsx("span",{className:"nx-inbox-preview",children:n.preview||n.message_kind}),o.jsx("time",{children:Ut(n.ts)})]})},n.delivery.id))})]})}function Fb(e){const[t,n]=x.useState(""),[r,s]=x.useState(),[i,a]=x.useState(!1),c=H(d=>ie(d,e.room).members),l=x.useRef(null);return x.useEffect(()=>{const d=t.trim();if(d.length<2){s(void 0);return}a(!0);const u=setTimeout(()=>{Vl(e.room,d,{token:e.token()}).then(h=>s(h)).catch(()=>s([])).finally(()=>a(!1))},250);return()=>clearTimeout(u)},[t,e.room,e.token]),o.jsxs(yt,{label:"Search messages",onClose:e.onClose,testid:"search-overlay",initialFocus:l,children:[o.jsxs("div",{className:"nx-search-box",children:[o.jsx(Tr,{size:16,"aria-hidden":"true"}),o.jsx("input",{ref:l,"data-testid":"search-input",placeholder:"Search this channel…","aria-label":"Search this channel",value:t,onChange:d=>n(d.target.value)})]}),i&&o.jsx("p",{className:"nx-search-note",children:"Searching…"}),r!==void 0&&!i&&(r.length===0?o.jsx("p",{className:"nx-search-note","data-testid":"search-empty",children:"No matches."}):o.jsx("ul",{className:"nx-search-results","data-testid":"search-results",children:r.map(d=>{var u;return o.jsx("li",{children:o.jsxs("button",{className:"nx-search-row","data-testid":`search-hit-${d.id}`,onClick:()=>{e.onClose(),Bs(e.room,d.id,e.token)},children:[o.jsxs("strong",{children:["@",((u=c[d.author])==null?void 0:u.handle)??"…"]}),o.jsx("span",{className:"nx-search-body",children:(d.body.split(`
|
|
340
|
+
`,1)[0]??"").slice(0,110)}),o.jsxs("span",{className:"nx-search-meta",children:["#",d.id," · ",Ut(d.ts)]})]})},d.id)})}))]})}function Ub({status:e,trigger:t,preTokens:n}){return e==="loading"?"Compacting…":t==="auto"?"Context automatically compacted":t==="manual"?"Context manually compacted":n!==void 0?`Context compacted (${un(n)} tokens)`:"Context compacted"}function Mc(e){const t=Ub(e);return o.jsxs("div",{className:`nx-compaction is-${e.status}`,role:"separator","aria-label":t,title:t,"data-testid":"compaction-marker","data-status":e.status,"data-trigger":e.trigger,"data-pre-tokens":e.preTokens,children:[o.jsx("span",{className:"nx-compaction-line","aria-hidden":"true"}),o.jsxs("span",{className:"nx-compaction-label","aria-hidden":"true",children:[e.status==="loading"?o.jsx(fn,{className:"nx-spin",size:13}):o.jsx(Qg,{size:13}),o.jsx("span",{children:t})]}),o.jsx("span",{className:"nx-compaction-line","aria-hidden":"true"})]})}/*! @license DOMPurify 3.4.12 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.4.12/LICENSE */function _o(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function qb(e){if(Array.isArray(e))return e}function Bb(e,t){var n=e==null?null:typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(n!=null){var r,s,i,a,c=[],l=!0,d=!1;try{if(i=(n=n.call(e)).next,t!==0)for(;!(l=(r=i.call(n)).done)&&(c.push(r.value),c.length!==t);l=!0);}catch(u){d=!0,s=u}finally{try{if(!l&&n.return!=null&&(a=n.return(),Object(a)!==a))return}finally{if(d)throw s}}return c}}function Hb(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
|
|
341
|
+
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function Wb(e,t){return qb(e)||Bb(e,t)||Vb(e,t)||Hb()}function Vb(e,t){if(e){if(typeof e=="string")return _o(e,t);var n={}.toString.call(e).slice(8,-1);return n==="Object"&&e.constructor&&(n=e.constructor.name),n==="Map"||n==="Set"?Array.from(e):n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?_o(e,t):void 0}}const Dc=Object.entries,vo=Object.setPrototypeOf,Gb=Object.isFrozen,Jb=Object.getPrototypeOf,Yb=Object.getOwnPropertyDescriptor;let Ee=Object.freeze,Re=Object.seal,nn=Object.create,Zc=typeof Reflect<"u"&&Reflect,xs=Zc.apply,bs=Zc.construct;Ee||(Ee=function(t){return t});Re||(Re=function(t){return t});xs||(xs=function(t,n){for(var r=arguments.length,s=new Array(r>2?r-2:0),i=2;i<r;i++)s[i-2]=arguments[i];return t.apply(n,s)});bs||(bs=function(t){for(var n=arguments.length,r=new Array(n>1?n-1:0),s=1;s<n;s++)r[s-1]=arguments[s];return new t(...r)});const Xt=ye(Array.prototype.forEach),Kb=ye(Array.prototype.lastIndexOf),yo=ye(Array.prototype.pop),Qt=ye(Array.prototype.push),Xb=ye(Array.prototype.splice),Tt=Array.isArray,Tn=ye(String.prototype.toLowerCase),Jr=ye(String.prototype.toString),ko=ye(String.prototype.match),kn=ye(String.prototype.replace),wo=ye(String.prototype.indexOf),Qb=ye(String.prototype.trim),e0=ye(Number.prototype.toString),t0=ye(Boolean.prototype.toString),So=typeof BigInt>"u"?null:ye(BigInt.prototype.toString),jo=typeof Symbol>"u"?null:ye(Symbol.prototype.toString),we=ye(Object.prototype.hasOwnProperty),wn=ye(Object.prototype.toString),ke=ye(RegExp.prototype.test),Lt=n0(TypeError);function ye(e){return function(t){t instanceof RegExp&&(t.lastIndex=0);for(var n=arguments.length,r=new Array(n>1?n-1:0),s=1;s<n;s++)r[s-1]=arguments[s];return xs(e,t,r)}}function n0(e){return function(){for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];return bs(e,n)}}function X(e,t){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:Tn;if(vo&&vo(e,null),!Tt(t))return e;let r=t.length;for(;r--;){let s=t[r];if(typeof s=="string"){const i=n(s);i!==s&&(Gb(t)||(t[r]=i),s=i)}e[s]=!0}return e}function r0(e){for(let t=0;t<e.length;t++)we(e,t)||(e[t]=null);return e}function Pe(e){const t=nn(null);for(const r of Dc(e)){var n=Wb(r,2);const s=n[0],i=n[1];we(e,s)&&(Tt(i)?t[s]=r0(i):i&&typeof i=="object"&&i.constructor===Object?t[s]=Pe(i):t[s]=i)}return t}function s0(e){switch(typeof e){case"string":return e;case"number":return e0(e);case"boolean":return t0(e);case"bigint":return So?So(e):"0";case"symbol":return jo?jo(e):"Symbol()";case"undefined":return wn(e);case"function":case"object":{if(e===null)return wn(e);const t=e,n=pt(t,"toString");if(typeof n=="function"){const r=n(t);return typeof r=="string"?r:wn(r)}return wn(e)}default:return wn(e)}}function pt(e,t){for(;e!==null;){const r=Yb(e,t);if(r){if(r.get)return ye(r.get);if(typeof r.value=="function")return ye(r.value)}e=Jb(e)}function n(){return null}return n}function i0(e){try{return ke(e,""),!0}catch{return!1}}const No=Ee(["a","abbr","acronym","address","area","article","aside","audio","b","bdi","bdo","big","blink","blockquote","body","br","button","canvas","caption","center","cite","code","col","colgroup","content","data","datalist","dd","decorator","del","details","dfn","dialog","dir","div","dl","dt","element","em","fieldset","figcaption","figure","font","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","img","input","ins","kbd","label","legend","li","main","map","mark","marquee","menu","menuitem","meter","nav","nobr","ol","optgroup","option","output","p","picture","pre","progress","q","rp","rt","ruby","s","samp","search","section","select","shadow","slot","small","source","spacer","span","strike","strong","style","sub","summary","sup","table","tbody","td","template","textarea","tfoot","th","thead","time","tr","track","tt","u","ul","var","video","wbr"]),Yr=Ee(["svg","a","altglyph","altglyphdef","altglyphitem","animatecolor","animatemotion","animatetransform","circle","clippath","defs","desc","ellipse","enterkeyhint","exportparts","filter","font","g","glyph","glyphref","hkern","image","inputmode","line","lineargradient","marker","mask","metadata","mpath","part","path","pattern","polygon","polyline","radialgradient","rect","stop","style","switch","symbol","text","textpath","title","tref","tspan","view","vkern"]),Kr=Ee(["feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feDropShadow","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence"]),o0=Ee(["animate","color-profile","cursor","discard","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","foreignobject","hatch","hatchpath","mesh","meshgradient","meshpatch","meshrow","missing-glyph","script","set","solidcolor","unknown","use"]),Xr=Ee(["math","menclose","merror","mfenced","mfrac","mglyph","mi","mlabeledtr","mmultiscripts","mn","mo","mover","mpadded","mphantom","mroot","mrow","ms","mspace","msqrt","mstyle","msub","msup","msubsup","mtable","mtd","mtext","mtr","munder","munderover","mprescripts"]),a0=Ee(["maction","maligngroup","malignmark","mlongdiv","mscarries","mscarry","msgroup","mstack","msline","msrow","semantics","annotation","annotation-xml","mprescripts","none"]),To=Ee(["#text"]),Eo=Ee(["accept","action","align","alt","autocapitalize","autocomplete","autopictureinpicture","autoplay","background","bgcolor","border","capture","cellpadding","cellspacing","checked","cite","class","clear","color","cols","colspan","command","commandfor","controls","controlslist","coords","crossorigin","datetime","decoding","default","dir","disabled","disablepictureinpicture","disableremoteplayback","download","draggable","enctype","enterkeyhint","exportparts","face","for","headers","height","hidden","high","href","hreflang","id","inert","inputmode","integrity","ismap","kind","label","lang","list","loading","loop","low","max","maxlength","media","method","min","minlength","multiple","muted","name","nonce","noshade","novalidate","nowrap","open","optimum","part","pattern","placeholder","playsinline","popover","popovertarget","popovertargetaction","poster","preload","pubdate","radiogroup","readonly","rel","required","rev","reversed","role","rows","rowspan","spellcheck","scope","selected","shape","size","sizes","slot","span","srclang","start","src","srcset","step","style","summary","tabindex","title","translate","type","usemap","valign","value","width","wrap","xmlns"]),Qr=Ee(["accent-height","accumulate","additive","alignment-baseline","amplitude","ascent","attributename","attributetype","azimuth","basefrequency","baseline-shift","begin","bias","by","class","clip","clippathunits","clip-path","clip-rule","color","color-interpolation","color-interpolation-filters","color-profile","color-rendering","cx","cy","d","dx","dy","diffuseconstant","direction","display","divisor","dominant-baseline","dur","edgemode","elevation","end","exponent","fill","fill-opacity","fill-rule","filter","filterunits","flood-color","flood-opacity","font-family","font-size","font-size-adjust","font-stretch","font-style","font-variant","font-weight","fx","fy","g1","g2","glyph-name","glyphref","gradientunits","gradienttransform","height","href","id","image-rendering","in","in2","intercept","k","k1","k2","k3","k4","kerning","keypoints","keysplines","keytimes","lang","lengthadjust","letter-spacing","kernelmatrix","kernelunitlength","lighting-color","local","marker-end","marker-mid","marker-start","markerheight","markerunits","markerwidth","maskcontentunits","maskunits","max","mask","mask-type","media","method","mode","min","name","numoctaves","offset","operator","opacity","order","orient","orientation","origin","overflow","paint-order","path","pathlength","patterncontentunits","patterntransform","patternunits","points","preservealpha","preserveaspectratio","primitiveunits","r","rx","ry","radius","refx","refy","repeatcount","repeatdur","restart","result","rotate","scale","seed","shape-rendering","slope","specularconstant","specularexponent","spreadmethod","startoffset","stddeviation","stitchtiles","stop-color","stop-opacity","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke","stroke-width","style","surfacescale","systemlanguage","tabindex","tablevalues","targetx","targety","transform","transform-origin","text-anchor","text-decoration","text-orientation","text-rendering","textlength","type","u1","u2","unicode","values","viewbox","visibility","version","vert-adv-y","vert-origin-x","vert-origin-y","width","word-spacing","wrap","writing-mode","xchannelselector","ychannelselector","x","x1","x2","xmlns","y","y1","y2","z","zoomandpan"]),$o=Ee(["accent","accentunder","align","bevelled","close","columnalign","columnlines","columnspacing","columnspan","denomalign","depth","dir","display","displaystyle","encoding","fence","frame","height","href","id","largeop","length","linethickness","lquote","lspace","mathbackground","mathcolor","mathsize","mathvariant","maxsize","minsize","movablelimits","notation","numalign","open","rowalign","rowlines","rowspacing","rowspan","rspace","rquote","scriptlevel","scriptminsize","scriptsizemultiplier","selection","separator","separators","stretchy","subscriptshift","supscriptshift","symmetric","voffset","width","xmlns"]),tr=Ee(["xlink:href","xml:id","xlink:title","xml:space","xmlns:xlink"]),c0=Re(/{{[\w\W]*|^[\w\W]*}}/g),l0=Re(/<%[\w\W]*|^[\w\W]*%>/g),u0=Re(/\${[\w\W]*/g),d0=Re(/^data-[\-\w.\u00B7-\uFFFF]+$/),h0=Re(/^aria-[\-\w]+$/),Ro=Re(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),f0=Re(/^(?:\w+script|data):/i),m0=Re(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),p0=Re(/^html$/i),g0=Re(/^[a-z][.\w]*(-[.\w]+)+$/i),Co=Re(/<[/\w!]/g),Ao=Re(/<[/\w]/g),x0=Re(/<\/no(script|embed|frames)/i),b0=Re(/\/>/i),Ve={element:1,attribute:2,text:3,cdataSection:4,entityReference:5,entityNode:6,processingInstruction:7,comment:8,document:9,documentType:10,documentFragment:11,notation:12},_0=function(){return typeof window>"u"?null:window},v0=function(t,n){if(typeof t!="object"||typeof t.createPolicy!="function")return null;let r=null;const s="data-tt-policy-suffix";n&&n.hasAttribute(s)&&(r=n.getAttribute(s));const i="dompurify"+(r?"#"+r:"");try{return t.createPolicy(i,{createHTML(a){return a},createScriptURL(a){return a}})}catch{return console.warn("TrustedTypes policy "+i+" could not be created."),null}},zo=function(){return{afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}},jt=function(t,n,r,s){return we(t,n)&&Tt(t[n])?X(s.base?Pe(s.base):{},t[n],s.transform):r};function Fc(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:_0();const t=R=>Fc(R);if(t.version="3.4.12",t.removed=[],!e||!e.document||e.document.nodeType!==Ve.document||!e.Element)return t.isSupported=!1,t;let n=e.document;const r=n,s=r.currentScript;e.DocumentFragment;const i=e.HTMLTemplateElement,a=e.Node,c=e.Element,l=e.NodeFilter,d=e.NamedNodeMap;d===void 0&&(e.NamedNodeMap||e.MozNamedAttrMap),e.HTMLFormElement;const u=e.DOMParser,h=e.trustedTypes,m=c.prototype,p=pt(m,"cloneNode"),g=pt(m,"remove"),_=pt(m,"nextSibling"),S=pt(m,"childNodes"),C=pt(m,"parentNode"),A=pt(m,"shadowRoot"),$=pt(m,"attributes"),I=a&&a.prototype?pt(a.prototype,"nodeType"):null,z=a&&a.prototype?pt(a.prototype,"nodeName"):null;if(typeof i=="function"){const R=n.createElement("template");R.content&&R.content.ownerDocument&&(n=R.content.ownerDocument)}let k,E="",L,J=!1,ce=0;const Z=function(){if(ce>0)throw Lt('A configured TRUSTED_TYPES_POLICY callback (createHTML or createScriptURL) must not call DOMPurify.sanitize, as that causes infinite recursion. Do not pass a policy whose callbacks wrap DOMPurify as TRUSTED_TYPES_POLICY; see the "DOMPurify and Trusted Types" section of the README.')},Y=function(f){Z(),ce++;try{return k.createHTML(f)}finally{ce--}},G=function(f){Z(),ce++;try{return k.createScriptURL(f)}finally{ce--}},oe=function(){return J||(L=v0(h,s),J=!0),L},Ce=n,ut=Ce.implementation,De=Ce.createNodeIterator,kt=Ce.createDocumentFragment,T=Ce.getElementsByTagName,B=r.importNode;let U=zo();t.isSupported=typeof Dc=="function"&&typeof C=="function"&&ut&&ut.createHTMLDocument!==void 0;const le=c0,Ye=l0,Ke=u0,pn=d0,Zn=h0,Wt=f0,dt=m0,wt=g0;let Ne=Ro,ee=null;const xt=X({},[...No,...Yr,...Kr,...Xr,...To]);let ue=null;const gn=X({},[...Eo,...Qr,...$o,...tr]);let de=Object.seal(nn(null,{tagNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},allowCustomizedBuiltInElements:{writable:!0,configurable:!1,enumerable:!0,value:!1}})),Xe=null,At=null;const Ie=Object.seal(nn(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}}));let He=!0,We=!0,Fn=!1,xn=!0,Qe=!1,et=!0,y=!1,M=!1,K=null,fe=null,Ze=!1,Fe=!1,bt=!1,_t=!1,ti=!0,ni=!1;const ri="user-content-";let Cr=!0,Ar=!1,Vt={},ht=null;const zr=X({},["annotation-xml","audio","colgroup","desc","foreignobject","head","iframe","math","mi","mn","mo","ms","mtext","noembed","noframes","noscript","plaintext","script","selectedcontent","style","svg","template","thead","title","video","xmp"]);let si=null;const ii=X({},["audio","video","img","source","image","track"]);let Ir=null;const oi=X({},["alt","class","for","id","label","name","pattern","placeholder","role","summary","title","value","style","xmlns"]),Un="http://www.w3.org/1998/Math/MathML",qn="http://www.w3.org/2000/svg",ft="http://www.w3.org/1999/xhtml";let Gt=ft,Lr=!1,Or=null;const ol=X({},[Un,qn,ft],Jr),ai=Ee(["mi","mo","mn","ms","mtext"]);let Pr=X({},ai);const ci=Ee(["annotation-xml"]);let Mr=X({},ci);const al=X({},["title","style","font","a","script"]);let bn=null;const cl=["application/xhtml+xml","text/html"],ll="text/html";let me=null,Jt=null;const ul=n.createElement("form"),li=function(f){return f instanceof RegExp||f instanceof Function},Dr=function(){let f=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(Jt&&Jt===f)return;(!f||typeof f!="object")&&(f={}),f=Pe(f),bn=cl.indexOf(f.PARSER_MEDIA_TYPE)===-1?ll:f.PARSER_MEDIA_TYPE,me=bn==="application/xhtml+xml"?Jr:Tn,ee=jt(f,"ALLOWED_TAGS",xt,{transform:me}),ue=jt(f,"ALLOWED_ATTR",gn,{transform:me}),Or=jt(f,"ALLOWED_NAMESPACES",ol,{transform:Jr}),Ir=jt(f,"ADD_URI_SAFE_ATTR",oi,{transform:me,base:oi}),si=jt(f,"ADD_DATA_URI_TAGS",ii,{transform:me,base:ii}),ht=jt(f,"FORBID_CONTENTS",zr,{transform:me}),Xe=jt(f,"FORBID_TAGS",Pe({}),{transform:me}),At=jt(f,"FORBID_ATTR",Pe({}),{transform:me}),Vt=we(f,"USE_PROFILES")?f.USE_PROFILES&&typeof f.USE_PROFILES=="object"?Pe(f.USE_PROFILES):f.USE_PROFILES:!1,He=f.ALLOW_ARIA_ATTR!==!1,We=f.ALLOW_DATA_ATTR!==!1,Fn=f.ALLOW_UNKNOWN_PROTOCOLS||!1,xn=f.ALLOW_SELF_CLOSE_IN_ATTR!==!1,Qe=f.SAFE_FOR_TEMPLATES||!1,et=f.SAFE_FOR_XML!==!1,y=f.WHOLE_DOCUMENT||!1,Fe=f.RETURN_DOM||!1,bt=f.RETURN_DOM_FRAGMENT||!1,_t=f.RETURN_TRUSTED_TYPE||!1,Ze=f.FORCE_BODY||!1,ti=f.SANITIZE_DOM!==!1,ni=f.SANITIZE_NAMED_PROPS||!1,Cr=f.KEEP_CONTENT!==!1,Ar=f.IN_PLACE||!1,Ne=i0(f.ALLOWED_URI_REGEXP)?f.ALLOWED_URI_REGEXP:Ro,Gt=typeof f.NAMESPACE=="string"?f.NAMESPACE:ft,Pr=we(f,"MATHML_TEXT_INTEGRATION_POINTS")&&f.MATHML_TEXT_INTEGRATION_POINTS&&typeof f.MATHML_TEXT_INTEGRATION_POINTS=="object"?Pe(f.MATHML_TEXT_INTEGRATION_POINTS):X({},ai),Mr=we(f,"HTML_INTEGRATION_POINTS")&&f.HTML_INTEGRATION_POINTS&&typeof f.HTML_INTEGRATION_POINTS=="object"?Pe(f.HTML_INTEGRATION_POINTS):X({},ci);const b=we(f,"CUSTOM_ELEMENT_HANDLING")&&f.CUSTOM_ELEMENT_HANDLING&&typeof f.CUSTOM_ELEMENT_HANDLING=="object"?Pe(f.CUSTOM_ELEMENT_HANDLING):nn(null);if(de=nn(null),we(b,"tagNameCheck")&&li(b.tagNameCheck)&&(de.tagNameCheck=b.tagNameCheck),we(b,"attributeNameCheck")&&li(b.attributeNameCheck)&&(de.attributeNameCheck=b.attributeNameCheck),we(b,"allowCustomizedBuiltInElements")&&typeof b.allowCustomizedBuiltInElements=="boolean"&&(de.allowCustomizedBuiltInElements=b.allowCustomizedBuiltInElements),Re(de),Qe&&(We=!1),bt&&(Fe=!0),Vt&&(ee=X({},To),ue=nn(null),Vt.html===!0&&(X(ee,No),X(ue,Eo)),Vt.svg===!0&&(X(ee,Yr),X(ue,Qr),X(ue,tr)),Vt.svgFilters===!0&&(X(ee,Kr),X(ue,Qr),X(ue,tr)),Vt.mathMl===!0&&(X(ee,Xr),X(ue,$o),X(ue,tr))),Ie.tagCheck=null,Ie.attributeCheck=null,we(f,"ADD_TAGS")&&(typeof f.ADD_TAGS=="function"?Ie.tagCheck=f.ADD_TAGS:Tt(f.ADD_TAGS)&&(ee===xt&&(ee=Pe(ee)),X(ee,f.ADD_TAGS,me))),we(f,"ADD_ATTR")&&(typeof f.ADD_ATTR=="function"?Ie.attributeCheck=f.ADD_ATTR:Tt(f.ADD_ATTR)&&(ue===gn&&(ue=Pe(ue)),X(ue,f.ADD_ATTR,me))),we(f,"ADD_URI_SAFE_ATTR")&&Tt(f.ADD_URI_SAFE_ATTR)&&X(Ir,f.ADD_URI_SAFE_ATTR,me),we(f,"FORBID_CONTENTS")&&Tt(f.FORBID_CONTENTS)&&(ht===zr&&(ht=Pe(ht)),X(ht,f.FORBID_CONTENTS,me)),we(f,"ADD_FORBID_CONTENTS")&&Tt(f.ADD_FORBID_CONTENTS)&&(ht===zr&&(ht=Pe(ht)),X(ht,f.ADD_FORBID_CONTENTS,me)),Cr&&(ee["#text"]=!0),y&&X(ee,["html","head","body"]),ee.table&&(X(ee,["tbody"]),delete Xe.tbody),f.TRUSTED_TYPES_POLICY){if(typeof f.TRUSTED_TYPES_POLICY.createHTML!="function")throw Lt('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');if(typeof f.TRUSTED_TYPES_POLICY.createScriptURL!="function")throw Lt('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');const N=k;k=f.TRUSTED_TYPES_POLICY;try{E=Y("")}catch(P){throw k=N,P}}else f.TRUSTED_TYPES_POLICY===null?(k=void 0,E=""):(k===void 0&&(k=oe()),k&&typeof E=="string"&&(E=Y("")));Ee&&Ee(f),Jt=f},ui=X({},[...Yr,...Kr,...o0]),di=X({},[...Xr,...a0]),dl=function(f,b,N){return b.namespaceURI===ft?f==="svg":b.namespaceURI===Un?f==="svg"&&(N==="annotation-xml"||Pr[N]):!!ui[f]},hl=function(f,b,N){return b.namespaceURI===ft?f==="math":b.namespaceURI===qn?f==="math"&&Mr[N]:!!di[f]},fl=function(f,b,N){return b.namespaceURI===qn&&!Mr[N]||b.namespaceURI===Un&&!Pr[N]?!1:!di[f]&&(al[f]||!ui[f])},ml=function(f){let b=C(f);(!b||!b.tagName)&&(b={namespaceURI:Gt,tagName:"template"});const N=Tn(f.tagName),P=Tn(b.tagName);return Or[f.namespaceURI]?f.namespaceURI===qn?dl(N,b,P):f.namespaceURI===Un?hl(N,b,P):f.namespaceURI===ft?fl(N,b,P):!!(bn==="application/xhtml+xml"&&Or[f.namespaceURI]):!1},St=function(f){Qt(t.removed,{element:f});try{C(f).removeChild(f)}catch{if(g(f),!C(f))throw Lt("a node selected for removal could not be detached from its tree and cannot be safely returned; refusing to sanitize in place")}},Bn=function(f){Zr(f);const b=S(f);if(b){const P=[];Xt(b,q=>{Qt(P,q)}),Xt(P,q=>{try{g(q)}catch{}})}const N=$(f);if(N)for(let P=N.length-1;P>=0;--P){const q=N[P],W=q&&q.name;if(typeof W=="string")try{f.removeAttribute(W)}catch{}}},zt=function(f,b){try{Qt(t.removed,{attribute:b.getAttributeNode(f),from:b})}catch{Qt(t.removed,{attribute:null,from:b})}if(b.removeAttribute(f),f==="is")if(Fe||bt)try{St(b)}catch{}else try{b.setAttribute(f,"")}catch{}},pl=function(f){const b=$(f);if(b)for(let N=b.length-1;N>=0;--N){const P=b[N],q=P&&P.name;if(!(typeof q!="string"||ue[me(q)]))try{f.removeAttribute(q)}catch{}}},Zr=function(f){const b=[f];for(;b.length>0;){const N=b.pop();(I?I(N):N.nodeType)===Ve.element&&pl(N);const q=S(N);if(q)for(let W=q.length-1;W>=0;--W)b.push(q[W])}},gl=function(f){if(!et)return;const b=[f];for(;b.length>0;){const N=b.pop(),P=I?I(N):N.nodeType;if(P===Ve.processingInstruction||P===Ve.comment&&ke(Ao,N.data)){try{g(N)}catch{}continue}if(P===Ve.element){const W=N,ge=me(z?z(N):N.nodeName);try{W.hasAttribute&&W.hasAttribute("patchsrc")&&W.removeAttribute("patchsrc"),W.hasAttribute&&W.hasAttribute("for")&&ge!=="label"&&ge!=="output"&&W.removeAttribute("for")}catch{}}const q=S(N);if(q)for(let W=q.length-1;W>=0;--W)b.push(q[W])}},hi=function(f){let b=null,N=null;if(Ze)f="<remove></remove>"+f;else{const W=ko(f,/^[\r\n\t ]+/);N=W&&W[0]}bn==="application/xhtml+xml"&&Gt===ft&&(f='<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>'+f+"</body></html>");const P=k?Y(f):f;if(Gt===ft)try{b=new u().parseFromString(P,bn)}catch{}if(!b||!b.documentElement){b=ut.createDocument(Gt,"template",null);try{b.documentElement.innerHTML=Lr?E:P}catch{}}const q=b.body||b.documentElement;return f&&N&&q.insertBefore(n.createTextNode(N),q.childNodes[0]||null),Gt===ft?T.call(b,y?"html":"body")[0]:y?b.documentElement:q},fi=function(f){return De.call(f.ownerDocument||f,f,l.SHOW_ELEMENT|l.SHOW_COMMENT|l.SHOW_TEXT|l.SHOW_PROCESSING_INSTRUCTION|l.SHOW_CDATA_SECTION,null)},Hn=function(f){return f=kn(f,le," "),f=kn(f,Ye," "),f=kn(f,Ke," "),f},Fr=function(f){var b;f.normalize();const N=De.call(f.ownerDocument||f,f,l.SHOW_TEXT|l.SHOW_COMMENT|l.SHOW_CDATA_SECTION|l.SHOW_PROCESSING_INSTRUCTION,null);let P=N.nextNode();for(;P;)P.data=Hn(P.data),P=N.nextNode();const q=(b=f.querySelectorAll)===null||b===void 0?void 0:b.call(f,"template");q&&Xt(q,W=>{Yt(W.content)&&Fr(W.content)})},Wn=function(f){const b=z?z(f):null;return typeof b!="string"||me(b)!=="form"?!1:typeof f.nodeName!="string"||typeof f.textContent!="string"||typeof f.removeChild!="function"||f.attributes!==$(f)||typeof f.removeAttribute!="function"||typeof f.setAttribute!="function"||typeof f.namespaceURI!="string"||typeof f.insertBefore!="function"||typeof f.hasChildNodes!="function"||f.nodeType!==I(f)||f.childNodes!==S(f)},Yt=function(f){if(!I||typeof f!="object"||f===null)return!1;try{return I(f)===Ve.documentFragment}catch{return!1}},_n=function(f){if(!I||typeof f!="object"||f===null)return!1;try{return typeof I(f)=="number"}catch{return!1}};function mt(R,f,b){R.length!==0&&Xt(R,N=>{N.call(t,f,b,Jt)})}const xl=function(f,b){return!!(et&&f.hasChildNodes()&&!_n(f.firstElementChild)&&ke(Co,f.textContent)&&ke(Co,f.innerHTML)||et&&f.namespaceURI===ft&&b==="style"&&_n(f.firstElementChild)||f.nodeType===Ve.processingInstruction||et&&f.nodeType===Ve.comment&&ke(Ao,f.data))},bl=function(f,b){if(!Xe[b]&&gi(b)&&(de.tagNameCheck instanceof RegExp&&ke(de.tagNameCheck,b)||de.tagNameCheck instanceof Function&&de.tagNameCheck(b)))return!1;if(Cr&&!ht[b]){const N=C(f),P=S(f);if(P&&N){const q=P.length;for(let W=q-1;W>=0;--W){const ge=Ar?P[W]:p(P[W],!0);N.insertBefore(ge,_(f))}}}return St(f),!0},mi=function(f,b){if(mt(U.beforeSanitizeElements,f,null),f!==b&&C(f)===null)return!0;if(Wn(f))return St(f),!0;const N=me(z?z(f):f.nodeName);if(mt(U.uponSanitizeElement,f,{tagName:N,allowedTags:ee}),f!==b&&C(f)===null)return!0;if(xl(f,N))return St(f),!0;if(Xe[N]||!(Ie.tagCheck instanceof Function&&Ie.tagCheck(N))&&!ee[N]){const q=bl(f,N);return q===!1&&mt(U.afterSanitizeElements,f,null),q}if((I?I(f):f.nodeType)===Ve.element&&!ml(f)||(N==="noscript"||N==="noembed"||N==="noframes")&&ke(x0,f.innerHTML))return St(f),!0;if(Qe&&f.nodeType===Ve.text){const q=Hn(f.textContent);f.textContent!==q&&(Qt(t.removed,{element:f.cloneNode()}),f.textContent=q)}return mt(U.afterSanitizeElements,f,null),!1},pi=function(f,b,N){if(At[b]||et&&b==="patchsrc"||et&&b==="for"&&f!=="label"&&f!=="output"||ti&&(b==="id"||b==="name")&&(N in n||N in ul))return!1;const P=ue[b]||Ie.attributeCheck instanceof Function&&Ie.attributeCheck(b,f);if(!(We&&ke(pn,b))){if(!(He&&ke(Zn,b))){if(P){if(!Ir[b]){if(!ke(Ne,kn(N,dt,""))){if(!((b==="src"||b==="xlink:href"||b==="href")&&f!=="script"&&wo(N,"data:")===0&&si[f])){if(!(Fn&&!ke(Wt,kn(N,dt,"")))){if(N)return!1}}}}}else if(!(gi(f)&&(de.tagNameCheck instanceof RegExp&&ke(de.tagNameCheck,f)||de.tagNameCheck instanceof Function&&de.tagNameCheck(f))&&(de.attributeNameCheck instanceof RegExp&&ke(de.attributeNameCheck,b)||de.attributeNameCheck instanceof Function&&de.attributeNameCheck(b,f))||b==="is"&&de.allowCustomizedBuiltInElements&&(de.tagNameCheck instanceof RegExp&&ke(de.tagNameCheck,N)||de.tagNameCheck instanceof Function&&de.tagNameCheck(N))))return!1}}return!0},_l=X({},["annotation-xml","color-profile","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","missing-glyph"]),gi=function(f){return!_l[Tn(f)]&&ke(wt,f)},vl=function(f,b,N,P){if(k&&typeof h=="object"&&typeof h.getAttributeType=="function"&&!N)switch(h.getAttributeType(f,b)){case"TrustedHTML":return Y(P);case"TrustedScriptURL":return G(P)}return P},yl=function(f,b,N,P){try{N?f.setAttributeNS(N,b,P):f.setAttribute(b,P),Wn(f)?St(f):yo(t.removed)}catch{zt(b,f)}},xi=function(f){mt(U.beforeSanitizeAttributes,f,null);const b=f.attributes;if(!b||Wn(f))return;const N={attrName:"",attrValue:"",keepAttr:!0,allowedAttributes:ue,forceKeepAttr:void 0};let P=b.length;const q=me(f.nodeName);for(;P--;){const W=b[P],ge=W.name,Ae=W.namespaceURI,tt=W.value,Ue=me(ge),nt=tt;let Le=ge==="value"?nt:Qb(nt);if(N.attrName=Ue,N.attrValue=Le,N.keepAttr=!0,N.forceKeepAttr=void 0,mt(U.uponSanitizeAttribute,f,N),Le=N.attrValue,ni&&(Ue==="id"||Ue==="name")&&wo(Le,ri)!==0&&(zt(ge,f),Le=ri+Le),et&&ke(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i,Le)){zt(ge,f);continue}if(Ue==="attributename"&&ko(Le,"href")){zt(ge,f);continue}if(!N.forceKeepAttr){if(!N.keepAttr){zt(ge,f);continue}if(!xn&&ke(b0,Le)){zt(ge,f);continue}if(Qe&&(Le=Hn(Le)),!pi(q,Ue,Le)){zt(ge,f);continue}Le=vl(q,Ue,Ae,Le),Le!==nt&&yl(f,ge,Ae,Le)}}mt(U.afterSanitizeAttributes,f,null)},Vn=function(f){let b=null;const N=fi(f);for(mt(U.beforeSanitizeShadowDOM,f,null);b=N.nextNode();)if(mt(U.uponSanitizeShadowNode,b,null),mi(b,f),xi(b),Yt(b.content)&&Vn(b.content),(I?I(b):b.nodeType)===Ve.element){const q=A(b);Yt(q)&&(Ur(q),Vn(q))}mt(U.afterSanitizeShadowDOM,f,null)},Ur=function(f){const b=[{node:f,shadow:null}];for(;b.length>0;){const N=b.pop();if(N.shadow){Vn(N.shadow);continue}const P=N.node,W=(I?I(P):P.nodeType)===Ve.element,ge=S(P);if(ge)for(let Ae=ge.length-1;Ae>=0;--Ae)b.push({node:ge[Ae],shadow:null});if(W){const Ae=z?z(P):null;if(typeof Ae=="string"&&me(Ae)==="template"){const tt=P.content;Yt(tt)&&b.push({node:tt,shadow:null})}}if(W){const Ae=A(P);Yt(Ae)&&b.push({node:null,shadow:Ae},{node:Ae,shadow:null})}}};return t.sanitize=function(R){let f=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},b=null,N=null,P=null,q=null;if(Lr=!R,Lr&&(R="<!-->"),typeof R!="string"&&!_n(R)&&(R=s0(R),typeof R!="string"))throw Lt("dirty is not a string, aborting");if(!t.isSupported)return R;M?(ee=K,ue=fe):Dr(f),(U.uponSanitizeElement.length>0||U.uponSanitizeAttribute.length>0)&&(ee=Pe(ee)),U.uponSanitizeAttribute.length>0&&(ue=Pe(ue)),t.removed=[];const W=Ar&&typeof R!="string"&&_n(R);if(W){gl(R);const Ue=z?z(R):R.nodeName;if(typeof Ue=="string"){const nt=me(Ue);if(!ee[nt]||Xe[nt])throw Bn(R),Lt("root node is forbidden and cannot be sanitized in-place")}if(Wn(R))throw Bn(R),Lt("root node is clobbered and cannot be sanitized in-place");try{Ur(R)}catch(nt){throw Bn(R),nt}}else if(_n(R))b=hi("<!---->"),N=b.ownerDocument.importNode(R,!0),N.nodeType===Ve.element&&N.nodeName==="BODY"||N.nodeName==="HTML"?b=N:b.appendChild(N),Ur(N);else{if(!Fe&&!Qe&&!y&&R.indexOf("<")===-1)return k&&_t?Y(R):R;if(b=hi(R),!b)return Fe?null:_t?E:""}b&&Ze&&St(b.firstChild);const ge=W?R:b,Ae=fi(ge);try{for(;P=Ae.nextNode();)mi(P,ge),xi(P),Yt(P.content)&&Vn(P.content)}catch(Ue){throw W&&(Bn(R),Xt(t.removed,nt=>{nt.element&&Zr(nt.element)})),Ue}if(W)return Xt(t.removed,Ue=>{Ue.element&&Zr(Ue.element)}),Qe&&Fr(R),R;if(Fe){if(Qe&&Fr(b),bt)for(q=kt.call(b.ownerDocument);b.firstChild;)q.appendChild(b.firstChild);else q=b;return(ue.shadowroot||ue.shadowrootmode)&&(q=B.call(r,q,!0)),q}let tt=y?b.outerHTML:b.innerHTML;return y&&ee["!doctype"]&&b.ownerDocument&&b.ownerDocument.doctype&&b.ownerDocument.doctype.name&&ke(p0,b.ownerDocument.doctype.name)&&(tt="<!DOCTYPE "+b.ownerDocument.doctype.name+`>
|
|
342
|
+
`+tt),Qe&&(tt=Hn(tt)),k&&_t?Y(tt):tt},t.setConfig=function(){let R=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};Dr(R),M=!0,K=ee,fe=ue},t.clearConfig=function(){Jt=null,M=!1,K=null,fe=null,k=L,E=""},t.isValidAttribute=function(R,f,b){Jt||Dr({});const N=me(R),P=me(f);return pi(N,P,b)},t.addHook=function(R,f){typeof f=="function"&&we(U,R)&&Qt(U[R],f)},t.removeHook=function(R,f){if(we(U,R)){if(f!==void 0){const b=Kb(U[R],f);return b===-1?void 0:Xb(U[R],b,1)[0]}return yo(U[R])}},t.removeHooks=function(R){we(U,R)&&(U[R]=[])},t.removeAllHooks=function(){U=zo()},t}var Uc=Fc();function Hs(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var Ht=Hs();function qc(e){Ht=e}var Pt={exec:()=>null};function en(e){let t=[];return n=>{let r=Math.max(0,Math.min(3,n-1)),s=t[r];return s||(s=e(r),t[r]=s),s}}function Q(e,t=""){let n=typeof e=="string"?e:e.source,r={replace:(s,i)=>{let a=typeof i=="string"?i:i.source;return a=a.replace(ze.caret,"$1"),n=n.replace(s,a),r},getRegex:()=>new RegExp(n,t)};return r}var y0=((e="")=>{try{return!!new RegExp("(?<=1)(?<!1)"+e)}catch{return!1}})(),ze={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] +\S/,listReplaceTask:/^\[[ xX]\] +/,listTaskCheckbox:/\[[ xX]\]/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:e=>new RegExp(`^( {0,3}${e})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:en(e=>new RegExp(`^ {0,${e}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`)),hrRegex:en(e=>new RegExp(`^ {0,${e}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`)),fencesBeginRegex:en(e=>new RegExp(`^ {0,${e}}(?:\`\`\`|~~~)`)),headingBeginRegex:en(e=>new RegExp(`^ {0,${e}}#`)),htmlBeginRegex:en(e=>new RegExp(`^ {0,${e}}<(?:[a-z].*>|!--)`,"i")),blockquoteBeginRegex:en(e=>new RegExp(`^ {0,${e}}>`))},k0=/^(?:[ \t]*(?:\n|$))+/,w0=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,S0=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,Dn=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,j0=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,Ws=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,Bc=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,Hc=Q(Bc).replace(/bull/g,Ws).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,"").getRegex(),N0=Q(Bc).replace(/bull/g,Ws).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),Vs=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,T0=/^[^\n]+/,Gs=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,E0=Q(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",Gs).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),$0=Q(/^(bull)([ \t][^\n]*?)?(?:\n|$)/).replace(/bull/g,Ws).getRegex(),$r="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",Js=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,R0=Q("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>[^\\n]*\\n+|$)|<![A-Z][\\s\\S]*?(?:>[^\\n]*\\n+|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>[^\\n]*\\n+|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))","i").replace("comment",Js).replace("tag",$r).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),Wc=e=>Q(Vs).replace("hr",Dn).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list",e).replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",$r).getRegex(),C0=Wc(/ {0,3}(?:[*+-]|1[.)])[ \t]+[^ \t\n]/),A0=Wc(/ {0,3}(?:[*+-]|\d{1,9}[.)])[ \t]+[^ \t\n]/),z0=Q(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",A0).getRegex(),Ys={blockquote:z0,code:w0,def:E0,fences:S0,heading:j0,hr:Dn,html:R0,lheading:Hc,list:$0,newline:k0,paragraph:C0,table:Pt,text:T0},Io=Q("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",Dn).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code","(?: {4}| {0,3} )[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",$r).getRegex(),I0={...Ys,lheading:N0,table:Io,paragraph:Q(Vs).replace("hr",Dn).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",Io).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]+[^ \\t\\n]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",$r).getRegex()},L0={...Ys,html:Q(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",Js).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:Pt,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:Q(Vs).replace("hr",Dn).replace("heading",` *#{1,6} *[^
|
|
343
|
+
]`).replace("lheading",Hc).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},O0=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,P0=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,Vc=/^( {2,}|\\)\n(?!\s*$)/,M0=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,mn=/[\p{P}\p{S}]/u,Rr=/[\s\p{P}\p{S}]/u,Ks=/[^\s\p{P}\p{S}]/u,D0=Q(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,Rr).getRegex(),Gc=/(?!~)[\p{P}\p{S}]/u,Z0=/(?!~)[\s\p{P}\p{S}]/u,F0=/(?:[^\s\p{P}\p{S}]|~)/u,U0=Q(/link|precode-code|html/,"g").replace("link",/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-",y0?"(?<!`)()":"(^^|[^`])").replace("code",/(?<b>`+)[^`]+\k<b>(?!`)/).replace("html",/<(?! )[^<>]*?>/).getRegex(),Jc=/^(?:\*+(?:((?!\*)punct)|([^\s*]))?)|^_+(?:((?!_)punct)|([^\s_]))?/,q0=Q(Jc,"u").replace(/punct/g,mn).getRegex(),B0=Q(Jc,"u").replace(/punct/g,Gc).getRegex(),Yc="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",H0=Q(Yc,"gu").replace(/notPunctSpace/g,Ks).replace(/punctSpace/g,Rr).replace(/punct/g,mn).getRegex(),W0=Q(Yc,"gu").replace(/notPunctSpace/g,F0).replace(/punctSpace/g,Z0).replace(/punct/g,Gc).getRegex(),V0=Q("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,Ks).replace(/punctSpace/g,Rr).replace(/punct/g,mn).getRegex(),G0=Q(/^~~?(?:((?!~)punct)|[^\s~])/,"u").replace(/punct/g,mn).getRegex(),J0="^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)",Y0=Q(J0,"gu").replace(/notPunctSpace/g,Ks).replace(/punctSpace/g,Rr).replace(/punct/g,mn).getRegex(),K0=Q(/\\(punct)/,"gu").replace(/punct/g,mn).getRegex(),X0=Q(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme",/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email",/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),Q0=Q(Js).replace("(?:-->|$)","-->").getRegex(),e_=Q("^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment",Q0).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),gr=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/,t_=Q(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace("label",gr).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]+|(?=\))/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),Kc=Q(/^!?\[(label)\]\[(ref)\]/).replace("label",gr).replace("ref",Gs).getRegex(),Xc=Q(/^!?\[(ref)\](?:\[\])?/).replace("ref",Gs).getRegex(),n_=Q("reflink|nolink(?!\\()","g").replace("reflink",Kc).replace("nolink",Xc).getRegex(),Lo=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,Xs={_backpedal:Pt,anyPunctuation:K0,autolink:X0,blockSkip:U0,br:Vc,code:P0,del:Pt,delLDelim:Pt,delRDelim:Pt,emStrongLDelim:q0,emStrongRDelimAst:H0,emStrongRDelimUnd:V0,escape:O0,link:t_,nolink:Xc,punctuation:D0,reflink:Kc,reflinkSearch:n_,tag:e_,text:M0,url:Pt},r_={...Xs,link:Q(/^!?\[(label)\]\((.*?)\)/).replace("label",gr).getRegex(),reflink:Q(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",gr).getRegex()},_s={...Xs,emStrongRDelimAst:W0,emStrongLDelim:B0,delLDelim:G0,delRDelim:Y0,url:Q(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("protocol",Lo).replace("email",/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/,text:Q(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace("protocol",Lo).getRegex()},s_={..._s,br:Q(Vc).replace("{2,}","*").getRegex(),text:Q(_s.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},nr={normal:Ys,gfm:I0,pedantic:L0},Sn={normal:Xs,gfm:_s,breaks:s_,pedantic:r_},i_={"&":"&","<":"<",">":">",'"':""","'":"'"},Oo=e=>i_[e];function gt(e,t){if(t){if(ze.escapeTest.test(e))return e.replace(ze.escapeReplace,Oo)}else if(ze.escapeTestNoEncode.test(e))return e.replace(ze.escapeReplaceNoEncode,Oo);return e}function Po(e){try{e=encodeURI(e).replace(ze.percentDecode,"%")}catch{return null}return e}function Mo(e,t){var i;let n=e.replace(ze.findPipe,(a,c,l)=>{let d=!1,u=c;for(;--u>=0&&l[u]==="\\";)d=!d;return d?"|":" |"}),r=n.split(ze.splitPipe),s=0;if(r[0].trim()||r.shift(),r.length>0&&!((i=r.at(-1))!=null&&i.trim())&&r.pop(),t)if(r.length>t)r.splice(t);else for(;r.length<t;)r.push("");for(;s<r.length;s++)r[s]=r[s].trim().replace(ze.slashPipe,"|");return r}function Nt(e,t,n){let r=e.length;if(r===0)return"";let s=0;for(;s<r&&e.charAt(r-s-1)===t;)s++;return e.slice(0,r-s)}function Do(e){let t=e.split(`
|
|
344
|
+
`),n=t.length-1;for(;n>=0&&ze.blankLine.test(t[n]);)n--;return t.length-n<=2?e:t.slice(0,n+1).join(`
|
|
345
|
+
`)}function o_(e,t){if(e.indexOf(t[1])===-1)return-1;let n=0;for(let r=0;r<e.length;r++)if(e[r]==="\\")r++;else if(e[r]===t[0])n++;else if(e[r]===t[1]&&(n--,n<0))return r;return n>0?-2:-1}function a_(e,t=0){let n=t,r="";for(let s of e)if(s===" "){let i=4-n%4;r+=" ".repeat(i),n+=i}else r+=s,n++;return r}function Zo(e,t,n,r,s){let i=t.href,a=t.title||null,c=e[1].replace(s.other.outputLinkReplace,"$1");r.state.inLink=!0;let l={type:e[0].charAt(0)==="!"?"image":"link",raw:n,href:i,title:a,text:c,tokens:r.inlineTokens(c)};return r.state.inLink=!1,l}function c_(e,t,n){let r=e.match(n.other.indentCodeCompensation);if(r===null)return t;let s=r[1];return t.split(`
|
|
346
|
+
`).map(i=>{let a=i.match(n.other.beginningSpace);if(a===null)return i;let[c]=a;return c.length>=s.length?i.slice(s.length):i}).join(`
|
|
347
|
+
`)}var xr=class{constructor(e){re(this,"options");re(this,"rules");re(this,"lexer");this.options=e||Ht}space(e){let t=this.rules.block.newline.exec(e);if(t&&t[0].length>0)return{type:"space",raw:t[0]}}code(e){let t=this.rules.block.code.exec(e);if(t){let n=this.options.pedantic?t[0]:Do(t[0]),r=n.replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:n,codeBlockStyle:"indented",text:r}}}fences(e){let t=this.rules.block.fences.exec(e);if(t){let n=t[0],r=c_(n,t[3]||"",this.rules);return{type:"code",raw:n,lang:t[2]?t[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):t[2],text:r}}}heading(e){let t=this.rules.block.heading.exec(e);if(t){let n=t[2].trim();if(this.rules.other.endingHash.test(n)){let r=Nt(n,"#");(this.options.pedantic||!r||this.rules.other.endingSpaceChar.test(r))&&(n=r.trim())}return{type:"heading",raw:Nt(t[0],`
|
|
348
|
+
`),depth:t[1].length,text:n,tokens:this.lexer.inline(n)}}}hr(e){let t=this.rules.block.hr.exec(e);if(t)return{type:"hr",raw:Nt(t[0],`
|
|
349
|
+
`)}}blockquote(e){let t=this.rules.block.blockquote.exec(e);if(t){let n=Nt(t[0],`
|
|
350
|
+
`).split(`
|
|
351
|
+
`),r="",s="",i=[];for(;n.length>0;){let a=!1,c=[],l;for(l=0;l<n.length;l++)if(this.rules.other.blockquoteStart.test(n[l]))c.push(n[l]),a=!0;else if(!a)c.push(n[l]);else break;n=n.slice(l);let d=c.join(`
|
|
352
|
+
`),u=d.replace(this.rules.other.blockquoteSetextReplace,`
|
|
353
|
+
$1`).replace(this.rules.other.blockquoteSetextReplace2,"");r=r?`${r}
|
|
354
|
+
${d}`:d,s=s?`${s}
|
|
355
|
+
${u}`:u;let h=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(u,i,!0),this.lexer.state.top=h,n.length===0)break;let m=i.at(-1);if((m==null?void 0:m.type)==="code")break;if((m==null?void 0:m.type)==="blockquote"){let p=m,g=p.raw+`
|
|
356
|
+
`+n.join(`
|
|
357
|
+
`),_=this.blockquote(g);i[i.length-1]=_,r=r.substring(0,r.length-p.raw.length)+_.raw,s=s.substring(0,s.length-p.text.length)+_.text;break}else if((m==null?void 0:m.type)==="list"){let p=m,g=p.raw+`
|
|
358
|
+
`+n.join(`
|
|
359
|
+
`),_=this.list(g);i[i.length-1]=_,r=r.substring(0,r.length-m.raw.length)+_.raw,s=s.substring(0,s.length-p.raw.length)+_.raw,n=g.substring(i.at(-1).raw.length).split(`
|
|
360
|
+
`);continue}}return{type:"blockquote",raw:r,tokens:i,text:s}}}list(e){let t=this.rules.block.list.exec(e);if(t){let n=t[1].trim(),r=n.length>1,s={type:"list",raw:"",ordered:r,start:r?+n.slice(0,-1):"",loose:!1,items:[]};n=r?`\\d{1,9}\\${n.slice(-1)}`:`\\${n}`,this.options.pedantic&&(n=r?n:"[*+-]");let i=this.rules.other.listItemRegex(n),a=!1;for(;e;){let l=!1,d="",u="";if(!(t=i.exec(e))||this.rules.block.hr.test(e))break;d=t[0],e=e.substring(d.length);let h=a_(t[2].split(`
|
|
361
|
+
`,1)[0],t[1].length),m=e.split(`
|
|
362
|
+
`,1)[0],p=!h.trim(),g=0;if(this.options.pedantic?(g=2,u=h.trimStart()):p?g=t[1].length+1:(g=h.search(this.rules.other.nonSpaceChar),g=g>4?1:g,u=h.slice(g),g+=t[1].length),p&&this.rules.other.blankLine.test(m)&&(d+=m+`
|
|
363
|
+
`,e=e.substring(m.length+1),l=!0),!l){let _=this.rules.other.nextBulletRegex(g),S=this.rules.other.hrRegex(g),C=this.rules.other.fencesBeginRegex(g),A=this.rules.other.headingBeginRegex(g),$=this.rules.other.htmlBeginRegex(g),I=this.rules.other.blockquoteBeginRegex(g);for(;e;){let z=e.split(`
|
|
364
|
+
`,1)[0],k;if(m=z,this.options.pedantic?(m=m.replace(this.rules.other.listReplaceNesting," "),k=m):k=m.replace(this.rules.other.tabCharGlobal," "),C.test(m)||A.test(m)||$.test(m)||I.test(m)||_.test(m)||S.test(m))break;if(k.search(this.rules.other.nonSpaceChar)>=g||!m.trim())u+=`
|
|
365
|
+
`+k.slice(g);else{if(p||h.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||C.test(h)||A.test(h)||S.test(h))break;u+=`
|
|
366
|
+
`+m}p=!m.trim(),d+=z+`
|
|
367
|
+
`,e=e.substring(z.length+1),h=k.slice(g)}}s.loose||(a?s.loose=!0:this.rules.other.doubleBlankLine.test(d)&&(a=!0)),s.items.push({type:"list_item",raw:d,task:!!this.options.gfm&&this.rules.other.listIsTask.test(u),loose:!1,text:u,tokens:[]}),s.raw+=d}let c=s.items.at(-1);if(c)c.raw=c.raw.trimEnd(),c.text=c.text.trimEnd();else return;s.raw=s.raw.trimEnd();for(let l of s.items){this.lexer.state.top=!1,l.tokens=this.lexer.blockTokens(l.text,[]);let d=l.tokens[0];if(l.task&&((d==null?void 0:d.type)==="text"||(d==null?void 0:d.type)==="paragraph")){l.text=l.text.replace(this.rules.other.listReplaceTask,""),d.raw=d.raw.replace(this.rules.other.listReplaceTask,""),d.text=d.text.replace(this.rules.other.listReplaceTask,"");for(let h=this.lexer.inlineQueue.length-1;h>=0;h--)if(this.rules.other.listIsTask.test(this.lexer.inlineQueue[h].src)){this.lexer.inlineQueue[h].src=this.lexer.inlineQueue[h].src.replace(this.rules.other.listReplaceTask,"");break}let u=this.rules.other.listTaskCheckbox.exec(l.raw);if(u){let h={type:"checkbox",raw:u[0]+" ",checked:u[0]!=="[ ]"};l.checked=h.checked,s.loose?l.tokens[0]&&["paragraph","text"].includes(l.tokens[0].type)&&"tokens"in l.tokens[0]&&l.tokens[0].tokens?(l.tokens[0].raw=h.raw+l.tokens[0].raw,l.tokens[0].text=h.raw+l.tokens[0].text,l.tokens[0].tokens.unshift(h)):l.tokens.unshift({type:"paragraph",raw:h.raw,text:h.raw,tokens:[h]}):l.tokens.unshift(h)}}else l.task&&(l.task=!1);if(!s.loose){let u=l.tokens.filter(m=>m.type==="space"),h=u.length>0&&u.some(m=>this.rules.other.anyLine.test(m.raw));s.loose=h}}if(s.loose)for(let l of s.items){l.loose=!0;for(let d of l.tokens)d.type==="text"&&(d.type="paragraph")}return s}}html(e){let t=this.rules.block.html.exec(e);if(t){let n=Do(t[0]);return{type:"html",block:!0,raw:n,pre:t[1]==="pre"||t[1]==="script"||t[1]==="style",text:n}}}def(e){let t=this.rules.block.def.exec(e);if(t){let n=t[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal," "),r=t[2]?t[2].replace(this.rules.other.hrefBrackets,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",s=t[3]?t[3].substring(1,t[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):t[3];return{type:"def",tag:n,raw:Nt(t[0],`
|
|
368
|
+
`),href:r,title:s}}}table(e){var a;let t=this.rules.block.table.exec(e);if(!t||!this.rules.other.tableDelimiter.test(t[2]))return;let n=Mo(t[1]),r=t[2].replace(this.rules.other.tableAlignChars,"").split("|"),s=(a=t[3])!=null&&a.trim()?t[3].replace(this.rules.other.tableRowBlankLine,"").split(`
|
|
369
|
+
`):[],i={type:"table",raw:Nt(t[0],`
|
|
370
|
+
`),header:[],align:[],rows:[]};if(n.length===r.length){for(let c of r)this.rules.other.tableAlignRight.test(c)?i.align.push("right"):this.rules.other.tableAlignCenter.test(c)?i.align.push("center"):this.rules.other.tableAlignLeft.test(c)?i.align.push("left"):i.align.push(null);for(let c=0;c<n.length;c++)i.header.push({text:n[c],tokens:this.lexer.inline(n[c]),header:!0,align:i.align[c]});for(let c of s)i.rows.push(Mo(c,i.header.length).map((l,d)=>({text:l,tokens:this.lexer.inline(l),header:!1,align:i.align[d]})));return i}}lheading(e){let t=this.rules.block.lheading.exec(e);if(t){let n=t[1].trim();return{type:"heading",raw:Nt(t[0],`
|
|
371
|
+
`),depth:t[2].charAt(0)==="="?1:2,text:n,tokens:this.lexer.inline(n)}}}paragraph(e){let t=this.rules.block.paragraph.exec(e);if(t){let n=t[1].charAt(t[1].length-1)===`
|
|
372
|
+
`?t[1].slice(0,-1):t[1];return{type:"paragraph",raw:t[0],text:n,tokens:this.lexer.inline(n)}}}text(e){let t=this.rules.block.text.exec(e);if(t)return{type:"text",raw:t[0],text:t[0],tokens:this.lexer.inline(t[0])}}escape(e){let t=this.rules.inline.escape.exec(e);if(t)return{type:"escape",raw:t[0],text:t[1]}}tag(e){let t=this.rules.inline.tag.exec(e);if(t)return!this.lexer.state.inLink&&this.rules.other.startATag.test(t[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test(t[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test(t[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.test(t[0])&&(this.lexer.state.inRawBlock=!1),{type:"html",raw:t[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:t[0]}}link(e){let t=this.rules.inline.link.exec(e);if(t){let n=t[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(n)){if(!this.rules.other.endAngleBracket.test(n))return;let i=Nt(n.slice(0,-1),"\\");if((n.length-i.length)%2===0)return}else{let i=o_(t[2],"()");if(i===-2)return;if(i>-1){let a=(t[0].indexOf("!")===0?5:4)+t[1].length+i;t[2]=t[2].substring(0,i),t[0]=t[0].substring(0,a).trim(),t[3]=""}}let r=t[2],s="";if(this.options.pedantic){let i=this.rules.other.pedanticHrefTitle.exec(r);i&&(r=i[1],s=i[3])}else s=t[3]?t[3].slice(1,-1):"";return r=r.trim(),this.rules.other.startAngleBracket.test(r)&&(this.options.pedantic&&!this.rules.other.endAngleBracket.test(n)?r=r.slice(1):r=r.slice(1,-1)),Zo(t,{href:r&&r.replace(this.rules.inline.anyPunctuation,"$1"),title:s&&s.replace(this.rules.inline.anyPunctuation,"$1")},t[0],this.lexer,this.rules)}}reflink(e,t){let n;if((n=this.rules.inline.reflink.exec(e))||(n=this.rules.inline.nolink.exec(e))){let r=(n[2]||n[1]).replace(this.rules.other.multipleSpaceGlobal," "),s=t[r.toLowerCase()];if(!s){let i=n[0].charAt(0);return{type:"text",raw:i,text:i}}return Zo(n,s,n[0],this.lexer,this.rules)}}emStrong(e,t,n=""){let r=this.rules.inline.emStrongLDelim.exec(e);if(!(!r||!r[1]&&!r[2]&&!r[3]&&!r[4]||r[4]&&n.match(this.rules.other.unicodeAlphaNumeric))&&(!(r[1]||r[3])||!n||this.rules.inline.punctuation.exec(n))){let s=[...r[0]].length-1,i,a,c=s,l=0,d=r[0][0]==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(d.lastIndex=0,t=t.slice(-1*e.length+s);(r=d.exec(t))!==null;){if(i=r[1]||r[2]||r[3]||r[4]||r[5]||r[6],!i)continue;if(a=[...i].length,r[3]||r[4]){c+=a;continue}else if((r[5]||r[6])&&s%3&&!((s+a)%3)){l+=a;continue}if(c-=a,c>0)continue;a=Math.min(a,a+c+l);let u=[...r[0]][0].length,h=e.slice(0,s+r.index+u+a);if(Math.min(s,a)%2){let p=h.slice(1,-1);return{type:"em",raw:h,text:p,tokens:this.lexer.inlineTokens(p)}}let m=h.slice(2,-2);return{type:"strong",raw:h,text:m,tokens:this.lexer.inlineTokens(m)}}}}codespan(e){let t=this.rules.inline.code.exec(e);if(t){let n=t[2].replace(this.rules.other.newLineCharGlobal," "),r=this.rules.other.nonSpaceChar.test(n),s=this.rules.other.startingSpaceChar.test(n)&&this.rules.other.endingSpaceChar.test(n);return r&&s&&(n=n.substring(1,n.length-1)),{type:"codespan",raw:t[0],text:n}}}br(e){let t=this.rules.inline.br.exec(e);if(t)return{type:"br",raw:t[0]}}del(e,t,n=""){let r=this.rules.inline.delLDelim.exec(e);if(r&&(!r[1]||!n||this.rules.inline.punctuation.exec(n))){let s=[...r[0]].length-1,i,a,c=s,l=this.rules.inline.delRDelim;for(l.lastIndex=0,t=t.slice(-1*e.length+s);(r=l.exec(t))!==null;){if(i=r[1]||r[2]||r[3]||r[4]||r[5]||r[6],!i||(a=[...i].length,a!==s))continue;if(r[3]||r[4]){c+=a;continue}if(c-=a,c>0)continue;a=Math.min(a,a+c);let d=[...r[0]][0].length,u=e.slice(0,s+r.index+d+a),h=u.slice(s,-s);return{type:"del",raw:u,text:h,tokens:this.lexer.inlineTokens(h)}}}}autolink(e){let t=this.rules.inline.autolink.exec(e);if(t){let n,r;return t[2]==="@"?(n=t[1],r="mailto:"+n):(n=t[1],r=n),{type:"link",raw:t[0],text:n,href:r,tokens:[{type:"text",raw:n,text:n}]}}}url(e){var n;let t;if(t=this.rules.inline.url.exec(e)){let r,s;if(t[2]==="@")r=t[0],s="mailto:"+r;else{let i;do i=t[0],t[0]=((n=this.rules.inline._backpedal.exec(t[0]))==null?void 0:n[0])??"";while(i!==t[0]);r=t[0],t[1]==="www."?s="http://"+t[0]:s=t[0]}return{type:"link",raw:t[0],text:r,href:s,tokens:[{type:"text",raw:r,text:r}]}}}inlineText(e){let t=this.rules.inline.text.exec(e);if(t){let n=this.lexer.state.inRawBlock;return{type:"text",raw:t[0],text:t[0],escaped:n}}}},it=class vs{constructor(t){re(this,"tokens");re(this,"options");re(this,"state");re(this,"inlineQueue");re(this,"tokenizer");this.tokens=[],this.tokens.links=Object.create(null),this.options=t||Ht,this.options.tokenizer=this.options.tokenizer||new xr,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};let n={other:ze,block:nr.normal,inline:Sn.normal};this.options.pedantic?(n.block=nr.pedantic,n.inline=Sn.pedantic):this.options.gfm&&(n.block=nr.gfm,this.options.breaks?n.inline=Sn.breaks:n.inline=Sn.gfm),this.tokenizer.rules=n}static get rules(){return{block:nr,inline:Sn}}static lex(t,n){return new vs(n).lex(t)}static lexInline(t,n){return new vs(n).inlineTokens(t)}lex(t){t=t.replace(ze.carriageReturn,`
|
|
373
|
+
`),this.blockTokens(t,this.tokens);for(let n=0;n<this.inlineQueue.length;n++){let r=this.inlineQueue[n];this.inlineTokens(r.src,r.tokens)}return this.inlineQueue=[],this.tokens}blockTokens(t,n=[],r=!1){var i,a,c;this.tokenizer.lexer=this,this.options.pedantic&&(t=t.replace(ze.tabCharGlobal," ").replace(ze.spaceLine,""));let s=1/0;for(;t;){if(t.length<s)s=t.length;else{this.infiniteLoopError(t.charCodeAt(0));break}let l;if((a=(i=this.options.extensions)==null?void 0:i.block)!=null&&a.some(u=>(l=u.call({lexer:this},t,n))?(t=t.substring(l.raw.length),n.push(l),!0):!1))continue;if(l=this.tokenizer.space(t)){t=t.substring(l.raw.length);let u=n.at(-1);l.raw.length===1&&u!==void 0?u.raw+=`
|
|
374
|
+
`:n.push(l);continue}if(l=this.tokenizer.code(t)){t=t.substring(l.raw.length);let u=n.at(-1);(u==null?void 0:u.type)==="paragraph"||(u==null?void 0:u.type)==="text"?(u.raw+=(u.raw.endsWith(`
|
|
375
|
+
`)?"":`
|
|
376
|
+
`)+l.raw,u.text+=`
|
|
377
|
+
`+l.text,this.inlineQueue.at(-1).src=u.text):n.push(l);continue}if(l=this.tokenizer.fences(t)){t=t.substring(l.raw.length),n.push(l);continue}if(l=this.tokenizer.heading(t)){t=t.substring(l.raw.length),n.push(l);continue}if(l=this.tokenizer.hr(t)){t=t.substring(l.raw.length),n.push(l);continue}if(l=this.tokenizer.blockquote(t)){t=t.substring(l.raw.length),n.push(l);continue}if(l=this.tokenizer.list(t)){t=t.substring(l.raw.length),n.push(l);continue}if(l=this.tokenizer.html(t)){t=t.substring(l.raw.length),n.push(l);continue}if(l=this.tokenizer.def(t)){t=t.substring(l.raw.length);let u=n.at(-1);(u==null?void 0:u.type)==="paragraph"||(u==null?void 0:u.type)==="text"?(u.raw+=(u.raw.endsWith(`
|
|
378
|
+
`)?"":`
|
|
379
|
+
`)+l.raw,u.text+=`
|
|
380
|
+
`+l.raw,this.inlineQueue.at(-1).src=u.text):this.tokens.links[l.tag]||(this.tokens.links[l.tag]={href:l.href,title:l.title},n.push(l));continue}if(l=this.tokenizer.table(t)){t=t.substring(l.raw.length),n.push(l);continue}if(l=this.tokenizer.lheading(t)){t=t.substring(l.raw.length),n.push(l);continue}let d=t;if((c=this.options.extensions)!=null&&c.startBlock){let u=1/0,h=t.slice(1),m;this.options.extensions.startBlock.forEach(p=>{m=p.call({lexer:this},h),typeof m=="number"&&m>=0&&(u=Math.min(u,m))}),u<1/0&&u>=0&&(d=t.substring(0,u+1))}if(this.state.top&&(l=this.tokenizer.paragraph(d))){let u=n.at(-1);r&&(u==null?void 0:u.type)==="paragraph"?(u.raw+=(u.raw.endsWith(`
|
|
381
|
+
`)?"":`
|
|
382
|
+
`)+l.raw,u.text+=`
|
|
383
|
+
`+l.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=u.text):n.push(l),r=d.length!==t.length,t=t.substring(l.raw.length);continue}if(l=this.tokenizer.text(t)){t=t.substring(l.raw.length);let u=n.at(-1);(u==null?void 0:u.type)==="text"?(u.raw+=(u.raw.endsWith(`
|
|
384
|
+
`)?"":`
|
|
385
|
+
`)+l.raw,u.text+=`
|
|
386
|
+
`+l.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=u.text):n.push(l);continue}if(t){this.infiniteLoopError(t.charCodeAt(0));break}}return this.state.top=!0,n}inline(t,n=[]){return this.inlineQueue.push({src:t,tokens:n}),n}inlineTokens(t,n=[]){var d,u,h,m,p;this.tokenizer.lexer=this;let r=t,s=null;if(this.tokens.links){let g=Object.keys(this.tokens.links);if(g.length>0)for(;(s=this.tokenizer.rules.inline.reflinkSearch.exec(r))!==null;)g.includes(s[0].slice(s[0].lastIndexOf("[")+1,-1))&&(r=r.slice(0,s.index)+"["+"a".repeat(s[0].length-2)+"]"+r.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(s=this.tokenizer.rules.inline.anyPunctuation.exec(r))!==null;)r=r.slice(0,s.index)+"++"+r.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);let i;for(;(s=this.tokenizer.rules.inline.blockSkip.exec(r))!==null;)i=s[2]?s[2].length:0,r=r.slice(0,s.index+i)+"["+"a".repeat(s[0].length-i-2)+"]"+r.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);r=((u=(d=this.options.hooks)==null?void 0:d.emStrongMask)==null?void 0:u.call({lexer:this},r))??r;let a=!1,c="",l=1/0;for(;t;){if(t.length<l)l=t.length;else{this.infiniteLoopError(t.charCodeAt(0));break}a||(c=""),a=!1;let g;if((m=(h=this.options.extensions)==null?void 0:h.inline)!=null&&m.some(S=>(g=S.call({lexer:this},t,n))?(t=t.substring(g.raw.length),n.push(g),!0):!1))continue;if(g=this.tokenizer.escape(t)){t=t.substring(g.raw.length),n.push(g);continue}if(g=this.tokenizer.tag(t)){t=t.substring(g.raw.length),n.push(g);continue}if(g=this.tokenizer.link(t)){t=t.substring(g.raw.length),n.push(g);continue}if(g=this.tokenizer.reflink(t,this.tokens.links)){t=t.substring(g.raw.length);let S=n.at(-1);g.type==="text"&&(S==null?void 0:S.type)==="text"?(S.raw+=g.raw,S.text+=g.text):n.push(g);continue}if(g=this.tokenizer.emStrong(t,r,c)){t=t.substring(g.raw.length),n.push(g);continue}if(g=this.tokenizer.codespan(t)){t=t.substring(g.raw.length),n.push(g);continue}if(g=this.tokenizer.br(t)){t=t.substring(g.raw.length),n.push(g);continue}if(g=this.tokenizer.del(t,r,c)){t=t.substring(g.raw.length),n.push(g);continue}if(g=this.tokenizer.autolink(t)){t=t.substring(g.raw.length),n.push(g);continue}if(!this.state.inLink&&(g=this.tokenizer.url(t))){t=t.substring(g.raw.length),n.push(g);continue}let _=t;if((p=this.options.extensions)!=null&&p.startInline){let S=1/0,C=t.slice(1),A;this.options.extensions.startInline.forEach($=>{A=$.call({lexer:this},C),typeof A=="number"&&A>=0&&(S=Math.min(S,A))}),S<1/0&&S>=0&&(_=t.substring(0,S+1))}if(g=this.tokenizer.inlineText(_)){t=t.substring(g.raw.length),g.raw.slice(-1)!=="_"&&(c=g.raw.slice(-1)),a=!0;let S=n.at(-1);(S==null?void 0:S.type)==="text"?(S.raw+=g.raw,S.text+=g.text):n.push(g);continue}if(t){this.infiniteLoopError(t.charCodeAt(0));break}}return n}infiniteLoopError(t){let n="Infinite loop on byte: "+t;if(this.options.silent)console.error(n);else throw new Error(n)}},br=class{constructor(e){re(this,"options");re(this,"parser");this.options=e||Ht}space(e){return""}code({text:e,lang:t,escaped:n}){var i;let r=(i=(t||"").match(ze.notSpaceStart))==null?void 0:i[0],s=e.replace(ze.endingNewline,"")+`
|
|
387
|
+
`;return r?'<pre><code class="language-'+gt(r)+'">'+(n?s:gt(s,!0))+`</code></pre>
|
|
388
|
+
`:"<pre><code>"+(n?s:gt(s,!0))+`</code></pre>
|
|
389
|
+
`}blockquote({tokens:e}){return`<blockquote>
|
|
390
|
+
${this.parser.parse(e)}</blockquote>
|
|
391
|
+
`}html({text:e}){return e}def(e){return""}heading({tokens:e,depth:t}){return`<h${t}>${this.parser.parseInline(e)}</h${t}>
|
|
392
|
+
`}hr(e){return`<hr>
|
|
393
|
+
`}list(e){let t=e.ordered,n=e.start,r="";for(let a=0;a<e.items.length;a++){let c=e.items[a];r+=this.listitem(c)}let s=t?"ol":"ul",i=t&&n!==1?' start="'+n+'"':"";return"<"+s+i+`>
|
|
394
|
+
`+r+"</"+s+`>
|
|
395
|
+
`}listitem(e){return`<li>${this.parser.parse(e.tokens)}</li>
|
|
396
|
+
`}checkbox({checked:e}){return"<input "+(e?'checked="" ':"")+'disabled="" type="checkbox"> '}paragraph({tokens:e}){return`<p>${this.parser.parseInline(e)}</p>
|
|
397
|
+
`}table(e){let t="",n="";for(let s=0;s<e.header.length;s++)n+=this.tablecell(e.header[s]);t+=this.tablerow({text:n});let r="";for(let s=0;s<e.rows.length;s++){let i=e.rows[s];n="";for(let a=0;a<i.length;a++)n+=this.tablecell(i[a]);r+=this.tablerow({text:n})}return r&&(r=`<tbody>${r}</tbody>`),`<table>
|
|
398
|
+
<thead>
|
|
399
|
+
`+t+`</thead>
|
|
400
|
+
`+r+`</table>
|
|
401
|
+
`}tablerow({text:e}){return`<tr>
|
|
402
|
+
${e}</tr>
|
|
403
|
+
`}tablecell(e){let t=this.parser.parseInline(e.tokens),n=e.header?"th":"td";return(e.align?`<${n} align="${e.align}">`:`<${n}>`)+t+`</${n}>
|
|
404
|
+
`}strong({tokens:e}){return`<strong>${this.parser.parseInline(e)}</strong>`}em({tokens:e}){return`<em>${this.parser.parseInline(e)}</em>`}codespan({text:e}){return`<code>${gt(e,!0)}</code>`}br(e){return"<br>"}del({tokens:e}){return`<del>${this.parser.parseInline(e)}</del>`}link({href:e,title:t,tokens:n}){let r=this.parser.parseInline(n),s=Po(e);if(s===null)return r;e=s;let i='<a href="'+e+'"';return t&&(i+=' title="'+gt(t)+'"'),i+=">"+r+"</a>",i}image({href:e,title:t,text:n,tokens:r}){r&&(n=this.parser.parseInline(r,this.parser.textRenderer));let s=Po(e);if(s===null)return gt(n);e=s;let i=`<img src="${e}" alt="${gt(n)}"`;return t&&(i+=` title="${gt(t)}"`),i+=">",i}text(e){return"tokens"in e&&e.tokens?this.parser.parseInline(e.tokens):"escaped"in e&&e.escaped?e.text:gt(e.text)}},Qs=class{strong({text:e}){return e}em({text:e}){return e}codespan({text:e}){return e}del({text:e}){return e}html({text:e}){return e}text({text:e}){return e}link({text:e}){return""+e}image({text:e}){return""+e}br(){return""}checkbox({raw:e}){return e}},ot=class ys{constructor(t){re(this,"options");re(this,"renderer");re(this,"textRenderer");this.options=t||Ht,this.options.renderer=this.options.renderer||new br,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new Qs}static parse(t,n){return new ys(n).parse(t)}static parseInline(t,n){return new ys(n).parseInline(t)}parse(t){var r,s;this.renderer.parser=this;let n="";for(let i=0;i<t.length;i++){let a=t[i];if((s=(r=this.options.extensions)==null?void 0:r.renderers)!=null&&s[a.type]){let l=a,d=this.options.extensions.renderers[l.type].call({parser:this},l);if(d!==!1||!["space","hr","heading","code","table","blockquote","list","html","def","paragraph","text"].includes(l.type)){n+=d||"";continue}}let c=a;switch(c.type){case"space":{n+=this.renderer.space(c);break}case"hr":{n+=this.renderer.hr(c);break}case"heading":{n+=this.renderer.heading(c);break}case"code":{n+=this.renderer.code(c);break}case"table":{n+=this.renderer.table(c);break}case"blockquote":{n+=this.renderer.blockquote(c);break}case"list":{n+=this.renderer.list(c);break}case"checkbox":{n+=this.renderer.checkbox(c);break}case"html":{n+=this.renderer.html(c);break}case"def":{n+=this.renderer.def(c);break}case"paragraph":{n+=this.renderer.paragraph(c);break}case"text":{n+=this.renderer.text(c);break}default:{let l='Token with "'+c.type+'" type was not found.';if(this.options.silent)return console.error(l),"";throw new Error(l)}}}return n}parseInline(t,n=this.renderer){var s,i;this.renderer.parser=this;let r="";for(let a=0;a<t.length;a++){let c=t[a];if((i=(s=this.options.extensions)==null?void 0:s.renderers)!=null&&i[c.type]){let d=this.options.extensions.renderers[c.type].call({parser:this},c);if(d!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(c.type)){r+=d||"";continue}}let l=c;switch(l.type){case"escape":{r+=n.text(l);break}case"html":{r+=n.html(l);break}case"link":{r+=n.link(l);break}case"image":{r+=n.image(l);break}case"checkbox":{r+=n.checkbox(l);break}case"strong":{r+=n.strong(l);break}case"em":{r+=n.em(l);break}case"codespan":{r+=n.codespan(l);break}case"br":{r+=n.br(l);break}case"del":{r+=n.del(l);break}case"text":{r+=n.text(l);break}default:{let d='Token with "'+l.type+'" type was not found.';if(this.options.silent)return console.error(d),"";throw new Error(d)}}}return r}},rr,En=(rr=class{constructor(e){re(this,"options");re(this,"block");this.options=e||Ht}preprocess(e){return e}postprocess(e){return e}processAllTokens(e){return e}emStrongMask(e){return e}provideLexer(e=this.block){return e?it.lex:it.lexInline}provideParser(e=this.block){return e?ot.parse:ot.parseInline}},re(rr,"passThroughHooks",new Set(["preprocess","postprocess","processAllTokens","emStrongMask"])),re(rr,"passThroughHooksRespectAsync",new Set(["preprocess","postprocess","processAllTokens"])),rr),l_=class{constructor(...e){re(this,"defaults",Hs());re(this,"options",this.setOptions);re(this,"parse",this.parseMarkdown(!0));re(this,"parseInline",this.parseMarkdown(!1));re(this,"Parser",ot);re(this,"Renderer",br);re(this,"TextRenderer",Qs);re(this,"Lexer",it);re(this,"Tokenizer",xr);re(this,"Hooks",En);this.use(...e)}walkTokens(e,t){var r,s;let n=[];for(let i of e)switch(n=n.concat(t.call(this,i)),i.type){case"table":{let a=i;for(let c of a.header)n=n.concat(this.walkTokens(c.tokens,t));for(let c of a.rows)for(let l of c)n=n.concat(this.walkTokens(l.tokens,t));break}case"list":{let a=i;n=n.concat(this.walkTokens(a.items,t));break}default:{let a=i;(s=(r=this.defaults.extensions)==null?void 0:r.childTokens)!=null&&s[a.type]?this.defaults.extensions.childTokens[a.type].forEach(c=>{let l=a[c].flat(1/0);n=n.concat(this.walkTokens(l,t))}):a.tokens&&(n=n.concat(this.walkTokens(a.tokens,t)))}}return n}use(...e){let t=this.defaults.extensions||{renderers:{},childTokens:{}};return e.forEach(n=>{let r={...n};if(r.async=this.defaults.async||r.async||!1,n.extensions&&(n.extensions.forEach(s=>{if(!s.name)throw new Error("extension name required");if("renderer"in s){let i=t.renderers[s.name];i?t.renderers[s.name]=function(...a){let c=s.renderer.apply(this,a);return c===!1&&(c=i.apply(this,a)),c}:t.renderers[s.name]=s.renderer}if("tokenizer"in s){if(!s.level||s.level!=="block"&&s.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");let i=t[s.level];i?i.unshift(s.tokenizer):t[s.level]=[s.tokenizer],s.start&&(s.level==="block"?t.startBlock?t.startBlock.push(s.start):t.startBlock=[s.start]:s.level==="inline"&&(t.startInline?t.startInline.push(s.start):t.startInline=[s.start]))}"childTokens"in s&&s.childTokens&&(t.childTokens[s.name]=s.childTokens)}),r.extensions=t),n.renderer){let s=this.defaults.renderer||new br(this.defaults);for(let i in n.renderer){if(!(i in s))throw new Error(`renderer '${i}' does not exist`);if(["options","parser"].includes(i))continue;let a=i,c=n.renderer[a],l=s[a];s[a]=(...d)=>{let u=c.apply(s,d);return u===!1&&(u=l.apply(s,d)),u||""}}r.renderer=s}if(n.tokenizer){let s=this.defaults.tokenizer||new xr(this.defaults);for(let i in n.tokenizer){if(!(i in s))throw new Error(`tokenizer '${i}' does not exist`);if(["options","rules","lexer"].includes(i))continue;let a=i,c=n.tokenizer[a],l=s[a];s[a]=(...d)=>{let u=c.apply(s,d);return u===!1&&(u=l.apply(s,d)),u}}r.tokenizer=s}if(n.hooks){let s=this.defaults.hooks||new En;for(let i in n.hooks){if(!(i in s))throw new Error(`hook '${i}' does not exist`);if(["options","block"].includes(i))continue;let a=i,c=n.hooks[a],l=s[a];En.passThroughHooks.has(i)?s[a]=d=>{if(this.defaults.async&&En.passThroughHooksRespectAsync.has(i))return(async()=>{let h=await c.call(s,d);return l.call(s,h)})();let u=c.call(s,d);return l.call(s,u)}:s[a]=(...d)=>{if(this.defaults.async)return(async()=>{let h=await c.apply(s,d);return h===!1&&(h=await l.apply(s,d)),h})();let u=c.apply(s,d);return u===!1&&(u=l.apply(s,d)),u}}r.hooks=s}if(n.walkTokens){let s=this.defaults.walkTokens,i=n.walkTokens;r.walkTokens=function(a){let c=[];return c.push(i.call(this,a)),s&&(c=c.concat(s.call(this,a))),c}}this.defaults={...this.defaults,...r}}),this}setOptions(e){return this.defaults={...this.defaults,...e},this}lexer(e,t){return it.lex(e,t??this.defaults)}parser(e,t){return ot.parse(e,t??this.defaults)}parseMarkdown(e){return(t,n)=>{let r={...n},s={...this.defaults,...r},i=this.onError(!!s.silent,!!s.async);if(this.defaults.async===!0&&r.async===!1)return i(new Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));if(typeof t>"u"||t===null)return i(new Error("marked(): input parameter is undefined or null"));if(typeof t!="string")return i(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(t)+", string expected"));if(s.hooks&&(s.hooks.options=s,s.hooks.block=e),s.async)return(async()=>{let a=s.hooks?await s.hooks.preprocess(t):t,c=await(s.hooks?await s.hooks.provideLexer(e):e?it.lex:it.lexInline)(a,s),l=s.hooks?await s.hooks.processAllTokens(c):c;s.walkTokens&&await Promise.all(this.walkTokens(l,s.walkTokens));let d=await(s.hooks?await s.hooks.provideParser(e):e?ot.parse:ot.parseInline)(l,s);return s.hooks?await s.hooks.postprocess(d):d})().catch(i);try{s.hooks&&(t=s.hooks.preprocess(t));let a=(s.hooks?s.hooks.provideLexer(e):e?it.lex:it.lexInline)(t,s);s.hooks&&(a=s.hooks.processAllTokens(a)),s.walkTokens&&this.walkTokens(a,s.walkTokens);let c=(s.hooks?s.hooks.provideParser(e):e?ot.parse:ot.parseInline)(a,s);return s.hooks&&(c=s.hooks.postprocess(c)),c}catch(a){return i(a)}}}onError(e,t){return n=>{if(n.message+=`
|
|
405
|
+
Please report this to https://github.com/markedjs/marked.`,e){let r="<p>An error occurred:</p><pre>"+gt(n.message+"",!0)+"</pre>";return t?Promise.resolve(r):r}if(t)return Promise.reject(n);throw n}}},qt=new l_;function te(e,t){return qt.parse(e,t)}te.options=te.setOptions=function(e){return qt.setOptions(e),te.defaults=qt.defaults,qc(te.defaults),te};te.getDefaults=Hs;te.defaults=Ht;te.use=function(...e){return qt.use(...e),te.defaults=qt.defaults,qc(te.defaults),te};te.walkTokens=function(e,t){return qt.walkTokens(e,t)};te.parseInline=qt.parseInline;te.Parser=ot;te.parser=ot.parse;te.Renderer=br;te.TextRenderer=Qs;te.Lexer=it;te.lexer=it.lex;te.Tokenizer=xr;te.Hooks=En;te.parse=te;te.options;te.setOptions;te.use;te.walkTokens;te.parseInline;ot.parse;it.lex;te.use({gfm:!0,breaks:!0});const u_=["p","br","hr","h1","h2","h3","h4","h5","h6","strong","em","del","code","pre","ul","ol","li","blockquote","a"],d_=["href","title","start","target","rel"];Uc.addHook("afterSanitizeAttributes",e=>{e.tagName==="A"&&(e.setAttribute("target","_blank"),e.setAttribute("rel","noopener noreferrer"))});function h_(e){const t=te.parse(e,{async:!1});return Uc.sanitize(t,{ALLOWED_TAGS:u_,ALLOWED_ATTR:d_})}function f_(e,t,n){if(t.status==="completed"){const r=e.findIndex(i=>i.kind==="compaction"&&i.status==="loading"),s=r>=0?e[r]:void 0;if((s==null?void 0:s.kind)==="compaction"){const i={...s,status:"completed",trigger:t.trigger??s.trigger,preTokens:t.preTokens??s.preTokens};return[...e.slice(0,r),i,...e.slice(r+1)]}}return[...e,{kind:"compaction",id:`compaction-${String(n)}`,eventIndex:n,...t}]}function Fo(e){if(e.type!=="run.item")return;const t=e.payload;return typeof(t==null?void 0:t.call_id)=="string"?t.call_id:void 0}function m_(e){const t=new Map,n=[];for(const r of e){if(r.kind!=="row"){n.push(r);continue}const{row:s}=r;if(s.event.type==="run.item"&&s.event.item_type==="tool_call"){const i=Fo(s.event);i!==void 0&&t.set(i,n.length),n.push(r);continue}if(s.event.type==="run.item"&&s.event.item_type==="tool_result"){const i=Fo(s.event),a=i===void 0?void 0:t.get(i),c=a===void 0?void 0:n[a];if((c==null?void 0:c.kind)==="row"&&c.row.status==="running"){n[a]={kind:"row",row:{...c.row,resultEventIndex:s.eventIndex,status:s.status,duration_ms:s.duration_ms,output_text:s.output_text,diff:s.diff,image:s.image}};continue}}n.push(r)}return n}function Qc(e){let t=[],n=[];const r=()=>{n.length!==0&&(t=[...t,...Cc(n).map(s=>({kind:"row",row:s}))],n=[])};for(const s of e)s.event.type==="timeline"&&s.event.item.type==="compaction"?(r(),t=f_(t,s.event.item,s.index)):s.event.type==="run.item"&&n.push(s);return r(),m_(t)}function ks(e){var t,n,r;return e.kind==="run"&&((t=e.run)==null?void 0:t.status)==="running"?Number.POSITIVE_INFINITY:e.kind==="run"&&((n=e.run)==null?void 0:n.status)!=="running"?Date.parse(((r=e.run)==null?void 0:r.ended_ts)??e.ts):Date.parse(e.ts)}function el(e){const t=e.flatMap(n=>{var r;return[...((r=n.run)==null?void 0:r.output_mode)==="messages"?[n.id]:[],...n.run_parent_id!==void 0?[n.run_parent_id]:[]]});return t.length>0?Math.min(...t):void 0}function Uo(e){return[...e].sort((t,n)=>{var a,c;const r=t.kind==="run"&&((a=t.run)==null?void 0:a.status)==="running",s=n.kind==="run"&&((c=n.run)==null?void 0:c.status)==="running";if(r!==s)return r?1:-1;const i=r&&s?Date.parse(t.ts)-Date.parse(n.ts):ks(t)-ks(n);return i===0?t.id-n.id:i})}function p_(e){const t=Object.values(e),n=el(t);return n===void 0?Uo(t):[...Uo(t.filter(r=>r.id<n)),...t.filter(r=>r.id>=n).sort((r,s)=>r.id-s.id)]}const g_=2*6e4,x_=120,b_=80,__=300,v_=48,y_=3;function qo(e){const t=e.getBoundingClientRect();let n;for(const r of e.querySelectorAll("[data-read-seq]")){const s=r.getBoundingClientRect();if(s.height<=0)continue;const i=Math.min(s.bottom,t.bottom)-Math.max(s.top,t.top),a=Math.min(v_,s.height/2);if(i<a)continue;const c=Number(r.dataset.readSeq);Number.isSafeInteger(c)&&(n=n===void 0?c:Math.max(n,c))}return n}function tl(e,t){if(!(t||e.deleted===!0||e.ack===!0)&&(e.kind==="chat"||e.kind==="run"&&e.run_parent_id!==void 0||e.kind==="run"&&e.run!==void 0&&e.run.status!=="running"))return e.seq}function k_(e,t,n){const r=new Set((n==null?void 0:n.map(s=>s.id))??[]);return e.filter(s=>{var a;if((s.kind==="ask"||s.kind==="approval")&&n!==void 0&&!r.has(s.id))return!1;const i=s.run_parent_id===void 0?s:t[s.run_parent_id];return(i==null?void 0:i.ack)!==!0||((a=i.run)==null?void 0:a.output_mode)!=="messages"?!0:s.id===(i.run.result_message_id??i.id)})}function Bo(e){var xn,Qe,et;const t=H(y=>ie(y,e.room)),n=t.messages,r=t.members,s=t.selfMemberId,i=t.historyCursor,a=t.hydrated,c=t.support,l=H(y=>y.connected);x.useEffect(()=>Nx(e.room),[e.room]);const d=x.useRef(null),u=x.useRef(null),h=x.useRef(!0),m=x.useRef(0),p=x.useRef(0),[g,_]=x.useState(!1),[S,C]=x.useState(0),A=x.useRef(),[$,I]=x.useState(!1),[z,k]=x.useState(!0),E=x.useRef(!1),L=x.useRef(),J=x.useRef(),ce=t.inbox,Z=x.useMemo(()=>p_(n),[n]),Y=x.useMemo(()=>k_(Z,n,c==null?void 0:c.interactions),[n,Z,c]),G=x.useMemo(()=>(c==null?void 0:c.interactions.filter(y=>n[y.id]===void 0))??[],[n,c]),[oe,Ce]=x.useState([]);x.useEffect(()=>{let y=!0;return Ce([]),fetch(`/api/rooms/${encodeURIComponent(e.room)}/messages?pinned=1`,{headers:{authorization:`Bearer ${e.token()}`}}).then(M=>M.ok?M.json():{messages:[]}).then(M=>{y&&Ce(M.messages)}).catch(()=>{}),()=>{y=!1}},[e.room,e.token]);const ut=x.useMemo(()=>{const y=new Map;for(const M of oe)y.set(M.id,M);for(const M of Z)M.pinned===!0?y.set(M.id,M):y.delete(M.id);return[...y.values()].sort((M,K)=>M.id-K.id)},[oe,Z]),De=s!==void 0?(xn=r[s])==null?void 0:xn.role:void 0,kt=De==="owner"||De==="admin",T=De==="owner"||De==="admin",B=De==="owner"||De==="admin",U=De==="owner"||De==="admin",le=s!==void 0?(Qe=r[s])==null?void 0:Qe.handle:void 0,Ye=x.useMemo(()=>[...new Set(Y.flatMap(y=>{var M;if(y.ack===!0)return[];if(y.run_parent_id!==void 0){const K=n[y.run_parent_id]??(c==null?void 0:c.active_runs.find(fe=>fe.id===y.run_parent_id));return((M=K==null?void 0:K.run)==null?void 0:M.status)==="running"?[]:[y.run_parent_id]}return y.kind==="run"&&y.run!==void 0&&y.run.status!=="running"?[y.id]:[]}))],[n,c,Y]),{segments:Ke,version:pn}=R_(e.room,e.token,Ye),Zn=x.useMemo(()=>Ho(Y,Ke),[Y,Ke]),Wt=x.useRef({room:e.room,ready:!1});Wt.current.room!==e.room&&(Wt.current={room:e.room,ready:!1});const dt=Ye.every(y=>Ms(e.room,y)!==void 0);a&&dt&&(Wt.current.ready=!0);const wt=a&&Wt.current.ready,Ne=x.useCallback(()=>{J.current!==void 0&&clearTimeout(J.current),J.current=void 0},[]),ee=x.useCallback(()=>{const y=L.current,M=d.current;if(y===void 0||!y.merged||y.room!==e.room||M===null)return;const K=document.getElementById(y.anchorId);if(K!==null&&M.contains(K)){const fe=K.getBoundingClientRect().top-M.getBoundingClientRect().top;M.scrollTop+=fe-y.anchorOffset}else M.scrollTop=y.fallbackTop+M.scrollHeight-y.fallbackHeight;m.current=M.scrollTop,p.current=0},[e.room]),xt=x.useCallback(()=>{Ne(),J.current=setTimeout(()=>{ee(),L.current=void 0,E.current=!1,J.current=void 0,I(!1)},120)},[Ne,ee]),ue=x.useMemo(()=>Object.values(r).filter(y=>y.kind==="agent"&&(y.state==="running"||y.state==="queued")).sort((y,M)=>y.state==="running"!=(M.state==="running")?y.state==="running"?-1:1:y.handle.localeCompare(M.handle)),[r]),gn=x.useMemo(()=>A_((c==null?void 0:c.active_runs)??[],Object.values(n)),[c,n]);x.useEffect(()=>{const y=Y.reduce((K,fe)=>Math.max(K,fe.id),0);if(h.current||A.current===void 0){A.current=y;return}const M=A.current;y>M&&(C(K=>K+Y.filter(fe=>fe.id>M).length),A.current=y)},[Y]);const de=(et=Y.at(-1))==null?void 0:et.id;x.useEffect(()=>{const y=d.current;y&&(h.current?(y.scrollTop=y.scrollHeight,m.current=y.scrollTop,_(!1)):_(!0))},[de]);const Xe=x.useRef(0),At=x.useRef(),Ie=x.useRef(),He=x.useCallback(()=>{Ie.current!==void 0&&clearTimeout(Ie.current),Ie.current=void 0,At.current=void 0},[]),We=x.useCallback(()=>{const y=d.current;if(!wt||!l||c===void 0||document.visibilityState!=="visible"||!document.hasFocus()||y===null){He();return}const M=qo(y);if(M===void 0||M<=Xe.current){He();return}At.current===M&&Ie.current!==void 0||(He(),At.current=M,Ie.current=setTimeout(()=>{Ie.current=void 0,At.current=void 0;const K=d.current;K===null||document.visibilityState!=="visible"||!document.hasFocus()||qo(K)!==M||M<=Xe.current||(Xe.current=M,e.connection.act({act:"mark_room_read",through_seq:M}))},__))},[He,l,e.connection,c,wt]);x.useEffect(()=>(Xe.current=0,He(),Ne(),h.current=!0,E.current=!1,L.current=void 0,I(!1),k(!0),()=>{Ne(),E.current=!1,L.current=void 0}),[Ne,He,e.room]),x.useEffect(()=>{l||(Xe.current=0,He())},[He,l]),x.useEffect(()=>{const y=()=>We();window.addEventListener("focus",y),document.addEventListener("visibilitychange",y);const M=requestAnimationFrame(We);return()=>{cancelAnimationFrame(M),He(),window.removeEventListener("focus",y),document.removeEventListener("visibilitychange",y)}},[He,We]),x.useEffect(()=>{const y=requestAnimationFrame(We);return()=>cancelAnimationFrame(y)},[Zn,pn,We]),x.useEffect(()=>{const y=d.current,M=u.current;if(!y||!M)return;let K;const fe=new ResizeObserver(()=>{var Ze;if(((Ze=L.current)==null?void 0:Ze.merged)===!0){Ne(),K!==void 0&&cancelAnimationFrame(K),K=requestAnimationFrame(()=>{ee(),dt&&xt()});return}h.current&&(K!==void 0&&cancelAnimationFrame(K),K=requestAnimationFrame(()=>{h.current&&(y.scrollTop=y.scrollHeight,m.current=y.scrollTop,_(!1),We())}))});return fe.observe(M),()=>{fe.disconnect(),K!==void 0&&cancelAnimationFrame(K)}},[Ne,dt,We,ee,xt]),x.useEffect(()=>{const y=()=>{h.current=!1,_(!0)};return window.addEventListener("hashchange",y),()=>window.removeEventListener("hashchange",y)},[]),x.useEffect(()=>{const y=M=>{const K=M.detail,fe=d.current,Ze=document.getElementById(String(K.id));if(K.room!==e.room||fe===null||Ze===null||!fe.contains(Ze))return;Ne();const Fe=fe.getBoundingClientRect();L.current={room:e.room,anchorId:Ze.id,anchorOffset:Ze.getBoundingClientRect().top-Fe.top,fallbackHeight:fe.scrollHeight,fallbackTop:fe.scrollTop,merged:!0},ee(),dt&&xt()};return window.addEventListener(gs,y),()=>window.removeEventListener(gs,y)},[Ne,dt,e.room,ee,xt]),x.useLayoutEffect(()=>{const y=L.current;y===void 0||!y.merged||y.room!==e.room||(Ne(),ee(),dt&&xt())},[Ne,pn,dt,n,e.room,ee,xt]);const Fn=()=>{var fe;const y=d.current;if(!y)return;const M=y.scrollHeight-y.scrollTop-y.clientHeight,K=m.current-y.scrollTop;if(m.current=y.scrollTop,K>0?p.current+=K:K<0&&(p.current=0),M<b_?(h.current=!0,C(0),requestAnimationFrame(We)):h.current&&p.current>=x_&&(h.current=!1),_(!h.current),We(),y.scrollTop<80&&!E.current&&z&&i!==void 0&&i>1){Ne(),E.current=!0,I(!0),h.current=!1,_(!0);const Ze=y.getBoundingClientRect(),Fe=[...((fe=u.current)==null?void 0:fe.querySelectorAll(":scope > [id]"))??[]].find(_t=>_t.getBoundingClientRect().bottom>Ze.top),bt={room:e.room,anchorId:(Fe==null?void 0:Fe.id)??"",anchorOffset:Fe===void 0?0:Fe.getBoundingClientRect().top-Ze.top,fallbackHeight:y.scrollHeight,fallbackTop:y.scrollTop,merged:!1};L.current=bt,ua(e.room,{before:i,limit:Ln},{token:e.token()}).then(_t=>{if(L.current===bt){if(_t.messages.length===0){k(!1),Ne(),L.current=void 0,E.current=!1,I(!1);return}bt.merged=!0,H.getState().mergeHistoryPage(e.room,_t.messages)}}).catch(()=>{L.current===bt&&(Ne(),L.current=void 0,E.current=!1,I(!1))})}};return o.jsxs("div",{className:"nx-transcript-wrap",children:[ut.length>0&&o.jsxs("div",{className:"nx-pinned-strip","data-testid":"pinned-strip",children:[o.jsx(On,{size:13,"aria-hidden":"true",className:"nx-pinned-mark"}),o.jsx("ul",{className:"nx-pinned-list",children:ut.map(y=>{var M;return o.jsx("li",{children:o.jsxs("button",{type:"button",className:"nx-pinned-item","data-testid":`pinned-${y.id}`,title:y.body,onClick:()=>void Bs(e.room,y.id,e.token),children:[o.jsxs("span",{className:"nx-pinned-who",children:["@",((M=r[y.author])==null?void 0:M.handle)??"…"]}),o.jsx("span",{className:"nx-pinned-snippet",children:w_(y)})]})},y.id)})})]}),o.jsx("div",{ref:d,className:"nx-transcript","data-testid":"timeline","aria-busy":$,onScroll:Fn,tabIndex:0,children:o.jsxs("div",{ref:u,className:"nx-column",children:[!wt&&o.jsx(Z_,{}),wt&&Y.length===0&&o.jsx("p",{className:"nx-empty","data-testid":"timeline-empty",children:"No messages yet — say something."}),wt&&Wo(Zn,{members:r,selfId:s,selfHandle:le,inbox:ce,room:e.room,token:e.token,connection:e.connection,canPin:kt,canDelete:B,canRetry:U}),wt&&G.length>0&&o.jsxs("section",{className:"nx-action-tray","aria-label":"Needs your response","data-testid":"interaction-tray",children:[o.jsx("p",{className:"nx-action-tray-label",children:"Needs your response"}),Wo(Ho(G,new Map),{members:r,selfId:s,selfHandle:le,inbox:ce,room:e.room,token:e.token,connection:e.connection,canPin:kt,canDelete:B,canRetry:U})]}),ue.length>0&&o.jsx("div",{className:"nx-typing-bar","data-testid":"live-activity",children:ue.map(y=>o.jsxs("span",{className:"nx-typing-agent","data-testid":`typing-${y.handle}`,children:[o.jsx(ct,{name:y.handle,accent:vt(y),size:24}),o.jsx(lb,{label:`@${y.handle} is working`}),gn[y.id]!==void 0&&o.jsx(O_,{ts:gn[y.id]}),T&&y.state==="running"&&o.jsx("button",{type:"button",className:"nx-typing-stop","aria-label":`Stop @${y.handle}`,"data-testid":`typing-stop-${y.handle}`,title:"Stop this run (the agent stays alive)",onClick:()=>e.connection.act({act:"interrupt",member_id:y.id}),children:o.jsx(pc,{size:12,"aria-hidden":"true"})})]},y.id))})]})}),g&&o.jsxs("button",{className:`nx-jump ${S===0?"is-arrow":""}`,"aria-label":S===0?"Back to latest":void 0,onClick:()=>{const y=d.current;y&&(y.scrollTop=y.scrollHeight,m.current=y.scrollTop),h.current=!0,C(0),_(!1)},children:[o.jsx(Kp,{size:14,"aria-hidden":"true"}),S>0&&`${S} new message${S===1?"":"s"}`]})]})}function w_(e){const t=e.body.split(`
|
|
406
|
+
`).find(n=>n.trim()!=="")??"";return t.length>80?`${t.slice(0,79)}…`:t||"(no text)"}function S_(e){var c,l;const{message:t,author:n}=e,r=Nr(),s=e.viewerId!==void 0&&t.mentions.some(d=>d.member_id===e.viewerId);if(t.kind==="system")return o.jsx("p",{id:String(t.id),"data-testid":`msg-${t.id}`,className:"nx-system",children:t.body});const i=(n==null?void 0:n.handle)??"…";if(t.ack===!0)return o.jsxs("p",{id:String(t.id),"data-testid":`ack-${i}`,className:"nx-system nx-ack",children:[o.jsx(Os,{size:13,"aria-hidden":"true"})," @",i," acknowledged"]});if(t.deleted===!0)return o.jsxs("article",{id:String(t.id),"data-testid":`msg-${t.id}`,className:`nx-turn is-deleted ${e.grouped?"is-grouped":""} ${e.mine?"is-mine":""}`,children:[!e.grouped&&!r&&o.jsx(ct,{name:i,accent:n?vt(n):"indigo",size:34}),o.jsxs("div",{className:"nx-turn-main",children:[!e.grouped&&o.jsxs("div",{className:"nx-turn-meta",children:[r&&o.jsx(ct,{name:i,accent:n?vt(n):"indigo",size:24}),o.jsxs("strong",{className:"nx-turn-author",children:["@",i]}),o.jsx("time",{className:"nx-turn-time",dateTime:t.ts,children:Ut(t.ts)}),o.jsx("span",{className:"nx-turn-spacer"}),o.jsxs("a",{className:"nx-permalink",href:`#${t.id}`,children:["#",t.id]})]}),o.jsx("p",{className:"nx-deleted","data-testid":`msg-${t.id}-deleted`,children:"[deleted]"})]})]});const a=()=>{const d=t.body.split(`
|
|
407
|
+
`,1)[0]??"";window.dispatchEvent(new CustomEvent("nx-quote",{detail:{text:`@${i} > ${d}`,replyTo:t.id}}))};return o.jsxs("article",{id:String(t.id),"data-testid":t.kind==="run"?`run-${t.id}`:`msg-${t.id}`,"data-read-seq":tl(t,e.mine),"data-mentions-me":s?"true":void 0,className:`nx-turn ${e.grouped?"is-grouped":""} ${e.mine?"is-mine":""} ${t.pinned===!0?"is-pinned":""} ${s?"is-mentioned":""}`,children:[!e.grouped&&!r&&o.jsx(ct,{name:i,accent:n?vt(n):"indigo",size:34}),o.jsxs("div",{className:"nx-turn-main",children:[!e.grouped&&o.jsxs("div",{className:"nx-turn-meta",children:[r&&o.jsx(ct,{name:i,accent:n?vt(n):"indigo",size:24}),o.jsxs("strong",{className:"nx-turn-author",children:["@",i]}),t.origin!==void 0&&o.jsxs("span",{className:"nx-turn-origin",title:`via ${t.origin.platform}`,children:[t.origin.sender_name," · ",t.origin.platform]}),o.jsx("time",{className:"nx-turn-time",dateTime:t.ts,children:Ut(t.ts)}),t.pinned===!0&&o.jsx(On,{size:12,className:"nx-pin-glyph","aria-label":"Pinned","data-testid":`msg-${t.id}-pinned`}),(n==null?void 0:n.kind)==="human"&&o.jsx(T_,{message:t,deliveries:e.deliveries,members:e.members}),o.jsx("span",{className:"nx-turn-spacer"}),o.jsxs("a",{className:"nx-permalink",href:`#${t.id}`,children:["#",t.id]}),o.jsxs("span",{className:"nx-turn-actions",children:[o.jsx("button",{className:"nx-iconbtn is-quiet","aria-label":"Quote message","data-testid":`msg-${t.id}-quote`,onClick:a,children:o.jsx(hc,{size:14,"aria-hidden":"true"})}),t.kind!=="run"&&o.jsx(nl,{text:t.body,label:"Copy message",testId:`msg-${t.id}-copy`}),e.canPin&&o.jsx("button",{className:"nx-iconbtn is-quiet","aria-label":t.pinned===!0?"Unpin message":"Pin message","aria-pressed":t.pinned===!0,"data-testid":`msg-${t.id}-pin`,onClick:()=>e.connection.act({act:"pin_message",message_id:t.id,pinned:t.pinned!==!0}),children:t.pinned===!0?o.jsx(uc,{size:14,"aria-hidden":"true"}):o.jsx(On,{size:14,"aria-hidden":"true"})}),e.canDelete&&t.kind==="chat"&&o.jsx(N_,{messageId:t.id,connection:e.connection}),e.canRetry&&t.kind==="run"&&(((c=t.run)==null?void 0:c.status)==="failed"||((l=t.run)==null?void 0:l.status)==="interrupted")&&o.jsx("button",{className:"nx-iconbtn is-quiet","aria-label":"Retry run","data-testid":`run-${t.id}-retry`,onClick:()=>e.connection.act({act:"retry_run",message_id:t.id}),children:o.jsx(fc,{size:14,"aria-hidden":"true"})})]})]}),t.kind==="run"?o.jsx(I_,{message:t,room:e.room,token:e.token}):t.kind==="ask"||t.kind==="approval"?o.jsx(D_,{message:t,connection:e.connection}):o.jsx(ei,{body:t.body,highlightHandle:s?e.viewerHandle:void 0}),t.attachments!==void 0&&t.attachments.length>0&&o.jsx(j_,{room:e.room,token:e.token,attachments:t.attachments})]})]})}function j_(e){return o.jsx("div",{className:"nx-attachments","data-testid":"message-attachments",children:e.attachments.map(t=>{const n=zb(e.room,t.id,e.token());return Ib(t.mime)?o.jsx("a",{className:"nx-attach-image",href:n,target:"_blank",rel:"noreferrer","data-testid":`attachment-${t.id}`,children:o.jsx("img",{src:n,alt:t.name,loading:"lazy"})},t.id):o.jsxs("a",{className:"nx-attach-download",href:n,download:t.name,"data-testid":`attachment-${t.id}`,children:[o.jsx(cs,{size:14,"aria-hidden":"true"}),o.jsx("span",{className:"nx-attach-name",children:t.name}),o.jsx("span",{className:"nx-attach-size",children:Pc(t.size)})]},t.id)})})}function nl(e){const[t,n]=x.useState(!1);return o.jsx("button",{className:"nx-iconbtn is-quiet","aria-label":e.label,"data-testid":e.testId,onClick:()=>{var r;(r=navigator.clipboard)==null||r.writeText(e.text).then(()=>{n(!0),setTimeout(()=>n(!1),1200)})},children:t?o.jsx(Os,{size:14,"aria-hidden":"true"}):o.jsx(xg,{size:14,"aria-hidden":"true"})})}function N_(e){const[t,n]=x.useState(!1);return o.jsxs(o.Fragment,{children:[o.jsx("button",{className:"nx-iconbtn is-quiet","aria-label":"Delete message","data-testid":`msg-${e.messageId}-delete`,onClick:()=>n(!0),children:o.jsx(cx,{size:14,"aria-hidden":"true"})}),t&&o.jsxs(yt,{label:"Delete message?",onClose:()=>n(!1),alert:!0,testid:"delete-confirm",children:[o.jsx("h2",{className:"nx-dialog-title",children:"Delete this message?"}),o.jsx("p",{className:"nx-dialog-body",children:"The body is purged for everyone and cannot be restored; a “[deleted]” marker stays in its place."}),o.jsxs("div",{className:"nx-dialog-actions",children:[o.jsx(qe,{variant:"quiet",onClick:()=>n(!1),children:"Cancel"}),o.jsx(qe,{variant:"danger","data-testid":"delete-confirm-go",onClick:()=>{e.connection.act({act:"delete_message",message_id:e.messageId}),n(!1)},children:"Delete"})]})]})]})}function T_(e){const t=Object.values(e.deliveries).filter(r=>{var s;return r.message_id===e.message.id&&((s=e.members[r.recipient])==null?void 0:s.kind)==="agent"});if(t.length===0)return null;const n=t.every(r=>r.state==="delivering"||r.state==="consumed");return o.jsx("span",{className:`nx-seen ${n?"is-seen":""}`,title:n?"Delivered to its agents":"Waiting in the queue","data-testid":`msg-${e.message.id}-seen`,"data-seen":n,children:n?o.jsx(ag,{size:13,"aria-hidden":"true"}):o.jsx(pg,{size:12,"aria-hidden":"true"})})}function E_(e,t){const n=t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");return e.replace(new RegExp(`(^|[^\\w@/])@(${n})\\b`,"gi"),'$1<strong class="nx-mention-self">@$2</strong>')}function ei(e){const t=x.useMemo(()=>{const n=h_(e.body);return e.highlightHandle===void 0?n:E_(n,e.highlightHandle)},[e.body,e.highlightHandle]);return o.jsx("div",{className:"nx-prose",dangerouslySetInnerHTML:{__html:t}})}function rl(e){const t=[];for(const n of e){if(n.kind==="compaction"){t.push({kind:"compaction",item:n});continue}const r=n.row,s=t.at(-1);r.icon==="reasoning"||r.event.type==="run.item"&&r.event.item_type==="reasoning_summary"||(r.kind==="tool"?(s==null?void 0:s.kind)==="tools"?s.rows.push(r):t.push({kind:"tools",rows:[r]}):t.push({kind:"prose",row:r}))}return t}function $_(e){var t;if(e.kind==="prose")return e.row.ts;if(e.kind==="tools")return(t=e.rows.find(n=>n.ts!==void 0))==null?void 0:t.ts}function R_(e,t,n){const r=kc(),s=n.join(",");x.useEffect(()=>{for(const c of n)yc(e,t,c,{terminal:!0})},[e,t,s]);const i=x.useRef(new Map);return{segments:x.useMemo(()=>{let c=i.current.get(e);for(c===void 0?c=new Map:i.current.delete(e),i.current.set(e,c);i.current.size>y_;){const d=i.current.keys().next().value;if(d===void 0)break;i.current.delete(d)}const l=new Map;for(const d of n){const u=Ms(e,d);if(u===void 0)continue;const h=c.get(d);if((h==null?void 0:h.events)===u){l.set(d,h.segments);continue}const m=rl(Qc(u.map((p,g)=>({index:g,event:p}))));c.set(d,{events:u,segments:m}),l.set(d,m)}return l},[e,s,r]),version:r}}function C_(e,t,n,r){return n&&r&&e.startsWith(t)?e.slice(t.length):""}function A_(e,t){var s,i;const n={},r=new Set;for(const a of e)((s=a.run)==null?void 0:s.status)==="running"&&(r.add(a.author),n[a.author]=a.run.started_ts??a.ts);for(const a of t){if(a.kind!=="run"||((i=a.run)==null?void 0:i.status)!=="running"||r.has(a.author))continue;const c=a.run.started_ts??a.ts,l=n[a.author];(l===void 0||c>l)&&(n[a.author]=c)}return n}function z_(e,t,n){const r=e.length>0?Math.max(...e):t;return{newestId:r,terminalOwnerId:n??r}}function I_(e){var z;const t=e.message.run_parent_id??e.message.id,n=H(k=>{var L;const E=ie(k,e.room);return E.messages[t]??((L=E.support)==null?void 0:L.active_runs.find(J=>J.id===t))}),r=H(k=>{const E=ie(k,e.room);return Object.values(E.messages).filter(L=>L.id===t||L.run_parent_id===t).map(L=>L.id).sort((L,J)=>L-J).join(",")}),s=(n==null?void 0:n.run)??e.message.run,i=e.message.run_parent_id!==void 0||(s==null?void 0:s.output_mode)==="messages",a=H(k=>ie(k,e.room).runEvents[t]),c=(s==null?void 0:s.status)==="running",l=t===e.message.id,d=kc();x.useEffect(()=>{yc(e.room,e.token,t,{terminal:!c,priority:c})},[e.room,e.token,t,c]);const u=Ms(e.room,t),h=x.useMemo(()=>{const k=Xx(u,a??{events:[],dropped_count:0}),E=i?k.filter(({event:L})=>((L.type==="run.item"||L.type==="timeline"||L.type==="run.completed"?L.output_message_id:void 0)??t)===e.message.id):k;return Qc(E)},[u,a==null?void 0:a.events.length,a==null?void 0:a.dropped_count,i,e.message.id,t,d]),m=x.useMemo(()=>rl(h),[h]),p=m.some(k=>k.kind==="prose"),g=i?e.message.body:((z=e.message.run)==null?void 0:z.final_text)??e.message.body,_=m.filter(k=>k.kind==="prose").map(k=>k.row.text??"").join(""),S=C_(g,_,i,p),C=l?s==null?void 0:s.error:void 0,A=x.useMemo(()=>{const k=(u??[]).find(Z=>Z.type==="run.completed"),E=r===""?[]:r.split(",").map(Number),{newestId:L,terminalOwnerId:J}=z_(E,t,(s==null?void 0:s.result_message_id)??(k==null?void 0:k.output_message_id)),ce=(s==null?void 0:s.status)??(k==null?void 0:k.status);return{newestId:L,terminalOwnerId:J,status:ce}},[u,r,t,s==null?void 0:s.status,s==null?void 0:s.result_message_id]),$=e.message.id===A.terminalOwnerId&&(A.status==="interrupted"||A.status==="failed"),I=c&&m.length===0&&g.length===0&&S.length===0;return o.jsxs("div",{className:`nx-run ${I?"is-evidence-free":""}`,...A.status!==void 0&&{"data-run-status":A.status},children:[m.map((k,E)=>{var L;return k.kind==="compaction"?o.jsx(Mc,{status:k.item.status,trigger:k.item.trigger,preTokens:k.item.preTokens},k.item.id):k.kind==="prose"?o.jsx(ar,{messageId:e.message.id,blockId:k.row.eventIndex,text:k.row.text??""},k.row.eventIndex):o.jsx(sl,{rows:k.rows},`tools-${((L=k.rows[0])==null?void 0:L.eventIndex)??E}`)}),!c&&!p&&g.length>0&&o.jsx(ar,{messageId:e.message.id,blockId:"final",text:g}),!c&&S.length>0&&o.jsx(ar,{messageId:e.message.id,blockId:"final",text:S}),!c&&C!==void 0&&C!==""&&o.jsx("p",{className:"nx-field-note is-error",role:"alert","data-testid":"run-error",children:C}),!c&&$&&o.jsxs("p",{className:`nx-run-status is-${A.status??""}`,"data-testid":`run-${e.message.id}-status`,children:["run ",A.status]})]})}function Ho(e,t){const n=el(e),r=n===void 0?e:e.filter(c=>c.id<n),s=n===void 0?[]:e.filter(c=>c.id>=n).sort((c,l)=>c.id-l.id),i=[];return r.forEach((c,l)=>{const d=l*1e3,u=c.kind==="run"&&c.run!==void 0&&c.run.status!=="running",h=u?t.get(c.id):void 0;if(u&&h!==void 0&&h.some(m=>m.kind==="prose")){let m=Date.parse(c.run.ended_ts??c.ts);h.forEach((p,g)=>{const _=$_(p),S=_!==void 0?Date.parse(_):m;m=S,i.push({kind:"runseg",message:c,segment:p,isLast:g===h.length-1,ts:S,order:d+g})})}else i.push({kind:"turn",message:c,ts:ks(c),order:d})}),[...i.sort((c,l)=>c.ts-l.ts||c.order-l.order),...s.map((c,l)=>({kind:"turn",message:c,ts:Date.parse(c.ts),order:(r.length+l)*1e3}))]}function Wo(e,t){var c,l;const n=[],r=new Set;let s,i=Number.NEGATIVE_INFINITY,a=0;for(;a<e.length;){const d=e[a];if(d.kind==="runseg"){const u=d.message.id,h=[];let m=!1;for(;a<e.length;){const g=e[a];if((g==null?void 0:g.kind)!=="runseg"||g.message.id!==u)break;h.push(g.segment),m=g.isLast,i=g.ts,a+=1}const p=!r.has(u);r.add(u),n.push(o.jsx(L_,{message:d.message,author:t.members[d.message.author],segments:h,isLastStretch:m,anchored:p,mine:d.message.author===t.selfId,canPin:t.canPin,canRetry:t.canRetry,connection:t.connection},`run-${u}-${d.order}`)),s=d.message.author}else{const u=d.message,m=!(u.kind==="run"&&(((c=u.run)==null?void 0:c.status)==="failed"||((l=u.run)==null?void 0:l.status)==="interrupted"))&&s!==void 0&&s===u.author&&u.kind!=="system"&&Number.isFinite(d.ts)&&Number.isFinite(i)&&d.ts-i<g_;n.push(o.jsx(S_,{message:u,author:t.members[u.author],mine:u.author===t.selfId,grouped:m,room:t.room,token:t.token,connection:t.connection,deliveries:t.inbox,members:t.members,canPin:t.canPin,canDelete:t.canDelete,canRetry:t.canRetry,viewerId:t.selfId,viewerHandle:t.selfHandle},`turn-${u.id}`)),s=u.kind==="system"?void 0:u.author,i=d.ts,a+=1}}return n}function L_(e){var l,d;const{message:t,author:n}=e,r=Nr(),s=(n==null?void 0:n.handle)??"…",i=(l=t.run)==null?void 0:l.status,a=(d=t.run)==null?void 0:d.error,c=()=>{const u=t.body.split(`
|
|
408
|
+
`,1)[0]??"";window.dispatchEvent(new CustomEvent("nx-quote",{detail:{text:`@${s} > ${u}`,replyTo:t.id}}))};return o.jsxs("article",{id:e.anchored?String(t.id):void 0,"data-testid":`run-${t.id}`,"data-read-seq":tl(t,e.mine),className:`nx-turn ${e.mine?"is-mine":""}`,children:[!r&&o.jsx(ct,{name:s,accent:n?vt(n):"indigo",size:34}),o.jsxs("div",{className:"nx-turn-main",children:[o.jsxs("div",{className:"nx-turn-meta",children:[r&&o.jsx(ct,{name:s,accent:n?vt(n):"indigo",size:24}),o.jsxs("strong",{className:"nx-turn-author",children:["@",s]}),o.jsx("time",{className:"nx-turn-time",dateTime:t.ts,children:Ut(t.ts)}),e.anchored&&t.pinned===!0&&o.jsx(On,{size:12,className:"nx-pin-glyph","aria-label":"Pinned","data-testid":`msg-${t.id}-pinned`}),o.jsx("span",{className:"nx-turn-spacer"}),o.jsxs("a",{className:"nx-permalink",href:`#${t.id}`,children:["#",t.id]}),e.anchored&&o.jsxs("span",{className:"nx-turn-actions",children:[o.jsx("button",{className:"nx-iconbtn is-quiet","aria-label":"Quote message","data-testid":`msg-${t.id}-quote`,onClick:c,children:o.jsx(hc,{size:14,"aria-hidden":"true"})}),e.canPin&&o.jsx("button",{className:"nx-iconbtn is-quiet","aria-label":t.pinned===!0?"Unpin message":"Pin message","aria-pressed":t.pinned===!0,"data-testid":`msg-${t.id}-pin`,onClick:()=>e.connection.act({act:"pin_message",message_id:t.id,pinned:t.pinned!==!0}),children:t.pinned===!0?o.jsx(uc,{size:14,"aria-hidden":"true"}):o.jsx(On,{size:14,"aria-hidden":"true"})}),e.canRetry&&(i==="failed"||i==="interrupted")&&o.jsx("button",{className:"nx-iconbtn is-quiet","aria-label":"Retry run","data-testid":`run-${t.id}-retry`,onClick:()=>e.connection.act({act:"retry_run",message_id:t.id}),children:o.jsx(fc,{size:14,"aria-hidden":"true"})})]})]}),o.jsxs("div",{className:"nx-run","data-run-status":i??"running",children:[e.segments.map((u,h)=>{var m;return u.kind==="compaction"?o.jsx(Mc,{status:u.item.status,trigger:u.item.trigger,preTokens:u.item.preTokens},u.item.id):u.kind==="prose"?o.jsx(ar,{messageId:t.id,blockId:u.row.eventIndex,text:u.row.text??""},u.row.eventIndex):o.jsx(sl,{rows:u.rows},`tools-${((m=u.rows[0])==null?void 0:m.eventIndex)??h}`)}),e.isLastStretch&&a!==void 0&&a!==""&&o.jsx("p",{className:"nx-field-note is-error",role:"alert","data-testid":"run-error",children:a}),e.isLastStretch&&(i==="interrupted"||i==="failed")&&o.jsxs("p",{className:`nx-run-status is-${i}`,"data-testid":`run-${t.id}-status`,children:["run ",i]})]})]})]})}function ar(e){return o.jsxs("div",{className:"nx-run-block","data-testid":`run-${e.messageId}-block-${e.blockId}`,children:[o.jsx(ei,{body:e.text}),o.jsx("span",{className:"nx-run-block-actions",children:o.jsx(nl,{text:e.text,label:"Copy run block",testId:`run-${e.messageId}-block-${e.blockId}-copy`})})]})}function O_(e){const[,t]=x.useState(0);x.useEffect(()=>{const s=setInterval(()=>t(i=>i+1),1e3);return()=>clearInterval(s)},[]);const n=Math.max(0,Date.now()-Date.parse(e.ts)),r=Math.floor(n/1e3);return o.jsx("span",{className:"nx-typing-elapsed","data-testid":"typing-elapsed","data-elapsed-ms":String(n),"aria-hidden":"true",children:Ac(r*1e3)})}function sl(e){const[t,n]=x.useState(!1);if(e.rows.length===1)return o.jsx(Vo,{row:e.rows[0]});const r=e.rows.some(l=>l.status==="running"),s=e.rows.filter(l=>{var d;return((d=l.diff)==null?void 0:d.unified)!==void 0}),i=s.reduce((l,d)=>{const{added:u,removed:h}=Us(d.diff.unified);return{added:l.added+u,removed:l.removed+h}},{added:0,removed:0}),a=e.rows.length===1?"tool":"tools",c=[r?`Running · ${e.rows.length} ${a} so far`:`Ran ${e.rows.length} ${a}`,s.length>0?`wrote ${s.length} file${s.length===1?"":"s"} +${i.added} −${i.removed}`:void 0].filter(Boolean).join(" · ");return o.jsxs("div",{className:"nx-batch","data-testid":"tool-batch",children:[o.jsxs("button",{className:`nx-batch-line ${r?"is-active":""}`,"aria-expanded":t,onClick:()=>n(l=>!l),children:[o.jsx(ac,{size:14,"aria-hidden":"true",className:t?"is-open":""}),c]}),t&&o.jsx("div",{className:"nx-batch-cards",children:e.rows.map(l=>o.jsx(Vo,{row:l},l.eventIndex))})]})}const P_={terminal:ix,edit:qg,search:Tr,web:Rg,commit:tn,reasoning:tn,text:tn,tool:tn,generic:tn},M_=/^\+(\d+)\s−(\d+)\s(.*)$/;function Vo(e){var d;const[t,n]=x.useState(!1),r=rb(e.row),s=P_[r.icon],i=M_.exec(r.label),a=(d=e.row.diff)==null?void 0:d.path,c=()=>{window.dispatchEvent(new CustomEvent(ps,{detail:{path:a}}))},l=e.row.status==="running"?"Running…":e.row.status==="error"?"Failed":`Done${e.row.duration_ms!==void 0?` · ${Ac(e.row.duration_ms)}`:""}`;return o.jsxs(o.Fragment,{children:[o.jsxs("button",{type:"button",className:`nx-tool is-${e.row.status}`,"data-row-kind":"tool","aria-label":a!==void 0?`Open diff for ${a}`:`Inspect ${e.row.title}`,onClick:a!==void 0?c:()=>n(!0),children:[o.jsx(s,{className:"nx-tool-icon",size:14,"aria-hidden":"true"}),o.jsx("span",{className:`nx-tool-label ${r.mono?"is-mono":""}`,children:i!==null?o.jsxs(o.Fragment,{children:[o.jsxs("span",{className:"nx-stat-add",children:["+",i[1]]})," ",o.jsxs("span",{className:"nx-stat-del",children:["−",i[2]]})," ",i[3]]}):r.label}),o.jsx("span",{className:`nx-tool-mark is-${e.row.status}`,children:e.row.status==="running"?o.jsx(fn,{className:"nx-spin",size:13,"aria-label":"running"}):e.row.status==="error"?o.jsx($t,{size:13,"aria-label":"failed"}):o.jsx(Os,{size:13,"aria-label":"done"})})]}),t&&o.jsxs(yt,{label:`Tool: ${e.row.title}`,onClose:()=>n(!1),wide:!0,testid:"run-inspector",children:[o.jsxs("div",{className:"nx-inspect-head",children:[o.jsx("h2",{className:"nx-dialog-title",children:e.row.title}),o.jsx("span",{className:`nx-tool-status is-${e.row.status}`,children:l})]}),e.row.detail!==void 0&&o.jsx("p",{className:"nx-inspect-detail",children:e.row.detail}),e.row.event.type==="run.item"&&e.row.event.item_type==="tool_call"&&o.jsx("pre",{className:"nx-inspect-block",children:JSON.stringify(e.row.event.payload,null,2)}),e.row.output_text!==void 0&&e.row.output_text!==""&&o.jsx("pre",{className:"nx-inspect-block","data-testid":"inspector-output",children:e.row.output_text})]})]})}function D_(e){const t=e.message.ask,[n,r]=x.useState([]),[s,i]=x.useState(!1);if(!t)return o.jsx(ei,{body:e.message.body});const a=c=>{e.connection.act({act:"answer_interaction",interaction_id:t.interaction_id,answer:c}),i(!0)};return o.jsxs("div",{className:"nx-ask","data-testid":`ask-${e.message.id}`,children:[o.jsxs("div",{className:"nx-ask-head",children:[o.jsx("span",{className:"nx-ask-kind",children:t.kind==="approval"?"Approval needed":"Question"}),t.tool!==void 0&&o.jsx("code",{className:"nx-code",children:t.tool})]}),o.jsx("p",{className:"nx-ask-prompt",children:t.prompt}),t.detail!==void 0&&o.jsx("pre",{className:"nx-ask-detail",children:t.detail}),t.options!==void 0&&t.options.length>0&&o.jsxs("div",{className:"nx-ask-options",children:[t.options.map(c=>o.jsx("button",{className:`nx-btn ${t.multi===!0&&n.includes(c.label)?"is-primary":""}`,disabled:s,title:c.description,"data-testid":`ask-${e.message.id}-${c.label}`,onClick:()=>{t.multi===!0?r(l=>l.includes(c.label)?l.filter(d=>d!==c.label):[...l,c.label]):a(c.label)},children:c.label},c.label)),t.multi===!0&&o.jsx("button",{className:"nx-btn is-primary",disabled:s||n.length===0,onClick:()=>a(n),children:"Send answer"})]}),s&&o.jsx("p",{className:"nx-ask-sent",children:"Answered — waiting for the agent…"})]})}function Z_(){return o.jsx("div",{className:"nx-skeleton","aria-hidden":"true",children:[0,1,2].map(e=>o.jsxs("div",{className:"nx-skeleton-row",children:[o.jsx("span",{className:"nx-skeleton-chip"}),o.jsxs("span",{className:"nx-skeleton-lines",children:[o.jsx("span",{style:{width:"38%"}}),o.jsx("span",{style:{width:"86%"}}),o.jsx("span",{style:{width:"64%"}})]})]},e))})}function F_(e){const t=Op(e.token),[n,r]=x.useState(e.room),s=x.useRef(null);s.current===null&&(s.current=kx({room:e.room,token:e.token,refreshToken:e.refreshToken,onResume:g=>{Tx(g,t)}}));const i=s.current,a=g=>{g!==n&&(i.switchRoom(g),r(g),fr(g),window.history.pushState(null,"",`/?room=${encodeURIComponent(g)}`))};x.useEffect(()=>()=>{var g;(g=s.current)==null||g.dispose()},[]),x.useEffect(()=>{const g=()=>{const _=rc().room;_!==void 0&&(i.switchRoom(_),r(_),fr(_))};return window.addEventListener("popstate",g),()=>window.removeEventListener("popstate",g)},[]);const c=Nr(),[l,d]=x.useState("room"),[u,h]=x.useState(!1),[m,p]=x.useState(!1);return x.useEffect(()=>{if(!m)return;const g=window.matchMedia("(min-width: 720px) and (max-width: 1360px)"),_=()=>{g.matches||p(!1)};return g.addEventListener("change",_),_(),()=>g.removeEventListener("change",_)},[m]),c?o.jsxs("div",{className:"nx-app is-mobile","data-testid":"app","data-surface":l,children:[l==="channels"?o.jsx(Go,{activeRoom:n,token:t,onSwitch:g=>{a(g),d("room")}}):o.jsx(Jo,{room:n,connection:i,token:t,mobile:{onBack:()=>d("channels"),onContext:()=>h(!0)}}),u&&l==="room"&&o.jsxs("div",{className:"nx-mobile-context","data-testid":"mobile-context",children:[o.jsx("button",{className:"nx-mobile-context-close nx-btn",onClick:()=>h(!1),children:"Close"}),o.jsx(Gr,{room:n,token:t,connection:i})]})]}):o.jsxs("div",{className:"nx-app","data-testid":"app",children:[o.jsx(Go,{activeRoom:n,token:t,onSwitch:a}),o.jsx(Jo,{room:n,connection:i,token:t,onContext:()=>p(!0)}),o.jsx(Gr,{room:n,token:t,connection:i}),m&&o.jsx(yt,{label:"Channel context",testid:"responsive-context",onClose:()=>p(!1),children:o.jsxs("div",{className:"nx-responsive-context-shell",children:[o.jsxs("header",{className:"nx-responsive-context-head",children:[o.jsx("h2",{children:"Channel context"}),o.jsx(Se,{icon:$t,label:"Close channel context",variant:"quiet",onClick:()=>p(!1)})]}),o.jsx(Gr,{room:n,token:t,connection:i})]})})]})}function Go(e){const[t,n]=x.useState(!1),r=Zp(e.token),s=H(p=>p.connected),i=H(p=>p.rooms),a=H(p=>ie(p,e.activeRoom)),c=a.room,l=a.members,d=a.selfMemberId;Dp();const u=d!==void 0?l[d]:void 0,h=x.useMemo(()=>Object.fromEntries(Object.entries(i).map(([p,g])=>[p,Object.values(g.members).filter(_=>_.kind==="agent"&&(_.state==="running"||_.state==="queued")).sort((_,S)=>_.handle.localeCompare(S.handle))])),[i]),m=x.useMemo(()=>{const p=r.length>0?[...r]:c!==void 0?[{id:c.id,name:c.name,created_ts:c.created_ts,working:!1,attention:!1,unread:0}]:[],g=_=>{var S;return Date.parse(((S=_.latest)==null?void 0:S.ts)??_.created_ts)||0};return p.sort((_,S)=>{var $,I;const C=((($=h[_.id])==null?void 0:$.length)??0)>0||_.working,A=(((I=h[S.id])==null?void 0:I.length)??0)>0||S.working;return C!==A?C?-1:1:g(S)-g(_)})},[r,c,h]);return o.jsxs("nav",{className:"nx-rail","aria-label":"Channels",children:[o.jsxs("div",{className:"nx-brand",children:[o.jsx("span",{className:"nx-brand-tile","aria-hidden":"true"}),o.jsx("strong",{children:"Codor"})]}),o.jsxs("div",{className:"nx-rail-search",children:[o.jsx(Tr,{size:15,"aria-hidden":"true"}),o.jsx("input",{type:"search",placeholder:"Search","aria-label":"Search channels"})]}),o.jsxs("div",{className:"nx-rail-label",children:[o.jsx(qs,{children:"Channels"}),o.jsx(Se,{icon:dc,label:"Create channel",size:"sm",variant:"quiet","data-testid":"create-room",onClick:()=>n(!0)})]}),o.jsx("ul",{className:"nx-rail-list",children:m.map(p=>{var z;const g=p.id===e.activeRoom,_=h[p.id]??[],S=_.length>0||p.working,C=_.length===1?`@${_[0].handle} is working…`:_.length>1?`${String(_.length)} agents are working…`:"working…",A=p.unread,$=(z=p.latest)==null?void 0:z.ts,I=U_(p);return o.jsx("li",{children:o.jsxs("a",{className:`nx-row ${g?"is-active":""}`,href:`/?room=${encodeURIComponent(p.id)}`,"aria-current":g?"page":void 0,"data-testid":`room-link-${p.id}`,onClick:k=>{k.metaKey||k.ctrlKey||k.shiftKey||(k.preventDefault(),e.onSwitch(p.id))},children:[o.jsx(ct,{name:p.name,accent:"indigo",size:38,presence:p.attention?"error":S?"live":g&&!s?"error":"idle",surface:g?"raised":"surface"}),o.jsxs("span",{className:"nx-row-main",children:[o.jsxs("span",{className:"nx-row-top",children:[o.jsx("span",{className:"nx-row-name",children:p.name}),$!==void 0&&o.jsx("time",{className:"nx-row-time",children:ib($)})]}),o.jsxs("span",{className:"nx-row-bottom",children:[S?o.jsxs("span",{className:"nx-row-working","data-testid":`room-working-${p.id}`,children:[o.jsxs("span",{className:"nx-typing","aria-hidden":"true",children:[o.jsx("span",{}),o.jsx("span",{}),o.jsx("span",{})]}),C]}):p.attention?o.jsx("span",{className:"nx-row-preview is-error",children:"agent needs attention"}):o.jsx("span",{className:"nx-row-preview",children:I}),A>0&&o.jsx("span",{className:"nx-unread","data-testid":`rail-unread-${p.id}`,children:A>99?"99+":A})]})]})]})},p.id)})}),o.jsxs("footer",{className:"nx-rail-footer",children:[o.jsx(ct,{name:(u==null?void 0:u.display_name)??(u==null?void 0:u.handle)??"You",accent:"user",size:32}),o.jsxs("span",{className:"nx-rail-id",children:[o.jsx("strong",{children:(u==null?void 0:u.display_name)??(u==null?void 0:u.handle)??"—"}),o.jsxs("span",{className:`nx-conn ${s?"is-live":"is-error"}`,"data-testid":"connection",title:s?"connected":"reconnecting",children:[o.jsx("span",{className:"nx-conn-dot","aria-hidden":"true"}),s?"Connected":"Reconnecting…"]})]}),o.jsx(Se,{icon:mc,label:"Settings",variant:"quiet",onClick:()=>{window.location.href=`/settings?room=${e.activeRoom}`}})]}),t&&o.jsx(Pb,{token:e.token,onClose:()=>n(!1),onCreated:p=>{n(!1),e.onSwitch(p.id)}})]})}function U_(e){if(!e.latest)return"No messages yet";const t=e.latest.author_handle===""?"…":`@${e.latest.author_handle}`,n=e.latest.preview!==""?e.latest.preview:e.latest.kind==="run"?"run in progress":"…";return`${t}: ${n}`}function Jo(e){const t=H(l=>ie(l,e.room).room),n=H(l=>ie(l,e.room).meter),r=H(l=>l.connected),s=H(l=>Object.values(ie(l,e.room).members).filter(d=>d.removed_ts===void 0&&(d.kind==="human"||d.kind==="agent")).length),i=H(l=>{var d;return(d=Object.values(ie(l,e.room).members).find(u=>u.kind==="agent"&&(u.state==="running"||u.state==="queued")))==null?void 0:d.handle}),[a,c]=x.useState(!1);return e.mobile?o.jsxs("main",{className:"nx-chat","data-testid":"room-view",children:[o.jsxs("header",{className:"nx-mobile-head",children:[o.jsx(Se,{icon:ug,label:"Back to channels","data-testid":"mobile-back",onClick:e.mobile.onBack}),o.jsxs("div",{className:"nx-mobile-title",children:[o.jsx("h1",{children:(t==null?void 0:t.name)??e.room}),o.jsx("span",{className:"nx-mobile-sub",children:i!==void 0?`@${i} is working…`:r?"live":"reconnecting…"})]}),o.jsx(Se,{icon:cc,label:"Channel details","data-testid":"mobile-kebab",onClick:e.mobile.onContext})]}),o.jsx(bo,{room:e.room,connection:e.connection}),o.jsx(Bo,{room:e.room,token:e.token,connection:e.connection}),o.jsx(xo,{room:e.room,token:e.token,connection:e.connection})]}):o.jsxs("main",{className:"nx-chat","data-testid":"room-view",children:[o.jsxs("header",{className:"nx-chat-header",children:[o.jsxs("div",{className:"nx-chat-id",children:[o.jsxs("div",{className:"nx-chat-title",children:[o.jsx("h1",{children:(t==null?void 0:t.name)??e.room}),o.jsx(zc,{tone:r?"live":"error",children:r?"Live":"Offline"})]}),o.jsxs("p",{className:"nx-chat-stats","data-testid":"meter",children:[s," members · ",(n==null?void 0:n.turns)??0," turns · ",un(((n==null?void 0:n.input_tokens)??0)+((n==null?void 0:n.output_tokens)??0))," tokens · ",Lc(n??{cost_usd:0})," today"]})]}),o.jsxs("div",{className:"nx-chat-actions",children:[o.jsx(Se,{icon:ux,label:"Open members and context","data-testid":"responsive-context-trigger",className:"nx-context-trigger",onClick:e.onContext}),o.jsx(Se,{icon:Tr,label:"Search messages","data-testid":"toggle-message-search",onClick:()=>c(!0)}),o.jsx(Db,{room:e.room,connection:e.connection,token:e.token}),o.jsx(Se,{icon:rx,label:"Open ledger graph",onClick:()=>{window.location.href=`/ledger?room=${e.room}`}}),o.jsx(Se,{icon:mc,label:"Channel settings","data-testid":"room-settings",onClick:()=>{window.location.href=`/settings?room=${e.room}`}})]})]}),o.jsx(bo,{room:e.room,connection:e.connection}),o.jsx(Bo,{room:e.room,token:e.token,connection:e.connection}),o.jsx(xo,{room:e.room,token:e.token,connection:e.connection}),a&&o.jsx(Fb,{room:e.room,token:e.token,onClose:()=>c(!1)})]})}ta();const il=document.querySelector("#root");if(!il)throw new Error("missing #root element");const q_=il;function Yo(e,t){const n=new URL(window.location.href);n.searchParams.get("room")!==t&&(n.searchParams.set("room",t),window.history.replaceState(null,"",`${e}${n.search}${n.hash}`))}async function Ko(e,t,n){if(e==="/settings"){const{SettingsPage:r}=await Ot(async()=>{const{SettingsPage:s}=await import("./SettingsPage-Cl3O3UCt.js");return{SettingsPage:s}},__vite__mapDeps([0,1,2,3,4,5]));return o.jsx(r,{room:t,token:n,refreshToken:os})}if(e==="/ledger"){const{LedgerPage:r}=await Ot(async()=>{const{LedgerPage:s}=await import("./LedgerPage-CDSjXPp5.js");return{LedgerPage:s}},__vite__mapDeps([6,4,7,2,5]));return o.jsx(r,{room:t,token:n})}return o.jsx(F_,{room:t,token:n,refreshToken:os})}async function B_(){const e=await os();e!==""&&await gx(e);const t=window.location.pathname,n=`${t}${window.location.search}${window.location.hash}`,r=await(async()=>{if(t==="/pair"){const{PairingPage:l}=await Ot(async()=>{const{PairingPage:d}=await import("./PairingPage-CC8sVZit.js");return{PairingPage:d}},__vite__mapDeps([8,1,2,3,9,5]));return o.jsx(l,{})}if(e===""){if(t==="/"){const{LandingPage:d}=await Ot(async()=>{const{LandingPage:u}=await import("./LandingPage-oLIz_H3H.js");return{LandingPage:u}},__vite__mapDeps([10,9,2,5]));return o.jsx(d,{})}const{PairingPage:l}=await Ot(async()=>{const{PairingPage:d}=await import("./PairingPage-CC8sVZit.js");return{PairingPage:d}},__vite__mapDeps([8,1,2,3,9,5]));return o.jsx(l,{autoPair:!0,returnTo:n})}const s=rc().room,i=await qp(e).catch(()=>{});if(i===void 0){const l=s??er();if(l===void 0){const{StartupUnavailable:d}=await Ot(async()=>{const{StartupUnavailable:u}=await import("./StartupUnavailable-CHDoG9xu.js");return{StartupUnavailable:u}},__vite__mapDeps([11,2,5]));return o.jsx(d,{})}return fr(l),Yo(t,l),Ko(t,l,e)}const a=Fp(i,{explicit:s,remembered:er()});if(a===void 0){er()!==void 0&&eo();const{NoChannels:l}=await Ot(async()=>{const{NoChannels:d}=await import("./NoChannels-yL8IGs8_.js");return{NoChannels:d}},__vite__mapDeps([12,2,5]));return o.jsx(l,{token:e})}const c=er();return c!==void 0&&!i.some(l=>l.id===c)&&eo(),fr(a),Yo(t,a),Ko(t,a,e)})();Rl.createRoot(q_).render(o.jsx(x.StrictMode,{children:o.jsx(_x,{children:r})}))}const jn=new URL(window.location.href);jn.searchParams.has("_codor_update")&&(jn.searchParams.delete("_codor_update"),window.history.replaceState(null,"",`${jn.pathname}${jn.search}${jn.hash}`));B_();"serviceWorker"in navigator&&window.addEventListener("load",()=>{navigator.serviceWorker.register("/sw.js",{scope:"/",type:"module",updateViaCache:"none"}).catch(()=>{})});export{sc as A,qe as B,uo as C,pr as D,zm as E,ln as F,$m as G,Rc as H,Se as I,Zs as J,Fs as K,Sg as L,Mg as M,Bl as N,Er as O,cb as S,cx as T,$t as X,x as a,Ol as b,V as c,kx as d,Al as e,tv as f,Ss as g,ie as h,Ut as i,o as j,yt as k,rv as l,ev as m,K_ as n,ta as o,Q_ as p,iv as q,nv as r,G_ as s,sv as t,H as u,Y_ as v,Os as w,J_ as x,X_ as y,xg as z};
|