@nextclaw/ui 0.9.0 → 0.9.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.
Files changed (44) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/assets/{ChannelsList-C7F_As4r.js → ChannelsList-DKD6Llid.js} +1 -1
  3. package/dist/assets/ChatPage-BK9X4Tin.js +38 -0
  4. package/dist/assets/{DocBrowser-Dsd8Dlq8.js → DocBrowser-CVwUDJMO.js} +1 -1
  5. package/dist/assets/{LogoBadge-2ChEc_oz.js → LogoBadge-CYQ_b7jk.js} +1 -1
  6. package/dist/assets/{MarketplacePage-BXck6-X3.js → MarketplacePage-B_2z3ii_.js} +1 -1
  7. package/dist/assets/{ModelConfig-CgHRSD0b.js → ModelConfig-CsX-_fyy.js} +1 -1
  8. package/dist/assets/{ProvidersList-PPfZucvS.js → ProvidersList-CZstsyv7.js} +1 -1
  9. package/dist/assets/{RuntimeConfig-ClLEKNTN.js → RuntimeConfig-CX2TGEG1.js} +1 -1
  10. package/dist/assets/{SearchConfig-CuXVCbrf.js → SearchConfig-C-WBTcWi.js} +1 -1
  11. package/dist/assets/{SecretsConfig-udJz6Ake.js → SecretsConfig-9kbR0ZCB.js} +1 -1
  12. package/dist/assets/{SessionsConfig-C1XnFfiC.js → SessionsConfig-Bohn3P1q.js} +1 -1
  13. package/dist/assets/{chat-message-BETwXLD4.js → chat-message-AWIcksDK.js} +1 -1
  14. package/dist/assets/{index-CsvP4CER.js → index-BEgClaDH.js} +3 -3
  15. package/dist/assets/index-C8GsgIUn.css +1 -0
  16. package/dist/assets/{index-COJdlL0e.js → index-CPDASUXh.js} +1 -1
  17. package/dist/assets/{label-BGL-ztxh.js → label-DD61y-4v.js} +1 -1
  18. package/dist/assets/{page-layout-aw88k7tG.js → page-layout-CfnoVycc.js} +1 -1
  19. package/dist/assets/{popover-DyEvzhmV.js → popover-DsugZ6rp.js} +1 -1
  20. package/dist/assets/{security-config-BuPAQn82.js → security-config-DIrf2Z0O.js} +1 -1
  21. package/dist/assets/skeleton-DJ-Wen2o.js +1 -0
  22. package/dist/assets/{switch-BK8jIzto.js → switch-NX5OmUXQ.js} +1 -1
  23. package/dist/assets/{tabs-custom-Da3cEOji.js → tabs-custom-9ihB5Jem.js} +1 -1
  24. package/dist/assets/{useConfirmDialog-z0CE92iS.js → useConfirmDialog-BuQnVTeR.js} +1 -1
  25. package/dist/assets/{vendor-CkJHmX1g.js → vendor-DKBNiC31.js} +1 -1
  26. package/dist/index.html +3 -3
  27. package/package.json +6 -6
  28. package/src/api/types.ts +63 -3
  29. package/src/components/chat/chat-composer-state.ts +53 -0
  30. package/src/components/chat/chat-page-data.ts +1 -15
  31. package/src/components/chat/chat-page-runtime.test.ts +26 -0
  32. package/src/components/chat/chat-page-runtime.ts +21 -4
  33. package/src/components/chat/chat-stream/types.ts +3 -0
  34. package/src/components/chat/containers/chat-input-bar.container.tsx +12 -41
  35. package/src/components/chat/legacy/LegacyChatPage.tsx +1 -15
  36. package/src/components/chat/managers/chat-input.manager.ts +43 -13
  37. package/src/components/chat/ncp/NcpChatPage.tsx +11 -18
  38. package/src/components/chat/ncp/ncp-chat-input.manager.ts +42 -12
  39. package/src/components/chat/ncp/ncp-chat-page-data.ts +1 -15
  40. package/src/components/chat/presenter/chat-presenter-context.tsx +2 -0
  41. package/src/components/chat/stores/chat-input.store.ts +4 -0
  42. package/dist/assets/ChatPage-Oo7-OUsx.js +0 -37
  43. package/dist/assets/index-D-bXl7qL.css +0 -1
  44. package/dist/assets/skeleton-drzO_tdU.js +0 -1
@@ -0,0 +1,38 @@
1
+ var _a=Object.defineProperty;var Oa=(e,t,n)=>t in e?_a(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var D=(e,t,n)=>Oa(e,typeof t!="symbol"?t+"":t,n);import{r as C,j as h,a2 as Fa,t as za,c as Ba,R as $a,o as Ua,T as pi,I as Ka,C as ir,P as Ha,h as gi,V as Va,i as mi,k as qa,l as or,m as Wa,S as yi,f as Ga,g as xi,a as Qa,a3 as Xa,B as ar,s as lr,a4 as Ya,a5 as Ja,a6 as Za,q as el,a7 as tl,a8 as nl,a9 as bi,aa as Si,ab as ki,ac as rl,ad as sl,ae as il,af as ol,ag as al,ah as ll,O as Jt,ai as ul,A as ur,N as Fr,aj as cl,z as dl,F as hl,D as fl,E as pl,ak as Pn,al as jn,am as Dn,an as Rt,M as gl,ao as vi,ap as ml,aq as yl,ar as xl,J as cr,as as wi,at as Ci,u as bl}from"./vendor-DKBNiC31.js";import{u as dr}from"./useConfirmDialog-BuQnVTeR.js";import{i as Sl,t as R,u as Ii,a as Ti,j as kl,k as vl,l as wl,m as Cl,c as Ie,n as Il,o as Tl,p as hr,q as Ml,T as zr,L as Br,r as Rl,B as et,I as Mi,s as Zt,S as _n,e as On,g as Fn,h as kt,v as El,w as Al,x as Ll,y as Nl,f as Pl,C as jl,z as Dl,A as $r,E as _l,F as Ol,G as Fl,H as zl,J as Bl,K as $l,M as Ul,N as Kl,O as Hl,P as Vl,Q as ql}from"./index-BEgClaDH.js";import{b as Wl,a as Gl,S as Ql,s as Xl,c as Ur,e as Kr}from"./chat-message-AWIcksDK.js";import{u as Ri,T as Yl,a as Jl,b as Zl,c as eu,P as tu,R as nu,d as ru,e as su,C as Ei,M as iu}from"./MarketplacePage-B_2z3ii_.js";import{b as Ai,c as Li,r as Ni}from"./provider-models-D3B_xWXx.js";import{R as ou,A as au,P as lu,C as Pi,T as uu,a as cu,b as du,c as hu}from"./popover-DsugZ6rp.js";import{P as fu,a as pu}from"./page-layout-CfnoVycc.js";import"./index-CPDASUXh.js";import"./skeleton-DJ-Wen2o.js";import"./tabs-custom-9ihB5Jem.js";const gu="ncp";function Hr(e){if(typeof e!="string")return null;const t=e.trim().toLowerCase();return t==="legacy"||t==="ncp"?t:null}function mu(e){const t=Hr(new URLSearchParams(e).get("chatChain"));return t||(Hr(void 0)??gu)}function Vr(e){return(e==null?void 0:e.trim().toLowerCase())||"native"}function jt(e,t){const n=t==null?void 0:t.trim();return n?e.some(r=>r.value===n):!1}function yu(e){var l;const{currentSelectedModel:t,modelOptions:n,selectedSessionPreferredModel:r,fallbackPreferredModel:s,defaultModel:i,preferSessionPreferredModel:o=!1,preserveCurrentSelectedModelOnSessionChange:a=!1}=e;return n.length===0?"":jt(n,t)&&(!o||a)?t.trim():jt(n,r)?r.trim():jt(n,s)?s.trim():jt(n,i)?i.trim():((l=n[0])==null?void 0:l.value)??""}function ji(e){var s,i;const t=Vr(e.sessionType);let n=null,r=Number.NEGATIVE_INFINITY;for(const o of e.sessions){if(o.key===e.selectedSessionKey||Vr(o.sessionType)!==t||!((s=o.preferredModel)==null?void 0:s.trim()))continue;const l=Date.parse(o.updatedAt),u=Number.isFinite(l)?l:Number.NEGATIVE_INFINITY;(!n||u>r)&&(n=o,r=u)}return(i=n==null?void 0:n.preferredModel)==null?void 0:i.trim()}function Di(e){const{modelOptions:t,selectedSessionKey:n,selectedSessionExists:r=!1,selectedSessionPreferredModel:s,fallbackPreferredModel:i,defaultModel:o,setSelectedModel:a}=e,l=C.useRef(void 0);C.useEffect(()=>{const u=l.current!==n;if(t.length===0){a(""),l.current=n;return}a(c=>yu({currentSelectedModel:c,modelOptions:t,selectedSessionPreferredModel:s,fallbackPreferredModel:i,defaultModel:o,preferSessionPreferredModel:u,preserveCurrentSelectedModelOnSessionChange:u&&!!n&&!r})),l.current=n},[o,i,t,r,n,s,a])}function xu(e){var v;const{view:t,selectedSessionKey:n,activeBackendRunId:r,isLocallyRunning:s,resumeRun:i}=e,[o,a]=C.useState(null),l=C.useRef(!1),u=C.useRef(new Map),c=C.useRef(new Map),d=C.useRef(new Map),p=C.useRef(r),f=C.useRef(new Set);C.useEffect(()=>{n&&f.current.add(n)},[n]),C.useEffect(()=>{n&&s&&f.current.delete(n)},[s,n]);const m=Sl(t==="chat"?{states:["queued","running"],limit:200,syncActiveStates:!0,isLocallyRunning:s}:void 0),y=C.useMemo(()=>{var w;return Wl(((w=m.data)==null?void 0:w.runs)??[])},[(v=m.data)==null?void 0:v.runs]),b=C.useMemo(()=>{const w=Gl(y);if(o){const T=y.get(o.sessionKey)??null;T&&(!o.runId||T.runId===o.runId)&&w.delete(o.sessionKey)}return w},[y,o]),g=C.useMemo(()=>{if(!n)return null;const w=y.get(n)??null;return(!w||!o||o.sessionKey!==n?!1:!o.runId||w.runId===o.runId)?null:w},[y,n,o]);return C.useEffect(()=>{r&&(p.current=r)},[r]),C.useEffect(()=>{if(t!=="chat"||!n||!g||!f.current.has(n)||s||r===g.runId||u.current.get(n)===g.runId)return;const T=c.current.get(n);if(T&&T===g.runId)return;const A=d.current.get(n);if(typeof A=="number"){const k=Date.parse(g.requestedAt??"");if(Number.isFinite(k)){if(k<=A+2e3)return}else if(Date.now()-A<=8e3)return}u.current.set(n,g.runId),f.current.delete(n),i(g)},[r,g,s,i,n,t]),C.useEffect(()=>{if(!n){u.current.clear(),c.current.clear(),d.current.clear(),f.current.clear();return}y.has(n)||(u.current.delete(n),c.current.delete(n),d.current.delete(n))},[y,n]),C.useEffect(()=>{var T,A,k;const w=l.current;if(l.current=s,!s&&w&&n){const N=((T=p.current)==null?void 0:T.trim())||((k=(A=y.get(n))==null?void 0:A.runId)==null?void 0:k.trim());N&&c.current.set(n,N),d.current.set(n,Date.now()),a({sessionKey:n,...N?{runId:N}:{}}),m.refetch()}},[y,s,n,m]),C.useEffect(()=>{if(!o)return;const w=y.get(o.sessionKey)??null;if(!w){a(null);return}o.runId&&w.runId!==o.runId&&a(null)},[y,o]),C.useEffect(()=>{s&&(o==null?void 0:o.sessionKey)===n&&a(null)},[s,n,o]),{sessionRunStatusByKey:b}}const Ee="native";function He(e){return typeof e!="string"?Ee:e.trim().toLowerCase()||Ee}function ut(e,t){return e==="native"?R("chatSessionTypeNative"):e.trim().split(/[-_]+/g).filter(Boolean).map(n=>n.charAt(0).toUpperCase()+n.slice(1)).join(" ")||e}function bu(e){var n;const t=new Map;for(const r of e){const s=He(r.value);t.set(s,{value:s,label:((n=r.label)==null?void 0:n.trim())||ut(s)})}return t.has(Ee)||t.set(Ee,{value:Ee,label:ut(Ee)}),Array.from(t.values()).sort((r,s)=>r.value===Ee?-1:s.value===Ee?1:r.value.localeCompare(s.value))}function _i(e){const{selectedSession:t,selectedSessionKey:n,pendingSessionType:r,setPendingSessionType:s,sessionTypesData:i}=e,o=C.useMemo(()=>bu((i==null?void 0:i.options)??[]),[i==null?void 0:i.options]),a=C.useMemo(()=>{const y=[...o],b=He(t==null?void 0:t.sessionType);return y.some(g=>g.value===b)||y.push({value:b,label:ut(b)}),y.sort((g,v)=>g.value===Ee?-1:v.value===Ee?1:g.value.localeCompare(v.value))},[o,t==null?void 0:t.sessionType]),l=C.useMemo(()=>He((i==null?void 0:i.defaultType)??Ee),[i==null?void 0:i.defaultType]),u=C.useRef(null),c=C.useMemo(()=>He((t==null?void 0:t.sessionType)??r??l),[l,r,t==null?void 0:t.sessionType]);C.useEffect(()=>{if(n)return;const y=typeof r=="string"?r.trim():"",b=He(r);(y.length===0||u.current===b||u.current===null&&b===Ee)&&(u.current=l,b!==l&&s(l))},[l,r,n,s]);const d=!n||!!(t!=null&&t.sessionTypeMutable),p=C.useMemo(()=>new Set(o.map(y=>y.value)),[o]),f=!!(t&&!p.has(He(t.sessionType))),m=f?`${ut(c)} ${R("chatSessionTypeUnavailableSuffix")}`:null;return{sessionTypeOptions:a,defaultSessionType:l,selectedSessionType:c,canEditSessionType:d,sessionTypeUnavailable:f,sessionTypeUnavailableMessage:m}}const Su=new Set(["off","minimal","low","medium","high","adaptive","xhigh"]);function ku(e){if(typeof e!="string")return null;const t=e.trim().toLowerCase();return t&&Su.has(t)?t:null}function vu(e){var g,v,w,T,A;const t=Ii(),n=Ti(),r=kl({q:e.query.trim()||void 0,limit:120,activeMinutes:0}),s=Ri("skill"),i=vl({sessionKey:e.selectedSessionKey,agentId:e.selectedAgentId}),o=wl(e.selectedSessionKey,300),a=Cl(),l=(t.isFetched||t.isSuccess)&&(n.isFetched||n.isSuccess),u=C.useMemo(()=>{const k=Ai({meta:n.data,config:t.data,onlyConfigured:!0}),N=new Set,F=[];for(const O of k)for(const I of O.models){const j=Li(O.prefix,I);!j||N.has(j)||(N.add(j),F.push({value:j,modelLabel:I,providerLabel:O.displayName,thinkingCapability:Ni(O.modelThinking,I,O.aliases)}))}return F.sort((O,I)=>{const j=O.providerLabel.localeCompare(I.providerLabel);return j!==0?j:O.modelLabel.localeCompare(I.modelLabel)})},[n.data,t.data]),c=C.useMemo(()=>{var k;return((k=r.data)==null?void 0:k.sessions)??[]},[(g=r.data)==null?void 0:g.sessions]),d=C.useMemo(()=>{var k;return((k=s.data)==null?void 0:k.records)??[]},[(v=s.data)==null?void 0:v.records]),p=C.useMemo(()=>c.find(k=>k.key===e.selectedSessionKey)??null,[e.selectedSessionKey,c]),f=_i({selectedSession:p,selectedSessionKey:e.selectedSessionKey,pendingSessionType:e.pendingSessionType,setPendingSessionType:e.setPendingSessionType,sessionTypesData:a.data}),m=C.useMemo(()=>ji({sessions:c,selectedSessionKey:e.selectedSessionKey,sessionType:f.selectedSessionType}),[e.selectedSessionKey,f.selectedSessionType,c]);Di({modelOptions:u,selectedSessionKey:e.selectedSessionKey,selectedSessionExists:!!p,selectedSessionPreferredModel:p==null?void 0:p.preferredModel,fallbackPreferredModel:m,defaultModel:(w=t.data)==null?void 0:w.agents.defaults.model,setSelectedModel:e.setSelectedModel});const y=C.useMemo(()=>{var k;return((k=o.data)==null?void 0:k.messages)??[]},[(T=o.data)==null?void 0:T.messages]),b=C.useMemo(()=>{var F;if(!e.selectedSessionKey)return null;const k=(F=o.data)==null?void 0:F.metadata;if(!k||typeof k!="object")return null;const N=[k.preferred_thinking,k.thinking,k.thinking_level,k.thinkingLevel];for(const O of N){const I=ku(O);if(I)return I}return null},[(A=o.data)==null?void 0:A.metadata,e.selectedSessionKey]);return{configQuery:t,configMetaQuery:n,sessionsQuery:r,installedSkillsQuery:s,chatCapabilitiesQuery:i,historyQuery:o,sessionTypesQuery:a,isProviderStateResolved:l,modelOptions:u,sessions:c,skillRecords:d,selectedSession:p,historyMessages:y,selectedSessionThinkingLevel:b,...f}}function Oi(e){if(e.label&&e.label.trim())return e.label.trim();const t=e.key.split(":");return t[t.length-1]||e.key}const wu={connected:{dotClass:"bg-emerald-500"},disconnected:{dotClass:"h-2.5 w-2.5 rounded-full border border-gray-400 bg-transparent"},connecting:{dotClass:"text-amber-600"}};function Cu({status:e,className:t}){const n=wu[e],r=e==="connected"?R("connected"):e==="disconnected"?R("disconnected"):R("connecting");return h.jsx(Yl,{delayDuration:250,children:h.jsxs(Jl,{children:[h.jsx(Zl,{asChild:!0,children:h.jsx("span",{role:"status","aria-label":r,className:Ie("inline-flex h-5 w-5 items-center justify-center",t),children:e==="connecting"?h.jsx(Fa,{className:Ie("h-3 w-3 animate-spin",n.dotClass)}):h.jsx("span",{className:Ie(e==="connected"?"h-2 w-2 rounded-full":"",n.dotClass)})})}),h.jsx(eu,{side:"bottom",className:"text-xs",children:r})]})})}const Fi=C.createContext(null);function zi({presenter:e,children:t}){return h.jsx(Fi.Provider,{value:e,children:t})}function fr(){const e=C.useContext(Fi);if(!e)throw new Error("usePresenter must be used inside ChatPresenterProvider");return e}const Iu=e=>`[data-item-index="${e}"]`;function Bi(e){const t=e.getItemSelector??Iu;C.useEffect(()=>{if(!e.isEnabled||e.itemCount===0)return;const n=e.containerRef.current;if(!n)return;const r=n.querySelector(t(e.activeIndex));r==null||r.scrollIntoView({block:"nearest",inline:"nearest"})},[t,e.activeIndex,e.containerRef,e.isEnabled,e.itemCount])}function Tu(){const e=C.useRef(null),[t,n]=C.useState(null);return C.useEffect(()=>{const r=e.current;if(!r||typeof ResizeObserver>"u")return;const s=()=>{n(r.getBoundingClientRect().width)};s();const i=new ResizeObserver(()=>s());return i.observe(r),()=>i.disconnect()},[]),{elementRef:e,width:t}}function le(...e){return za(Ba(e))}const $i=C.forwardRef(({className:e,type:t,...n},r)=>h.jsx("input",{type:t,className:le("flex h-9 w-full rounded-xl border border-gray-200/80 bg-white px-3.5 py-2 text-sm text-gray-900 file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-gray-300 placeholder:font-normal focus:outline-none focus:ring-1 focus:ring-primary/40 focus:border-primary/40 transition-colors disabled:cursor-not-allowed disabled:opacity-50",e),ref:r,...n}));$i.displayName="ChatInput";const Mu=ou,Ru=uu,Eu=au,Ui=C.forwardRef(({className:e,sideOffset:t=8,align:n="start",...r},s)=>h.jsx(lu,{children:h.jsx(Pi,{ref:s,sideOffset:t,align:n,className:le("z-[var(--z-popover,50)] w-72 overflow-hidden rounded-2xl border border-gray-200/50 bg-white p-4 shadow-lg animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...r})}));Ui.displayName=Pi.displayName;const Au=$a,Lu=Ua,Ki=C.forwardRef(({className:e,children:t,...n},r)=>h.jsxs(pi,{ref:r,className:le("flex h-9 w-full items-center justify-between whitespace-nowrap rounded-xl border border-gray-200/80 bg-white px-3 py-2 text-sm shadow-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/40 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",e),...n,children:[t,h.jsx(Ka,{asChild:!0,children:h.jsx(ir,{className:"h-4 w-4 opacity-50"})})]}));Ki.displayName=pi.displayName;const Hi=C.forwardRef(({className:e,...t},n)=>h.jsx(yi,{ref:n,className:le("flex cursor-default items-center justify-center py-1",e),...t,children:h.jsx(Ga,{className:"h-4 w-4"})}));Hi.displayName=yi.displayName;const Vi=C.forwardRef(({className:e,...t},n)=>h.jsx(xi,{ref:n,className:le("flex cursor-default items-center justify-center py-1",e),...t,children:h.jsx(ir,{className:"h-4 w-4"})}));Vi.displayName=xi.displayName;const qi=C.forwardRef(({className:e,children:t,position:n="popper",...r},s)=>h.jsx(Ha,{children:h.jsxs(gi,{ref:s,className:le("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md bg-white text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",e),position:n,...r,children:[h.jsx(Hi,{}),h.jsx(Va,{className:le("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),h.jsx(Vi,{})]})}));qi.displayName=gi.displayName;const Wi=C.forwardRef(({className:e,children:t,...n},r)=>h.jsxs(mi,{ref:r,className:le("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-2 pr-8 text-sm outline-none focus:bg-gray-100 data-[disabled]:pointer-events-none data-[disabled]:opacity-50 hover:bg-gray-100",e),...n,children:[h.jsx("span",{className:"absolute right-2 flex h-3.5 w-3.5 items-center justify-center",children:h.jsx(qa,{children:h.jsx(or,{className:"h-4 w-4"})})}),h.jsx(Wa,{children:t})]}));Wi.displayName=mi.displayName;const Nu=tu,Pu=nu,ju=ru,Gi=C.forwardRef(({className:e,sideOffset:t=4,...n},r)=>h.jsx(su,{children:h.jsx(Ei,{ref:r,sideOffset:t,className:le("z-[var(--z-tooltip)] overflow-hidden rounded-md border bg-popover px-3 py-1.5 text-sm text-popover-foreground shadow-md animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...n})}));Gi.displayName=Ei.displayName;const Et={Popover:Mu,PopoverAnchor:Eu,PopoverContent:Ui,PopoverTrigger:Ru,Input:$i,Select:Au,SelectContent:qi,SelectItem:Wi,SelectTrigger:Ki,SelectValue:Lu,Tooltip:Pu,TooltipContent:Gi,TooltipProvider:Nu,TooltipTrigger:ju},Du=680,_u=.82,Ou=560;function Fu(e){const{Popover:t,PopoverAnchor:n,PopoverContent:r}=Et,{elementRef:s,width:i}=Tu(),o=C.useRef(null),{isOpen:a,isLoading:l,items:u,activeIndex:c,activeItem:d,texts:p,onSelectItem:f,onOpenChange:m,onSetActiveIndex:y}=e,b=C.useMemo(()=>{if(i)return Math.min(i>Ou?i*_u:i,Du)},[i]);return Bi({containerRef:o,activeIndex:c,itemCount:u.length,isEnabled:a&&!l,getItemSelector:g=>`[data-slash-index="${g}"]`}),h.jsxs(t,{open:a,onOpenChange:m,children:[h.jsx(n,{asChild:!0,children:h.jsx("div",{ref:s,className:"pointer-events-none absolute bottom-full left-3 right-3 h-0"})}),h.jsx(r,{side:"top",align:"start",sideOffset:10,className:"z-[70] max-w-[calc(100vw-1.5rem)] overflow-hidden rounded-2xl border border-gray-200 bg-white/95 p-0 shadow-2xl backdrop-blur-md",onOpenAutoFocus:g=>g.preventDefault(),style:b?{width:`${b}px`}:void 0,children:h.jsxs("div",{className:"grid min-h-[240px] grid-cols-[minmax(220px,300px)_minmax(0,1fr)]",children:[h.jsx("div",{ref:o,role:"listbox","aria-label":p.slashSectionLabel,className:"custom-scrollbar max-h-[320px] overflow-y-auto border-r border-gray-200 p-2.5",children:l?h.jsx("div",{className:"p-2 text-xs text-gray-500",children:p.slashLoadingLabel}):h.jsxs(h.Fragment,{children:[h.jsx("div",{className:"mb-2 px-2 text-[11px] font-semibold uppercase tracking-wide text-gray-500",children:p.slashSectionLabel}),u.length===0?h.jsx("div",{className:"px-2 text-xs text-gray-400",children:p.slashEmptyLabel}):h.jsx("div",{className:"space-y-1",children:u.map((g,v)=>{const w=v===c;return h.jsxs("button",{type:"button",role:"option","aria-selected":w,"data-slash-index":v,onMouseEnter:()=>y(v),onClick:()=>f(g),className:`flex w-full items-start gap-2 rounded-lg px-2 py-1.5 text-left transition ${w?"bg-gray-100 text-gray-900":"text-gray-700 hover:bg-gray-50"}`,children:[h.jsx("span",{className:"truncate text-xs font-semibold",children:g.title}),h.jsx("span",{className:"truncate text-xs text-gray-500",children:g.subtitle})]},g.key)})})]})}),h.jsx("div",{className:"max-w-[320px] p-3.5",children:d?h.jsxs("div",{className:"space-y-3",children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx("span",{className:"inline-flex rounded-full bg-primary/10 px-2 py-0.5 text-[11px] font-semibold text-primary",children:d.subtitle}),h.jsx("span",{className:"text-sm font-semibold text-gray-900",children:d.title})]}),h.jsx("p",{className:"text-xs leading-5 text-gray-600",children:d.description}),h.jsx("div",{className:"space-y-1",children:d.detailLines.map(g=>h.jsx("div",{className:"rounded-md bg-gray-50 px-2 py-1 text-[11px] text-gray-600",children:g},g))}),h.jsx("div",{className:"pt-1 text-[11px] text-gray-500",children:p.slashSkillHintLabel})]}):h.jsx("div",{className:"text-xs text-gray-500",children:p.slashHintLabel})})]})})]})}const zu=Qa("inline-flex items-center justify-center whitespace-nowrap rounded-full text-sm font-medium ring-offset-background transition-all duration-fast focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary-600 active:bg-primary-700 shadow-sm",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-gray-200 bg-white hover:bg-gray-50 hover:text-gray-800 text-gray-600",secondary:"bg-gray-100 text-gray-700 hover:bg-gray-200/80",ghost:"hover:bg-gray-100/80 hover:text-gray-800",link:"text-primary underline-offset-4 hover:underline",primary:"bg-primary text-primary-foreground hover:bg-primary-600 active:bg-primary-700 shadow-sm",subtle:"bg-gray-100 text-gray-600 hover:bg-gray-200/80","primary-outline":"border border-primary/30 text-primary hover:bg-primary hover:text-primary-foreground"},size:{default:"h-9 px-4 py-2",sm:"h-8 px-3 text-xs",lg:"h-11 px-5 text-[14px]",xl:"h-12 px-6 text-[15px]",icon:"h-9 w-9"}},defaultVariants:{variant:"default",size:"default"}}),Kt=C.forwardRef(({className:e,variant:t,size:n,...r},s)=>h.jsx("button",{className:le(zu({variant:t,size:n,className:e})),ref:s,...r}));Kt.displayName="ChatButton";function qr(){return h.jsx("span",{"aria-hidden":"true","data-testid":"chat-stop-icon",className:"block h-3 w-3 rounded-[2px] bg-gray-700 shadow-[inset_0_0_0_1px_rgba(17,24,39,0.06)]"})}function Bu(e){var i;const{Tooltip:t,TooltipContent:n,TooltipProvider:r,TooltipTrigger:s}=Et;return h.jsxs("div",{className:"flex flex-col items-end gap-1",children:[(i=e.sendError)!=null&&i.trim()?h.jsx("div",{className:"max-w-[420px] text-right text-[11px] text-red-600",children:e.sendError}):null,h.jsx("div",{className:"flex items-center gap-2",children:e.isSending?e.canStopGeneration?h.jsx(Kt,{size:"icon",variant:"outline",className:"h-8 w-8 rounded-full","aria-label":e.stopButtonLabel,onClick:()=>void e.onStop(),disabled:e.stopDisabled,children:h.jsx(qr,{})}):h.jsx(r,{children:h.jsxs(t,{children:[h.jsx(s,{asChild:!0,children:h.jsx("span",{children:h.jsx(Kt,{size:"icon",variant:"outline",className:"h-8 w-8 rounded-full","aria-label":e.stopButtonLabel,disabled:!0,children:h.jsx(qr,{})})})}),h.jsx(n,{side:"top",children:h.jsx("p",{className:"text-xs",children:e.stopHint})})]})}):h.jsx(Kt,{size:"icon",className:"h-8 w-8 rounded-full","aria-label":e.sendButtonLabel,onClick:()=>void e.onSend(),disabled:e.sendDisabled,children:h.jsx(Xa,{className:"h-5 w-5"})})})]})}function $u(e,t){const n=t.trim().toLowerCase();return n?e.filter(r=>[r.label,r.key,r.description].filter(i=>typeof i=="string"&&i.trim().length>0).join(" ").toLowerCase().includes(n)):e}function Uu(e){const{Input:t,Popover:n,PopoverContent:r,PopoverTrigger:s}=Et,{picker:i}=e,o=C.useRef(null),a=C.useId(),[l,u]=C.useState(""),[c,d]=C.useState(0),p=C.useMemo(()=>new Set(i.selectedKeys),[i.selectedKeys]),f=i.selectedKeys.length,m=C.useMemo(()=>$u(i.options,l),[i.options,l]);C.useEffect(()=>{d(0)},[l]),C.useEffect(()=>{d(g=>m.length===0?0:Math.min(g,m.length-1))},[m.length]),Bi({containerRef:o,activeIndex:c,itemCount:m.length,isEnabled:m.length>0,getItemSelector:g=>`[data-skill-index="${g}"]`});const y=g=>{if(p.has(g)){i.onSelectedKeysChange(i.selectedKeys.filter(v=>v!==g));return}i.onSelectedKeysChange([...i.selectedKeys,g])},b=g=>{if(m.length!==0){if(g.key==="ArrowDown"){g.preventDefault(),d(v=>Math.min(v+1,m.length-1));return}if(g.key==="ArrowUp"){g.preventDefault(),d(v=>Math.max(v-1,0));return}if(g.key==="Enter"){g.preventDefault();const v=m[c];v&&y(v.key)}}};return h.jsxs(n,{children:[h.jsx(s,{asChild:!0,children:h.jsxs("button",{type:"button","aria-haspopup":"listbox",className:"inline-flex items-center gap-1.5 rounded-lg px-3 py-1.5 text-xs font-medium text-gray-600 transition-colors hover:bg-gray-100 hover:text-gray-900",children:[h.jsx(ar,{className:"h-4 w-4"}),h.jsx("span",{children:i.title}),f>0?h.jsx("span",{className:"ml-0.5 flex h-[18px] min-w-[18px] items-center justify-center rounded-full bg-primary/10 text-[10px] font-semibold text-primary",children:f}):null]})}),h.jsxs(r,{side:"top",align:"start",className:"w-[360px] p-0",children:[h.jsxs("div",{className:"space-y-2 border-b border-gray-100 px-4 py-3",children:[h.jsx("div",{className:"text-sm font-semibold text-gray-900",children:i.title}),h.jsxs("div",{className:"relative",children:[h.jsx(lr,{className:"pointer-events-none absolute left-3 top-2.5 h-3.5 w-3.5 text-gray-400"}),h.jsx(t,{value:l,onChange:g=>u(g.target.value),onKeyDown:b,placeholder:i.searchPlaceholder,role:"combobox","aria-controls":a,"aria-expanded":"true","aria-autocomplete":"list","aria-activedescendant":m[c]?`${a}-option-${c}`:void 0,className:"h-8 rounded-lg pl-8 text-xs"})]})]}),h.jsx("div",{ref:o,id:a,role:"listbox","aria-multiselectable":"true",className:"custom-scrollbar max-h-[320px] overflow-y-auto",children:i.isLoading?h.jsx("div",{className:"p-4 text-xs text-gray-500",children:i.loadingLabel}):m.length===0?h.jsx("div",{className:"p-4 text-center text-xs text-gray-500",children:i.emptyLabel}):h.jsx("div",{className:"py-1",children:m.map((g,v)=>{const w=p.has(g.key),T=v===c;return h.jsxs("button",{type:"button",id:`${a}-option-${v}`,role:"option","aria-selected":w,"data-skill-index":v,onClick:()=>y(g.key),onMouseEnter:()=>d(v),className:`flex w-full items-center gap-3 px-4 py-2.5 text-left transition-colors ${T?"bg-gray-50":"hover:bg-gray-50"}`,children:[h.jsx("div",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-gray-100 text-gray-500",children:h.jsx(Ya,{className:"h-4 w-4"})}),h.jsxs("div",{className:"min-w-0 flex-1",children:[h.jsxs("div",{className:"flex items-center gap-1.5",children:[h.jsx("span",{className:"truncate text-sm text-gray-900",children:g.label}),g.badgeLabel?h.jsx("span",{className:"shrink-0 rounded-full bg-primary/10 px-1.5 py-0.5 text-[10px] font-medium text-primary",children:g.badgeLabel}):null]}),h.jsx("div",{className:"mt-0.5 truncate text-xs text-gray-500",children:g.description||g.key})]}),h.jsx("div",{className:"ml-3 shrink-0",children:h.jsx("span",{className:w?"inline-flex h-5 w-5 items-center justify-center rounded-full bg-primary text-white":"inline-flex h-5 w-5 items-center justify-center rounded-full border border-gray-300 bg-white",children:w?h.jsx(or,{className:"h-3 w-3"}):null})})]},g.key)})})}),i.manageHref&&i.manageLabel?h.jsx("div",{className:"border-t border-gray-100 px-4 py-2.5",children:h.jsxs("a",{href:i.manageHref,className:"inline-flex items-center gap-1.5 text-xs font-medium text-primary transition-colors hover:text-primary/80",children:[i.manageLabel,h.jsx(Ja,{className:"h-3 w-3"})]})}):null]})]})}function Qi({icon:e}){return e==="sparkles"?h.jsx(el,{className:"h-3.5 w-3.5 shrink-0 text-primary"}):e==="brain"?h.jsx(tl,{className:"h-3.5 w-3.5 shrink-0 text-gray-500"}):null}function Ku({icon:e}){return e==="paperclip"?h.jsx(Za,{className:"h-4 w-4"}):h.jsx(Qi,{icon:e})}function Hu(e){return e==="model"?"min-w-[220px]":e==="session-type"?"min-w-[140px]":e==="thinking"?"min-w-[150px]":""}function Vu(e){return e==="model"?"w-[320px]":e==="session-type"?"w-[220px]":e==="thinking"?"w-[180px]":""}function qu({item:e}){const{Select:t,SelectContent:n,SelectItem:r,SelectTrigger:s,SelectValue:i}=Et;return h.jsxs(t,{value:e.value,onValueChange:e.onValueChange,disabled:e.disabled,children:[h.jsx(s,{className:`h-8 w-auto rounded-lg border-0 bg-transparent px-3 text-xs font-medium text-gray-600 shadow-none hover:bg-gray-100 focus:ring-0 ${Hu(e.key)}`,children:e.selectedLabel?h.jsxs("div",{className:"flex min-w-0 items-center gap-2 text-left",children:[h.jsx(Qi,{icon:e.icon}),h.jsx("span",{className:"truncate text-xs font-semibold text-gray-700",children:e.selectedLabel})]}):e.loading?h.jsx("div",{className:"h-3 w-24 animate-pulse rounded bg-gray-200"}):h.jsx(i,{placeholder:e.placeholder})}),h.jsxs(n,{className:Vu(e.key),children:[e.options.length===0?e.loading?h.jsxs("div",{className:"space-y-2 px-3 py-2",children:[h.jsx("div",{className:"h-3 w-36 animate-pulse rounded bg-gray-200"}),h.jsx("div",{className:"h-3 w-28 animate-pulse rounded bg-gray-200"}),h.jsx("div",{className:"h-3 w-32 animate-pulse rounded bg-gray-200"})]}):e.emptyLabel?h.jsx("div",{className:"px-3 py-2 text-xs text-gray-500",children:e.emptyLabel}):null:null,e.options.map(o=>h.jsx(r,{value:o.value,className:"py-2",children:o.description?h.jsxs("div",{className:"flex min-w-0 flex-col gap-0.5",children:[h.jsx("span",{className:"truncate text-xs font-semibold text-gray-800",children:o.label}),h.jsx("span",{className:"truncate text-[11px] text-gray-500",children:o.description})]}):h.jsx("span",{className:"truncate text-xs font-semibold text-gray-800",children:o.label})},o.value))]})]})}function Wu(e){var i;const{Tooltip:t,TooltipContent:n,TooltipProvider:r,TooltipTrigger:s}=Et;return h.jsxs("div",{className:"flex items-center justify-between px-3 pb-3",children:[h.jsxs("div",{className:"flex items-center gap-1",children:[e.skillPicker?h.jsx(Uu,{picker:e.skillPicker}):null,e.selects.map(o=>h.jsx(qu,{item:o},o.key)),(i=e.accessories)==null?void 0:i.map(o=>{const a=h.jsxs("button",{type:"button",className:`inline-flex items-center rounded-lg py-1.5 text-xs font-medium text-gray-600 transition-colors hover:bg-gray-100 hover:text-gray-900 disabled:cursor-not-allowed disabled:text-gray-400 ${o.iconOnly?"h-8 w-8 justify-center px-0":"gap-1.5 px-3"}`,onClick:o.onClick,disabled:o.disabled,"aria-label":o.label,children:[h.jsx(Ku,{icon:o.icon}),o.iconOnly?null:h.jsx("span",{children:o.label})]});if(!o.tooltip)return h.jsx("div",{children:a},o.key);const l=o.disabled?h.jsx("span",{className:"inline-flex",children:a}):a;return h.jsx(r,{children:h.jsxs(t,{children:[h.jsx(s,{asChild:!0,children:l}),h.jsx(n,{side:"top",children:h.jsx("p",{className:"text-xs",children:o.tooltip})})]})},o.key)})]}),h.jsx(Bu,{...e.actions})]})}const Gu="";function Xi(){return`composer-${Math.random().toString(36).slice(2,10)}`}function It(e=""){return{id:Xi(),type:"text",text:e}}function pr(e){return{id:Xi(),type:"token",tokenKind:e.tokenKind,tokenKey:e.tokenKey,label:e.label}}function At(e){return e.type==="text"?e.text.length:1}function gr(){return[It("")]}function Qu(e){return[It(e)]}function ct(e){const t=[];for(const n of e){if(n.type==="text"){if(n.text.length===0)continue;const r=t[t.length-1];if((r==null?void 0:r.type)==="text"){t[t.length-1]={...r,text:r.text+n.text};continue}}t.push(n)}return t.length===0?gr():t}function Xu(e){return e.map(t=>t.type==="text"?t.text:Gu).join("")}function Yu(e){return e.filter(t=>t.type==="text").map(t=>t.text).join("")}function mr(e,t){const n=[],r=new Set;for(const s of e)s.type!=="token"||s.tokenKind!==t||r.has(s.tokenKey)||(r.add(s.tokenKey),n.push(s.tokenKey));return n}function Ju(e,t,n,r){const s=Math.max(0,n-t),i=Math.max(0,t+e.text.length-r),o=[];return s>0&&o.push({...e,text:e.text.slice(0,s)}),i>0&&o.push({...e,text:e.text.slice(e.text.length-i)}),o}function Zu(e,t,n,r){return t<=n||e>=r}function ec(e,t,n,r,s){return!n&&r>=s?(e.push(...t),!0):n}function tc(e,t,n,r,s,i,o){const a=Ju(t,n,r,s);a[0]&&e.push(a[0]);let l=o;return l||(e.push(...i),l=!0),a[1]&&e.push(a[1]),l}function nc(e,t,n,r,s,i){return!r&&s<=i?(e.push(...n),!0):(e.push(t),r)}function ln(e,t,n,r){const s=Math.max(0,t),i=Math.max(s,n),o=[];let a=0,l=!1;for(const u of e){const c=At(u),d=a,p=a+c;if(Zu(d,p,s,i)){l=ec(o,r,l,d,i),o.push(u),a=p;continue}u.type==="text"?l=tc(o,u,d,s,i,r,l):l=nc(o,u,r,l,s,d),a=p}return l||o.push(...r),ct(o)}function Yi(e,t){return ct(e.filter(n=>n.type!=="token"||!t(n)))}function rc(e,t){if(!t||t.start!==t.end)return null;const n=Xu(e),r=t.end,s=n.slice(0,r),i=/(?:^|\s)\/([^\s\uFFFC]*)$/.exec(s);if(!i)return null;const o=r-i[0].length+(i[0].startsWith("/")?0:1);return{query:(i[1]??"").trim().toLowerCase(),start:o,end:r}}function sc(e,t,n){return e?e.start<n&&e.end>t:!1}function Ji(e){const t=new Map;let n=0;for(const r of e)t.set(r.id,n),n+=At(r);return t}function Zi(e,t){let n=t;for(;n&&n.parentNode!==e;)n=n.parentNode;return n?Array.prototype.indexOf.call(e.childNodes,n):e.childNodes.length}function ic(e,t,n){if(e instanceof HTMLElement){const r=e.dataset.composerNodeId;if(r)return n.find(s=>s.id===r)}return n[t]}function eo(e,t,n){let r=0;for(let s=0;s<n;s+=1){const i=ic(e.childNodes[s],s,t);i&&(r+=At(i))}return r}function oc(e,t,n,r){var a;const s=Zi(e,t),i=eo(e,r,s),o=r[s];return(o==null?void 0:o.type)==="text"?i+Math.min(n,o.text.length):i+Math.min(n,((a=t.textContent)==null?void 0:a.length)??0)}function ac(e,t,n,r,s){return n.type==="text"?e.nodeType===Node.TEXT_NODE?r+Math.min(t,n.text.length):e===s?r+(t>0?n.text.length:0):r+n.text.length:e===s?r+(t>0?1:0):r+1}function zn(e,t,n,r,s){var u;if(t===e)return eo(e,r,n);if(t.nodeType===Node.TEXT_NODE&&t.parentNode===e)return oc(e,t,n,r);const i=t instanceof HTMLElement?t.closest("[data-composer-node-id]"):((u=t.parentElement)==null?void 0:u.closest("[data-composer-node-id]"))??null;if(!(i instanceof HTMLElement)){const c=Zi(e,t);return zn(e,e,c,r,s)}const o=i.dataset.composerNodeId;if(!o)return 0;const a=r.find(c=>c.id===o),l=s.get(o)??0;return a?ac(t,n,a,l,i):l}function to(e,t){const n=window.getSelection();if(!n||n.rangeCount===0)return null;const r=n.getRangeAt(0);if(!e.contains(r.startContainer)||!e.contains(r.endContainer))return null;const s=Ji(t),i=zn(e,r.startContainer,r.startOffset,t,s),o=zn(e,r.endContainer,r.endOffset,t,s);return{start:Math.min(i,o),end:Math.max(i,o)}}function lc(e,t,n){if(!n)return;const r=window.getSelection();if(!r)return;const s=l=>{let u=0;for(let c=0;c<t.length;c+=1){const d=t[c],p=At(d),f=u,m=u+p,y=e.childNodes[c];if(!y){u=m;continue}if(d.type==="text"){if(l<=m)return{container:y.firstChild??y,offset:Math.max(0,Math.min(l-f,d.text.length))}}else{if(l<=f)return{container:e,offset:c};if(l<=m)return{container:e,offset:c+1}}u=m}return{container:e,offset:e.childNodes.length}},i=s(n.start),o=s(n.end),a=document.createRange();a.setStart(i.container,i.offset),a.setEnd(o.container,o.offset),r.removeAllRanges(),r.addRange(a)}function uc(e){const t=[];for(const n of Array.from(e.childNodes)){if(n.nodeType===Node.TEXT_NODE){t.push(It(n.textContent??""));continue}if(!(n instanceof HTMLElement))continue;if(n.dataset.composerNodeType==="token"){const i=n.dataset.composerTokenKind,o=n.dataset.composerTokenKey,a=n.dataset.composerLabel;i&&o&&a&&t.push({id:n.dataset.composerNodeId??pr({tokenKind:i,tokenKey:o,label:a}).id,type:"token",tokenKind:i,tokenKey:o,label:a});continue}const s=n.textContent??"";t.push({id:n.dataset.composerNodeId??It(s).id,type:"text",text:s})}return ct(t)}function Wr(e){const t=uc(e);return{nodes:t,selection:to(e,t)}}class cc{constructor(){this.nodes=gr(),this.selection=null,this.sync=(t,n)=>(this.nodes=ct(t),this.selection=n,this.getSnapshot()),this.setSelection=t=>(this.selection=t,this.getSnapshot()),this.replaceDocument=(t,n)=>(this.nodes=ct(t),this.selection=n,this.getSnapshot()),this.insertText=t=>{const n=this.selection??{start:0,end:0};this.nodes=ln(this.nodes,n.start,n.end,[It(t)]);const r=n.start+t.length;return this.selection={start:r,end:r},this.getSnapshot()},this.insertSkillToken=(t,n)=>{var a,l;if(this.getSelectedSkillKeys().includes(t))return this.getSnapshot();const r=this.getSlashTrigger(),s=this.getDocumentLength(),i=(r==null?void 0:r.start)??((a=this.selection)==null?void 0:a.start)??s,o=(r==null?void 0:r.end)??((l=this.selection)==null?void 0:l.end)??i;return this.nodes=ln(this.nodes,i,o,[pr({tokenKind:"skill",tokenKey:t,label:n})]),this.selection={start:i+1,end:i+1},this.getSnapshot()},this.syncSelectedSkills=(t,n)=>{const r=this.getSelectedSkillKeys(),s=new Map(n.map(a=>[a.key,a])),i=t.find(a=>!r.includes(a));if(i){const a=s.get(i);return this.insertSkillToken(i,(a==null?void 0:a.label)??i)}const o=r.find(a=>!t.includes(a));return o&&(this.nodes=Yi(this.nodes,a=>a.tokenKind==="skill"&&a.tokenKey===o)),this.getSnapshot()},this.deleteContent=t=>{const n=this.getDocumentLength(),r=this.selection??{start:n,end:n};let s=r.start,i=r.end;if(r.start===r.end)if(t==="backward"&&r.start>0)s=r.start-1;else if(t==="forward")i=r.end+1;else return this.getSnapshot();return this.nodes=ln(this.nodes,s,i,[]),this.selection={start:s,end:s},this.getSnapshot()},this.getSnapshot=()=>({nodes:this.nodes,selection:this.selection,nodeStartMap:Ji(this.nodes),documentLength:this.getDocumentLength(),selectedSkillKeys:this.getSelectedSkillKeys(),slashTrigger:this.getSlashTrigger()}),this.getDocumentLength=()=>this.nodes.reduce((t,n)=>t+At(n),0),this.getSelectedSkillKeys=()=>mr(this.nodes,"skill"),this.getSlashTrigger=()=>rc(this.nodes,this.selection)}}function dc(e){const{key:t,shiftKey:n,isComposing:r,isSlashMenuOpen:s,slashItemCount:i,activeSlashIndex:o,isSending:a,canStopGeneration:l}=e;if(s&&i>0){if(t==="ArrowDown")return{type:"move-slash-index",index:(o+1)%i};if(t==="ArrowUp")return{type:"move-slash-index",index:(o-1+i)%i};if(t==="Enter"&&!n||t==="Tab")return{type:"insert-active-slash-item"}}return t==="Escape"?s?{type:"close-slash"}:a&&l?{type:"stop-generation"}:{type:"noop"}:t==="Enter"&&n?{type:"insert-line-break"}:t==="Enter"?{type:"send-message"}:!r&&(t==="Backspace"||t==="Delete")?{type:"delete-content",direction:t==="Backspace"?"backward":"forward"}:{type:"noop"}}const Gr="http://www.w3.org/2000/svg";class hc{constructor(){this.render=(t,n)=>{if(!t)return;const r=document.createDocumentFragment();for(const s of n.nodes){const i=s.type==="text"?this.createTextNodeElement(s):this.createTokenNodeElement(s,n.selectedRange,n.nodeStartMap);i&&r.appendChild(i)}t.replaceChildren(r)},this.createTextNodeElement=t=>{if(t.text.length===0)return null;const n=document.createElement("span");return n.dataset.composerNodeId=t.id,n.dataset.composerNodeType="text",n.textContent=t.text,n},this.createTokenNodeElement=(t,n,r)=>{const s=r.get(t.id)??0,i=sc(n,s,s+1),o=document.createElement("span");o.contentEditable="false",o.dataset.composerNodeId=t.id,o.dataset.composerNodeType="token",o.dataset.composerTokenKind=t.tokenKind,o.dataset.composerTokenKey=t.tokenKey,o.dataset.composerLabel=t.label,o.className=["mx-[2px]","inline-flex","h-6","max-w-full","items-center","gap-1","rounded-md","border","px-1.5","align-baseline","text-[11px]","font-medium","transition",i?"border-primary/30 bg-primary/18 text-primary":"border-primary/12 bg-primary/8 text-primary"].join(" "),o.append(this.createTokenIcon(t.tokenKind));const a=document.createElement("span");return a.className="truncate",a.textContent=t.label,o.append(a),o},this.createTokenIcon=t=>{const n=document.createElement("span");return n.className="inline-flex h-3 w-3 shrink-0 items-center justify-center text-primary/70",n.append(t==="file"?this.createFileIcon():this.createSkillIcon()),n},this.createSkillIcon=()=>this.createSvgIcon([{tag:"path",attrs:{d:"M8.5 2.75 2.75 6l5.75 3.25L14.25 6 8.5 2.75Z"}},{tag:"path",attrs:{d:"M2.75 10 8.5 13.25 14.25 10"}},{tag:"path",attrs:{d:"M2.75 6v4l5.75 3.25V9.25L2.75 6Z"}},{tag:"path",attrs:{d:"M14.25 6v4L8.5 13.25V9.25L14.25 6Z"}}]),this.createFileIcon=()=>this.createSvgIcon([{tag:"path",attrs:{d:"M5.25 2.75h4.5L13 6v7.25A1.75 1.75 0 0 1 11.25 15h-6.5A1.75 1.75 0 0 1 3 13.25v-8.75A1.75 1.75 0 0 1 4.75 2.75Z"}},{tag:"path",attrs:{d:"M9.75 2.75V6H13"}},{tag:"path",attrs:{d:"M5.75 8.75h4.5"}},{tag:"path",attrs:{d:"M5.75 10.75h4.5"}}]),this.createSvgIcon=t=>{const n=document.createElementNS(Gr,"svg");n.setAttribute("viewBox","0 0 16 16"),n.setAttribute("fill","none"),n.setAttribute("stroke","currentColor"),n.setAttribute("stroke-width","1.25"),n.setAttribute("stroke-linecap","round"),n.setAttribute("stroke-linejoin","round"),n.setAttribute("aria-hidden","true"),n.setAttribute("class","h-3 w-3");for(const r of t){const s=document.createElementNS(Gr,r.tag);for(const[i,o]of Object.entries(r.attrs))s.setAttribute(i,o);n.append(s)}return n}}}const Qr=188;class fc{constructor(t){this.controller=t,this.surfaceRenderer=new hc,this.sync=(n,r)=>this.controller.sync(n,r),this.syncSelectionFromRoot=n=>this.controller.setSelection(to(n,this.controller.getSnapshot().nodes)),this.restoreSelectionIfFocused=(n,r)=>{!n||document.activeElement!==n||lc(n,this.controller.getSnapshot().nodes,r)},this.syncViewport=n=>{n&&(n.style.maxHeight=`${Qr}px`,n.style.overflowY=n.scrollHeight>Qr?"auto":"hidden")},this.renderSurface=n=>{this.surfaceRenderer.render(n.root,{nodes:n.snapshot.nodes,selectedRange:n.selectedRange,nodeStartMap:n.snapshot.nodeStartMap})},this.insertSlashItem=(n,r)=>{n.value&&r(this.controller.insertSkillToken(n.value,n.title))},this.syncSelectedSkills=(n,r,s)=>{s(this.controller.syncSelectedSkills(n,r))},this.handleBeforeInput=n=>{const{event:r,disabled:s,isComposing:i,commitSnapshot:o}=n,a=r.nativeEvent;s||i||a.isComposing||!(a.inputType==="insertText"||a.inputType==="insertReplacementText")||!a.data||(r.preventDefault(),o(this.controller.insertText(a.data)))},this.handleInput=n=>{const{event:r,isComposing:s,commitSnapshot:i}=n,o=r.nativeEvent;if(s||o.isComposing)return;const a=r.currentTarget,l=Wr(a);i(this.controller.replaceDocument(l.nodes,l.selection))},this.handleCompositionEnd=n=>{const{event:r,commitSnapshot:s}=n,i=r.currentTarget,o=Wr(i);s(this.controller.replaceDocument(o.nodes,o.selection))},this.handleKeyDown=n=>{const{event:r,slashItems:s,activeSlashIndex:i,activeSlashItem:o,actions:a,commitSnapshot:l,insertSkillToken:u,onSlashActiveIndexChange:c,onSlashQueryChange:d,onSlashOpenChange:p}=n,f=this.controller.getSnapshot(),m=dc({key:r.key,shiftKey:r.shiftKey,isComposing:r.nativeEvent.isComposing,isSlashMenuOpen:f.slashTrigger!==null,slashItemCount:s.length,activeSlashIndex:i,isSending:a.isSending,canStopGeneration:a.canStopGeneration});if(m.type!=="noop"){if(r.preventDefault(),m.type==="move-slash-index"){c(m.index);return}if(m.type==="insert-active-slash-item"){o&&u(o.value??o.key,o.title);return}if(m.type==="close-slash"){d==null||d(null),p(!1);return}if(m.type==="stop-generation"){a.onStop();return}if(m.type==="insert-line-break"){l(this.controller.insertText(`
2
+ `));return}if(m.type==="send-message"){a.onSend();return}m.type==="delete-content"&&l(this.controller.deleteContent(m.direction))}},this.handlePaste=n=>{const{event:r,commitSnapshot:s}=n,i=r.clipboardData.getData("text/plain");i&&(r.preventDefault(),s(this.controller.insertText(i)))},this.handleBlur=n=>{const{setSelectedRange:r,onSlashQueryChange:s,onSlashOpenChange:i}=n;r(null),s==null||s(null),i(!1)}}}class pc{constructor(){this.controller=new cc,this.viewController=new fc(this.controller),this.rootElement=null,this.selection=null,this.selectedRange=null,this.snapshot=this.controller.getSnapshot(),this.config=null,this.isComposing=!1,this.bindRootElement=t=>{this.rootElement=t},this.update=t=>(this.config=t,this.snapshot=this.viewController.sync(t.nodes,this.selectedRange),{snapshot:this.snapshot,selectedRange:this.selectedRange,bindRootElement:this.bindRootElement,handleBeforeInput:this.handleBeforeInput,handleInput:this.handleInput,handleCompositionStart:this.handleCompositionStart,handleCompositionEnd:this.handleCompositionEnd,handleKeyDown:this.handleKeyDown,handlePaste:this.handlePaste,handleBlur:this.handleBlur,syncSelectionState:this.syncSelectionState,imperativeHandle:this.createHandle()}),this.createHandle=()=>({insertSlashItem:t=>{this.viewController.insertSlashItem(t,this.commitSnapshot)},syncSelectedSkills:(t,n)=>{this.viewController.syncSelectedSkills(t,n,this.commitSnapshot)}}),this.restoreDomAfterCommit=()=>{this.isComposing||this.viewController.restoreSelectionIfFocused(this.rootElement,this.selection)},this.renderSurface=()=>{this.isComposing||this.viewController.renderSurface({root:this.rootElement,snapshot:this.snapshot,selectedRange:this.selectedRange})},this.syncViewport=()=>{this.viewController.syncViewport(this.rootElement)},this.syncSelectionState=()=>{if(!this.rootElement||this.isComposing)return;const t=this.viewController.syncSelectionFromRoot(this.rootElement);this.selection=t.selection,this.selectedRange=t.selection,this.syncSlashState(t),this.requestRender()},this.handleBeforeInput=t=>{this.viewController.handleBeforeInput({event:t,disabled:this.requireConfig().disabled,isComposing:this.isComposing,commitSnapshot:this.commitSnapshot})},this.handleInput=t=>{this.viewController.handleInput({event:t,isComposing:this.isComposing,commitSnapshot:this.commitSnapshot})},this.handleCompositionStart=()=>{this.isComposing=!0},this.handleCompositionEnd=t=>{this.isComposing=!1,this.viewController.handleCompositionEnd({event:t,commitSnapshot:this.commitSnapshot})},this.handleKeyDown=t=>{const n=this.requireConfig(),r=n.slashItems[n.activeSlashIndex]??null;this.viewController.handleKeyDown({event:t,slashItems:n.slashItems,activeSlashIndex:n.activeSlashIndex,activeSlashItem:r,actions:n.actions,commitSnapshot:this.commitSnapshot,insertSkillToken:this.insertSkillToken,onSlashActiveIndexChange:n.onSlashActiveIndexChange,onSlashQueryChange:n.onSlashQueryChange,onSlashOpenChange:n.onSlashOpenChange})},this.handlePaste=t=>{this.viewController.handlePaste({event:t,commitSnapshot:this.commitSnapshot})},this.handleBlur=()=>{const t=this.requireConfig();this.isComposing=!1,this.viewController.handleBlur({setSelectedRange:this.setSelectedRange,onSlashQueryChange:t.onSlashQueryChange,onSlashOpenChange:t.onSlashOpenChange})},this.setSelectedRange=t=>{this.selectedRange=t,this.selection=t,this.requestRender()},this.commitSnapshot=t=>{const n=this.requireConfig();this.selection=t.selection,this.selectedRange=t.selection,this.snapshot=t,n.onNodesChange(t.nodes),this.syncSlashState(t)},this.insertSkillToken=(t,n)=>{this.commitSnapshot(this.controller.insertSkillToken(t,n))},this.syncSlashState=t=>{var r,s;const n=this.requireConfig();(s=n.onSlashQueryChange)==null||s.call(n,((r=t.slashTrigger)==null?void 0:r.query)??null),n.onSlashOpenChange(t.slashTrigger!==null)},this.requestRender=()=>{this.requireConfig().requestRender()},this.requireConfig=()=>{if(!this.config)throw new Error("ChatComposerRuntime is not configured.");return this.config}}}const gc=C.forwardRef(function(t,n){const{nodes:r,placeholder:s,disabled:i,slashItems:o,actions:a,onNodesChange:l,onSlashQueryChange:u,onSlashOpenChange:c,onSlashActiveIndexChange:d,activeSlashIndex:p}=t,[f,m]=C.useState(0),[y]=C.useState(()=>new pc),{snapshot:b,bindRootElement:g,handleBeforeInput:v,handleInput:w,handleCompositionStart:T,handleCompositionEnd:A,handleKeyDown:k,handlePaste:N,handleBlur:F,syncSelectionState:O,imperativeHandle:I}=y.update({nodes:r,disabled:i,slashItems:o,actions:a,onNodesChange:l,onSlashQueryChange:u,onSlashOpenChange:c,onSlashActiveIndexChange:d,activeSlashIndex:p,requestRender:()=>m(j=>j+1)});return C.useImperativeHandle(n,()=>I,[I]),C.useLayoutEffect(()=>{y.renderSurface(),y.restoreDomAfterCommit(),y.syncViewport()},[y,b.nodes,b.nodeStartMap,f]),h.jsx("div",{className:"px-4 py-2.5",children:h.jsx("div",{className:"min-h-[60px]",children:h.jsx("div",{ref:g,contentEditable:!i,suppressContentEditableWarning:!0,role:"textbox","aria-multiline":"true","data-placeholder":s,onBeforeInput:v,onInput:w,onCompositionStart:T,onCompositionEnd:A,onKeyDown:k,onKeyUp:O,onMouseUp:O,onFocus:O,onBlur:F,onPaste:N,className:"min-h-7 max-h-[188px] w-full overflow-y-auto whitespace-pre-wrap break-words bg-transparent py-0.5 text-sm leading-6 text-gray-800 outline-none empty:before:pointer-events-none empty:before:text-gray-400 empty:before:content-[attr(data-placeholder)]"})})})});function mc({hint:e}){if(!e)return null;if(e.loading)return h.jsx("div",{className:"px-4 pb-2",children:h.jsxs("div",{className:"inline-flex items-center gap-2 rounded-lg border border-gray-200 bg-gray-50 px-3 py-2",children:[h.jsx("span",{className:"h-3 w-28 animate-pulse rounded bg-gray-200"}),h.jsx("span",{className:"h-3 w-16 animate-pulse rounded bg-gray-200"})]})});const t=e.tone==="warning"?"border-amber-200 bg-amber-50 text-amber-800":"border-gray-200 bg-gray-50 text-gray-700";return h.jsx("div",{className:"px-4 pb-2",children:h.jsxs("div",{className:`inline-flex items-center gap-2 rounded-lg px-3 py-1.5 text-xs ${t}`,children:[e.text?h.jsx("span",{children:e.text}):null,e.actionLabel&&e.onAction?h.jsx("button",{type:"button",onClick:e.onAction,className:"font-semibold underline-offset-2 hover:underline",children:e.actionLabel}):null]})})}function yc(e){const t=C.useRef(null),[n,r]=C.useState(null),[s,i]=C.useState(0),o=n!==null,a=e.slashMenu.items[s]??null;C.useEffect(()=>{i(u=>e.slashMenu.items.length===0?0:Math.min(u,e.slashMenu.items.length-1))},[e.slashMenu.items.length]),C.useEffect(()=>{n!==null&&i(0)},[n]);const l=C.useMemo(()=>e.toolbar.skillPicker?{...e.toolbar,skillPicker:{...e.toolbar.skillPicker,onSelectedKeysChange:u=>{var c,d;(d=t.current)==null||d.syncSelectedSkills(u,((c=e.toolbar.skillPicker)==null?void 0:c.options)??[])}}}:e.toolbar,[e.toolbar]);return h.jsx("div",{className:"border-t border-gray-200/80 bg-white p-4",children:h.jsx("div",{className:"mx-auto w-full max-w-[min(1120px,100%)]",children:h.jsxs("div",{className:"overflow-hidden rounded-2xl border border-gray-200 bg-white shadow-card",children:[h.jsxs("div",{className:"relative",children:[h.jsx(gc,{ref:t,nodes:e.composer.nodes,placeholder:e.composer.placeholder,disabled:e.composer.disabled,slashItems:e.slashMenu.items,actions:e.toolbar.actions,activeSlashIndex:s,onNodesChange:e.composer.onNodesChange,onSlashQueryChange:u=>{var c,d;r(u),(d=(c=e.composer).onSlashQueryChange)==null||d.call(c,u)},onSlashOpenChange:u=>{u||r(null)},onSlashActiveIndexChange:i}),h.jsx(Fu,{isOpen:o,isLoading:e.slashMenu.isLoading,items:e.slashMenu.items,activeIndex:s,activeItem:a,texts:e.slashMenu.texts,onSelectItem:u=>{var c;(c=t.current)==null||c.insertSlashItem(u)},onOpenChange:u=>{u||r(null)},onSetActiveIndex:i})]}),h.jsx(mc,{hint:e.hint}),h.jsx(Wu,{...l})]})})})}function un({role:e}){return e==="user"?h.jsx("div",{"data-testid":"chat-message-avatar-user",className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-primary text-white shadow-sm",children:h.jsx(nl,{className:"h-4 w-4"})}):e==="tool"?h.jsx("div",{"data-testid":"chat-message-avatar-tool",className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-amber-100 text-amber-700 shadow-sm",children:h.jsx(bi,{className:"h-4 w-4"})}):h.jsx("div",{"data-testid":"chat-message-avatar-assistant",className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-full border border-gray-200/80 bg-gray-900 text-white shadow-sm",children:h.jsx(Si,{className:"h-4 w-4"})})}function xc(e,t){const n={};return(e[e.length-1]===""?[...e,""]:e).join((n.padRight?" ":"")+","+(n.padLeft===!1?"":" ")).trim()}const bc=/^[$_\p{ID_Start}][$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,Sc=/^[$_\p{ID_Start}][-$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,kc={};function Xr(e,t){return(kc.jsx?Sc:bc).test(e)}const vc=/[ \t\n\f\r]/g;function wc(e){return typeof e=="object"?e.type==="text"?Yr(e.value):!1:Yr(e)}function Yr(e){return e.replace(vc,"")===""}class Lt{constructor(t,n,r){this.normal=n,this.property=t,r&&(this.space=r)}}Lt.prototype.normal={};Lt.prototype.property={};Lt.prototype.space=void 0;function no(e,t){const n={},r={};for(const s of e)Object.assign(n,s.property),Object.assign(r,s.normal);return new Lt(n,r,t)}function Bn(e){return e.toLowerCase()}class Se{constructor(t,n){this.attribute=n,this.property=t}}Se.prototype.attribute="";Se.prototype.booleanish=!1;Se.prototype.boolean=!1;Se.prototype.commaOrSpaceSeparated=!1;Se.prototype.commaSeparated=!1;Se.prototype.defined=!1;Se.prototype.mustUseProperty=!1;Se.prototype.number=!1;Se.prototype.overloadedBoolean=!1;Se.prototype.property="";Se.prototype.spaceSeparated=!1;Se.prototype.space=void 0;let Cc=0;const U=nt(),ie=nt(),$n=nt(),E=nt(),te=nt(),lt=nt(),Ce=nt();function nt(){return 2**++Cc}const Un=Object.freeze(Object.defineProperty({__proto__:null,boolean:U,booleanish:ie,commaOrSpaceSeparated:Ce,commaSeparated:lt,number:E,overloadedBoolean:$n,spaceSeparated:te},Symbol.toStringTag,{value:"Module"})),cn=Object.keys(Un);class yr extends Se{constructor(t,n,r,s){let i=-1;if(super(t,n),Jr(this,"space",s),typeof r=="number")for(;++i<cn.length;){const o=cn[i];Jr(this,cn[i],(r&Un[o])===Un[o])}}}yr.prototype.defined=!0;function Jr(e,t,n){n&&(e[t]=n)}function ht(e){const t={},n={};for(const[r,s]of Object.entries(e.properties)){const i=new yr(r,e.transform(e.attributes||{},r),s,e.space);e.mustUseProperty&&e.mustUseProperty.includes(r)&&(i.mustUseProperty=!0),t[r]=i,n[Bn(r)]=r,n[Bn(i.attribute)]=r}return new Lt(t,n,e.space)}const ro=ht({properties:{ariaActiveDescendant:null,ariaAtomic:ie,ariaAutoComplete:null,ariaBusy:ie,ariaChecked:ie,ariaColCount:E,ariaColIndex:E,ariaColSpan:E,ariaControls:te,ariaCurrent:null,ariaDescribedBy:te,ariaDetails:null,ariaDisabled:ie,ariaDropEffect:te,ariaErrorMessage:null,ariaExpanded:ie,ariaFlowTo:te,ariaGrabbed:ie,ariaHasPopup:null,ariaHidden:ie,ariaInvalid:null,ariaKeyShortcuts:null,ariaLabel:null,ariaLabelledBy:te,ariaLevel:E,ariaLive:null,ariaModal:ie,ariaMultiLine:ie,ariaMultiSelectable:ie,ariaOrientation:null,ariaOwns:te,ariaPlaceholder:null,ariaPosInSet:E,ariaPressed:ie,ariaReadOnly:ie,ariaRelevant:null,ariaRequired:ie,ariaRoleDescription:te,ariaRowCount:E,ariaRowIndex:E,ariaRowSpan:E,ariaSelected:ie,ariaSetSize:E,ariaSort:null,ariaValueMax:E,ariaValueMin:E,ariaValueNow:E,ariaValueText:null,role:null},transform(e,t){return t==="role"?t:"aria-"+t.slice(4).toLowerCase()}});function so(e,t){return t in e?e[t]:t}function io(e,t){return so(e,t.toLowerCase())}const Ic=ht({attributes:{acceptcharset:"accept-charset",classname:"class",htmlfor:"for",httpequiv:"http-equiv"},mustUseProperty:["checked","multiple","muted","selected"],properties:{abbr:null,accept:lt,acceptCharset:te,accessKey:te,action:null,allow:null,allowFullScreen:U,allowPaymentRequest:U,allowUserMedia:U,alt:null,as:null,async:U,autoCapitalize:null,autoComplete:te,autoFocus:U,autoPlay:U,blocking:te,capture:null,charSet:null,checked:U,cite:null,className:te,cols:E,colSpan:null,content:null,contentEditable:ie,controls:U,controlsList:te,coords:E|lt,crossOrigin:null,data:null,dateTime:null,decoding:null,default:U,defer:U,dir:null,dirName:null,disabled:U,download:$n,draggable:ie,encType:null,enterKeyHint:null,fetchPriority:null,form:null,formAction:null,formEncType:null,formMethod:null,formNoValidate:U,formTarget:null,headers:te,height:E,hidden:$n,high:E,href:null,hrefLang:null,htmlFor:te,httpEquiv:te,id:null,imageSizes:null,imageSrcSet:null,inert:U,inputMode:null,integrity:null,is:null,isMap:U,itemId:null,itemProp:te,itemRef:te,itemScope:U,itemType:te,kind:null,label:null,lang:null,language:null,list:null,loading:null,loop:U,low:E,manifest:null,max:null,maxLength:E,media:null,method:null,min:null,minLength:E,multiple:U,muted:U,name:null,nonce:null,noModule:U,noValidate:U,onAbort:null,onAfterPrint:null,onAuxClick:null,onBeforeMatch:null,onBeforePrint:null,onBeforeToggle:null,onBeforeUnload:null,onBlur:null,onCancel:null,onCanPlay:null,onCanPlayThrough:null,onChange:null,onClick:null,onClose:null,onContextLost:null,onContextMenu:null,onContextRestored:null,onCopy:null,onCueChange:null,onCut:null,onDblClick:null,onDrag:null,onDragEnd:null,onDragEnter:null,onDragExit:null,onDragLeave:null,onDragOver:null,onDragStart:null,onDrop:null,onDurationChange:null,onEmptied:null,onEnded:null,onError:null,onFocus:null,onFormData:null,onHashChange:null,onInput:null,onInvalid:null,onKeyDown:null,onKeyPress:null,onKeyUp:null,onLanguageChange:null,onLoad:null,onLoadedData:null,onLoadedMetadata:null,onLoadEnd:null,onLoadStart:null,onMessage:null,onMessageError:null,onMouseDown:null,onMouseEnter:null,onMouseLeave:null,onMouseMove:null,onMouseOut:null,onMouseOver:null,onMouseUp:null,onOffline:null,onOnline:null,onPageHide:null,onPageShow:null,onPaste:null,onPause:null,onPlay:null,onPlaying:null,onPopState:null,onProgress:null,onRateChange:null,onRejectionHandled:null,onReset:null,onResize:null,onScroll:null,onScrollEnd:null,onSecurityPolicyViolation:null,onSeeked:null,onSeeking:null,onSelect:null,onSlotChange:null,onStalled:null,onStorage:null,onSubmit:null,onSuspend:null,onTimeUpdate:null,onToggle:null,onUnhandledRejection:null,onUnload:null,onVolumeChange:null,onWaiting:null,onWheel:null,open:U,optimum:E,pattern:null,ping:te,placeholder:null,playsInline:U,popover:null,popoverTarget:null,popoverTargetAction:null,poster:null,preload:null,readOnly:U,referrerPolicy:null,rel:te,required:U,reversed:U,rows:E,rowSpan:E,sandbox:te,scope:null,scoped:U,seamless:U,selected:U,shadowRootClonable:U,shadowRootDelegatesFocus:U,shadowRootMode:null,shape:null,size:E,sizes:null,slot:null,span:E,spellCheck:ie,src:null,srcDoc:null,srcLang:null,srcSet:null,start:E,step:null,style:null,tabIndex:E,target:null,title:null,translate:null,type:null,typeMustMatch:U,useMap:null,value:ie,width:E,wrap:null,writingSuggestions:null,align:null,aLink:null,archive:te,axis:null,background:null,bgColor:null,border:E,borderColor:null,bottomMargin:E,cellPadding:null,cellSpacing:null,char:null,charOff:null,classId:null,clear:null,code:null,codeBase:null,codeType:null,color:null,compact:U,declare:U,event:null,face:null,frame:null,frameBorder:null,hSpace:E,leftMargin:E,link:null,longDesc:null,lowSrc:null,marginHeight:E,marginWidth:E,noResize:U,noHref:U,noShade:U,noWrap:U,object:null,profile:null,prompt:null,rev:null,rightMargin:E,rules:null,scheme:null,scrolling:ie,standby:null,summary:null,text:null,topMargin:E,valueType:null,version:null,vAlign:null,vLink:null,vSpace:E,allowTransparency:null,autoCorrect:null,autoSave:null,disablePictureInPicture:U,disableRemotePlayback:U,prefix:null,property:null,results:E,security:null,unselectable:null},space:"html",transform:io}),Tc=ht({attributes:{accentHeight:"accent-height",alignmentBaseline:"alignment-baseline",arabicForm:"arabic-form",baselineShift:"baseline-shift",capHeight:"cap-height",className:"class",clipPath:"clip-path",clipRule:"clip-rule",colorInterpolation:"color-interpolation",colorInterpolationFilters:"color-interpolation-filters",colorProfile:"color-profile",colorRendering:"color-rendering",crossOrigin:"crossorigin",dataType:"datatype",dominantBaseline:"dominant-baseline",enableBackground:"enable-background",fillOpacity:"fill-opacity",fillRule:"fill-rule",floodColor:"flood-color",floodOpacity:"flood-opacity",fontFamily:"font-family",fontSize:"font-size",fontSizeAdjust:"font-size-adjust",fontStretch:"font-stretch",fontStyle:"font-style",fontVariant:"font-variant",fontWeight:"font-weight",glyphName:"glyph-name",glyphOrientationHorizontal:"glyph-orientation-horizontal",glyphOrientationVertical:"glyph-orientation-vertical",hrefLang:"hreflang",horizAdvX:"horiz-adv-x",horizOriginX:"horiz-origin-x",horizOriginY:"horiz-origin-y",imageRendering:"image-rendering",letterSpacing:"letter-spacing",lightingColor:"lighting-color",markerEnd:"marker-end",markerMid:"marker-mid",markerStart:"marker-start",navDown:"nav-down",navDownLeft:"nav-down-left",navDownRight:"nav-down-right",navLeft:"nav-left",navNext:"nav-next",navPrev:"nav-prev",navRight:"nav-right",navUp:"nav-up",navUpLeft:"nav-up-left",navUpRight:"nav-up-right",onAbort:"onabort",onActivate:"onactivate",onAfterPrint:"onafterprint",onBeforePrint:"onbeforeprint",onBegin:"onbegin",onCancel:"oncancel",onCanPlay:"oncanplay",onCanPlayThrough:"oncanplaythrough",onChange:"onchange",onClick:"onclick",onClose:"onclose",onCopy:"oncopy",onCueChange:"oncuechange",onCut:"oncut",onDblClick:"ondblclick",onDrag:"ondrag",onDragEnd:"ondragend",onDragEnter:"ondragenter",onDragExit:"ondragexit",onDragLeave:"ondragleave",onDragOver:"ondragover",onDragStart:"ondragstart",onDrop:"ondrop",onDurationChange:"ondurationchange",onEmptied:"onemptied",onEnd:"onend",onEnded:"onended",onError:"onerror",onFocus:"onfocus",onFocusIn:"onfocusin",onFocusOut:"onfocusout",onHashChange:"onhashchange",onInput:"oninput",onInvalid:"oninvalid",onKeyDown:"onkeydown",onKeyPress:"onkeypress",onKeyUp:"onkeyup",onLoad:"onload",onLoadedData:"onloadeddata",onLoadedMetadata:"onloadedmetadata",onLoadStart:"onloadstart",onMessage:"onmessage",onMouseDown:"onmousedown",onMouseEnter:"onmouseenter",onMouseLeave:"onmouseleave",onMouseMove:"onmousemove",onMouseOut:"onmouseout",onMouseOver:"onmouseover",onMouseUp:"onmouseup",onMouseWheel:"onmousewheel",onOffline:"onoffline",onOnline:"ononline",onPageHide:"onpagehide",onPageShow:"onpageshow",onPaste:"onpaste",onPause:"onpause",onPlay:"onplay",onPlaying:"onplaying",onPopState:"onpopstate",onProgress:"onprogress",onRateChange:"onratechange",onRepeat:"onrepeat",onReset:"onreset",onResize:"onresize",onScroll:"onscroll",onSeeked:"onseeked",onSeeking:"onseeking",onSelect:"onselect",onShow:"onshow",onStalled:"onstalled",onStorage:"onstorage",onSubmit:"onsubmit",onSuspend:"onsuspend",onTimeUpdate:"ontimeupdate",onToggle:"ontoggle",onUnload:"onunload",onVolumeChange:"onvolumechange",onWaiting:"onwaiting",onZoom:"onzoom",overlinePosition:"overline-position",overlineThickness:"overline-thickness",paintOrder:"paint-order",panose1:"panose-1",pointerEvents:"pointer-events",referrerPolicy:"referrerpolicy",renderingIntent:"rendering-intent",shapeRendering:"shape-rendering",stopColor:"stop-color",stopOpacity:"stop-opacity",strikethroughPosition:"strikethrough-position",strikethroughThickness:"strikethrough-thickness",strokeDashArray:"stroke-dasharray",strokeDashOffset:"stroke-dashoffset",strokeLineCap:"stroke-linecap",strokeLineJoin:"stroke-linejoin",strokeMiterLimit:"stroke-miterlimit",strokeOpacity:"stroke-opacity",strokeWidth:"stroke-width",tabIndex:"tabindex",textAnchor:"text-anchor",textDecoration:"text-decoration",textRendering:"text-rendering",transformOrigin:"transform-origin",typeOf:"typeof",underlinePosition:"underline-position",underlineThickness:"underline-thickness",unicodeBidi:"unicode-bidi",unicodeRange:"unicode-range",unitsPerEm:"units-per-em",vAlphabetic:"v-alphabetic",vHanging:"v-hanging",vIdeographic:"v-ideographic",vMathematical:"v-mathematical",vectorEffect:"vector-effect",vertAdvY:"vert-adv-y",vertOriginX:"vert-origin-x",vertOriginY:"vert-origin-y",wordSpacing:"word-spacing",writingMode:"writing-mode",xHeight:"x-height",playbackOrder:"playbackorder",timelineBegin:"timelinebegin"},properties:{about:Ce,accentHeight:E,accumulate:null,additive:null,alignmentBaseline:null,alphabetic:E,amplitude:E,arabicForm:null,ascent:E,attributeName:null,attributeType:null,azimuth:E,bandwidth:null,baselineShift:null,baseFrequency:null,baseProfile:null,bbox:null,begin:null,bias:E,by:null,calcMode:null,capHeight:E,className:te,clip:null,clipPath:null,clipPathUnits:null,clipRule:null,color:null,colorInterpolation:null,colorInterpolationFilters:null,colorProfile:null,colorRendering:null,content:null,contentScriptType:null,contentStyleType:null,crossOrigin:null,cursor:null,cx:null,cy:null,d:null,dataType:null,defaultAction:null,descent:E,diffuseConstant:E,direction:null,display:null,dur:null,divisor:E,dominantBaseline:null,download:U,dx:null,dy:null,edgeMode:null,editable:null,elevation:E,enableBackground:null,end:null,event:null,exponent:E,externalResourcesRequired:null,fill:null,fillOpacity:E,fillRule:null,filter:null,filterRes:null,filterUnits:null,floodColor:null,floodOpacity:null,focusable:null,focusHighlight:null,fontFamily:null,fontSize:null,fontSizeAdjust:null,fontStretch:null,fontStyle:null,fontVariant:null,fontWeight:null,format:null,fr:null,from:null,fx:null,fy:null,g1:lt,g2:lt,glyphName:lt,glyphOrientationHorizontal:null,glyphOrientationVertical:null,glyphRef:null,gradientTransform:null,gradientUnits:null,handler:null,hanging:E,hatchContentUnits:null,hatchUnits:null,height:null,href:null,hrefLang:null,horizAdvX:E,horizOriginX:E,horizOriginY:E,id:null,ideographic:E,imageRendering:null,initialVisibility:null,in:null,in2:null,intercept:E,k:E,k1:E,k2:E,k3:E,k4:E,kernelMatrix:Ce,kernelUnitLength:null,keyPoints:null,keySplines:null,keyTimes:null,kerning:null,lang:null,lengthAdjust:null,letterSpacing:null,lightingColor:null,limitingConeAngle:E,local:null,markerEnd:null,markerMid:null,markerStart:null,markerHeight:null,markerUnits:null,markerWidth:null,mask:null,maskContentUnits:null,maskUnits:null,mathematical:null,max:null,media:null,mediaCharacterEncoding:null,mediaContentEncodings:null,mediaSize:E,mediaTime:null,method:null,min:null,mode:null,name:null,navDown:null,navDownLeft:null,navDownRight:null,navLeft:null,navNext:null,navPrev:null,navRight:null,navUp:null,navUpLeft:null,navUpRight:null,numOctaves:null,observer:null,offset:null,onAbort:null,onActivate:null,onAfterPrint:null,onBeforePrint:null,onBegin:null,onCancel:null,onCanPlay:null,onCanPlayThrough:null,onChange:null,onClick:null,onClose:null,onCopy:null,onCueChange:null,onCut:null,onDblClick:null,onDrag:null,onDragEnd:null,onDragEnter:null,onDragExit:null,onDragLeave:null,onDragOver:null,onDragStart:null,onDrop:null,onDurationChange:null,onEmptied:null,onEnd:null,onEnded:null,onError:null,onFocus:null,onFocusIn:null,onFocusOut:null,onHashChange:null,onInput:null,onInvalid:null,onKeyDown:null,onKeyPress:null,onKeyUp:null,onLoad:null,onLoadedData:null,onLoadedMetadata:null,onLoadStart:null,onMessage:null,onMouseDown:null,onMouseEnter:null,onMouseLeave:null,onMouseMove:null,onMouseOut:null,onMouseOver:null,onMouseUp:null,onMouseWheel:null,onOffline:null,onOnline:null,onPageHide:null,onPageShow:null,onPaste:null,onPause:null,onPlay:null,onPlaying:null,onPopState:null,onProgress:null,onRateChange:null,onRepeat:null,onReset:null,onResize:null,onScroll:null,onSeeked:null,onSeeking:null,onSelect:null,onShow:null,onStalled:null,onStorage:null,onSubmit:null,onSuspend:null,onTimeUpdate:null,onToggle:null,onUnload:null,onVolumeChange:null,onWaiting:null,onZoom:null,opacity:null,operator:null,order:null,orient:null,orientation:null,origin:null,overflow:null,overlay:null,overlinePosition:E,overlineThickness:E,paintOrder:null,panose1:null,path:null,pathLength:E,patternContentUnits:null,patternTransform:null,patternUnits:null,phase:null,ping:te,pitch:null,playbackOrder:null,pointerEvents:null,points:null,pointsAtX:E,pointsAtY:E,pointsAtZ:E,preserveAlpha:null,preserveAspectRatio:null,primitiveUnits:null,propagate:null,property:Ce,r:null,radius:null,referrerPolicy:null,refX:null,refY:null,rel:Ce,rev:Ce,renderingIntent:null,repeatCount:null,repeatDur:null,requiredExtensions:Ce,requiredFeatures:Ce,requiredFonts:Ce,requiredFormats:Ce,resource:null,restart:null,result:null,rotate:null,rx:null,ry:null,scale:null,seed:null,shapeRendering:null,side:null,slope:null,snapshotTime:null,specularConstant:E,specularExponent:E,spreadMethod:null,spacing:null,startOffset:null,stdDeviation:null,stemh:null,stemv:null,stitchTiles:null,stopColor:null,stopOpacity:null,strikethroughPosition:E,strikethroughThickness:E,string:null,stroke:null,strokeDashArray:Ce,strokeDashOffset:null,strokeLineCap:null,strokeLineJoin:null,strokeMiterLimit:E,strokeOpacity:E,strokeWidth:null,style:null,surfaceScale:E,syncBehavior:null,syncBehaviorDefault:null,syncMaster:null,syncTolerance:null,syncToleranceDefault:null,systemLanguage:Ce,tabIndex:E,tableValues:null,target:null,targetX:E,targetY:E,textAnchor:null,textDecoration:null,textRendering:null,textLength:null,timelineBegin:null,title:null,transformBehavior:null,type:null,typeOf:Ce,to:null,transform:null,transformOrigin:null,u1:null,u2:null,underlinePosition:E,underlineThickness:E,unicode:null,unicodeBidi:null,unicodeRange:null,unitsPerEm:E,values:null,vAlphabetic:E,vMathematical:E,vectorEffect:null,vHanging:E,vIdeographic:E,version:null,vertAdvY:E,vertOriginX:E,vertOriginY:E,viewBox:null,viewTarget:null,visibility:null,width:null,widths:null,wordSpacing:null,writingMode:null,x:null,x1:null,x2:null,xChannelSelector:null,xHeight:E,y:null,y1:null,y2:null,yChannelSelector:null,z:null,zoomAndPan:null},space:"svg",transform:so}),oo=ht({properties:{xLinkActuate:null,xLinkArcRole:null,xLinkHref:null,xLinkRole:null,xLinkShow:null,xLinkTitle:null,xLinkType:null},space:"xlink",transform(e,t){return"xlink:"+t.slice(5).toLowerCase()}}),ao=ht({attributes:{xmlnsxlink:"xmlns:xlink"},properties:{xmlnsXLink:null,xmlns:null},space:"xmlns",transform:io}),lo=ht({properties:{xmlBase:null,xmlLang:null,xmlSpace:null},space:"xml",transform(e,t){return"xml:"+t.slice(3).toLowerCase()}}),Mc={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"},Rc=/[A-Z]/g,Zr=/-[a-z]/g,Ec=/^data[-\w.:]+$/i;function Ac(e,t){const n=Bn(t);let r=t,s=Se;if(n in e.normal)return e.property[e.normal[n]];if(n.length>4&&n.slice(0,4)==="data"&&Ec.test(t)){if(t.charAt(4)==="-"){const i=t.slice(5).replace(Zr,Nc);r="data"+i.charAt(0).toUpperCase()+i.slice(1)}else{const i=t.slice(4);if(!Zr.test(i)){let o=i.replace(Rc,Lc);o.charAt(0)!=="-"&&(o="-"+o),t="data"+o}}s=yr}return new s(r,t)}function Lc(e){return"-"+e.toLowerCase()}function Nc(e){return e.charAt(1).toUpperCase()}const Pc=no([ro,Ic,oo,ao,lo],"html"),xr=no([ro,Tc,oo,ao,lo],"svg");function jc(e){return e.join(" ").trim()}var st={},dn,es;function Dc(){if(es)return dn;es=1;var e=/\/\*[^*]*\*+([^/*][^*]*\*+)*\//g,t=/\n/g,n=/^\s*/,r=/^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/,s=/^:\s*/,i=/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^)]*?\)|[^};])+)/,o=/^[;\s]*/,a=/^\s+|\s+$/g,l=`
3
+ `,u="/",c="*",d="",p="comment",f="declaration";function m(b,g){if(typeof b!="string")throw new TypeError("First argument must be a string");if(!b)return[];g=g||{};var v=1,w=1;function T(z){var P=z.match(t);P&&(v+=P.length);var Q=z.lastIndexOf(l);w=~Q?z.length-Q:w+z.length}function A(){var z={line:v,column:w};return function(P){return P.position=new k(z),O(),P}}function k(z){this.start=z,this.end={line:v,column:w},this.source=g.source}k.prototype.content=b;function N(z){var P=new Error(g.source+":"+v+":"+w+": "+z);if(P.reason=z,P.filename=g.source,P.line=v,P.column=w,P.source=b,!g.silent)throw P}function F(z){var P=z.exec(b);if(P){var Q=P[0];return T(Q),b=b.slice(Q.length),P}}function O(){F(n)}function I(z){var P;for(z=z||[];P=j();)P!==!1&&z.push(P);return z}function j(){var z=A();if(!(u!=b.charAt(0)||c!=b.charAt(1))){for(var P=2;d!=b.charAt(P)&&(c!=b.charAt(P)||u!=b.charAt(P+1));)++P;if(P+=2,d===b.charAt(P-1))return N("End of comment missing");var Q=b.slice(2,P-2);return w+=2,T(Q),b=b.slice(P),w+=2,z({type:p,comment:Q})}}function _(){var z=A(),P=F(r);if(P){if(j(),!F(s))return N("property missing ':'");var Q=F(i),Y=z({type:f,property:y(P[0].replace(e,d)),value:Q?y(Q[0].replace(e,d)):d});return F(o),Y}}function W(){var z=[];I(z);for(var P;P=_();)P!==!1&&(z.push(P),I(z));return z}return O(),W()}function y(b){return b?b.replace(a,d):d}return dn=m,dn}var ts;function _c(){if(ts)return st;ts=1;var e=st&&st.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(st,"__esModule",{value:!0}),st.default=n;const t=e(Dc());function n(r,s){let i=null;if(!r||typeof r!="string")return i;const o=(0,t.default)(r),a=typeof s=="function";return o.forEach(l=>{if(l.type!=="declaration")return;const{property:u,value:c}=l;a?s(u,c,l):c&&(i=i||{},i[u]=c)}),i}return st}var mt={},ns;function Oc(){if(ns)return mt;ns=1,Object.defineProperty(mt,"__esModule",{value:!0}),mt.camelCase=void 0;var e=/^--[a-zA-Z0-9_-]+$/,t=/-([a-z])/g,n=/^[^-]+$/,r=/^-(webkit|moz|ms|o|khtml)-/,s=/^-(ms)-/,i=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={}),i(u)?u:(u=u.toLowerCase(),c.reactCompat?u=u.replace(s,a):u=u.replace(r,a),u.replace(t,o))};return mt.camelCase=l,mt}var yt,rs;function Fc(){if(rs)return yt;rs=1;var e=yt&&yt.__importDefault||function(s){return s&&s.__esModule?s:{default:s}},t=e(_c()),n=Oc();function r(s,i){var o={};return!s||typeof s!="string"||(0,t.default)(s,function(a,l){a&&l&&(o[(0,n.camelCase)(a,i)]=l)}),o}return r.default=r,yt=r,yt}var zc=Fc();const Bc=ki(zc),uo=co("end"),br=co("start");function co(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 $c(e){const t=br(e),n=uo(e);if(t&&n)return{start:t,end:n}}function vt(e){return!e||typeof e!="object"?"":"position"in e||"type"in e?ss(e.position):"start"in e||"end"in e?ss(e):"line"in e||"column"in e?Kn(e):""}function Kn(e){return is(e&&e.line)+":"+is(e&&e.column)}function ss(e){return Kn(e&&e.start)+"-"+Kn(e&&e.end)}function is(e){return e&&typeof e=="number"?e:1}class ge extends Error{constructor(t,n,r){super(),typeof n=="string"&&(r=n,n=void 0);let s="",i={},o=!1;if(n&&("line"in n&&"column"in n?i={place:n}:"start"in n&&"end"in n?i={place:n}:"type"in n?i={ancestors:[n],place:n.position}:i={...n}),typeof t=="string"?s=t:!i.cause&&t&&(o=!0,s=t.message,i.cause=t),!i.ruleId&&!i.source&&typeof r=="string"){const l=r.indexOf(":");l===-1?i.ruleId=r:(i.source=r.slice(0,l),i.ruleId=r.slice(l+1))}if(!i.place&&i.ancestors&&i.ancestors){const l=i.ancestors[i.ancestors.length-1];l&&(i.place=l.position)}const a=i.place&&"start"in i.place?i.place.start:i.place;this.ancestors=i.ancestors||void 0,this.cause=i.cause||void 0,this.column=a?a.column:void 0,this.fatal=void 0,this.file="",this.message=s,this.line=a?a.line:void 0,this.name=vt(i.place)||"1:1",this.place=i.place||void 0,this.reason=this.message,this.ruleId=i.ruleId||void 0,this.source=i.source||void 0,this.stack=o&&i.cause&&typeof i.cause.stack=="string"?i.cause.stack:"",this.actual=void 0,this.expected=void 0,this.note=void 0,this.url=void 0}}ge.prototype.file="";ge.prototype.name="";ge.prototype.reason="";ge.prototype.message="";ge.prototype.stack="";ge.prototype.column=void 0;ge.prototype.line=void 0;ge.prototype.ancestors=void 0;ge.prototype.cause=void 0;ge.prototype.fatal=void 0;ge.prototype.place=void 0;ge.prototype.ruleId=void 0;ge.prototype.source=void 0;const Sr={}.hasOwnProperty,Uc=new Map,Kc=/[A-Z]/g,Hc=new Set(["table","tbody","thead","tfoot","tr"]),Vc=new Set(["td","th"]),ho="https://github.com/syntax-tree/hast-util-to-jsx-runtime";function qc(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=ed(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=Zc(n,t.jsx,t.jsxs)}const s={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"?xr:Pc,stylePropertyNameCase:t.stylePropertyNameCase||"dom",tableCellAlignToStyle:t.tableCellAlignToStyle!==!1},i=fo(s,e,void 0);return i&&typeof i!="string"?i:s.create(e,s.Fragment,{children:i||void 0},void 0)}function fo(e,t,n){if(t.type==="element")return Wc(e,t,n);if(t.type==="mdxFlowExpression"||t.type==="mdxTextExpression")return Gc(e,t);if(t.type==="mdxJsxFlowElement"||t.type==="mdxJsxTextElement")return Xc(e,t,n);if(t.type==="mdxjsEsm")return Qc(e,t);if(t.type==="root")return Yc(e,t,n);if(t.type==="text")return Jc(e,t)}function Wc(e,t,n){const r=e.schema;let s=r;t.tagName.toLowerCase()==="svg"&&r.space==="html"&&(s=xr,e.schema=s),e.ancestors.push(t);const i=go(e,t.tagName,!1),o=td(e,t);let a=vr(e,t);return Hc.has(t.tagName)&&(a=a.filter(function(l){return typeof l=="string"?!wc(l):!0})),po(e,o,i,t),kr(o,a),e.ancestors.pop(),e.schema=r,e.create(t,i,o,n)}function Gc(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)}Tt(e,t.position)}function Qc(e,t){if(t.data&&t.data.estree&&e.evaluater)return e.evaluater.evaluateProgram(t.data.estree);Tt(e,t.position)}function Xc(e,t,n){const r=e.schema;let s=r;t.name==="svg"&&r.space==="html"&&(s=xr,e.schema=s),e.ancestors.push(t);const i=t.name===null?e.Fragment:go(e,t.name,!0),o=nd(e,t),a=vr(e,t);return po(e,o,i,t),kr(o,a),e.ancestors.pop(),e.schema=r,e.create(t,i,o,n)}function Yc(e,t,n){const r={};return kr(r,vr(e,t)),e.create(t,e.Fragment,r,n)}function Jc(e,t){return t.value}function po(e,t,n,r){typeof n!="string"&&n!==e.Fragment&&e.passNode&&(t.node=r)}function kr(e,t){if(t.length>0){const n=t.length>1?t:t[0];n&&(e.children=n)}}function Zc(e,t,n){return r;function r(s,i,o,a){const u=Array.isArray(o.children)?n:t;return a?u(i,o,a):u(i,o)}}function ed(e,t){return n;function n(r,s,i,o){const a=Array.isArray(i.children),l=br(r);return t(s,i,o,a,{columnNumber:l?l.column-1:void 0,fileName:e,lineNumber:l?l.line:void 0},void 0)}}function td(e,t){const n={};let r,s;for(s in t.properties)if(s!=="children"&&Sr.call(t.properties,s)){const i=rd(e,s,t.properties[s]);if(i){const[o,a]=i;e.tableCellAlignToStyle&&o==="align"&&typeof a=="string"&&Vc.has(t.tagName)?r=a:n[o]=a}}if(r){const i=n.style||(n.style={});i[e.stylePropertyNameCase==="css"?"text-align":"textAlign"]=r}return n}function nd(e,t){const n={};for(const r of t.attributes)if(r.type==="mdxJsxExpressionAttribute")if(r.data&&r.data.estree&&e.evaluater){const i=r.data.estree.body[0];i.type;const o=i.expression;o.type;const a=o.properties[0];a.type,Object.assign(n,e.evaluater.evaluateExpression(a.argument))}else Tt(e,t.position);else{const s=r.name;let i;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,i=e.evaluater.evaluateExpression(a.expression)}else Tt(e,t.position);else i=r.value===null?!0:r.value;n[s]=i}return n}function vr(e,t){const n=[];let r=-1;const s=e.passKeys?new Map:Uc;for(;++r<t.children.length;){const i=t.children[r];let o;if(e.passKeys){const l=i.type==="element"?i.tagName:i.type==="mdxJsxFlowElement"||i.type==="mdxJsxTextElement"?i.name:void 0;if(l){const u=s.get(l)||0;o=l+"-"+u,s.set(l,u+1)}}const a=fo(e,i,o);a!==void 0&&n.push(a)}return n}function rd(e,t,n){const r=Ac(e.schema,t);if(!(n==null||typeof n=="number"&&Number.isNaN(n))){if(Array.isArray(n)&&(n=r.commaSeparated?xc(n):jc(n)),r.property==="style"){let s=typeof n=="object"?n:sd(e,String(n));return e.stylePropertyNameCase==="css"&&(s=id(s)),["style",s]}return[e.elementAttributeNameCase==="react"&&r.space?Mc[r.property]||r.property:r.attribute,n]}}function sd(e,t){try{return Bc(t,{reactCompat:!0})}catch(n){if(e.ignoreInvalidStyle)return{};const r=n,s=new ge("Cannot parse `style` attribute",{ancestors:e.ancestors,cause:r,ruleId:"style",source:"hast-util-to-jsx-runtime"});throw s.file=e.filePath||void 0,s.url=ho+"#cannot-parse-style-attribute",s}}function go(e,t,n){let r;if(!n)r={type:"Literal",value:t};else if(t.includes(".")){const s=t.split(".");let i=-1,o;for(;++i<s.length;){const a=Xr(s[i])?{type:"Identifier",name:s[i]}:{type:"Literal",value:s[i]};o=o?{type:"MemberExpression",object:o,property:a,computed:!!(i&&a.type==="Literal"),optional:!1}:a}r=o}else r=Xr(t)&&!/^[a-z]/.test(t)?{type:"Identifier",name:t}:{type:"Literal",value:t};if(r.type==="Literal"){const s=r.value;return Sr.call(e.components,s)?e.components[s]:s}if(e.evaluater)return e.evaluater.evaluateExpression(r);Tt(e)}function Tt(e,t){const n=new ge("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=ho+"#cannot-handle-mdx-estrees-without-createevaluater",n}function id(e){const t={};let n;for(n in e)Sr.call(e,n)&&(t[od(n)]=e[n]);return t}function od(e){let t=e.replace(Kc,ad);return t.slice(0,3)==="ms-"&&(t="-"+t),t}function ad(e){return"-"+e.toLowerCase()}const hn={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"]},ld={};function wr(e,t){const n=ld,r=typeof n.includeImageAlt=="boolean"?n.includeImageAlt:!0,s=typeof n.includeHtml=="boolean"?n.includeHtml:!0;return mo(e,r,s)}function mo(e,t,n){if(ud(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 os(e.children,t,n)}return Array.isArray(e)?os(e,t,n):""}function os(e,t,n){const r=[];let s=-1;for(;++s<e.length;)r[s]=mo(e[s],t,n);return r.join("")}function ud(e){return!!(e&&typeof e=="object")}const as=document.createElement("i");function Cr(e){const t="&"+e+";";as.innerHTML=t;const n=as.textContent;return n.charCodeAt(n.length-1)===59&&e!=="semi"||n===t?!1:n}function Te(e,t,n,r){const s=e.length;let i=0,o;if(t<0?t=-t>s?0:s+t:t=t>s?s: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);i<r.length;)o=r.slice(i,i+1e4),o.unshift(t,0),e.splice(...o),i+=1e4,t+=1e4}function Ae(e,t){return e.length>0?(Te(e,e.length,0,t),e):t}const ls={}.hasOwnProperty;function yo(e){const t={};let n=-1;for(;++n<e.length;)cd(t,e[n]);return t}function cd(e,t){let n;for(n in t){const s=(ls.call(e,n)?e[n]:void 0)||(e[n]={}),i=t[n];let o;if(i)for(o in i){ls.call(s,o)||(s[o]=[]);const a=i[o];dd(s[o],Array.isArray(a)?a:a?[a]:[])}}}function dd(e,t){let n=-1;const r=[];for(;++n<t.length;)(t[n].add==="after"?e:r).push(t[n]);Te(e,0,0,r)}function xo(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 je(e){return e.replace(/[\t\n\r ]+/g," ").replace(/^ | $/g,"").toLowerCase().toUpperCase()}const me=Qe(/[A-Za-z]/),pe=Qe(/[\dA-Za-z]/),hd=Qe(/[#-'*+\--9=?A-Z^-~]/);function Wt(e){return e!==null&&(e<32||e===127)}const Hn=Qe(/\d/),fd=Qe(/[\dA-Fa-f]/),pd=Qe(/[!-/:-@[-`{-~]/);function B(e){return e!==null&&e<-2}function ee(e){return e!==null&&(e<0||e===32)}function V(e){return e===-2||e===-1||e===32}const en=Qe(new RegExp("\\p{P}|\\p{S}","u")),tt=Qe(/\s/);function Qe(e){return t;function t(n){return n!==null&&n>-1&&e.test(String.fromCharCode(n))}}function ft(e){const t=[];let n=-1,r=0,s=0;for(;++n<e.length;){const i=e.charCodeAt(n);let o="";if(i===37&&pe(e.charCodeAt(n+1))&&pe(e.charCodeAt(n+2)))s=2;else if(i<128)/[!#$&-;=?-Z_a-z~]/.test(String.fromCharCode(i))||(o=String.fromCharCode(i));else if(i>55295&&i<57344){const a=e.charCodeAt(n+1);i<56320&&a>56319&&a<57344?(o=String.fromCharCode(i,a),s=1):o="�"}else o=String.fromCharCode(i);o&&(t.push(e.slice(r,n),encodeURIComponent(o)),r=n+s+1,o=""),s&&(n+=s,s=0)}return t.join("")+e.slice(r)}function X(e,t,n,r){const s=r?r-1:Number.POSITIVE_INFINITY;let i=0;return o;function o(l){return V(l)?(e.enter(n),a(l)):t(l)}function a(l){return V(l)&&i++<s?(e.consume(l),a):(e.exit(n),t(l))}}const gd={tokenize:md};function md(e){const t=e.attempt(this.parser.constructs.contentInitial,r,s);let n;return t;function r(a){if(a===null){e.consume(a);return}return e.enter("lineEnding"),e.consume(a),e.exit("lineEnding"),X(e,t,"linePrefix")}function s(a){return e.enter("paragraph"),i(a)}function i(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 B(a)?(e.consume(a),e.exit("chunkText"),i):(e.consume(a),o)}}const yd={tokenize:xd},us={tokenize:bd};function xd(e){const t=this,n=[];let r=0,s,i,o;return a;function a(w){if(r<n.length){const T=n[r];return t.containerState=T[1],e.attempt(T[0].continuation,l,u)(w)}return u(w)}function l(w){if(r++,t.containerState._closeFlow){t.containerState._closeFlow=void 0,s&&v();const T=t.events.length;let A=T,k;for(;A--;)if(t.events[A][0]==="exit"&&t.events[A][1].type==="chunkFlow"){k=t.events[A][1].end;break}g(r);let N=T;for(;N<t.events.length;)t.events[N][1].end={...k},N++;return Te(t.events,A+1,0,t.events.slice(T)),t.events.length=N,u(w)}return a(w)}function u(w){if(r===n.length){if(!s)return p(w);if(s.currentConstruct&&s.currentConstruct.concrete)return m(w);t.interrupt=!!(s.currentConstruct&&!s._gfmTableDynamicInterruptHack)}return t.containerState={},e.check(us,c,d)(w)}function c(w){return s&&v(),g(r),p(w)}function d(w){return t.parser.lazy[t.now().line]=r!==n.length,o=t.now().offset,m(w)}function p(w){return t.containerState={},e.attempt(us,f,m)(w)}function f(w){return r++,n.push([t.currentConstruct,t.containerState]),p(w)}function m(w){if(w===null){s&&v(),g(0),e.consume(w);return}return s=s||t.parser.flow(t.now()),e.enter("chunkFlow",{_tokenizer:s,contentType:"flow",previous:i}),y(w)}function y(w){if(w===null){b(e.exit("chunkFlow"),!0),g(0),e.consume(w);return}return B(w)?(e.consume(w),b(e.exit("chunkFlow")),r=0,t.interrupt=void 0,a):(e.consume(w),y)}function b(w,T){const A=t.sliceStream(w);if(T&&A.push(null),w.previous=i,i&&(i.next=w),i=w,s.defineSkip(w.start),s.write(A),t.parser.lazy[w.start.line]){let k=s.events.length;for(;k--;)if(s.events[k][1].start.offset<o&&(!s.events[k][1].end||s.events[k][1].end.offset>o))return;const N=t.events.length;let F=N,O,I;for(;F--;)if(t.events[F][0]==="exit"&&t.events[F][1].type==="chunkFlow"){if(O){I=t.events[F][1].end;break}O=!0}for(g(r),k=N;k<t.events.length;)t.events[k][1].end={...I},k++;Te(t.events,F+1,0,t.events.slice(N)),t.events.length=k}}function g(w){let T=n.length;for(;T-- >w;){const A=n[T];t.containerState=A[1],A[0].exit.call(t,e)}n.length=w}function v(){s.write([null]),i=void 0,s=void 0,t.containerState._closeFlow=void 0}}function bd(e,t,n){return X(e,e.attempt(this.parser.constructs.document,t,n),"linePrefix",this.parser.constructs.disable.null.includes("codeIndented")?void 0:4)}function dt(e){if(e===null||ee(e)||tt(e))return 1;if(en(e))return 2}function tn(e,t,n){const r=[];let s=-1;for(;++s<e.length;){const i=e[s].resolveAll;i&&!r.includes(i)&&(t=i(t,n),r.push(i))}return t}const Vn={name:"attention",resolveAll:Sd,tokenize:kd};function Sd(e,t){let n=-1,r,s,i,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 d={...e[r][1].end},p={...e[n][1].start};cs(d,-l),cs(p,l),o={type:l>1?"strongSequence":"emphasisSequence",start:d,end:{...e[r][1].end}},a={type:l>1?"strongSequence":"emphasisSequence",start:{...e[n][1].start},end:p},i={type:l>1?"strongText":"emphasisText",start:{...e[r][1].end},end:{...e[n][1].start}},s={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=Ae(u,[["enter",e[r][1],t],["exit",e[r][1],t]])),u=Ae(u,[["enter",s,t],["enter",o,t],["exit",o,t],["enter",i,t]]),u=Ae(u,tn(t.parser.constructs.insideSpan.null,e.slice(r+1,n),t)),u=Ae(u,[["exit",i,t],["enter",a,t],["exit",a,t],["exit",s,t]]),e[n][1].end.offset-e[n][1].start.offset?(c=2,u=Ae(u,[["enter",e[n][1],t],["exit",e[n][1],t]])):c=0,Te(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 kd(e,t){const n=this.parser.constructs.attentionMarkers.null,r=this.previous,s=dt(r);let i;return o;function o(l){return i=l,e.enter("attentionSequence"),a(l)}function a(l){if(l===i)return e.consume(l),a;const u=e.exit("attentionSequence"),c=dt(l),d=!c||c===2&&s||n.includes(l),p=!s||s===2&&c||n.includes(r);return u._open=!!(i===42?d:d&&(s||!p)),u._close=!!(i===42?p:p&&(c||!d)),t(l)}}function cs(e,t){e.column+=t,e.offset+=t,e._bufferIndex+=t}const vd={name:"autolink",tokenize:wd};function wd(e,t,n){let r=0;return s;function s(f){return e.enter("autolink"),e.enter("autolinkMarker"),e.consume(f),e.exit("autolinkMarker"),e.enter("autolinkProtocol"),i}function i(f){return me(f)?(e.consume(f),o):f===64?n(f):u(f)}function o(f){return f===43||f===45||f===46||pe(f)?(r=1,a(f)):u(f)}function a(f){return f===58?(e.consume(f),r=0,l):(f===43||f===45||f===46||pe(f))&&r++<32?(e.consume(f),a):(r=0,u(f))}function l(f){return f===62?(e.exit("autolinkProtocol"),e.enter("autolinkMarker"),e.consume(f),e.exit("autolinkMarker"),e.exit("autolink"),t):f===null||f===32||f===60||Wt(f)?n(f):(e.consume(f),l)}function u(f){return f===64?(e.consume(f),c):hd(f)?(e.consume(f),u):n(f)}function c(f){return pe(f)?d(f):n(f)}function d(f){return f===46?(e.consume(f),r=0,c):f===62?(e.exit("autolinkProtocol").type="autolinkEmail",e.enter("autolinkMarker"),e.consume(f),e.exit("autolinkMarker"),e.exit("autolink"),t):p(f)}function p(f){if((f===45||pe(f))&&r++<63){const m=f===45?p:d;return e.consume(f),m}return n(f)}}const Nt={partial:!0,tokenize:Cd};function Cd(e,t,n){return r;function r(i){return V(i)?X(e,s,"linePrefix")(i):s(i)}function s(i){return i===null||B(i)?t(i):n(i)}}const bo={continuation:{tokenize:Td},exit:Md,name:"blockQuote",tokenize:Id};function Id(e,t,n){const r=this;return s;function s(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"),i}return n(o)}function i(o){return V(o)?(e.enter("blockQuotePrefixWhitespace"),e.consume(o),e.exit("blockQuotePrefixWhitespace"),e.exit("blockQuotePrefix"),t):(e.exit("blockQuotePrefix"),t(o))}}function Td(e,t,n){const r=this;return s;function s(o){return V(o)?X(e,i,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(o):i(o)}function i(o){return e.attempt(bo,t,n)(o)}}function Md(e){e.exit("blockQuote")}const So={name:"characterEscape",tokenize:Rd};function Rd(e,t,n){return r;function r(i){return e.enter("characterEscape"),e.enter("escapeMarker"),e.consume(i),e.exit("escapeMarker"),s}function s(i){return pd(i)?(e.enter("characterEscapeValue"),e.consume(i),e.exit("characterEscapeValue"),e.exit("characterEscape"),t):n(i)}}const ko={name:"characterReference",tokenize:Ed};function Ed(e,t,n){const r=this;let s=0,i,o;return a;function a(d){return e.enter("characterReference"),e.enter("characterReferenceMarker"),e.consume(d),e.exit("characterReferenceMarker"),l}function l(d){return d===35?(e.enter("characterReferenceMarkerNumeric"),e.consume(d),e.exit("characterReferenceMarkerNumeric"),u):(e.enter("characterReferenceValue"),i=31,o=pe,c(d))}function u(d){return d===88||d===120?(e.enter("characterReferenceMarkerHexadecimal"),e.consume(d),e.exit("characterReferenceMarkerHexadecimal"),e.enter("characterReferenceValue"),i=6,o=fd,c):(e.enter("characterReferenceValue"),i=7,o=Hn,c(d))}function c(d){if(d===59&&s){const p=e.exit("characterReferenceValue");return o===pe&&!Cr(r.sliceSerialize(p))?n(d):(e.enter("characterReferenceMarker"),e.consume(d),e.exit("characterReferenceMarker"),e.exit("characterReference"),t)}return o(d)&&s++<i?(e.consume(d),c):n(d)}}const ds={partial:!0,tokenize:Ld},hs={concrete:!0,name:"codeFenced",tokenize:Ad};function Ad(e,t,n){const r=this,s={partial:!0,tokenize:A};let i=0,o=0,a;return l;function l(k){return u(k)}function u(k){const N=r.events[r.events.length-1];return i=N&&N[1].type==="linePrefix"?N[2].sliceSerialize(N[1],!0).length:0,a=k,e.enter("codeFenced"),e.enter("codeFencedFence"),e.enter("codeFencedFenceSequence"),c(k)}function c(k){return k===a?(o++,e.consume(k),c):o<3?n(k):(e.exit("codeFencedFenceSequence"),V(k)?X(e,d,"whitespace")(k):d(k))}function d(k){return k===null||B(k)?(e.exit("codeFencedFence"),r.interrupt?t(k):e.check(ds,y,T)(k)):(e.enter("codeFencedFenceInfo"),e.enter("chunkString",{contentType:"string"}),p(k))}function p(k){return k===null||B(k)?(e.exit("chunkString"),e.exit("codeFencedFenceInfo"),d(k)):V(k)?(e.exit("chunkString"),e.exit("codeFencedFenceInfo"),X(e,f,"whitespace")(k)):k===96&&k===a?n(k):(e.consume(k),p)}function f(k){return k===null||B(k)?d(k):(e.enter("codeFencedFenceMeta"),e.enter("chunkString",{contentType:"string"}),m(k))}function m(k){return k===null||B(k)?(e.exit("chunkString"),e.exit("codeFencedFenceMeta"),d(k)):k===96&&k===a?n(k):(e.consume(k),m)}function y(k){return e.attempt(s,T,b)(k)}function b(k){return e.enter("lineEnding"),e.consume(k),e.exit("lineEnding"),g}function g(k){return i>0&&V(k)?X(e,v,"linePrefix",i+1)(k):v(k)}function v(k){return k===null||B(k)?e.check(ds,y,T)(k):(e.enter("codeFlowValue"),w(k))}function w(k){return k===null||B(k)?(e.exit("codeFlowValue"),v(k)):(e.consume(k),w)}function T(k){return e.exit("codeFenced"),t(k)}function A(k,N,F){let O=0;return I;function I(P){return k.enter("lineEnding"),k.consume(P),k.exit("lineEnding"),j}function j(P){return k.enter("codeFencedFence"),V(P)?X(k,_,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(P):_(P)}function _(P){return P===a?(k.enter("codeFencedFenceSequence"),W(P)):F(P)}function W(P){return P===a?(O++,k.consume(P),W):O>=o?(k.exit("codeFencedFenceSequence"),V(P)?X(k,z,"whitespace")(P):z(P)):F(P)}function z(P){return P===null||B(P)?(k.exit("codeFencedFence"),N(P)):F(P)}}}function Ld(e,t,n){const r=this;return s;function s(o){return o===null?n(o):(e.enter("lineEnding"),e.consume(o),e.exit("lineEnding"),i)}function i(o){return r.parser.lazy[r.now().line]?n(o):t(o)}}const fn={name:"codeIndented",tokenize:Pd},Nd={partial:!0,tokenize:jd};function Pd(e,t,n){const r=this;return s;function s(u){return e.enter("codeIndented"),X(e,i,"linePrefix",5)(u)}function i(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):B(u)?e.attempt(Nd,o,l)(u):(e.enter("codeFlowValue"),a(u))}function a(u){return u===null||B(u)?(e.exit("codeFlowValue"),o(u)):(e.consume(u),a)}function l(u){return e.exit("codeIndented"),t(u)}}function jd(e,t,n){const r=this;return s;function s(o){return r.parser.lazy[r.now().line]?n(o):B(o)?(e.enter("lineEnding"),e.consume(o),e.exit("lineEnding"),s):X(e,i,"linePrefix",5)(o)}function i(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):B(o)?s(o):n(o)}}const Dd={name:"codeText",previous:Od,resolve:_d,tokenize:Fd};function _d(e){let t=e.length-4,n=3,r,s;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;)s===void 0?r!==t&&e[r][1].type!=="lineEnding"&&(s=r):(r===t||e[r][1].type==="lineEnding")&&(e[s][1].type="codeTextData",r!==s+2&&(e[s][1].end=e[r-1][1].end,e.splice(s+2,r-s-2),t-=r-s-2,r=s+2),s=void 0);return e}function Od(e){return e!==96||this.events[this.events.length-1][1].type==="characterEscape"}function Fd(e,t,n){let r=0,s,i;return o;function o(d){return e.enter("codeText"),e.enter("codeTextSequence"),a(d)}function a(d){return d===96?(e.consume(d),r++,a):(e.exit("codeTextSequence"),l(d))}function l(d){return d===null?n(d):d===32?(e.enter("space"),e.consume(d),e.exit("space"),l):d===96?(i=e.enter("codeTextSequence"),s=0,c(d)):B(d)?(e.enter("lineEnding"),e.consume(d),e.exit("lineEnding"),l):(e.enter("codeTextData"),u(d))}function u(d){return d===null||d===32||d===96||B(d)?(e.exit("codeTextData"),l(d)):(e.consume(d),u)}function c(d){return d===96?(e.consume(d),s++,c):s===r?(e.exit("codeTextSequence"),e.exit("codeText"),t(d)):(i.type="codeTextData",u(d))}}class zd{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 s=n||0;this.setCursor(Math.trunc(t));const i=this.right.splice(this.right.length-s,Number.POSITIVE_INFINITY);return r&&xt(this.left,r),i.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),xt(this.left,t)}unshift(t){this.setCursor(0),this.right.push(t)}unshiftMany(t){this.setCursor(0),xt(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);xt(this.right,n.reverse())}else{const n=this.right.splice(this.left.length+this.right.length-t,Number.POSITIVE_INFINITY);xt(this.left,n.reverse())}}}function xt(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 vo(e){const t={};let n=-1,r,s,i,o,a,l,u;const c=new zd(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,i=0,i<l.length&&l[i][1].type==="lineEndingBlank"&&(i+=2),i<l.length&&l[i][1].type==="content"))for(;++i<l.length&&l[i][1].type!=="content";)l[i][1].type==="chunkText"&&(l[i][1]._isInFirstContentOfListItem=!0,i++);if(r[0]==="enter")r[1].contentType&&(Object.assign(t,Bd(c,n)),n=t[n],u=!0);else if(r[1]._container){for(i=n,s=void 0;i--;)if(o=c.get(i),o[1].type==="lineEnding"||o[1].type==="lineEndingBlank")o[0]==="enter"&&(s&&(c.get(s)[1].type="lineEndingBlank"),o[1].type="lineEnding",s=i);else if(!(o[1].type==="linePrefix"||o[1].type==="listItemIndent"))break;s&&(r[1].end={...c.get(s)[1].start},a=c.slice(s,n),a.unshift(r),c.splice(s,n-s+1,a))}}return Te(e,0,Number.POSITIVE_INFINITY,c.slice(0)),!u}function Bd(e,t){const n=e.get(t)[1],r=e.get(t)[2];let s=t-1;const i=[];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,d,p=-1,f=n,m=0,y=0;const b=[y];for(;f;){for(;e.get(++s)[1]!==f;);i.push(s),f._tokenizer||(c=r.sliceStream(f),f.next||c.push(null),d&&o.defineSkip(f.start),f._isInFirstContentOfListItem&&(o._gfmTasklistFirstContentOfListItem=!0),o.write(c),f._isInFirstContentOfListItem&&(o._gfmTasklistFirstContentOfListItem=void 0)),d=f,f=f.next}for(f=n;++p<a.length;)a[p][0]==="exit"&&a[p-1][0]==="enter"&&a[p][1].type===a[p-1][1].type&&a[p][1].start.line!==a[p][1].end.line&&(y=p+1,b.push(y),f._tokenizer=void 0,f.previous=void 0,f=f.next);for(o.events=[],f?(f._tokenizer=void 0,f.previous=void 0):b.pop(),p=b.length;p--;){const g=a.slice(b[p],b[p+1]),v=i.pop();l.push([v,v+g.length-1]),e.splice(v,2,g)}for(l.reverse(),p=-1;++p<l.length;)u[m+l[p][0]]=m+l[p][1],m+=l[p][1]-l[p][0]-1;return u}const $d={resolve:Kd,tokenize:Hd},Ud={partial:!0,tokenize:Vd};function Kd(e){return vo(e),e}function Hd(e,t){let n;return r;function r(a){return e.enter("content"),n=e.enter("chunkContent",{contentType:"content"}),s(a)}function s(a){return a===null?i(a):B(a)?e.check(Ud,o,i)(a):(e.consume(a),s)}function i(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,s}}function Vd(e,t,n){const r=this;return s;function s(o){return e.exit("chunkContent"),e.enter("lineEnding"),e.consume(o),e.exit("lineEnding"),X(e,i,"linePrefix")}function i(o){if(o===null||B(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 wo(e,t,n,r,s,i,o,a,l){const u=l||Number.POSITIVE_INFINITY;let c=0;return d;function d(g){return g===60?(e.enter(r),e.enter(s),e.enter(i),e.consume(g),e.exit(i),p):g===null||g===32||g===41||Wt(g)?n(g):(e.enter(r),e.enter(o),e.enter(a),e.enter("chunkString",{contentType:"string"}),y(g))}function p(g){return g===62?(e.enter(i),e.consume(g),e.exit(i),e.exit(s),e.exit(r),t):(e.enter(a),e.enter("chunkString",{contentType:"string"}),f(g))}function f(g){return g===62?(e.exit("chunkString"),e.exit(a),p(g)):g===null||g===60||B(g)?n(g):(e.consume(g),g===92?m:f)}function m(g){return g===60||g===62||g===92?(e.consume(g),f):f(g)}function y(g){return!c&&(g===null||g===41||ee(g))?(e.exit("chunkString"),e.exit(a),e.exit(o),e.exit(r),t(g)):c<u&&g===40?(e.consume(g),c++,y):g===41?(e.consume(g),c--,y):g===null||g===32||g===40||Wt(g)?n(g):(e.consume(g),g===92?b:y)}function b(g){return g===40||g===41||g===92?(e.consume(g),y):y(g)}}function Co(e,t,n,r,s,i){const o=this;let a=0,l;return u;function u(f){return e.enter(r),e.enter(s),e.consume(f),e.exit(s),e.enter(i),c}function c(f){return a>999||f===null||f===91||f===93&&!l||f===94&&!a&&"_hiddenFootnoteSupport"in o.parser.constructs?n(f):f===93?(e.exit(i),e.enter(s),e.consume(f),e.exit(s),e.exit(r),t):B(f)?(e.enter("lineEnding"),e.consume(f),e.exit("lineEnding"),c):(e.enter("chunkString",{contentType:"string"}),d(f))}function d(f){return f===null||f===91||f===93||B(f)||a++>999?(e.exit("chunkString"),c(f)):(e.consume(f),l||(l=!V(f)),f===92?p:d)}function p(f){return f===91||f===92||f===93?(e.consume(f),a++,d):d(f)}}function Io(e,t,n,r,s,i){let o;return a;function a(p){return p===34||p===39||p===40?(e.enter(r),e.enter(s),e.consume(p),e.exit(s),o=p===40?41:p,l):n(p)}function l(p){return p===o?(e.enter(s),e.consume(p),e.exit(s),e.exit(r),t):(e.enter(i),u(p))}function u(p){return p===o?(e.exit(i),l(o)):p===null?n(p):B(p)?(e.enter("lineEnding"),e.consume(p),e.exit("lineEnding"),X(e,u,"linePrefix")):(e.enter("chunkString",{contentType:"string"}),c(p))}function c(p){return p===o||p===null||B(p)?(e.exit("chunkString"),u(p)):(e.consume(p),p===92?d:c)}function d(p){return p===o||p===92?(e.consume(p),c):c(p)}}function wt(e,t){let n;return r;function r(s){return B(s)?(e.enter("lineEnding"),e.consume(s),e.exit("lineEnding"),n=!0,r):V(s)?X(e,r,n?"linePrefix":"lineSuffix")(s):t(s)}}const qd={name:"definition",tokenize:Gd},Wd={partial:!0,tokenize:Qd};function Gd(e,t,n){const r=this;let s;return i;function i(f){return e.enter("definition"),o(f)}function o(f){return Co.call(r,e,a,n,"definitionLabel","definitionLabelMarker","definitionLabelString")(f)}function a(f){return s=je(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)),f===58?(e.enter("definitionMarker"),e.consume(f),e.exit("definitionMarker"),l):n(f)}function l(f){return ee(f)?wt(e,u)(f):u(f)}function u(f){return wo(e,c,n,"definitionDestination","definitionDestinationLiteral","definitionDestinationLiteralMarker","definitionDestinationRaw","definitionDestinationString")(f)}function c(f){return e.attempt(Wd,d,d)(f)}function d(f){return V(f)?X(e,p,"whitespace")(f):p(f)}function p(f){return f===null||B(f)?(e.exit("definition"),r.parser.defined.push(s),t(f)):n(f)}}function Qd(e,t,n){return r;function r(a){return ee(a)?wt(e,s)(a):n(a)}function s(a){return Io(e,i,n,"definitionTitle","definitionTitleMarker","definitionTitleString")(a)}function i(a){return V(a)?X(e,o,"whitespace")(a):o(a)}function o(a){return a===null||B(a)?t(a):n(a)}}const Xd={name:"hardBreakEscape",tokenize:Yd};function Yd(e,t,n){return r;function r(i){return e.enter("hardBreakEscape"),e.consume(i),s}function s(i){return B(i)?(e.exit("hardBreakEscape"),t(i)):n(i)}}const Jd={name:"headingAtx",resolve:Zd,tokenize:eh};function Zd(e,t){let n=e.length-2,r=3,s,i;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&&(s={type:"atxHeadingText",start:e[r][1].start,end:e[n][1].end},i={type:"chunkText",start:e[r][1].start,end:e[n][1].end,contentType:"text"},Te(e,r,n-r+1,[["enter",s,t],["enter",i,t],["exit",i,t],["exit",s,t]])),e}function eh(e,t,n){let r=0;return s;function s(c){return e.enter("atxHeading"),i(c)}function i(c){return e.enter("atxHeadingSequence"),o(c)}function o(c){return c===35&&r++<6?(e.consume(c),o):c===null||ee(c)?(e.exit("atxHeadingSequence"),a(c)):n(c)}function a(c){return c===35?(e.enter("atxHeadingSequence"),l(c)):c===null||B(c)?(e.exit("atxHeading"),t(c)):V(c)?X(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||ee(c)?(e.exit("atxHeadingText"),a(c)):(e.consume(c),u)}}const th=["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"],fs=["pre","script","style","textarea"],nh={concrete:!0,name:"htmlFlow",resolveTo:ih,tokenize:oh},rh={partial:!0,tokenize:lh},sh={partial:!0,tokenize:ah};function ih(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 oh(e,t,n){const r=this;let s,i,o,a,l;return u;function u(x){return c(x)}function c(x){return e.enter("htmlFlow"),e.enter("htmlFlowData"),e.consume(x),d}function d(x){return x===33?(e.consume(x),p):x===47?(e.consume(x),i=!0,y):x===63?(e.consume(x),s=3,r.interrupt?t:S):me(x)?(e.consume(x),o=String.fromCharCode(x),b):n(x)}function p(x){return x===45?(e.consume(x),s=2,f):x===91?(e.consume(x),s=5,a=0,m):me(x)?(e.consume(x),s=4,r.interrupt?t:S):n(x)}function f(x){return x===45?(e.consume(x),r.interrupt?t:S):n(x)}function m(x){const de="CDATA[";return x===de.charCodeAt(a++)?(e.consume(x),a===de.length?r.interrupt?t:_:m):n(x)}function y(x){return me(x)?(e.consume(x),o=String.fromCharCode(x),b):n(x)}function b(x){if(x===null||x===47||x===62||ee(x)){const de=x===47,ke=o.toLowerCase();return!de&&!i&&fs.includes(ke)?(s=1,r.interrupt?t(x):_(x)):th.includes(o.toLowerCase())?(s=6,de?(e.consume(x),g):r.interrupt?t(x):_(x)):(s=7,r.interrupt&&!r.parser.lazy[r.now().line]?n(x):i?v(x):w(x))}return x===45||pe(x)?(e.consume(x),o+=String.fromCharCode(x),b):n(x)}function g(x){return x===62?(e.consume(x),r.interrupt?t:_):n(x)}function v(x){return V(x)?(e.consume(x),v):I(x)}function w(x){return x===47?(e.consume(x),I):x===58||x===95||me(x)?(e.consume(x),T):V(x)?(e.consume(x),w):I(x)}function T(x){return x===45||x===46||x===58||x===95||pe(x)?(e.consume(x),T):A(x)}function A(x){return x===61?(e.consume(x),k):V(x)?(e.consume(x),A):w(x)}function k(x){return x===null||x===60||x===61||x===62||x===96?n(x):x===34||x===39?(e.consume(x),l=x,N):V(x)?(e.consume(x),k):F(x)}function N(x){return x===l?(e.consume(x),l=null,O):x===null||B(x)?n(x):(e.consume(x),N)}function F(x){return x===null||x===34||x===39||x===47||x===60||x===61||x===62||x===96||ee(x)?A(x):(e.consume(x),F)}function O(x){return x===47||x===62||V(x)?w(x):n(x)}function I(x){return x===62?(e.consume(x),j):n(x)}function j(x){return x===null||B(x)?_(x):V(x)?(e.consume(x),j):n(x)}function _(x){return x===45&&s===2?(e.consume(x),Q):x===60&&s===1?(e.consume(x),Y):x===62&&s===4?(e.consume(x),J):x===63&&s===3?(e.consume(x),S):x===93&&s===5?(e.consume(x),ye):B(x)&&(s===6||s===7)?(e.exit("htmlFlowData"),e.check(rh,ce,W)(x)):x===null||B(x)?(e.exit("htmlFlowData"),W(x)):(e.consume(x),_)}function W(x){return e.check(sh,z,ce)(x)}function z(x){return e.enter("lineEnding"),e.consume(x),e.exit("lineEnding"),P}function P(x){return x===null||B(x)?W(x):(e.enter("htmlFlowData"),_(x))}function Q(x){return x===45?(e.consume(x),S):_(x)}function Y(x){return x===47?(e.consume(x),o="",ue):_(x)}function ue(x){if(x===62){const de=o.toLowerCase();return fs.includes(de)?(e.consume(x),J):_(x)}return me(x)&&o.length<8?(e.consume(x),o+=String.fromCharCode(x),ue):_(x)}function ye(x){return x===93?(e.consume(x),S):_(x)}function S(x){return x===62?(e.consume(x),J):x===45&&s===2?(e.consume(x),S):_(x)}function J(x){return x===null||B(x)?(e.exit("htmlFlowData"),ce(x)):(e.consume(x),J)}function ce(x){return e.exit("htmlFlow"),t(x)}}function ah(e,t,n){const r=this;return s;function s(o){return B(o)?(e.enter("lineEnding"),e.consume(o),e.exit("lineEnding"),i):n(o)}function i(o){return r.parser.lazy[r.now().line]?n(o):t(o)}}function lh(e,t,n){return r;function r(s){return e.enter("lineEnding"),e.consume(s),e.exit("lineEnding"),e.attempt(Nt,t,n)}}const uh={name:"htmlText",tokenize:ch};function ch(e,t,n){const r=this;let s,i,o;return a;function a(S){return e.enter("htmlText"),e.enter("htmlTextData"),e.consume(S),l}function l(S){return S===33?(e.consume(S),u):S===47?(e.consume(S),A):S===63?(e.consume(S),w):me(S)?(e.consume(S),F):n(S)}function u(S){return S===45?(e.consume(S),c):S===91?(e.consume(S),i=0,m):me(S)?(e.consume(S),v):n(S)}function c(S){return S===45?(e.consume(S),f):n(S)}function d(S){return S===null?n(S):S===45?(e.consume(S),p):B(S)?(o=d,Y(S)):(e.consume(S),d)}function p(S){return S===45?(e.consume(S),f):d(S)}function f(S){return S===62?Q(S):S===45?p(S):d(S)}function m(S){const J="CDATA[";return S===J.charCodeAt(i++)?(e.consume(S),i===J.length?y:m):n(S)}function y(S){return S===null?n(S):S===93?(e.consume(S),b):B(S)?(o=y,Y(S)):(e.consume(S),y)}function b(S){return S===93?(e.consume(S),g):y(S)}function g(S){return S===62?Q(S):S===93?(e.consume(S),g):y(S)}function v(S){return S===null||S===62?Q(S):B(S)?(o=v,Y(S)):(e.consume(S),v)}function w(S){return S===null?n(S):S===63?(e.consume(S),T):B(S)?(o=w,Y(S)):(e.consume(S),w)}function T(S){return S===62?Q(S):w(S)}function A(S){return me(S)?(e.consume(S),k):n(S)}function k(S){return S===45||pe(S)?(e.consume(S),k):N(S)}function N(S){return B(S)?(o=N,Y(S)):V(S)?(e.consume(S),N):Q(S)}function F(S){return S===45||pe(S)?(e.consume(S),F):S===47||S===62||ee(S)?O(S):n(S)}function O(S){return S===47?(e.consume(S),Q):S===58||S===95||me(S)?(e.consume(S),I):B(S)?(o=O,Y(S)):V(S)?(e.consume(S),O):Q(S)}function I(S){return S===45||S===46||S===58||S===95||pe(S)?(e.consume(S),I):j(S)}function j(S){return S===61?(e.consume(S),_):B(S)?(o=j,Y(S)):V(S)?(e.consume(S),j):O(S)}function _(S){return S===null||S===60||S===61||S===62||S===96?n(S):S===34||S===39?(e.consume(S),s=S,W):B(S)?(o=_,Y(S)):V(S)?(e.consume(S),_):(e.consume(S),z)}function W(S){return S===s?(e.consume(S),s=void 0,P):S===null?n(S):B(S)?(o=W,Y(S)):(e.consume(S),W)}function z(S){return S===null||S===34||S===39||S===60||S===61||S===96?n(S):S===47||S===62||ee(S)?O(S):(e.consume(S),z)}function P(S){return S===47||S===62||ee(S)?O(S):n(S)}function Q(S){return S===62?(e.consume(S),e.exit("htmlTextData"),e.exit("htmlText"),t):n(S)}function Y(S){return e.exit("htmlTextData"),e.enter("lineEnding"),e.consume(S),e.exit("lineEnding"),ue}function ue(S){return V(S)?X(e,ye,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(S):ye(S)}function ye(S){return e.enter("htmlTextData"),o(S)}}const Ir={name:"labelEnd",resolveAll:ph,resolveTo:gh,tokenize:mh},dh={tokenize:yh},hh={tokenize:xh},fh={tokenize:bh};function ph(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 s=r.type==="labelImage"?4:2;r.type="data",t+=s}}return e.length!==n.length&&Te(e,0,e.length,n),e}function gh(e,t){let n=e.length,r=0,s,i,o,a;for(;n--;)if(s=e[n][1],i){if(s.type==="link"||s.type==="labelLink"&&s._inactive)break;e[n][0]==="enter"&&s.type==="labelLink"&&(s._inactive=!0)}else if(o){if(e[n][0]==="enter"&&(s.type==="labelImage"||s.type==="labelLink")&&!s._balanced&&(i=n,s.type!=="labelLink")){r=2;break}}else s.type==="labelEnd"&&(o=n);const l={type:e[i][1].type==="labelLink"?"link":"image",start:{...e[i][1].start},end:{...e[e.length-1][1].end}},u={type:"label",start:{...e[i][1].start},end:{...e[o][1].end}},c={type:"labelText",start:{...e[i+r+2][1].end},end:{...e[o-2][1].start}};return a=[["enter",l,t],["enter",u,t]],a=Ae(a,e.slice(i+1,i+r+3)),a=Ae(a,[["enter",c,t]]),a=Ae(a,tn(t.parser.constructs.insideSpan.null,e.slice(i+r+4,o-3),t)),a=Ae(a,[["exit",c,t],e[o-2],e[o-1],["exit",u,t]]),a=Ae(a,e.slice(o+1)),a=Ae(a,[["exit",l,t]]),Te(e,i,e.length,a),e}function mh(e,t,n){const r=this;let s=r.events.length,i,o;for(;s--;)if((r.events[s][1].type==="labelImage"||r.events[s][1].type==="labelLink")&&!r.events[s][1]._balanced){i=r.events[s][1];break}return a;function a(p){return i?i._inactive?d(p):(o=r.parser.defined.includes(je(r.sliceSerialize({start:i.end,end:r.now()}))),e.enter("labelEnd"),e.enter("labelMarker"),e.consume(p),e.exit("labelMarker"),e.exit("labelEnd"),l):n(p)}function l(p){return p===40?e.attempt(dh,c,o?c:d)(p):p===91?e.attempt(hh,c,o?u:d)(p):o?c(p):d(p)}function u(p){return e.attempt(fh,c,d)(p)}function c(p){return t(p)}function d(p){return i._balanced=!0,n(p)}}function yh(e,t,n){return r;function r(d){return e.enter("resource"),e.enter("resourceMarker"),e.consume(d),e.exit("resourceMarker"),s}function s(d){return ee(d)?wt(e,i)(d):i(d)}function i(d){return d===41?c(d):wo(e,o,a,"resourceDestination","resourceDestinationLiteral","resourceDestinationLiteralMarker","resourceDestinationRaw","resourceDestinationString",32)(d)}function o(d){return ee(d)?wt(e,l)(d):c(d)}function a(d){return n(d)}function l(d){return d===34||d===39||d===40?Io(e,u,n,"resourceTitle","resourceTitleMarker","resourceTitleString")(d):c(d)}function u(d){return ee(d)?wt(e,c)(d):c(d)}function c(d){return d===41?(e.enter("resourceMarker"),e.consume(d),e.exit("resourceMarker"),e.exit("resource"),t):n(d)}}function xh(e,t,n){const r=this;return s;function s(a){return Co.call(r,e,i,o,"reference","referenceMarker","referenceString")(a)}function i(a){return r.parser.defined.includes(je(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)))?t(a):n(a)}function o(a){return n(a)}}function bh(e,t,n){return r;function r(i){return e.enter("reference"),e.enter("referenceMarker"),e.consume(i),e.exit("referenceMarker"),s}function s(i){return i===93?(e.enter("referenceMarker"),e.consume(i),e.exit("referenceMarker"),e.exit("reference"),t):n(i)}}const Sh={name:"labelStartImage",resolveAll:Ir.resolveAll,tokenize:kh};function kh(e,t,n){const r=this;return s;function s(a){return e.enter("labelImage"),e.enter("labelImageMarker"),e.consume(a),e.exit("labelImageMarker"),i}function i(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 vh={name:"labelStartLink",resolveAll:Ir.resolveAll,tokenize:wh};function wh(e,t,n){const r=this;return s;function s(o){return e.enter("labelLink"),e.enter("labelMarker"),e.consume(o),e.exit("labelMarker"),e.exit("labelLink"),i}function i(o){return o===94&&"_hiddenFootnoteSupport"in r.parser.constructs?n(o):t(o)}}const pn={name:"lineEnding",tokenize:Ch};function Ch(e,t){return n;function n(r){return e.enter("lineEnding"),e.consume(r),e.exit("lineEnding"),X(e,t,"linePrefix")}}const Ht={name:"thematicBreak",tokenize:Ih};function Ih(e,t,n){let r=0,s;return i;function i(u){return e.enter("thematicBreak"),o(u)}function o(u){return s=u,a(u)}function a(u){return u===s?(e.enter("thematicBreakSequence"),l(u)):r>=3&&(u===null||B(u))?(e.exit("thematicBreak"),t(u)):n(u)}function l(u){return u===s?(e.consume(u),r++,l):(e.exit("thematicBreakSequence"),V(u)?X(e,a,"whitespace")(u):a(u))}}const be={continuation:{tokenize:Eh},exit:Lh,name:"list",tokenize:Rh},Th={partial:!0,tokenize:Nh},Mh={partial:!0,tokenize:Ah};function Rh(e,t,n){const r=this,s=r.events[r.events.length-1];let i=s&&s[1].type==="linePrefix"?s[2].sliceSerialize(s[1],!0).length:0,o=0;return a;function a(f){const m=r.containerState.type||(f===42||f===43||f===45?"listUnordered":"listOrdered");if(m==="listUnordered"?!r.containerState.marker||f===r.containerState.marker:Hn(f)){if(r.containerState.type||(r.containerState.type=m,e.enter(m,{_container:!0})),m==="listUnordered")return e.enter("listItemPrefix"),f===42||f===45?e.check(Ht,n,u)(f):u(f);if(!r.interrupt||f===49)return e.enter("listItemPrefix"),e.enter("listItemValue"),l(f)}return n(f)}function l(f){return Hn(f)&&++o<10?(e.consume(f),l):(!r.interrupt||o<2)&&(r.containerState.marker?f===r.containerState.marker:f===41||f===46)?(e.exit("listItemValue"),u(f)):n(f)}function u(f){return e.enter("listItemMarker"),e.consume(f),e.exit("listItemMarker"),r.containerState.marker=r.containerState.marker||f,e.check(Nt,r.interrupt?n:c,e.attempt(Th,p,d))}function c(f){return r.containerState.initialBlankLine=!0,i++,p(f)}function d(f){return V(f)?(e.enter("listItemPrefixWhitespace"),e.consume(f),e.exit("listItemPrefixWhitespace"),p):n(f)}function p(f){return r.containerState.size=i+r.sliceSerialize(e.exit("listItemPrefix"),!0).length,t(f)}}function Eh(e,t,n){const r=this;return r.containerState._closeFlow=void 0,e.check(Nt,s,i);function s(a){return r.containerState.furtherBlankLines=r.containerState.furtherBlankLines||r.containerState.initialBlankLine,X(e,t,"listItemIndent",r.containerState.size+1)(a)}function i(a){return r.containerState.furtherBlankLines||!V(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(Mh,t,o)(a))}function o(a){return r.containerState._closeFlow=!0,r.interrupt=void 0,X(e,e.attempt(be,t,n),"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(a)}}function Ah(e,t,n){const r=this;return X(e,s,"listItemIndent",r.containerState.size+1);function s(i){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(i):n(i)}}function Lh(e){e.exit(this.containerState.type)}function Nh(e,t,n){const r=this;return X(e,s,"listItemPrefixWhitespace",r.parser.constructs.disable.null.includes("codeIndented")?void 0:5);function s(i){const o=r.events[r.events.length-1];return!V(i)&&o&&o[1].type==="listItemPrefixWhitespace"?t(i):n(i)}}const ps={name:"setextUnderline",resolveTo:Ph,tokenize:jh};function Ph(e,t){let n=e.length,r,s,i;for(;n--;)if(e[n][0]==="enter"){if(e[n][1].type==="content"){r=n;break}e[n][1].type==="paragraph"&&(s=n)}else e[n][1].type==="content"&&e.splice(n,1),!i&&e[n][1].type==="definition"&&(i=n);const o={type:"setextHeading",start:{...e[r][1].start},end:{...e[e.length-1][1].end}};return e[s][1].type="setextHeadingText",i?(e.splice(s,0,["enter",o,t]),e.splice(i+1,0,["exit",e[r][1],t]),e[r][1].end={...e[i][1].end}):e[r][1]=o,e.push(["exit",o,t]),e}function jh(e,t,n){const r=this;let s;return i;function i(u){let c=r.events.length,d;for(;c--;)if(r.events[c][1].type!=="lineEnding"&&r.events[c][1].type!=="linePrefix"&&r.events[c][1].type!=="content"){d=r.events[c][1].type==="paragraph";break}return!r.parser.lazy[r.now().line]&&(r.interrupt||d)?(e.enter("setextHeadingLine"),s=u,o(u)):n(u)}function o(u){return e.enter("setextHeadingLineSequence"),a(u)}function a(u){return u===s?(e.consume(u),a):(e.exit("setextHeadingLineSequence"),V(u)?X(e,l,"lineSuffix")(u):l(u))}function l(u){return u===null||B(u)?(e.exit("setextHeadingLine"),t(u)):n(u)}}const Dh={tokenize:_h};function _h(e){const t=this,n=e.attempt(Nt,r,e.attempt(this.parser.constructs.flowInitial,s,X(e,e.attempt(this.parser.constructs.flow,s,e.attempt($d,s)),"linePrefix")));return n;function r(i){if(i===null){e.consume(i);return}return e.enter("lineEndingBlank"),e.consume(i),e.exit("lineEndingBlank"),t.currentConstruct=void 0,n}function s(i){if(i===null){e.consume(i);return}return e.enter("lineEnding"),e.consume(i),e.exit("lineEnding"),t.currentConstruct=void 0,n}}const Oh={resolveAll:Mo()},Fh=To("string"),zh=To("text");function To(e){return{resolveAll:Mo(e==="text"?Bh:void 0),tokenize:t};function t(n){const r=this,s=this.parser.constructs[e],i=n.attempt(s,o,a);return o;function o(c){return u(c)?i(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"),i(c)):(n.consume(c),l)}function u(c){if(c===null)return!0;const d=s[c];let p=-1;if(d)for(;++p<d.length;){const f=d[p];if(!f.previous||f.previous.call(r,r.previous))return!0}return!1}}}function Mo(e){return t;function t(n,r){let s=-1,i;for(;++s<=n.length;)i===void 0?n[s]&&n[s][1].type==="data"&&(i=s,s++):(!n[s]||n[s][1].type!=="data")&&(s!==i+2&&(n[i][1].end=n[s-1][1].end,n.splice(i+2,s-i-2),s=i+2),i=void 0);return e?e(n,r):n}}function Bh(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],s=t.sliceStream(r);let i=s.length,o=-1,a=0,l;for(;i--;){const u=s[i];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){i++;break}}if(t._contentTypeTextTrailing&&n===e.length&&(a=0),a){const u={type:n===e.length||l||a<2?"lineSuffix":"hardBreakTrailing",start:{_bufferIndex:i?o:r.start._bufferIndex+o,_index:r.start._index+i,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 $h={42:be,43:be,45:be,48:be,49:be,50:be,51:be,52:be,53:be,54:be,55:be,56:be,57:be,62:bo},Uh={91:qd},Kh={[-2]:fn,[-1]:fn,32:fn},Hh={35:Jd,42:Ht,45:[ps,Ht],60:nh,61:ps,95:Ht,96:hs,126:hs},Vh={38:ko,92:So},qh={[-5]:pn,[-4]:pn,[-3]:pn,33:Sh,38:ko,42:Vn,60:[vd,uh],91:vh,92:[Xd,So],93:Ir,95:Vn,96:Dd},Wh={null:[Vn,Oh]},Gh={null:[42,95]},Qh={null:[]},Xh=Object.freeze(Object.defineProperty({__proto__:null,attentionMarkers:Gh,contentInitial:Uh,disable:Qh,document:$h,flow:Hh,flowInitial:Kh,insideSpan:Wh,string:Vh,text:qh},Symbol.toStringTag,{value:"Module"}));function Yh(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 s={},i=[];let o=[],a=[];const l={attempt:N(A),check:N(k),consume:v,enter:w,exit:T,interrupt:N(k,{interrupt:!0})},u={code:null,containerState:{},defineSkip:y,events:[],now:m,parser:e,previous:null,sliceSerialize:p,sliceStream:f,write:d};let c=t.tokenize.call(u,l);return t.resolveAll&&i.push(t),u;function d(j){return o=Ae(o,j),b(),o[o.length-1]!==null?[]:(F(t,0),u.events=tn(i,u.events,u),u.events)}function p(j,_){return Zh(f(j),_)}function f(j){return Jh(o,j)}function m(){const{_bufferIndex:j,_index:_,line:W,column:z,offset:P}=r;return{_bufferIndex:j,_index:_,line:W,column:z,offset:P}}function y(j){s[j.line]=j.column,I()}function b(){let j;for(;r._index<o.length;){const _=o[r._index];if(typeof _=="string")for(j=r._index,r._bufferIndex<0&&(r._bufferIndex=0);r._index===j&&r._bufferIndex<_.length;)g(_.charCodeAt(r._bufferIndex));else g(_)}}function g(j){c=c(j)}function v(j){B(j)?(r.line++,r.column=1,r.offset+=j===-3?2:1,I()):j!==-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=j}function w(j,_){const W=_||{};return W.type=j,W.start=m(),u.events.push(["enter",W,u]),a.push(W),W}function T(j){const _=a.pop();return _.end=m(),u.events.push(["exit",_,u]),_}function A(j,_){F(j,_.from)}function k(j,_){_.restore()}function N(j,_){return W;function W(z,P,Q){let Y,ue,ye,S;return Array.isArray(z)?ce(z):"tokenize"in z?ce([z]):J(z);function J(re){return Le;function Le(ae){const Me=ae!==null&&re[ae],Re=ae!==null&&re.null,De=[...Array.isArray(Me)?Me:Me?[Me]:[],...Array.isArray(Re)?Re:Re?[Re]:[]];return ce(De)(ae)}}function ce(re){return Y=re,ue=0,re.length===0?Q:x(re[ue])}function x(re){return Le;function Le(ae){return S=O(),ye=re,re.partial||(u.currentConstruct=re),re.name&&u.parser.constructs.disable.null.includes(re.name)?ke():re.tokenize.call(_?Object.assign(Object.create(u),_):u,l,de,ke)(ae)}}function de(re){return j(ye,S),P}function ke(re){return S.restore(),++ue<Y.length?x(Y[ue]):Q}}}function F(j,_){j.resolveAll&&!i.includes(j)&&i.push(j),j.resolve&&Te(u.events,_,u.events.length-_,j.resolve(u.events.slice(_),u)),j.resolveTo&&(u.events=j.resolveTo(u.events,u))}function O(){const j=m(),_=u.previous,W=u.currentConstruct,z=u.events.length,P=Array.from(a);return{from:z,restore:Q};function Q(){r=j,u.previous=_,u.currentConstruct=W,u.events.length=z,a=P,I()}}function I(){r.line in s&&r.column<2&&(r.column=s[r.line],r.offset+=s[r.line]-1)}}function Jh(e,t){const n=t.start._index,r=t.start._bufferIndex,s=t.end._index,i=t.end._bufferIndex;let o;if(n===s)o=[e[n].slice(r,i)];else{if(o=e.slice(n,s),r>-1){const a=o[0];typeof a=="string"?o[0]=a.slice(r):o.shift()}i>0&&o.push(e[s].slice(0,i))}return o}function Zh(e,t){let n=-1;const r=[];let s;for(;++n<e.length;){const i=e[n];let o;if(typeof i=="string")o=i;else switch(i){case-5:{o="\r";break}case-4:{o=`
4
+ `;break}case-3:{o=`\r
5
+ `;break}case-2:{o=t?" ":" ";break}case-1:{if(!t&&s)continue;o=" ";break}default:o=String.fromCharCode(i)}s=i===-2,r.push(o)}return r.join("")}function ef(e){const r={constructs:yo([Xh,...(e||{}).extensions||[]]),content:s(gd),defined:[],document:s(yd),flow:s(Dh),lazy:{},string:s(Fh),text:s(zh)};return r;function s(i){return o;function o(a){return Yh(r,i,a)}}}function tf(e){for(;!vo(e););return e}const gs=/[\0\t\n\r]/g;function nf(){let e=1,t="",n=!0,r;return s;function s(i,o,a){const l=[];let u,c,d,p,f;for(i=t+(typeof i=="string"?i.toString():new TextDecoder(o||void 0).decode(i)),d=0,t="",n&&(i.charCodeAt(0)===65279&&d++,n=void 0);d<i.length;){if(gs.lastIndex=d,u=gs.exec(i),p=u&&u.index!==void 0?u.index:i.length,f=i.charCodeAt(p),!u){t=i.slice(d);break}if(f===10&&d===p&&r)l.push(-3),r=void 0;else switch(r&&(l.push(-5),r=void 0),d<p&&(l.push(i.slice(d,p)),e+=p-d),f){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}d=p+1}return a&&(r&&l.push(-5),t&&l.push(t),l.push(null)),l}}const rf=/\\([!-/:-@[-`{-~])|&(#(?:\d{1,7}|x[\da-f]{1,6})|[\da-z]{1,31});/gi;function sf(e){return e.replace(rf,of)}function of(e,t,n){if(t)return t;if(n.charCodeAt(0)===35){const s=n.charCodeAt(1),i=s===120||s===88;return xo(n.slice(i?2:1),i?16:10)}return Cr(n)||e}const Ro={}.hasOwnProperty;function af(e,t,n){return t&&typeof t=="object"&&(n=t,t=void 0),lf(n)(tf(ef(n).document().write(nf()(e,t,!0))))}function lf(e){const t={transforms:[],canContainEols:["emphasis","fragment","heading","paragraph","strong"],enter:{autolink:i(_e),autolinkProtocol:O,autolinkEmail:O,atxHeading:i(H),blockQuote:i(Re),characterEscape:O,characterReference:O,codeFenced:i(De),codeFencedFenceInfo:o,codeFencedFenceMeta:o,codeIndented:i(De,o),codeText:i(Xe,o),codeTextData:O,data:O,codeFlowValue:O,definition:i(Ye),definitionDestinationString:o,definitionLabelString:o,definitionTitleString:o,emphasis:i(he),hardBreakEscape:i(ve),hardBreakTrailing:i(ve),htmlFlow:i(Be,o),htmlFlowData:O,htmlText:i(Be,o),htmlTextData:O,image:i(xe),label:o,link:i(_e),listItem:i(La),listItemValue:p,listOrdered:i(Or,d),listUnordered:i(Or),paragraph:i(Na),reference:x,referenceString:o,resourceDestinationString:o,resourceTitleString:o,setextHeading:i(H),strong:i(Pa),thematicBreak:i(Da)},exit:{atxHeading:l(),atxHeadingSequence:A,autolink:l(),autolinkEmail:Me,autolinkProtocol:ae,blockQuote:l(),characterEscapeValue:I,characterReferenceMarkerHexadecimal:ke,characterReferenceMarkerNumeric:ke,characterReferenceValue:re,characterReference:Le,codeFenced:l(b),codeFencedFence:y,codeFencedFenceInfo:f,codeFencedFenceMeta:m,codeFlowValue:I,codeIndented:l(g),codeText:l(P),codeTextData:I,data:I,definition:l(),definitionDestinationString:T,definitionLabelString:v,definitionTitleString:w,emphasis:l(),hardBreakEscape:l(_),hardBreakTrailing:l(_),htmlFlow:l(W),htmlFlowData:I,htmlText:l(z),htmlTextData:I,image:l(Y),label:ye,labelText:ue,lineEnding:j,link:l(Q),listItem:l(),listOrdered:l(),listUnordered:l(),paragraph:l(),referenceString:de,resourceDestinationString:S,resourceTitleString:J,resource:ce,setextHeading:l(F),setextHeadingLineSequence:N,setextHeadingText:k,strong:l(),thematicBreak:l()}};Eo(t,(e||{}).mdastExtensions||[]);const n={};return r;function r(M){let L={type:"root",children:[]};const $={stack:[L],tokenStack:[],config:t,enter:a,exit:u,buffer:o,resume:c,data:n},G=[];let Z=-1;for(;++Z<M.length;)if(M[Z][1].type==="listOrdered"||M[Z][1].type==="listUnordered")if(M[Z][0]==="enter")G.push(Z);else{const Ne=G.pop();Z=s(M,Ne,Z)}for(Z=-1;++Z<M.length;){const Ne=t[M[Z][0]];Ro.call(Ne,M[Z][1].type)&&Ne[M[Z][1].type].call(Object.assign({sliceSerialize:M[Z][2].sliceSerialize},$),M[Z][1])}if($.tokenStack.length>0){const Ne=$.tokenStack[$.tokenStack.length-1];(Ne[1]||ms).call($,void 0,Ne[0])}for(L.position={start:Ge(M.length>0?M[0][1].start:{line:1,column:1,offset:0}),end:Ge(M.length>0?M[M.length-2][1].end:{line:1,column:1,offset:0})},Z=-1;++Z<t.transforms.length;)L=t.transforms[Z](L)||L;return L}function s(M,L,$){let G=L-1,Z=-1,Ne=!1,Je,$e,pt,gt;for(;++G<=$;){const we=M[G];switch(we[1].type){case"listUnordered":case"listOrdered":case"blockQuote":{we[0]==="enter"?Z++:Z--,gt=void 0;break}case"lineEndingBlank":{we[0]==="enter"&&(Je&&!gt&&!Z&&!pt&&(pt=G),gt=void 0);break}case"linePrefix":case"listItemValue":case"listItemMarker":case"listItemPrefix":case"listItemPrefixWhitespace":break;default:gt=void 0}if(!Z&&we[0]==="enter"&&we[1].type==="listItemPrefix"||Z===-1&&we[0]==="exit"&&(we[1].type==="listUnordered"||we[1].type==="listOrdered")){if(Je){let rt=G;for($e=void 0;rt--;){const Ue=M[rt];if(Ue[1].type==="lineEnding"||Ue[1].type==="lineEndingBlank"){if(Ue[0]==="exit")continue;$e&&(M[$e][1].type="lineEndingBlank",Ne=!0),Ue[1].type="lineEnding",$e=rt}else if(!(Ue[1].type==="linePrefix"||Ue[1].type==="blockQuotePrefix"||Ue[1].type==="blockQuotePrefixWhitespace"||Ue[1].type==="blockQuoteMarker"||Ue[1].type==="listItemIndent"))break}pt&&(!$e||pt<$e)&&(Je._spread=!0),Je.end=Object.assign({},$e?M[$e][1].start:we[1].end),M.splice($e||G,0,["exit",Je,we[2]]),G++,$++}if(we[1].type==="listItemPrefix"){const rt={type:"listItem",_spread:!1,start:Object.assign({},we[1].start),end:void 0};Je=rt,M.splice(G,0,["enter",rt,we[2]]),G++,$++,pt=void 0,gt=!0}}}return M[L][1]._spread=Ne,$}function i(M,L){return $;function $(G){a.call(this,M(G),G),L&&L.call(this,G)}}function o(){this.stack.push({type:"fragment",children:[]})}function a(M,L,$){this.stack[this.stack.length-1].children.push(M),this.stack.push(M),this.tokenStack.push([L,$||void 0]),M.position={start:Ge(L.start),end:void 0}}function l(M){return L;function L($){M&&M.call(this,$),u.call(this,$)}}function u(M,L){const $=this.stack.pop(),G=this.tokenStack.pop();if(G)G[0].type!==M.type&&(L?L.call(this,M,G[0]):(G[1]||ms).call(this,M,G[0]));else throw new Error("Cannot close `"+M.type+"` ("+vt({start:M.start,end:M.end})+"): it’s not open");$.position.end=Ge(M.end)}function c(){return wr(this.stack.pop())}function d(){this.data.expectingFirstListItemValue=!0}function p(M){if(this.data.expectingFirstListItemValue){const L=this.stack[this.stack.length-2];L.start=Number.parseInt(this.sliceSerialize(M),10),this.data.expectingFirstListItemValue=void 0}}function f(){const M=this.resume(),L=this.stack[this.stack.length-1];L.lang=M}function m(){const M=this.resume(),L=this.stack[this.stack.length-1];L.meta=M}function y(){this.data.flowCodeInside||(this.buffer(),this.data.flowCodeInside=!0)}function b(){const M=this.resume(),L=this.stack[this.stack.length-1];L.value=M.replace(/^(\r?\n|\r)|(\r?\n|\r)$/g,""),this.data.flowCodeInside=void 0}function g(){const M=this.resume(),L=this.stack[this.stack.length-1];L.value=M.replace(/(\r?\n|\r)$/g,"")}function v(M){const L=this.resume(),$=this.stack[this.stack.length-1];$.label=L,$.identifier=je(this.sliceSerialize(M)).toLowerCase()}function w(){const M=this.resume(),L=this.stack[this.stack.length-1];L.title=M}function T(){const M=this.resume(),L=this.stack[this.stack.length-1];L.url=M}function A(M){const L=this.stack[this.stack.length-1];if(!L.depth){const $=this.sliceSerialize(M).length;L.depth=$}}function k(){this.data.setextHeadingSlurpLineEnding=!0}function N(M){const L=this.stack[this.stack.length-1];L.depth=this.sliceSerialize(M).codePointAt(0)===61?1:2}function F(){this.data.setextHeadingSlurpLineEnding=void 0}function O(M){const $=this.stack[this.stack.length-1].children;let G=$[$.length-1];(!G||G.type!=="text")&&(G=ja(),G.position={start:Ge(M.start),end:void 0},$.push(G)),this.stack.push(G)}function I(M){const L=this.stack.pop();L.value+=this.sliceSerialize(M),L.position.end=Ge(M.end)}function j(M){const L=this.stack[this.stack.length-1];if(this.data.atHardBreak){const $=L.children[L.children.length-1];$.position.end=Ge(M.end),this.data.atHardBreak=void 0;return}!this.data.setextHeadingSlurpLineEnding&&t.canContainEols.includes(L.type)&&(O.call(this,M),I.call(this,M))}function _(){this.data.atHardBreak=!0}function W(){const M=this.resume(),L=this.stack[this.stack.length-1];L.value=M}function z(){const M=this.resume(),L=this.stack[this.stack.length-1];L.value=M}function P(){const M=this.resume(),L=this.stack[this.stack.length-1];L.value=M}function Q(){const M=this.stack[this.stack.length-1];if(this.data.inReference){const L=this.data.referenceType||"shortcut";M.type+="Reference",M.referenceType=L,delete M.url,delete M.title}else delete M.identifier,delete M.label;this.data.referenceType=void 0}function Y(){const M=this.stack[this.stack.length-1];if(this.data.inReference){const L=this.data.referenceType||"shortcut";M.type+="Reference",M.referenceType=L,delete M.url,delete M.title}else delete M.identifier,delete M.label;this.data.referenceType=void 0}function ue(M){const L=this.sliceSerialize(M),$=this.stack[this.stack.length-2];$.label=sf(L),$.identifier=je(L).toLowerCase()}function ye(){const M=this.stack[this.stack.length-1],L=this.resume(),$=this.stack[this.stack.length-1];if(this.data.inReference=!0,$.type==="link"){const G=M.children;$.children=G}else $.alt=L}function S(){const M=this.resume(),L=this.stack[this.stack.length-1];L.url=M}function J(){const M=this.resume(),L=this.stack[this.stack.length-1];L.title=M}function ce(){this.data.inReference=void 0}function x(){this.data.referenceType="collapsed"}function de(M){const L=this.resume(),$=this.stack[this.stack.length-1];$.label=L,$.identifier=je(this.sliceSerialize(M)).toLowerCase(),this.data.referenceType="full"}function ke(M){this.data.characterReferenceType=M.type}function re(M){const L=this.sliceSerialize(M),$=this.data.characterReferenceType;let G;$?(G=xo(L,$==="characterReferenceMarkerNumeric"?10:16),this.data.characterReferenceType=void 0):G=Cr(L);const Z=this.stack[this.stack.length-1];Z.value+=G}function Le(M){const L=this.stack.pop();L.position.end=Ge(M.end)}function ae(M){I.call(this,M);const L=this.stack[this.stack.length-1];L.url=this.sliceSerialize(M)}function Me(M){I.call(this,M);const L=this.stack[this.stack.length-1];L.url="mailto:"+this.sliceSerialize(M)}function Re(){return{type:"blockquote",children:[]}}function De(){return{type:"code",lang:null,meta:null,value:""}}function Xe(){return{type:"inlineCode",value:""}}function Ye(){return{type:"definition",identifier:"",label:null,title:null,url:""}}function he(){return{type:"emphasis",children:[]}}function H(){return{type:"heading",depth:0,children:[]}}function ve(){return{type:"break"}}function Be(){return{type:"html",value:""}}function xe(){return{type:"image",title:null,url:"",alt:null}}function _e(){return{type:"link",title:null,url:"",children:[]}}function Or(M){return{type:"list",ordered:M.type==="listOrdered",start:null,spread:M._spread,children:[]}}function La(M){return{type:"listItem",spread:M._spread,checked:null,children:[]}}function Na(){return{type:"paragraph",children:[]}}function Pa(){return{type:"strong",children:[]}}function ja(){return{type:"text",value:""}}function Da(){return{type:"thematicBreak"}}}function Ge(e){return{line:e.line,column:e.column,offset:e.offset}}function Eo(e,t){let n=-1;for(;++n<t.length;){const r=t[n];Array.isArray(r)?Eo(e,r):uf(e,r)}}function uf(e,t){let n;for(n in t)if(Ro.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 ms(e,t){throw e?new Error("Cannot close `"+e.type+"` ("+vt({start:e.start,end:e.end})+"): a different token (`"+t.type+"`, "+vt({start:t.start,end:t.end})+") is open"):new Error("Cannot close document, a token (`"+t.type+"`, "+vt({start:t.start,end:t.end})+") is still open")}function cf(e){const t=this;t.parser=n;function n(r){return af(r,{...t.data("settings"),...e,extensions:t.data("micromarkExtensions")||[],mdastExtensions:t.data("fromMarkdownExtensions")||[]})}}function df(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 hf(e,t){const n={type:"element",tagName:"br",properties:{},children:[]};return e.patch(t,n),[e.applyData(t,n),{type:"text",value:`
6
+ `}]}function ff(e,t){const n=t.value?t.value+`
7
+ `:"",r={},s=t.lang?t.lang.split(/\s+/):[];s.length>0&&(r.className=["language-"+s[0]]);let i={type:"element",tagName:"code",properties:r,children:[{type:"text",value:n}]};return t.meta&&(i.data={meta:t.meta}),e.patch(t,i),i=e.applyData(t,i),i={type:"element",tagName:"pre",properties:{},children:[i]},e.patch(t,i),i}function pf(e,t){const n={type:"element",tagName:"del",properties:{},children:e.all(t)};return e.patch(t,n),e.applyData(t,n)}function gf(e,t){const n={type:"element",tagName:"em",properties:{},children:e.all(t)};return e.patch(t,n),e.applyData(t,n)}function mf(e,t){const n=typeof e.options.clobberPrefix=="string"?e.options.clobberPrefix:"user-content-",r=String(t.identifier).toUpperCase(),s=ft(r.toLowerCase()),i=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=i+1,a+=1,e.footnoteCounts.set(r,a);const l={type:"element",tagName:"a",properties:{href:"#"+n+"fn-"+s,id:n+"fnref-"+s+(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 yf(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 xf(e,t){if(e.options.allowDangerousHtml){const n={type:"raw",value:t.value};return e.patch(t,n),e.applyData(t,n)}}function Ao(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 s=e.all(t),i=s[0];i&&i.type==="text"?i.value="["+i.value:s.unshift({type:"text",value:"["});const o=s[s.length-1];return o&&o.type==="text"?o.value+=r:s.push({type:"text",value:r}),s}function bf(e,t){const n=String(t.identifier).toUpperCase(),r=e.definitionById.get(n);if(!r)return Ao(e,t);const s={src:ft(r.url||""),alt:t.alt};r.title!==null&&r.title!==void 0&&(s.title=r.title);const i={type:"element",tagName:"img",properties:s,children:[]};return e.patch(t,i),e.applyData(t,i)}function Sf(e,t){const n={src:ft(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 kf(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 vf(e,t){const n=String(t.identifier).toUpperCase(),r=e.definitionById.get(n);if(!r)return Ao(e,t);const s={href:ft(r.url||"")};r.title!==null&&r.title!==void 0&&(s.title=r.title);const i={type:"element",tagName:"a",properties:s,children:e.all(t)};return e.patch(t,i),e.applyData(t,i)}function wf(e,t){const n={href:ft(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 Cf(e,t,n){const r=e.all(t),s=n?If(n):Lo(t),i={},o=[];if(typeof t.checked=="boolean"){const c=r[0];let d;c&&c.type==="element"&&c.tagName==="p"?d=c:(d={type:"element",tagName:"p",properties:{},children:[]},r.unshift(d)),d.children.length>0&&d.children.unshift({type:"text",value:" "}),d.children.unshift({type:"element",tagName:"input",properties:{type:"checkbox",checked:t.checked,disabled:!0},children:[]}),i.className=["task-list-item"]}let a=-1;for(;++a<r.length;){const c=r[a];(s||a!==0||c.type!=="element"||c.tagName!=="p")&&o.push({type:"text",value:`
8
+ `}),c.type==="element"&&c.tagName==="p"&&!s?o.push(...c.children):o.push(c)}const l=r[r.length-1];l&&(s||l.type!=="element"||l.tagName!=="p")&&o.push({type:"text",value:`
9
+ `});const u={type:"element",tagName:"li",properties:i,children:o};return e.patch(t,u),e.applyData(t,u)}function If(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=Lo(n[r])}return t}function Lo(e){const t=e.spread;return t??e.children.length>1}function Tf(e,t){const n={},r=e.all(t);let s=-1;for(typeof t.start=="number"&&t.start!==1&&(n.start=t.start);++s<r.length;){const o=r[s];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 i={type:"element",tagName:t.ordered?"ol":"ul",properties:n,children:e.wrap(r,!0)};return e.patch(t,i),e.applyData(t,i)}function Mf(e,t){const n={type:"element",tagName:"p",properties:{},children:e.all(t)};return e.patch(t,n),e.applyData(t,n)}function Rf(e,t){const n={type:"root",children:e.wrap(e.all(t))};return e.patch(t,n),e.applyData(t,n)}function Ef(e,t){const n={type:"element",tagName:"strong",properties:{},children:e.all(t)};return e.patch(t,n),e.applyData(t,n)}function Af(e,t){const n=e.all(t),r=n.shift(),s=[];if(r){const o={type:"element",tagName:"thead",properties:{},children:e.wrap([r],!0)};e.patch(t.children[0],o),s.push(o)}if(n.length>0){const o={type:"element",tagName:"tbody",properties:{},children:e.wrap(n,!0)},a=br(t.children[1]),l=uo(t.children[t.children.length-1]);a&&l&&(o.position={start:a,end:l}),s.push(o)}const i={type:"element",tagName:"table",properties:{},children:e.wrap(s,!0)};return e.patch(t,i),e.applyData(t,i)}function Lf(e,t,n){const r=n?n.children:void 0,i=(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 d=t.children[l],p={},f=o?o[l]:void 0;f&&(p.align=f);let m={type:"element",tagName:i,properties:p,children:[]};d&&(m.children=e.all(d),e.patch(d,m),m=e.applyData(d,m)),u.push(m)}const c={type:"element",tagName:"tr",properties:{},children:e.wrap(u,!0)};return e.patch(t,c),e.applyData(t,c)}function Nf(e,t){const n={type:"element",tagName:"td",properties:{},children:e.all(t)};return e.patch(t,n),e.applyData(t,n)}const ys=9,xs=32;function Pf(e){const t=String(e),n=/\r?\n|\r/g;let r=n.exec(t),s=0;const i=[];for(;r;)i.push(bs(t.slice(s,r.index),s>0,!0),r[0]),s=r.index+r[0].length,r=n.exec(t);return i.push(bs(t.slice(s),s>0,!1)),i.join("")}function bs(e,t,n){let r=0,s=e.length;if(t){let i=e.codePointAt(r);for(;i===ys||i===xs;)r++,i=e.codePointAt(r)}if(n){let i=e.codePointAt(s-1);for(;i===ys||i===xs;)s--,i=e.codePointAt(s-1)}return s>r?e.slice(r,s):""}function jf(e,t){const n={type:"text",value:Pf(String(t.value))};return e.patch(t,n),e.applyData(t,n)}function Df(e,t){const n={type:"element",tagName:"hr",properties:{},children:[]};return e.patch(t,n),e.applyData(t,n)}const _f={blockquote:df,break:hf,code:ff,delete:pf,emphasis:gf,footnoteReference:mf,heading:yf,html:xf,imageReference:bf,image:Sf,inlineCode:kf,linkReference:vf,link:wf,listItem:Cf,list:Tf,paragraph:Mf,root:Rf,strong:Ef,table:Af,tableCell:Nf,tableRow:Lf,text:jf,thematicBreak:Df,toml:Dt,yaml:Dt,definition:Dt,footnoteDefinition:Dt};function Dt(){}const No=-1,nn=0,Ct=1,Gt=2,Tr=3,Mr=4,Rr=5,Er=6,Po=7,jo=8,Ss=typeof self=="object"?self:globalThis,Of=(e,t)=>{const n=(s,i)=>(e.set(i,s),s),r=s=>{if(e.has(s))return e.get(s);const[i,o]=t[s];switch(i){case nn:case No:return n(o,s);case Ct:{const a=n([],s);for(const l of o)a.push(r(l));return a}case Gt:{const a=n({},s);for(const[l,u]of o)a[r(l)]=r(u);return a}case Tr:return n(new Date(o),s);case Mr:{const{source:a,flags:l}=o;return n(new RegExp(a,l),s)}case Rr:{const a=n(new Map,s);for(const[l,u]of o)a.set(r(l),r(u));return a}case Er:{const a=n(new Set,s);for(const l of o)a.add(r(l));return a}case Po:{const{name:a,message:l}=o;return n(new Ss[a](l),s)}case jo:return n(BigInt(o),s);case"BigInt":return n(Object(BigInt(o)),s);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 Ss[i](o),s)};return r},ks=e=>Of(new Map,e)(0),it="",{toString:Ff}={},{keys:zf}=Object,bt=e=>{const t=typeof e;if(t!=="object"||!e)return[nn,t];const n=Ff.call(e).slice(8,-1);switch(n){case"Array":return[Ct,it];case"Object":return[Gt,it];case"Date":return[Tr,it];case"RegExp":return[Mr,it];case"Map":return[Rr,it];case"Set":return[Er,it];case"DataView":return[Ct,n]}return n.includes("Array")?[Ct,n]:n.includes("Error")?[Po,n]:[Gt,n]},_t=([e,t])=>e===nn&&(t==="function"||t==="symbol"),Bf=(e,t,n,r)=>{const s=(o,a)=>{const l=r.push(o)-1;return n.set(a,l),l},i=o=>{if(n.has(o))return n.get(o);let[a,l]=bt(o);switch(a){case nn:{let c=o;switch(l){case"bigint":a=jo,c=o.toString();break;case"function":case"symbol":if(e)throw new TypeError("unable to serialize "+l);c=null;break;case"undefined":return s([No],o)}return s([a,c],o)}case Ct:{if(l){let p=o;return l==="DataView"?p=new Uint8Array(o.buffer):l==="ArrayBuffer"&&(p=new Uint8Array(o)),s([l,[...p]],o)}const c=[],d=s([a,c],o);for(const p of o)c.push(i(p));return d}case Gt:{if(l)switch(l){case"BigInt":return s([l,o.toString()],o);case"Boolean":case"Number":case"String":return s([l,o.valueOf()],o)}if(t&&"toJSON"in o)return i(o.toJSON());const c=[],d=s([a,c],o);for(const p of zf(o))(e||!_t(bt(o[p])))&&c.push([i(p),i(o[p])]);return d}case Tr:return s([a,o.toISOString()],o);case Mr:{const{source:c,flags:d}=o;return s([a,{source:c,flags:d}],o)}case Rr:{const c=[],d=s([a,c],o);for(const[p,f]of o)(e||!(_t(bt(p))||_t(bt(f))))&&c.push([i(p),i(f)]);return d}case Er:{const c=[],d=s([a,c],o);for(const p of o)(e||!_t(bt(p)))&&c.push(i(p));return d}}const{message:u}=o;return s([a,{name:l,message:u}],o)};return i},vs=(e,{json:t,lossy:n}={})=>{const r=[];return Bf(!(t||n),!!t,new Map,r)(e),r},Qt=typeof structuredClone=="function"?(e,t)=>t&&("json"in t||"lossy"in t)?ks(vs(e,t)):structuredClone(e):(e,t)=>ks(vs(e,t));function $f(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 Uf(e,t){return"Back to reference "+(e+1)+(t>1?"-"+t:"")}function Kf(e){const t=typeof e.options.clobberPrefix=="string"?e.options.clobberPrefix:"user-content-",n=e.options.footnoteBackContent||$f,r=e.options.footnoteBackLabel||Uf,s=e.options.footnoteLabel||"Footnotes",i=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),d=String(u.identifier).toUpperCase(),p=ft(d.toLowerCase());let f=0;const m=[],y=e.footnoteCounts.get(d);for(;y!==void 0&&++f<=y;){m.length>0&&m.push({type:"text",value:" "});let v=typeof n=="string"?n:n(l,f);typeof v=="string"&&(v={type:"text",value:v}),m.push({type:"element",tagName:"a",properties:{href:"#"+t+"fnref-"+p+(f>1?"-"+f:""),dataFootnoteBackref:"",ariaLabel:typeof r=="string"?r:r(l,f),className:["data-footnote-backref"]},children:Array.isArray(v)?v:[v]})}const b=c[c.length-1];if(b&&b.type==="element"&&b.tagName==="p"){const v=b.children[b.children.length-1];v&&v.type==="text"?v.value+=" ":b.children.push({type:"text",value:" "}),b.children.push(...m)}else c.push(...m);const g={type:"element",tagName:"li",properties:{id:t+"fn-"+p},children:e.wrap(c,!0)};e.patch(u,g),a.push(g)}if(a.length!==0)return{type:"element",tagName:"section",properties:{dataFootnotes:!0,className:["footnotes"]},children:[{type:"element",tagName:i,properties:{...Qt(o),id:"footnote-label"},children:[{type:"text",value:s}]},{type:"text",value:`
10
+ `},{type:"element",tagName:"ol",properties:{},children:e.wrap(a,!0)},{type:"text",value:`
11
+ `}]}}const rn=(function(e){if(e==null)return Wf;if(typeof e=="function")return sn(e);if(typeof e=="object")return Array.isArray(e)?Hf(e):Vf(e);if(typeof e=="string")return qf(e);throw new Error("Expected function, string, or object as test")});function Hf(e){const t=[];let n=-1;for(;++n<e.length;)t[n]=rn(e[n]);return sn(r);function r(...s){let i=-1;for(;++i<t.length;)if(t[i].apply(this,s))return!0;return!1}}function Vf(e){const t=e;return sn(n);function n(r){const s=r;let i;for(i in e)if(s[i]!==t[i])return!1;return!0}}function qf(e){return sn(t);function t(n){return n&&n.type===e}}function sn(e){return t;function t(n,r,s){return!!(Gf(n)&&e.call(this,n,typeof r=="number"?r:void 0,s||void 0))}}function Wf(){return!0}function Gf(e){return e!==null&&typeof e=="object"&&"type"in e}const Do=[],Qf=!0,qn=!1,Xf="skip";function _o(e,t,n,r){let s;typeof t=="function"&&typeof n!="function"?(r=n,n=t):s=t;const i=rn(s),o=r?-1:1;a(e,void 0,[])();function a(l,u,c){const d=l&&typeof l=="object"?l:{};if(typeof d.type=="string"){const f=typeof d.tagName=="string"?d.tagName:typeof d.name=="string"?d.name:void 0;Object.defineProperty(p,"name",{value:"node ("+(l.type+(f?"<"+f+">":""))+")"})}return p;function p(){let f=Do,m,y,b;if((!t||i(l,u,c[c.length-1]||void 0))&&(f=Yf(n(l,c)),f[0]===qn))return f;if("children"in l&&l.children){const g=l;if(g.children&&f[0]!==Xf)for(y=(r?g.children.length:-1)+o,b=c.concat(g);y>-1&&y<g.children.length;){const v=g.children[y];if(m=a(v,y,b)(),m[0]===qn)return m;y=typeof m[1]=="number"?m[1]:y+o}}return f}}}function Yf(e){return Array.isArray(e)?e:typeof e=="number"?[Qf,e]:e==null?Do:[e]}function Ar(e,t,n,r){let s,i,o;typeof t=="function"&&typeof n!="function"?(i=void 0,o=t,s=n):(i=t,o=n,s=r),_o(e,i,a,s);function a(l,u){const c=u[u.length-1],d=c?c.children.indexOf(l):void 0;return o(l,d,c)}}const Wn={}.hasOwnProperty,Jf={};function Zf(e,t){const n=t||Jf,r=new Map,s=new Map,i=new Map,o={..._f,...n.handlers},a={all:u,applyData:tp,definitionById:r,footnoteById:s,footnoteCounts:i,footnoteOrder:[],handlers:o,one:l,options:n,patch:ep,wrap:rp};return Ar(e,function(c){if(c.type==="definition"||c.type==="footnoteDefinition"){const d=c.type==="definition"?r:s,p=String(c.identifier).toUpperCase();d.has(p)||d.set(p,c)}}),a;function l(c,d){const p=c.type,f=a.handlers[p];if(Wn.call(a.handlers,p)&&f)return f(a,c,d);if(a.options.passThrough&&a.options.passThrough.includes(p)){if("children"in c){const{children:y,...b}=c,g=Qt(b);return g.children=a.all(c),g}return Qt(c)}return(a.options.unknownHandler||np)(a,c,d)}function u(c){const d=[];if("children"in c){const p=c.children;let f=-1;for(;++f<p.length;){const m=a.one(p[f],c);if(m){if(f&&p[f-1].type==="break"&&(!Array.isArray(m)&&m.type==="text"&&(m.value=ws(m.value)),!Array.isArray(m)&&m.type==="element")){const y=m.children[0];y&&y.type==="text"&&(y.value=ws(y.value))}Array.isArray(m)?d.push(...m):d.push(m)}}}return d}}function ep(e,t){e.position&&(t.position=$c(e))}function tp(e,t){let n=t;if(e&&e.data){const r=e.data.hName,s=e.data.hChildren,i=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"&&i&&Object.assign(n.properties,Qt(i)),"children"in n&&n.children&&s!==null&&s!==void 0&&(n.children=s)}return n}function np(e,t){const n=t.data||{},r="value"in t&&!(Wn.call(n,"hProperties")||Wn.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 rp(e,t){const n=[];let r=-1;for(t&&n.push({type:"text",value:`
12
+ `});++r<e.length;)r&&n.push({type:"text",value:`
13
+ `}),n.push(e[r]);return t&&e.length>0&&n.push({type:"text",value:`
14
+ `}),n}function ws(e){let t=0,n=e.charCodeAt(t);for(;n===9||n===32;)t++,n=e.charCodeAt(t);return e.slice(t)}function Cs(e,t){const n=Zf(e,t),r=n.one(e,void 0),s=Kf(n),i=Array.isArray(r)?{type:"root",children:r}:r||{type:"root",children:[]};return s&&i.children.push({type:"text",value:`
15
+ `},s),i}function sp(e,t){return e&&"run"in e?async function(n,r){const s=Cs(n,{file:r,...t});await e.run(s,r)}:function(n,r){return Cs(n,{file:r,...e||t})}}function Is(e){if(e)throw e}var gn,Ts;function ip(){if(Ts)return gn;Ts=1;var e=Object.prototype.hasOwnProperty,t=Object.prototype.toString,n=Object.defineProperty,r=Object.getOwnPropertyDescriptor,s=function(u){return typeof Array.isArray=="function"?Array.isArray(u):t.call(u)==="[object Array]"},i=function(u){if(!u||t.call(u)!=="[object Object]")return!1;var c=e.call(u,"constructor"),d=u.constructor&&u.constructor.prototype&&e.call(u.constructor.prototype,"isPrototypeOf");if(u.constructor&&!c&&!d)return!1;var p;for(p in u);return typeof p>"u"||e.call(u,p)},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 gn=function l(){var u,c,d,p,f,m,y=arguments[0],b=1,g=arguments.length,v=!1;for(typeof y=="boolean"&&(v=y,y=arguments[1]||{},b=2),(y==null||typeof y!="object"&&typeof y!="function")&&(y={});b<g;++b)if(u=arguments[b],u!=null)for(c in u)d=a(y,c),p=a(u,c),y!==p&&(v&&p&&(i(p)||(f=s(p)))?(f?(f=!1,m=d&&s(d)?d:[]):m=d&&i(d)?d:{},o(y,{name:c,newValue:l(v,m,p)})):typeof p<"u"&&o(y,{name:c,newValue:p}));return y},gn}var op=ip();const mn=ki(op);function Gn(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 ap(){const e=[],t={run:n,use:r};return t;function n(...s){let i=-1;const o=s.pop();if(typeof o!="function")throw new TypeError("Expected function as last argument, not "+o);a(null,...s);function a(l,...u){const c=e[++i];let d=-1;if(l){o(l);return}for(;++d<s.length;)(u[d]===null||u[d]===void 0)&&(u[d]=s[d]);s=u,c?lp(c,a)(...u):o(null,...u)}}function r(s){if(typeof s!="function")throw new TypeError("Expected `middelware` to be a function, not "+s);return e.push(s),t}}function lp(e,t){let n;return r;function r(...o){const a=e.length>o.length;let l;a&&o.push(s);try{l=e.apply(this,o)}catch(u){const c=u;if(a&&n)throw c;return s(c)}a||(l&&l.then&&typeof l.then=="function"?l.then(i,s):l instanceof Error?s(l):i(l))}function s(o,...a){n||(n=!0,t(o,...a))}function i(o){s(null,o)}}const Fe={basename:up,dirname:cp,extname:dp,join:hp,sep:"/"};function up(e,t){if(t!==void 0&&typeof t!="string")throw new TypeError('"ext" argument must be a string');Pt(e);let n=0,r=-1,s=e.length,i;if(t===void 0||t.length===0||t.length>e.length){for(;s--;)if(e.codePointAt(s)===47){if(i){n=s+1;break}}else r<0&&(i=!0,r=s+1);return r<0?"":e.slice(n,r)}if(t===e)return"";let o=-1,a=t.length-1;for(;s--;)if(e.codePointAt(s)===47){if(i){n=s+1;break}}else o<0&&(i=!0,o=s+1),a>-1&&(e.codePointAt(s)===t.codePointAt(a--)?a<0&&(r=s):(a=-1,r=o));return n===r?r=o:r<0&&(r=e.length),e.slice(n,r)}function cp(e){if(Pt(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 dp(e){Pt(e);let t=e.length,n=-1,r=0,s=-1,i=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?s<0?s=t:i!==1&&(i=1):s>-1&&(i=-1)}return s<0||n<0||i===0||i===1&&s===n-1&&s===r+1?"":e.slice(s,n)}function hp(...e){let t=-1,n;for(;++t<e.length;)Pt(e[t]),e[t]&&(n=n===void 0?e[t]:n+"/"+e[t]);return n===void 0?".":fp(n)}function fp(e){Pt(e);const t=e.codePointAt(0)===47;let n=pp(e,!t);return n.length===0&&!t&&(n="."),n.length>0&&e.codePointAt(e.length-1)===47&&(n+="/"),t?"/"+n:n}function pp(e,t){let n="",r=0,s=-1,i=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(!(s===o-1||i===1))if(s!==o-1&&i===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("/")),s=o,i=0;continue}}else if(n.length>0){n="",r=0,s=o,i=0;continue}}t&&(n=n.length>0?n+"/..":"..",r=2)}else n.length>0?n+="/"+e.slice(s+1,o):n=e.slice(s+1,o),r=o-s-1;s=o,i=0}else a===46&&i>-1?i++:i=-1}return n}function Pt(e){if(typeof e!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(e))}const gp={cwd:mp};function mp(){return"/"}function Qn(e){return!!(e!==null&&typeof e=="object"&&"href"in e&&e.href&&"protocol"in e&&e.protocol&&e.auth===void 0)}function yp(e){if(typeof e=="string")e=new URL(e);else if(!Qn(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 xp(e)}function xp(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 s=new TypeError("File URL path must not include encoded / characters");throw s.code="ERR_INVALID_FILE_URL_PATH",s}}return decodeURIComponent(t)}const yn=["history","path","basename","stem","extname","dirname"];class Oo{constructor(t){let n;t?Qn(t)?n={path:t}:typeof t=="string"||bp(t)?n={value:t}:n=t:n={},this.cwd="cwd"in n?"":gp.cwd(),this.data={},this.history=[],this.messages=[],this.value,this.map,this.result,this.stored;let r=-1;for(;++r<yn.length;){const i=yn[r];i in n&&n[i]!==void 0&&n[i]!==null&&(this[i]=i==="history"?[...n[i]]:n[i])}let s;for(s in n)yn.includes(s)||(this[s]=n[s])}get basename(){return typeof this.path=="string"?Fe.basename(this.path):void 0}set basename(t){bn(t,"basename"),xn(t,"basename"),this.path=Fe.join(this.dirname||"",t)}get dirname(){return typeof this.path=="string"?Fe.dirname(this.path):void 0}set dirname(t){Ms(this.basename,"dirname"),this.path=Fe.join(t||"",this.basename)}get extname(){return typeof this.path=="string"?Fe.extname(this.path):void 0}set extname(t){if(xn(t,"extname"),Ms(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=Fe.join(this.dirname,this.stem+(t||""))}get path(){return this.history[this.history.length-1]}set path(t){Qn(t)&&(t=yp(t)),bn(t,"path"),this.path!==t&&this.history.push(t)}get stem(){return typeof this.path=="string"?Fe.basename(this.path,this.extname):void 0}set stem(t){bn(t,"stem"),xn(t,"stem"),this.path=Fe.join(this.dirname||"",t+(this.extname||""))}fail(t,n,r){const s=this.message(t,n,r);throw s.fatal=!0,s}info(t,n,r){const s=this.message(t,n,r);return s.fatal=void 0,s}message(t,n,r){const s=new ge(t,n,r);return this.path&&(s.name=this.path+":"+s.name,s.file=this.path),s.fatal=!1,this.messages.push(s),s}toString(t){return this.value===void 0?"":typeof this.value=="string"?this.value:new TextDecoder(t||void 0).decode(this.value)}}function xn(e,t){if(e&&e.includes(Fe.sep))throw new Error("`"+t+"` cannot be a path: did not expect `"+Fe.sep+"`")}function bn(e,t){if(!e)throw new Error("`"+t+"` cannot be empty")}function Ms(e,t){if(!e)throw new Error("Setting `"+t+"` requires `path` to be set too")}function bp(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}const Sp=(function(e){const r=this.constructor.prototype,s=r[e],i=function(){return s.apply(i,arguments)};return Object.setPrototypeOf(i,r),i}),kp={}.hasOwnProperty;class Lr extends Sp{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=ap()}copy(){const t=new Lr;let n=-1;for(;++n<this.attachers.length;){const r=this.attachers[n];t.use(...r)}return t.data(mn(!0,{},this.namespace)),t}data(t,n){return typeof t=="string"?arguments.length===2?(vn("data",this.frozen),this.namespace[t]=n,this):kp.call(this.namespace,t)&&this.namespace[t]||void 0:t?(vn("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 s=n.call(t,...r);typeof s=="function"&&this.transformers.use(s)}return this.frozen=!0,this.freezeIndex=Number.POSITIVE_INFINITY,this}parse(t){this.freeze();const n=Ot(t),r=this.parser||this.Parser;return Sn("parse",r),r(String(n),n)}process(t,n){const r=this;return this.freeze(),Sn("process",this.parser||this.Parser),kn("process",this.compiler||this.Compiler),n?s(void 0,n):new Promise(s);function s(i,o){const a=Ot(t),l=r.parse(a);r.run(l,a,function(c,d,p){if(c||!d||!p)return u(c);const f=d,m=r.stringify(f,p);Cp(m)?p.value=m:p.result=m,u(c,p)});function u(c,d){c||!d?o(c):i?i(d):n(void 0,d)}}}processSync(t){let n=!1,r;return this.freeze(),Sn("processSync",this.parser||this.Parser),kn("processSync",this.compiler||this.Compiler),this.process(t,s),Es("processSync","process",n),r;function s(i,o){n=!0,Is(i),r=o}}run(t,n,r){Rs(t),this.freeze();const s=this.transformers;return!r&&typeof n=="function"&&(r=n,n=void 0),r?i(void 0,r):new Promise(i);function i(o,a){const l=Ot(n);s.run(t,l,u);function u(c,d,p){const f=d||t;c?a(c):o?o(f):r(void 0,f,p)}}}runSync(t,n){let r=!1,s;return this.run(t,n,i),Es("runSync","run",r),s;function i(o,a){Is(o),s=a,r=!0}}stringify(t,n){this.freeze();const r=Ot(n),s=this.compiler||this.Compiler;return kn("stringify",s),Rs(t),s(t,r)}use(t,...n){const r=this.attachers,s=this.namespace;if(vn("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 i(u){if(typeof u=="function")l(u,[]);else if(typeof u=="object")if(Array.isArray(u)){const[c,...d]=u;l(c,d)}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&&(s.settings=mn(!0,s.settings,u.settings))}function a(u){let c=-1;if(u!=null)if(Array.isArray(u))for(;++c<u.length;){const d=u[c];i(d)}else throw new TypeError("Expected a list of plugins, not `"+u+"`")}function l(u,c){let d=-1,p=-1;for(;++d<r.length;)if(r[d][0]===u){p=d;break}if(p===-1)r.push([u,...c]);else if(c.length>0){let[f,...m]=c;const y=r[p][1];Gn(y)&&Gn(f)&&(f=mn(!0,y,f)),r[p]=[u,f,...m]}}}}const vp=new Lr().freeze();function Sn(e,t){if(typeof t!="function")throw new TypeError("Cannot `"+e+"` without `parser`")}function kn(e,t){if(typeof t!="function")throw new TypeError("Cannot `"+e+"` without `compiler`")}function vn(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 Rs(e){if(!Gn(e)||typeof e.type!="string")throw new TypeError("Expected node, got `"+e+"`")}function Es(e,t,n){if(!n)throw new Error("`"+e+"` finished async. Use `"+t+"` instead")}function Ot(e){return wp(e)?e:new Oo(e)}function wp(e){return!!(e&&typeof e=="object"&&"message"in e&&"messages"in e)}function Cp(e){return typeof e=="string"||Ip(e)}function Ip(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}const Tp="https://github.com/remarkjs/react-markdown/blob/main/changelog.md",As=[],Ls={allowDangerousHtml:!0},Mp=/^(https?|ircs?|mailto|xmpp)$/i,Rp=[{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 Ep(e){const t=Ap(e),n=Lp(e);return Np(t.runSync(t.parse(n),n),e)}function Ap(e){const t=e.rehypePlugins||As,n=e.remarkPlugins||As,r=e.remarkRehypeOptions?{...e.remarkRehypeOptions,...Ls}:Ls;return vp().use(cf).use(n).use(sp,r).use(t)}function Lp(e){const t=e.children||"",n=new Oo;return typeof t=="string"&&(n.value=t),n}function Np(e,t){const n=t.allowedElements,r=t.allowElement,s=t.components,i=t.disallowedElements,o=t.skipHtml,a=t.unwrapDisallowed,l=t.urlTransform||Pp;for(const c of Rp)Object.hasOwn(t,c.from)&&(""+c.from+(c.to?"use `"+c.to+"` instead":"remove it")+Tp+c.id,void 0);return Ar(e,u),qc(e,{Fragment:h.Fragment,components:s,ignoreInvalidStyle:!0,jsx:h.jsx,jsxs:h.jsxs,passKeys:!0,passNode:!0});function u(c,d,p){if(c.type==="raw"&&p&&typeof d=="number")return o?p.children.splice(d,1):p.children[d]={type:"text",value:c.value},d;if(c.type==="element"){let f;for(f in hn)if(Object.hasOwn(hn,f)&&Object.hasOwn(c.properties,f)){const m=c.properties[f],y=hn[f];(y===null||y.includes(c.tagName))&&(c.properties[f]=l(String(m||""),f,c))}}if(c.type==="element"){let f=n?!n.includes(c.tagName):i?i.includes(c.tagName):!1;if(!f&&r&&typeof d=="number"&&(f=!r(c,d,p)),f&&p&&typeof d=="number")return a&&c.children?p.children.splice(d,1,...c.children):p.children.splice(d,1),d}}}function Pp(e){const t=e.indexOf(":"),n=e.indexOf("?"),r=e.indexOf("#"),s=e.indexOf("/");return t===-1||s!==-1&&t>s||n!==-1&&t>n||r!==-1&&t>r||Mp.test(e.slice(0,t))?e:""}function Ns(e,t){const n=String(e);if(typeof t!="string")throw new TypeError("Expected character");let r=0,s=n.indexOf(t);for(;s!==-1;)r++,s=n.indexOf(t,s+t.length);return r}function jp(e){if(typeof e!="string")throw new TypeError("Expected a string");return e.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}function Dp(e,t,n){const s=rn((n||{}).ignore||[]),i=_p(t);let o=-1;for(;++o<i.length;)_o(e,"text",a);function a(u,c){let d=-1,p;for(;++d<c.length;){const f=c[d],m=p?p.children:void 0;if(s(f,m?m.indexOf(f):void 0,p))return;p=f}if(p)return l(u,c)}function l(u,c){const d=c[c.length-1],p=i[o][0],f=i[o][1];let m=0;const b=d.children.indexOf(u);let g=!1,v=[];p.lastIndex=0;let w=p.exec(u.value);for(;w;){const T=w.index,A={index:w.index,input:w.input,stack:[...c,u]};let k=f(...w,A);if(typeof k=="string"&&(k=k.length>0?{type:"text",value:k}:void 0),k===!1?p.lastIndex=T+1:(m!==T&&v.push({type:"text",value:u.value.slice(m,T)}),Array.isArray(k)?v.push(...k):k&&v.push(k),m=T+w[0].length,g=!0),!p.global)break;w=p.exec(u.value)}return g?(m<u.value.length&&v.push({type:"text",value:u.value.slice(m)}),d.children.splice(b,1,...v)):v=[u],b+v.length}}function _p(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 s=n[r];t.push([Op(s[0]),Fp(s[1])])}return t}function Op(e){return typeof e=="string"?new RegExp(jp(e),"g"):e}function Fp(e){return typeof e=="function"?e:function(){return e}}const wn="phrasing",Cn=["autolink","link","image","label"];function zp(){return{transforms:[qp],enter:{literalAutolink:$p,literalAutolinkEmail:In,literalAutolinkHttp:In,literalAutolinkWww:In},exit:{literalAutolink:Vp,literalAutolinkEmail:Hp,literalAutolinkHttp:Up,literalAutolinkWww:Kp}}}function Bp(){return{unsafe:[{character:"@",before:"[+\\-.\\w]",after:"[\\-.\\w]",inConstruct:wn,notInConstruct:Cn},{character:".",before:"[Ww]",after:"[\\-.\\w]",inConstruct:wn,notInConstruct:Cn},{character:":",before:"[ps]",after:"\\/",inConstruct:wn,notInConstruct:Cn}]}}function $p(e){this.enter({type:"link",title:null,url:"",children:[]},e)}function In(e){this.config.enter.autolinkProtocol.call(this,e)}function Up(e){this.config.exit.autolinkProtocol.call(this,e)}function Kp(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 Hp(e){this.config.exit.autolinkEmail.call(this,e)}function Vp(e){this.exit(e)}function qp(e){Dp(e,[[/(https?:\/\/|www(?=\.))([-.\w]+)([^ \t\r\n]*)/gi,Wp],[new RegExp("(?<=^|\\s|\\p{P}|\\p{S})([-.\\w+]+)@([-\\w]+(?:\\.[-\\w]+)+)","gu"),Gp]],{ignore:["link","linkReference"]})}function Wp(e,t,n,r,s){let i="";if(!Fo(s)||(/^w/i.test(t)&&(n=t+n,t="",i="http://"),!Qp(n)))return!1;const o=Xp(n+r);if(!o[0])return!1;const a={type:"link",title:null,url:i+t+o[0],children:[{type:"text",value:t+o[0]}]};return o[1]?[a,{type:"text",value:o[1]}]:a}function Gp(e,t,n,r){return!Fo(r,!0)||/[-\d_]$/.test(n)?!1:{type:"link",title:null,url:"mailto:"+t+"@"+n,children:[{type:"text",value:t+"@"+n}]}}function Qp(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 Xp(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 s=Ns(e,"(");let i=Ns(e,")");for(;r!==-1&&s>i;)e+=n.slice(0,r+1),n=n.slice(r+1),r=n.indexOf(")"),i++;return[e,n]}function Fo(e,t){const n=e.input.charCodeAt(e.index-1);return(e.index===0||tt(n)||en(n))&&(!t||n!==47)}zo.peek=ig;function Yp(){this.buffer()}function Jp(e){this.enter({type:"footnoteReference",identifier:"",label:""},e)}function Zp(){this.buffer()}function eg(e){this.enter({type:"footnoteDefinition",identifier:"",label:"",children:[]},e)}function tg(e){const t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=je(this.sliceSerialize(e)).toLowerCase(),n.label=t}function ng(e){this.exit(e)}function rg(e){const t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=je(this.sliceSerialize(e)).toLowerCase(),n.label=t}function sg(e){this.exit(e)}function ig(){return"["}function zo(e,t,n,r){const s=n.createTracker(r);let i=s.move("[^");const o=n.enter("footnoteReference"),a=n.enter("reference");return i+=s.move(n.safe(n.associationId(e),{after:"]",before:i})),a(),o(),i+=s.move("]"),i}function og(){return{enter:{gfmFootnoteCallString:Yp,gfmFootnoteCall:Jp,gfmFootnoteDefinitionLabelString:Zp,gfmFootnoteDefinition:eg},exit:{gfmFootnoteCallString:tg,gfmFootnoteCall:ng,gfmFootnoteDefinitionLabelString:rg,gfmFootnoteDefinition:sg}}}function ag(e){let t=!1;return e&&e.firstLineBlank&&(t=!0),{handlers:{footnoteDefinition:n,footnoteReference:zo},unsafe:[{character:"[",inConstruct:["label","phrasing","reference"]}]};function n(r,s,i,o){const a=i.createTracker(o);let l=a.move("[^");const u=i.enter("footnoteDefinition"),c=i.enter("label");return l+=a.move(i.safe(i.associationId(r),{before:l,after:"]"})),c(),l+=a.move("]:"),r.children&&r.children.length>0&&(a.shift(4),l+=a.move((t?`
16
+ `:" ")+i.indentLines(i.containerFlow(r,a.current()),t?Bo:lg))),u(),l}}function lg(e,t,n){return t===0?e:Bo(e,t,n)}function Bo(e,t,n){return(n?"":" ")+e}const ug=["autolink","destinationLiteral","destinationRaw","reference","titleQuote","titleApostrophe"];$o.peek=pg;function cg(){return{canContainEols:["delete"],enter:{strikethrough:hg},exit:{strikethrough:fg}}}function dg(){return{unsafe:[{character:"~",inConstruct:"phrasing",notInConstruct:ug}],handlers:{delete:$o}}}function hg(e){this.enter({type:"delete",children:[]},e)}function fg(e){this.exit(e)}function $o(e,t,n,r){const s=n.createTracker(r),i=n.enter("strikethrough");let o=s.move("~~");return o+=n.containerPhrasing(e,{...s.current(),before:o,after:"~"}),o+=s.move("~~"),i(),o}function pg(){return"~"}function gg(e){return e.length}function mg(e,t){const n=t||{},r=(n.align||[]).concat(),s=n.stringLength||gg,i=[],o=[],a=[],l=[];let u=0,c=-1;for(;++c<e.length;){const y=[],b=[];let g=-1;for(e[c].length>u&&(u=e[c].length);++g<e[c].length;){const v=yg(e[c][g]);if(n.alignDelimiters!==!1){const w=s(v);b[g]=w,(l[g]===void 0||w>l[g])&&(l[g]=w)}y.push(v)}o[c]=y,a[c]=b}let d=-1;if(typeof r=="object"&&"length"in r)for(;++d<u;)i[d]=Ps(r[d]);else{const y=Ps(r);for(;++d<u;)i[d]=y}d=-1;const p=[],f=[];for(;++d<u;){const y=i[d];let b="",g="";y===99?(b=":",g=":"):y===108?b=":":y===114&&(g=":");let v=n.alignDelimiters===!1?1:Math.max(1,l[d]-b.length-g.length);const w=b+"-".repeat(v)+g;n.alignDelimiters!==!1&&(v=b.length+v+g.length,v>l[d]&&(l[d]=v),f[d]=v),p[d]=w}o.splice(1,0,p),a.splice(1,0,f),c=-1;const m=[];for(;++c<o.length;){const y=o[c],b=a[c];d=-1;const g=[];for(;++d<u;){const v=y[d]||"";let w="",T="";if(n.alignDelimiters!==!1){const A=l[d]-(b[d]||0),k=i[d];k===114?w=" ".repeat(A):k===99?A%2?(w=" ".repeat(A/2+.5),T=" ".repeat(A/2-.5)):(w=" ".repeat(A/2),T=w):T=" ".repeat(A)}n.delimiterStart!==!1&&!d&&g.push("|"),n.padding!==!1&&!(n.alignDelimiters===!1&&v==="")&&(n.delimiterStart!==!1||d)&&g.push(" "),n.alignDelimiters!==!1&&g.push(w),g.push(v),n.alignDelimiters!==!1&&g.push(T),n.padding!==!1&&g.push(" "),(n.delimiterEnd!==!1||d!==u-1)&&g.push("|")}m.push(n.delimiterEnd===!1?g.join("").replace(/ +$/,""):g.join(""))}return m.join(`
17
+ `)}function yg(e){return e==null?"":String(e)}function Ps(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 xg(e,t,n,r){const s=n.enter("blockquote"),i=n.createTracker(r);i.move("> "),i.shift(2);const o=n.indentLines(n.containerFlow(e,i.current()),bg);return s(),o}function bg(e,t,n){return">"+(n?"":" ")+e}function Sg(e,t){return js(e,t.inConstruct,!0)&&!js(e,t.notInConstruct,!1)}function js(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 Ds(e,t,n,r){let s=-1;for(;++s<n.unsafe.length;)if(n.unsafe[s].character===`
18
+ `&&Sg(n.stack,n.unsafe[s]))return/[ \t]/.test(r.before)?"":" ";return`\\
19
+ `}function kg(e,t){const n=String(e);let r=n.indexOf(t),s=r,i=0,o=0;if(typeof t!="string")throw new TypeError("Expected substring");for(;r!==-1;)r===s?++i>o&&(o=i):i=1,s=r+t.length,r=n.indexOf(t,s);return o}function vg(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 wg(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 Cg(e,t,n,r){const s=wg(n),i=e.value||"",o=s==="`"?"GraveAccent":"Tilde";if(vg(e,n)){const d=n.enter("codeIndented"),p=n.indentLines(i,Ig);return d(),p}const a=n.createTracker(r),l=s.repeat(Math.max(kg(i,s)+1,3)),u=n.enter("codeFenced");let c=a.move(l);if(e.lang){const d=n.enter(`codeFencedLang${o}`);c+=a.move(n.safe(e.lang,{before:c,after:" ",encode:["`"],...a.current()})),d()}if(e.lang&&e.meta){const d=n.enter(`codeFencedMeta${o}`);c+=a.move(" "),c+=a.move(n.safe(e.meta,{before:c,after:`
20
+ `,encode:["`"],...a.current()})),d()}return c+=a.move(`
21
+ `),i&&(c+=a.move(i+`
22
+ `)),c+=a.move(l),u(),c}function Ig(e,t,n){return(n?"":" ")+e}function Nr(e){const t=e.options.quote||'"';if(t!=='"'&&t!=="'")throw new Error("Cannot serialize title with `"+t+"` for `options.quote`, expected `\"`, or `'`");return t}function Tg(e,t,n,r){const s=Nr(n),i=s==='"'?"Quote":"Apostrophe",o=n.enter("definition");let a=n.enter("label");const l=n.createTracker(r);let u=l.move("[");return u+=l.move(n.safe(n.associationId(e),{before:u,after:"]",...l.current()})),u+=l.move("]: "),a(),!e.url||/[\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?" ":`
23
+ `,...l.current()}))),a(),e.title&&(a=n.enter(`title${i}`),u+=l.move(" "+s),u+=l.move(n.safe(e.title,{before:u,after:s,...l.current()})),u+=l.move(s),a()),o(),u}function Mg(e){const t=e.options.emphasis||"*";if(t!=="*"&&t!=="_")throw new Error("Cannot serialize emphasis with `"+t+"` for `options.emphasis`, expected `*`, or `_`");return t}function Mt(e){return"&#x"+e.toString(16).toUpperCase()+";"}function Xt(e,t,n){const r=dt(e),s=dt(t);return r===void 0?s===void 0?n==="_"?{inside:!0,outside:!0}:{inside:!1,outside:!1}:s===1?{inside:!0,outside:!0}:{inside:!1,outside:!0}:r===1?s===void 0?{inside:!1,outside:!1}:s===1?{inside:!0,outside:!0}:{inside:!1,outside:!1}:s===void 0?{inside:!1,outside:!1}:s===1?{inside:!0,outside:!1}:{inside:!1,outside:!1}}Uo.peek=Rg;function Uo(e,t,n,r){const s=Mg(n),i=n.enter("emphasis"),o=n.createTracker(r),a=o.move(s);let l=o.move(n.containerPhrasing(e,{after:s,before:a,...o.current()}));const u=l.charCodeAt(0),c=Xt(r.before.charCodeAt(r.before.length-1),u,s);c.inside&&(l=Mt(u)+l.slice(1));const d=l.charCodeAt(l.length-1),p=Xt(r.after.charCodeAt(0),d,s);p.inside&&(l=l.slice(0,-1)+Mt(d));const f=o.move(s);return i(),n.attentionEncodeSurroundingInfo={after:p.outside,before:c.outside},a+l+f}function Rg(e,t,n){return n.options.emphasis||"*"}function Eg(e,t){let n=!1;return Ar(e,function(r){if("value"in r&&/\r?\n|\r/.test(r.value)||r.type==="break")return n=!0,qn}),!!((!e.depth||e.depth<3)&&wr(e)&&(t.options.setext||n))}function Ag(e,t,n,r){const s=Math.max(Math.min(6,e.depth||1),1),i=n.createTracker(r);if(Eg(e,n)){const c=n.enter("headingSetext"),d=n.enter("phrasing"),p=n.containerPhrasing(e,{...i.current(),before:`
24
+ `,after:`
25
+ `});return d(),c(),p+`
26
+ `+(s===1?"=":"-").repeat(p.length-(Math.max(p.lastIndexOf("\r"),p.lastIndexOf(`
27
+ `))+1))}const o="#".repeat(s),a=n.enter("headingAtx"),l=n.enter("phrasing");i.move(o+" ");let u=n.containerPhrasing(e,{before:"# ",after:`
28
+ `,...i.current()});return/^[\t ]/.test(u)&&(u=Mt(u.charCodeAt(0))+u.slice(1)),u=u?o+" "+u:o,n.options.closeAtx&&(u+=" "+o),l(),a(),u}Ko.peek=Lg;function Ko(e){return e.value||""}function Lg(){return"<"}Ho.peek=Ng;function Ho(e,t,n,r){const s=Nr(n),i=s==='"'?"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${i}`),u+=l.move(" "+s),u+=l.move(n.safe(e.title,{before:u,after:s,...l.current()})),u+=l.move(s),a()),u+=l.move(")"),o(),u}function Ng(){return"!"}Vo.peek=Pg;function Vo(e,t,n,r){const s=e.referenceType,i=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 d=n.safe(n.associationId(e),{before:l,after:"]",...a.current()});return o(),n.stack=c,i(),s==="full"||!u||u!==d?l+=a.move(d+"]"):s==="shortcut"?l=l.slice(0,-1):l+=a.move("]"),l}function Pg(){return"!"}qo.peek=jg;function qo(e,t,n){let r=e.value||"",s="`",i=-1;for(;new RegExp("(^|[^`])"+s+"([^`]|$)").test(r);)s+="`";for(/[^ \r\n]/.test(r)&&(/^[ \r\n]/.test(r)&&/[ \r\n]$/.test(r)||/^`|`$/.test(r))&&(r=" "+r+" ");++i<n.unsafe.length;){const o=n.unsafe[i],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 s+r+s}function jg(){return"`"}function Wo(e,t){const n=wr(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))}Go.peek=Dg;function Go(e,t,n,r){const s=Nr(n),i=s==='"'?"Quote":"Apostrophe",o=n.createTracker(r);let a,l;if(Wo(e,n)){const c=n.stack;n.stack=[],a=n.enter("autolink");let d=o.move("<");return d+=o.move(n.containerPhrasing(e,{before:d,after:">",...o.current()})),d+=o.move(">"),a(),n.stack=c,d}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${i}`),u+=o.move(" "+s),u+=o.move(n.safe(e.title,{before:u,after:s,...o.current()})),u+=o.move(s),l()),u+=o.move(")"),a(),u}function Dg(e,t,n){return Wo(e,n)?"<":"["}Qo.peek=_g;function Qo(e,t,n,r){const s=e.referenceType,i=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 d=n.safe(n.associationId(e),{before:l,after:"]",...a.current()});return o(),n.stack=c,i(),s==="full"||!u||u!==d?l+=a.move(d+"]"):s==="shortcut"?l=l.slice(0,-1):l+=a.move("]"),l}function _g(){return"["}function Pr(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 Og(e){const t=Pr(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 Fg(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 Xo(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 zg(e,t,n,r){const s=n.enter("list"),i=n.bulletCurrent;let o=e.ordered?Fg(n):Pr(n);const a=e.ordered?o==="."?")":".":Og(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),Xo(n)===o&&c){let d=-1;for(;++d<e.children.length;){const p=e.children[d];if(p&&p.type==="listItem"&&p.children&&p.children[0]&&p.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=i,s(),u}function Bg(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 $g(e,t,n,r){const s=Bg(n);let i=n.bulletCurrent||Pr(n);t&&t.type==="list"&&t.ordered&&(i=(typeof t.start=="number"&&t.start>-1?t.start:1)+(n.options.incrementListMarker===!1?0:t.children.indexOf(e))+i);let o=i.length+1;(s==="tab"||s==="mixed"&&(t&&t.type==="list"&&t.spread||e.spread))&&(o=Math.ceil(o/4)*4);const a=n.createTracker(r);a.move(i+" ".repeat(o-i.length)),a.shift(o);const l=n.enter("listItem"),u=n.indentLines(n.containerFlow(e,a.current()),c);return l(),u;function c(d,p,f){return p?(f?"":" ".repeat(o))+d:(f?i:i+" ".repeat(o-i.length))+d}}function Ug(e,t,n,r){const s=n.enter("paragraph"),i=n.enter("phrasing"),o=n.containerPhrasing(e,r);return i(),s(),o}const Kg=rn(["break","delete","emphasis","footnote","footnoteReference","image","imageReference","inlineCode","inlineMath","link","linkReference","mdxJsxTextElement","mdxTextExpression","strong","text","textDirective"]);function Hg(e,t,n,r){return(e.children.some(function(o){return Kg(o)})?n.containerPhrasing:n.containerFlow).call(n,e,r)}function Vg(e){const t=e.options.strong||"*";if(t!=="*"&&t!=="_")throw new Error("Cannot serialize strong with `"+t+"` for `options.strong`, expected `*`, or `_`");return t}Yo.peek=qg;function Yo(e,t,n,r){const s=Vg(n),i=n.enter("strong"),o=n.createTracker(r),a=o.move(s+s);let l=o.move(n.containerPhrasing(e,{after:s,before:a,...o.current()}));const u=l.charCodeAt(0),c=Xt(r.before.charCodeAt(r.before.length-1),u,s);c.inside&&(l=Mt(u)+l.slice(1));const d=l.charCodeAt(l.length-1),p=Xt(r.after.charCodeAt(0),d,s);p.inside&&(l=l.slice(0,-1)+Mt(d));const f=o.move(s+s);return i(),n.attentionEncodeSurroundingInfo={after:p.outside,before:c.outside},a+l+f}function qg(e,t,n){return n.options.strong||"*"}function Wg(e,t,n,r){return n.safe(e.value,r)}function Gg(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 Qg(e,t,n){const r=(Xo(n)+(n.options.ruleSpaces?" ":"")).repeat(Gg(n));return n.options.ruleSpaces?r.slice(0,-1):r}const Jo={blockquote:xg,break:Ds,code:Cg,definition:Tg,emphasis:Uo,hardBreak:Ds,heading:Ag,html:Ko,image:Ho,imageReference:Vo,inlineCode:qo,link:Go,linkReference:Qo,list:zg,listItem:$g,paragraph:Ug,root:Hg,strong:Yo,text:Wg,thematicBreak:Qg};function Xg(){return{enter:{table:Yg,tableData:_s,tableHeader:_s,tableRow:Zg},exit:{codeText:em,table:Jg,tableData:Tn,tableHeader:Tn,tableRow:Tn}}}function Yg(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 Jg(e){this.exit(e),this.data.inTable=void 0}function Zg(e){this.enter({type:"tableRow",children:[]},e)}function Tn(e){this.exit(e)}function _s(e){this.enter({type:"tableCell",children:[]},e)}function em(e){let t=this.resume();this.data.inTable&&(t=t.replace(/\\([\\|])/g,tm));const n=this.stack[this.stack.length-1];n.type,n.value=t,this.exit(e)}function tm(e,t){return t==="|"?t:e}function nm(e){const t=e||{},n=t.tableCellPadding,r=t.tablePipeAlign,s=t.stringLength,i=n?" ":"|";return{unsafe:[{character:"\r",inConstruct:"tableCell"},{character:`
29
+ `,inConstruct:"tableCell"},{atBreak:!0,character:"|",after:"[ :-]"},{character:"|",inConstruct:"tableCell"},{atBreak:!0,character:":",after:"-"},{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{inlineCode:p,table:o,tableCell:l,tableRow:a}};function o(f,m,y,b){return u(c(f,y,b),f.align)}function a(f,m,y,b){const g=d(f,y,b),v=u([g]);return v.slice(0,v.indexOf(`
30
+ `))}function l(f,m,y,b){const g=y.enter("tableCell"),v=y.enter("phrasing"),w=y.containerPhrasing(f,{...b,before:i,after:i});return v(),g(),w}function u(f,m){return mg(f,{align:m,alignDelimiters:r,padding:n,stringLength:s})}function c(f,m,y){const b=f.children;let g=-1;const v=[],w=m.enter("table");for(;++g<b.length;)v[g]=d(b[g],m,y);return w(),v}function d(f,m,y){const b=f.children;let g=-1;const v=[],w=m.enter("tableRow");for(;++g<b.length;)v[g]=l(b[g],f,m,y);return w(),v}function p(f,m,y){let b=Jo.inlineCode(f,m,y);return y.stack.includes("tableCell")&&(b=b.replace(/\|/g,"\\$&")),b}}function rm(){return{exit:{taskListCheckValueChecked:Os,taskListCheckValueUnchecked:Os,paragraph:im}}}function sm(){return{unsafe:[{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{listItem:om}}}function Os(e){const t=this.stack[this.stack.length-2];t.type,t.checked=e.type==="taskListCheckValueChecked"}function im(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 s=t.children;let i=-1,o;for(;++i<s.length;){const a=s[i];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 om(e,t,n,r){const s=e.children[0],i=typeof e.checked=="boolean"&&s&&s.type==="paragraph",o="["+(e.checked?"x":" ")+"] ",a=n.createTracker(r);i&&a.move(o);let l=Jo.listItem(e,t,n,{...r,...a.current()});return i&&(l=l.replace(/^(?:[*+-]|\d+\.)([\r\n]| {1,3})/,u)),l;function u(c){return c+o}}function am(){return[zp(),og(),cg(),Xg(),rm()]}function lm(e){return{extensions:[Bp(),ag(e),dg(),nm(e),sm()]}}const um={tokenize:gm,partial:!0},Zo={tokenize:mm,partial:!0},ea={tokenize:ym,partial:!0},ta={tokenize:xm,partial:!0},cm={tokenize:bm,partial:!0},na={name:"wwwAutolink",tokenize:fm,previous:sa},ra={name:"protocolAutolink",tokenize:pm,previous:ia},We={name:"emailAutolink",tokenize:hm,previous:oa},ze={};function dm(){return{text:ze}}let Ze=48;for(;Ze<123;)ze[Ze]=We,Ze++,Ze===58?Ze=65:Ze===91&&(Ze=97);ze[43]=We;ze[45]=We;ze[46]=We;ze[95]=We;ze[72]=[We,ra];ze[104]=[We,ra];ze[87]=[We,na];ze[119]=[We,na];function hm(e,t,n){const r=this;let s,i;return o;function o(d){return!Xn(d)||!oa.call(r,r.previous)||jr(r.events)?n(d):(e.enter("literalAutolink"),e.enter("literalAutolinkEmail"),a(d))}function a(d){return Xn(d)?(e.consume(d),a):d===64?(e.consume(d),l):n(d)}function l(d){return d===46?e.check(cm,c,u)(d):d===45||d===95||pe(d)?(i=!0,e.consume(d),l):c(d)}function u(d){return e.consume(d),s=!0,l}function c(d){return i&&s&&me(r.previous)?(e.exit("literalAutolinkEmail"),e.exit("literalAutolink"),t(d)):n(d)}}function fm(e,t,n){const r=this;return s;function s(o){return o!==87&&o!==119||!sa.call(r,r.previous)||jr(r.events)?n(o):(e.enter("literalAutolink"),e.enter("literalAutolinkWww"),e.check(um,e.attempt(Zo,e.attempt(ea,i),n),n)(o))}function i(o){return e.exit("literalAutolinkWww"),e.exit("literalAutolink"),t(o)}}function pm(e,t,n){const r=this;let s="",i=!1;return o;function o(d){return(d===72||d===104)&&ia.call(r,r.previous)&&!jr(r.events)?(e.enter("literalAutolink"),e.enter("literalAutolinkHttp"),s+=String.fromCodePoint(d),e.consume(d),a):n(d)}function a(d){if(me(d)&&s.length<5)return s+=String.fromCodePoint(d),e.consume(d),a;if(d===58){const p=s.toLowerCase();if(p==="http"||p==="https")return e.consume(d),l}return n(d)}function l(d){return d===47?(e.consume(d),i?u:(i=!0,l)):n(d)}function u(d){return d===null||Wt(d)||ee(d)||tt(d)||en(d)?n(d):e.attempt(Zo,e.attempt(ea,c),n)(d)}function c(d){return e.exit("literalAutolinkHttp"),e.exit("literalAutolink"),t(d)}}function gm(e,t,n){let r=0;return s;function s(o){return(o===87||o===119)&&r<3?(r++,e.consume(o),s):o===46&&r===3?(e.consume(o),i):n(o)}function i(o){return o===null?n(o):t(o)}}function mm(e,t,n){let r,s,i;return o;function o(u){return u===46||u===95?e.check(ta,l,a)(u):u===null||ee(u)||tt(u)||u!==45&&en(u)?l(u):(i=!0,e.consume(u),o)}function a(u){return u===95?r=!0:(s=r,r=void 0),e.consume(u),o}function l(u){return s||r||!i?n(u):t(u)}}function ym(e,t){let n=0,r=0;return s;function s(o){return o===40?(n++,e.consume(o),s):o===41&&r<n?i(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(ta,t,i)(o):o===null||ee(o)||tt(o)?t(o):(e.consume(o),s)}function i(o){return o===41&&r++,e.consume(o),s}}function xm(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),i):a===93?(e.consume(a),s):a===60||a===null||ee(a)||tt(a)?t(a):n(a)}function s(a){return a===null||a===40||a===91||ee(a)||tt(a)?t(a):r(a)}function i(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 bm(e,t,n){return r;function r(i){return e.consume(i),s}function s(i){return pe(i)?n(i):t(i)}}function sa(e){return e===null||e===40||e===42||e===95||e===91||e===93||e===126||ee(e)}function ia(e){return!me(e)}function oa(e){return!(e===47||Xn(e))}function Xn(e){return e===43||e===45||e===46||e===95||pe(e)}function jr(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 Sm={tokenize:Rm,partial:!0};function km(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:Im,continuation:{tokenize:Tm},exit:Mm}},text:{91:{name:"gfmFootnoteCall",tokenize:Cm},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:vm,resolveTo:wm}}}}function vm(e,t,n){const r=this;let s=r.events.length;const i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let o;for(;s--;){const l=r.events[s][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=je(r.sliceSerialize({start:o.end,end:r.now()}));return u.codePointAt(0)!==94||!i.includes(u.slice(1))?n(l):(e.enter("gfmFootnoteCallLabelMarker"),e.consume(l),e.exit("gfmFootnoteCallLabelMarker"),t(l))}}function wm(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)},s={type:"gfmFootnoteCallMarker",start:Object.assign({},e[n+3][1].end),end:Object.assign({},e[n+3][1].end)};s.end.column++,s.end.offset++,s.end._bufferIndex++;const i={type:"gfmFootnoteCallString",start:Object.assign({},s.end),end:Object.assign({},e[e.length-1][1].start)},o={type:"chunkString",contentType:"string",start:Object.assign({},i.start),end:Object.assign({},i.end)},a=[e[n+1],e[n+2],["enter",r,t],e[n+3],e[n+4],["enter",s,t],["exit",s,t],["enter",i,t],["enter",o,t],["exit",o,t],["exit",i,t],e[e.length-2],e[e.length-1],["exit",r,t]];return e.splice(n,e.length-n+1,...a),e}function Cm(e,t,n){const r=this,s=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let i=0,o;return a;function a(d){return e.enter("gfmFootnoteCall"),e.enter("gfmFootnoteCallLabelMarker"),e.consume(d),e.exit("gfmFootnoteCallLabelMarker"),l}function l(d){return d!==94?n(d):(e.enter("gfmFootnoteCallMarker"),e.consume(d),e.exit("gfmFootnoteCallMarker"),e.enter("gfmFootnoteCallString"),e.enter("chunkString").contentType="string",u)}function u(d){if(i>999||d===93&&!o||d===null||d===91||ee(d))return n(d);if(d===93){e.exit("chunkString");const p=e.exit("gfmFootnoteCallString");return s.includes(je(r.sliceSerialize(p)))?(e.enter("gfmFootnoteCallLabelMarker"),e.consume(d),e.exit("gfmFootnoteCallLabelMarker"),e.exit("gfmFootnoteCall"),t):n(d)}return ee(d)||(o=!0),i++,e.consume(d),d===92?c:u}function c(d){return d===91||d===92||d===93?(e.consume(d),i++,u):u(d)}}function Im(e,t,n){const r=this,s=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let i,o=0,a;return l;function l(m){return e.enter("gfmFootnoteDefinition")._container=!0,e.enter("gfmFootnoteDefinitionLabel"),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(m),e.exit("gfmFootnoteDefinitionLabelMarker"),u}function u(m){return m===94?(e.enter("gfmFootnoteDefinitionMarker"),e.consume(m),e.exit("gfmFootnoteDefinitionMarker"),e.enter("gfmFootnoteDefinitionLabelString"),e.enter("chunkString").contentType="string",c):n(m)}function c(m){if(o>999||m===93&&!a||m===null||m===91||ee(m))return n(m);if(m===93){e.exit("chunkString");const y=e.exit("gfmFootnoteDefinitionLabelString");return i=je(r.sliceSerialize(y)),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(m),e.exit("gfmFootnoteDefinitionLabelMarker"),e.exit("gfmFootnoteDefinitionLabel"),p}return ee(m)||(a=!0),o++,e.consume(m),m===92?d:c}function d(m){return m===91||m===92||m===93?(e.consume(m),o++,c):c(m)}function p(m){return m===58?(e.enter("definitionMarker"),e.consume(m),e.exit("definitionMarker"),s.includes(i)||s.push(i),X(e,f,"gfmFootnoteDefinitionWhitespace")):n(m)}function f(m){return t(m)}}function Tm(e,t,n){return e.check(Nt,t,e.attempt(Sm,t,n))}function Mm(e){e.exit("gfmFootnoteDefinition")}function Rm(e,t,n){const r=this;return X(e,s,"gfmFootnoteDefinitionIndent",5);function s(i){const o=r.events[r.events.length-1];return o&&o[1].type==="gfmFootnoteDefinitionIndent"&&o[2].sliceSerialize(o[1],!0).length===4?t(i):n(i)}}function Em(e){let n=(e||{}).singleTilde;const r={name:"strikethrough",tokenize:i,resolveAll:s};return n==null&&(n=!0),{text:{126:r},insideSpan:{null:[r]},attentionMarkers:{null:[126]}};function s(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)},d={type:"strikethroughText",start:Object.assign({},o[u][1].end),end:Object.assign({},o[l][1].start)},p=[["enter",c,a],["enter",o[u][1],a],["exit",o[u][1],a],["enter",d,a]],f=a.parser.constructs.insideSpan.null;f&&Te(p,p.length,0,tn(f,o.slice(u+1,l),a)),Te(p,p.length,0,[["exit",d,a],["enter",o[l][1],a],["exit",o[l][1],a],["exit",c,a]]),Te(o,u-1,l-u+3,p),l=u+p.length-2;break}}for(l=-1;++l<o.length;)o[l][1].type==="strikethroughSequenceTemporary"&&(o[l][1].type="data");return o}function i(o,a,l){const u=this.previous,c=this.events;let d=0;return p;function p(m){return u===126&&c[c.length-1][1].type!=="characterEscape"?l(m):(o.enter("strikethroughSequenceTemporary"),f(m))}function f(m){const y=dt(u);if(m===126)return d>1?l(m):(o.consume(m),d++,f);if(d<2&&!n)return l(m);const b=o.exit("strikethroughSequenceTemporary"),g=dt(m);return b._open=!g||g===2&&!!y,b._close=!y||y===2&&!!g,a(m)}}}class Am{constructor(){this.map=[]}add(t,n,r){Lm(this,t,n,r)}consume(t){if(this.map.sort(function(i,o){return i[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 s=r.pop();for(;s;){for(const i of s)t.push(i);s=r.pop()}this.map.length=0}}function Lm(e,t,n,r){let s=0;if(!(n===0&&r.length===0)){for(;s<e.map.length;){if(e.map[s][0]===t){e.map[s][1]+=n,e.map[s][2].push(...r);return}s+=1}e.map.push([t,n,r])}}function Nm(e,t){let n=!1;const r=[];for(;t<e.length;){const s=e[t];if(n){if(s[0]==="enter")s[1].type==="tableContent"&&r.push(e[t+1][1].type==="tableDelimiterMarker"?"left":"none");else if(s[1].type==="tableContent"){if(e[t-1][1].type==="tableDelimiterMarker"){const i=r.length-1;r[i]=r[i]==="left"?"center":"right"}}else if(s[1].type==="tableDelimiterRow")break}else s[0]==="enter"&&s[1].type==="tableDelimiterRow"&&(n=!0);t+=1}return r}function Pm(){return{flow:{null:{name:"table",tokenize:jm,resolveAll:Dm}}}}function jm(e,t,n){const r=this;let s=0,i=0,o;return a;function a(I){let j=r.events.length-1;for(;j>-1;){const z=r.events[j][1].type;if(z==="lineEnding"||z==="linePrefix")j--;else break}const _=j>-1?r.events[j][1].type:null,W=_==="tableHead"||_==="tableRow"?k:l;return W===k&&r.parser.lazy[r.now().line]?n(I):W(I)}function l(I){return e.enter("tableHead"),e.enter("tableRow"),u(I)}function u(I){return I===124||(o=!0,i+=1),c(I)}function c(I){return I===null?n(I):B(I)?i>1?(i=0,r.interrupt=!0,e.exit("tableRow"),e.enter("lineEnding"),e.consume(I),e.exit("lineEnding"),f):n(I):V(I)?X(e,c,"whitespace")(I):(i+=1,o&&(o=!1,s+=1),I===124?(e.enter("tableCellDivider"),e.consume(I),e.exit("tableCellDivider"),o=!0,c):(e.enter("data"),d(I)))}function d(I){return I===null||I===124||ee(I)?(e.exit("data"),c(I)):(e.consume(I),I===92?p:d)}function p(I){return I===92||I===124?(e.consume(I),d):d(I)}function f(I){return r.interrupt=!1,r.parser.lazy[r.now().line]?n(I):(e.enter("tableDelimiterRow"),o=!1,V(I)?X(e,m,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(I):m(I))}function m(I){return I===45||I===58?b(I):I===124?(o=!0,e.enter("tableCellDivider"),e.consume(I),e.exit("tableCellDivider"),y):A(I)}function y(I){return V(I)?X(e,b,"whitespace")(I):b(I)}function b(I){return I===58?(i+=1,o=!0,e.enter("tableDelimiterMarker"),e.consume(I),e.exit("tableDelimiterMarker"),g):I===45?(i+=1,g(I)):I===null||B(I)?T(I):A(I)}function g(I){return I===45?(e.enter("tableDelimiterFiller"),v(I)):A(I)}function v(I){return I===45?(e.consume(I),v):I===58?(o=!0,e.exit("tableDelimiterFiller"),e.enter("tableDelimiterMarker"),e.consume(I),e.exit("tableDelimiterMarker"),w):(e.exit("tableDelimiterFiller"),w(I))}function w(I){return V(I)?X(e,T,"whitespace")(I):T(I)}function T(I){return I===124?m(I):I===null||B(I)?!o||s!==i?A(I):(e.exit("tableDelimiterRow"),e.exit("tableHead"),t(I)):A(I)}function A(I){return n(I)}function k(I){return e.enter("tableRow"),N(I)}function N(I){return I===124?(e.enter("tableCellDivider"),e.consume(I),e.exit("tableCellDivider"),N):I===null||B(I)?(e.exit("tableRow"),t(I)):V(I)?X(e,N,"whitespace")(I):(e.enter("data"),F(I))}function F(I){return I===null||I===124||ee(I)?(e.exit("data"),N(I)):(e.consume(I),I===92?O:F)}function O(I){return I===92||I===124?(e.consume(I),F):F(I)}}function Dm(e,t){let n=-1,r=!0,s=0,i=[0,0,0,0],o=[0,0,0,0],a=!1,l=0,u,c,d;const p=new Am;for(;++n<e.length;){const f=e[n],m=f[1];f[0]==="enter"?m.type==="tableHead"?(a=!1,l!==0&&(Fs(p,t,l,u,c),c=void 0,l=0),u={type:"table",start:Object.assign({},m.start),end:Object.assign({},m.end)},p.add(n,0,[["enter",u,t]])):m.type==="tableRow"||m.type==="tableDelimiterRow"?(r=!0,d=void 0,i=[0,0,0,0],o=[0,n+1,0,0],a&&(a=!1,c={type:"tableBody",start:Object.assign({},m.start),end:Object.assign({},m.end)},p.add(n,0,[["enter",c,t]])),s=m.type==="tableDelimiterRow"?2:c?3:1):s&&(m.type==="data"||m.type==="tableDelimiterMarker"||m.type==="tableDelimiterFiller")?(r=!1,o[2]===0&&(i[1]!==0&&(o[0]=o[1],d=Ft(p,t,i,s,void 0,d),i=[0,0,0,0]),o[2]=n)):m.type==="tableCellDivider"&&(r?r=!1:(i[1]!==0&&(o[0]=o[1],d=Ft(p,t,i,s,void 0,d)),i=o,o=[i[1],n,0,0])):m.type==="tableHead"?(a=!0,l=n):m.type==="tableRow"||m.type==="tableDelimiterRow"?(l=n,i[1]!==0?(o[0]=o[1],d=Ft(p,t,i,s,n,d)):o[1]!==0&&(d=Ft(p,t,o,s,n,d)),s=0):s&&(m.type==="data"||m.type==="tableDelimiterMarker"||m.type==="tableDelimiterFiller")&&(o[3]=n)}for(l!==0&&Fs(p,t,l,u,c),p.consume(t.events),n=-1;++n<t.events.length;){const f=t.events[n];f[0]==="enter"&&f[1].type==="table"&&(f[1]._align=Nm(t.events,n))}return e}function Ft(e,t,n,r,s,i){const o=r===1?"tableHeader":r===2?"tableDelimiter":"tableData",a="tableContent";n[0]!==0&&(i.end=Object.assign({},at(t.events,n[0])),e.add(n[0],0,[["exit",i,t]]));const l=at(t.events,n[1]);if(i={type:o,start:Object.assign({},l),end:Object.assign({},l)},e.add(n[1],0,[["enter",i,t]]),n[2]!==0){const u=at(t.events,n[2]),c=at(t.events,n[3]),d={type:a,start:Object.assign({},u),end:Object.assign({},c)};if(e.add(n[2],0,[["enter",d,t]]),r!==2){const p=t.events[n[2]],f=t.events[n[3]];if(p[1].end=Object.assign({},f[1].end),p[1].type="chunkText",p[1].contentType="text",n[3]>n[2]+1){const m=n[2]+1,y=n[3]-n[2]-1;e.add(m,y,[])}}e.add(n[3]+1,0,[["exit",d,t]])}return s!==void 0&&(i.end=Object.assign({},at(t.events,s)),e.add(s,0,[["exit",i,t]]),i=void 0),i}function Fs(e,t,n,r,s){const i=[],o=at(t.events,n);s&&(s.end=Object.assign({},o),i.push(["exit",s,t])),r.end=Object.assign({},o),i.push(["exit",r,t]),e.add(n+1,0,i)}function at(e,t){const n=e[t],r=n[0]==="enter"?"start":"end";return n[1][r]}const _m={name:"tasklistCheck",tokenize:Fm};function Om(){return{text:{91:_m}}}function Fm(e,t,n){const r=this;return s;function s(l){return r.previous!==null||!r._gfmTasklistFirstContentOfListItem?n(l):(e.enter("taskListCheck"),e.enter("taskListCheckMarker"),e.consume(l),e.exit("taskListCheckMarker"),i)}function i(l){return ee(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 B(l)?t(l):V(l)?e.check({tokenize:zm},t,n)(l):n(l)}}function zm(e,t,n){return X(e,r,"whitespace");function r(s){return s===null?n(s):t(s)}}function Bm(e){return yo([dm(),km(),Em(e),Pm(),Om()])}const $m={};function Um(e){const t=this,n=e||$m,r=t.data(),s=r.micromarkExtensions||(r.micromarkExtensions=[]),i=r.fromMarkdownExtensions||(r.fromMarkdownExtensions=[]),o=r.toMarkdownExtensions||(r.toMarkdownExtensions=[]);s.push(Bm(n)),i.push(am()),o.push(lm(n))}function Km(){var e;return typeof navigator<"u"&&typeof((e=navigator.clipboard)==null?void 0:e.writeText)=="function"}function Hm(e){if(typeof document>"u")return;const t=document.getSelection();t&&(t.removeAllRanges(),e.forEach(n=>t.addRange(n)))}function zs(e){if(typeof document>"u"||!document.body)return!1;const t=document.activeElement instanceof HTMLElement?document.activeElement:null,n=t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement?t:null,r=n?{start:n.selectionStart,end:n.selectionEnd}:null,s=document.getSelection(),i=s?Array.from({length:s.rangeCount},(l,u)=>s.getRangeAt(u).cloneRange()):[],o=document.createElement("textarea");o.value=e,o.setAttribute("readonly",""),o.setAttribute("aria-hidden","true"),o.style.position="fixed",o.style.top="0",o.style.left="-9999px",o.style.opacity="0",o.style.pointerEvents="none",o.style.fontSize="12pt",document.body.appendChild(o);try{o.focus({preventScroll:!0})}catch{o.focus()}o.select(),o.setSelectionRange(0,o.value.length);let a=!1;try{a=typeof document.execCommand=="function"&&document.execCommand("copy")}catch{a=!1}if(o.remove(),t)try{t.focus({preventScroll:!0})}catch{t.focus()}return n&&r?n.setSelectionRange(r.start,r.end):Hm(i),a}async function Vm(e){if(!e)return!1;if(Km())try{return await navigator.clipboard.writeText(e),!0}catch{return zs(e)}return zs(e)}const qm=1300;function Wm(e){const[t,n]=C.useState(!1),r=C.useCallback(async()=>{if(!e.text)return;const s=await Vm(e.text);n(!!s)},[e.text]);return C.useEffect(()=>{if(!t||typeof window>"u")return;const s=window.setTimeout(()=>n(!1),e.resetDelayMs??qm);return()=>window.clearTimeout(s)},[t,e.resetDelayMs]),{copied:t,copy:r}}const Gm=/language-([a-z0-9-]+)/i;function aa(e){return typeof e=="string"||typeof e=="number"?String(e):Array.isArray(e)?e.map(aa).join(""):""}function Qm(e){const t=aa(e);return t.endsWith(`
31
+ `)?t.slice(0,-1):t}function Xm(e){var n;const t=e?Gm.exec(e):null;return((n=t==null?void 0:t[1])==null?void 0:n.toLowerCase())||"text"}function Ym(e){const t=C.useMemo(()=>Xm(e.className),[e.className]),n=C.useMemo(()=>Qm(e.children),[e.children]),{copied:r,copy:s}=Wm({text:n});return h.jsxs("div",{className:"chat-codeblock",children:[h.jsxs("div",{className:"chat-codeblock-toolbar",children:[h.jsx("span",{className:"chat-codeblock-language",children:t}),h.jsxs("button",{type:"button",className:"chat-codeblock-copy",onClick:()=>void s(),"aria-label":r?e.texts.copiedCodeLabel:e.texts.copyCodeLabel,children:[r?h.jsx(or,{className:"h-3.5 w-3.5"}):h.jsx(rl,{className:"h-3.5 w-3.5"}),h.jsx("span",{children:r?e.texts.copiedCodeLabel:e.texts.copyCodeLabel})]})]}),h.jsx("pre",{children:h.jsx("code",{className:e.className,children:n})})]})}const Bs=14e4,Jm=new Set(["http:","https:","mailto:","tel:"]);function Zm(e){return e.length<=Bs?e:`${e.slice(0,Bs)}
32
+
33
+ ...`}function $s(e){if(!e)return null;if(e.startsWith("#")||e.startsWith("/")||e.startsWith("./")||e.startsWith("../"))return e;try{const t=new URL(e);return Jm.has(t.protocol)?e:null}catch{return null}}function ey(e){return/^https?:\/\//i.test(e)}function ty(e){const t=e.role==="user",n=C.useMemo(()=>({a:({href:r,children:s,...i})=>{const o=$s(r);if(!o)return h.jsx("span",{className:"chat-link-invalid",children:s});const a=ey(o);return h.jsx("a",{...i,href:o,target:a?"_blank":void 0,rel:a?"noreferrer noopener":void 0,children:s})},table:({children:r,...s})=>h.jsx("div",{className:"chat-table-wrap",children:h.jsx("table",{...s,children:r})}),input:({type:r,checked:s,...i})=>r!=="checkbox"?h.jsx("input",{...i,type:r}):h.jsx("input",{...i,type:"checkbox",checked:s,readOnly:!0,disabled:!0,className:"chat-task-checkbox"}),img:({src:r,alt:s,...i})=>{const o=$s(r);return o?h.jsx("img",{...i,src:o,alt:s||"",loading:"lazy",decoding:"async"}):null},code:({className:r,children:s,...i})=>{const o=String(s??"");return!r&&!o.includes(`
34
+ `)?h.jsx("code",{...i,className:le("chat-inline-code",r),children:s}):h.jsx(Ym,{className:r,texts:e.texts,children:s})}}),[e.texts]);return h.jsx("div",{className:le("chat-markdown",t?"chat-markdown-user":"chat-markdown-assistant"),children:h.jsx(Ep,{skipHtml:!0,remarkPlugins:[Um],components:n,children:Zm(e.text)})})}function ny(e){return h.jsxs("details",{className:"mt-3",open:!0,children:[h.jsx("summary",{className:le("cursor-pointer text-xs",e.isUser?"text-primary-100":"text-gray-500"),children:e.label}),h.jsx("pre",{className:le("mt-2 whitespace-pre-wrap break-words rounded-lg p-2 text-[11px]",e.isUser?"bg-primary-700/60":"bg-gray-100"),children:e.text})]})}const Us=220;function ry(e){const t=e.toLowerCase();return t.includes("exec")||t.includes("shell")||t.includes("command")?h.jsx(sl,{className:"h-3.5 w-3.5"}):t.includes("search")?h.jsx(lr,{className:"h-3.5 w-3.5"}):t.includes("fetch")||t.includes("http")||t.includes("web")?h.jsx(il,{className:"h-3.5 w-3.5"}):t.includes("read")||t.includes("file")?h.jsx(ol,{className:"h-3.5 w-3.5"}):t.includes("message")||t.includes("send")?h.jsx(al,{className:"h-3.5 w-3.5"}):t.includes("cron")||t.includes("schedule")?h.jsx(ll,{className:"h-3.5 w-3.5"}):h.jsx(bi,{className:"h-3.5 w-3.5"})}function sy({card:e}){var i;const t=((i=e.output)==null?void 0:i.trim())??"",n=t.length>Us||t.includes(`
35
+ `),r=n?`${t.slice(0,Us)}...`:t,s=e.kind==="result"||e.hasResult;return h.jsxs("div",{className:"rounded-xl border border-amber-200/80 bg-amber-50/60 px-3 py-2.5",children:[h.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-xs font-semibold text-amber-800",children:[ry(e.toolName),h.jsx("span",{children:e.titleLabel}),h.jsx("span",{className:"font-mono text-[11px] text-amber-900/80",children:e.toolName})]}),e.summary?h.jsx("div",{className:"mt-1 break-words font-mono text-[11px] text-amber-800/90",children:e.summary}):null,s?h.jsx("div",{className:"mt-2",children:t?n?h.jsxs("details",{className:"group",children:[h.jsx("summary",{className:"cursor-pointer text-[11px] text-amber-700",children:e.outputLabel}),h.jsx("pre",{className:"mt-2 whitespace-pre-wrap break-words rounded-lg border border-amber-200 bg-amber-100/40 p-2 text-[11px] text-amber-900",children:t})]}):h.jsx("pre",{className:"rounded-lg border border-amber-200 bg-amber-100/40 p-2 text-[11px] whitespace-pre-wrap break-words text-amber-900",children:r}):h.jsx("div",{className:"text-[11px] text-amber-700/80",children:e.emptyLabel})}):null]})}function iy(e){return h.jsxs("div",{className:"rounded-lg border border-gray-200 bg-gray-50 px-2.5 py-2 text-xs text-gray-600",children:[h.jsxs("div",{className:"font-semibold text-gray-700",children:[e.label,": ",e.rawType]}),e.text?h.jsx("pre",{className:"mt-1 whitespace-pre-wrap break-words text-[11px] text-gray-500",children:e.text}):null]})}function oy(e){const{message:t,texts:n}=e,{role:r}=t,s=r==="user";return h.jsx("div",{className:le("inline-block w-fit max-w-full rounded-2xl border px-4 py-3 shadow-sm",s?"border-primary bg-primary text-white":r==="assistant"?"border-gray-200 bg-white text-gray-900":"border-orange-200/80 bg-orange-50/70 text-gray-900"),children:h.jsx("div",{className:"space-y-2",children:t.parts.map((i,o)=>i.type==="markdown"?h.jsx(ty,{text:i.text,role:r,texts:n},`markdown-${o}`):i.type==="reasoning"?h.jsx(ny,{label:i.label,text:i.text,isUser:s},`reasoning-${o}`):i.type==="tool-card"?h.jsx("div",{className:"mt-0.5",children:h.jsx(sy,{card:i.card})},`tool-${o}`):i.type==="unknown"?h.jsx(iy,{label:i.label,rawType:i.rawType,text:i.text},`unknown-${o}`):null)})})}function ay(e){return h.jsxs("div",{className:le("px-1 text-[11px] leading-4 text-gray-400",e.isUser?"text-right":"text-left"),children:[e.roleLabel," · ",e.timestampLabel]})}const ly=/\u200B|\u200C|\u200D|\u2060|\uFEFF/g;function uy(e){const t=e.trim();return t?t.replace(ly,"").trim().length>0:!1}function cy(e){return e.parts.some(t=>t.type==="markdown"||t.type==="reasoning"?uy(t.text):!0)}function dy(e){const t=e.messages.filter(cy),n=t.some(r=>r.role==="assistant"&&(r.status==="streaming"||r.status==="pending"));return h.jsxs("div",{className:le("space-y-5",e.className),children:[t.map(r=>{const s=r.role==="user";return h.jsxs("div",{className:le("flex gap-3",s?"justify-end":"justify-start"),children:[s?null:h.jsx(un,{role:r.role}),h.jsxs("div",{className:le("w-fit max-w-[92%] space-y-2",s&&"flex flex-col items-end"),children:[h.jsx(oy,{message:r,texts:e.texts}),h.jsx(ay,{roleLabel:r.roleLabel,timestampLabel:r.timestampLabel,isUser:s})]}),s?h.jsx(un,{role:r.role}):null]},r.id)}),e.isSending&&!n?h.jsxs("div",{className:"flex justify-start gap-3",children:[h.jsx(un,{role:"assistant"}),h.jsx("div",{className:"rounded-2xl border border-gray-200 bg-white px-4 py-3 text-sm text-gray-500 shadow-sm",children:e.texts.typingLabel})]}):null]})}const hy=10;function Ks(e){e.scrollTop=e.scrollHeight}function fy(e){const t=C.useRef(!0),n=C.useRef(!1),r=C.useRef(null),s=C.useRef(!1),i=C.useCallback(()=>{if(n.current){n.current=!1;return}const o=e.scrollRef.current;if(!o)return;const a=o.scrollHeight-o.scrollTop-o.clientHeight;t.current=a<=(e.stickyThresholdPx??hy)},[e.scrollRef,e.stickyThresholdPx]);return C.useEffect(()=>{r.current!==e.resetKey&&(r.current=e.resetKey,t.current=!0,s.current=!0)},[e.resetKey]),C.useLayoutEffect(()=>{if(!s.current||e.isLoading||!e.hasContent)return;const o=e.scrollRef.current;o&&(s.current=!1,n.current=!0,Ks(o))},[e.hasContent,e.isLoading,e.scrollRef]),C.useLayoutEffect(()=>{if(!t.current||!e.hasContent)return;const o=e.scrollRef.current;o&&(n.current=!0,Ks(o))},[e.contentVersion,e.hasContent,e.scrollRef]),{onScroll:i}}function Dr(){return gr()}function la(e){return Qu(e)}function ua(e){return Yu(e)}function ca(e){return mr(e,"skill")}function da(e,t,n){const r=new Set(t),s=Yi(e,l=>l.tokenKind==="skill"&&!r.has(l.tokenKey)),i=mr(s,"skill"),o=new Map(n.map(l=>[l.spec,l])),a=t.filter(l=>!i.includes(l)).map(l=>{var u;return pr({tokenKind:"skill",tokenKey:l,label:((u=o.get(l))==null?void 0:u.label)||l})});return a.length===0?s:ct([...s,...a])}const py={isProviderStateResolved:!1,composerNodes:Dr(),draft:"",pendingSessionType:"native",defaultSessionType:"native",canStopGeneration:!1,stopDisabledReason:null,sendError:null,isSending:!1,modelOptions:[],selectedModel:"",selectedThinkingLevel:null,sessionTypeOptions:[],selectedSessionType:void 0,stopSupported:!1,stopReason:void 0,canEditSessionType:!1,sessionTypeUnavailable:!1,skillRecords:[],isSkillsLoading:!1,selectedSkills:[]},K=Jt(e=>({snapshot:py,setSnapshot:t=>e(n=>({snapshot:{...n.snapshot,...t}}))})),gy={sessionRunStatusByKey:new Map,isLocallyRunning:!1,activeBackendRunId:null},Yn=Jt(e=>({snapshot:gy,setSnapshot:t=>e(n=>({snapshot:{...n.snapshot,...t}}))})),my={sessions:[],selectedSessionKey:null,selectedAgentId:"main",query:"",isLoading:!1},se=Jt(e=>({snapshot:my,setSnapshot:t=>e(n=>({snapshot:{...n.snapshot,...t}}))}));function yy(e){const t=new Date,n=new Date(t.getFullYear(),t.getMonth(),t.getDate()).getTime(),r=n-864e5,s=n-7*864e5,i=[],o=[],a=[],l=[];for(const c of e){const d=new Date(c.updatedAt).getTime();d>=n?i.push(c):d>=r?o.push(c):d>=s?a.push(c):l.push(c)}const u=[];return i.length>0&&u.push({label:R("chatSidebarToday"),sessions:i}),o.length>0&&u.push({label:R("chatSidebarYesterday"),sessions:o}),a.length>0&&u.push({label:R("chatSidebarPrevious7Days"),sessions:a}),l.length>0&&u.push({label:R("chatSidebarOlder"),sessions:l}),u}function xy(e){if(e.label&&e.label.trim())return e.label.trim();const t=e.key.split(":");return t[t.length-1]||e.key}function by(e,t){const n=e.trim().toLowerCase();if(!n||n==="native")return null;const r=t.find(s=>s.value.trim().toLowerCase()===n);return r!=null&&r.label.trim()?r.label.trim():n.split(/[-_]+/g).filter(Boolean).map(s=>s.charAt(0).toUpperCase()+s.slice(1)).join(" ")}const Sy=[{target:"/cron",label:()=>R("chatSidebarScheduledTasks"),icon:ur},{target:"/skills",label:()=>R("chatSidebarSkills"),icon:ar}];function ky(){var v,w;const e=fr(),t=Il(),[n,r]=C.useState(!1),s=K(T=>T.snapshot),i=se(T=>T.snapshot),o=Yn(T=>T.snapshot),a=Tl(T=>T.connectionStatus),{language:l,setLanguage:u}=hr(),{theme:c,setTheme:d}=Ml(),p=R(((v=zr.find(T=>T.value===c))==null?void 0:v.labelKey)??"themeWarm"),f=((w=Br.find(T=>T.value===l))==null?void 0:w.label)??l,m=C.useMemo(()=>yy(i.sessions),[i.sessions]),y=s.defaultSessionType||"native",b=C.useMemo(()=>s.sessionTypeOptions.filter(T=>T.value!==y),[y,s.sessionTypeOptions]),g=T=>{l!==T&&(u(T),window.location.reload())};return h.jsxs("aside",{className:"w-[280px] shrink-0 flex flex-col h-full bg-secondary border-r border-gray-200/60",children:[h.jsx("div",{className:"px-5 pt-5 pb-3",children:h.jsx(Rl,{className:"flex items-center gap-2.5 min-w-0",suffix:h.jsx(Cu,{status:a})})}),h.jsx("div",{className:"px-4 pb-3",children:h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsxs(et,{variant:"primary",className:Ie("min-w-0 rounded-xl",b.length>0?"flex-1 rounded-r-md":"w-full"),onClick:()=>{r(!1),e.chatSessionListManager.createSession(y)},children:[h.jsx(ul,{className:"h-4 w-4 mr-2"}),R("chatSidebarNewTask")]}),b.length>0?h.jsxs(cu,{open:n,onOpenChange:r,children:[h.jsx(du,{asChild:!0,children:h.jsx(et,{variant:"primary",size:"icon",className:"h-9 w-10 shrink-0 rounded-xl rounded-l-md","aria-label":R("chatSessionTypeLabel"),children:h.jsx(ir,{className:"h-4 w-4"})})}),h.jsxs(hu,{align:"end",className:"w-64 p-2",children:[h.jsx("div",{className:"px-2 py-1 text-[11px] font-medium uppercase tracking-wider text-gray-400",children:R("chatSessionTypeLabel")}),h.jsx("div",{className:"mt-1 space-y-1",children:b.map(T=>h.jsxs("button",{type:"button",onClick:()=>{e.chatSessionListManager.createSession(T.value),r(!1)},className:"w-full rounded-xl px-3 py-2 text-left transition-colors hover:bg-gray-100",children:[h.jsx("div",{className:"text-[13px] font-medium text-gray-900",children:T.label}),h.jsx("div",{className:"mt-0.5 text-[11px] text-gray-500",children:R("chatSidebarNewTask")})]},T.value))})]})]}):null]})}),h.jsx("div",{className:"px-4 pb-3",children:h.jsxs("div",{className:"relative",children:[h.jsx(lr,{className:"h-3.5 w-3.5 absolute left-3 top-2.5 text-gray-400"}),h.jsx(Mi,{value:i.query,onChange:T=>e.chatSessionListManager.setQuery(T.target.value),placeholder:R("chatSidebarSearchPlaceholder"),className:"pl-8 h-9 rounded-lg text-xs"})]})}),h.jsx("div",{className:"px-3 pb-2",children:h.jsx("ul",{className:"space-y-0.5",children:Sy.map(T=>{const A=T.icon;return h.jsx("li",{children:h.jsx(Fr,{to:T.target,className:({isActive:k})=>Ie("group w-full flex items-center gap-3 px-3 py-2 rounded-xl text-[13px] font-medium transition-all duration-150",k?"bg-gray-200 text-gray-900 font-semibold shadow-sm":"text-gray-600 hover:bg-gray-200/60 hover:text-gray-900"),children:({isActive:k})=>h.jsxs(h.Fragment,{children:[h.jsx(A,{className:Ie("h-4 w-4 transition-colors",k?"text-gray-900":"text-gray-500 group-hover:text-gray-800")}),h.jsx("span",{children:T.label()})]})})},T.target)})})}),h.jsx("div",{className:"mx-4 border-t border-gray-200/60"}),h.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto custom-scrollbar px-3 py-2",children:i.isLoading?h.jsx("div",{className:"text-xs text-gray-500 p-3",children:R("sessionsLoading")}):m.length===0?h.jsxs("div",{className:"p-4 text-center",children:[h.jsx(cl,{className:"h-6 w-6 mx-auto mb-2 text-gray-300"}),h.jsx("div",{className:"text-xs text-gray-500",children:R("sessionsEmpty")})]}):h.jsx("div",{className:"space-y-3",children:m.map(T=>h.jsxs("div",{children:[h.jsx("div",{className:"px-2 py-1 text-[11px] font-medium text-gray-400 uppercase tracking-wider",children:T.label}),h.jsx("div",{className:"space-y-0.5",children:T.sessions.map(A=>{const k=i.selectedSessionKey===A.key,N=o.sessionRunStatusByKey.get(A.key),F=by(A.sessionType,s.sessionTypeOptions);return h.jsxs("button",{onClick:()=>e.chatSessionListManager.selectSession(A.key),className:Ie("w-full rounded-xl px-3 py-2 text-left transition-all text-[13px]",k?"bg-gray-200 text-gray-900 font-semibold shadow-sm":"text-gray-700 hover:bg-gray-200/60 hover:text-gray-900"),children:[h.jsxs("div",{className:"grid grid-cols-[minmax(0,1fr)_0.875rem] items-center gap-1.5",children:[h.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[h.jsx("span",{className:"truncate font-medium",children:xy(A)}),F?h.jsx("span",{className:Ie("shrink-0 rounded-full border px-1.5 py-0.5 text-[10px] font-semibold leading-none",k?"border-gray-300 bg-white/80 text-gray-700":"border-gray-200 bg-gray-100 text-gray-500"),children:F}):null]}),h.jsx("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center",children:N?h.jsx(Ql,{status:N}):null})]}),h.jsxs("div",{className:"mt-0.5 text-[11px] text-gray-400 truncate",children:[A.messageCount," · ",Zt(A.updatedAt)]})]},A.key)})})]},T.label))})}),h.jsxs("div",{className:"px-3 py-3 border-t border-gray-200/60 space-y-0.5",children:[h.jsx(Fr,{to:"/settings",className:({isActive:T})=>Ie("group w-full flex items-center gap-2.5 px-3 py-2 rounded-xl text-[13px] font-medium transition-all duration-150",T?"bg-gray-200 text-gray-900 font-semibold shadow-sm":"text-gray-600 hover:bg-gray-200/60 hover:text-gray-900"),children:({isActive:T})=>h.jsxs(h.Fragment,{children:[h.jsx(dl,{className:Ie("h-4 w-4 transition-colors",T?"text-gray-900":"text-gray-500 group-hover:text-gray-800")}),h.jsx("span",{children:R("settings")})]})}),h.jsxs("button",{onClick:()=>t.open(void 0,{kind:"docs",newTab:!0,title:"Docs"}),className:"w-full flex items-center gap-2.5 px-3 py-2 rounded-xl text-[13px] font-medium transition-all duration-150 text-gray-600 hover:bg-gray-200/60 hover:text-gray-800",children:[h.jsx(hl,{className:"h-4 w-4 text-gray-400"}),h.jsx("span",{children:R("docBrowserHelp")})]}),h.jsxs(_n,{value:c,onValueChange:T=>d(T),children:[h.jsxs(On,{className:"w-full h-auto rounded-xl border-0 bg-transparent shadow-none px-3 py-2 text-[13px] font-medium text-gray-600 hover:bg-gray-200/60 focus:ring-0",children:[h.jsxs("div",{className:"flex items-center gap-2.5 min-w-0",children:[h.jsx(fl,{className:"h-4 w-4 text-gray-400"}),h.jsx("span",{children:R("theme")})]}),h.jsx("span",{className:"ml-auto text-[11px] text-gray-500",children:p})]}),h.jsx(Fn,{children:zr.map(T=>h.jsx(kt,{value:T.value,className:"text-xs",children:R(T.labelKey)},T.value))})]}),h.jsxs(_n,{value:l,onValueChange:T=>g(T),children:[h.jsxs(On,{className:"w-full h-auto rounded-xl border-0 bg-transparent shadow-none px-3 py-2 text-[13px] font-medium text-gray-600 hover:bg-gray-200/60 focus:ring-0",children:[h.jsxs("div",{className:"flex items-center gap-2.5 min-w-0",children:[h.jsx(pl,{className:"h-4 w-4 text-gray-400"}),h.jsx("span",{children:R("language")})]}),h.jsx("span",{className:"ml-auto text-[11px] text-gray-500",children:f})]}),h.jsx(Fn,{children:Br.map(T=>h.jsx(kt,{value:T.value,className:"text-xs",children:T.label},T.value))})]})]})]})}const Oe={exactSpec:1200,exactLabel:1150,prefixSpec:1e3,prefixLabel:950,prefixToken:900,containsSpec:800,containsLabel:760,containsDescription:500,subsequence:300,fallback:1};function zt(e){return(e??"").trim().toLowerCase()}function Hs(e,t){if(!e||!t)return!1;let n=0;for(const r of t)if(r===e[n]&&(n+=1,n>=e.length))return!0;return!1}function vy(e,t){const n=zt(t);if(!n)return Oe.fallback;const r=zt(e.key),s=zt(e.label||e.key),i=zt(`${e.descriptionZh??""} ${e.description??""}`),o=s.split(/[\s/_-]+/).filter(Boolean);return r===n?Oe.exactSpec:s===n?Oe.exactLabel:r.startsWith(n)?Oe.prefixSpec:s.startsWith(n)?Oe.prefixLabel:o.some(a=>a.startsWith(n))?Oe.prefixToken:r.includes(n)?Oe.containsSpec:s.includes(n)?Oe.containsLabel:i.includes(n)?Oe.containsDescription:Hs(n,s)||Hs(n,r)?Oe.subsequence:0}function wy(e,t,n){const r=new Intl.Collator(void 0,{sensitivity:"base",numeric:!0});return e.map((s,i)=>({record:s,order:i,score:vy(s,t)})).filter(s=>s.score>0).sort((s,i)=>{if(i.score!==s.score)return i.score-s.score;const o=(s.record.label||s.record.key).trim(),a=(i.record.label||i.record.key).trim(),l=r.compare(o,a);return l!==0?l:s.order-i.order}).map(({record:s})=>({key:`skill:${s.key}`,title:s.label||s.key,subtitle:n.slashSkillSubtitle,description:(s.descriptionZh??s.description??"").trim()||n.noSkillDescription,detailLines:[`${n.slashSkillSpecLabel}: ${s.key}`],value:s.key}))}function Cy(e){return e.map(t=>({key:t.key,label:t.label,description:t.descriptionZh||t.description||"",badgeLabel:t.badgeLabel}))}function Iy(e){return{title:e.texts.title,searchPlaceholder:e.texts.searchPlaceholder,emptyLabel:e.texts.emptyLabel,loadingLabel:e.texts.loadingLabel,isLoading:e.isLoading,manageLabel:e.texts.manageLabel,manageHref:"/marketplace/skills",options:Cy(e.skillRecords),selectedKeys:e.selectedSkills,onSelectedKeysChange:e.onSelectedKeysChange}}function Ty(e){return!e.isModelOptionsLoading&&!e.isModelOptionsEmpty?null:e.isModelOptionsLoading?{tone:"neutral",loading:!0}:{tone:"warning",text:e.texts.noModelOptionsLabel,actionLabel:e.texts.configureProviderLabel,onAction:e.onGoToProviders}}function My(e){const t=e.modelOptions.find(n=>n.value===e.selectedModel);return{key:"model",value:e.hasModelOptions?e.selectedModel:void 0,placeholder:e.texts.modelSelectPlaceholder,selectedLabel:t?`${t.providerLabel}/${t.modelLabel}`:void 0,icon:"sparkles",options:e.modelOptions.map(n=>({value:n.value,label:n.modelLabel,description:n.providerLabel})),disabled:!e.hasModelOptions,loading:e.isModelOptionsLoading,emptyLabel:e.texts.modelNoOptionsLabel,onValueChange:e.onValueChange}}function Ry(e){const t=[];for(const n of["off",...e])t.includes(n)||t.push(n);return t}function Ey(e){if(e.supportedLevels.length===0)return null;const t=Ry(e.supportedLevels),n=t.includes("off")?"off":t[0],r=e.selectedThinkingLevel&&t.includes(e.selectedThinkingLevel)&&e.selectedThinkingLevel||e.defaultThinkingLevel&&t.includes(e.defaultThinkingLevel)&&e.defaultThinkingLevel||n;return{key:"thinking",value:r,placeholder:e.texts.thinkingLabels[r],selectedLabel:e.texts.thinkingLabels[r],icon:"brain",options:t.map(s=>({value:s,label:e.texts.thinkingLabels[s]})),onValueChange:s=>e.onValueChange(s)}}function Ay(){return{off:R("chatThinkingLevelOff"),minimal:R("chatThinkingLevelMinimal"),low:R("chatThinkingLevelLow"),medium:R("chatThinkingLevelMedium"),high:R("chatThinkingLevelHigh"),adaptive:R("chatThinkingLevelAdaptive"),xhigh:R("chatThinkingLevelXhigh")}}function Ly(e,t){return e.map(n=>({key:n.spec,label:n.label||n.spec,description:n.description,descriptionZh:n.descriptionZh,badgeLabel:n.origin==="builtin"?t:void 0}))}function Ny(e){return e.map(t=>({value:t.value,modelLabel:t.modelLabel,providerLabel:t.providerLabel,thinkingCapability:t.thinkingCapability?{supported:t.thinkingCapability.supported,default:t.thinkingCapability.default??null}:null}))}function Py(){var A;const e=fr(),{language:t}=hr(),n=K(k=>k.snapshot),[r,s]=C.useState(null),i=C.useMemo(()=>R("chatSkillsPickerOfficial"),[t]),o=C.useMemo(()=>({slashSkillSubtitle:R("chatSlashTypeSkill"),slashSkillSpecLabel:R("chatSlashSkillSpec"),noSkillDescription:R("chatSkillsPickerNoDescription")}),[t]),a=C.useMemo(()=>Ly(n.skillRecords,i),[n.skillRecords,i]),l=C.useMemo(()=>Ny(n.modelOptions),[n.modelOptions]),u=l.length>0,c=!n.isProviderStateResolved&&!u,d=n.isProviderStateResolved&&!u,p=(c||d)&&!n.isSending||n.sessionTypeUnavailable,f=c?"":u?R("chatInputPlaceholder"):R("chatModelNoOptions"),m=C.useMemo(()=>wy(a,r??"",o),[r,a,o]),y=l.find(k=>k.value===n.selectedModel),b=y==null?void 0:y.thinkingCapability,g=(b==null?void 0:b.supported)??[],v=n.stopDisabledReason==="__preparing__"?R("chatStopPreparing"):((A=n.stopDisabledReason)==null?void 0:A.trim())||R("chatStopUnavailable"),w=[My({modelOptions:l,selectedModel:n.selectedModel,isModelOptionsLoading:c,hasModelOptions:u,onValueChange:e.chatInputManager.selectModel,texts:{modelSelectPlaceholder:R("chatSelectModel"),modelNoOptionsLabel:R("chatModelNoOptions")}}),Ey({supportedLevels:g,selectedThinkingLevel:n.selectedThinkingLevel,defaultThinkingLevel:(b==null?void 0:b.default)??null,onValueChange:k=>e.chatInputManager.selectThinkingLevel(k),texts:{thinkingLabels:Ay()}})].filter(k=>k!==null),T=Iy({skillRecords:a,selectedSkills:n.selectedSkills,isLoading:n.isSkillsLoading,onSelectedKeysChange:e.chatInputManager.selectSkills,texts:{title:R("chatSkillsPickerTitle"),searchPlaceholder:R("chatSkillsPickerSearchPlaceholder"),emptyLabel:R("chatSkillsPickerEmpty"),loadingLabel:R("sessionsLoading"),manageLabel:R("chatSkillsPickerManage")}});return h.jsx(yc,{composer:{nodes:n.composerNodes,placeholder:f,disabled:p,onNodesChange:e.chatInputManager.setComposerNodes,onSlashQueryChange:s},slashMenu:{isLoading:n.isSkillsLoading,items:m,texts:{slashLoadingLabel:R("chatSlashLoading"),slashSectionLabel:R("chatSlashSectionSkills"),slashEmptyLabel:R("chatSlashNoResult"),slashHintLabel:R("chatSlashHint"),slashSkillHintLabel:R("chatSlashSkillHint")}},hint:Ty({isModelOptionsLoading:c,isModelOptionsEmpty:d,onGoToProviders:e.chatInputManager.goToProviders,texts:{noModelOptionsLabel:R("chatModelNoOptions"),configureProviderLabel:R("chatGoConfigureProvider")}}),toolbar:{selects:w,accessories:[{key:"attach",label:R("chatInputAttach"),icon:"paperclip",iconOnly:!0,disabled:!0,tooltip:R("chatInputAttachComingSoon")}],skillPicker:T,actions:{sendError:n.sendError,isSending:n.isSending,canStopGeneration:n.canStopGeneration,sendDisabled:n.draft.trim().length===0||!u||n.sessionTypeUnavailable,stopDisabled:!n.canStopGeneration,stopHint:v,sendButtonLabel:R("chatSend"),stopButtonLabel:R("chatStop"),onSend:e.chatInputManager.send,onStop:e.chatInputManager.stop}}})}function qe(e){return typeof e=="function"}function ha(e){var t=function(r){Error.call(r),r.stack=new Error().stack},n=e(t);return n.prototype=Object.create(Error.prototype),n.prototype.constructor=n,n}var Mn=ha(function(e){return function(n){e(this),this.message=n?n.length+` errors occurred during unsubscription:
36
+ `+n.map(function(r,s){return s+1+") "+r.toString()}).join(`
37
+ `):"",this.name="UnsubscriptionError",this.errors=n}});function Jn(e,t){if(e){var n=e.indexOf(t);0<=n&&e.splice(n,1)}}var on=(function(){function e(t){this.initialTeardown=t,this.closed=!1,this._parentage=null,this._finalizers=null}return e.prototype.unsubscribe=function(){var t,n,r,s,i;if(!this.closed){this.closed=!0;var o=this._parentage;if(o)if(this._parentage=null,Array.isArray(o))try{for(var a=Pn(o),l=a.next();!l.done;l=a.next()){var u=l.value;u.remove(this)}}catch(y){t={error:y}}finally{try{l&&!l.done&&(n=a.return)&&n.call(a)}finally{if(t)throw t.error}}else o.remove(this);var c=this.initialTeardown;if(qe(c))try{c()}catch(y){i=y instanceof Mn?y.errors:[y]}var d=this._finalizers;if(d){this._finalizers=null;try{for(var p=Pn(d),f=p.next();!f.done;f=p.next()){var m=f.value;try{Vs(m)}catch(y){i=i??[],y instanceof Mn?i=jn(jn([],Dn(i)),Dn(y.errors)):i.push(y)}}}catch(y){r={error:y}}finally{try{f&&!f.done&&(s=p.return)&&s.call(p)}finally{if(r)throw r.error}}}if(i)throw new Mn(i)}},e.prototype.add=function(t){var n;if(t&&t!==this)if(this.closed)Vs(t);else{if(t instanceof e){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=(n=this._finalizers)!==null&&n!==void 0?n:[]).push(t)}},e.prototype._hasParent=function(t){var n=this._parentage;return n===t||Array.isArray(n)&&n.includes(t)},e.prototype._addParent=function(t){var n=this._parentage;this._parentage=Array.isArray(n)?(n.push(t),n):n?[n,t]:t},e.prototype._removeParent=function(t){var n=this._parentage;n===t?this._parentage=null:Array.isArray(n)&&Jn(n,t)},e.prototype.remove=function(t){var n=this._finalizers;n&&Jn(n,t),t instanceof e&&t._removeParent(this)},e.EMPTY=(function(){var t=new e;return t.closed=!0,t})(),e})(),fa=on.EMPTY;function pa(e){return e instanceof on||e&&"closed"in e&&qe(e.remove)&&qe(e.add)&&qe(e.unsubscribe)}function Vs(e){qe(e)?e():e.unsubscribe()}var jy={Promise:void 0},Dy={setTimeout:function(e,t){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];return setTimeout.apply(void 0,jn([e,t],Dn(n)))},clearTimeout:function(e){return clearTimeout(e)},delegate:void 0};function _y(e){Dy.setTimeout(function(){throw e})}function qs(){}function Vt(e){e()}var ga=(function(e){Rt(t,e);function t(n){var r=e.call(this)||this;return r.isStopped=!1,n?(r.destination=n,pa(n)&&n.add(r)):r.destination=zy,r}return t.create=function(n,r,s){return new Zn(n,r,s)},t.prototype.next=function(n){this.isStopped||this._next(n)},t.prototype.error=function(n){this.isStopped||(this.isStopped=!0,this._error(n))},t.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},t.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,e.prototype.unsubscribe.call(this),this.destination=null)},t.prototype._next=function(n){this.destination.next(n)},t.prototype._error=function(n){try{this.destination.error(n)}finally{this.unsubscribe()}},t.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},t})(on),Oy=(function(){function e(t){this.partialObserver=t}return e.prototype.next=function(t){var n=this.partialObserver;if(n.next)try{n.next(t)}catch(r){Bt(r)}},e.prototype.error=function(t){var n=this.partialObserver;if(n.error)try{n.error(t)}catch(r){Bt(r)}else Bt(t)},e.prototype.complete=function(){var t=this.partialObserver;if(t.complete)try{t.complete()}catch(n){Bt(n)}},e})(),Zn=(function(e){Rt(t,e);function t(n,r,s){var i=e.call(this)||this,o;return qe(n)||!n?o={next:n??void 0,error:r??void 0,complete:s??void 0}:o=n,i.destination=new Oy(o),i}return t})(ga);function Bt(e){_y(e)}function Fy(e){throw e}var zy={closed:!0,next:qs,error:Fy,complete:qs},By=(function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"})();function $y(e){return e}function Uy(e){return e.length===0?$y:e.length===1?e[0]:function(n){return e.reduce(function(r,s){return s(r)},n)}}var Yt=(function(){function e(t){t&&(this._subscribe=t)}return e.prototype.lift=function(t){var n=new e;return n.source=this,n.operator=t,n},e.prototype.subscribe=function(t,n,r){var s=this,i=Hy(t)?t:new Zn(t,n,r);return Vt(function(){var o=s,a=o.operator,l=o.source;i.add(a?a.call(i,l):l?s._subscribe(i):s._trySubscribe(i))}),i},e.prototype._trySubscribe=function(t){try{return this._subscribe(t)}catch(n){t.error(n)}},e.prototype.forEach=function(t,n){var r=this;return n=Ws(n),new n(function(s,i){var o=new Zn({next:function(a){try{t(a)}catch(l){i(l),o.unsubscribe()}},error:i,complete:s});r.subscribe(o)})},e.prototype._subscribe=function(t){var n;return(n=this.source)===null||n===void 0?void 0:n.subscribe(t)},e.prototype[By]=function(){return this},e.prototype.pipe=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return Uy(t)(this)},e.prototype.toPromise=function(t){var n=this;return t=Ws(t),new t(function(r,s){var i;n.subscribe(function(o){return i=o},function(o){return s(o)},function(){return r(i)})})},e.create=function(t){return new e(t)},e})();function Ws(e){var t;return(t=e??jy.Promise)!==null&&t!==void 0?t:Promise}function Ky(e){return e&&qe(e.next)&&qe(e.error)&&qe(e.complete)}function Hy(e){return e&&e instanceof ga||Ky(e)&&pa(e)}var Vy=ha(function(e){return function(){e(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}}),Ke=(function(e){Rt(t,e);function t(){var n=e.call(this)||this;return n.closed=!1,n.currentObservers=null,n.observers=[],n.isStopped=!1,n.hasError=!1,n.thrownError=null,n}return t.prototype.lift=function(n){var r=new Gs(this,this);return r.operator=n,r},t.prototype._throwIfClosed=function(){if(this.closed)throw new Vy},t.prototype.next=function(n){var r=this;Vt(function(){var s,i;if(r._throwIfClosed(),!r.isStopped){r.currentObservers||(r.currentObservers=Array.from(r.observers));try{for(var o=Pn(r.currentObservers),a=o.next();!a.done;a=o.next()){var l=a.value;l.next(n)}}catch(u){s={error:u}}finally{try{a&&!a.done&&(i=o.return)&&i.call(o)}finally{if(s)throw s.error}}}})},t.prototype.error=function(n){var r=this;Vt(function(){if(r._throwIfClosed(),!r.isStopped){r.hasError=r.isStopped=!0,r.thrownError=n;for(var s=r.observers;s.length;)s.shift().error(n)}})},t.prototype.complete=function(){var n=this;Vt(function(){if(n._throwIfClosed(),!n.isStopped){n.isStopped=!0;for(var r=n.observers;r.length;)r.shift().complete()}})},t.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(t.prototype,"observed",{get:function(){var n;return((n=this.observers)===null||n===void 0?void 0:n.length)>0},enumerable:!1,configurable:!0}),t.prototype._trySubscribe=function(n){return this._throwIfClosed(),e.prototype._trySubscribe.call(this,n)},t.prototype._subscribe=function(n){return this._throwIfClosed(),this._checkFinalizedStatuses(n),this._innerSubscribe(n)},t.prototype._innerSubscribe=function(n){var r=this,s=this,i=s.hasError,o=s.isStopped,a=s.observers;return i||o?fa:(this.currentObservers=null,a.push(n),new on(function(){r.currentObservers=null,Jn(a,n)}))},t.prototype._checkFinalizedStatuses=function(n){var r=this,s=r.hasError,i=r.thrownError,o=r.isStopped;s?n.error(i):o&&n.complete()},t.prototype.asObservable=function(){var n=new Yt;return n.source=this,n},t.create=function(n,r){return new Gs(n,r)},t})(Yt),Gs=(function(e){Rt(t,e);function t(n,r){var s=e.call(this)||this;return s.destination=n,s.source=r,s}return t.prototype.next=function(n){var r,s;(s=(r=this.destination)===null||r===void 0?void 0:r.next)===null||s===void 0||s.call(r,n)},t.prototype.error=function(n){var r,s;(s=(r=this.destination)===null||r===void 0?void 0:r.error)===null||s===void 0||s.call(r,n)},t.prototype.complete=function(){var n,r;(r=(n=this.destination)===null||n===void 0?void 0:n.complete)===null||r===void 0||r.call(n)},t.prototype._subscribe=function(n){var r,s;return(s=(r=this.source)===null||r===void 0?void 0:r.subscribe(n))!==null&&s!==void 0?s:fa},t})(Ke),ot=(function(e){Rt(t,e);function t(n){var r=e.call(this)||this;return r._value=n,r}return Object.defineProperty(t.prototype,"value",{get:function(){return this.getValue()},enumerable:!1,configurable:!0}),t.prototype._subscribe=function(n){var r=e.prototype._subscribe.call(this,n);return!r.closed&&n.next(this._value),r},t.prototype.getValue=function(){var n=this,r=n.hasError,s=n.thrownError,i=n._value;if(r)throw s;return this._throwIfClosed(),i},t.prototype.next=function(n){e.prototype.next.call(this,this._value=n)},t})(Ke);const fe=[];for(let e=0;e<256;++e)fe.push((e+256).toString(16).slice(1));function qy(e,t=0){return(fe[e[t+0]]+fe[e[t+1]]+fe[e[t+2]]+fe[e[t+3]]+"-"+fe[e[t+4]]+fe[e[t+5]]+"-"+fe[e[t+6]]+fe[e[t+7]]+"-"+fe[e[t+8]]+fe[e[t+9]]+"-"+fe[e[t+10]]+fe[e[t+11]]+fe[e[t+12]]+fe[e[t+13]]+fe[e[t+14]]+fe[e[t+15]]).toLowerCase()}let Rn;const Wy=new Uint8Array(16);function Gy(){if(!Rn){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Rn=crypto.getRandomValues.bind(crypto)}return Rn(Wy)}const Qy=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Qs={randomUUID:Qy};function er(e,t,n){var s;if(Qs.randomUUID&&!e)return Qs.randomUUID();e=e||{};const r=e.random??((s=e.rng)==null?void 0:s.call(e))??Gy();if(r.length<16)throw new Error("Random bytes length must be >= 16");return r[6]=r[6]&15|64,r[8]=r[8]&63|128,qy(r)}var oe=(e=>(e.CALL="call",e.RESULT="result",e.PARTIAL_CALL="partial-call",e.ERROR="error",e.CANCELLED="cancelled",e))(oe||{}),q=(e=>(e.TEXT_START="TEXT_START",e.TEXT_DELTA="TEXT_DELTA",e.TEXT_END="TEXT_END",e.TOOL_CALL_START="TOOL_CALL_START",e.TOOL_CALL_ARGS="TOOL_CALL_ARGS",e.TOOL_CALL_ARGS_DELTA="TOOL_CALL_ARGS_DELTA",e.TOOL_CALL_END="TOOL_CALL_END",e.TOOL_CALL_RESULT="TOOL_CALL_RESULT",e.RUN_STARTED="RUN_STARTED",e.RUN_FINISHED="RUN_FINISHED",e.RUN_ERROR="RUN_ERROR",e.RUN_METADATA="RUN_METADATA",e.REASONING_START="REASONING_START",e.REASONING_DELTA="REASONING_DELTA",e.REASONING_END="REASONING_END",e))(q||{});function Xy(e){return!e||e.remoteStopCapable&&e.remoteRunId?null:e.remoteStopCapable?"__preparing__":e.remoteStopReason??""}const Yy=e=>{try{return JSON.parse(e)}catch{return}},Xs=e=>({toolCallId:e.id,toolName:e.function.name,args:e.function.arguments,parsedArgs:Yy(e.function.arguments),status:oe.CALL});function Jy(e,t){const n={error:"tool_call_interrupted",note:"User continued before tool produced a result."};return e.map(r=>{var s;return(s=r.parts)!=null&&s.length?{...r,parts:r.parts.map(i=>{if(i.type!=="tool-invocation"||![oe.CALL,oe.PARTIAL_CALL].includes(i.toolInvocation.status))return i;let o;if(typeof i.toolInvocation.args=="string")try{o=JSON.parse(i.toolInvocation.args)}catch{return{...i,toolInvocation:{...i.toolInvocation,args:JSON.stringify({}),parsedArgs:o,status:oe.RESULT,result:{error:"invalid_args",raw:i.toolInvocation.args}}}}return{...i,toolInvocation:{...i.toolInvocation,args:i.toolInvocation.args,parsedArgs:o,status:oe.RESULT,result:n}}})}:r})}function tr(e){if(e instanceof DOMException&&e.name==="AbortError")return!0;if(e instanceof Error){if(e.name==="AbortError")return!0;const t=e.message.toLowerCase();return t.includes("aborted")||t.includes("abort")}return!1}function Ys(e){if(e instanceof Error){const n=e.message.trim();if(n)return n}return String(e??"").trim()||"Failed to send message"}function Js(e,t){return{id:`local-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,role:"assistant",parts:[{type:"text",text:e}],meta:{source:"local",status:(t==null?void 0:t.status)??"final",sessionKey:t==null?void 0:t.sessionKey,timestamp:new Date().toISOString()}}}class Zy{constructor(t){D(this,"currentMessageId");D(this,"currentReasoningMessageId");D(this,"currentReasoningContent","");D(this,"currentToolCallId");D(this,"currentToolCallMessageId");D(this,"currentToolCallName");D(this,"currentToolCallArgs","");D(this,"emittedToolCallIds",new Set);this.sessionManager=t}findAssistantMessageById(t){const n=t==null?void 0:t.trim();return n?this.sessionManager.getMessages().find(s=>s.role==="assistant"&&s.id===n)??null:null}findAssistantMessageByToolCallId(t){var r;if(!t)return null;const n=this.sessionManager.getMessages();for(let s=n.length-1;s>=0;s-=1){const i=n[s];if(i.role!=="assistant")continue;if((r=i.parts)==null?void 0:r.some(a=>a.type==="tool-invocation"&&a.toolInvocation.toolCallId===t))return i}return null}findAssistantMessageForCurrentTool(t){var r;const n=this.findAssistantMessageById(this.currentToolCallMessageId);return(r=n==null?void 0:n.parts)!=null&&r.some(s=>s.type==="tool-invocation"&&s.toolInvocation.toolCallId===t)?n:this.findAssistantMessageByToolCallId(t)}reset(){this.currentMessageId=void 0,this.currentReasoningMessageId=void 0,this.currentReasoningContent="",this.currentToolCallId=void 0,this.currentToolCallMessageId=void 0,this.currentToolCallName=void 0,this.currentToolCallArgs="",this.emittedToolCallIds.clear()}emitToolCallEvents(){const t=this.sessionManager.getMessages();for(const n of t)if(!(n.role!=="assistant"||!n.parts))for(const r of n.parts){if(r.type!=="tool-invocation")continue;const s=r.toolInvocation;s.status===oe.CALL&&!this.emittedToolCallIds.has(s.toolCallId)&&(this.emittedToolCallIds.add(s.toolCallId),this.sessionManager.toolCall$.next({toolCall:{id:s.toolCallId,type:"function",function:{name:s.toolName,arguments:s.args}}}))}}handleEvent(t){switch(t.type){case q.RUN_STARTED:break;case q.TEXT_START:this.handleTextStart(t);break;case q.TEXT_DELTA:this.handleTextContent(t);break;case q.TEXT_END:this.handleTextEnd();break;case q.REASONING_START:this.handleReasoningStart(t);break;case q.REASONING_DELTA:this.handleReasoningContent(t);break;case q.REASONING_END:this.handleReasoningEnd();break;case q.TOOL_CALL_START:this.handleToolCallStart(t);break;case q.TOOL_CALL_ARGS_DELTA:this.handleToolCallArgsDelta(t);break;case q.TOOL_CALL_ARGS:this.handleToolCallArgs(t);break;case q.TOOL_CALL_END:this.handleToolCallEnd(),this.emitToolCallEvents();break;case q.TOOL_CALL_RESULT:this.handleToolCallResult(t);break}}handleTextStart(t){this.currentMessageId=t.messageId}appendTextDelta(t,n){const r=[...t.parts||[]],s=r[r.length-1];return s&&s.type==="text"?{...t,parts:[...r.slice(0,-1),{type:"text",text:`${s.text}${n}`}]}:{...t,parts:[...r,{type:"text",text:n}]}}handleTextContent(t){if(!t.delta||this.currentMessageId!==t.messageId)return;const r=this.sessionManager.getMessages().find(s=>s.role==="assistant"&&s.id===this.currentMessageId);r?this.sessionManager.updateMessage(this.appendTextDelta(r,t.delta)):this.sessionManager.addMessages([{id:this.currentMessageId,role:"assistant",parts:[{type:"text",text:t.delta}]}])}handleTextEnd(){this.currentMessageId=void 0}updateReasoningPart(t,n){var i;const r=[...t.parts||[]];let s=-1;for(let o=r.length-1;o>=0;o-=1)if(((i=r[o])==null?void 0:i.type)==="reasoning"){s=o;break}return s>=0?{...t,parts:[...r.slice(0,s),{type:"reasoning",reasoning:n,details:[]},...r.slice(s+1)]}:{...t,parts:[...r,{type:"reasoning",reasoning:n,details:[]}]}}handleReasoningStart(t){this.currentReasoningMessageId=t.messageId,this.currentReasoningContent=""}handleReasoningContent(t){if(!t.delta||this.currentReasoningMessageId!==t.messageId)return;this.currentReasoningContent+=t.delta;const n=this.currentReasoningContent,r=this.currentReasoningMessageId,i=this.sessionManager.getMessages().find(o=>o.role==="assistant"&&o.id===r);i?this.sessionManager.updateMessage(this.updateReasoningPart(i,n)):this.sessionManager.addMessages([{id:r,role:"assistant",parts:[{type:"reasoning",reasoning:n,details:[]}]}])}handleReasoningEnd(){this.currentReasoningMessageId=void 0,this.currentReasoningContent=""}handleToolCallStart(t){var l;this.currentToolCallId=t.toolCallId,this.currentToolCallName=t.toolName,this.currentToolCallArgs="",this.currentToolCallMessageId=t.messageId;const n={type:"tool-invocation",toolInvocation:{status:oe.PARTIAL_CALL,toolCallId:this.currentToolCallId,toolName:this.currentToolCallName,args:""}},r=this.sessionManager.getMessages(),s=(l=t.messageId)==null?void 0:l.trim(),i=this.findAssistantMessageById(s);if(i){this.currentToolCallMessageId=i.id;const u=i.parts.find(c=>c.type==="tool-invocation"&&c.toolInvocation.toolCallId===this.currentToolCallId);if(u&&u.type==="tool-invocation"){this.currentToolCallArgs=u.toolInvocation.args;return}this.sessionManager.updateMessage({...i,parts:[...i.parts||[],n]});return}if(s){this.currentToolCallMessageId=s,this.sessionManager.addMessages([{id:s,role:"assistant",parts:[n]}]);return}const o=this.findAssistantMessageByToolCallId(this.currentToolCallId);if(o){this.currentToolCallMessageId=o.id;const u=o.parts.find(c=>c.type==="tool-invocation"&&c.toolInvocation.toolCallId===this.currentToolCallId);this.currentToolCallArgs=(u==null?void 0:u.type)==="tool-invocation"?u.toolInvocation.args:"";return}const a=r[r.length-1];if(a&&a.role==="assistant")this.currentToolCallMessageId=a.id,this.sessionManager.updateMessage({...a,parts:[...a.parts||[],n]});else{const u=er();this.currentToolCallMessageId=u,this.sessionManager.addMessages([{id:u,role:"assistant",parts:[n]}])}}handleToolCallArgsDelta(t){var s;if(this.currentToolCallId!==t.toolCallId)return;this.currentToolCallArgs+=t.argsDelta;const n=this.findAssistantMessageForCurrentTool(t.toolCallId);if(!n||n.role!=="assistant"||!((s=n.parts)!=null&&s.length))return;const r=[...n.parts];for(let i=r.length-1;i>=0;i--){const o=r[i];if(o.type==="tool-invocation"&&o.toolInvocation.toolCallId===t.toolCallId){let a;try{a=JSON.parse(this.currentToolCallArgs)}catch{}r[i]={...o,toolInvocation:{...o.toolInvocation,status:oe.PARTIAL_CALL,args:this.currentToolCallArgs,parsedArgs:a}};break}}this.sessionManager.updateMessage({...n,parts:r})}handleToolCallArgs(t){this.currentToolCallId===t.toolCallId&&(this.currentToolCallArgs=t.args,this.handleToolCallArgsDelta({type:q.TOOL_CALL_ARGS_DELTA,toolCallId:t.toolCallId,argsDelta:""}))}handleToolCallEnd(){var t;if(!(!this.currentToolCallId||!this.currentToolCallName)){try{const n={id:this.currentToolCallId,type:"function",function:{name:this.currentToolCallName,arguments:this.currentToolCallArgs}},r=this.findAssistantMessageForCurrentTool(this.currentToolCallId);if(r&&r.role==="assistant"){const s=[...r.parts||[]];for(let i=s.length-1;i>=0;i--){const o=s[i];if(o.type==="tool-invocation"&&o.toolInvocation.toolCallId===this.currentToolCallId){s[i]={...o,toolInvocation:{...Xs(n),status:oe.CALL}};break}}this.sessionManager.updateMessage({...r,parts:s})}else{const s=((t=this.currentToolCallMessageId)==null?void 0:t.trim())||er();this.sessionManager.addMessages([{id:s,role:"assistant",parts:[{type:"tool-invocation",toolInvocation:{...Xs(n),status:oe.CALL}}]}])}}catch{}this.currentToolCallId=void 0,this.currentToolCallMessageId=void 0,this.currentToolCallName=void 0,this.currentToolCallArgs=""}}handleToolCallResult(t){this.sessionManager.addToolResult({toolCallId:t.toolCallId,result:t.content,status:oe.RESULT})}}class ex{constructor(){D(this,"disposables",[]);D(this,"addDisposable",t=>{this.disposables.push(t)});D(this,"dispose",()=>{this.disposables.forEach(t=>t()),this.disposables=[]})}}class tx extends ex{constructor(n=null,r){super();D(this,"_messages$",new ot([]));D(this,"messages$");D(this,"threadId$",new ot(null));D(this,"isAgentResponding$",new ot(!1));D(this,"activeRun$",new ot(null));D(this,"lastError$",new ot(null));D(this,"isAwaitingResponse$",new ot(!1));D(this,"runCompleted$",new Ke);D(this,"runError$",new Ke);D(this,"runMetadata$",new Ke);D(this,"activeSubscription",null);D(this,"addMessagesEvent$",new Ke);D(this,"updateMessageEvent$",new Ke);D(this,"setMessagesEvent$",new Ke);D(this,"toolCall$",new Ke);D(this,"eventHandler",new Zy(this));D(this,"runIdCounter",0);D(this,"metadataParsers");D(this,"callbacks");D(this,"getMessages",()=>this._messages$.getValue());D(this,"setMessages",n=>{this._messages$.next(n),this.setMessagesEvent$.next({messages:n})});D(this,"handleEvent",n=>{this.eventHandler.handleEvent(n)});D(this,"setCallbacks",n=>{this.callbacks=n});D(this,"reset",()=>{this.abortAgentRun(),this._messages$.next([]),this.eventHandler.reset(),this.threadId$.next(null),this.isAgentResponding$.next(!1),this.activeRun$.next(null),this.lastError$.next(null),this.isAwaitingResponse$.next(!1),this.runIdCounter+=1});D(this,"addMessages",n=>{const s=[...this.getMessages()];for(const i of n){const o=s.findIndex(a=>a.id===i.id);o>=0?s[o]=i:s.push(i)}this._messages$.next(s),this.addMessagesEvent$.next({messages:n}),this.isAwaitingResponse$.getValue()&&n.some(i=>i.role==="assistant")&&this.isAwaitingResponse$.next(!1)});D(this,"removeMessages",n=>{n.length!==0&&this._messages$.next(this.getMessages().filter(r=>!n.includes(r.id)))});D(this,"updateMessage",n=>{this._messages$.next(this.getMessages().map(r=>r.id===n.id?n:r)),this.updateMessageEvent$.next({message:n}),this.isAwaitingResponse$.getValue()&&n.role==="assistant"&&this.isAwaitingResponse$.next(!1)});D(this,"addToolResult",(n,r)=>{const s=this.getMessages().find(o=>o.parts.find(a=>a.type==="tool-invocation"&&a.toolInvocation.toolCallId===n.toolCallId));if(!s)return;const i={...s,parts:s.parts.map(o=>o.type==="tool-invocation"&&o.toolInvocation.toolCallId===n.toolCallId?{...o,toolInvocation:{...o.toolInvocation,result:n.result??void 0,status:n.status,error:n.error??void 0,cancelled:n.cancelled??void 0}}:o)};this.updateMessage(i)});D(this,"send",async n=>{(this.activeRun$.getValue()||this.activeSubscription)&&this.abortAgentRun(),this.lastError$.next(null);const r=n.message.trim();r&&(this.addMessages([{id:er(),role:"user",parts:[{type:"text",text:r}]}]),await this.runAgent({metadata:n.metadata,sessionId:n.sessionId,agentId:n.agentId,stopCapable:n.stopCapable,stopReason:n.stopReason,sourceMessage:r,restoreDraftOnError:n.restoreDraftOnError}))});D(this,"resume",async n=>{var o,a;const r=(o=n.remoteRunId)==null?void 0:o.trim(),s=(a=n.sessionId)==null?void 0:a.trim();if(!r)return;const i=this.activeRun$.getValue();(i==null?void 0:i.remoteRunId)!==r&&(i||(this.lastError$.next(null),await this.runAgent({metadata:n.metadata,sessionId:s,agentId:n.agentId,stopCapable:n.stopCapable,stopReason:n.stopReason})))});D(this,"stop",async()=>{var s,i;const n=this.activeRun$.getValue();if(!n)return;const r=n.sessionId;this.abortAgentRun(),r&&await((i=(s=this.callbacks).onRunSettled)==null?void 0:i.call(s,{sourceSessionId:r}))});D(this,"handleAgentResponse",n=>{this.activeSubscription&&this.activeSubscription.unsubscribe(),this.activeSubscription=n.subscribe(r=>{var s,i,o,a,l,u,c,d,p;if(r.type===q.RUN_METADATA){const f=r,m=this.activeRun$.getValue(),y=((s=f.runId)==null?void 0:s.trim())||(m?`ui-${m.localRunId}`:"");this.metadataParsers&&m&&this.isMatchingRun(m,y)&&this.processRunMetadata(m,f.metadata),this.runMetadata$.next({runId:y,metadata:f.metadata});return}if(this.handleEvent(r),r.type===q.RUN_FINISHED){this.isAgentResponding$.next(!1),this.isAwaitingResponse$.next(!1),this.activeSubscription=null;const f=this.activeRun$.getValue(),m=((i=r.runId)==null?void 0:i.trim())||(f?`ui-${f.localRunId}`:"");if(!f||!this.isMatchingRun(f,m))return;const y=f.sessionId;this.activeRun$.next(null),y&&((a=(o=this.callbacks).onRunSettled)==null||a.call(o,{sourceSessionId:y}))}else if(r.type===q.RUN_ERROR){this.isAgentResponding$.next(!1),this.isAwaitingResponse$.next(!1),this.activeSubscription=null;const f=this.activeRun$.getValue(),m=((l=r.runId)==null?void 0:l.trim())||(f?`ui-${f.localRunId}`:""),y=tr(r.error);if(this.runError$.next({runId:m,error:r.error,isAbort:y}),!f||!this.isMatchingRun(f,m)){this.activeRun$.next(null);return}const b=f.sessionId;if(y){this.activeRun$.next(null),b&&((c=(u=this.callbacks).onRunSettled)==null||c.call(u,{sourceSessionId:b}));return}const g=Ys(r.error);this.lastError$.next(g),this.activeRun$.next(null),b&&this.addMessages([Js(g,{sessionKey:b,status:"error"})]),(p=(d=this.callbacks).onRunError)==null||p.call(d,{error:g,sourceMessage:f.sourceMessage,restoreDraft:f.restoreDraftOnError})}})});D(this,"abortAgentRun",()=>{var n,r,s;(s=(n=this.agentProvider)==null?void 0:(r=n.agent).abortRun)==null||s.call(r),this.activeSubscription&&(this.activeSubscription.unsubscribe(),this.activeSubscription=null,this.isAgentResponding$.next(!1),this.isAwaitingResponse$.next(!1)),this.activeRun$.next(null)});D(this,"runAgent",async n=>{var o,a,l,u;if(!this.agentProvider)return;(this.activeRun$.getValue()||this.activeSubscription)&&this.abortAgentRun();const r=++this.runIdCounter,s=`ui-${r}`,i={localRunId:r,sessionId:n==null?void 0:n.sessionId,...n!=null&&n.agentId?{agentId:n.agentId}:{},remoteStopCapable:!!(n!=null&&n.stopCapable),...n!=null&&n.stopReason?{remoteStopReason:n.stopReason}:{},sourceMessage:n==null?void 0:n.sourceMessage,restoreDraftOnError:n==null?void 0:n.restoreDraftOnError};this.activeRun$.next(i),this.isAgentResponding$.next(!0),this.isAwaitingResponse$.next(!0);try{const c=Jy(this.getMessages()),d=typeof(n==null?void 0:n.threadId)=="string"&&n.threadId.trim()?n.threadId:this.threadId$.getValue()??"",p=await this.agentProvider.agent.run({threadId:d,runId:s,messages:c,tools:this.agentProvider.getToolDefs(),context:this.agentProvider.getContexts(),...n!=null&&n.metadata?{metadata:n.metadata}:{}});this.handleAgentResponse(p)}catch(c){const d=tr(c);d?console.info("Agent run aborted"):console.error("Error running agent:",c),this.isAgentResponding$.next(!1),this.isAwaitingResponse$.next(!1);const p=this.activeRun$.getValue();if(this.activeRun$.next(null),this.runError$.next({runId:s,error:c,isAbort:d}),!d&&p){const f=Ys(c);this.lastError$.next(f),p.sessionId&&this.addMessages([Js(f,{sessionKey:p.sessionId,status:"error"})]),(a=(o=this.callbacks).onRunError)==null||a.call(o,{error:f,sourceMessage:p.sourceMessage,restoreDraft:p.restoreDraftOnError})}else d&&(p!=null&&p.sessionId)&&((u=(l=this.callbacks).onRunSettled)==null||u.call(l,{sourceSessionId:p.sessionId}))}});D(this,"processRunMetadata",(n,r)=>{if(!this.metadataParsers)return;const s=this.metadataParsers.parseReady(r);if(s){this.applyReadyMetadata(n,s);return}const i=this.metadataParsers.parseFinal(r);i&&this.applyFinalMetadata(n,i)});D(this,"applyReadyMetadata",(n,r)=>{var i,o,a,l,u;const s={...n};(i=r.remoteRunId)!=null&&i.trim()&&(s.remoteRunId=r.remoteRunId.trim()),typeof r.stopCapable=="boolean"&&(s.remoteStopCapable=r.stopCapable),(o=r.stopReason)!=null&&o.trim()&&(s.remoteStopReason=r.stopReason.trim()),(a=r.sessionId)!=null&&a.trim()&&(s.sessionId=r.sessionId.trim(),(u=(l=this.callbacks).onSessionChanged)==null||u.call(l,s.sessionId)),this.activeRun$.next(s)});D(this,"applyFinalMetadata",(n,r)=>{var o,a,l,u;const s=n.sessionId,i=r.sessionId;i&&i!==s&&((a=(o=this.callbacks).onSessionChanged)==null||a.call(o,i)),this.activeRun$.next(null),s&&((u=(l=this.callbacks).onRunSettled)==null||u.call(l,{sourceSessionId:s,resultSessionId:i}))});D(this,"isMatchingRun",(n,r)=>r.trim()?r===`ui-${n.localRunId}`:!1);D(this,"connectToolExecutor",()=>{const n=this.toolCall$.subscribe(async({toolCall:r})=>{var i;const s=(i=this.agentProvider)==null?void 0:i.getToolExecutor(r.function.name);if(s)try{const o=JSON.parse(r.function.arguments),a=await s(o);this.addToolResult({toolCallId:r.id,result:a,status:oe.RESULT}),this.runAgent()}catch(o){console.error("[AgentChatController] handleAddToolResult error",o),this.addToolResult({toolCallId:r.id,error:o instanceof Error?o.message:String(o),status:oe.ERROR}),this.runAgent()}});return()=>n.unsubscribe()});this.agentProvider=n;const{initialMessages:s=[],metadataParsers:i,callbacks:o={}}=r||{};this.metadataParsers=i??null,this.callbacks=o,this._messages$.next(s),this.messages$=this._messages$.asObservable(),this.agentProvider&&this.addDisposable(this.connectToolExecutor())}}const nx=/\u200B|\u200C|\u200D|\u2060|\uFEFF/g;function rx(e){return typeof e=="object"&&e!==null}function sx(e){return e.type==="text"&&typeof e.text=="string"}function ix(e){return e.type==="reasoning"&&typeof e.reasoning=="string"}function ox(e){return e.type!=="tool-invocation"||!rx(e.toolInvocation)?!1:typeof e.toolInvocation.toolName=="string"}function ax(e){var n;const t=(n=e.meta)==null?void 0:n.timestamp;return t&&Number.isFinite(Date.parse(t))?t:new Date().toISOString()}function lx(e,t){return e==="user"?t.user:e==="assistant"?t.assistant:e==="tool"?t.tool:e==="system"?t.system:t.fallback}function ux(e){return e==="user"||e==="assistant"||e==="tool"||e==="system"?e:"message"}function cx(e,t){return{kind:e.kind,toolName:e.name,summary:e.detail,output:e.text,hasResult:!!e.hasResult,titleLabel:e.kind==="call"?t.toolCallLabel:t.toolResultLabel,outputLabel:t.toolOutputLabel,emptyLabel:t.toolNoOutputLabel}}function Zs(e){const t=e.trim();return t&&t.replace(nx,"").trim()?t:null}function dx(e){return e.uiMessages.map(t=>{var n;return{id:t.id,role:ux(t.role),roleLabel:lx(t.role,e.texts.roleLabels),timestampLabel:e.formatTimestamp(ax(t)),status:(n=t.meta)==null?void 0:n.status,parts:t.parts.map(r=>{if(sx(r)){const s=Zs(r.text);return s?{type:"markdown",text:s}:null}if(ix(r)){const s=Zs(r.reasoning);return s?{type:"reasoning",text:s,label:e.texts.reasoningLabel}:null}if(ox(r)){const s=r.toolInvocation,i=Xl(s.parsedArgs??s.args),o=typeof s.error=="string"&&s.error.trim()?s.error.trim():s.result!=null?Ur(s.result).trim():"",a=s.status==="result"||s.status==="error"||s.status==="cancelled",l={kind:a?"result":"call",name:s.toolName,detail:i,text:o||void 0,callId:s.toolCallId||void 0,hasResult:a};return{type:"tool-card",card:cx(l,e.texts)}}return{type:"unknown",label:e.texts.unknownPartLabel,rawType:typeof r.type=="string"?r.type:"unknown",text:Ur(r)}}).filter(r=>r!==null)}})}function hx(e){const{language:t}=hr(),n=C.useMemo(()=>e.uiMessages.map(s=>{var i,o;return{id:s.id,role:s.role,meta:{timestamp:(i=s.meta)==null?void 0:i.timestamp,status:(o=s.meta)==null?void 0:o.status},parts:s.parts}}),[e.uiMessages]),r=C.useMemo(()=>dx({uiMessages:n,formatTimestamp:s=>Zt(s,t),texts:{roleLabels:{user:R("chatRoleUser"),assistant:R("chatRoleAssistant"),tool:R("chatRoleTool"),system:R("chatRoleSystem"),fallback:R("chatRoleMessage")},reasoningLabel:R("chatReasoning"),toolCallLabel:R("chatToolCall"),toolResultLabel:R("chatToolResult"),toolNoOutputLabel:R("chatToolNoOutput"),toolOutputLabel:R("chatToolOutput"),unknownPartLabel:R("chatUnknownPart")}}),[t,n]);return h.jsx(dy,{messages:r,isSending:e.isSending,hasAssistantDraft:e.uiMessages.some(s=>{var i,o;return s.role==="assistant"&&(((i=s.meta)==null?void 0:i.status)==="streaming"||((o=s.meta)==null?void 0:o.status)==="pending")}),className:e.className,texts:{copyCodeLabel:R("chatCodeCopy"),copiedCodeLabel:R("chatCodeCopied"),typingLabel:R("chatTyping")}})}const fx=[{icon:gl,titleKey:"chatWelcomeCapability1Title",descKey:"chatWelcomeCapability1Desc"},{icon:ar,titleKey:"chatWelcomeCapability2Title",descKey:"chatWelcomeCapability2Desc"},{icon:ur,titleKey:"chatWelcomeCapability3Title",descKey:"chatWelcomeCapability3Desc"}];function px({onCreateSession:e}){return h.jsx("div",{className:"h-full flex items-center justify-center p-8",children:h.jsxs("div",{className:"max-w-lg w-full text-center",children:[h.jsx("div",{className:"mx-auto mb-6 h-16 w-16 rounded-2xl bg-primary/10 flex items-center justify-center",children:h.jsx(Si,{className:"h-8 w-8 text-primary"})}),h.jsx("h2",{className:"text-xl font-semibold text-gray-900 mb-2",children:R("chatWelcomeTitle")}),h.jsx("p",{className:"text-sm text-gray-500 mb-8",children:R("chatWelcomeSubtitle")}),h.jsx("div",{className:"grid grid-cols-3 gap-3",children:fx.map(t=>{const n=t.icon;return h.jsxs("button",{onClick:e,className:"rounded-2xl border border-gray-200 bg-white p-4 text-left shadow-card hover:shadow-card-hover transition-shadow cursor-pointer",children:[h.jsx("div",{className:"h-9 w-9 rounded-xl bg-primary/8 flex items-center justify-center mb-3",children:h.jsx(n,{className:"h-4.5 w-4.5 text-primary"})}),h.jsx("div",{className:"text-sm font-semibold text-gray-900 mb-1",children:R(t.titleKey)}),h.jsx("div",{className:"text-[11px] text-gray-500 leading-relaxed",children:R(t.descKey)})]},t.titleKey)})})]})})}const gx={isProviderStateResolved:!1,modelOptions:[],sessionTypeUnavailable:!1,sessionTypeUnavailableMessage:null,sessionTypeLabel:null,selectedSessionKey:null,sessionDisplayName:void 0,canDeleteSession:!1,isDeletePending:!1,threadRef:null,isHistoryLoading:!1,uiMessages:[],isSending:!1,isAwaitingAssistantOutput:!1},Ve=Jt(e=>({snapshot:gx,setSnapshot:t=>e(n=>({snapshot:{...n.snapshot,...t}}))}));function mx(){return h.jsxs("section",{className:"flex-1 min-h-0 flex flex-col overflow-hidden bg-gradient-to-b from-gray-50/60 to-white",children:[h.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto custom-scrollbar",children:h.jsx("div",{className:"mx-auto w-full max-w-[min(1120px,100%)] px-6 py-5",children:h.jsxs("div",{className:"space-y-4",children:[h.jsx("div",{className:"h-6 w-48 animate-pulse rounded bg-gray-200"}),h.jsx("div",{className:"h-24 w-[78%] animate-pulse rounded-2xl bg-gray-200/80"}),h.jsx("div",{className:"h-20 w-[62%] animate-pulse rounded-2xl bg-gray-200/80"}),h.jsx("div",{className:"h-28 w-[84%] animate-pulse rounded-2xl bg-gray-200/80"})]})})}),h.jsx("div",{className:"border-t border-gray-200/80 bg-white p-4",children:h.jsx("div",{className:"mx-auto w-full max-w-[min(1120px,100%)]",children:h.jsxs("div",{className:"rounded-2xl border border-gray-200 bg-white shadow-card p-4",children:[h.jsx("div",{className:"h-16 w-full animate-pulse rounded-xl bg-gray-200/80"}),h.jsxs("div",{className:"mt-3 flex items-center justify-between",children:[h.jsx("div",{className:"h-8 w-36 animate-pulse rounded-lg bg-gray-200/80"}),h.jsx("div",{className:"h-8 w-20 animate-pulse rounded-lg bg-gray-200/80"})]})]})})})]})}function yx(){var d;const e=fr(),t=Ve(p=>p.snapshot),n=C.useRef(null),r=t.threadRef??n,s=!!(t.selectedSessionKey||t.sessionTypeLabel),i=t.sessionDisplayName||t.selectedSessionKey||R("chatSidebarNewTask"),o=!t.selectedSessionKey&&t.uiMessages.length===0&&!t.isSending,a=t.modelOptions.length>0,l=t.isProviderStateResolved&&!a,u=t.isHistoryLoading&&t.uiMessages.length===0&&!t.isSending&&!t.isAwaitingAssistantOutput,{onScroll:c}=fy({scrollRef:r,resetKey:t.selectedSessionKey,isLoading:t.isHistoryLoading,hasContent:t.uiMessages.length>0,contentVersion:t.uiMessages});return t.isProviderStateResolved?h.jsxs("section",{className:"flex-1 min-h-0 flex flex-col overflow-hidden bg-gradient-to-b from-gray-50/60 to-white",children:[h.jsxs("div",{className:Ie("px-5 border-b border-gray-200/60 bg-white/80 backdrop-blur-sm flex items-center justify-between shrink-0 overflow-hidden transition-all duration-200",s?"py-3 opacity-100":"h-0 py-0 opacity-0 border-b-0"),children:[h.jsxs("div",{className:"min-w-0 flex-1 flex items-center gap-2",children:[h.jsx("span",{className:"text-sm font-medium text-gray-700 truncate",children:i}),t.sessionTypeLabel?h.jsx("span",{className:"shrink-0 rounded-full border border-gray-200 bg-gray-100 px-2 py-0.5 text-[11px] font-medium text-gray-600",children:t.sessionTypeLabel}):null]}),t.selectedSessionKey?h.jsx(et,{variant:"ghost",size:"icon",className:"rounded-lg shrink-0 text-gray-400 hover:text-destructive",onClick:e.chatThreadManager.deleteSession,disabled:!t.canDeleteSession||t.isDeletePending,children:h.jsx(vi,{className:"h-4 w-4"})}):null]}),l&&h.jsxs("div",{className:"px-5 py-2.5 border-b border-amber-200/70 bg-amber-50/70 flex items-center justify-between gap-3 shrink-0",children:[h.jsx("span",{className:"text-xs text-amber-800",children:R("chatModelNoOptions")}),h.jsx("button",{type:"button",onClick:e.chatThreadManager.goToProviders,className:"text-xs font-semibold text-amber-900 underline-offset-2 hover:underline",children:R("chatGoConfigureProvider")})]}),t.sessionTypeUnavailable&&((d=t.sessionTypeUnavailableMessage)==null?void 0:d.trim())&&h.jsx("div",{className:"px-5 py-2.5 border-b border-amber-200/70 bg-amber-50/70 shrink-0",children:h.jsx("span",{className:"text-xs text-amber-800",children:t.sessionTypeUnavailableMessage})}),h.jsx("div",{ref:r,onScroll:c,className:"flex-1 min-h-0 overflow-y-auto custom-scrollbar",children:o?h.jsx(px,{onCreateSession:e.chatThreadManager.createSession}):u?h.jsx("div",{className:"h-full"}):t.uiMessages.length===0?h.jsx("div",{className:"px-5 py-5 text-sm text-gray-500",children:R("chatNoMessages")}):h.jsx("div",{className:"mx-auto w-full max-w-[min(1120px,100%)] px-6 py-5",children:h.jsx(hx,{uiMessages:t.uiMessages,isSending:t.isSending&&t.isAwaitingAssistantOutput})})}),h.jsx(Py,{})]}):h.jsx(mx,{})}function ei(e){return Zt(e??void 0)}function xx(e){return typeof e!="number"||!Number.isFinite(e)?"-":Zt(new Date(e))}function bx(e){if(typeof e!="number"||!Number.isFinite(e))return"-";const t=Math.round(e/1e3);if(t<60)return`${t}s`;const n=Math.round(t/60);if(n<60)return`${n}m`;const r=Math.round(n/60);return r<24?`${r}h`:`${Math.round(r/24)}d`}function Sx(e){const t=e.schedule;return t.kind==="cron"?t.expr?`cron ${t.expr}`:"cron":t.kind==="every"?`every ${bx(t.everyMs)}`:t.kind==="at"?`at ${xx(t.atMs)}`:"-"}function kx(e){if(!e.payload.deliver)return"-";const t=e.payload.channel??"-",n=e.payload.to??"-";return`${t}:${n}`}function vx(e,t){const n=t.trim().toLowerCase();return n?[e.id,e.name,e.payload.message,e.payload.channel??"",e.payload.to??""].join(" ").toLowerCase().includes(n):!0}function wx(e,t){return t==="all"?!0:t==="enabled"?e.enabled:!e.enabled}function Cx(){var m;const[e,t]=C.useState(""),[n,r]=C.useState("all"),s=El({all:!0}),i=Al(),o=Ll(),a=Nl(),{confirm:l,ConfirmDialog:u}=dr(),c=C.useMemo(()=>{var b;return(((b=s.data)==null?void 0:b.jobs)??[]).filter(g=>vx(g,e)).filter(g=>wx(g,n))},[s.data,e,n]),d=async y=>{await l({title:`${R("cronDeleteConfirm")}?`,description:y.name?`${y.name} (${y.id})`:y.id,variant:"destructive",confirmLabel:R("delete")})&&i.mutate({id:y.id})},p=async y=>{const b=!y.enabled;await l({title:b?`${R("cronEnableConfirm")}?`:`${R("cronDisableConfirm")}?`,description:y.name?`${y.name} (${y.id})`:y.id,variant:b?"default":"destructive",confirmLabel:b?R("cronEnable"):R("cronDisable")})&&o.mutate({id:y.id,enabled:b})},f=async y=>{const b=!y.enabled;await l({title:b?`${R("cronRunForceConfirm")}?`:`${R("cronRunConfirm")}?`,description:y.name?`${y.name} (${y.id})`:y.id,confirmLabel:R("cronRunNow")})&&a.mutate({id:y.id,force:b})};return h.jsxs(fu,{fullHeight:!0,children:[h.jsx(pu,{title:R("cronPageTitle"),description:R("cronPageDescription"),actions:h.jsx(et,{variant:"ghost",size:"icon",className:"h-9 w-9 rounded-lg text-gray-400 hover:text-gray-700 hover:bg-gray-100",onClick:()=>s.refetch(),children:h.jsx(ml,{className:Ie("h-4 w-4",s.isFetching&&"animate-spin")})})}),h.jsx("div",{className:"mb-6",children:h.jsxs("div",{className:"flex flex-wrap gap-3 items-center",children:[h.jsxs("div",{className:"relative flex-1 min-w-[240px]",children:[h.jsx(Mi,{value:e,onChange:y=>t(y.target.value),placeholder:R("cronSearchPlaceholder"),className:"pl-9"}),h.jsx(ur,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-gray-400"})]}),h.jsx("div",{className:"min-w-[180px]",children:h.jsxs(_n,{value:n,onValueChange:y=>r(y),children:[h.jsx(On,{className:"w-full",children:h.jsx(Pl,{placeholder:R("cronStatusLabel")})}),h.jsxs(Fn,{children:[h.jsx(kt,{value:"all",children:R("cronStatusAll")}),h.jsx(kt,{value:"enabled",children:R("cronStatusEnabled")}),h.jsx(kt,{value:"disabled",children:R("cronStatusDisabled")})]})]})}),h.jsxs("div",{className:"text-xs text-gray-500 ml-auto",children:[R("cronTotalLabel"),": ",((m=s.data)==null?void 0:m.total)??0," / ",c.length]})]})}),h.jsx("div",{className:"flex-1 overflow-auto custom-scrollbar",children:s.isLoading?h.jsx("div",{className:"text-sm text-gray-400 p-4 text-center",children:R("cronLoading")}):c.length===0?h.jsx("div",{className:"text-sm text-gray-400 p-4 text-center",children:R("cronEmpty")}):h.jsx("div",{className:"space-y-4",children:c.map(y=>h.jsx(jl,{className:"border border-gray-200",children:h.jsx(Dl,{className:"pt-5 pb-5",children:h.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-4",children:[h.jsxs("div",{className:"min-w-[220px] flex-1",children:[h.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[h.jsx("span",{className:"text-sm font-semibold text-gray-900",children:y.name||y.id}),h.jsx("span",{className:"text-[10px] font-semibold px-2 py-0.5 rounded-full bg-gray-100 text-gray-500",children:y.id}),h.jsx("span",{className:Ie("text-[10px] font-semibold px-2 py-0.5 rounded-full",y.enabled?"bg-emerald-50 text-emerald-700":"bg-gray-100 text-gray-500"),children:y.enabled?R("enabled"):R("disabled")}),y.deleteAfterRun&&h.jsx("span",{className:"text-[10px] font-semibold px-2 py-0.5 rounded-full bg-amber-50 text-amber-700",children:R("cronOneShot")})]}),h.jsxs("div",{className:"mt-2 text-xs text-gray-500",children:[R("cronScheduleLabel"),": ",Sx(y)]}),h.jsx("div",{className:"mt-2 text-sm text-gray-700 whitespace-pre-wrap break-words",children:y.payload.message}),h.jsxs("div",{className:"mt-2 text-xs text-gray-500",children:[R("cronDeliverTo"),": ",kx(y)]})]}),h.jsxs("div",{className:"min-w-[220px] text-xs text-gray-500 space-y-2",children:[h.jsxs("div",{children:[h.jsxs("span",{className:"font-medium text-gray-700",children:[R("cronNextRun"),":"]})," ",ei(y.state.nextRunAt)]}),h.jsxs("div",{children:[h.jsxs("span",{className:"font-medium text-gray-700",children:[R("cronLastRun"),":"]})," ",ei(y.state.lastRunAt)]}),h.jsxs("div",{children:[h.jsxs("span",{className:"font-medium text-gray-700",children:[R("cronLastStatus"),":"]})," ",y.state.lastStatus??"-"]}),y.state.lastError&&h.jsx("div",{className:"text-[11px] text-red-500 break-words",children:y.state.lastError})]}),h.jsxs("div",{className:"flex items-start gap-2 flex-wrap justify-end",children:[h.jsxs(et,{variant:"subtle",size:"sm",onClick:()=>f(y),className:"gap-1",children:[h.jsx(yl,{className:"h-3.5 w-3.5"}),R("cronRunNow")]}),h.jsxs(et,{variant:y.enabled?"outline":"primary",size:"sm",onClick:()=>p(y),className:"gap-1",children:[h.jsx(xl,{className:"h-3.5 w-3.5"}),y.enabled?R("cronDisable"):R("cronEnable")]}),h.jsxs(et,{variant:"destructive",size:"sm",onClick:()=>d(y),className:"gap-1",children:[h.jsx(vi,{className:"h-3.5 w-3.5"}),R("delete")]})]})]})})},y.id))})}),h.jsx(u,{})]})}function ma(e){const{view:t,routeSessionKey:n,selectedSessionKey:r,selectedAgentId:s,setSelectedSessionKey:i,setSelectedAgentId:o,selectedSessionKeyRef:a,resetStreamState:l,resolveAgentIdFromSessionKey:u}=e;C.useEffect(()=>{if(t==="chat"){if(n){r!==n&&i(n);return}r!==null&&(i(null),l())}},[l,n,r,i,t]),C.useEffect(()=>{const c=r?u(r):null;c&&s!==c&&o(c)},[u,s,r,o]),C.useEffect(()=>{a.current=r},[r,a])}function ya({view:e,confirmDialog:t}){return h.jsxs("div",{className:"h-full flex",children:[h.jsx(ky,{}),e==="chat"?h.jsx(yx,{}):h.jsx("section",{className:"flex-1 min-h-0 overflow-hidden bg-gradient-to-b from-gray-50/60 to-white",children:e==="cron"?h.jsx("div",{className:"h-full overflow-auto custom-scrollbar",children:h.jsx("div",{className:"mx-auto w-full max-w-[min(1120px,100%)] px-6 py-5",children:h.jsx(Cx,{})})}):h.jsx("div",{className:"h-full overflow-hidden",children:h.jsx("div",{className:"mx-auto flex h-full min-h-0 w-full max-w-[min(1120px,100%)] flex-col px-6 py-5",children:h.jsx(iu,{forcedType:"skills"})})})}),t]})}const nr="sid_";function xa(e){var r;const t=/^agent:([^:]+):/i.exec(e.trim());if(!t)return null;const n=(r=t[1])==null?void 0:r.trim();return n||null}function Ix(e){const t=Math.random().toString(36).slice(2,8);return`agent:${e}:ui:direct:web-${Date.now().toString(36)}${t}`}function Tx(e){const t=new TextEncoder().encode(e);let n="";for(const s of t)n+=String.fromCharCode(s);const r=btoa(n).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/g,"");return`${nr}${r}`}function Mx(e){if(!e.startsWith(nr))return null;const t=e.slice(nr.length).replace(/-/g,"+").replace(/_/g,"/"),n=t.length%4===0?"":"=".repeat(4-t.length%4);try{const r=atob(t+n),s=Uint8Array.from(r,i=>i.charCodeAt(0));return new TextDecoder().decode(s)}catch{return null}}function ba(e){if(!e)return null;const t=Mx(e);if(t)return t;try{return decodeURIComponent(e)}catch{return e}}function Rx(e){return`/chat/${Tx(e)}`}function Ex(e){const t=e.trim();return t.length>0?t:null}function Ax(e){return e??null}class Sa{constructor(t){this.updateSession=t,this.inFlight=null,this.queued=null,this.syncSelectedSessionPreferences=()=>{const n=K.getState().snapshot,s=se.getState().snapshot.selectedSessionKey;s&&this.enqueue({sessionKey:s,patch:{preferredModel:Ex(n.selectedModel),preferredThinking:Ax(n.selectedThinkingLevel)}})}}enqueue(t){this.queued=t,!this.inFlight&&this.startFlush()}startFlush(){this.inFlight=this.flush().catch(t=>{console.error(`Failed to sync chat session preferences: ${String(t)}`)}).finally(()=>{this.inFlight=null,this.queued&&this.startFlush()})}async flush(){for(;this.queued;){const t=this.queued;this.queued=null,await this.updateSession(t.sessionKey,t.patch)}}}class Lx{constructor(t,n){this.uiManager=t,this.streamActionsManager=n,this.sessionPreferenceSync=new Sa($r),this.hasSnapshotChanges=r=>{const s=K.getState().snapshot;for(const[i,o]of Object.entries(r))if(!Object.is(s[i],o))return!0;return!1},this.resolveUpdateValue=(r,s)=>typeof s=="function"?s(r):s,this.isSameStringArray=(r,s)=>r.length===s.length&&r.every((i,o)=>i===s[o]),this.syncComposerSnapshot=r=>{K.getState().setSnapshot({composerNodes:r,draft:ua(r),selectedSkills:ca(r)})},this.syncSnapshot=r=>{if(this.hasSnapshotChanges(r)&&(K.getState().setSnapshot(r),Object.prototype.hasOwnProperty.call(r,"modelOptions")||Object.prototype.hasOwnProperty.call(r,"selectedModel")||Object.prototype.hasOwnProperty.call(r,"selectedThinkingLevel"))){const{selectedModel:s}=K.getState().snapshot;this.reconcileThinkingForModel(s)}},this.setDraft=r=>{const s=K.getState().snapshot.draft,i=this.resolveUpdateValue(s,r);i!==s&&this.syncComposerSnapshot(la(i))},this.setComposerNodes=r=>{const s=K.getState().snapshot.composerNodes,i=this.resolveUpdateValue(s,r);Object.is(i,s)||this.syncComposerSnapshot(i)},this.setPendingSessionType=r=>{const s=K.getState().snapshot.pendingSessionType,i=this.resolveUpdateValue(s,r);i!==s&&K.getState().setSnapshot({pendingSessionType:i})},this.send=async()=>{const r=K.getState().snapshot,s=se.getState().snapshot,i=r.draft.trim();if(!i)return;const{selectedSkills:o,composerNodes:a}=r,l=!!s.selectedSessionKey,u=s.selectedSessionKey??Ix(s.selectedAgentId);l||this.uiManager.goToSession(u,{replace:!0}),this.setComposerNodes(Dr()),await this.streamActionsManager.sendMessage({message:i,sessionKey:u,agentId:s.selectedAgentId,sessionType:r.selectedSessionType,model:r.selectedModel||void 0,thinkingLevel:r.selectedThinkingLevel??void 0,stopSupported:r.stopSupported,stopReason:r.stopReason,requestedSkills:o,restoreDraftOnError:!0,composerNodes:a})},this.stop=async()=>{await this.streamActionsManager.stopCurrentRun()},this.goToProviders=()=>{this.uiManager.goToProviders()},this.setSelectedModel=r=>{const s=K.getState().snapshot.selectedModel,i=this.resolveUpdateValue(s,r);i!==s&&(K.getState().setSnapshot({selectedModel:i}),this.reconcileThinkingForModel(i))},this.setSelectedThinkingLevel=r=>{const s=K.getState().snapshot.selectedThinkingLevel,i=this.resolveUpdateValue(s,r);i!==s&&K.getState().setSnapshot({selectedThinkingLevel:i})},this.selectSessionType=r=>{const s=He(r);K.getState().setSnapshot({selectedSessionType:s,pendingSessionType:s}),this.syncRemoteSessionType(s)},this.setSelectedSkills=r=>{const s=K.getState().snapshot,{selectedSkills:i}=s,o=this.resolveUpdateValue(i,r);this.isSameStringArray(o,i)||this.syncComposerSnapshot(da(s.composerNodes,o,s.skillRecords))},this.selectModel=r=>{this.setSelectedModel(r),this.sessionPreferenceSync.syncSelectedSessionPreferences()},this.selectThinkingLevel=r=>{this.setSelectedThinkingLevel(r),this.sessionPreferenceSync.syncSelectedSessionPreferences()},this.selectSkills=r=>{this.setSelectedSkills(r)},this.syncRemoteSessionType=async r=>{const s=se.getState().snapshot,{selectedSessionKey:i}=s;if(!i)return;const o=s.sessions.find(a=>a.key===i);o!=null&&o.sessionTypeMutable&&He(o.sessionType)!==r&&await $r(i,{sessionType:r})}}resolveThinkingForModel(t,n){const r=t==null?void 0:t.thinkingCapability;return!r||r.supported.length===0?null:n==="off"?"off":n&&r.supported.includes(n)?n:r.default&&r.supported.includes(r.default)?r.default:"off"}reconcileThinkingForModel(t){const n=K.getState().snapshot,r=n.modelOptions.find(o=>o.value===t),{selectedThinkingLevel:s}=n,i=this.resolveThinkingForModel(r,s);i!==s&&K.getState().setSnapshot({selectedThinkingLevel:i})}}const Nx={parseReady:e=>e.driver!=="nextbot-stream"||e.kind!=="ready"?null:{remoteRunId:typeof e.backendRunId=="string"?e.backendRunId:void 0,sessionId:typeof e.sessionKey=="string"?e.sessionKey:void 0,stopCapable:typeof e.stopSupported=="boolean"?e.stopSupported:void 0,stopReason:typeof e.stopReason=="string"?e.stopReason:void 0},parseFinal:e=>e.driver!=="nextbot-stream"||e.kind!=="final"?null:{sessionId:typeof e.sessionKey=="string"?e.sessionKey:void 0,hasOutput:!!e.hasAssistantSessionEvent}};function Px(e,t){return{driver:"nextbot-stream",mode:"send",payload:e,requestedSkills:t}}function jx(e){const t=Number.isFinite(e.eventCount)&&e.eventCount>0?Math.max(0,Math.trunc(e.eventCount)):void 0;return{driver:"nextbot-stream",mode:"resume",runId:e.runId,...typeof t=="number"?{fromEventIndex:t}:{},sessionKey:e.sessionKey,...e.agentId?{agentId:e.agentId}:{},stopSupported:e.stopSupported,...e.stopReason?{stopReason:e.stopReason}:{}}}function Dx(e,t){if(e===t)return!0;if(e.size!==t.size)return!1;for(const[n,r]of e.entries())if(!Object.is(r,t.get(n)))return!1;return!0}class ka{constructor(){this.syncSnapshot=t=>{const n=Yn.getState().snapshot,r=t.sessionRunStatusByKey;(!r||Dx(n.sessionRunStatusByKey,r))&&(t.isLocallyRunning===void 0||Object.is(n.isLocallyRunning,t.isLocallyRunning))&&(t.activeBackendRunId===void 0||Object.is(n.activeBackendRunId,t.activeBackendRunId))||Yn.getState().setSnapshot(t)}}}class va{constructor(t,n){this.uiManager=t,this.streamActionsManager=n,this.hasSnapshotChanges=r=>{const s=se.getState().snapshot;for(const[i,o]of Object.entries(r))if(!Object.is(s[i],o))return!0;return!1},this.resolveUpdateValue=(r,s)=>typeof s=="function"?s(r):s,this.syncSnapshot=r=>{this.hasSnapshotChanges(r)&&se.getState().setSnapshot(r)},this.setSelectedAgentId=r=>{const s=se.getState().snapshot.selectedAgentId,i=this.resolveUpdateValue(s,r);i!==s&&se.getState().setSnapshot({selectedAgentId:i})},this.setSelectedSessionKey=r=>{const s=se.getState().snapshot.selectedSessionKey,i=this.resolveUpdateValue(s,r);i!==s&&se.getState().setSnapshot({selectedSessionKey:i})},this.createSession=r=>{const{snapshot:s}=K.getState(),{defaultSessionType:i}=s,o=i||"native",a=typeof r=="string"&&r.trim().length>0?r.trim():o;this.streamActionsManager.resetStreamState(),this.setSelectedSessionKey(null),K.getState().setSnapshot({pendingSessionType:a}),this.uiManager.goToChatRoot()},this.selectSession=r=>{this.setSelectedSessionKey(r),this.uiManager.goToSession(r)},this.setQuery=r=>{const s=se.getState().snapshot.query,i=this.resolveUpdateValue(s,r);i!==s&&se.getState().setSnapshot({query:i})}}}const En=async()=>{},ti=()=>{};class wa{constructor(){this.actions={sendMessage:En,stopCurrentRun:En,resumeRun:En,resetStreamState:ti,applyHistoryMessages:ti},this.bind=t=>{this.actions={...this.actions,...t}},this.sendMessage=t=>this.actions.sendMessage(t),this.stopCurrentRun=()=>this.actions.stopCurrentRun(),this.resumeRun=t=>this.actions.resumeRun(t),this.resetStreamState=()=>this.actions.resetStreamState(),this.applyHistoryMessages=(t,n)=>this.actions.applyHistoryMessages(t,n)}}const _x=async()=>{};class Ox{constructor(t,n,r){this.uiManager=t,this.sessionListManager=n,this.streamActionsManager=r,this.actions={refetchSessions:_x},this.bindActions=s=>{this.actions={...this.actions,...s}},this.hasSnapshotChanges=s=>{const i=Ve.getState().snapshot;for(const[o,a]of Object.entries(s))if(!Object.is(i[o],a))return!0;return!1},this.syncSnapshot=s=>{this.hasSnapshotChanges(s)&&Ve.getState().setSnapshot(s)},this.deleteSession=()=>{this.deleteCurrentSession()},this.createSession=()=>{this.sessionListManager.createSession()},this.goToProviders=()=>{this.uiManager.goToProviders()},this.deleteCurrentSession=async()=>{const{snapshot:{selectedSessionKey:s}}=se.getState();if(!(!s||!await this.uiManager.confirm({title:R("chatDeleteSessionConfirm"),variant:"destructive",confirmLabel:R("delete")}))){Ve.getState().setSnapshot({isDeletePending:!0});try{await _l(s),this.streamActionsManager.resetStreamState(),se.getState().setSnapshot({selectedSessionKey:null}),this.uiManager.goToChatRoot({replace:!0}),await this.actions.refetchSessions()}finally{Ve.getState().setSnapshot({isDeletePending:!1})}}}}}const Fx=async e=>!1;class Ca{constructor(){this.state={pathname:""},this.actions={navigate:null,confirm:Fx},this.syncState=t=>{this.state={...this.state,...t}},this.bindActions=t=>{this.actions={...this.actions,...t}},this.confirm=async t=>this.actions.confirm(t),this.navigateTo=(t,n)=>{this.actions.navigate&&(this.state.pathname===t&&!(n!=null&&n.replace)||(this.actions.navigate(t,n),this.state.pathname=t))},this.goToProviders=()=>{this.navigateTo("/providers")},this.goToChatRoot=t=>{this.navigateTo("/chat",t)},this.goToSession=(t,n)=>{this.navigateTo(Rx(t),n)}}}function zx(e){return e.delta?e.started?[{type:q.TEXT_DELTA,messageId:e.messageId,delta:e.delta}]:[{type:q.TEXT_START,messageId:e.messageId},{type:q.TEXT_DELTA,messageId:e.messageId,delta:e.delta}]:[]}function Bx(e){return!1}function $x(e){var n,r;return((r=(n=e.message)==null?void 0:n.role)==null?void 0:r.toLowerCase().trim())==="assistant"}function Ux(e){var o;const{event:t,messageId:n}=e,r=t.message;if(!r)return[];const s=(o=r.role)==null?void 0:o.toLowerCase().trim();if(!s)return[];const i=[];if(typeof r.reasoning_content=="string"&&r.reasoning_content.trim()&&(i.push({type:q.REASONING_START,messageId:n}),i.push({type:q.REASONING_DELTA,messageId:n,delta:r.reasoning_content.trim()}),i.push({type:q.REASONING_END,messageId:n})),Array.isArray(r.tool_calls))for(let a=0;a<r.tool_calls.length;a+=1){const l=r.tool_calls[a];if(!l||typeof l!="object")continue;const u=l,c=u.function,d=typeof c=="object"&&c?c:null,p=typeof t.seq=="number"?String(t.seq):"unknown",f=typeof u.id=="string"?u.id:`tool-${p}-${a}`,m=typeof(d==null?void 0:d.name)=="string"?d.name:typeof u.name=="string"?u.name:"tool",y=(d==null?void 0:d.arguments)??u.arguments??"",b=typeof y=="string"?y:JSON.stringify(y??{});i.push({type:q.TOOL_CALL_START,messageId:n,toolCallId:f,toolName:m}),i.push({type:q.TOOL_CALL_ARGS,toolCallId:f,args:b}),i.push({type:q.TOOL_CALL_END,toolCallId:f})}if(s==="tool"||s==="tool_result"||s==="toolresult"||s==="function"){const a=typeof r.tool_call_id=="string"?r.tool_call_id.trim():"";a&&i.push({type:q.TOOL_CALL_RESULT,toolCallId:a,content:r.content})}return i}function Ia(){return`stream-${Date.now()}-${Math.random().toString(36).slice(2,8)}`}function Kx(e,t){const n={};return e.sessionType&&(n.session_type=e.sessionType),e.thinkingLevel&&(n.thinking=e.thinkingLevel),t.length>0&&(n.requested_skills=t),{message:e.message,...e.runId?{runId:e.runId}:{},sessionKey:e.sessionKey,agentId:e.agentId,...e.model?{model:e.model}:{},...Object.keys(n).length>0?{metadata:n}:{},channel:"ui",chatId:"web-ui"}}async function Hx(e){return Ol(Kx(e.item,e.requestedSkills),{signal:e.signal,onReady:e.onReady,onDelta:e.onDelta,onSessionEvent:e.onSessionEvent})}async function Vx(e){return Fl({runId:e.runId,...typeof e.fromEventIndex=="number"?{fromEventIndex:e.fromEventIndex}:{}},{signal:e.signal,onReady:e.onReady,onDelta:e.onDelta,onSessionEvent:e.onSessionEvent})}async function qx(e){var t;if(e.backendStopSupported)try{const n=new Set,r=(t=e.backendRunId)==null?void 0:t.trim();if(r&&(n.add(r),await An(r)))return;const s=await Wx(e);for(const i of s){if(n.has(i))continue;if(n.add(i),await An(i))return}if(r&&await An(r))return}catch{}}async function An(e){const t=e.trim();if(!t)return!1;try{return(await zl({runId:t})).stopped===!0}catch{return!1}}async function Wx(e){var s;const t=(s=e.sessionKey)==null?void 0:s.trim();if(!t)return[];const n=8,r=120;for(let i=0;i<n;i+=1){const o=await Gx(e,t);if(o.length>0)return o;i<n-1&&await Qx(r)}return[]}async function Gx(e,t){try{const n=await Bl({sessionKey:t,states:["queued","running"],limit:50}),r=n.runs.filter(s=>{var i;return((i=s.runId)==null?void 0:i.trim())&&s.sessionKey===t&&s.agentId===e.agentId}).map(s=>s.runId.trim());return r.length>0?r:n.runs.filter(s=>{var i;return((i=s.runId)==null?void 0:i.trim())&&s.sessionKey===t}).map(s=>s.runId.trim())}catch{return[]}}function Qx(e){return new Promise(t=>{window.setTimeout(t,e)})}function Ta(e){if(!Array.isArray(e))return[];const t=new Set;for(const n of e){const r=n.trim();r&&t.add(r)}return[...t]}function Xx(e){var y;const t=new Set(["tool","tool_result","toolresult","function"]),n=[];let r=0,s=0,i=null;const o=(b,g)=>(r+=1,`history-${b}-${g||"unknown"}-${r}`),a=b=>{const g=typeof b=="string"?b:JSON.stringify(b??{});try{return{args:g,parsedArgs:JSON.parse(g)}}catch{return{args:g}}},l=(b,g)=>{for(let v=b.length-1;v>=0;v-=1){const w=b[v];if(w.type==="tool-invocation"&&w.toolInvocation.toolCallId===g)return v}return-1},u=b=>i?(i={...i,meta:{...i.meta,timestamp:b}},i):(s+=1,i={id:`history-assistant-${s}-${b||"unknown"}`,role:"assistant",parts:[],meta:{source:"history",status:"final",timestamp:b}},i),c=()=>{i&&(i.parts.length>0&&n.push(i),i=null)},d=(b,g)=>{if(!g)return;const v=u(b);v.parts=[...v.parts,{type:"text",text:g}]},p=(b,g)=>{if(!g)return;const v=u(b);v.parts=[...v.parts,{type:"reasoning",reasoning:g,details:[]}]},f=b=>{const g=u(b.timestamp),v=l(g.parts,b.toolCallId),w={type:"tool-invocation",toolInvocation:{status:oe.CALL,toolCallId:b.toolCallId,toolName:b.toolName,args:b.args,parsedArgs:b.parsedArgs}};if(v>=0){g.parts=[...g.parts.slice(0,v),w,...g.parts.slice(v+1)];return}g.parts=[...g.parts,w]},m=b=>{if(!b.toolCallId)return;const g=u(b.timestamp),v=l(g.parts,b.toolCallId);if(v<0){g.parts=[...g.parts,{type:"tool-invocation",toolInvocation:{status:oe.RESULT,toolCallId:b.toolCallId,toolName:b.toolName,args:"{}",parsedArgs:void 0,result:b.result}}];return}const w=g.parts[v];w.type==="tool-invocation"&&(g.parts=[...g.parts.slice(0,v),{...w,toolInvocation:{...w.toolInvocation,status:oe.RESULT,result:b.result}},...g.parts.slice(v+1)])};for(const b of e){const g=(y=b.role)==null?void 0:y.toLowerCase().trim();if(!g)continue;const v=b.timestamp;if(g==="user"||g==="system"||g==="data"){c();const w=Kr(b.content).trim();if(!w)continue;n.push({id:o(g,v),role:g,parts:[{type:"text",text:w}],meta:{source:"history",status:"final",timestamp:v}});continue}if(g==="assistant"){const w=Kr(b.content).trim();if(w&&d(v,w),typeof b.reasoning_content=="string"&&b.reasoning_content.trim()&&p(v,b.reasoning_content.trim()),Array.isArray(b.tool_calls))for(const T of b.tool_calls){if(!T||typeof T!="object")continue;const A=T,k=A.function,N=typeof k=="object"&&k?k:null,F=typeof A.id=="string"?A.id.trim():"";if(!F)continue;const O=typeof(N==null?void 0:N.name)=="string"?N.name:typeof A.name=="string"?A.name:"tool",I=a((N==null?void 0:N.arguments)??A.arguments??"");f({timestamp:v,toolCallId:F,toolName:O,args:I.args,parsedArgs:I.parsedArgs})}continue}if(t.has(g)){const w=typeof b.tool_call_id=="string"?b.tool_call_id.trim():"",T=typeof b.name=="string"&&b.name.trim()?b.name.trim():"tool";m({timestamp:v,toolCallId:w,toolName:T,result:b.content})}}return c(),n}function Yx(){const e=Date.now().toString(36),t=Math.random().toString(36).slice(2,10);return`run-${e}-${t}`}function Jx(e){const t=e.metadata;if(!t||typeof t!="object"||Array.isArray(t))return null;const n=t;if(n.driver!=="nextbot-stream")return null;const r=n.mode;if(r==="send"){const s=n.payload;if(!s||typeof s!="object"||Array.isArray(s))return null;const i=Array.isArray(n.requestedSkills)?n.requestedSkills.filter(o=>typeof o=="string"):[];return{driver:"nextbot-stream",mode:"send",payload:s,requestedSkills:i}}if(r==="resume"){const s=typeof n.runId=="string"?n.runId.trim():"";if(!s)return null;const i=typeof n.fromEventIndex=="number"&&Number.isFinite(n.fromEventIndex)?Math.max(0,Math.trunc(n.fromEventIndex)):void 0,o=typeof n.sessionKey=="string"?n.sessionKey.trim():"",a=typeof n.agentId=="string"?n.agentId.trim():"",l=typeof n.stopSupported=="boolean"?n.stopSupported:void 0,u=typeof n.stopReason=="string"?n.stopReason.trim():"";return{driver:"nextbot-stream",mode:"resume",runId:s,...typeof i=="number"?{fromEventIndex:i}:{},...o?{sessionKey:o}:{},...a?{agentId:a}:{},...typeof l=="boolean"?{stopSupported:l}:{},...u?{stopReason:u}:{}}}return null}function Zx(e){var t;if(e.mode==="send"){const n=((t=e.payload.runId)==null?void 0:t.trim())||"";return{localRunId:0,sessionKey:e.payload.sessionKey,...e.payload.agentId?{agentId:e.payload.agentId}:{},...n?{backendRunId:n}:{},backendStopSupported:!!e.payload.stopSupported,...e.payload.stopReason?{backendStopReason:e.payload.stopReason}:{}}}return{localRunId:0,sessionKey:e.sessionKey??"",...e.agentId?{agentId:e.agentId}:{},backendRunId:e.runId,backendStopSupported:!!e.stopSupported,...e.stopReason?{backendStopReason:e.stopReason}:{}}}function eb(e){var n;return e.mode!=="send"||((n=e.payload.runId)==null?void 0:n.trim())?e:{...e,payload:{...e.payload,runId:Yx()}}}function tb(e,t){var n,r,s;e.backendRunId=((n=t.runId)==null?void 0:n.trim())||e.backendRunId,e.backendStopSupported=typeof t.stopSupported=="boolean"?t.stopSupported:e.backendStopSupported,(r=t.stopReason)!=null&&r.trim()&&(e.backendStopReason=t.stopReason.trim()),(s=t.sessionKey)!=null&&s.trim()&&(e.sessionKey=t.sessionKey.trim())}function nb(){return{deltaMessageId:Ia(),deltaStarted:!1,deltaClosed:!1,hasAssistantSessionEvent:!1,hasAssistantOutput:!1}}function rb(e){var t,n,r;return{driver:"nextbot-stream",kind:"ready",...(t=e.sessionKey)!=null&&t.trim()?{sessionKey:e.sessionKey.trim()}:{},...(n=e.runId)!=null&&n.trim()?{backendRunId:e.runId.trim()}:{},...typeof e.stopSupported=="boolean"?{stopSupported:e.stopSupported}:{},...(r=e.stopReason)!=null&&r.trim()?{stopReason:e.stopReason.trim()}:{},...e.requestedAt?{requestedAt:e.requestedAt}:{}}}function sb(e,t){return{driver:"nextbot-stream",kind:"final",sessionKey:e.sessionKey,reply:e.reply,hasAssistantSessionEvent:t}}function ni(e,t,n){e({type:q.RUN_METADATA,runId:t,metadata:n})}function ri(e,t){!e.deltaStarted||e.deltaClosed||(t({type:q.TEXT_END,messageId:e.deltaMessageId}),e.deltaClosed=!0)}function ib(e,t,n){const r=zx({messageId:e.deltaMessageId,delta:n.delta,started:e.deltaStarted});r.length>0&&(e.deltaStarted=!0,e.deltaClosed=!1,e.hasAssistantOutput=!0);for(const s of r)t(s)}function ob(e,t,n){Bx(n.data),$x(n.data)&&(e.hasAssistantSessionEvent=!0);for(const r of Ux({event:n.data,messageId:e.deltaMessageId}))t(r)}function ab(e,t,n){const r=n.trim();if(e.hasAssistantOutput||!r)return;const s=Ia();t({type:q.TEXT_START,messageId:s}),t({type:q.TEXT_DELTA,messageId:s,delta:r}),t({type:q.TEXT_END,messageId:s})}class lb{constructor(){this.activeAbortController=null,this.activeRunState=null,this.buildMissingMetadataObservable=t=>new Yt(n=>{n.next({type:q.RUN_ERROR,runId:t,error:"nextbot runtime metadata is required"}),n.complete()}),this.openRunStream=t=>{const{metadata:n,signal:r,onReady:s,onDelta:i,onSessionEvent:o}=t;return n.mode==="send"?Hx({item:n.payload,requestedSkills:n.requestedSkills,signal:r,onReady:s,onDelta:i,onSessionEvent:o}):Vx({runId:n.runId,fromEventIndex:n.fromEventIndex,signal:r,onReady:s,onDelta:i,onSessionEvent:o})},this.finalizeRunState=(t,n)=>{this.activeAbortController===t&&(this.activeAbortController=null),this.activeRunState===n&&(this.activeRunState=null)},this.createRunObservable=({metadata:t,clientRunId:n,abortController:r,runState:s})=>new Yt(i=>{const o=nb();let a=!1;const l=c=>{a||i.next(c)};return l({type:q.RUN_STARTED,runId:n}),this.openRunStream({metadata:t,signal:r.signal,onReady:c=>{this.activeRunState&&tb(this.activeRunState,c),ni(l,n,rb(c))},onDelta:c=>{ib(o,l,c)},onSessionEvent:c=>{ob(o,l,c)}}).then(c=>{ri(o,l),ab(o,l,c.reply),ni(l,n,sb(c,o.hasAssistantSessionEvent)),l({type:q.RUN_FINISHED,runId:n}),i.complete()}).catch(c=>{ri(o,l),tr(c)||l({type:q.RUN_ERROR,runId:n,error:c instanceof Error?c.message:String(c)}),i.complete()}).finally(()=>{this.finalizeRunState(r,s)}),()=>{a=!0,r.abort(),this.activeAbortController===r&&(this.activeAbortController=null)}}),this.abortRun=()=>{var n;const t=this.activeRunState;t!=null&&t.backendStopSupported&&qx(t),(n=this.activeAbortController)==null||n.abort(),this.activeAbortController=null,this.activeRunState=null},this.run=t=>{const n=Jx(t),r=typeof t.runId=="string"&&t.runId.trim()?t.runId:`run-${Date.now()}`;if(!n)return this.buildMissingMetadataObservable(r);const s=eb(n);this.abortRun();const i=new AbortController;this.activeAbortController=i;const o=Zx(s);return this.activeRunState=o,this.createRunObservable({metadata:s,clientRunId:r,abortController:i,runState:o})}}}class ub{constructor(){this.chatUiManager=new Ca,this.runtimeAgent=new lb,this.chatController=new tx({agent:this.runtimeAgent,getToolDefs:()=>[],getContexts:()=>[],getToolExecutor:()=>{}},{metadataParsers:Nx}),this.chatStreamActionsManager=new wa,this.chatInputManager=new Lx(this.chatUiManager,this.chatStreamActionsManager),this.chatSessionListManager=new va(this.chatUiManager,this.chatStreamActionsManager),this.chatRunStatusManager=new ka,this.chatThreadManager=new Ox(this.chatUiManager,this.chatSessionListManager,this.chatStreamActionsManager)}}function $t(e){const[t,n]=C.useState(e.getValue());return C.useEffect(()=>{const r=e.subscribe(n);return()=>r.unsubscribe()},[e]),t}function cb(e,t){const[n,r]=C.useState(t);return C.useEffect(()=>{const s=e.subscribe(r);return()=>s.unsubscribe()},[e]),n}function db(e,t){const n=C.useRef(e);C.useEffect(()=>{n.current=e});const r=C.useRef(null);C.useEffect(()=>{t.setCallbacks({onRunSettled:async({sourceSessionId:g,resultSessionId:v})=>{const w=n.current;await w.refetchSessions();const T=w.selectedSessionKeyRef.current;(!T||T===g||v&&T===v)&&await w.refetchHistory()},onRunError:({sourceMessage:g,restoreDraft:v})=>{v&&n.current.setDraft(w=>w.trim().length===0&&g?g:w)},onSessionChanged:g=>{n.current.setSelectedSessionKey(v=>v===g?v:g)}})},[t]);const s=cb(t.messages$,t.getMessages()),i=$t(t.isAgentResponding$),o=$t(t.isAwaitingResponse$),a=$t(t.activeRun$),l=$t(t.lastError$),u=(a==null?void 0:a.remoteRunId)??null,c=Xy(a),d=!!(a&&(c===null||a.remoteStopCapable&&!u)),p=C.useCallback(async g=>{const v=Ta(g.requestedSkills),w=Px(g,v);await t.send({message:g.message,sessionId:g.sessionKey,agentId:g.agentId,metadata:w,restoreDraftOnError:g.restoreDraftOnError,stopCapable:g.stopSupported,stopReason:g.stopReason})},[t]),f=C.useCallback(async g=>{var A,k;const v=(A=g.runId)==null?void 0:A.trim(),w=(k=g.sessionKey)==null?void 0:k.trim();if(!v||!w)return;const T=jx(g);await t.resume({remoteRunId:v,sessionId:w,agentId:g.agentId,metadata:T,stopCapable:g.stopSupported,stopReason:g.stopReason})},[t]),m=C.useCallback(async()=>{await t.stop()},[t]),y=C.useCallback(()=>{r.current=null,t.reset()},[t]),b=C.useCallback((g,v)=>{if(!!(t.activeRun$.getValue()||t.isAgentResponding$.getValue()))return;const T=n.current.selectedSessionKeyRef.current;if(T!==r.current&&(r.current=T,t.getMessages().length>0&&t.setMessages([])),!T){t.getMessages().length>0&&t.setMessages([]);return}v!=null&&v.isLoading&&g.length===0||t.setMessages(Xx(g))},[t]);return{uiMessages:s,isSending:i,isAwaitingAssistantOutput:o,canStopCurrentRun:d,stopDisabledReason:c,lastSendError:l,activeBackendRunId:u,sendMessage:p,stopCurrentRun:m,resumeRun:f,resetStreamState:y,applyHistoryMessages:b}}function hb({view:e}){var De,Xe,Ye;const[t]=C.useState(()=>new ub),n=se(he=>he.snapshot.query),r=se(he=>he.snapshot.selectedSessionKey),s=se(he=>he.snapshot.selectedAgentId),i=K(he=>he.snapshot.pendingSessionType),{confirm:o,ConfirmDialog:a}=dr(),l=cr(),u=wi(),{sessionId:c}=Ci(),d=C.useRef(null),p=C.useRef(r),f=C.useRef(null),m=C.useMemo(()=>ba(c),[c]),{sessionsQuery:y,installedSkillsQuery:b,chatCapabilitiesQuery:g,historyQuery:v,isProviderStateResolved:w,modelOptions:T,sessions:A,skillRecords:k,selectedSession:N,historyMessages:F,selectedSessionThinkingLevel:O,sessionTypeOptions:I,defaultSessionType:j,selectedSessionType:_,canEditSessionType:W,sessionTypeUnavailable:z,sessionTypeUnavailableMessage:P}=vu({query:n,selectedSessionKey:r,selectedAgentId:s,pendingSessionType:i,setPendingSessionType:t.chatInputManager.setPendingSessionType,setSelectedModel:t.chatInputManager.setSelectedModel}),{uiMessages:Q,isSending:Y,isAwaitingAssistantOutput:ue,canStopCurrentRun:ye,stopDisabledReason:S,lastSendError:J,activeBackendRunId:ce,sendMessage:x,stopCurrentRun:de,resumeRun:ke,resetStreamState:re,applyHistoryMessages:Le}=db({selectedSessionKeyRef:p,setSelectedSessionKey:t.chatSessionListManager.setSelectedSessionKey,setDraft:t.chatInputManager.setDraft,setComposerNodes:t.chatInputManager.setComposerNodes,refetchSessions:y.refetch,refetchHistory:v.refetch},t.chatController);C.useEffect(()=>{t.chatStreamActionsManager.bind({sendMessage:x,stopCurrentRun:de,resumeRun:ke,resetStreamState:re,applyHistoryMessages:Le})},[Le,t,re,ke,x,de]);const{sessionRunStatusByKey:ae}=xu({view:e,selectedSessionKey:r,activeBackendRunId:ce,isLocallyRunning:Y||!!ce,resumeRun:t.chatStreamActionsManager.resumeRun});ma({view:e,routeSessionKey:m,selectedSessionKey:r,selectedAgentId:s,setSelectedSessionKey:t.chatSessionListManager.setSelectedSessionKey,setSelectedAgentId:t.chatSessionListManager.setSelectedAgentId,selectedSessionKeyRef:p,resetStreamState:t.chatStreamActionsManager.resetStreamState,resolveAgentIdFromSessionKey:xa}),C.useEffect(()=>{t.chatStreamActionsManager.applyHistoryMessages(F,{isLoading:v.isLoading})},[F,v.isLoading,t]),C.useEffect(()=>{t.chatUiManager.syncState({pathname:l.pathname}),t.chatUiManager.bindActions({navigate:u,confirm:o})},[o,l.pathname,u,t]);const Me=N?Oi(N):void 0,Re=((De=I.find(he=>he.value===_))==null?void 0:De.label)??ut(_);return C.useEffect(()=>{t.chatThreadManager.bindActions({refetchSessions:y.refetch})},[t,y.refetch]),C.useEffect(()=>{var H,ve;const he=!Y&&!ue&&!v.isLoading&&w&&T.length>0&&r!==f.current;t.chatInputManager.syncSnapshot({isProviderStateResolved:w,defaultSessionType:j,canStopGeneration:ye,stopDisabledReason:S,stopSupported:((H=g.data)==null?void 0:H.stopSupported)??!1,stopReason:(ve=g.data)==null?void 0:ve.stopReason,sendError:J,isSending:Y,modelOptions:T,sessionTypeOptions:I,selectedSessionType:_,...he?{selectedThinkingLevel:O}:{},canEditSessionType:W,sessionTypeUnavailable:z,skillRecords:k,isSkillsLoading:b.isLoading}),he&&(f.current=r),r||(f.current=null),t.chatSessionListManager.syncSnapshot({sessions:A,query:n,isLoading:y.isLoading}),t.chatRunStatusManager.syncSnapshot({sessionRunStatusByKey:ae,isLocallyRunning:Y||!!ce,activeBackendRunId:ce}),t.chatThreadManager.syncSnapshot({isProviderStateResolved:w,modelOptions:T,sessionTypeUnavailable:z,sessionTypeUnavailableMessage:P,sessionTypeLabel:Re,selectedSessionKey:r,sessionDisplayName:Me,canDeleteSession:!!N,threadRef:d,isHistoryLoading:v.isLoading,uiMessages:Q,isSending:Y,isAwaitingAssistantOutput:ue})},[ce,W,ye,Me,Re,(Xe=g.data)==null?void 0:Xe.stopReason,(Ye=g.data)==null?void 0:Ye.stopSupported,j,v.isLoading,b.isLoading,ue,w,Y,J,T.length,T,t,n,N,r,O,_,ae,I,z,P,A,y.isLoading,k,S,d,Q]),h.jsx(zi,{presenter:t,children:h.jsx(ya,{view:e,confirmDialog:h.jsx(a,{})})})}var ne=(e=>(e.EndpointReady="endpoint.ready",e.EndpointError="endpoint.error",e.MessageRequest="message.request",e.MessageStreamRequest="message.stream-request",e.MessageSent="message.sent",e.MessageAccepted="message.accepted",e.MessageIncoming="message.incoming",e.MessageCompleted="message.completed",e.MessageFailed="message.failed",e.MessageAbort="message.abort",e.MessageTextStart="message.text-start",e.MessageTextDelta="message.text-delta",e.MessageTextEnd="message.text-end",e.MessageReasoningStart="message.reasoning-start",e.MessageReasoningDelta="message.reasoning-delta",e.MessageReasoningEnd="message.reasoning-end",e.MessageToolCallStart="message.tool-call-start",e.MessageToolCallArgs="message.tool-call-args",e.MessageToolCallArgsDelta="message.tool-call-args-delta",e.MessageToolCallEnd="message.tool-call-end",e.MessageToolCallResult="message.tool-call-result",e.MessageRead="message.read",e.MessageDelivered="message.delivered",e.MessageRecalled="message.recalled",e.MessageReaction="message.reaction",e.RunStarted="run.started",e.RunFinished="run.finished",e.RunError="run.error",e.RunMetadata="run.metadata",e.TypingStart="typing.start",e.TypingEnd="typing.end",e.PresenceUpdated="presence.updated",e))(ne||{}),si=/\[\[\s*reply_to_current\s*\]\]/gi,ii=/\[\[\s*reply_to\s*:\s*([^\]]+?)\s*\]\]/i;function rr(e){if(typeof e!="string")return;const t=e.trim();return t.length>0?t:void 0}function fb(e,t){var i;let n=e,r;si.test(n)&&(r=rr(t),n=n.replace(si,"").trim());const s=(i=n.match(ii))==null?void 0:i[1];return s&&(r=rr(s),n=n.replace(ii,"").trim()),r?{content:n,replyTo:r}:{content:n}}function pb(e,t=e.id){if(e.role!=="assistant")return{...e,parts:[...e.parts],metadata:e.metadata?{...e.metadata}:void 0};const n=e.parts.findIndex(c=>c.type==="text"),r=e.metadata?{...e.metadata}:void 0,s=rr(r==null?void 0:r.reply_to);if(n<0)return{...e,parts:[...e.parts],metadata:r};const i=e.parts[n];if(!i||i.type!=="text")return{...e,parts:[...e.parts],metadata:r};const{content:o,replyTo:a}=fb(i.text,t),l=a??s,u=e.parts.flatMap((c,d)=>d!==n||c.type!=="text"?[c]:o.length===0?[]:[{...c,text:o}]);return l?{...e,parts:u,metadata:{...r,reply_to:l}}:{...e,parts:u,metadata:r}}function oi(e){const t=e.split(/\r?\n/);let n="message";const r=[];for(const s of t){const i=s.trimEnd();if(!(!i||i.startsWith(":"))){if(i.startsWith("event:")){n=i.slice(6).trim()||"message";continue}i.startsWith("data:")&&r.push(i.slice(5).trimStart())}}return r.length===0?null:{event:n,data:r.join(`
38
+ `)}}async function*gb(e){const t=e.getReader(),n=new TextDecoder;let r="";try{for(;;){const{value:i,done:o}=await t.read();if(o)break;r+=n.decode(i,{stream:!0});const{frames:a,rest:l}=ai(r);r=l;for(const u of a)yield u}r+=n.decode();const{frames:s}=ai(r,!0);for(const i of s)yield i}finally{t.releaseLock()}}function ai(e,t=!1){const n=e.split(/\r?\n\r?\n/),r=n.pop()??"",s=[];for(const i of n){const o=oi(i);o&&s.push(o)}if(t&&r.trim()){const i=oi(r);return i&&s.push(i),{frames:s,rest:""}}return{frames:s,rest:r}}var li="/ncp/agent",mb="ncp-http-agent-client",Ma=class extends Error{constructor(t,n=!1){super(t.message);D(this,"ncpError");D(this,"alreadyPublished");this.name=`NcpHttpAgentClientError(${t.code})`,this.ncpError=t,this.alreadyPublished=n}};function yb(e){const t=e.trim();if(!t)throw new Error("NcpHttpAgentClient requires a non-empty baseUrl.");return new URL(t)}function xb(e){if(e)return e;if(typeof globalThis.fetch=="function")return globalThis.fetch.bind(globalThis);throw new Error("No fetch implementation found. Pass options.fetchImpl explicitly.")}function bb(e){const t=(e??li).trim();if(!t)return li;const n=t.startsWith("/")?t:`/${t}`;return n.endsWith("/")?n.slice(0,-1):n}async function ui(e){try{return(await e.text()).trim()}catch{return""}}function ci(e){if(Ra(e))return e.ncpError;if(Sb(e))return e;const t=e instanceof Error?e.message:String(e??"Unknown error");return{code:Ea(void 0),message:t,...e instanceof Error&&e.stack?{details:{stack:e.stack}}:{}}}function Ln(e,t={}){return new Ma(e,t.alreadyPublished??!1)}function Sb(e){return _r(e)&&typeof e.code=="string"&&typeof e.message=="string"}function _r(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function Ra(e){return e instanceof Ma}var kb={"config-error":"config-error","auth-error":"auth-error","runtime-error":"runtime-error","timeout-error":"timeout-error","abort-error":"abort-error"};function Ea(e){if(!e)return"runtime-error";const t=kb[e];if(t)return t;const n=e.toLowerCase();return n.includes("timeout")?"timeout-error":n.includes("abort")||n.includes("cancel")?"abort-error":n.includes("auth")?"auth-error":n.includes("config")?"config-error":"runtime-error"}function vb(e){const t=Aa(e);return!t||typeof t.type!="string"||!t.type.trim()?null:t}function wb(e){const t=Aa(e);if(!t)return{code:"runtime-error",message:e||"Unknown stream error."};const n=typeof t.code=="string"?t.code:void 0,r=Ea(n),s=_r(t.details)?t.details:{};return n&&n!==r&&(s.originalCode=n),{code:r,message:typeof t.message=="string"&&t.message?t.message:"Unknown stream error.",...Object.keys(s).length>0?{details:s}:{}}}function Aa(e){try{const t=JSON.parse(e);return _r(t)?t:null}catch{return null}}var Cb=["text","file","source","step-start","reasoning","tool-invocation","card","rich-text","action","extension"],Ib=class{constructor(e){D(this,"manifest");D(this,"baseUrl");D(this,"basePath");D(this,"fetchImpl");D(this,"defaultHeaders");D(this,"subscribers",new Set);D(this,"activeControllers",new Set);D(this,"started",!1);var t;this.baseUrl=yb(e.baseUrl),this.basePath=bb(e.basePath),this.fetchImpl=xb(e.fetchImpl),this.defaultHeaders=e.headers??{},this.manifest={endpointKind:"custom",endpointId:((t=e.endpointId)==null?void 0:t.trim())||mb,version:"0.1.0",supportsStreaming:!0,supportsAbort:!0,supportsProactiveMessages:!1,supportsLiveSessionStream:!0,supportedPartTypes:Cb,expectedLatency:"seconds",metadata:{transport:"http+sse",scope:"agent"}}}async start(){this.started||(this.started=!0,this.publish({type:ne.EndpointReady}))}async stop(){if(this.started){this.started=!1;for(const e of this.activeControllers)e.abort();this.activeControllers.clear()}}async emit(e){switch(e.type){case"message.request":await this.send(e.payload);return;case"message.stream-request":await this.stream(e.payload);return;case"message.abort":await this.abort(e.payload);return;default:this.publish(e);return}}subscribe(e){return this.subscribers.add(e),()=>{this.subscribers.delete(e)}}async send(e){await this.ensureStarted(),await this.streamRequest({path:"/send",method:"POST",body:e})}async stream(e){await this.ensureStarted();const t=new URLSearchParams({sessionId:e.sessionId});await this.streamRequest({path:`/stream?${t.toString()}`,method:"GET"})}async abort(e){await this.ensureStarted();const t=new AbortController;this.activeControllers.add(t);try{const n=await this.fetchImpl(this.resolveUrl("/abort"),{method:"POST",headers:{...this.defaultHeaders,"content-type":"application/json",accept:"application/json"},body:JSON.stringify(e),signal:t.signal});if(!n.ok)throw new Error(`Abort request failed with HTTP ${n.status}: ${await ui(n)}`)}catch(n){if(t.signal.aborted)return;const r=ci(n);throw this.publish({type:ne.EndpointError,payload:r}),Ln(r)}finally{this.activeControllers.delete(t)}}async ensureStarted(){this.started||await this.start()}publish(e){for(const t of this.subscribers)t(e)}resolveUrl(e){return new URL(`${this.basePath}${e}`,this.baseUrl)}async streamRequest(e){const t=new AbortController;this.activeControllers.add(t);try{const n=await this.fetchImpl(this.resolveUrl(e.path),{method:e.method,headers:{...this.defaultHeaders,accept:"text/event-stream",...e.body!==void 0?{"content-type":"application/json"}:{}},body:e.body===void 0?void 0:JSON.stringify(e.body),signal:t.signal});if(!n.ok)throw new Error(`NCP stream request failed with HTTP ${n.status}: ${await ui(n)}`);if(!n.body)throw new Error("NCP stream response has no body.");for await(const r of gb(n.body)){if(t.signal.aborted)return;this.handleSseFrame(r)}}catch(n){if(t.signal.aborted)return;if(Ra(n))throw n;const r=ci(n);throw this.publish({type:ne.EndpointError,payload:r}),Ln(r)}finally{this.activeControllers.delete(t)}}handleSseFrame(e){if(e.event==="ncp-event"){const t=vb(e.data);if(!t){this.publish({type:ne.EndpointError,payload:{code:"runtime-error",message:"Received malformed ncp-event frame."}});return}this.publish(t);return}if(e.event==="error"){const t=wb(e.data);throw this.publish({type:ne.EndpointError,payload:t}),Ln(t,{alreadyPublished:!0})}}};function qt(e){return{...e,parts:[...e.parts],metadata:e.metadata?{...e.metadata}:void 0}}function Nn(e){return qt(pb(e))}function Tb(e){var n;const t=(n=e.error)==null?void 0:n.trim();return{code:"runtime-error",message:t&&t.length>0?t:"Agent run failed.",details:{sessionId:e.sessionId,messageId:e.messageId,threadId:e.threadId,runId:e.runId}}}function Mb(e,t){return t.trim()?e.id.startsWith("tool-")?!0:e.parts.some(n=>n.type==="tool-invocation"):!1}function Rb(e,t,n){for(const[r,s]of e)s===t&&e.set(r,n)}function Ut(e,t,n){for(const[r,s]of e)s===n&&(e.delete(r),t.delete(r))}function sr(e,t){for(let n=e.length-1;n>=0;n-=1){const r=e[n];if(r.type==="tool-invocation"&&r.toolCallId===t)return r}return null}function di(e,t){const n=sr(e,t);return(n==null?void 0:n.toolName)??null}function St(e,t){const n=[...e];for(let r=n.length-1;r>=0;r-=1){const s=n[r];if(s.type==="tool-invocation"&&s.toolCallId===t.toolCallId)return n[r]={...s,...t},n}return n.push(t),n}var Eb="assistant",Ab=class{constructor(){D(this,"messages",[]);D(this,"streamingMessage",null);D(this,"error",null);D(this,"activeRun",null);D(this,"listeners",new Set);D(this,"toolCallMessageIdByCallId",new Map);D(this,"toolCallArgsRawByCallId",new Map);D(this,"snapshotCache",null);D(this,"snapshotVersion",-1);D(this,"stateVersion",0)}getSnapshot(){if(this.snapshotCache&&this.snapshotVersion===this.stateVersion)return this.snapshotCache;const e={messages:this.messages.map(t=>qt(t)),streamingMessage:this.streamingMessage?qt(this.streamingMessage):null,error:this.error?{...this.error,details:this.error.details?{...this.error.details}:void 0}:null,activeRun:this.activeRun?{...this.activeRun}:null};return this.snapshotCache=e,this.snapshotVersion=this.stateVersion,e}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}reset(){this.messages.length===0&&!this.streamingMessage&&!this.error&&!this.activeRun&&this.toolCallMessageIdByCallId.size===0&&this.toolCallArgsRawByCallId.size===0||(this.messages=[],this.streamingMessage=null,this.error=null,this.activeRun=null,this.toolCallMessageIdByCallId.clear(),this.toolCallArgsRawByCallId.clear(),this.stateVersion+=1,this.notifyListeners())}hydrate(e){this.messages=e.messages.map(t=>Nn(t)),this.streamingMessage=null,this.error=null,this.activeRun=e.activeRun?{...e.activeRun,sessionId:e.activeRun.sessionId??e.sessionId,abortDisabledReason:e.activeRun.abortDisabledReason??null}:null,this.toolCallMessageIdByCallId.clear(),this.toolCallArgsRawByCallId.clear(),this.stateVersion+=1,this.notifyListeners()}async dispatch(e){const t=this.stateVersion;switch(e.type){case ne.MessageSent:this.handleMessageSent(e.payload);break;case ne.MessageAbort:this.handleMessageAbort(e.payload);break;case ne.MessageTextStart:this.handleMessageTextStart(e.payload);break;case ne.MessageTextDelta:this.handleMessageTextDelta(e.payload);break;case ne.MessageTextEnd:this.handleMessageTextEnd(e.payload);break;case ne.MessageReasoningStart:this.handleMessageReasoningStart(e.payload);break;case ne.MessageReasoningDelta:this.handleMessageReasoningDelta(e.payload);break;case ne.MessageReasoningEnd:this.handleMessageReasoningEnd(e.payload);break;case ne.MessageToolCallStart:this.handleMessageToolCallStart(e.payload);break;case ne.MessageToolCallArgs:this.handleMessageToolCallArgs(e.payload);break;case ne.MessageToolCallArgsDelta:this.handleMessageToolCallArgsDelta(e.payload);break;case ne.MessageToolCallEnd:this.handleMessageToolCallEnd(e.payload);break;case ne.MessageToolCallResult:this.handleMessageToolCallResult(e.payload);break;case ne.RunStarted:this.handleRunStarted(e.payload);break;case ne.RunFinished:this.handleRunFinished(e.payload);break;case ne.RunError:this.handleRunError(e.payload);break;case ne.RunMetadata:this.handleRunMetadata(e.payload);break;case ne.EndpointError:this.handleEndpointError(e.payload);break}this.stateVersion!==t&&this.notifyListeners()}handleMessageSent(e){this.upsertMessage(e.message),this.setError(null)}handleMessageAbort(e){var n;const t=(n=e.messageId)==null?void 0:n.trim();if(this.clearActiveRun(),this.setError(null),this.streamingMessage&&(!t||this.streamingMessage.id===t)){const r=this.streamingMessage.id;this.upsertMessage({...this.streamingMessage,status:"final"}),this.replaceStreamingMessage(null),t?Ut(this.toolCallMessageIdByCallId,this.toolCallArgsRawByCallId,t):Ut(this.toolCallMessageIdByCallId,this.toolCallArgsRawByCallId,r)}}handleMessageTextStart(e){this.ensureStreamingMessage(e.sessionId,e.messageId,"streaming"),this.setError(null)}handleMessageTextDelta(e){if(!e.delta)return;const t=this.ensureStreamingMessage(e.sessionId,e.messageId,"streaming"),n=[...t.parts],r=n[n.length-1];(r==null?void 0:r.type)==="text"?n[n.length-1]={type:"text",text:`${r.text}${e.delta}`}:n.push({type:"text",text:e.delta}),this.replaceStreamingMessage({...t,parts:n,status:"streaming"})}handleMessageTextEnd(e){var t;((t=this.streamingMessage)==null?void 0:t.id)===e.messageId&&this.streamingMessage.status==="streaming"&&this.replaceStreamingMessage({...this.streamingMessage,status:"pending"})}handleMessageReasoningStart(e){this.ensureStreamingMessage(e.sessionId,e.messageId,"streaming")}handleMessageReasoningDelta(e){if(!e.delta)return;const t=this.ensureStreamingMessage(e.sessionId,e.messageId,"streaming"),n=[...t.parts],r=n[n.length-1];(r==null?void 0:r.type)==="reasoning"?n[n.length-1]={type:"reasoning",text:`${r.text}${e.delta}`}:n.push({type:"reasoning",text:e.delta}),this.replaceStreamingMessage({...t,parts:n,status:"streaming"})}handleMessageReasoningEnd(e){var t;(t=this.streamingMessage)==null||t.id,e.messageId}handleMessageToolCallStart(e){const t=this.resolveToolCallTargetMessage(e.sessionId,e.toolCallId,e.messageId);this.toolCallArgsRawByCallId.set(e.toolCallId,"");const n=St(t.parts,{type:"tool-invocation",toolCallId:e.toolCallId,toolName:e.toolName,state:"partial-call",args:""});this.replaceStreamingMessage({...t,parts:n,status:"streaming"}),this.setError(null)}handleMessageToolCallArgs(e){this.toolCallArgsRawByCallId.set(e.toolCallId,e.args),this.applyToolCallArgs(e.sessionId,e.toolCallId,e.args)}handleMessageToolCallArgsDelta(e){const n=`${this.toolCallArgsRawByCallId.get(e.toolCallId)??""}${e.delta}`;this.toolCallArgsRawByCallId.set(e.toolCallId,n),this.applyToolCallArgs(e.sessionId,e.toolCallId,n,e.messageId)}handleMessageToolCallEnd(e){const t=this.resolveToolCallTargetMessage(e.sessionId,e.toolCallId),n=this.toolCallArgsRawByCallId.get(e.toolCallId)??"",r=St(t.parts,{type:"tool-invocation",toolCallId:e.toolCallId,toolName:di(t.parts,e.toolCallId)??"unknown",state:"call",args:n});this.replaceStreamingMessage({...t,parts:r,status:"streaming"})}handleMessageToolCallResult(e){if(!this.updateMessageContainingToolCall(e.toolCallId,(n,r)=>{const s={type:"tool-invocation",toolCallId:e.toolCallId,toolName:r.toolName,state:"result",args:r.args,result:e.content};return St(n.parts,s)})){const n=this.resolveToolCallTargetMessage(e.sessionId,e.toolCallId),r=St(n.parts,{type:"tool-invocation",toolCallId:e.toolCallId,toolName:"unknown",state:"result",result:e.content});this.replaceStreamingMessage({...n,parts:r,status:"streaming"})}}handleRunStarted(e){this.setError(null),this.activeRun={runId:e.runId??null,sessionId:e.sessionId},this.stateVersion+=1}handleRunFinished(e){if(this.streamingMessage){const t={...this.streamingMessage,status:"final"};this.upsertMessage(t),this.replaceStreamingMessage(null),Ut(this.toolCallMessageIdByCallId,this.toolCallArgsRawByCallId,t.id)}this.setError(null),this.clearActiveRun()}handleRunError(e){if(this.streamingMessage){const t={...this.streamingMessage,status:"error"};this.upsertMessage(t),this.replaceStreamingMessage(null),Ut(this.toolCallMessageIdByCallId,this.toolCallArgsRawByCallId,t.id)}this.setError(Tb(e)),this.clearActiveRun()}handleRunMetadata(e){var n,r;const t=e.metadata;if((t==null?void 0:t.kind)==="ready"){const s=t;this.activeRun={runId:s.runId??((n=this.activeRun)==null?void 0:n.runId)??null,sessionId:s.sessionId??((r=this.activeRun)==null?void 0:r.sessionId),abortDisabledReason:s.supportsAbort===!1?s.abortDisabledReason??"Unsupported":null},this.stateVersion+=1}else(t==null?void 0:t.kind)==="final"&&this.clearActiveRun()}handleEndpointError(e){this.setError(e)}applyToolCallArgs(e,t,n,r){const s=this.resolveToolCallTargetMessage(e,t,r),i=di(s.parts,t)??"unknown",o=St(s.parts,{type:"tool-invocation",toolCallId:t,toolName:i,state:"partial-call",args:n});this.replaceStreamingMessage({...s,parts:o,status:"streaming"})}ensureStreamingMessage(e,t,n){var o;if(((o=this.streamingMessage)==null?void 0:o.id)===t){if(this.streamingMessage.status===n)return this.streamingMessage;const a={...this.streamingMessage,status:n};return this.replaceStreamingMessage(a),a}const r=this.messages.findIndex(a=>a.id===t);if(r>=0){const a=qt(this.messages[r]),l=[...this.messages];l.splice(r,1),this.messages=l,this.stateVersion+=1;const u={...a,sessionId:e,status:n};return this.replaceStreamingMessage(u),u}const s=this.streamingMessage;if(s&&s.id!==t&&s.sessionId===e&&Mb(s,t)){const a={...s,id:t,sessionId:e,status:n};return Rb(this.toolCallMessageIdByCallId,s.id,t),this.replaceStreamingMessage(a),a}const i={id:t,sessionId:e,role:Eb,status:n,parts:[],timestamp:new Date().toISOString()};return this.replaceStreamingMessage(i),i}resolveToolCallTargetMessage(e,t,n){var s;const r=(n==null?void 0:n.trim())||this.toolCallMessageIdByCallId.get(t)||((s=this.streamingMessage)==null?void 0:s.id)||`tool-${t}`;return this.toolCallMessageIdByCallId.set(t,r),this.ensureStreamingMessage(e,r,"streaming")}updateMessageContainingToolCall(e,t){if(this.streamingMessage){const n=sr(this.streamingMessage.parts,e);if(n){const r=t(this.streamingMessage,n);return this.replaceStreamingMessage({...this.streamingMessage,parts:r}),!0}}for(let n=this.messages.length-1;n>=0;n-=1){const r=this.messages[n],s=sr(r.parts,e);if(!s)continue;const i=[...this.messages];return i[n]={...r,parts:t(r,s)},this.messages=i,this.stateVersion+=1,!0}return!1}upsertMessage(e){const t=Nn(e),n=this.messages.findIndex(s=>s.id===t.id);if(n<0){this.messages=[...this.messages,t],this.stateVersion+=1;return}const r=[...this.messages];r[n]=t,this.messages=r,this.stateVersion+=1}replaceStreamingMessage(e){!e&&!this.streamingMessage||(this.streamingMessage=e?Nn(e):null,this.stateVersion+=1)}setError(e){var n,r,s,i;((n=this.error)==null?void 0:n.code)===(e==null?void 0:e.code)&&((r=this.error)==null?void 0:r.message)===(e==null?void 0:e.message)&&((s=this.error)==null?void 0:s.details)===(e==null?void 0:e.details)&&((i=this.error)==null?void 0:i.cause)===(e==null?void 0:e.cause)||(this.error=e?{...e,details:e.details?{...e.details}:void 0}:null,this.stateVersion+=1)}clearActiveRun(){this.activeRun&&(this.activeRun=null,this.stateVersion+=1)}notifyListeners(){const e=this.getSnapshot();for(const t of this.listeners)t(e)}};function Lb(e,t){const n="payload"in e?e.payload:null;return!n||typeof n!="object"||!("sessionId"in n)||typeof n.sessionId!="string"?!0:n.sessionId===t}function Nb(e){return e.parts.some(t=>t.type==="text"||t.type==="rich-text"||t.type==="reasoning"?t.text.trim().length>0:!0)}function Pb(e,t){if(typeof e=="string"){const n=e.trim();return n?{sessionId:t,message:{id:`user-${Date.now().toString(36)}`,sessionId:t,role:"user",status:"final",parts:[{type:"text",text:n}],timestamp:new Date().toISOString()}}:null}return Nb(e.message)?{...e,sessionId:e.sessionId,message:{...e.message,sessionId:e.message.sessionId||e.sessionId}}:null}function jb(e,t){return{sessionId:e,messages:t.messages,activeRun:t.activeRun}}function Db(e){const t=C.useRef();return(!t.current||t.current.sessionId!==e)&&(t.current={sessionId:e,manager:new Ab}),t.current.manager}function _b({sessionId:e,client:t,manager:n}){var p;const r=C.useSyncExternalStore(f=>n.subscribe(()=>f()),()=>n.getSnapshot(),()=>n.getSnapshot()),[s,i]=C.useState(!1);C.useEffect(()=>{i(!1)},[e]),C.useEffect(()=>{const f=t.subscribe(m=>{Lb(m,e)&&n.dispatch(m)});return()=>{f(),t.stop()}},[t,n,e]);const o=r.streamingMessage?[...r.messages,r.streamingMessage]:r.messages,a=((p=r.activeRun)==null?void 0:p.runId)??null,l=!!r.activeRun;return{snapshot:r,visibleMessages:o,activeRunId:a,isRunning:l,isSending:s,send:async f=>{if(s||l)return;const m=Pb(f,e);if(!m)return;i(!0);const y=n.getSnapshot();await n.dispatch({type:ne.MessageSent,payload:{sessionId:e,message:m.message,metadata:m.metadata}});try{await t.send(m)}catch(b){throw n.hydrate(jb(e,y)),b}finally{i(!1)}},abort:async()=>{r.activeRun&&await t.abort({sessionId:e})},streamRun:async()=>{r.activeRun&&await t.stream({sessionId:e})}}}function hi(e){return e instanceof Error?e:new Error(String(e))}function Ob({sessionId:e,client:t,loadSeed:n,autoResumeRunningSession:r=!0}){const s=Db(e),i=_b({sessionId:e,client:t,manager:s}),[o,a]=C.useState(!0),[l,u]=C.useState(null),c=C.useRef({requestId:0,controller:null}),d=C.useCallback(async()=>{var m;(m=c.current.controller)==null||m.abort();const p=new AbortController,f=c.current.requestId+1;c.current={requestId:f,controller:p},await t.stop(),s.reset(),u(null),a(!0);try{const y=await n(e,p.signal);if(p.signal.aborted||c.current.requestId!==f)return;s.hydrate({sessionId:e,messages:y.messages,activeRun:y.status==="running"?{runId:null,sessionId:e,abortDisabledReason:null}:null}),u(null),a(!1),y.status==="running"&&r&&t.stream({sessionId:e}).catch(b=>{c.current.requestId===f&&u(hi(b))})}catch(y){if(p.signal.aborted||c.current.requestId!==f)return;u(hi(y)),a(!1)}finally{c.current.controller===p&&(c.current.controller=null)}},[r,t,n,s,e]);return C.useEffect(()=>(d(),()=>{var p;(p=c.current.controller)==null||p.abort(),c.current.controller=null}),[d]),{...i,isHydrating:o,hydrateError:l,reloadSeed:d}}const Fb=new Set(["off","minimal","low","medium","high","adaptive","xhigh"]);function zb(e){if(typeof e=="string")return e;try{return JSON.stringify(e??{})}catch{return String(e??"")}}function Pe(e){if(typeof e!="string")return null;const t=e.trim();return t.length>0?t:null}function an(e){const{metadata:t}=e;return!t||typeof t!="object"||Array.isArray(t)?null:t}function Bb(e){const t=an(e);return t?Pe(t.preferred_model)??Pe(t.preferredModel)??Pe(t.model):null}function $b(e){const t=an(e);if(!t)return null;const n=Pe(t.preferred_thinking)??Pe(t.thinking)??Pe(t.thinking_level)??Pe(t.thinkingLevel);if(!n)return null;const r=n.toLowerCase();return Fb.has(r)?r:null}function Ub(e){const t=an(e);return t?Pe(t.label):null}function Kb(e){const t=an(e);return t?Pe(t.session_type)??Pe(t.sessionType)??"native":"native"}function Hb(e){return e.state==="result"?oe.RESULT:e.state==="partial-call"?oe.PARTIAL_CALL:oe.CALL}function Vb(e){const t=[];for(const n of e){if(n.type==="text"){t.push({type:"text",text:n.text});continue}if(n.type==="rich-text"){t.push({type:"text",text:n.text});continue}if(n.type==="reasoning"){t.push({type:"reasoning",reasoning:n.text,details:[]});continue}if(n.type==="source"){t.push({type:"source",source:{sourceType:"url",id:n.url??n.title??Math.random().toString(36).slice(2,8),url:n.url??"",...n.title?{title:n.title}:{}}});continue}if(n.type==="file"&&n.contentBase64){t.push({type:"file",mimeType:n.mimeType??"application/octet-stream",data:n.contentBase64});continue}if(n.type==="step-start"){t.push({type:"step-start"});continue}n.type==="tool-invocation"&&t.push({type:"tool-invocation",toolInvocation:{status:Hb(n),toolCallId:n.toolCallId??`${n.toolName}-${Math.random().toString(36).slice(2,8)}`,toolName:n.toolName,args:zb(n.args),result:n.result}})}return t}function qb(e){return e==="service"?"system":e==="tool"?"assistant":e}function Wb(e){return{id:e.id,role:qb(e.role),parts:Vb(e.parts),meta:{source:"stream",status:e.status,sessionKey:e.sessionId,timestamp:e.timestamp}}}function Gb(e){return console.log("[adaptNcpMessagesToUiMessages]",{messages:e}),e.map(Wb)}function Qb(e){const t=Ub(e),n=Bb(e);return{key:e.sessionId,createdAt:e.updatedAt,updatedAt:e.updatedAt,...t?{label:t}:{},...n?{preferredModel:n}:{},sessionType:Kb(e),sessionTypeMutable:!1,messageCount:e.messageCount}}function Xb(e){return e.map(Qb)}function Yb(e){const t=new Map;for(const r of e.summaries)r.status==="running"&&t.set(r.sessionId,"running");const n=Pe(e.activeSessionId);return e.isLocallyRunning&&n&&t.set(n,"running"),t}function fi(){return`ncp-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function Jb(){return bl({queryKey:["ncp-session-types"],queryFn:$l,staleTime:1e4,retry:!1})}function Zb(e,t){const n=t.trim().toLowerCase();return n?e.filter(r=>r.key.toLowerCase().includes(n)):e}function eS(e){var g,v,w;const t=Ii(),n=Ti(),r=Ul({limit:200}),s=Jb(),i=Ri("skill"),o=(t.isFetched||t.isSuccess)&&(n.isFetched||n.isSuccess),a=C.useMemo(()=>{const T=Ai({meta:n.data,config:t.data,onlyConfigured:!0}),A=new Set,k=[];for(const N of T)for(const F of N.models){const O=Li(N.prefix,F);!O||A.has(O)||(A.add(O),k.push({value:O,modelLabel:F,providerLabel:N.displayName,thinkingCapability:Ni(N.modelThinking,F,N.aliases)}))}return k.sort((N,F)=>{const O=N.providerLabel.localeCompare(F.providerLabel);return O!==0?O:N.modelLabel.localeCompare(F.modelLabel)})},[n.data,t.data]),l=C.useMemo(()=>{var T;return((T=r.data)==null?void 0:T.sessions)??[]},[(g=r.data)==null?void 0:g.sessions]),u=C.useMemo(()=>Xb(l),[l]),c=C.useMemo(()=>Zb(u,e.query),[u,e.query]),d=C.useMemo(()=>u.find(T=>T.key===e.selectedSessionKey)??null,[u,e.selectedSessionKey]),p=C.useMemo(()=>l.find(T=>T.sessionId===e.selectedSessionKey)??null,[e.selectedSessionKey,l]),f=C.useMemo(()=>{var T;return((T=i.data)==null?void 0:T.records)??[]},[(v=i.data)==null?void 0:v.records]),m=C.useMemo(()=>p?$b(p):null,[p]),y=_i({selectedSession:d,selectedSessionKey:e.selectedSessionKey,pendingSessionType:e.pendingSessionType,setPendingSessionType:e.setPendingSessionType,sessionTypesData:s.data}),b=C.useMemo(()=>ji({sessions:u,selectedSessionKey:e.selectedSessionKey,sessionType:y.selectedSessionType}),[u,e.selectedSessionKey,y.selectedSessionType]);return Di({modelOptions:a,selectedSessionKey:e.selectedSessionKey,selectedSessionExists:!!d,selectedSessionPreferredModel:d==null?void 0:d.preferredModel,fallbackPreferredModel:b,defaultModel:(w=t.data)==null?void 0:w.agents.defaults.model,setSelectedModel:e.setSelectedModel}),{configQuery:t,configMetaQuery:n,sessionsQuery:r,sessionTypesQuery:s,installedSkillsQuery:i,isProviderStateResolved:o,modelOptions:a,sessionSummaries:l,sessions:c,skillRecords:f,selectedSession:d,selectedSessionThinkingLevel:m,...y}}class tS{constructor(t,n,r){this.uiManager=t,this.streamActionsManager=n,this.getDraftSessionId=r,this.sessionPreferenceSync=new Sa(Kl),this.hasSnapshotChanges=s=>{const i=K.getState().snapshot;for(const[o,a]of Object.entries(s))if(!Object.is(i[o],a))return!0;return!1},this.resolveUpdateValue=(s,i)=>typeof i=="function"?i(s):i,this.isSameStringArray=(s,i)=>s.length===i.length&&s.every((o,a)=>o===i[a]),this.syncComposerSnapshot=s=>{K.getState().setSnapshot({composerNodes:s,draft:ua(s),selectedSkills:ca(s)})},this.syncSnapshot=s=>{if(this.hasSnapshotChanges(s)&&(K.getState().setSnapshot(s),Object.prototype.hasOwnProperty.call(s,"modelOptions")||Object.prototype.hasOwnProperty.call(s,"selectedModel")||Object.prototype.hasOwnProperty.call(s,"selectedThinkingLevel"))){const{selectedModel:i}=K.getState().snapshot;this.reconcileThinkingForModel(i)}},this.setDraft=s=>{const i=K.getState().snapshot.draft,o=this.resolveUpdateValue(i,s);o!==i&&this.syncComposerSnapshot(la(o))},this.setComposerNodes=s=>{const i=K.getState().snapshot.composerNodes,o=this.resolveUpdateValue(i,s);Object.is(o,i)||this.syncComposerSnapshot(o)},this.setPendingSessionType=s=>{const i=K.getState().snapshot.pendingSessionType,o=this.resolveUpdateValue(i,s);o!==i&&K.getState().setSnapshot({pendingSessionType:o})},this.send=async()=>{const s=K.getState().snapshot,i=se.getState().snapshot,o=s.draft.trim();if(!o)return;const{selectedSkills:a,composerNodes:l}=s,u=i.selectedSessionKey??this.getDraftSessionId();i.selectedSessionKey||this.uiManager.goToSession(u,{replace:!0}),this.setComposerNodes(Dr()),await this.streamActionsManager.sendMessage({message:o,sessionKey:u,agentId:i.selectedAgentId,sessionType:s.selectedSessionType,model:s.selectedModel||void 0,thinkingLevel:s.selectedThinkingLevel??void 0,stopSupported:!0,requestedSkills:a,restoreDraftOnError:!0,composerNodes:l})},this.stop=async()=>{await this.streamActionsManager.stopCurrentRun()},this.goToProviders=()=>{this.uiManager.goToProviders()},this.setSelectedModel=s=>{const i=K.getState().snapshot.selectedModel,o=this.resolveUpdateValue(i,s);o!==i&&(K.getState().setSnapshot({selectedModel:o}),this.reconcileThinkingForModel(o))},this.setSelectedThinkingLevel=s=>{const i=K.getState().snapshot.selectedThinkingLevel,o=this.resolveUpdateValue(i,s);o!==i&&K.getState().setSnapshot({selectedThinkingLevel:o})},this.selectSessionType=s=>{const i=He(s);K.getState().setSnapshot({selectedSessionType:i,pendingSessionType:i})},this.setSelectedSkills=s=>{const i=K.getState().snapshot,{selectedSkills:o}=i,a=this.resolveUpdateValue(o,s);this.isSameStringArray(a,o)||this.syncComposerSnapshot(da(i.composerNodes,a,i.skillRecords))},this.selectModel=s=>{this.setSelectedModel(s),this.sessionPreferenceSync.syncSelectedSessionPreferences()},this.selectThinkingLevel=s=>{this.setSelectedThinkingLevel(s),this.sessionPreferenceSync.syncSelectedSessionPreferences()},this.selectSkills=s=>{this.setSelectedSkills(s)}}resolveThinkingForModel(t,n){const r=t==null?void 0:t.thinkingCapability;return!r||r.supported.length===0?null:n==="off"?"off":n&&r.supported.includes(n)?n:r.default&&r.supported.includes(r.default)?r.default:"off"}reconcileThinkingForModel(t){const n=K.getState().snapshot,r=n.modelOptions.find(o=>o.value===t),{selectedThinkingLevel:s}=n,i=this.resolveThinkingForModel(r,s);i!==s&&K.getState().setSnapshot({selectedThinkingLevel:i})}}const nS=async()=>{};class rS{constructor(t,n,r){this.uiManager=t,this.sessionListManager=n,this.streamActionsManager=r,this.actions={refetchSessions:nS},this.bindActions=s=>{this.actions={...this.actions,...s}},this.hasSnapshotChanges=s=>{const i=Ve.getState().snapshot;for(const[o,a]of Object.entries(s))if(!Object.is(i[o],a))return!0;return!1},this.syncSnapshot=s=>{this.hasSnapshotChanges(s)&&Ve.getState().setSnapshot(s)},this.deleteSession=()=>{this.deleteCurrentSession()},this.createSession=()=>{this.sessionListManager.createSession()},this.goToProviders=()=>{this.uiManager.goToProviders()},this.deleteCurrentSession=async()=>{const{snapshot:{selectedSessionKey:s}}=se.getState();if(!(!s||!await this.uiManager.confirm({title:R("chatDeleteSessionConfirm"),variant:"destructive",confirmLabel:R("delete")}))){Ve.getState().setSnapshot({isDeletePending:!0});try{await Hl(s),this.streamActionsManager.resetStreamState(),se.getState().setSnapshot({selectedSessionKey:null}),this.uiManager.goToChatRoot({replace:!0}),await this.actions.refetchSessions()}finally{Ve.getState().setSnapshot({isDeletePending:!1})}}}}}class sS{constructor(){this.chatUiManager=new Ca,this.chatStreamActionsManager=new wa,this.chatSessionListManager=new va(this.chatUiManager,this.chatStreamActionsManager),this.chatInputManager=new tS(this.chatUiManager,this.chatStreamActionsManager,()=>this.getDraftSessionId()),this.chatRunStatusManager=new ka,this.chatThreadManager=new rS(this.chatUiManager,this.chatSessionListManager,this.chatStreamActionsManager),this.draftSessionId="",this.setDraftSessionId=t=>{this.draftSessionId=t}}getDraftSessionId(){return this.draftSessionId}}function iS(){return(e,t)=>fetch(e,{credentials:"include",...t})}function oS(e){var r,s,i;const t={};(r=e.model)!=null&&r.trim()&&(t.model=e.model.trim(),t.preferred_model=e.model.trim()),(s=e.thinkingLevel)!=null&&s.trim()&&(t.thinking=e.thinkingLevel.trim(),t.preferred_thinking=e.thinkingLevel.trim()),(i=e.sessionType)!=null&&i.trim()&&(t.session_type=e.sessionType.trim());const n=Ta(e.requestedSkills);return n.length>0&&(t.requested_skills=n),t}function aS(e){return e instanceof Error?e.message.includes("ncp session not found:"):!1}function lS({view:e}){var Xe,Ye,he;const[t]=C.useState(()=>new sS),[n,r]=C.useState(()=>fi()),s=se(H=>H.snapshot.query),i=se(H=>H.snapshot.selectedSessionKey),o=se(H=>H.snapshot.selectedAgentId),a=K(H=>H.snapshot.pendingSessionType),{confirm:l,ConfirmDialog:u}=dr(),c=cr(),d=wi(),{sessionId:p}=Ci(),f=C.useRef(null),m=C.useRef(i),y=C.useRef(null),b=C.useMemo(()=>ba(p),[p]),{sessionsQuery:g,installedSkillsQuery:v,isProviderStateResolved:w,modelOptions:T,sessionSummaries:A,sessions:k,skillRecords:N,selectedSession:F,selectedSessionThinkingLevel:O,sessionTypeOptions:I,defaultSessionType:j,selectedSessionType:_,canEditSessionType:W,sessionTypeUnavailable:z,sessionTypeUnavailableMessage:P}=eS({query:s,selectedSessionKey:i,pendingSessionType:a,setPendingSessionType:t.chatInputManager.setPendingSessionType,setSelectedModel:t.chatInputManager.setSelectedModel}),Q=g.refetch,Y=i??n,ue=C.useRef(A);C.useEffect(()=>{ue.current=A},[A]);const[ye]=C.useState(()=>new Ib({baseUrl:Vl,basePath:"/api/ncp/agent",fetchImpl:iS()})),S=C.useCallback(async(H,ve)=>{ve.throwIfAborted();let Be=null;try{Be=await ql(H,300)}catch(_e){if(!aS(_e))throw _e}ve.throwIfAborted();const xe=ue.current.find(_e=>_e.sessionId===H)??null;return{messages:(Be==null?void 0:Be.messages)??[],status:(xe==null?void 0:xe.status)==="running"?"running":"idle"}},[]),J=Ob({sessionId:Y,client:ye,loadSeed:S});C.useEffect(()=>{t.setDraftSessionId(n)},[n,t]),C.useEffect(()=>{if(i===null){const H=fi();r(H),t.setDraftSessionId(H)}},[t,i]);const ce=C.useMemo(()=>Gb(J.visibleMessages),[J.visibleMessages]),x=J.isSending||J.isRunning,de=J.isRunning,ke=J.isRunning,re=J.isRunning?null:"__preparing__",Le=((Xe=J.hydrateError)==null?void 0:Xe.message)??((Ye=J.snapshot.error)==null?void 0:Ye.message)??null,ae=J.activeRunId,Me=C.useMemo(()=>Yb({summaries:A,activeSessionId:Y,isLocallyRunning:x||!!ae}),[ae,Y,x,A]);C.useEffect(()=>{!x&&!ae||Q()},[ae,x,Q]),C.useEffect(()=>{t.chatStreamActionsManager.bind({sendMessage:async H=>{if(H.sessionKey!==Y)return;const ve=oS({model:H.model,thinkingLevel:H.thinkingLevel,sessionType:H.sessionType,requestedSkills:H.requestedSkills});try{g.refetch(),await J.send({sessionId:H.sessionKey,message:{id:`user-${Date.now().toString(36)}`,sessionId:H.sessionKey,role:"user",status:"final",parts:[{type:"text",text:H.message}],timestamp:new Date().toISOString(),...Object.keys(ve).length>0?{metadata:ve}:{}},...Object.keys(ve).length>0?{metadata:ve}:{}}),await g.refetch()}catch(Be){throw H.restoreDraftOnError&&(H.composerNodes&&H.composerNodes.length>0?t.chatInputManager.setComposerNodes(xe=>{var _e;return xe.length===1&&((_e=xe[0])==null?void 0:_e.type)==="text"&&xe[0].text.length===0?H.composerNodes??xe:xe}):t.chatInputManager.setDraft(xe=>xe.trim().length===0?H.message:xe)),Be}},stopCurrentRun:async()=>{await J.abort(),await g.refetch()},resumeRun:async H=>{H.sessionKey===Y&&await J.streamRun()},resetStreamState:()=>{m.current=null},applyHistoryMessages:()=>{}})},[Y,J,t,g]),ma({view:e,routeSessionKey:b,selectedSessionKey:i,selectedAgentId:o,setSelectedSessionKey:t.chatSessionListManager.setSelectedSessionKey,setSelectedAgentId:t.chatSessionListManager.setSelectedAgentId,selectedSessionKeyRef:m,resetStreamState:t.chatStreamActionsManager.resetStreamState,resolveAgentIdFromSessionKey:xa}),C.useEffect(()=>{t.chatUiManager.syncState({pathname:c.pathname}),t.chatUiManager.bindActions({navigate:d,confirm:l})},[l,c.pathname,d,t]);const Re=F?Oi(F):void 0,De=((he=I.find(H=>H.value===_))==null?void 0:he.label)??ut(_);return C.useEffect(()=>{t.chatThreadManager.bindActions({refetchSessions:g.refetch})},[t,g.refetch]),C.useEffect(()=>{const H=!x&&!de&&!J.isHydrating&&w&&T.length>0&&i!==y.current;t.chatInputManager.syncSnapshot({isProviderStateResolved:w,defaultSessionType:j,canStopGeneration:ke,stopDisabledReason:re,stopSupported:!0,stopReason:void 0,sendError:Le,isSending:x,modelOptions:T,sessionTypeOptions:I,selectedSessionType:_,...H?{selectedThinkingLevel:O}:{},canEditSessionType:W,sessionTypeUnavailable:z,skillRecords:N,isSkillsLoading:v.isLoading}),H&&(y.current=i),i||(y.current=null),t.chatSessionListManager.syncSnapshot({sessions:k,query:s,isLoading:g.isLoading}),t.chatRunStatusManager.syncSnapshot({sessionRunStatusByKey:Me,isLocallyRunning:x||!!ae,activeBackendRunId:ae}),t.chatThreadManager.syncSnapshot({isProviderStateResolved:w,modelOptions:T,sessionTypeUnavailable:z,sessionTypeUnavailableMessage:P,sessionTypeLabel:De,selectedSessionKey:i,sessionDisplayName:Re,canDeleteSession:!!F,threadRef:f,isHistoryLoading:J.isHydrating,uiMessages:ce,isSending:x,isAwaitingAssistantOutput:de})},[ae,J.isHydrating,W,ke,Re,De,j,v.isLoading,de,w,x,Le,T.length,T,t,s,F,i,O,_,Me,I,z,P,k,g.isLoading,N,re,f,ce]),h.jsx(zi,{presenter:t,children:h.jsx(ya,{view:e,confirmDialog:h.jsx(u,{})})})}function kS({view:e}){const t=cr();return mu(t.search)==="ncp"?h.jsx(lS,{view:e}):h.jsx(hb,{view:e})}export{kS as ChatPage};