opencami 1.3.1 → 1.3.2
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/dist/client/assets/{_sessionKey-CaDTbjXx.js → _sessionKey-Z6Wcnj0N.js} +26 -26
- package/dist/client/assets/{agents-CGtqdyBi.js → agents-D8ZHVQ1Z.js} +2 -2
- package/dist/client/assets/{agents-screen-DzIMcmHe.js → agents-screen-BVK0QTRH.js} +1 -1
- package/dist/client/assets/{button-BcnCTjUT.js → button-CuH8u1uR.js} +1 -1
- package/dist/client/assets/{connect-B8sfEQyb.js → connect-CtDn993i.js} +1 -1
- package/dist/client/assets/file-explorer-screen-DMUuR1uG.js +1 -0
- package/dist/client/assets/{files-BHXmS1J5.js → files-CDMLoJ0u.js} +2 -2
- package/dist/client/assets/{index-CxJ4zG_W.js → index-IGP-Igwt.js} +1 -1
- package/dist/client/assets/{index-BfhiL2JN.js → index-N9-2R5hZ.js} +1 -1
- package/dist/client/assets/{keyboard-shortcuts-dialog-DEknElTu.js → keyboard-shortcuts-dialog-DW--4YLF.js} +1 -1
- package/dist/client/assets/{main-BlX7CS2-.js → main-DrVY5UJU.js} +2 -2
- package/dist/client/assets/{opencami-logo-5KynvViW.js → opencami-logo-ChD2XR2j.js} +1 -1
- package/dist/client/assets/{react-ONC2UaeC.js → react-CzqI3gbN.js} +1 -1
- package/dist/client/assets/search-dialog-DYyFYJmw.js +1 -0
- package/dist/client/assets/{session-export-dialog-DSRWU2YO.js → session-export-dialog-BFizBmGb.js} +1 -1
- package/dist/client/assets/settings-dialog-UvgVi2It.js +1 -0
- package/dist/client/assets/{switch-dAvZcYA-.js → switch-DxW2OWPG.js} +1 -1
- package/dist/client/assets/{use-file-explorer-state-C6lX-h0n.js → use-file-explorer-state-Cii59H70.js} +1 -1
- package/dist/client/assets/{useButton-DhneLsMA.js → useButton-hZdvKtl_.js} +1 -1
- package/dist/server/assets/{_sessionKey-ZF1_Jqbt.js → _sessionKey-DVNrEYFh.js} +38 -9
- package/dist/server/assets/_tanstack-start-manifest_v-PwRq_yJS.js +4 -0
- package/dist/server/assets/{file-explorer-screen-BzvgvV8m.js → file-explorer-screen-Cx0jiLRU.js} +72 -15
- package/dist/server/assets/{files-BxvRDIWU.js → files-Trs1M5ba.js} +1 -1
- package/dist/server/assets/{index-CTTNe_Sf.js → index-Dv2RXDa2.js} +1 -1
- package/dist/server/assets/{router-D5D0udHV.js → router-OoQe2c20.js} +3 -3
- package/dist/server/assets/{search-dialog-C8Oy-FBs.js → search-dialog-Bq0Pnxdb.js} +95 -52
- package/dist/server/assets/{settings-dialog-CQFuAt9B.js → settings-dialog-BsJsnMiu.js} +11 -5
- package/dist/server/server.js +2 -2
- package/package.json +1 -1
- package/dist/client/assets/file-explorer-screen-hjggspl-.js +0 -1
- package/dist/client/assets/search-dialog-40gW31ca.js +0 -1
- package/dist/client/assets/settings-dialog-AsvYzSBc.js +0 -1
- package/dist/server/assets/_tanstack-start-manifest_v-C2FijMus.js +0 -4
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/settings-dialog-
|
|
2
|
-
import{j as h,r as m,L as tn,u as qt,_ as Fn,g as Ks,a as al,b as ll,c as Ws,d as ul}from"./main-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/settings-dialog-UvgVi2It.js","assets/main-DrVY5UJU.js","assets/button-CuH8u1uR.js","assets/use-file-explorer-state-Cii59H70.js","assets/useButton-hZdvKtl_.js","assets/react-CzqI3gbN.js","assets/switch-DxW2OWPG.js","assets/opencami-logo-ChD2XR2j.js","assets/index-IGP-Igwt.js","assets/session-export-dialog-BFizBmGb.js","assets/keyboard-shortcuts-dialog-DW--4YLF.js","assets/search-dialog-DYyFYJmw.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{j as h,r as m,L as tn,u as qt,_ as Fn,g as Ks,a as al,b as ll,c as Ws,d as ul}from"./main-DrVY5UJU.js";import{u as cl,a as Vs,b as fl,c as dt,d as Xs,t as hl,e as Ze,T as Ri,f as Ys,g as pl,h as dl,A as We,i as ml,n as gl,j as xl,k as vn,l as yl,m as Gs,o as bl,p as Ve,q as Ct,r as jt,s as At,v as It,w as Rt,x as En,y as pt,z as kl,B as Ni}from"./useButton-hZdvKtl_.js";import{B as ve,u as wl,c as q,f as Kr,a as xt,b as Sl,H as te,J as Qs,V as $n,d as Cl,e as vl,g as El,h as Js,q as Tl,i as jl,M as Al,l as Wr,j as Zn,I as Il,k as Rl,P as Nl,s as Zs,A as eo,m as Ll,n as Ml,X as Vr,x as Dl,o as zl,D as to,T as Pl,p as Xr,r as no,Q as er,W as Li,t as _l,S as Ol,v as Fl,w as $l}from"./button-CuH8u1uR.js";import{D as ro,a as io,b as so,c as Bl,d as oo,u as Hl,e as Ul,f as ql,g as Kl,h as Wl,i as Vl,j as Xl,k as Yl,l as Gl,m as ao,M as Bn,n as Hn,o as Un,p as mt,q as lo,r as Ql}from"./use-file-explorer-state-Cii59H70.js";import{u as Jl,O as Zl,a as eu}from"./opencami-logo-ChD2XR2j.js";import{s as Yr,h as tu,w as nu,f as ru,a as iu,b as su,c as Mi,r as ou,u as au,C as uo,d as lu,p as co}from"./index-IGP-Igwt.js";import{c as fo}from"./react-CzqI3gbN.js";const uu={classId:"classID",dataType:"datatype",itemId:"itemID",strokeDashArray:"strokeDasharray",strokeDashOffset:"strokeDashoffset",strokeLineCap:"strokeLinecap",strokeLineJoin:"strokeLinejoin",strokeMiterLimit:"strokeMiterlimit",typeOf:"typeof",xLinkActuate:"xlinkActuate",xLinkArcRole:"xlinkArcrole",xLinkHref:"xlinkHref",xLinkRole:"xlinkRole",xLinkShow:"xlinkShow",xLinkTitle:"xlinkTitle",xLinkType:"xlinkType",xmlnsXLink:"xmlnsXlink"};function jr(e){if(!e)return"main";const t=e.trim();if(t.length===0)return"main";const n=t.split(":"),i=(n[n.length-1]??"").trim();return i.length>0?i:t}function et(e){return(Array.isArray(e.content)?e.content:[]).map(n=>n.type==="text"?String(n.text??""):"").join("").trim()}function Tt(e){return(Array.isArray(e.content)?e.content:[]).filter(n=>n.type==="toolCall")}function cu(e){if(typeof e=="number"&&Number.isFinite(e))return e<1e12?e*1e3:e;if(typeof e=="string"){const t=Date.parse(e);if(!Number.isNaN(t))return t}return null}function Ar(e){const t=[e.createdAt,e.created_at,e.timestamp,e.time,e.ts];for(const n of t){const r=cu(n);if(r)return r}return Date.now()}const fu=["agent:main:main","main"];function Ir(e){return fu.includes(e)}const hu=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function pu(e){if(e.includes(":subagent:")||e.startsWith("agent:codex:")||e.includes(":openai:"))return"subagent";if(e.startsWith("isolated:")||e.includes(":cron:"))return"cron";if(e.startsWith("agent:")&&!e.startsWith("agent:main:"))return"other";if(e.startsWith("agent:main:")){const t=e.slice(11);return hu.test(t)?"webchat":"chat"}return"other"}function du(e){return Array.isArray(e)?e.map(t=>{const n=typeof t.key=="string"&&t.key.trim().length>0?t.key.trim():jr(t.friendlyId??t.key),r=typeof t.friendlyId=="string"&&t.friendlyId.trim().length>0?t.friendlyId.trim():jr(n),i=pu(n),s=t,o=typeof s.totalTokens=="number"?s.totalTokens:void 0,a=typeof s.contextTokens=="number"?s.contextTokens:void 0,l=typeof s.status=="string"?s.status:void 0;return{key:n,friendlyId:r,title:typeof t.title=="string"?t.title:void 0,derivedTitle:typeof t.derivedTitle=="string"?t.derivedTitle:void 0,label:typeof t.label=="string"?t.label:void 0,updatedAt:typeof t.updatedAt=="number"?t.updatedAt:void 0,lastMessage:t.lastMessage??null,kind:i,status:l,totalTokens:o,contextTokens:a}}):[]}async function it(e){try{const t=await e.json();return t?.error?String(t.error):t?.message?String(t.message):JSON.stringify(t)}catch{try{return await e.text()}catch{return e.statusText||"Request failed"}}}const mu="Missing gateway auth. Set CLAWDBOT_GATEWAY_TOKEN (recommended) or CLAWDBOT_GATEWAY_PASSWORD in the server environment.";function Di(e){return e.includes(mu)}function zi(e,t){const n=crypto.randomUUID(),r=`opt-${n}`,i=Date.now(),s=[];if(t&&t.length>0)for(const a of t)a.type==="image"&&a.base64&&s.push({type:"image",source:{type:"base64",media_type:a.file.type,data:a.base64}});return e.trim()?s.push({type:"text",text:e}):t&&t.length>0&&s.push({type:"text",text:""}),{clientId:n,optimisticId:r,optimisticMessage:{role:"user",content:s,__optimisticId:r,clientId:n,status:"sending",timestamp:i}}}const be={sessions:["chat","sessions"],history:function(t,n){return["chat","history",t,n]}};async function gu(){const e=await fetch("/api/sessions");if(!e.ok)throw new Error(await it(e));const t=await e.json();return du(t.sessions)}async function xu(e){const t=new URLSearchParams({limit:"200"});e.sessionKey&&t.set("sessionKey",e.sessionKey),e.friendlyId&&t.set("friendlyId",e.friendlyId);const n=await fetch(`/api/history?${t.toString()}`);if(!n.ok)throw new Error(await it(n));return await n.json()}async function yu(){const e=new AbortController,t=window.setTimeout(()=>e.abort(),2500);try{const n=await fetch("/api/ping",{signal:e.signal});if(!n.ok)throw new Error(await it(n));return await n.json()}catch(n){throw n instanceof DOMException&&n.name==="AbortError"?new Error("Gateway check timed out"):n}finally{window.clearTimeout(t)}}function Gr(e,t,n,r){const i=be.history(t,n);e.setQueryData(i,function(o){const a=o,l=Array.isArray(a?.messages)?a.messages:[],u=r(l);return{sessionKey:a?.sessionKey??n,sessionId:a?.sessionId,messages:u}})}function tr(e,t,n,r){Gr(e,t,n,function(s){return[...s,r]})}function bu(e,t,n,r,i){const s=`opt-${r}`;Gr(e,t,n,function(a){return a.map(l=>l.clientId===r||l.__optimisticId===r||l.__optimisticId===s?i(l):l)})}function ku(e,t,n,r,i){Gr(e,t,n,function(o){return o.filter(a=>!(a.clientId===r||a.__optimisticId===r||i&&a.__optimisticId===i))})}function Rr(e,t,n){const r=be.history(t,n);e.setQueryData(r,{sessionKey:n,messages:[]})}function wu(e,t,n,r,i){const s=be.history(t,n),o=be.history(r,i),a=e.getQueryData(s);if(!a)return;const l=Array.isArray(a.messages)?a.messages:[];e.setQueryData(o,{sessionKey:i,sessionId:a.sessionId,messages:l}),e.removeQueries({queryKey:s,exact:!0})}function Su(e,t,n,r){e.setQueryData(be.sessions,function(s){return Array.isArray(s)?s.map(o=>o.key!==t&&o.friendlyId!==n?o:{...o,lastMessage:r}):s})}function Cu(e,t,n){e.setQueryData(be.sessions,function(i){return Array.isArray(i)?i.filter(s=>s.key!==t&&s.friendlyId!==n):i}),e.removeQueries({queryKey:["chat","history",n],exact:!1}),t&&t!==n&&e.removeQueries({queryKey:["chat","history",t],exact:!1})}async function vu(e,t,n,r){e.setQueryData(be.sessions,function(s){return Array.isArray(s)?s.map(o=>o.key===t||o.friendlyId===n?{...o,label:r}:o):s});try{const i=await fetch("/api/sessions",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionKey:t,friendlyId:n,label:r})});if(!i.ok){const s=await it(i);console.error("[updateSessionLabel] Failed to persist:",s)}}catch(i){console.error("[updateSessionLabel] Network error:",i)}}function ho(e){return!e.content||!Array.isArray(e.content)?"":e.content.filter(t=>t.type==="text").map(t=>t.text||"").join(`
|
|
3
3
|
`)}function Eu(e,t,n){const r=[];r.push(`# Conversation: ${e}`),r.push(`Date: ${n.toLocaleString()}`),r.push("");for(const i of t){const s=i.role||"unknown",o=ho(i);if(o){const a=s==="user"?"User":"Assistant";r.push(`## ${a}`),r.push(""),r.push(o),r.push("")}}return r.join(`
|
|
4
4
|
`)}function Tu(e,t,n){const r={title:e,exportDate:n.toISOString(),messages:t.map(i=>({role:i.role,content:i.content,timestamp:i.timestamp}))};return JSON.stringify(r,null,2)}function ju(e,t,n){const r=[];r.push(`Conversation: ${e}`),r.push(`Date: ${n.toLocaleString()}`),r.push("─".repeat(60)),r.push("");for(const i of t){const s=i.role||"unknown",o=ho(i);if(o){const a=s==="user"?"User":"Assistant";r.push(`${a}:`),r.push(o),r.push("")}}return r.join(`
|
|
5
|
-
`)}function Au(e,t,n){const r=new Date;let i,s,o;switch(n){case"markdown":i=Eu(e,t,r),s=`${nr(e)}.md`,o="text/markdown";break;case"json":i=Tu(e,t,r),s=`${nr(e)}.json`,o="application/json";break;case"txt":i=ju(e,t,r),s=`${nr(e)}.txt`,o="text/plain";break;default:throw new Error(`Unsupported format: ${n}`)}Iu(i,s,o)}function nr(e){return e.replace(/[^a-z0-9-_\s]/gi,"").replace(/\s+/g,"-").toLowerCase().slice(0,50)||"conversation"}function Iu(e,t,n){const r=new Blob([e],{type:n}),i=URL.createObjectURL(r),s=document.createElement("a");s.href=i,s.download=t,document.body.appendChild(s),s.click(),document.body.removeChild(s),URL.revokeObjectURL(i)}function Ru({open:e,onOpenChange:t,sessionTitle:n,onSave:r,onCancel:i}){return h.jsx(ro,{open:e,onOpenChange:t,children:h.jsx(io,{children:h.jsxs("div",{className:"p-4",children:[h.jsx(so,{className:"mb-1",children:"Rename"}),h.jsx(Bl,{className:"mb-4",children:"Enter a new name for this session."}),h.jsx("input",{type:"text",defaultValue:n,onKeyDown:s=>{s.key==="Enter"&&(s.preventDefault(),r(s.currentTarget.value))},className:"w-full rounded-lg border border-primary-200 bg-primary-50 px-3 py-2 text-sm text-primary-900 outline-none focus:border-primary-400",placeholder:"Session name",autoFocus:!0}),h.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[h.jsx(oo,{onClick:i,children:"Cancel"}),h.jsx(ve,{onClick:s=>{const o=s.currentTarget.parentElement?.previousElementSibling;r(o.value)},children:"Save"})]})]})})})}function Nu(e){const{children:t,open:n,defaultOpen:r=!1,onOpenChange:i,onOpenChangeComplete:s,actionsRef:o,handle:a,triggerId:l,defaultTriggerId:u=null}=e,c=Hl(),f=!!c,d=wl(()=>a?.store??new Ul({open:n??r,activeTriggerId:l!==void 0?l:u,modal:!0,disablePointerDismissal:!0,nested:f,role:"alertdialog"})).current;d.useControlledProp("open",n,r),d.useControlledProp("activeTriggerId",l,u),d.useSyncedValue("nested",f),d.useContextCallback("onOpenChange",i),d.useContextCallback("onOpenChangeComplete",s);const p=d.useState("payload");ql({store:d,actionsRef:o,parentContext:c?.store.context});const g=m.useMemo(()=>({store:d}),[d]);return h.jsx(Kl.Provider,{value:g,children:typeof t=="function"?t({payload:p}):t})}function Lu({children:e,...t}){return h.jsx(Nu,{...t,children:e})}function Mu({className:e,children:t}){return h.jsxs(Wl,{children:[h.jsx(Vl,{className:"fixed inset-0 bg-primary-950/20 transition-all duration-150 data-[state=open]:opacity-100 data-[state=closed]:opacity-0"}),h.jsx(Xl,{className:q("fixed left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2","w-[min(400px,92vw)] rounded-xl border border-primary-200 bg-primary-50 p-0 shadow-xl","transition-all duration-150","data-[state=open]:opacity-100 data-[state=closed]:opacity-0","data-[state=open]:scale-100 data-[state=closed]:scale-95",e),children:t})]})}function Du({className:e,...t}){return h.jsx(Yl,{className:q("text-lg font-medium text-primary-900",e),...t})}function zu({className:e,...t}){return h.jsx(Gl,{className:q("text-sm text-primary-600",e),...t})}function Pu({className:e,...t}){return h.jsx(ao,{render:h.jsx(ve,{variant:"outline",className:q(e)}),...t})}function _u({className:e,...t}){return h.jsx(ao,{render:h.jsx(ve,{variant:"destructive",className:q(e)}),...t})}function Ou({open:e,onOpenChange:t,sessionTitle:n,onConfirm:r,onCancel:i}){return h.jsx(Lu,{open:e,onOpenChange:t,children:h.jsx(Mu,{children:h.jsxs("div",{className:"p-4",children:[h.jsx(Du,{className:"mb-1",children:"Delete Session"}),h.jsxs(zu,{className:"mb-4",children:['Are you sure you want to delete "',n,'"? This action cannot be undone.']}),h.jsxs("div",{className:"flex justify-end gap-2",children:[h.jsx(Pu,{onClick:i,children:"Cancel"}),h.jsx(_u,{onClick:r,children:"Delete"})]})]})})})}function Fu(e){const{open:t,defaultOpen:n,onOpenChange:r,disabled:i}=e,s=t!==void 0,[o,a]=Jl({controlled:t,default:n,name:"Collapsible",state:"open"}),{mounted:l,setMounted:u,transitionStatus:c}=cl(o,!0,!0),[f,d]=m.useState(o),[{height:p,width:g},b]=m.useState({height:void 0,width:void 0}),w=Vs(),[k,C]=m.useState(),E=k??w,[N,_]=m.useState(!1),[S,M]=m.useState(!1),U=m.useRef(null),O=m.useRef(null),v=m.useRef(null),L=m.useRef(null),A=fl(L,!1),F=dt(T=>{const j=!o,R=Xs(hl,T.nativeEvent);if(r(j,R),R.isCanceled)return;const D=L.current;O.current==="css-animation"&&D!=null&&D.style.removeProperty("animation-name"),!N&&!S&&(O.current!=null&&O.current!=="css-animation"&&!l&&j&&u(!0),O.current==="css-animation"&&(!f&&j&&d(!0),!l&&j&&u(!0))),a(j),O.current==="none"&&l&&!j&&u(!1)});return Qe(()=>{s&&O.current==="none"&&!S&&!o&&u(!1)},[s,S,o,t,u]),m.useMemo(()=>({abortControllerRef:U,animationTypeRef:O,disabled:i,handleTrigger:F,height:p,mounted:l,open:o,panelId:E,panelRef:L,runOnceAnimationsFinish:A,setDimensions:b,setHiddenUntilFound:_,setKeepMounted:M,setMounted:u,setOpen:a,setPanelIdState:C,setVisible:d,transitionDimensionRef:v,transitionStatus:c,visible:f,width:g}),[U,O,i,F,p,l,o,E,L,A,b,_,M,u,a,d,v,c,f,g])}const po=m.createContext(void 0);function mo(){const e=m.useContext(po);if(e===void 0)throw new Error(Kr(15));return e}let nn=(function(e){return e.open="data-open",e.closed="data-closed",e[e.startingStyle=Ri.startingStyle]="startingStyle",e[e.endingStyle=Ri.endingStyle]="endingStyle",e})({}),$u=(function(e){return e.panelOpen="data-panel-open",e})({});const Bu={[nn.open]:""},Hu={[nn.closed]:""},Uu={open(e){return e?{[$u.panelOpen]:""}:null}},qu={open(e){return e?Bu:Hu}},go={...qu,...Ys},Ku=m.forwardRef(function(t,n){const{render:r,className:i,defaultOpen:s=!1,disabled:o=!1,onOpenChange:a,open:l,...u}=t,c=dt(a),f=Fu({open:l,defaultOpen:s,onOpenChange:c,disabled:o}),d=m.useMemo(()=>({open:f.open,disabled:f.disabled,transitionStatus:f.transitionStatus}),[f.open,f.disabled,f.transitionStatus]),p=m.useMemo(()=>({...f,onOpenChange:c,state:d}),[f,c,d]),g=xt("div",t,{state:d,ref:n,props:u,stateAttributesMapping:go});return h.jsx(po.Provider,{value:p,children:g})}),Wu={...Uu,...Ys},Vu=m.forwardRef(function(t,n){const{panelId:r,open:i,handleTrigger:s,state:o,disabled:a}=mo(),{className:l,disabled:u=a,id:c,render:f,nativeButton:d=!0,...p}=t,{getButtonProps:g,buttonRef:b}=pl({disabled:u,focusableWhenDisabled:!0,native:d}),w=m.useMemo(()=>({"aria-controls":i?r:void 0,"aria-expanded":i,onClick:s}),[r,i,s]);return xt("button",t,{state:o,ref:[n,b],props:[w,p,g],stateAttributesMapping:Wu})});let Xu=(function(e){return e.disabled="data-disabled",e.orientation="data-orientation",e})({});function Yu(e){const{abortControllerRef:t,animationTypeRef:n,externalRef:r,height:i,hiddenUntilFound:s,keepMounted:o,id:a,mounted:l,onOpenChange:u,open:c,panelRef:f,runOnceAnimationsFinish:d,setDimensions:p,setMounted:g,setOpen:b,setVisible:w,transitionDimensionRef:k,visible:C,width:E}=e,N=m.useRef(!1),_=m.useRef(null),S=m.useRef(c),M=m.useRef(c),U=dl(),O=m.useMemo(()=>n.current==="css-animation"?!C:!c&&!l,[c,l,C,n]),v=dt(A=>{if(!A)return;if(n.current==null||k.current==null){const j=getComputedStyle(A),R=j.animationName!=="none"&&j.animationName!=="",D=j.transitionDuration!=="0s"&&j.transitionDuration!=="";R&&D||(j.animationName==="none"&&j.transitionDuration!=="0s"?n.current="css-transition":j.animationName!=="none"&&j.transitionDuration==="0s"?n.current="css-animation":n.current="none"),A.getAttribute(Xu.orientation)==="horizontal"||j.transitionProperty.indexOf("width")>-1?k.current="width":k.current="height"}if(n.current!=="css-transition")return;(i===void 0||E===void 0)&&(p({height:A.scrollHeight,width:A.scrollWidth}),M.current&&A.style.setProperty("transition-duration","0s"));let F=-1,T=-1;return F=qe.request(()=>{M.current=!1,T=qe.request(()=>{setTimeout(()=>{A.style.removeProperty("transition-duration")})})}),()=>{qe.cancel(F),qe.cancel(T)}}),L=Sl(r,f,v);return Qe(()=>{if(n.current!=="css-transition")return;const A=f.current;if(!A)return;let F=-1;if(t.current!=null&&(t.current.abort(),t.current=null),c){const T={"justify-content":A.style.justifyContent,"align-items":A.style.alignItems,"align-content":A.style.alignContent,"justify-items":A.style.justifyItems};Object.keys(T).forEach(j=>{A.style.setProperty(j,"initial","important")}),!M.current&&!o&&A.setAttribute(nn.startingStyle,""),p({height:A.scrollHeight,width:A.scrollWidth}),F=qe.request(()=>{Object.entries(T).forEach(([j,R])=>{R===""?A.style.removeProperty(j):A.style.setProperty(j,R)})})}else{if(A.scrollHeight===0&&A.scrollWidth===0)return;p({height:A.scrollHeight,width:A.scrollWidth});const T=new AbortController;t.current=T;const j=T.signal;let R=null;const D=nn.endingStyle;return R=new MutationObserver(H=>{H.some(x=>x.type==="attributes"&&x.attributeName===D)&&(R?.disconnect(),R=null,d(()=>{p({height:0,width:0}),A.style.removeProperty("content-visibility"),g(!1),t.current===T&&(t.current=null)},j))}),R.observe(A,{attributes:!0,attributeFilter:[D]}),()=>{R?.disconnect(),U.cancel(),t.current===T&&(T.abort(),t.current=null)}}return()=>{qe.cancel(F)}},[t,n,U,s,o,l,c,f,d,p,g]),Qe(()=>{if(n.current!=="css-animation")return;const A=f.current;A&&(_.current=A.style.animationName||_.current,A.style.setProperty("animation-name","none"),p({height:A.scrollHeight,width:A.scrollWidth}),!S.current&&!N.current&&A.style.removeProperty("animation-name"),c?(t.current!=null&&(t.current.abort(),t.current=null),g(!0),w(!0)):(t.current=new AbortController,d(()=>{g(!1),w(!1),t.current=null},t.current.signal)))},[t,n,c,f,d,p,g,w,C]),ml(()=>{const A=qe.request(()=>{S.current=!1});return()=>qe.cancel(A)}),Qe(()=>{if(!s)return;const A=f.current;if(!A)return;let F=-1,T=-1;return c&&N.current&&(A.style.transitionDuration="0s",p({height:A.scrollHeight,width:A.scrollWidth}),F=qe.request(()=>{N.current=!1,T=qe.request(()=>{setTimeout(()=>{A.style.removeProperty("transition-duration")})})})),()=>{qe.cancel(F),qe.cancel(T)}},[s,c,f,p]),Qe(()=>{const A=f.current;A&&s&&O&&(A.setAttribute("hidden","until-found"),n.current==="css-transition"&&A.setAttribute(nn.startingStyle,""))},[s,O,n,f]),m.useEffect(function(){const F=f.current;if(!F)return;function T(j){N.current=!0,b(!0),u(!0,Xs(gl,j))}return F.addEventListener("beforematch",T),()=>{F.removeEventListener("beforematch",T)}},[u,f,b]),m.useMemo(()=>({props:{hidden:O,id:a,ref:L}}),[O,a,L])}let Pi=(function(e){return e.collapsiblePanelHeight="--collapsible-panel-height",e.collapsiblePanelWidth="--collapsible-panel-width",e})({});const Gu=m.forwardRef(function(t,n){const{className:r,hiddenUntilFound:i,keepMounted:s,render:o,id:a,...l}=t,{abortControllerRef:u,animationTypeRef:c,height:f,mounted:d,onOpenChange:p,open:g,panelId:b,panelRef:w,runOnceAnimationsFinish:k,setDimensions:C,setHiddenUntilFound:E,setKeepMounted:N,setMounted:_,setPanelIdState:S,setOpen:M,setVisible:U,state:O,transitionDimensionRef:v,visible:L,width:A,transitionStatus:F}=mo(),T=i??!1,j=s??!1;Qe(()=>{if(a)return S(a),()=>{S(void 0)}},[a,S]),Qe(()=>{E(T)},[E,T]),Qe(()=>{N(j)},[N,j]);const{props:R}=Yu({abortControllerRef:u,animationTypeRef:c,externalRef:n,height:f,hiddenUntilFound:T,id:b,keepMounted:j,mounted:d,onOpenChange:p,open:g,panelRef:w,runOnceAnimationsFinish:k,setDimensions:C,setMounted:_,setOpen:M,setVisible:U,transitionDimensionRef:v,visible:L,width:A});xl({open:g&&F==="idle",ref:w,onComplete(){g&&C({height:void 0,width:void 0})}});const D=m.useMemo(()=>({...O,transitionStatus:F}),[O,F]),H=xt("div",t,{state:D,ref:[n,w],props:[R,{style:{[Pi.collapsiblePanelHeight]:f===void 0?"auto":`${f}px`,[Pi.collapsiblePanelWidth]:A===void 0?"auto":`${A}px`}},l],stateAttributesMapping:go});return j||T||!j&&d?H:null});function Tn(e){return h.jsx(Ku,{...e})}function jn({className:e,...t}){return h.jsx(Vu,{className:q("group inline-flex items-center gap-1.5 rounded-md px-2 py-1 text-left text-xs font-medium text-primary-500 transition-colors hover:bg-primary-100 hover:text-primary-700 data-panel-open:text-primary-700",e),...t})}function An({className:e,contentClassName:t,children:n,...r}){return h.jsx(Gu,{className:q('flex h-(--collapsible-panel-height) flex-col overflow-hidden text-sm transition-all duration-150 ease-out data-ending-style:h-0 data-starting-style:h-0 [&[hidden]:not([hidden="until-found"])]:hidden',e),...r,children:h.jsx("div",{className:q("pt-1",t),children:n})})}const xo=m.createContext(void 0);function qn(){const e=m.useContext(xo);if(e===void 0)throw new Error(Kr(53));return e}let In=(function(e){return e.scrollAreaCornerHeight="--scroll-area-corner-height",e.scrollAreaCornerWidth="--scroll-area-corner-width",e})({});const pn=500,_i=16;function Ve(e,t,n){if(!e)return 0;const r=getComputedStyle(e),i=n==="x"?"Inline":"Block";return n==="x"&&t==="margin"?parseFloat(r[`${t}InlineStart`])*2:parseFloat(r[`${t}${i}Start`])+parseFloat(r[`${t}${i}End`])}let Qu=(function(e){return e.orientation="data-orientation",e.hovering="data-hovering",e.scrolling="data-scrolling",e.hasOverflowX="data-has-overflow-x",e.hasOverflowY="data-has-overflow-y",e.overflowXStart="data-overflow-x-start",e.overflowXEnd="data-overflow-x-end",e.overflowYStart="data-overflow-y-start",e.overflowYEnd="data-overflow-y-end",e})({});const dn="base-ui-disable-scrollbar",yo={className:dn,getElement(e){return h.jsx("style",{nonce:e,href:dn,precedence:"base-ui:low",children:`.${dn}{scrollbar-width:none}.${dn}::-webkit-scrollbar{display:none}`})}};let _t=(function(e){return e.hasOverflowX="data-has-overflow-x",e.hasOverflowY="data-has-overflow-y",e.overflowXStart="data-overflow-x-start",e.overflowXEnd="data-overflow-x-end",e.overflowYStart="data-overflow-y-start",e.overflowYEnd="data-overflow-y-end",e})({});const Qr={hasOverflowX:e=>e?{[_t.hasOverflowX]:""}:null,hasOverflowY:e=>e?{[_t.hasOverflowY]:""}:null,overflowXStart:e=>e?{[_t.overflowXStart]:""}:null,overflowXEnd:e=>e?{[_t.overflowXEnd]:""}:null,overflowYStart:e=>e?{[_t.overflowYStart]:""}:null,overflowYEnd:e=>e?{[_t.overflowYEnd]:""}:null,cornerHidden:()=>null},Ju=m.createContext(void 0),Zu={disableStyleElements:!1};function ec(){return m.useContext(Ju)??Zu}const tc={x:0,y:0},Oi={width:0,height:0},nc={xStart:!1,xEnd:!1,yStart:!1,yEnd:!1},rc={x:!1,y:!1,corner:!1},ic=m.forwardRef(function(t,n){const{render:r,className:i,overflowEdgeThreshold:s,...o}=t,a=sc(s),l=Vs(),u=vn(),c=vn(),{nonce:f,disableStyleElements:d}=ec(),[p,g]=m.useState(!1),[b,w]=m.useState(!1),[k,C]=m.useState(!1),[E,N]=m.useState(!1),[_,S]=m.useState(Oi),[M,U]=m.useState(Oi),[O,v]=m.useState(nc),[L,A]=m.useState(rc),F=m.useRef(null),T=m.useRef(null),j=m.useRef(null),R=m.useRef(null),D=m.useRef(null),H=m.useRef(null),z=m.useRef(null),x=m.useRef(!1),V=m.useRef(0),X=m.useRef(0),y=m.useRef(0),Q=m.useRef(0),ne=m.useRef("vertical"),W=m.useRef(tc),me=dt($=>{const ue=$.x-W.current.x,re=$.y-W.current.y;W.current=$,re!==0&&(C(!0),u.start(pn,()=>{C(!1)})),ue!==0&&(w(!0),c.start(pn,()=>{w(!1)}))}),ge=dt($=>{$.button===0&&(x.current=!0,V.current=$.clientY,X.current=$.clientX,ne.current=$.currentTarget.getAttribute(Qu.orientation),T.current&&(y.current=T.current.scrollTop,Q.current=T.current.scrollLeft),D.current&&ne.current==="vertical"&&D.current.setPointerCapture($.pointerId),H.current&&ne.current==="horizontal"&&H.current.setPointerCapture($.pointerId))}),le=dt($=>{if(!x.current)return;const ue=$.clientY-V.current,re=$.clientX-X.current;if(T.current){const pe=T.current.scrollHeight,Be=T.current.clientHeight,Ee=T.current.scrollWidth,Le=T.current.clientWidth;if(D.current&&j.current&&ne.current==="vertical"){const st=Ve(j.current,"padding","y"),et=Ve(D.current,"margin","y"),I=D.current.offsetHeight,P=j.current.offsetHeight-I-st-et,Y=ue/P;T.current.scrollTop=y.current+Y*(pe-Be),$.preventDefault(),C(!0),u.start(pn,()=>{C(!1)})}if(H.current&&R.current&&ne.current==="horizontal"){const st=Ve(R.current,"padding","x"),et=Ve(H.current,"margin","x"),I=H.current.offsetWidth,P=R.current.offsetWidth-I-st-et,Y=re/P;T.current.scrollLeft=Q.current+Y*(Ee-Le),$.preventDefault(),w(!0),c.start(pn,()=>{w(!1)})}}}),ie=dt($=>{x.current=!1,D.current&&ne.current==="vertical"&&D.current.releasePointerCapture($.pointerId),H.current&&ne.current==="horizontal"&&H.current.releasePointerCapture($.pointerId)});function be($){N($.pointerType==="touch")}function ke($){if(be($),$.pointerType!=="touch"){const ue=yl(F.current,$.target);g(ue)}}const we=m.useMemo(()=>({hasOverflowX:!L.x,hasOverflowY:!L.y,overflowXStart:O.xStart,overflowXEnd:O.xEnd,overflowYStart:O.yStart,overflowYEnd:O.yEnd,cornerHidden:L.corner}),[L.x,L.y,L.corner,O]),Se={role:"presentation",onPointerEnter:ke,onPointerMove:ke,onPointerDown:be,onPointerLeave(){g(!1)},style:{position:"relative",[In.scrollAreaCornerHeight]:`${_.height}px`,[In.scrollAreaCornerWidth]:`${_.width}px`}},K=xt("div",t,{state:we,ref:[n,F],props:[Se,o],stateAttributesMapping:Qr}),Z=m.useMemo(()=>({handlePointerDown:ge,handlePointerMove:le,handlePointerUp:ie,handleScroll:me,cornerSize:_,setCornerSize:S,thumbSize:M,setThumbSize:U,touchModality:E,cornerRef:z,scrollingX:b,setScrollingX:w,scrollingY:k,setScrollingY:C,hovering:p,setHovering:g,viewportRef:T,rootRef:F,scrollbarYRef:j,scrollbarXRef:R,thumbYRef:D,thumbXRef:H,rootId:l,hiddenState:L,setHiddenState:A,overflowEdges:O,setOverflowEdges:v,viewportState:we,overflowEdgeThreshold:a}),[ge,le,ie,me,_,M,E,b,w,k,C,p,g,l,L,O,we,a]);return h.jsxs(xo.Provider,{value:Z,children:[!d&&yo.getElement(f),K]})});function sc(e){if(typeof e=="number"){const t=Math.max(0,e);return{xStart:t,xEnd:t,yStart:t,yEnd:t}}return{xStart:Math.max(0,e?.xStart||0),xEnd:Math.max(0,e?.xEnd||0),yStart:Math.max(0,e?.yStart||0),yEnd:Math.max(0,e?.yEnd||0)}}const oc=m.createContext(void 0);function ot(e,t=Number.MIN_SAFE_INTEGER,n=Number.MAX_SAFE_INTEGER){return Math.max(t,Math.min(e,n))}function ac(e,t){if(typeof IntersectionObserver>"u")return()=>{};const n=new IntersectionObserver(r=>{r.forEach(i=>{i.intersectionRatio>0&&(t(),n.disconnect())})});return n.observe(e),()=>{n.disconnect()}}let gt=(function(e){return e.scrollAreaOverflowXStart="--scroll-area-overflow-x-start",e.scrollAreaOverflowXEnd="--scroll-area-overflow-x-end",e.scrollAreaOverflowYStart="--scroll-area-overflow-y-start",e.scrollAreaOverflowYEnd="--scroll-area-overflow-y-end",e})({}),Fi=!1;function lc(){Fi||bl||(typeof CSS<"u"&&"registerProperty"in CSS&&[gt.scrollAreaOverflowXStart,gt.scrollAreaOverflowXEnd,gt.scrollAreaOverflowYStart,gt.scrollAreaOverflowYEnd].forEach(e=>{try{CSS.registerProperty({name:e,syntax:"<length>",inherits:!1,initialValue:"0px"})}catch{}}),Fi=!0)}const uc=m.forwardRef(function(t,n){const{render:r,className:i,...s}=t,{viewportRef:o,scrollbarYRef:a,scrollbarXRef:l,thumbYRef:u,thumbXRef:c,cornerRef:f,cornerSize:d,setCornerSize:p,setThumbSize:g,rootId:b,setHiddenState:w,hiddenState:k,handleScroll:C,setHovering:E,setOverflowEdges:N,overflowEdges:_,overflowEdgeThreshold:S}=qn(),M=Gs(),U=m.useRef(!0),O=vn(),v=vn(),L=dt(()=>{const D=o.current,H=a.current,z=l.current,x=u.current,V=c.current,X=f.current;if(!D)return;const y=D.scrollHeight,Q=D.scrollWidth,ne=D.clientHeight,W=D.clientWidth,me=D.scrollTop,ge=D.scrollLeft;if(y===0||Q===0)return;const le=ne>=y,ie=W>=Q,be=W/Q,ke=ne/y,we=Math.max(0,Q-W),Se=Math.max(0,y-ne);let K=0,Z=0;ie||(M==="rtl"?K=ot(-ge,0,we):K=ot(ge,0,we),Z=we-K);const $=le?0:ot(me,0,Se),ue=le?0:Se-$,re=ie?0:W,pe=le?0:ne;let Be=0,Ee=0;!ie&&!le&&(Be=H?.offsetWidth||0,Ee=z?.offsetHeight||0);const Le=d.width===0&&d.height===0,st=Le?Be:0,et=Le?Ee:0,I=Ve(z,"padding","x"),P=Ve(H,"padding","y"),Y=Ve(V,"margin","x"),ee=Ve(x,"margin","y"),ae=re-I-Y,Te=pe-P-ee,He=z?Math.min(z.offsetWidth-st,ae):ae,Oe=H?Math.min(H.offsetHeight-et,Te):Te,Xe=Math.max(_i,He*be),Ue=Math.max(_i,Oe*ke);if(g(de=>de.height===Ue&&de.width===Xe?de:{width:Xe,height:Ue}),H&&x){const de=H.offsetHeight-Ue-P-ee,Ae=y-ne,wt=Ae===0?0:me/Ae,ut=Math.min(de,Math.max(0,wt*de));x.style.transform=`translate3d(0,${ut}px,0)`}if(z&&V){const de=z.offsetWidth-Xe-I-Y,Ae=Q-W,wt=Ae===0?0:ge/Ae,ut=M==="rtl"?ot(wt*de,-de,0):ot(wt*de,0,de);V.style.transform=`translate3d(${ut}px,0,0)`}const Ce=ot(K,0,we),je=ot(Z,0,we),ze=ot($,0,Se),bt=ot(ue,0,Se),zt=[[gt.scrollAreaOverflowXStart,Ce],[gt.scrollAreaOverflowXEnd,je],[gt.scrollAreaOverflowYStart,ze],[gt.scrollAreaOverflowYEnd,bt]];for(const[de,Ae]of zt)D.style.setProperty(de,`${Ae}px`);X&&(ie||le?p({width:0,height:0}):!ie&&!le&&p({width:Be,height:Ee})),w(de=>{const Ae=le||ie;return de.y===le&&de.x===ie&&de.corner===Ae?de:{y:le,x:ie,corner:Ae}});const kt={xStart:!ie&&Ce>S.xStart,xEnd:!ie&&je>S.xEnd,yStart:!le&&ze>S.yStart,yEnd:!le&&bt>S.yEnd};N(de=>de.xStart===kt.xStart&&de.xEnd===kt.xEnd&&de.yStart===kt.yStart&&de.yEnd===kt.yEnd?de:kt)});Qe(()=>{if(!o.current)return;lc();let D=!1;return ac(o.current,()=>{if(!D){D=!0;return}L()})},[L,o]),Qe(()=>{queueMicrotask(L)},[L,k,M]),Qe(()=>{o.current?.matches(":hover")&&E(!0)},[o,E]),m.useEffect(()=>{const D=o.current;if(typeof ResizeObserver>"u"||!D)return;let H=!1;const z=new ResizeObserver(()=>{if(!H){H=!0;return}L()});return z.observe(D),v.start(0,()=>{const x=D.getAnimations({subtree:!0});x.length!==0&&Promise.all(x.map(V=>V.finished)).then(L).catch(()=>{})}),()=>{z.disconnect(),v.clear()}},[L,o,v]);function A(){U.current=!1}const F={role:"presentation",...b&&{"data-id":`${b}-viewport`},...(!k.x||!k.y)&&{tabIndex:0},className:yo.className,style:{overflow:"scroll"},onScroll(){o.current&&(L(),U.current||C({x:o.current.scrollLeft,y:o.current.scrollTop}),O.start(100,()=>{U.current=!0}))},onWheel:A,onTouchMove:A,onPointerMove:A,onPointerEnter:A,onKeyDown:A},T=m.useMemo(()=>({hasOverflowX:!k.x,hasOverflowY:!k.y,overflowXStart:_.xStart,overflowXEnd:_.xEnd,overflowYStart:_.yStart,overflowYEnd:_.yEnd,cornerHidden:k.corner}),[k.x,k.y,k.corner,_]),j=xt("div",t,{ref:[n,o],state:T,props:[F,s],stateAttributesMapping:Qr}),R=m.useMemo(()=>({computeThumbPosition:L}),[L]);return h.jsx(oc.Provider,{value:R,children:j})}),bo=m.createContext(void 0);function cc(){const e=m.useContext(bo);if(e===void 0)throw new Error(Kr(54));return e}let Rn=(function(e){return e.scrollAreaThumbHeight="--scroll-area-thumb-height",e.scrollAreaThumbWidth="--scroll-area-thumb-width",e})({});const fc=m.forwardRef(function(t,n){const{render:r,className:i,orientation:s="vertical",keepMounted:o=!1,...a}=t,{hovering:l,scrollingX:u,scrollingY:c,hiddenState:f,overflowEdges:d,scrollbarYRef:p,scrollbarXRef:g,viewportRef:b,thumbYRef:w,thumbXRef:k,handlePointerDown:C,handlePointerUp:E,rootId:N,thumbSize:_}=qn(),S=m.useMemo(()=>({hovering:l,scrolling:{horizontal:u,vertical:c}[s],orientation:s,hasOverflowX:!f.x,hasOverflowY:!f.y,overflowXStart:d.xStart,overflowXEnd:d.xEnd,overflowYStart:d.yStart,overflowYEnd:d.yEnd,cornerHidden:f.corner}),[l,u,c,s,f,d]),M=Gs();m.useEffect(()=>{const F=b.current,T=s==="vertical"?p.current:g.current;if(!T)return;function j(R){if(!(!F||!T||R.ctrlKey)){if(R.preventDefault(),s==="vertical"){if(F.scrollTop===0&&R.deltaY<0)return}else if(F.scrollLeft===0&&R.deltaX<0)return;if(s==="vertical"){if(F.scrollTop===F.scrollHeight-F.clientHeight&&R.deltaY>0)return}else if(F.scrollLeft===F.scrollWidth-F.clientWidth&&R.deltaX>0)return;s==="vertical"?F.scrollTop+=R.deltaY:F.scrollLeft+=R.deltaX}}return T.addEventListener("wheel",j,{passive:!1}),()=>{T.removeEventListener("wheel",j)}},[s,g,p,b]);const U={...N&&{"data-id":`${N}-scrollbar`},onPointerDown(F){if(F.button===0&&F.currentTarget===F.target&&b.current){if(w.current&&p.current&&s==="vertical"){const T=Ve(w.current,"margin","y"),j=Ve(p.current,"padding","y"),R=w.current.offsetHeight,D=p.current.getBoundingClientRect(),H=F.clientY-D.top-R/2-j+T/2,z=b.current.scrollHeight,x=b.current.clientHeight,V=p.current.offsetHeight-R-j-T,y=H/V*(z-x);b.current.scrollTop=y}if(k.current&&g.current&&s==="horizontal"){const T=Ve(k.current,"margin","x"),j=Ve(g.current,"padding","x"),R=k.current.offsetWidth,D=g.current.getBoundingClientRect(),H=F.clientX-D.left-R/2-j+T/2,z=b.current.scrollWidth,x=b.current.clientWidth,V=g.current.offsetWidth-R-j-T,X=H/V;let y;M==="rtl"?(y=(1-X)*(z-x),b.current.scrollLeft<=0&&(y=-y)):y=X*(z-x),b.current.scrollLeft=y}C(F)}},onPointerUp:E,style:{position:"absolute",touchAction:"none",WebkitUserSelect:"none",userSelect:"none",...s==="vertical"&&{top:0,bottom:`var(${In.scrollAreaCornerHeight})`,insetInlineEnd:0,[Rn.scrollAreaThumbHeight]:`${_.height}px`},...s==="horizontal"&&{insetInlineStart:0,insetInlineEnd:`var(${In.scrollAreaCornerWidth})`,bottom:0,[Rn.scrollAreaThumbWidth]:`${_.width}px`}}},O=xt("div",t,{ref:[n,s==="vertical"?p:g],state:S,props:[U,a],stateAttributesMapping:Qr}),v=m.useMemo(()=>({orientation:s}),[s]),L=s==="vertical"?f.y:f.x;return o||!L?h.jsx(bo.Provider,{value:v,children:O}):null}),hc=m.forwardRef(function(t,n){const{render:r,className:i,...s}=t,{thumbYRef:o,thumbXRef:a,handlePointerDown:l,handlePointerMove:u,handlePointerUp:c,setScrollingX:f,setScrollingY:d}=qn(),{orientation:p}=cc(),g=m.useMemo(()=>({orientation:p}),[p]);return xt("div",t,{ref:[n,p==="vertical"?o:a],state:g,props:[{onPointerDown:l,onPointerMove:u,onPointerUp(w){p==="vertical"&&d(!1),p==="horizontal"&&f(!1),c(w)},style:{...p==="vertical"&&{height:`var(${Rn.scrollAreaThumbHeight})`},...p==="horizontal"&&{width:`var(${Rn.scrollAreaThumbWidth})`}}},s]})}),pc=m.forwardRef(function(t,n){const{render:r,className:i,...s}=t,{cornerRef:o,cornerSize:a,hiddenState:l}=qn(),u=xt("div",t,{ref:[n,o],props:[{style:{position:"absolute",bottom:0,insetInlineEnd:0,width:a.width,height:a.height}},s]});return l.corner?null:u});function ko({className:e,...t}){return h.jsx(ic,{className:q("group/scroll-area relative outline-none focus-visible:outline-none",e),...t})}function wo({className:e,...t}){return h.jsx(uc,{className:q("h-full w-full outline-none focus-visible:outline-none",e),...t})}function So({className:e,...t}){return h.jsx(fc,{className:q("flex w-2 touch-none select-none p-0.5 outline-none focus-visible:outline-none","opacity-0 transition-opacity duration-150","data-hovering:opacity-100 data-scrolling:opacity-100 group-hover/scroll-area:opacity-100",e),...t})}function Co({className:e,...t}){return h.jsx(hc,{className:q("flex-1 rounded-full bg-primary-500 outline-none focus-visible:outline-none",e),...t})}function dc({className:e,...t}){return h.jsx(pc,{className:q("bg-primary-100 outline-none focus-visible:outline-none",e),...t})}function mc(e){return e==="subagent"?Tl:e==="cron"?jl:Al}function gc(e){return!e||!Array.isArray(e.content)?"":e.content.map(n=>n.type==="text"?String(n.text??""):"").join(" ").replace(/\s+/g," ").trim()}function xc(e){if(typeof e=="number"&&Number.isFinite(e))return e<1e12?e*1e3:e;if(typeof e=="string"){const t=Date.parse(e);if(!Number.isNaN(t))return t}return null}function yc(e){if(!e)return null;const t=[e.createdAt,e.created_at,e.timestamp,e.time,e.ts];for(const n of t){const r=xc(n);if(r)return r}return null}function bc(e){const t=e-Date.now(),n=Math.abs(t),r=[["minute",6e4],["hour",36e5],["day",864e5]];let i="minute",s=6e4;n>=r[2][1]?[i,s]=r[2]:n>=r[1][1]&&([i,s]=r[1]);const o=Math.round(t/s);return new Intl.RelativeTimeFormat("en",{numeric:"auto"}).format(o,i)}function kc(e){const t=String(e??"").toLowerCase().trim();return t?t==="error"||t==="failed"?"error":t==="completed"||t==="ended"||t==="done"?"success":null:null}function wc({session:e,active:t,isGenerating:n=!1,isPinned:r,selectionMode:i=!1,selected:s=!1,onToggleSelect:o,onSelect:a,onTogglePin:l,onRename:u,onDelete:c,onExport:f}){const d=e.label||e.title||e.derivedTitle||e.friendlyId,p=mc(e.kind),g=e.kind==="subagent"&&(e.lastMessage?.role==="assistant"||e.lastMessage?.role==="toolResult")?gc(e.lastMessage):"",b=g.length>50?`${g.slice(0,50).trimEnd()}…`:g,w=e.kind==="subagent"?kc(e.status):null,k=e.kind==="cron"?yc(e.lastMessage):null;return h.jsxs(tn,{to:"/chat/$sessionKey",params:{sessionKey:e.friendlyId},onClick:C=>{if(i){C.preventDefault(),C.stopPropagation(),o?.(e);return}a?.()},className:q("group inline-flex items-center justify-between","w-full text-left pl-1.5 pr-0.5 min-h-8 py-1 rounded-lg transition-colors duration-0","select-none",t?"bg-primary-200 text-primary-950":"bg-transparent text-primary-950 [&:hover:not(:has(button:hover))]:bg-primary-200"),children:[h.jsxs("div",{className:"flex items-center gap-2 flex-1 min-w-0",children:[i?h.jsx("span",{"aria-hidden":"true",className:q("inline-flex items-center justify-center size-4 shrink-0 rounded border transition-colors",s?"bg-primary-700 border-primary-700 text-white":"border-primary-300 bg-surface"),children:s?h.jsx("svg",{viewBox:"0 0 12 12",className:"size-3",fill:"none",stroke:"currentColor",strokeWidth:2,children:h.jsx("path",{d:"M2.5 6l2.5 2.5 4.5-5"})}):null}):null,h.jsxs("div",{className:"flex-1 min-w-0",children:[h.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[h.jsx(te,{icon:p,size:12,strokeWidth:1.75,className:"text-primary-500/70 shrink-0"}),h.jsxs("div",{className:"text-sm font-[450] line-clamp-1 min-w-0",children:[r?h.jsx("span",{className:"mr-1 text-xs text-primary-700","aria-hidden":"true",children:"📌"}):null,d]}),e.kind==="subagent"?n?h.jsx("span",{"aria-label":"Session active",className:"size-1.5 rounded-full bg-green-500 shrink-0"}):w==="success"?h.jsx(te,{icon:Qs,size:12,strokeWidth:1.8,className:"text-green-600/80 shrink-0"}):w==="error"?h.jsx(te,{icon:$n,size:12,strokeWidth:1.8,className:"text-red-600/80 shrink-0"}):null:null]}),b?h.jsx("div",{className:"text-[11px] text-primary-600/80 line-clamp-1 mt-0.5 pl-[18px]",children:b}):null,e.kind==="cron"&&k?h.jsx("div",{className:"text-[10px] text-primary-500/75 line-clamp-1 mt-0.5 pl-[18px] font-mono",children:bc(k)}):null]})]}),i?null:h.jsxs(Bn,{children:[h.jsx(Hn,{type:"button",onClick:C=>{C.preventDefault(),C.stopPropagation()},className:q("ml-2 inline-flex size-7 items-center justify-center rounded-md text-primary-700","opacity-0 transition-opacity group-hover:opacity-100 hover:bg-primary-200","aria-expanded:opacity-100 aria-expanded:bg-primary-200"),children:h.jsx(te,{icon:Cl,size:20,strokeWidth:1.5})}),h.jsxs(Un,{side:"bottom",align:"end",children:[h.jsxs(mt,{onClick:C=>{C.preventDefault(),C.stopPropagation(),l(e)},className:"gap-2",children:[h.jsx("span",{className:"text-xs","aria-hidden":"true",children:"📌"})," ",r?"Unpin Session":"Pin Session"]}),h.jsxs(mt,{onClick:C=>{C.preventDefault(),C.stopPropagation(),u(e)},className:"gap-2",children:[h.jsx(te,{icon:vl,size:20,strokeWidth:1.5})," ","Rename"]}),h.jsxs(mt,{onClick:C=>{C.preventDefault(),C.stopPropagation(),f(e)},className:"gap-2",children:[h.jsx(te,{icon:El,size:20,strokeWidth:1.5})," ","Export"]}),Ir(e.key)?null:h.jsxs(mt,{onClick:C=>{C.preventDefault(),C.stopPropagation(),c(e)},className:"text-red-700 gap-2 hover:bg-red-50/80 data-highlighted:bg-red-50/80",children:[h.jsx(te,{icon:Js,size:20,strokeWidth:1.5})," ","Delete"]})]})]})]})}function Sc(e,t){return e.active!==t.active||e.isGenerating!==t.isGenerating||e.isPinned!==t.isPinned||e.selectionMode!==t.selectionMode||e.selected!==t.selected||e.onToggleSelect!==t.onToggleSelect||e.onSelect!==t.onSelect||e.onTogglePin!==t.onTogglePin||e.onRename!==t.onRename||e.onDelete!==t.onDelete||e.onExport!==t.onExport?!1:e.session===t.session?!0:e.session.key===t.session.key&&e.session.friendlyId===t.session.friendlyId&&e.session.label===t.session.label&&e.session.title===t.session.title&&e.session.derivedTitle===t.session.derivedTitle&&e.session.updatedAt===t.session.updatedAt&&e.session.kind===t.session.kind&&e.session.status===t.session.status&&e.session.lastMessage===t.session.lastMessage}const rr=m.memo(wc,Sc),vo="opencami-pinned-sessions",Eo="opencami-sidebar-folders",ft={webchat:!1,subagent:!1,cron:!1,other:!1};async function Cc(e){const t=new URLSearchParams;e&&t.set("sessionKey",e);const n=await fetch(`/api/sessions?${t.toString()}`,{method:"DELETE"});if(!n.ok)throw new Error(await rt(n))}async function vc(e,t,n){const r=[];let i=0;const s=Array.from({length:Math.min(t,e.length)},async function(){for(;i<e.length;){const a=i;i+=1;try{await n(e[a])}catch(l){r.push(l)}}});return await Promise.all(s),r}function Ec(){if(typeof window>"u")return[];try{const e=localStorage.getItem(vo);if(!e)return[];const t=JSON.parse(e);return Array.isArray(t)?t.filter(n=>typeof n=="string"):[]}catch{return[]}}function Tc(e){if(!(typeof window>"u"))try{const t=Array.from(new Set(e));localStorage.setItem(vo,JSON.stringify(t))}catch{}}function jc(){if(typeof window>"u")return{...ft};try{const e=localStorage.getItem(Eo);if(!e)return{...ft};const t=JSON.parse(e);return!t||typeof t!="object"?{...ft}:{webchat:typeof t.webchat=="boolean"?t.webchat:ft.webchat,subagent:typeof t.subagent=="boolean"?t.subagent:ft.subagent,cron:typeof t.cron=="boolean"?t.cron:ft.cron,other:typeof t.other=="boolean"?t.other:ft.other}}catch{return{...ft}}}function Ac(e){if(!(typeof window>"u"))try{localStorage.setItem(Eo,JSON.stringify(e))}catch{}}function kn(e,t,n){return n&&e.key?e.key===n:e.friendlyId===t}function Ic(e){if(!e)return!1;const t=e.toLowerCase();return t.includes("running")||t.includes("active")||t.includes("stream")||t.includes("generat")}function ir(e,t,n,r){return kn(e,t,n)&&r?!0:Ic(e.status)}const Rc=m.memo(function({sessions:t,activeFriendlyId:n,activeSessionKey:r,isStreaming:i=!1,defaultOpen:s=!0,onSelect:o,onRename:a,onDelete:l,onExport:u}){const c=m.useDeferredValue(t),f=qt(),[d,p]=m.useState(()=>Ec()),[g,b]=m.useState(()=>jc()),[w,k]=m.useState(!1),[C,E]=m.useState(()=>new Set),N=m.useMemo(()=>new Set(d),[d]),_=c.filter(z=>N.has(z.key)),S=c.filter(z=>!N.has(z.key)),M=_.length>0&&S.length>0,U=m.useMemo(()=>{const z={chat:[],webchat:[],subagent:[],cron:[],other:[]};for(const x of S){const V=x.kind??"other";z[V].push(x)}return z},[S]),O=m.useMemo(()=>c.filter(z=>C.has(z.key)),[C,c]),v=O.length,L=m.useCallback(()=>{k(z=>(z&&E(new Set),!z))},[]),A=m.useCallback(z=>{Ir(z.key)||E(x=>{const V=new Set(x);return V.has(z.key)?V.delete(z.key):V.add(z.key),V})},[]),F=m.useCallback(()=>{E(new Set(c.filter(z=>!Ir(z.key)).map(z=>z.key)))},[c]),T=m.useCallback(()=>{k(!1),E(new Set)},[]),j=m.useCallback(async()=>{if(O.length===0||!window.confirm(`Delete ${O.length} sessions? This will archive them.`))return;const x=await vc(O.map(V=>V.key),10,Cc);x.length>0&&console.error("[sidebar] Bulk delete failed for some sessions",x),k(!1),E(new Set),f.invalidateQueries({queryKey:ye.sessions})},[f,O]),R=m.useCallback(z=>{p(x=>{const X=x.includes(z.key)?x.filter(y=>y!==z.key):[...x,z.key];return Tc(X),X})},[]),D=m.useCallback((z,x)=>{b(V=>{const X={...V,[z]:x};return Ac(X),X})},[]);function H(z,x,V){return V.length===0?null:h.jsxs(Tn,{className:"flex flex-col",open:g[z],onOpenChange:X=>D(z,X),children:[h.jsxs(jn,{className:q("w-full justify-between border-l-2 border-primary-200/70 px-2 py-1 text-[11px] font-medium text-primary-500/80 text-balance"),children:[h.jsx("span",{className:"truncate",children:x}),h.jsx("span",{className:q("rounded-full bg-primary-100 px-1.5 py-0.5 text-[10px] font-medium text-primary-700 tabular-nums"),children:V.length})]}),h.jsx(An,{contentClassName:"flex flex-col gap-px",children:V.map(X=>h.jsx(rr,{session:X,active:kn(X,n,r),isGenerating:ir(X,n,r,i),isPinned:!1,selectionMode:w,selected:C.has(X.key),onToggleSelect:A,onSelect:o,onTogglePin:R,onRename:a,onDelete:l,onExport:u},X.key))})]})}return h.jsxs(Tn,{className:"flex h-full flex-col flex-1 min-h-0 w-full",defaultOpen:s,children:[h.jsxs("div",{className:"flex items-center justify-between pr-2 shrink-0",children:[h.jsxs(jn,{className:"w-fit pl-1.5 text-balance",children:["Sessions",h.jsx("span",{className:"opacity-0 transition-opacity duration-150 group-hover:opacity-100",children:h.jsx(te,{icon:Wr,className:"size-3 transition-transform duration-150 group-data-panel-open:rotate-90"})})]}),h.jsx("button",{type:"button",onClick:L,className:q("text-[11px] font-medium px-1.5 py-0.5 rounded-md transition-colors",w?"text-primary-900 bg-primary-200":"text-primary-500 hover:text-primary-700 hover:bg-primary-100"),children:w?"Done":"Select"})]}),h.jsx(An,{className:"w-full flex-1 min-h-0 h-auto data-starting-style:h-0 data-ending-style:h-0",contentClassName:"flex flex-1 min-h-0 flex-col overflow-y-auto",children:h.jsxs(ko,{className:"flex-1 min-h-0",children:[h.jsx(wo,{className:"min-h-0",children:h.jsxs("div",{className:"flex flex-col gap-2 pl-2 pr-2",children:[_.length>0?h.jsx("div",{className:"flex flex-col gap-px",children:_.map(z=>h.jsx(rr,{session:z,active:kn(z,n,r),isGenerating:ir(z,n,r,i),isPinned:!0,selectionMode:w,selected:C.has(z.key),onToggleSelect:A,onSelect:o,onTogglePin:R,onRename:a,onDelete:l,onExport:u},z.key))}):null,M?h.jsx("div",{className:"my-1 border-t border-primary-200/80"}):null,U.chat.length>0?h.jsxs("div",{className:"flex flex-col gap-px",children:[h.jsx("div",{className:q("border-l-2 border-primary-200/70 px-2 py-1 text-[11px] font-medium text-primary-500/80 text-balance"),children:"💬 Chats"}),h.jsx("div",{className:"flex flex-col gap-px",children:U.chat.map(z=>h.jsx(rr,{session:z,active:kn(z,n,r),isGenerating:ir(z,n,r,i),isPinned:!1,selectionMode:w,selected:C.has(z.key),onToggleSelect:A,onSelect:o,onTogglePin:R,onRename:a,onDelete:l,onExport:u},z.key))})]}):null,H("webchat","🦎 OpenCami",U.webchat),H("subagent","🤖 Sub-agents",U.subagent),H("cron","⏰ Cron / Isolated",U.cron),H("other","📁 Other",U.other)]})}),h.jsx(So,{orientation:"vertical",children:h.jsx(Co,{})})]})}),w?h.jsxs("div",{className:"shrink-0 border-t border-primary-200 bg-surface px-2 py-2 flex flex-col gap-1.5",children:[h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsxs("span",{className:"text-xs text-primary-600 font-medium",children:[v," selected"]}),h.jsx("button",{type:"button",onClick:F,className:"text-[11px] font-medium text-primary-600 hover:text-primary-800",children:"Select all"})]}),h.jsxs("div",{className:"flex gap-1.5",children:[h.jsxs("button",{type:"button",onClick:j,disabled:v===0,className:q("flex-1 inline-flex items-center justify-center gap-1.5 rounded-md px-2 py-1.5 text-xs font-medium transition-colors",v>0?"bg-red-100 text-red-700 hover:bg-red-200":"bg-primary-100 text-primary-400 cursor-not-allowed"),children:[h.jsx(te,{icon:Js,size:14,strokeWidth:1.5}),"Delete"]}),h.jsx("button",{type:"button",onClick:T,className:"flex-1 inline-flex items-center justify-center rounded-md px-2 py-1.5 text-xs font-medium bg-primary-100 text-primary-700 hover:bg-primary-200 transition-colors",children:"Cancel"})]})]}):null]})},Nc);function Nc(e,t){if(e.activeFriendlyId!==t.activeFriendlyId||e.activeSessionKey!==t.activeSessionKey||e.isStreaming!==t.isStreaming||e.defaultOpen!==t.defaultOpen||e.onSelect!==t.onSelect||e.onRename!==t.onRename||e.onDelete!==t.onDelete||e.onExport!==t.onExport)return!1;if(e.sessions===t.sessions)return!0;if(e.sessions.length!==t.sessions.length)return!1;for(let n=0;n<e.sessions.length;n+=1){const r=e.sessions[n],i=t.sessions[n];if(r.key!==i.key||r.friendlyId!==i.friendlyId||r.label!==i.label||r.title!==i.title||r.derivedTitle!==i.derivedTitle||r.updatedAt!==i.updatedAt||r.kind!==i.kind||r.status!==i.status||r.lastMessage!==i.lastMessage)return!1}return!0}function Lc(){const[e,t]=m.useState(!1),[n,r]=m.useState(!1),[i,s]=m.useState(null),[o,a]=m.useState(null),l=m.useCallback(async()=>{if(t(!0),s(null),!(n||o)){r(!0);try{const p=await fetch("/api/paths");if(!p.ok)throw new Error(await rt(p));const g=await p.json();a({agentId:String(g.agentId??"main"),stateDir:String(g.stateDir??""),sessionsDir:String(g.sessionsDir??""),storePath:String(g.storePath??"")})}catch(p){s(p instanceof Error?p.message:String(p))}finally{r(!1)}}},[o,n]),u=m.useCallback(()=>{l()},[l]),c=m.useCallback(()=>{t(!1)},[]),f=m.useCallback(()=>{if(o?.sessionsDir)try{navigator.clipboard.writeText(o.sessionsDir)}catch{}},[o]),d=m.useCallback(()=>{if(o?.storePath)try{navigator.clipboard.writeText(o.storePath)}catch{}},[o]);return{settingsOpen:e,setSettingsOpen:t,pathsLoading:n,pathsError:i,paths:o,handleOpenSettings:u,closeSettings:c,copySessionsDir:f,copyStorePath:d}}let Fe=null,Jr=!1,wn=null;function Mc(e){Fe=e}function sr(){return Fe!==null}function Vt(e){Jr=e}function or(){return Jr}function Nn(){Fe=null,Jr=!1}function Dc(e,t){if(Fe){if(e&&Fe.sessionKey===e){Nn();return}t&&Fe.friendlyId===t&&Nn()}}function zc(e){wn={friendlyId:e,at:Date.now()}}function To(e,t=15e3){return!(!wn||wn.friendlyId!==e||Date.now()-wn.at>t)}function Pc(e,t){if(!Fe)return null;if(e&&Fe.sessionKey===e){const n=Fe;return Fe=null,n}if(t&&Fe.friendlyId===t){const n=Fe;return Fe=null,n}return null}const _c=8e3,Et=new Map;function Oc(e){e&&Et.set(e,{id:e,expiresAt:Date.now()+_c})}function Fc(e){e&&Et.delete(e)}function $c(e){if(Et.size===0)return e;const t=Date.now();let n=!1;const r=e.filter(i=>{const s=Et.get(i.key),o=Et.get(i.friendlyId);return s&&s.expiresAt<=t||o&&o.expiresAt<=t?(s&&s.expiresAt<=t&&Et.delete(i.key),o&&o.expiresAt<=t&&Et.delete(i.friendlyId),!0):s||o?(n=!0,!1):!0});return n?r:e}function Bc(){const e=qt(),[t,n]=m.useState(!1),[r,i]=m.useState(null),s=lo({mutationFn:async function(l){const u=new URLSearchParams;l.sessionKey&&u.set("sessionKey",l.sessionKey),l.friendlyId&&u.set("friendlyId",l.friendlyId);const c=await fetch(`/api/sessions?${u.toString()}`,{method:"DELETE"});if(!c.ok)throw new Error(await rt(c));return l},onMutate:async function(l){i(null),Oc(l.sessionKey||l.friendlyId),Dc(l.sessionKey,l.friendlyId),await e.cancelQueries({queryKey:ye.sessions});const u=e.getQueryData(ye.sessions);return Cu(e,l.sessionKey,l.friendlyId),l.isActive&&(l.sessionKey||l.friendlyId)&&Rr(e,l.friendlyId||l.sessionKey,l.sessionKey||l.friendlyId),{previousSessions:u,isActive:l.isActive}},onError:function(l,u,c){c?.previousSessions&&e.setQueryData(ye.sessions,c.previousSessions),Fc(u.sessionKey||u.friendlyId),i(l instanceof Error?l.message:String(l))},onSuccess:function(l){l.isActive&&Nn(),e.invalidateQueries({queryKey:ye.sessions})},onSettled:function(){n(!1)}});return{deleteSession:m.useCallback(async(a,l,u)=>{!a&&!l||(n(!0),await s.mutateAsync({sessionKey:a,friendlyId:l,isActive:u}))},[s]),deleting:t,error:r}}function Hc(){const e=qt(),[t,n]=m.useState(!1),[r,i]=m.useState(null),s=lo({mutationFn:async function(l){const u=await fetch("/api/sessions",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({sessionKey:l.sessionKey,label:l.newTitle})});if(!u.ok)throw new Error(await rt(u));return l},onMutate:async function(l){i(null),await e.cancelQueries({queryKey:ye.sessions});const u=e.getQueryData(ye.sessions);return e.setQueryData(ye.sessions,function(f){return Array.isArray(f)?f.map(d=>d.key!==l.sessionKey?d:{...d,label:l.newTitle,title:l.newTitle}):f}),{previousSessions:u}},onError:function(l,u,c){c?.previousSessions&&e.setQueryData(ye.sessions,c.previousSessions),i(l instanceof Error?l.message:String(l))},onSuccess:function(){e.invalidateQueries({queryKey:ye.sessions})},onSettled:function(){n(!1)}});return{renameSession:m.useCallback(async(a,l)=>{!a||!l.trim()||(n(!0),await s.mutateAsync({sessionKey:a,newTitle:l.trim()}))},[s]),renaming:t,error:r}}const Uc=m.lazy(()=>Fn(()=>import("./settings-dialog-AsvYzSBc.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8])).then(e=>({default:e.SettingsDialog}))),qc=m.lazy(()=>Fn(()=>import("./session-export-dialog-DSRWU2YO.js"),__vite__mapDeps([9,1,3,2,4,5])).then(e=>({default:e.SessionExportDialog})));function Kc({sessions:e,activeFriendlyId:t,activeSessionKey:n,isStreaming:r=!1,creatingSession:i,onCreateSession:s,isCollapsed:o,onToggleCollapse:a,onSelectSession:l,onActiveSessionDelete:u,onOpenSearch:c}){const{settingsOpen:f,setSettingsOpen:d,pathsLoading:p,pathsError:g,paths:b,handleOpenSettings:w,closeSettings:k,copySessionsDir:C,copyStorePath:E}=Lc(),{deleteSession:N}=Bc(),{renameSession:_}=Hc(),S={duration:.15,ease:o?"easeIn":"easeOut"},[M,U]=m.useState(!1),[O,v]=m.useState(null),[L,A]=m.useState(""),[F,T]=m.useState(!1),[j,R]=m.useState(null),[D,H]=m.useState(null),[z,x]=m.useState(""),[V,X]=m.useState(!1),[y,Q]=m.useState(null),[ne,W]=m.useState(null),[me,ge]=m.useState(""),le=qt();function ie($){v($.key),A($.label||$.title||$.derivedTitle||""),U(!0)}function be($){O&&_(O,$),U(!1),v(null)}function ke($){R($.key),H($.friendlyId),x($.label||$.title||$.derivedTitle||$.friendlyId),T(!0)}function we(){if(j&&D){const $=D===t;$&&u&&u(),N(j,D,$)}T(!1),R(null),H(null)}function Se($){Q($.key),W($.friendlyId),ge($.label||$.title||$.derivedTitle||$.friendlyId),X(!0)}function K($){if(y&&ne){const ue=ye.history(ne,y),re=le.getQueryData(ue);re?.messages&&Au(me,re.messages,$)}X(!1),Q(null),W(null)}const Z={className:"border-r border-primary-200 h-full overflow-hidden bg-primary-100 flex flex-col"};return h.jsxs(Ke.aside,{initial:!1,animate:{width:o?48:300},transition:S,className:Z.className,children:[h.jsxs(Ke.div,{layout:!0,transition:{layout:S},className:q("flex items-center h-12 px-2 justify-between"),children:[h.jsx(Ct,{initial:!1,children:o?null:h.jsx(Ke.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:S,children:h.jsxs(tn,{to:"/new",className:q(Zn({variant:"ghost",size:"sm"}),"w-full pl-1.5 justify-start"),children:[h.jsx(Zl,{className:"size-5"}),h.jsx(eu,{})]})})}),h.jsx(jt,{children:h.jsxs(At,{children:[h.jsx(It,{onClick:a,render:h.jsx(ve,{size:"icon-sm",variant:"ghost",children:h.jsx(te,{icon:Il,size:20,strokeWidth:1.5})})}),h.jsx(Rt,{side:"right",children:o?"Open Sidebar":"Close Sidebar"})]})})]}),h.jsxs("div",{className:"px-2 mb-4 flex flex-col gap-1",children:[h.jsxs(Ke.div,{layout:!0,transition:{layout:S},className:"w-full space-y-2",children:[h.jsxs(ve,{disabled:i,variant:"ghost",size:"sm",onClick:s,onMouseUp:l,className:"w-full pl-1.5 justify-start",children:[h.jsx(te,{icon:Rl,size:20,strokeWidth:1.5,className:"min-w-5"}),h.jsx(Ct,{initial:!1,mode:"wait",children:!o&&h.jsx(Ke.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:S,className:"overflow-hidden whitespace-nowrap",children:"New Session"})})]}),h.jsx(jt,{children:h.jsxs(At,{children:[h.jsx(It,{asChild:!0,children:h.jsxs(tn,{to:"/files",className:q(Zn({variant:"ghost",size:"sm"}),"w-full pl-1.5 justify-start"),onClick:l,children:[h.jsx(te,{icon:Nl,size:20,strokeWidth:1.5,className:"min-w-5"}),h.jsx(Ct,{initial:!1,mode:"wait",children:!o&&h.jsx(Ke.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:S,className:"overflow-hidden whitespace-nowrap",children:"Files"})})]})}),o&&h.jsx(Rt,{side:"right",children:"Files"})]})}),(()=>{try{return localStorage.getItem("opencami-agent-manager")==="true"}catch{return!1}})()&&h.jsx(jt,{children:h.jsxs(At,{children:[h.jsx(It,{asChild:!0,children:h.jsxs(tn,{to:"/agents",className:q(Zn({variant:"ghost",size:"sm"}),"w-full pl-1.5 justify-start"),onClick:l,children:[h.jsx(te,{icon:Zs,size:20,strokeWidth:1.5,className:"min-w-5"}),h.jsx(Ct,{initial:!1,mode:"wait",children:!o&&h.jsx(Ke.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:S,className:"overflow-hidden whitespace-nowrap",children:"Agents"})})]})}),o&&h.jsx(Rt,{side:"right",children:"Agents"})]})})]}),h.jsx(Ke.div,{layout:!0,transition:{layout:S},className:"w-full",children:h.jsxs(ve,{variant:"ghost",size:"sm",onClick:c,className:"w-full pl-1.5 justify-start",children:[h.jsx(te,{icon:eo,size:20,strokeWidth:1.5,className:"min-w-5"}),h.jsx(Ct,{initial:!1,mode:"wait",children:!o&&h.jsx(Ke.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:S,className:"overflow-hidden whitespace-nowrap",children:"Search"})})]})})]}),h.jsx("div",{className:"flex-1 min-h-0 overflow-hidden",children:h.jsx(Ct,{initial:!1,children:!o&&h.jsx(Ke.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:S,className:"pt-0 flex flex-col w-full min-h-0 h-full",children:h.jsx("div",{className:"flex-1 min-h-0",children:h.jsx(Rc,{sessions:e,activeFriendlyId:t,activeSessionKey:n,isStreaming:r,onSelect:l,onRename:ie,onDelete:ke,onExport:Se})})},"content")})}),h.jsx("div",{className:"px-2 py-3 border-t border-primary-200 bg-primary-100",children:h.jsx(Ke.div,{layout:!0,transition:{layout:S},className:"w-full",children:h.jsxs(ve,{variant:"ghost",size:"sm",onClick:w,title:o?"Settings":void 0,className:"w-full justify-start pl-1.5",children:[h.jsx(te,{icon:Ll,size:20,strokeWidth:1.5,className:"min-w-5"}),h.jsx(Ct,{initial:!1,mode:"wait",children:!o&&h.jsx(Ke.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:S,className:"overflow-hidden whitespace-nowrap",children:"Settings"})})]})})}),f&&h.jsx(m.Suspense,{fallback:null,children:h.jsx(Uc,{open:f,onOpenChange:d,pathsLoading:p,pathsError:g,paths:b,onClose:k,onCopySessionsDir:C,onCopyStorePath:E})}),h.jsx(Ru,{open:M,onOpenChange:U,sessionTitle:L,onSave:be,onCancel:()=>U(!1)}),h.jsx(Ou,{open:F,onOpenChange:T,sessionTitle:z,onConfirm:we,onCancel:()=>T(!1)}),V&&h.jsx(m.Suspense,{fallback:null,children:h.jsx(qc,{open:V,onOpenChange:X,sessionTitle:me,onExport:K,onCancel:()=>X(!1)})})]})}function Wc(e,t){if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1){const r=e[n],i=t[n];if(r.key!==i.key||r.friendlyId!==i.friendlyId||r.label!==i.label||r.title!==i.title||r.derivedTitle!==i.derivedTitle||r.updatedAt!==i.updatedAt||r.kind!==i.kind||r.status!==i.status||r.lastMessage!==i.lastMessage)return!1}return!0}function Vc(e,t){return!(e.activeFriendlyId!==t.activeFriendlyId||e.activeSessionKey!==t.activeSessionKey||e.isStreaming!==t.isStreaming||e.creatingSession!==t.creatingSession||e.isCollapsed!==t.isCollapsed||!Wc(e.sessions,t.sessions))}const Xc=m.memo(Kc,Vc);function $i(e){if(e<=0)return"0";if(e>=1e6){const t=e/1e6,n=t.toFixed(1);return n.endsWith(".0")?`${Math.round(t)}M`:`${n}M`}if(e>=1e5)return`${Math.round(e/1e3)}K`;if(e>=1e4)return`${Math.round(e/1e3)}K`;if(e>=1e3){const t=e/1e3,n=t.toFixed(1);return n.endsWith(".0")?`${Math.round(t)}K`:`${n}K`}return String(Math.round(e))}function Bi(e){return e>=90?{bar:"bg-red-500",text:"text-red-600 dark:text-red-400"}:e>=70?{bar:"bg-yellow-500",text:"text-yellow-600 dark:text-yellow-400"}:{bar:"bg-emerald-500",text:"text-emerald-600 dark:text-emerald-400"}}function Yc({totalTokens:e,contextTokens:t,className:n}){const{percentage:r,usedStr:i,maxStr:s,colors:o,hasData:a,isNearlyFull:l}=m.useMemo(()=>{if(typeof t!="number"||t<=0)return{percentage:0,usedStr:"",maxStr:"",colors:Bi(0),hasData:!1,isNearlyFull:!1};const f=typeof e=="number"&&e>0?e:0,d=Math.min(100,Math.round(f/t*100));return{percentage:d,usedStr:$i(f),maxStr:$i(t),colors:Bi(d),hasData:!0,isNearlyFull:d>=95}},[e,t]);if(!a)return null;const u=typeof e=="number"&&e>0?e.toLocaleString():"0",c=typeof t=="number"?t.toLocaleString():"0";return h.jsxs("div",{className:q("group relative flex items-center gap-1.5",n),title:`Context: ${u} / ${c} tokens (${r}%)`,children:[h.jsxs("div",{className:"flex items-center gap-1.5",children:[h.jsx("div",{className:"w-12 h-1.5 rounded-full bg-primary-200 dark:bg-primary-700 overflow-hidden shrink-0 group-hover:h-2 transition-all",children:h.jsx("div",{className:q("h-full rounded-full transition-all duration-500 ease-out",o.bar,l&&"animate-pulse"),style:{width:`${r}%`}})}),h.jsx("span",{className:q("text-[10px] leading-none font-medium tabular-nums whitespace-nowrap",l?o.text:"text-primary-500 dark:text-primary-400"),children:i})]}),h.jsx("div",{className:q("absolute right-0 top-full mt-1 z-50","pointer-events-none opacity-0 scale-95","group-hover:pointer-events-auto group-hover:opacity-100 group-hover:scale-100","transition-all duration-150 origin-top-right"),children:h.jsxs("div",{className:q("rounded-md border border-primary-200 dark:border-primary-700","bg-surface shadow-lg px-3 py-2","text-xs whitespace-nowrap"),children:[h.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[h.jsx("span",{className:"text-primary-500 dark:text-primary-400",children:"Context window"}),h.jsxs("span",{className:q("font-semibold",o.text),children:[r,"%"]})]}),h.jsxs("div",{className:"flex items-center gap-1.5 text-primary-700 dark:text-primary-300",children:[h.jsx("span",{className:"font-medium",children:i}),h.jsx("span",{className:"text-primary-400",children:"/"}),h.jsx("span",{children:s}),h.jsx("span",{className:"text-primary-400",children:"tokens"})]}),h.jsx("div",{className:"w-full h-1.5 rounded-full bg-primary-200 dark:bg-primary-700 overflow-hidden mt-1.5",children:h.jsx("div",{className:q("h-full rounded-full transition-all duration-500 ease-out",o.bar),style:{width:`${r}%`}})}),l&&h.jsx("div",{className:"mt-1.5 text-[10px] text-red-500 dark:text-red-400 font-medium",children:"⚠ Context nearly full — consider /compact"})]})})]})}const Gc=m.memo(Yc);function Qc({activeTitle:e,wrapperRef:t,showSidebarButton:n=!1,onOpenSidebar:r,totalTokens:i,contextTokens:s}){return h.jsxs("div",{ref:t,className:"border-b border-primary-200 px-4 h-12 flex items-center bg-surface",children:[n?h.jsx(ve,{size:"icon-sm",variant:"ghost",onClick:r,className:"mr-2 text-primary-800 hover:bg-primary-100","aria-label":"Open sidebar",children:h.jsx(te,{icon:Ml,size:18,strokeWidth:1.6})}):null,h.jsx("div",{className:"text-sm font-medium truncate flex-1 min-w-0",children:e}),h.jsx(Gc,{totalTokens:i,contextTokens:s,className:"ml-3 hidden sm:flex"})]})}const Jc=m.memo(Qc);function Zc(e,t){return e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}function ef(e){const t=new Date(e);return Zc(t,new Date)?new Intl.DateTimeFormat("en-GB",{hour:"2-digit",minute:"2-digit"}).format(t):new Intl.DateTimeFormat("en-GB",{day:"2-digit",month:"short"}).format(t)}function tf(e){return new Intl.DateTimeFormat("en-GB",{day:"2-digit",month:"short",year:"numeric",hour:"2-digit",minute:"2-digit",second:"2-digit"}).format(new Date(e))}function nf({timestamp:e}){const t=ef(e),n=tf(e);return h.jsx(jt,{children:h.jsxs(At,{children:[h.jsx(It,{className:"inline-flex items-center text-xs text-primary-600",children:t}),h.jsx(Rt,{side:"top",children:n})]})})}function rf({text:e,align:t,timestamp:n,forceVisible:r=!1}){const[i,s]=m.useState(!1),[o,a]=m.useState("idle"),l=m.useRef(null),u=m.useRef(null),[c,f]=m.useState(()=>{if(typeof window>"u")return!0;try{const w=localStorage.getItem("opencami-tts-enabled");return w===null?!0:w==="true"}catch{return!0}});m.useEffect(()=>{function w(k){k.key==="opencami-tts-enabled"&&f(k.newValue===null?!0:k.newValue==="true")}return window.addEventListener("storage",w),()=>window.removeEventListener("storage",w)},[]),m.useEffect(()=>()=>{l.current&&(l.current.pause(),l.current=null),u.current&&(URL.revokeObjectURL(u.current),u.current=null)},[]);const d=async()=>{try{await navigator.clipboard.writeText(e),s(!0),window.setTimeout(()=>s(!1),1400)}catch{s(!1)}},p=async()=>{if(o==="playing"){l.current&&(l.current.pause(),l.current=null),u.current&&(URL.revokeObjectURL(u.current),u.current=null),a("idle");return}a("loading");try{const w=await fetch("/api/tts",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:e})});if(!w.ok)throw new Error("TTS failed");const k=await w.blob(),C=URL.createObjectURL(k);u.current=C;const E=new Audio(C);l.current=E,E.onended=()=>{a("idle"),u.current&&(URL.revokeObjectURL(u.current),u.current=null),l.current=null},E.onerror=()=>{a("idle"),u.current&&(URL.revokeObjectURL(u.current),u.current=null),l.current=null},await E.play(),a("playing")}catch{a("idle"),u.current&&(URL.revokeObjectURL(u.current),u.current=null),l.current=null}},g=t==="end"?"justify-end":"justify-start",b=t==="start"&&c&&e.trim().length>0;return h.jsxs("div",{className:q("flex items-center gap-2 text-xs text-primary-600 transition-opacity group-hover:opacity-100 group-focus-within:opacity-100 duration-100 ease-out",r?"opacity-100":"opacity-0",g),children:[h.jsx(jt,{children:h.jsxs(At,{children:[h.jsx(It,{type:"button",onClick:()=>{d().catch(()=>{})},className:"inline-flex items-center justify-center rounded border border-transparent bg-transparent p-1 text-primary-700 hover:text-primary-900 hover:bg-primary-100",children:h.jsx(te,{icon:i?Vr:Dl,size:16,strokeWidth:1.6})}),h.jsx(Rt,{side:"top",children:"Copy"})]})}),b&&h.jsx(jt,{children:h.jsxs(At,{children:[h.jsx(It,{type:"button",onClick:()=>{p().catch(()=>{})},disabled:o==="loading",className:q("inline-flex items-center justify-center rounded border border-transparent bg-transparent p-1 text-primary-700 hover:text-primary-900 hover:bg-primary-100",o==="loading"&&"opacity-60 cursor-wait"),children:h.jsx(te,{icon:o==="loading"?zl:o==="playing"?to:Pl,size:16,strokeWidth:1.6,className:q(o==="loading"&&"animate-spin")})}),h.jsx(Rt,{side:"top",children:o==="loading"?"Generating speech…":o==="playing"?"Stop":"Listen"})]})}),h.jsx(nf,{timestamp:n})]})}function Zr(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var Dt=Zr();function jo(e){Dt=e}var rn={exec:()=>null};function ce(e,t=""){let n=typeof e=="string"?e:e.source,r={replace:(i,s)=>{let o=typeof s=="string"?s:s.source;return o=o.replace(De.caret,"$1"),n=n.replace(i,o),r},getRegex:()=>new RegExp(n,t)};return r}var sf=(()=>{try{return!!new RegExp("(?<=1)(?<!1)")}catch{return!1}})(),De={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,listReplaceTabs:/^\t+/,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,unescapeTest:/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig,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:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),hrRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}#`),htmlBeginRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}<(?:[a-z].*>|!--)`,"i")},of=/^(?:[ \t]*(?:\n|$))+/,af=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,lf=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,cn=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,uf=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,ei=/(?:[*+-]|\d{1,9}[.)])/,Ao=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,Io=ce(Ao).replace(/bull/g,ei).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(),cf=ce(Ao).replace(/bull/g,ei).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(),ti=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,ff=/^[^\n]+/,ni=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,hf=ce(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",ni).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),pf=ce(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,ei).getRegex(),Kn="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",ri=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,df=ce("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\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",ri).replace("tag",Kn).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),Ro=ce(ti).replace("hr",cn).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"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",Kn).getRegex(),mf=ce(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",Ro).getRegex(),ii={blockquote:mf,code:af,def:hf,fences:lf,heading:uf,hr:cn,html:df,lheading:Io,list:pf,newline:of,paragraph:Ro,table:rn,text:ff},Hi=ce("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",cn).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[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",Kn).getRegex(),gf={...ii,lheading:cf,table:Hi,paragraph:ce(ti).replace("hr",cn).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",Hi).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",Kn).getRegex()},xf={...ii,html:ce(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",ri).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:rn,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:ce(ti).replace("hr",cn).replace("heading",` *#{1,6} *[^
|
|
6
|
-
]`).replace("lheading",Io).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},yf=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,bf=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,No=/^( {2,}|\\)\n(?!\s*$)/,kf=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,Wn=/[\p{P}\p{S}]/u,si=/[\s\p{P}\p{S}]/u,Lo=/[^\s\p{P}\p{S}]/u,wf=
|
|
5
|
+
`)}function Au(e,t,n){const r=new Date;let i,s,o;switch(n){case"markdown":i=Eu(e,t,r),s=`${nr(e)}.md`,o="text/markdown";break;case"json":i=Tu(e,t,r),s=`${nr(e)}.json`,o="application/json";break;case"txt":i=ju(e,t,r),s=`${nr(e)}.txt`,o="text/plain";break;default:throw new Error(`Unsupported format: ${n}`)}Iu(i,s,o)}function nr(e){return e.replace(/[^a-z0-9-_\s]/gi,"").replace(/\s+/g,"-").toLowerCase().slice(0,50)||"conversation"}function Iu(e,t,n){const r=new Blob([e],{type:n}),i=URL.createObjectURL(r),s=document.createElement("a");s.href=i,s.download=t,document.body.appendChild(s),s.click(),document.body.removeChild(s),URL.revokeObjectURL(i)}function Ru({open:e,onOpenChange:t,sessionTitle:n,onSave:r,onCancel:i}){return h.jsx(ro,{open:e,onOpenChange:t,children:h.jsx(io,{children:h.jsxs("div",{className:"p-4",children:[h.jsx(so,{className:"mb-1",children:"Rename"}),h.jsx(Bl,{className:"mb-4",children:"Enter a new name for this session."}),h.jsx("input",{type:"text",defaultValue:n,onKeyDown:s=>{s.key==="Enter"&&(s.preventDefault(),r(s.currentTarget.value))},className:"w-full rounded-lg border border-primary-200 bg-primary-50 px-3 py-2 text-sm text-primary-900 outline-none focus:border-primary-400",placeholder:"Session name",autoFocus:!0}),h.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[h.jsx(oo,{onClick:i,children:"Cancel"}),h.jsx(ve,{onClick:s=>{const o=s.currentTarget.parentElement?.previousElementSibling;r(o.value)},children:"Save"})]})]})})})}function Nu(e){const{children:t,open:n,defaultOpen:r=!1,onOpenChange:i,onOpenChangeComplete:s,actionsRef:o,handle:a,triggerId:l,defaultTriggerId:u=null}=e,c=Hl(),f=!!c,d=wl(()=>a?.store??new Ul({open:n??r,activeTriggerId:l!==void 0?l:u,modal:!0,disablePointerDismissal:!0,nested:f,role:"alertdialog"})).current;d.useControlledProp("open",n,r),d.useControlledProp("activeTriggerId",l,u),d.useSyncedValue("nested",f),d.useContextCallback("onOpenChange",i),d.useContextCallback("onOpenChangeComplete",s);const p=d.useState("payload");ql({store:d,actionsRef:o,parentContext:c?.store.context});const g=m.useMemo(()=>({store:d}),[d]);return h.jsx(Kl.Provider,{value:g,children:typeof t=="function"?t({payload:p}):t})}function Lu({children:e,...t}){return h.jsx(Nu,{...t,children:e})}function Mu({className:e,children:t}){return h.jsxs(Wl,{children:[h.jsx(Vl,{className:"fixed inset-0 bg-primary-950/20 transition-all duration-150 data-[state=open]:opacity-100 data-[state=closed]:opacity-0"}),h.jsx(Xl,{className:q("fixed left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2","w-[min(400px,92vw)] rounded-xl border border-primary-200 bg-primary-50 p-0 shadow-xl","transition-all duration-150","data-[state=open]:opacity-100 data-[state=closed]:opacity-0","data-[state=open]:scale-100 data-[state=closed]:scale-95",e),children:t})]})}function Du({className:e,...t}){return h.jsx(Yl,{className:q("text-lg font-medium text-primary-900",e),...t})}function zu({className:e,...t}){return h.jsx(Gl,{className:q("text-sm text-primary-600",e),...t})}function Pu({className:e,...t}){return h.jsx(ao,{render:h.jsx(ve,{variant:"outline",className:q(e)}),...t})}function _u({className:e,...t}){return h.jsx(ao,{render:h.jsx(ve,{variant:"destructive",className:q(e)}),...t})}function Ou({open:e,onOpenChange:t,sessionTitle:n,onConfirm:r,onCancel:i}){return h.jsx(Lu,{open:e,onOpenChange:t,children:h.jsx(Mu,{children:h.jsxs("div",{className:"p-4",children:[h.jsx(Du,{className:"mb-1",children:"Delete Session"}),h.jsxs(zu,{className:"mb-4",children:['Are you sure you want to delete "',n,'"? This action cannot be undone.']}),h.jsxs("div",{className:"flex justify-end gap-2",children:[h.jsx(Pu,{onClick:i,children:"Cancel"}),h.jsx(_u,{onClick:r,children:"Delete"})]})]})})})}function Fu(e){const{open:t,defaultOpen:n,onOpenChange:r,disabled:i}=e,s=t!==void 0,[o,a]=Jl({controlled:t,default:n,name:"Collapsible",state:"open"}),{mounted:l,setMounted:u,transitionStatus:c}=cl(o,!0,!0),[f,d]=m.useState(o),[{height:p,width:g},y]=m.useState({height:void 0,width:void 0}),w=Vs(),[k,S]=m.useState(),v=k??w,[R,M]=m.useState(!1),[C,z]=m.useState(!1),U=m.useRef(null),F=m.useRef(null),E=m.useRef(null),N=m.useRef(null),A=fl(N,!1),P=dt(j=>{const T=!o,D=Xs(hl,j.nativeEvent);if(r(T,D),D.isCanceled)return;const L=N.current;F.current==="css-animation"&&L!=null&&L.style.removeProperty("animation-name"),!R&&!C&&(F.current!=null&&F.current!=="css-animation"&&!l&&T&&u(!0),F.current==="css-animation"&&(!f&&T&&d(!0),!l&&T&&u(!0))),a(T),F.current==="none"&&l&&!T&&u(!1)});return Ze(()=>{s&&F.current==="none"&&!C&&!o&&u(!1)},[s,C,o,t,u]),m.useMemo(()=>({abortControllerRef:U,animationTypeRef:F,disabled:i,handleTrigger:P,height:p,mounted:l,open:o,panelId:v,panelRef:N,runOnceAnimationsFinish:A,setDimensions:y,setHiddenUntilFound:M,setKeepMounted:z,setMounted:u,setOpen:a,setPanelIdState:S,setVisible:d,transitionDimensionRef:E,transitionStatus:c,visible:f,width:g}),[U,F,i,P,p,l,o,v,N,A,y,M,z,u,a,d,E,c,f,g])}const po=m.createContext(void 0);function mo(){const e=m.useContext(po);if(e===void 0)throw new Error(Kr(15));return e}let nn=(function(e){return e.open="data-open",e.closed="data-closed",e[e.startingStyle=Ri.startingStyle]="startingStyle",e[e.endingStyle=Ri.endingStyle]="endingStyle",e})({}),$u=(function(e){return e.panelOpen="data-panel-open",e})({});const Bu={[nn.open]:""},Hu={[nn.closed]:""},Uu={open(e){return e?{[$u.panelOpen]:""}:null}},qu={open(e){return e?Bu:Hu}},go={...qu,...Ys},Ku=m.forwardRef(function(t,n){const{render:r,className:i,defaultOpen:s=!1,disabled:o=!1,onOpenChange:a,open:l,...u}=t,c=dt(a),f=Fu({open:l,defaultOpen:s,onOpenChange:c,disabled:o}),d=m.useMemo(()=>({open:f.open,disabled:f.disabled,transitionStatus:f.transitionStatus}),[f.open,f.disabled,f.transitionStatus]),p=m.useMemo(()=>({...f,onOpenChange:c,state:d}),[f,c,d]),g=xt("div",t,{state:d,ref:n,props:u,stateAttributesMapping:go});return h.jsx(po.Provider,{value:p,children:g})}),Wu={...Uu,...Ys},Vu=m.forwardRef(function(t,n){const{panelId:r,open:i,handleTrigger:s,state:o,disabled:a}=mo(),{className:l,disabled:u=a,id:c,render:f,nativeButton:d=!0,...p}=t,{getButtonProps:g,buttonRef:y}=pl({disabled:u,focusableWhenDisabled:!0,native:d}),w=m.useMemo(()=>({"aria-controls":i?r:void 0,"aria-expanded":i,onClick:s}),[r,i,s]);return xt("button",t,{state:o,ref:[n,y],props:[w,p,g],stateAttributesMapping:Wu})});let Xu=(function(e){return e.disabled="data-disabled",e.orientation="data-orientation",e})({});function Yu(e){const{abortControllerRef:t,animationTypeRef:n,externalRef:r,height:i,hiddenUntilFound:s,keepMounted:o,id:a,mounted:l,onOpenChange:u,open:c,panelRef:f,runOnceAnimationsFinish:d,setDimensions:p,setMounted:g,setOpen:y,setVisible:w,transitionDimensionRef:k,visible:S,width:v}=e,R=m.useRef(!1),M=m.useRef(null),C=m.useRef(c),z=m.useRef(c),U=dl(),F=m.useMemo(()=>n.current==="css-animation"?!S:!c&&!l,[c,l,S,n]),E=dt(A=>{if(!A)return;if(n.current==null||k.current==null){const T=getComputedStyle(A),D=T.animationName!=="none"&&T.animationName!=="",L=T.transitionDuration!=="0s"&&T.transitionDuration!=="";D&&L||(T.animationName==="none"&&T.transitionDuration!=="0s"?n.current="css-transition":T.animationName!=="none"&&T.transitionDuration==="0s"?n.current="css-animation":n.current="none"),A.getAttribute(Xu.orientation)==="horizontal"||T.transitionProperty.indexOf("width")>-1?k.current="width":k.current="height"}if(n.current!=="css-transition")return;(i===void 0||v===void 0)&&(p({height:A.scrollHeight,width:A.scrollWidth}),z.current&&A.style.setProperty("transition-duration","0s"));let P=-1,j=-1;return P=We.request(()=>{z.current=!1,j=We.request(()=>{setTimeout(()=>{A.style.removeProperty("transition-duration")})})}),()=>{We.cancel(P),We.cancel(j)}}),N=Sl(r,f,E);return Ze(()=>{if(n.current!=="css-transition")return;const A=f.current;if(!A)return;let P=-1;if(t.current!=null&&(t.current.abort(),t.current=null),c){const j={"justify-content":A.style.justifyContent,"align-items":A.style.alignItems,"align-content":A.style.alignContent,"justify-items":A.style.justifyItems};Object.keys(j).forEach(T=>{A.style.setProperty(T,"initial","important")}),!z.current&&!o&&A.setAttribute(nn.startingStyle,""),p({height:A.scrollHeight,width:A.scrollWidth}),P=We.request(()=>{Object.entries(j).forEach(([T,D])=>{D===""?A.style.removeProperty(T):A.style.setProperty(T,D)})})}else{if(A.scrollHeight===0&&A.scrollWidth===0)return;p({height:A.scrollHeight,width:A.scrollWidth});const j=new AbortController;t.current=j;const T=j.signal;let D=null;const L=nn.endingStyle;return D=new MutationObserver(H=>{H.some(x=>x.type==="attributes"&&x.attributeName===L)&&(D?.disconnect(),D=null,d(()=>{p({height:0,width:0}),A.style.removeProperty("content-visibility"),g(!1),t.current===j&&(t.current=null)},T))}),D.observe(A,{attributes:!0,attributeFilter:[L]}),()=>{D?.disconnect(),U.cancel(),t.current===j&&(j.abort(),t.current=null)}}return()=>{We.cancel(P)}},[t,n,U,s,o,l,c,f,d,p,g]),Ze(()=>{if(n.current!=="css-animation")return;const A=f.current;A&&(M.current=A.style.animationName||M.current,A.style.setProperty("animation-name","none"),p({height:A.scrollHeight,width:A.scrollWidth}),!C.current&&!R.current&&A.style.removeProperty("animation-name"),c?(t.current!=null&&(t.current.abort(),t.current=null),g(!0),w(!0)):(t.current=new AbortController,d(()=>{g(!1),w(!1),t.current=null},t.current.signal)))},[t,n,c,f,d,p,g,w,S]),ml(()=>{const A=We.request(()=>{C.current=!1});return()=>We.cancel(A)}),Ze(()=>{if(!s)return;const A=f.current;if(!A)return;let P=-1,j=-1;return c&&R.current&&(A.style.transitionDuration="0s",p({height:A.scrollHeight,width:A.scrollWidth}),P=We.request(()=>{R.current=!1,j=We.request(()=>{setTimeout(()=>{A.style.removeProperty("transition-duration")})})})),()=>{We.cancel(P),We.cancel(j)}},[s,c,f,p]),Ze(()=>{const A=f.current;A&&s&&F&&(A.setAttribute("hidden","until-found"),n.current==="css-transition"&&A.setAttribute(nn.startingStyle,""))},[s,F,n,f]),m.useEffect(function(){const P=f.current;if(!P)return;function j(T){R.current=!0,y(!0),u(!0,Xs(gl,T))}return P.addEventListener("beforematch",j),()=>{P.removeEventListener("beforematch",j)}},[u,f,y]),m.useMemo(()=>({props:{hidden:F,id:a,ref:N}}),[F,a,N])}let Pi=(function(e){return e.collapsiblePanelHeight="--collapsible-panel-height",e.collapsiblePanelWidth="--collapsible-panel-width",e})({});const Gu=m.forwardRef(function(t,n){const{className:r,hiddenUntilFound:i,keepMounted:s,render:o,id:a,...l}=t,{abortControllerRef:u,animationTypeRef:c,height:f,mounted:d,onOpenChange:p,open:g,panelId:y,panelRef:w,runOnceAnimationsFinish:k,setDimensions:S,setHiddenUntilFound:v,setKeepMounted:R,setMounted:M,setPanelIdState:C,setOpen:z,setVisible:U,state:F,transitionDimensionRef:E,visible:N,width:A,transitionStatus:P}=mo(),j=i??!1,T=s??!1;Ze(()=>{if(a)return C(a),()=>{C(void 0)}},[a,C]),Ze(()=>{v(j)},[v,j]),Ze(()=>{R(T)},[R,T]);const{props:D}=Yu({abortControllerRef:u,animationTypeRef:c,externalRef:n,height:f,hiddenUntilFound:j,id:y,keepMounted:T,mounted:d,onOpenChange:p,open:g,panelRef:w,runOnceAnimationsFinish:k,setDimensions:S,setMounted:M,setOpen:z,setVisible:U,transitionDimensionRef:E,visible:N,width:A});xl({open:g&&P==="idle",ref:w,onComplete(){g&&S({height:void 0,width:void 0})}});const L=m.useMemo(()=>({...F,transitionStatus:P}),[F,P]),H=xt("div",t,{state:L,ref:[n,w],props:[D,{style:{[Pi.collapsiblePanelHeight]:f===void 0?"auto":`${f}px`,[Pi.collapsiblePanelWidth]:A===void 0?"auto":`${A}px`}},l],stateAttributesMapping:go});return T||j||!T&&d?H:null});function Tn(e){return h.jsx(Ku,{...e})}function jn({className:e,...t}){return h.jsx(Vu,{className:q("group inline-flex items-center gap-1.5 rounded-md px-2 py-1 text-left text-xs font-medium text-primary-500 transition-colors hover:bg-primary-100 hover:text-primary-700 data-panel-open:text-primary-700",e),...t})}function An({className:e,contentClassName:t,children:n,...r}){return h.jsx(Gu,{className:q('flex h-(--collapsible-panel-height) flex-col overflow-hidden text-sm transition-all duration-150 ease-out data-ending-style:h-0 data-starting-style:h-0 [&[hidden]:not([hidden="until-found"])]:hidden',e),...r,children:h.jsx("div",{className:q("pt-1",t),children:n})})}const xo=m.createContext(void 0);function qn(){const e=m.useContext(xo);if(e===void 0)throw new Error(Kr(53));return e}let In=(function(e){return e.scrollAreaCornerHeight="--scroll-area-corner-height",e.scrollAreaCornerWidth="--scroll-area-corner-width",e})({});const pn=500,_i=16;function Ye(e,t,n){if(!e)return 0;const r=getComputedStyle(e),i=n==="x"?"Inline":"Block";return n==="x"&&t==="margin"?parseFloat(r[`${t}InlineStart`])*2:parseFloat(r[`${t}${i}Start`])+parseFloat(r[`${t}${i}End`])}let Qu=(function(e){return e.orientation="data-orientation",e.hovering="data-hovering",e.scrolling="data-scrolling",e.hasOverflowX="data-has-overflow-x",e.hasOverflowY="data-has-overflow-y",e.overflowXStart="data-overflow-x-start",e.overflowXEnd="data-overflow-x-end",e.overflowYStart="data-overflow-y-start",e.overflowYEnd="data-overflow-y-end",e})({});const dn="base-ui-disable-scrollbar",yo={className:dn,getElement(e){return h.jsx("style",{nonce:e,href:dn,precedence:"base-ui:low",children:`.${dn}{scrollbar-width:none}.${dn}::-webkit-scrollbar{display:none}`})}};let _t=(function(e){return e.hasOverflowX="data-has-overflow-x",e.hasOverflowY="data-has-overflow-y",e.overflowXStart="data-overflow-x-start",e.overflowXEnd="data-overflow-x-end",e.overflowYStart="data-overflow-y-start",e.overflowYEnd="data-overflow-y-end",e})({});const Qr={hasOverflowX:e=>e?{[_t.hasOverflowX]:""}:null,hasOverflowY:e=>e?{[_t.hasOverflowY]:""}:null,overflowXStart:e=>e?{[_t.overflowXStart]:""}:null,overflowXEnd:e=>e?{[_t.overflowXEnd]:""}:null,overflowYStart:e=>e?{[_t.overflowYStart]:""}:null,overflowYEnd:e=>e?{[_t.overflowYEnd]:""}:null,cornerHidden:()=>null},Ju=m.createContext(void 0),Zu={disableStyleElements:!1};function ec(){return m.useContext(Ju)??Zu}const tc={x:0,y:0},Oi={width:0,height:0},nc={xStart:!1,xEnd:!1,yStart:!1,yEnd:!1},rc={x:!1,y:!1,corner:!1},ic=m.forwardRef(function(t,n){const{render:r,className:i,overflowEdgeThreshold:s,...o}=t,a=sc(s),l=Vs(),u=vn(),c=vn(),{nonce:f,disableStyleElements:d}=ec(),[p,g]=m.useState(!1),[y,w]=m.useState(!1),[k,S]=m.useState(!1),[v,R]=m.useState(!1),[M,C]=m.useState(Oi),[z,U]=m.useState(Oi),[F,E]=m.useState(nc),[N,A]=m.useState(rc),P=m.useRef(null),j=m.useRef(null),T=m.useRef(null),D=m.useRef(null),L=m.useRef(null),H=m.useRef(null),_=m.useRef(null),x=m.useRef(!1),V=m.useRef(0),X=m.useRef(0),b=m.useRef(0),Q=m.useRef(0),re=m.useRef("vertical"),K=m.useRef(tc),he=dt($=>{const J=$.x-K.current.x,xe=$.y-K.current.y;K.current=$,xe!==0&&(S(!0),u.start(pn,()=>{S(!1)})),J!==0&&(w(!0),c.start(pn,()=>{w(!1)}))}),me=dt($=>{$.button===0&&(x.current=!0,V.current=$.clientY,X.current=$.clientX,re.current=$.currentTarget.getAttribute(Qu.orientation),j.current&&(b.current=j.current.scrollTop,Q.current=j.current.scrollLeft),L.current&&re.current==="vertical"&&L.current.setPointerCapture($.pointerId),H.current&&re.current==="horizontal"&&H.current.setPointerCapture($.pointerId))}),ue=dt($=>{if(!x.current)return;const J=$.clientY-V.current,xe=$.clientX-X.current;if(j.current){const ne=j.current.scrollHeight,pe=j.current.clientHeight,Oe=j.current.scrollWidth,Fe=j.current.clientWidth;if(L.current&&T.current&&re.current==="vertical"){const Ae=Ye(T.current,"padding","y"),$e=Ye(L.current,"margin","y"),I=L.current.offsetHeight,O=T.current.offsetHeight-I-Ae-$e,Y=J/O;j.current.scrollTop=b.current+Y*(ne-pe),$.preventDefault(),S(!0),u.start(pn,()=>{S(!1)})}if(H.current&&D.current&&re.current==="horizontal"){const Ae=Ye(D.current,"padding","x"),$e=Ye(H.current,"margin","x"),I=H.current.offsetWidth,O=D.current.offsetWidth-I-Ae-$e,Y=xe/O;j.current.scrollLeft=Q.current+Y*(Oe-Fe),$.preventDefault(),w(!0),c.start(pn,()=>{w(!1)})}}}),se=dt($=>{x.current=!1,L.current&&re.current==="vertical"&&L.current.releasePointerCapture($.pointerId),H.current&&re.current==="horizontal"&&H.current.releasePointerCapture($.pointerId)});function ge($){R($.pointerType==="touch")}function ke($){if(ge($),$.pointerType!=="touch"){const J=yl(P.current,$.target);g(J)}}const we=m.useMemo(()=>({hasOverflowX:!N.x,hasOverflowY:!N.y,overflowXStart:F.xStart,overflowXEnd:F.xEnd,overflowYStart:F.yStart,overflowYEnd:F.yEnd,cornerHidden:N.corner}),[N.x,N.y,N.corner,F]),Se={role:"presentation",onPointerEnter:ke,onPointerMove:ke,onPointerDown:ge,onPointerLeave(){g(!1)},style:{position:"relative",[In.scrollAreaCornerHeight]:`${M.height}px`,[In.scrollAreaCornerWidth]:`${M.width}px`}},Le=xt("div",t,{state:we,ref:[n,P],props:[Se,o],stateAttributesMapping:Qr}),W=m.useMemo(()=>({handlePointerDown:me,handlePointerMove:ue,handlePointerUp:se,handleScroll:he,cornerSize:M,setCornerSize:C,thumbSize:z,setThumbSize:U,touchModality:v,cornerRef:_,scrollingX:y,setScrollingX:w,scrollingY:k,setScrollingY:S,hovering:p,setHovering:g,viewportRef:j,rootRef:P,scrollbarYRef:T,scrollbarXRef:D,thumbYRef:L,thumbXRef:H,rootId:l,hiddenState:N,setHiddenState:A,overflowEdges:F,setOverflowEdges:E,viewportState:we,overflowEdgeThreshold:a}),[me,ue,se,he,M,z,v,y,w,k,S,p,g,l,N,F,we,a]);return h.jsxs(xo.Provider,{value:W,children:[!d&&yo.getElement(f),Le]})});function sc(e){if(typeof e=="number"){const t=Math.max(0,e);return{xStart:t,xEnd:t,yStart:t,yEnd:t}}return{xStart:Math.max(0,e?.xStart||0),xEnd:Math.max(0,e?.xEnd||0),yStart:Math.max(0,e?.yStart||0),yEnd:Math.max(0,e?.yEnd||0)}}const oc=m.createContext(void 0);function ot(e,t=Number.MIN_SAFE_INTEGER,n=Number.MAX_SAFE_INTEGER){return Math.max(t,Math.min(e,n))}function ac(e,t){if(typeof IntersectionObserver>"u")return()=>{};const n=new IntersectionObserver(r=>{r.forEach(i=>{i.intersectionRatio>0&&(t(),n.disconnect())})});return n.observe(e),()=>{n.disconnect()}}let gt=(function(e){return e.scrollAreaOverflowXStart="--scroll-area-overflow-x-start",e.scrollAreaOverflowXEnd="--scroll-area-overflow-x-end",e.scrollAreaOverflowYStart="--scroll-area-overflow-y-start",e.scrollAreaOverflowYEnd="--scroll-area-overflow-y-end",e})({}),Fi=!1;function lc(){Fi||bl||(typeof CSS<"u"&&"registerProperty"in CSS&&[gt.scrollAreaOverflowXStart,gt.scrollAreaOverflowXEnd,gt.scrollAreaOverflowYStart,gt.scrollAreaOverflowYEnd].forEach(e=>{try{CSS.registerProperty({name:e,syntax:"<length>",inherits:!1,initialValue:"0px"})}catch{}}),Fi=!0)}const uc=m.forwardRef(function(t,n){const{render:r,className:i,...s}=t,{viewportRef:o,scrollbarYRef:a,scrollbarXRef:l,thumbYRef:u,thumbXRef:c,cornerRef:f,cornerSize:d,setCornerSize:p,setThumbSize:g,rootId:y,setHiddenState:w,hiddenState:k,handleScroll:S,setHovering:v,setOverflowEdges:R,overflowEdges:M,overflowEdgeThreshold:C}=qn(),z=Gs(),U=m.useRef(!0),F=vn(),E=vn(),N=dt(()=>{const L=o.current,H=a.current,_=l.current,x=u.current,V=c.current,X=f.current;if(!L)return;const b=L.scrollHeight,Q=L.scrollWidth,re=L.clientHeight,K=L.clientWidth,he=L.scrollTop,me=L.scrollLeft;if(b===0||Q===0)return;const ue=re>=b,se=K>=Q,ge=K/Q,ke=re/b,we=Math.max(0,Q-K),Se=Math.max(0,b-re);let Le=0,W=0;se||(z==="rtl"?Le=ot(-me,0,we):Le=ot(me,0,we),W=we-Le);const $=ue?0:ot(he,0,Se),J=ue?0:Se-$,xe=se?0:K,ne=ue?0:re;let pe=0,Oe=0;!se&&!ue&&(pe=H?.offsetWidth||0,Oe=_?.offsetHeight||0);const Fe=d.width===0&&d.height===0,Ae=Fe?pe:0,$e=Fe?Oe:0,I=Ye(_,"padding","x"),O=Ye(H,"padding","y"),Y=Ye(V,"margin","x"),ee=Ye(x,"margin","y"),ae=xe-I-Y,Ee=ne-O-ee,qe=_?Math.min(_.offsetWidth-Ae,ae):ae,Be=H?Math.min(H.offsetHeight-$e,Ee):Ee,Ge=Math.max(_i,qe*ge),Ke=Math.max(_i,Be*ke);if(g(de=>de.height===Ke&&de.width===Ge?de:{width:Ge,height:Ke}),H&&x){const de=H.offsetHeight-Ke-O-ee,je=b-re,wt=je===0?0:he/je,ut=Math.min(de,Math.max(0,wt*de));x.style.transform=`translate3d(0,${ut}px,0)`}if(_&&V){const de=_.offsetWidth-Ge-I-Y,je=Q-K,wt=je===0?0:me/je,ut=z==="rtl"?ot(wt*de,-de,0):ot(wt*de,0,de);V.style.transform=`translate3d(${ut}px,0,0)`}const Ce=ot(Le,0,we),Te=ot(W,0,we),ze=ot($,0,Se),bt=ot(J,0,Se),zt=[[gt.scrollAreaOverflowXStart,Ce],[gt.scrollAreaOverflowXEnd,Te],[gt.scrollAreaOverflowYStart,ze],[gt.scrollAreaOverflowYEnd,bt]];for(const[de,je]of zt)L.style.setProperty(de,`${je}px`);X&&(se||ue?p({width:0,height:0}):!se&&!ue&&p({width:pe,height:Oe})),w(de=>{const je=ue||se;return de.y===ue&&de.x===se&&de.corner===je?de:{y:ue,x:se,corner:je}});const kt={xStart:!se&&Ce>C.xStart,xEnd:!se&&Te>C.xEnd,yStart:!ue&&ze>C.yStart,yEnd:!ue&&bt>C.yEnd};R(de=>de.xStart===kt.xStart&&de.xEnd===kt.xEnd&&de.yStart===kt.yStart&&de.yEnd===kt.yEnd?de:kt)});Ze(()=>{if(!o.current)return;lc();let L=!1;return ac(o.current,()=>{if(!L){L=!0;return}N()})},[N,o]),Ze(()=>{queueMicrotask(N)},[N,k,z]),Ze(()=>{o.current?.matches(":hover")&&v(!0)},[o,v]),m.useEffect(()=>{const L=o.current;if(typeof ResizeObserver>"u"||!L)return;let H=!1;const _=new ResizeObserver(()=>{if(!H){H=!0;return}N()});return _.observe(L),E.start(0,()=>{const x=L.getAnimations({subtree:!0});x.length!==0&&Promise.all(x.map(V=>V.finished)).then(N).catch(()=>{})}),()=>{_.disconnect(),E.clear()}},[N,o,E]);function A(){U.current=!1}const P={role:"presentation",...y&&{"data-id":`${y}-viewport`},...(!k.x||!k.y)&&{tabIndex:0},className:yo.className,style:{overflow:"scroll"},onScroll(){o.current&&(N(),U.current||S({x:o.current.scrollLeft,y:o.current.scrollTop}),F.start(100,()=>{U.current=!0}))},onWheel:A,onTouchMove:A,onPointerMove:A,onPointerEnter:A,onKeyDown:A},j=m.useMemo(()=>({hasOverflowX:!k.x,hasOverflowY:!k.y,overflowXStart:M.xStart,overflowXEnd:M.xEnd,overflowYStart:M.yStart,overflowYEnd:M.yEnd,cornerHidden:k.corner}),[k.x,k.y,k.corner,M]),T=xt("div",t,{ref:[n,o],state:j,props:[P,s],stateAttributesMapping:Qr}),D=m.useMemo(()=>({computeThumbPosition:N}),[N]);return h.jsx(oc.Provider,{value:D,children:T})}),bo=m.createContext(void 0);function cc(){const e=m.useContext(bo);if(e===void 0)throw new Error(Kr(54));return e}let Rn=(function(e){return e.scrollAreaThumbHeight="--scroll-area-thumb-height",e.scrollAreaThumbWidth="--scroll-area-thumb-width",e})({});const fc=m.forwardRef(function(t,n){const{render:r,className:i,orientation:s="vertical",keepMounted:o=!1,...a}=t,{hovering:l,scrollingX:u,scrollingY:c,hiddenState:f,overflowEdges:d,scrollbarYRef:p,scrollbarXRef:g,viewportRef:y,thumbYRef:w,thumbXRef:k,handlePointerDown:S,handlePointerUp:v,rootId:R,thumbSize:M}=qn(),C=m.useMemo(()=>({hovering:l,scrolling:{horizontal:u,vertical:c}[s],orientation:s,hasOverflowX:!f.x,hasOverflowY:!f.y,overflowXStart:d.xStart,overflowXEnd:d.xEnd,overflowYStart:d.yStart,overflowYEnd:d.yEnd,cornerHidden:f.corner}),[l,u,c,s,f,d]),z=Gs();m.useEffect(()=>{const P=y.current,j=s==="vertical"?p.current:g.current;if(!j)return;function T(D){if(!(!P||!j||D.ctrlKey)){if(D.preventDefault(),s==="vertical"){if(P.scrollTop===0&&D.deltaY<0)return}else if(P.scrollLeft===0&&D.deltaX<0)return;if(s==="vertical"){if(P.scrollTop===P.scrollHeight-P.clientHeight&&D.deltaY>0)return}else if(P.scrollLeft===P.scrollWidth-P.clientWidth&&D.deltaX>0)return;s==="vertical"?P.scrollTop+=D.deltaY:P.scrollLeft+=D.deltaX}}return j.addEventListener("wheel",T,{passive:!1}),()=>{j.removeEventListener("wheel",T)}},[s,g,p,y]);const U={...R&&{"data-id":`${R}-scrollbar`},onPointerDown(P){if(P.button===0&&P.currentTarget===P.target&&y.current){if(w.current&&p.current&&s==="vertical"){const j=Ye(w.current,"margin","y"),T=Ye(p.current,"padding","y"),D=w.current.offsetHeight,L=p.current.getBoundingClientRect(),H=P.clientY-L.top-D/2-T+j/2,_=y.current.scrollHeight,x=y.current.clientHeight,V=p.current.offsetHeight-D-T-j,b=H/V*(_-x);y.current.scrollTop=b}if(k.current&&g.current&&s==="horizontal"){const j=Ye(k.current,"margin","x"),T=Ye(g.current,"padding","x"),D=k.current.offsetWidth,L=g.current.getBoundingClientRect(),H=P.clientX-L.left-D/2-T+j/2,_=y.current.scrollWidth,x=y.current.clientWidth,V=g.current.offsetWidth-D-T-j,X=H/V;let b;z==="rtl"?(b=(1-X)*(_-x),y.current.scrollLeft<=0&&(b=-b)):b=X*(_-x),y.current.scrollLeft=b}S(P)}},onPointerUp:v,style:{position:"absolute",touchAction:"none",WebkitUserSelect:"none",userSelect:"none",...s==="vertical"&&{top:0,bottom:`var(${In.scrollAreaCornerHeight})`,insetInlineEnd:0,[Rn.scrollAreaThumbHeight]:`${M.height}px`},...s==="horizontal"&&{insetInlineStart:0,insetInlineEnd:`var(${In.scrollAreaCornerWidth})`,bottom:0,[Rn.scrollAreaThumbWidth]:`${M.width}px`}}},F=xt("div",t,{ref:[n,s==="vertical"?p:g],state:C,props:[U,a],stateAttributesMapping:Qr}),E=m.useMemo(()=>({orientation:s}),[s]),N=s==="vertical"?f.y:f.x;return o||!N?h.jsx(bo.Provider,{value:E,children:F}):null}),hc=m.forwardRef(function(t,n){const{render:r,className:i,...s}=t,{thumbYRef:o,thumbXRef:a,handlePointerDown:l,handlePointerMove:u,handlePointerUp:c,setScrollingX:f,setScrollingY:d}=qn(),{orientation:p}=cc(),g=m.useMemo(()=>({orientation:p}),[p]);return xt("div",t,{ref:[n,p==="vertical"?o:a],state:g,props:[{onPointerDown:l,onPointerMove:u,onPointerUp(w){p==="vertical"&&d(!1),p==="horizontal"&&f(!1),c(w)},style:{...p==="vertical"&&{height:`var(${Rn.scrollAreaThumbHeight})`},...p==="horizontal"&&{width:`var(${Rn.scrollAreaThumbWidth})`}}},s]})}),pc=m.forwardRef(function(t,n){const{render:r,className:i,...s}=t,{cornerRef:o,cornerSize:a,hiddenState:l}=qn(),u=xt("div",t,{ref:[n,o],props:[{style:{position:"absolute",bottom:0,insetInlineEnd:0,width:a.width,height:a.height}},s]});return l.corner?null:u});function ko({className:e,...t}){return h.jsx(ic,{className:q("group/scroll-area relative outline-none focus-visible:outline-none",e),...t})}function wo({className:e,...t}){return h.jsx(uc,{className:q("h-full w-full outline-none focus-visible:outline-none",e),...t})}function So({className:e,...t}){return h.jsx(fc,{className:q("flex w-2 touch-none select-none p-0.5 outline-none focus-visible:outline-none","opacity-0 transition-opacity duration-150","data-hovering:opacity-100 data-scrolling:opacity-100 group-hover/scroll-area:opacity-100",e),...t})}function Co({className:e,...t}){return h.jsx(hc,{className:q("flex-1 rounded-full bg-primary-500 outline-none focus-visible:outline-none",e),...t})}function dc({className:e,...t}){return h.jsx(pc,{className:q("bg-primary-100 outline-none focus-visible:outline-none",e),...t})}function mc(e){return e==="subagent"?Tl:e==="cron"?jl:Al}function gc(e){return!e||!Array.isArray(e.content)?"":e.content.map(n=>n.type==="text"?String(n.text??""):"").join(" ").replace(/\s+/g," ").trim()}function xc(e){if(typeof e=="number"&&Number.isFinite(e))return e<1e12?e*1e3:e;if(typeof e=="string"){const t=Date.parse(e);if(!Number.isNaN(t))return t}return null}function yc(e){if(!e)return null;const t=[e.createdAt,e.created_at,e.timestamp,e.time,e.ts];for(const n of t){const r=xc(n);if(r)return r}return null}function bc(e){const t=e-Date.now(),n=Math.abs(t),r=[["minute",6e4],["hour",36e5],["day",864e5]];let i="minute",s=6e4;n>=r[2][1]?[i,s]=r[2]:n>=r[1][1]&&([i,s]=r[1]);const o=Math.round(t/s);return new Intl.RelativeTimeFormat("en",{numeric:"auto"}).format(o,i)}function kc(e){const t=String(e??"").toLowerCase().trim();return t?t==="error"||t==="failed"?"error":t==="completed"||t==="ended"||t==="done"?"success":null:null}function wc({session:e,active:t,isGenerating:n=!1,isPinned:r,selectionMode:i=!1,selected:s=!1,onToggleSelect:o,onSelect:a,onTogglePin:l,onRename:u,onDelete:c,onExport:f}){const d=e.label||e.title||e.derivedTitle||e.friendlyId,p=mc(e.kind),g=e.kind==="subagent"&&(e.lastMessage?.role==="assistant"||e.lastMessage?.role==="toolResult")?gc(e.lastMessage):"",y=g.length>50?`${g.slice(0,50).trimEnd()}…`:g,w=e.kind==="subagent"?kc(e.status):null,k=e.kind==="cron"?yc(e.lastMessage):null;return h.jsxs(tn,{to:"/chat/$sessionKey",params:{sessionKey:e.friendlyId},onClick:S=>{if(i){S.preventDefault(),S.stopPropagation(),o?.(e);return}a?.()},className:q("group inline-flex items-center justify-between","w-full text-left pl-1.5 pr-0.5 min-h-8 py-1 rounded-lg transition-colors duration-0","select-none",t?"bg-primary-200 text-primary-950":"bg-transparent text-primary-950 [&:hover:not(:has(button:hover))]:bg-primary-200"),children:[h.jsxs("div",{className:"flex items-center gap-2 flex-1 min-w-0",children:[i?h.jsx("span",{"aria-hidden":"true",className:q("inline-flex items-center justify-center size-4 shrink-0 rounded border transition-colors",s?"bg-primary-700 border-primary-700 text-white":"border-primary-300 bg-surface"),children:s?h.jsx("svg",{viewBox:"0 0 12 12",className:"size-3",fill:"none",stroke:"currentColor",strokeWidth:2,children:h.jsx("path",{d:"M2.5 6l2.5 2.5 4.5-5"})}):null}):null,h.jsxs("div",{className:"flex-1 min-w-0",children:[h.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[h.jsx(te,{icon:p,size:12,strokeWidth:1.75,className:"text-primary-500/70 shrink-0"}),h.jsxs("div",{className:"text-sm font-[450] line-clamp-1 min-w-0",children:[r?h.jsx("span",{className:"mr-1 text-xs text-primary-700","aria-hidden":"true",children:"📌"}):null,d]}),e.kind==="subagent"?n?h.jsx("span",{"aria-label":"Session active",className:"size-1.5 rounded-full bg-green-500 shrink-0"}):w==="success"?h.jsx(te,{icon:Qs,size:12,strokeWidth:1.8,className:"text-green-600/80 shrink-0"}):w==="error"?h.jsx(te,{icon:$n,size:12,strokeWidth:1.8,className:"text-red-600/80 shrink-0"}):null:null]}),y?h.jsx("div",{className:"text-[11px] text-primary-600/80 line-clamp-1 mt-0.5 pl-[18px]",children:y}):null,e.kind==="cron"&&k?h.jsx("div",{className:"text-[10px] text-primary-500/75 line-clamp-1 mt-0.5 pl-[18px] font-mono",children:bc(k)}):null]})]}),i?null:h.jsxs(Bn,{children:[h.jsx(Hn,{type:"button",onClick:S=>{S.preventDefault(),S.stopPropagation()},className:q("ml-2 inline-flex size-7 items-center justify-center rounded-md text-primary-700","opacity-0 transition-opacity group-hover:opacity-100 hover:bg-primary-200","aria-expanded:opacity-100 aria-expanded:bg-primary-200"),children:h.jsx(te,{icon:Cl,size:20,strokeWidth:1.5})}),h.jsxs(Un,{side:"bottom",align:"end",children:[h.jsxs(mt,{onClick:S=>{S.preventDefault(),S.stopPropagation(),l(e)},className:"gap-2",children:[h.jsx("span",{className:"text-xs","aria-hidden":"true",children:"📌"})," ",r?"Unpin Session":"Pin Session"]}),h.jsxs(mt,{onClick:S=>{S.preventDefault(),S.stopPropagation(),u(e)},className:"gap-2",children:[h.jsx(te,{icon:vl,size:20,strokeWidth:1.5})," ","Rename"]}),h.jsxs(mt,{onClick:S=>{S.preventDefault(),S.stopPropagation(),f(e)},className:"gap-2",children:[h.jsx(te,{icon:El,size:20,strokeWidth:1.5})," ","Export"]}),Ir(e.key)?null:h.jsxs(mt,{onClick:S=>{S.preventDefault(),S.stopPropagation(),c(e)},className:"text-red-700 gap-2 hover:bg-red-50/80 data-highlighted:bg-red-50/80",children:[h.jsx(te,{icon:Js,size:20,strokeWidth:1.5})," ","Delete"]})]})]})]})}function Sc(e,t){return e.active!==t.active||e.isGenerating!==t.isGenerating||e.isPinned!==t.isPinned||e.selectionMode!==t.selectionMode||e.selected!==t.selected||e.onToggleSelect!==t.onToggleSelect||e.onSelect!==t.onSelect||e.onTogglePin!==t.onTogglePin||e.onRename!==t.onRename||e.onDelete!==t.onDelete||e.onExport!==t.onExport?!1:e.session===t.session?!0:e.session.key===t.session.key&&e.session.friendlyId===t.session.friendlyId&&e.session.label===t.session.label&&e.session.title===t.session.title&&e.session.derivedTitle===t.session.derivedTitle&&e.session.updatedAt===t.session.updatedAt&&e.session.kind===t.session.kind&&e.session.status===t.session.status&&e.session.lastMessage===t.session.lastMessage}const rr=m.memo(wc,Sc),vo="opencami-pinned-sessions",Eo="opencami-sidebar-folders",ft={webchat:!1,subagent:!1,cron:!1,other:!1};async function Cc(e){const t=new URLSearchParams;e&&t.set("sessionKey",e);const n=await fetch(`/api/sessions?${t.toString()}`,{method:"DELETE"});if(!n.ok)throw new Error(await it(n))}async function vc(e,t,n){const r=[];let i=0;const s=Array.from({length:Math.min(t,e.length)},async function(){for(;i<e.length;){const a=i;i+=1;try{await n(e[a])}catch(l){r.push(l)}}});return await Promise.all(s),r}function Ec(){if(typeof window>"u")return[];try{const e=localStorage.getItem(vo);if(!e)return[];const t=JSON.parse(e);return Array.isArray(t)?t.filter(n=>typeof n=="string"):[]}catch{return[]}}function Tc(e){if(!(typeof window>"u"))try{const t=Array.from(new Set(e));localStorage.setItem(vo,JSON.stringify(t))}catch{}}function jc(){if(typeof window>"u")return{...ft};try{const e=localStorage.getItem(Eo);if(!e)return{...ft};const t=JSON.parse(e);return!t||typeof t!="object"?{...ft}:{webchat:typeof t.webchat=="boolean"?t.webchat:ft.webchat,subagent:typeof t.subagent=="boolean"?t.subagent:ft.subagent,cron:typeof t.cron=="boolean"?t.cron:ft.cron,other:typeof t.other=="boolean"?t.other:ft.other}}catch{return{...ft}}}function Ac(e){if(!(typeof window>"u"))try{localStorage.setItem(Eo,JSON.stringify(e))}catch{}}function kn(e,t,n){return n&&e.key?e.key===n:e.friendlyId===t}function Ic(e){if(!e)return!1;const t=e.toLowerCase();return t.includes("running")||t.includes("active")||t.includes("stream")||t.includes("generat")}function ir(e,t,n,r){return kn(e,t,n)&&r?!0:Ic(e.status)}const Rc=m.memo(function({sessions:t,activeFriendlyId:n,activeSessionKey:r,isStreaming:i=!1,defaultOpen:s=!0,onSelect:o,onRename:a,onDelete:l,onExport:u}){const c=m.useDeferredValue(t),f=qt(),[d,p]=m.useState(()=>Ec()),[g,y]=m.useState(()=>jc()),[w,k]=m.useState(!1),[S,v]=m.useState(()=>new Set),R=m.useMemo(()=>new Set(d),[d]),M=c.filter(_=>R.has(_.key)),C=c.filter(_=>!R.has(_.key)),z=M.length>0&&C.length>0,U=m.useMemo(()=>{const _={chat:[],webchat:[],subagent:[],cron:[],other:[]};for(const x of C){const V=x.kind??"other";_[V].push(x)}return _},[C]),F=m.useMemo(()=>c.filter(_=>S.has(_.key)),[S,c]),E=F.length,N=m.useCallback(()=>{k(_=>(_&&v(new Set),!_))},[]),A=m.useCallback(_=>{Ir(_.key)||v(x=>{const V=new Set(x);return V.has(_.key)?V.delete(_.key):V.add(_.key),V})},[]),P=m.useCallback(()=>{v(new Set(c.filter(_=>!Ir(_.key)).map(_=>_.key)))},[c]),j=m.useCallback(()=>{k(!1),v(new Set)},[]),T=m.useCallback(async()=>{if(F.length===0||!window.confirm(`Delete ${F.length} sessions? This will archive them.`))return;const x=await vc(F.map(V=>V.key),10,Cc);x.length>0&&console.error("[sidebar] Bulk delete failed for some sessions",x),k(!1),v(new Set),f.invalidateQueries({queryKey:be.sessions})},[f,F]),D=m.useCallback(_=>{p(x=>{const X=x.includes(_.key)?x.filter(b=>b!==_.key):[...x,_.key];return Tc(X),X})},[]),L=m.useCallback((_,x)=>{y(V=>{const X={...V,[_]:x};return Ac(X),X})},[]);function H(_,x,V){return V.length===0?null:h.jsxs(Tn,{className:"flex flex-col",open:g[_],onOpenChange:X=>L(_,X),children:[h.jsxs(jn,{className:q("w-full justify-between border-l-2 border-primary-200/70 px-2 py-1 text-[11px] font-medium text-primary-500/80 text-balance"),children:[h.jsx("span",{className:"truncate",children:x}),h.jsx("span",{className:q("rounded-full bg-primary-100 px-1.5 py-0.5 text-[10px] font-medium text-primary-700 tabular-nums"),children:V.length})]}),h.jsx(An,{contentClassName:"flex flex-col gap-px",children:V.map(X=>h.jsx(rr,{session:X,active:kn(X,n,r),isGenerating:ir(X,n,r,i),isPinned:!1,selectionMode:w,selected:S.has(X.key),onToggleSelect:A,onSelect:o,onTogglePin:D,onRename:a,onDelete:l,onExport:u},X.key))})]})}return h.jsxs(Tn,{className:"flex h-full flex-col flex-1 min-h-0 w-full",defaultOpen:s,children:[h.jsxs("div",{className:"flex items-center justify-between pr-2 shrink-0",children:[h.jsxs(jn,{className:"w-fit pl-1.5 text-balance",children:["Sessions",h.jsx("span",{className:"opacity-0 transition-opacity duration-150 group-hover:opacity-100",children:h.jsx(te,{icon:Wr,className:"size-3 transition-transform duration-150 group-data-panel-open:rotate-90"})})]}),h.jsx("button",{type:"button",onClick:N,className:q("text-[11px] font-medium px-1.5 py-0.5 rounded-md transition-colors",w?"text-primary-900 bg-primary-200":"text-primary-500 hover:text-primary-700 hover:bg-primary-100"),children:w?"Done":"Select"})]}),h.jsx(An,{className:"w-full flex-1 min-h-0 h-auto data-starting-style:h-0 data-ending-style:h-0",contentClassName:"flex flex-1 min-h-0 flex-col overflow-y-auto",children:h.jsxs(ko,{className:"flex-1 min-h-0",children:[h.jsx(wo,{className:"min-h-0",children:h.jsxs("div",{className:"flex flex-col gap-2 pl-2 pr-2",children:[M.length>0?h.jsx("div",{className:"flex flex-col gap-px",children:M.map(_=>h.jsx(rr,{session:_,active:kn(_,n,r),isGenerating:ir(_,n,r,i),isPinned:!0,selectionMode:w,selected:S.has(_.key),onToggleSelect:A,onSelect:o,onTogglePin:D,onRename:a,onDelete:l,onExport:u},_.key))}):null,z?h.jsx("div",{className:"my-1 border-t border-primary-200/80"}):null,U.chat.length>0?h.jsxs("div",{className:"flex flex-col gap-px",children:[h.jsx("div",{className:q("border-l-2 border-primary-200/70 px-2 py-1 text-[11px] font-medium text-primary-500/80 text-balance"),children:"💬 Chats"}),h.jsx("div",{className:"flex flex-col gap-px",children:U.chat.map(_=>h.jsx(rr,{session:_,active:kn(_,n,r),isGenerating:ir(_,n,r,i),isPinned:!1,selectionMode:w,selected:S.has(_.key),onToggleSelect:A,onSelect:o,onTogglePin:D,onRename:a,onDelete:l,onExport:u},_.key))})]}):null,H("webchat","🦎 OpenCami",U.webchat),H("subagent","🤖 Sub-agents",U.subagent),H("cron","⏰ Cron / Isolated",U.cron),H("other","📁 Other",U.other)]})}),h.jsx(So,{orientation:"vertical",children:h.jsx(Co,{})})]})}),w?h.jsxs("div",{className:"shrink-0 border-t border-primary-200 bg-surface px-2 py-2 flex flex-col gap-1.5",children:[h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsxs("span",{className:"text-xs text-primary-600 font-medium",children:[E," selected"]}),h.jsx("button",{type:"button",onClick:P,className:"text-[11px] font-medium text-primary-600 hover:text-primary-800",children:"Select all"})]}),h.jsxs("div",{className:"flex gap-1.5",children:[h.jsxs("button",{type:"button",onClick:T,disabled:E===0,className:q("flex-1 inline-flex items-center justify-center gap-1.5 rounded-md px-2 py-1.5 text-xs font-medium transition-colors",E>0?"bg-red-100 text-red-700 hover:bg-red-200":"bg-primary-100 text-primary-400 cursor-not-allowed"),children:[h.jsx(te,{icon:Js,size:14,strokeWidth:1.5}),"Delete"]}),h.jsx("button",{type:"button",onClick:j,className:"flex-1 inline-flex items-center justify-center rounded-md px-2 py-1.5 text-xs font-medium bg-primary-100 text-primary-700 hover:bg-primary-200 transition-colors",children:"Cancel"})]})]}):null]})},Nc);function Nc(e,t){if(e.activeFriendlyId!==t.activeFriendlyId||e.activeSessionKey!==t.activeSessionKey||e.isStreaming!==t.isStreaming||e.defaultOpen!==t.defaultOpen||e.onSelect!==t.onSelect||e.onRename!==t.onRename||e.onDelete!==t.onDelete||e.onExport!==t.onExport)return!1;if(e.sessions===t.sessions)return!0;if(e.sessions.length!==t.sessions.length)return!1;for(let n=0;n<e.sessions.length;n+=1){const r=e.sessions[n],i=t.sessions[n];if(r.key!==i.key||r.friendlyId!==i.friendlyId||r.label!==i.label||r.title!==i.title||r.derivedTitle!==i.derivedTitle||r.updatedAt!==i.updatedAt||r.kind!==i.kind||r.status!==i.status||r.lastMessage!==i.lastMessage)return!1}return!0}function Lc(){const[e,t]=m.useState(!1),[n,r]=m.useState(!1),[i,s]=m.useState(null),[o,a]=m.useState(null),l=m.useCallback(async()=>{if(t(!0),s(null),!(n||o)){r(!0);try{const p=await fetch("/api/paths");if(!p.ok)throw new Error(await it(p));const g=await p.json();a({agentId:String(g.agentId??"main"),stateDir:String(g.stateDir??""),sessionsDir:String(g.sessionsDir??""),storePath:String(g.storePath??"")})}catch(p){s(p instanceof Error?p.message:String(p))}finally{r(!1)}}},[o,n]),u=m.useCallback(()=>{l()},[l]),c=m.useCallback(()=>{t(!1)},[]),f=m.useCallback(()=>{if(o?.sessionsDir)try{navigator.clipboard.writeText(o.sessionsDir)}catch{}},[o]),d=m.useCallback(()=>{if(o?.storePath)try{navigator.clipboard.writeText(o.storePath)}catch{}},[o]);return{settingsOpen:e,setSettingsOpen:t,pathsLoading:n,pathsError:i,paths:o,handleOpenSettings:u,closeSettings:c,copySessionsDir:f,copyStorePath:d}}let He=null,Jr=!1,wn=null;function Mc(e){He=e}function sr(){return He!==null}function Vt(e){Jr=e}function or(){return Jr}function Nn(){He=null,Jr=!1}function Dc(e,t){if(He){if(e&&He.sessionKey===e){Nn();return}t&&He.friendlyId===t&&Nn()}}function zc(e){wn={friendlyId:e,at:Date.now()}}function To(e,t=15e3){return!(!wn||wn.friendlyId!==e||Date.now()-wn.at>t)}function Pc(e,t){if(!He)return null;if(e&&He.sessionKey===e){const n=He;return He=null,n}if(t&&He.friendlyId===t){const n=He;return He=null,n}return null}const _c=8e3,Et=new Map;function Oc(e){e&&Et.set(e,{id:e,expiresAt:Date.now()+_c})}function Fc(e){e&&Et.delete(e)}function $c(e){if(Et.size===0)return e;const t=Date.now();let n=!1;const r=e.filter(i=>{const s=Et.get(i.key),o=Et.get(i.friendlyId);return s&&s.expiresAt<=t||o&&o.expiresAt<=t?(s&&s.expiresAt<=t&&Et.delete(i.key),o&&o.expiresAt<=t&&Et.delete(i.friendlyId),!0):s||o?(n=!0,!1):!0});return n?r:e}function Bc(){const e=qt(),[t,n]=m.useState(!1),[r,i]=m.useState(null),s=lo({mutationFn:async function(l){const u=new URLSearchParams;l.sessionKey&&u.set("sessionKey",l.sessionKey),l.friendlyId&&u.set("friendlyId",l.friendlyId);const c=await fetch(`/api/sessions?${u.toString()}`,{method:"DELETE"});if(!c.ok)throw new Error(await it(c));return l},onMutate:async function(l){i(null),Oc(l.sessionKey||l.friendlyId),Dc(l.sessionKey,l.friendlyId),await e.cancelQueries({queryKey:be.sessions});const u=e.getQueryData(be.sessions);return Cu(e,l.sessionKey,l.friendlyId),l.isActive&&(l.sessionKey||l.friendlyId)&&Rr(e,l.friendlyId||l.sessionKey,l.sessionKey||l.friendlyId),{previousSessions:u,isActive:l.isActive}},onError:function(l,u,c){c?.previousSessions&&e.setQueryData(be.sessions,c.previousSessions),Fc(u.sessionKey||u.friendlyId),i(l instanceof Error?l.message:String(l))},onSuccess:function(l){l.isActive&&Nn(),e.invalidateQueries({queryKey:be.sessions})},onSettled:function(){n(!1)}});return{deleteSession:m.useCallback(async(a,l,u)=>{!a&&!l||(n(!0),await s.mutateAsync({sessionKey:a,friendlyId:l,isActive:u}))},[s]),deleting:t,error:r}}function Hc(){const e=qt(),[t,n]=m.useState(!1),[r,i]=m.useState(null),s=lo({mutationFn:async function(l){const u=await fetch("/api/sessions",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({sessionKey:l.sessionKey,label:l.newTitle})});if(!u.ok)throw new Error(await it(u));return l},onMutate:async function(l){i(null),await e.cancelQueries({queryKey:be.sessions});const u=e.getQueryData(be.sessions);return e.setQueryData(be.sessions,function(f){return Array.isArray(f)?f.map(d=>d.key!==l.sessionKey?d:{...d,label:l.newTitle,title:l.newTitle}):f}),{previousSessions:u}},onError:function(l,u,c){c?.previousSessions&&e.setQueryData(be.sessions,c.previousSessions),i(l instanceof Error?l.message:String(l))},onSuccess:function(){e.invalidateQueries({queryKey:be.sessions})},onSettled:function(){n(!1)}});return{renameSession:m.useCallback(async(a,l)=>{!a||!l.trim()||(n(!0),await s.mutateAsync({sessionKey:a,newTitle:l.trim()}))},[s]),renaming:t,error:r}}const Uc=m.lazy(()=>Fn(()=>import("./settings-dialog-UvgVi2It.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8])).then(e=>({default:e.SettingsDialog}))),qc=m.lazy(()=>Fn(()=>import("./session-export-dialog-BFizBmGb.js"),__vite__mapDeps([9,1,3,2,4,5])).then(e=>({default:e.SessionExportDialog})));function Kc({sessions:e,activeFriendlyId:t,activeSessionKey:n,isStreaming:r=!1,creatingSession:i,onCreateSession:s,isCollapsed:o,onToggleCollapse:a,onSelectSession:l,onActiveSessionDelete:u,onOpenSearch:c}){const{settingsOpen:f,setSettingsOpen:d,pathsLoading:p,pathsError:g,paths:y,handleOpenSettings:w,closeSettings:k,copySessionsDir:S,copyStorePath:v}=Lc(),{deleteSession:R}=Bc(),{renameSession:M}=Hc(),C={duration:.15,ease:o?"easeIn":"easeOut"},[z,U]=m.useState(!1),[F,E]=m.useState(null),[N,A]=m.useState(""),[P,j]=m.useState(!1),[T,D]=m.useState(null),[L,H]=m.useState(null),[_,x]=m.useState(""),[V,X]=m.useState(!1),[b,Q]=m.useState(null),[re,K]=m.useState(null),[he,me]=m.useState(""),ue=qt();function se($){E($.key),A($.label||$.title||$.derivedTitle||""),U(!0)}function ge($){F&&M(F,$),U(!1),E(null)}function ke($){D($.key),H($.friendlyId),x($.label||$.title||$.derivedTitle||$.friendlyId),j(!0)}function we(){if(T&&L){const $=L===t;$&&u&&u(),R(T,L,$)}j(!1),D(null),H(null)}function Se($){Q($.key),K($.friendlyId),me($.label||$.title||$.derivedTitle||$.friendlyId),X(!0)}function Le($){if(b&&re){const J=be.history(re,b),xe=ue.getQueryData(J);xe?.messages&&Au(he,xe.messages,$)}X(!1),Q(null),K(null)}const W={className:"border-r border-primary-200 h-full overflow-hidden bg-primary-100 flex flex-col"};return h.jsxs(Ve.aside,{initial:!1,animate:{width:o?48:300},transition:C,className:W.className,children:[h.jsxs(Ve.div,{layout:!0,transition:{layout:C},className:q("flex items-center h-12 px-2 justify-between"),children:[h.jsx(Ct,{initial:!1,children:o?null:h.jsx(Ve.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:C,children:h.jsxs(tn,{to:"/new",className:q(Zn({variant:"ghost",size:"sm"}),"w-full pl-1.5 justify-start"),children:[h.jsx(Zl,{className:"size-5"}),h.jsx(eu,{})]})})}),h.jsx(jt,{children:h.jsxs(At,{children:[h.jsx(It,{onClick:a,render:h.jsx(ve,{size:"icon-sm",variant:"ghost",children:h.jsx(te,{icon:Il,size:20,strokeWidth:1.5})})}),h.jsx(Rt,{side:"right",children:o?"Open Sidebar":"Close Sidebar"})]})})]}),h.jsxs("div",{className:"px-2 mb-4 flex flex-col gap-1",children:[h.jsxs(Ve.div,{layout:!0,transition:{layout:C},className:"w-full space-y-2",children:[h.jsxs(ve,{disabled:i,variant:"ghost",size:"sm",onClick:s,onMouseUp:l,className:"w-full pl-1.5 justify-start",children:[h.jsx(te,{icon:Rl,size:20,strokeWidth:1.5,className:"min-w-5"}),h.jsx(Ct,{initial:!1,mode:"wait",children:!o&&h.jsx(Ve.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:C,className:"overflow-hidden whitespace-nowrap",children:"New Session"})})]}),h.jsx(jt,{children:h.jsxs(At,{children:[h.jsx(It,{asChild:!0,children:h.jsxs(tn,{to:"/files",className:q(Zn({variant:"ghost",size:"sm"}),"w-full pl-1.5 justify-start"),onClick:l,children:[h.jsx(te,{icon:Nl,size:20,strokeWidth:1.5,className:"min-w-5"}),h.jsx(Ct,{initial:!1,mode:"wait",children:!o&&h.jsx(Ve.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:C,className:"overflow-hidden whitespace-nowrap",children:"Files"})})]})}),o&&h.jsx(Rt,{side:"right",children:"Files"})]})}),(()=>{try{return localStorage.getItem("opencami-agent-manager")==="true"}catch{return!1}})()&&h.jsx(jt,{children:h.jsxs(At,{children:[h.jsx(It,{asChild:!0,children:h.jsxs(tn,{to:"/agents",className:q(Zn({variant:"ghost",size:"sm"}),"w-full pl-1.5 justify-start"),onClick:l,children:[h.jsx(te,{icon:Zs,size:20,strokeWidth:1.5,className:"min-w-5"}),h.jsx(Ct,{initial:!1,mode:"wait",children:!o&&h.jsx(Ve.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:C,className:"overflow-hidden whitespace-nowrap",children:"Agents"})})]})}),o&&h.jsx(Rt,{side:"right",children:"Agents"})]})})]}),h.jsx(Ve.div,{layout:!0,transition:{layout:C},className:"w-full",children:h.jsxs(ve,{variant:"ghost",size:"sm",onClick:c,className:"w-full pl-1.5 justify-start",children:[h.jsx(te,{icon:eo,size:20,strokeWidth:1.5,className:"min-w-5"}),h.jsx(Ct,{initial:!1,mode:"wait",children:!o&&h.jsx(Ve.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:C,className:"overflow-hidden whitespace-nowrap",children:"Search"})})]})})]}),h.jsx("div",{className:"flex-1 min-h-0 overflow-hidden",children:h.jsx(Ct,{initial:!1,children:!o&&h.jsx(Ve.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:C,className:"pt-0 flex flex-col w-full min-h-0 h-full",children:h.jsx("div",{className:"flex-1 min-h-0",children:h.jsx(Rc,{sessions:e,activeFriendlyId:t,activeSessionKey:n,isStreaming:r,onSelect:l,onRename:se,onDelete:ke,onExport:Se})})},"content")})}),h.jsx("div",{className:"px-2 py-3 border-t border-primary-200 bg-primary-100",children:h.jsx(Ve.div,{layout:!0,transition:{layout:C},className:"w-full",children:h.jsxs(ve,{variant:"ghost",size:"sm",onClick:w,title:o?"Settings":void 0,className:"w-full justify-start pl-1.5",children:[h.jsx(te,{icon:Ll,size:20,strokeWidth:1.5,className:"min-w-5"}),h.jsx(Ct,{initial:!1,mode:"wait",children:!o&&h.jsx(Ve.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:C,className:"overflow-hidden whitespace-nowrap",children:"Settings"})})]})})}),f&&h.jsx(m.Suspense,{fallback:null,children:h.jsx(Uc,{open:f,onOpenChange:d,pathsLoading:p,pathsError:g,paths:y,onClose:k,onCopySessionsDir:S,onCopyStorePath:v})}),h.jsx(Ru,{open:z,onOpenChange:U,sessionTitle:N,onSave:ge,onCancel:()=>U(!1)}),h.jsx(Ou,{open:P,onOpenChange:j,sessionTitle:_,onConfirm:we,onCancel:()=>j(!1)}),V&&h.jsx(m.Suspense,{fallback:null,children:h.jsx(qc,{open:V,onOpenChange:X,sessionTitle:he,onExport:Le,onCancel:()=>X(!1)})})]})}function Wc(e,t){if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1){const r=e[n],i=t[n];if(r.key!==i.key||r.friendlyId!==i.friendlyId||r.label!==i.label||r.title!==i.title||r.derivedTitle!==i.derivedTitle||r.updatedAt!==i.updatedAt||r.kind!==i.kind||r.status!==i.status||r.lastMessage!==i.lastMessage)return!1}return!0}function Vc(e,t){return!(e.activeFriendlyId!==t.activeFriendlyId||e.activeSessionKey!==t.activeSessionKey||e.isStreaming!==t.isStreaming||e.creatingSession!==t.creatingSession||e.isCollapsed!==t.isCollapsed||!Wc(e.sessions,t.sessions))}const Xc=m.memo(Kc,Vc);function $i(e){if(e<=0)return"0";if(e>=1e6){const t=e/1e6,n=t.toFixed(1);return n.endsWith(".0")?`${Math.round(t)}M`:`${n}M`}if(e>=1e5)return`${Math.round(e/1e3)}K`;if(e>=1e4)return`${Math.round(e/1e3)}K`;if(e>=1e3){const t=e/1e3,n=t.toFixed(1);return n.endsWith(".0")?`${Math.round(t)}K`:`${n}K`}return String(Math.round(e))}function Bi(e){return e>=90?{bar:"bg-red-500",text:"text-red-600 dark:text-red-400"}:e>=70?{bar:"bg-yellow-500",text:"text-yellow-600 dark:text-yellow-400"}:{bar:"bg-emerald-500",text:"text-emerald-600 dark:text-emerald-400"}}function Yc({totalTokens:e,contextTokens:t,className:n}){const{percentage:r,usedStr:i,maxStr:s,colors:o,hasData:a,isNearlyFull:l}=m.useMemo(()=>{if(typeof t!="number"||t<=0)return{percentage:0,usedStr:"",maxStr:"",colors:Bi(0),hasData:!1,isNearlyFull:!1};const f=typeof e=="number"&&e>0?e:0,d=Math.min(100,Math.round(f/t*100));return{percentage:d,usedStr:$i(f),maxStr:$i(t),colors:Bi(d),hasData:!0,isNearlyFull:d>=95}},[e,t]);if(!a)return null;const u=typeof e=="number"&&e>0?e.toLocaleString():"0",c=typeof t=="number"?t.toLocaleString():"0";return h.jsxs("div",{className:q("group relative flex items-center gap-1.5",n),title:`Context: ${u} / ${c} tokens (${r}%)`,children:[h.jsxs("div",{className:"flex items-center gap-1.5",children:[h.jsx("div",{className:"w-12 h-1.5 rounded-full bg-primary-200 dark:bg-primary-700 overflow-hidden shrink-0 group-hover:h-2 transition-all",children:h.jsx("div",{className:q("h-full rounded-full transition-all duration-500 ease-out",o.bar,l&&"animate-pulse"),style:{width:`${r}%`}})}),h.jsx("span",{className:q("text-[10px] leading-none font-medium tabular-nums whitespace-nowrap",l?o.text:"text-primary-500 dark:text-primary-400"),children:i})]}),h.jsx("div",{className:q("absolute right-0 top-full mt-1 z-50","pointer-events-none opacity-0 scale-95","group-hover:pointer-events-auto group-hover:opacity-100 group-hover:scale-100","transition-all duration-150 origin-top-right"),children:h.jsxs("div",{className:q("rounded-md border border-primary-200 dark:border-primary-700","bg-surface shadow-lg px-3 py-2","text-xs whitespace-nowrap"),children:[h.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[h.jsx("span",{className:"text-primary-500 dark:text-primary-400",children:"Context window"}),h.jsxs("span",{className:q("font-semibold",o.text),children:[r,"%"]})]}),h.jsxs("div",{className:"flex items-center gap-1.5 text-primary-700 dark:text-primary-300",children:[h.jsx("span",{className:"font-medium",children:i}),h.jsx("span",{className:"text-primary-400",children:"/"}),h.jsx("span",{children:s}),h.jsx("span",{className:"text-primary-400",children:"tokens"})]}),h.jsx("div",{className:"w-full h-1.5 rounded-full bg-primary-200 dark:bg-primary-700 overflow-hidden mt-1.5",children:h.jsx("div",{className:q("h-full rounded-full transition-all duration-500 ease-out",o.bar),style:{width:`${r}%`}})}),l&&h.jsx("div",{className:"mt-1.5 text-[10px] text-red-500 dark:text-red-400 font-medium",children:"⚠ Context nearly full — consider /compact"})]})})]})}const Gc=m.memo(Yc);function Qc({activeTitle:e,wrapperRef:t,showSidebarButton:n=!1,onOpenSidebar:r,totalTokens:i,contextTokens:s}){return h.jsxs("div",{ref:t,className:"border-b border-primary-200 px-4 h-12 flex items-center bg-surface",children:[n?h.jsx(ve,{size:"icon-sm",variant:"ghost",onClick:r,className:"mr-2 text-primary-800 hover:bg-primary-100","aria-label":"Open sidebar",children:h.jsx(te,{icon:Ml,size:18,strokeWidth:1.6})}):null,h.jsx("div",{className:"text-sm font-medium truncate flex-1 min-w-0",children:e}),h.jsx(Gc,{totalTokens:i,contextTokens:s,className:"ml-3 hidden sm:flex"})]})}const Jc=m.memo(Qc);function Zc(e,t){return e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}function ef(e){const t=new Date(e);return Zc(t,new Date)?new Intl.DateTimeFormat("en-GB",{hour:"2-digit",minute:"2-digit"}).format(t):new Intl.DateTimeFormat("en-GB",{day:"2-digit",month:"short"}).format(t)}function tf(e){return new Intl.DateTimeFormat("en-GB",{day:"2-digit",month:"short",year:"numeric",hour:"2-digit",minute:"2-digit",second:"2-digit"}).format(new Date(e))}function nf({timestamp:e}){const t=ef(e),n=tf(e);return h.jsx(jt,{children:h.jsxs(At,{children:[h.jsx(It,{className:"inline-flex items-center text-xs text-primary-600",children:t}),h.jsx(Rt,{side:"top",children:n})]})})}function rf({text:e,align:t,timestamp:n,forceVisible:r=!1}){const[i,s]=m.useState(!1),[o,a]=m.useState("idle"),l=m.useRef(null),u=m.useRef(null),c=m.useRef(null),[f,d]=m.useState(()=>{if(typeof window>"u")return!0;try{const k=localStorage.getItem("opencami-tts-enabled");return k===null?!0:k==="true"}catch{return!0}});m.useEffect(()=>{function k(S){S.key==="opencami-tts-enabled"&&d(S.newValue===null?!0:S.newValue==="true")}return window.addEventListener("storage",k),()=>window.removeEventListener("storage",k)},[]),m.useEffect(()=>()=>{c.current?.abort(),l.current&&(l.current.pause(),l.current=null),u.current&&(URL.revokeObjectURL(u.current),u.current=null)},[]);const p=async()=>{try{await navigator.clipboard.writeText(e),s(!0),window.setTimeout(()=>s(!1),1400)}catch{s(!1)}},g=async()=>{if(o==="playing"){c.current?.abort(),l.current&&(l.current.pause(),l.current=null),u.current&&(URL.revokeObjectURL(u.current),u.current=null),a("idle");return}c.current?.abort();const k=new AbortController;c.current=k,a("loading");try{const S=await fetch("/api/tts",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:e}),signal:k.signal});if(!S.ok)throw new Error("TTS failed");const v=await S.blob(),R=URL.createObjectURL(v);u.current=R;const M=new Audio(R);l.current=M,M.onended=()=>{a("idle"),u.current&&(URL.revokeObjectURL(u.current),u.current=null),l.current=null},M.onerror=()=>{a("idle"),u.current&&(URL.revokeObjectURL(u.current),u.current=null),l.current=null},await M.play(),a("playing")}catch(S){if(S instanceof Error&&S.name==="AbortError"){a("idle");return}a("idle"),u.current&&(URL.revokeObjectURL(u.current),u.current=null),l.current=null}},y=t==="end"?"justify-end":"justify-start",w=t==="start"&&f&&e.trim().length>0;return h.jsxs("div",{className:q("flex items-center gap-2 text-xs text-primary-600 transition-opacity group-hover:opacity-100 group-focus-within:opacity-100 duration-100 ease-out",r?"opacity-100":"opacity-0",y),children:[h.jsx(jt,{children:h.jsxs(At,{children:[h.jsx(It,{type:"button",onClick:()=>{p().catch(()=>{})},className:"inline-flex items-center justify-center rounded border border-transparent bg-transparent p-1 text-primary-700 hover:text-primary-900 hover:bg-primary-100",children:h.jsx(te,{icon:i?Vr:Dl,size:16,strokeWidth:1.6})}),h.jsx(Rt,{side:"top",children:"Copy"})]})}),w&&h.jsx(jt,{children:h.jsxs(At,{children:[h.jsx(It,{type:"button",onClick:()=>{g().catch(()=>{})},disabled:o==="loading",className:q("inline-flex items-center justify-center rounded border border-transparent bg-transparent p-1 text-primary-700 hover:text-primary-900 hover:bg-primary-100",o==="loading"&&"opacity-60 cursor-wait"),children:h.jsx(te,{icon:o==="loading"?zl:o==="playing"?to:Pl,size:16,strokeWidth:1.6,className:q(o==="loading"&&"animate-spin")})}),h.jsx(Rt,{side:"top",children:o==="loading"?"Generating speech…":o==="playing"?"Stop":"Listen"})]})}),h.jsx(nf,{timestamp:n})]})}function Zr(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var Dt=Zr();function jo(e){Dt=e}var rn={exec:()=>null};function le(e,t=""){let n=typeof e=="string"?e:e.source,r={replace:(i,s)=>{let o=typeof s=="string"?s:s.source;return o=o.replace(De.caret,"$1"),n=n.replace(i,o),r},getRegex:()=>new RegExp(n,t)};return r}var sf=(()=>{try{return!!new RegExp("(?<=1)(?<!1)")}catch{return!1}})(),De={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,listReplaceTabs:/^\t+/,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,unescapeTest:/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig,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:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),hrRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}#`),htmlBeginRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}<(?:[a-z].*>|!--)`,"i")},of=/^(?:[ \t]*(?:\n|$))+/,af=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,lf=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,cn=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,uf=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,ei=/(?:[*+-]|\d{1,9}[.)])/,Ao=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,Io=le(Ao).replace(/bull/g,ei).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(),cf=le(Ao).replace(/bull/g,ei).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(),ti=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,ff=/^[^\n]+/,ni=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,hf=le(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",ni).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),pf=le(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,ei).getRegex(),Kn="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",ri=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,df=le("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\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",ri).replace("tag",Kn).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),Ro=le(ti).replace("hr",cn).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"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",Kn).getRegex(),mf=le(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",Ro).getRegex(),ii={blockquote:mf,code:af,def:hf,fences:lf,heading:uf,hr:cn,html:df,lheading:Io,list:pf,newline:of,paragraph:Ro,table:rn,text:ff},Hi=le("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",cn).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[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",Kn).getRegex(),gf={...ii,lheading:cf,table:Hi,paragraph:le(ti).replace("hr",cn).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",Hi).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",Kn).getRegex()},xf={...ii,html:le(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",ri).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:rn,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:le(ti).replace("hr",cn).replace("heading",` *#{1,6} *[^
|
|
6
|
+
]`).replace("lheading",Io).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},yf=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,bf=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,No=/^( {2,}|\\)\n(?!\s*$)/,kf=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,Wn=/[\p{P}\p{S}]/u,si=/[\s\p{P}\p{S}]/u,Lo=/[^\s\p{P}\p{S}]/u,wf=le(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,si).getRegex(),Mo=/(?!~)[\p{P}\p{S}]/u,Sf=/(?!~)[\s\p{P}\p{S}]/u,Cf=/(?:[^\s\p{P}\p{S}]|~)/u,vf=le(/link|precode-code|html/,"g").replace("link",/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-",sf?"(?<!`)()":"(^^|[^`])").replace("code",/(?<b>`+)[^`]+\k<b>(?!`)/).replace("html",/<(?! )[^<>]*?>/).getRegex(),Do=/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/,Ef=le(Do,"u").replace(/punct/g,Wn).getRegex(),Tf=le(Do,"u").replace(/punct/g,Mo).getRegex(),zo="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",jf=le(zo,"gu").replace(/notPunctSpace/g,Lo).replace(/punctSpace/g,si).replace(/punct/g,Wn).getRegex(),Af=le(zo,"gu").replace(/notPunctSpace/g,Cf).replace(/punctSpace/g,Sf).replace(/punct/g,Mo).getRegex(),If=le("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,Lo).replace(/punctSpace/g,si).replace(/punct/g,Wn).getRegex(),Rf=le(/\\(punct)/,"gu").replace(/punct/g,Wn).getRegex(),Nf=le(/^<(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(),Lf=le(ri).replace("(?:-->|$)","-->").getRegex(),Mf=le("^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",Lf).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),Ln=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+[^`]*?`+(?!`)|[^\[\]\\`])*?/,Df=le(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]*(?:\n[ \t]*)?)(title))?\s*\)/).replace("label",Ln).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),Po=le(/^!?\[(label)\]\[(ref)\]/).replace("label",Ln).replace("ref",ni).getRegex(),_o=le(/^!?\[(ref)\](?:\[\])?/).replace("ref",ni).getRegex(),zf=le("reflink|nolink(?!\\()","g").replace("reflink",Po).replace("nolink",_o).getRegex(),Ui=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,oi={_backpedal:rn,anyPunctuation:Rf,autolink:Nf,blockSkip:vf,br:No,code:bf,del:rn,emStrongLDelim:Ef,emStrongRDelimAst:jf,emStrongRDelimUnd:If,escape:yf,link:Df,nolink:_o,punctuation:wf,reflink:Po,reflinkSearch:zf,tag:Mf,text:kf,url:rn},Pf={...oi,link:le(/^!?\[(label)\]\((.*?)\)/).replace("label",Ln).getRegex(),reflink:le(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",Ln).getRegex()},Nr={...oi,emStrongRDelimAst:Af,emStrongLDelim:Tf,url:le(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("protocol",Ui).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:le(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace("protocol",Ui).getRegex()},_f={...Nr,br:le(No).replace("{2,}","*").getRegex(),text:le(Nr.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},mn={normal:ii,gfm:gf,pedantic:xf},Xt={normal:oi,gfm:Nr,breaks:_f,pedantic:Pf},Of={"&":"&","<":"<",">":">",'"':""","'":"'"},qi=e=>Of[e];function at(e,t){if(t){if(De.escapeTest.test(e))return e.replace(De.escapeReplace,qi)}else if(De.escapeTestNoEncode.test(e))return e.replace(De.escapeReplaceNoEncode,qi);return e}function Ki(e){try{e=encodeURI(e).replace(De.percentDecode,"%")}catch{return null}return e}function Wi(e,t){let n=e.replace(De.findPipe,(s,o,a)=>{let l=!1,u=o;for(;--u>=0&&a[u]==="\\";)l=!l;return l?"|":" |"}),r=n.split(De.splitPipe),i=0;if(r[0].trim()||r.shift(),r.length>0&&!r.at(-1)?.trim()&&r.pop(),t)if(r.length>t)r.splice(t);else for(;r.length<t;)r.push("");for(;i<r.length;i++)r[i]=r[i].trim().replace(De.slashPipe,"|");return r}function Yt(e,t,n){let r=e.length;if(r===0)return"";let i=0;for(;i<r&&e.charAt(r-i-1)===t;)i++;return e.slice(0,r-i)}function Ff(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 Vi(e,t,n,r,i){let s=t.href,o=t.title||null,a=e[1].replace(i.other.outputLinkReplace,"$1");r.state.inLink=!0;let l={type:e[0].charAt(0)==="!"?"image":"link",raw:n,href:s,title:o,text:a,tokens:r.inlineTokens(a)};return r.state.inLink=!1,l}function $f(e,t,n){let r=e.match(n.other.indentCodeCompensation);if(r===null)return t;let i=r[1];return t.split(`
|
|
7
7
|
`).map(s=>{let o=s.match(n.other.beginningSpace);if(o===null)return s;let[a]=o;return a.length>=i.length?s.slice(i.length):s}).join(`
|
|
8
8
|
`)}var Mn=class{options;rules;lexer;constructor(e){this.options=e||Dt}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=t[0].replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:t[0],codeBlockStyle:"indented",text:this.options.pedantic?n:Yt(n,`
|
|
9
9
|
`)}}}fences(e){let t=this.rules.block.fences.exec(e);if(t){let n=t[0],r=$f(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=Yt(n,"#");(this.options.pedantic||!r||this.rules.other.endingSpaceChar.test(r))&&(n=r.trim())}return{type:"heading",raw:t[0],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:Yt(t[0],`
|
|
@@ -15,19 +15,19 @@ import{j as h,r as m,L as tn,u as qt,_ as Fn,g as Ks,a as al,b as ll,c as Ws,d a
|
|
|
15
15
|
${u}`:u,i=i?`${i}
|
|
16
16
|
${c}`:c;let f=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(c,s,!0),this.lexer.state.top=f,n.length===0)break;let d=s.at(-1);if(d?.type==="code")break;if(d?.type==="blockquote"){let p=d,g=p.raw+`
|
|
17
17
|
`+n.join(`
|
|
18
|
-
`),
|
|
18
|
+
`),y=this.blockquote(g);s[s.length-1]=y,r=r.substring(0,r.length-p.raw.length)+y.raw,i=i.substring(0,i.length-p.text.length)+y.text;break}else if(d?.type==="list"){let p=d,g=p.raw+`
|
|
19
19
|
`+n.join(`
|
|
20
|
-
`),
|
|
20
|
+
`),y=this.list(g);s[s.length-1]=y,r=r.substring(0,r.length-d.raw.length)+y.raw,i=i.substring(0,i.length-p.raw.length)+y.raw,n=g.substring(s.at(-1).raw.length).split(`
|
|
21
21
|
`);continue}}return{type:"blockquote",raw:r,tokens:s,text:i}}}list(e){let t=this.rules.block.list.exec(e);if(t){let n=t[1].trim(),r=n.length>1,i={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 s=this.rules.other.listItemRegex(n),o=!1;for(;e;){let l=!1,u="",c="";if(!(t=s.exec(e))||this.rules.block.hr.test(e))break;u=t[0],e=e.substring(u.length);let f=t[2].split(`
|
|
22
|
-
`,1)[0].replace(this.rules.other.listReplaceTabs,
|
|
22
|
+
`,1)[0].replace(this.rules.other.listReplaceTabs,y=>" ".repeat(3*y.length)),d=e.split(`
|
|
23
23
|
`,1)[0],p=!f.trim(),g=0;if(this.options.pedantic?(g=2,c=f.trimStart()):p?g=t[1].length+1:(g=t[2].search(this.rules.other.nonSpaceChar),g=g>4?1:g,c=f.slice(g),g+=t[1].length),p&&this.rules.other.blankLine.test(d)&&(u+=d+`
|
|
24
|
-
`,e=e.substring(d.length+1),l=!0),!l){let
|
|
25
|
-
`,1)[0],
|
|
26
|
-
`+
|
|
27
|
-
`+d}!p&&!d.trim()&&(p=!0),u+=
|
|
28
|
-
`,e=e.substring(
|
|
24
|
+
`,e=e.substring(d.length+1),l=!0),!l){let y=this.rules.other.nextBulletRegex(g),w=this.rules.other.hrRegex(g),k=this.rules.other.fencesBeginRegex(g),S=this.rules.other.headingBeginRegex(g),v=this.rules.other.htmlBeginRegex(g);for(;e;){let R=e.split(`
|
|
25
|
+
`,1)[0],M;if(d=R,this.options.pedantic?(d=d.replace(this.rules.other.listReplaceNesting," "),M=d):M=d.replace(this.rules.other.tabCharGlobal," "),k.test(d)||S.test(d)||v.test(d)||y.test(d)||w.test(d))break;if(M.search(this.rules.other.nonSpaceChar)>=g||!d.trim())c+=`
|
|
26
|
+
`+M.slice(g);else{if(p||f.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||k.test(f)||S.test(f)||w.test(f))break;c+=`
|
|
27
|
+
`+d}!p&&!d.trim()&&(p=!0),u+=R+`
|
|
28
|
+
`,e=e.substring(R.length+1),f=M.slice(g)}}i.loose||(o?i.loose=!0:this.rules.other.doubleBlankLine.test(u)&&(o=!0)),i.items.push({type:"list_item",raw:u,task:!!this.options.gfm&&this.rules.other.listIsTask.test(c),loose:!1,text:c,tokens:[]}),i.raw+=u}let a=i.items.at(-1);if(a)a.raw=a.raw.trimEnd(),a.text=a.text.trimEnd();else return;i.raw=i.raw.trimEnd();for(let l of i.items){if(this.lexer.state.top=!1,l.tokens=this.lexer.blockTokens(l.text,[]),l.task){if(l.text=l.text.replace(this.rules.other.listReplaceTask,""),l.tokens[0]?.type==="text"||l.tokens[0]?.type==="paragraph"){l.tokens[0].raw=l.tokens[0].raw.replace(this.rules.other.listReplaceTask,""),l.tokens[0].text=l.tokens[0].text.replace(this.rules.other.listReplaceTask,"");for(let c=this.lexer.inlineQueue.length-1;c>=0;c--)if(this.rules.other.listIsTask.test(this.lexer.inlineQueue[c].src)){this.lexer.inlineQueue[c].src=this.lexer.inlineQueue[c].src.replace(this.rules.other.listReplaceTask,"");break}}let u=this.rules.other.listTaskCheckbox.exec(l.raw);if(u){let c={type:"checkbox",raw:u[0]+" ",checked:u[0]!=="[ ]"};l.checked=c.checked,i.loose?l.tokens[0]&&["paragraph","text"].includes(l.tokens[0].type)&&"tokens"in l.tokens[0]&&l.tokens[0].tokens?(l.tokens[0].raw=c.raw+l.tokens[0].raw,l.tokens[0].text=c.raw+l.tokens[0].text,l.tokens[0].tokens.unshift(c)):l.tokens.unshift({type:"paragraph",raw:c.raw,text:c.raw,tokens:[c]}):l.tokens.unshift(c)}}if(!i.loose){let u=l.tokens.filter(f=>f.type==="space"),c=u.length>0&&u.some(f=>this.rules.other.anyLine.test(f.raw));i.loose=c}}if(i.loose)for(let l of i.items){l.loose=!0;for(let u of l.tokens)u.type==="text"&&(u.type="paragraph")}return i}}html(e){let t=this.rules.block.html.exec(e);if(t)return{type:"html",block:!0,raw:t[0],pre:t[1]==="pre"||t[1]==="script"||t[1]==="style",text:t[0]}}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"):"",i=t[3]?t[3].substring(1,t[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):t[3];return{type:"def",tag:n,raw:t[0],href:r,title:i}}}table(e){let t=this.rules.block.table.exec(e);if(!t||!this.rules.other.tableDelimiter.test(t[2]))return;let n=Wi(t[1]),r=t[2].replace(this.rules.other.tableAlignChars,"").split("|"),i=t[3]?.trim()?t[3].replace(this.rules.other.tableRowBlankLine,"").split(`
|
|
29
29
|
`):[],s={type:"table",raw:t[0],header:[],align:[],rows:[]};if(n.length===r.length){for(let o of r)this.rules.other.tableAlignRight.test(o)?s.align.push("right"):this.rules.other.tableAlignCenter.test(o)?s.align.push("center"):this.rules.other.tableAlignLeft.test(o)?s.align.push("left"):s.align.push(null);for(let o=0;o<n.length;o++)s.header.push({text:n[o],tokens:this.lexer.inline(n[o]),header:!0,align:s.align[o]});for(let o of i)s.rows.push(Wi(o,s.header.length).map((a,l)=>({text:a,tokens:this.lexer.inline(a),header:!1,align:s.align[l]})));return s}}lheading(e){let t=this.rules.block.lheading.exec(e);if(t)return{type:"heading",raw:t[0],depth:t[2].charAt(0)==="="?1:2,text:t[1],tokens:this.lexer.inline(t[1])}}paragraph(e){let t=this.rules.block.paragraph.exec(e);if(t){let n=t[1].charAt(t[1].length-1)===`
|
|
30
|
-
`?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 s=Yt(n.slice(0,-1),"\\");if((n.length-s.length)%2===0)return}else{let s=Ff(t[2],"()");if(s===-2)return;if(s>-1){let o=(t[0].indexOf("!")===0?5:4)+t[1].length+s;t[2]=t[2].substring(0,s),t[0]=t[0].substring(0,o).trim(),t[3]=""}}let r=t[2],i="";if(this.options.pedantic){let s=this.rules.other.pedanticHrefTitle.exec(r);s&&(r=s[1],i=s[3])}else i=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)),Vi(t,{href:r&&r.replace(this.rules.inline.anyPunctuation,"$1"),title:i&&i.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," "),i=t[r.toLowerCase()];if(!i){let s=n[0].charAt(0);return{type:"text",raw:s,text:s}}return Vi(n,i,n[0],this.lexer,this.rules)}}emStrong(e,t,n=""){let r=this.rules.inline.emStrongLDelim.exec(e);if(!(!r||r[3]&&n.match(this.rules.other.unicodeAlphaNumeric))&&(!(r[1]||r[2])||!n||this.rules.inline.punctuation.exec(n))){let i=[...r[0]].length-1,s,o,a=i,l=0,u=r[0][0]==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(u.lastIndex=0,t=t.slice(-1*e.length+i);(r=u.exec(t))!=null;){if(s=r[1]||r[2]||r[3]||r[4]||r[5]||r[6],!s)continue;if(o=[...s].length,r[3]||r[4]){a+=o;continue}else if((r[5]||r[6])&&i%3&&!((i+o)%3)){l+=o;continue}if(a-=o,a>0)continue;o=Math.min(o,o+a+l);let c=[...r[0]][0].length,f=e.slice(0,i+r.index+c+o);if(Math.min(i,o)%2){let p=f.slice(1,-1);return{type:"em",raw:f,text:p,tokens:this.lexer.inlineTokens(p)}}let d=f.slice(2,-2);return{type:"strong",raw:f,text:d,tokens:this.lexer.inlineTokens(d)}}}}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),i=this.rules.other.startingSpaceChar.test(n)&&this.rules.other.endingSpaceChar.test(n);return r&&i&&(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){let t=this.rules.inline.del.exec(e);if(t)return{type:"del",raw:t[0],text:t[2],tokens:this.lexer.inlineTokens(t[2])}}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){let t;if(t=this.rules.inline.url.exec(e)){let n,r;if(t[2]==="@")n=t[0],r="mailto:"+n;else{let i;do i=t[0],t[0]=this.rules.inline._backpedal.exec(t[0])?.[0]??"";while(i!==t[0]);n=t[0],t[1]==="www."?r="http://"+t[0]:r=t[0]}return{type:"link",raw:t[0],text:n,href:r,tokens:[{type:"text",raw:n,text:n}]}}}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}}}},
|
|
30
|
+
`?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 s=Yt(n.slice(0,-1),"\\");if((n.length-s.length)%2===0)return}else{let s=Ff(t[2],"()");if(s===-2)return;if(s>-1){let o=(t[0].indexOf("!")===0?5:4)+t[1].length+s;t[2]=t[2].substring(0,s),t[0]=t[0].substring(0,o).trim(),t[3]=""}}let r=t[2],i="";if(this.options.pedantic){let s=this.rules.other.pedanticHrefTitle.exec(r);s&&(r=s[1],i=s[3])}else i=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)),Vi(t,{href:r&&r.replace(this.rules.inline.anyPunctuation,"$1"),title:i&&i.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," "),i=t[r.toLowerCase()];if(!i){let s=n[0].charAt(0);return{type:"text",raw:s,text:s}}return Vi(n,i,n[0],this.lexer,this.rules)}}emStrong(e,t,n=""){let r=this.rules.inline.emStrongLDelim.exec(e);if(!(!r||r[3]&&n.match(this.rules.other.unicodeAlphaNumeric))&&(!(r[1]||r[2])||!n||this.rules.inline.punctuation.exec(n))){let i=[...r[0]].length-1,s,o,a=i,l=0,u=r[0][0]==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(u.lastIndex=0,t=t.slice(-1*e.length+i);(r=u.exec(t))!=null;){if(s=r[1]||r[2]||r[3]||r[4]||r[5]||r[6],!s)continue;if(o=[...s].length,r[3]||r[4]){a+=o;continue}else if((r[5]||r[6])&&i%3&&!((i+o)%3)){l+=o;continue}if(a-=o,a>0)continue;o=Math.min(o,o+a+l);let c=[...r[0]][0].length,f=e.slice(0,i+r.index+c+o);if(Math.min(i,o)%2){let p=f.slice(1,-1);return{type:"em",raw:f,text:p,tokens:this.lexer.inlineTokens(p)}}let d=f.slice(2,-2);return{type:"strong",raw:f,text:d,tokens:this.lexer.inlineTokens(d)}}}}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),i=this.rules.other.startingSpaceChar.test(n)&&this.rules.other.endingSpaceChar.test(n);return r&&i&&(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){let t=this.rules.inline.del.exec(e);if(t)return{type:"del",raw:t[0],text:t[2],tokens:this.lexer.inlineTokens(t[2])}}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){let t;if(t=this.rules.inline.url.exec(e)){let n,r;if(t[2]==="@")n=t[0],r="mailto:"+n;else{let i;do i=t[0],t[0]=this.rules.inline._backpedal.exec(t[0])?.[0]??"";while(i!==t[0]);n=t[0],t[1]==="www."?r="http://"+t[0]:r=t[0]}return{type:"link",raw:t[0],text:n,href:r,tokens:[{type:"text",raw:n,text:n}]}}}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}}}},Qe=class Lr{tokens;options;state;inlineQueue;tokenizer;constructor(t){this.tokens=[],this.tokens.links=Object.create(null),this.options=t||Dt,this.options.tokenizer=this.options.tokenizer||new Mn,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:De,block:mn.normal,inline:Xt.normal};this.options.pedantic?(n.block=mn.pedantic,n.inline=Xt.pedantic):this.options.gfm&&(n.block=mn.gfm,this.options.breaks?n.inline=Xt.breaks:n.inline=Xt.gfm),this.tokenizer.rules=n}static get rules(){return{block:mn,inline:Xt}}static lex(t,n){return new Lr(n).lex(t)}static lexInline(t,n){return new Lr(n).inlineTokens(t)}lex(t){t=t.replace(De.carriageReturn,`
|
|
31
31
|
`),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){for(this.options.pedantic&&(t=t.replace(De.tabCharGlobal," ").replace(De.spaceLine,""));t;){let i;if(this.options.extensions?.block?.some(o=>(i=o.call({lexer:this},t,n))?(t=t.substring(i.raw.length),n.push(i),!0):!1))continue;if(i=this.tokenizer.space(t)){t=t.substring(i.raw.length);let o=n.at(-1);i.raw.length===1&&o!==void 0?o.raw+=`
|
|
32
32
|
`:n.push(i);continue}if(i=this.tokenizer.code(t)){t=t.substring(i.raw.length);let o=n.at(-1);o?.type==="paragraph"||o?.type==="text"?(o.raw+=(o.raw.endsWith(`
|
|
33
33
|
`)?"":`
|
|
@@ -59,22 +59,22 @@ ${this.parser.parse(e)}</blockquote>
|
|
|
59
59
|
`}tablerow({text:e}){return`<tr>
|
|
60
60
|
${e}</tr>
|
|
61
61
|
`}tablecell(e){let t=this.parser.parseInline(e.tokens),n=e.header?"th":"td";return(e.align?`<${n} align="${e.align}">`:`<${n}>`)+t+`</${n}>
|
|
62
|
-
`}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>${at(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),i=Ki(e);if(i===null)return r;e=i;let s='<a href="'+e+'"';return t&&(s+=' title="'+at(t)+'"'),s+=">"+r+"</a>",s}image({href:e,title:t,text:n,tokens:r}){r&&(n=this.parser.parseInline(r,this.parser.textRenderer));let i=Ki(e);if(i===null)return at(n);e=i;let s=`<img src="${e}" alt="${n}"`;return t&&(s+=` title="${at(t)}"`),s+=">",s}text(e){return"tokens"in e&&e.tokens?this.parser.parseInline(e.tokens):"escaped"in e&&e.escaped?e.text:at(e.text)}},ai=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}},
|
|
63
|
-
Please report this to https://github.com/markedjs/marked.`,e){let r="<p>An error occurred:</p><pre>"+at(n.message+"",!0)+"</pre>";return t?Promise.resolve(r):r}if(t)return Promise.reject(n);throw n}}},Lt=new Bf;function
|
|
64
|
-
`,u="/",c="*",f="",d="comment",p="declaration";function g(w,k){if(typeof w!="string")throw new TypeError("First argument must be a string");if(!w)return[];k=k||{};var C=1,E=1;function N(T){var j=T.match(t);j&&(C+=j.length);var R=T.lastIndexOf(l);E=~R?T.length-R:E+T.length}function _(){var T={line:C,column:E};return function(j){return j.position=new S(T),O(),j}}function S(T){this.start=T,this.end={line:C,column:E},this.source=k.source}S.prototype.content=w;function M(T){var j=new Error(k.source+":"+C+":"+E+": "+T);if(j.reason=T,j.filename=k.source,j.line=C,j.column=E,j.source=w,!k.silent)throw j}function U(T){var j=T.exec(w);if(j){var R=j[0];return N(R),w=w.slice(R.length),j}}function O(){U(n)}function v(T){var j;for(T=T||[];j=L();)j!==!1&&T.push(j);return T}function L(){var T=_();if(!(u!=w.charAt(0)||c!=w.charAt(1))){for(var j=2;f!=w.charAt(j)&&(c!=w.charAt(j)||u!=w.charAt(j+1));)++j;if(j+=2,f===w.charAt(j-1))return M("End of comment missing");var R=w.slice(2,j-2);return E+=2,N(R),w=w.slice(j),E+=2,T({type:d,comment:R})}}function A(){var T=_(),j=U(r);if(j){if(L(),!U(i))return M("property missing ':'");var R=U(s),D=T({type:p,property:b(j[0].replace(e,f)),value:R?b(R[0].replace(e,f)):f});return U(o),D}}function F(){var T=[];v(T);for(var j;j=A();)j!==!1&&(T.push(j),v(T));return T}return O(),F()}function b(w){return w?w.replace(a,f):f}return ar=g,ar}var Gi;function Wf(){if(Gi)return Ot;Gi=1;var e=Ot&&Ot.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(Ot,"__esModule",{value:!0}),Ot.default=n;const t=e(Kf());function n(r,i){let s=null;if(!r||typeof r!="string")return s;const o=(0,t.default)(r),a=typeof i=="function";return o.forEach(l=>{if(l.type!=="declaration")return;const{property:u,value:c}=l;a?i(u,c,l):c&&(s=s||{},s[u]=c)}),s}return Ot}var Gt={},Qi;function Vf(){if(Qi)return Gt;Qi=1,Object.defineProperty(Gt,"__esModule",{value:!0}),Gt.camelCase=void 0;var e=/^--[a-zA-Z0-9_-]+$/,t=/-([a-z])/g,n=/^[^-]+$/,r=/^-(webkit|moz|ms|o|khtml)-/,i=/^-(ms)-/,s=function(u){return!u||n.test(u)||e.test(u)},o=function(u,c){return c.toUpperCase()},a=function(u,c){return"".concat(c,"-")},l=function(u,c){return c===void 0&&(c={}),s(u)?u:(u=u.toLowerCase(),c.reactCompat?u=u.replace(i,a):u=u.replace(r,a),u.replace(t,o))};return Gt.camelCase=l,Gt}var Qt,Ji;function Xf(){if(Ji)return Qt;Ji=1;var e=Qt&&Qt.__importDefault||function(i){return i&&i.__esModule?i:{default:i}},t=e(Wf()),n=Vf();function r(i,s){var o={};return!i||typeof i!="string"||(0,t.default)(i,function(a,l){a&&l&&(o[(0,n.camelCase)(a,s)]=l)}),o}return r.default=r,Qt=r,Qt}var Yf=Xf();const Gf=Ks(Yf),Oo=Fo("end"),li=Fo("start");function Fo(e){return t;function t(n){const r=n&&n.position&&n.position[e]||{};if(typeof r.line=="number"&&r.line>0&&typeof r.column=="number"&&r.column>0)return{line:r.line,column:r.column,offset:typeof r.offset=="number"&&r.offset>-1?r.offset:void 0}}}function Qf(e){const t=li(e),n=Oo(e);if(t&&n)return{start:t,end:n}}function sn(e){return!e||typeof e!="object"?"":"position"in e||"type"in e?Zi(e.position):"start"in e||"end"in e?Zi(e):"line"in e||"column"in e?Dr(e):""}function Dr(e){return es(e&&e.line)+":"+es(e&&e.column)}function Zi(e){return Dr(e&&e.start)+"-"+Dr(e&&e.end)}function es(e){return e&&typeof e=="number"?e:1}class Ne extends Error{constructor(t,n,r){super(),typeof n=="string"&&(r=n,n=void 0);let i="",s={},o=!1;if(n&&("line"in n&&"column"in n?s={place:n}:"start"in n&&"end"in n?s={place:n}:"type"in n?s={ancestors:[n],place:n.position}:s={...n}),typeof t=="string"?i=t:!s.cause&&t&&(o=!0,i=t.message,s.cause=t),!s.ruleId&&!s.source&&typeof r=="string"){const l=r.indexOf(":");l===-1?s.ruleId=r:(s.source=r.slice(0,l),s.ruleId=r.slice(l+1))}if(!s.place&&s.ancestors&&s.ancestors){const l=s.ancestors[s.ancestors.length-1];l&&(s.place=l.position)}const a=s.place&&"start"in s.place?s.place.start:s.place;this.ancestors=s.ancestors||void 0,this.cause=s.cause||void 0,this.column=a?a.column:void 0,this.fatal=void 0,this.file="",this.message=i,this.line=a?a.line:void 0,this.name=sn(s.place)||"1:1",this.place=s.place||void 0,this.reason=this.message,this.ruleId=s.ruleId||void 0,this.source=s.source||void 0,this.stack=o&&s.cause&&typeof s.cause.stack=="string"?s.cause.stack:"",this.actual=void 0,this.expected=void 0,this.note=void 0,this.url=void 0}}Ne.prototype.file="";Ne.prototype.name="";Ne.prototype.reason="";Ne.prototype.message="";Ne.prototype.stack="";Ne.prototype.column=void 0;Ne.prototype.line=void 0;Ne.prototype.ancestors=void 0;Ne.prototype.cause=void 0;Ne.prototype.fatal=void 0;Ne.prototype.place=void 0;Ne.prototype.ruleId=void 0;Ne.prototype.source=void 0;const ui={}.hasOwnProperty,Jf=new Map,Zf=/[A-Z]/g,eh=new Set(["table","tbody","thead","tfoot","tr"]),th=new Set(["td","th"]),$o="https://github.com/syntax-tree/hast-util-to-jsx-runtime";function nh(e,t){if(!t||t.Fragment===void 0)throw new TypeError("Expected `Fragment` in options");const n=t.filePath||void 0;let r;if(t.development){if(typeof t.jsxDEV!="function")throw new TypeError("Expected `jsxDEV` in options when `development: true`");r=ch(n,t.jsxDEV)}else{if(typeof t.jsx!="function")throw new TypeError("Expected `jsx` in production options");if(typeof t.jsxs!="function")throw new TypeError("Expected `jsxs` in production options");r=uh(n,t.jsx,t.jsxs)}const i={Fragment:t.Fragment,ancestors:[],components:t.components||{},create:r,elementAttributeNameCase:t.elementAttributeNameCase||"react",evaluater:t.createEvaluater?t.createEvaluater():void 0,filePath:n,ignoreInvalidStyle:t.ignoreInvalidStyle||!1,passKeys:t.passKeys!==!1,passNode:t.passNode||!1,schema:t.space==="svg"?Yr:tu,stylePropertyNameCase:t.stylePropertyNameCase||"dom",tableCellAlignToStyle:t.tableCellAlignToStyle!==!1},s=Bo(i,e,void 0);return s&&typeof s!="string"?s:i.create(e,i.Fragment,{children:s||void 0},void 0)}function Bo(e,t,n){if(t.type==="element")return rh(e,t,n);if(t.type==="mdxFlowExpression"||t.type==="mdxTextExpression")return ih(e,t);if(t.type==="mdxJsxFlowElement"||t.type==="mdxJsxTextElement")return oh(e,t,n);if(t.type==="mdxjsEsm")return sh(e,t);if(t.type==="root")return ah(e,t,n);if(t.type==="text")return lh(e,t)}function rh(e,t,n){const r=e.schema;let i=r;t.tagName.toLowerCase()==="svg"&&r.space==="html"&&(i=Yr,e.schema=i),e.ancestors.push(t);const s=Uo(e,t.tagName,!1),o=fh(e,t);let a=fi(e,t);return eh.has(t.tagName)&&(a=a.filter(function(l){return typeof l=="string"?!nu(l):!0})),Ho(e,o,s,t),ci(o,a),e.ancestors.pop(),e.schema=r,e.create(t,s,o,n)}function ih(e,t){if(t.data&&t.data.estree&&e.evaluater){const r=t.data.estree.body[0];return r.type,e.evaluater.evaluateExpression(r.expression)}ln(e,t.position)}function sh(e,t){if(t.data&&t.data.estree&&e.evaluater)return e.evaluater.evaluateProgram(t.data.estree);ln(e,t.position)}function oh(e,t,n){const r=e.schema;let i=r;t.name==="svg"&&r.space==="html"&&(i=Yr,e.schema=i),e.ancestors.push(t);const s=t.name===null?e.Fragment:Uo(e,t.name,!0),o=hh(e,t),a=fi(e,t);return Ho(e,o,s,t),ci(o,a),e.ancestors.pop(),e.schema=r,e.create(t,s,o,n)}function ah(e,t,n){const r={};return ci(r,fi(e,t)),e.create(t,e.Fragment,r,n)}function lh(e,t){return t.value}function Ho(e,t,n,r){typeof n!="string"&&n!==e.Fragment&&e.passNode&&(t.node=r)}function ci(e,t){if(t.length>0){const n=t.length>1?t:t[0];n&&(e.children=n)}}function uh(e,t,n){return r;function r(i,s,o,a){const u=Array.isArray(o.children)?n:t;return a?u(s,o,a):u(s,o)}}function ch(e,t){return n;function n(r,i,s,o){const a=Array.isArray(s.children),l=li(r);return t(i,s,o,a,{columnNumber:l?l.column-1:void 0,fileName:e,lineNumber:l?l.line:void 0},void 0)}}function fh(e,t){const n={};let r,i;for(i in t.properties)if(i!=="children"&&ui.call(t.properties,i)){const s=ph(e,i,t.properties[i]);if(s){const[o,a]=s;e.tableCellAlignToStyle&&o==="align"&&typeof a=="string"&&th.has(t.tagName)?r=a:n[o]=a}}if(r){const s=n.style||(n.style={});s[e.stylePropertyNameCase==="css"?"text-align":"textAlign"]=r}return n}function hh(e,t){const n={};for(const r of t.attributes)if(r.type==="mdxJsxExpressionAttribute")if(r.data&&r.data.estree&&e.evaluater){const s=r.data.estree.body[0];s.type;const o=s.expression;o.type;const a=o.properties[0];a.type,Object.assign(n,e.evaluater.evaluateExpression(a.argument))}else ln(e,t.position);else{const i=r.name;let s;if(r.value&&typeof r.value=="object")if(r.value.data&&r.value.data.estree&&e.evaluater){const a=r.value.data.estree.body[0];a.type,s=e.evaluater.evaluateExpression(a.expression)}else ln(e,t.position);else s=r.value===null?!0:r.value;n[i]=s}return n}function fi(e,t){const n=[];let r=-1;const i=e.passKeys?new Map:Jf;for(;++r<t.children.length;){const s=t.children[r];let o;if(e.passKeys){const l=s.type==="element"?s.tagName:s.type==="mdxJsxFlowElement"||s.type==="mdxJsxTextElement"?s.name:void 0;if(l){const u=i.get(l)||0;o=l+"-"+u,i.set(l,u+1)}}const a=Bo(e,s,o);a!==void 0&&n.push(a)}return n}function ph(e,t,n){const r=ru(e.schema,t);if(!(n==null||typeof n=="number"&&Number.isNaN(n))){if(Array.isArray(n)&&(n=r.commaSeparated?iu(n):su(n)),r.property==="style"){let i=typeof n=="object"?n:dh(e,String(n));return e.stylePropertyNameCase==="css"&&(i=mh(i)),["style",i]}return[e.elementAttributeNameCase==="react"&&r.space?uu[r.property]||r.property:r.attribute,n]}}function dh(e,t){try{return Gf(t,{reactCompat:!0})}catch(n){if(e.ignoreInvalidStyle)return{};const r=n,i=new Ne("Cannot parse `style` attribute",{ancestors:e.ancestors,cause:r,ruleId:"style",source:"hast-util-to-jsx-runtime"});throw i.file=e.filePath||void 0,i.url=$o+"#cannot-parse-style-attribute",i}}function Uo(e,t,n){let r;if(!n)r={type:"Literal",value:t};else if(t.includes(".")){const i=t.split(".");let s=-1,o;for(;++s<i.length;){const a=Xi(i[s])?{type:"Identifier",name:i[s]}:{type:"Literal",value:i[s]};o=o?{type:"MemberExpression",object:o,property:a,computed:!!(s&&a.type==="Literal"),optional:!1}:a}r=o}else r=Xi(t)&&!/^[a-z]/.test(t)?{type:"Identifier",name:t}:{type:"Literal",value:t};if(r.type==="Literal"){const i=r.value;return ui.call(e.components,i)?e.components[i]:i}if(e.evaluater)return e.evaluater.evaluateExpression(r);ln(e)}function ln(e,t){const n=new Ne("Cannot handle MDX estrees without `createEvaluater`",{ancestors:e.ancestors,place:t,ruleId:"mdx-estree",source:"hast-util-to-jsx-runtime"});throw n.file=e.filePath||void 0,n.url=$o+"#cannot-handle-mdx-estrees-without-createevaluater",n}function mh(e){const t={};let n;for(n in e)ui.call(e,n)&&(t[gh(n)]=e[n]);return t}function gh(e){let t=e.replace(Zf,xh);return t.slice(0,3)==="ms-"&&(t="-"+t),t}function xh(e){return"-"+e.toLowerCase()}const lr={action:["form"],cite:["blockquote","del","ins","q"],data:["object"],formAction:["button","input"],href:["a","area","base","link"],icon:["menuitem"],itemId:null,manifest:["html"],ping:["a","area"],poster:["video"],src:["audio","embed","iframe","img","input","script","source","track","video"]},yh={};function hi(e,t){const n=yh,r=typeof n.includeImageAlt=="boolean"?n.includeImageAlt:!0,i=typeof n.includeHtml=="boolean"?n.includeHtml:!0;return qo(e,r,i)}function qo(e,t,n){if(bh(e)){if("value"in e)return e.type==="html"&&!n?"":e.value;if(t&&"alt"in e&&e.alt)return e.alt;if("children"in e)return ts(e.children,t,n)}return Array.isArray(e)?ts(e,t,n):""}function ts(e,t,n){const r=[];let i=-1;for(;++i<e.length;)r[i]=qo(e[i],t,n);return r.join("")}function bh(e){return!!(e&&typeof e=="object")}const ns=document.createElement("i");function pi(e){const t="&"+e+";";ns.innerHTML=t;const n=ns.textContent;return n.charCodeAt(n.length-1)===59&&e!=="semi"||n===t?!1:n}function $e(e,t,n,r){const i=e.length;let s=0,o;if(t<0?t=-t>i?0:i+t:t=t>i?i:t,n=n>0?n:0,r.length<1e4)o=Array.from(r),o.unshift(t,n),e.splice(...o);else for(n&&e.splice(t,n);s<r.length;)o=r.slice(s,s+1e4),o.unshift(t,0),e.splice(...o),s+=1e4,t+=1e4}function We(e,t){return e.length>0?($e(e,e.length,0,t),e):t}const rs={}.hasOwnProperty;function Ko(e){const t={};let n=-1;for(;++n<e.length;)kh(t,e[n]);return t}function kh(e,t){let n;for(n in t){const i=(rs.call(e,n)?e[n]:void 0)||(e[n]={}),s=t[n];let o;if(s)for(o in s){rs.call(i,o)||(i[o]=[]);const a=s[o];wh(i[o],Array.isArray(a)?a:a?[a]:[])}}}function wh(e,t){let n=-1;const r=[];for(;++n<t.length;)(t[n].add==="after"?e:r).push(t[n]);$e(e,0,0,r)}function Wo(e,t){const n=Number.parseInt(e,t);return n<9||n===11||n>13&&n<32||n>126&&n<160||n>55295&&n<57344||n>64975&&n<65008||(n&65535)===65535||(n&65535)===65534||n>1114111?"�":String.fromCodePoint(n)}function Ze(e){return e.replace(/[\t\n\r ]+/g," ").replace(/^ | $/g,"").toLowerCase().toUpperCase()}const Me=yt(/[A-Za-z]/),Re=yt(/[\dA-Za-z]/),Sh=yt(/[#-'*+\--9=?A-Z^-~]/);function zn(e){return e!==null&&(e<32||e===127)}const zr=yt(/\d/),Ch=yt(/[\dA-Fa-f]/),vh=yt(/[!-/:-@[-`{-~]/);function G(e){return e!==null&&e<-2}function he(e){return e!==null&&(e<0||e===32)}function se(e){return e===-2||e===-1||e===32}const Vn=yt(new RegExp("\\p{P}|\\p{S}","u")),Mt=yt(/\s/);function yt(e){return t;function t(n){return n!==null&&n>-1&&e.test(String.fromCharCode(n))}}function Kt(e){const t=[];let n=-1,r=0,i=0;for(;++n<e.length;){const s=e.charCodeAt(n);let o="";if(s===37&&Re(e.charCodeAt(n+1))&&Re(e.charCodeAt(n+2)))i=2;else if(s<128)/[!#$&-;=?-Z_a-z~]/.test(String.fromCharCode(s))||(o=String.fromCharCode(s));else if(s>55295&&s<57344){const a=e.charCodeAt(n+1);s<56320&&a>56319&&a<57344?(o=String.fromCharCode(s,a),i=1):o="�"}else o=String.fromCharCode(s);o&&(t.push(e.slice(r,n),encodeURIComponent(o)),r=n+i+1,o=""),i&&(n+=i,i=0)}return t.join("")+e.slice(r)}function oe(e,t,n,r){const i=r?r-1:Number.POSITIVE_INFINITY;let s=0;return o;function o(l){return se(l)?(e.enter(n),a(l)):t(l)}function a(l){return se(l)&&s++<i?(e.consume(l),a):(e.exit(n),t(l))}}const Eh={tokenize:Th};function Th(e){const t=e.attempt(this.parser.constructs.contentInitial,r,i);let n;return t;function r(a){if(a===null){e.consume(a);return}return e.enter("lineEnding"),e.consume(a),e.exit("lineEnding"),oe(e,t,"linePrefix")}function i(a){return e.enter("paragraph"),s(a)}function s(a){const l=e.enter("chunkText",{contentType:"text",previous:n});return n&&(n.next=l),n=l,o(a)}function o(a){if(a===null){e.exit("chunkText"),e.exit("paragraph"),e.consume(a);return}return G(a)?(e.consume(a),e.exit("chunkText"),s):(e.consume(a),o)}}const jh={tokenize:Ah},is={tokenize:Ih};function Ah(e){const t=this,n=[];let r=0,i,s,o;return a;function a(E){if(r<n.length){const N=n[r];return t.containerState=N[1],e.attempt(N[0].continuation,l,u)(E)}return u(E)}function l(E){if(r++,t.containerState._closeFlow){t.containerState._closeFlow=void 0,i&&C();const N=t.events.length;let _=N,S;for(;_--;)if(t.events[_][0]==="exit"&&t.events[_][1].type==="chunkFlow"){S=t.events[_][1].end;break}k(r);let M=N;for(;M<t.events.length;)t.events[M][1].end={...S},M++;return $e(t.events,_+1,0,t.events.slice(N)),t.events.length=M,u(E)}return a(E)}function u(E){if(r===n.length){if(!i)return d(E);if(i.currentConstruct&&i.currentConstruct.concrete)return g(E);t.interrupt=!!(i.currentConstruct&&!i._gfmTableDynamicInterruptHack)}return t.containerState={},e.check(is,c,f)(E)}function c(E){return i&&C(),k(r),d(E)}function f(E){return t.parser.lazy[t.now().line]=r!==n.length,o=t.now().offset,g(E)}function d(E){return t.containerState={},e.attempt(is,p,g)(E)}function p(E){return r++,n.push([t.currentConstruct,t.containerState]),d(E)}function g(E){if(E===null){i&&C(),k(0),e.consume(E);return}return i=i||t.parser.flow(t.now()),e.enter("chunkFlow",{_tokenizer:i,contentType:"flow",previous:s}),b(E)}function b(E){if(E===null){w(e.exit("chunkFlow"),!0),k(0),e.consume(E);return}return G(E)?(e.consume(E),w(e.exit("chunkFlow")),r=0,t.interrupt=void 0,a):(e.consume(E),b)}function w(E,N){const _=t.sliceStream(E);if(N&&_.push(null),E.previous=s,s&&(s.next=E),s=E,i.defineSkip(E.start),i.write(_),t.parser.lazy[E.start.line]){let S=i.events.length;for(;S--;)if(i.events[S][1].start.offset<o&&(!i.events[S][1].end||i.events[S][1].end.offset>o))return;const M=t.events.length;let U=M,O,v;for(;U--;)if(t.events[U][0]==="exit"&&t.events[U][1].type==="chunkFlow"){if(O){v=t.events[U][1].end;break}O=!0}for(k(r),S=M;S<t.events.length;)t.events[S][1].end={...v},S++;$e(t.events,U+1,0,t.events.slice(M)),t.events.length=S}}function k(E){let N=n.length;for(;N-- >E;){const _=n[N];t.containerState=_[1],_[0].exit.call(t,e)}n.length=E}function C(){i.write([null]),s=void 0,i=void 0,t.containerState._closeFlow=void 0}}function Ih(e,t,n){return oe(e,e.attempt(this.parser.constructs.document,t,n),"linePrefix",this.parser.constructs.disable.null.includes("codeIndented")?void 0:4)}function Ut(e){if(e===null||he(e)||Mt(e))return 1;if(Vn(e))return 2}function Xn(e,t,n){const r=[];let i=-1;for(;++i<e.length;){const s=e[i].resolveAll;s&&!r.includes(s)&&(t=s(t,n),r.push(s))}return t}const Pr={name:"attention",resolveAll:Rh,tokenize:Nh};function Rh(e,t){let n=-1,r,i,s,o,a,l,u,c;for(;++n<e.length;)if(e[n][0]==="enter"&&e[n][1].type==="attentionSequence"&&e[n][1]._close){for(r=n;r--;)if(e[r][0]==="exit"&&e[r][1].type==="attentionSequence"&&e[r][1]._open&&t.sliceSerialize(e[r][1]).charCodeAt(0)===t.sliceSerialize(e[n][1]).charCodeAt(0)){if((e[r][1]._close||e[n][1]._open)&&(e[n][1].end.offset-e[n][1].start.offset)%3&&!((e[r][1].end.offset-e[r][1].start.offset+e[n][1].end.offset-e[n][1].start.offset)%3))continue;l=e[r][1].end.offset-e[r][1].start.offset>1&&e[n][1].end.offset-e[n][1].start.offset>1?2:1;const f={...e[r][1].end},d={...e[n][1].start};ss(f,-l),ss(d,l),o={type:l>1?"strongSequence":"emphasisSequence",start:f,end:{...e[r][1].end}},a={type:l>1?"strongSequence":"emphasisSequence",start:{...e[n][1].start},end:d},s={type:l>1?"strongText":"emphasisText",start:{...e[r][1].end},end:{...e[n][1].start}},i={type:l>1?"strong":"emphasis",start:{...o.start},end:{...a.end}},e[r][1].end={...o.start},e[n][1].start={...a.end},u=[],e[r][1].end.offset-e[r][1].start.offset&&(u=We(u,[["enter",e[r][1],t],["exit",e[r][1],t]])),u=We(u,[["enter",i,t],["enter",o,t],["exit",o,t],["enter",s,t]]),u=We(u,Xn(t.parser.constructs.insideSpan.null,e.slice(r+1,n),t)),u=We(u,[["exit",s,t],["enter",a,t],["exit",a,t],["exit",i,t]]),e[n][1].end.offset-e[n][1].start.offset?(c=2,u=We(u,[["enter",e[n][1],t],["exit",e[n][1],t]])):c=0,$e(e,r-1,n-r+3,u),n=r+u.length-c-2;break}}for(n=-1;++n<e.length;)e[n][1].type==="attentionSequence"&&(e[n][1].type="data");return e}function Nh(e,t){const n=this.parser.constructs.attentionMarkers.null,r=this.previous,i=Ut(r);let s;return o;function o(l){return s=l,e.enter("attentionSequence"),a(l)}function a(l){if(l===s)return e.consume(l),a;const u=e.exit("attentionSequence"),c=Ut(l),f=!c||c===2&&i||n.includes(l),d=!i||i===2&&c||n.includes(r);return u._open=!!(s===42?f:f&&(i||!d)),u._close=!!(s===42?d:d&&(c||!f)),t(l)}}function ss(e,t){e.column+=t,e.offset+=t,e._bufferIndex+=t}const Lh={name:"autolink",tokenize:Mh};function Mh(e,t,n){let r=0;return i;function i(p){return e.enter("autolink"),e.enter("autolinkMarker"),e.consume(p),e.exit("autolinkMarker"),e.enter("autolinkProtocol"),s}function s(p){return Me(p)?(e.consume(p),o):p===64?n(p):u(p)}function o(p){return p===43||p===45||p===46||Re(p)?(r=1,a(p)):u(p)}function a(p){return p===58?(e.consume(p),r=0,l):(p===43||p===45||p===46||Re(p))&&r++<32?(e.consume(p),a):(r=0,u(p))}function l(p){return p===62?(e.exit("autolinkProtocol"),e.enter("autolinkMarker"),e.consume(p),e.exit("autolinkMarker"),e.exit("autolink"),t):p===null||p===32||p===60||zn(p)?n(p):(e.consume(p),l)}function u(p){return p===64?(e.consume(p),c):Sh(p)?(e.consume(p),u):n(p)}function c(p){return Re(p)?f(p):n(p)}function f(p){return p===46?(e.consume(p),r=0,c):p===62?(e.exit("autolinkProtocol").type="autolinkEmail",e.enter("autolinkMarker"),e.consume(p),e.exit("autolinkMarker"),e.exit("autolink"),t):d(p)}function d(p){if((p===45||Re(p))&&r++<63){const g=p===45?d:f;return e.consume(p),g}return n(p)}}const fn={partial:!0,tokenize:Dh};function Dh(e,t,n){return r;function r(s){return se(s)?oe(e,i,"linePrefix")(s):i(s)}function i(s){return s===null||G(s)?t(s):n(s)}}const Vo={continuation:{tokenize:Ph},exit:_h,name:"blockQuote",tokenize:zh};function zh(e,t,n){const r=this;return i;function i(o){if(o===62){const a=r.containerState;return a.open||(e.enter("blockQuote",{_container:!0}),a.open=!0),e.enter("blockQuotePrefix"),e.enter("blockQuoteMarker"),e.consume(o),e.exit("blockQuoteMarker"),s}return n(o)}function s(o){return se(o)?(e.enter("blockQuotePrefixWhitespace"),e.consume(o),e.exit("blockQuotePrefixWhitespace"),e.exit("blockQuotePrefix"),t):(e.exit("blockQuotePrefix"),t(o))}}function Ph(e,t,n){const r=this;return i;function i(o){return se(o)?oe(e,s,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(o):s(o)}function s(o){return e.attempt(Vo,t,n)(o)}}function _h(e){e.exit("blockQuote")}const Xo={name:"characterEscape",tokenize:Oh};function Oh(e,t,n){return r;function r(s){return e.enter("characterEscape"),e.enter("escapeMarker"),e.consume(s),e.exit("escapeMarker"),i}function i(s){return vh(s)?(e.enter("characterEscapeValue"),e.consume(s),e.exit("characterEscapeValue"),e.exit("characterEscape"),t):n(s)}}const Yo={name:"characterReference",tokenize:Fh};function Fh(e,t,n){const r=this;let i=0,s,o;return a;function a(f){return e.enter("characterReference"),e.enter("characterReferenceMarker"),e.consume(f),e.exit("characterReferenceMarker"),l}function l(f){return f===35?(e.enter("characterReferenceMarkerNumeric"),e.consume(f),e.exit("characterReferenceMarkerNumeric"),u):(e.enter("characterReferenceValue"),s=31,o=Re,c(f))}function u(f){return f===88||f===120?(e.enter("characterReferenceMarkerHexadecimal"),e.consume(f),e.exit("characterReferenceMarkerHexadecimal"),e.enter("characterReferenceValue"),s=6,o=Ch,c):(e.enter("characterReferenceValue"),s=7,o=zr,c(f))}function c(f){if(f===59&&i){const d=e.exit("characterReferenceValue");return o===Re&&!pi(r.sliceSerialize(d))?n(f):(e.enter("characterReferenceMarker"),e.consume(f),e.exit("characterReferenceMarker"),e.exit("characterReference"),t)}return o(f)&&i++<s?(e.consume(f),c):n(f)}}const os={partial:!0,tokenize:Bh},as={concrete:!0,name:"codeFenced",tokenize:$h};function $h(e,t,n){const r=this,i={partial:!0,tokenize:_};let s=0,o=0,a;return l;function l(S){return u(S)}function u(S){const M=r.events[r.events.length-1];return s=M&&M[1].type==="linePrefix"?M[2].sliceSerialize(M[1],!0).length:0,a=S,e.enter("codeFenced"),e.enter("codeFencedFence"),e.enter("codeFencedFenceSequence"),c(S)}function c(S){return S===a?(o++,e.consume(S),c):o<3?n(S):(e.exit("codeFencedFenceSequence"),se(S)?oe(e,f,"whitespace")(S):f(S))}function f(S){return S===null||G(S)?(e.exit("codeFencedFence"),r.interrupt?t(S):e.check(os,b,N)(S)):(e.enter("codeFencedFenceInfo"),e.enter("chunkString",{contentType:"string"}),d(S))}function d(S){return S===null||G(S)?(e.exit("chunkString"),e.exit("codeFencedFenceInfo"),f(S)):se(S)?(e.exit("chunkString"),e.exit("codeFencedFenceInfo"),oe(e,p,"whitespace")(S)):S===96&&S===a?n(S):(e.consume(S),d)}function p(S){return S===null||G(S)?f(S):(e.enter("codeFencedFenceMeta"),e.enter("chunkString",{contentType:"string"}),g(S))}function g(S){return S===null||G(S)?(e.exit("chunkString"),e.exit("codeFencedFenceMeta"),f(S)):S===96&&S===a?n(S):(e.consume(S),g)}function b(S){return e.attempt(i,N,w)(S)}function w(S){return e.enter("lineEnding"),e.consume(S),e.exit("lineEnding"),k}function k(S){return s>0&&se(S)?oe(e,C,"linePrefix",s+1)(S):C(S)}function C(S){return S===null||G(S)?e.check(os,b,N)(S):(e.enter("codeFlowValue"),E(S))}function E(S){return S===null||G(S)?(e.exit("codeFlowValue"),C(S)):(e.consume(S),E)}function N(S){return e.exit("codeFenced"),t(S)}function _(S,M,U){let O=0;return v;function v(j){return S.enter("lineEnding"),S.consume(j),S.exit("lineEnding"),L}function L(j){return S.enter("codeFencedFence"),se(j)?oe(S,A,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(j):A(j)}function A(j){return j===a?(S.enter("codeFencedFenceSequence"),F(j)):U(j)}function F(j){return j===a?(O++,S.consume(j),F):O>=o?(S.exit("codeFencedFenceSequence"),se(j)?oe(S,T,"whitespace")(j):T(j)):U(j)}function T(j){return j===null||G(j)?(S.exit("codeFencedFence"),M(j)):U(j)}}}function Bh(e,t,n){const r=this;return i;function i(o){return o===null?n(o):(e.enter("lineEnding"),e.consume(o),e.exit("lineEnding"),s)}function s(o){return r.parser.lazy[r.now().line]?n(o):t(o)}}const ur={name:"codeIndented",tokenize:Uh},Hh={partial:!0,tokenize:qh};function Uh(e,t,n){const r=this;return i;function i(u){return e.enter("codeIndented"),oe(e,s,"linePrefix",5)(u)}function s(u){const c=r.events[r.events.length-1];return c&&c[1].type==="linePrefix"&&c[2].sliceSerialize(c[1],!0).length>=4?o(u):n(u)}function o(u){return u===null?l(u):G(u)?e.attempt(Hh,o,l)(u):(e.enter("codeFlowValue"),a(u))}function a(u){return u===null||G(u)?(e.exit("codeFlowValue"),o(u)):(e.consume(u),a)}function l(u){return e.exit("codeIndented"),t(u)}}function qh(e,t,n){const r=this;return i;function i(o){return r.parser.lazy[r.now().line]?n(o):G(o)?(e.enter("lineEnding"),e.consume(o),e.exit("lineEnding"),i):oe(e,s,"linePrefix",5)(o)}function s(o){const a=r.events[r.events.length-1];return a&&a[1].type==="linePrefix"&&a[2].sliceSerialize(a[1],!0).length>=4?t(o):G(o)?i(o):n(o)}}const Kh={name:"codeText",previous:Vh,resolve:Wh,tokenize:Xh};function Wh(e){let t=e.length-4,n=3,r,i;if((e[n][1].type==="lineEnding"||e[n][1].type==="space")&&(e[t][1].type==="lineEnding"||e[t][1].type==="space")){for(r=n;++r<t;)if(e[r][1].type==="codeTextData"){e[n][1].type="codeTextPadding",e[t][1].type="codeTextPadding",n+=2,t-=2;break}}for(r=n-1,t++;++r<=t;)i===void 0?r!==t&&e[r][1].type!=="lineEnding"&&(i=r):(r===t||e[r][1].type==="lineEnding")&&(e[i][1].type="codeTextData",r!==i+2&&(e[i][1].end=e[r-1][1].end,e.splice(i+2,r-i-2),t-=r-i-2,r=i+2),i=void 0);return e}function Vh(e){return e!==96||this.events[this.events.length-1][1].type==="characterEscape"}function Xh(e,t,n){let r=0,i,s;return o;function o(f){return e.enter("codeText"),e.enter("codeTextSequence"),a(f)}function a(f){return f===96?(e.consume(f),r++,a):(e.exit("codeTextSequence"),l(f))}function l(f){return f===null?n(f):f===32?(e.enter("space"),e.consume(f),e.exit("space"),l):f===96?(s=e.enter("codeTextSequence"),i=0,c(f)):G(f)?(e.enter("lineEnding"),e.consume(f),e.exit("lineEnding"),l):(e.enter("codeTextData"),u(f))}function u(f){return f===null||f===32||f===96||G(f)?(e.exit("codeTextData"),l(f)):(e.consume(f),u)}function c(f){return f===96?(e.consume(f),i++,c):i===r?(e.exit("codeTextSequence"),e.exit("codeText"),t(f)):(s.type="codeTextData",u(f))}}class Yh{constructor(t){this.left=t?[...t]:[],this.right=[]}get(t){if(t<0||t>=this.left.length+this.right.length)throw new RangeError("Cannot access index `"+t+"` in a splice buffer of size `"+(this.left.length+this.right.length)+"`");return t<this.left.length?this.left[t]:this.right[this.right.length-t+this.left.length-1]}get length(){return this.left.length+this.right.length}shift(){return this.setCursor(0),this.right.pop()}slice(t,n){const r=n??Number.POSITIVE_INFINITY;return r<this.left.length?this.left.slice(t,r):t>this.left.length?this.right.slice(this.right.length-r+this.left.length,this.right.length-t+this.left.length).reverse():this.left.slice(t).concat(this.right.slice(this.right.length-r+this.left.length).reverse())}splice(t,n,r){const i=n||0;this.setCursor(Math.trunc(t));const s=this.right.splice(this.right.length-i,Number.POSITIVE_INFINITY);return r&&Jt(this.left,r),s.reverse()}pop(){return this.setCursor(Number.POSITIVE_INFINITY),this.left.pop()}push(t){this.setCursor(Number.POSITIVE_INFINITY),this.left.push(t)}pushMany(t){this.setCursor(Number.POSITIVE_INFINITY),Jt(this.left,t)}unshift(t){this.setCursor(0),this.right.push(t)}unshiftMany(t){this.setCursor(0),Jt(this.right,t.reverse())}setCursor(t){if(!(t===this.left.length||t>this.left.length&&this.right.length===0||t<0&&this.left.length===0))if(t<this.left.length){const n=this.left.splice(t,Number.POSITIVE_INFINITY);Jt(this.right,n.reverse())}else{const n=this.right.splice(this.left.length+this.right.length-t,Number.POSITIVE_INFINITY);Jt(this.left,n.reverse())}}}function Jt(e,t){let n=0;if(t.length<1e4)e.push(...t);else for(;n<t.length;)e.push(...t.slice(n,n+1e4)),n+=1e4}function Go(e){const t={};let n=-1,r,i,s,o,a,l,u;const c=new Yh(e);for(;++n<c.length;){for(;n in t;)n=t[n];if(r=c.get(n),n&&r[1].type==="chunkFlow"&&c.get(n-1)[1].type==="listItemPrefix"&&(l=r[1]._tokenizer.events,s=0,s<l.length&&l[s][1].type==="lineEndingBlank"&&(s+=2),s<l.length&&l[s][1].type==="content"))for(;++s<l.length&&l[s][1].type!=="content";)l[s][1].type==="chunkText"&&(l[s][1]._isInFirstContentOfListItem=!0,s++);if(r[0]==="enter")r[1].contentType&&(Object.assign(t,Gh(c,n)),n=t[n],u=!0);else if(r[1]._container){for(s=n,i=void 0;s--;)if(o=c.get(s),o[1].type==="lineEnding"||o[1].type==="lineEndingBlank")o[0]==="enter"&&(i&&(c.get(i)[1].type="lineEndingBlank"),o[1].type="lineEnding",i=s);else if(!(o[1].type==="linePrefix"||o[1].type==="listItemIndent"))break;i&&(r[1].end={...c.get(i)[1].start},a=c.slice(i,n),a.unshift(r),c.splice(i,n-i+1,a))}}return $e(e,0,Number.POSITIVE_INFINITY,c.slice(0)),!u}function Gh(e,t){const n=e.get(t)[1],r=e.get(t)[2];let i=t-1;const s=[];let o=n._tokenizer;o||(o=r.parser[n.contentType](n.start),n._contentTypeTextTrailing&&(o._contentTypeTextTrailing=!0));const a=o.events,l=[],u={};let c,f,d=-1,p=n,g=0,b=0;const w=[b];for(;p;){for(;e.get(++i)[1]!==p;);s.push(i),p._tokenizer||(c=r.sliceStream(p),p.next||c.push(null),f&&o.defineSkip(p.start),p._isInFirstContentOfListItem&&(o._gfmTasklistFirstContentOfListItem=!0),o.write(c),p._isInFirstContentOfListItem&&(o._gfmTasklistFirstContentOfListItem=void 0)),f=p,p=p.next}for(p=n;++d<a.length;)a[d][0]==="exit"&&a[d-1][0]==="enter"&&a[d][1].type===a[d-1][1].type&&a[d][1].start.line!==a[d][1].end.line&&(b=d+1,w.push(b),p._tokenizer=void 0,p.previous=void 0,p=p.next);for(o.events=[],p?(p._tokenizer=void 0,p.previous=void 0):w.pop(),d=w.length;d--;){const k=a.slice(w[d],w[d+1]),C=s.pop();l.push([C,C+k.length-1]),e.splice(C,2,k)}for(l.reverse(),d=-1;++d<l.length;)u[g+l[d][0]]=g+l[d][1],g+=l[d][1]-l[d][0]-1;return u}const Qh={resolve:Zh,tokenize:ep},Jh={partial:!0,tokenize:tp};function Zh(e){return Go(e),e}function ep(e,t){let n;return r;function r(a){return e.enter("content"),n=e.enter("chunkContent",{contentType:"content"}),i(a)}function i(a){return a===null?s(a):G(a)?e.check(Jh,o,s)(a):(e.consume(a),i)}function s(a){return e.exit("chunkContent"),e.exit("content"),t(a)}function o(a){return e.consume(a),e.exit("chunkContent"),n.next=e.enter("chunkContent",{contentType:"content",previous:n}),n=n.next,i}}function tp(e,t,n){const r=this;return i;function i(o){return e.exit("chunkContent"),e.enter("lineEnding"),e.consume(o),e.exit("lineEnding"),oe(e,s,"linePrefix")}function s(o){if(o===null||G(o))return n(o);const a=r.events[r.events.length-1];return!r.parser.constructs.disable.null.includes("codeIndented")&&a&&a[1].type==="linePrefix"&&a[2].sliceSerialize(a[1],!0).length>=4?t(o):e.interrupt(r.parser.constructs.flow,n,t)(o)}}function Qo(e,t,n,r,i,s,o,a,l){const u=l||Number.POSITIVE_INFINITY;let c=0;return f;function f(k){return k===60?(e.enter(r),e.enter(i),e.enter(s),e.consume(k),e.exit(s),d):k===null||k===32||k===41||zn(k)?n(k):(e.enter(r),e.enter(o),e.enter(a),e.enter("chunkString",{contentType:"string"}),b(k))}function d(k){return k===62?(e.enter(s),e.consume(k),e.exit(s),e.exit(i),e.exit(r),t):(e.enter(a),e.enter("chunkString",{contentType:"string"}),p(k))}function p(k){return k===62?(e.exit("chunkString"),e.exit(a),d(k)):k===null||k===60||G(k)?n(k):(e.consume(k),k===92?g:p)}function g(k){return k===60||k===62||k===92?(e.consume(k),p):p(k)}function b(k){return!c&&(k===null||k===41||he(k))?(e.exit("chunkString"),e.exit(a),e.exit(o),e.exit(r),t(k)):c<u&&k===40?(e.consume(k),c++,b):k===41?(e.consume(k),c--,b):k===null||k===32||k===40||zn(k)?n(k):(e.consume(k),k===92?w:b)}function w(k){return k===40||k===41||k===92?(e.consume(k),b):b(k)}}function Jo(e,t,n,r,i,s){const o=this;let a=0,l;return u;function u(p){return e.enter(r),e.enter(i),e.consume(p),e.exit(i),e.enter(s),c}function c(p){return a>999||p===null||p===91||p===93&&!l||p===94&&!a&&"_hiddenFootnoteSupport"in o.parser.constructs?n(p):p===93?(e.exit(s),e.enter(i),e.consume(p),e.exit(i),e.exit(r),t):G(p)?(e.enter("lineEnding"),e.consume(p),e.exit("lineEnding"),c):(e.enter("chunkString",{contentType:"string"}),f(p))}function f(p){return p===null||p===91||p===93||G(p)||a++>999?(e.exit("chunkString"),c(p)):(e.consume(p),l||(l=!se(p)),p===92?d:f)}function d(p){return p===91||p===92||p===93?(e.consume(p),a++,f):f(p)}}function Zo(e,t,n,r,i,s){let o;return a;function a(d){return d===34||d===39||d===40?(e.enter(r),e.enter(i),e.consume(d),e.exit(i),o=d===40?41:d,l):n(d)}function l(d){return d===o?(e.enter(i),e.consume(d),e.exit(i),e.exit(r),t):(e.enter(s),u(d))}function u(d){return d===o?(e.exit(s),l(o)):d===null?n(d):G(d)?(e.enter("lineEnding"),e.consume(d),e.exit("lineEnding"),oe(e,u,"linePrefix")):(e.enter("chunkString",{contentType:"string"}),c(d))}function c(d){return d===o||d===null||G(d)?(e.exit("chunkString"),u(d)):(e.consume(d),d===92?f:c)}function f(d){return d===o||d===92?(e.consume(d),c):c(d)}}function on(e,t){let n;return r;function r(i){return G(i)?(e.enter("lineEnding"),e.consume(i),e.exit("lineEnding"),n=!0,r):se(i)?oe(e,r,n?"linePrefix":"lineSuffix")(i):t(i)}}const np={name:"definition",tokenize:ip},rp={partial:!0,tokenize:sp};function ip(e,t,n){const r=this;let i;return s;function s(p){return e.enter("definition"),o(p)}function o(p){return Jo.call(r,e,a,n,"definitionLabel","definitionLabelMarker","definitionLabelString")(p)}function a(p){return i=Ze(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)),p===58?(e.enter("definitionMarker"),e.consume(p),e.exit("definitionMarker"),l):n(p)}function l(p){return he(p)?on(e,u)(p):u(p)}function u(p){return Qo(e,c,n,"definitionDestination","definitionDestinationLiteral","definitionDestinationLiteralMarker","definitionDestinationRaw","definitionDestinationString")(p)}function c(p){return e.attempt(rp,f,f)(p)}function f(p){return se(p)?oe(e,d,"whitespace")(p):d(p)}function d(p){return p===null||G(p)?(e.exit("definition"),r.parser.defined.push(i),t(p)):n(p)}}function sp(e,t,n){return r;function r(a){return he(a)?on(e,i)(a):n(a)}function i(a){return Zo(e,s,n,"definitionTitle","definitionTitleMarker","definitionTitleString")(a)}function s(a){return se(a)?oe(e,o,"whitespace")(a):o(a)}function o(a){return a===null||G(a)?t(a):n(a)}}const op={name:"hardBreakEscape",tokenize:ap};function ap(e,t,n){return r;function r(s){return e.enter("hardBreakEscape"),e.consume(s),i}function i(s){return G(s)?(e.exit("hardBreakEscape"),t(s)):n(s)}}const lp={name:"headingAtx",resolve:up,tokenize:cp};function up(e,t){let n=e.length-2,r=3,i,s;return e[r][1].type==="whitespace"&&(r+=2),n-2>r&&e[n][1].type==="whitespace"&&(n-=2),e[n][1].type==="atxHeadingSequence"&&(r===n-1||n-4>r&&e[n-2][1].type==="whitespace")&&(n-=r+1===n?2:4),n>r&&(i={type:"atxHeadingText",start:e[r][1].start,end:e[n][1].end},s={type:"chunkText",start:e[r][1].start,end:e[n][1].end,contentType:"text"},$e(e,r,n-r+1,[["enter",i,t],["enter",s,t],["exit",s,t],["exit",i,t]])),e}function cp(e,t,n){let r=0;return i;function i(c){return e.enter("atxHeading"),s(c)}function s(c){return e.enter("atxHeadingSequence"),o(c)}function o(c){return c===35&&r++<6?(e.consume(c),o):c===null||he(c)?(e.exit("atxHeadingSequence"),a(c)):n(c)}function a(c){return c===35?(e.enter("atxHeadingSequence"),l(c)):c===null||G(c)?(e.exit("atxHeading"),t(c)):se(c)?oe(e,a,"whitespace")(c):(e.enter("atxHeadingText"),u(c))}function l(c){return c===35?(e.consume(c),l):(e.exit("atxHeadingSequence"),a(c))}function u(c){return c===null||c===35||he(c)?(e.exit("atxHeadingText"),a(c)):(e.consume(c),u)}}const fp=["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","h1","h2","h3","h4","h5","h6","head","header","hr","html","iframe","legend","li","link","main","menu","menuitem","nav","noframes","ol","optgroup","option","p","param","search","section","summary","table","tbody","td","tfoot","th","thead","title","tr","track","ul"],ls=["pre","script","style","textarea"],hp={concrete:!0,name:"htmlFlow",resolveTo:mp,tokenize:gp},pp={partial:!0,tokenize:yp},dp={partial:!0,tokenize:xp};function mp(e){let t=e.length;for(;t--&&!(e[t][0]==="enter"&&e[t][1].type==="htmlFlow"););return t>1&&e[t-2][1].type==="linePrefix"&&(e[t][1].start=e[t-2][1].start,e[t+1][1].start=e[t-2][1].start,e.splice(t-2,2)),e}function gp(e,t,n){const r=this;let i,s,o,a,l;return u;function u(y){return c(y)}function c(y){return e.enter("htmlFlow"),e.enter("htmlFlowData"),e.consume(y),f}function f(y){return y===33?(e.consume(y),d):y===47?(e.consume(y),s=!0,b):y===63?(e.consume(y),i=3,r.interrupt?t:x):Me(y)?(e.consume(y),o=String.fromCharCode(y),w):n(y)}function d(y){return y===45?(e.consume(y),i=2,p):y===91?(e.consume(y),i=5,a=0,g):Me(y)?(e.consume(y),i=4,r.interrupt?t:x):n(y)}function p(y){return y===45?(e.consume(y),r.interrupt?t:x):n(y)}function g(y){const Q="CDATA[";return y===Q.charCodeAt(a++)?(e.consume(y),a===Q.length?r.interrupt?t:A:g):n(y)}function b(y){return Me(y)?(e.consume(y),o=String.fromCharCode(y),w):n(y)}function w(y){if(y===null||y===47||y===62||he(y)){const Q=y===47,ne=o.toLowerCase();return!Q&&!s&&ls.includes(ne)?(i=1,r.interrupt?t(y):A(y)):fp.includes(o.toLowerCase())?(i=6,Q?(e.consume(y),k):r.interrupt?t(y):A(y)):(i=7,r.interrupt&&!r.parser.lazy[r.now().line]?n(y):s?C(y):E(y))}return y===45||Re(y)?(e.consume(y),o+=String.fromCharCode(y),w):n(y)}function k(y){return y===62?(e.consume(y),r.interrupt?t:A):n(y)}function C(y){return se(y)?(e.consume(y),C):v(y)}function E(y){return y===47?(e.consume(y),v):y===58||y===95||Me(y)?(e.consume(y),N):se(y)?(e.consume(y),E):v(y)}function N(y){return y===45||y===46||y===58||y===95||Re(y)?(e.consume(y),N):_(y)}function _(y){return y===61?(e.consume(y),S):se(y)?(e.consume(y),_):E(y)}function S(y){return y===null||y===60||y===61||y===62||y===96?n(y):y===34||y===39?(e.consume(y),l=y,M):se(y)?(e.consume(y),S):U(y)}function M(y){return y===l?(e.consume(y),l=null,O):y===null||G(y)?n(y):(e.consume(y),M)}function U(y){return y===null||y===34||y===39||y===47||y===60||y===61||y===62||y===96||he(y)?_(y):(e.consume(y),U)}function O(y){return y===47||y===62||se(y)?E(y):n(y)}function v(y){return y===62?(e.consume(y),L):n(y)}function L(y){return y===null||G(y)?A(y):se(y)?(e.consume(y),L):n(y)}function A(y){return y===45&&i===2?(e.consume(y),R):y===60&&i===1?(e.consume(y),D):y===62&&i===4?(e.consume(y),V):y===63&&i===3?(e.consume(y),x):y===93&&i===5?(e.consume(y),z):G(y)&&(i===6||i===7)?(e.exit("htmlFlowData"),e.check(pp,X,F)(y)):y===null||G(y)?(e.exit("htmlFlowData"),F(y)):(e.consume(y),A)}function F(y){return e.check(dp,T,X)(y)}function T(y){return e.enter("lineEnding"),e.consume(y),e.exit("lineEnding"),j}function j(y){return y===null||G(y)?F(y):(e.enter("htmlFlowData"),A(y))}function R(y){return y===45?(e.consume(y),x):A(y)}function D(y){return y===47?(e.consume(y),o="",H):A(y)}function H(y){if(y===62){const Q=o.toLowerCase();return ls.includes(Q)?(e.consume(y),V):A(y)}return Me(y)&&o.length<8?(e.consume(y),o+=String.fromCharCode(y),H):A(y)}function z(y){return y===93?(e.consume(y),x):A(y)}function x(y){return y===62?(e.consume(y),V):y===45&&i===2?(e.consume(y),x):A(y)}function V(y){return y===null||G(y)?(e.exit("htmlFlowData"),X(y)):(e.consume(y),V)}function X(y){return e.exit("htmlFlow"),t(y)}}function xp(e,t,n){const r=this;return i;function i(o){return G(o)?(e.enter("lineEnding"),e.consume(o),e.exit("lineEnding"),s):n(o)}function s(o){return r.parser.lazy[r.now().line]?n(o):t(o)}}function yp(e,t,n){return r;function r(i){return e.enter("lineEnding"),e.consume(i),e.exit("lineEnding"),e.attempt(fn,t,n)}}const bp={name:"htmlText",tokenize:kp};function kp(e,t,n){const r=this;let i,s,o;return a;function a(x){return e.enter("htmlText"),e.enter("htmlTextData"),e.consume(x),l}function l(x){return x===33?(e.consume(x),u):x===47?(e.consume(x),_):x===63?(e.consume(x),E):Me(x)?(e.consume(x),U):n(x)}function u(x){return x===45?(e.consume(x),c):x===91?(e.consume(x),s=0,g):Me(x)?(e.consume(x),C):n(x)}function c(x){return x===45?(e.consume(x),p):n(x)}function f(x){return x===null?n(x):x===45?(e.consume(x),d):G(x)?(o=f,D(x)):(e.consume(x),f)}function d(x){return x===45?(e.consume(x),p):f(x)}function p(x){return x===62?R(x):x===45?d(x):f(x)}function g(x){const V="CDATA[";return x===V.charCodeAt(s++)?(e.consume(x),s===V.length?b:g):n(x)}function b(x){return x===null?n(x):x===93?(e.consume(x),w):G(x)?(o=b,D(x)):(e.consume(x),b)}function w(x){return x===93?(e.consume(x),k):b(x)}function k(x){return x===62?R(x):x===93?(e.consume(x),k):b(x)}function C(x){return x===null||x===62?R(x):G(x)?(o=C,D(x)):(e.consume(x),C)}function E(x){return x===null?n(x):x===63?(e.consume(x),N):G(x)?(o=E,D(x)):(e.consume(x),E)}function N(x){return x===62?R(x):E(x)}function _(x){return Me(x)?(e.consume(x),S):n(x)}function S(x){return x===45||Re(x)?(e.consume(x),S):M(x)}function M(x){return G(x)?(o=M,D(x)):se(x)?(e.consume(x),M):R(x)}function U(x){return x===45||Re(x)?(e.consume(x),U):x===47||x===62||he(x)?O(x):n(x)}function O(x){return x===47?(e.consume(x),R):x===58||x===95||Me(x)?(e.consume(x),v):G(x)?(o=O,D(x)):se(x)?(e.consume(x),O):R(x)}function v(x){return x===45||x===46||x===58||x===95||Re(x)?(e.consume(x),v):L(x)}function L(x){return x===61?(e.consume(x),A):G(x)?(o=L,D(x)):se(x)?(e.consume(x),L):O(x)}function A(x){return x===null||x===60||x===61||x===62||x===96?n(x):x===34||x===39?(e.consume(x),i=x,F):G(x)?(o=A,D(x)):se(x)?(e.consume(x),A):(e.consume(x),T)}function F(x){return x===i?(e.consume(x),i=void 0,j):x===null?n(x):G(x)?(o=F,D(x)):(e.consume(x),F)}function T(x){return x===null||x===34||x===39||x===60||x===61||x===96?n(x):x===47||x===62||he(x)?O(x):(e.consume(x),T)}function j(x){return x===47||x===62||he(x)?O(x):n(x)}function R(x){return x===62?(e.consume(x),e.exit("htmlTextData"),e.exit("htmlText"),t):n(x)}function D(x){return e.exit("htmlTextData"),e.enter("lineEnding"),e.consume(x),e.exit("lineEnding"),H}function H(x){return se(x)?oe(e,z,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(x):z(x)}function z(x){return e.enter("htmlTextData"),o(x)}}const di={name:"labelEnd",resolveAll:vp,resolveTo:Ep,tokenize:Tp},wp={tokenize:jp},Sp={tokenize:Ap},Cp={tokenize:Ip};function vp(e){let t=-1;const n=[];for(;++t<e.length;){const r=e[t][1];if(n.push(e[t]),r.type==="labelImage"||r.type==="labelLink"||r.type==="labelEnd"){const i=r.type==="labelImage"?4:2;r.type="data",t+=i}}return e.length!==n.length&&$e(e,0,e.length,n),e}function Ep(e,t){let n=e.length,r=0,i,s,o,a;for(;n--;)if(i=e[n][1],s){if(i.type==="link"||i.type==="labelLink"&&i._inactive)break;e[n][0]==="enter"&&i.type==="labelLink"&&(i._inactive=!0)}else if(o){if(e[n][0]==="enter"&&(i.type==="labelImage"||i.type==="labelLink")&&!i._balanced&&(s=n,i.type!=="labelLink")){r=2;break}}else i.type==="labelEnd"&&(o=n);const l={type:e[s][1].type==="labelLink"?"link":"image",start:{...e[s][1].start},end:{...e[e.length-1][1].end}},u={type:"label",start:{...e[s][1].start},end:{...e[o][1].end}},c={type:"labelText",start:{...e[s+r+2][1].end},end:{...e[o-2][1].start}};return a=[["enter",l,t],["enter",u,t]],a=We(a,e.slice(s+1,s+r+3)),a=We(a,[["enter",c,t]]),a=We(a,Xn(t.parser.constructs.insideSpan.null,e.slice(s+r+4,o-3),t)),a=We(a,[["exit",c,t],e[o-2],e[o-1],["exit",u,t]]),a=We(a,e.slice(o+1)),a=We(a,[["exit",l,t]]),$e(e,s,e.length,a),e}function Tp(e,t,n){const r=this;let i=r.events.length,s,o;for(;i--;)if((r.events[i][1].type==="labelImage"||r.events[i][1].type==="labelLink")&&!r.events[i][1]._balanced){s=r.events[i][1];break}return a;function a(d){return s?s._inactive?f(d):(o=r.parser.defined.includes(Ze(r.sliceSerialize({start:s.end,end:r.now()}))),e.enter("labelEnd"),e.enter("labelMarker"),e.consume(d),e.exit("labelMarker"),e.exit("labelEnd"),l):n(d)}function l(d){return d===40?e.attempt(wp,c,o?c:f)(d):d===91?e.attempt(Sp,c,o?u:f)(d):o?c(d):f(d)}function u(d){return e.attempt(Cp,c,f)(d)}function c(d){return t(d)}function f(d){return s._balanced=!0,n(d)}}function jp(e,t,n){return r;function r(f){return e.enter("resource"),e.enter("resourceMarker"),e.consume(f),e.exit("resourceMarker"),i}function i(f){return he(f)?on(e,s)(f):s(f)}function s(f){return f===41?c(f):Qo(e,o,a,"resourceDestination","resourceDestinationLiteral","resourceDestinationLiteralMarker","resourceDestinationRaw","resourceDestinationString",32)(f)}function o(f){return he(f)?on(e,l)(f):c(f)}function a(f){return n(f)}function l(f){return f===34||f===39||f===40?Zo(e,u,n,"resourceTitle","resourceTitleMarker","resourceTitleString")(f):c(f)}function u(f){return he(f)?on(e,c)(f):c(f)}function c(f){return f===41?(e.enter("resourceMarker"),e.consume(f),e.exit("resourceMarker"),e.exit("resource"),t):n(f)}}function Ap(e,t,n){const r=this;return i;function i(a){return Jo.call(r,e,s,o,"reference","referenceMarker","referenceString")(a)}function s(a){return r.parser.defined.includes(Ze(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)))?t(a):n(a)}function o(a){return n(a)}}function Ip(e,t,n){return r;function r(s){return e.enter("reference"),e.enter("referenceMarker"),e.consume(s),e.exit("referenceMarker"),i}function i(s){return s===93?(e.enter("referenceMarker"),e.consume(s),e.exit("referenceMarker"),e.exit("reference"),t):n(s)}}const Rp={name:"labelStartImage",resolveAll:di.resolveAll,tokenize:Np};function Np(e,t,n){const r=this;return i;function i(a){return e.enter("labelImage"),e.enter("labelImageMarker"),e.consume(a),e.exit("labelImageMarker"),s}function s(a){return a===91?(e.enter("labelMarker"),e.consume(a),e.exit("labelMarker"),e.exit("labelImage"),o):n(a)}function o(a){return a===94&&"_hiddenFootnoteSupport"in r.parser.constructs?n(a):t(a)}}const Lp={name:"labelStartLink",resolveAll:di.resolveAll,tokenize:Mp};function Mp(e,t,n){const r=this;return i;function i(o){return e.enter("labelLink"),e.enter("labelMarker"),e.consume(o),e.exit("labelMarker"),e.exit("labelLink"),s}function s(o){return o===94&&"_hiddenFootnoteSupport"in r.parser.constructs?n(o):t(o)}}const cr={name:"lineEnding",tokenize:Dp};function Dp(e,t){return n;function n(r){return e.enter("lineEnding"),e.consume(r),e.exit("lineEnding"),oe(e,t,"linePrefix")}}const Sn={name:"thematicBreak",tokenize:zp};function zp(e,t,n){let r=0,i;return s;function s(u){return e.enter("thematicBreak"),o(u)}function o(u){return i=u,a(u)}function a(u){return u===i?(e.enter("thematicBreakSequence"),l(u)):r>=3&&(u===null||G(u))?(e.exit("thematicBreak"),t(u)):n(u)}function l(u){return u===i?(e.consume(u),r++,l):(e.exit("thematicBreakSequence"),se(u)?oe(e,a,"whitespace")(u):a(u))}}const _e={continuation:{tokenize:Fp},exit:Bp,name:"list",tokenize:Op},Pp={partial:!0,tokenize:Hp},_p={partial:!0,tokenize:$p};function Op(e,t,n){const r=this,i=r.events[r.events.length-1];let s=i&&i[1].type==="linePrefix"?i[2].sliceSerialize(i[1],!0).length:0,o=0;return a;function a(p){const g=r.containerState.type||(p===42||p===43||p===45?"listUnordered":"listOrdered");if(g==="listUnordered"?!r.containerState.marker||p===r.containerState.marker:zr(p)){if(r.containerState.type||(r.containerState.type=g,e.enter(g,{_container:!0})),g==="listUnordered")return e.enter("listItemPrefix"),p===42||p===45?e.check(Sn,n,u)(p):u(p);if(!r.interrupt||p===49)return e.enter("listItemPrefix"),e.enter("listItemValue"),l(p)}return n(p)}function l(p){return zr(p)&&++o<10?(e.consume(p),l):(!r.interrupt||o<2)&&(r.containerState.marker?p===r.containerState.marker:p===41||p===46)?(e.exit("listItemValue"),u(p)):n(p)}function u(p){return e.enter("listItemMarker"),e.consume(p),e.exit("listItemMarker"),r.containerState.marker=r.containerState.marker||p,e.check(fn,r.interrupt?n:c,e.attempt(Pp,d,f))}function c(p){return r.containerState.initialBlankLine=!0,s++,d(p)}function f(p){return se(p)?(e.enter("listItemPrefixWhitespace"),e.consume(p),e.exit("listItemPrefixWhitespace"),d):n(p)}function d(p){return r.containerState.size=s+r.sliceSerialize(e.exit("listItemPrefix"),!0).length,t(p)}}function Fp(e,t,n){const r=this;return r.containerState._closeFlow=void 0,e.check(fn,i,s);function i(a){return r.containerState.furtherBlankLines=r.containerState.furtherBlankLines||r.containerState.initialBlankLine,oe(e,t,"listItemIndent",r.containerState.size+1)(a)}function s(a){return r.containerState.furtherBlankLines||!se(a)?(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,o(a)):(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,e.attempt(_p,t,o)(a))}function o(a){return r.containerState._closeFlow=!0,r.interrupt=void 0,oe(e,e.attempt(_e,t,n),"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(a)}}function $p(e,t,n){const r=this;return oe(e,i,"listItemIndent",r.containerState.size+1);function i(s){const o=r.events[r.events.length-1];return o&&o[1].type==="listItemIndent"&&o[2].sliceSerialize(o[1],!0).length===r.containerState.size?t(s):n(s)}}function Bp(e){e.exit(this.containerState.type)}function Hp(e,t,n){const r=this;return oe(e,i,"listItemPrefixWhitespace",r.parser.constructs.disable.null.includes("codeIndented")?void 0:5);function i(s){const o=r.events[r.events.length-1];return!se(s)&&o&&o[1].type==="listItemPrefixWhitespace"?t(s):n(s)}}const us={name:"setextUnderline",resolveTo:Up,tokenize:qp};function Up(e,t){let n=e.length,r,i,s;for(;n--;)if(e[n][0]==="enter"){if(e[n][1].type==="content"){r=n;break}e[n][1].type==="paragraph"&&(i=n)}else e[n][1].type==="content"&&e.splice(n,1),!s&&e[n][1].type==="definition"&&(s=n);const o={type:"setextHeading",start:{...e[r][1].start},end:{...e[e.length-1][1].end}};return e[i][1].type="setextHeadingText",s?(e.splice(i,0,["enter",o,t]),e.splice(s+1,0,["exit",e[r][1],t]),e[r][1].end={...e[s][1].end}):e[r][1]=o,e.push(["exit",o,t]),e}function qp(e,t,n){const r=this;let i;return s;function s(u){let c=r.events.length,f;for(;c--;)if(r.events[c][1].type!=="lineEnding"&&r.events[c][1].type!=="linePrefix"&&r.events[c][1].type!=="content"){f=r.events[c][1].type==="paragraph";break}return!r.parser.lazy[r.now().line]&&(r.interrupt||f)?(e.enter("setextHeadingLine"),i=u,o(u)):n(u)}function o(u){return e.enter("setextHeadingLineSequence"),a(u)}function a(u){return u===i?(e.consume(u),a):(e.exit("setextHeadingLineSequence"),se(u)?oe(e,l,"lineSuffix")(u):l(u))}function l(u){return u===null||G(u)?(e.exit("setextHeadingLine"),t(u)):n(u)}}const Kp={tokenize:Wp};function Wp(e){const t=this,n=e.attempt(fn,r,e.attempt(this.parser.constructs.flowInitial,i,oe(e,e.attempt(this.parser.constructs.flow,i,e.attempt(Qh,i)),"linePrefix")));return n;function r(s){if(s===null){e.consume(s);return}return e.enter("lineEndingBlank"),e.consume(s),e.exit("lineEndingBlank"),t.currentConstruct=void 0,n}function i(s){if(s===null){e.consume(s);return}return e.enter("lineEnding"),e.consume(s),e.exit("lineEnding"),t.currentConstruct=void 0,n}}const Vp={resolveAll:ta()},Xp=ea("string"),Yp=ea("text");function ea(e){return{resolveAll:ta(e==="text"?Gp:void 0),tokenize:t};function t(n){const r=this,i=this.parser.constructs[e],s=n.attempt(i,o,a);return o;function o(c){return u(c)?s(c):a(c)}function a(c){if(c===null){n.consume(c);return}return n.enter("data"),n.consume(c),l}function l(c){return u(c)?(n.exit("data"),s(c)):(n.consume(c),l)}function u(c){if(c===null)return!0;const f=i[c];let d=-1;if(f)for(;++d<f.length;){const p=f[d];if(!p.previous||p.previous.call(r,r.previous))return!0}return!1}}}function ta(e){return t;function t(n,r){let i=-1,s;for(;++i<=n.length;)s===void 0?n[i]&&n[i][1].type==="data"&&(s=i,i++):(!n[i]||n[i][1].type!=="data")&&(i!==s+2&&(n[s][1].end=n[i-1][1].end,n.splice(s+2,i-s-2),i=s+2),s=void 0);return e?e(n,r):n}}function Gp(e,t){let n=0;for(;++n<=e.length;)if((n===e.length||e[n][1].type==="lineEnding")&&e[n-1][1].type==="data"){const r=e[n-1][1],i=t.sliceStream(r);let s=i.length,o=-1,a=0,l;for(;s--;){const u=i[s];if(typeof u=="string"){for(o=u.length;u.charCodeAt(o-1)===32;)a++,o--;if(o)break;o=-1}else if(u===-2)l=!0,a++;else if(u!==-1){s++;break}}if(t._contentTypeTextTrailing&&n===e.length&&(a=0),a){const u={type:n===e.length||l||a<2?"lineSuffix":"hardBreakTrailing",start:{_bufferIndex:s?o:r.start._bufferIndex+o,_index:r.start._index+s,line:r.end.line,column:r.end.column-a,offset:r.end.offset-a},end:{...r.end}};r.end={...u.start},r.start.offset===r.end.offset?Object.assign(r,u):(e.splice(n,0,["enter",u,t],["exit",u,t]),n+=2)}n++}return e}const Qp={42:_e,43:_e,45:_e,48:_e,49:_e,50:_e,51:_e,52:_e,53:_e,54:_e,55:_e,56:_e,57:_e,62:Vo},Jp={91:np},Zp={[-2]:ur,[-1]:ur,32:ur},ed={35:lp,42:Sn,45:[us,Sn],60:hp,61:us,95:Sn,96:as,126:as},td={38:Yo,92:Xo},nd={[-5]:cr,[-4]:cr,[-3]:cr,33:Rp,38:Yo,42:Pr,60:[Lh,bp],91:Lp,92:[op,Xo],93:di,95:Pr,96:Kh},rd={null:[Pr,Vp]},id={null:[42,95]},sd={null:[]},od=Object.freeze(Object.defineProperty({__proto__:null,attentionMarkers:id,contentInitial:Jp,disable:sd,document:Qp,flow:ed,flowInitial:Zp,insideSpan:rd,string:td,text:nd},Symbol.toStringTag,{value:"Module"}));function ad(e,t,n){let r={_bufferIndex:-1,_index:0,line:n&&n.line||1,column:n&&n.column||1,offset:n&&n.offset||0};const i={},s=[];let o=[],a=[];const l={attempt:M(_),check:M(S),consume:C,enter:E,exit:N,interrupt:M(S,{interrupt:!0})},u={code:null,containerState:{},defineSkip:b,events:[],now:g,parser:e,previous:null,sliceSerialize:d,sliceStream:p,write:f};let c=t.tokenize.call(u,l);return t.resolveAll&&s.push(t),u;function f(L){return o=We(o,L),w(),o[o.length-1]!==null?[]:(U(t,0),u.events=Xn(s,u.events,u),u.events)}function d(L,A){return ud(p(L),A)}function p(L){return ld(o,L)}function g(){const{_bufferIndex:L,_index:A,line:F,column:T,offset:j}=r;return{_bufferIndex:L,_index:A,line:F,column:T,offset:j}}function b(L){i[L.line]=L.column,v()}function w(){let L;for(;r._index<o.length;){const A=o[r._index];if(typeof A=="string")for(L=r._index,r._bufferIndex<0&&(r._bufferIndex=0);r._index===L&&r._bufferIndex<A.length;)k(A.charCodeAt(r._bufferIndex));else k(A)}}function k(L){c=c(L)}function C(L){G(L)?(r.line++,r.column=1,r.offset+=L===-3?2:1,v()):L!==-1&&(r.column++,r.offset++),r._bufferIndex<0?r._index++:(r._bufferIndex++,r._bufferIndex===o[r._index].length&&(r._bufferIndex=-1,r._index++)),u.previous=L}function E(L,A){const F=A||{};return F.type=L,F.start=g(),u.events.push(["enter",F,u]),a.push(F),F}function N(L){const A=a.pop();return A.end=g(),u.events.push(["exit",A,u]),A}function _(L,A){U(L,A.from)}function S(L,A){A.restore()}function M(L,A){return F;function F(T,j,R){let D,H,z,x;return Array.isArray(T)?X(T):"tokenize"in T?X([T]):V(T);function V(W){return me;function me(ge){const le=ge!==null&&W[ge],ie=ge!==null&&W.null,be=[...Array.isArray(le)?le:le?[le]:[],...Array.isArray(ie)?ie:ie?[ie]:[]];return X(be)(ge)}}function X(W){return D=W,H=0,W.length===0?R:y(W[H])}function y(W){return me;function me(ge){return x=O(),z=W,W.partial||(u.currentConstruct=W),W.name&&u.parser.constructs.disable.null.includes(W.name)?ne():W.tokenize.call(A?Object.assign(Object.create(u),A):u,l,Q,ne)(ge)}}function Q(W){return L(z,x),j}function ne(W){return x.restore(),++H<D.length?y(D[H]):R}}}function U(L,A){L.resolveAll&&!s.includes(L)&&s.push(L),L.resolve&&$e(u.events,A,u.events.length-A,L.resolve(u.events.slice(A),u)),L.resolveTo&&(u.events=L.resolveTo(u.events,u))}function O(){const L=g(),A=u.previous,F=u.currentConstruct,T=u.events.length,j=Array.from(a);return{from:T,restore:R};function R(){r=L,u.previous=A,u.currentConstruct=F,u.events.length=T,a=j,v()}}function v(){r.line in i&&r.column<2&&(r.column=i[r.line],r.offset+=i[r.line]-1)}}function ld(e,t){const n=t.start._index,r=t.start._bufferIndex,i=t.end._index,s=t.end._bufferIndex;let o;if(n===i)o=[e[n].slice(r,s)];else{if(o=e.slice(n,i),r>-1){const a=o[0];typeof a=="string"?o[0]=a.slice(r):o.shift()}s>0&&o.push(e[i].slice(0,s))}return o}function ud(e,t){let n=-1;const r=[];let i;for(;++n<e.length;){const s=e[n];let o;if(typeof s=="string")o=s;else switch(s){case-5:{o="\r";break}case-4:{o=`
|
|
62
|
+
`}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>${at(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),i=Ki(e);if(i===null)return r;e=i;let s='<a href="'+e+'"';return t&&(s+=' title="'+at(t)+'"'),s+=">"+r+"</a>",s}image({href:e,title:t,text:n,tokens:r}){r&&(n=this.parser.parseInline(r,this.parser.textRenderer));let i=Ki(e);if(i===null)return at(n);e=i;let s=`<img src="${e}" alt="${n}"`;return t&&(s+=` title="${at(t)}"`),s+=">",s}text(e){return"tokens"in e&&e.tokens?this.parser.parseInline(e.tokens):"escaped"in e&&e.escaped?e.text:at(e.text)}},ai=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}},Je=class Mr{options;renderer;textRenderer;constructor(t){this.options=t||Dt,this.options.renderer=this.options.renderer||new Dn,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new ai}static parse(t,n){return new Mr(n).parse(t)}static parseInline(t,n){return new Mr(n).parseInline(t)}parse(t){let n="";for(let r=0;r<t.length;r++){let i=t[r];if(this.options.extensions?.renderers?.[i.type]){let o=i,a=this.options.extensions.renderers[o.type].call({parser:this},o);if(a!==!1||!["space","hr","heading","code","table","blockquote","list","html","def","paragraph","text"].includes(o.type)){n+=a||"";continue}}let s=i;switch(s.type){case"space":{n+=this.renderer.space(s);break}case"hr":{n+=this.renderer.hr(s);break}case"heading":{n+=this.renderer.heading(s);break}case"code":{n+=this.renderer.code(s);break}case"table":{n+=this.renderer.table(s);break}case"blockquote":{n+=this.renderer.blockquote(s);break}case"list":{n+=this.renderer.list(s);break}case"checkbox":{n+=this.renderer.checkbox(s);break}case"html":{n+=this.renderer.html(s);break}case"def":{n+=this.renderer.def(s);break}case"paragraph":{n+=this.renderer.paragraph(s);break}case"text":{n+=this.renderer.text(s);break}default:{let o='Token with "'+s.type+'" type was not found.';if(this.options.silent)return console.error(o),"";throw new Error(o)}}}return n}parseInline(t,n=this.renderer){let r="";for(let i=0;i<t.length;i++){let s=t[i];if(this.options.extensions?.renderers?.[s.type]){let a=this.options.extensions.renderers[s.type].call({parser:this},s);if(a!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(s.type)){r+=a||"";continue}}let o=s;switch(o.type){case"escape":{r+=n.text(o);break}case"html":{r+=n.html(o);break}case"link":{r+=n.link(o);break}case"image":{r+=n.image(o);break}case"checkbox":{r+=n.checkbox(o);break}case"strong":{r+=n.strong(o);break}case"em":{r+=n.em(o);break}case"codespan":{r+=n.codespan(o);break}case"br":{r+=n.br(o);break}case"del":{r+=n.del(o);break}case"text":{r+=n.text(o);break}default:{let a='Token with "'+o.type+'" type was not found.';if(this.options.silent)return console.error(a),"";throw new Error(a)}}}return r}},en=class{options;block;constructor(e){this.options=e||Dt}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens","emStrongMask"]);static passThroughHooksRespectAsync=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(e){return e}postprocess(e){return e}processAllTokens(e){return e}emStrongMask(e){return e}provideLexer(){return this.block?Qe.lex:Qe.lexInline}provideParser(){return this.block?Je.parse:Je.parseInline}},Bf=class{defaults=Zr();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=Je;Renderer=Dn;TextRenderer=ai;Lexer=Qe;Tokenizer=Mn;Hooks=en;constructor(...e){this.use(...e)}walkTokens(e,t){let n=[];for(let r of e)switch(n=n.concat(t.call(this,r)),r.type){case"table":{let i=r;for(let s of i.header)n=n.concat(this.walkTokens(s.tokens,t));for(let s of i.rows)for(let o of s)n=n.concat(this.walkTokens(o.tokens,t));break}case"list":{let i=r;n=n.concat(this.walkTokens(i.items,t));break}default:{let i=r;this.defaults.extensions?.childTokens?.[i.type]?this.defaults.extensions.childTokens[i.type].forEach(s=>{let o=i[s].flat(1/0);n=n.concat(this.walkTokens(o,t))}):i.tokens&&(n=n.concat(this.walkTokens(i.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(i=>{if(!i.name)throw new Error("extension name required");if("renderer"in i){let s=t.renderers[i.name];s?t.renderers[i.name]=function(...o){let a=i.renderer.apply(this,o);return a===!1&&(a=s.apply(this,o)),a}:t.renderers[i.name]=i.renderer}if("tokenizer"in i){if(!i.level||i.level!=="block"&&i.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");let s=t[i.level];s?s.unshift(i.tokenizer):t[i.level]=[i.tokenizer],i.start&&(i.level==="block"?t.startBlock?t.startBlock.push(i.start):t.startBlock=[i.start]:i.level==="inline"&&(t.startInline?t.startInline.push(i.start):t.startInline=[i.start]))}"childTokens"in i&&i.childTokens&&(t.childTokens[i.name]=i.childTokens)}),r.extensions=t),n.renderer){let i=this.defaults.renderer||new Dn(this.defaults);for(let s in n.renderer){if(!(s in i))throw new Error(`renderer '${s}' does not exist`);if(["options","parser"].includes(s))continue;let o=s,a=n.renderer[o],l=i[o];i[o]=(...u)=>{let c=a.apply(i,u);return c===!1&&(c=l.apply(i,u)),c||""}}r.renderer=i}if(n.tokenizer){let i=this.defaults.tokenizer||new Mn(this.defaults);for(let s in n.tokenizer){if(!(s in i))throw new Error(`tokenizer '${s}' does not exist`);if(["options","rules","lexer"].includes(s))continue;let o=s,a=n.tokenizer[o],l=i[o];i[o]=(...u)=>{let c=a.apply(i,u);return c===!1&&(c=l.apply(i,u)),c}}r.tokenizer=i}if(n.hooks){let i=this.defaults.hooks||new en;for(let s in n.hooks){if(!(s in i))throw new Error(`hook '${s}' does not exist`);if(["options","block"].includes(s))continue;let o=s,a=n.hooks[o],l=i[o];en.passThroughHooks.has(s)?i[o]=u=>{if(this.defaults.async&&en.passThroughHooksRespectAsync.has(s))return(async()=>{let f=await a.call(i,u);return l.call(i,f)})();let c=a.call(i,u);return l.call(i,c)}:i[o]=(...u)=>{if(this.defaults.async)return(async()=>{let f=await a.apply(i,u);return f===!1&&(f=await l.apply(i,u)),f})();let c=a.apply(i,u);return c===!1&&(c=l.apply(i,u)),c}}r.hooks=i}if(n.walkTokens){let i=this.defaults.walkTokens,s=n.walkTokens;r.walkTokens=function(o){let a=[];return a.push(s.call(this,o)),i&&(a=a.concat(i.call(this,o))),a}}this.defaults={...this.defaults,...r}}),this}setOptions(e){return this.defaults={...this.defaults,...e},this}lexer(e,t){return Qe.lex(e,t??this.defaults)}parser(e,t){return Je.parse(e,t??this.defaults)}parseMarkdown(e){return(t,n)=>{let r={...n},i={...this.defaults,...r},s=this.onError(!!i.silent,!!i.async);if(this.defaults.async===!0&&r.async===!1)return s(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 s(new Error("marked(): input parameter is undefined or null"));if(typeof t!="string")return s(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(t)+", string expected"));if(i.hooks&&(i.hooks.options=i,i.hooks.block=e),i.async)return(async()=>{let o=i.hooks?await i.hooks.preprocess(t):t,a=await(i.hooks?await i.hooks.provideLexer():e?Qe.lex:Qe.lexInline)(o,i),l=i.hooks?await i.hooks.processAllTokens(a):a;i.walkTokens&&await Promise.all(this.walkTokens(l,i.walkTokens));let u=await(i.hooks?await i.hooks.provideParser():e?Je.parse:Je.parseInline)(l,i);return i.hooks?await i.hooks.postprocess(u):u})().catch(s);try{i.hooks&&(t=i.hooks.preprocess(t));let o=(i.hooks?i.hooks.provideLexer():e?Qe.lex:Qe.lexInline)(t,i);i.hooks&&(o=i.hooks.processAllTokens(o)),i.walkTokens&&this.walkTokens(o,i.walkTokens);let a=(i.hooks?i.hooks.provideParser():e?Je.parse:Je.parseInline)(o,i);return i.hooks&&(a=i.hooks.postprocess(a)),a}catch(o){return s(o)}}}onError(e,t){return n=>{if(n.message+=`
|
|
63
|
+
Please report this to https://github.com/markedjs/marked.`,e){let r="<p>An error occurred:</p><pre>"+at(n.message+"",!0)+"</pre>";return t?Promise.resolve(r):r}if(t)return Promise.reject(n);throw n}}},Lt=new Bf;function ce(e,t){return Lt.parse(e,t)}ce.options=ce.setOptions=function(e){return Lt.setOptions(e),ce.defaults=Lt.defaults,jo(ce.defaults),ce};ce.getDefaults=Zr;ce.defaults=Dt;ce.use=function(...e){return Lt.use(...e),ce.defaults=Lt.defaults,jo(ce.defaults),ce};ce.walkTokens=function(e,t){return Lt.walkTokens(e,t)};ce.parseInline=Lt.parseInline;ce.Parser=Je;ce.parser=Je.parse;ce.Renderer=Dn;ce.TextRenderer=ai;ce.Lexer=Qe;ce.lexer=Qe.lex;ce.Tokenizer=Mn;ce.Hooks=en;ce.parse=ce;ce.options;ce.setOptions;ce.use;ce.walkTokens;ce.parseInline;Je.parse;Qe.lex;const Hf=/^[$_\p{ID_Start}][$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,Uf=/^[$_\p{ID_Start}][-$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,qf={};function Xi(e,t){return(qf.jsx?Uf:Hf).test(e)}var Ot={},ar,Yi;function Kf(){if(Yi)return ar;Yi=1;var e=/\/\*[^*]*\*+([^/*][^*]*\*+)*\//g,t=/\n/g,n=/^\s*/,r=/^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/,i=/^:\s*/,s=/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^)]*?\)|[^};])+)/,o=/^[;\s]*/,a=/^\s+|\s+$/g,l=`
|
|
64
|
+
`,u="/",c="*",f="",d="comment",p="declaration";function g(w,k){if(typeof w!="string")throw new TypeError("First argument must be a string");if(!w)return[];k=k||{};var S=1,v=1;function R(j){var T=j.match(t);T&&(S+=T.length);var D=j.lastIndexOf(l);v=~D?j.length-D:v+j.length}function M(){var j={line:S,column:v};return function(T){return T.position=new C(j),F(),T}}function C(j){this.start=j,this.end={line:S,column:v},this.source=k.source}C.prototype.content=w;function z(j){var T=new Error(k.source+":"+S+":"+v+": "+j);if(T.reason=j,T.filename=k.source,T.line=S,T.column=v,T.source=w,!k.silent)throw T}function U(j){var T=j.exec(w);if(T){var D=T[0];return R(D),w=w.slice(D.length),T}}function F(){U(n)}function E(j){var T;for(j=j||[];T=N();)T!==!1&&j.push(T);return j}function N(){var j=M();if(!(u!=w.charAt(0)||c!=w.charAt(1))){for(var T=2;f!=w.charAt(T)&&(c!=w.charAt(T)||u!=w.charAt(T+1));)++T;if(T+=2,f===w.charAt(T-1))return z("End of comment missing");var D=w.slice(2,T-2);return v+=2,R(D),w=w.slice(T),v+=2,j({type:d,comment:D})}}function A(){var j=M(),T=U(r);if(T){if(N(),!U(i))return z("property missing ':'");var D=U(s),L=j({type:p,property:y(T[0].replace(e,f)),value:D?y(D[0].replace(e,f)):f});return U(o),L}}function P(){var j=[];E(j);for(var T;T=A();)T!==!1&&(j.push(T),E(j));return j}return F(),P()}function y(w){return w?w.replace(a,f):f}return ar=g,ar}var Gi;function Wf(){if(Gi)return Ot;Gi=1;var e=Ot&&Ot.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(Ot,"__esModule",{value:!0}),Ot.default=n;const t=e(Kf());function n(r,i){let s=null;if(!r||typeof r!="string")return s;const o=(0,t.default)(r),a=typeof i=="function";return o.forEach(l=>{if(l.type!=="declaration")return;const{property:u,value:c}=l;a?i(u,c,l):c&&(s=s||{},s[u]=c)}),s}return Ot}var Gt={},Qi;function Vf(){if(Qi)return Gt;Qi=1,Object.defineProperty(Gt,"__esModule",{value:!0}),Gt.camelCase=void 0;var e=/^--[a-zA-Z0-9_-]+$/,t=/-([a-z])/g,n=/^[^-]+$/,r=/^-(webkit|moz|ms|o|khtml)-/,i=/^-(ms)-/,s=function(u){return!u||n.test(u)||e.test(u)},o=function(u,c){return c.toUpperCase()},a=function(u,c){return"".concat(c,"-")},l=function(u,c){return c===void 0&&(c={}),s(u)?u:(u=u.toLowerCase(),c.reactCompat?u=u.replace(i,a):u=u.replace(r,a),u.replace(t,o))};return Gt.camelCase=l,Gt}var Qt,Ji;function Xf(){if(Ji)return Qt;Ji=1;var e=Qt&&Qt.__importDefault||function(i){return i&&i.__esModule?i:{default:i}},t=e(Wf()),n=Vf();function r(i,s){var o={};return!i||typeof i!="string"||(0,t.default)(i,function(a,l){a&&l&&(o[(0,n.camelCase)(a,s)]=l)}),o}return r.default=r,Qt=r,Qt}var Yf=Xf();const Gf=Ks(Yf),Oo=Fo("end"),li=Fo("start");function Fo(e){return t;function t(n){const r=n&&n.position&&n.position[e]||{};if(typeof r.line=="number"&&r.line>0&&typeof r.column=="number"&&r.column>0)return{line:r.line,column:r.column,offset:typeof r.offset=="number"&&r.offset>-1?r.offset:void 0}}}function Qf(e){const t=li(e),n=Oo(e);if(t&&n)return{start:t,end:n}}function sn(e){return!e||typeof e!="object"?"":"position"in e||"type"in e?Zi(e.position):"start"in e||"end"in e?Zi(e):"line"in e||"column"in e?Dr(e):""}function Dr(e){return es(e&&e.line)+":"+es(e&&e.column)}function Zi(e){return Dr(e&&e.start)+"-"+Dr(e&&e.end)}function es(e){return e&&typeof e=="number"?e:1}class Ne extends Error{constructor(t,n,r){super(),typeof n=="string"&&(r=n,n=void 0);let i="",s={},o=!1;if(n&&("line"in n&&"column"in n?s={place:n}:"start"in n&&"end"in n?s={place:n}:"type"in n?s={ancestors:[n],place:n.position}:s={...n}),typeof t=="string"?i=t:!s.cause&&t&&(o=!0,i=t.message,s.cause=t),!s.ruleId&&!s.source&&typeof r=="string"){const l=r.indexOf(":");l===-1?s.ruleId=r:(s.source=r.slice(0,l),s.ruleId=r.slice(l+1))}if(!s.place&&s.ancestors&&s.ancestors){const l=s.ancestors[s.ancestors.length-1];l&&(s.place=l.position)}const a=s.place&&"start"in s.place?s.place.start:s.place;this.ancestors=s.ancestors||void 0,this.cause=s.cause||void 0,this.column=a?a.column:void 0,this.fatal=void 0,this.file="",this.message=i,this.line=a?a.line:void 0,this.name=sn(s.place)||"1:1",this.place=s.place||void 0,this.reason=this.message,this.ruleId=s.ruleId||void 0,this.source=s.source||void 0,this.stack=o&&s.cause&&typeof s.cause.stack=="string"?s.cause.stack:"",this.actual=void 0,this.expected=void 0,this.note=void 0,this.url=void 0}}Ne.prototype.file="";Ne.prototype.name="";Ne.prototype.reason="";Ne.prototype.message="";Ne.prototype.stack="";Ne.prototype.column=void 0;Ne.prototype.line=void 0;Ne.prototype.ancestors=void 0;Ne.prototype.cause=void 0;Ne.prototype.fatal=void 0;Ne.prototype.place=void 0;Ne.prototype.ruleId=void 0;Ne.prototype.source=void 0;const ui={}.hasOwnProperty,Jf=new Map,Zf=/[A-Z]/g,eh=new Set(["table","tbody","thead","tfoot","tr"]),th=new Set(["td","th"]),$o="https://github.com/syntax-tree/hast-util-to-jsx-runtime";function nh(e,t){if(!t||t.Fragment===void 0)throw new TypeError("Expected `Fragment` in options");const n=t.filePath||void 0;let r;if(t.development){if(typeof t.jsxDEV!="function")throw new TypeError("Expected `jsxDEV` in options when `development: true`");r=ch(n,t.jsxDEV)}else{if(typeof t.jsx!="function")throw new TypeError("Expected `jsx` in production options");if(typeof t.jsxs!="function")throw new TypeError("Expected `jsxs` in production options");r=uh(n,t.jsx,t.jsxs)}const i={Fragment:t.Fragment,ancestors:[],components:t.components||{},create:r,elementAttributeNameCase:t.elementAttributeNameCase||"react",evaluater:t.createEvaluater?t.createEvaluater():void 0,filePath:n,ignoreInvalidStyle:t.ignoreInvalidStyle||!1,passKeys:t.passKeys!==!1,passNode:t.passNode||!1,schema:t.space==="svg"?Yr:tu,stylePropertyNameCase:t.stylePropertyNameCase||"dom",tableCellAlignToStyle:t.tableCellAlignToStyle!==!1},s=Bo(i,e,void 0);return s&&typeof s!="string"?s:i.create(e,i.Fragment,{children:s||void 0},void 0)}function Bo(e,t,n){if(t.type==="element")return rh(e,t,n);if(t.type==="mdxFlowExpression"||t.type==="mdxTextExpression")return ih(e,t);if(t.type==="mdxJsxFlowElement"||t.type==="mdxJsxTextElement")return oh(e,t,n);if(t.type==="mdxjsEsm")return sh(e,t);if(t.type==="root")return ah(e,t,n);if(t.type==="text")return lh(e,t)}function rh(e,t,n){const r=e.schema;let i=r;t.tagName.toLowerCase()==="svg"&&r.space==="html"&&(i=Yr,e.schema=i),e.ancestors.push(t);const s=Uo(e,t.tagName,!1),o=fh(e,t);let a=fi(e,t);return eh.has(t.tagName)&&(a=a.filter(function(l){return typeof l=="string"?!nu(l):!0})),Ho(e,o,s,t),ci(o,a),e.ancestors.pop(),e.schema=r,e.create(t,s,o,n)}function ih(e,t){if(t.data&&t.data.estree&&e.evaluater){const r=t.data.estree.body[0];return r.type,e.evaluater.evaluateExpression(r.expression)}ln(e,t.position)}function sh(e,t){if(t.data&&t.data.estree&&e.evaluater)return e.evaluater.evaluateProgram(t.data.estree);ln(e,t.position)}function oh(e,t,n){const r=e.schema;let i=r;t.name==="svg"&&r.space==="html"&&(i=Yr,e.schema=i),e.ancestors.push(t);const s=t.name===null?e.Fragment:Uo(e,t.name,!0),o=hh(e,t),a=fi(e,t);return Ho(e,o,s,t),ci(o,a),e.ancestors.pop(),e.schema=r,e.create(t,s,o,n)}function ah(e,t,n){const r={};return ci(r,fi(e,t)),e.create(t,e.Fragment,r,n)}function lh(e,t){return t.value}function Ho(e,t,n,r){typeof n!="string"&&n!==e.Fragment&&e.passNode&&(t.node=r)}function ci(e,t){if(t.length>0){const n=t.length>1?t:t[0];n&&(e.children=n)}}function uh(e,t,n){return r;function r(i,s,o,a){const u=Array.isArray(o.children)?n:t;return a?u(s,o,a):u(s,o)}}function ch(e,t){return n;function n(r,i,s,o){const a=Array.isArray(s.children),l=li(r);return t(i,s,o,a,{columnNumber:l?l.column-1:void 0,fileName:e,lineNumber:l?l.line:void 0},void 0)}}function fh(e,t){const n={};let r,i;for(i in t.properties)if(i!=="children"&&ui.call(t.properties,i)){const s=ph(e,i,t.properties[i]);if(s){const[o,a]=s;e.tableCellAlignToStyle&&o==="align"&&typeof a=="string"&&th.has(t.tagName)?r=a:n[o]=a}}if(r){const s=n.style||(n.style={});s[e.stylePropertyNameCase==="css"?"text-align":"textAlign"]=r}return n}function hh(e,t){const n={};for(const r of t.attributes)if(r.type==="mdxJsxExpressionAttribute")if(r.data&&r.data.estree&&e.evaluater){const s=r.data.estree.body[0];s.type;const o=s.expression;o.type;const a=o.properties[0];a.type,Object.assign(n,e.evaluater.evaluateExpression(a.argument))}else ln(e,t.position);else{const i=r.name;let s;if(r.value&&typeof r.value=="object")if(r.value.data&&r.value.data.estree&&e.evaluater){const a=r.value.data.estree.body[0];a.type,s=e.evaluater.evaluateExpression(a.expression)}else ln(e,t.position);else s=r.value===null?!0:r.value;n[i]=s}return n}function fi(e,t){const n=[];let r=-1;const i=e.passKeys?new Map:Jf;for(;++r<t.children.length;){const s=t.children[r];let o;if(e.passKeys){const l=s.type==="element"?s.tagName:s.type==="mdxJsxFlowElement"||s.type==="mdxJsxTextElement"?s.name:void 0;if(l){const u=i.get(l)||0;o=l+"-"+u,i.set(l,u+1)}}const a=Bo(e,s,o);a!==void 0&&n.push(a)}return n}function ph(e,t,n){const r=ru(e.schema,t);if(!(n==null||typeof n=="number"&&Number.isNaN(n))){if(Array.isArray(n)&&(n=r.commaSeparated?iu(n):su(n)),r.property==="style"){let i=typeof n=="object"?n:dh(e,String(n));return e.stylePropertyNameCase==="css"&&(i=mh(i)),["style",i]}return[e.elementAttributeNameCase==="react"&&r.space?uu[r.property]||r.property:r.attribute,n]}}function dh(e,t){try{return Gf(t,{reactCompat:!0})}catch(n){if(e.ignoreInvalidStyle)return{};const r=n,i=new Ne("Cannot parse `style` attribute",{ancestors:e.ancestors,cause:r,ruleId:"style",source:"hast-util-to-jsx-runtime"});throw i.file=e.filePath||void 0,i.url=$o+"#cannot-parse-style-attribute",i}}function Uo(e,t,n){let r;if(!n)r={type:"Literal",value:t};else if(t.includes(".")){const i=t.split(".");let s=-1,o;for(;++s<i.length;){const a=Xi(i[s])?{type:"Identifier",name:i[s]}:{type:"Literal",value:i[s]};o=o?{type:"MemberExpression",object:o,property:a,computed:!!(s&&a.type==="Literal"),optional:!1}:a}r=o}else r=Xi(t)&&!/^[a-z]/.test(t)?{type:"Identifier",name:t}:{type:"Literal",value:t};if(r.type==="Literal"){const i=r.value;return ui.call(e.components,i)?e.components[i]:i}if(e.evaluater)return e.evaluater.evaluateExpression(r);ln(e)}function ln(e,t){const n=new Ne("Cannot handle MDX estrees without `createEvaluater`",{ancestors:e.ancestors,place:t,ruleId:"mdx-estree",source:"hast-util-to-jsx-runtime"});throw n.file=e.filePath||void 0,n.url=$o+"#cannot-handle-mdx-estrees-without-createevaluater",n}function mh(e){const t={};let n;for(n in e)ui.call(e,n)&&(t[gh(n)]=e[n]);return t}function gh(e){let t=e.replace(Zf,xh);return t.slice(0,3)==="ms-"&&(t="-"+t),t}function xh(e){return"-"+e.toLowerCase()}const lr={action:["form"],cite:["blockquote","del","ins","q"],data:["object"],formAction:["button","input"],href:["a","area","base","link"],icon:["menuitem"],itemId:null,manifest:["html"],ping:["a","area"],poster:["video"],src:["audio","embed","iframe","img","input","script","source","track","video"]},yh={};function hi(e,t){const n=yh,r=typeof n.includeImageAlt=="boolean"?n.includeImageAlt:!0,i=typeof n.includeHtml=="boolean"?n.includeHtml:!0;return qo(e,r,i)}function qo(e,t,n){if(bh(e)){if("value"in e)return e.type==="html"&&!n?"":e.value;if(t&&"alt"in e&&e.alt)return e.alt;if("children"in e)return ts(e.children,t,n)}return Array.isArray(e)?ts(e,t,n):""}function ts(e,t,n){const r=[];let i=-1;for(;++i<e.length;)r[i]=qo(e[i],t,n);return r.join("")}function bh(e){return!!(e&&typeof e=="object")}const ns=document.createElement("i");function pi(e){const t="&"+e+";";ns.innerHTML=t;const n=ns.textContent;return n.charCodeAt(n.length-1)===59&&e!=="semi"||n===t?!1:n}function Ue(e,t,n,r){const i=e.length;let s=0,o;if(t<0?t=-t>i?0:i+t:t=t>i?i:t,n=n>0?n:0,r.length<1e4)o=Array.from(r),o.unshift(t,n),e.splice(...o);else for(n&&e.splice(t,n);s<r.length;)o=r.slice(s,s+1e4),o.unshift(t,0),e.splice(...o),s+=1e4,t+=1e4}function Xe(e,t){return e.length>0?(Ue(e,e.length,0,t),e):t}const rs={}.hasOwnProperty;function Ko(e){const t={};let n=-1;for(;++n<e.length;)kh(t,e[n]);return t}function kh(e,t){let n;for(n in t){const i=(rs.call(e,n)?e[n]:void 0)||(e[n]={}),s=t[n];let o;if(s)for(o in s){rs.call(i,o)||(i[o]=[]);const a=s[o];wh(i[o],Array.isArray(a)?a:a?[a]:[])}}}function wh(e,t){let n=-1;const r=[];for(;++n<t.length;)(t[n].add==="after"?e:r).push(t[n]);Ue(e,0,0,r)}function Wo(e,t){const n=Number.parseInt(e,t);return n<9||n===11||n>13&&n<32||n>126&&n<160||n>55295&&n<57344||n>64975&&n<65008||(n&65535)===65535||(n&65535)===65534||n>1114111?"�":String.fromCodePoint(n)}function tt(e){return e.replace(/[\t\n\r ]+/g," ").replace(/^ | $/g,"").toLowerCase().toUpperCase()}const Me=yt(/[A-Za-z]/),Re=yt(/[\dA-Za-z]/),Sh=yt(/[#-'*+\--9=?A-Z^-~]/);function zn(e){return e!==null&&(e<32||e===127)}const zr=yt(/\d/),Ch=yt(/[\dA-Fa-f]/),vh=yt(/[!-/:-@[-`{-~]/);function G(e){return e!==null&&e<-2}function fe(e){return e!==null&&(e<0||e===32)}function ie(e){return e===-2||e===-1||e===32}const Vn=yt(new RegExp("\\p{P}|\\p{S}","u")),Mt=yt(/\s/);function yt(e){return t;function t(n){return n!==null&&n>-1&&e.test(String.fromCharCode(n))}}function Kt(e){const t=[];let n=-1,r=0,i=0;for(;++n<e.length;){const s=e.charCodeAt(n);let o="";if(s===37&&Re(e.charCodeAt(n+1))&&Re(e.charCodeAt(n+2)))i=2;else if(s<128)/[!#$&-;=?-Z_a-z~]/.test(String.fromCharCode(s))||(o=String.fromCharCode(s));else if(s>55295&&s<57344){const a=e.charCodeAt(n+1);s<56320&&a>56319&&a<57344?(o=String.fromCharCode(s,a),i=1):o="�"}else o=String.fromCharCode(s);o&&(t.push(e.slice(r,n),encodeURIComponent(o)),r=n+i+1,o=""),i&&(n+=i,i=0)}return t.join("")+e.slice(r)}function oe(e,t,n,r){const i=r?r-1:Number.POSITIVE_INFINITY;let s=0;return o;function o(l){return ie(l)?(e.enter(n),a(l)):t(l)}function a(l){return ie(l)&&s++<i?(e.consume(l),a):(e.exit(n),t(l))}}const Eh={tokenize:Th};function Th(e){const t=e.attempt(this.parser.constructs.contentInitial,r,i);let n;return t;function r(a){if(a===null){e.consume(a);return}return e.enter("lineEnding"),e.consume(a),e.exit("lineEnding"),oe(e,t,"linePrefix")}function i(a){return e.enter("paragraph"),s(a)}function s(a){const l=e.enter("chunkText",{contentType:"text",previous:n});return n&&(n.next=l),n=l,o(a)}function o(a){if(a===null){e.exit("chunkText"),e.exit("paragraph"),e.consume(a);return}return G(a)?(e.consume(a),e.exit("chunkText"),s):(e.consume(a),o)}}const jh={tokenize:Ah},is={tokenize:Ih};function Ah(e){const t=this,n=[];let r=0,i,s,o;return a;function a(v){if(r<n.length){const R=n[r];return t.containerState=R[1],e.attempt(R[0].continuation,l,u)(v)}return u(v)}function l(v){if(r++,t.containerState._closeFlow){t.containerState._closeFlow=void 0,i&&S();const R=t.events.length;let M=R,C;for(;M--;)if(t.events[M][0]==="exit"&&t.events[M][1].type==="chunkFlow"){C=t.events[M][1].end;break}k(r);let z=R;for(;z<t.events.length;)t.events[z][1].end={...C},z++;return Ue(t.events,M+1,0,t.events.slice(R)),t.events.length=z,u(v)}return a(v)}function u(v){if(r===n.length){if(!i)return d(v);if(i.currentConstruct&&i.currentConstruct.concrete)return g(v);t.interrupt=!!(i.currentConstruct&&!i._gfmTableDynamicInterruptHack)}return t.containerState={},e.check(is,c,f)(v)}function c(v){return i&&S(),k(r),d(v)}function f(v){return t.parser.lazy[t.now().line]=r!==n.length,o=t.now().offset,g(v)}function d(v){return t.containerState={},e.attempt(is,p,g)(v)}function p(v){return r++,n.push([t.currentConstruct,t.containerState]),d(v)}function g(v){if(v===null){i&&S(),k(0),e.consume(v);return}return i=i||t.parser.flow(t.now()),e.enter("chunkFlow",{_tokenizer:i,contentType:"flow",previous:s}),y(v)}function y(v){if(v===null){w(e.exit("chunkFlow"),!0),k(0),e.consume(v);return}return G(v)?(e.consume(v),w(e.exit("chunkFlow")),r=0,t.interrupt=void 0,a):(e.consume(v),y)}function w(v,R){const M=t.sliceStream(v);if(R&&M.push(null),v.previous=s,s&&(s.next=v),s=v,i.defineSkip(v.start),i.write(M),t.parser.lazy[v.start.line]){let C=i.events.length;for(;C--;)if(i.events[C][1].start.offset<o&&(!i.events[C][1].end||i.events[C][1].end.offset>o))return;const z=t.events.length;let U=z,F,E;for(;U--;)if(t.events[U][0]==="exit"&&t.events[U][1].type==="chunkFlow"){if(F){E=t.events[U][1].end;break}F=!0}for(k(r),C=z;C<t.events.length;)t.events[C][1].end={...E},C++;Ue(t.events,U+1,0,t.events.slice(z)),t.events.length=C}}function k(v){let R=n.length;for(;R-- >v;){const M=n[R];t.containerState=M[1],M[0].exit.call(t,e)}n.length=v}function S(){i.write([null]),s=void 0,i=void 0,t.containerState._closeFlow=void 0}}function Ih(e,t,n){return oe(e,e.attempt(this.parser.constructs.document,t,n),"linePrefix",this.parser.constructs.disable.null.includes("codeIndented")?void 0:4)}function Ut(e){if(e===null||fe(e)||Mt(e))return 1;if(Vn(e))return 2}function Xn(e,t,n){const r=[];let i=-1;for(;++i<e.length;){const s=e[i].resolveAll;s&&!r.includes(s)&&(t=s(t,n),r.push(s))}return t}const Pr={name:"attention",resolveAll:Rh,tokenize:Nh};function Rh(e,t){let n=-1,r,i,s,o,a,l,u,c;for(;++n<e.length;)if(e[n][0]==="enter"&&e[n][1].type==="attentionSequence"&&e[n][1]._close){for(r=n;r--;)if(e[r][0]==="exit"&&e[r][1].type==="attentionSequence"&&e[r][1]._open&&t.sliceSerialize(e[r][1]).charCodeAt(0)===t.sliceSerialize(e[n][1]).charCodeAt(0)){if((e[r][1]._close||e[n][1]._open)&&(e[n][1].end.offset-e[n][1].start.offset)%3&&!((e[r][1].end.offset-e[r][1].start.offset+e[n][1].end.offset-e[n][1].start.offset)%3))continue;l=e[r][1].end.offset-e[r][1].start.offset>1&&e[n][1].end.offset-e[n][1].start.offset>1?2:1;const f={...e[r][1].end},d={...e[n][1].start};ss(f,-l),ss(d,l),o={type:l>1?"strongSequence":"emphasisSequence",start:f,end:{...e[r][1].end}},a={type:l>1?"strongSequence":"emphasisSequence",start:{...e[n][1].start},end:d},s={type:l>1?"strongText":"emphasisText",start:{...e[r][1].end},end:{...e[n][1].start}},i={type:l>1?"strong":"emphasis",start:{...o.start},end:{...a.end}},e[r][1].end={...o.start},e[n][1].start={...a.end},u=[],e[r][1].end.offset-e[r][1].start.offset&&(u=Xe(u,[["enter",e[r][1],t],["exit",e[r][1],t]])),u=Xe(u,[["enter",i,t],["enter",o,t],["exit",o,t],["enter",s,t]]),u=Xe(u,Xn(t.parser.constructs.insideSpan.null,e.slice(r+1,n),t)),u=Xe(u,[["exit",s,t],["enter",a,t],["exit",a,t],["exit",i,t]]),e[n][1].end.offset-e[n][1].start.offset?(c=2,u=Xe(u,[["enter",e[n][1],t],["exit",e[n][1],t]])):c=0,Ue(e,r-1,n-r+3,u),n=r+u.length-c-2;break}}for(n=-1;++n<e.length;)e[n][1].type==="attentionSequence"&&(e[n][1].type="data");return e}function Nh(e,t){const n=this.parser.constructs.attentionMarkers.null,r=this.previous,i=Ut(r);let s;return o;function o(l){return s=l,e.enter("attentionSequence"),a(l)}function a(l){if(l===s)return e.consume(l),a;const u=e.exit("attentionSequence"),c=Ut(l),f=!c||c===2&&i||n.includes(l),d=!i||i===2&&c||n.includes(r);return u._open=!!(s===42?f:f&&(i||!d)),u._close=!!(s===42?d:d&&(c||!f)),t(l)}}function ss(e,t){e.column+=t,e.offset+=t,e._bufferIndex+=t}const Lh={name:"autolink",tokenize:Mh};function Mh(e,t,n){let r=0;return i;function i(p){return e.enter("autolink"),e.enter("autolinkMarker"),e.consume(p),e.exit("autolinkMarker"),e.enter("autolinkProtocol"),s}function s(p){return Me(p)?(e.consume(p),o):p===64?n(p):u(p)}function o(p){return p===43||p===45||p===46||Re(p)?(r=1,a(p)):u(p)}function a(p){return p===58?(e.consume(p),r=0,l):(p===43||p===45||p===46||Re(p))&&r++<32?(e.consume(p),a):(r=0,u(p))}function l(p){return p===62?(e.exit("autolinkProtocol"),e.enter("autolinkMarker"),e.consume(p),e.exit("autolinkMarker"),e.exit("autolink"),t):p===null||p===32||p===60||zn(p)?n(p):(e.consume(p),l)}function u(p){return p===64?(e.consume(p),c):Sh(p)?(e.consume(p),u):n(p)}function c(p){return Re(p)?f(p):n(p)}function f(p){return p===46?(e.consume(p),r=0,c):p===62?(e.exit("autolinkProtocol").type="autolinkEmail",e.enter("autolinkMarker"),e.consume(p),e.exit("autolinkMarker"),e.exit("autolink"),t):d(p)}function d(p){if((p===45||Re(p))&&r++<63){const g=p===45?d:f;return e.consume(p),g}return n(p)}}const fn={partial:!0,tokenize:Dh};function Dh(e,t,n){return r;function r(s){return ie(s)?oe(e,i,"linePrefix")(s):i(s)}function i(s){return s===null||G(s)?t(s):n(s)}}const Vo={continuation:{tokenize:Ph},exit:_h,name:"blockQuote",tokenize:zh};function zh(e,t,n){const r=this;return i;function i(o){if(o===62){const a=r.containerState;return a.open||(e.enter("blockQuote",{_container:!0}),a.open=!0),e.enter("blockQuotePrefix"),e.enter("blockQuoteMarker"),e.consume(o),e.exit("blockQuoteMarker"),s}return n(o)}function s(o){return ie(o)?(e.enter("blockQuotePrefixWhitespace"),e.consume(o),e.exit("blockQuotePrefixWhitespace"),e.exit("blockQuotePrefix"),t):(e.exit("blockQuotePrefix"),t(o))}}function Ph(e,t,n){const r=this;return i;function i(o){return ie(o)?oe(e,s,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(o):s(o)}function s(o){return e.attempt(Vo,t,n)(o)}}function _h(e){e.exit("blockQuote")}const Xo={name:"characterEscape",tokenize:Oh};function Oh(e,t,n){return r;function r(s){return e.enter("characterEscape"),e.enter("escapeMarker"),e.consume(s),e.exit("escapeMarker"),i}function i(s){return vh(s)?(e.enter("characterEscapeValue"),e.consume(s),e.exit("characterEscapeValue"),e.exit("characterEscape"),t):n(s)}}const Yo={name:"characterReference",tokenize:Fh};function Fh(e,t,n){const r=this;let i=0,s,o;return a;function a(f){return e.enter("characterReference"),e.enter("characterReferenceMarker"),e.consume(f),e.exit("characterReferenceMarker"),l}function l(f){return f===35?(e.enter("characterReferenceMarkerNumeric"),e.consume(f),e.exit("characterReferenceMarkerNumeric"),u):(e.enter("characterReferenceValue"),s=31,o=Re,c(f))}function u(f){return f===88||f===120?(e.enter("characterReferenceMarkerHexadecimal"),e.consume(f),e.exit("characterReferenceMarkerHexadecimal"),e.enter("characterReferenceValue"),s=6,o=Ch,c):(e.enter("characterReferenceValue"),s=7,o=zr,c(f))}function c(f){if(f===59&&i){const d=e.exit("characterReferenceValue");return o===Re&&!pi(r.sliceSerialize(d))?n(f):(e.enter("characterReferenceMarker"),e.consume(f),e.exit("characterReferenceMarker"),e.exit("characterReference"),t)}return o(f)&&i++<s?(e.consume(f),c):n(f)}}const os={partial:!0,tokenize:Bh},as={concrete:!0,name:"codeFenced",tokenize:$h};function $h(e,t,n){const r=this,i={partial:!0,tokenize:M};let s=0,o=0,a;return l;function l(C){return u(C)}function u(C){const z=r.events[r.events.length-1];return s=z&&z[1].type==="linePrefix"?z[2].sliceSerialize(z[1],!0).length:0,a=C,e.enter("codeFenced"),e.enter("codeFencedFence"),e.enter("codeFencedFenceSequence"),c(C)}function c(C){return C===a?(o++,e.consume(C),c):o<3?n(C):(e.exit("codeFencedFenceSequence"),ie(C)?oe(e,f,"whitespace")(C):f(C))}function f(C){return C===null||G(C)?(e.exit("codeFencedFence"),r.interrupt?t(C):e.check(os,y,R)(C)):(e.enter("codeFencedFenceInfo"),e.enter("chunkString",{contentType:"string"}),d(C))}function d(C){return C===null||G(C)?(e.exit("chunkString"),e.exit("codeFencedFenceInfo"),f(C)):ie(C)?(e.exit("chunkString"),e.exit("codeFencedFenceInfo"),oe(e,p,"whitespace")(C)):C===96&&C===a?n(C):(e.consume(C),d)}function p(C){return C===null||G(C)?f(C):(e.enter("codeFencedFenceMeta"),e.enter("chunkString",{contentType:"string"}),g(C))}function g(C){return C===null||G(C)?(e.exit("chunkString"),e.exit("codeFencedFenceMeta"),f(C)):C===96&&C===a?n(C):(e.consume(C),g)}function y(C){return e.attempt(i,R,w)(C)}function w(C){return e.enter("lineEnding"),e.consume(C),e.exit("lineEnding"),k}function k(C){return s>0&&ie(C)?oe(e,S,"linePrefix",s+1)(C):S(C)}function S(C){return C===null||G(C)?e.check(os,y,R)(C):(e.enter("codeFlowValue"),v(C))}function v(C){return C===null||G(C)?(e.exit("codeFlowValue"),S(C)):(e.consume(C),v)}function R(C){return e.exit("codeFenced"),t(C)}function M(C,z,U){let F=0;return E;function E(T){return C.enter("lineEnding"),C.consume(T),C.exit("lineEnding"),N}function N(T){return C.enter("codeFencedFence"),ie(T)?oe(C,A,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(T):A(T)}function A(T){return T===a?(C.enter("codeFencedFenceSequence"),P(T)):U(T)}function P(T){return T===a?(F++,C.consume(T),P):F>=o?(C.exit("codeFencedFenceSequence"),ie(T)?oe(C,j,"whitespace")(T):j(T)):U(T)}function j(T){return T===null||G(T)?(C.exit("codeFencedFence"),z(T)):U(T)}}}function Bh(e,t,n){const r=this;return i;function i(o){return o===null?n(o):(e.enter("lineEnding"),e.consume(o),e.exit("lineEnding"),s)}function s(o){return r.parser.lazy[r.now().line]?n(o):t(o)}}const ur={name:"codeIndented",tokenize:Uh},Hh={partial:!0,tokenize:qh};function Uh(e,t,n){const r=this;return i;function i(u){return e.enter("codeIndented"),oe(e,s,"linePrefix",5)(u)}function s(u){const c=r.events[r.events.length-1];return c&&c[1].type==="linePrefix"&&c[2].sliceSerialize(c[1],!0).length>=4?o(u):n(u)}function o(u){return u===null?l(u):G(u)?e.attempt(Hh,o,l)(u):(e.enter("codeFlowValue"),a(u))}function a(u){return u===null||G(u)?(e.exit("codeFlowValue"),o(u)):(e.consume(u),a)}function l(u){return e.exit("codeIndented"),t(u)}}function qh(e,t,n){const r=this;return i;function i(o){return r.parser.lazy[r.now().line]?n(o):G(o)?(e.enter("lineEnding"),e.consume(o),e.exit("lineEnding"),i):oe(e,s,"linePrefix",5)(o)}function s(o){const a=r.events[r.events.length-1];return a&&a[1].type==="linePrefix"&&a[2].sliceSerialize(a[1],!0).length>=4?t(o):G(o)?i(o):n(o)}}const Kh={name:"codeText",previous:Vh,resolve:Wh,tokenize:Xh};function Wh(e){let t=e.length-4,n=3,r,i;if((e[n][1].type==="lineEnding"||e[n][1].type==="space")&&(e[t][1].type==="lineEnding"||e[t][1].type==="space")){for(r=n;++r<t;)if(e[r][1].type==="codeTextData"){e[n][1].type="codeTextPadding",e[t][1].type="codeTextPadding",n+=2,t-=2;break}}for(r=n-1,t++;++r<=t;)i===void 0?r!==t&&e[r][1].type!=="lineEnding"&&(i=r):(r===t||e[r][1].type==="lineEnding")&&(e[i][1].type="codeTextData",r!==i+2&&(e[i][1].end=e[r-1][1].end,e.splice(i+2,r-i-2),t-=r-i-2,r=i+2),i=void 0);return e}function Vh(e){return e!==96||this.events[this.events.length-1][1].type==="characterEscape"}function Xh(e,t,n){let r=0,i,s;return o;function o(f){return e.enter("codeText"),e.enter("codeTextSequence"),a(f)}function a(f){return f===96?(e.consume(f),r++,a):(e.exit("codeTextSequence"),l(f))}function l(f){return f===null?n(f):f===32?(e.enter("space"),e.consume(f),e.exit("space"),l):f===96?(s=e.enter("codeTextSequence"),i=0,c(f)):G(f)?(e.enter("lineEnding"),e.consume(f),e.exit("lineEnding"),l):(e.enter("codeTextData"),u(f))}function u(f){return f===null||f===32||f===96||G(f)?(e.exit("codeTextData"),l(f)):(e.consume(f),u)}function c(f){return f===96?(e.consume(f),i++,c):i===r?(e.exit("codeTextSequence"),e.exit("codeText"),t(f)):(s.type="codeTextData",u(f))}}class Yh{constructor(t){this.left=t?[...t]:[],this.right=[]}get(t){if(t<0||t>=this.left.length+this.right.length)throw new RangeError("Cannot access index `"+t+"` in a splice buffer of size `"+(this.left.length+this.right.length)+"`");return t<this.left.length?this.left[t]:this.right[this.right.length-t+this.left.length-1]}get length(){return this.left.length+this.right.length}shift(){return this.setCursor(0),this.right.pop()}slice(t,n){const r=n??Number.POSITIVE_INFINITY;return r<this.left.length?this.left.slice(t,r):t>this.left.length?this.right.slice(this.right.length-r+this.left.length,this.right.length-t+this.left.length).reverse():this.left.slice(t).concat(this.right.slice(this.right.length-r+this.left.length).reverse())}splice(t,n,r){const i=n||0;this.setCursor(Math.trunc(t));const s=this.right.splice(this.right.length-i,Number.POSITIVE_INFINITY);return r&&Jt(this.left,r),s.reverse()}pop(){return this.setCursor(Number.POSITIVE_INFINITY),this.left.pop()}push(t){this.setCursor(Number.POSITIVE_INFINITY),this.left.push(t)}pushMany(t){this.setCursor(Number.POSITIVE_INFINITY),Jt(this.left,t)}unshift(t){this.setCursor(0),this.right.push(t)}unshiftMany(t){this.setCursor(0),Jt(this.right,t.reverse())}setCursor(t){if(!(t===this.left.length||t>this.left.length&&this.right.length===0||t<0&&this.left.length===0))if(t<this.left.length){const n=this.left.splice(t,Number.POSITIVE_INFINITY);Jt(this.right,n.reverse())}else{const n=this.right.splice(this.left.length+this.right.length-t,Number.POSITIVE_INFINITY);Jt(this.left,n.reverse())}}}function Jt(e,t){let n=0;if(t.length<1e4)e.push(...t);else for(;n<t.length;)e.push(...t.slice(n,n+1e4)),n+=1e4}function Go(e){const t={};let n=-1,r,i,s,o,a,l,u;const c=new Yh(e);for(;++n<c.length;){for(;n in t;)n=t[n];if(r=c.get(n),n&&r[1].type==="chunkFlow"&&c.get(n-1)[1].type==="listItemPrefix"&&(l=r[1]._tokenizer.events,s=0,s<l.length&&l[s][1].type==="lineEndingBlank"&&(s+=2),s<l.length&&l[s][1].type==="content"))for(;++s<l.length&&l[s][1].type!=="content";)l[s][1].type==="chunkText"&&(l[s][1]._isInFirstContentOfListItem=!0,s++);if(r[0]==="enter")r[1].contentType&&(Object.assign(t,Gh(c,n)),n=t[n],u=!0);else if(r[1]._container){for(s=n,i=void 0;s--;)if(o=c.get(s),o[1].type==="lineEnding"||o[1].type==="lineEndingBlank")o[0]==="enter"&&(i&&(c.get(i)[1].type="lineEndingBlank"),o[1].type="lineEnding",i=s);else if(!(o[1].type==="linePrefix"||o[1].type==="listItemIndent"))break;i&&(r[1].end={...c.get(i)[1].start},a=c.slice(i,n),a.unshift(r),c.splice(i,n-i+1,a))}}return Ue(e,0,Number.POSITIVE_INFINITY,c.slice(0)),!u}function Gh(e,t){const n=e.get(t)[1],r=e.get(t)[2];let i=t-1;const s=[];let o=n._tokenizer;o||(o=r.parser[n.contentType](n.start),n._contentTypeTextTrailing&&(o._contentTypeTextTrailing=!0));const a=o.events,l=[],u={};let c,f,d=-1,p=n,g=0,y=0;const w=[y];for(;p;){for(;e.get(++i)[1]!==p;);s.push(i),p._tokenizer||(c=r.sliceStream(p),p.next||c.push(null),f&&o.defineSkip(p.start),p._isInFirstContentOfListItem&&(o._gfmTasklistFirstContentOfListItem=!0),o.write(c),p._isInFirstContentOfListItem&&(o._gfmTasklistFirstContentOfListItem=void 0)),f=p,p=p.next}for(p=n;++d<a.length;)a[d][0]==="exit"&&a[d-1][0]==="enter"&&a[d][1].type===a[d-1][1].type&&a[d][1].start.line!==a[d][1].end.line&&(y=d+1,w.push(y),p._tokenizer=void 0,p.previous=void 0,p=p.next);for(o.events=[],p?(p._tokenizer=void 0,p.previous=void 0):w.pop(),d=w.length;d--;){const k=a.slice(w[d],w[d+1]),S=s.pop();l.push([S,S+k.length-1]),e.splice(S,2,k)}for(l.reverse(),d=-1;++d<l.length;)u[g+l[d][0]]=g+l[d][1],g+=l[d][1]-l[d][0]-1;return u}const Qh={resolve:Zh,tokenize:ep},Jh={partial:!0,tokenize:tp};function Zh(e){return Go(e),e}function ep(e,t){let n;return r;function r(a){return e.enter("content"),n=e.enter("chunkContent",{contentType:"content"}),i(a)}function i(a){return a===null?s(a):G(a)?e.check(Jh,o,s)(a):(e.consume(a),i)}function s(a){return e.exit("chunkContent"),e.exit("content"),t(a)}function o(a){return e.consume(a),e.exit("chunkContent"),n.next=e.enter("chunkContent",{contentType:"content",previous:n}),n=n.next,i}}function tp(e,t,n){const r=this;return i;function i(o){return e.exit("chunkContent"),e.enter("lineEnding"),e.consume(o),e.exit("lineEnding"),oe(e,s,"linePrefix")}function s(o){if(o===null||G(o))return n(o);const a=r.events[r.events.length-1];return!r.parser.constructs.disable.null.includes("codeIndented")&&a&&a[1].type==="linePrefix"&&a[2].sliceSerialize(a[1],!0).length>=4?t(o):e.interrupt(r.parser.constructs.flow,n,t)(o)}}function Qo(e,t,n,r,i,s,o,a,l){const u=l||Number.POSITIVE_INFINITY;let c=0;return f;function f(k){return k===60?(e.enter(r),e.enter(i),e.enter(s),e.consume(k),e.exit(s),d):k===null||k===32||k===41||zn(k)?n(k):(e.enter(r),e.enter(o),e.enter(a),e.enter("chunkString",{contentType:"string"}),y(k))}function d(k){return k===62?(e.enter(s),e.consume(k),e.exit(s),e.exit(i),e.exit(r),t):(e.enter(a),e.enter("chunkString",{contentType:"string"}),p(k))}function p(k){return k===62?(e.exit("chunkString"),e.exit(a),d(k)):k===null||k===60||G(k)?n(k):(e.consume(k),k===92?g:p)}function g(k){return k===60||k===62||k===92?(e.consume(k),p):p(k)}function y(k){return!c&&(k===null||k===41||fe(k))?(e.exit("chunkString"),e.exit(a),e.exit(o),e.exit(r),t(k)):c<u&&k===40?(e.consume(k),c++,y):k===41?(e.consume(k),c--,y):k===null||k===32||k===40||zn(k)?n(k):(e.consume(k),k===92?w:y)}function w(k){return k===40||k===41||k===92?(e.consume(k),y):y(k)}}function Jo(e,t,n,r,i,s){const o=this;let a=0,l;return u;function u(p){return e.enter(r),e.enter(i),e.consume(p),e.exit(i),e.enter(s),c}function c(p){return a>999||p===null||p===91||p===93&&!l||p===94&&!a&&"_hiddenFootnoteSupport"in o.parser.constructs?n(p):p===93?(e.exit(s),e.enter(i),e.consume(p),e.exit(i),e.exit(r),t):G(p)?(e.enter("lineEnding"),e.consume(p),e.exit("lineEnding"),c):(e.enter("chunkString",{contentType:"string"}),f(p))}function f(p){return p===null||p===91||p===93||G(p)||a++>999?(e.exit("chunkString"),c(p)):(e.consume(p),l||(l=!ie(p)),p===92?d:f)}function d(p){return p===91||p===92||p===93?(e.consume(p),a++,f):f(p)}}function Zo(e,t,n,r,i,s){let o;return a;function a(d){return d===34||d===39||d===40?(e.enter(r),e.enter(i),e.consume(d),e.exit(i),o=d===40?41:d,l):n(d)}function l(d){return d===o?(e.enter(i),e.consume(d),e.exit(i),e.exit(r),t):(e.enter(s),u(d))}function u(d){return d===o?(e.exit(s),l(o)):d===null?n(d):G(d)?(e.enter("lineEnding"),e.consume(d),e.exit("lineEnding"),oe(e,u,"linePrefix")):(e.enter("chunkString",{contentType:"string"}),c(d))}function c(d){return d===o||d===null||G(d)?(e.exit("chunkString"),u(d)):(e.consume(d),d===92?f:c)}function f(d){return d===o||d===92?(e.consume(d),c):c(d)}}function on(e,t){let n;return r;function r(i){return G(i)?(e.enter("lineEnding"),e.consume(i),e.exit("lineEnding"),n=!0,r):ie(i)?oe(e,r,n?"linePrefix":"lineSuffix")(i):t(i)}}const np={name:"definition",tokenize:ip},rp={partial:!0,tokenize:sp};function ip(e,t,n){const r=this;let i;return s;function s(p){return e.enter("definition"),o(p)}function o(p){return Jo.call(r,e,a,n,"definitionLabel","definitionLabelMarker","definitionLabelString")(p)}function a(p){return i=tt(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)),p===58?(e.enter("definitionMarker"),e.consume(p),e.exit("definitionMarker"),l):n(p)}function l(p){return fe(p)?on(e,u)(p):u(p)}function u(p){return Qo(e,c,n,"definitionDestination","definitionDestinationLiteral","definitionDestinationLiteralMarker","definitionDestinationRaw","definitionDestinationString")(p)}function c(p){return e.attempt(rp,f,f)(p)}function f(p){return ie(p)?oe(e,d,"whitespace")(p):d(p)}function d(p){return p===null||G(p)?(e.exit("definition"),r.parser.defined.push(i),t(p)):n(p)}}function sp(e,t,n){return r;function r(a){return fe(a)?on(e,i)(a):n(a)}function i(a){return Zo(e,s,n,"definitionTitle","definitionTitleMarker","definitionTitleString")(a)}function s(a){return ie(a)?oe(e,o,"whitespace")(a):o(a)}function o(a){return a===null||G(a)?t(a):n(a)}}const op={name:"hardBreakEscape",tokenize:ap};function ap(e,t,n){return r;function r(s){return e.enter("hardBreakEscape"),e.consume(s),i}function i(s){return G(s)?(e.exit("hardBreakEscape"),t(s)):n(s)}}const lp={name:"headingAtx",resolve:up,tokenize:cp};function up(e,t){let n=e.length-2,r=3,i,s;return e[r][1].type==="whitespace"&&(r+=2),n-2>r&&e[n][1].type==="whitespace"&&(n-=2),e[n][1].type==="atxHeadingSequence"&&(r===n-1||n-4>r&&e[n-2][1].type==="whitespace")&&(n-=r+1===n?2:4),n>r&&(i={type:"atxHeadingText",start:e[r][1].start,end:e[n][1].end},s={type:"chunkText",start:e[r][1].start,end:e[n][1].end,contentType:"text"},Ue(e,r,n-r+1,[["enter",i,t],["enter",s,t],["exit",s,t],["exit",i,t]])),e}function cp(e,t,n){let r=0;return i;function i(c){return e.enter("atxHeading"),s(c)}function s(c){return e.enter("atxHeadingSequence"),o(c)}function o(c){return c===35&&r++<6?(e.consume(c),o):c===null||fe(c)?(e.exit("atxHeadingSequence"),a(c)):n(c)}function a(c){return c===35?(e.enter("atxHeadingSequence"),l(c)):c===null||G(c)?(e.exit("atxHeading"),t(c)):ie(c)?oe(e,a,"whitespace")(c):(e.enter("atxHeadingText"),u(c))}function l(c){return c===35?(e.consume(c),l):(e.exit("atxHeadingSequence"),a(c))}function u(c){return c===null||c===35||fe(c)?(e.exit("atxHeadingText"),a(c)):(e.consume(c),u)}}const fp=["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","h1","h2","h3","h4","h5","h6","head","header","hr","html","iframe","legend","li","link","main","menu","menuitem","nav","noframes","ol","optgroup","option","p","param","search","section","summary","table","tbody","td","tfoot","th","thead","title","tr","track","ul"],ls=["pre","script","style","textarea"],hp={concrete:!0,name:"htmlFlow",resolveTo:mp,tokenize:gp},pp={partial:!0,tokenize:yp},dp={partial:!0,tokenize:xp};function mp(e){let t=e.length;for(;t--&&!(e[t][0]==="enter"&&e[t][1].type==="htmlFlow"););return t>1&&e[t-2][1].type==="linePrefix"&&(e[t][1].start=e[t-2][1].start,e[t+1][1].start=e[t-2][1].start,e.splice(t-2,2)),e}function gp(e,t,n){const r=this;let i,s,o,a,l;return u;function u(b){return c(b)}function c(b){return e.enter("htmlFlow"),e.enter("htmlFlowData"),e.consume(b),f}function f(b){return b===33?(e.consume(b),d):b===47?(e.consume(b),s=!0,y):b===63?(e.consume(b),i=3,r.interrupt?t:x):Me(b)?(e.consume(b),o=String.fromCharCode(b),w):n(b)}function d(b){return b===45?(e.consume(b),i=2,p):b===91?(e.consume(b),i=5,a=0,g):Me(b)?(e.consume(b),i=4,r.interrupt?t:x):n(b)}function p(b){return b===45?(e.consume(b),r.interrupt?t:x):n(b)}function g(b){const Q="CDATA[";return b===Q.charCodeAt(a++)?(e.consume(b),a===Q.length?r.interrupt?t:A:g):n(b)}function y(b){return Me(b)?(e.consume(b),o=String.fromCharCode(b),w):n(b)}function w(b){if(b===null||b===47||b===62||fe(b)){const Q=b===47,re=o.toLowerCase();return!Q&&!s&&ls.includes(re)?(i=1,r.interrupt?t(b):A(b)):fp.includes(o.toLowerCase())?(i=6,Q?(e.consume(b),k):r.interrupt?t(b):A(b)):(i=7,r.interrupt&&!r.parser.lazy[r.now().line]?n(b):s?S(b):v(b))}return b===45||Re(b)?(e.consume(b),o+=String.fromCharCode(b),w):n(b)}function k(b){return b===62?(e.consume(b),r.interrupt?t:A):n(b)}function S(b){return ie(b)?(e.consume(b),S):E(b)}function v(b){return b===47?(e.consume(b),E):b===58||b===95||Me(b)?(e.consume(b),R):ie(b)?(e.consume(b),v):E(b)}function R(b){return b===45||b===46||b===58||b===95||Re(b)?(e.consume(b),R):M(b)}function M(b){return b===61?(e.consume(b),C):ie(b)?(e.consume(b),M):v(b)}function C(b){return b===null||b===60||b===61||b===62||b===96?n(b):b===34||b===39?(e.consume(b),l=b,z):ie(b)?(e.consume(b),C):U(b)}function z(b){return b===l?(e.consume(b),l=null,F):b===null||G(b)?n(b):(e.consume(b),z)}function U(b){return b===null||b===34||b===39||b===47||b===60||b===61||b===62||b===96||fe(b)?M(b):(e.consume(b),U)}function F(b){return b===47||b===62||ie(b)?v(b):n(b)}function E(b){return b===62?(e.consume(b),N):n(b)}function N(b){return b===null||G(b)?A(b):ie(b)?(e.consume(b),N):n(b)}function A(b){return b===45&&i===2?(e.consume(b),D):b===60&&i===1?(e.consume(b),L):b===62&&i===4?(e.consume(b),V):b===63&&i===3?(e.consume(b),x):b===93&&i===5?(e.consume(b),_):G(b)&&(i===6||i===7)?(e.exit("htmlFlowData"),e.check(pp,X,P)(b)):b===null||G(b)?(e.exit("htmlFlowData"),P(b)):(e.consume(b),A)}function P(b){return e.check(dp,j,X)(b)}function j(b){return e.enter("lineEnding"),e.consume(b),e.exit("lineEnding"),T}function T(b){return b===null||G(b)?P(b):(e.enter("htmlFlowData"),A(b))}function D(b){return b===45?(e.consume(b),x):A(b)}function L(b){return b===47?(e.consume(b),o="",H):A(b)}function H(b){if(b===62){const Q=o.toLowerCase();return ls.includes(Q)?(e.consume(b),V):A(b)}return Me(b)&&o.length<8?(e.consume(b),o+=String.fromCharCode(b),H):A(b)}function _(b){return b===93?(e.consume(b),x):A(b)}function x(b){return b===62?(e.consume(b),V):b===45&&i===2?(e.consume(b),x):A(b)}function V(b){return b===null||G(b)?(e.exit("htmlFlowData"),X(b)):(e.consume(b),V)}function X(b){return e.exit("htmlFlow"),t(b)}}function xp(e,t,n){const r=this;return i;function i(o){return G(o)?(e.enter("lineEnding"),e.consume(o),e.exit("lineEnding"),s):n(o)}function s(o){return r.parser.lazy[r.now().line]?n(o):t(o)}}function yp(e,t,n){return r;function r(i){return e.enter("lineEnding"),e.consume(i),e.exit("lineEnding"),e.attempt(fn,t,n)}}const bp={name:"htmlText",tokenize:kp};function kp(e,t,n){const r=this;let i,s,o;return a;function a(x){return e.enter("htmlText"),e.enter("htmlTextData"),e.consume(x),l}function l(x){return x===33?(e.consume(x),u):x===47?(e.consume(x),M):x===63?(e.consume(x),v):Me(x)?(e.consume(x),U):n(x)}function u(x){return x===45?(e.consume(x),c):x===91?(e.consume(x),s=0,g):Me(x)?(e.consume(x),S):n(x)}function c(x){return x===45?(e.consume(x),p):n(x)}function f(x){return x===null?n(x):x===45?(e.consume(x),d):G(x)?(o=f,L(x)):(e.consume(x),f)}function d(x){return x===45?(e.consume(x),p):f(x)}function p(x){return x===62?D(x):x===45?d(x):f(x)}function g(x){const V="CDATA[";return x===V.charCodeAt(s++)?(e.consume(x),s===V.length?y:g):n(x)}function y(x){return x===null?n(x):x===93?(e.consume(x),w):G(x)?(o=y,L(x)):(e.consume(x),y)}function w(x){return x===93?(e.consume(x),k):y(x)}function k(x){return x===62?D(x):x===93?(e.consume(x),k):y(x)}function S(x){return x===null||x===62?D(x):G(x)?(o=S,L(x)):(e.consume(x),S)}function v(x){return x===null?n(x):x===63?(e.consume(x),R):G(x)?(o=v,L(x)):(e.consume(x),v)}function R(x){return x===62?D(x):v(x)}function M(x){return Me(x)?(e.consume(x),C):n(x)}function C(x){return x===45||Re(x)?(e.consume(x),C):z(x)}function z(x){return G(x)?(o=z,L(x)):ie(x)?(e.consume(x),z):D(x)}function U(x){return x===45||Re(x)?(e.consume(x),U):x===47||x===62||fe(x)?F(x):n(x)}function F(x){return x===47?(e.consume(x),D):x===58||x===95||Me(x)?(e.consume(x),E):G(x)?(o=F,L(x)):ie(x)?(e.consume(x),F):D(x)}function E(x){return x===45||x===46||x===58||x===95||Re(x)?(e.consume(x),E):N(x)}function N(x){return x===61?(e.consume(x),A):G(x)?(o=N,L(x)):ie(x)?(e.consume(x),N):F(x)}function A(x){return x===null||x===60||x===61||x===62||x===96?n(x):x===34||x===39?(e.consume(x),i=x,P):G(x)?(o=A,L(x)):ie(x)?(e.consume(x),A):(e.consume(x),j)}function P(x){return x===i?(e.consume(x),i=void 0,T):x===null?n(x):G(x)?(o=P,L(x)):(e.consume(x),P)}function j(x){return x===null||x===34||x===39||x===60||x===61||x===96?n(x):x===47||x===62||fe(x)?F(x):(e.consume(x),j)}function T(x){return x===47||x===62||fe(x)?F(x):n(x)}function D(x){return x===62?(e.consume(x),e.exit("htmlTextData"),e.exit("htmlText"),t):n(x)}function L(x){return e.exit("htmlTextData"),e.enter("lineEnding"),e.consume(x),e.exit("lineEnding"),H}function H(x){return ie(x)?oe(e,_,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(x):_(x)}function _(x){return e.enter("htmlTextData"),o(x)}}const di={name:"labelEnd",resolveAll:vp,resolveTo:Ep,tokenize:Tp},wp={tokenize:jp},Sp={tokenize:Ap},Cp={tokenize:Ip};function vp(e){let t=-1;const n=[];for(;++t<e.length;){const r=e[t][1];if(n.push(e[t]),r.type==="labelImage"||r.type==="labelLink"||r.type==="labelEnd"){const i=r.type==="labelImage"?4:2;r.type="data",t+=i}}return e.length!==n.length&&Ue(e,0,e.length,n),e}function Ep(e,t){let n=e.length,r=0,i,s,o,a;for(;n--;)if(i=e[n][1],s){if(i.type==="link"||i.type==="labelLink"&&i._inactive)break;e[n][0]==="enter"&&i.type==="labelLink"&&(i._inactive=!0)}else if(o){if(e[n][0]==="enter"&&(i.type==="labelImage"||i.type==="labelLink")&&!i._balanced&&(s=n,i.type!=="labelLink")){r=2;break}}else i.type==="labelEnd"&&(o=n);const l={type:e[s][1].type==="labelLink"?"link":"image",start:{...e[s][1].start},end:{...e[e.length-1][1].end}},u={type:"label",start:{...e[s][1].start},end:{...e[o][1].end}},c={type:"labelText",start:{...e[s+r+2][1].end},end:{...e[o-2][1].start}};return a=[["enter",l,t],["enter",u,t]],a=Xe(a,e.slice(s+1,s+r+3)),a=Xe(a,[["enter",c,t]]),a=Xe(a,Xn(t.parser.constructs.insideSpan.null,e.slice(s+r+4,o-3),t)),a=Xe(a,[["exit",c,t],e[o-2],e[o-1],["exit",u,t]]),a=Xe(a,e.slice(o+1)),a=Xe(a,[["exit",l,t]]),Ue(e,s,e.length,a),e}function Tp(e,t,n){const r=this;let i=r.events.length,s,o;for(;i--;)if((r.events[i][1].type==="labelImage"||r.events[i][1].type==="labelLink")&&!r.events[i][1]._balanced){s=r.events[i][1];break}return a;function a(d){return s?s._inactive?f(d):(o=r.parser.defined.includes(tt(r.sliceSerialize({start:s.end,end:r.now()}))),e.enter("labelEnd"),e.enter("labelMarker"),e.consume(d),e.exit("labelMarker"),e.exit("labelEnd"),l):n(d)}function l(d){return d===40?e.attempt(wp,c,o?c:f)(d):d===91?e.attempt(Sp,c,o?u:f)(d):o?c(d):f(d)}function u(d){return e.attempt(Cp,c,f)(d)}function c(d){return t(d)}function f(d){return s._balanced=!0,n(d)}}function jp(e,t,n){return r;function r(f){return e.enter("resource"),e.enter("resourceMarker"),e.consume(f),e.exit("resourceMarker"),i}function i(f){return fe(f)?on(e,s)(f):s(f)}function s(f){return f===41?c(f):Qo(e,o,a,"resourceDestination","resourceDestinationLiteral","resourceDestinationLiteralMarker","resourceDestinationRaw","resourceDestinationString",32)(f)}function o(f){return fe(f)?on(e,l)(f):c(f)}function a(f){return n(f)}function l(f){return f===34||f===39||f===40?Zo(e,u,n,"resourceTitle","resourceTitleMarker","resourceTitleString")(f):c(f)}function u(f){return fe(f)?on(e,c)(f):c(f)}function c(f){return f===41?(e.enter("resourceMarker"),e.consume(f),e.exit("resourceMarker"),e.exit("resource"),t):n(f)}}function Ap(e,t,n){const r=this;return i;function i(a){return Jo.call(r,e,s,o,"reference","referenceMarker","referenceString")(a)}function s(a){return r.parser.defined.includes(tt(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)))?t(a):n(a)}function o(a){return n(a)}}function Ip(e,t,n){return r;function r(s){return e.enter("reference"),e.enter("referenceMarker"),e.consume(s),e.exit("referenceMarker"),i}function i(s){return s===93?(e.enter("referenceMarker"),e.consume(s),e.exit("referenceMarker"),e.exit("reference"),t):n(s)}}const Rp={name:"labelStartImage",resolveAll:di.resolveAll,tokenize:Np};function Np(e,t,n){const r=this;return i;function i(a){return e.enter("labelImage"),e.enter("labelImageMarker"),e.consume(a),e.exit("labelImageMarker"),s}function s(a){return a===91?(e.enter("labelMarker"),e.consume(a),e.exit("labelMarker"),e.exit("labelImage"),o):n(a)}function o(a){return a===94&&"_hiddenFootnoteSupport"in r.parser.constructs?n(a):t(a)}}const Lp={name:"labelStartLink",resolveAll:di.resolveAll,tokenize:Mp};function Mp(e,t,n){const r=this;return i;function i(o){return e.enter("labelLink"),e.enter("labelMarker"),e.consume(o),e.exit("labelMarker"),e.exit("labelLink"),s}function s(o){return o===94&&"_hiddenFootnoteSupport"in r.parser.constructs?n(o):t(o)}}const cr={name:"lineEnding",tokenize:Dp};function Dp(e,t){return n;function n(r){return e.enter("lineEnding"),e.consume(r),e.exit("lineEnding"),oe(e,t,"linePrefix")}}const Sn={name:"thematicBreak",tokenize:zp};function zp(e,t,n){let r=0,i;return s;function s(u){return e.enter("thematicBreak"),o(u)}function o(u){return i=u,a(u)}function a(u){return u===i?(e.enter("thematicBreakSequence"),l(u)):r>=3&&(u===null||G(u))?(e.exit("thematicBreak"),t(u)):n(u)}function l(u){return u===i?(e.consume(u),r++,l):(e.exit("thematicBreakSequence"),ie(u)?oe(e,a,"whitespace")(u):a(u))}}const _e={continuation:{tokenize:Fp},exit:Bp,name:"list",tokenize:Op},Pp={partial:!0,tokenize:Hp},_p={partial:!0,tokenize:$p};function Op(e,t,n){const r=this,i=r.events[r.events.length-1];let s=i&&i[1].type==="linePrefix"?i[2].sliceSerialize(i[1],!0).length:0,o=0;return a;function a(p){const g=r.containerState.type||(p===42||p===43||p===45?"listUnordered":"listOrdered");if(g==="listUnordered"?!r.containerState.marker||p===r.containerState.marker:zr(p)){if(r.containerState.type||(r.containerState.type=g,e.enter(g,{_container:!0})),g==="listUnordered")return e.enter("listItemPrefix"),p===42||p===45?e.check(Sn,n,u)(p):u(p);if(!r.interrupt||p===49)return e.enter("listItemPrefix"),e.enter("listItemValue"),l(p)}return n(p)}function l(p){return zr(p)&&++o<10?(e.consume(p),l):(!r.interrupt||o<2)&&(r.containerState.marker?p===r.containerState.marker:p===41||p===46)?(e.exit("listItemValue"),u(p)):n(p)}function u(p){return e.enter("listItemMarker"),e.consume(p),e.exit("listItemMarker"),r.containerState.marker=r.containerState.marker||p,e.check(fn,r.interrupt?n:c,e.attempt(Pp,d,f))}function c(p){return r.containerState.initialBlankLine=!0,s++,d(p)}function f(p){return ie(p)?(e.enter("listItemPrefixWhitespace"),e.consume(p),e.exit("listItemPrefixWhitespace"),d):n(p)}function d(p){return r.containerState.size=s+r.sliceSerialize(e.exit("listItemPrefix"),!0).length,t(p)}}function Fp(e,t,n){const r=this;return r.containerState._closeFlow=void 0,e.check(fn,i,s);function i(a){return r.containerState.furtherBlankLines=r.containerState.furtherBlankLines||r.containerState.initialBlankLine,oe(e,t,"listItemIndent",r.containerState.size+1)(a)}function s(a){return r.containerState.furtherBlankLines||!ie(a)?(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,o(a)):(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,e.attempt(_p,t,o)(a))}function o(a){return r.containerState._closeFlow=!0,r.interrupt=void 0,oe(e,e.attempt(_e,t,n),"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(a)}}function $p(e,t,n){const r=this;return oe(e,i,"listItemIndent",r.containerState.size+1);function i(s){const o=r.events[r.events.length-1];return o&&o[1].type==="listItemIndent"&&o[2].sliceSerialize(o[1],!0).length===r.containerState.size?t(s):n(s)}}function Bp(e){e.exit(this.containerState.type)}function Hp(e,t,n){const r=this;return oe(e,i,"listItemPrefixWhitespace",r.parser.constructs.disable.null.includes("codeIndented")?void 0:5);function i(s){const o=r.events[r.events.length-1];return!ie(s)&&o&&o[1].type==="listItemPrefixWhitespace"?t(s):n(s)}}const us={name:"setextUnderline",resolveTo:Up,tokenize:qp};function Up(e,t){let n=e.length,r,i,s;for(;n--;)if(e[n][0]==="enter"){if(e[n][1].type==="content"){r=n;break}e[n][1].type==="paragraph"&&(i=n)}else e[n][1].type==="content"&&e.splice(n,1),!s&&e[n][1].type==="definition"&&(s=n);const o={type:"setextHeading",start:{...e[r][1].start},end:{...e[e.length-1][1].end}};return e[i][1].type="setextHeadingText",s?(e.splice(i,0,["enter",o,t]),e.splice(s+1,0,["exit",e[r][1],t]),e[r][1].end={...e[s][1].end}):e[r][1]=o,e.push(["exit",o,t]),e}function qp(e,t,n){const r=this;let i;return s;function s(u){let c=r.events.length,f;for(;c--;)if(r.events[c][1].type!=="lineEnding"&&r.events[c][1].type!=="linePrefix"&&r.events[c][1].type!=="content"){f=r.events[c][1].type==="paragraph";break}return!r.parser.lazy[r.now().line]&&(r.interrupt||f)?(e.enter("setextHeadingLine"),i=u,o(u)):n(u)}function o(u){return e.enter("setextHeadingLineSequence"),a(u)}function a(u){return u===i?(e.consume(u),a):(e.exit("setextHeadingLineSequence"),ie(u)?oe(e,l,"lineSuffix")(u):l(u))}function l(u){return u===null||G(u)?(e.exit("setextHeadingLine"),t(u)):n(u)}}const Kp={tokenize:Wp};function Wp(e){const t=this,n=e.attempt(fn,r,e.attempt(this.parser.constructs.flowInitial,i,oe(e,e.attempt(this.parser.constructs.flow,i,e.attempt(Qh,i)),"linePrefix")));return n;function r(s){if(s===null){e.consume(s);return}return e.enter("lineEndingBlank"),e.consume(s),e.exit("lineEndingBlank"),t.currentConstruct=void 0,n}function i(s){if(s===null){e.consume(s);return}return e.enter("lineEnding"),e.consume(s),e.exit("lineEnding"),t.currentConstruct=void 0,n}}const Vp={resolveAll:ta()},Xp=ea("string"),Yp=ea("text");function ea(e){return{resolveAll:ta(e==="text"?Gp:void 0),tokenize:t};function t(n){const r=this,i=this.parser.constructs[e],s=n.attempt(i,o,a);return o;function o(c){return u(c)?s(c):a(c)}function a(c){if(c===null){n.consume(c);return}return n.enter("data"),n.consume(c),l}function l(c){return u(c)?(n.exit("data"),s(c)):(n.consume(c),l)}function u(c){if(c===null)return!0;const f=i[c];let d=-1;if(f)for(;++d<f.length;){const p=f[d];if(!p.previous||p.previous.call(r,r.previous))return!0}return!1}}}function ta(e){return t;function t(n,r){let i=-1,s;for(;++i<=n.length;)s===void 0?n[i]&&n[i][1].type==="data"&&(s=i,i++):(!n[i]||n[i][1].type!=="data")&&(i!==s+2&&(n[s][1].end=n[i-1][1].end,n.splice(s+2,i-s-2),i=s+2),s=void 0);return e?e(n,r):n}}function Gp(e,t){let n=0;for(;++n<=e.length;)if((n===e.length||e[n][1].type==="lineEnding")&&e[n-1][1].type==="data"){const r=e[n-1][1],i=t.sliceStream(r);let s=i.length,o=-1,a=0,l;for(;s--;){const u=i[s];if(typeof u=="string"){for(o=u.length;u.charCodeAt(o-1)===32;)a++,o--;if(o)break;o=-1}else if(u===-2)l=!0,a++;else if(u!==-1){s++;break}}if(t._contentTypeTextTrailing&&n===e.length&&(a=0),a){const u={type:n===e.length||l||a<2?"lineSuffix":"hardBreakTrailing",start:{_bufferIndex:s?o:r.start._bufferIndex+o,_index:r.start._index+s,line:r.end.line,column:r.end.column-a,offset:r.end.offset-a},end:{...r.end}};r.end={...u.start},r.start.offset===r.end.offset?Object.assign(r,u):(e.splice(n,0,["enter",u,t],["exit",u,t]),n+=2)}n++}return e}const Qp={42:_e,43:_e,45:_e,48:_e,49:_e,50:_e,51:_e,52:_e,53:_e,54:_e,55:_e,56:_e,57:_e,62:Vo},Jp={91:np},Zp={[-2]:ur,[-1]:ur,32:ur},ed={35:lp,42:Sn,45:[us,Sn],60:hp,61:us,95:Sn,96:as,126:as},td={38:Yo,92:Xo},nd={[-5]:cr,[-4]:cr,[-3]:cr,33:Rp,38:Yo,42:Pr,60:[Lh,bp],91:Lp,92:[op,Xo],93:di,95:Pr,96:Kh},rd={null:[Pr,Vp]},id={null:[42,95]},sd={null:[]},od=Object.freeze(Object.defineProperty({__proto__:null,attentionMarkers:id,contentInitial:Jp,disable:sd,document:Qp,flow:ed,flowInitial:Zp,insideSpan:rd,string:td,text:nd},Symbol.toStringTag,{value:"Module"}));function ad(e,t,n){let r={_bufferIndex:-1,_index:0,line:n&&n.line||1,column:n&&n.column||1,offset:n&&n.offset||0};const i={},s=[];let o=[],a=[];const l={attempt:z(M),check:z(C),consume:S,enter:v,exit:R,interrupt:z(C,{interrupt:!0})},u={code:null,containerState:{},defineSkip:y,events:[],now:g,parser:e,previous:null,sliceSerialize:d,sliceStream:p,write:f};let c=t.tokenize.call(u,l);return t.resolveAll&&s.push(t),u;function f(N){return o=Xe(o,N),w(),o[o.length-1]!==null?[]:(U(t,0),u.events=Xn(s,u.events,u),u.events)}function d(N,A){return ud(p(N),A)}function p(N){return ld(o,N)}function g(){const{_bufferIndex:N,_index:A,line:P,column:j,offset:T}=r;return{_bufferIndex:N,_index:A,line:P,column:j,offset:T}}function y(N){i[N.line]=N.column,E()}function w(){let N;for(;r._index<o.length;){const A=o[r._index];if(typeof A=="string")for(N=r._index,r._bufferIndex<0&&(r._bufferIndex=0);r._index===N&&r._bufferIndex<A.length;)k(A.charCodeAt(r._bufferIndex));else k(A)}}function k(N){c=c(N)}function S(N){G(N)?(r.line++,r.column=1,r.offset+=N===-3?2:1,E()):N!==-1&&(r.column++,r.offset++),r._bufferIndex<0?r._index++:(r._bufferIndex++,r._bufferIndex===o[r._index].length&&(r._bufferIndex=-1,r._index++)),u.previous=N}function v(N,A){const P=A||{};return P.type=N,P.start=g(),u.events.push(["enter",P,u]),a.push(P),P}function R(N){const A=a.pop();return A.end=g(),u.events.push(["exit",A,u]),A}function M(N,A){U(N,A.from)}function C(N,A){A.restore()}function z(N,A){return P;function P(j,T,D){let L,H,_,x;return Array.isArray(j)?X(j):"tokenize"in j?X([j]):V(j);function V(K){return he;function he(me){const ue=me!==null&&K[me],se=me!==null&&K.null,ge=[...Array.isArray(ue)?ue:ue?[ue]:[],...Array.isArray(se)?se:se?[se]:[]];return X(ge)(me)}}function X(K){return L=K,H=0,K.length===0?D:b(K[H])}function b(K){return he;function he(me){return x=F(),_=K,K.partial||(u.currentConstruct=K),K.name&&u.parser.constructs.disable.null.includes(K.name)?re():K.tokenize.call(A?Object.assign(Object.create(u),A):u,l,Q,re)(me)}}function Q(K){return N(_,x),T}function re(K){return x.restore(),++H<L.length?b(L[H]):D}}}function U(N,A){N.resolveAll&&!s.includes(N)&&s.push(N),N.resolve&&Ue(u.events,A,u.events.length-A,N.resolve(u.events.slice(A),u)),N.resolveTo&&(u.events=N.resolveTo(u.events,u))}function F(){const N=g(),A=u.previous,P=u.currentConstruct,j=u.events.length,T=Array.from(a);return{from:j,restore:D};function D(){r=N,u.previous=A,u.currentConstruct=P,u.events.length=j,a=T,E()}}function E(){r.line in i&&r.column<2&&(r.column=i[r.line],r.offset+=i[r.line]-1)}}function ld(e,t){const n=t.start._index,r=t.start._bufferIndex,i=t.end._index,s=t.end._bufferIndex;let o;if(n===i)o=[e[n].slice(r,s)];else{if(o=e.slice(n,i),r>-1){const a=o[0];typeof a=="string"?o[0]=a.slice(r):o.shift()}s>0&&o.push(e[i].slice(0,s))}return o}function ud(e,t){let n=-1;const r=[];let i;for(;++n<e.length;){const s=e[n];let o;if(typeof s=="string")o=s;else switch(s){case-5:{o="\r";break}case-4:{o=`
|
|
65
65
|
`;break}case-3:{o=`\r
|
|
66
|
-
`;break}case-2:{o=t?" ":" ";break}case-1:{if(!t&&i)continue;o=" ";break}default:o=String.fromCharCode(s)}i=s===-2,r.push(o)}return r.join("")}function cd(e){const r={constructs:Ko([od,...(e||{}).extensions||[]]),content:i(Eh),defined:[],document:i(jh),flow:i(Kp),lazy:{},string:i(Xp),text:i(Yp)};return r;function i(s){return o;function o(a){return ad(r,s,a)}}}function fd(e){for(;!Go(e););return e}const cs=/[\0\t\n\r]/g;function hd(){let e=1,t="",n=!0,r;return i;function i(s,o,a){const l=[];let u,c,f,d,p;for(s=t+(typeof s=="string"?s.toString():new TextDecoder(o||void 0).decode(s)),f=0,t="",n&&(s.charCodeAt(0)===65279&&f++,n=void 0);f<s.length;){if(cs.lastIndex=f,u=cs.exec(s),d=u&&u.index!==void 0?u.index:s.length,p=s.charCodeAt(d),!u){t=s.slice(f);break}if(p===10&&f===d&&r)l.push(-3),r=void 0;else switch(r&&(l.push(-5),r=void 0),f<d&&(l.push(s.slice(f,d)),e+=d-f),p){case 0:{l.push(65533),e++;break}case 9:{for(c=Math.ceil(e/4)*4,l.push(-2);e++<c;)l.push(-1);break}case 10:{l.push(-4),e=1;break}default:r=!0,e=1}f=d+1}return a&&(r&&l.push(-5),t&&l.push(t),l.push(null)),l}}const pd=/\\([!-/:-@[-`{-~])|&(#(?:\d{1,7}|x[\da-f]{1,6})|[\da-z]{1,31});/gi;function dd(e){return e.replace(pd,md)}function md(e,t,n){if(t)return t;if(n.charCodeAt(0)===35){const i=n.charCodeAt(1),s=i===120||i===88;return Wo(n.slice(s?2:1),s?16:10)}return pi(n)||e}const na={}.hasOwnProperty;function gd(e,t,n){return typeof t!="string"&&(n=t,t=void 0),xd(n)(fd(cd(n).document().write(hd()(e,t,!0))))}function xd(e){const t={transforms:[],canContainEols:["emphasis","fragment","heading","paragraph","strong"],enter:{autolink:s(re),autolinkProtocol:O,autolinkEmail:O,atxHeading:s(K),blockQuote:s(ie),characterEscape:O,characterReference:O,codeFenced:s(be),codeFencedFenceInfo:o,codeFencedFenceMeta:o,codeIndented:s(be,o),codeText:s(ke,o),codeTextData:O,data:O,codeFlowValue:O,definition:s(we),definitionDestinationString:o,definitionLabelString:o,definitionTitleString:o,emphasis:s(Se),hardBreakEscape:s(Z),hardBreakTrailing:s(Z),htmlFlow:s($,o),htmlFlowData:O,htmlText:s($,o),htmlTextData:O,image:s(ue),label:o,link:s(re),listItem:s(Be),listItemValue:d,listOrdered:s(pe,f),listUnordered:s(pe),paragraph:s(Ee),reference:y,referenceString:o,resourceDestinationString:o,resourceTitleString:o,setextHeading:s(K),strong:s(Le),thematicBreak:s(et)},exit:{atxHeading:l(),atxHeadingSequence:_,autolink:l(),autolinkEmail:le,autolinkProtocol:ge,blockQuote:l(),characterEscapeValue:v,characterReferenceMarkerHexadecimal:ne,characterReferenceMarkerNumeric:ne,characterReferenceValue:W,characterReference:me,codeFenced:l(w),codeFencedFence:b,codeFencedFenceInfo:p,codeFencedFenceMeta:g,codeFlowValue:v,codeIndented:l(k),codeText:l(j),codeTextData:v,data:v,definition:l(),definitionDestinationString:N,definitionLabelString:C,definitionTitleString:E,emphasis:l(),hardBreakEscape:l(A),hardBreakTrailing:l(A),htmlFlow:l(F),htmlFlowData:v,htmlText:l(T),htmlTextData:v,image:l(D),label:z,labelText:H,lineEnding:L,link:l(R),listItem:l(),listOrdered:l(),listUnordered:l(),paragraph:l(),referenceString:Q,resourceDestinationString:x,resourceTitleString:V,resource:X,setextHeading:l(U),setextHeadingLineSequence:M,setextHeadingText:S,strong:l(),thematicBreak:l()}};ra(t,(e||{}).mdastExtensions||[]);const n={};return r;function r(I){let P={type:"root",children:[]};const Y={stack:[P],tokenStack:[],config:t,enter:a,exit:u,buffer:o,resume:c,data:n},ee=[];let ae=-1;for(;++ae<I.length;)if(I[ae][1].type==="listOrdered"||I[ae][1].type==="listUnordered")if(I[ae][0]==="enter")ee.push(ae);else{const Te=ee.pop();ae=i(I,Te,ae)}for(ae=-1;++ae<I.length;){const Te=t[I[ae][0]];na.call(Te,I[ae][1].type)&&Te[I[ae][1].type].call(Object.assign({sliceSerialize:I[ae][2].sliceSerialize},Y),I[ae][1])}if(Y.tokenStack.length>0){const Te=Y.tokenStack[Y.tokenStack.length-1];(Te[1]||fs).call(Y,void 0,Te[0])}for(P.position={start:ht(I.length>0?I[0][1].start:{line:1,column:1,offset:0}),end:ht(I.length>0?I[I.length-2][1].end:{line:1,column:1,offset:0})},ae=-1;++ae<t.transforms.length;)P=t.transforms[ae](P)||P;return P}function i(I,P,Y){let ee=P-1,ae=-1,Te=!1,He,Oe,Xe,Ue;for(;++ee<=Y;){const Ce=I[ee];switch(Ce[1].type){case"listUnordered":case"listOrdered":case"blockQuote":{Ce[0]==="enter"?ae++:ae--,Ue=void 0;break}case"lineEndingBlank":{Ce[0]==="enter"&&(He&&!Ue&&!ae&&!Xe&&(Xe=ee),Ue=void 0);break}case"linePrefix":case"listItemValue":case"listItemMarker":case"listItemPrefix":case"listItemPrefixWhitespace":break;default:Ue=void 0}if(!ae&&Ce[0]==="enter"&&Ce[1].type==="listItemPrefix"||ae===-1&&Ce[0]==="exit"&&(Ce[1].type==="listUnordered"||Ce[1].type==="listOrdered")){if(He){let je=ee;for(Oe=void 0;je--;){const ze=I[je];if(ze[1].type==="lineEnding"||ze[1].type==="lineEndingBlank"){if(ze[0]==="exit")continue;Oe&&(I[Oe][1].type="lineEndingBlank",Te=!0),ze[1].type="lineEnding",Oe=je}else if(!(ze[1].type==="linePrefix"||ze[1].type==="blockQuotePrefix"||ze[1].type==="blockQuotePrefixWhitespace"||ze[1].type==="blockQuoteMarker"||ze[1].type==="listItemIndent"))break}Xe&&(!Oe||Xe<Oe)&&(He._spread=!0),He.end=Object.assign({},Oe?I[Oe][1].start:Ce[1].end),I.splice(Oe||ee,0,["exit",He,Ce[2]]),ee++,Y++}if(Ce[1].type==="listItemPrefix"){const je={type:"listItem",_spread:!1,start:Object.assign({},Ce[1].start),end:void 0};He=je,I.splice(ee,0,["enter",je,Ce[2]]),ee++,Y++,Xe=void 0,Ue=!0}}}return I[P][1]._spread=Te,Y}function s(I,P){return Y;function Y(ee){a.call(this,I(ee),ee),P&&P.call(this,ee)}}function o(){this.stack.push({type:"fragment",children:[]})}function a(I,P,Y){this.stack[this.stack.length-1].children.push(I),this.stack.push(I),this.tokenStack.push([P,Y||void 0]),I.position={start:ht(P.start),end:void 0}}function l(I){return P;function P(Y){I&&I.call(this,Y),u.call(this,Y)}}function u(I,P){const Y=this.stack.pop(),ee=this.tokenStack.pop();if(ee)ee[0].type!==I.type&&(P?P.call(this,I,ee[0]):(ee[1]||fs).call(this,I,ee[0]));else throw new Error("Cannot close `"+I.type+"` ("+sn({start:I.start,end:I.end})+"): it’s not open");Y.position.end=ht(I.end)}function c(){return hi(this.stack.pop())}function f(){this.data.expectingFirstListItemValue=!0}function d(I){if(this.data.expectingFirstListItemValue){const P=this.stack[this.stack.length-2];P.start=Number.parseInt(this.sliceSerialize(I),10),this.data.expectingFirstListItemValue=void 0}}function p(){const I=this.resume(),P=this.stack[this.stack.length-1];P.lang=I}function g(){const I=this.resume(),P=this.stack[this.stack.length-1];P.meta=I}function b(){this.data.flowCodeInside||(this.buffer(),this.data.flowCodeInside=!0)}function w(){const I=this.resume(),P=this.stack[this.stack.length-1];P.value=I.replace(/^(\r?\n|\r)|(\r?\n|\r)$/g,""),this.data.flowCodeInside=void 0}function k(){const I=this.resume(),P=this.stack[this.stack.length-1];P.value=I.replace(/(\r?\n|\r)$/g,"")}function C(I){const P=this.resume(),Y=this.stack[this.stack.length-1];Y.label=P,Y.identifier=Ze(this.sliceSerialize(I)).toLowerCase()}function E(){const I=this.resume(),P=this.stack[this.stack.length-1];P.title=I}function N(){const I=this.resume(),P=this.stack[this.stack.length-1];P.url=I}function _(I){const P=this.stack[this.stack.length-1];if(!P.depth){const Y=this.sliceSerialize(I).length;P.depth=Y}}function S(){this.data.setextHeadingSlurpLineEnding=!0}function M(I){const P=this.stack[this.stack.length-1];P.depth=this.sliceSerialize(I).codePointAt(0)===61?1:2}function U(){this.data.setextHeadingSlurpLineEnding=void 0}function O(I){const Y=this.stack[this.stack.length-1].children;let ee=Y[Y.length-1];(!ee||ee.type!=="text")&&(ee=st(),ee.position={start:ht(I.start),end:void 0},Y.push(ee)),this.stack.push(ee)}function v(I){const P=this.stack.pop();P.value+=this.sliceSerialize(I),P.position.end=ht(I.end)}function L(I){const P=this.stack[this.stack.length-1];if(this.data.atHardBreak){const Y=P.children[P.children.length-1];Y.position.end=ht(I.end),this.data.atHardBreak=void 0;return}!this.data.setextHeadingSlurpLineEnding&&t.canContainEols.includes(P.type)&&(O.call(this,I),v.call(this,I))}function A(){this.data.atHardBreak=!0}function F(){const I=this.resume(),P=this.stack[this.stack.length-1];P.value=I}function T(){const I=this.resume(),P=this.stack[this.stack.length-1];P.value=I}function j(){const I=this.resume(),P=this.stack[this.stack.length-1];P.value=I}function R(){const I=this.stack[this.stack.length-1];if(this.data.inReference){const P=this.data.referenceType||"shortcut";I.type+="Reference",I.referenceType=P,delete I.url,delete I.title}else delete I.identifier,delete I.label;this.data.referenceType=void 0}function D(){const I=this.stack[this.stack.length-1];if(this.data.inReference){const P=this.data.referenceType||"shortcut";I.type+="Reference",I.referenceType=P,delete I.url,delete I.title}else delete I.identifier,delete I.label;this.data.referenceType=void 0}function H(I){const P=this.sliceSerialize(I),Y=this.stack[this.stack.length-2];Y.label=dd(P),Y.identifier=Ze(P).toLowerCase()}function z(){const I=this.stack[this.stack.length-1],P=this.resume(),Y=this.stack[this.stack.length-1];if(this.data.inReference=!0,Y.type==="link"){const ee=I.children;Y.children=ee}else Y.alt=P}function x(){const I=this.resume(),P=this.stack[this.stack.length-1];P.url=I}function V(){const I=this.resume(),P=this.stack[this.stack.length-1];P.title=I}function X(){this.data.inReference=void 0}function y(){this.data.referenceType="collapsed"}function Q(I){const P=this.resume(),Y=this.stack[this.stack.length-1];Y.label=P,Y.identifier=Ze(this.sliceSerialize(I)).toLowerCase(),this.data.referenceType="full"}function ne(I){this.data.characterReferenceType=I.type}function W(I){const P=this.sliceSerialize(I),Y=this.data.characterReferenceType;let ee;Y?(ee=Wo(P,Y==="characterReferenceMarkerNumeric"?10:16),this.data.characterReferenceType=void 0):ee=pi(P);const ae=this.stack[this.stack.length-1];ae.value+=ee}function me(I){const P=this.stack.pop();P.position.end=ht(I.end)}function ge(I){v.call(this,I);const P=this.stack[this.stack.length-1];P.url=this.sliceSerialize(I)}function le(I){v.call(this,I);const P=this.stack[this.stack.length-1];P.url="mailto:"+this.sliceSerialize(I)}function ie(){return{type:"blockquote",children:[]}}function be(){return{type:"code",lang:null,meta:null,value:""}}function ke(){return{type:"inlineCode",value:""}}function we(){return{type:"definition",identifier:"",label:null,title:null,url:""}}function Se(){return{type:"emphasis",children:[]}}function K(){return{type:"heading",depth:0,children:[]}}function Z(){return{type:"break"}}function $(){return{type:"html",value:""}}function ue(){return{type:"image",title:null,url:"",alt:null}}function re(){return{type:"link",title:null,url:"",children:[]}}function pe(I){return{type:"list",ordered:I.type==="listOrdered",start:null,spread:I._spread,children:[]}}function Be(I){return{type:"listItem",spread:I._spread,checked:null,children:[]}}function Ee(){return{type:"paragraph",children:[]}}function Le(){return{type:"strong",children:[]}}function st(){return{type:"text",value:""}}function et(){return{type:"thematicBreak"}}}function ht(e){return{line:e.line,column:e.column,offset:e.offset}}function ra(e,t){let n=-1;for(;++n<t.length;){const r=t[n];Array.isArray(r)?ra(e,r):yd(e,r)}}function yd(e,t){let n;for(n in t)if(na.call(t,n))switch(n){case"canContainEols":{const r=t[n];r&&e[n].push(...r);break}case"transforms":{const r=t[n];r&&e[n].push(...r);break}case"enter":case"exit":{const r=t[n];r&&Object.assign(e[n],r);break}}}function fs(e,t){throw e?new Error("Cannot close `"+e.type+"` ("+sn({start:e.start,end:e.end})+"): a different token (`"+t.type+"`, "+sn({start:t.start,end:t.end})+") is open"):new Error("Cannot close document, a token (`"+t.type+"`, "+sn({start:t.start,end:t.end})+") is still open")}function bd(e){const t=this;t.parser=n;function n(r){return gd(r,{...t.data("settings"),...e,extensions:t.data("micromarkExtensions")||[],mdastExtensions:t.data("fromMarkdownExtensions")||[]})}}function kd(e,t){const n={type:"element",tagName:"blockquote",properties:{},children:e.wrap(e.all(t),!0)};return e.patch(t,n),e.applyData(t,n)}function wd(e,t){const n={type:"element",tagName:"br",properties:{},children:[]};return e.patch(t,n),[e.applyData(t,n),{type:"text",value:`
|
|
66
|
+
`;break}case-2:{o=t?" ":" ";break}case-1:{if(!t&&i)continue;o=" ";break}default:o=String.fromCharCode(s)}i=s===-2,r.push(o)}return r.join("")}function cd(e){const r={constructs:Ko([od,...(e||{}).extensions||[]]),content:i(Eh),defined:[],document:i(jh),flow:i(Kp),lazy:{},string:i(Xp),text:i(Yp)};return r;function i(s){return o;function o(a){return ad(r,s,a)}}}function fd(e){for(;!Go(e););return e}const cs=/[\0\t\n\r]/g;function hd(){let e=1,t="",n=!0,r;return i;function i(s,o,a){const l=[];let u,c,f,d,p;for(s=t+(typeof s=="string"?s.toString():new TextDecoder(o||void 0).decode(s)),f=0,t="",n&&(s.charCodeAt(0)===65279&&f++,n=void 0);f<s.length;){if(cs.lastIndex=f,u=cs.exec(s),d=u&&u.index!==void 0?u.index:s.length,p=s.charCodeAt(d),!u){t=s.slice(f);break}if(p===10&&f===d&&r)l.push(-3),r=void 0;else switch(r&&(l.push(-5),r=void 0),f<d&&(l.push(s.slice(f,d)),e+=d-f),p){case 0:{l.push(65533),e++;break}case 9:{for(c=Math.ceil(e/4)*4,l.push(-2);e++<c;)l.push(-1);break}case 10:{l.push(-4),e=1;break}default:r=!0,e=1}f=d+1}return a&&(r&&l.push(-5),t&&l.push(t),l.push(null)),l}}const pd=/\\([!-/:-@[-`{-~])|&(#(?:\d{1,7}|x[\da-f]{1,6})|[\da-z]{1,31});/gi;function dd(e){return e.replace(pd,md)}function md(e,t,n){if(t)return t;if(n.charCodeAt(0)===35){const i=n.charCodeAt(1),s=i===120||i===88;return Wo(n.slice(s?2:1),s?16:10)}return pi(n)||e}const na={}.hasOwnProperty;function gd(e,t,n){return typeof t!="string"&&(n=t,t=void 0),xd(n)(fd(cd(n).document().write(hd()(e,t,!0))))}function xd(e){const t={transforms:[],canContainEols:["emphasis","fragment","heading","paragraph","strong"],enter:{autolink:s(xe),autolinkProtocol:F,autolinkEmail:F,atxHeading:s(Le),blockQuote:s(se),characterEscape:F,characterReference:F,codeFenced:s(ge),codeFencedFenceInfo:o,codeFencedFenceMeta:o,codeIndented:s(ge,o),codeText:s(ke,o),codeTextData:F,data:F,codeFlowValue:F,definition:s(we),definitionDestinationString:o,definitionLabelString:o,definitionTitleString:o,emphasis:s(Se),hardBreakEscape:s(W),hardBreakTrailing:s(W),htmlFlow:s($,o),htmlFlowData:F,htmlText:s($,o),htmlTextData:F,image:s(J),label:o,link:s(xe),listItem:s(pe),listItemValue:d,listOrdered:s(ne,f),listUnordered:s(ne),paragraph:s(Oe),reference:b,referenceString:o,resourceDestinationString:o,resourceTitleString:o,setextHeading:s(Le),strong:s(Fe),thematicBreak:s($e)},exit:{atxHeading:l(),atxHeadingSequence:M,autolink:l(),autolinkEmail:ue,autolinkProtocol:me,blockQuote:l(),characterEscapeValue:E,characterReferenceMarkerHexadecimal:re,characterReferenceMarkerNumeric:re,characterReferenceValue:K,characterReference:he,codeFenced:l(w),codeFencedFence:y,codeFencedFenceInfo:p,codeFencedFenceMeta:g,codeFlowValue:E,codeIndented:l(k),codeText:l(T),codeTextData:E,data:E,definition:l(),definitionDestinationString:R,definitionLabelString:S,definitionTitleString:v,emphasis:l(),hardBreakEscape:l(A),hardBreakTrailing:l(A),htmlFlow:l(P),htmlFlowData:E,htmlText:l(j),htmlTextData:E,image:l(L),label:_,labelText:H,lineEnding:N,link:l(D),listItem:l(),listOrdered:l(),listUnordered:l(),paragraph:l(),referenceString:Q,resourceDestinationString:x,resourceTitleString:V,resource:X,setextHeading:l(U),setextHeadingLineSequence:z,setextHeadingText:C,strong:l(),thematicBreak:l()}};ra(t,(e||{}).mdastExtensions||[]);const n={};return r;function r(I){let O={type:"root",children:[]};const Y={stack:[O],tokenStack:[],config:t,enter:a,exit:u,buffer:o,resume:c,data:n},ee=[];let ae=-1;for(;++ae<I.length;)if(I[ae][1].type==="listOrdered"||I[ae][1].type==="listUnordered")if(I[ae][0]==="enter")ee.push(ae);else{const Ee=ee.pop();ae=i(I,Ee,ae)}for(ae=-1;++ae<I.length;){const Ee=t[I[ae][0]];na.call(Ee,I[ae][1].type)&&Ee[I[ae][1].type].call(Object.assign({sliceSerialize:I[ae][2].sliceSerialize},Y),I[ae][1])}if(Y.tokenStack.length>0){const Ee=Y.tokenStack[Y.tokenStack.length-1];(Ee[1]||fs).call(Y,void 0,Ee[0])}for(O.position={start:ht(I.length>0?I[0][1].start:{line:1,column:1,offset:0}),end:ht(I.length>0?I[I.length-2][1].end:{line:1,column:1,offset:0})},ae=-1;++ae<t.transforms.length;)O=t.transforms[ae](O)||O;return O}function i(I,O,Y){let ee=O-1,ae=-1,Ee=!1,qe,Be,Ge,Ke;for(;++ee<=Y;){const Ce=I[ee];switch(Ce[1].type){case"listUnordered":case"listOrdered":case"blockQuote":{Ce[0]==="enter"?ae++:ae--,Ke=void 0;break}case"lineEndingBlank":{Ce[0]==="enter"&&(qe&&!Ke&&!ae&&!Ge&&(Ge=ee),Ke=void 0);break}case"linePrefix":case"listItemValue":case"listItemMarker":case"listItemPrefix":case"listItemPrefixWhitespace":break;default:Ke=void 0}if(!ae&&Ce[0]==="enter"&&Ce[1].type==="listItemPrefix"||ae===-1&&Ce[0]==="exit"&&(Ce[1].type==="listUnordered"||Ce[1].type==="listOrdered")){if(qe){let Te=ee;for(Be=void 0;Te--;){const ze=I[Te];if(ze[1].type==="lineEnding"||ze[1].type==="lineEndingBlank"){if(ze[0]==="exit")continue;Be&&(I[Be][1].type="lineEndingBlank",Ee=!0),ze[1].type="lineEnding",Be=Te}else if(!(ze[1].type==="linePrefix"||ze[1].type==="blockQuotePrefix"||ze[1].type==="blockQuotePrefixWhitespace"||ze[1].type==="blockQuoteMarker"||ze[1].type==="listItemIndent"))break}Ge&&(!Be||Ge<Be)&&(qe._spread=!0),qe.end=Object.assign({},Be?I[Be][1].start:Ce[1].end),I.splice(Be||ee,0,["exit",qe,Ce[2]]),ee++,Y++}if(Ce[1].type==="listItemPrefix"){const Te={type:"listItem",_spread:!1,start:Object.assign({},Ce[1].start),end:void 0};qe=Te,I.splice(ee,0,["enter",Te,Ce[2]]),ee++,Y++,Ge=void 0,Ke=!0}}}return I[O][1]._spread=Ee,Y}function s(I,O){return Y;function Y(ee){a.call(this,I(ee),ee),O&&O.call(this,ee)}}function o(){this.stack.push({type:"fragment",children:[]})}function a(I,O,Y){this.stack[this.stack.length-1].children.push(I),this.stack.push(I),this.tokenStack.push([O,Y||void 0]),I.position={start:ht(O.start),end:void 0}}function l(I){return O;function O(Y){I&&I.call(this,Y),u.call(this,Y)}}function u(I,O){const Y=this.stack.pop(),ee=this.tokenStack.pop();if(ee)ee[0].type!==I.type&&(O?O.call(this,I,ee[0]):(ee[1]||fs).call(this,I,ee[0]));else throw new Error("Cannot close `"+I.type+"` ("+sn({start:I.start,end:I.end})+"): it’s not open");Y.position.end=ht(I.end)}function c(){return hi(this.stack.pop())}function f(){this.data.expectingFirstListItemValue=!0}function d(I){if(this.data.expectingFirstListItemValue){const O=this.stack[this.stack.length-2];O.start=Number.parseInt(this.sliceSerialize(I),10),this.data.expectingFirstListItemValue=void 0}}function p(){const I=this.resume(),O=this.stack[this.stack.length-1];O.lang=I}function g(){const I=this.resume(),O=this.stack[this.stack.length-1];O.meta=I}function y(){this.data.flowCodeInside||(this.buffer(),this.data.flowCodeInside=!0)}function w(){const I=this.resume(),O=this.stack[this.stack.length-1];O.value=I.replace(/^(\r?\n|\r)|(\r?\n|\r)$/g,""),this.data.flowCodeInside=void 0}function k(){const I=this.resume(),O=this.stack[this.stack.length-1];O.value=I.replace(/(\r?\n|\r)$/g,"")}function S(I){const O=this.resume(),Y=this.stack[this.stack.length-1];Y.label=O,Y.identifier=tt(this.sliceSerialize(I)).toLowerCase()}function v(){const I=this.resume(),O=this.stack[this.stack.length-1];O.title=I}function R(){const I=this.resume(),O=this.stack[this.stack.length-1];O.url=I}function M(I){const O=this.stack[this.stack.length-1];if(!O.depth){const Y=this.sliceSerialize(I).length;O.depth=Y}}function C(){this.data.setextHeadingSlurpLineEnding=!0}function z(I){const O=this.stack[this.stack.length-1];O.depth=this.sliceSerialize(I).codePointAt(0)===61?1:2}function U(){this.data.setextHeadingSlurpLineEnding=void 0}function F(I){const Y=this.stack[this.stack.length-1].children;let ee=Y[Y.length-1];(!ee||ee.type!=="text")&&(ee=Ae(),ee.position={start:ht(I.start),end:void 0},Y.push(ee)),this.stack.push(ee)}function E(I){const O=this.stack.pop();O.value+=this.sliceSerialize(I),O.position.end=ht(I.end)}function N(I){const O=this.stack[this.stack.length-1];if(this.data.atHardBreak){const Y=O.children[O.children.length-1];Y.position.end=ht(I.end),this.data.atHardBreak=void 0;return}!this.data.setextHeadingSlurpLineEnding&&t.canContainEols.includes(O.type)&&(F.call(this,I),E.call(this,I))}function A(){this.data.atHardBreak=!0}function P(){const I=this.resume(),O=this.stack[this.stack.length-1];O.value=I}function j(){const I=this.resume(),O=this.stack[this.stack.length-1];O.value=I}function T(){const I=this.resume(),O=this.stack[this.stack.length-1];O.value=I}function D(){const I=this.stack[this.stack.length-1];if(this.data.inReference){const O=this.data.referenceType||"shortcut";I.type+="Reference",I.referenceType=O,delete I.url,delete I.title}else delete I.identifier,delete I.label;this.data.referenceType=void 0}function L(){const I=this.stack[this.stack.length-1];if(this.data.inReference){const O=this.data.referenceType||"shortcut";I.type+="Reference",I.referenceType=O,delete I.url,delete I.title}else delete I.identifier,delete I.label;this.data.referenceType=void 0}function H(I){const O=this.sliceSerialize(I),Y=this.stack[this.stack.length-2];Y.label=dd(O),Y.identifier=tt(O).toLowerCase()}function _(){const I=this.stack[this.stack.length-1],O=this.resume(),Y=this.stack[this.stack.length-1];if(this.data.inReference=!0,Y.type==="link"){const ee=I.children;Y.children=ee}else Y.alt=O}function x(){const I=this.resume(),O=this.stack[this.stack.length-1];O.url=I}function V(){const I=this.resume(),O=this.stack[this.stack.length-1];O.title=I}function X(){this.data.inReference=void 0}function b(){this.data.referenceType="collapsed"}function Q(I){const O=this.resume(),Y=this.stack[this.stack.length-1];Y.label=O,Y.identifier=tt(this.sliceSerialize(I)).toLowerCase(),this.data.referenceType="full"}function re(I){this.data.characterReferenceType=I.type}function K(I){const O=this.sliceSerialize(I),Y=this.data.characterReferenceType;let ee;Y?(ee=Wo(O,Y==="characterReferenceMarkerNumeric"?10:16),this.data.characterReferenceType=void 0):ee=pi(O);const ae=this.stack[this.stack.length-1];ae.value+=ee}function he(I){const O=this.stack.pop();O.position.end=ht(I.end)}function me(I){E.call(this,I);const O=this.stack[this.stack.length-1];O.url=this.sliceSerialize(I)}function ue(I){E.call(this,I);const O=this.stack[this.stack.length-1];O.url="mailto:"+this.sliceSerialize(I)}function se(){return{type:"blockquote",children:[]}}function ge(){return{type:"code",lang:null,meta:null,value:""}}function ke(){return{type:"inlineCode",value:""}}function we(){return{type:"definition",identifier:"",label:null,title:null,url:""}}function Se(){return{type:"emphasis",children:[]}}function Le(){return{type:"heading",depth:0,children:[]}}function W(){return{type:"break"}}function $(){return{type:"html",value:""}}function J(){return{type:"image",title:null,url:"",alt:null}}function xe(){return{type:"link",title:null,url:"",children:[]}}function ne(I){return{type:"list",ordered:I.type==="listOrdered",start:null,spread:I._spread,children:[]}}function pe(I){return{type:"listItem",spread:I._spread,checked:null,children:[]}}function Oe(){return{type:"paragraph",children:[]}}function Fe(){return{type:"strong",children:[]}}function Ae(){return{type:"text",value:""}}function $e(){return{type:"thematicBreak"}}}function ht(e){return{line:e.line,column:e.column,offset:e.offset}}function ra(e,t){let n=-1;for(;++n<t.length;){const r=t[n];Array.isArray(r)?ra(e,r):yd(e,r)}}function yd(e,t){let n;for(n in t)if(na.call(t,n))switch(n){case"canContainEols":{const r=t[n];r&&e[n].push(...r);break}case"transforms":{const r=t[n];r&&e[n].push(...r);break}case"enter":case"exit":{const r=t[n];r&&Object.assign(e[n],r);break}}}function fs(e,t){throw e?new Error("Cannot close `"+e.type+"` ("+sn({start:e.start,end:e.end})+"): a different token (`"+t.type+"`, "+sn({start:t.start,end:t.end})+") is open"):new Error("Cannot close document, a token (`"+t.type+"`, "+sn({start:t.start,end:t.end})+") is still open")}function bd(e){const t=this;t.parser=n;function n(r){return gd(r,{...t.data("settings"),...e,extensions:t.data("micromarkExtensions")||[],mdastExtensions:t.data("fromMarkdownExtensions")||[]})}}function kd(e,t){const n={type:"element",tagName:"blockquote",properties:{},children:e.wrap(e.all(t),!0)};return e.patch(t,n),e.applyData(t,n)}function wd(e,t){const n={type:"element",tagName:"br",properties:{},children:[]};return e.patch(t,n),[e.applyData(t,n),{type:"text",value:`
|
|
67
67
|
`}]}function Sd(e,t){const n=t.value?t.value+`
|
|
68
68
|
`:"",r={},i=t.lang?t.lang.split(/\s+/):[];i.length>0&&(r.className=["language-"+i[0]]);let s={type:"element",tagName:"code",properties:r,children:[{type:"text",value:n}]};return t.meta&&(s.data={meta:t.meta}),e.patch(t,s),s=e.applyData(t,s),s={type:"element",tagName:"pre",properties:{},children:[s]},e.patch(t,s),s}function Cd(e,t){const n={type:"element",tagName:"del",properties:{},children:e.all(t)};return e.patch(t,n),e.applyData(t,n)}function vd(e,t){const n={type:"element",tagName:"em",properties:{},children:e.all(t)};return e.patch(t,n),e.applyData(t,n)}function Ed(e,t){const n=typeof e.options.clobberPrefix=="string"?e.options.clobberPrefix:"user-content-",r=String(t.identifier).toUpperCase(),i=Kt(r.toLowerCase()),s=e.footnoteOrder.indexOf(r);let o,a=e.footnoteCounts.get(r);a===void 0?(a=0,e.footnoteOrder.push(r),o=e.footnoteOrder.length):o=s+1,a+=1,e.footnoteCounts.set(r,a);const l={type:"element",tagName:"a",properties:{href:"#"+n+"fn-"+i,id:n+"fnref-"+i+(a>1?"-"+a:""),dataFootnoteRef:!0,ariaDescribedBy:["footnote-label"]},children:[{type:"text",value:String(o)}]};e.patch(t,l);const u={type:"element",tagName:"sup",properties:{},children:[l]};return e.patch(t,u),e.applyData(t,u)}function Td(e,t){const n={type:"element",tagName:"h"+t.depth,properties:{},children:e.all(t)};return e.patch(t,n),e.applyData(t,n)}function jd(e,t){if(e.options.allowDangerousHtml){const n={type:"raw",value:t.value};return e.patch(t,n),e.applyData(t,n)}}function ia(e,t){const n=t.referenceType;let r="]";if(n==="collapsed"?r+="[]":n==="full"&&(r+="["+(t.label||t.identifier)+"]"),t.type==="imageReference")return[{type:"text",value:"!["+t.alt+r}];const i=e.all(t),s=i[0];s&&s.type==="text"?s.value="["+s.value:i.unshift({type:"text",value:"["});const o=i[i.length-1];return o&&o.type==="text"?o.value+=r:i.push({type:"text",value:r}),i}function Ad(e,t){const n=String(t.identifier).toUpperCase(),r=e.definitionById.get(n);if(!r)return ia(e,t);const i={src:Kt(r.url||""),alt:t.alt};r.title!==null&&r.title!==void 0&&(i.title=r.title);const s={type:"element",tagName:"img",properties:i,children:[]};return e.patch(t,s),e.applyData(t,s)}function Id(e,t){const n={src:Kt(t.url)};t.alt!==null&&t.alt!==void 0&&(n.alt=t.alt),t.title!==null&&t.title!==void 0&&(n.title=t.title);const r={type:"element",tagName:"img",properties:n,children:[]};return e.patch(t,r),e.applyData(t,r)}function Rd(e,t){const n={type:"text",value:t.value.replace(/\r?\n|\r/g," ")};e.patch(t,n);const r={type:"element",tagName:"code",properties:{},children:[n]};return e.patch(t,r),e.applyData(t,r)}function Nd(e,t){const n=String(t.identifier).toUpperCase(),r=e.definitionById.get(n);if(!r)return ia(e,t);const i={href:Kt(r.url||"")};r.title!==null&&r.title!==void 0&&(i.title=r.title);const s={type:"element",tagName:"a",properties:i,children:e.all(t)};return e.patch(t,s),e.applyData(t,s)}function Ld(e,t){const n={href:Kt(t.url)};t.title!==null&&t.title!==void 0&&(n.title=t.title);const r={type:"element",tagName:"a",properties:n,children:e.all(t)};return e.patch(t,r),e.applyData(t,r)}function Md(e,t,n){const r=e.all(t),i=n?Dd(n):sa(t),s={},o=[];if(typeof t.checked=="boolean"){const c=r[0];let f;c&&c.type==="element"&&c.tagName==="p"?f=c:(f={type:"element",tagName:"p",properties:{},children:[]},r.unshift(f)),f.children.length>0&&f.children.unshift({type:"text",value:" "}),f.children.unshift({type:"element",tagName:"input",properties:{type:"checkbox",checked:t.checked,disabled:!0},children:[]}),s.className=["task-list-item"]}let a=-1;for(;++a<r.length;){const c=r[a];(i||a!==0||c.type!=="element"||c.tagName!=="p")&&o.push({type:"text",value:`
|
|
69
69
|
`}),c.type==="element"&&c.tagName==="p"&&!i?o.push(...c.children):o.push(c)}const l=r[r.length-1];l&&(i||l.type!=="element"||l.tagName!=="p")&&o.push({type:"text",value:`
|
|
70
|
-
`});const u={type:"element",tagName:"li",properties:s,children:o};return e.patch(t,u),e.applyData(t,u)}function Dd(e){let t=!1;if(e.type==="list"){t=e.spread||!1;const n=e.children;let r=-1;for(;!t&&++r<n.length;)t=sa(n[r])}return t}function sa(e){const t=e.spread;return t??e.children.length>1}function zd(e,t){const n={},r=e.all(t);let i=-1;for(typeof t.start=="number"&&t.start!==1&&(n.start=t.start);++i<r.length;){const o=r[i];if(o.type==="element"&&o.tagName==="li"&&o.properties&&Array.isArray(o.properties.className)&&o.properties.className.includes("task-list-item")){n.className=["contains-task-list"];break}}const s={type:"element",tagName:t.ordered?"ol":"ul",properties:n,children:e.wrap(r,!0)};return e.patch(t,s),e.applyData(t,s)}function Pd(e,t){const n={type:"element",tagName:"p",properties:{},children:e.all(t)};return e.patch(t,n),e.applyData(t,n)}function _d(e,t){const n={type:"root",children:e.wrap(e.all(t))};return e.patch(t,n),e.applyData(t,n)}function Od(e,t){const n={type:"element",tagName:"strong",properties:{},children:e.all(t)};return e.patch(t,n),e.applyData(t,n)}function Fd(e,t){const n=e.all(t),r=n.shift(),i=[];if(r){const o={type:"element",tagName:"thead",properties:{},children:e.wrap([r],!0)};e.patch(t.children[0],o),i.push(o)}if(n.length>0){const o={type:"element",tagName:"tbody",properties:{},children:e.wrap(n,!0)},a=li(t.children[1]),l=Oo(t.children[t.children.length-1]);a&&l&&(o.position={start:a,end:l}),i.push(o)}const s={type:"element",tagName:"table",properties:{},children:e.wrap(i,!0)};return e.patch(t,s),e.applyData(t,s)}function $d(e,t,n){const r=n?n.children:void 0,s=(r?r.indexOf(t):1)===0?"th":"td",o=n&&n.type==="table"?n.align:void 0,a=o?o.length:t.children.length;let l=-1;const u=[];for(;++l<a;){const f=t.children[l],d={},p=o?o[l]:void 0;p&&(d.align=p);let g={type:"element",tagName:s,properties:d,children:[]};f&&(g.children=e.all(f),e.patch(f,g),g=e.applyData(f,g)),u.push(g)}const c={type:"element",tagName:"tr",properties:{},children:e.wrap(u,!0)};return e.patch(t,c),e.applyData(t,c)}function Bd(e,t){const n={type:"element",tagName:"td",properties:{},children:e.all(t)};return e.patch(t,n),e.applyData(t,n)}const hs=9,ps=32;function Hd(e){const t=String(e),n=/\r?\n|\r/g;let r=n.exec(t),i=0;const s=[];for(;r;)s.push(ds(t.slice(i,r.index),i>0,!0),r[0]),i=r.index+r[0].length,r=n.exec(t);return s.push(ds(t.slice(i),i>0,!1)),s.join("")}function ds(e,t,n){let r=0,i=e.length;if(t){let s=e.codePointAt(r);for(;s===hs||s===ps;)r++,s=e.codePointAt(r)}if(n){let s=e.codePointAt(i-1);for(;s===hs||s===ps;)i--,s=e.codePointAt(i-1)}return i>r?e.slice(r,i):""}function Ud(e,t){const n={type:"text",value:Hd(String(t.value))};return e.patch(t,n),e.applyData(t,n)}function qd(e,t){const n={type:"element",tagName:"hr",properties:{},children:[]};return e.patch(t,n),e.applyData(t,n)}const Kd={blockquote:kd,break:wd,code:Sd,delete:Cd,emphasis:vd,footnoteReference:Ed,heading:Td,html:jd,imageReference:Ad,image:Id,inlineCode:Rd,linkReference:Nd,link:Ld,listItem:Md,list:zd,paragraph:Pd,root:_d,strong:Od,table:Fd,tableCell:Bd,tableRow:$d,text:Ud,thematicBreak:qd,toml:gn,yaml:gn,definition:gn,footnoteDefinition:gn};function gn(){}const oa=-1,Yn=0,an=1,Pn=2,mi=3,gi=4,xi=5,yi=6,aa=7,la=8,ms=typeof self=="object"?self:globalThis,Wd=(e,t)=>{const n=(i,s)=>(e.set(s,i),i),r=i=>{if(e.has(i))return e.get(i);const[s,o]=t[i];switch(s){case Yn:case oa:return n(o,i);case an:{const a=n([],i);for(const l of o)a.push(r(l));return a}case Pn:{const a=n({},i);for(const[l,u]of o)a[r(l)]=r(u);return a}case mi:return n(new Date(o),i);case gi:{const{source:a,flags:l}=o;return n(new RegExp(a,l),i)}case xi:{const a=n(new Map,i);for(const[l,u]of o)a.set(r(l),r(u));return a}case yi:{const a=n(new Set,i);for(const l of o)a.add(r(l));return a}case aa:{const{name:a,message:l}=o;return n(new ms[a](l),i)}case la:return n(BigInt(o),i);case"BigInt":return n(Object(BigInt(o)),i);case"ArrayBuffer":return n(new Uint8Array(o).buffer,o);case"DataView":{const{buffer:a}=new Uint8Array(o);return n(new DataView(a),o)}}return n(new ms[s](o),i)};return r},gs=e=>Wd(new Map,e)(0),Ft="",{toString:Vd}={},{keys:Xd}=Object,Zt=e=>{const t=typeof e;if(t!=="object"||!e)return[Yn,t];const n=Vd.call(e).slice(8,-1);switch(n){case"Array":return[an,Ft];case"Object":return[Pn,Ft];case"Date":return[mi,Ft];case"RegExp":return[gi,Ft];case"Map":return[xi,Ft];case"Set":return[yi,Ft];case"DataView":return[an,n]}return n.includes("Array")?[an,n]:n.includes("Error")?[aa,n]:[Pn,n]},xn=([e,t])=>e===Yn&&(t==="function"||t==="symbol"),Yd=(e,t,n,r)=>{const i=(o,a)=>{const l=r.push(o)-1;return n.set(a,l),l},s=o=>{if(n.has(o))return n.get(o);let[a,l]=Zt(o);switch(a){case Yn:{let c=o;switch(l){case"bigint":a=la,c=o.toString();break;case"function":case"symbol":if(e)throw new TypeError("unable to serialize "+l);c=null;break;case"undefined":return i([oa],o)}return i([a,c],o)}case an:{if(l){let d=o;return l==="DataView"?d=new Uint8Array(o.buffer):l==="ArrayBuffer"&&(d=new Uint8Array(o)),i([l,[...d]],o)}const c=[],f=i([a,c],o);for(const d of o)c.push(s(d));return f}case Pn:{if(l)switch(l){case"BigInt":return i([l,o.toString()],o);case"Boolean":case"Number":case"String":return i([l,o.valueOf()],o)}if(t&&"toJSON"in o)return s(o.toJSON());const c=[],f=i([a,c],o);for(const d of Xd(o))(e||!xn(Zt(o[d])))&&c.push([s(d),s(o[d])]);return f}case mi:return i([a,o.toISOString()],o);case gi:{const{source:c,flags:f}=o;return i([a,{source:c,flags:f}],o)}case xi:{const c=[],f=i([a,c],o);for(const[d,p]of o)(e||!(xn(Zt(d))||xn(Zt(p))))&&c.push([s(d),s(p)]);return f}case yi:{const c=[],f=i([a,c],o);for(const d of o)(e||!xn(Zt(d)))&&c.push(s(d));return f}}const{message:u}=o;return i([a,{name:l,message:u}],o)};return s},xs=(e,{json:t,lossy:n}={})=>{const r=[];return Yd(!(t||n),!!t,new Map,r)(e),r},_n=typeof structuredClone=="function"?(e,t)=>t&&("json"in t||"lossy"in t)?gs(xs(e,t)):structuredClone(e):(e,t)=>gs(xs(e,t));function Gd(e,t){const n=[{type:"text",value:"↩"}];return t>1&&n.push({type:"element",tagName:"sup",properties:{},children:[{type:"text",value:String(t)}]}),n}function Qd(e,t){return"Back to reference "+(e+1)+(t>1?"-"+t:"")}function Jd(e){const t=typeof e.options.clobberPrefix=="string"?e.options.clobberPrefix:"user-content-",n=e.options.footnoteBackContent||Gd,r=e.options.footnoteBackLabel||Qd,i=e.options.footnoteLabel||"Footnotes",s=e.options.footnoteLabelTagName||"h2",o=e.options.footnoteLabelProperties||{className:["sr-only"]},a=[];let l=-1;for(;++l<e.footnoteOrder.length;){const u=e.footnoteById.get(e.footnoteOrder[l]);if(!u)continue;const c=e.all(u),f=String(u.identifier).toUpperCase(),d=Kt(f.toLowerCase());let p=0;const g=[],
|
|
70
|
+
`});const u={type:"element",tagName:"li",properties:s,children:o};return e.patch(t,u),e.applyData(t,u)}function Dd(e){let t=!1;if(e.type==="list"){t=e.spread||!1;const n=e.children;let r=-1;for(;!t&&++r<n.length;)t=sa(n[r])}return t}function sa(e){const t=e.spread;return t??e.children.length>1}function zd(e,t){const n={},r=e.all(t);let i=-1;for(typeof t.start=="number"&&t.start!==1&&(n.start=t.start);++i<r.length;){const o=r[i];if(o.type==="element"&&o.tagName==="li"&&o.properties&&Array.isArray(o.properties.className)&&o.properties.className.includes("task-list-item")){n.className=["contains-task-list"];break}}const s={type:"element",tagName:t.ordered?"ol":"ul",properties:n,children:e.wrap(r,!0)};return e.patch(t,s),e.applyData(t,s)}function Pd(e,t){const n={type:"element",tagName:"p",properties:{},children:e.all(t)};return e.patch(t,n),e.applyData(t,n)}function _d(e,t){const n={type:"root",children:e.wrap(e.all(t))};return e.patch(t,n),e.applyData(t,n)}function Od(e,t){const n={type:"element",tagName:"strong",properties:{},children:e.all(t)};return e.patch(t,n),e.applyData(t,n)}function Fd(e,t){const n=e.all(t),r=n.shift(),i=[];if(r){const o={type:"element",tagName:"thead",properties:{},children:e.wrap([r],!0)};e.patch(t.children[0],o),i.push(o)}if(n.length>0){const o={type:"element",tagName:"tbody",properties:{},children:e.wrap(n,!0)},a=li(t.children[1]),l=Oo(t.children[t.children.length-1]);a&&l&&(o.position={start:a,end:l}),i.push(o)}const s={type:"element",tagName:"table",properties:{},children:e.wrap(i,!0)};return e.patch(t,s),e.applyData(t,s)}function $d(e,t,n){const r=n?n.children:void 0,s=(r?r.indexOf(t):1)===0?"th":"td",o=n&&n.type==="table"?n.align:void 0,a=o?o.length:t.children.length;let l=-1;const u=[];for(;++l<a;){const f=t.children[l],d={},p=o?o[l]:void 0;p&&(d.align=p);let g={type:"element",tagName:s,properties:d,children:[]};f&&(g.children=e.all(f),e.patch(f,g),g=e.applyData(f,g)),u.push(g)}const c={type:"element",tagName:"tr",properties:{},children:e.wrap(u,!0)};return e.patch(t,c),e.applyData(t,c)}function Bd(e,t){const n={type:"element",tagName:"td",properties:{},children:e.all(t)};return e.patch(t,n),e.applyData(t,n)}const hs=9,ps=32;function Hd(e){const t=String(e),n=/\r?\n|\r/g;let r=n.exec(t),i=0;const s=[];for(;r;)s.push(ds(t.slice(i,r.index),i>0,!0),r[0]),i=r.index+r[0].length,r=n.exec(t);return s.push(ds(t.slice(i),i>0,!1)),s.join("")}function ds(e,t,n){let r=0,i=e.length;if(t){let s=e.codePointAt(r);for(;s===hs||s===ps;)r++,s=e.codePointAt(r)}if(n){let s=e.codePointAt(i-1);for(;s===hs||s===ps;)i--,s=e.codePointAt(i-1)}return i>r?e.slice(r,i):""}function Ud(e,t){const n={type:"text",value:Hd(String(t.value))};return e.patch(t,n),e.applyData(t,n)}function qd(e,t){const n={type:"element",tagName:"hr",properties:{},children:[]};return e.patch(t,n),e.applyData(t,n)}const Kd={blockquote:kd,break:wd,code:Sd,delete:Cd,emphasis:vd,footnoteReference:Ed,heading:Td,html:jd,imageReference:Ad,image:Id,inlineCode:Rd,linkReference:Nd,link:Ld,listItem:Md,list:zd,paragraph:Pd,root:_d,strong:Od,table:Fd,tableCell:Bd,tableRow:$d,text:Ud,thematicBreak:qd,toml:gn,yaml:gn,definition:gn,footnoteDefinition:gn};function gn(){}const oa=-1,Yn=0,an=1,Pn=2,mi=3,gi=4,xi=5,yi=6,aa=7,la=8,ms=typeof self=="object"?self:globalThis,Wd=(e,t)=>{const n=(i,s)=>(e.set(s,i),i),r=i=>{if(e.has(i))return e.get(i);const[s,o]=t[i];switch(s){case Yn:case oa:return n(o,i);case an:{const a=n([],i);for(const l of o)a.push(r(l));return a}case Pn:{const a=n({},i);for(const[l,u]of o)a[r(l)]=r(u);return a}case mi:return n(new Date(o),i);case gi:{const{source:a,flags:l}=o;return n(new RegExp(a,l),i)}case xi:{const a=n(new Map,i);for(const[l,u]of o)a.set(r(l),r(u));return a}case yi:{const a=n(new Set,i);for(const l of o)a.add(r(l));return a}case aa:{const{name:a,message:l}=o;return n(new ms[a](l),i)}case la:return n(BigInt(o),i);case"BigInt":return n(Object(BigInt(o)),i);case"ArrayBuffer":return n(new Uint8Array(o).buffer,o);case"DataView":{const{buffer:a}=new Uint8Array(o);return n(new DataView(a),o)}}return n(new ms[s](o),i)};return r},gs=e=>Wd(new Map,e)(0),Ft="",{toString:Vd}={},{keys:Xd}=Object,Zt=e=>{const t=typeof e;if(t!=="object"||!e)return[Yn,t];const n=Vd.call(e).slice(8,-1);switch(n){case"Array":return[an,Ft];case"Object":return[Pn,Ft];case"Date":return[mi,Ft];case"RegExp":return[gi,Ft];case"Map":return[xi,Ft];case"Set":return[yi,Ft];case"DataView":return[an,n]}return n.includes("Array")?[an,n]:n.includes("Error")?[aa,n]:[Pn,n]},xn=([e,t])=>e===Yn&&(t==="function"||t==="symbol"),Yd=(e,t,n,r)=>{const i=(o,a)=>{const l=r.push(o)-1;return n.set(a,l),l},s=o=>{if(n.has(o))return n.get(o);let[a,l]=Zt(o);switch(a){case Yn:{let c=o;switch(l){case"bigint":a=la,c=o.toString();break;case"function":case"symbol":if(e)throw new TypeError("unable to serialize "+l);c=null;break;case"undefined":return i([oa],o)}return i([a,c],o)}case an:{if(l){let d=o;return l==="DataView"?d=new Uint8Array(o.buffer):l==="ArrayBuffer"&&(d=new Uint8Array(o)),i([l,[...d]],o)}const c=[],f=i([a,c],o);for(const d of o)c.push(s(d));return f}case Pn:{if(l)switch(l){case"BigInt":return i([l,o.toString()],o);case"Boolean":case"Number":case"String":return i([l,o.valueOf()],o)}if(t&&"toJSON"in o)return s(o.toJSON());const c=[],f=i([a,c],o);for(const d of Xd(o))(e||!xn(Zt(o[d])))&&c.push([s(d),s(o[d])]);return f}case mi:return i([a,o.toISOString()],o);case gi:{const{source:c,flags:f}=o;return i([a,{source:c,flags:f}],o)}case xi:{const c=[],f=i([a,c],o);for(const[d,p]of o)(e||!(xn(Zt(d))||xn(Zt(p))))&&c.push([s(d),s(p)]);return f}case yi:{const c=[],f=i([a,c],o);for(const d of o)(e||!xn(Zt(d)))&&c.push(s(d));return f}}const{message:u}=o;return i([a,{name:l,message:u}],o)};return s},xs=(e,{json:t,lossy:n}={})=>{const r=[];return Yd(!(t||n),!!t,new Map,r)(e),r},_n=typeof structuredClone=="function"?(e,t)=>t&&("json"in t||"lossy"in t)?gs(xs(e,t)):structuredClone(e):(e,t)=>gs(xs(e,t));function Gd(e,t){const n=[{type:"text",value:"↩"}];return t>1&&n.push({type:"element",tagName:"sup",properties:{},children:[{type:"text",value:String(t)}]}),n}function Qd(e,t){return"Back to reference "+(e+1)+(t>1?"-"+t:"")}function Jd(e){const t=typeof e.options.clobberPrefix=="string"?e.options.clobberPrefix:"user-content-",n=e.options.footnoteBackContent||Gd,r=e.options.footnoteBackLabel||Qd,i=e.options.footnoteLabel||"Footnotes",s=e.options.footnoteLabelTagName||"h2",o=e.options.footnoteLabelProperties||{className:["sr-only"]},a=[];let l=-1;for(;++l<e.footnoteOrder.length;){const u=e.footnoteById.get(e.footnoteOrder[l]);if(!u)continue;const c=e.all(u),f=String(u.identifier).toUpperCase(),d=Kt(f.toLowerCase());let p=0;const g=[],y=e.footnoteCounts.get(f);for(;y!==void 0&&++p<=y;){g.length>0&&g.push({type:"text",value:" "});let S=typeof n=="string"?n:n(l,p);typeof S=="string"&&(S={type:"text",value:S}),g.push({type:"element",tagName:"a",properties:{href:"#"+t+"fnref-"+d+(p>1?"-"+p:""),dataFootnoteBackref:"",ariaLabel:typeof r=="string"?r:r(l,p),className:["data-footnote-backref"]},children:Array.isArray(S)?S:[S]})}const w=c[c.length-1];if(w&&w.type==="element"&&w.tagName==="p"){const S=w.children[w.children.length-1];S&&S.type==="text"?S.value+=" ":w.children.push({type:"text",value:" "}),w.children.push(...g)}else c.push(...g);const k={type:"element",tagName:"li",properties:{id:t+"fn-"+d},children:e.wrap(c,!0)};e.patch(u,k),a.push(k)}if(a.length!==0)return{type:"element",tagName:"section",properties:{dataFootnotes:!0,className:["footnotes"]},children:[{type:"element",tagName:s,properties:{..._n(o),id:"footnote-label"},children:[{type:"text",value:i}]},{type:"text",value:`
|
|
71
71
|
`},{type:"element",tagName:"ol",properties:{},children:e.wrap(a,!0)},{type:"text",value:`
|
|
72
|
-
`}]}}const Gn=(function(e){if(e==null)return nm;if(typeof e=="function")return Qn(e);if(typeof e=="object")return Array.isArray(e)?Zd(e):em(e);if(typeof e=="string")return tm(e);throw new Error("Expected function, string, or object as test")});function Zd(e){const t=[];let n=-1;for(;++n<e.length;)t[n]=Gn(e[n]);return Qn(r);function r(...i){let s=-1;for(;++s<t.length;)if(t[s].apply(this,i))return!0;return!1}}function em(e){const t=e;return Qn(n);function n(r){const i=r;let s;for(s in e)if(i[s]!==t[s])return!1;return!0}}function tm(e){return Qn(t);function t(n){return n&&n.type===e}}function Qn(e){return t;function t(n,r,i){return!!(rm(n)&&e.call(this,n,typeof r=="number"?r:void 0,i||void 0))}}function nm(){return!0}function rm(e){return e!==null&&typeof e=="object"&&"type"in e}const ua=[],im=!0,_r=!1,sm="skip";function ca(e,t,n,r){let i;typeof t=="function"&&typeof n!="function"?(r=n,n=t):i=t;const s=Gn(i),o=r?-1:1;a(e,void 0,[])();function a(l,u,c){const f=l&&typeof l=="object"?l:{};if(typeof f.type=="string"){const p=typeof f.tagName=="string"?f.tagName:typeof f.name=="string"?f.name:void 0;Object.defineProperty(d,"name",{value:"node ("+(l.type+(p?"<"+p+">":""))+")"})}return d;function d(){let p=ua,g,
|
|
72
|
+
`}]}}const Gn=(function(e){if(e==null)return nm;if(typeof e=="function")return Qn(e);if(typeof e=="object")return Array.isArray(e)?Zd(e):em(e);if(typeof e=="string")return tm(e);throw new Error("Expected function, string, or object as test")});function Zd(e){const t=[];let n=-1;for(;++n<e.length;)t[n]=Gn(e[n]);return Qn(r);function r(...i){let s=-1;for(;++s<t.length;)if(t[s].apply(this,i))return!0;return!1}}function em(e){const t=e;return Qn(n);function n(r){const i=r;let s;for(s in e)if(i[s]!==t[s])return!1;return!0}}function tm(e){return Qn(t);function t(n){return n&&n.type===e}}function Qn(e){return t;function t(n,r,i){return!!(rm(n)&&e.call(this,n,typeof r=="number"?r:void 0,i||void 0))}}function nm(){return!0}function rm(e){return e!==null&&typeof e=="object"&&"type"in e}const ua=[],im=!0,_r=!1,sm="skip";function ca(e,t,n,r){let i;typeof t=="function"&&typeof n!="function"?(r=n,n=t):i=t;const s=Gn(i),o=r?-1:1;a(e,void 0,[])();function a(l,u,c){const f=l&&typeof l=="object"?l:{};if(typeof f.type=="string"){const p=typeof f.tagName=="string"?f.tagName:typeof f.name=="string"?f.name:void 0;Object.defineProperty(d,"name",{value:"node ("+(l.type+(p?"<"+p+">":""))+")"})}return d;function d(){let p=ua,g,y,w;if((!t||s(l,u,c[c.length-1]||void 0))&&(p=om(n(l,c)),p[0]===_r))return p;if("children"in l&&l.children){const k=l;if(k.children&&p[0]!==sm)for(y=(r?k.children.length:-1)+o,w=c.concat(k);y>-1&&y<k.children.length;){const S=k.children[y];if(g=a(S,y,w)(),g[0]===_r)return g;y=typeof g[1]=="number"?g[1]:y+o}}return p}}}function om(e){return Array.isArray(e)?e:typeof e=="number"?[im,e]:e==null?ua:[e]}function bi(e,t,n,r){let i,s,o;typeof t=="function"&&typeof n!="function"?(s=void 0,o=t,i=n):(s=t,o=n,i=r),ca(e,s,a,i);function a(l,u){const c=u[u.length-1],f=c?c.children.indexOf(l):void 0;return o(l,f,c)}}const Or={}.hasOwnProperty,am={};function lm(e,t){const n=t||am,r=new Map,i=new Map,s=new Map,o={...Kd,...n.handlers},a={all:u,applyData:cm,definitionById:r,footnoteById:i,footnoteCounts:s,footnoteOrder:[],handlers:o,one:l,options:n,patch:um,wrap:hm};return bi(e,function(c){if(c.type==="definition"||c.type==="footnoteDefinition"){const f=c.type==="definition"?r:i,d=String(c.identifier).toUpperCase();f.has(d)||f.set(d,c)}}),a;function l(c,f){const d=c.type,p=a.handlers[d];if(Or.call(a.handlers,d)&&p)return p(a,c,f);if(a.options.passThrough&&a.options.passThrough.includes(d)){if("children"in c){const{children:y,...w}=c,k=_n(w);return k.children=a.all(c),k}return _n(c)}return(a.options.unknownHandler||fm)(a,c,f)}function u(c){const f=[];if("children"in c){const d=c.children;let p=-1;for(;++p<d.length;){const g=a.one(d[p],c);if(g){if(p&&d[p-1].type==="break"&&(!Array.isArray(g)&&g.type==="text"&&(g.value=ys(g.value)),!Array.isArray(g)&&g.type==="element")){const y=g.children[0];y&&y.type==="text"&&(y.value=ys(y.value))}Array.isArray(g)?f.push(...g):f.push(g)}}}return f}}function um(e,t){e.position&&(t.position=Qf(e))}function cm(e,t){let n=t;if(e&&e.data){const r=e.data.hName,i=e.data.hChildren,s=e.data.hProperties;if(typeof r=="string")if(n.type==="element")n.tagName=r;else{const o="children"in n?n.children:[n];n={type:"element",tagName:r,properties:{},children:o}}n.type==="element"&&s&&Object.assign(n.properties,_n(s)),"children"in n&&n.children&&i!==null&&i!==void 0&&(n.children=i)}return n}function fm(e,t){const n=t.data||{},r="value"in t&&!(Or.call(n,"hProperties")||Or.call(n,"hChildren"))?{type:"text",value:t.value}:{type:"element",tagName:"div",properties:{},children:e.all(t)};return e.patch(t,r),e.applyData(t,r)}function hm(e,t){const n=[];let r=-1;for(t&&n.push({type:"text",value:`
|
|
73
73
|
`});++r<e.length;)r&&n.push({type:"text",value:`
|
|
74
74
|
`}),n.push(e[r]);return t&&e.length>0&&n.push({type:"text",value:`
|
|
75
75
|
`}),n}function ys(e){let t=0,n=e.charCodeAt(t);for(;n===9||n===32;)t++,n=e.charCodeAt(t);return e.slice(t)}function bs(e,t){const n=lm(e,t),r=n.one(e,void 0),i=Jd(n),s=Array.isArray(r)?{type:"root",children:r}:r||{type:"root",children:[]};return i&&s.children.push({type:"text",value:`
|
|
76
|
-
`},i),s}function pm(e,t){return e&&"run"in e?async function(n,r){const i=bs(n,{file:r,...t});await e.run(i,r)}:function(n,r){return bs(n,{file:r,...e||t})}}function ks(e){if(e)throw e}var fr,ws;function dm(){if(ws)return fr;ws=1;var e=Object.prototype.hasOwnProperty,t=Object.prototype.toString,n=Object.defineProperty,r=Object.getOwnPropertyDescriptor,i=function(u){return typeof Array.isArray=="function"?Array.isArray(u):t.call(u)==="[object Array]"},s=function(u){if(!u||t.call(u)!=="[object Object]")return!1;var c=e.call(u,"constructor"),f=u.constructor&&u.constructor.prototype&&e.call(u.constructor.prototype,"isPrototypeOf");if(u.constructor&&!c&&!f)return!1;var d;for(d in u);return typeof d>"u"||e.call(u,d)},o=function(u,c){n&&c.name==="__proto__"?n(u,c.name,{enumerable:!0,configurable:!0,value:c.newValue,writable:!0}):u[c.name]=c.newValue},a=function(u,c){if(c==="__proto__")if(e.call(u,c)){if(r)return r(u,c).value}else return;return u[c]};return fr=function l(){var u,c,f,d,p,g,b=arguments[0],w=1,k=arguments.length,C=!1;for(typeof b=="boolean"&&(C=b,b=arguments[1]||{},w=2),(b==null||typeof b!="object"&&typeof b!="function")&&(b={});w<k;++w)if(u=arguments[w],u!=null)for(c in u)f=a(b,c),d=a(u,c),b!==d&&(C&&d&&(s(d)||(p=i(d)))?(p?(p=!1,g=f&&i(f)?f:[]):g=f&&s(f)?f:{},o(b,{name:c,newValue:l(C,g,d)})):typeof d<"u"&&o(b,{name:c,newValue:d}));return b},fr}var mm=dm();const hr=Ks(mm);function Fr(e){if(typeof e!="object"||e===null)return!1;const t=Object.getPrototypeOf(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Symbol.toStringTag in e)&&!(Symbol.iterator in e)}function gm(){const e=[],t={run:n,use:r};return t;function n(...i){let s=-1;const o=i.pop();if(typeof o!="function")throw new TypeError("Expected function as last argument, not "+o);a(null,...i);function a(l,...u){const c=e[++s];let f=-1;if(l){o(l);return}for(;++f<i.length;)(u[f]===null||u[f]===void 0)&&(u[f]=i[f]);i=u,c?xm(c,a)(...u):o(null,...u)}}function r(i){if(typeof i!="function")throw new TypeError("Expected `middelware` to be a function, not "+i);return e.push(i),t}}function xm(e,t){let n;return r;function r(...o){const a=e.length>o.length;let l;a&&o.push(i);try{l=e.apply(this,o)}catch(u){const c=u;if(a&&n)throw c;return i(c)}a||(l&&l.then&&typeof l.then=="function"?l.then(s,i):l instanceof Error?i(l):s(l))}function i(o,...a){n||(n=!0,t(o,...a))}function s(o){i(null,o)}}const nt={basename:ym,dirname:bm,extname:km,join:wm,sep:"/"};function ym(e,t){if(t!==void 0&&typeof t!="string")throw new TypeError('"ext" argument must be a string');hn(e);let n=0,r=-1,i=e.length,s;if(t===void 0||t.length===0||t.length>e.length){for(;i--;)if(e.codePointAt(i)===47){if(s){n=i+1;break}}else r<0&&(s=!0,r=i+1);return r<0?"":e.slice(n,r)}if(t===e)return"";let o=-1,a=t.length-1;for(;i--;)if(e.codePointAt(i)===47){if(s){n=i+1;break}}else o<0&&(s=!0,o=i+1),a>-1&&(e.codePointAt(i)===t.codePointAt(a--)?a<0&&(r=i):(a=-1,r=o));return n===r?r=o:r<0&&(r=e.length),e.slice(n,r)}function bm(e){if(hn(e),e.length===0)return".";let t=-1,n=e.length,r;for(;--n;)if(e.codePointAt(n)===47){if(r){t=n;break}}else r||(r=!0);return t<0?e.codePointAt(0)===47?"/":".":t===1&&e.codePointAt(0)===47?"//":e.slice(0,t)}function km(e){hn(e);let t=e.length,n=-1,r=0,i=-1,s=0,o;for(;t--;){const a=e.codePointAt(t);if(a===47){if(o){r=t+1;break}continue}n<0&&(o=!0,n=t+1),a===46?i<0?i=t:s!==1&&(s=1):i>-1&&(s=-1)}return i<0||n<0||s===0||s===1&&i===n-1&&i===r+1?"":e.slice(i,n)}function wm(...e){let t=-1,n;for(;++t<e.length;)hn(e[t]),e[t]&&(n=n===void 0?e[t]:n+"/"+e[t]);return n===void 0?".":Sm(n)}function Sm(e){hn(e);const t=e.codePointAt(0)===47;let n=Cm(e,!t);return n.length===0&&!t&&(n="."),n.length>0&&e.codePointAt(e.length-1)===47&&(n+="/"),t?"/"+n:n}function Cm(e,t){let n="",r=0,i=-1,s=0,o=-1,a,l;for(;++o<=e.length;){if(o<e.length)a=e.codePointAt(o);else{if(a===47)break;a=47}if(a===47){if(!(i===o-1||s===1))if(i!==o-1&&s===2){if(n.length<2||r!==2||n.codePointAt(n.length-1)!==46||n.codePointAt(n.length-2)!==46){if(n.length>2){if(l=n.lastIndexOf("/"),l!==n.length-1){l<0?(n="",r=0):(n=n.slice(0,l),r=n.length-1-n.lastIndexOf("/")),i=o,s=0;continue}}else if(n.length>0){n="",r=0,i=o,s=0;continue}}t&&(n=n.length>0?n+"/..":"..",r=2)}else n.length>0?n+="/"+e.slice(i+1,o):n=e.slice(i+1,o),r=o-i-1;i=o,s=0}else a===46&&s>-1?s++:s=-1}return n}function hn(e){if(typeof e!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(e))}const vm={cwd:Em};function Em(){return"/"}function $r(e){return!!(e!==null&&typeof e=="object"&&"href"in e&&e.href&&"protocol"in e&&e.protocol&&e.auth===void 0)}function Tm(e){if(typeof e=="string")e=new URL(e);else if(!$r(e)){const t=new TypeError('The "path" argument must be of type string or an instance of URL. Received `'+e+"`");throw t.code="ERR_INVALID_ARG_TYPE",t}if(e.protocol!=="file:"){const t=new TypeError("The URL must be of scheme file");throw t.code="ERR_INVALID_URL_SCHEME",t}return jm(e)}function jm(e){if(e.hostname!==""){const r=new TypeError('File URL host must be "localhost" or empty on darwin');throw r.code="ERR_INVALID_FILE_URL_HOST",r}const t=e.pathname;let n=-1;for(;++n<t.length;)if(t.codePointAt(n)===37&&t.codePointAt(n+1)===50){const r=t.codePointAt(n+2);if(r===70||r===102){const i=new TypeError("File URL path must not include encoded / characters");throw i.code="ERR_INVALID_FILE_URL_PATH",i}}return decodeURIComponent(t)}const pr=["history","path","basename","stem","extname","dirname"];class fa{constructor(t){let n;t?$r(t)?n={path:t}:typeof t=="string"||Am(t)?n={value:t}:n=t:n={},this.cwd="cwd"in n?"":vm.cwd(),this.data={},this.history=[],this.messages=[],this.value,this.map,this.result,this.stored;let r=-1;for(;++r<pr.length;){const s=pr[r];s in n&&n[s]!==void 0&&n[s]!==null&&(this[s]=s==="history"?[...n[s]]:n[s])}let i;for(i in n)pr.includes(i)||(this[i]=n[i])}get basename(){return typeof this.path=="string"?nt.basename(this.path):void 0}set basename(t){mr(t,"basename"),dr(t,"basename"),this.path=nt.join(this.dirname||"",t)}get dirname(){return typeof this.path=="string"?nt.dirname(this.path):void 0}set dirname(t){Ss(this.basename,"dirname"),this.path=nt.join(t||"",this.basename)}get extname(){return typeof this.path=="string"?nt.extname(this.path):void 0}set extname(t){if(dr(t,"extname"),Ss(this.dirname,"extname"),t){if(t.codePointAt(0)!==46)throw new Error("`extname` must start with `.`");if(t.includes(".",1))throw new Error("`extname` cannot contain multiple dots")}this.path=nt.join(this.dirname,this.stem+(t||""))}get path(){return this.history[this.history.length-1]}set path(t){$r(t)&&(t=Tm(t)),mr(t,"path"),this.path!==t&&this.history.push(t)}get stem(){return typeof this.path=="string"?nt.basename(this.path,this.extname):void 0}set stem(t){mr(t,"stem"),dr(t,"stem"),this.path=nt.join(this.dirname||"",t+(this.extname||""))}fail(t,n,r){const i=this.message(t,n,r);throw i.fatal=!0,i}info(t,n,r){const i=this.message(t,n,r);return i.fatal=void 0,i}message(t,n,r){const i=new Ne(t,n,r);return this.path&&(i.name=this.path+":"+i.name,i.file=this.path),i.fatal=!1,this.messages.push(i),i}toString(t){return this.value===void 0?"":typeof this.value=="string"?this.value:new TextDecoder(t||void 0).decode(this.value)}}function dr(e,t){if(e&&e.includes(nt.sep))throw new Error("`"+t+"` cannot be a path: did not expect `"+nt.sep+"`")}function mr(e,t){if(!e)throw new Error("`"+t+"` cannot be empty")}function Ss(e,t){if(!e)throw new Error("Setting `"+t+"` requires `path` to be set too")}function Am(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}const Im=(function(e){const r=this.constructor.prototype,i=r[e],s=function(){return i.apply(s,arguments)};return Object.setPrototypeOf(s,r),s}),Rm={}.hasOwnProperty;class ki extends Im{constructor(){super("copy"),this.Compiler=void 0,this.Parser=void 0,this.attachers=[],this.compiler=void 0,this.freezeIndex=-1,this.frozen=void 0,this.namespace={},this.parser=void 0,this.transformers=gm()}copy(){const t=new ki;let n=-1;for(;++n<this.attachers.length;){const r=this.attachers[n];t.use(...r)}return t.data(hr(!0,{},this.namespace)),t}data(t,n){return typeof t=="string"?arguments.length===2?(yr("data",this.frozen),this.namespace[t]=n,this):Rm.call(this.namespace,t)&&this.namespace[t]||void 0:t?(yr("data",this.frozen),this.namespace=t,this):this.namespace}freeze(){if(this.frozen)return this;const t=this;for(;++this.freezeIndex<this.attachers.length;){const[n,...r]=this.attachers[this.freezeIndex];if(r[0]===!1)continue;r[0]===!0&&(r[0]=void 0);const i=n.call(t,...r);typeof i=="function"&&this.transformers.use(i)}return this.frozen=!0,this.freezeIndex=Number.POSITIVE_INFINITY,this}parse(t){this.freeze();const n=yn(t),r=this.parser||this.Parser;return gr("parse",r),r(String(n),n)}process(t,n){const r=this;return this.freeze(),gr("process",this.parser||this.Parser),xr("process",this.compiler||this.Compiler),n?i(void 0,n):new Promise(i);function i(s,o){const a=yn(t),l=r.parse(a);r.run(l,a,function(c,f,d){if(c||!f||!d)return u(c);const p=f,g=r.stringify(p,d);Mm(g)?d.value=g:d.result=g,u(c,d)});function u(c,f){c||!f?o(c):s?s(f):n(void 0,f)}}}processSync(t){let n=!1,r;return this.freeze(),gr("processSync",this.parser||this.Parser),xr("processSync",this.compiler||this.Compiler),this.process(t,i),vs("processSync","process",n),r;function i(s,o){n=!0,ks(s),r=o}}run(t,n,r){Cs(t),this.freeze();const i=this.transformers;return!r&&typeof n=="function"&&(r=n,n=void 0),r?s(void 0,r):new Promise(s);function s(o,a){const l=yn(n);i.run(t,l,u);function u(c,f,d){const p=f||t;c?a(c):o?o(p):r(void 0,p,d)}}}runSync(t,n){let r=!1,i;return this.run(t,n,s),vs("runSync","run",r),i;function s(o,a){ks(o),i=a,r=!0}}stringify(t,n){this.freeze();const r=yn(n),i=this.compiler||this.Compiler;return xr("stringify",i),Cs(t),i(t,r)}use(t,...n){const r=this.attachers,i=this.namespace;if(yr("use",this.frozen),t!=null)if(typeof t=="function")l(t,n);else if(typeof t=="object")Array.isArray(t)?a(t):o(t);else throw new TypeError("Expected usable value, not `"+t+"`");return this;function s(u){if(typeof u=="function")l(u,[]);else if(typeof u=="object")if(Array.isArray(u)){const[c,...f]=u;l(c,f)}else o(u);else throw new TypeError("Expected usable value, not `"+u+"`")}function o(u){if(!("plugins"in u)&&!("settings"in u))throw new Error("Expected usable value but received an empty preset, which is probably a mistake: presets typically come with `plugins` and sometimes with `settings`, but this has neither");a(u.plugins),u.settings&&(i.settings=hr(!0,i.settings,u.settings))}function a(u){let c=-1;if(u!=null)if(Array.isArray(u))for(;++c<u.length;){const f=u[c];s(f)}else throw new TypeError("Expected a list of plugins, not `"+u+"`")}function l(u,c){let f=-1,d=-1;for(;++f<r.length;)if(r[f][0]===u){d=f;break}if(d===-1)r.push([u,...c]);else if(c.length>0){let[p,...g]=c;const b=r[d][1];Fr(b)&&Fr(p)&&(p=hr(!0,b,p)),r[d]=[u,p,...g]}}}}const Nm=new ki().freeze();function gr(e,t){if(typeof t!="function")throw new TypeError("Cannot `"+e+"` without `parser`")}function xr(e,t){if(typeof t!="function")throw new TypeError("Cannot `"+e+"` without `compiler`")}function yr(e,t){if(t)throw new Error("Cannot call `"+e+"` on a frozen processor.\nCreate a new processor first, by calling it: use `processor()` instead of `processor`.")}function Cs(e){if(!Fr(e)||typeof e.type!="string")throw new TypeError("Expected node, got `"+e+"`")}function vs(e,t,n){if(!n)throw new Error("`"+e+"` finished async. Use `"+t+"` instead")}function yn(e){return Lm(e)?e:new fa(e)}function Lm(e){return!!(e&&typeof e=="object"&&"message"in e&&"messages"in e)}function Mm(e){return typeof e=="string"||Dm(e)}function Dm(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}const zm="https://github.com/remarkjs/react-markdown/blob/main/changelog.md",Es=[],Ts={allowDangerousHtml:!0},Pm=/^(https?|ircs?|mailto|xmpp)$/i,_m=[{from:"astPlugins",id:"remove-buggy-html-in-markdown-parser"},{from:"allowDangerousHtml",id:"remove-buggy-html-in-markdown-parser"},{from:"allowNode",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"allowElement"},{from:"allowedTypes",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"allowedElements"},{from:"className",id:"remove-classname"},{from:"disallowedTypes",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"disallowedElements"},{from:"escapeHtml",id:"remove-buggy-html-in-markdown-parser"},{from:"includeElementIndex",id:"#remove-includeelementindex"},{from:"includeNodeIndex",id:"change-includenodeindex-to-includeelementindex"},{from:"linkTarget",id:"remove-linktarget"},{from:"plugins",id:"change-plugins-to-remarkplugins",to:"remarkPlugins"},{from:"rawSourcePos",id:"#remove-rawsourcepos"},{from:"renderers",id:"change-renderers-to-components",to:"components"},{from:"source",id:"change-source-to-children",to:"children"},{from:"sourcePos",id:"#remove-sourcepos"},{from:"transformImageUri",id:"#add-urltransform",to:"urlTransform"},{from:"transformLinkUri",id:"#add-urltransform",to:"urlTransform"}];function Om(e){const t=Fm(e),n=$m(e);return Bm(t.runSync(t.parse(n),n),e)}function Fm(e){const t=e.rehypePlugins||Es,n=e.remarkPlugins||Es,r=e.remarkRehypeOptions?{...e.remarkRehypeOptions,...Ts}:Ts;return Nm().use(bd).use(n).use(pm,r).use(t)}function $m(e){const t=e.children||"",n=new fa;return typeof t=="string"&&(n.value=t),n}function Bm(e,t){const n=t.allowedElements,r=t.allowElement,i=t.components,s=t.disallowedElements,o=t.skipHtml,a=t.unwrapDisallowed,l=t.urlTransform||Hm;for(const c of _m)Object.hasOwn(t,c.from)&&(""+c.from+(c.to?"use `"+c.to+"` instead":"remove it")+zm+c.id,void 0);return bi(e,u),nh(e,{Fragment:h.Fragment,components:i,ignoreInvalidStyle:!0,jsx:h.jsx,jsxs:h.jsxs,passKeys:!0,passNode:!0});function u(c,f,d){if(c.type==="raw"&&d&&typeof f=="number")return o?d.children.splice(f,1):d.children[f]={type:"text",value:c.value},f;if(c.type==="element"){let p;for(p in lr)if(Object.hasOwn(lr,p)&&Object.hasOwn(c.properties,p)){const g=c.properties[p],b=lr[p];(b===null||b.includes(c.tagName))&&(c.properties[p]=l(String(g||""),p,c))}}if(c.type==="element"){let p=n?!n.includes(c.tagName):s?s.includes(c.tagName):!1;if(!p&&r&&typeof f=="number"&&(p=!r(c,f,d)),p&&d&&typeof f=="number")return a&&c.children?d.children.splice(f,1,...c.children):d.children.splice(f,1),f}}}function Hm(e){const t=e.indexOf(":"),n=e.indexOf("?"),r=e.indexOf("#"),i=e.indexOf("/");return t===-1||i!==-1&&t>i||n!==-1&&t>n||r!==-1&&t>r||Pm.test(e.slice(0,t))?e:""}function Um(e){if(typeof e!="string")throw new TypeError("Expected a string");return e.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}function ha(e,t,n){const i=Gn((n||{}).ignore||[]),s=qm(t);let o=-1;for(;++o<s.length;)ca(e,"text",a);function a(u,c){let f=-1,d;for(;++f<c.length;){const p=c[f],g=d?d.children:void 0;if(i(p,g?g.indexOf(p):void 0,d))return;d=p}if(d)return l(u,c)}function l(u,c){const f=c[c.length-1],d=s[o][0],p=s[o][1];let g=0;const w=f.children.indexOf(u);let k=!1,C=[];d.lastIndex=0;let E=d.exec(u.value);for(;E;){const N=E.index,_={index:E.index,input:E.input,stack:[...c,u]};let S=p(...E,_);if(typeof S=="string"&&(S=S.length>0?{type:"text",value:S}:void 0),S===!1?d.lastIndex=N+1:(g!==N&&C.push({type:"text",value:u.value.slice(g,N)}),Array.isArray(S)?C.push(...S):S&&C.push(S),g=N+E[0].length,k=!0),!d.global)break;E=d.exec(u.value)}return k?(g<u.value.length&&C.push({type:"text",value:u.value.slice(g)}),f.children.splice(w,1,...C)):C=[u],w+C.length}}function qm(e){const t=[];if(!Array.isArray(e))throw new TypeError("Expected find and replace tuple or list of tuples");const n=!e[0]||Array.isArray(e[0])?e:[e];let r=-1;for(;++r<n.length;){const i=n[r];t.push([Km(i[0]),Wm(i[1])])}return t}function Km(e){return typeof e=="string"?new RegExp(Um(e),"g"):e}function Wm(e){return typeof e=="function"?e:function(){return e}}function Vm(e){ha(e,[/\r?\n|\r/g,Xm])}function Xm(){return{type:"break"}}function Ym(){return function(e){Vm(e)}}const br="phrasing",kr=["autolink","link","image","label"];function Gm(){return{transforms:[rg],enter:{literalAutolink:Jm,literalAutolinkEmail:wr,literalAutolinkHttp:wr,literalAutolinkWww:wr},exit:{literalAutolink:ng,literalAutolinkEmail:tg,literalAutolinkHttp:Zm,literalAutolinkWww:eg}}}function Qm(){return{unsafe:[{character:"@",before:"[+\\-.\\w]",after:"[\\-.\\w]",inConstruct:br,notInConstruct:kr},{character:".",before:"[Ww]",after:"[\\-.\\w]",inConstruct:br,notInConstruct:kr},{character:":",before:"[ps]",after:"\\/",inConstruct:br,notInConstruct:kr}]}}function Jm(e){this.enter({type:"link",title:null,url:"",children:[]},e)}function wr(e){this.config.enter.autolinkProtocol.call(this,e)}function Zm(e){this.config.exit.autolinkProtocol.call(this,e)}function eg(e){this.config.exit.data.call(this,e);const t=this.stack[this.stack.length-1];t.type,t.url="http://"+this.sliceSerialize(e)}function tg(e){this.config.exit.autolinkEmail.call(this,e)}function ng(e){this.exit(e)}function rg(e){ha(e,[[/(https?:\/\/|www(?=\.))([-.\w]+)([^ \t\r\n]*)/gi,ig],[new RegExp("(?<=^|\\s|\\p{P}|\\p{S})([-.\\w+]+)@([-\\w]+(?:\\.[-\\w]+)+)","gu"),sg]],{ignore:["link","linkReference"]})}function ig(e,t,n,r,i){let s="";if(!pa(i)||(/^w/i.test(t)&&(n=t+n,t="",s="http://"),!og(n)))return!1;const o=ag(n+r);if(!o[0])return!1;const a={type:"link",title:null,url:s+t+o[0],children:[{type:"text",value:t+o[0]}]};return o[1]?[a,{type:"text",value:o[1]}]:a}function sg(e,t,n,r){return!pa(r,!0)||/[-\d_]$/.test(n)?!1:{type:"link",title:null,url:"mailto:"+t+"@"+n,children:[{type:"text",value:t+"@"+n}]}}function og(e){const t=e.split(".");return!(t.length<2||t[t.length-1]&&(/_/.test(t[t.length-1])||!/[a-zA-Z\d]/.test(t[t.length-1]))||t[t.length-2]&&(/_/.test(t[t.length-2])||!/[a-zA-Z\d]/.test(t[t.length-2])))}function ag(e){const t=/[!"&'),.:;<>?\]}]+$/.exec(e);if(!t)return[e,void 0];e=e.slice(0,t.index);let n=t[0],r=n.indexOf(")");const i=Mi(e,"(");let s=Mi(e,")");for(;r!==-1&&i>s;)e+=n.slice(0,r+1),n=n.slice(r+1),r=n.indexOf(")"),s++;return[e,n]}function pa(e,t){const n=e.input.charCodeAt(e.index-1);return(e.index===0||Mt(n)||Vn(n))&&(!t||n!==47)}da.peek=gg;function lg(){this.buffer()}function ug(e){this.enter({type:"footnoteReference",identifier:"",label:""},e)}function cg(){this.buffer()}function fg(e){this.enter({type:"footnoteDefinition",identifier:"",label:"",children:[]},e)}function hg(e){const t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=Ze(this.sliceSerialize(e)).toLowerCase(),n.label=t}function pg(e){this.exit(e)}function dg(e){const t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=Ze(this.sliceSerialize(e)).toLowerCase(),n.label=t}function mg(e){this.exit(e)}function gg(){return"["}function da(e,t,n,r){const i=n.createTracker(r);let s=i.move("[^");const o=n.enter("footnoteReference"),a=n.enter("reference");return s+=i.move(n.safe(n.associationId(e),{after:"]",before:s})),a(),o(),s+=i.move("]"),s}function xg(){return{enter:{gfmFootnoteCallString:lg,gfmFootnoteCall:ug,gfmFootnoteDefinitionLabelString:cg,gfmFootnoteDefinition:fg},exit:{gfmFootnoteCallString:hg,gfmFootnoteCall:pg,gfmFootnoteDefinitionLabelString:dg,gfmFootnoteDefinition:mg}}}function yg(e){let t=!1;return e&&e.firstLineBlank&&(t=!0),{handlers:{footnoteDefinition:n,footnoteReference:da},unsafe:[{character:"[",inConstruct:["label","phrasing","reference"]}]};function n(r,i,s,o){const a=s.createTracker(o);let l=a.move("[^");const u=s.enter("footnoteDefinition"),c=s.enter("label");return l+=a.move(s.safe(s.associationId(r),{before:l,after:"]"})),c(),l+=a.move("]:"),r.children&&r.children.length>0&&(a.shift(4),l+=a.move((t?`
|
|
77
|
-
`:" ")+s.indentLines(s.containerFlow(r,a.current()),t?ma:bg))),u(),l}}function bg(e,t,n){return t===0?e:ma(e,t,n)}function ma(e,t,n){return(n?"":" ")+e}const kg=["autolink","destinationLiteral","destinationRaw","reference","titleQuote","titleApostrophe"];ga.peek=Eg;function wg(){return{canContainEols:["delete"],enter:{strikethrough:Cg},exit:{strikethrough:vg}}}function Sg(){return{unsafe:[{character:"~",inConstruct:"phrasing",notInConstruct:kg}],handlers:{delete:ga}}}function Cg(e){this.enter({type:"delete",children:[]},e)}function vg(e){this.exit(e)}function ga(e,t,n,r){const i=n.createTracker(r),s=n.enter("strikethrough");let o=i.move("~~");return o+=n.containerPhrasing(e,{...i.current(),before:o,after:"~"}),o+=i.move("~~"),s(),o}function Eg(){return"~"}function Tg(e){return e.length}function jg(e,t){const n=t||{},r=(n.align||[]).concat(),i=n.stringLength||Tg,s=[],o=[],a=[],l=[];let u=0,c=-1;for(;++c<e.length;){const
|
|
76
|
+
`},i),s}function pm(e,t){return e&&"run"in e?async function(n,r){const i=bs(n,{file:r,...t});await e.run(i,r)}:function(n,r){return bs(n,{file:r,...e||t})}}function ks(e){if(e)throw e}var fr,ws;function dm(){if(ws)return fr;ws=1;var e=Object.prototype.hasOwnProperty,t=Object.prototype.toString,n=Object.defineProperty,r=Object.getOwnPropertyDescriptor,i=function(u){return typeof Array.isArray=="function"?Array.isArray(u):t.call(u)==="[object Array]"},s=function(u){if(!u||t.call(u)!=="[object Object]")return!1;var c=e.call(u,"constructor"),f=u.constructor&&u.constructor.prototype&&e.call(u.constructor.prototype,"isPrototypeOf");if(u.constructor&&!c&&!f)return!1;var d;for(d in u);return typeof d>"u"||e.call(u,d)},o=function(u,c){n&&c.name==="__proto__"?n(u,c.name,{enumerable:!0,configurable:!0,value:c.newValue,writable:!0}):u[c.name]=c.newValue},a=function(u,c){if(c==="__proto__")if(e.call(u,c)){if(r)return r(u,c).value}else return;return u[c]};return fr=function l(){var u,c,f,d,p,g,y=arguments[0],w=1,k=arguments.length,S=!1;for(typeof y=="boolean"&&(S=y,y=arguments[1]||{},w=2),(y==null||typeof y!="object"&&typeof y!="function")&&(y={});w<k;++w)if(u=arguments[w],u!=null)for(c in u)f=a(y,c),d=a(u,c),y!==d&&(S&&d&&(s(d)||(p=i(d)))?(p?(p=!1,g=f&&i(f)?f:[]):g=f&&s(f)?f:{},o(y,{name:c,newValue:l(S,g,d)})):typeof d<"u"&&o(y,{name:c,newValue:d}));return y},fr}var mm=dm();const hr=Ks(mm);function Fr(e){if(typeof e!="object"||e===null)return!1;const t=Object.getPrototypeOf(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Symbol.toStringTag in e)&&!(Symbol.iterator in e)}function gm(){const e=[],t={run:n,use:r};return t;function n(...i){let s=-1;const o=i.pop();if(typeof o!="function")throw new TypeError("Expected function as last argument, not "+o);a(null,...i);function a(l,...u){const c=e[++s];let f=-1;if(l){o(l);return}for(;++f<i.length;)(u[f]===null||u[f]===void 0)&&(u[f]=i[f]);i=u,c?xm(c,a)(...u):o(null,...u)}}function r(i){if(typeof i!="function")throw new TypeError("Expected `middelware` to be a function, not "+i);return e.push(i),t}}function xm(e,t){let n;return r;function r(...o){const a=e.length>o.length;let l;a&&o.push(i);try{l=e.apply(this,o)}catch(u){const c=u;if(a&&n)throw c;return i(c)}a||(l&&l.then&&typeof l.then=="function"?l.then(s,i):l instanceof Error?i(l):s(l))}function i(o,...a){n||(n=!0,t(o,...a))}function s(o){i(null,o)}}const rt={basename:ym,dirname:bm,extname:km,join:wm,sep:"/"};function ym(e,t){if(t!==void 0&&typeof t!="string")throw new TypeError('"ext" argument must be a string');hn(e);let n=0,r=-1,i=e.length,s;if(t===void 0||t.length===0||t.length>e.length){for(;i--;)if(e.codePointAt(i)===47){if(s){n=i+1;break}}else r<0&&(s=!0,r=i+1);return r<0?"":e.slice(n,r)}if(t===e)return"";let o=-1,a=t.length-1;for(;i--;)if(e.codePointAt(i)===47){if(s){n=i+1;break}}else o<0&&(s=!0,o=i+1),a>-1&&(e.codePointAt(i)===t.codePointAt(a--)?a<0&&(r=i):(a=-1,r=o));return n===r?r=o:r<0&&(r=e.length),e.slice(n,r)}function bm(e){if(hn(e),e.length===0)return".";let t=-1,n=e.length,r;for(;--n;)if(e.codePointAt(n)===47){if(r){t=n;break}}else r||(r=!0);return t<0?e.codePointAt(0)===47?"/":".":t===1&&e.codePointAt(0)===47?"//":e.slice(0,t)}function km(e){hn(e);let t=e.length,n=-1,r=0,i=-1,s=0,o;for(;t--;){const a=e.codePointAt(t);if(a===47){if(o){r=t+1;break}continue}n<0&&(o=!0,n=t+1),a===46?i<0?i=t:s!==1&&(s=1):i>-1&&(s=-1)}return i<0||n<0||s===0||s===1&&i===n-1&&i===r+1?"":e.slice(i,n)}function wm(...e){let t=-1,n;for(;++t<e.length;)hn(e[t]),e[t]&&(n=n===void 0?e[t]:n+"/"+e[t]);return n===void 0?".":Sm(n)}function Sm(e){hn(e);const t=e.codePointAt(0)===47;let n=Cm(e,!t);return n.length===0&&!t&&(n="."),n.length>0&&e.codePointAt(e.length-1)===47&&(n+="/"),t?"/"+n:n}function Cm(e,t){let n="",r=0,i=-1,s=0,o=-1,a,l;for(;++o<=e.length;){if(o<e.length)a=e.codePointAt(o);else{if(a===47)break;a=47}if(a===47){if(!(i===o-1||s===1))if(i!==o-1&&s===2){if(n.length<2||r!==2||n.codePointAt(n.length-1)!==46||n.codePointAt(n.length-2)!==46){if(n.length>2){if(l=n.lastIndexOf("/"),l!==n.length-1){l<0?(n="",r=0):(n=n.slice(0,l),r=n.length-1-n.lastIndexOf("/")),i=o,s=0;continue}}else if(n.length>0){n="",r=0,i=o,s=0;continue}}t&&(n=n.length>0?n+"/..":"..",r=2)}else n.length>0?n+="/"+e.slice(i+1,o):n=e.slice(i+1,o),r=o-i-1;i=o,s=0}else a===46&&s>-1?s++:s=-1}return n}function hn(e){if(typeof e!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(e))}const vm={cwd:Em};function Em(){return"/"}function $r(e){return!!(e!==null&&typeof e=="object"&&"href"in e&&e.href&&"protocol"in e&&e.protocol&&e.auth===void 0)}function Tm(e){if(typeof e=="string")e=new URL(e);else if(!$r(e)){const t=new TypeError('The "path" argument must be of type string or an instance of URL. Received `'+e+"`");throw t.code="ERR_INVALID_ARG_TYPE",t}if(e.protocol!=="file:"){const t=new TypeError("The URL must be of scheme file");throw t.code="ERR_INVALID_URL_SCHEME",t}return jm(e)}function jm(e){if(e.hostname!==""){const r=new TypeError('File URL host must be "localhost" or empty on darwin');throw r.code="ERR_INVALID_FILE_URL_HOST",r}const t=e.pathname;let n=-1;for(;++n<t.length;)if(t.codePointAt(n)===37&&t.codePointAt(n+1)===50){const r=t.codePointAt(n+2);if(r===70||r===102){const i=new TypeError("File URL path must not include encoded / characters");throw i.code="ERR_INVALID_FILE_URL_PATH",i}}return decodeURIComponent(t)}const pr=["history","path","basename","stem","extname","dirname"];class fa{constructor(t){let n;t?$r(t)?n={path:t}:typeof t=="string"||Am(t)?n={value:t}:n=t:n={},this.cwd="cwd"in n?"":vm.cwd(),this.data={},this.history=[],this.messages=[],this.value,this.map,this.result,this.stored;let r=-1;for(;++r<pr.length;){const s=pr[r];s in n&&n[s]!==void 0&&n[s]!==null&&(this[s]=s==="history"?[...n[s]]:n[s])}let i;for(i in n)pr.includes(i)||(this[i]=n[i])}get basename(){return typeof this.path=="string"?rt.basename(this.path):void 0}set basename(t){mr(t,"basename"),dr(t,"basename"),this.path=rt.join(this.dirname||"",t)}get dirname(){return typeof this.path=="string"?rt.dirname(this.path):void 0}set dirname(t){Ss(this.basename,"dirname"),this.path=rt.join(t||"",this.basename)}get extname(){return typeof this.path=="string"?rt.extname(this.path):void 0}set extname(t){if(dr(t,"extname"),Ss(this.dirname,"extname"),t){if(t.codePointAt(0)!==46)throw new Error("`extname` must start with `.`");if(t.includes(".",1))throw new Error("`extname` cannot contain multiple dots")}this.path=rt.join(this.dirname,this.stem+(t||""))}get path(){return this.history[this.history.length-1]}set path(t){$r(t)&&(t=Tm(t)),mr(t,"path"),this.path!==t&&this.history.push(t)}get stem(){return typeof this.path=="string"?rt.basename(this.path,this.extname):void 0}set stem(t){mr(t,"stem"),dr(t,"stem"),this.path=rt.join(this.dirname||"",t+(this.extname||""))}fail(t,n,r){const i=this.message(t,n,r);throw i.fatal=!0,i}info(t,n,r){const i=this.message(t,n,r);return i.fatal=void 0,i}message(t,n,r){const i=new Ne(t,n,r);return this.path&&(i.name=this.path+":"+i.name,i.file=this.path),i.fatal=!1,this.messages.push(i),i}toString(t){return this.value===void 0?"":typeof this.value=="string"?this.value:new TextDecoder(t||void 0).decode(this.value)}}function dr(e,t){if(e&&e.includes(rt.sep))throw new Error("`"+t+"` cannot be a path: did not expect `"+rt.sep+"`")}function mr(e,t){if(!e)throw new Error("`"+t+"` cannot be empty")}function Ss(e,t){if(!e)throw new Error("Setting `"+t+"` requires `path` to be set too")}function Am(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}const Im=(function(e){const r=this.constructor.prototype,i=r[e],s=function(){return i.apply(s,arguments)};return Object.setPrototypeOf(s,r),s}),Rm={}.hasOwnProperty;class ki extends Im{constructor(){super("copy"),this.Compiler=void 0,this.Parser=void 0,this.attachers=[],this.compiler=void 0,this.freezeIndex=-1,this.frozen=void 0,this.namespace={},this.parser=void 0,this.transformers=gm()}copy(){const t=new ki;let n=-1;for(;++n<this.attachers.length;){const r=this.attachers[n];t.use(...r)}return t.data(hr(!0,{},this.namespace)),t}data(t,n){return typeof t=="string"?arguments.length===2?(yr("data",this.frozen),this.namespace[t]=n,this):Rm.call(this.namespace,t)&&this.namespace[t]||void 0:t?(yr("data",this.frozen),this.namespace=t,this):this.namespace}freeze(){if(this.frozen)return this;const t=this;for(;++this.freezeIndex<this.attachers.length;){const[n,...r]=this.attachers[this.freezeIndex];if(r[0]===!1)continue;r[0]===!0&&(r[0]=void 0);const i=n.call(t,...r);typeof i=="function"&&this.transformers.use(i)}return this.frozen=!0,this.freezeIndex=Number.POSITIVE_INFINITY,this}parse(t){this.freeze();const n=yn(t),r=this.parser||this.Parser;return gr("parse",r),r(String(n),n)}process(t,n){const r=this;return this.freeze(),gr("process",this.parser||this.Parser),xr("process",this.compiler||this.Compiler),n?i(void 0,n):new Promise(i);function i(s,o){const a=yn(t),l=r.parse(a);r.run(l,a,function(c,f,d){if(c||!f||!d)return u(c);const p=f,g=r.stringify(p,d);Mm(g)?d.value=g:d.result=g,u(c,d)});function u(c,f){c||!f?o(c):s?s(f):n(void 0,f)}}}processSync(t){let n=!1,r;return this.freeze(),gr("processSync",this.parser||this.Parser),xr("processSync",this.compiler||this.Compiler),this.process(t,i),vs("processSync","process",n),r;function i(s,o){n=!0,ks(s),r=o}}run(t,n,r){Cs(t),this.freeze();const i=this.transformers;return!r&&typeof n=="function"&&(r=n,n=void 0),r?s(void 0,r):new Promise(s);function s(o,a){const l=yn(n);i.run(t,l,u);function u(c,f,d){const p=f||t;c?a(c):o?o(p):r(void 0,p,d)}}}runSync(t,n){let r=!1,i;return this.run(t,n,s),vs("runSync","run",r),i;function s(o,a){ks(o),i=a,r=!0}}stringify(t,n){this.freeze();const r=yn(n),i=this.compiler||this.Compiler;return xr("stringify",i),Cs(t),i(t,r)}use(t,...n){const r=this.attachers,i=this.namespace;if(yr("use",this.frozen),t!=null)if(typeof t=="function")l(t,n);else if(typeof t=="object")Array.isArray(t)?a(t):o(t);else throw new TypeError("Expected usable value, not `"+t+"`");return this;function s(u){if(typeof u=="function")l(u,[]);else if(typeof u=="object")if(Array.isArray(u)){const[c,...f]=u;l(c,f)}else o(u);else throw new TypeError("Expected usable value, not `"+u+"`")}function o(u){if(!("plugins"in u)&&!("settings"in u))throw new Error("Expected usable value but received an empty preset, which is probably a mistake: presets typically come with `plugins` and sometimes with `settings`, but this has neither");a(u.plugins),u.settings&&(i.settings=hr(!0,i.settings,u.settings))}function a(u){let c=-1;if(u!=null)if(Array.isArray(u))for(;++c<u.length;){const f=u[c];s(f)}else throw new TypeError("Expected a list of plugins, not `"+u+"`")}function l(u,c){let f=-1,d=-1;for(;++f<r.length;)if(r[f][0]===u){d=f;break}if(d===-1)r.push([u,...c]);else if(c.length>0){let[p,...g]=c;const y=r[d][1];Fr(y)&&Fr(p)&&(p=hr(!0,y,p)),r[d]=[u,p,...g]}}}}const Nm=new ki().freeze();function gr(e,t){if(typeof t!="function")throw new TypeError("Cannot `"+e+"` without `parser`")}function xr(e,t){if(typeof t!="function")throw new TypeError("Cannot `"+e+"` without `compiler`")}function yr(e,t){if(t)throw new Error("Cannot call `"+e+"` on a frozen processor.\nCreate a new processor first, by calling it: use `processor()` instead of `processor`.")}function Cs(e){if(!Fr(e)||typeof e.type!="string")throw new TypeError("Expected node, got `"+e+"`")}function vs(e,t,n){if(!n)throw new Error("`"+e+"` finished async. Use `"+t+"` instead")}function yn(e){return Lm(e)?e:new fa(e)}function Lm(e){return!!(e&&typeof e=="object"&&"message"in e&&"messages"in e)}function Mm(e){return typeof e=="string"||Dm(e)}function Dm(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}const zm="https://github.com/remarkjs/react-markdown/blob/main/changelog.md",Es=[],Ts={allowDangerousHtml:!0},Pm=/^(https?|ircs?|mailto|xmpp)$/i,_m=[{from:"astPlugins",id:"remove-buggy-html-in-markdown-parser"},{from:"allowDangerousHtml",id:"remove-buggy-html-in-markdown-parser"},{from:"allowNode",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"allowElement"},{from:"allowedTypes",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"allowedElements"},{from:"className",id:"remove-classname"},{from:"disallowedTypes",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"disallowedElements"},{from:"escapeHtml",id:"remove-buggy-html-in-markdown-parser"},{from:"includeElementIndex",id:"#remove-includeelementindex"},{from:"includeNodeIndex",id:"change-includenodeindex-to-includeelementindex"},{from:"linkTarget",id:"remove-linktarget"},{from:"plugins",id:"change-plugins-to-remarkplugins",to:"remarkPlugins"},{from:"rawSourcePos",id:"#remove-rawsourcepos"},{from:"renderers",id:"change-renderers-to-components",to:"components"},{from:"source",id:"change-source-to-children",to:"children"},{from:"sourcePos",id:"#remove-sourcepos"},{from:"transformImageUri",id:"#add-urltransform",to:"urlTransform"},{from:"transformLinkUri",id:"#add-urltransform",to:"urlTransform"}];function Om(e){const t=Fm(e),n=$m(e);return Bm(t.runSync(t.parse(n),n),e)}function Fm(e){const t=e.rehypePlugins||Es,n=e.remarkPlugins||Es,r=e.remarkRehypeOptions?{...e.remarkRehypeOptions,...Ts}:Ts;return Nm().use(bd).use(n).use(pm,r).use(t)}function $m(e){const t=e.children||"",n=new fa;return typeof t=="string"&&(n.value=t),n}function Bm(e,t){const n=t.allowedElements,r=t.allowElement,i=t.components,s=t.disallowedElements,o=t.skipHtml,a=t.unwrapDisallowed,l=t.urlTransform||Hm;for(const c of _m)Object.hasOwn(t,c.from)&&(""+c.from+(c.to?"use `"+c.to+"` instead":"remove it")+zm+c.id,void 0);return bi(e,u),nh(e,{Fragment:h.Fragment,components:i,ignoreInvalidStyle:!0,jsx:h.jsx,jsxs:h.jsxs,passKeys:!0,passNode:!0});function u(c,f,d){if(c.type==="raw"&&d&&typeof f=="number")return o?d.children.splice(f,1):d.children[f]={type:"text",value:c.value},f;if(c.type==="element"){let p;for(p in lr)if(Object.hasOwn(lr,p)&&Object.hasOwn(c.properties,p)){const g=c.properties[p],y=lr[p];(y===null||y.includes(c.tagName))&&(c.properties[p]=l(String(g||""),p,c))}}if(c.type==="element"){let p=n?!n.includes(c.tagName):s?s.includes(c.tagName):!1;if(!p&&r&&typeof f=="number"&&(p=!r(c,f,d)),p&&d&&typeof f=="number")return a&&c.children?d.children.splice(f,1,...c.children):d.children.splice(f,1),f}}}function Hm(e){const t=e.indexOf(":"),n=e.indexOf("?"),r=e.indexOf("#"),i=e.indexOf("/");return t===-1||i!==-1&&t>i||n!==-1&&t>n||r!==-1&&t>r||Pm.test(e.slice(0,t))?e:""}function Um(e){if(typeof e!="string")throw new TypeError("Expected a string");return e.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}function ha(e,t,n){const i=Gn((n||{}).ignore||[]),s=qm(t);let o=-1;for(;++o<s.length;)ca(e,"text",a);function a(u,c){let f=-1,d;for(;++f<c.length;){const p=c[f],g=d?d.children:void 0;if(i(p,g?g.indexOf(p):void 0,d))return;d=p}if(d)return l(u,c)}function l(u,c){const f=c[c.length-1],d=s[o][0],p=s[o][1];let g=0;const w=f.children.indexOf(u);let k=!1,S=[];d.lastIndex=0;let v=d.exec(u.value);for(;v;){const R=v.index,M={index:v.index,input:v.input,stack:[...c,u]};let C=p(...v,M);if(typeof C=="string"&&(C=C.length>0?{type:"text",value:C}:void 0),C===!1?d.lastIndex=R+1:(g!==R&&S.push({type:"text",value:u.value.slice(g,R)}),Array.isArray(C)?S.push(...C):C&&S.push(C),g=R+v[0].length,k=!0),!d.global)break;v=d.exec(u.value)}return k?(g<u.value.length&&S.push({type:"text",value:u.value.slice(g)}),f.children.splice(w,1,...S)):S=[u],w+S.length}}function qm(e){const t=[];if(!Array.isArray(e))throw new TypeError("Expected find and replace tuple or list of tuples");const n=!e[0]||Array.isArray(e[0])?e:[e];let r=-1;for(;++r<n.length;){const i=n[r];t.push([Km(i[0]),Wm(i[1])])}return t}function Km(e){return typeof e=="string"?new RegExp(Um(e),"g"):e}function Wm(e){return typeof e=="function"?e:function(){return e}}function Vm(e){ha(e,[/\r?\n|\r/g,Xm])}function Xm(){return{type:"break"}}function Ym(){return function(e){Vm(e)}}const br="phrasing",kr=["autolink","link","image","label"];function Gm(){return{transforms:[rg],enter:{literalAutolink:Jm,literalAutolinkEmail:wr,literalAutolinkHttp:wr,literalAutolinkWww:wr},exit:{literalAutolink:ng,literalAutolinkEmail:tg,literalAutolinkHttp:Zm,literalAutolinkWww:eg}}}function Qm(){return{unsafe:[{character:"@",before:"[+\\-.\\w]",after:"[\\-.\\w]",inConstruct:br,notInConstruct:kr},{character:".",before:"[Ww]",after:"[\\-.\\w]",inConstruct:br,notInConstruct:kr},{character:":",before:"[ps]",after:"\\/",inConstruct:br,notInConstruct:kr}]}}function Jm(e){this.enter({type:"link",title:null,url:"",children:[]},e)}function wr(e){this.config.enter.autolinkProtocol.call(this,e)}function Zm(e){this.config.exit.autolinkProtocol.call(this,e)}function eg(e){this.config.exit.data.call(this,e);const t=this.stack[this.stack.length-1];t.type,t.url="http://"+this.sliceSerialize(e)}function tg(e){this.config.exit.autolinkEmail.call(this,e)}function ng(e){this.exit(e)}function rg(e){ha(e,[[/(https?:\/\/|www(?=\.))([-.\w]+)([^ \t\r\n]*)/gi,ig],[new RegExp("(?<=^|\\s|\\p{P}|\\p{S})([-.\\w+]+)@([-\\w]+(?:\\.[-\\w]+)+)","gu"),sg]],{ignore:["link","linkReference"]})}function ig(e,t,n,r,i){let s="";if(!pa(i)||(/^w/i.test(t)&&(n=t+n,t="",s="http://"),!og(n)))return!1;const o=ag(n+r);if(!o[0])return!1;const a={type:"link",title:null,url:s+t+o[0],children:[{type:"text",value:t+o[0]}]};return o[1]?[a,{type:"text",value:o[1]}]:a}function sg(e,t,n,r){return!pa(r,!0)||/[-\d_]$/.test(n)?!1:{type:"link",title:null,url:"mailto:"+t+"@"+n,children:[{type:"text",value:t+"@"+n}]}}function og(e){const t=e.split(".");return!(t.length<2||t[t.length-1]&&(/_/.test(t[t.length-1])||!/[a-zA-Z\d]/.test(t[t.length-1]))||t[t.length-2]&&(/_/.test(t[t.length-2])||!/[a-zA-Z\d]/.test(t[t.length-2])))}function ag(e){const t=/[!"&'),.:;<>?\]}]+$/.exec(e);if(!t)return[e,void 0];e=e.slice(0,t.index);let n=t[0],r=n.indexOf(")");const i=Mi(e,"(");let s=Mi(e,")");for(;r!==-1&&i>s;)e+=n.slice(0,r+1),n=n.slice(r+1),r=n.indexOf(")"),s++;return[e,n]}function pa(e,t){const n=e.input.charCodeAt(e.index-1);return(e.index===0||Mt(n)||Vn(n))&&(!t||n!==47)}da.peek=gg;function lg(){this.buffer()}function ug(e){this.enter({type:"footnoteReference",identifier:"",label:""},e)}function cg(){this.buffer()}function fg(e){this.enter({type:"footnoteDefinition",identifier:"",label:"",children:[]},e)}function hg(e){const t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=tt(this.sliceSerialize(e)).toLowerCase(),n.label=t}function pg(e){this.exit(e)}function dg(e){const t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=tt(this.sliceSerialize(e)).toLowerCase(),n.label=t}function mg(e){this.exit(e)}function gg(){return"["}function da(e,t,n,r){const i=n.createTracker(r);let s=i.move("[^");const o=n.enter("footnoteReference"),a=n.enter("reference");return s+=i.move(n.safe(n.associationId(e),{after:"]",before:s})),a(),o(),s+=i.move("]"),s}function xg(){return{enter:{gfmFootnoteCallString:lg,gfmFootnoteCall:ug,gfmFootnoteDefinitionLabelString:cg,gfmFootnoteDefinition:fg},exit:{gfmFootnoteCallString:hg,gfmFootnoteCall:pg,gfmFootnoteDefinitionLabelString:dg,gfmFootnoteDefinition:mg}}}function yg(e){let t=!1;return e&&e.firstLineBlank&&(t=!0),{handlers:{footnoteDefinition:n,footnoteReference:da},unsafe:[{character:"[",inConstruct:["label","phrasing","reference"]}]};function n(r,i,s,o){const a=s.createTracker(o);let l=a.move("[^");const u=s.enter("footnoteDefinition"),c=s.enter("label");return l+=a.move(s.safe(s.associationId(r),{before:l,after:"]"})),c(),l+=a.move("]:"),r.children&&r.children.length>0&&(a.shift(4),l+=a.move((t?`
|
|
77
|
+
`:" ")+s.indentLines(s.containerFlow(r,a.current()),t?ma:bg))),u(),l}}function bg(e,t,n){return t===0?e:ma(e,t,n)}function ma(e,t,n){return(n?"":" ")+e}const kg=["autolink","destinationLiteral","destinationRaw","reference","titleQuote","titleApostrophe"];ga.peek=Eg;function wg(){return{canContainEols:["delete"],enter:{strikethrough:Cg},exit:{strikethrough:vg}}}function Sg(){return{unsafe:[{character:"~",inConstruct:"phrasing",notInConstruct:kg}],handlers:{delete:ga}}}function Cg(e){this.enter({type:"delete",children:[]},e)}function vg(e){this.exit(e)}function ga(e,t,n,r){const i=n.createTracker(r),s=n.enter("strikethrough");let o=i.move("~~");return o+=n.containerPhrasing(e,{...i.current(),before:o,after:"~"}),o+=i.move("~~"),s(),o}function Eg(){return"~"}function Tg(e){return e.length}function jg(e,t){const n=t||{},r=(n.align||[]).concat(),i=n.stringLength||Tg,s=[],o=[],a=[],l=[];let u=0,c=-1;for(;++c<e.length;){const y=[],w=[];let k=-1;for(e[c].length>u&&(u=e[c].length);++k<e[c].length;){const S=Ag(e[c][k]);if(n.alignDelimiters!==!1){const v=i(S);w[k]=v,(l[k]===void 0||v>l[k])&&(l[k]=v)}y.push(S)}o[c]=y,a[c]=w}let f=-1;if(typeof r=="object"&&"length"in r)for(;++f<u;)s[f]=js(r[f]);else{const y=js(r);for(;++f<u;)s[f]=y}f=-1;const d=[],p=[];for(;++f<u;){const y=s[f];let w="",k="";y===99?(w=":",k=":"):y===108?w=":":y===114&&(k=":");let S=n.alignDelimiters===!1?1:Math.max(1,l[f]-w.length-k.length);const v=w+"-".repeat(S)+k;n.alignDelimiters!==!1&&(S=w.length+S+k.length,S>l[f]&&(l[f]=S),p[f]=S),d[f]=v}o.splice(1,0,d),a.splice(1,0,p),c=-1;const g=[];for(;++c<o.length;){const y=o[c],w=a[c];f=-1;const k=[];for(;++f<u;){const S=y[f]||"";let v="",R="";if(n.alignDelimiters!==!1){const M=l[f]-(w[f]||0),C=s[f];C===114?v=" ".repeat(M):C===99?M%2?(v=" ".repeat(M/2+.5),R=" ".repeat(M/2-.5)):(v=" ".repeat(M/2),R=v):R=" ".repeat(M)}n.delimiterStart!==!1&&!f&&k.push("|"),n.padding!==!1&&!(n.alignDelimiters===!1&&S==="")&&(n.delimiterStart!==!1||f)&&k.push(" "),n.alignDelimiters!==!1&&k.push(v),k.push(S),n.alignDelimiters!==!1&&k.push(R),n.padding!==!1&&k.push(" "),(n.delimiterEnd!==!1||f!==u-1)&&k.push("|")}g.push(n.delimiterEnd===!1?k.join("").replace(/ +$/,""):k.join(""))}return g.join(`
|
|
78
78
|
`)}function Ag(e){return e==null?"":String(e)}function js(e){const t=typeof e=="string"?e.codePointAt(0):0;return t===67||t===99?99:t===76||t===108?108:t===82||t===114?114:0}function Ig(e,t,n,r){const i=n.enter("blockquote"),s=n.createTracker(r);s.move("> "),s.shift(2);const o=n.indentLines(n.containerFlow(e,s.current()),Rg);return i(),o}function Rg(e,t,n){return">"+(n?"":" ")+e}function Ng(e,t){return As(e,t.inConstruct,!0)&&!As(e,t.notInConstruct,!1)}function As(e,t,n){if(typeof t=="string"&&(t=[t]),!t||t.length===0)return n;let r=-1;for(;++r<t.length;)if(e.includes(t[r]))return!0;return!1}function Is(e,t,n,r){let i=-1;for(;++i<n.unsafe.length;)if(n.unsafe[i].character===`
|
|
79
79
|
`&&Ng(n.stack,n.unsafe[i]))return/[ \t]/.test(r.before)?"":" ";return`\\
|
|
80
80
|
`}function Lg(e,t){const n=String(e);let r=n.indexOf(t),i=r,s=0,o=0;if(typeof t!="string")throw new TypeError("Expected substring");for(;r!==-1;)r===i?++s>o&&(o=s):s=1,i=r+t.length,r=n.indexOf(t,i);return o}function Mg(e,t){return!!(t.options.fences===!1&&e.value&&!e.lang&&/[^ \r\n]/.test(e.value)&&!/^[\t ]*(?:[\r\n]|$)|(?:^|[\r\n])[\t ]*$/.test(e.value))}function Dg(e){const t=e.options.fence||"`";if(t!=="`"&&t!=="~")throw new Error("Cannot serialize code with `"+t+"` for `options.fence`, expected `` ` `` or `~`");return t}function zg(e,t,n,r){const i=Dg(n),s=e.value||"",o=i==="`"?"GraveAccent":"Tilde";if(Mg(e,n)){const f=n.enter("codeIndented"),d=n.indentLines(s,Pg);return f(),d}const a=n.createTracker(r),l=i.repeat(Math.max(Lg(s,i)+1,3)),u=n.enter("codeFenced");let c=a.move(l);if(e.lang){const f=n.enter(`codeFencedLang${o}`);c+=a.move(n.safe(e.lang,{before:c,after:" ",encode:["`"],...a.current()})),f()}if(e.lang&&e.meta){const f=n.enter(`codeFencedMeta${o}`);c+=a.move(" "),c+=a.move(n.safe(e.meta,{before:c,after:`
|
|
@@ -87,11 +87,11 @@ Please report this to https://github.com/markedjs/marked.`,e){let r="<p>An error
|
|
|
87
87
|
`+(i===1?"=":"-").repeat(d.length-(Math.max(d.lastIndexOf("\r"),d.lastIndexOf(`
|
|
88
88
|
`))+1))}const o="#".repeat(i),a=n.enter("headingAtx"),l=n.enter("phrasing");s.move(o+" ");let u=n.containerPhrasing(e,{before:"# ",after:`
|
|
89
89
|
`,...s.current()});return/^[\t ]/.test(u)&&(u=un(u.charCodeAt(0))+u.slice(1)),u=u?o+" "+u:o,n.options.closeAtx&&(u+=" "+o),l(),a(),u}ya.peek=Hg;function ya(e){return e.value||""}function Hg(){return"<"}ba.peek=Ug;function ba(e,t,n,r){const i=wi(n),s=i==='"'?"Quote":"Apostrophe",o=n.enter("image");let a=n.enter("label");const l=n.createTracker(r);let u=l.move("![");return u+=l.move(n.safe(e.alt,{before:u,after:"]",...l.current()})),u+=l.move("]("),a(),!e.url&&e.title||/[\0- \u007F]/.test(e.url)?(a=n.enter("destinationLiteral"),u+=l.move("<"),u+=l.move(n.safe(e.url,{before:u,after:">",...l.current()})),u+=l.move(">")):(a=n.enter("destinationRaw"),u+=l.move(n.safe(e.url,{before:u,after:e.title?" ":")",...l.current()}))),a(),e.title&&(a=n.enter(`title${s}`),u+=l.move(" "+i),u+=l.move(n.safe(e.title,{before:u,after:i,...l.current()})),u+=l.move(i),a()),u+=l.move(")"),o(),u}function Ug(){return"!"}ka.peek=qg;function ka(e,t,n,r){const i=e.referenceType,s=n.enter("imageReference");let o=n.enter("label");const a=n.createTracker(r);let l=a.move("![");const u=n.safe(e.alt,{before:l,after:"]",...a.current()});l+=a.move(u+"]["),o();const c=n.stack;n.stack=[],o=n.enter("reference");const f=n.safe(n.associationId(e),{before:l,after:"]",...a.current()});return o(),n.stack=c,s(),i==="full"||!u||u!==f?l+=a.move(f+"]"):i==="shortcut"?l=l.slice(0,-1):l+=a.move("]"),l}function qg(){return"!"}wa.peek=Kg;function wa(e,t,n){let r=e.value||"",i="`",s=-1;for(;new RegExp("(^|[^`])"+i+"([^`]|$)").test(r);)i+="`";for(/[^ \r\n]/.test(r)&&(/^[ \r\n]/.test(r)&&/[ \r\n]$/.test(r)||/^`|`$/.test(r))&&(r=" "+r+" ");++s<n.unsafe.length;){const o=n.unsafe[s],a=n.compilePattern(o);let l;if(o.atBreak)for(;l=a.exec(r);){let u=l.index;r.charCodeAt(u)===10&&r.charCodeAt(u-1)===13&&u--,r=r.slice(0,u)+" "+r.slice(l.index+1)}}return i+r+i}function Kg(){return"`"}function Sa(e,t){const n=hi(e);return!!(!t.options.resourceLink&&e.url&&!e.title&&e.children&&e.children.length===1&&e.children[0].type==="text"&&(n===e.url||"mailto:"+n===e.url)&&/^[a-z][a-z+.-]+:/i.test(e.url)&&!/[\0- <>\u007F]/.test(e.url))}Ca.peek=Wg;function Ca(e,t,n,r){const i=wi(n),s=i==='"'?"Quote":"Apostrophe",o=n.createTracker(r);let a,l;if(Sa(e,n)){const c=n.stack;n.stack=[],a=n.enter("autolink");let f=o.move("<");return f+=o.move(n.containerPhrasing(e,{before:f,after:">",...o.current()})),f+=o.move(">"),a(),n.stack=c,f}a=n.enter("link"),l=n.enter("label");let u=o.move("[");return u+=o.move(n.containerPhrasing(e,{before:u,after:"](",...o.current()})),u+=o.move("]("),l(),!e.url&&e.title||/[\0- \u007F]/.test(e.url)?(l=n.enter("destinationLiteral"),u+=o.move("<"),u+=o.move(n.safe(e.url,{before:u,after:">",...o.current()})),u+=o.move(">")):(l=n.enter("destinationRaw"),u+=o.move(n.safe(e.url,{before:u,after:e.title?" ":")",...o.current()}))),l(),e.title&&(l=n.enter(`title${s}`),u+=o.move(" "+i),u+=o.move(n.safe(e.title,{before:u,after:i,...o.current()})),u+=o.move(i),l()),u+=o.move(")"),a(),u}function Wg(e,t,n){return Sa(e,n)?"<":"["}va.peek=Vg;function va(e,t,n,r){const i=e.referenceType,s=n.enter("linkReference");let o=n.enter("label");const a=n.createTracker(r);let l=a.move("[");const u=n.containerPhrasing(e,{before:l,after:"]",...a.current()});l+=a.move(u+"]["),o();const c=n.stack;n.stack=[],o=n.enter("reference");const f=n.safe(n.associationId(e),{before:l,after:"]",...a.current()});return o(),n.stack=c,s(),i==="full"||!u||u!==f?l+=a.move(f+"]"):i==="shortcut"?l=l.slice(0,-1):l+=a.move("]"),l}function Vg(){return"["}function Si(e){const t=e.options.bullet||"*";if(t!=="*"&&t!=="+"&&t!=="-")throw new Error("Cannot serialize items with `"+t+"` for `options.bullet`, expected `*`, `+`, or `-`");return t}function Xg(e){const t=Si(e),n=e.options.bulletOther;if(!n)return t==="*"?"-":"*";if(n!=="*"&&n!=="+"&&n!=="-")throw new Error("Cannot serialize items with `"+n+"` for `options.bulletOther`, expected `*`, `+`, or `-`");if(n===t)throw new Error("Expected `bullet` (`"+t+"`) and `bulletOther` (`"+n+"`) to be different");return n}function Yg(e){const t=e.options.bulletOrdered||".";if(t!=="."&&t!==")")throw new Error("Cannot serialize items with `"+t+"` for `options.bulletOrdered`, expected `.` or `)`");return t}function Ea(e){const t=e.options.rule||"*";if(t!=="*"&&t!=="-"&&t!=="_")throw new Error("Cannot serialize rules with `"+t+"` for `options.rule`, expected `*`, `-`, or `_`");return t}function Gg(e,t,n,r){const i=n.enter("list"),s=n.bulletCurrent;let o=e.ordered?Yg(n):Si(n);const a=e.ordered?o==="."?")":".":Xg(n);let l=t&&n.bulletLastUsed?o===n.bulletLastUsed:!1;if(!e.ordered){const c=e.children?e.children[0]:void 0;if((o==="*"||o==="-")&&c&&(!c.children||!c.children[0])&&n.stack[n.stack.length-1]==="list"&&n.stack[n.stack.length-2]==="listItem"&&n.stack[n.stack.length-3]==="list"&&n.stack[n.stack.length-4]==="listItem"&&n.indexStack[n.indexStack.length-1]===0&&n.indexStack[n.indexStack.length-2]===0&&n.indexStack[n.indexStack.length-3]===0&&(l=!0),Ea(n)===o&&c){let f=-1;for(;++f<e.children.length;){const d=e.children[f];if(d&&d.type==="listItem"&&d.children&&d.children[0]&&d.children[0].type==="thematicBreak"){l=!0;break}}}}l&&(o=a),n.bulletCurrent=o;const u=n.containerFlow(e,r);return n.bulletLastUsed=o,n.bulletCurrent=s,i(),u}function Qg(e){const t=e.options.listItemIndent||"one";if(t!=="tab"&&t!=="one"&&t!=="mixed")throw new Error("Cannot serialize items with `"+t+"` for `options.listItemIndent`, expected `tab`, `one`, or `mixed`");return t}function Jg(e,t,n,r){const i=Qg(n);let s=n.bulletCurrent||Si(n);t&&t.type==="list"&&t.ordered&&(s=(typeof t.start=="number"&&t.start>-1?t.start:1)+(n.options.incrementListMarker===!1?0:t.children.indexOf(e))+s);let o=s.length+1;(i==="tab"||i==="mixed"&&(t&&t.type==="list"&&t.spread||e.spread))&&(o=Math.ceil(o/4)*4);const a=n.createTracker(r);a.move(s+" ".repeat(o-s.length)),a.shift(o);const l=n.enter("listItem"),u=n.indentLines(n.containerFlow(e,a.current()),c);return l(),u;function c(f,d,p){return d?(p?"":" ".repeat(o))+f:(p?s:s+" ".repeat(o-s.length))+f}}function Zg(e,t,n,r){const i=n.enter("paragraph"),s=n.enter("phrasing"),o=n.containerPhrasing(e,r);return s(),i(),o}const ex=Gn(["break","delete","emphasis","footnote","footnoteReference","image","imageReference","inlineCode","inlineMath","link","linkReference","mdxJsxTextElement","mdxTextExpression","strong","text","textDirective"]);function tx(e,t,n,r){return(e.children.some(function(o){return ex(o)})?n.containerPhrasing:n.containerFlow).call(n,e,r)}function nx(e){const t=e.options.strong||"*";if(t!=="*"&&t!=="_")throw new Error("Cannot serialize strong with `"+t+"` for `options.strong`, expected `*`, or `_`");return t}Ta.peek=rx;function Ta(e,t,n,r){const i=nx(n),s=n.enter("strong"),o=n.createTracker(r),a=o.move(i+i);let l=o.move(n.containerPhrasing(e,{after:i,before:a,...o.current()}));const u=l.charCodeAt(0),c=On(r.before.charCodeAt(r.before.length-1),u,i);c.inside&&(l=un(u)+l.slice(1));const f=l.charCodeAt(l.length-1),d=On(r.after.charCodeAt(0),f,i);d.inside&&(l=l.slice(0,-1)+un(f));const p=o.move(i+i);return s(),n.attentionEncodeSurroundingInfo={after:d.outside,before:c.outside},a+l+p}function rx(e,t,n){return n.options.strong||"*"}function ix(e,t,n,r){return n.safe(e.value,r)}function sx(e){const t=e.options.ruleRepetition||3;if(t<3)throw new Error("Cannot serialize rules with repetition `"+t+"` for `options.ruleRepetition`, expected `3` or more");return t}function ox(e,t,n){const r=(Ea(n)+(n.options.ruleSpaces?" ":"")).repeat(sx(n));return n.options.ruleSpaces?r.slice(0,-1):r}const ja={blockquote:Ig,break:Is,code:zg,definition:_g,emphasis:xa,hardBreak:Is,heading:Bg,html:ya,image:ba,imageReference:ka,inlineCode:wa,link:Ca,linkReference:va,list:Gg,listItem:Jg,paragraph:Zg,root:tx,strong:Ta,text:ix,thematicBreak:ox};function ax(){return{enter:{table:lx,tableData:Rs,tableHeader:Rs,tableRow:cx},exit:{codeText:fx,table:ux,tableData:Sr,tableHeader:Sr,tableRow:Sr}}}function lx(e){const t=e._align;this.enter({type:"table",align:t.map(function(n){return n==="none"?null:n}),children:[]},e),this.data.inTable=!0}function ux(e){this.exit(e),this.data.inTable=void 0}function cx(e){this.enter({type:"tableRow",children:[]},e)}function Sr(e){this.exit(e)}function Rs(e){this.enter({type:"tableCell",children:[]},e)}function fx(e){let t=this.resume();this.data.inTable&&(t=t.replace(/\\([\\|])/g,hx));const n=this.stack[this.stack.length-1];n.type,n.value=t,this.exit(e)}function hx(e,t){return t==="|"?t:e}function px(e){const t=e||{},n=t.tableCellPadding,r=t.tablePipeAlign,i=t.stringLength,s=n?" ":"|";return{unsafe:[{character:"\r",inConstruct:"tableCell"},{character:`
|
|
90
|
-
`,inConstruct:"tableCell"},{atBreak:!0,character:"|",after:"[ :-]"},{character:"|",inConstruct:"tableCell"},{atBreak:!0,character:":",after:"-"},{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{inlineCode:d,table:o,tableCell:l,tableRow:a}};function o(p,g,
|
|
91
|
-
`))}function l(p,g,b,w){const k=b.enter("tableCell"),C=b.enter("phrasing"),E=b.containerPhrasing(p,{...w,before:s,after:s});return C(),k(),E}function u(p,g){return jg(p,{align:g,alignDelimiters:r,padding:n,stringLength:i})}function c(p,g,b){const w=p.children;let k=-1;const C=[],E=g.enter("table");for(;++k<w.length;)C[k]=f(w[k],g,b);return E(),C}function f(p,g,b){const w=p.children;let k=-1;const C=[],E=g.enter("tableRow");for(;++k<w.length;)C[k]=l(w[k],p,g,b);return E(),C}function d(p,g,b){let w=ja.inlineCode(p,g,b);return b.stack.includes("tableCell")&&(w=w.replace(/\|/g,"\\$&")),w}}function dx(){return{exit:{taskListCheckValueChecked:Ns,taskListCheckValueUnchecked:Ns,paragraph:gx}}}function mx(){return{unsafe:[{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{listItem:xx}}}function Ns(e){const t=this.stack[this.stack.length-2];t.type,t.checked=e.type==="taskListCheckValueChecked"}function gx(e){const t=this.stack[this.stack.length-2];if(t&&t.type==="listItem"&&typeof t.checked=="boolean"){const n=this.stack[this.stack.length-1];n.type;const r=n.children[0];if(r&&r.type==="text"){const i=t.children;let s=-1,o;for(;++s<i.length;){const a=i[s];if(a.type==="paragraph"){o=a;break}}o===n&&(r.value=r.value.slice(1),r.value.length===0?n.children.shift():n.position&&r.position&&typeof r.position.start.offset=="number"&&(r.position.start.column++,r.position.start.offset++,n.position.start=Object.assign({},r.position.start)))}}this.exit(e)}function xx(e,t,n,r){const i=e.children[0],s=typeof e.checked=="boolean"&&i&&i.type==="paragraph",o="["+(e.checked?"x":" ")+"] ",a=n.createTracker(r);s&&a.move(o);let l=ja.listItem(e,t,n,{...r,...a.current()});return s&&(l=l.replace(/^(?:[*+-]|\d+\.)([\r\n]| {1,3})/,u)),l;function u(c){return c+o}}function yx(){return[Gm(),xg(),wg(),ax(),dx()]}function bx(e){return{extensions:[Qm(),yg(e),Sg(),px(e),mx()]}}const kx={tokenize:Tx,partial:!0},Aa={tokenize:jx,partial:!0},Ia={tokenize:Ax,partial:!0},Ra={tokenize:Ix,partial:!0},wx={tokenize:Rx,partial:!0},Na={name:"wwwAutolink",tokenize:vx,previous:Ma},La={name:"protocolAutolink",tokenize:Ex,previous:Da},lt={name:"emailAutolink",tokenize:Cx,previous:za},it={};function Sx(){return{text:it}}let vt=48;for(;vt<123;)it[vt]=lt,vt++,vt===58?vt=65:vt===91&&(vt=97);it[43]=lt;it[45]=lt;it[46]=lt;it[95]=lt;it[72]=[lt,La];it[104]=[lt,La];it[87]=[lt,Na];it[119]=[lt,Na];function Cx(e,t,n){const r=this;let i,s;return o;function o(f){return!Br(f)||!za.call(r,r.previous)||Ci(r.events)?n(f):(e.enter("literalAutolink"),e.enter("literalAutolinkEmail"),a(f))}function a(f){return Br(f)?(e.consume(f),a):f===64?(e.consume(f),l):n(f)}function l(f){return f===46?e.check(wx,c,u)(f):f===45||f===95||Re(f)?(s=!0,e.consume(f),l):c(f)}function u(f){return e.consume(f),i=!0,l}function c(f){return s&&i&&Me(r.previous)?(e.exit("literalAutolinkEmail"),e.exit("literalAutolink"),t(f)):n(f)}}function vx(e,t,n){const r=this;return i;function i(o){return o!==87&&o!==119||!Ma.call(r,r.previous)||Ci(r.events)?n(o):(e.enter("literalAutolink"),e.enter("literalAutolinkWww"),e.check(kx,e.attempt(Aa,e.attempt(Ia,s),n),n)(o))}function s(o){return e.exit("literalAutolinkWww"),e.exit("literalAutolink"),t(o)}}function Ex(e,t,n){const r=this;let i="",s=!1;return o;function o(f){return(f===72||f===104)&&Da.call(r,r.previous)&&!Ci(r.events)?(e.enter("literalAutolink"),e.enter("literalAutolinkHttp"),i+=String.fromCodePoint(f),e.consume(f),a):n(f)}function a(f){if(Me(f)&&i.length<5)return i+=String.fromCodePoint(f),e.consume(f),a;if(f===58){const d=i.toLowerCase();if(d==="http"||d==="https")return e.consume(f),l}return n(f)}function l(f){return f===47?(e.consume(f),s?u:(s=!0,l)):n(f)}function u(f){return f===null||zn(f)||he(f)||Mt(f)||Vn(f)?n(f):e.attempt(Aa,e.attempt(Ia,c),n)(f)}function c(f){return e.exit("literalAutolinkHttp"),e.exit("literalAutolink"),t(f)}}function Tx(e,t,n){let r=0;return i;function i(o){return(o===87||o===119)&&r<3?(r++,e.consume(o),i):o===46&&r===3?(e.consume(o),s):n(o)}function s(o){return o===null?n(o):t(o)}}function jx(e,t,n){let r,i,s;return o;function o(u){return u===46||u===95?e.check(Ra,l,a)(u):u===null||he(u)||Mt(u)||u!==45&&Vn(u)?l(u):(s=!0,e.consume(u),o)}function a(u){return u===95?r=!0:(i=r,r=void 0),e.consume(u),o}function l(u){return i||r||!s?n(u):t(u)}}function Ax(e,t){let n=0,r=0;return i;function i(o){return o===40?(n++,e.consume(o),i):o===41&&r<n?s(o):o===33||o===34||o===38||o===39||o===41||o===42||o===44||o===46||o===58||o===59||o===60||o===63||o===93||o===95||o===126?e.check(Ra,t,s)(o):o===null||he(o)||Mt(o)?t(o):(e.consume(o),i)}function s(o){return o===41&&r++,e.consume(o),i}}function Ix(e,t,n){return r;function r(a){return a===33||a===34||a===39||a===41||a===42||a===44||a===46||a===58||a===59||a===63||a===95||a===126?(e.consume(a),r):a===38?(e.consume(a),s):a===93?(e.consume(a),i):a===60||a===null||he(a)||Mt(a)?t(a):n(a)}function i(a){return a===null||a===40||a===91||he(a)||Mt(a)?t(a):r(a)}function s(a){return Me(a)?o(a):n(a)}function o(a){return a===59?(e.consume(a),r):Me(a)?(e.consume(a),o):n(a)}}function Rx(e,t,n){return r;function r(s){return e.consume(s),i}function i(s){return Re(s)?n(s):t(s)}}function Ma(e){return e===null||e===40||e===42||e===95||e===91||e===93||e===126||he(e)}function Da(e){return!Me(e)}function za(e){return!(e===47||Br(e))}function Br(e){return e===43||e===45||e===46||e===95||Re(e)}function Ci(e){let t=e.length,n=!1;for(;t--;){const r=e[t][1];if((r.type==="labelLink"||r.type==="labelImage")&&!r._balanced){n=!0;break}if(r._gfmAutolinkLiteralWalkedInto){n=!1;break}}return e.length>0&&!n&&(e[e.length-1][1]._gfmAutolinkLiteralWalkedInto=!0),n}const Nx={tokenize:Fx,partial:!0};function Lx(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:Px,continuation:{tokenize:_x},exit:Ox}},text:{91:{name:"gfmFootnoteCall",tokenize:zx},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:Mx,resolveTo:Dx}}}}function Mx(e,t,n){const r=this;let i=r.events.length;const s=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let o;for(;i--;){const l=r.events[i][1];if(l.type==="labelImage"){o=l;break}if(l.type==="gfmFootnoteCall"||l.type==="labelLink"||l.type==="label"||l.type==="image"||l.type==="link")break}return a;function a(l){if(!o||!o._balanced)return n(l);const u=Ze(r.sliceSerialize({start:o.end,end:r.now()}));return u.codePointAt(0)!==94||!s.includes(u.slice(1))?n(l):(e.enter("gfmFootnoteCallLabelMarker"),e.consume(l),e.exit("gfmFootnoteCallLabelMarker"),t(l))}}function Dx(e,t){let n=e.length;for(;n--;)if(e[n][1].type==="labelImage"&&e[n][0]==="enter"){e[n][1];break}e[n+1][1].type="data",e[n+3][1].type="gfmFootnoteCallLabelMarker";const r={type:"gfmFootnoteCall",start:Object.assign({},e[n+3][1].start),end:Object.assign({},e[e.length-1][1].end)},i={type:"gfmFootnoteCallMarker",start:Object.assign({},e[n+3][1].end),end:Object.assign({},e[n+3][1].end)};i.end.column++,i.end.offset++,i.end._bufferIndex++;const s={type:"gfmFootnoteCallString",start:Object.assign({},i.end),end:Object.assign({},e[e.length-1][1].start)},o={type:"chunkString",contentType:"string",start:Object.assign({},s.start),end:Object.assign({},s.end)},a=[e[n+1],e[n+2],["enter",r,t],e[n+3],e[n+4],["enter",i,t],["exit",i,t],["enter",s,t],["enter",o,t],["exit",o,t],["exit",s,t],e[e.length-2],e[e.length-1],["exit",r,t]];return e.splice(n,e.length-n+1,...a),e}function zx(e,t,n){const r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let s=0,o;return a;function a(f){return e.enter("gfmFootnoteCall"),e.enter("gfmFootnoteCallLabelMarker"),e.consume(f),e.exit("gfmFootnoteCallLabelMarker"),l}function l(f){return f!==94?n(f):(e.enter("gfmFootnoteCallMarker"),e.consume(f),e.exit("gfmFootnoteCallMarker"),e.enter("gfmFootnoteCallString"),e.enter("chunkString").contentType="string",u)}function u(f){if(s>999||f===93&&!o||f===null||f===91||he(f))return n(f);if(f===93){e.exit("chunkString");const d=e.exit("gfmFootnoteCallString");return i.includes(Ze(r.sliceSerialize(d)))?(e.enter("gfmFootnoteCallLabelMarker"),e.consume(f),e.exit("gfmFootnoteCallLabelMarker"),e.exit("gfmFootnoteCall"),t):n(f)}return he(f)||(o=!0),s++,e.consume(f),f===92?c:u}function c(f){return f===91||f===92||f===93?(e.consume(f),s++,u):u(f)}}function Px(e,t,n){const r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let s,o=0,a;return l;function l(g){return e.enter("gfmFootnoteDefinition")._container=!0,e.enter("gfmFootnoteDefinitionLabel"),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(g),e.exit("gfmFootnoteDefinitionLabelMarker"),u}function u(g){return g===94?(e.enter("gfmFootnoteDefinitionMarker"),e.consume(g),e.exit("gfmFootnoteDefinitionMarker"),e.enter("gfmFootnoteDefinitionLabelString"),e.enter("chunkString").contentType="string",c):n(g)}function c(g){if(o>999||g===93&&!a||g===null||g===91||he(g))return n(g);if(g===93){e.exit("chunkString");const b=e.exit("gfmFootnoteDefinitionLabelString");return s=Ze(r.sliceSerialize(b)),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(g),e.exit("gfmFootnoteDefinitionLabelMarker"),e.exit("gfmFootnoteDefinitionLabel"),d}return he(g)||(a=!0),o++,e.consume(g),g===92?f:c}function f(g){return g===91||g===92||g===93?(e.consume(g),o++,c):c(g)}function d(g){return g===58?(e.enter("definitionMarker"),e.consume(g),e.exit("definitionMarker"),i.includes(s)||i.push(s),oe(e,p,"gfmFootnoteDefinitionWhitespace")):n(g)}function p(g){return t(g)}}function _x(e,t,n){return e.check(fn,t,e.attempt(Nx,t,n))}function Ox(e){e.exit("gfmFootnoteDefinition")}function Fx(e,t,n){const r=this;return oe(e,i,"gfmFootnoteDefinitionIndent",5);function i(s){const o=r.events[r.events.length-1];return o&&o[1].type==="gfmFootnoteDefinitionIndent"&&o[2].sliceSerialize(o[1],!0).length===4?t(s):n(s)}}function $x(e){let n=(e||{}).singleTilde;const r={name:"strikethrough",tokenize:s,resolveAll:i};return n==null&&(n=!0),{text:{126:r},insideSpan:{null:[r]},attentionMarkers:{null:[126]}};function i(o,a){let l=-1;for(;++l<o.length;)if(o[l][0]==="enter"&&o[l][1].type==="strikethroughSequenceTemporary"&&o[l][1]._close){let u=l;for(;u--;)if(o[u][0]==="exit"&&o[u][1].type==="strikethroughSequenceTemporary"&&o[u][1]._open&&o[l][1].end.offset-o[l][1].start.offset===o[u][1].end.offset-o[u][1].start.offset){o[l][1].type="strikethroughSequence",o[u][1].type="strikethroughSequence";const c={type:"strikethrough",start:Object.assign({},o[u][1].start),end:Object.assign({},o[l][1].end)},f={type:"strikethroughText",start:Object.assign({},o[u][1].end),end:Object.assign({},o[l][1].start)},d=[["enter",c,a],["enter",o[u][1],a],["exit",o[u][1],a],["enter",f,a]],p=a.parser.constructs.insideSpan.null;p&&$e(d,d.length,0,Xn(p,o.slice(u+1,l),a)),$e(d,d.length,0,[["exit",f,a],["enter",o[l][1],a],["exit",o[l][1],a],["exit",c,a]]),$e(o,u-1,l-u+3,d),l=u+d.length-2;break}}for(l=-1;++l<o.length;)o[l][1].type==="strikethroughSequenceTemporary"&&(o[l][1].type="data");return o}function s(o,a,l){const u=this.previous,c=this.events;let f=0;return d;function d(g){return u===126&&c[c.length-1][1].type!=="characterEscape"?l(g):(o.enter("strikethroughSequenceTemporary"),p(g))}function p(g){const b=Ut(u);if(g===126)return f>1?l(g):(o.consume(g),f++,p);if(f<2&&!n)return l(g);const w=o.exit("strikethroughSequenceTemporary"),k=Ut(g);return w._open=!k||k===2&&!!b,w._close=!b||b===2&&!!k,a(g)}}}class Bx{constructor(){this.map=[]}add(t,n,r){Hx(this,t,n,r)}consume(t){if(this.map.sort(function(s,o){return s[0]-o[0]}),this.map.length===0)return;let n=this.map.length;const r=[];for(;n>0;)n-=1,r.push(t.slice(this.map[n][0]+this.map[n][1]),this.map[n][2]),t.length=this.map[n][0];r.push(t.slice()),t.length=0;let i=r.pop();for(;i;){for(const s of i)t.push(s);i=r.pop()}this.map.length=0}}function Hx(e,t,n,r){let i=0;if(!(n===0&&r.length===0)){for(;i<e.map.length;){if(e.map[i][0]===t){e.map[i][1]+=n,e.map[i][2].push(...r);return}i+=1}e.map.push([t,n,r])}}function Ux(e,t){let n=!1;const r=[];for(;t<e.length;){const i=e[t];if(n){if(i[0]==="enter")i[1].type==="tableContent"&&r.push(e[t+1][1].type==="tableDelimiterMarker"?"left":"none");else if(i[1].type==="tableContent"){if(e[t-1][1].type==="tableDelimiterMarker"){const s=r.length-1;r[s]=r[s]==="left"?"center":"right"}}else if(i[1].type==="tableDelimiterRow")break}else i[0]==="enter"&&i[1].type==="tableDelimiterRow"&&(n=!0);t+=1}return r}function qx(){return{flow:{null:{name:"table",tokenize:Kx,resolveAll:Wx}}}}function Kx(e,t,n){const r=this;let i=0,s=0,o;return a;function a(v){let L=r.events.length-1;for(;L>-1;){const T=r.events[L][1].type;if(T==="lineEnding"||T==="linePrefix")L--;else break}const A=L>-1?r.events[L][1].type:null,F=A==="tableHead"||A==="tableRow"?S:l;return F===S&&r.parser.lazy[r.now().line]?n(v):F(v)}function l(v){return e.enter("tableHead"),e.enter("tableRow"),u(v)}function u(v){return v===124||(o=!0,s+=1),c(v)}function c(v){return v===null?n(v):G(v)?s>1?(s=0,r.interrupt=!0,e.exit("tableRow"),e.enter("lineEnding"),e.consume(v),e.exit("lineEnding"),p):n(v):se(v)?oe(e,c,"whitespace")(v):(s+=1,o&&(o=!1,i+=1),v===124?(e.enter("tableCellDivider"),e.consume(v),e.exit("tableCellDivider"),o=!0,c):(e.enter("data"),f(v)))}function f(v){return v===null||v===124||he(v)?(e.exit("data"),c(v)):(e.consume(v),v===92?d:f)}function d(v){return v===92||v===124?(e.consume(v),f):f(v)}function p(v){return r.interrupt=!1,r.parser.lazy[r.now().line]?n(v):(e.enter("tableDelimiterRow"),o=!1,se(v)?oe(e,g,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(v):g(v))}function g(v){return v===45||v===58?w(v):v===124?(o=!0,e.enter("tableCellDivider"),e.consume(v),e.exit("tableCellDivider"),b):_(v)}function b(v){return se(v)?oe(e,w,"whitespace")(v):w(v)}function w(v){return v===58?(s+=1,o=!0,e.enter("tableDelimiterMarker"),e.consume(v),e.exit("tableDelimiterMarker"),k):v===45?(s+=1,k(v)):v===null||G(v)?N(v):_(v)}function k(v){return v===45?(e.enter("tableDelimiterFiller"),C(v)):_(v)}function C(v){return v===45?(e.consume(v),C):v===58?(o=!0,e.exit("tableDelimiterFiller"),e.enter("tableDelimiterMarker"),e.consume(v),e.exit("tableDelimiterMarker"),E):(e.exit("tableDelimiterFiller"),E(v))}function E(v){return se(v)?oe(e,N,"whitespace")(v):N(v)}function N(v){return v===124?g(v):v===null||G(v)?!o||i!==s?_(v):(e.exit("tableDelimiterRow"),e.exit("tableHead"),t(v)):_(v)}function _(v){return n(v)}function S(v){return e.enter("tableRow"),M(v)}function M(v){return v===124?(e.enter("tableCellDivider"),e.consume(v),e.exit("tableCellDivider"),M):v===null||G(v)?(e.exit("tableRow"),t(v)):se(v)?oe(e,M,"whitespace")(v):(e.enter("data"),U(v))}function U(v){return v===null||v===124||he(v)?(e.exit("data"),M(v)):(e.consume(v),v===92?O:U)}function O(v){return v===92||v===124?(e.consume(v),U):U(v)}}function Wx(e,t){let n=-1,r=!0,i=0,s=[0,0,0,0],o=[0,0,0,0],a=!1,l=0,u,c,f;const d=new Bx;for(;++n<e.length;){const p=e[n],g=p[1];p[0]==="enter"?g.type==="tableHead"?(a=!1,l!==0&&(Ls(d,t,l,u,c),c=void 0,l=0),u={type:"table",start:Object.assign({},g.start),end:Object.assign({},g.end)},d.add(n,0,[["enter",u,t]])):g.type==="tableRow"||g.type==="tableDelimiterRow"?(r=!0,f=void 0,s=[0,0,0,0],o=[0,n+1,0,0],a&&(a=!1,c={type:"tableBody",start:Object.assign({},g.start),end:Object.assign({},g.end)},d.add(n,0,[["enter",c,t]])),i=g.type==="tableDelimiterRow"?2:c?3:1):i&&(g.type==="data"||g.type==="tableDelimiterMarker"||g.type==="tableDelimiterFiller")?(r=!1,o[2]===0&&(s[1]!==0&&(o[0]=o[1],f=bn(d,t,s,i,void 0,f),s=[0,0,0,0]),o[2]=n)):g.type==="tableCellDivider"&&(r?r=!1:(s[1]!==0&&(o[0]=o[1],f=bn(d,t,s,i,void 0,f)),s=o,o=[s[1],n,0,0])):g.type==="tableHead"?(a=!0,l=n):g.type==="tableRow"||g.type==="tableDelimiterRow"?(l=n,s[1]!==0?(o[0]=o[1],f=bn(d,t,s,i,n,f)):o[1]!==0&&(f=bn(d,t,o,i,n,f)),i=0):i&&(g.type==="data"||g.type==="tableDelimiterMarker"||g.type==="tableDelimiterFiller")&&(o[3]=n)}for(l!==0&&Ls(d,t,l,u,c),d.consume(t.events),n=-1;++n<t.events.length;){const p=t.events[n];p[0]==="enter"&&p[1].type==="table"&&(p[1]._align=Ux(t.events,n))}return e}function bn(e,t,n,r,i,s){const o=r===1?"tableHeader":r===2?"tableDelimiter":"tableData",a="tableContent";n[0]!==0&&(s.end=Object.assign({},Bt(t.events,n[0])),e.add(n[0],0,[["exit",s,t]]));const l=Bt(t.events,n[1]);if(s={type:o,start:Object.assign({},l),end:Object.assign({},l)},e.add(n[1],0,[["enter",s,t]]),n[2]!==0){const u=Bt(t.events,n[2]),c=Bt(t.events,n[3]),f={type:a,start:Object.assign({},u),end:Object.assign({},c)};if(e.add(n[2],0,[["enter",f,t]]),r!==2){const d=t.events[n[2]],p=t.events[n[3]];if(d[1].end=Object.assign({},p[1].end),d[1].type="chunkText",d[1].contentType="text",n[3]>n[2]+1){const g=n[2]+1,b=n[3]-n[2]-1;e.add(g,b,[])}}e.add(n[3]+1,0,[["exit",f,t]])}return i!==void 0&&(s.end=Object.assign({},Bt(t.events,i)),e.add(i,0,[["exit",s,t]]),s=void 0),s}function Ls(e,t,n,r,i){const s=[],o=Bt(t.events,n);i&&(i.end=Object.assign({},o),s.push(["exit",i,t])),r.end=Object.assign({},o),s.push(["exit",r,t]),e.add(n+1,0,s)}function Bt(e,t){const n=e[t],r=n[0]==="enter"?"start":"end";return n[1][r]}const Vx={name:"tasklistCheck",tokenize:Yx};function Xx(){return{text:{91:Vx}}}function Yx(e,t,n){const r=this;return i;function i(l){return r.previous!==null||!r._gfmTasklistFirstContentOfListItem?n(l):(e.enter("taskListCheck"),e.enter("taskListCheckMarker"),e.consume(l),e.exit("taskListCheckMarker"),s)}function s(l){return he(l)?(e.enter("taskListCheckValueUnchecked"),e.consume(l),e.exit("taskListCheckValueUnchecked"),o):l===88||l===120?(e.enter("taskListCheckValueChecked"),e.consume(l),e.exit("taskListCheckValueChecked"),o):n(l)}function o(l){return l===93?(e.enter("taskListCheckMarker"),e.consume(l),e.exit("taskListCheckMarker"),e.exit("taskListCheck"),a):n(l)}function a(l){return G(l)?t(l):se(l)?e.check({tokenize:Gx},t,n)(l):n(l)}}function Gx(e,t,n){return oe(e,r,"whitespace");function r(i){return i===null?n(i):t(i)}}function Qx(e){return Ko([Sx(),Lx(),$x(e),qx(),Xx()])}const Jx={};function Zx(e){const t=this,n=e||Jx,r=t.data(),i=r.micromarkExtensions||(r.micromarkExtensions=[]),s=r.fromMarkdownExtensions||(r.fromMarkdownExtensions=[]),o=r.toMarkdownExtensions||(r.toMarkdownExtensions=[]);i.push(Qx(n)),s.push(yx()),o.push(bx(n))}function ey(e){if(!e?.startsWith("openclaw-file://"))return null;try{return decodeURIComponent(e.slice(16))}catch{return null}}const ty={py:"python",ts:"typescript",js:"javascript",jsx:"jsx",tsx:"tsx",json:"json",md:"markdown",yml:"yaml",yaml:"yaml",sh:"bash",bash:"bash",zsh:"bash",html:"html",css:"css",sql:"sql",xml:"xml",toml:"toml",rs:"rust",go:"go",java:"java",c:"c",cpp:"cpp",cs:"csharp",php:"php",rb:"ruby",graphql:"graphql",diff:"diff",patch:"diff",env:"text"};function ny(e){if(!e)return"text";const n=(e.split("/").pop()||"").toLowerCase();if(n==="dockerfile")return"dockerfile";if(n==="makefile")return"text";const r=n.split("."),i=r.length>1&&r.pop()||"",s=ty[i]||i||"text";return ou(s)}const ry=100*1024;function iy(e){return fe.lexer(e).map(n=>n.raw)}function sy(e){if(!e)return"text";const t=e.match(/language-(\w+)/);return t?t[1]:"text"}const oy={code:function({className:t,children:n}){if(!t?.includes("language-"))return h.jsx("code",{className:"rounded bg-primary-100 px-1.5 py-1 text-sm font-mono text-primary-900 border border-primary-200",children:n});const i=sy(t);return h.jsx(uo,{content:String(n??""),language:i,className:"w-full"})},pre:function({children:t}){return h.jsx(h.Fragment,{children:t})},h1:function({children:t}){return h.jsx("h1",{className:"text-xl font-medium text-primary-950",children:t})},h2:function({children:t}){return h.jsx("h2",{className:"text-lg font-medium text-primary-900",children:t})},h3:function({children:t}){return h.jsx("h3",{className:"font-medium text-primary-900",children:t})},p:function({children:t}){return h.jsx("p",{className:"text-primary-950 text-pretty leading-relaxed",children:t})},ul:function({children:t}){return h.jsx("ul",{className:"ml-4 list-disc text-primary-950 marker:text-primary-400",children:t})},ol:function({children:t}){return h.jsx("ol",{className:"ml-4 list-decimal text-primary-950 marker:text-primary-500",children:t})},li:function({children:t}){return h.jsx("li",{className:"leading-relaxed",children:t})},blockquote:function({children:t}){return h.jsx("blockquote",{className:"border-l-2 border-primary-300 pl-4 text-primary-900 italic",children:t})},strong:function({children:t}){return h.jsx("strong",{className:"font-medium text-primary-950",children:t})},em:function({children:t}){return h.jsx("em",{className:"italic text-primary-950",children:t})},hr:function(){return h.jsx("hr",{className:"my-3 border-primary-200"})},table:function({children:t}){return h.jsx("div",{className:"overflow-x-auto",children:h.jsx("table",{className:"w-full border-collapse text-sm",children:t})})},thead:function({children:t}){return h.jsx("thead",{className:"border-b border-primary-200 bg-primary-50",children:t})},tbody:function({children:t}){return h.jsx("tbody",{className:"divide-y divide-primary-100",children:t})},tr:function({children:t}){return h.jsx("tr",{className:"transition-colors hover:bg-primary-50/50",children:t})},th:function({children:t}){return h.jsx("th",{className:"px-3 py-2 text-left font-medium text-primary-950",children:t})},td:function({children:t}){return h.jsx("td",{className:"px-3 py-2 text-primary-950",children:t})}};function ay(e,t){const n=/^(?:~\/[\w.\-\/]+|\/(?:[\w.\-]+\/)+[\w.\-]+)$/;return{...oy,a:function({children:i,href:s}){const o=ey(s);return t&&o?h.jsx("button",{type:"button",onClick:()=>e(o),className:"font-mono text-primary-900 underline decoration-primary-300 underline-offset-4 hover:decoration-primary-600 cursor-pointer",children:i}):h.jsx("a",{href:s,className:"text-primary-950 underline decoration-primary-300 underline-offset-4 transition-colors hover:text-primary-950 hover:decoration-primary-500",target:"_blank",rel:"noopener noreferrer",children:i})},code:function({children:i,className:s}){if(s)return h.jsx("code",{className:s,children:i});const o=typeof i=="string"?i:Array.isArray(i)?i.filter(a=>typeof a=="string").join(""):String(i??"");return t&&o&&n.test(o)?h.jsx("button",{type:"button",onClick:()=>e(o),className:"font-mono text-sm bg-primary-100 rounded px-1.5 py-0.5 text-primary-900 underline decoration-primary-300 underline-offset-4 hover:decoration-primary-600 cursor-pointer",children:i}):h.jsx("code",{className:"font-mono text-sm bg-primary-100 rounded px-1.5 py-0.5 text-primary-900",children:i})}}}const Pa=m.memo(function({content:t,components:n}){return h.jsx(Om,{remarkPlugins:[Zx,Ym],components:n,children:t})},function(t,n){return t.content===n.content});Pa.displayName="MemoizedMarkdownBlock";function ly(e,t){return t==="NOT_FOUND"||e===404?"File not found":t==="UNSUPPORTED_TYPE"?"Binary file":t==="FILE_TOO_LARGE"||e===413?"File too large":"Failed to load file preview"}function uy({children:e,id:t,className:n,components:r}){const i=m.useId(),s=t??i,o=m.useMemo(()=>iy(e),[e]),[a,l]=m.useState({status:"idle"}),u=au(p=>p.settings.inlineFilePreview),c=m.useMemo(()=>ay(p=>l({status:"loading",path:p}),u),[u]),f=m.useMemo(()=>({...c,...r||{}}),[c,r]);m.useEffect(()=>{if(a.status!=="loading")return;const p=a.path,g=new AbortController;return fetch(`/api/files/read?path=${encodeURIComponent(p)}`,{signal:g.signal}).then(async b=>{const w=await b.json().catch(()=>({}));if(!b.ok){const E=ly(b.status,w.code);l({status:"error",path:p,message:E});return}if(Number(w.size??0)>ry){l({status:"error",path:p,message:"File too large"});return}const C=String(w.content??"");l({status:"success",path:p,content:C,language:ny(p)})}).catch(()=>{g.signal.aborted||l({status:"error",path:p,message:"Failed to load file preview"})}),()=>g.abort()},[a]);const d=a.status!=="idle";return h.jsxs(h.Fragment,{children:[h.jsx("div",{className:q("flex flex-col gap-2",n),children:o.map((p,g)=>h.jsx(Pa,{content:p,components:f},`${s}-block-${g}`))}),h.jsx(ro,{open:d,onOpenChange:p=>{p||l({status:"idle"})},children:h.jsxs(io,{className:"w-[min(1000px,95vw)] max-h-[88vh] overflow-hidden p-0",children:[h.jsxs("div",{className:"border-b border-primary-200 px-4 py-3 flex items-start justify-between gap-3",children:[h.jsxs("div",{className:"min-w-0",children:[h.jsx(so,{className:"text-base",children:"File Preview"}),a.status!=="idle"&&h.jsx("p",{className:"text-xs text-primary-600 font-mono truncate",children:a.path})]}),h.jsxs("div",{className:"flex items-center gap-2",children:[a.status!=="idle"&&h.jsx(ve,{variant:"ghost",size:"sm",asChild:!0,children:h.jsx(tn,{to:"/files",onClick:()=>{let p=a.status!=="idle"?a.path:"";if(p){const g=["/root/clawd/","/root/"];for(const w of g)if(p.startsWith(w)){p="/"+p.slice(w.length);break}const b=p.includes("/")&&p.slice(0,p.lastIndexOf("/"))||"/";Ql.getState().navigateTo(b)}l({status:"idle"})},children:"Open in File Explorer"})}),h.jsx(oo,{children:"Close"})]})]}),h.jsxs("div",{className:"p-4 overflow-auto max-h-[calc(88vh-72px)]",children:[a.status==="loading"&&h.jsx("p",{className:"text-sm text-primary-600",children:"Loading preview…"}),a.status==="error"&&h.jsx("p",{className:"text-sm text-red-600",children:a.message}),a.status==="success"&&h.jsx(uo,{content:a.content,language:a.language,className:"w-full"})]})]})})]})}const _a=m.memo(uy);_a.displayName="Markdown";function Oa({children:e,className:t,...n}){return h.jsx("div",{className:q("flex gap-3 w-full",t),...n,children:e})}function cy({children:e,markdown:t=!1,className:n,...r}){const i=q("rounded-[12px] break-words whitespace-normal min-w-0",n);return t?h.jsx(_a,{className:i,...r,children:e}):h.jsx("div",{className:i,...r,children:e})}function fy(){const[e,t]=m.useState(()=>typeof window<"u"?window.innerWidth<768:!1);return m.useEffect(()=>{if(typeof window>"u")return;const n=window.matchMedia("(max-width: 767px)"),r=i=>t(i.matches);return n.addEventListener("change",r),t(n.matches),()=>n.removeEventListener("change",r)},[]),e}function hy({content:e}){const t=fy();return h.jsx("div",{className:"inline-flex flex-col",children:h.jsxs(Tn,{defaultOpen:!t,children:[h.jsxs(jn,{render:h.jsx(ve,{variant:"ghost",className:"h-auto gap-1.5 px-1.5 py-0.5 -mx-2"}),children:[h.jsx("span",{className:"text-sm font-medium text-primary-900",children:"Thinking"}),h.jsx(te,{icon:Xr,size:14,strokeWidth:1.5,className:"text-primary-900 transition-transform duration-150 group-data-panel-open:rotate-180"})]}),h.jsx(An,{children:h.jsx("div",{className:"pt-1 mb-3",children:h.jsx("p",{className:"text-sm text-primary-700 whitespace-pre-wrap",children:e})})})]})})}function py({toolPart:e,defaultOpen:t=!1}){const{state:n,input:r,output:i,toolCallId:s}=e,o=(u,c=3200)=>{const f=u===void 0?"undefined":u;let d;if(typeof f=="string")try{d=JSON.stringify(JSON.parse(f),null,2)}catch{d=f}else d=JSON.stringify(f,null,2);return d.length<=c?d:`${d.slice(0,c).trimEnd()}
|
|
92
|
-
…[truncated]`},a=n==="output-error"?$n:n==="output-available"?Qs:no,l=n==="output-error"?"text-red-600/80":n==="output-available"?"text-green-600/80":"text-primary-500/80";return h.jsx("div",{className:"inline-flex flex-col w-full",children:h.jsxs(Tn,{defaultOpen:t,children:[h.jsxs(jn,{render:h.jsx(ve,{variant:"ghost",className:"h-auto w-full justify-start gap-1.5 rounded-md px-1.5 py-1"}),children:[h.jsx(te,{icon:a,size:12,strokeWidth:1.7,className:l}),h.jsx("span",{className:"text-sm font-medium text-primary-900",children:e.type}),h.jsx(te,{icon:Xr,size:14,strokeWidth:1.5,className:"ml-auto text-primary-700/80 transition-transform duration-150 group-data-panel-open:rotate-180"})]}),h.jsx(An,{className:"mt-1",children:h.jsxs("div",{className:"space-y-2 rounded-md border border-primary-200 bg-primary-100/70 p-2",children:[h.jsxs("div",{className:"rounded border border-primary-200 bg-primary-50 px-2 py-1.5",children:[h.jsx("div",{className:"text-[11px] font-medium text-primary-600",children:"Tool"}),h.jsx("div",{className:"font-mono text-xs text-primary-800 break-all",children:e.type})]}),r&&Object.keys(r).length>0&&h.jsxs("div",{className:"rounded border border-primary-200 bg-primary-50 px-2 py-1.5",children:[h.jsx("h4",{className:"mb-1 text-[11px] font-medium text-primary-600",children:"Input"}),h.jsx("pre",{className:"max-h-44 overflow-auto whitespace-pre-wrap break-all font-mono text-xs leading-relaxed text-primary-800",children:o(r)})]}),i!=null&&h.jsxs("div",{className:"rounded border border-primary-200 bg-primary-50 px-2 py-1.5",children:[h.jsx("h4",{className:"mb-1 text-[11px] font-medium text-primary-600",children:"Output"}),h.jsx("pre",{className:"max-h-44 overflow-auto whitespace-pre-wrap break-all font-mono text-xs leading-relaxed text-primary-800",children:o(i)})]}),n==="output-error"&&e.errorText&&h.jsxs("div",{className:"rounded border border-red-200 bg-red-50 px-2 py-1.5",children:[h.jsx("h4",{className:"mb-1 text-[11px] font-medium text-red-600",children:"Error"}),h.jsx("div",{className:"text-xs text-red-700",children:e.errorText})]}),s&&h.jsxs("div",{className:"text-[11px] text-primary-500/80 font-mono tabular-nums",children:["ID: ",s.slice(0,16),"..."]})]})})]})})}function Ms(e){try{return new URL(e).hostname.replace("www.","")}catch{return e}}function Ds({domain:e}){return h.jsx("div",{className:"flex items-center justify-center w-5 h-5 rounded-full bg-white dark:bg-zinc-800 border border-cyan-500/20 overflow-hidden",title:e,children:h.jsx("img",{src:`https://www.google.com/s2/favicons?domain=${e}&sz=32`,alt:"",className:"w-4 h-4 object-contain",loading:"lazy",onError:t=>{const n=t.target;n.style.display="none";const r=n.parentElement;r&&(r.textContent=e.charAt(0).toUpperCase(),r.classList.add("text-[10px]","font-medium","text-cyan-400"))}})})}function dy({sources:e}){const[t,n]=m.useState(!1);if(!e.length)return null;const r=[...new Set(e.map(i=>Ms(i.url)))];return h.jsxs("div",{className:"mt-2 w-full",children:[h.jsxs("button",{onClick:()=>n(!t),className:q("inline-flex items-center gap-1.5 px-3 py-1.5 rounded-full text-xs","bg-cyan-500/10 hover:bg-cyan-500/20 border border-cyan-500/30","text-cyan-300 transition-colors"),children:[h.jsx(te,{icon:eo,size:14}),h.jsx("span",{className:"font-medium",children:"Sources"}),h.jsx("span",{className:"px-1.5 py-0.5 rounded-full bg-cyan-500/20 text-cyan-400 font-semibold",children:e.length}),h.jsxs("div",{className:"flex items-center gap-0.5 ml-1",children:[r.slice(0,3).map(i=>h.jsx(Ds,{domain:i},i)),r.length>3&&h.jsxs("span",{className:"text-cyan-500/70 text-[10px] ml-0.5",children:["+",r.length-3]})]}),h.jsx(te,{icon:Wr,size:12,className:q("transition-transform",t&&"rotate-90")})]}),t&&h.jsx("div",{className:"mt-2 rounded-lg border border-cyan-500/20 bg-cyan-500/5 max-h-80 overflow-y-auto",children:e.map((i,s)=>{const o=Ms(i.url);return h.jsxs("a",{href:i.url,target:"_blank",rel:"noopener noreferrer",className:"flex items-start gap-2 p-2.5 border-b border-cyan-500/10 last:border-b-0 hover:bg-cyan-500/5 transition-colors",children:[h.jsx(Ds,{domain:o}),h.jsxs("div",{className:"flex-1 min-w-0",children:[h.jsx("div",{className:"text-sm font-medium text-primary-900 hover:underline line-clamp-1",children:i.title||o}),h.jsx("div",{className:"text-xs text-muted-foreground",children:o}),i.snippet&&h.jsx("p",{className:"text-xs text-muted-foreground/80 line-clamp-2 mt-0.5",children:i.snippet})]})]},`${i.url}-${s}`)})})]})}function my(e,t){const n=t!==void 0,r=t?.isError??!1;let i;n?r?i="output-error":i="output-available":i="input-available";let s;r&&t?.content?.[0]?.type==="text"&&(s=t.content[0].text||"Unknown error");const o=t?.content?.map(l=>l.type==="text"?String(l.text??""):"").join("").trim(),a=t?.details??(o&&o.length>0?o:void 0);return{type:e.name||"unknown",state:i,input:e.arguments,output:a,toolCallId:e.id,errorText:s}}function zs(e){return Tt(e).map(n=>{const r=n.id??"",i=n.name??"",s=n.partialJson??"",o=n.arguments?JSON.stringify(n.arguments):"";return`${r}|${i}|${s}|${o}`}).join("||")}function gy(e){if(!e)return"missing";const n=(Array.isArray(e.content)?e.content:[]).map(i=>i.type==="text"?String(i.text??""):"").join("").trim(),r=e.details?JSON.stringify(e.details):"";return`${e.toolCallId??""}|${e.toolName??""}|${e.isError?"1":"0"}|${n}|${r}`}function Ps(e,t){if(!t)return"";const n=Tt(e);return n.length===0?"":n.map(r=>r.id?gy(t.get(r.id)):"missing").join("||")}function xy(e){if(typeof e=="number"&&Number.isFinite(e))return e<1e12?e*1e3:e;if(typeof e=="string"){const t=Date.parse(e);if(!Number.isNaN(t))return t}return null}function _s(e){const t=[e.createdAt,e.created_at,e.timestamp,e.time,e.ts];for(const n of t){const r=xy(n);if(r)return r}return null}function Hr(e){const n=(Array.isArray(e.content)?e.content:[]).find(r=>r.type==="thinking");return n&&"thinking"in n?String(n.thinking??""):null}function yy(e){const t=Array.isArray(e.content)?e.content:[],n=[];for(const r of t)r.type==="image"&&"source"in r&&typeof r.source?.data=="string"&&n.push(r);return n}function by({message:e,toolResultsByCallId:t,forceActionsVisible:n=!1,isStreaming:r=!1,isLastAssistant:i=!1,aggregatedSearchSources:s,wrapperRef:o,wrapperClassName:a,wrapperScrollMarginTop:l}){const{settings:u}=lu(),c=e.role||"assistant",f=Je(e),d=Hr(e),p=yy(e),g=c==="user",b=Ar(e),w=c==="assistant"?Tt(e):[],k=w.length>0,C=i&&!r&&u.showSearchSources&&s?s:[];return h.jsxs("div",{ref:o,style:{contentVisibility:"auto",containIntrinsicSize:"auto 120px",...typeof l=="number"?{scrollMarginTop:`${l}px`}:void 0},className:q("group flex flex-col gap-1",a,g?"items-end":"items-start"),children:[d&&u.showReasoningBlocks&&h.jsx("div",{className:"w-full max-w-[900px]",children:h.jsx(hy,{content:d})}),p.length>0&&h.jsx("div",{className:q("flex flex-wrap gap-2 mb-2",g?"justify-end":"justify-start"),children:p.map((E,N)=>h.jsx("img",{src:`data:${E.source.media_type};base64,${E.source.data}`,alt:`Attachment ${N+1}`,loading:"lazy",decoding:"async",className:"max-w-[300px] max-h-[300px] rounded-lg object-cover"},N))}),h.jsx(Oa,{className:q(g?"flex-row-reverse":""),children:h.jsx(cy,{markdown:!g,className:q("text-primary-900 opencami-text-size",g?"bg-primary-100 px-4 py-2.5 max-w-[85%]":"bg-transparent w-full",!g&&r&&"stream-fade-in"),children:f})}),k&&u.showToolMessages&&h.jsx("div",{className:"w-full max-w-[900px] mt-2 flex flex-col gap-3",children:w.map(E=>{const N=E.id?t?.get(E.id):void 0,_=my(E,N);return h.jsx(py,{toolPart:_,defaultOpen:!1},E.id||E.name)})}),C.length>0&&h.jsx("div",{className:"w-full max-w-[900px]",children:h.jsx(dy,{sources:C})}),!k&&h.jsx(rf,{text:f,timestamp:b,align:g?"end":"start",forceVisible:n})]})}function ky(e,t){return!(e.forceActionsVisible!==t.forceActionsVisible||e.isStreaming!==t.isStreaming||e.isLastAssistant!==t.isLastAssistant||e.aggregatedSearchSources!==t.aggregatedSearchSources||e.wrapperClassName!==t.wrapperClassName||e.wrapperRef!==t.wrapperRef||e.wrapperScrollMarginTop!==t.wrapperScrollMarginTop||(e.message.role||"assistant")!==(t.message.role||"assistant")||Je(e.message)!==Je(t.message)||Hr(e.message)!==Hr(t.message)||zs(e.message)!==zs(t.message)||Ps(e.message,e.toolResultsByCallId)!==Ps(t.message,t.toolResultsByCallId)||_s(e.message)!==_s(t.message))}const Cr=m.memo(by,ky),wy=[/```[\s\S]*?```/g,/`[^`]+`/g,/\b(function|const|let|var|class|import|export|return|async|await)\b/g];function Sy(e){const t=[],n=e.match(/"([^"]+)"|'([^']+)'/g);n&&t.push(...n.map(s=>s.replace(/['"]/g,"")));const r=e.match(/\b[A-Z][a-z]+(?:\s+[A-Z][a-z]+)*\b/g);r&&t.push(...r.filter(s=>!["I","The","A","An","This"].includes(s)));const i=e.match(/`([^`]+)`/g);return i&&t.push(...i.map(s=>s.replace(/`/g,""))),[...new Set(t)].slice(0,5)}function Cy(e){return wy.some(t=>t.test(e))}function vy(e){return/^[\s]*[-*•\d]+[.)\s]/m.test(e)||/\b(first|second|third|1\.|2\.|3\.)/i.test(e)}function Ey(e){return/\b(alternatively|another|other option|could also|you might|consider)\b/i.test(e)}function Ty(e){return/\b(because|since|due to|reason|why|how|what|when|where)\b/i.test(e)}function jy(e){return/\b(however|but|note|warning|caution|careful|important|keep in mind|be aware)\b/i.test(e)}function Ay(e){const t=[],n=Sy(e);if(Cy(e)&&(t.push({text:"Can you explain this code step by step?",type:"clarify"}),t.push({text:"How would I modify this for my use case?",type:"actionable"})),vy(e)&&(t.push({text:"Can you elaborate on the first point?",type:"expand"}),t.push({text:"Which of these is most important to start with?",type:"actionable"})),Ey(e)&&(t.push({text:"What are the pros and cons of each approach?",type:"alternative"}),t.push({text:"Which option would you recommend and why?",type:"clarify"})),Ty(e)&&t.length<3&&t.push({text:"Can you give me a practical example?",type:"example"}),jy(e)&&t.length<3&&t.push({text:"What potential issues should I watch out for?",type:"clarify"}),n.length>0&&t.length<3){const s=n[0];t.push({text:`Tell me more about ${s}`,type:"expand"})}const r=[{text:"Can you give me a concrete example?",type:"example"},{text:"What would be the next steps?",type:"actionable"},{text:"How does this work in practice?",type:"expand"},{text:"Are there any common mistakes to avoid?",type:"clarify"},{text:"Can you simplify this explanation?",type:"clarify"}],i=new Set(t.map(s=>s.type));for(const s of r){if(t.length>=3)break;i.has(s.type)||(t.push(s),i.add(s.type))}for(const s of r){if(t.length>=3)break;t.some(o=>o.text===s.text)||t.push(s)}return t.slice(0,3)}function Os(e){return Ay(e).map(t=>t.text)}const Iy={openai:{baseUrl:"https://api.openai.com/v1",model:"gpt-4.1-nano"},openrouter:{baseUrl:"https://openrouter.ai/api/v1",model:"openai/gpt-oss-120b"},ollama:{baseUrl:"http://localhost:11434/v1",model:"llama3.2"},custom:{baseUrl:"",model:""}},Cn={useLlmTitles:!0,useLlmFollowUps:!0,llmProvider:"openai",llmBaseUrl:"",llmModel:"",llmApiKey:""};function Fa(e){return Iy[e]}function Ry(e){return e.llmBaseUrl.trim()?e.llmBaseUrl.trim():Fa(e.llmProvider).baseUrl}function Ny(e){return e.llmModel.trim()?e.llmModel.trim():Fa(e.llmProvider).model}function Fs(e,t){return e.llmProvider==="ollama"?!0:e.llmProvider==="custom"?!!e.llmApiKey.trim()||e.llmBaseUrl.trim()&&e.llmModel.trim():t||!!e.llmApiKey.trim()}function Ly(e){if(!e||typeof e!="object")return{settings:Cn};const{settings:t}=e;if(!t)return{settings:Cn};const{openaiApiKey:n,...r}=t,i=r.llmApiKey??n??"";return{settings:{...Cn,...r,llmApiKey:i}}}const Nt=fo()(co(e=>({settings:{...Cn},updateSettings:t=>e(n=>({settings:{...n.settings,...t}})),clearApiKey:()=>e(t=>({settings:{...t.settings,llmApiKey:""}}))}),{name:"llm-settings",version:2,migrate:e=>Ly(e)}));function Zb(){const e=Nt(o=>o.settings),t=Nt(o=>o.updateSettings),n=Nt(o=>o.clearApiKey),[r,i]=m.useState({hasEnvKey:!1,hasOpenRouterKey:!1,hasUserKey:!!e.llmApiKey,isAvailable:Fs(e,!1),isLoading:!0,error:null});m.useEffect(()=>{let o=!1;async function a(){try{const l=await fetch("/api/llm-features");if(!l.ok)throw new Error("Failed to check LLM status");const u=await l.json();if(o)return;const c=!!e.llmApiKey,f=e.llmProvider==="openrouter"?!!u.hasOpenRouterKey:u.hasEnvKey;i({hasEnvKey:u.hasEnvKey,hasOpenRouterKey:!!u.hasOpenRouterKey,hasUserKey:c,isAvailable:Fs(e,f),isLoading:!1,error:null})}catch(l){if(o)return;i(u=>({...u,isLoading:!1,error:l instanceof Error?l.message:"Failed to check status"}))}}return a(),()=>{o=!0}},[e.llmApiKey,e.llmProvider,e.llmBaseUrl,e.llmModel]);const s=m.useCallback(async o=>{try{const a=$a({...e,llmApiKey:o}),u=await(await fetch("/api/llm-features",{method:"POST",headers:{"Content-Type":"application/json",...a},body:JSON.stringify({action:"test"})})).json();return u.ok?{valid:u.valid??!1,error:u.error}:{valid:!1,error:u.error||"Test failed"}}catch(a){return{valid:!1,error:a instanceof Error?a.message:"Network error"}}},[e]);return{settings:e,updateSettings:t,clearApiKey:n,status:r,testApiKey:s}}function $a(e){const t=e.llmApiKey,n=Ry(e),r=Ny(e);return t?{"X-OpenAI-API-Key":t,...n?{"X-LLM-Base-URL":n}:{},...r?{"X-LLM-Model":r}:{}}:{...n?{"X-LLM-Base-URL":n}:{},...r?{"X-LLM-Model":r}:{}}}function Ba(){const e=Nt.getState().settings;return $a(e)}async function My(e,t){const n={"Content-Type":"application/json",...Ba()},r=await fetch("/api/llm-features",{method:"POST",headers:n,body:JSON.stringify({action:"followups",conversationContext:e}),signal:t});if(!r.ok)throw new Error(`API error: ${r.status}`);const i=await r.json();return i.ok&&Array.isArray(i.suggestions)&&i.suggestions.length>0?i.suggestions:[]}function Dy(e,t,n){const r=Nt(E=>E.settings),i=r.useLlmFollowUps,{minResponseLength:s=50,timeoutMs:o=8e3,heuristicsOnly:a}=n??{},l=a??!i,[u,c]=m.useState([]),[f,d]=m.useState(!1),[p,g]=m.useState(null),[b,w]=m.useState(null),k=m.useRef(""),C=m.useRef(null);return m.useEffect(()=>{if(!e||e.trim().length<s){c([]),w(null),d(!1),g(null);return}const E=e.slice(0,200)+e.length;if(E===k.current)return;if(k.current=E,C.current&&C.current.abort(),l){const M=Os(e);c(M),w("heuristic"),d(!1),g(null);return}const N=new AbortController;C.current=N,d(!0),g(null);const _=Os(e);c(_),w("heuristic");const S=t?`Context: ${t}
|
|
90
|
+
`,inConstruct:"tableCell"},{atBreak:!0,character:"|",after:"[ :-]"},{character:"|",inConstruct:"tableCell"},{atBreak:!0,character:":",after:"-"},{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{inlineCode:d,table:o,tableCell:l,tableRow:a}};function o(p,g,y,w){return u(c(p,y,w),p.align)}function a(p,g,y,w){const k=f(p,y,w),S=u([k]);return S.slice(0,S.indexOf(`
|
|
91
|
+
`))}function l(p,g,y,w){const k=y.enter("tableCell"),S=y.enter("phrasing"),v=y.containerPhrasing(p,{...w,before:s,after:s});return S(),k(),v}function u(p,g){return jg(p,{align:g,alignDelimiters:r,padding:n,stringLength:i})}function c(p,g,y){const w=p.children;let k=-1;const S=[],v=g.enter("table");for(;++k<w.length;)S[k]=f(w[k],g,y);return v(),S}function f(p,g,y){const w=p.children;let k=-1;const S=[],v=g.enter("tableRow");for(;++k<w.length;)S[k]=l(w[k],p,g,y);return v(),S}function d(p,g,y){let w=ja.inlineCode(p,g,y);return y.stack.includes("tableCell")&&(w=w.replace(/\|/g,"\\$&")),w}}function dx(){return{exit:{taskListCheckValueChecked:Ns,taskListCheckValueUnchecked:Ns,paragraph:gx}}}function mx(){return{unsafe:[{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{listItem:xx}}}function Ns(e){const t=this.stack[this.stack.length-2];t.type,t.checked=e.type==="taskListCheckValueChecked"}function gx(e){const t=this.stack[this.stack.length-2];if(t&&t.type==="listItem"&&typeof t.checked=="boolean"){const n=this.stack[this.stack.length-1];n.type;const r=n.children[0];if(r&&r.type==="text"){const i=t.children;let s=-1,o;for(;++s<i.length;){const a=i[s];if(a.type==="paragraph"){o=a;break}}o===n&&(r.value=r.value.slice(1),r.value.length===0?n.children.shift():n.position&&r.position&&typeof r.position.start.offset=="number"&&(r.position.start.column++,r.position.start.offset++,n.position.start=Object.assign({},r.position.start)))}}this.exit(e)}function xx(e,t,n,r){const i=e.children[0],s=typeof e.checked=="boolean"&&i&&i.type==="paragraph",o="["+(e.checked?"x":" ")+"] ",a=n.createTracker(r);s&&a.move(o);let l=ja.listItem(e,t,n,{...r,...a.current()});return s&&(l=l.replace(/^(?:[*+-]|\d+\.)([\r\n]| {1,3})/,u)),l;function u(c){return c+o}}function yx(){return[Gm(),xg(),wg(),ax(),dx()]}function bx(e){return{extensions:[Qm(),yg(e),Sg(),px(e),mx()]}}const kx={tokenize:Tx,partial:!0},Aa={tokenize:jx,partial:!0},Ia={tokenize:Ax,partial:!0},Ra={tokenize:Ix,partial:!0},wx={tokenize:Rx,partial:!0},Na={name:"wwwAutolink",tokenize:vx,previous:Ma},La={name:"protocolAutolink",tokenize:Ex,previous:Da},lt={name:"emailAutolink",tokenize:Cx,previous:za},st={};function Sx(){return{text:st}}let vt=48;for(;vt<123;)st[vt]=lt,vt++,vt===58?vt=65:vt===91&&(vt=97);st[43]=lt;st[45]=lt;st[46]=lt;st[95]=lt;st[72]=[lt,La];st[104]=[lt,La];st[87]=[lt,Na];st[119]=[lt,Na];function Cx(e,t,n){const r=this;let i,s;return o;function o(f){return!Br(f)||!za.call(r,r.previous)||Ci(r.events)?n(f):(e.enter("literalAutolink"),e.enter("literalAutolinkEmail"),a(f))}function a(f){return Br(f)?(e.consume(f),a):f===64?(e.consume(f),l):n(f)}function l(f){return f===46?e.check(wx,c,u)(f):f===45||f===95||Re(f)?(s=!0,e.consume(f),l):c(f)}function u(f){return e.consume(f),i=!0,l}function c(f){return s&&i&&Me(r.previous)?(e.exit("literalAutolinkEmail"),e.exit("literalAutolink"),t(f)):n(f)}}function vx(e,t,n){const r=this;return i;function i(o){return o!==87&&o!==119||!Ma.call(r,r.previous)||Ci(r.events)?n(o):(e.enter("literalAutolink"),e.enter("literalAutolinkWww"),e.check(kx,e.attempt(Aa,e.attempt(Ia,s),n),n)(o))}function s(o){return e.exit("literalAutolinkWww"),e.exit("literalAutolink"),t(o)}}function Ex(e,t,n){const r=this;let i="",s=!1;return o;function o(f){return(f===72||f===104)&&Da.call(r,r.previous)&&!Ci(r.events)?(e.enter("literalAutolink"),e.enter("literalAutolinkHttp"),i+=String.fromCodePoint(f),e.consume(f),a):n(f)}function a(f){if(Me(f)&&i.length<5)return i+=String.fromCodePoint(f),e.consume(f),a;if(f===58){const d=i.toLowerCase();if(d==="http"||d==="https")return e.consume(f),l}return n(f)}function l(f){return f===47?(e.consume(f),s?u:(s=!0,l)):n(f)}function u(f){return f===null||zn(f)||fe(f)||Mt(f)||Vn(f)?n(f):e.attempt(Aa,e.attempt(Ia,c),n)(f)}function c(f){return e.exit("literalAutolinkHttp"),e.exit("literalAutolink"),t(f)}}function Tx(e,t,n){let r=0;return i;function i(o){return(o===87||o===119)&&r<3?(r++,e.consume(o),i):o===46&&r===3?(e.consume(o),s):n(o)}function s(o){return o===null?n(o):t(o)}}function jx(e,t,n){let r,i,s;return o;function o(u){return u===46||u===95?e.check(Ra,l,a)(u):u===null||fe(u)||Mt(u)||u!==45&&Vn(u)?l(u):(s=!0,e.consume(u),o)}function a(u){return u===95?r=!0:(i=r,r=void 0),e.consume(u),o}function l(u){return i||r||!s?n(u):t(u)}}function Ax(e,t){let n=0,r=0;return i;function i(o){return o===40?(n++,e.consume(o),i):o===41&&r<n?s(o):o===33||o===34||o===38||o===39||o===41||o===42||o===44||o===46||o===58||o===59||o===60||o===63||o===93||o===95||o===126?e.check(Ra,t,s)(o):o===null||fe(o)||Mt(o)?t(o):(e.consume(o),i)}function s(o){return o===41&&r++,e.consume(o),i}}function Ix(e,t,n){return r;function r(a){return a===33||a===34||a===39||a===41||a===42||a===44||a===46||a===58||a===59||a===63||a===95||a===126?(e.consume(a),r):a===38?(e.consume(a),s):a===93?(e.consume(a),i):a===60||a===null||fe(a)||Mt(a)?t(a):n(a)}function i(a){return a===null||a===40||a===91||fe(a)||Mt(a)?t(a):r(a)}function s(a){return Me(a)?o(a):n(a)}function o(a){return a===59?(e.consume(a),r):Me(a)?(e.consume(a),o):n(a)}}function Rx(e,t,n){return r;function r(s){return e.consume(s),i}function i(s){return Re(s)?n(s):t(s)}}function Ma(e){return e===null||e===40||e===42||e===95||e===91||e===93||e===126||fe(e)}function Da(e){return!Me(e)}function za(e){return!(e===47||Br(e))}function Br(e){return e===43||e===45||e===46||e===95||Re(e)}function Ci(e){let t=e.length,n=!1;for(;t--;){const r=e[t][1];if((r.type==="labelLink"||r.type==="labelImage")&&!r._balanced){n=!0;break}if(r._gfmAutolinkLiteralWalkedInto){n=!1;break}}return e.length>0&&!n&&(e[e.length-1][1]._gfmAutolinkLiteralWalkedInto=!0),n}const Nx={tokenize:Fx,partial:!0};function Lx(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:Px,continuation:{tokenize:_x},exit:Ox}},text:{91:{name:"gfmFootnoteCall",tokenize:zx},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:Mx,resolveTo:Dx}}}}function Mx(e,t,n){const r=this;let i=r.events.length;const s=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let o;for(;i--;){const l=r.events[i][1];if(l.type==="labelImage"){o=l;break}if(l.type==="gfmFootnoteCall"||l.type==="labelLink"||l.type==="label"||l.type==="image"||l.type==="link")break}return a;function a(l){if(!o||!o._balanced)return n(l);const u=tt(r.sliceSerialize({start:o.end,end:r.now()}));return u.codePointAt(0)!==94||!s.includes(u.slice(1))?n(l):(e.enter("gfmFootnoteCallLabelMarker"),e.consume(l),e.exit("gfmFootnoteCallLabelMarker"),t(l))}}function Dx(e,t){let n=e.length;for(;n--;)if(e[n][1].type==="labelImage"&&e[n][0]==="enter"){e[n][1];break}e[n+1][1].type="data",e[n+3][1].type="gfmFootnoteCallLabelMarker";const r={type:"gfmFootnoteCall",start:Object.assign({},e[n+3][1].start),end:Object.assign({},e[e.length-1][1].end)},i={type:"gfmFootnoteCallMarker",start:Object.assign({},e[n+3][1].end),end:Object.assign({},e[n+3][1].end)};i.end.column++,i.end.offset++,i.end._bufferIndex++;const s={type:"gfmFootnoteCallString",start:Object.assign({},i.end),end:Object.assign({},e[e.length-1][1].start)},o={type:"chunkString",contentType:"string",start:Object.assign({},s.start),end:Object.assign({},s.end)},a=[e[n+1],e[n+2],["enter",r,t],e[n+3],e[n+4],["enter",i,t],["exit",i,t],["enter",s,t],["enter",o,t],["exit",o,t],["exit",s,t],e[e.length-2],e[e.length-1],["exit",r,t]];return e.splice(n,e.length-n+1,...a),e}function zx(e,t,n){const r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let s=0,o;return a;function a(f){return e.enter("gfmFootnoteCall"),e.enter("gfmFootnoteCallLabelMarker"),e.consume(f),e.exit("gfmFootnoteCallLabelMarker"),l}function l(f){return f!==94?n(f):(e.enter("gfmFootnoteCallMarker"),e.consume(f),e.exit("gfmFootnoteCallMarker"),e.enter("gfmFootnoteCallString"),e.enter("chunkString").contentType="string",u)}function u(f){if(s>999||f===93&&!o||f===null||f===91||fe(f))return n(f);if(f===93){e.exit("chunkString");const d=e.exit("gfmFootnoteCallString");return i.includes(tt(r.sliceSerialize(d)))?(e.enter("gfmFootnoteCallLabelMarker"),e.consume(f),e.exit("gfmFootnoteCallLabelMarker"),e.exit("gfmFootnoteCall"),t):n(f)}return fe(f)||(o=!0),s++,e.consume(f),f===92?c:u}function c(f){return f===91||f===92||f===93?(e.consume(f),s++,u):u(f)}}function Px(e,t,n){const r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let s,o=0,a;return l;function l(g){return e.enter("gfmFootnoteDefinition")._container=!0,e.enter("gfmFootnoteDefinitionLabel"),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(g),e.exit("gfmFootnoteDefinitionLabelMarker"),u}function u(g){return g===94?(e.enter("gfmFootnoteDefinitionMarker"),e.consume(g),e.exit("gfmFootnoteDefinitionMarker"),e.enter("gfmFootnoteDefinitionLabelString"),e.enter("chunkString").contentType="string",c):n(g)}function c(g){if(o>999||g===93&&!a||g===null||g===91||fe(g))return n(g);if(g===93){e.exit("chunkString");const y=e.exit("gfmFootnoteDefinitionLabelString");return s=tt(r.sliceSerialize(y)),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(g),e.exit("gfmFootnoteDefinitionLabelMarker"),e.exit("gfmFootnoteDefinitionLabel"),d}return fe(g)||(a=!0),o++,e.consume(g),g===92?f:c}function f(g){return g===91||g===92||g===93?(e.consume(g),o++,c):c(g)}function d(g){return g===58?(e.enter("definitionMarker"),e.consume(g),e.exit("definitionMarker"),i.includes(s)||i.push(s),oe(e,p,"gfmFootnoteDefinitionWhitespace")):n(g)}function p(g){return t(g)}}function _x(e,t,n){return e.check(fn,t,e.attempt(Nx,t,n))}function Ox(e){e.exit("gfmFootnoteDefinition")}function Fx(e,t,n){const r=this;return oe(e,i,"gfmFootnoteDefinitionIndent",5);function i(s){const o=r.events[r.events.length-1];return o&&o[1].type==="gfmFootnoteDefinitionIndent"&&o[2].sliceSerialize(o[1],!0).length===4?t(s):n(s)}}function $x(e){let n=(e||{}).singleTilde;const r={name:"strikethrough",tokenize:s,resolveAll:i};return n==null&&(n=!0),{text:{126:r},insideSpan:{null:[r]},attentionMarkers:{null:[126]}};function i(o,a){let l=-1;for(;++l<o.length;)if(o[l][0]==="enter"&&o[l][1].type==="strikethroughSequenceTemporary"&&o[l][1]._close){let u=l;for(;u--;)if(o[u][0]==="exit"&&o[u][1].type==="strikethroughSequenceTemporary"&&o[u][1]._open&&o[l][1].end.offset-o[l][1].start.offset===o[u][1].end.offset-o[u][1].start.offset){o[l][1].type="strikethroughSequence",o[u][1].type="strikethroughSequence";const c={type:"strikethrough",start:Object.assign({},o[u][1].start),end:Object.assign({},o[l][1].end)},f={type:"strikethroughText",start:Object.assign({},o[u][1].end),end:Object.assign({},o[l][1].start)},d=[["enter",c,a],["enter",o[u][1],a],["exit",o[u][1],a],["enter",f,a]],p=a.parser.constructs.insideSpan.null;p&&Ue(d,d.length,0,Xn(p,o.slice(u+1,l),a)),Ue(d,d.length,0,[["exit",f,a],["enter",o[l][1],a],["exit",o[l][1],a],["exit",c,a]]),Ue(o,u-1,l-u+3,d),l=u+d.length-2;break}}for(l=-1;++l<o.length;)o[l][1].type==="strikethroughSequenceTemporary"&&(o[l][1].type="data");return o}function s(o,a,l){const u=this.previous,c=this.events;let f=0;return d;function d(g){return u===126&&c[c.length-1][1].type!=="characterEscape"?l(g):(o.enter("strikethroughSequenceTemporary"),p(g))}function p(g){const y=Ut(u);if(g===126)return f>1?l(g):(o.consume(g),f++,p);if(f<2&&!n)return l(g);const w=o.exit("strikethroughSequenceTemporary"),k=Ut(g);return w._open=!k||k===2&&!!y,w._close=!y||y===2&&!!k,a(g)}}}class Bx{constructor(){this.map=[]}add(t,n,r){Hx(this,t,n,r)}consume(t){if(this.map.sort(function(s,o){return s[0]-o[0]}),this.map.length===0)return;let n=this.map.length;const r=[];for(;n>0;)n-=1,r.push(t.slice(this.map[n][0]+this.map[n][1]),this.map[n][2]),t.length=this.map[n][0];r.push(t.slice()),t.length=0;let i=r.pop();for(;i;){for(const s of i)t.push(s);i=r.pop()}this.map.length=0}}function Hx(e,t,n,r){let i=0;if(!(n===0&&r.length===0)){for(;i<e.map.length;){if(e.map[i][0]===t){e.map[i][1]+=n,e.map[i][2].push(...r);return}i+=1}e.map.push([t,n,r])}}function Ux(e,t){let n=!1;const r=[];for(;t<e.length;){const i=e[t];if(n){if(i[0]==="enter")i[1].type==="tableContent"&&r.push(e[t+1][1].type==="tableDelimiterMarker"?"left":"none");else if(i[1].type==="tableContent"){if(e[t-1][1].type==="tableDelimiterMarker"){const s=r.length-1;r[s]=r[s]==="left"?"center":"right"}}else if(i[1].type==="tableDelimiterRow")break}else i[0]==="enter"&&i[1].type==="tableDelimiterRow"&&(n=!0);t+=1}return r}function qx(){return{flow:{null:{name:"table",tokenize:Kx,resolveAll:Wx}}}}function Kx(e,t,n){const r=this;let i=0,s=0,o;return a;function a(E){let N=r.events.length-1;for(;N>-1;){const j=r.events[N][1].type;if(j==="lineEnding"||j==="linePrefix")N--;else break}const A=N>-1?r.events[N][1].type:null,P=A==="tableHead"||A==="tableRow"?C:l;return P===C&&r.parser.lazy[r.now().line]?n(E):P(E)}function l(E){return e.enter("tableHead"),e.enter("tableRow"),u(E)}function u(E){return E===124||(o=!0,s+=1),c(E)}function c(E){return E===null?n(E):G(E)?s>1?(s=0,r.interrupt=!0,e.exit("tableRow"),e.enter("lineEnding"),e.consume(E),e.exit("lineEnding"),p):n(E):ie(E)?oe(e,c,"whitespace")(E):(s+=1,o&&(o=!1,i+=1),E===124?(e.enter("tableCellDivider"),e.consume(E),e.exit("tableCellDivider"),o=!0,c):(e.enter("data"),f(E)))}function f(E){return E===null||E===124||fe(E)?(e.exit("data"),c(E)):(e.consume(E),E===92?d:f)}function d(E){return E===92||E===124?(e.consume(E),f):f(E)}function p(E){return r.interrupt=!1,r.parser.lazy[r.now().line]?n(E):(e.enter("tableDelimiterRow"),o=!1,ie(E)?oe(e,g,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(E):g(E))}function g(E){return E===45||E===58?w(E):E===124?(o=!0,e.enter("tableCellDivider"),e.consume(E),e.exit("tableCellDivider"),y):M(E)}function y(E){return ie(E)?oe(e,w,"whitespace")(E):w(E)}function w(E){return E===58?(s+=1,o=!0,e.enter("tableDelimiterMarker"),e.consume(E),e.exit("tableDelimiterMarker"),k):E===45?(s+=1,k(E)):E===null||G(E)?R(E):M(E)}function k(E){return E===45?(e.enter("tableDelimiterFiller"),S(E)):M(E)}function S(E){return E===45?(e.consume(E),S):E===58?(o=!0,e.exit("tableDelimiterFiller"),e.enter("tableDelimiterMarker"),e.consume(E),e.exit("tableDelimiterMarker"),v):(e.exit("tableDelimiterFiller"),v(E))}function v(E){return ie(E)?oe(e,R,"whitespace")(E):R(E)}function R(E){return E===124?g(E):E===null||G(E)?!o||i!==s?M(E):(e.exit("tableDelimiterRow"),e.exit("tableHead"),t(E)):M(E)}function M(E){return n(E)}function C(E){return e.enter("tableRow"),z(E)}function z(E){return E===124?(e.enter("tableCellDivider"),e.consume(E),e.exit("tableCellDivider"),z):E===null||G(E)?(e.exit("tableRow"),t(E)):ie(E)?oe(e,z,"whitespace")(E):(e.enter("data"),U(E))}function U(E){return E===null||E===124||fe(E)?(e.exit("data"),z(E)):(e.consume(E),E===92?F:U)}function F(E){return E===92||E===124?(e.consume(E),U):U(E)}}function Wx(e,t){let n=-1,r=!0,i=0,s=[0,0,0,0],o=[0,0,0,0],a=!1,l=0,u,c,f;const d=new Bx;for(;++n<e.length;){const p=e[n],g=p[1];p[0]==="enter"?g.type==="tableHead"?(a=!1,l!==0&&(Ls(d,t,l,u,c),c=void 0,l=0),u={type:"table",start:Object.assign({},g.start),end:Object.assign({},g.end)},d.add(n,0,[["enter",u,t]])):g.type==="tableRow"||g.type==="tableDelimiterRow"?(r=!0,f=void 0,s=[0,0,0,0],o=[0,n+1,0,0],a&&(a=!1,c={type:"tableBody",start:Object.assign({},g.start),end:Object.assign({},g.end)},d.add(n,0,[["enter",c,t]])),i=g.type==="tableDelimiterRow"?2:c?3:1):i&&(g.type==="data"||g.type==="tableDelimiterMarker"||g.type==="tableDelimiterFiller")?(r=!1,o[2]===0&&(s[1]!==0&&(o[0]=o[1],f=bn(d,t,s,i,void 0,f),s=[0,0,0,0]),o[2]=n)):g.type==="tableCellDivider"&&(r?r=!1:(s[1]!==0&&(o[0]=o[1],f=bn(d,t,s,i,void 0,f)),s=o,o=[s[1],n,0,0])):g.type==="tableHead"?(a=!0,l=n):g.type==="tableRow"||g.type==="tableDelimiterRow"?(l=n,s[1]!==0?(o[0]=o[1],f=bn(d,t,s,i,n,f)):o[1]!==0&&(f=bn(d,t,o,i,n,f)),i=0):i&&(g.type==="data"||g.type==="tableDelimiterMarker"||g.type==="tableDelimiterFiller")&&(o[3]=n)}for(l!==0&&Ls(d,t,l,u,c),d.consume(t.events),n=-1;++n<t.events.length;){const p=t.events[n];p[0]==="enter"&&p[1].type==="table"&&(p[1]._align=Ux(t.events,n))}return e}function bn(e,t,n,r,i,s){const o=r===1?"tableHeader":r===2?"tableDelimiter":"tableData",a="tableContent";n[0]!==0&&(s.end=Object.assign({},Bt(t.events,n[0])),e.add(n[0],0,[["exit",s,t]]));const l=Bt(t.events,n[1]);if(s={type:o,start:Object.assign({},l),end:Object.assign({},l)},e.add(n[1],0,[["enter",s,t]]),n[2]!==0){const u=Bt(t.events,n[2]),c=Bt(t.events,n[3]),f={type:a,start:Object.assign({},u),end:Object.assign({},c)};if(e.add(n[2],0,[["enter",f,t]]),r!==2){const d=t.events[n[2]],p=t.events[n[3]];if(d[1].end=Object.assign({},p[1].end),d[1].type="chunkText",d[1].contentType="text",n[3]>n[2]+1){const g=n[2]+1,y=n[3]-n[2]-1;e.add(g,y,[])}}e.add(n[3]+1,0,[["exit",f,t]])}return i!==void 0&&(s.end=Object.assign({},Bt(t.events,i)),e.add(i,0,[["exit",s,t]]),s=void 0),s}function Ls(e,t,n,r,i){const s=[],o=Bt(t.events,n);i&&(i.end=Object.assign({},o),s.push(["exit",i,t])),r.end=Object.assign({},o),s.push(["exit",r,t]),e.add(n+1,0,s)}function Bt(e,t){const n=e[t],r=n[0]==="enter"?"start":"end";return n[1][r]}const Vx={name:"tasklistCheck",tokenize:Yx};function Xx(){return{text:{91:Vx}}}function Yx(e,t,n){const r=this;return i;function i(l){return r.previous!==null||!r._gfmTasklistFirstContentOfListItem?n(l):(e.enter("taskListCheck"),e.enter("taskListCheckMarker"),e.consume(l),e.exit("taskListCheckMarker"),s)}function s(l){return fe(l)?(e.enter("taskListCheckValueUnchecked"),e.consume(l),e.exit("taskListCheckValueUnchecked"),o):l===88||l===120?(e.enter("taskListCheckValueChecked"),e.consume(l),e.exit("taskListCheckValueChecked"),o):n(l)}function o(l){return l===93?(e.enter("taskListCheckMarker"),e.consume(l),e.exit("taskListCheckMarker"),e.exit("taskListCheck"),a):n(l)}function a(l){return G(l)?t(l):ie(l)?e.check({tokenize:Gx},t,n)(l):n(l)}}function Gx(e,t,n){return oe(e,r,"whitespace");function r(i){return i===null?n(i):t(i)}}function Qx(e){return Ko([Sx(),Lx(),$x(e),qx(),Xx()])}const Jx={};function Zx(e){const t=this,n=e||Jx,r=t.data(),i=r.micromarkExtensions||(r.micromarkExtensions=[]),s=r.fromMarkdownExtensions||(r.fromMarkdownExtensions=[]),o=r.toMarkdownExtensions||(r.toMarkdownExtensions=[]);i.push(Qx(n)),s.push(yx()),o.push(bx(n))}function ey(e){if(!e?.startsWith("openclaw-file://"))return null;try{return decodeURIComponent(e.slice(16))}catch{return null}}const ty={py:"python",ts:"typescript",js:"javascript",jsx:"jsx",tsx:"tsx",json:"json",md:"markdown",yml:"yaml",yaml:"yaml",sh:"bash",bash:"bash",zsh:"bash",html:"html",css:"css",sql:"sql",xml:"xml",toml:"toml",rs:"rust",go:"go",java:"java",c:"c",cpp:"cpp",cs:"csharp",php:"php",rb:"ruby",graphql:"graphql",diff:"diff",patch:"diff",env:"text"};function ny(e){if(!e)return"text";const n=(e.split("/").pop()||"").toLowerCase();if(n==="dockerfile")return"dockerfile";if(n==="makefile")return"text";const r=n.split("."),i=r.length>1&&r.pop()||"",s=ty[i]||i||"text";return ou(s)}const ry=100*1024;function iy(e){return ce.lexer(e).map(n=>n.raw)}function sy(e){if(!e)return"text";const t=e.match(/language-(\w+)/);return t?t[1]:"text"}const oy={code:function({className:t,children:n}){if(!t?.includes("language-"))return h.jsx("code",{className:"rounded bg-primary-100 px-1.5 py-1 text-sm font-mono text-primary-900 border border-primary-200",children:n});const i=sy(t);return h.jsx(uo,{content:String(n??""),language:i,className:"w-full"})},pre:function({children:t}){return h.jsx(h.Fragment,{children:t})},h1:function({children:t}){return h.jsx("h1",{className:"text-xl font-medium text-primary-950",children:t})},h2:function({children:t}){return h.jsx("h2",{className:"text-lg font-medium text-primary-900",children:t})},h3:function({children:t}){return h.jsx("h3",{className:"font-medium text-primary-900",children:t})},p:function({children:t}){return h.jsx("p",{className:"text-primary-950 text-pretty leading-relaxed",children:t})},ul:function({children:t}){return h.jsx("ul",{className:"ml-4 list-disc text-primary-950 marker:text-primary-400",children:t})},ol:function({children:t}){return h.jsx("ol",{className:"ml-4 list-decimal text-primary-950 marker:text-primary-500",children:t})},li:function({children:t}){return h.jsx("li",{className:"leading-relaxed",children:t})},blockquote:function({children:t}){return h.jsx("blockquote",{className:"border-l-2 border-primary-300 pl-4 text-primary-900 italic",children:t})},strong:function({children:t}){return h.jsx("strong",{className:"font-medium text-primary-950",children:t})},em:function({children:t}){return h.jsx("em",{className:"italic text-primary-950",children:t})},hr:function(){return h.jsx("hr",{className:"my-3 border-primary-200"})},table:function({children:t}){return h.jsx("div",{className:"overflow-x-auto",children:h.jsx("table",{className:"w-full border-collapse text-sm",children:t})})},thead:function({children:t}){return h.jsx("thead",{className:"border-b border-primary-200 bg-primary-50",children:t})},tbody:function({children:t}){return h.jsx("tbody",{className:"divide-y divide-primary-100",children:t})},tr:function({children:t}){return h.jsx("tr",{className:"transition-colors hover:bg-primary-50/50",children:t})},th:function({children:t}){return h.jsx("th",{className:"px-3 py-2 text-left font-medium text-primary-950",children:t})},td:function({children:t}){return h.jsx("td",{className:"px-3 py-2 text-primary-950",children:t})}};function ay(e,t){const n=/^(?:~\/[\w.\-\/]+|\/(?:[\w.\-]+\/)+[\w.\-]+)$/;return{...oy,a:function({children:i,href:s}){const o=ey(s);return t&&o?h.jsx("button",{type:"button",onClick:()=>e(o),className:"font-mono text-primary-900 underline decoration-primary-300 underline-offset-4 hover:decoration-primary-600 cursor-pointer",children:i}):h.jsx("a",{href:s,className:"text-primary-950 underline decoration-primary-300 underline-offset-4 transition-colors hover:text-primary-950 hover:decoration-primary-500",target:"_blank",rel:"noopener noreferrer",children:i})},code:function({children:i,className:s}){if(s)return h.jsx("code",{className:s,children:i});const o=typeof i=="string"?i:Array.isArray(i)?i.filter(a=>typeof a=="string").join(""):String(i??"");return t&&o&&n.test(o)?h.jsx("button",{type:"button",onClick:()=>e(o),className:"font-mono text-sm bg-primary-100 rounded px-1.5 py-0.5 text-primary-900 underline decoration-primary-300 underline-offset-4 hover:decoration-primary-600 cursor-pointer",children:i}):h.jsx("code",{className:"font-mono text-sm bg-primary-100 rounded px-1.5 py-0.5 text-primary-900",children:i})}}}const Pa=m.memo(function({content:t,components:n}){return h.jsx(Om,{remarkPlugins:[Zx,Ym],components:n,children:t})},function(t,n){return t.content===n.content});Pa.displayName="MemoizedMarkdownBlock";function ly(e,t){return t==="NOT_FOUND"||e===404?"File not found":t==="UNSUPPORTED_TYPE"?"Binary file":t==="FILE_TOO_LARGE"||e===413?"File too large":"Failed to load file preview"}function uy({children:e,id:t,className:n,components:r}){const i=m.useId(),s=t??i,o=m.useMemo(()=>iy(e),[e]),[a,l]=m.useState({status:"idle"}),u=au(p=>p.settings.inlineFilePreview),c=m.useMemo(()=>ay(p=>l({status:"loading",path:p}),u),[u]),f=m.useMemo(()=>({...c,...r||{}}),[c,r]);m.useEffect(()=>{if(a.status!=="loading")return;const p=a.path,g=new AbortController;return fetch(`/api/files/read?path=${encodeURIComponent(p)}`,{signal:g.signal}).then(async y=>{const w=await y.json().catch(()=>({}));if(!y.ok){const v=ly(y.status,w.code);l({status:"error",path:p,message:v});return}if(Number(w.size??0)>ry){l({status:"error",path:p,message:"File too large"});return}const S=String(w.content??"");l({status:"success",path:p,content:S,language:ny(p)})}).catch(()=>{g.signal.aborted||l({status:"error",path:p,message:"Failed to load file preview"})}),()=>g.abort()},[a]);const d=a.status!=="idle";return h.jsxs(h.Fragment,{children:[h.jsx("div",{className:q("flex flex-col gap-2",n),children:o.map((p,g)=>h.jsx(Pa,{content:p,components:f},`${s}-block-${g}`))}),h.jsx(ro,{open:d,onOpenChange:p=>{p||l({status:"idle"})},children:h.jsxs(io,{className:"w-[min(1000px,95vw)] max-h-[88vh] overflow-hidden p-0",children:[h.jsxs("div",{className:"border-b border-primary-200 px-4 py-3 flex items-start justify-between gap-3",children:[h.jsxs("div",{className:"min-w-0",children:[h.jsx(so,{className:"text-base",children:"File Preview"}),a.status!=="idle"&&h.jsx("p",{className:"text-xs text-primary-600 font-mono truncate",children:a.path})]}),h.jsxs("div",{className:"flex items-center gap-2",children:[a.status!=="idle"&&h.jsx(ve,{variant:"ghost",size:"sm",asChild:!0,children:h.jsx(tn,{to:"/files",onClick:()=>{let p=a.status!=="idle"?a.path:"";if(p){const g=["/root/clawd/","/root/"];for(const w of g)if(p.startsWith(w)){p="/"+p.slice(w.length);break}const y=p.includes("/")&&p.slice(0,p.lastIndexOf("/"))||"/";Ql.getState().navigateTo(y)}l({status:"idle"})},children:"Open in File Explorer"})}),h.jsx(oo,{children:"Close"})]})]}),h.jsxs("div",{className:"p-4 overflow-auto max-h-[calc(88vh-72px)]",children:[a.status==="loading"&&h.jsx("p",{className:"text-sm text-primary-600",children:"Loading preview…"}),a.status==="error"&&h.jsx("p",{className:"text-sm text-red-600",children:a.message}),a.status==="success"&&h.jsx(uo,{content:a.content,language:a.language,className:"w-full"})]})]})})]})}const _a=m.memo(uy);_a.displayName="Markdown";function Oa({children:e,className:t,...n}){return h.jsx("div",{className:q("flex gap-3 w-full",t),...n,children:e})}function cy({children:e,markdown:t=!1,className:n,...r}){const i=q("rounded-[12px] break-words whitespace-normal min-w-0",n);return t?h.jsx(_a,{className:i,...r,children:e}):h.jsx("div",{className:i,...r,children:e})}function fy(){const[e,t]=m.useState(()=>typeof window<"u"?window.innerWidth<768:!1);return m.useEffect(()=>{if(typeof window>"u")return;const n=window.matchMedia("(max-width: 767px)"),r=i=>t(i.matches);return n.addEventListener("change",r),t(n.matches),()=>n.removeEventListener("change",r)},[]),e}function hy({content:e}){const t=fy();return h.jsx("div",{className:"inline-flex flex-col",children:h.jsxs(Tn,{defaultOpen:!t,children:[h.jsxs(jn,{render:h.jsx(ve,{variant:"ghost",className:"h-auto gap-1.5 px-1.5 py-0.5 -mx-2"}),children:[h.jsx("span",{className:"text-sm font-medium text-primary-900",children:"Thinking"}),h.jsx(te,{icon:Xr,size:14,strokeWidth:1.5,className:"text-primary-900 transition-transform duration-150 group-data-panel-open:rotate-180"})]}),h.jsx(An,{children:h.jsx("div",{className:"pt-1 mb-3",children:h.jsx("p",{className:"text-sm text-primary-700 whitespace-pre-wrap",children:e})})})]})})}function py({toolPart:e,defaultOpen:t=!1}){const{state:n,input:r,output:i,toolCallId:s}=e,o=(u,c=3200)=>{const f=u===void 0?"undefined":u;let d;if(typeof f=="string")try{d=JSON.stringify(JSON.parse(f),null,2)}catch{d=f}else d=JSON.stringify(f,null,2);return d.length<=c?d:`${d.slice(0,c).trimEnd()}
|
|
92
|
+
…[truncated]`},a=n==="output-error"?$n:n==="output-available"?Qs:no,l=n==="output-error"?"text-red-600/80":n==="output-available"?"text-green-600/80":"text-primary-500/80";return h.jsx("div",{className:"inline-flex flex-col w-full",children:h.jsxs(Tn,{defaultOpen:t,children:[h.jsxs(jn,{render:h.jsx(ve,{variant:"ghost",className:"h-auto w-full justify-start gap-1.5 rounded-md px-1.5 py-1"}),children:[h.jsx(te,{icon:a,size:12,strokeWidth:1.7,className:l}),h.jsx("span",{className:"text-sm font-medium text-primary-900",children:e.type}),h.jsx(te,{icon:Xr,size:14,strokeWidth:1.5,className:"ml-auto text-primary-700/80 transition-transform duration-150 group-data-panel-open:rotate-180"})]}),h.jsx(An,{className:"mt-1",children:h.jsxs("div",{className:"space-y-2 rounded-md border border-primary-200 bg-primary-100/70 p-2",children:[h.jsxs("div",{className:"rounded border border-primary-200 bg-primary-50 px-2 py-1.5",children:[h.jsx("div",{className:"text-[11px] font-medium text-primary-600",children:"Tool"}),h.jsx("div",{className:"font-mono text-xs text-primary-800 break-all",children:e.type})]}),r&&Object.keys(r).length>0&&h.jsxs("div",{className:"rounded border border-primary-200 bg-primary-50 px-2 py-1.5",children:[h.jsx("h4",{className:"mb-1 text-[11px] font-medium text-primary-600",children:"Input"}),h.jsx("pre",{className:"max-h-44 overflow-auto whitespace-pre-wrap break-all font-mono text-xs leading-relaxed text-primary-800",children:o(r)})]}),i!=null&&h.jsxs("div",{className:"rounded border border-primary-200 bg-primary-50 px-2 py-1.5",children:[h.jsx("h4",{className:"mb-1 text-[11px] font-medium text-primary-600",children:"Output"}),h.jsx("pre",{className:"max-h-44 overflow-auto whitespace-pre-wrap break-all font-mono text-xs leading-relaxed text-primary-800",children:o(i)})]}),n==="output-error"&&e.errorText&&h.jsxs("div",{className:"rounded border border-red-200 bg-red-50 px-2 py-1.5",children:[h.jsx("h4",{className:"mb-1 text-[11px] font-medium text-red-600",children:"Error"}),h.jsx("div",{className:"text-xs text-red-700",children:e.errorText})]}),s&&h.jsxs("div",{className:"text-[11px] text-primary-500/80 font-mono tabular-nums",children:["ID: ",s.slice(0,16),"..."]})]})})]})})}function Ms(e){try{return new URL(e).hostname.replace("www.","")}catch{return e}}function Ds({domain:e}){return h.jsx("div",{className:"flex items-center justify-center w-5 h-5 rounded-full bg-white dark:bg-zinc-800 border border-cyan-500/20 overflow-hidden",title:e,children:h.jsx("img",{src:`https://www.google.com/s2/favicons?domain=${e}&sz=32`,alt:"",className:"w-4 h-4 object-contain",loading:"lazy",onError:t=>{const n=t.target;n.style.display="none";const r=n.parentElement;r&&(r.textContent=e.charAt(0).toUpperCase(),r.classList.add("text-[10px]","font-medium","text-cyan-400"))}})})}function dy({sources:e}){const[t,n]=m.useState(!1);if(!e.length)return null;const r=[...new Set(e.map(i=>Ms(i.url)))];return h.jsxs("div",{className:"mt-2 w-full",children:[h.jsxs("button",{onClick:()=>n(!t),className:q("inline-flex items-center gap-1.5 px-3 py-1.5 rounded-full text-xs","bg-cyan-500/10 hover:bg-cyan-500/20 border border-cyan-500/30","text-cyan-300 transition-colors"),children:[h.jsx(te,{icon:eo,size:14}),h.jsx("span",{className:"font-medium",children:"Sources"}),h.jsx("span",{className:"px-1.5 py-0.5 rounded-full bg-cyan-500/20 text-cyan-400 font-semibold",children:e.length}),h.jsxs("div",{className:"flex items-center gap-0.5 ml-1",children:[r.slice(0,3).map(i=>h.jsx(Ds,{domain:i},i)),r.length>3&&h.jsxs("span",{className:"text-cyan-500/70 text-[10px] ml-0.5",children:["+",r.length-3]})]}),h.jsx(te,{icon:Wr,size:12,className:q("transition-transform",t&&"rotate-90")})]}),t&&h.jsx("div",{className:"mt-2 rounded-lg border border-cyan-500/20 bg-cyan-500/5 max-h-80 overflow-y-auto",children:e.map((i,s)=>{const o=Ms(i.url);return h.jsxs("a",{href:i.url,target:"_blank",rel:"noopener noreferrer",className:"flex items-start gap-2 p-2.5 border-b border-cyan-500/10 last:border-b-0 hover:bg-cyan-500/5 transition-colors",children:[h.jsx(Ds,{domain:o}),h.jsxs("div",{className:"flex-1 min-w-0",children:[h.jsx("div",{className:"text-sm font-medium text-primary-900 hover:underline line-clamp-1",children:i.title||o}),h.jsx("div",{className:"text-xs text-muted-foreground",children:o}),i.snippet&&h.jsx("p",{className:"text-xs text-muted-foreground/80 line-clamp-2 mt-0.5",children:i.snippet})]})]},`${i.url}-${s}`)})})]})}function my(e,t){const n=t!==void 0,r=t?.isError??!1;let i;n?r?i="output-error":i="output-available":i="input-available";let s;r&&t?.content?.[0]?.type==="text"&&(s=t.content[0].text||"Unknown error");const o=t?.content?.map(l=>l.type==="text"?String(l.text??""):"").join("").trim(),a=t?.details??(o&&o.length>0?o:void 0);return{type:e.name||"unknown",state:i,input:e.arguments,output:a,toolCallId:e.id,errorText:s}}function zs(e){return Tt(e).map(n=>{const r=n.id??"",i=n.name??"",s=n.partialJson??"",o=n.arguments?JSON.stringify(n.arguments):"";return`${r}|${i}|${s}|${o}`}).join("||")}function gy(e){if(!e)return"missing";const n=(Array.isArray(e.content)?e.content:[]).map(i=>i.type==="text"?String(i.text??""):"").join("").trim(),r=e.details?JSON.stringify(e.details):"";return`${e.toolCallId??""}|${e.toolName??""}|${e.isError?"1":"0"}|${n}|${r}`}function Ps(e,t){if(!t)return"";const n=Tt(e);return n.length===0?"":n.map(r=>r.id?gy(t.get(r.id)):"missing").join("||")}function xy(e){if(typeof e=="number"&&Number.isFinite(e))return e<1e12?e*1e3:e;if(typeof e=="string"){const t=Date.parse(e);if(!Number.isNaN(t))return t}return null}function _s(e){const t=[e.createdAt,e.created_at,e.timestamp,e.time,e.ts];for(const n of t){const r=xy(n);if(r)return r}return null}function Hr(e){const n=(Array.isArray(e.content)?e.content:[]).find(r=>r.type==="thinking");return n&&"thinking"in n?String(n.thinking??""):null}function yy(e){const t=Array.isArray(e.content)?e.content:[],n=[];for(const r of t)r.type==="image"&&"source"in r&&typeof r.source?.data=="string"&&n.push(r);return n}function by({message:e,toolResultsByCallId:t,forceActionsVisible:n=!1,isStreaming:r=!1,isLastAssistant:i=!1,aggregatedSearchSources:s,wrapperRef:o,wrapperClassName:a,wrapperScrollMarginTop:l}){const{settings:u}=lu(),c=e.role||"assistant",f=et(e),d=Hr(e),p=yy(e),g=c==="user",y=Ar(e),w=c==="assistant"?Tt(e):[],k=w.length>0,S=i&&!r&&u.showSearchSources&&s?s:[];return h.jsxs("div",{ref:o,style:{contentVisibility:"auto",containIntrinsicSize:"auto 120px",...typeof l=="number"?{scrollMarginTop:`${l}px`}:void 0},className:q("group flex flex-col gap-1",a,g?"items-end":"items-start"),children:[d&&u.showReasoningBlocks&&h.jsx("div",{className:"w-full max-w-[900px]",children:h.jsx(hy,{content:d})}),p.length>0&&h.jsx("div",{className:q("flex flex-wrap gap-2 mb-2",g?"justify-end":"justify-start"),children:p.map((v,R)=>h.jsx("img",{src:`data:${v.source.media_type};base64,${v.source.data}`,alt:`Attachment ${R+1}`,loading:"lazy",decoding:"async",className:"max-w-[300px] max-h-[300px] rounded-lg object-cover"},R))}),h.jsx(Oa,{className:q(g?"flex-row-reverse":""),children:h.jsx(cy,{markdown:!g,className:q("text-primary-900 opencami-text-size",g?"bg-primary-100 px-4 py-2.5 max-w-[85%]":"bg-transparent w-full",!g&&r&&"stream-fade-in"),children:f})}),k&&u.showToolMessages&&h.jsx("div",{className:"w-full max-w-[900px] mt-2 flex flex-col gap-3",children:w.map(v=>{const R=v.id?t?.get(v.id):void 0,M=my(v,R);return h.jsx(py,{toolPart:M,defaultOpen:!1},v.id||v.name)})}),S.length>0&&h.jsx("div",{className:"w-full max-w-[900px]",children:h.jsx(dy,{sources:S})}),!k&&h.jsx(rf,{text:f,timestamp:y,align:g?"end":"start",forceVisible:n})]})}function ky(e,t){return!(e.forceActionsVisible!==t.forceActionsVisible||e.isStreaming!==t.isStreaming||e.isLastAssistant!==t.isLastAssistant||e.aggregatedSearchSources!==t.aggregatedSearchSources||e.wrapperClassName!==t.wrapperClassName||e.wrapperRef!==t.wrapperRef||e.wrapperScrollMarginTop!==t.wrapperScrollMarginTop||(e.message.role||"assistant")!==(t.message.role||"assistant")||et(e.message)!==et(t.message)||Hr(e.message)!==Hr(t.message)||zs(e.message)!==zs(t.message)||Ps(e.message,e.toolResultsByCallId)!==Ps(t.message,t.toolResultsByCallId)||_s(e.message)!==_s(t.message))}const Cr=m.memo(by,ky),wy=[/```[\s\S]*?```/g,/`[^`]+`/g,/\b(function|const|let|var|class|import|export|return|async|await)\b/g];function Sy(e){const t=[],n=e.match(/"([^"]+)"|'([^']+)'/g);n&&t.push(...n.map(s=>s.replace(/['"]/g,"")));const r=e.match(/\b[A-Z][a-z]+(?:\s+[A-Z][a-z]+)*\b/g);r&&t.push(...r.filter(s=>!["I","The","A","An","This"].includes(s)));const i=e.match(/`([^`]+)`/g);return i&&t.push(...i.map(s=>s.replace(/`/g,""))),[...new Set(t)].slice(0,5)}function Cy(e){return wy.some(t=>t.test(e))}function vy(e){return/^[\s]*[-*•\d]+[.)\s]/m.test(e)||/\b(first|second|third|1\.|2\.|3\.)/i.test(e)}function Ey(e){return/\b(alternatively|another|other option|could also|you might|consider)\b/i.test(e)}function Ty(e){return/\b(because|since|due to|reason|why|how|what|when|where)\b/i.test(e)}function jy(e){return/\b(however|but|note|warning|caution|careful|important|keep in mind|be aware)\b/i.test(e)}function Ay(e){const t=[],n=Sy(e);if(Cy(e)&&(t.push({text:"Can you explain this code step by step?",type:"clarify"}),t.push({text:"How would I modify this for my use case?",type:"actionable"})),vy(e)&&(t.push({text:"Can you elaborate on the first point?",type:"expand"}),t.push({text:"Which of these is most important to start with?",type:"actionable"})),Ey(e)&&(t.push({text:"What are the pros and cons of each approach?",type:"alternative"}),t.push({text:"Which option would you recommend and why?",type:"clarify"})),Ty(e)&&t.length<3&&t.push({text:"Can you give me a practical example?",type:"example"}),jy(e)&&t.length<3&&t.push({text:"What potential issues should I watch out for?",type:"clarify"}),n.length>0&&t.length<3){const s=n[0];t.push({text:`Tell me more about ${s}`,type:"expand"})}const r=[{text:"Can you give me a concrete example?",type:"example"},{text:"What would be the next steps?",type:"actionable"},{text:"How does this work in practice?",type:"expand"},{text:"Are there any common mistakes to avoid?",type:"clarify"},{text:"Can you simplify this explanation?",type:"clarify"}],i=new Set(t.map(s=>s.type));for(const s of r){if(t.length>=3)break;i.has(s.type)||(t.push(s),i.add(s.type))}for(const s of r){if(t.length>=3)break;t.some(o=>o.text===s.text)||t.push(s)}return t.slice(0,3)}function Os(e){return Ay(e).map(t=>t.text)}const Iy={openai:{baseUrl:"https://api.openai.com/v1",model:"gpt-4.1-nano"},openrouter:{baseUrl:"https://openrouter.ai/api/v1",model:"openai/gpt-oss-120b"},ollama:{baseUrl:"http://localhost:11434/v1",model:"llama3.2"},custom:{baseUrl:"",model:""}},Cn={useLlmTitles:!0,useLlmFollowUps:!0,llmProvider:"openai",llmBaseUrl:"",llmModel:"",llmApiKey:""};function Fa(e){return Iy[e]}function Ry(e){return e.llmBaseUrl.trim()?e.llmBaseUrl.trim():Fa(e.llmProvider).baseUrl}function Ny(e){return e.llmModel.trim()?e.llmModel.trim():Fa(e.llmProvider).model}function Fs(e,t){return e.llmProvider==="ollama"?!0:e.llmProvider==="custom"?!!e.llmApiKey.trim()||e.llmBaseUrl.trim()&&e.llmModel.trim():t||!!e.llmApiKey.trim()}function Ly(e){if(!e||typeof e!="object")return{settings:Cn};const{settings:t}=e;if(!t)return{settings:Cn};const{openaiApiKey:n,...r}=t,i=r.llmApiKey??n??"";return{settings:{...Cn,...r,llmApiKey:i}}}const Nt=fo()(co(e=>({settings:{...Cn},updateSettings:t=>e(n=>({settings:{...n.settings,...t}})),clearApiKey:()=>e(t=>({settings:{...t.settings,llmApiKey:""}}))}),{name:"llm-settings",version:2,migrate:e=>Ly(e)}));function Zb(){const e=Nt(o=>o.settings),t=Nt(o=>o.updateSettings),n=Nt(o=>o.clearApiKey),[r,i]=m.useState({hasEnvKey:!1,hasOpenRouterKey:!1,hasUserKey:!!e.llmApiKey,isAvailable:Fs(e,!1),isLoading:!0,error:null});m.useEffect(()=>{let o=!1;async function a(){try{const l=await fetch("/api/llm-features");if(!l.ok)throw new Error("Failed to check LLM status");const u=await l.json();if(o)return;const c=!!e.llmApiKey,f=e.llmProvider==="openrouter"?!!u.hasOpenRouterKey:u.hasEnvKey;i({hasEnvKey:u.hasEnvKey,hasOpenRouterKey:!!u.hasOpenRouterKey,hasUserKey:c,isAvailable:Fs(e,f),isLoading:!1,error:null})}catch(l){if(o)return;i(u=>({...u,isLoading:!1,error:l instanceof Error?l.message:"Failed to check status"}))}}return a(),()=>{o=!0}},[e.llmApiKey,e.llmProvider,e.llmBaseUrl,e.llmModel]);const s=m.useCallback(async o=>{try{const a=$a({...e,llmApiKey:o}),u=await(await fetch("/api/llm-features",{method:"POST",headers:{"Content-Type":"application/json",...a},body:JSON.stringify({action:"test"})})).json();return u.ok?{valid:u.valid??!1,error:u.error}:{valid:!1,error:u.error||"Test failed"}}catch(a){return{valid:!1,error:a instanceof Error?a.message:"Network error"}}},[e]);return{settings:e,updateSettings:t,clearApiKey:n,status:r,testApiKey:s}}function $a(e){const t=e.llmApiKey,n=Ry(e),r=Ny(e);return t?{"X-OpenAI-API-Key":t,...n?{"X-LLM-Base-URL":n}:{},...r?{"X-LLM-Model":r}:{}}:{...n?{"X-LLM-Base-URL":n}:{},...r?{"X-LLM-Model":r}:{}}}function Ba(){const e=Nt.getState().settings;return $a(e)}async function My(e,t){const n={"Content-Type":"application/json",...Ba()},r=await fetch("/api/llm-features",{method:"POST",headers:n,body:JSON.stringify({action:"followups",conversationContext:e}),signal:t});if(!r.ok)throw new Error(`API error: ${r.status}`);const i=await r.json();return i.ok&&Array.isArray(i.suggestions)&&i.suggestions.length>0?i.suggestions:[]}function Dy(e,t,n){const r=Nt(v=>v.settings),i=r.useLlmFollowUps,{minResponseLength:s=50,timeoutMs:o=8e3,heuristicsOnly:a}=n??{},l=a??!i,[u,c]=m.useState([]),[f,d]=m.useState(!1),[p,g]=m.useState(null),[y,w]=m.useState(null),k=m.useRef(""),S=m.useRef(null);return m.useEffect(()=>{if(!e||e.trim().length<s){c([]),w(null),d(!1),g(null);return}const v=e.slice(0,200)+e.length;if(v===k.current)return;if(k.current=v,S.current&&S.current.abort(),l){const z=Os(e);c(z),w("heuristic"),d(!1),g(null);return}const R=new AbortController;S.current=R,d(!0),g(null);const M=Os(e);c(M),w("heuristic");const C=t?`Context: ${t}
|
|
93
93
|
|
|
94
94
|
Assistant's response:
|
|
95
95
|
${e.slice(0,2e3)}`:`Assistant's response:
|
|
96
|
-
${e.slice(0,2e3)}`;return My(
|
|
97
|
-
`).trim():"",j=(H,z,x)=>{try{const V=JSON.parse(H),X=Array.isArray(V)?V:V?.results??V?.web?.results??[];if(!Array.isArray(X))return!1;let y=!1;for(const Q of X)Q?.url&&Q?.title&&!x.has(Q.url)&&(x.add(Q.url),z.push({title:T(Q.title),url:Q.url,snippet:T(Q.description||Q.snippet||Q.content||"")}),y=!0);return y}catch{return!1}},R=[],D=new Set;for(const H of E){if(H.role!=="assistant")continue;const z=Tt(H);for(const x of z){if(!x.id)continue;const V=x.name==="web_search",X=x.name==="web_fetch",y=x.name==="exec";if(!V&&!X&&!y)continue;const Q=N.get(x.id);if(!Q)continue;const ne=Q.content?.map(W=>W.type==="text"?String(W.text??""):"").join("").trim();if(ne){if(V||y){if(y&&(!ne.includes('"results"')||!ne.includes('"url"')))continue;let W=ne;const me=ne.indexOf("{");me>0&&(W=ne.slice(me));const ge=W.lastIndexOf("}");ge>0&&(W=W.slice(0,ge+1)),j(W,R,D)}else if(X){const W=x.arguments?.url;if(W&&!D.has(W)){D.add(W);let me;try{me=new URL(W).hostname}catch{me=W}R.push({title:me,url:W})}}}}}return R},[E,N]),S=E.map((T,j)=>({message:T,index:j})).filter(({message:T})=>T.role!=="user").map(({index:T})=>T).pop(),M=E.map((T,j)=>({message:T,index:j})).filter(({message:T})=>T.role==="user").map(({index:T})=>T).pop(),U=o&&(typeof M!="number"||typeof S!="number"||S<M),O=typeof M=="number"?M:-1,v=u&&O>=0,L=typeof S=="number"?E[S]:void 0,A=L?Je(L):"",F=!o&&!a&&A.length>0&&p!==void 0&&(typeof M!="number"||typeof S!="number"||S>M);return m.useLayoutEffect(()=>{if(!t){if(u){const T=!k.current||C.current!==M;k.current=!0,C.current=M,T&&b.current&&(w.current=!0,b.current.scrollIntoView({behavior:"auto",block:"start"}),window.setTimeout(()=>{w.current=!1},0));return}k.current=!1,C.current=M,g.current&&(w.current=!0,g.current.scrollIntoView({behavior:"auto",block:"end"}),window.setTimeout(()=>{w.current=!1},0))}},[t,E.length,l,u,M]),h.jsx(Uy,{className:"flex-1 min-h-0 -mb-4",children:h.jsxs(qy,{className:"pt-6",style:d,children:[i&&s==="start"?i:null,n&&!i?r??h.jsx("div",{"aria-hidden":!0}):v?h.jsxs(h.Fragment,{children:[E.slice(0,O).map((T,j)=>{const R=j,D=typeof S=="number"&&j===S,H=typeof S=="number"&&j===S,z=T.role==="assistant"&&Tt(T).length>0;return h.jsx(Cr,{message:T,toolResultsByCallId:z?N:void 0,forceActionsVisible:D,isStreaming:H&&a,isLastAssistant:H,aggregatedSearchSources:H?_:void 0},R)}),h.jsxs("div",{className:"flex flex-col space-y-3 md:space-y-6",style:{minHeight:`${Math.max(0,c-24)}px`},children:[E.slice(O).map((T,j)=>{const R=O+j,D=R,H=typeof S=="number"&&R===S,z=typeof S=="number"&&R===S,x=R===M?b:void 0,V=R===M?"scroll-mt-0":void 0,X=R===M?f:void 0,y=T.role==="assistant"&&Tt(T).length>0;return h.jsx(Cr,{message:T,toolResultsByCallId:y?N:void 0,forceActionsVisible:H,isStreaming:z&&a,isLastAssistant:z,aggregatedSearchSources:z?_:void 0,wrapperRef:x,wrapperClassName:V,wrapperScrollMarginTop:X},D)}),U?h.jsx("div",{className:"py-2",children:h.jsx(Vy,{})}):null,F&&p?h.jsx($s,{responseText:A,onSuggestionClick:p,disabled:o}):null]})]}):h.jsxs(h.Fragment,{children:[E.map((T,j)=>{const R=j,D=typeof S=="number"&&j===S,H=typeof S=="number"&&j===S,z=T.role==="assistant"&&Tt(T).length>0;return h.jsx(Cr,{message:T,toolResultsByCallId:z?N:void 0,forceActionsVisible:D,isStreaming:H&&a,isLastAssistant:H,aggregatedSearchSources:H?_:void 0},R)}),F&&p?h.jsx($s,{responseText:A,onSuggestionClick:p,disabled:o}):null]}),i&&s==="end"?i:null,h.jsx(Ky,{ref:g})]})})}function Yy(e,t){return e.messages===t.messages&&e.loading===t.loading&&e.empty===t.empty&&e.emptyState===t.emptyState&&e.notice===t.notice&&e.noticePosition===t.noticePosition&&e.waitingForResponse===t.waitingForResponse&&e.isStreaming===t.isStreaming&&e.sessionKey===t.sessionKey&&e.pinToTop===t.pinToTop&&e.pinGroupMinHeight===t.pinGroupMinHeight&&e.headerHeight===t.headerHeight&&e.contentStyle===t.contentStyle&&e.onFollowUpClick===t.onFollowUpClick}const Gy=m.memo(Xy,Yy),Ha=m.createContext({isLoading:!1,value:"",setValue:()=>{},maxHeight:240,onSubmit:void 0,disabled:!1,textareaRef:ll.createRef()});let Ht=null,Bs=!1;function Qy(){Bs||typeof window>"u"||(Bs=!0,window.addEventListener("keydown",e=>{if(e.defaultPrevented||e.metaKey||e.ctrlKey||e.altKey)return;const t=e.target;if(!t)return;const n=t.tagName.toLowerCase();if(n==="input"||n==="textarea"||n==="select"||t.isContentEditable)return;const r=e.key.length===1,i=e.key==="Backspace";!r&&!i||!Ht||Ht.disabled||Ht.focus()}))}function Ua(){return m.useContext(Ha)}function Jy({className:e,isLoading:t=!1,maxHeight:n=240,value:r,onValueChange:i,onSubmit:s,children:o,disabled:a=!1,onClick:l,...u}){const[c,f]=m.useState(r||""),d=m.useRef(null);Qy();function p(b){f(b),i?.(b)}function g(b){a||d.current?.focus(),l?.(b)}return h.jsx(jt,{children:h.jsx(Ha.Provider,{value:{isLoading:t,value:r??c,setValue:i??p,maxHeight:n,onSubmit:s,disabled:a,textareaRef:d},children:h.jsx("div",{onClick:g,className:q("bg-surface cursor-text rounded-[22px] outline outline-ink/10 shadow-[0px_12px_32px_0px_rgba(0,0,0,0.05)] py-3 gap-3 flex flex-col",a&&"cursor-not-allowed opacity-60",e),...u,children:o})})})}function Zy({className:e,onKeyDown:t,disableAutosize:n=!1,inputRef:r,...i}){const{value:s,setValue:o,maxHeight:a,onSubmit:l,disabled:u,textareaRef:c}=Ua();function f(b){!b||n||(b.style.height="auto",typeof a=="number"?b.style.height=`${Math.min(b.scrollHeight,a)}px`:b.style.height=`min(${b.scrollHeight}px, ${a})`)}function d(b){c.current=b,typeof r=="function"?r(b):r&&"current"in r&&(r.current=b),b?Ht=b:Ht===b&&(Ht=null),f(b)}m.useLayoutEffect(()=>{if(!c.current||n)return;const b=c.current;b.style.height="auto",typeof a=="number"?b.style.height=`${Math.min(b.scrollHeight,a)}px`:b.style.height=`min(${b.scrollHeight}px, ${a})`},[s,a,n]);function p(b){f(b.target),o(b.target.value)}function g(b){b.key==="Enter"&&!b.shiftKey&&(b.preventDefault(),l?.()),t?.(b)}return h.jsx("textarea",{ref:d,value:s,onChange:p,onKeyDown:g,className:q("text-primary-950 opencami-text-size min-h-[28px] w-full resize-none border-none bg-transparent shadow-none outline-none focus-visible:ring-0 pl-4 pr-1 placeholder:text-primary-500",e),rows:1,readOnly:u,"aria-disabled":u,...i})}function eb({children:e,className:t,...n}){return h.jsx("div",{className:q("flex items-center gap-2",t),...n,children:e})}function vr({tooltip:e,children:t,className:n,side:r="top",...i}){const{disabled:s}=Ua();return h.jsxs(At,{...i,children:[h.jsx(It,{disabled:s,onClick:o=>o.stopPropagation(),children:t}),h.jsx(Rt,{side:r,className:n,children:e})]})}const qa="opencami-selected-model";function tb(){if(typeof window>"u")return null;try{return localStorage.getItem(qa)}catch{return null}}function nb(e){if(!(typeof window>"u"))try{localStorage.setItem(qa,e)}catch{}}function rb({className:e,onModelChange:t}){const[n,r]=m.useState([]),[i,s]=m.useState(""),[o,a]=m.useState(!0),[l,u]=m.useState(null);m.useEffect(()=>{let g=!0;async function b(){try{a(!0),u(null);const w=await fetch("/api/models");if(!w.ok)throw new Error("Failed to fetch models");const k=await w.json();if(!g)return;if(k.ok&&k.models.length>0){r(k.models);const C=tb(),E=C&&k.models.some(N=>N.id===C)?C:k.defaultModel;s(E),t?.(E)}else throw new Error("No models available")}catch(w){if(!g)return;console.error("[model-selector] Error fetching models:",w),u(w instanceof Error?w.message:"Failed to load models"),r([{id:"default",name:"Default Model"}]),s("default")}finally{g&&a(!1)}}return b(),()=>{g=!1}},[t]);function c(g){s(g),nb(g),t?.(g)}if(o)return h.jsxs("div",{className:q("flex items-center gap-2 text-xs text-primary-500",e),children:[h.jsx(te,{icon:er,size:14}),h.jsx("span",{children:"Loading..."})]});if(l||n.length===0)return null;const f=n.find(g=>g.id===i),d=f?.name||"Select Model",p=(()=>{if(!f?.name)return d;const b=f.name.replace(/\s*\([^)]*\)\s*$/,"").trim(),w=b.split(/\s+/);return w.length>3?w.slice(0,3).join(" "):b})();return n.length===1?h.jsxs("div",{className:q("flex items-center gap-2 text-xs text-primary-500",e),children:[h.jsx(te,{icon:er,size:14}),h.jsx("span",{className:"font-[450] md:hidden",children:p}),h.jsx("span",{className:"font-[450] hidden md:inline",children:d})]}):h.jsxs(Bn,{children:[h.jsxs(Hn,{className:q("inline-flex h-7 items-center gap-2 rounded-md px-2 text-xs font-[450] text-primary-600 hover:text-primary-900 hover:bg-primary-100",e),children:[h.jsx(te,{icon:er,size:14}),h.jsx("span",{className:"md:hidden",children:p}),h.jsx("span",{className:"hidden md:inline",children:d})]}),h.jsx(Un,{side:"top",align:"start",children:n.map(g=>h.jsxs(mt,{onClick:()=>c(g.id),className:"justify-between min-w-[180px]",children:[h.jsx("span",{children:g.name}),i===g.id&&h.jsx(te,{icon:Vr,size:14,className:"text-primary-600"})]},g.id))})]})}const Ka="opencami-personas-enabled",Ur="opencami-active-persona";function ib(){if(typeof window>"u")return!0;try{const e=localStorage.getItem(Ka);return e===null?!0:e==="true"}catch{return!0}}function sb(){if(typeof window>"u")return null;try{const e=localStorage.getItem(Ur);return e?JSON.parse(e):null}catch{return null}}function Hs(e){if(!(typeof window>"u"))try{e?localStorage.setItem(Ur,JSON.stringify(e)):localStorage.removeItem(Ur)}catch{}}const ob={core:"Core",creative:"Creative",curator:"Curator",learning:"Learning",lifestyle:"Lifestyle",professional:"Professional"};function ab({className:e,onSelect:t}){const[n,r]=m.useState({}),[i,s]=m.useState(null),[o,a]=m.useState(!0),[l,u]=m.useState(!1),[c,f]=m.useState(ib);m.useEffect(()=>{const b=w=>{w.key===Ka&&f(w.newValue===null?!0:w.newValue==="true")};return window.addEventListener("storage",b),()=>window.removeEventListener("storage",b)},[]),m.useEffect(()=>{let b=!0;async function w(){try{a(!0);const k=await fetch("/api/personas");if(!k.ok){u(!1);return}const C=await k.json();if(!b)return;C.ok&&C.available?(r(C.personas),u(!0),s(sb())):u(!1)}catch{if(!b)return;u(!1)}finally{b&&a(!1)}}return w(),()=>{b=!1}},[]);const d=m.useCallback(b=>{s(b),Hs(b),t(`/persona ${b.id}`)},[t]),p=m.useCallback(()=>{s(null),Hs(null),t("/persona exit")},[t]);if(o||!l||!c)return null;const g=Object.entries(n);return g.length===0?null:h.jsxs(Bn,{children:[h.jsxs(Hn,{className:q("inline-flex h-7 items-center gap-1.5 rounded-md px-2 text-xs font-[450] text-primary-600 hover:text-primary-900 hover:bg-primary-100",e),children:[h.jsx("span",{className:"text-sm","aria-hidden":"true",children:"🎭"}),i?h.jsxs("span",{className:"flex items-center gap-1",children:[h.jsx("span",{children:i.emoji}),h.jsx("span",{children:i.name})]}):h.jsx("span",{children:"Persona"})]}),h.jsxs(Un,{side:"top",align:"start",className:"w-[300px] max-h-[360px] overflow-y-auto",children:[i&&h.jsxs(h.Fragment,{children:[h.jsxs(mt,{onClick:p,className:"text-red-600 hover:bg-red-50",children:[h.jsx("span",{className:"text-sm",children:"✕"}),h.jsx("span",{children:"Exit Persona"}),h.jsxs("span",{className:"ml-auto text-[10px] text-primary-400",children:[i.emoji," ",i.name]})]}),h.jsx("div",{className:"my-1 h-px bg-primary-200"})]}),g.map(([b,w])=>h.jsxs("div",{children:[h.jsx("div",{className:"px-2 pb-0.5 pt-2 text-[10px] font-semibold uppercase tracking-wider text-primary-400",children:ob[b]??b}),w.map(k=>h.jsxs(mt,{onClick:()=>d(k),className:"justify-between",children:[h.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[h.jsx("span",{className:"text-sm flex-shrink-0",children:k.emoji}),h.jsx("span",{className:"truncate",children:k.name})]}),h.jsx("span",{className:"text-[11px] text-primary-400 truncate ml-2 max-w-[140px]",children:k.description})]},k.id))]},b))]})]})}const lb=[{command:"/new",description:"Start a new conversation",usage:"/new"},{command:"/reset",description:"Reset conversation context",usage:"/reset"},{command:"/abort",description:"Abort current generation",usage:"/abort"},{command:"/status",description:"Show session status card",usage:"/status"},{command:"/usage",description:"Show token usage",usage:"/usage [off|tokens|full]"},{command:"/models",description:"List available models",usage:"/models"},{command:"/agents",description:"List available agents",usage:"/agents"},{command:"/sessions",description:"List active sessions",usage:"/sessions"},{command:"/model",description:"Switch model for this session",usage:"/model <alias>"},{command:"/reasoning",description:"Toggle reasoning mode",usage:"/reasoning [on|off|stream]"},{command:"/think",description:"Set thinking budget",usage:"/think [off|minimal|low|medium|high]"},{command:"/verbose",description:"Toggle verbose output",usage:"/verbose [on|full|off]"},{command:"/tts",description:"Text-to-speech controls",usage:"/tts [status|off|always]"},{command:"/settings",description:"Show current settings",usage:"/settings"},{command:"/help",description:"Show help",usage:"/help"}];function ub({className:e,onCommandSelect:t}){const[n,r]=m.useState(!1);function i(s){t?.(s),r(!1)}return h.jsxs(h.Fragment,{children:[h.jsx(ve,{variant:"ghost",size:"sm",onClick:()=>r(!0),className:q("h-7 w-7 p-0",e),title:"Show commands (Ctrl+/)",children:h.jsx(te,{icon:Li,size:16,className:"text-primary-500"})}),n&&h.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm",children:h.jsxs("div",{className:"bg-white dark:bg-neutral-900 border border-primary-200 dark:border-neutral-700 rounded-xl shadow-2xl w-full max-w-lg max-h-[80vh] overflow-hidden",children:[h.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-primary-200 dark:border-neutral-700 bg-neutral-50 dark:bg-neutral-800",children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx(te,{icon:Li,size:18,className:"text-primary-600 dark:text-primary-400"}),h.jsx("h2",{className:"font-semibold text-primary-900 dark:text-white",children:"Slash Commands"})]}),h.jsx(ve,{variant:"ghost",size:"sm",onClick:()=>r(!1),className:"h-7 w-7 p-0",children:h.jsx(te,{icon:$n,size:16})})]}),h.jsxs("div",{className:"overflow-y-auto max-h-[60vh] p-2 bg-white dark:bg-neutral-900",children:[h.jsx("div",{className:"text-xs text-primary-500 dark:text-neutral-400 px-2 py-1 mb-2",children:"Type these commands in the chat input"}),lb.map(s=>h.jsxs("button",{onClick:()=>i(s.command),className:"w-full flex items-start gap-3 px-3 py-2 rounded-lg hover:bg-primary-100 dark:hover:bg-neutral-800 transition-colors text-left",children:[h.jsx("code",{className:"text-sm font-mono font-medium text-primary-700 dark:text-primary-300 bg-primary-100 dark:bg-neutral-800 px-1.5 py-0.5 rounded min-w-[80px]",children:s.command}),h.jsxs("div",{className:"flex-1 min-w-0",children:[h.jsx("div",{className:"text-sm text-primary-900 dark:text-neutral-100",children:s.description}),s.usage&&s.usage!==s.command&&h.jsx("div",{className:"text-xs text-primary-500 dark:text-neutral-500 font-mono mt-0.5",children:s.usage})]})]},s.command))]}),h.jsx("div",{className:"px-4 py-2 border-t border-primary-200 dark:border-neutral-700 bg-neutral-50 dark:bg-neutral-800",children:h.jsxs("div",{className:"text-xs text-primary-500 dark:text-neutral-400",children:["Press ",h.jsx("kbd",{className:"px-1 py-0.5 bg-primary-200 dark:bg-neutral-700 rounded text-primary-700 dark:text-neutral-300",children:"Esc"})," to close"]})})]})})]})}const cb=10*1024*1024,$t=1280,fb=.75,hb=300*1024,pb=["image/png","image/jpeg","image/gif","image/webp"],db=".png,.jpg,.jpeg,.gif,.webp";function mb(){if(typeof document>"u")return!1;try{const e=document.createElement("canvas");return!!(e.getContext&&e.getContext("2d"))}catch{return!1}}async function gb(e){if(!mb())throw new Error("Image compression not available in this browser");return new Promise((t,n)=>{const r=new Image,i=URL.createObjectURL(e),s=()=>{URL.revokeObjectURL(i)};r.onload=()=>{try{let o=r.width,a=r.height;(o>$t||a>$t)&&(o>a?(a=Math.round(a*$t/o),o=$t):(o=Math.round(o*$t/a),a=$t));const l=document.createElement("canvas");l.width=o,l.height=a;const u=l.getContext("2d");if(!u){s(),n(new Error("Failed to get canvas context"));return}u.drawImage(r,0,0,o,a);const c=e.type==="image/png"?"image/png":"image/jpeg";let f=fb,d=l.toDataURL(c,f);if(c==="image/jpeg"){const g=hb*1.37;for(;d.length>g&&f>.3;)f-=.1,d=l.toDataURL(c,f)}const p=d.split(",")[1];if(!p){s(),n(new Error("Failed to encode image"));return}s(),t(p)}catch(o){s(),n(o instanceof Error?o:new Error("Image compression failed"))}},r.onerror=()=>{s(),n(new Error("Failed to load image"))},r.src=i})}function Wa(e){return pb.includes(e.type)}async function Va(e){const t=crypto.randomUUID();if(!Wa(e))return{id:t,file:e,preview:null,type:"image",base64:null,error:"Unsupported file type. Please use PNG, JPG, GIF, or WebP images."};if(e.size>cb)return{id:t,file:e,preview:null,type:"image",base64:null,error:"Image is too large. Maximum size is 10MB."};try{const n=await gb(e),r=URL.createObjectURL(e);return{id:t,file:e,preview:r,type:"image",base64:n}}catch(n){return{id:t,file:e,preview:null,type:"image",base64:null,error:n instanceof Error?n.message:"Failed to process image"}}}function xb({onFileSelect:e,disabled:t=!1,className:n}){const r=m.useRef(null),i=m.useCallback(()=>{r.current?.click()},[]),s=m.useCallback(async o=>{const a=o.target.files?.[0];if(!a)return;o.target.value="";const l=await Va(a);e(l)},[e]);return h.jsxs(h.Fragment,{children:[h.jsx("input",{ref:r,type:"file",accept:db,onChange:s,className:"hidden","aria-hidden":"true"}),h.jsx(ve,{variant:"ghost",size:"icon-sm",onClick:i,disabled:t,className:n,"aria-label":"Attach image",type:"button",children:h.jsx(te,{icon:_l,size:18,strokeWidth:1.8})})]})}function yb(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function bb(e){const t=e.split(".");return t.length>1&&t.pop()?.toUpperCase()||""}function kb({attachment:e,onRemove:t,className:n}){m.useEffect(()=>()=>{e.preview&&URL.revokeObjectURL(e.preview)},[e.preview]);const r=!!e.error;return h.jsxs("div",{className:q("relative flex items-center gap-3 rounded-xl border p-2 pr-3",r?"border-red-300 bg-red-50":"border-primary-200 bg-primary-50",n),children:[h.jsx("div",{className:"relative shrink-0",children:e.type==="image"&&e.preview?h.jsx("img",{src:e.preview,alt:e.file.name,className:"h-12 w-12 rounded-lg object-cover"}):h.jsx("div",{className:"flex h-12 w-12 items-center justify-center rounded-lg bg-primary-100",children:h.jsx(te,{icon:Ol,size:24,className:"text-primary-500"})})}),h.jsxs("div",{className:"min-w-0 flex-1",children:[h.jsx("p",{className:"truncate text-sm font-medium text-primary-900",children:e.file.name}),r?h.jsx("p",{className:"text-xs text-red-600",children:e.error}):h.jsxs("p",{className:"text-xs text-primary-500",children:[bb(e.file.name)," •"," ",yb(e.file.size)]})]}),h.jsx(ve,{variant:"ghost",size:"icon-sm",onClick:()=>t(e.id),className:"h-6 w-6 shrink-0 rounded-full hover:bg-primary-200","aria-label":"Remove attachment",type:"button",children:h.jsx(te,{icon:$n,size:14})})]})}function wb({attachments:e,onRemove:t,className:n}){return e.length===0?null:h.jsx("div",{className:q("flex flex-col gap-2 px-4",n),children:e.map(r=>h.jsx(kb,{attachment:r,onRemove:t},r.id))})}function Sb({commands:e,selectedIndex:t,onSelect:n,className:r}){return e.length===0?null:h.jsx("div",{className:q("absolute left-2 right-2 md:left-5 md:right-5 bottom-full mb-2 z-20 rounded-xl border border-white/10 bg-neutral-900/95 shadow-2xl backdrop-blur-sm overflow-hidden",r),role:"listbox","aria-label":"Slash commands",children:h.jsx("div",{className:"max-h-56 overflow-y-auto p-1",children:e.map((i,s)=>{const o=s===t;return h.jsx("button",{type:"button",role:"option","aria-selected":o,onMouseDown:a=>{a.preventDefault(),n(i)},className:q("w-full rounded-md px-3 py-2 text-left transition-colors",o?"bg-neutral-800":"hover:bg-neutral-800/80"),children:h.jsxs("div",{className:"flex items-start gap-3",children:[h.jsx("code",{className:"min-w-[90px] font-mono text-xs text-primary-300",children:i.command}),h.jsx("span",{className:"text-xs text-neutral-300",children:i.description})]})},i.command)})})})}const Cb=m.memo(Sb),qr=fo()(co(e=>({level:"low",setLevel:t=>e({level:t})}),{name:"thinking-level"}));function vb(){const e=qr(n=>n.level),t=qr(n=>n.setLevel);return{level:e,setLevel:t}}const Er=[{value:"off",label:"Off",description:"No reasoning",shortLabel:"Off"},{value:"low",label:"Low",description:"Think",shortLabel:"Low"},{value:"medium",label:"Medium",description:"Think harder",shortLabel:"Medium"},{value:"high",label:"High",description:"Ultrathink",shortLabel:"High"}];function Eb({className:e}){const{level:t,setLevel:n}=vb(),r=Er.find(i=>i.value===t)??Er[1];return h.jsxs(Bn,{children:[h.jsxs(Hn,{className:q("inline-flex h-7 items-center gap-2 rounded-md px-2 text-xs font-[450] text-primary-600 hover:text-primary-900 hover:bg-primary-100",e),children:[h.jsx(te,{icon:Zs,size:20,strokeWidth:1.5,className:q(t==="off"?"text-primary-400":"text-primary-700")}),h.jsx("span",{className:"text-pretty",children:r.shortLabel})]}),h.jsx(Un,{side:"top",align:"start",className:"min-w-[190px]",children:Er.map(i=>h.jsxs(mt,{onClick:()=>n(i.value),className:"justify-between",children:[h.jsxs("span",{className:"flex flex-col text-pretty",children:[h.jsx("span",{className:"text-sm text-primary-900",children:i.label}),h.jsx("span",{className:"text-xs text-primary-500",children:i.description})]}),t===i.value&&h.jsx(te,{icon:Vr,size:20,strokeWidth:1.5,className:"text-primary-600"})]},i.value))})]})}const Us=[{command:"/haiku",description:"Switch to Claude Haiku 4.5"},{command:"/sonnet",description:"Switch to Claude Sonnet 4.5"},{command:"/opus",description:"Switch to Claude Opus 4.5"},{command:"/opus46",description:"Switch to Claude Opus 4.6"},{command:"/codex",description:"Switch to GPT 5.3 Codex"},{command:"/glm",description:"Switch to GLM 4.7"},{command:"/kimi",description:"Switch to Kimi K2.5"},{command:"/minimax",description:"Switch to MiniMax M2.1"},{command:"/grok",description:"Switch to Grok 4.1 Fast"},{command:"/model",description:"Show model picker or switch model"},{command:"/new",description:"New chat (optional: /new model)"},{command:"/reset",description:"Reset session"},{command:"/stop",description:"Stop current generation"},{command:"/compact",description:"Compact conversation context"},{command:"/help",description:"Show available commands"},{command:"/commands",description:"List all commands"},{command:"/status",description:"Show session status & usage"},{command:"/whoami",description:"Show your sender ID"},{command:"/context",description:"Show context window details"},{command:"/usage",description:"Toggle usage footer (off/tokens/full/cost)"},{command:"/think",description:"Set thinking level (off/low/medium/high)"},{command:"/reasoning",description:"Toggle reasoning (on/off/stream)"},{command:"/verbose",description:"Toggle verbose mode (on/full/off)"},{command:"/elevated",description:"Toggle elevated permissions (on/off/ask)"},{command:"/exec",description:"Configure exec settings"},{command:"/queue",description:"Show/configure message queue"},{command:"/tts",description:"Text-to-speech (off/always/tagged/status)"},{command:"/subagents",description:"List/stop/log sub-agent runs"},{command:"/followups",description:"Show follow-up suggestions"},{command:"/skill",description:"Run a skill by name"},{command:"/allowlist",description:"List/add/remove allowlist entries"},{command:"/approve",description:"Resolve exec approval (allow/deny)"},{command:"/config",description:"Show/get/set config (owner-only)"},{command:"/debug",description:"Runtime overrides (owner-only)"},{command:"/send",description:"Toggle message sending (on/off)"},{command:"/restart",description:"Restart gateway"},{command:"/activation",description:"Set activation mode (mention/always)"},{command:"/dock-telegram",description:"Switch replies to Telegram"},{command:"/dock-discord",description:"Switch replies to Discord"},{command:"/bash",description:"Run host shell command"}];function Tb({onSubmit:e,isLoading:t,disabled:n,wrapperRef:r,inputRef:i}){const[s,o]=m.useState(""),[a,l]=m.useState(""),[u,c]=m.useState([]),[f,d]=m.useState(0),[p,g]=m.useState(!1),[b,w]=m.useState(!1),[k,C]=m.useState(!1),[E,N]=m.useState(0),[_,S]=m.useState(!1),M=m.useRef(null),U=m.useRef([]),O=m.useRef(null),v=m.useRef(null),L=m.useRef(null),A=m.useMemo(()=>/^\/\S*$/.test(s)&&!p,[s,p]),F=m.useMemo(()=>A?s.slice(1).toLowerCase():"",[A,s]),T=m.useMemo(()=>A?F?Us.filter(K=>K.command.slice(1).toLowerCase().startsWith(F)):Us:[],[A,F]),j=m.useCallback(K=>{L.current=K,i&&(typeof i=="function"?i(K):i.current=K)},[i]),R=m.useCallback(()=>{typeof window>"u"||window.requestAnimationFrame(()=>{L.current?.focus()})},[]),D=m.useCallback(()=>{o(""),c([]),d(0),g(!1),R()},[R]),H=m.useCallback(K=>{c(Z=>[...Z,K])},[]),z=m.useCallback(K=>{c(Z=>Z.filter($=>$.id!==K))},[]),x=m.useCallback(K=>{Array.from(K.dataTransfer.types).includes("Files")&&(K.preventDefault(),K.dataTransfer.dropEffect="copy",w(!0))},[]),V=m.useCallback(K=>{K.preventDefault();const Z=K.relatedTarget;Z&&K.currentTarget.contains(Z)||w(!1)},[]),X=m.useCallback(async K=>{K.preventDefault(),w(!1);const Z=Array.from(K.dataTransfer.files??[]);if(Z.length===0)return;const $=Z.filter(re=>Wa(re));if($.length===0)return;const ue=await Promise.all($.map(re=>Va(re)));c(re=>[...re,...ue]),R()},[R]),y=m.useCallback(K=>{o(K),d(0),g(!1),R()},[R]),Q=m.useCallback(K=>{o(K),d(0),g(!1)},[]),ne=m.useCallback(K=>{o(`${K.command} `),d(0),g(!1),R()},[R]),W=m.useCallback(()=>{if(n)return;if(A&&T.length>0){const $=Math.min(f,T.length-1);ne(T[$]);return}const K=s.trim(),Z=u.filter($=>!$.error&&$.base64);K.length===0&&Z.length===0||(e(K,{reset:D,setValue:y,model:a||void 0,attachments:Z}),R())},[n,A,T,f,ne,s,u,e,D,y,a,R]),me=m.useCallback(K=>{e(K,{reset:D,setValue:y,model:a||void 0,attachments:[]}),R()},[R,e,D,y,a]),ge=m.useCallback(K=>{if(A){if(K.key==="Escape"){K.preventDefault(),g(!0),d(0);return}if(T.length!==0){if(K.key==="ArrowDown"){K.preventDefault(),d(Z=>(Z+1)%T.length);return}if(K.key==="ArrowUp"){K.preventDefault(),d(Z=>(Z-1+T.length)%T.length);return}if(K.key==="Tab"){K.preventDefault();const Z=Math.min(f,T.length-1);ne(T[Z])}}}},[A,T,f,ne]);m.useEffect(()=>()=>{O.current&&clearInterval(O.current),M.current&&M.current.state!=="inactive"&&M.current.stop(),v.current&&v.current.abort()},[]);const le=m.useCallback(()=>{if(typeof window>"u")return"auto";try{return localStorage.getItem("opencami-stt-provider")||"auto"}catch{return"auto"}},[]),ie=m.useCallback(()=>{M.current&&M.current.state!=="inactive"&&M.current.stop(),v.current&&v.current.stop(),O.current&&(clearInterval(O.current),O.current=null),C(!1),N(0)},[]),be=m.useCallback(async()=>{const K=le();if(K==="browser"){const Z=window.SpeechRecognition||window.webkitSpeechRecognition;if(!Z){alert("Web Speech API is not supported in this browser.");return}const $=new Z;$.continuous=!0,$.interimResults=!1,$.lang=navigator.language||"en-US",v.current=$,C(!0),N(0),O.current=setInterval(()=>{N(re=>re>=119?(ie(),0):re+1)},1e3);let ue="";$.onresult=re=>{for(let pe=re.resultIndex;pe<re.results.length;pe++)re.results[pe].isFinal&&(ue+=re.results[pe][0].transcript)},$.onend=()=>{C(!1),N(0),O.current&&clearInterval(O.current),ue.trim()&&(o(re=>re+(re?" ":"")+ue.trim()),R())},$.onerror=()=>{C(!1),N(0),O.current&&clearInterval(O.current)},$.start();return}try{const Z=await navigator.mediaDevices.getUserMedia({audio:!0}),$=MediaRecorder.isTypeSupported("audio/webm")?"audio/webm":"audio/mp4",ue=new MediaRecorder(Z,{mimeType:$});M.current=ue,U.current=[],ue.ondataavailable=re=>{re.data.size>0&&U.current.push(re.data)},ue.onstop=async()=>{Z.getTracks().forEach(pe=>pe.stop());const re=new Blob(U.current,{type:$});if(re.size!==0){S(!0);try{const pe=new FormData;pe.append("audio",re,`recording.${$==="audio/webm"?"webm":"mp4"}`),K!=="auto"&&pe.append("provider",K);const Ee=await(await fetch("/api/stt",{method:"POST",body:pe})).json();Ee.ok&&Ee.text?(o(Le=>Le+(Le?" ":"")+Ee.text),R()):Ee.ok||(console.warn("STT failed:",Ee.error),alert(Ee.error||"Speech-to-text failed. Try the Browser provider in Settings."))}catch(pe){console.warn("STT request failed:",pe),alert("Could not reach speech-to-text service.")}finally{S(!1)}}},C(!0),N(0),O.current=setInterval(()=>{N(re=>re>=119?(ie(),0):re+1)},1e3),ue.start()}catch(Z){const $=Z instanceof Error?Z.message:String(Z);if($.includes("NotAllowedError")||$.includes("Permission"))try{(await navigator.permissions.query({name:"microphone"})).state==="denied"?alert("Microphone access is blocked. Please enable it in your browser/app settings."):alert("Microphone permission was not granted. Please try again and allow access when prompted.")}catch{alert("Could not access microphone. Please check your browser settings and allow microphone access for this site.")}else alert("Could not access microphone: "+$)}},[le,ie,R]),ke=m.useCallback(()=>{k?ie():be()},[k,ie,be]),we=u.filter(K=>!K.error&&K.base64),Se=n||s.trim().length===0&&we.length===0;return h.jsxs("div",{className:"mx-auto w-full max-w-full px-2 md:px-5 sm:max-w-[768px] sm:min-w-[400px] relative pb-1 md:pb-3",ref:r,onDragOver:x,onDragLeave:V,onDrop:X,children:[b&&h.jsx("div",{className:"pointer-events-none absolute inset-2 z-20 flex items-center justify-center rounded-2xl border-2 border-dashed border-primary-400 bg-primary-50/90 text-sm font-medium text-primary-700",children:"Drop image here"}),h.jsxs(Jy,{value:s,onValueChange:Q,onSubmit:W,isLoading:t,disabled:n,children:[h.jsx(wb,{attachments:u,onRemove:z}),A&&T.length>0&&h.jsx(Cb,{commands:T,selectedIndex:Math.min(f,T.length-1),onSelect:ne}),h.jsx(Zy,{placeholder:"Type a message…",inputRef:j,onKeyDown:ge}),h.jsxs(eb,{className:"justify-between px-3",children:[h.jsxs("div",{className:"flex items-center gap-1",children:[h.jsx(rb,{onModelChange:l}),h.jsx(Eb,{}),h.jsx(ab,{onSelect:me}),h.jsx(ub,{onCommandSelect:K=>Q(K+" ")})]}),h.jsxs("div",{className:"flex items-center gap-1",children:[h.jsx(vr,{tooltip:"Attach file",children:h.jsx(xb,{onFileSelect:H,disabled:n})}),h.jsx(vr,{tooltip:k?"Stop recording":"Voice input",children:h.jsx(ve,{onClick:ke,disabled:n||_,size:"icon-sm",variant:k?"destructive":"ghost",className:`rounded-full ${k?"animate-pulse":""}`,"aria-label":k?"Stop recording":"Voice input",children:_?h.jsx("span",{className:"size-4 animate-spin rounded-full border-2 border-current border-t-transparent"}):k?h.jsxs("span",{className:"flex items-center gap-1",children:[h.jsx("span",{className:"size-2 rounded-full bg-red-500"}),h.jsxs("span",{className:"text-xs tabular-nums",children:[Math.floor(E/60),":",String(E%60).padStart(2,"0")]}),h.jsx(te,{icon:to,size:14,strokeWidth:2})]}):h.jsx(te,{icon:Fl,size:18,strokeWidth:2})})}),h.jsx(vr,{tooltip:"Send message",children:h.jsx(ve,{onClick:W,disabled:Se,size:"icon-sm",className:"rounded-full","aria-label":"Send message",children:h.jsx(te,{icon:$l,size:18,strokeWidth:2})})})]})]})]})]})}const jb=m.memo(Tb);function Ab({title:e,description:t,detail:n,actionLabel:r,onAction:i,className:s}){return h.jsx("div",{className:q("w-full max-w-[900px]",s),children:h.jsx(Oa,{children:h.jsxs("div",{className:"w-full rounded-xl border border-primary-200 bg-primary-50 p-4 text-primary-900",children:[h.jsx("div",{className:"text-balance font-medium",children:e}),h.jsx("div",{className:"mt-2 text-pretty text-primary-700",children:t}),n?h.jsx("div",{className:"mt-2 text-xs text-primary-600",children:n}):null,r&&i?h.jsx("div",{className:"mt-3",children:h.jsx(ve,{size:"sm",variant:"outline",onClick:i,children:r})}):null]})})})}function Ib({state:e,error:t,onRetry:n,className:r}){const i=e==="checking",s=i?"Checking gateway connection...":"OpenClaw gateway is unreachable",o=i?"This dashboard needs access to the OpenClaw gateway configured by your server environment variables.":"";return h.jsx(Ab,{title:s,description:i?o:h.jsxs(h.Fragment,{children:["We could not reach the gateway from the dashboard server. Start the gateway and confirm your server environment has"," ",h.jsx("span",{className:"font-mono",children:"CLAWDBOT_GATEWAY_URL"})," plus"," ",h.jsx("span",{className:"font-mono",children:"CLAWDBOT_GATEWAY_TOKEN"})," (or"," ",h.jsx("span",{className:"font-mono",children:"CLAWDBOT_GATEWAY_PASSWORD"}),")."]}),detail:i?null:t,actionLabel:i?void 0:"Retry",onAction:i?void 0:n,className:r})}function Rb(){const e=m.useRef(null),t=m.useRef(null),n=m.useRef(null),[r,i]=m.useState(0),[s,o]=m.useState(0);return m.useLayoutEffect(()=>{const a=e.current,l=t.current,u=n.current;if(!u)return;const c=()=>{const d=a?.offsetHeight??0,p=l?.offsetHeight??0,g=u.clientHeight;u.style.setProperty("--chat-header-height",`${Math.max(0,d)}px`),u.style.setProperty("--chat-composer-height",`${Math.max(0,p)}px`),o(d),i(Math.max(0,g-d-p))};c();const f=new ResizeObserver(()=>c());return a&&f.observe(a),l&&f.observe(l),()=>f.disconnect()},[]),{headerRef:e,composerRef:t,mainRef:n,pinGroupMinHeight:r,headerHeight:s}}function Nb({activeFriendlyId:e,activeSessionKey:t,forcedSessionKey:n,isNewChat:r,isRedirecting:i,activeExists:s,sessionsReady:o,queryClient:a}){const l=n||t||e,u=ye.history(e,l),c=En({queryKey:u,queryFn:async function(){const C=a.getQueryData(u),E=Array.isArray(C?.messages)?C.messages.filter(S=>S.status==="sending"||S.__optimisticId?!0:!!S.clientId):[],N=await xu({sessionKey:l,friendlyId:e});if(!E.length)return N;const _=Lb(N.messages,E);return{...N,messages:_}},enabled:!r&&!!e&&!i&&(!o||s),placeholderData:function(){return a.getQueryData(u)},gcTime:1e3*60*10}),f=m.useRef(""),d=m.useRef([]),p=m.useMemo(()=>{const k=Array.isArray(c.data?.messages)?c.data.messages:[],C=k[k.length-1],E=C&&typeof C.id=="string"?C.id:"",N=`${k.length}:${C?.role??""}:${E}:${Je(C??{content:[]}).slice(-32)}`;return N===f.current?d.current:(f.current=N,d.current=k,k)},[c.data?.messages]),g=c.error instanceof Error?c.error.message:null,b=m.useMemo(()=>{if(n)return n;const k=c.data?.sessionKey;return typeof k=="string"&&k.trim().length>0?k.trim():t},[t,n,c.data?.sessionKey]);return{historyQuery:c,historyMessages:p,displayMessages:p,historyError:g,resolvedSessionKey:b,activeCanonicalKey:r?"new":b||e,sessionKeyForHistory:l}}function Lb(e,t){if(!t.length)return e;const n=[...e];for(const r of t)e.some(s=>{if(r.clientId&&s.clientId&&r.clientId===s.clientId||r.__optimisticId&&s.__optimisticId&&r.__optimisticId===s.__optimisticId)return!0;if(r.role&&s.role&&r.role!==s.role)return!1;const o=Je(r);if(!o||o!==Je(s))return!1;const a=Ar(r),l=Ar(s);return Math.abs(a-l)<=1e4})||n.push(r);return n}function Mb(e){const[t,n]=m.useState(!1);return m.useLayoutEffect(()=>{const r=window.matchMedia("(max-width: 768px)"),i=()=>n(r.matches);return i(),r.addEventListener("change",i),()=>r.removeEventListener("change",i)},[]),m.useLayoutEffect(()=>{t&&pt(e,function(i){return{...i,isSidebarCollapsed:!0}})},[t,e]),{isMobile:t}}function Db({activeFriendlyId:e,isNewChat:t,forcedSessionKey:n}){const r=En({queryKey:ye.sessions,queryFn:gu,refetchInterval:3e4}),i=m.useMemo(()=>{const f=r.data??[];return $c(f)},[r.data]),s=m.useMemo(()=>i.find(f=>f.friendlyId===e),[i,e]),o=m.useMemo(()=>t||n||To(e)?!0:i.some(f=>f.friendlyId===e),[e,n,t,i]),a=s?.key??"",l=m.useMemo(()=>s?s.label||s.title||s.derivedTitle||s.friendlyId:e,[e,s]),u=r.error instanceof Error?r.error.message:null,c=m.useMemo(()=>({totalTokens:s?.totalTokens,contextTokens:s?.contextTokens}),[s?.totalTokens,s?.contextTokens]);return{sessionsQuery:r,sessions:i,activeSession:s,activeExists:o,activeSessionKey:a,activeTitle:l,activeTokens:c,sessionsError:u}}function zb(){const e=Nt(u=>u.settings),[t,n]=m.useState(!1),[r,i]=m.useState(null),[s,o]=m.useState(null),a=m.useRef(null);return{generateTitle:m.useCallback(async u=>{a.current&&a.current.abort();const c=new AbortController;a.current=c,n(!0);try{const f={"Content-Type":"application/json",...Ba()},d=await fetch("/api/llm-features",{method:"POST",headers:f,body:JSON.stringify({action:"title",message:u}),signal:c.signal});if(!d.ok)throw new Error(`API error: ${d.status}`);const p=await d.json();if(c.signal.aborted)throw new Error("Aborted");const g=p.title||u.slice(0,50),b=p.source||"heuristic";return i(g),o(b),{title:g,source:b,error:p.error}}catch(f){if(f instanceof Error&&f.name==="AbortError")throw f;const d=Pb(u);return i(d),o("heuristic"),{title:d,source:"heuristic",error:f instanceof Error?f.message:"Unknown error"}}finally{n(!1),a.current===c&&(a.current=null)}},[e.llmApiKey,e.llmBaseUrl,e.llmModel,e.llmProvider]),isGenerating:t,lastTitle:r,lastSource:s}}function Pb(e){let t=e.replace(/```[\s\S]*?```/g," ");t=t.replace(/`[^`]+`/g," "),t=t.replace(/https?:\/\/[^\s]+/g," "),t=t.replace(/[^\w\s.,!?'-]/g," "),t=t.replace(/\s+/g," ").trim();let i=t.split(/\s+/).filter(s=>{if(s.length<=2){const o=s.toUpperCase();return["AI","ML","UI","UX","API","CSS","JS"].includes(o)}return!0}).slice(0,6).join(" ");return i=i.replace(/[.,!?]+$/,""),i.length>60&&(i=i.slice(0,57)+"..."),i||e.slice(0,50)}function _b(){return Nt(e=>e.settings.useLlmTitles)}const Tr={active:!1,text:"",tools:[],sessionKey:null};function Ob(e){const[t,n]=m.useState(Tr),r=m.useRef(null),i=m.useRef(e.onDone),s=m.useRef(e.onError);i.current=e.onDone,s.current=e.onError;const o=m.useCallback(l=>{if(r.current&&(r.current.close(),r.current=null),l?.preserveState){n(u=>({...u,active:!1}));return}n(Tr)},[]),a=m.useCallback(l=>{r.current&&(r.current.close(),r.current=null),n({active:!0,text:"",tools:[],sessionKey:l});const u=new EventSource(`/api/stream?sessionKey=${encodeURIComponent(l)}`);r.current=u,u.addEventListener("delta",c=>{try{const f=JSON.parse(c.data);n(d=>({...d,text:d.text+f.text}))}catch{}}),u.addEventListener("tool",c=>{try{const f=JSON.parse(c.data);n(d=>{const p=d.tools.findIndex(b=>b.id===f.id),g=[...d.tools];return p>=0?g[p]={name:f.name,status:f.status,id:f.id}:g.push({name:f.name,status:f.status,id:f.id}),{...d,tools:g}})}catch{}}),u.addEventListener("done",c=>{try{const f=JSON.parse(c.data);u.close(),r.current=null,n(d=>({...d,active:!1})),i.current(f.sessionKey)}catch{}}),u.onerror=()=>{u.readyState===EventSource.CLOSED&&(u.close(),r.current=null,n(Tr),s.current?.("Stream connection lost"))}},[]);return{streaming:t,startStream:a,stopStream:o}}function Fb(e){const t=m.useCallback(n=>{const r=n.target,i=r.tagName==="INPUT"||r.tagName==="TEXTAREA"||r.isContentEditable;if(n.key==="Escape"){e.onEscape?.();return}if(n.key==="?"&&!i&&!n.metaKey&&!n.ctrlKey){n.preventDefault(),e.onShowHelp?.();return}if(i)return;const o=navigator.platform.toUpperCase().indexOf("MAC")>=0?n.metaKey:n.ctrlKey;if(o&&n.key==="k"&&!n.shiftKey){n.preventDefault(),e.onNewChat?.();return}if(o&&n.key==="/"){n.preventDefault(),e.onFocusInput?.();return}if(o&&n.shiftKey&&n.key==="C"){n.preventDefault(),e.onCopyLastResponse?.();return}if(o&&n.key==="f"&&!n.shiftKey){n.preventDefault(),e.onSearch?.();return}if(o&&n.shiftKey&&n.key==="F"){n.preventDefault(),e.onSearchGlobal?.();return}},[e]);m.useEffect(()=>(window.addEventListener("keydown",t),()=>{window.removeEventListener("keydown",t)}),[t])}function qs(e){const{threshold:t=50,edgeWidth:n,onMove:r,onSwipe:i,onCancel:s,direction:o,enabled:a=!0}=e,l=m.useRef({startX:0,startY:0,tracking:!1,directionLocked:!1}),u=m.useCallback(d=>{if(!a)return;const p=d.touches[0];p&&(n!==void 0&&p.clientX>n||(l.current={startX:p.clientX,startY:p.clientY,tracking:!0,directionLocked:!1}))},[a,n]),c=m.useCallback(d=>{const p=l.current;if(!p.tracking)return;const g=d.touches[0];if(!g)return;const b=g.clientX-p.startX,w=g.clientY-p.startY,k=Math.abs(b),C=Math.abs(w);if(!p.directionLocked){if(k<5&&C<5)return;if(C>k){p.tracking=!1,s?.();return}p.directionLocked=!0}o==="left"&&b>0||o==="right"&&b<0||(d.preventDefault(),r?.(b))},[o,r,s]),f=m.useCallback(d=>{const p=l.current;if(!p.tracking)return;p.tracking=!1;const g=d.changedTouches[0];if(!g){s?.();return}const b=g.clientX-p.startX,w=Math.abs(b);if(!p.directionLocked||w<t){s?.();return}const k=b>0?"right":"left";if(o&&k!==o){s?.();return}i(k)},[o,s,i,t]);return{onTouchStart:u,onTouchMove:c,onTouchEnd:f}}const $b=m.lazy(()=>Fn(()=>import("./keyboard-shortcuts-dialog-DEknElTu.js"),__vite__mapDeps([10,1,3,2,4,5])).then(e=>({default:e.KeyboardShortcutsDialog}))),Bb=m.lazy(()=>Fn(()=>import("./search-dialog-40gW31ca.js"),__vite__mapDeps([11,1,2,3,4,5,7,8])).then(e=>({default:e.SearchDialog})));function Hb({activeFriendlyId:e,isNewChat:t=!1,onSessionResolved:n,forcedSessionKey:r}){const i=Ws(),s=qt(),[o,a]=m.useState(!1),[l,u]=m.useState(!1),[c,f]=m.useState(null),[d,p]=m.useState(!1),{headerRef:g,composerRef:b,mainRef:w,pinGroupMinHeight:k,headerHeight:C}=Rb(),[E,N]=m.useState(()=>sr()||or()),[_,S]=m.useState(()=>sr()||or()),[M,U]=m.useState(!1),[O,v]=m.useState(!1),[L,A]=m.useState("global"),[F,T]=m.useState(!1),j=qr(B=>B.level),R=m.useRef(null),D=m.useRef(null),H=m.useRef(null),z=m.useRef(""),x=m.useRef(()=>{}),V=m.useRef(!1),{isMobile:X}=Mb(s),{sessionsQuery:y,sessions:Q,activeExists:ne,activeSessionKey:W,activeTitle:me,activeTokens:ge,sessionsError:le}=Db({activeFriendlyId:e,isNewChat:t,forcedSessionKey:r}),{historyQuery:ie,historyMessages:be,displayMessages:ke,historyError:we,resolvedSessionKey:Se,activeCanonicalKey:K,sessionKeyForHistory:Z}=Nb({activeFriendlyId:e,activeSessionKey:W,forcedSessionKey:r,isNewChat:t,isRedirecting:d,activeExists:ne,sessionsReady:y.isSuccess,queryClient:s}),$=En({queryKey:kl,queryFn:function(){return Ni(s)},initialData:function(){return Ni(s)},staleTime:1/0}),ue=En({queryKey:["gateway","status"],queryFn:yu,retry:!1,refetchOnWindowFocus:!1,refetchOnReconnect:!1,refetchOnMount:"always"}),re=m.useRef(Date.now()),pe=ue.error instanceof Error?ue.error.message:ue.data&&!ue.data.ok?ue.data.error||"Gateway unavailable":null,Be=pe??le??we,Ee=m.useCallback(()=>{ue.refetch()},[ue]),Le=$.data?.isSidebarCollapsed??!1,st=qs({enabled:X&&Le,edgeWidth:40,threshold:50,direction:"right",onSwipe:()=>{pt(s,B=>({...B,isSidebarCollapsed:!1}))}}),et=qs({enabled:X&&!Le,threshold:50,direction:"left",onSwipe:()=>{pt(s,B=>({...B,isSidebarCollapsed:!0}))}}),I=m.useCallback(()=>{f(null),p(!0),i({to:"/new",replace:!0})},[i]),P=m.useCallback(()=>{D.current&&(window.clearInterval(D.current),D.current=null),H.current&&(window.clearTimeout(H.current),H.current=null)},[]),Y=m.useCallback(()=>{P(),Vt(!1),N(!1),T(!1)},[P]),ee=_b(),{generateTitle:ae}=zb(),Te=m.useRef(new Set),He=150,Oe=600,Xe=m.useCallback(()=>{!e||t||(D.current&&window.clearInterval(D.current),T(!0),D.current=window.setInterval(()=>{x.current()},He))},[e,t]),Ue=m.useRef(()=>{}),Ce=m.useRef(()=>{}),{streaming:je,startStream:ze,stopStream:bt}=Ob({onDone:B=>Ue.current(B),onError:B=>Ce.current(B)});Ue.current=m.useCallback(async B=>{await ie.refetch(),bt({preserveState:!0}),Y(),s.invalidateQueries({queryKey:ye.sessions})},[ie,s,bt,Y]),Ce.current=m.useCallback(B=>{console.warn("[stream] SSE error, falling back to polling")},[]);const zt=m.useMemo(()=>{if(!je.text)return null;const B=[];for(const J of je.tools)B.push({type:"toolCall",name:J.name,id:J.id});return B.push({type:"text",text:je.text}),{role:"assistant",content:B,id:"__streaming__",__streaming:!0,timestamp:Date.now()}},[je.text,je.tools]),kt=m.useMemo(()=>{if(!zt)return ke;const B=ke[ke.length-1];if(B?.role==="assistant"){if(Je(B).length>=je.text.length)return ke;const xe=[...ke];return xe[xe.length-1]=zt,xe}return[...ke,zt]},[ke,zt,je.text]),de=m.useMemo(()=>({}),[]);x.current=function(){ie.refetch()},m.useEffect(()=>{if(d){c&&f(null);return}if(Ae){c&&f(null);return}if(y.isSuccess&&!ne){c&&f(null);return}const B=le??we??pe;if(!B){c?.startsWith("Failed to load")&&f(null);return}Di(B)&&i({to:"/connect",replace:!0});const J=le?`Failed to load sessions. ${le}`:we?`Failed to load history. ${we}`:pe?`Gateway unavailable. ${pe}`:null;J&&f(J)},[c,pe,we,d,i,le]);const Ae=!t&&!r&&!To(e)&&y.isSuccess&&Q.length>0&&!Q.some(B=>B.friendlyId===e)&&!ie.isFetching&&!ie.isSuccess;m.useEffect(()=>{if(d){if(t){p(!1);return}!Ae&&y.isSuccess&&p(!1)}},[t,d,y.isSuccess,Ae]),m.useEffect(()=>{t||y.isSuccess&&Q.length!==0&&Ae&&(Nn(),Rr(s,e,Z),i({to:"/new",replace:!0}))},[e,ie.isFetching,ie.isSuccess,t,i,s,Z,Q,y.isSuccess,Ae]);const wt=Ae||d,ut=m.useRef("fast");m.useEffect(()=>{const B=be[be.length-1];if(!B||B.role!=="assistant")return;const J=`${be.length}:${Je(B).slice(-64)}`;J!==z.current&&(z.current=J,ut.current!=="fast"&&D.current&&(window.clearInterval(D.current),D.current=window.setInterval(()=>{x.current()},He),ut.current="fast"),H.current&&window.clearTimeout(H.current),H.current=window.setTimeout(()=>{D.current&&(window.clearInterval(D.current),D.current=window.setInterval(()=>{x.current()},Oe),ut.current="slow"),H.current=window.setTimeout(()=>{Y(),ut.current="fast"},3e3)},1500))},[be,Y]),m.useEffect(()=>{if(!ee||t||d)return;const B=r||Se||W;if(!B||Te.current.has(B))return;const J=be.filter(Pe=>Pe.role==="user"),xe=be.filter(Pe=>Pe.role==="assistant");if(J.length===0||xe.length===0||J.length!==1)return;const tt=Je(J[0]);!tt||tt.length<5||(Te.current.add(B),(async()=>{try{const Pe=await ae(tt);Pe.title&&await vu(s,B,e,Pe.title)}catch(Pe){console.error("[smart-title] Error generating title:",Pe)}})())},[ee,t,d,r,Se,W,e,be,ae,s]),m.useEffect(()=>{if(t||e){if(V.current){V.current=!1;return}if(sr()||or()){N(!0),S(!0);return}P(),bt(),z.current="",N(!1),S(!1),T(!1)}},[e,t,P,bt]),m.useLayoutEffect(()=>{if(t)return;const B=Pc(r||Se||W,e);if(!B)return;V.current=!0;const J=ye.history(B.friendlyId,B.sessionKey),xe=s.getQueryData(J);(Array.isArray(xe?.messages)?xe.messages:[]).some(St=>!!(B.optimisticMessage.clientId&&(St.clientId===B.optimisticMessage.clientId||St.__optimisticId===B.optimisticMessage.clientId)||B.optimisticMessage.__optimisticId&&St.__optimisticId===B.optimisticMessage.__optimisticId))||tr(s,B.friendlyId,B.sessionKey,B.optimisticMessage),N(!0),S(!0),Jn(B.sessionKey,B.friendlyId,B.message,!0,B.attachments)},[e,W,r,t,s,Se]);function Jn(B,J,xe,tt=!1,Pe,St){let Pt="";if(!tt){const{clientId:Ie,optimisticMessage:Wt}=zi(xe,Pe);Pt=Ie,tr(s,J,B,Wt),Su(s,B,J,Wt)}Vt(!0),a(!0),f(null),N(!0),S(!0);const ct=Pe?.map(Ie=>({mimeType:Ie.file.type,content:Ie.base64}));ze(B),Xe(),fetch("/api/send",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({sessionKey:B,friendlyId:J,message:xe,thinking:j,idempotencyKey:crypto.randomUUID(),attachments:ct,model:St||void 0})}).then(async Ie=>{if(!Ie.ok)throw new Error(await rt(Ie))}).catch(Ie=>{const Wt=Ie instanceof Error?Ie.message:String(Ie);if(Di(Wt)){i({to:"/connect",replace:!0});return}Pt&&bu(s,J,B,Pt,function(ol){return{...ol,status:"error"}}),f(`Failed to send message. ${Wt}`),Vt(!1),N(!1),S(!1)}).finally(()=>{a(!1)})}const vi=m.useCallback(async()=>{u(!0);try{const B=await fetch("/api/sessions",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({})});if(!B.ok)throw new Error(await rt(B));const J=await B.json(),xe=typeof J.sessionKey=="string"?J.sessionKey:"",tt=typeof J.friendlyId=="string"&&J.friendlyId.trim().length>0?J.friendlyId.trim():jr(xe);if(!xe||!tt)throw new Error("Invalid session response");return s.invalidateQueries({queryKey:ye.sessions}),{sessionKey:xe,friendlyId:tt}}finally{u(!1)}},[s]),Xa=m.useCallback((B,J)=>{const xe=J.attachments;if(B.length===0&&(!xe||xe.length===0))return;if(J.reset(),t){const{clientId:Pe,optimisticId:St,optimisticMessage:Pt}=zi(B,xe);tr(s,"new","new",Pt),Vt(!0),a(!0),N(!0),S(!0),vi().then(({sessionKey:ct,friendlyId:Ie})=>{if(zc(Ie),Mc({sessionKey:ct,friendlyId:Ie,message:B,optimisticMessage:Pt,attachments:xe}),n){n({sessionKey:ct,friendlyId:Ie});return}i({to:"/chat/$sessionKey",params:{sessionKey:Ie},replace:!0})}).catch(ct=>{ku(s,"new","new",Pe,St),J.setValue(B),f(`Failed to create session. ${ct instanceof Error?ct.message:String(ct)}`),Vt(!1),N(!1),S(!1),a(!1)});return}Jn(r||Se||W,e,B,!1,xe,J.model)},[e,W,vi,r,t,i,n,s,Se]),Ei=m.useCallback(()=>{N(!1),S(!1),Rr(s,"new","new"),i({to:"/new"}),X&&pt(s,function(J){return{...J,isSidebarCollapsed:!0}})},[X,i,s]),Ya=m.useCallback(()=>{pt(s,function(J){return{...J,isSidebarCollapsed:!J.isSidebarCollapsed}})},[s]),Ga=m.useCallback(()=>{X&&pt(s,function(J){return{...J,isSidebarCollapsed:!0}})},[X,s]),Qa=m.useCallback(()=>{pt(s,function(J){return{...J,isSidebarCollapsed:!1}})},[s]),Ja=m.useCallback(B=>{if(t||!B.trim())return;const J=r||Se||W;J&&Jn(J,e,B.trim())},[e,W,r,t,Se]),Za=m.useCallback(()=>{R.current?.focus()},[]),el=m.useCallback(()=>{if(M){U(!1);return}document.activeElement instanceof HTMLElement&&document.activeElement.blur()},[M]),tl=m.useCallback(()=>{const B=[...ke].reverse().find(xe=>xe.role==="assistant");if(!B)return;const J=Je(B);J&&navigator.clipboard.writeText(J).catch(()=>{})},[ke]),nl=m.useCallback(()=>{U(!0)},[]),rl=m.useCallback(()=>{A(t?"global":"current"),v(!0)},[t]),Ti=m.useCallback(()=>{A("global"),v(!0)},[]);Fb({onNewChat:Ei,onFocusInput:Za,onEscape:el,onCopyLastResponse:tl,onShowHelp:nl,onSearch:rl,onSearchGlobal:Ti});const ji=ie.isLoading&&!ie.data||d,Ai=!!pe&&ue.errorUpdatedAt>re.current,il=!ji&&ke.length===0,sl=m.useMemo(()=>!Ai||!Be?null:h.jsx(Ib,{state:"error",error:Be,onRetry:Ee}),[Be,Ee,Ai]),Ii=h.jsx(Xc,{sessions:Q,activeFriendlyId:e,activeSessionKey:Z,creatingSession:l,onCreateSession:Ei,isCollapsed:X?!1:Le,onToggleCollapse:Ya,onSelectSession:Ga,onActiveSessionDelete:I,onOpenSearch:Ti});return h.jsxs("div",{className:"h-screen bg-surface text-primary-900",children:[h.jsxs("div",{className:q("h-full overflow-hidden",X?"relative":"grid grid-cols-[auto_1fr]"),children:[wt?null:X?h.jsxs(h.Fragment,{children:[!Le&&h.jsx("div",{className:"fixed inset-0 z-40 bg-black/40 transition-opacity duration-200",onClick:()=>pt(s,B=>({...B,isSidebarCollapsed:!0})),...et}),h.jsx("div",{className:q("fixed inset-y-0 left-0 z-50 w-[300px] transition-transform duration-150 safe-area-top",Le?"-translate-x-full":"translate-x-0"),...et,children:Ii})]}):Ii,h.jsxs("main",{className:"flex flex-col h-full min-h-0",ref:w,...st,children:[h.jsx(Jc,{activeTitle:me,wrapperRef:g,showSidebarButton:X,onOpenSidebar:Qa,totalTokens:ge.totalTokens,contextTokens:ge.contextTokens}),wt?null:h.jsxs(h.Fragment,{children:[h.jsx(Gy,{messages:kt,loading:ji,empty:il,notice:sl,noticePosition:"end",waitingForResponse:E,isStreaming:F,sessionKey:K,pinToTop:_,pinGroupMinHeight:k,headerHeight:C,contentStyle:de,onFollowUpClick:Ja}),h.jsx(jb,{onSubmit:Xa,isLoading:o,disabled:o,wrapperRef:b,inputRef:R})]})]})]}),M&&h.jsx(m.Suspense,{fallback:null,children:h.jsx($b,{open:M,onOpenChange:U})}),O&&h.jsx(m.Suspense,{fallback:null,children:h.jsx(Bb,{open:O,onOpenChange:v,sessions:Q,currentFriendlyId:e,currentSessionKey:W,mode:L,onJumpToMessage:B=>{v(!1),B.friendlyId&&i({to:"/chat/$sessionKey",params:{sessionKey:B.friendlyId}})}})})]})}function Ub(){const e=qt(),t=Ws(),[n,r]=m.useState(null),i=ul.useParams(),s=typeof i.sessionKey=="string"?i.sessionKey:"main",o=s==="new",a=n?.friendlyId===s?n.sessionKey:void 0,l=m.useCallback(function(c){wu(e,"new","new",c.friendlyId,c.sessionKey),r({friendlyId:c.friendlyId,sessionKey:c.sessionKey}),t({to:"/chat/$sessionKey",params:{sessionKey:c.friendlyId},replace:!0})},[t,e]);return h.jsx(Hb,{activeFriendlyId:s,isNewChat:o,forcedSessionKey:a,onSessionResolved:o?l:void 0})}const e0=Object.freeze(Object.defineProperty({__proto__:null,component:Ub},Symbol.toStringTag,{value:"Module"}));export{e0 as $,Zb as a,ye as c,Fa as g,ec as u};
|
|
96
|
+
${e.slice(0,2e3)}`;return My(C,R.signal).then(z=>{R.signal.aborted||(z.length>0&&(c(z),w("llm")),d(!1))}).catch(z=>{R.signal.aborted||(g(z instanceof Error?z.message:String(z)),d(!1))}),()=>{}},[e,t,s,o,l,r.llmApiKey,r.llmBaseUrl,r.llmModel,r.llmProvider]),{suggestions:u,isLoading:f,error:p,source:y}}function zy({responseText:e,contextSummary:t,onSuggestionClick:n,disabled:r=!1,className:i}){const{suggestions:s,isLoading:o,source:a}=Dy(e,t,{minResponseLength:50,timeoutMs:8e3});return s.length===0&&!o?null:h.jsxs("div",{className:q("flex flex-col gap-2 mt-3",i),children:[h.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-primary-500",children:[h.jsx("span",{className:"text-primary-400",children:"✨"}),h.jsx("span",{children:o?h.jsxs("span",{className:"flex items-center gap-1",children:["Thinking of follow-ups",h.jsx(te,{icon:no,size:12,strokeWidth:2,className:"animate-spin text-primary-400"})]}):a==="llm"?"AI suggestions":"Follow-up suggestions"})]}),h.jsx("div",{className:"flex flex-wrap gap-2",children:s.map((l,u)=>h.jsxs("button",{type:"button",disabled:r,onClick:()=>n(l),className:q("group inline-flex items-center gap-1.5 px-3 py-1.5 rounded-full","text-sm text-primary-700 bg-primary-50 border border-primary-200","hover:bg-primary-100 hover:border-primary-300 hover:text-primary-900","focus:outline-none focus:ring-2 focus:ring-primary-500/20 focus:ring-offset-1","transition-all duration-150 cursor-pointer","disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:bg-primary-50 disabled:hover:border-primary-200",o&&"opacity-75"),children:[h.jsx("span",{children:l}),h.jsx(te,{icon:Wr,size:14,strokeWidth:2,className:"text-primary-400 group-hover:text-primary-600 group-hover:translate-x-0.5 transition-all duration-150"})]},`${u}-${l.slice(0,20)}`))})]})}const $s=m.memo(zy);function Py({className:e,variant:t="outline",scrollRef:n,...r}){const[i,s]=m.useState(!0),[o,a]=m.useState(!1),l=m.useRef(0),u=m.useCallback(()=>{const c=n.current;if(!c)return;const f=Math.abs(c.scrollHeight-c.scrollTop-c.clientHeight)<100;s(f)},[n]);return m.useLayoutEffect(()=>{const c=n.current;if(!c)return;const f=()=>{l.current=c.scrollTop,u()},d=new MutationObserver(()=>{c&&(c.scrollTop!==l.current&&(l.current=c.scrollTop),u())});return u(),c.addEventListener("scroll",f),d.observe(c,{childList:!0,subtree:!0}),()=>{c.removeEventListener("scroll",f),d.disconnect()}},[u,n]),m.useLayoutEffect(()=>{if(i){a(!1);return}const c=window.setTimeout(()=>{a(!0)},200);return()=>window.clearTimeout(c)},[i]),h.jsx(ve,{variant:"secondary",size:"icon-sm",className:q("pointer-events-auto rounded-full shadow-md","transition-all duration-100 ease-in-out",!i&&o?"translate-y-0 scale-100 opacity-100":"pointer-events-none translate-y-4 scale-98 opacity-0",e),onClick:()=>{const c=n.current;c&&(c.scrollTop=c.scrollHeight,s(!0))},...r,children:h.jsx(te,{icon:Xr,size:18,strokeWidth:1.8})})}function _y({className:e,viewportRef:t,scrollRef:n,viewportProps:r}){return h.jsxs(ko,{className:q("relative flex flex-1 min-h-0 flex-col",e),children:[h.jsx(wo,{className:"relative will-change-transform",ref:t,...r}),h.jsx("div",{className:"relative mx-auto w-full max-w-full px-5 sm:max-w-[768px] sm:min-w-[400px] ",children:h.jsx("div",{className:"pointer-events-none absolute bottom-10 right-10 z-50",children:h.jsx(Py,{scrollRef:n})})}),h.jsx(So,{orientation:"vertical",children:h.jsx(Co,{})}),h.jsx(dc,{})]})}function Oy(e,t){if(e===t)return!0;const n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(const i of n)if(e[i]!==t[i])return!1;return!0}function Fy(e,t){return!(e.className!==t.className||e.viewportRef!==t.viewportRef||e.scrollRef!==t.scrollRef||!Oy(e.viewportProps,t.viewportProps))}const $y=m.memo(_y,Fy);function By({viewportNode:e,children:t}){return e?al.createPortal(h.jsx("div",{className:"relative flex w-full flex-col",children:t}),e):null}function Hy({children:e,className:t,onUserScroll:n,...r}){const i=m.useRef(null),[s,o]=m.useState(null),a=m.useCallback(function(u){i.current=u,o(u)},[]);return m.useLayoutEffect(()=>{const l=i.current;if(!l)return;const u=()=>{n?.(l.scrollTop)};return l.addEventListener("scroll",u),()=>l.removeEventListener("scroll",u)},[n]),h.jsxs(h.Fragment,{children:[h.jsx($y,{className:t,viewportRef:a,scrollRef:i,viewportProps:r}),h.jsx(By,{viewportNode:s,children:e})]})}const Uy=m.memo(Hy);function qy({children:e,className:t,...n}){return h.jsx("div",{className:q("flex w-full flex-col min-h-full",t),...n,children:h.jsx("div",{className:"mx-auto w-full max-w-full px-2 md:px-5 sm:max-w-[768px] sm:min-w-[400px] flex flex-col flex-1 min-h-full",children:h.jsx("div",{className:"flex flex-col space-y-3 md:space-y-6",children:e})})})}function Ky({...e}){return h.jsx("div",{className:"h-px w-full shrink-0 scroll-mt-4 pt-6","aria-hidden":"true",...e})}function Wy({as:e="span",className:t,duration:n=4,spread:r=20,children:i,...s}){const o=Math.min(Math.max(r,5),45),a=e;return h.jsx(a,{className:q("bg-size-[200%_auto] bg-clip-text font-medium text-transparent","animate-[shimmer_4s_infinite_linear]",t),style:{backgroundImage:`linear-gradient(to right, var(--color-primary-600) ${50-o}%, var(--color-primary-950) 50%, var(--color-primary-600) ${50+o}%)`,animationDuration:`${n}s`},...s,children:i})}function Vy({className:e}){return h.jsxs("div",{className:q("flex items-center gap-2",e),children:[h.jsxs("div",{className:"relative flex h-1.5 w-1.5",children:[h.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-primary-400 opacity-75"}),h.jsx("span",{className:"relative inline-flex rounded-full h-1.5 w-1.5 bg-size-[200%_auto] animate-[shimmer_2s_infinite_linear]",style:{backgroundImage:"linear-gradient(to right, var(--color-primary-600) 0%, var(--color-primary-950) 50%, var(--color-primary-600) 100%)"}})]}),h.jsx(Wy,{className:"text-sm",duration:2,children:"Generating..."})]})}function Xy({messages:e,loading:t,empty:n,emptyState:r,notice:i,noticePosition:s="start",waitingForResponse:o,isStreaming:a=!1,sessionKey:l,pinToTop:u,pinGroupMinHeight:c,headerHeight:f,contentStyle:d,onFollowUpClick:p}){const g=m.useRef(null),y=m.useRef(null),w=m.useRef(!1),k=m.useRef(u),S=m.useRef(void 0),v=m.useMemo(()=>e.filter(j=>j.role!=="toolResult"),[e]),R=m.useMemo(()=>{const j=new Map;for(const T of e){if(T.role!=="toolResult")continue;const D=T.toolCallId;typeof D=="string"&&D.trim().length>0&&j.set(D,T)}return j},[e]),M=m.useMemo(()=>{const j=H=>H?H.replace(/SECURITY NOTICE:[\s\S]*?<<<EXTERNAL_UNTRUSTED_CONTENT>>>/g,"").replace(/<<<\/?EXTERNAL_UNTRUSTED_CONTENT>>>/g,"").replace(/<<<\/?END_EXTERNAL_UNTRUSTED_CONTENT>>>/g,"").replace(/Source: Web (?:Search|Fetch)\n---/g,"").replace(/\n{2,}/g,`
|
|
97
|
+
`).trim():"",T=(H,_,x)=>{try{const V=JSON.parse(H),X=Array.isArray(V)?V:V?.results??V?.web?.results??[];if(!Array.isArray(X))return!1;let b=!1;for(const Q of X)Q?.url&&Q?.title&&!x.has(Q.url)&&(x.add(Q.url),_.push({title:j(Q.title),url:Q.url,snippet:j(Q.description||Q.snippet||Q.content||"")}),b=!0);return b}catch{return!1}},D=[],L=new Set;for(const H of v){if(H.role!=="assistant")continue;const _=Tt(H);for(const x of _){if(!x.id)continue;const V=x.name==="web_search",X=x.name==="web_fetch",b=x.name==="exec";if(!V&&!X&&!b)continue;const Q=R.get(x.id);if(!Q)continue;const re=Q.content?.map(K=>K.type==="text"?String(K.text??""):"").join("").trim();if(re){if(V||b){if(b&&(!re.includes('"results"')||!re.includes('"url"')))continue;let K=re;const he=re.indexOf("{");he>0&&(K=re.slice(he));const me=K.lastIndexOf("}");me>0&&(K=K.slice(0,me+1)),T(K,D,L)}else if(X){const K=x.arguments?.url;if(K&&!L.has(K)){L.add(K);let he;try{he=new URL(K).hostname}catch{he=K}D.push({title:he,url:K})}}}}}return D},[v,R]),C=v.map((j,T)=>({message:j,index:T})).filter(({message:j})=>j.role!=="user").map(({index:j})=>j).pop(),z=v.map((j,T)=>({message:j,index:T})).filter(({message:j})=>j.role==="user").map(({index:j})=>j).pop(),U=o&&(typeof z!="number"||typeof C!="number"||C<z),F=typeof z=="number"?z:-1,E=u&&F>=0,N=typeof C=="number"?v[C]:void 0,A=N?et(N):"",P=!o&&!a&&A.length>0&&p!==void 0&&(typeof z!="number"||typeof C!="number"||C>z);return m.useLayoutEffect(()=>{if(!t){if(u){const j=!k.current||S.current!==z;k.current=!0,S.current=z,j&&y.current&&(w.current=!0,y.current.scrollIntoView({behavior:"auto",block:"start"}),window.setTimeout(()=>{w.current=!1},0));return}k.current=!1,S.current=z,g.current&&(w.current=!0,g.current.scrollIntoView({behavior:"auto",block:"end"}),window.setTimeout(()=>{w.current=!1},0))}},[t,v.length,l,u,z]),h.jsx(Uy,{className:"flex-1 min-h-0 -mb-4",children:h.jsxs(qy,{className:"pt-6",style:d,children:[i&&s==="start"?i:null,n&&!i?r??h.jsx("div",{"aria-hidden":!0}):E?h.jsxs(h.Fragment,{children:[v.slice(0,F).map((j,T)=>{const D=T,L=typeof C=="number"&&T===C,H=typeof C=="number"&&T===C,_=j.role==="assistant"&&Tt(j).length>0;return h.jsx(Cr,{message:j,toolResultsByCallId:_?R:void 0,forceActionsVisible:L,isStreaming:H&&a,isLastAssistant:H,aggregatedSearchSources:H?M:void 0},D)}),h.jsxs("div",{className:"flex flex-col space-y-3 md:space-y-6",style:{minHeight:`${Math.max(0,c-24)}px`},children:[v.slice(F).map((j,T)=>{const D=F+T,L=D,H=typeof C=="number"&&D===C,_=typeof C=="number"&&D===C,x=D===z?y:void 0,V=D===z?"scroll-mt-0":void 0,X=D===z?f:void 0,b=j.role==="assistant"&&Tt(j).length>0;return h.jsx(Cr,{message:j,toolResultsByCallId:b?R:void 0,forceActionsVisible:H,isStreaming:_&&a,isLastAssistant:_,aggregatedSearchSources:_?M:void 0,wrapperRef:x,wrapperClassName:V,wrapperScrollMarginTop:X},L)}),U?h.jsx("div",{className:"py-2",children:h.jsx(Vy,{})}):null,P&&p?h.jsx($s,{responseText:A,onSuggestionClick:p,disabled:o}):null]})]}):h.jsxs(h.Fragment,{children:[v.map((j,T)=>{const D=T,L=typeof C=="number"&&T===C,H=typeof C=="number"&&T===C,_=j.role==="assistant"&&Tt(j).length>0;return h.jsx(Cr,{message:j,toolResultsByCallId:_?R:void 0,forceActionsVisible:L,isStreaming:H&&a,isLastAssistant:H,aggregatedSearchSources:H?M:void 0},D)}),P&&p?h.jsx($s,{responseText:A,onSuggestionClick:p,disabled:o}):null]}),i&&s==="end"?i:null,h.jsx(Ky,{ref:g})]})})}function Yy(e,t){return e.messages===t.messages&&e.loading===t.loading&&e.empty===t.empty&&e.emptyState===t.emptyState&&e.notice===t.notice&&e.noticePosition===t.noticePosition&&e.waitingForResponse===t.waitingForResponse&&e.isStreaming===t.isStreaming&&e.sessionKey===t.sessionKey&&e.pinToTop===t.pinToTop&&e.pinGroupMinHeight===t.pinGroupMinHeight&&e.headerHeight===t.headerHeight&&e.contentStyle===t.contentStyle&&e.onFollowUpClick===t.onFollowUpClick}const Gy=m.memo(Xy,Yy),Ha=m.createContext({isLoading:!1,value:"",setValue:()=>{},maxHeight:240,onSubmit:void 0,disabled:!1,textareaRef:ll.createRef()});let Ht=null,Bs=!1;function Qy(){Bs||typeof window>"u"||(Bs=!0,window.addEventListener("keydown",e=>{if(e.defaultPrevented||e.metaKey||e.ctrlKey||e.altKey)return;const t=e.target;if(!t)return;const n=t.tagName.toLowerCase();if(n==="input"||n==="textarea"||n==="select"||t.isContentEditable)return;const r=e.key.length===1,i=e.key==="Backspace";!r&&!i||!Ht||Ht.disabled||Ht.focus()}))}function Ua(){return m.useContext(Ha)}function Jy({className:e,isLoading:t=!1,maxHeight:n=240,value:r,onValueChange:i,onSubmit:s,children:o,disabled:a=!1,onClick:l,...u}){const[c,f]=m.useState(r||""),d=m.useRef(null);Qy();function p(y){f(y),i?.(y)}function g(y){a||d.current?.focus(),l?.(y)}return h.jsx(jt,{children:h.jsx(Ha.Provider,{value:{isLoading:t,value:r??c,setValue:i??p,maxHeight:n,onSubmit:s,disabled:a,textareaRef:d},children:h.jsx("div",{onClick:g,className:q("bg-surface cursor-text rounded-[22px] outline outline-ink/10 shadow-[0px_12px_32px_0px_rgba(0,0,0,0.05)] py-3 gap-3 flex flex-col",a&&"cursor-not-allowed opacity-60",e),...u,children:o})})})}function Zy({className:e,onKeyDown:t,disableAutosize:n=!1,inputRef:r,...i}){const{value:s,setValue:o,maxHeight:a,onSubmit:l,disabled:u,textareaRef:c}=Ua();function f(y){!y||n||(y.style.height="auto",typeof a=="number"?y.style.height=`${Math.min(y.scrollHeight,a)}px`:y.style.height=`min(${y.scrollHeight}px, ${a})`)}function d(y){c.current=y,typeof r=="function"?r(y):r&&"current"in r&&(r.current=y),y?Ht=y:Ht===y&&(Ht=null),f(y)}m.useLayoutEffect(()=>{if(!c.current||n)return;const y=c.current;y.style.height="auto",typeof a=="number"?y.style.height=`${Math.min(y.scrollHeight,a)}px`:y.style.height=`min(${y.scrollHeight}px, ${a})`},[s,a,n]);function p(y){f(y.target),o(y.target.value)}function g(y){y.key==="Enter"&&!y.shiftKey&&(y.preventDefault(),l?.()),t?.(y)}return h.jsx("textarea",{ref:d,value:s,onChange:p,onKeyDown:g,className:q("text-primary-950 opencami-text-size min-h-[28px] w-full resize-none border-none bg-transparent shadow-none outline-none focus-visible:ring-0 pl-4 pr-1 placeholder:text-primary-500",e),rows:1,readOnly:u,"aria-disabled":u,...i})}function eb({children:e,className:t,...n}){return h.jsx("div",{className:q("flex items-center gap-2",t),...n,children:e})}function vr({tooltip:e,children:t,className:n,side:r="top",...i}){const{disabled:s}=Ua();return h.jsxs(At,{...i,children:[h.jsx(It,{disabled:s,onClick:o=>o.stopPropagation(),children:t}),h.jsx(Rt,{side:r,className:n,children:e})]})}const qa="opencami-selected-model";function tb(){if(typeof window>"u")return null;try{return localStorage.getItem(qa)}catch{return null}}function nb(e){if(!(typeof window>"u"))try{localStorage.setItem(qa,e)}catch{}}function rb({className:e,onModelChange:t}){const[n,r]=m.useState([]),[i,s]=m.useState(""),[o,a]=m.useState(!0),[l,u]=m.useState(null),c=m.useRef(null);m.useEffect(()=>{let y=!0;async function w(){c.current?.abort();const k=new AbortController;c.current=k;try{a(!0),u(null);const S=await fetch("/api/models",{signal:k.signal});if(!S.ok)throw new Error("Failed to fetch models");const v=await S.json();if(!y)return;if(v.ok&&v.models.length>0){r(v.models);const R=tb(),M=R&&v.models.some(C=>C.id===R)?R:v.defaultModel;s(M),t?.(M)}else throw new Error("No models available")}catch(S){if(S instanceof Error&&S.name==="AbortError"||!y)return;console.error("[model-selector] Error fetching models:",S),u(S instanceof Error?S.message:"Failed to load models"),r([{id:"default",name:"Default Model"}]),s("default")}finally{y&&a(!1)}}return w(),()=>{y=!1,c.current?.abort()}},[t]);function f(y){s(y),nb(y),t?.(y)}if(o)return h.jsxs("div",{className:q("flex items-center gap-2 text-xs text-primary-500",e),children:[h.jsx(te,{icon:er,size:14}),h.jsx("span",{children:"Loading..."})]});if(l||n.length===0)return null;const d=n.find(y=>y.id===i),p=d?.name||"Select Model",g=(()=>{if(!d?.name)return p;const w=d.name.replace(/\s*\([^)]*\)\s*$/,"").trim(),k=w.split(/\s+/);return k.length>3?k.slice(0,3).join(" "):w})();return n.length===1?h.jsxs("div",{className:q("flex items-center gap-2 text-xs text-primary-500",e),children:[h.jsx(te,{icon:er,size:14}),h.jsx("span",{className:"font-[450] md:hidden",children:g}),h.jsx("span",{className:"font-[450] hidden md:inline",children:p})]}):h.jsxs(Bn,{children:[h.jsxs(Hn,{className:q("inline-flex h-7 items-center gap-2 rounded-md px-2 text-xs font-[450] text-primary-600 hover:text-primary-900 hover:bg-primary-100",e),children:[h.jsx(te,{icon:er,size:14}),h.jsx("span",{className:"md:hidden",children:g}),h.jsx("span",{className:"hidden md:inline",children:p})]}),h.jsx(Un,{side:"top",align:"start",children:n.map(y=>h.jsxs(mt,{onClick:()=>f(y.id),className:"justify-between min-w-[180px]",children:[h.jsx("span",{children:y.name}),i===y.id&&h.jsx(te,{icon:Vr,size:14,className:"text-primary-600"})]},y.id))})]})}const Ka="opencami-personas-enabled",Ur="opencami-active-persona";function ib(){if(typeof window>"u")return!0;try{const e=localStorage.getItem(Ka);return e===null?!0:e==="true"}catch{return!0}}function sb(){if(typeof window>"u")return null;try{const e=localStorage.getItem(Ur);return e?JSON.parse(e):null}catch{return null}}function Hs(e){if(!(typeof window>"u"))try{e?localStorage.setItem(Ur,JSON.stringify(e)):localStorage.removeItem(Ur)}catch{}}const ob={core:"Core",creative:"Creative",curator:"Curator",learning:"Learning",lifestyle:"Lifestyle",professional:"Professional"};function ab({className:e,onSelect:t}){const[n,r]=m.useState({}),[i,s]=m.useState(null),[o,a]=m.useState(!0),[l,u]=m.useState(!1),[c,f]=m.useState(ib),d=m.useRef(null);m.useEffect(()=>{const w=k=>{k.key===Ka&&f(k.newValue===null?!0:k.newValue==="true")};return window.addEventListener("storage",w),()=>window.removeEventListener("storage",w)},[]),m.useEffect(()=>{let w=!0;async function k(){d.current?.abort();const S=new AbortController;d.current=S;try{a(!0);const v=await fetch("/api/personas",{signal:S.signal});if(!v.ok){u(!1);return}const R=await v.json();if(!w)return;R.ok&&R.available?(r(R.personas),u(!0),s(sb())):u(!1)}catch(v){if(v instanceof Error&&v.name==="AbortError"||!w)return;u(!1)}finally{w&&a(!1)}}return k(),()=>{w=!1,d.current?.abort()}},[]);const p=m.useCallback(w=>{s(w),Hs(w),t(`/persona ${w.id}`)},[t]),g=m.useCallback(()=>{s(null),Hs(null),t("/persona exit")},[t]);if(o||!l||!c)return null;const y=Object.entries(n);return y.length===0?null:h.jsxs(Bn,{children:[h.jsxs(Hn,{className:q("inline-flex h-7 items-center gap-1.5 rounded-md px-2 text-xs font-[450] text-primary-600 hover:text-primary-900 hover:bg-primary-100",e),children:[h.jsx("span",{className:"text-sm","aria-hidden":"true",children:"🎭"}),i?h.jsxs("span",{className:"flex items-center gap-1",children:[h.jsx("span",{children:i.emoji}),h.jsx("span",{children:i.name})]}):h.jsx("span",{children:"Persona"})]}),h.jsxs(Un,{side:"top",align:"start",className:"w-[300px] max-h-[360px] overflow-y-auto",children:[i&&h.jsxs(h.Fragment,{children:[h.jsxs(mt,{onClick:g,className:"text-red-600 hover:bg-red-50",children:[h.jsx("span",{className:"text-sm",children:"✕"}),h.jsx("span",{children:"Exit Persona"}),h.jsxs("span",{className:"ml-auto text-[10px] text-primary-400",children:[i.emoji," ",i.name]})]}),h.jsx("div",{className:"my-1 h-px bg-primary-200"})]}),y.map(([w,k])=>h.jsxs("div",{children:[h.jsx("div",{className:"px-2 pb-0.5 pt-2 text-[10px] font-semibold uppercase tracking-wider text-primary-400",children:ob[w]??w}),k.map(S=>h.jsxs(mt,{onClick:()=>p(S),className:"justify-between",children:[h.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[h.jsx("span",{className:"text-sm flex-shrink-0",children:S.emoji}),h.jsx("span",{className:"truncate",children:S.name})]}),h.jsx("span",{className:"text-[11px] text-primary-400 truncate ml-2 max-w-[140px]",children:S.description})]},S.id))]},w))]})]})}const lb=[{command:"/new",description:"Start a new conversation",usage:"/new"},{command:"/reset",description:"Reset conversation context",usage:"/reset"},{command:"/abort",description:"Abort current generation",usage:"/abort"},{command:"/status",description:"Show session status card",usage:"/status"},{command:"/usage",description:"Show token usage",usage:"/usage [off|tokens|full]"},{command:"/models",description:"List available models",usage:"/models"},{command:"/agents",description:"List available agents",usage:"/agents"},{command:"/sessions",description:"List active sessions",usage:"/sessions"},{command:"/model",description:"Switch model for this session",usage:"/model <alias>"},{command:"/reasoning",description:"Toggle reasoning mode",usage:"/reasoning [on|off|stream]"},{command:"/think",description:"Set thinking budget",usage:"/think [off|minimal|low|medium|high]"},{command:"/verbose",description:"Toggle verbose output",usage:"/verbose [on|full|off]"},{command:"/tts",description:"Text-to-speech controls",usage:"/tts [status|off|always]"},{command:"/settings",description:"Show current settings",usage:"/settings"},{command:"/help",description:"Show help",usage:"/help"}];function ub({className:e,onCommandSelect:t}){const[n,r]=m.useState(!1);function i(s){t?.(s),r(!1)}return h.jsxs(h.Fragment,{children:[h.jsx(ve,{variant:"ghost",size:"sm",onClick:()=>r(!0),className:q("h-7 w-7 p-0",e),title:"Show commands (Ctrl+/)",children:h.jsx(te,{icon:Li,size:16,className:"text-primary-500"})}),n&&h.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm",children:h.jsxs("div",{className:"bg-white dark:bg-neutral-900 border border-primary-200 dark:border-neutral-700 rounded-xl shadow-2xl w-full max-w-lg max-h-[80vh] overflow-hidden",children:[h.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-primary-200 dark:border-neutral-700 bg-neutral-50 dark:bg-neutral-800",children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx(te,{icon:Li,size:18,className:"text-primary-600 dark:text-primary-400"}),h.jsx("h2",{className:"font-semibold text-primary-900 dark:text-white",children:"Slash Commands"})]}),h.jsx(ve,{variant:"ghost",size:"sm",onClick:()=>r(!1),className:"h-7 w-7 p-0",children:h.jsx(te,{icon:$n,size:16})})]}),h.jsxs("div",{className:"overflow-y-auto max-h-[60vh] p-2 bg-white dark:bg-neutral-900",children:[h.jsx("div",{className:"text-xs text-primary-500 dark:text-neutral-400 px-2 py-1 mb-2",children:"Type these commands in the chat input"}),lb.map(s=>h.jsxs("button",{onClick:()=>i(s.command),className:"w-full flex items-start gap-3 px-3 py-2 rounded-lg hover:bg-primary-100 dark:hover:bg-neutral-800 transition-colors text-left",children:[h.jsx("code",{className:"text-sm font-mono font-medium text-primary-700 dark:text-primary-300 bg-primary-100 dark:bg-neutral-800 px-1.5 py-0.5 rounded min-w-[80px]",children:s.command}),h.jsxs("div",{className:"flex-1 min-w-0",children:[h.jsx("div",{className:"text-sm text-primary-900 dark:text-neutral-100",children:s.description}),s.usage&&s.usage!==s.command&&h.jsx("div",{className:"text-xs text-primary-500 dark:text-neutral-500 font-mono mt-0.5",children:s.usage})]})]},s.command))]}),h.jsx("div",{className:"px-4 py-2 border-t border-primary-200 dark:border-neutral-700 bg-neutral-50 dark:bg-neutral-800",children:h.jsxs("div",{className:"text-xs text-primary-500 dark:text-neutral-400",children:["Press ",h.jsx("kbd",{className:"px-1 py-0.5 bg-primary-200 dark:bg-neutral-700 rounded text-primary-700 dark:text-neutral-300",children:"Esc"})," to close"]})})]})})]})}const cb=10*1024*1024,$t=1280,fb=.75,hb=300*1024,pb=["image/png","image/jpeg","image/gif","image/webp"],db=".png,.jpg,.jpeg,.gif,.webp";function mb(){if(typeof document>"u")return!1;try{const e=document.createElement("canvas");return!!(e.getContext&&e.getContext("2d"))}catch{return!1}}async function gb(e){if(!mb())throw new Error("Image compression not available in this browser");return new Promise((t,n)=>{const r=new Image,i=URL.createObjectURL(e),s=()=>{URL.revokeObjectURL(i)};r.onload=()=>{try{let o=r.width,a=r.height;(o>$t||a>$t)&&(o>a?(a=Math.round(a*$t/o),o=$t):(o=Math.round(o*$t/a),a=$t));const l=document.createElement("canvas");l.width=o,l.height=a;const u=l.getContext("2d");if(!u){s(),n(new Error("Failed to get canvas context"));return}u.drawImage(r,0,0,o,a);const c=e.type==="image/png"?"image/png":"image/jpeg";let f=fb,d=l.toDataURL(c,f);if(c==="image/jpeg"){const g=hb*1.37;for(;d.length>g&&f>.3;)f-=.1,d=l.toDataURL(c,f)}const p=d.split(",")[1];if(!p){s(),n(new Error("Failed to encode image"));return}s(),t(p)}catch(o){s(),n(o instanceof Error?o:new Error("Image compression failed"))}},r.onerror=()=>{s(),n(new Error("Failed to load image"))},r.src=i})}function Wa(e){return pb.includes(e.type)}async function Va(e){const t=crypto.randomUUID();if(!Wa(e))return{id:t,file:e,preview:null,type:"image",base64:null,error:"Unsupported file type. Please use PNG, JPG, GIF, or WebP images."};if(e.size>cb)return{id:t,file:e,preview:null,type:"image",base64:null,error:"Image is too large. Maximum size is 10MB."};try{const n=await gb(e),r=URL.createObjectURL(e);return{id:t,file:e,preview:r,type:"image",base64:n}}catch(n){return{id:t,file:e,preview:null,type:"image",base64:null,error:n instanceof Error?n.message:"Failed to process image"}}}function xb({onFileSelect:e,disabled:t=!1,className:n}){const r=m.useRef(null),i=m.useCallback(()=>{r.current?.click()},[]),s=m.useCallback(async o=>{const a=o.target.files?.[0];if(!a)return;o.target.value="";const l=await Va(a);e(l)},[e]);return h.jsxs(h.Fragment,{children:[h.jsx("input",{ref:r,type:"file",accept:db,onChange:s,className:"hidden","aria-hidden":"true"}),h.jsx(ve,{variant:"ghost",size:"icon-sm",onClick:i,disabled:t,className:n,"aria-label":"Attach image",type:"button",children:h.jsx(te,{icon:_l,size:18,strokeWidth:1.8})})]})}function yb(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function bb(e){const t=e.split(".");return t.length>1&&t.pop()?.toUpperCase()||""}function kb({attachment:e,onRemove:t,className:n}){m.useEffect(()=>()=>{e.preview&&URL.revokeObjectURL(e.preview)},[e.preview]);const r=!!e.error;return h.jsxs("div",{className:q("relative flex items-center gap-3 rounded-xl border p-2 pr-3",r?"border-red-300 bg-red-50":"border-primary-200 bg-primary-50",n),children:[h.jsx("div",{className:"relative shrink-0",children:e.type==="image"&&e.preview?h.jsx("img",{src:e.preview,alt:e.file.name,className:"h-12 w-12 rounded-lg object-cover"}):h.jsx("div",{className:"flex h-12 w-12 items-center justify-center rounded-lg bg-primary-100",children:h.jsx(te,{icon:Ol,size:24,className:"text-primary-500"})})}),h.jsxs("div",{className:"min-w-0 flex-1",children:[h.jsx("p",{className:"truncate text-sm font-medium text-primary-900",children:e.file.name}),r?h.jsx("p",{className:"text-xs text-red-600",children:e.error}):h.jsxs("p",{className:"text-xs text-primary-500",children:[bb(e.file.name)," •"," ",yb(e.file.size)]})]}),h.jsx(ve,{variant:"ghost",size:"icon-sm",onClick:()=>t(e.id),className:"h-6 w-6 shrink-0 rounded-full hover:bg-primary-200","aria-label":"Remove attachment",type:"button",children:h.jsx(te,{icon:$n,size:14})})]})}function wb({attachments:e,onRemove:t,className:n}){return e.length===0?null:h.jsx("div",{className:q("flex flex-col gap-2 px-4",n),children:e.map(r=>h.jsx(kb,{attachment:r,onRemove:t},r.id))})}function Sb({commands:e,selectedIndex:t,onSelect:n,className:r}){return e.length===0?null:h.jsx("div",{className:q("absolute left-2 right-2 md:left-5 md:right-5 bottom-full mb-2 z-20 rounded-xl border border-white/10 bg-neutral-900/95 shadow-2xl backdrop-blur-sm overflow-hidden",r),role:"listbox","aria-label":"Slash commands",children:h.jsx("div",{className:"max-h-56 overflow-y-auto p-1",children:e.map((i,s)=>{const o=s===t;return h.jsx("button",{type:"button",role:"option","aria-selected":o,onMouseDown:a=>{a.preventDefault(),n(i)},className:q("w-full rounded-md px-3 py-2 text-left transition-colors",o?"bg-neutral-800":"hover:bg-neutral-800/80"),children:h.jsxs("div",{className:"flex items-start gap-3",children:[h.jsx("code",{className:"min-w-[90px] font-mono text-xs text-primary-300",children:i.command}),h.jsx("span",{className:"text-xs text-neutral-300",children:i.description})]})},i.command)})})})}const Cb=m.memo(Sb),qr=fo()(co(e=>({level:"low",setLevel:t=>e({level:t})}),{name:"thinking-level"}));function vb(){const e=qr(n=>n.level),t=qr(n=>n.setLevel);return{level:e,setLevel:t}}const Er=[{value:"off",label:"Off",description:"No reasoning",shortLabel:"Off"},{value:"low",label:"Low",description:"Think",shortLabel:"Low"},{value:"medium",label:"Medium",description:"Think harder",shortLabel:"Medium"},{value:"high",label:"High",description:"Ultrathink",shortLabel:"High"}];function Eb({className:e}){const{level:t,setLevel:n}=vb(),r=Er.find(i=>i.value===t)??Er[1];return h.jsxs(Bn,{children:[h.jsxs(Hn,{className:q("inline-flex h-7 items-center gap-2 rounded-md px-2 text-xs font-[450] text-primary-600 hover:text-primary-900 hover:bg-primary-100",e),children:[h.jsx(te,{icon:Zs,size:20,strokeWidth:1.5,className:q(t==="off"?"text-primary-400":"text-primary-700")}),h.jsx("span",{className:"text-pretty",children:r.shortLabel})]}),h.jsx(Un,{side:"top",align:"start",className:"min-w-[190px]",children:Er.map(i=>h.jsxs(mt,{onClick:()=>n(i.value),className:"justify-between",children:[h.jsxs("span",{className:"flex flex-col text-pretty",children:[h.jsx("span",{className:"text-sm text-primary-900",children:i.label}),h.jsx("span",{className:"text-xs text-primary-500",children:i.description})]}),t===i.value&&h.jsx(te,{icon:Vr,size:20,strokeWidth:1.5,className:"text-primary-600"})]},i.value))})]})}const Us=[{command:"/haiku",description:"Switch to Claude Haiku 4.5"},{command:"/sonnet",description:"Switch to Claude Sonnet 4.5"},{command:"/opus",description:"Switch to Claude Opus 4.5"},{command:"/opus46",description:"Switch to Claude Opus 4.6"},{command:"/codex",description:"Switch to GPT 5.3 Codex"},{command:"/glm",description:"Switch to GLM 4.7"},{command:"/kimi",description:"Switch to Kimi K2.5"},{command:"/minimax",description:"Switch to MiniMax M2.1"},{command:"/grok",description:"Switch to Grok 4.1 Fast"},{command:"/model",description:"Show model picker or switch model"},{command:"/new",description:"New chat (optional: /new model)"},{command:"/reset",description:"Reset session"},{command:"/stop",description:"Stop current generation"},{command:"/compact",description:"Compact conversation context"},{command:"/help",description:"Show available commands"},{command:"/commands",description:"List all commands"},{command:"/status",description:"Show session status & usage"},{command:"/whoami",description:"Show your sender ID"},{command:"/context",description:"Show context window details"},{command:"/usage",description:"Toggle usage footer (off/tokens/full/cost)"},{command:"/think",description:"Set thinking level (off/low/medium/high)"},{command:"/reasoning",description:"Toggle reasoning (on/off/stream)"},{command:"/verbose",description:"Toggle verbose mode (on/full/off)"},{command:"/elevated",description:"Toggle elevated permissions (on/off/ask)"},{command:"/exec",description:"Configure exec settings"},{command:"/queue",description:"Show/configure message queue"},{command:"/tts",description:"Text-to-speech (off/always/tagged/status)"},{command:"/subagents",description:"List/stop/log sub-agent runs"},{command:"/followups",description:"Show follow-up suggestions"},{command:"/skill",description:"Run a skill by name"},{command:"/allowlist",description:"List/add/remove allowlist entries"},{command:"/approve",description:"Resolve exec approval (allow/deny)"},{command:"/config",description:"Show/get/set config (owner-only)"},{command:"/debug",description:"Runtime overrides (owner-only)"},{command:"/send",description:"Toggle message sending (on/off)"},{command:"/restart",description:"Restart gateway"},{command:"/activation",description:"Set activation mode (mention/always)"},{command:"/dock-telegram",description:"Switch replies to Telegram"},{command:"/dock-discord",description:"Switch replies to Discord"},{command:"/bash",description:"Run host shell command"}];function Tb({onSubmit:e,isLoading:t,disabled:n,wrapperRef:r,inputRef:i}){const[s,o]=m.useState(""),[a,l]=m.useState(""),[u,c]=m.useState([]),[f,d]=m.useState(0),[p,g]=m.useState(!1),[y,w]=m.useState(!1),[k,S]=m.useState(!1),[v,R]=m.useState(0),[M,C]=m.useState(!1),z=m.useRef(null),U=m.useRef([]),F=m.useRef(null),E=m.useRef(null),N=m.useRef(null),A=m.useRef(null),P=m.useMemo(()=>/^\/\S*$/.test(s)&&!p,[s,p]),j=m.useMemo(()=>P?s.slice(1).toLowerCase():"",[P,s]),T=m.useMemo(()=>P?j?Us.filter(W=>W.command.slice(1).toLowerCase().startsWith(j)):Us:[],[P,j]),D=m.useCallback(W=>{A.current=W,i&&(typeof i=="function"?i(W):i.current=W)},[i]),L=m.useCallback(()=>{typeof window>"u"||window.requestAnimationFrame(()=>{A.current?.focus()})},[]),H=m.useCallback(()=>{o(""),c([]),d(0),g(!1),L()},[L]),_=m.useCallback(W=>{c($=>[...$,W])},[]),x=m.useCallback(W=>{c($=>$.filter(J=>J.id!==W))},[]),V=m.useCallback(W=>{Array.from(W.dataTransfer.types).includes("Files")&&(W.preventDefault(),W.dataTransfer.dropEffect="copy",w(!0))},[]),X=m.useCallback(W=>{W.preventDefault();const $=W.relatedTarget;$&&W.currentTarget.contains($)||w(!1)},[]),b=m.useCallback(async W=>{W.preventDefault(),w(!1);const $=Array.from(W.dataTransfer.files??[]);if($.length===0)return;const J=$.filter(ne=>Wa(ne));if(J.length===0)return;const xe=await Promise.all(J.map(ne=>Va(ne)));c(ne=>[...ne,...xe]),L()},[L]),Q=m.useCallback(W=>{o(W),d(0),g(!1),L()},[L]),re=m.useCallback(W=>{o(W),d(0),g(!1)},[]),K=m.useCallback(W=>{o(`${W.command} `),d(0),g(!1),L()},[L]),he=m.useCallback(()=>{if(n)return;if(P&&T.length>0){const J=Math.min(f,T.length-1);K(T[J]);return}const W=s.trim(),$=u.filter(J=>!J.error&&J.base64);W.length===0&&$.length===0||(e(W,{reset:H,setValue:Q,model:a||void 0,attachments:$}),L())},[n,P,T,f,K,s,u,e,H,Q,a,L]),me=m.useCallback(W=>{e(W,{reset:H,setValue:Q,model:a||void 0,attachments:[]}),L()},[L,e,H,Q,a]),ue=m.useCallback(W=>{if(P){if(W.key==="Escape"){W.preventDefault(),g(!0),d(0);return}if(T.length!==0){if(W.key==="ArrowDown"){W.preventDefault(),d($=>($+1)%T.length);return}if(W.key==="ArrowUp"){W.preventDefault(),d($=>($-1+T.length)%T.length);return}if(W.key==="Tab"){W.preventDefault();const $=Math.min(f,T.length-1);K(T[$])}}}},[P,T,f,K]);m.useEffect(()=>()=>{E.current?.abort(),F.current&&clearInterval(F.current),z.current&&z.current.state!=="inactive"&&z.current.stop(),N.current&&N.current.abort()},[]);const se=m.useCallback(()=>{if(typeof window>"u")return"auto";try{return localStorage.getItem("opencami-stt-provider")||"auto"}catch{return"auto"}},[]),ge=m.useCallback(()=>{z.current&&z.current.state!=="inactive"&&z.current.stop(),N.current&&N.current.stop(),F.current&&(clearInterval(F.current),F.current=null),S(!1),R(0)},[]),ke=m.useCallback(async()=>{const W=se();if(W==="browser"){const $=window.SpeechRecognition||window.webkitSpeechRecognition;if(!$){alert("Web Speech API is not supported in this browser.");return}const J=new $;J.continuous=!0,J.interimResults=!1,J.lang=navigator.language||"en-US",N.current=J,S(!0),R(0),F.current=setInterval(()=>{R(ne=>ne>=119?(ge(),0):ne+1)},1e3);let xe="";J.onresult=ne=>{for(let pe=ne.resultIndex;pe<ne.results.length;pe++)ne.results[pe].isFinal&&(xe+=ne.results[pe][0].transcript)},J.onend=()=>{S(!1),R(0),F.current&&clearInterval(F.current),xe.trim()&&(o(ne=>ne+(ne?" ":"")+xe.trim()),L())},J.onerror=()=>{S(!1),R(0),F.current&&clearInterval(F.current)},J.start();return}try{const $=await navigator.mediaDevices.getUserMedia({audio:!0}),J=MediaRecorder.isTypeSupported("audio/webm")?"audio/webm":"audio/mp4",xe=new MediaRecorder($,{mimeType:J});z.current=xe,U.current=[],xe.ondataavailable=ne=>{ne.data.size>0&&U.current.push(ne.data)},xe.onstop=async()=>{$.getTracks().forEach(pe=>pe.stop());const ne=new Blob(U.current,{type:J});if(ne.size!==0){C(!0);try{const pe=new FormData;pe.append("audio",ne,`recording.${J==="audio/webm"?"webm":"mp4"}`),W!=="auto"&&pe.append("provider",W),E.current?.abort();const Oe=new AbortController;E.current=Oe;const Ae=await(await fetch("/api/stt",{method:"POST",body:pe,signal:Oe.signal})).json();Ae.ok&&Ae.text?(o($e=>$e+($e?" ":"")+Ae.text),L()):Ae.ok||(console.warn("STT failed:",Ae.error),alert(Ae.error||"Speech-to-text failed. Try the Browser provider in Settings."))}catch(pe){if(pe instanceof Error&&pe.name==="AbortError")return;console.warn("STT request failed:",pe),alert("Could not reach speech-to-text service.")}finally{C(!1)}}},S(!0),R(0),F.current=setInterval(()=>{R(ne=>ne>=119?(ge(),0):ne+1)},1e3),xe.start()}catch($){const J=$ instanceof Error?$.message:String($);if(J.includes("NotAllowedError")||J.includes("Permission"))try{(await navigator.permissions.query({name:"microphone"})).state==="denied"?alert("Microphone access is blocked. Please enable it in your browser/app settings."):alert("Microphone permission was not granted. Please try again and allow access when prompted.")}catch{alert("Could not access microphone. Please check your browser settings and allow microphone access for this site.")}else alert("Could not access microphone: "+J)}},[se,ge,L]),we=m.useCallback(()=>{k?ge():ke()},[k,ge,ke]),Se=u.filter(W=>!W.error&&W.base64),Le=n||s.trim().length===0&&Se.length===0;return h.jsxs("div",{className:"mx-auto w-full max-w-full px-2 md:px-5 sm:max-w-[768px] sm:min-w-[400px] relative pb-1 md:pb-3",ref:r,onDragOver:V,onDragLeave:X,onDrop:b,children:[y&&h.jsx("div",{className:"pointer-events-none absolute inset-2 z-20 flex items-center justify-center rounded-2xl border-2 border-dashed border-primary-400 bg-primary-50/90 text-sm font-medium text-primary-700",children:"Drop image here"}),h.jsxs(Jy,{value:s,onValueChange:re,onSubmit:he,isLoading:t,disabled:n,children:[h.jsx(wb,{attachments:u,onRemove:x}),P&&T.length>0&&h.jsx(Cb,{commands:T,selectedIndex:Math.min(f,T.length-1),onSelect:K}),h.jsx(Zy,{placeholder:"Type a message…",inputRef:D,onKeyDown:ue}),h.jsxs(eb,{className:"justify-between px-3",children:[h.jsxs("div",{className:"flex items-center gap-1",children:[h.jsx(rb,{onModelChange:l}),h.jsx(Eb,{}),h.jsx(ab,{onSelect:me}),h.jsx(ub,{onCommandSelect:W=>re(W+" ")})]}),h.jsxs("div",{className:"flex items-center gap-1",children:[h.jsx(vr,{tooltip:"Attach file",children:h.jsx(xb,{onFileSelect:_,disabled:n})}),h.jsx(vr,{tooltip:k?"Stop recording":"Voice input",children:h.jsx(ve,{onClick:we,disabled:n||M,size:"icon-sm",variant:k?"destructive":"ghost",className:`rounded-full ${k?"animate-pulse":""}`,"aria-label":k?"Stop recording":"Voice input",children:M?h.jsx("span",{className:"size-4 animate-spin rounded-full border-2 border-current border-t-transparent"}):k?h.jsxs("span",{className:"flex items-center gap-1",children:[h.jsx("span",{className:"size-2 rounded-full bg-red-500"}),h.jsxs("span",{className:"text-xs tabular-nums",children:[Math.floor(v/60),":",String(v%60).padStart(2,"0")]}),h.jsx(te,{icon:to,size:14,strokeWidth:2})]}):h.jsx(te,{icon:Fl,size:18,strokeWidth:2})})}),h.jsx(vr,{tooltip:"Send message",children:h.jsx(ve,{onClick:he,disabled:Le,size:"icon-sm",className:"rounded-full","aria-label":"Send message",children:h.jsx(te,{icon:$l,size:18,strokeWidth:2})})})]})]})]})]})}const jb=m.memo(Tb);function Ab({title:e,description:t,detail:n,actionLabel:r,onAction:i,className:s}){return h.jsx("div",{className:q("w-full max-w-[900px]",s),children:h.jsx(Oa,{children:h.jsxs("div",{className:"w-full rounded-xl border border-primary-200 bg-primary-50 p-4 text-primary-900",children:[h.jsx("div",{className:"text-balance font-medium",children:e}),h.jsx("div",{className:"mt-2 text-pretty text-primary-700",children:t}),n?h.jsx("div",{className:"mt-2 text-xs text-primary-600",children:n}):null,r&&i?h.jsx("div",{className:"mt-3",children:h.jsx(ve,{size:"sm",variant:"outline",onClick:i,children:r})}):null]})})})}function Ib({state:e,error:t,onRetry:n,className:r}){const i=e==="checking",s=i?"Checking gateway connection...":"OpenClaw gateway is unreachable",o=i?"This dashboard needs access to the OpenClaw gateway configured by your server environment variables.":"";return h.jsx(Ab,{title:s,description:i?o:h.jsxs(h.Fragment,{children:["We could not reach the gateway from the dashboard server. Start the gateway and confirm your server environment has"," ",h.jsx("span",{className:"font-mono",children:"CLAWDBOT_GATEWAY_URL"})," plus"," ",h.jsx("span",{className:"font-mono",children:"CLAWDBOT_GATEWAY_TOKEN"})," (or"," ",h.jsx("span",{className:"font-mono",children:"CLAWDBOT_GATEWAY_PASSWORD"}),")."]}),detail:i?null:t,actionLabel:i?void 0:"Retry",onAction:i?void 0:n,className:r})}function Rb(){const e=m.useRef(null),t=m.useRef(null),n=m.useRef(null),[r,i]=m.useState(0),[s,o]=m.useState(0);return m.useLayoutEffect(()=>{const a=e.current,l=t.current,u=n.current;if(!u)return;const c=()=>{const d=a?.offsetHeight??0,p=l?.offsetHeight??0,g=u.clientHeight;u.style.setProperty("--chat-header-height",`${Math.max(0,d)}px`),u.style.setProperty("--chat-composer-height",`${Math.max(0,p)}px`),o(d),i(Math.max(0,g-d-p))};c();const f=new ResizeObserver(()=>c());return a&&f.observe(a),l&&f.observe(l),()=>f.disconnect()},[]),{headerRef:e,composerRef:t,mainRef:n,pinGroupMinHeight:r,headerHeight:s}}function Nb({activeFriendlyId:e,activeSessionKey:t,forcedSessionKey:n,isNewChat:r,isRedirecting:i,activeExists:s,sessionsReady:o,queryClient:a}){const l=n||t||e,u=be.history(e,l),c=En({queryKey:u,queryFn:async function(){const S=a.getQueryData(u),v=Array.isArray(S?.messages)?S.messages.filter(C=>C.status==="sending"||C.__optimisticId?!0:!!C.clientId):[],R=await xu({sessionKey:l,friendlyId:e});if(!v.length)return R;const M=Lb(R.messages,v);return{...R,messages:M}},enabled:!r&&!!e&&!i&&(!o||s),placeholderData:function(){return a.getQueryData(u)},gcTime:1e3*60*10}),f=m.useRef(""),d=m.useRef([]),p=m.useMemo(()=>{const k=Array.isArray(c.data?.messages)?c.data.messages:[],S=k[k.length-1],v=S&&typeof S.id=="string"?S.id:"",R=`${k.length}:${S?.role??""}:${v}:${et(S??{content:[]}).slice(-32)}`;return R===f.current?d.current:(f.current=R,d.current=k,k)},[c.data?.messages]),g=c.error instanceof Error?c.error.message:null,y=m.useMemo(()=>{if(n)return n;const k=c.data?.sessionKey;return typeof k=="string"&&k.trim().length>0?k.trim():t},[t,n,c.data?.sessionKey]);return{historyQuery:c,historyMessages:p,displayMessages:p,historyError:g,resolvedSessionKey:y,activeCanonicalKey:r?"new":y||e,sessionKeyForHistory:l}}function Lb(e,t){if(!t.length)return e;const n=[...e];for(const r of t)e.some(s=>{if(r.clientId&&s.clientId&&r.clientId===s.clientId||r.__optimisticId&&s.__optimisticId&&r.__optimisticId===s.__optimisticId)return!0;if(r.role&&s.role&&r.role!==s.role)return!1;const o=et(r);if(!o||o!==et(s))return!1;const a=Ar(r),l=Ar(s);return Math.abs(a-l)<=1e4})||n.push(r);return n}function Mb(e){const[t,n]=m.useState(!1);return m.useLayoutEffect(()=>{const r=window.matchMedia("(max-width: 768px)"),i=()=>n(r.matches);return i(),r.addEventListener("change",i),()=>r.removeEventListener("change",i)},[]),m.useLayoutEffect(()=>{t&&pt(e,function(i){return{...i,isSidebarCollapsed:!0}})},[t,e]),{isMobile:t}}function Db({activeFriendlyId:e,isNewChat:t,forcedSessionKey:n}){const r=En({queryKey:be.sessions,queryFn:gu,refetchInterval:3e4}),i=m.useMemo(()=>{const f=r.data??[];return $c(f)},[r.data]),s=m.useMemo(()=>i.find(f=>f.friendlyId===e),[i,e]),o=m.useMemo(()=>t||n||To(e)?!0:i.some(f=>f.friendlyId===e),[e,n,t,i]),a=s?.key??"",l=m.useMemo(()=>s?s.label||s.title||s.derivedTitle||s.friendlyId:e,[e,s]),u=r.error instanceof Error?r.error.message:null,c=m.useMemo(()=>({totalTokens:s?.totalTokens,contextTokens:s?.contextTokens}),[s?.totalTokens,s?.contextTokens]);return{sessionsQuery:r,sessions:i,activeSession:s,activeExists:o,activeSessionKey:a,activeTitle:l,activeTokens:c,sessionsError:u}}function zb(){const e=Nt(u=>u.settings),[t,n]=m.useState(!1),[r,i]=m.useState(null),[s,o]=m.useState(null),a=m.useRef(null);return{generateTitle:m.useCallback(async u=>{a.current&&a.current.abort();const c=new AbortController;a.current=c,n(!0);try{const f={"Content-Type":"application/json",...Ba()},d=await fetch("/api/llm-features",{method:"POST",headers:f,body:JSON.stringify({action:"title",message:u}),signal:c.signal});if(!d.ok)throw new Error(`API error: ${d.status}`);const p=await d.json();if(c.signal.aborted)throw new Error("Aborted");const g=p.title||u.slice(0,50),y=p.source||"heuristic";return i(g),o(y),{title:g,source:y,error:p.error}}catch(f){if(f instanceof Error&&f.name==="AbortError")throw f;const d=Pb(u);return i(d),o("heuristic"),{title:d,source:"heuristic",error:f instanceof Error?f.message:"Unknown error"}}finally{n(!1),a.current===c&&(a.current=null)}},[e.llmApiKey,e.llmBaseUrl,e.llmModel,e.llmProvider]),isGenerating:t,lastTitle:r,lastSource:s}}function Pb(e){let t=e.replace(/```[\s\S]*?```/g," ");t=t.replace(/`[^`]+`/g," "),t=t.replace(/https?:\/\/[^\s]+/g," "),t=t.replace(/[^\w\s.,!?'-]/g," "),t=t.replace(/\s+/g," ").trim();let i=t.split(/\s+/).filter(s=>{if(s.length<=2){const o=s.toUpperCase();return["AI","ML","UI","UX","API","CSS","JS"].includes(o)}return!0}).slice(0,6).join(" ");return i=i.replace(/[.,!?]+$/,""),i.length>60&&(i=i.slice(0,57)+"..."),i||e.slice(0,50)}function _b(){return Nt(e=>e.settings.useLlmTitles)}const Tr={active:!1,text:"",tools:[],sessionKey:null};function Ob(e){const[t,n]=m.useState(Tr),r=m.useRef(null),i=m.useRef(e.onDone),s=m.useRef(e.onError);i.current=e.onDone,s.current=e.onError;const o=m.useCallback(l=>{if(r.current&&(r.current.close(),r.current=null),l?.preserveState){n(u=>({...u,active:!1}));return}n(Tr)},[]),a=m.useCallback(l=>{r.current&&(r.current.close(),r.current=null),n({active:!0,text:"",tools:[],sessionKey:l});const u=new EventSource(`/api/stream?sessionKey=${encodeURIComponent(l)}`);r.current=u,u.addEventListener("delta",c=>{try{const f=JSON.parse(c.data);n(d=>({...d,text:d.text+f.text}))}catch{}}),u.addEventListener("tool",c=>{try{const f=JSON.parse(c.data);n(d=>{const p=d.tools.findIndex(y=>y.id===f.id),g=[...d.tools];return p>=0?g[p]={name:f.name,status:f.status,id:f.id}:g.push({name:f.name,status:f.status,id:f.id}),{...d,tools:g}})}catch{}}),u.addEventListener("done",c=>{try{const f=JSON.parse(c.data);u.close(),r.current=null,n(d=>({...d,active:!1})),i.current(f.sessionKey)}catch{}}),u.onerror=()=>{u.readyState===EventSource.CLOSED&&(u.close(),r.current=null,n(Tr),s.current?.("Stream connection lost"))}},[]);return{streaming:t,startStream:a,stopStream:o}}function Fb(e){const t=m.useCallback(n=>{const r=n.target,i=r.tagName==="INPUT"||r.tagName==="TEXTAREA"||r.isContentEditable;if(n.key==="Escape"){e.onEscape?.();return}if(n.key==="?"&&!i&&!n.metaKey&&!n.ctrlKey){n.preventDefault(),e.onShowHelp?.();return}if(i)return;const o=navigator.platform.toUpperCase().indexOf("MAC")>=0?n.metaKey:n.ctrlKey;if(o&&n.key==="k"&&!n.shiftKey){n.preventDefault(),e.onNewChat?.();return}if(o&&n.key==="/"){n.preventDefault(),e.onFocusInput?.();return}if(o&&n.shiftKey&&n.key==="C"){n.preventDefault(),e.onCopyLastResponse?.();return}if(o&&n.key==="f"&&!n.shiftKey){n.preventDefault(),e.onSearch?.();return}if(o&&n.shiftKey&&n.key==="F"){n.preventDefault(),e.onSearchGlobal?.();return}},[e]);m.useEffect(()=>(window.addEventListener("keydown",t),()=>{window.removeEventListener("keydown",t)}),[t])}function qs(e){const{threshold:t=50,edgeWidth:n,onMove:r,onSwipe:i,onCancel:s,direction:o,enabled:a=!0}=e,l=m.useRef({startX:0,startY:0,tracking:!1,directionLocked:!1}),u=m.useCallback(d=>{if(!a)return;const p=d.touches[0];p&&(n!==void 0&&p.clientX>n||(l.current={startX:p.clientX,startY:p.clientY,tracking:!0,directionLocked:!1}))},[a,n]),c=m.useCallback(d=>{const p=l.current;if(!p.tracking)return;const g=d.touches[0];if(!g)return;const y=g.clientX-p.startX,w=g.clientY-p.startY,k=Math.abs(y),S=Math.abs(w);if(!p.directionLocked){if(k<5&&S<5)return;if(S>k){p.tracking=!1,s?.();return}p.directionLocked=!0}o==="left"&&y>0||o==="right"&&y<0||(d.preventDefault(),r?.(y))},[o,r,s]),f=m.useCallback(d=>{const p=l.current;if(!p.tracking)return;p.tracking=!1;const g=d.changedTouches[0];if(!g){s?.();return}const y=g.clientX-p.startX,w=Math.abs(y);if(!p.directionLocked||w<t){s?.();return}const k=y>0?"right":"left";if(o&&k!==o){s?.();return}i(k)},[o,s,i,t]);return{onTouchStart:u,onTouchMove:c,onTouchEnd:f}}const $b=m.lazy(()=>Fn(()=>import("./keyboard-shortcuts-dialog-DW--4YLF.js"),__vite__mapDeps([10,1,3,2,4,5])).then(e=>({default:e.KeyboardShortcutsDialog}))),Bb=m.lazy(()=>Fn(()=>import("./search-dialog-DYyFYJmw.js"),__vite__mapDeps([11,1,2,3,4,5,7,8])).then(e=>({default:e.SearchDialog})));function Hb({activeFriendlyId:e,isNewChat:t=!1,onSessionResolved:n,forcedSessionKey:r}){const i=Ws(),s=qt(),[o,a]=m.useState(!1),[l,u]=m.useState(!1),[c,f]=m.useState(null),[d,p]=m.useState(!1),{headerRef:g,composerRef:y,mainRef:w,pinGroupMinHeight:k,headerHeight:S}=Rb(),[v,R]=m.useState(()=>sr()||or()),[M,C]=m.useState(()=>sr()||or()),[z,U]=m.useState(!1),[F,E]=m.useState(!1),[N,A]=m.useState("global"),[P,j]=m.useState(!1),T=qr(B=>B.level),D=m.useRef(null),L=m.useRef(null),H=m.useRef(null),_=m.useRef(""),x=m.useRef(()=>{}),V=m.useRef(!1),{isMobile:X}=Mb(s),{sessionsQuery:b,sessions:Q,activeExists:re,activeSessionKey:K,activeTitle:he,activeTokens:me,sessionsError:ue}=Db({activeFriendlyId:e,isNewChat:t,forcedSessionKey:r}),{historyQuery:se,historyMessages:ge,displayMessages:ke,historyError:we,resolvedSessionKey:Se,activeCanonicalKey:Le,sessionKeyForHistory:W}=Nb({activeFriendlyId:e,activeSessionKey:K,forcedSessionKey:r,isNewChat:t,isRedirecting:d,activeExists:re,sessionsReady:b.isSuccess,queryClient:s}),$=En({queryKey:kl,queryFn:function(){return Ni(s)},initialData:function(){return Ni(s)},staleTime:1/0}),J=En({queryKey:["gateway","status"],queryFn:yu,retry:!1,refetchOnWindowFocus:!1,refetchOnReconnect:!1,refetchOnMount:"always"}),xe=m.useRef(Date.now()),ne=J.error instanceof Error?J.error.message:J.data&&!J.data.ok?J.data.error||"Gateway unavailable":null,pe=ne??ue??we,Oe=m.useCallback(()=>{J.refetch()},[J]),Fe=$.data?.isSidebarCollapsed??!1,Ae=qs({enabled:X&&Fe,edgeWidth:40,threshold:50,direction:"right",onSwipe:()=>{pt(s,B=>({...B,isSidebarCollapsed:!1}))}}),$e=qs({enabled:X&&!Fe,threshold:50,direction:"left",onSwipe:()=>{pt(s,B=>({...B,isSidebarCollapsed:!0}))}}),I=m.useCallback(()=>{f(null),p(!0),i({to:"/new",replace:!0})},[i]),O=m.useCallback(()=>{L.current&&(window.clearInterval(L.current),L.current=null),H.current&&(window.clearTimeout(H.current),H.current=null)},[]),Y=m.useCallback(()=>{O(),Vt(!1),R(!1),j(!1)},[O]),ee=_b(),{generateTitle:ae}=zb(),Ee=m.useRef(new Set),qe=150,Be=600,Ge=m.useCallback(()=>{!e||t||(L.current&&window.clearInterval(L.current),j(!0),L.current=window.setInterval(()=>{x.current()},qe))},[e,t]),Ke=m.useRef(()=>{}),Ce=m.useRef(()=>{}),{streaming:Te,startStream:ze,stopStream:bt}=Ob({onDone:B=>Ke.current(B),onError:B=>Ce.current(B)});Ke.current=m.useCallback(async B=>{await se.refetch(),bt({preserveState:!0}),Y(),s.invalidateQueries({queryKey:be.sessions})},[se,s,bt,Y]),Ce.current=m.useCallback(B=>{console.warn("[stream] SSE error, falling back to polling")},[]);const zt=m.useMemo(()=>{if(!Te.text)return null;const B=[];for(const Z of Te.tools)B.push({type:"toolCall",name:Z.name,id:Z.id});return B.push({type:"text",text:Te.text}),{role:"assistant",content:B,id:"__streaming__",__streaming:!0,timestamp:Date.now()}},[Te.text,Te.tools]),kt=m.useMemo(()=>{if(!zt)return ke;const B=ke[ke.length-1];if(B?.role==="assistant"){if(et(B).length>=Te.text.length)return ke;const ye=[...ke];return ye[ye.length-1]=zt,ye}return[...ke,zt]},[ke,zt,Te.text]),de=m.useMemo(()=>({}),[]);x.current=function(){se.refetch()},m.useEffect(()=>{if(d){c&&f(null);return}if(je){c&&f(null);return}if(b.isSuccess&&!re){c&&f(null);return}const B=ue??we??ne;if(!B){c?.startsWith("Failed to load")&&f(null);return}Di(B)&&i({to:"/connect",replace:!0});const Z=ue?`Failed to load sessions. ${ue}`:we?`Failed to load history. ${we}`:ne?`Gateway unavailable. ${ne}`:null;Z&&f(Z)},[c,ne,we,d,i,ue]);const je=!t&&!r&&!To(e)&&b.isSuccess&&Q.length>0&&!Q.some(B=>B.friendlyId===e)&&!se.isFetching&&!se.isSuccess;m.useEffect(()=>{if(d){if(t){p(!1);return}!je&&b.isSuccess&&p(!1)}},[t,d,b.isSuccess,je]),m.useEffect(()=>{t||b.isSuccess&&Q.length!==0&&je&&(Nn(),Rr(s,e,W),i({to:"/new",replace:!0}))},[e,se.isFetching,se.isSuccess,t,i,s,W,Q,b.isSuccess,je]);const wt=je||d,ut=m.useRef("fast");m.useEffect(()=>{const B=ge[ge.length-1];if(!B||B.role!=="assistant")return;const Z=`${ge.length}:${et(B).slice(-64)}`;Z!==_.current&&(_.current=Z,ut.current!=="fast"&&L.current&&(window.clearInterval(L.current),L.current=window.setInterval(()=>{x.current()},qe),ut.current="fast"),H.current&&window.clearTimeout(H.current),H.current=window.setTimeout(()=>{L.current&&(window.clearInterval(L.current),L.current=window.setInterval(()=>{x.current()},Be),ut.current="slow"),H.current=window.setTimeout(()=>{Y(),ut.current="fast"},3e3)},1500))},[ge,Y]),m.useEffect(()=>{if(!ee||t||d)return;const B=r||Se||K;if(!B||Ee.current.has(B))return;const Z=ge.filter(Pe=>Pe.role==="user"),ye=ge.filter(Pe=>Pe.role==="assistant");if(Z.length===0||ye.length===0||Z.length!==1)return;const nt=et(Z[0]);!nt||nt.length<5||(Ee.current.add(B),(async()=>{try{const Pe=await ae(nt);Pe.title&&await vu(s,B,e,Pe.title)}catch(Pe){console.error("[smart-title] Error generating title:",Pe)}})())},[ee,t,d,r,Se,K,e,ge,ae,s]),m.useEffect(()=>{if(t||e){if(V.current){V.current=!1;return}if(sr()||or()){R(!0),C(!0);return}O(),bt(),_.current="",R(!1),C(!1),j(!1)}},[e,t,O,bt]),m.useLayoutEffect(()=>{if(t)return;const B=Pc(r||Se||K,e);if(!B)return;V.current=!0;const Z=be.history(B.friendlyId,B.sessionKey),ye=s.getQueryData(Z);(Array.isArray(ye?.messages)?ye.messages:[]).some(St=>!!(B.optimisticMessage.clientId&&(St.clientId===B.optimisticMessage.clientId||St.__optimisticId===B.optimisticMessage.clientId)||B.optimisticMessage.__optimisticId&&St.__optimisticId===B.optimisticMessage.__optimisticId))||tr(s,B.friendlyId,B.sessionKey,B.optimisticMessage),R(!0),C(!0),Jn(B.sessionKey,B.friendlyId,B.message,!0,B.attachments)},[e,K,r,t,s,Se]);function Jn(B,Z,ye,nt=!1,Pe,St){let Pt="";if(!nt){const{clientId:Ie,optimisticMessage:Wt}=zi(ye,Pe);Pt=Ie,tr(s,Z,B,Wt),Su(s,B,Z,Wt)}Vt(!0),a(!0),f(null),R(!0),C(!0);const ct=Pe?.map(Ie=>({mimeType:Ie.file.type,content:Ie.base64}));ze(B),Ge(),fetch("/api/send",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({sessionKey:B,friendlyId:Z,message:ye,thinking:T,idempotencyKey:crypto.randomUUID(),attachments:ct,model:St||void 0})}).then(async Ie=>{if(!Ie.ok)throw new Error(await it(Ie))}).catch(Ie=>{const Wt=Ie instanceof Error?Ie.message:String(Ie);if(Di(Wt)){i({to:"/connect",replace:!0});return}Pt&&bu(s,Z,B,Pt,function(ol){return{...ol,status:"error"}}),f(`Failed to send message. ${Wt}`),Vt(!1),R(!1),C(!1)}).finally(()=>{a(!1)})}const vi=m.useCallback(async()=>{u(!0);try{const B=await fetch("/api/sessions",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({})});if(!B.ok)throw new Error(await it(B));const Z=await B.json(),ye=typeof Z.sessionKey=="string"?Z.sessionKey:"",nt=typeof Z.friendlyId=="string"&&Z.friendlyId.trim().length>0?Z.friendlyId.trim():jr(ye);if(!ye||!nt)throw new Error("Invalid session response");return s.invalidateQueries({queryKey:be.sessions}),{sessionKey:ye,friendlyId:nt}}finally{u(!1)}},[s]),Xa=m.useCallback((B,Z)=>{const ye=Z.attachments;if(B.length===0&&(!ye||ye.length===0))return;if(Z.reset(),t){const{clientId:Pe,optimisticId:St,optimisticMessage:Pt}=zi(B,ye);tr(s,"new","new",Pt),Vt(!0),a(!0),R(!0),C(!0),vi().then(({sessionKey:ct,friendlyId:Ie})=>{if(zc(Ie),Mc({sessionKey:ct,friendlyId:Ie,message:B,optimisticMessage:Pt,attachments:ye}),n){n({sessionKey:ct,friendlyId:Ie});return}i({to:"/chat/$sessionKey",params:{sessionKey:Ie},replace:!0})}).catch(ct=>{ku(s,"new","new",Pe,St),Z.setValue(B),f(`Failed to create session. ${ct instanceof Error?ct.message:String(ct)}`),Vt(!1),R(!1),C(!1),a(!1)});return}Jn(r||Se||K,e,B,!1,ye,Z.model)},[e,K,vi,r,t,i,n,s,Se]),Ei=m.useCallback(()=>{R(!1),C(!1),Rr(s,"new","new"),i({to:"/new"}),X&&pt(s,function(Z){return{...Z,isSidebarCollapsed:!0}})},[X,i,s]),Ya=m.useCallback(()=>{pt(s,function(Z){return{...Z,isSidebarCollapsed:!Z.isSidebarCollapsed}})},[s]),Ga=m.useCallback(()=>{X&&pt(s,function(Z){return{...Z,isSidebarCollapsed:!0}})},[X,s]),Qa=m.useCallback(()=>{pt(s,function(Z){return{...Z,isSidebarCollapsed:!1}})},[s]),Ja=m.useCallback(B=>{if(t||!B.trim())return;const Z=r||Se||K;Z&&Jn(Z,e,B.trim())},[e,K,r,t,Se]),Za=m.useCallback(()=>{D.current?.focus()},[]),el=m.useCallback(()=>{if(z){U(!1);return}document.activeElement instanceof HTMLElement&&document.activeElement.blur()},[z]),tl=m.useCallback(()=>{const B=[...ke].reverse().find(ye=>ye.role==="assistant");if(!B)return;const Z=et(B);Z&&navigator.clipboard.writeText(Z).catch(()=>{})},[ke]),nl=m.useCallback(()=>{U(!0)},[]),rl=m.useCallback(()=>{A(t?"global":"current"),E(!0)},[t]),Ti=m.useCallback(()=>{A("global"),E(!0)},[]);Fb({onNewChat:Ei,onFocusInput:Za,onEscape:el,onCopyLastResponse:tl,onShowHelp:nl,onSearch:rl,onSearchGlobal:Ti});const ji=se.isLoading&&!se.data||d,Ai=!!ne&&J.errorUpdatedAt>xe.current,il=!ji&&ke.length===0,sl=m.useMemo(()=>!Ai||!pe?null:h.jsx(Ib,{state:"error",error:pe,onRetry:Oe}),[pe,Oe,Ai]),Ii=h.jsx(Xc,{sessions:Q,activeFriendlyId:e,activeSessionKey:W,creatingSession:l,onCreateSession:Ei,isCollapsed:X?!1:Fe,onToggleCollapse:Ya,onSelectSession:Ga,onActiveSessionDelete:I,onOpenSearch:Ti});return h.jsxs("div",{className:"h-screen bg-surface text-primary-900",children:[h.jsxs("div",{className:q("h-full overflow-hidden",X?"relative":"grid grid-cols-[auto_1fr]"),children:[wt?null:X?h.jsxs(h.Fragment,{children:[!Fe&&h.jsx("div",{className:"fixed inset-0 z-40 bg-black/40 transition-opacity duration-200",onClick:()=>pt(s,B=>({...B,isSidebarCollapsed:!0})),...$e}),h.jsx("div",{className:q("fixed inset-y-0 left-0 z-50 w-[300px] transition-transform duration-150 safe-area-top",Fe?"-translate-x-full":"translate-x-0"),...$e,children:Ii})]}):Ii,h.jsxs("main",{className:"flex flex-col h-full min-h-0",ref:w,...Ae,children:[h.jsx(Jc,{activeTitle:he,wrapperRef:g,showSidebarButton:X,onOpenSidebar:Qa,totalTokens:me.totalTokens,contextTokens:me.contextTokens}),wt?null:h.jsxs(h.Fragment,{children:[h.jsx(Gy,{messages:kt,loading:ji,empty:il,notice:sl,noticePosition:"end",waitingForResponse:v,isStreaming:P,sessionKey:Le,pinToTop:M,pinGroupMinHeight:k,headerHeight:S,contentStyle:de,onFollowUpClick:Ja}),h.jsx(jb,{onSubmit:Xa,isLoading:o,disabled:o,wrapperRef:y,inputRef:D})]})]})]}),z&&h.jsx(m.Suspense,{fallback:null,children:h.jsx($b,{open:z,onOpenChange:U})}),F&&h.jsx(m.Suspense,{fallback:null,children:h.jsx(Bb,{open:F,onOpenChange:E,sessions:Q,currentFriendlyId:e,currentSessionKey:K,mode:N,onJumpToMessage:B=>{E(!1),B.friendlyId&&i({to:"/chat/$sessionKey",params:{sessionKey:B.friendlyId}})}})})]})}function Ub(){const e=qt(),t=Ws(),[n,r]=m.useState(null),i=ul.useParams(),s=typeof i.sessionKey=="string"?i.sessionKey:"main",o=s==="new",a=n?.friendlyId===s?n.sessionKey:void 0,l=m.useCallback(function(c){wu(e,"new","new",c.friendlyId,c.sessionKey),r({friendlyId:c.friendlyId,sessionKey:c.sessionKey}),t({to:"/chat/$sessionKey",params:{sessionKey:c.friendlyId},replace:!0})},[t,e]);return h.jsx(Hb,{activeFriendlyId:s,isNewChat:o,forcedSessionKey:a,onSessionResolved:o?l:void 0})}const e0=Object.freeze(Object.defineProperty({__proto__:null,component:Ub},Symbol.toStringTag,{value:"Module"}));export{e0 as $,Zb as a,be as c,Fa as g,ec as u};
|