@nextclaw/ui 0.6.15 → 0.7.0

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 (88) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +2 -0
  3. package/dist/assets/ChannelsList-DF2U-LY1.js +1 -0
  4. package/dist/assets/ChatPage-BX39y0U5.js +36 -0
  5. package/dist/assets/DocBrowser-B9ws5JL7.js +1 -0
  6. package/dist/assets/{LogoBadge-Cer0jX6t.js → LogoBadge-DvGAzkZ3.js} +1 -1
  7. package/dist/assets/MarketplacePage-DG5mHWJ8.js +49 -0
  8. package/dist/assets/ModelConfig-BL_HsOsm.js +1 -0
  9. package/dist/assets/ProvidersList-CH5z00YT.js +1 -0
  10. package/dist/assets/RuntimeConfig-BplBgkwo.js +1 -0
  11. package/dist/assets/SearchConfig-BhaI0fUf.js +1 -0
  12. package/dist/assets/{SecretsConfig-BnGVZiv4.js → SecretsConfig-CFoimOh9.js} +2 -2
  13. package/dist/assets/SessionsConfig-BHTAYn9T.js +2 -0
  14. package/dist/assets/index-BLeJkJ0o.css +1 -0
  15. package/dist/assets/index-DK4TS5ev.js +8 -0
  16. package/dist/assets/index-X5J6Mm--.js +1 -0
  17. package/dist/assets/{index-CkqvHQAt.js → index-uMsNsQX6.js} +1 -1
  18. package/dist/assets/{label-DkL14Jvl.js → label-D8ly4a2P.js} +1 -1
  19. package/dist/assets/page-layout-BSYfvwbp.js +1 -0
  20. package/dist/assets/security-config-DlKEYHNN.js +1 -0
  21. package/dist/assets/{session-run-status-tZ4ISNj-.js → session-run-status-TkIuGbVw.js} +1 -1
  22. package/dist/assets/skeleton-CWbsNx2h.js +1 -0
  23. package/dist/assets/{switch-CgbPbIX3.js → switch-Ce_g9lpN.js} +1 -1
  24. package/dist/assets/tabs-custom-Cf5azvT5.js +1 -0
  25. package/dist/assets/useConfirmDialog-A8Ek8Wu7.js +5 -0
  26. package/dist/assets/vendor-B7ozqnFC.js +412 -0
  27. package/dist/index.html +3 -3
  28. package/package.json +9 -5
  29. package/src/App.tsx +49 -27
  30. package/src/api/client.ts +1 -0
  31. package/src/api/config.ts +60 -0
  32. package/src/api/types.ts +26 -0
  33. package/src/components/auth/login-page.tsx +69 -0
  34. package/src/components/chat/ChatConversationPanel.tsx +12 -54
  35. package/src/components/chat/adapters/chat-input-bar.adapter.test.ts +80 -0
  36. package/src/components/chat/adapters/chat-input-bar.adapter.ts +329 -0
  37. package/src/components/chat/adapters/chat-message.adapter.test.ts +137 -0
  38. package/src/components/chat/adapters/chat-message.adapter.ts +200 -0
  39. package/src/components/chat/chat-input/chat-input-bar.controller.test.tsx +128 -0
  40. package/src/components/chat/chat-input/chat-input-bar.controller.ts +105 -0
  41. package/src/components/chat/containers/chat-input-bar.container.tsx +270 -0
  42. package/src/components/chat/containers/chat-message-list.container.tsx +67 -0
  43. package/src/components/chat/index.ts +1 -0
  44. package/src/components/chat/managers/chat-thread.manager.ts +3 -1
  45. package/src/components/chat/nextclaw/index.ts +23 -0
  46. package/src/components/config/runtime-security-card.tsx +276 -0
  47. package/src/components/config/security-config.tsx +12 -0
  48. package/src/components/layout/Sidebar.tsx +6 -1
  49. package/src/components/marketplace/MarketplacePage.test.tsx +170 -0
  50. package/src/components/marketplace/MarketplacePage.tsx +77 -28
  51. package/src/hooks/use-auth.ts +111 -0
  52. package/src/hooks/useMarketplace.ts +9 -0
  53. package/src/lib/i18n.ts +72 -0
  54. package/src/test/setup.ts +16 -0
  55. package/tsconfig.json +3 -2
  56. package/vite.config.ts +2 -1
  57. package/vitest.config.ts +16 -0
  58. package/dist/assets/ChannelsList-DzeVn-JC.js +0 -1
  59. package/dist/assets/ChatPage-BiFhIm1-.js +0 -36
  60. package/dist/assets/DocBrowser-By3lF9yN.js +0 -1
  61. package/dist/assets/MarketplacePage-EZxALdIz.js +0 -49
  62. package/dist/assets/ModelConfig-AchYxLft.js +0 -1
  63. package/dist/assets/ProvidersList-BsD-4kKX.js +0 -1
  64. package/dist/assets/RuntimeConfig-sKOERbFD.js +0 -1
  65. package/dist/assets/SearchConfig-DAfvDwX6.js +0 -1
  66. package/dist/assets/SessionsConfig-CzvrKDRs.js +0 -2
  67. package/dist/assets/card-BAM7vbMg.js +0 -1
  68. package/dist/assets/index-D9rRqOi8.css +0 -1
  69. package/dist/assets/index-DJZ5y7t1.js +0 -8
  70. package/dist/assets/input-BoelTiYL.js +0 -1
  71. package/dist/assets/page-layout-CERNdqzB.js +0 -1
  72. package/dist/assets/popover-uwYz3Chm.js +0 -1
  73. package/dist/assets/tabs-custom-pDyl95el.js +0 -1
  74. package/dist/assets/useConfirmDialog-DyP6Ac75.js +0 -5
  75. package/dist/assets/vendor-BKtTvQYU.js +0 -407
  76. package/src/components/chat/ChatThread.tsx +0 -402
  77. package/src/components/chat/SkillsPicker.tsx +0 -137
  78. package/src/components/chat/chat-input/ChatInputBarView.tsx +0 -82
  79. package/src/components/chat/chat-input/ChatInputBottomToolbar.tsx +0 -83
  80. package/src/components/chat/chat-input/components/ChatInputModelStateHint.tsx +0 -39
  81. package/src/components/chat/chat-input/components/ChatInputSelectedSkillsSection.tsx +0 -31
  82. package/src/components/chat/chat-input/components/ChatInputSlashPanelSection.tsx +0 -112
  83. package/src/components/chat/chat-input/components/bottom-toolbar/ChatInputAttachButton.tsx +0 -24
  84. package/src/components/chat/chat-input/components/bottom-toolbar/ChatInputModelSelector.tsx +0 -58
  85. package/src/components/chat/chat-input/components/bottom-toolbar/ChatInputSendControls.tsx +0 -56
  86. package/src/components/chat/chat-input/components/bottom-toolbar/ChatInputSessionTypeSelector.tsx +0 -40
  87. package/src/components/chat/chat-input/components/bottom-toolbar/ChatInputThinkingSelector.tsx +0 -74
  88. package/src/components/chat/chat-input/useChatInputBarController.ts +0 -322
@@ -1,36 +0,0 @@
1
- var Qs=Object.defineProperty;var Ys=(e,t,n)=>t in e?Qs(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var z=(e,t,n)=>Ys(e,typeof t!="symbol"?t+"":t,n);import{j as d,a0 as Js,r as E,F as Ot,a1 as Zs,q as Dn,A as On,B as zn,N as mn,a2 as ea,x as ta,D as na,y as ra,z as ia,a3 as gn,a4 as xn,a5 as yn,a6 as gt,a7 as Ci,a8 as sa,a9 as Ii,aa as Ti,k as Ri,ab as aa,ac as oa,ad as la,ae as ua,af as ca,ag as ha,M as da,ah as fa,ai as pa,aj as ma,p as ga,ak as pr,al as xa,am as ya,an as ba,ao as Ei,ap as Sa,aq as ka,ar as wa,E as va,as as Ca,at as Ia}from"./vendor-BKtTvQYU.js";import{u as Ai}from"./useConfirmDialog-DyP6Ac75.js";import{B as je,P as Ta,a as Ra}from"./page-layout-CERNdqzB.js";import{t as T,c as ne,i as Ea,j as Aa,k as Mi,l as Ma,T as mr,L as gr,B as Na,m as zt,S as Je,e as Ze,g as et,h as ze,f as Fn,n as La,o as ja,p as Pa,q as _a,r as Da,u as Oa,a as za,s as Fa,v as Ba,w as $a,x as Ua,y as Ha,z as Ka,A as Va,C as qa,E as Wa,F as Ga}from"./index-DJZ5y7t1.js";import{T as Bn,a as $n,b as Un,c as Hn,u as Xa,M as Qa}from"./MarketplacePage-EZxALdIz.js";import{I as Kn}from"./input-BoelTiYL.js";import{S as Ya,s as Ja,a as Za,b as eo,c as to,e as xr}from"./session-run-status-tZ4ISNj-.js";import{P as Ni,a as no,b as Li,c as ro}from"./popover-uwYz3Chm.js";import{C as io,a as so}from"./card-BAM7vbMg.js";import{b as ao,c as oo,r as lo}from"./provider-models-D3B_xWXx.js";import"./index-CkqvHQAt.js";import"./tabs-custom-pDyl95el.js";const uo={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 co({status:e,className:t}){const n=uo[e],r=e==="connected"?T("connected"):e==="disconnected"?T("disconnected"):T("connecting");return d.jsx(Bn,{delayDuration:250,children:d.jsxs($n,{children:[d.jsx(Un,{asChild:!0,children:d.jsx("span",{role:"status","aria-label":r,className:ne("inline-flex h-5 w-5 items-center justify-center",t),children:e==="connecting"?d.jsx(Js,{className:ne("h-3 w-3 animate-spin",n.dotClass)}):d.jsx("span",{className:ne(e==="connected"?"h-2 w-2 rounded-full":"",n.dotClass)})})}),d.jsx(Hn,{side:"bottom",className:"text-xs",children:r})]})})}const ji=E.createContext(null);function ho({presenter:e,children:t}){return d.jsx(ji.Provider,{value:e,children:t})}function Ft(){const e=E.useContext(ji);if(!e)throw new Error("usePresenter must be used inside ChatPresenterProvider");return e}const fo={sessionRunStatusByKey:new Map,isLocallyRunning:!1,activeBackendRunId:null},bn=Ot(e=>({snapshot:fo,setSnapshot:t=>e(n=>({snapshot:{...n.snapshot,...t}}))})),po={sessions:[],selectedSessionKey:null,selectedAgentId:"main",query:"",isLoading:!1},se=Ot(e=>({snapshot:po,setSnapshot:t=>e(n=>({snapshot:{...n.snapshot,...t}}))}));function mo(e){const t=new Date,n=new Date(t.getFullYear(),t.getMonth(),t.getDate()).getTime(),r=n-864e5,i=n-7*864e5,s=[],a=[],o=[],l=[];for(const h of e){const c=new Date(h.updatedAt).getTime();c>=n?s.push(h):c>=r?a.push(h):c>=i?o.push(h):l.push(h)}const u=[];return s.length>0&&u.push({label:T("chatSidebarToday"),sessions:s}),a.length>0&&u.push({label:T("chatSidebarYesterday"),sessions:a}),o.length>0&&u.push({label:T("chatSidebarPrevious7Days"),sessions:o}),l.length>0&&u.push({label:T("chatSidebarOlder"),sessions:l}),u}function go(e){if(e.label&&e.label.trim())return e.label.trim();const t=e.key.split(":");return t[t.length-1]||e.key}const xo=[{target:"/cron",label:()=>T("chatSidebarScheduledTasks"),icon:On},{target:"/skills",label:()=>T("chatSidebarSkills"),icon:zn}];function yo(){var f,x;const e=Ft(),t=Ea(),n=se(m=>m.snapshot),r=bn(m=>m.snapshot),i=Aa(m=>m.connectionStatus),{language:s,setLanguage:a}=Mi(),{theme:o,setTheme:l}=Ma(),u=T(((f=mr.find(m=>m.value===o))==null?void 0:f.labelKey)??"themeWarm"),h=((x=gr.find(m=>m.value===s))==null?void 0:x.label)??s,c=E.useMemo(()=>mo(n.sessions),[n.sessions]),p=m=>{s!==m&&(a(m),window.location.reload())};return d.jsxs("aside",{className:"w-[280px] shrink-0 flex flex-col h-full bg-secondary border-r border-gray-200/60",children:[d.jsx("div",{className:"px-5 pt-5 pb-3",children:d.jsx(Na,{className:"flex items-center gap-2.5 min-w-0",suffix:d.jsx(co,{status:i})})}),d.jsx("div",{className:"px-4 pb-3",children:d.jsxs(je,{variant:"primary",className:"w-full rounded-xl",onClick:e.chatSessionListManager.createSession,children:[d.jsx(Zs,{className:"h-4 w-4 mr-2"}),T("chatSidebarNewTask")]})}),d.jsx("div",{className:"px-4 pb-3",children:d.jsxs("div",{className:"relative",children:[d.jsx(Dn,{className:"h-3.5 w-3.5 absolute left-3 top-2.5 text-gray-400"}),d.jsx(Kn,{value:n.query,onChange:m=>e.chatSessionListManager.setQuery(m.target.value),placeholder:T("chatSidebarSearchPlaceholder"),className:"pl-8 h-9 rounded-lg text-xs"})]})}),d.jsx("div",{className:"px-3 pb-2",children:d.jsx("ul",{className:"space-y-0.5",children:xo.map(m=>{const S=m.icon;return d.jsx("li",{children:d.jsx(mn,{to:m.target,className:({isActive:g})=>ne("group w-full flex items-center gap-3 px-3 py-2 rounded-xl text-[13px] font-medium transition-all duration-150",g?"bg-gray-200 text-gray-900 font-semibold shadow-sm":"text-gray-600 hover:bg-gray-200/60 hover:text-gray-900"),children:({isActive:g})=>d.jsxs(d.Fragment,{children:[d.jsx(S,{className:ne("h-4 w-4 transition-colors",g?"text-gray-900":"text-gray-500 group-hover:text-gray-800")}),d.jsx("span",{children:m.label()})]})})},m.target)})})}),d.jsx("div",{className:"mx-4 border-t border-gray-200/60"}),d.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto custom-scrollbar px-3 py-2",children:n.isLoading?d.jsx("div",{className:"text-xs text-gray-500 p-3",children:T("sessionsLoading")}):c.length===0?d.jsxs("div",{className:"p-4 text-center",children:[d.jsx(ea,{className:"h-6 w-6 mx-auto mb-2 text-gray-300"}),d.jsx("div",{className:"text-xs text-gray-500",children:T("sessionsEmpty")})]}):d.jsx("div",{className:"space-y-3",children:c.map(m=>d.jsxs("div",{children:[d.jsx("div",{className:"px-2 py-1 text-[11px] font-medium text-gray-400 uppercase tracking-wider",children:m.label}),d.jsx("div",{className:"space-y-0.5",children:m.sessions.map(S=>{const g=n.selectedSessionKey===S.key,v=r.sessionRunStatusByKey.get(S.key);return d.jsxs("button",{onClick:()=>e.chatSessionListManager.selectSession(S.key),className:ne("w-full rounded-xl px-3 py-2 text-left transition-all text-[13px]",g?"bg-gray-200 text-gray-900 font-semibold shadow-sm":"text-gray-700 hover:bg-gray-200/60 hover:text-gray-900"),children:[d.jsxs("div",{className:"grid grid-cols-[minmax(0,1fr)_0.875rem] items-center gap-1.5",children:[d.jsx("span",{className:"truncate font-medium",children:go(S)}),d.jsx("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center",children:v?d.jsx(Ya,{status:v}):null})]}),d.jsxs("div",{className:"mt-0.5 text-[11px] text-gray-400 truncate",children:[S.messageCount," · ",zt(S.updatedAt)]})]},S.key)})})]},m.label))})}),d.jsxs("div",{className:"px-3 py-3 border-t border-gray-200/60 space-y-0.5",children:[d.jsx(mn,{to:"/settings",className:({isActive:m})=>ne("group w-full flex items-center gap-2.5 px-3 py-2 rounded-xl text-[13px] font-medium transition-all duration-150",m?"bg-gray-200 text-gray-900 font-semibold shadow-sm":"text-gray-600 hover:bg-gray-200/60 hover:text-gray-900"),children:({isActive:m})=>d.jsxs(d.Fragment,{children:[d.jsx(ta,{className:ne("h-4 w-4 transition-colors",m?"text-gray-900":"text-gray-500 group-hover:text-gray-800")}),d.jsx("span",{children:T("settings")})]})}),d.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:[d.jsx(na,{className:"h-4 w-4 text-gray-400"}),d.jsx("span",{children:T("docBrowserHelp")})]}),d.jsxs(Je,{value:o,onValueChange:m=>l(m),children:[d.jsxs(Ze,{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:[d.jsxs("div",{className:"flex items-center gap-2.5 min-w-0",children:[d.jsx(ra,{className:"h-4 w-4 text-gray-400"}),d.jsx("span",{children:T("theme")})]}),d.jsx("span",{className:"ml-auto text-[11px] text-gray-500",children:u})]}),d.jsx(et,{children:mr.map(m=>d.jsx(ze,{value:m.value,className:"text-xs",children:T(m.labelKey)},m.value))})]}),d.jsxs(Je,{value:s,onValueChange:m=>p(m),children:[d.jsxs(Ze,{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:[d.jsxs("div",{className:"flex items-center gap-2.5 min-w-0",children:[d.jsx(ia,{className:"h-4 w-4 text-gray-400"}),d.jsx("span",{children:T("language")})]}),d.jsx("span",{className:"ml-auto text-[11px] text-gray-500",children:h})]}),d.jsx(et,{children:gr.map(m=>d.jsx(ze,{value:m.value,className:"text-xs",children:m.label},m.value))})]})]})]})}function Pe(e){return typeof e=="function"}function Pi(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 qt=Pi(function(e){return function(n){e(this),this.message=n?n.length+` errors occurred during unsubscription:
2
- `+n.map(function(r,i){return i+1+") "+r.toString()}).join(`
3
- `):"",this.name="UnsubscriptionError",this.errors=n}});function Sn(e,t){if(e){var n=e.indexOf(t);0<=n&&e.splice(n,1)}}var Bt=(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,i,s;if(!this.closed){this.closed=!0;var a=this._parentage;if(a)if(this._parentage=null,Array.isArray(a))try{for(var o=gn(a),l=o.next();!l.done;l=o.next()){var u=l.value;u.remove(this)}}catch(m){t={error:m}}finally{try{l&&!l.done&&(n=o.return)&&n.call(o)}finally{if(t)throw t.error}}else a.remove(this);var h=this.initialTeardown;if(Pe(h))try{h()}catch(m){s=m instanceof qt?m.errors:[m]}var c=this._finalizers;if(c){this._finalizers=null;try{for(var p=gn(c),f=p.next();!f.done;f=p.next()){var x=f.value;try{yr(x)}catch(m){s=s??[],m instanceof qt?s=xn(xn([],yn(s)),yn(m.errors)):s.push(m)}}}catch(m){r={error:m}}finally{try{f&&!f.done&&(i=p.return)&&i.call(p)}finally{if(r)throw r.error}}}if(s)throw new qt(s)}},e.prototype.add=function(t){var n;if(t&&t!==this)if(this.closed)yr(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)&&Sn(n,t)},e.prototype.remove=function(t){var n=this._finalizers;n&&Sn(n,t),t instanceof e&&t._removeParent(this)},e.EMPTY=(function(){var t=new e;return t.closed=!0,t})(),e})(),_i=Bt.EMPTY;function Di(e){return e instanceof Bt||e&&"closed"in e&&Pe(e.remove)&&Pe(e.add)&&Pe(e.unsubscribe)}function yr(e){Pe(e)?e():e.unsubscribe()}var bo={Promise:void 0},So={setTimeout:function(e,t){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];return setTimeout.apply(void 0,xn([e,t],yn(n)))},clearTimeout:function(e){return clearTimeout(e)},delegate:void 0};function ko(e){So.setTimeout(function(){throw e})}function br(){}function At(e){e()}var Oi=(function(e){gt(t,e);function t(n){var r=e.call(this)||this;return r.isStopped=!1,n?(r.destination=n,Di(n)&&n.add(r)):r.destination=Co,r}return t.create=function(n,r,i){return new kn(n,r,i)},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})(Bt),wo=(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){wt(r)}},e.prototype.error=function(t){var n=this.partialObserver;if(n.error)try{n.error(t)}catch(r){wt(r)}else wt(t)},e.prototype.complete=function(){var t=this.partialObserver;if(t.complete)try{t.complete()}catch(n){wt(n)}},e})(),kn=(function(e){gt(t,e);function t(n,r,i){var s=e.call(this)||this,a;return Pe(n)||!n?a={next:n??void 0,error:r??void 0,complete:i??void 0}:a=n,s.destination=new wo(a),s}return t})(Oi);function wt(e){ko(e)}function vo(e){throw e}var Co={closed:!0,next:br,error:vo,complete:br},Io=(function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"})();function To(e){return e}function Ro(e){return e.length===0?To:e.length===1?e[0]:function(n){return e.reduce(function(r,i){return i(r)},n)}}var Nt=(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 i=this,s=Ao(t)?t:new kn(t,n,r);return At(function(){var a=i,o=a.operator,l=a.source;s.add(o?o.call(s,l):l?i._subscribe(s):i._trySubscribe(s))}),s},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=Sr(n),new n(function(i,s){var a=new kn({next:function(o){try{t(o)}catch(l){s(l),a.unsubscribe()}},error:s,complete:i});r.subscribe(a)})},e.prototype._subscribe=function(t){var n;return(n=this.source)===null||n===void 0?void 0:n.subscribe(t)},e.prototype[Io]=function(){return this},e.prototype.pipe=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return Ro(t)(this)},e.prototype.toPromise=function(t){var n=this;return t=Sr(t),new t(function(r,i){var s;n.subscribe(function(a){return s=a},function(a){return i(a)},function(){return r(s)})})},e.create=function(t){return new e(t)},e})();function Sr(e){var t;return(t=e??bo.Promise)!==null&&t!==void 0?t:Promise}function Eo(e){return e&&Pe(e.next)&&Pe(e.error)&&Pe(e.complete)}function Ao(e){return e&&e instanceof Oi||Eo(e)&&Di(e)}var Mo=Pi(function(e){return function(){e(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}}),Le=(function(e){gt(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 kr(this,this);return r.operator=n,r},t.prototype._throwIfClosed=function(){if(this.closed)throw new Mo},t.prototype.next=function(n){var r=this;At(function(){var i,s;if(r._throwIfClosed(),!r.isStopped){r.currentObservers||(r.currentObservers=Array.from(r.observers));try{for(var a=gn(r.currentObservers),o=a.next();!o.done;o=a.next()){var l=o.value;l.next(n)}}catch(u){i={error:u}}finally{try{o&&!o.done&&(s=a.return)&&s.call(a)}finally{if(i)throw i.error}}}})},t.prototype.error=function(n){var r=this;At(function(){if(r._throwIfClosed(),!r.isStopped){r.hasError=r.isStopped=!0,r.thrownError=n;for(var i=r.observers;i.length;)i.shift().error(n)}})},t.prototype.complete=function(){var n=this;At(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,i=this,s=i.hasError,a=i.isStopped,o=i.observers;return s||a?_i:(this.currentObservers=null,o.push(n),new Bt(function(){r.currentObservers=null,Sn(o,n)}))},t.prototype._checkFinalizedStatuses=function(n){var r=this,i=r.hasError,s=r.thrownError,a=r.isStopped;i?n.error(s):a&&n.complete()},t.prototype.asObservable=function(){var n=new Nt;return n.source=this,n},t.create=function(n,r){return new kr(n,r)},t})(Nt),kr=(function(e){gt(t,e);function t(n,r){var i=e.call(this)||this;return i.destination=n,i.source=r,i}return t.prototype.next=function(n){var r,i;(i=(r=this.destination)===null||r===void 0?void 0:r.next)===null||i===void 0||i.call(r,n)},t.prototype.error=function(n){var r,i;(i=(r=this.destination)===null||r===void 0?void 0:r.error)===null||i===void 0||i.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,i;return(i=(r=this.source)===null||r===void 0?void 0:r.subscribe(n))!==null&&i!==void 0?i:_i},t})(Le),We=(function(e){gt(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,i=n.thrownError,s=n._value;if(r)throw i;return this._throwIfClosed(),s},t.prototype.next=function(n){e.prototype.next.call(this,this._value=n)},t})(Le);const re=[];for(let e=0;e<256;++e)re.push((e+256).toString(16).slice(1));function No(e,t=0){return(re[e[t+0]]+re[e[t+1]]+re[e[t+2]]+re[e[t+3]]+"-"+re[e[t+4]]+re[e[t+5]]+"-"+re[e[t+6]]+re[e[t+7]]+"-"+re[e[t+8]]+re[e[t+9]]+"-"+re[e[t+10]]+re[e[t+11]]+re[e[t+12]]+re[e[t+13]]+re[e[t+14]]+re[e[t+15]]).toLowerCase()}let Wt;const Lo=new Uint8Array(16);function jo(){if(!Wt){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Wt=crypto.getRandomValues.bind(crypto)}return Wt(Lo)}const Po=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),wr={randomUUID:Po};function wn(e,t,n){var i;if(wr.randomUUID&&!e)return wr.randomUUID();e=e||{};const r=e.random??((i=e.rng)==null?void 0:i.call(e))??jo();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,No(r)}var ie=(e=>(e.CALL="call",e.RESULT="result",e.PARTIAL_CALL="partial-call",e.ERROR="error",e.CANCELLED="cancelled",e))(ie||{}),K=(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))(K||{});function _o(e){return!e||e.remoteStopCapable&&e.remoteRunId?null:e.remoteStopCapable?"__preparing__":e.remoteStopReason??""}const Do=e=>{try{return JSON.parse(e)}catch{return}},vr=e=>({toolCallId:e.id,toolName:e.function.name,args:e.function.arguments,parsedArgs:Do(e.function.arguments),status:ie.CALL});function Oo(e,t){const n={error:"tool_call_interrupted",note:"User continued before tool produced a result."};return e.map(r=>{var i;return(i=r.parts)!=null&&i.length?{...r,parts:r.parts.map(s=>{if(s.type!=="tool-invocation"||![ie.CALL,ie.PARTIAL_CALL].includes(s.toolInvocation.status))return s;let a;if(typeof s.toolInvocation.args=="string")try{a=JSON.parse(s.toolInvocation.args)}catch{return{...s,toolInvocation:{...s.toolInvocation,args:JSON.stringify({}),parsedArgs:a,status:ie.RESULT,result:{error:"invalid_args",raw:s.toolInvocation.args}}}}return{...s,toolInvocation:{...s.toolInvocation,args:s.toolInvocation.args,parsedArgs:a,status:ie.RESULT,result:n}}})}:r})}function vn(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 Cr(e){if(e instanceof Error){const n=e.message.trim();if(n)return n}return String(e??"").trim()||"Failed to send message"}function Ir(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 zo{constructor(t){z(this,"currentMessageId");z(this,"currentReasoningMessageId");z(this,"currentReasoningContent","");z(this,"currentToolCallId");z(this,"currentToolCallMessageId");z(this,"currentToolCallName");z(this,"currentToolCallArgs","");z(this,"emittedToolCallIds",new Set);this.sessionManager=t}findAssistantMessageById(t){const n=t==null?void 0:t.trim();return n?this.sessionManager.getMessages().find(i=>i.role==="assistant"&&i.id===n)??null:null}findAssistantMessageByToolCallId(t){var r;if(!t)return null;const n=this.sessionManager.getMessages();for(let i=n.length-1;i>=0;i-=1){const s=n[i];if(s.role!=="assistant")continue;if((r=s.parts)==null?void 0:r.some(o=>o.type==="tool-invocation"&&o.toolInvocation.toolCallId===t))return s}return null}findAssistantMessageForCurrentTool(t){var r;const n=this.findAssistantMessageById(this.currentToolCallMessageId);return(r=n==null?void 0:n.parts)!=null&&r.some(i=>i.type==="tool-invocation"&&i.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 i=r.toolInvocation;i.status===ie.CALL&&!this.emittedToolCallIds.has(i.toolCallId)&&(this.emittedToolCallIds.add(i.toolCallId),this.sessionManager.toolCall$.next({toolCall:{id:i.toolCallId,type:"function",function:{name:i.toolName,arguments:i.args}}}))}}handleEvent(t){switch(t.type){case K.RUN_STARTED:break;case K.TEXT_START:this.handleTextStart(t);break;case K.TEXT_DELTA:this.handleTextContent(t);break;case K.TEXT_END:this.handleTextEnd();break;case K.REASONING_START:this.handleReasoningStart(t);break;case K.REASONING_DELTA:this.handleReasoningContent(t);break;case K.REASONING_END:this.handleReasoningEnd();break;case K.TOOL_CALL_START:this.handleToolCallStart(t);break;case K.TOOL_CALL_ARGS_DELTA:this.handleToolCallArgsDelta(t);break;case K.TOOL_CALL_ARGS:this.handleToolCallArgs(t);break;case K.TOOL_CALL_END:this.handleToolCallEnd(),this.emitToolCallEvents();break;case K.TOOL_CALL_RESULT:this.handleToolCallResult(t);break}}handleTextStart(t){this.currentMessageId=t.messageId}appendTextDelta(t,n){const r=[...t.parts||[]],i=r[r.length-1];return i&&i.type==="text"?{...t,parts:[...r.slice(0,-1),{type:"text",text:`${i.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(i=>i.role==="assistant"&&i.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 s;const r=[...t.parts||[]];let i=-1;for(let a=r.length-1;a>=0;a-=1)if(((s=r[a])==null?void 0:s.type)==="reasoning"){i=a;break}return i>=0?{...t,parts:[...r.slice(0,i),{type:"reasoning",reasoning:n,details:[]},...r.slice(i+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,s=this.sessionManager.getMessages().find(a=>a.role==="assistant"&&a.id===r);s?this.sessionManager.updateMessage(this.updateReasoningPart(s,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:ie.PARTIAL_CALL,toolCallId:this.currentToolCallId,toolName:this.currentToolCallName,args:""}},r=this.sessionManager.getMessages(),i=(l=t.messageId)==null?void 0:l.trim(),s=this.findAssistantMessageById(i);if(s){this.currentToolCallMessageId=s.id;const u=s.parts.find(h=>h.type==="tool-invocation"&&h.toolInvocation.toolCallId===this.currentToolCallId);if(u&&u.type==="tool-invocation"){this.currentToolCallArgs=u.toolInvocation.args;return}this.sessionManager.updateMessage({...s,parts:[...s.parts||[],n]});return}if(i){this.currentToolCallMessageId=i,this.sessionManager.addMessages([{id:i,role:"assistant",parts:[n]}]);return}const a=this.findAssistantMessageByToolCallId(this.currentToolCallId);if(a){this.currentToolCallMessageId=a.id;const u=a.parts.find(h=>h.type==="tool-invocation"&&h.toolInvocation.toolCallId===this.currentToolCallId);this.currentToolCallArgs=(u==null?void 0:u.type)==="tool-invocation"?u.toolInvocation.args:"";return}const o=r[r.length-1];if(o&&o.role==="assistant")this.currentToolCallMessageId=o.id,this.sessionManager.updateMessage({...o,parts:[...o.parts||[],n]});else{const u=wn();this.currentToolCallMessageId=u,this.sessionManager.addMessages([{id:u,role:"assistant",parts:[n]}])}}handleToolCallArgsDelta(t){var i;if(this.currentToolCallId!==t.toolCallId)return;this.currentToolCallArgs+=t.argsDelta;const n=this.findAssistantMessageForCurrentTool(t.toolCallId);if(!n||n.role!=="assistant"||!((i=n.parts)!=null&&i.length))return;const r=[...n.parts];for(let s=r.length-1;s>=0;s--){const a=r[s];if(a.type==="tool-invocation"&&a.toolInvocation.toolCallId===t.toolCallId){let o;try{o=JSON.parse(this.currentToolCallArgs)}catch{}r[s]={...a,toolInvocation:{...a.toolInvocation,status:ie.PARTIAL_CALL,args:this.currentToolCallArgs,parsedArgs:o}};break}}this.sessionManager.updateMessage({...n,parts:r})}handleToolCallArgs(t){this.currentToolCallId===t.toolCallId&&(this.currentToolCallArgs=t.args,this.handleToolCallArgsDelta({type:K.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 i=[...r.parts||[]];for(let s=i.length-1;s>=0;s--){const a=i[s];if(a.type==="tool-invocation"&&a.toolInvocation.toolCallId===this.currentToolCallId){i[s]={...a,toolInvocation:{...vr(n),status:ie.CALL}};break}}this.sessionManager.updateMessage({...r,parts:i})}else{const i=((t=this.currentToolCallMessageId)==null?void 0:t.trim())||wn();this.sessionManager.addMessages([{id:i,role:"assistant",parts:[{type:"tool-invocation",toolInvocation:{...vr(n),status:ie.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:ie.RESULT})}}class Fo{constructor(){z(this,"disposables",[]);z(this,"addDisposable",t=>{this.disposables.push(t)});z(this,"dispose",()=>{this.disposables.forEach(t=>t()),this.disposables=[]})}}class Bo extends Fo{constructor(n=null,r){super();z(this,"_messages$",new We([]));z(this,"messages$");z(this,"threadId$",new We(null));z(this,"isAgentResponding$",new We(!1));z(this,"activeRun$",new We(null));z(this,"lastError$",new We(null));z(this,"isAwaitingResponse$",new We(!1));z(this,"runCompleted$",new Le);z(this,"runError$",new Le);z(this,"runMetadata$",new Le);z(this,"activeSubscription",null);z(this,"addMessagesEvent$",new Le);z(this,"updateMessageEvent$",new Le);z(this,"setMessagesEvent$",new Le);z(this,"toolCall$",new Le);z(this,"eventHandler",new zo(this));z(this,"runIdCounter",0);z(this,"metadataParsers");z(this,"callbacks");z(this,"getMessages",()=>this._messages$.getValue());z(this,"setMessages",n=>{this._messages$.next(n),this.setMessagesEvent$.next({messages:n})});z(this,"handleEvent",n=>{this.eventHandler.handleEvent(n)});z(this,"setCallbacks",n=>{this.callbacks=n});z(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});z(this,"addMessages",n=>{const i=[...this.getMessages()];for(const s of n){const a=i.findIndex(o=>o.id===s.id);a>=0?i[a]=s:i.push(s)}this._messages$.next(i),this.addMessagesEvent$.next({messages:n}),this.isAwaitingResponse$.getValue()&&n.some(s=>s.role==="assistant")&&this.isAwaitingResponse$.next(!1)});z(this,"removeMessages",n=>{n.length!==0&&this._messages$.next(this.getMessages().filter(r=>!n.includes(r.id)))});z(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)});z(this,"addToolResult",(n,r)=>{const i=this.getMessages().find(a=>a.parts.find(o=>o.type==="tool-invocation"&&o.toolInvocation.toolCallId===n.toolCallId));if(!i)return;const s={...i,parts:i.parts.map(a=>a.type==="tool-invocation"&&a.toolInvocation.toolCallId===n.toolCallId?{...a,toolInvocation:{...a.toolInvocation,result:n.result??void 0,status:n.status,error:n.error??void 0,cancelled:n.cancelled??void 0}}:a)};this.updateMessage(s)});z(this,"send",async n=>{(this.activeRun$.getValue()||this.activeSubscription)&&this.abortAgentRun(),this.lastError$.next(null);const r=n.message.trim();r&&(this.addMessages([{id:wn(),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}))});z(this,"resume",async n=>{var a,o;const r=(a=n.remoteRunId)==null?void 0:a.trim(),i=(o=n.sessionId)==null?void 0:o.trim();if(!r)return;const s=this.activeRun$.getValue();(s==null?void 0:s.remoteRunId)!==r&&(s||(this.lastError$.next(null),await this.runAgent({metadata:n.metadata,sessionId:i,agentId:n.agentId,stopCapable:n.stopCapable,stopReason:n.stopReason})))});z(this,"stop",async()=>{var i,s;const n=this.activeRun$.getValue();if(!n)return;const r=n.sessionId;this.abortAgentRun(),r&&await((s=(i=this.callbacks).onRunSettled)==null?void 0:s.call(i,{sourceSessionId:r}))});z(this,"handleAgentResponse",n=>{this.activeSubscription&&this.activeSubscription.unsubscribe(),this.activeSubscription=n.subscribe(r=>{var i,s,a,o,l,u,h,c,p;if(r.type===K.RUN_METADATA){const f=r,x=this.activeRun$.getValue(),m=((i=f.runId)==null?void 0:i.trim())||(x?`ui-${x.localRunId}`:"");this.metadataParsers&&x&&this.isMatchingRun(x,m)&&this.processRunMetadata(x,f.metadata),this.runMetadata$.next({runId:m,metadata:f.metadata});return}if(this.handleEvent(r),r.type===K.RUN_FINISHED){this.isAgentResponding$.next(!1),this.isAwaitingResponse$.next(!1),this.activeSubscription=null;const f=this.activeRun$.getValue(),x=((s=r.runId)==null?void 0:s.trim())||(f?`ui-${f.localRunId}`:"");if(!f||!this.isMatchingRun(f,x))return;const m=f.sessionId;this.activeRun$.next(null),m&&((o=(a=this.callbacks).onRunSettled)==null||o.call(a,{sourceSessionId:m}))}else if(r.type===K.RUN_ERROR){this.isAgentResponding$.next(!1),this.isAwaitingResponse$.next(!1),this.activeSubscription=null;const f=this.activeRun$.getValue(),x=((l=r.runId)==null?void 0:l.trim())||(f?`ui-${f.localRunId}`:""),m=vn(r.error);if(this.runError$.next({runId:x,error:r.error,isAbort:m}),!f||!this.isMatchingRun(f,x)){this.activeRun$.next(null);return}const S=f.sessionId;if(m){this.activeRun$.next(null),S&&((h=(u=this.callbacks).onRunSettled)==null||h.call(u,{sourceSessionId:S}));return}const g=Cr(r.error);this.lastError$.next(g),this.activeRun$.next(null),S&&this.addMessages([Ir(g,{sessionKey:S,status:"error"})]),(p=(c=this.callbacks).onRunError)==null||p.call(c,{error:g,sourceMessage:f.sourceMessage,restoreDraft:f.restoreDraftOnError})}})});z(this,"abortAgentRun",()=>{var n,r,i;(i=(n=this.agentProvider)==null?void 0:(r=n.agent).abortRun)==null||i.call(r),this.activeSubscription&&(this.activeSubscription.unsubscribe(),this.activeSubscription=null,this.isAgentResponding$.next(!1),this.isAwaitingResponse$.next(!1)),this.activeRun$.next(null)});z(this,"runAgent",async n=>{var a,o,l,u;if(!this.agentProvider)return;(this.activeRun$.getValue()||this.activeSubscription)&&this.abortAgentRun();const r=++this.runIdCounter,i=`ui-${r}`,s={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(s),this.isAgentResponding$.next(!0),this.isAwaitingResponse$.next(!0);try{const h=Oo(this.getMessages()),c=typeof(n==null?void 0:n.threadId)=="string"&&n.threadId.trim()?n.threadId:this.threadId$.getValue()??"",p=await this.agentProvider.agent.run({threadId:c,runId:i,messages:h,tools:this.agentProvider.getToolDefs(),context:this.agentProvider.getContexts(),...n!=null&&n.metadata?{metadata:n.metadata}:{}});this.handleAgentResponse(p)}catch(h){const c=vn(h);c?console.info("Agent run aborted"):console.error("Error running agent:",h),this.isAgentResponding$.next(!1),this.isAwaitingResponse$.next(!1);const p=this.activeRun$.getValue();if(this.activeRun$.next(null),this.runError$.next({runId:i,error:h,isAbort:c}),!c&&p){const f=Cr(h);this.lastError$.next(f),p.sessionId&&this.addMessages([Ir(f,{sessionKey:p.sessionId,status:"error"})]),(o=(a=this.callbacks).onRunError)==null||o.call(a,{error:f,sourceMessage:p.sourceMessage,restoreDraft:p.restoreDraftOnError})}else c&&(p!=null&&p.sessionId)&&((u=(l=this.callbacks).onRunSettled)==null||u.call(l,{sourceSessionId:p.sessionId}))}});z(this,"processRunMetadata",(n,r)=>{if(!this.metadataParsers)return;const i=this.metadataParsers.parseReady(r);if(i){this.applyReadyMetadata(n,i);return}const s=this.metadataParsers.parseFinal(r);s&&this.applyFinalMetadata(n,s)});z(this,"applyReadyMetadata",(n,r)=>{var s,a,o,l,u;const i={...n};(s=r.remoteRunId)!=null&&s.trim()&&(i.remoteRunId=r.remoteRunId.trim()),typeof r.stopCapable=="boolean"&&(i.remoteStopCapable=r.stopCapable),(a=r.stopReason)!=null&&a.trim()&&(i.remoteStopReason=r.stopReason.trim()),(o=r.sessionId)!=null&&o.trim()&&(i.sessionId=r.sessionId.trim(),(u=(l=this.callbacks).onSessionChanged)==null||u.call(l,i.sessionId)),this.activeRun$.next(i)});z(this,"applyFinalMetadata",(n,r)=>{var a,o,l,u;const i=n.sessionId,s=r.sessionId;s&&s!==i&&((o=(a=this.callbacks).onSessionChanged)==null||o.call(a,s)),this.activeRun$.next(null),i&&((u=(l=this.callbacks).onRunSettled)==null||u.call(l,{sourceSessionId:i,resultSessionId:s}))});z(this,"isMatchingRun",(n,r)=>r.trim()?r===`ui-${n.localRunId}`:!1);z(this,"connectToolExecutor",()=>{const n=this.toolCall$.subscribe(async({toolCall:r})=>{var s;const i=(s=this.agentProvider)==null?void 0:s.getToolExecutor(r.function.name);if(i)try{const a=JSON.parse(r.function.arguments),o=await i(a);this.addToolResult({toolCallId:r.id,result:o,status:ie.RESULT}),this.runAgent()}catch(a){console.error("[AgentChatController] handleAddToolResult error",a),this.addToolResult({toolCallId:r.id,error:a instanceof Error?a.message:String(a),status:ie.ERROR}),this.runAgent()}});return()=>n.unsubscribe()});this.agentProvider=n;const{initialMessages:i=[],metadataParsers:s,callbacks:a={}}=r||{};this.metadataParsers=s??null,this.callbacks=a,this._messages$.next(i),this.messages$=this._messages$.asObservable(),this.agentProvider&&this.addDisposable(this.connectToolExecutor())}}function $o(e,t){const n={};return(e[e.length-1]===""?[...e,""]:e).join((n.padRight?" ":"")+","+(n.padLeft===!1?"":" ")).trim()}const Uo=/^[$_\p{ID_Start}][$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,Ho=/^[$_\p{ID_Start}][-$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,Ko={};function Tr(e,t){return(Ko.jsx?Ho:Uo).test(e)}const Vo=/[ \t\n\f\r]/g;function qo(e){return typeof e=="object"?e.type==="text"?Rr(e.value):!1:Rr(e)}function Rr(e){return e.replace(Vo,"")===""}class xt{constructor(t,n,r){this.normal=n,this.property=t,r&&(this.space=r)}}xt.prototype.normal={};xt.prototype.property={};xt.prototype.space=void 0;function zi(e,t){const n={},r={};for(const i of e)Object.assign(n,i.property),Object.assign(r,i.normal);return new xt(n,r,t)}function Cn(e){return e.toLowerCase()}class pe{constructor(t,n){this.attribute=n,this.property=t}}pe.prototype.attribute="";pe.prototype.booleanish=!1;pe.prototype.boolean=!1;pe.prototype.commaOrSpaceSeparated=!1;pe.prototype.commaSeparated=!1;pe.prototype.defined=!1;pe.prototype.mustUseProperty=!1;pe.prototype.number=!1;pe.prototype.overloadedBoolean=!1;pe.prototype.property="";pe.prototype.spaceSeparated=!1;pe.prototype.space=void 0;let Wo=0;const U=Ve(),te=Ve(),In=Ve(),M=Ve(),J=Ve(),Ye=Ve(),ge=Ve();function Ve(){return 2**++Wo}const Tn=Object.freeze(Object.defineProperty({__proto__:null,boolean:U,booleanish:te,commaOrSpaceSeparated:ge,commaSeparated:Ye,number:M,overloadedBoolean:In,spaceSeparated:J},Symbol.toStringTag,{value:"Module"})),Gt=Object.keys(Tn);class Vn extends pe{constructor(t,n,r,i){let s=-1;if(super(t,n),Er(this,"space",i),typeof r=="number")for(;++s<Gt.length;){const a=Gt[s];Er(this,Gt[s],(r&Tn[a])===Tn[a])}}}Vn.prototype.defined=!0;function Er(e,t,n){n&&(e[t]=n)}function nt(e){const t={},n={};for(const[r,i]of Object.entries(e.properties)){const s=new Vn(r,e.transform(e.attributes||{},r),i,e.space);e.mustUseProperty&&e.mustUseProperty.includes(r)&&(s.mustUseProperty=!0),t[r]=s,n[Cn(r)]=r,n[Cn(s.attribute)]=r}return new xt(t,n,e.space)}const Fi=nt({properties:{ariaActiveDescendant:null,ariaAtomic:te,ariaAutoComplete:null,ariaBusy:te,ariaChecked:te,ariaColCount:M,ariaColIndex:M,ariaColSpan:M,ariaControls:J,ariaCurrent:null,ariaDescribedBy:J,ariaDetails:null,ariaDisabled:te,ariaDropEffect:J,ariaErrorMessage:null,ariaExpanded:te,ariaFlowTo:J,ariaGrabbed:te,ariaHasPopup:null,ariaHidden:te,ariaInvalid:null,ariaKeyShortcuts:null,ariaLabel:null,ariaLabelledBy:J,ariaLevel:M,ariaLive:null,ariaModal:te,ariaMultiLine:te,ariaMultiSelectable:te,ariaOrientation:null,ariaOwns:J,ariaPlaceholder:null,ariaPosInSet:M,ariaPressed:te,ariaReadOnly:te,ariaRelevant:null,ariaRequired:te,ariaRoleDescription:J,ariaRowCount:M,ariaRowIndex:M,ariaRowSpan:M,ariaSelected:te,ariaSetSize:M,ariaSort:null,ariaValueMax:M,ariaValueMin:M,ariaValueNow:M,ariaValueText:null,role:null},transform(e,t){return t==="role"?t:"aria-"+t.slice(4).toLowerCase()}});function Bi(e,t){return t in e?e[t]:t}function $i(e,t){return Bi(e,t.toLowerCase())}const Go=nt({attributes:{acceptcharset:"accept-charset",classname:"class",htmlfor:"for",httpequiv:"http-equiv"},mustUseProperty:["checked","multiple","muted","selected"],properties:{abbr:null,accept:Ye,acceptCharset:J,accessKey:J,action:null,allow:null,allowFullScreen:U,allowPaymentRequest:U,allowUserMedia:U,alt:null,as:null,async:U,autoCapitalize:null,autoComplete:J,autoFocus:U,autoPlay:U,blocking:J,capture:null,charSet:null,checked:U,cite:null,className:J,cols:M,colSpan:null,content:null,contentEditable:te,controls:U,controlsList:J,coords:M|Ye,crossOrigin:null,data:null,dateTime:null,decoding:null,default:U,defer:U,dir:null,dirName:null,disabled:U,download:In,draggable:te,encType:null,enterKeyHint:null,fetchPriority:null,form:null,formAction:null,formEncType:null,formMethod:null,formNoValidate:U,formTarget:null,headers:J,height:M,hidden:In,high:M,href:null,hrefLang:null,htmlFor:J,httpEquiv:J,id:null,imageSizes:null,imageSrcSet:null,inert:U,inputMode:null,integrity:null,is:null,isMap:U,itemId:null,itemProp:J,itemRef:J,itemScope:U,itemType:J,kind:null,label:null,lang:null,language:null,list:null,loading:null,loop:U,low:M,manifest:null,max:null,maxLength:M,media:null,method:null,min:null,minLength:M,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:M,pattern:null,ping:J,placeholder:null,playsInline:U,popover:null,popoverTarget:null,popoverTargetAction:null,poster:null,preload:null,readOnly:U,referrerPolicy:null,rel:J,required:U,reversed:U,rows:M,rowSpan:M,sandbox:J,scope:null,scoped:U,seamless:U,selected:U,shadowRootClonable:U,shadowRootDelegatesFocus:U,shadowRootMode:null,shape:null,size:M,sizes:null,slot:null,span:M,spellCheck:te,src:null,srcDoc:null,srcLang:null,srcSet:null,start:M,step:null,style:null,tabIndex:M,target:null,title:null,translate:null,type:null,typeMustMatch:U,useMap:null,value:te,width:M,wrap:null,writingSuggestions:null,align:null,aLink:null,archive:J,axis:null,background:null,bgColor:null,border:M,borderColor:null,bottomMargin:M,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:M,leftMargin:M,link:null,longDesc:null,lowSrc:null,marginHeight:M,marginWidth:M,noResize:U,noHref:U,noShade:U,noWrap:U,object:null,profile:null,prompt:null,rev:null,rightMargin:M,rules:null,scheme:null,scrolling:te,standby:null,summary:null,text:null,topMargin:M,valueType:null,version:null,vAlign:null,vLink:null,vSpace:M,allowTransparency:null,autoCorrect:null,autoSave:null,disablePictureInPicture:U,disableRemotePlayback:U,prefix:null,property:null,results:M,security:null,unselectable:null},space:"html",transform:$i}),Xo=nt({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:ge,accentHeight:M,accumulate:null,additive:null,alignmentBaseline:null,alphabetic:M,amplitude:M,arabicForm:null,ascent:M,attributeName:null,attributeType:null,azimuth:M,bandwidth:null,baselineShift:null,baseFrequency:null,baseProfile:null,bbox:null,begin:null,bias:M,by:null,calcMode:null,capHeight:M,className:J,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:M,diffuseConstant:M,direction:null,display:null,dur:null,divisor:M,dominantBaseline:null,download:U,dx:null,dy:null,edgeMode:null,editable:null,elevation:M,enableBackground:null,end:null,event:null,exponent:M,externalResourcesRequired:null,fill:null,fillOpacity:M,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:Ye,g2:Ye,glyphName:Ye,glyphOrientationHorizontal:null,glyphOrientationVertical:null,glyphRef:null,gradientTransform:null,gradientUnits:null,handler:null,hanging:M,hatchContentUnits:null,hatchUnits:null,height:null,href:null,hrefLang:null,horizAdvX:M,horizOriginX:M,horizOriginY:M,id:null,ideographic:M,imageRendering:null,initialVisibility:null,in:null,in2:null,intercept:M,k:M,k1:M,k2:M,k3:M,k4:M,kernelMatrix:ge,kernelUnitLength:null,keyPoints:null,keySplines:null,keyTimes:null,kerning:null,lang:null,lengthAdjust:null,letterSpacing:null,lightingColor:null,limitingConeAngle:M,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:M,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:M,overlineThickness:M,paintOrder:null,panose1:null,path:null,pathLength:M,patternContentUnits:null,patternTransform:null,patternUnits:null,phase:null,ping:J,pitch:null,playbackOrder:null,pointerEvents:null,points:null,pointsAtX:M,pointsAtY:M,pointsAtZ:M,preserveAlpha:null,preserveAspectRatio:null,primitiveUnits:null,propagate:null,property:ge,r:null,radius:null,referrerPolicy:null,refX:null,refY:null,rel:ge,rev:ge,renderingIntent:null,repeatCount:null,repeatDur:null,requiredExtensions:ge,requiredFeatures:ge,requiredFonts:ge,requiredFormats:ge,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:M,specularExponent:M,spreadMethod:null,spacing:null,startOffset:null,stdDeviation:null,stemh:null,stemv:null,stitchTiles:null,stopColor:null,stopOpacity:null,strikethroughPosition:M,strikethroughThickness:M,string:null,stroke:null,strokeDashArray:ge,strokeDashOffset:null,strokeLineCap:null,strokeLineJoin:null,strokeMiterLimit:M,strokeOpacity:M,strokeWidth:null,style:null,surfaceScale:M,syncBehavior:null,syncBehaviorDefault:null,syncMaster:null,syncTolerance:null,syncToleranceDefault:null,systemLanguage:ge,tabIndex:M,tableValues:null,target:null,targetX:M,targetY:M,textAnchor:null,textDecoration:null,textRendering:null,textLength:null,timelineBegin:null,title:null,transformBehavior:null,type:null,typeOf:ge,to:null,transform:null,transformOrigin:null,u1:null,u2:null,underlinePosition:M,underlineThickness:M,unicode:null,unicodeBidi:null,unicodeRange:null,unitsPerEm:M,values:null,vAlphabetic:M,vMathematical:M,vectorEffect:null,vHanging:M,vIdeographic:M,version:null,vertAdvY:M,vertOriginX:M,vertOriginY:M,viewBox:null,viewTarget:null,visibility:null,width:null,widths:null,wordSpacing:null,writingMode:null,x:null,x1:null,x2:null,xChannelSelector:null,xHeight:M,y:null,y1:null,y2:null,yChannelSelector:null,z:null,zoomAndPan:null},space:"svg",transform:Bi}),Ui=nt({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()}}),Hi=nt({attributes:{xmlnsxlink:"xmlns:xlink"},properties:{xmlnsXLink:null,xmlns:null},space:"xmlns",transform:$i}),Ki=nt({properties:{xmlBase:null,xmlLang:null,xmlSpace:null},space:"xml",transform(e,t){return"xml:"+t.slice(3).toLowerCase()}}),Qo={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"},Yo=/[A-Z]/g,Ar=/-[a-z]/g,Jo=/^data[-\w.:]+$/i;function Zo(e,t){const n=Cn(t);let r=t,i=pe;if(n in e.normal)return e.property[e.normal[n]];if(n.length>4&&n.slice(0,4)==="data"&&Jo.test(t)){if(t.charAt(4)==="-"){const s=t.slice(5).replace(Ar,tl);r="data"+s.charAt(0).toUpperCase()+s.slice(1)}else{const s=t.slice(4);if(!Ar.test(s)){let a=s.replace(Yo,el);a.charAt(0)!=="-"&&(a="-"+a),t="data"+a}}i=Vn}return new i(r,t)}function el(e){return"-"+e.toLowerCase()}function tl(e){return e.charAt(1).toUpperCase()}const nl=zi([Fi,Go,Ui,Hi,Ki],"html"),qn=zi([Fi,Xo,Ui,Hi,Ki],"svg");function rl(e){return e.join(" ").trim()}var Ge={},Xt,Mr;function il(){if(Mr)return Xt;Mr=1;var e=/\/\*[^*]*\*+([^/*][^*]*\*+)*\//g,t=/\n/g,n=/^\s*/,r=/^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/,i=/^:\s*/,s=/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^)]*?\)|[^};])+)/,a=/^[;\s]*/,o=/^\s+|\s+$/g,l=`
4
- `,u="/",h="*",c="",p="comment",f="declaration";function x(S,g){if(typeof S!="string")throw new TypeError("First argument must be a string");if(!S)return[];g=g||{};var v=1,k=1;function R(D){var L=D.match(t);L&&(v+=L.length);var G=D.lastIndexOf(l);k=~G?D.length-G:k+D.length}function A(){var D={line:v,column:k};return function(L){return L.position=new C(D),B(),L}}function C(D){this.start=D,this.end={line:v,column:k},this.source=g.source}C.prototype.content=S;function P(D){var L=new Error(g.source+":"+v+":"+k+": "+D);if(L.reason=D,L.filename=g.source,L.line=v,L.column=k,L.source=S,!g.silent)throw L}function F(D){var L=D.exec(S);if(L){var G=L[0];return R(G),S=S.slice(G.length),L}}function B(){F(n)}function w(D){var L;for(D=D||[];L=j();)L!==!1&&D.push(L);return D}function j(){var D=A();if(!(u!=S.charAt(0)||h!=S.charAt(1))){for(var L=2;c!=S.charAt(L)&&(h!=S.charAt(L)||u!=S.charAt(L+1));)++L;if(L+=2,c===S.charAt(L-1))return P("End of comment missing");var G=S.slice(2,L-2);return k+=2,R(G),S=S.slice(L),k+=2,D({type:p,comment:G})}}function _(){var D=A(),L=F(r);if(L){if(j(),!F(i))return P("property missing ':'");var G=F(s),Y=D({type:f,property:m(L[0].replace(e,c)),value:G?m(G[0].replace(e,c)):c});return F(a),Y}}function W(){var D=[];w(D);for(var L;L=_();)L!==!1&&(D.push(L),w(D));return D}return B(),W()}function m(S){return S?S.replace(o,c):c}return Xt=x,Xt}var Nr;function sl(){if(Nr)return Ge;Nr=1;var e=Ge&&Ge.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(Ge,"__esModule",{value:!0}),Ge.default=n;const t=e(il());function n(r,i){let s=null;if(!r||typeof r!="string")return s;const a=(0,t.default)(r),o=typeof i=="function";return a.forEach(l=>{if(l.type!=="declaration")return;const{property:u,value:h}=l;o?i(u,h,l):h&&(s=s||{},s[u]=h)}),s}return Ge}var at={},Lr;function al(){if(Lr)return at;Lr=1,Object.defineProperty(at,"__esModule",{value:!0}),at.camelCase=void 0;var e=/^--[a-zA-Z0-9_-]+$/,t=/-([a-z])/g,n=/^[^-]+$/,r=/^-(webkit|moz|ms|o|khtml)-/,i=/^-(ms)-/,s=function(u){return!u||n.test(u)||e.test(u)},a=function(u,h){return h.toUpperCase()},o=function(u,h){return"".concat(h,"-")},l=function(u,h){return h===void 0&&(h={}),s(u)?u:(u=u.toLowerCase(),h.reactCompat?u=u.replace(i,o):u=u.replace(r,o),u.replace(t,a))};return at.camelCase=l,at}var ot,jr;function ol(){if(jr)return ot;jr=1;var e=ot&&ot.__importDefault||function(i){return i&&i.__esModule?i:{default:i}},t=e(sl()),n=al();function r(i,s){var a={};return!i||typeof i!="string"||(0,t.default)(i,function(o,l){o&&l&&(a[(0,n.camelCase)(o,s)]=l)}),a}return r.default=r,ot=r,ot}var ll=ol();const ul=Ci(ll),Vi=qi("end"),Wn=qi("start");function qi(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 cl(e){const t=Wn(e),n=Vi(e);if(t&&n)return{start:t,end:n}}function ht(e){return!e||typeof e!="object"?"":"position"in e||"type"in e?Pr(e.position):"start"in e||"end"in e?Pr(e):"line"in e||"column"in e?Rn(e):""}function Rn(e){return _r(e&&e.line)+":"+_r(e&&e.column)}function Pr(e){return Rn(e&&e.start)+"-"+Rn(e&&e.end)}function _r(e){return e&&typeof e=="number"?e:1}class oe extends Error{constructor(t,n,r){super(),typeof n=="string"&&(r=n,n=void 0);let i="",s={},a=!1;if(n&&("line"in n&&"column"in n?s={place:n}:"start"in n&&"end"in n?s={place:n}:"type"in n?s={ancestors:[n],place:n.position}:s={...n}),typeof t=="string"?i=t:!s.cause&&t&&(a=!0,i=t.message,s.cause=t),!s.ruleId&&!s.source&&typeof r=="string"){const l=r.indexOf(":");l===-1?s.ruleId=r:(s.source=r.slice(0,l),s.ruleId=r.slice(l+1))}if(!s.place&&s.ancestors&&s.ancestors){const l=s.ancestors[s.ancestors.length-1];l&&(s.place=l.position)}const o=s.place&&"start"in s.place?s.place.start:s.place;this.ancestors=s.ancestors||void 0,this.cause=s.cause||void 0,this.column=o?o.column:void 0,this.fatal=void 0,this.file="",this.message=i,this.line=o?o.line:void 0,this.name=ht(s.place)||"1:1",this.place=s.place||void 0,this.reason=this.message,this.ruleId=s.ruleId||void 0,this.source=s.source||void 0,this.stack=a&&s.cause&&typeof s.cause.stack=="string"?s.cause.stack:"",this.actual=void 0,this.expected=void 0,this.note=void 0,this.url=void 0}}oe.prototype.file="";oe.prototype.name="";oe.prototype.reason="";oe.prototype.message="";oe.prototype.stack="";oe.prototype.column=void 0;oe.prototype.line=void 0;oe.prototype.ancestors=void 0;oe.prototype.cause=void 0;oe.prototype.fatal=void 0;oe.prototype.place=void 0;oe.prototype.ruleId=void 0;oe.prototype.source=void 0;const Gn={}.hasOwnProperty,hl=new Map,dl=/[A-Z]/g,fl=new Set(["table","tbody","thead","tfoot","tr"]),pl=new Set(["td","th"]),Wi="https://github.com/syntax-tree/hast-util-to-jsx-runtime";function ml(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=vl(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=wl(n,t.jsx,t.jsxs)}const i={Fragment:t.Fragment,ancestors:[],components:t.components||{},create:r,elementAttributeNameCase:t.elementAttributeNameCase||"react",evaluater:t.createEvaluater?t.createEvaluater():void 0,filePath:n,ignoreInvalidStyle:t.ignoreInvalidStyle||!1,passKeys:t.passKeys!==!1,passNode:t.passNode||!1,schema:t.space==="svg"?qn:nl,stylePropertyNameCase:t.stylePropertyNameCase||"dom",tableCellAlignToStyle:t.tableCellAlignToStyle!==!1},s=Gi(i,e,void 0);return s&&typeof s!="string"?s:i.create(e,i.Fragment,{children:s||void 0},void 0)}function Gi(e,t,n){if(t.type==="element")return gl(e,t,n);if(t.type==="mdxFlowExpression"||t.type==="mdxTextExpression")return xl(e,t);if(t.type==="mdxJsxFlowElement"||t.type==="mdxJsxTextElement")return bl(e,t,n);if(t.type==="mdxjsEsm")return yl(e,t);if(t.type==="root")return Sl(e,t,n);if(t.type==="text")return kl(e,t)}function gl(e,t,n){const r=e.schema;let i=r;t.tagName.toLowerCase()==="svg"&&r.space==="html"&&(i=qn,e.schema=i),e.ancestors.push(t);const s=Qi(e,t.tagName,!1),a=Cl(e,t);let o=Qn(e,t);return fl.has(t.tagName)&&(o=o.filter(function(l){return typeof l=="string"?!qo(l):!0})),Xi(e,a,s,t),Xn(a,o),e.ancestors.pop(),e.schema=r,e.create(t,s,a,n)}function xl(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)}pt(e,t.position)}function yl(e,t){if(t.data&&t.data.estree&&e.evaluater)return e.evaluater.evaluateProgram(t.data.estree);pt(e,t.position)}function bl(e,t,n){const r=e.schema;let i=r;t.name==="svg"&&r.space==="html"&&(i=qn,e.schema=i),e.ancestors.push(t);const s=t.name===null?e.Fragment:Qi(e,t.name,!0),a=Il(e,t),o=Qn(e,t);return Xi(e,a,s,t),Xn(a,o),e.ancestors.pop(),e.schema=r,e.create(t,s,a,n)}function Sl(e,t,n){const r={};return Xn(r,Qn(e,t)),e.create(t,e.Fragment,r,n)}function kl(e,t){return t.value}function Xi(e,t,n,r){typeof n!="string"&&n!==e.Fragment&&e.passNode&&(t.node=r)}function Xn(e,t){if(t.length>0){const n=t.length>1?t:t[0];n&&(e.children=n)}}function wl(e,t,n){return r;function r(i,s,a,o){const u=Array.isArray(a.children)?n:t;return o?u(s,a,o):u(s,a)}}function vl(e,t){return n;function n(r,i,s,a){const o=Array.isArray(s.children),l=Wn(r);return t(i,s,a,o,{columnNumber:l?l.column-1:void 0,fileName:e,lineNumber:l?l.line:void 0},void 0)}}function Cl(e,t){const n={};let r,i;for(i in t.properties)if(i!=="children"&&Gn.call(t.properties,i)){const s=Tl(e,i,t.properties[i]);if(s){const[a,o]=s;e.tableCellAlignToStyle&&a==="align"&&typeof o=="string"&&pl.has(t.tagName)?r=o:n[a]=o}}if(r){const s=n.style||(n.style={});s[e.stylePropertyNameCase==="css"?"text-align":"textAlign"]=r}return n}function Il(e,t){const n={};for(const r of t.attributes)if(r.type==="mdxJsxExpressionAttribute")if(r.data&&r.data.estree&&e.evaluater){const s=r.data.estree.body[0];s.type;const a=s.expression;a.type;const o=a.properties[0];o.type,Object.assign(n,e.evaluater.evaluateExpression(o.argument))}else pt(e,t.position);else{const i=r.name;let s;if(r.value&&typeof r.value=="object")if(r.value.data&&r.value.data.estree&&e.evaluater){const o=r.value.data.estree.body[0];o.type,s=e.evaluater.evaluateExpression(o.expression)}else pt(e,t.position);else s=r.value===null?!0:r.value;n[i]=s}return n}function Qn(e,t){const n=[];let r=-1;const i=e.passKeys?new Map:hl;for(;++r<t.children.length;){const s=t.children[r];let a;if(e.passKeys){const l=s.type==="element"?s.tagName:s.type==="mdxJsxFlowElement"||s.type==="mdxJsxTextElement"?s.name:void 0;if(l){const u=i.get(l)||0;a=l+"-"+u,i.set(l,u+1)}}const o=Gi(e,s,a);o!==void 0&&n.push(o)}return n}function Tl(e,t,n){const r=Zo(e.schema,t);if(!(n==null||typeof n=="number"&&Number.isNaN(n))){if(Array.isArray(n)&&(n=r.commaSeparated?$o(n):rl(n)),r.property==="style"){let i=typeof n=="object"?n:Rl(e,String(n));return e.stylePropertyNameCase==="css"&&(i=El(i)),["style",i]}return[e.elementAttributeNameCase==="react"&&r.space?Qo[r.property]||r.property:r.attribute,n]}}function Rl(e,t){try{return ul(t,{reactCompat:!0})}catch(n){if(e.ignoreInvalidStyle)return{};const r=n,i=new oe("Cannot parse `style` attribute",{ancestors:e.ancestors,cause:r,ruleId:"style",source:"hast-util-to-jsx-runtime"});throw i.file=e.filePath||void 0,i.url=Wi+"#cannot-parse-style-attribute",i}}function Qi(e,t,n){let r;if(!n)r={type:"Literal",value:t};else if(t.includes(".")){const i=t.split(".");let s=-1,a;for(;++s<i.length;){const o=Tr(i[s])?{type:"Identifier",name:i[s]}:{type:"Literal",value:i[s]};a=a?{type:"MemberExpression",object:a,property:o,computed:!!(s&&o.type==="Literal"),optional:!1}:o}r=a}else r=Tr(t)&&!/^[a-z]/.test(t)?{type:"Identifier",name:t}:{type:"Literal",value:t};if(r.type==="Literal"){const i=r.value;return Gn.call(e.components,i)?e.components[i]:i}if(e.evaluater)return e.evaluater.evaluateExpression(r);pt(e)}function pt(e,t){const n=new oe("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=Wi+"#cannot-handle-mdx-estrees-without-createevaluater",n}function El(e){const t={};let n;for(n in e)Gn.call(e,n)&&(t[Al(n)]=e[n]);return t}function Al(e){let t=e.replace(dl,Ml);return t.slice(0,3)==="ms-"&&(t="-"+t),t}function Ml(e){return"-"+e.toLowerCase()}const Qt={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"]},Nl={};function Yn(e,t){const n=Nl,r=typeof n.includeImageAlt=="boolean"?n.includeImageAlt:!0,i=typeof n.includeHtml=="boolean"?n.includeHtml:!0;return Yi(e,r,i)}function Yi(e,t,n){if(Ll(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 Dr(e.children,t,n)}return Array.isArray(e)?Dr(e,t,n):""}function Dr(e,t,n){const r=[];let i=-1;for(;++i<e.length;)r[i]=Yi(e[i],t,n);return r.join("")}function Ll(e){return!!(e&&typeof e=="object")}const Or=document.createElement("i");function Jn(e){const t="&"+e+";";Or.innerHTML=t;const n=Or.textContent;return n.charCodeAt(n.length-1)===59&&e!=="semi"||n===t?!1:n}function xe(e,t,n,r){const i=e.length;let s=0,a;if(t<0?t=-t>i?0:i+t:t=t>i?i:t,n=n>0?n:0,r.length<1e4)a=Array.from(r),a.unshift(t,n),e.splice(...a);else for(n&&e.splice(t,n);s<r.length;)a=r.slice(s,s+1e4),a.unshift(t,0),e.splice(...a),s+=1e4,t+=1e4}function Se(e,t){return e.length>0?(xe(e,e.length,0,t),e):t}const zr={}.hasOwnProperty;function Ji(e){const t={};let n=-1;for(;++n<e.length;)jl(t,e[n]);return t}function jl(e,t){let n;for(n in t){const i=(zr.call(e,n)?e[n]:void 0)||(e[n]={}),s=t[n];let a;if(s)for(a in s){zr.call(i,a)||(i[a]=[]);const o=s[a];Pl(i[a],Array.isArray(o)?o:o?[o]:[])}}}function Pl(e,t){let n=-1;const r=[];for(;++n<t.length;)(t[n].add==="after"?e:r).push(t[n]);xe(e,0,0,r)}function Zi(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 Ce(e){return e.replace(/[\t\n\r ]+/g," ").replace(/^ | $/g,"").toLowerCase().toUpperCase()}const ce=Fe(/[A-Za-z]/),ae=Fe(/[\dA-Za-z]/),_l=Fe(/[#-'*+\--9=?A-Z^-~]/);function Lt(e){return e!==null&&(e<32||e===127)}const En=Fe(/\d/),Dl=Fe(/[\dA-Fa-f]/),Ol=Fe(/[!-/:-@[-`{-~]/);function O(e){return e!==null&&e<-2}function Q(e){return e!==null&&(e<0||e===32)}function H(e){return e===-2||e===-1||e===32}const $t=Fe(new RegExp("\\p{P}|\\p{S}","u")),Ke=Fe(/\s/);function Fe(e){return t;function t(n){return n!==null&&n>-1&&e.test(String.fromCharCode(n))}}function rt(e){const t=[];let n=-1,r=0,i=0;for(;++n<e.length;){const s=e.charCodeAt(n);let a="";if(s===37&&ae(e.charCodeAt(n+1))&&ae(e.charCodeAt(n+2)))i=2;else if(s<128)/[!#$&-;=?-Z_a-z~]/.test(String.fromCharCode(s))||(a=String.fromCharCode(s));else if(s>55295&&s<57344){const o=e.charCodeAt(n+1);s<56320&&o>56319&&o<57344?(a=String.fromCharCode(s,o),i=1):a="�"}else a=String.fromCharCode(s);a&&(t.push(e.slice(r,n),encodeURIComponent(a)),r=n+i+1,a=""),i&&(n+=i,i=0)}return t.join("")+e.slice(r)}function q(e,t,n,r){const i=r?r-1:Number.POSITIVE_INFINITY;let s=0;return a;function a(l){return H(l)?(e.enter(n),o(l)):t(l)}function o(l){return H(l)&&s++<i?(e.consume(l),o):(e.exit(n),t(l))}}const zl={tokenize:Fl};function Fl(e){const t=e.attempt(this.parser.constructs.contentInitial,r,i);let n;return t;function r(o){if(o===null){e.consume(o);return}return e.enter("lineEnding"),e.consume(o),e.exit("lineEnding"),q(e,t,"linePrefix")}function i(o){return e.enter("paragraph"),s(o)}function s(o){const l=e.enter("chunkText",{contentType:"text",previous:n});return n&&(n.next=l),n=l,a(o)}function a(o){if(o===null){e.exit("chunkText"),e.exit("paragraph"),e.consume(o);return}return O(o)?(e.consume(o),e.exit("chunkText"),s):(e.consume(o),a)}}const Bl={tokenize:$l},Fr={tokenize:Ul};function $l(e){const t=this,n=[];let r=0,i,s,a;return o;function o(k){if(r<n.length){const R=n[r];return t.containerState=R[1],e.attempt(R[0].continuation,l,u)(k)}return u(k)}function l(k){if(r++,t.containerState._closeFlow){t.containerState._closeFlow=void 0,i&&v();const R=t.events.length;let A=R,C;for(;A--;)if(t.events[A][0]==="exit"&&t.events[A][1].type==="chunkFlow"){C=t.events[A][1].end;break}g(r);let P=R;for(;P<t.events.length;)t.events[P][1].end={...C},P++;return xe(t.events,A+1,0,t.events.slice(R)),t.events.length=P,u(k)}return o(k)}function u(k){if(r===n.length){if(!i)return p(k);if(i.currentConstruct&&i.currentConstruct.concrete)return x(k);t.interrupt=!!(i.currentConstruct&&!i._gfmTableDynamicInterruptHack)}return t.containerState={},e.check(Fr,h,c)(k)}function h(k){return i&&v(),g(r),p(k)}function c(k){return t.parser.lazy[t.now().line]=r!==n.length,a=t.now().offset,x(k)}function p(k){return t.containerState={},e.attempt(Fr,f,x)(k)}function f(k){return r++,n.push([t.currentConstruct,t.containerState]),p(k)}function x(k){if(k===null){i&&v(),g(0),e.consume(k);return}return i=i||t.parser.flow(t.now()),e.enter("chunkFlow",{_tokenizer:i,contentType:"flow",previous:s}),m(k)}function m(k){if(k===null){S(e.exit("chunkFlow"),!0),g(0),e.consume(k);return}return O(k)?(e.consume(k),S(e.exit("chunkFlow")),r=0,t.interrupt=void 0,o):(e.consume(k),m)}function S(k,R){const A=t.sliceStream(k);if(R&&A.push(null),k.previous=s,s&&(s.next=k),s=k,i.defineSkip(k.start),i.write(A),t.parser.lazy[k.start.line]){let C=i.events.length;for(;C--;)if(i.events[C][1].start.offset<a&&(!i.events[C][1].end||i.events[C][1].end.offset>a))return;const P=t.events.length;let F=P,B,w;for(;F--;)if(t.events[F][0]==="exit"&&t.events[F][1].type==="chunkFlow"){if(B){w=t.events[F][1].end;break}B=!0}for(g(r),C=P;C<t.events.length;)t.events[C][1].end={...w},C++;xe(t.events,F+1,0,t.events.slice(P)),t.events.length=C}}function g(k){let R=n.length;for(;R-- >k;){const A=n[R];t.containerState=A[1],A[0].exit.call(t,e)}n.length=k}function v(){i.write([null]),s=void 0,i=void 0,t.containerState._closeFlow=void 0}}function Ul(e,t,n){return q(e,e.attempt(this.parser.constructs.document,t,n),"linePrefix",this.parser.constructs.disable.null.includes("codeIndented")?void 0:4)}function tt(e){if(e===null||Q(e)||Ke(e))return 1;if($t(e))return 2}function Ut(e,t,n){const r=[];let i=-1;for(;++i<e.length;){const s=e[i].resolveAll;s&&!r.includes(s)&&(t=s(t,n),r.push(s))}return t}const An={name:"attention",resolveAll:Hl,tokenize:Kl};function Hl(e,t){let n=-1,r,i,s,a,o,l,u,h;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 c={...e[r][1].end},p={...e[n][1].start};Br(c,-l),Br(p,l),a={type:l>1?"strongSequence":"emphasisSequence",start:c,end:{...e[r][1].end}},o={type:l>1?"strongSequence":"emphasisSequence",start:{...e[n][1].start},end:p},s={type:l>1?"strongText":"emphasisText",start:{...e[r][1].end},end:{...e[n][1].start}},i={type:l>1?"strong":"emphasis",start:{...a.start},end:{...o.end}},e[r][1].end={...a.start},e[n][1].start={...o.end},u=[],e[r][1].end.offset-e[r][1].start.offset&&(u=Se(u,[["enter",e[r][1],t],["exit",e[r][1],t]])),u=Se(u,[["enter",i,t],["enter",a,t],["exit",a,t],["enter",s,t]]),u=Se(u,Ut(t.parser.constructs.insideSpan.null,e.slice(r+1,n),t)),u=Se(u,[["exit",s,t],["enter",o,t],["exit",o,t],["exit",i,t]]),e[n][1].end.offset-e[n][1].start.offset?(h=2,u=Se(u,[["enter",e[n][1],t],["exit",e[n][1],t]])):h=0,xe(e,r-1,n-r+3,u),n=r+u.length-h-2;break}}for(n=-1;++n<e.length;)e[n][1].type==="attentionSequence"&&(e[n][1].type="data");return e}function Kl(e,t){const n=this.parser.constructs.attentionMarkers.null,r=this.previous,i=tt(r);let s;return a;function a(l){return s=l,e.enter("attentionSequence"),o(l)}function o(l){if(l===s)return e.consume(l),o;const u=e.exit("attentionSequence"),h=tt(l),c=!h||h===2&&i||n.includes(l),p=!i||i===2&&h||n.includes(r);return u._open=!!(s===42?c:c&&(i||!p)),u._close=!!(s===42?p:p&&(h||!c)),t(l)}}function Br(e,t){e.column+=t,e.offset+=t,e._bufferIndex+=t}const Vl={name:"autolink",tokenize:ql};function ql(e,t,n){let r=0;return i;function i(f){return e.enter("autolink"),e.enter("autolinkMarker"),e.consume(f),e.exit("autolinkMarker"),e.enter("autolinkProtocol"),s}function s(f){return ce(f)?(e.consume(f),a):f===64?n(f):u(f)}function a(f){return f===43||f===45||f===46||ae(f)?(r=1,o(f)):u(f)}function o(f){return f===58?(e.consume(f),r=0,l):(f===43||f===45||f===46||ae(f))&&r++<32?(e.consume(f),o):(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||Lt(f)?n(f):(e.consume(f),l)}function u(f){return f===64?(e.consume(f),h):_l(f)?(e.consume(f),u):n(f)}function h(f){return ae(f)?c(f):n(f)}function c(f){return f===46?(e.consume(f),r=0,h):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||ae(f))&&r++<63){const x=f===45?p:c;return e.consume(f),x}return n(f)}}const yt={partial:!0,tokenize:Wl};function Wl(e,t,n){return r;function r(s){return H(s)?q(e,i,"linePrefix")(s):i(s)}function i(s){return s===null||O(s)?t(s):n(s)}}const es={continuation:{tokenize:Xl},exit:Ql,name:"blockQuote",tokenize:Gl};function Gl(e,t,n){const r=this;return i;function i(a){if(a===62){const o=r.containerState;return o.open||(e.enter("blockQuote",{_container:!0}),o.open=!0),e.enter("blockQuotePrefix"),e.enter("blockQuoteMarker"),e.consume(a),e.exit("blockQuoteMarker"),s}return n(a)}function s(a){return H(a)?(e.enter("blockQuotePrefixWhitespace"),e.consume(a),e.exit("blockQuotePrefixWhitespace"),e.exit("blockQuotePrefix"),t):(e.exit("blockQuotePrefix"),t(a))}}function Xl(e,t,n){const r=this;return i;function i(a){return H(a)?q(e,s,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(a):s(a)}function s(a){return e.attempt(es,t,n)(a)}}function Ql(e){e.exit("blockQuote")}const ts={name:"characterEscape",tokenize:Yl};function Yl(e,t,n){return r;function r(s){return e.enter("characterEscape"),e.enter("escapeMarker"),e.consume(s),e.exit("escapeMarker"),i}function i(s){return Ol(s)?(e.enter("characterEscapeValue"),e.consume(s),e.exit("characterEscapeValue"),e.exit("characterEscape"),t):n(s)}}const ns={name:"characterReference",tokenize:Jl};function Jl(e,t,n){const r=this;let i=0,s,a;return o;function o(c){return e.enter("characterReference"),e.enter("characterReferenceMarker"),e.consume(c),e.exit("characterReferenceMarker"),l}function l(c){return c===35?(e.enter("characterReferenceMarkerNumeric"),e.consume(c),e.exit("characterReferenceMarkerNumeric"),u):(e.enter("characterReferenceValue"),s=31,a=ae,h(c))}function u(c){return c===88||c===120?(e.enter("characterReferenceMarkerHexadecimal"),e.consume(c),e.exit("characterReferenceMarkerHexadecimal"),e.enter("characterReferenceValue"),s=6,a=Dl,h):(e.enter("characterReferenceValue"),s=7,a=En,h(c))}function h(c){if(c===59&&i){const p=e.exit("characterReferenceValue");return a===ae&&!Jn(r.sliceSerialize(p))?n(c):(e.enter("characterReferenceMarker"),e.consume(c),e.exit("characterReferenceMarker"),e.exit("characterReference"),t)}return a(c)&&i++<s?(e.consume(c),h):n(c)}}const $r={partial:!0,tokenize:eu},Ur={concrete:!0,name:"codeFenced",tokenize:Zl};function Zl(e,t,n){const r=this,i={partial:!0,tokenize:A};let s=0,a=0,o;return l;function l(C){return u(C)}function u(C){const P=r.events[r.events.length-1];return s=P&&P[1].type==="linePrefix"?P[2].sliceSerialize(P[1],!0).length:0,o=C,e.enter("codeFenced"),e.enter("codeFencedFence"),e.enter("codeFencedFenceSequence"),h(C)}function h(C){return C===o?(a++,e.consume(C),h):a<3?n(C):(e.exit("codeFencedFenceSequence"),H(C)?q(e,c,"whitespace")(C):c(C))}function c(C){return C===null||O(C)?(e.exit("codeFencedFence"),r.interrupt?t(C):e.check($r,m,R)(C)):(e.enter("codeFencedFenceInfo"),e.enter("chunkString",{contentType:"string"}),p(C))}function p(C){return C===null||O(C)?(e.exit("chunkString"),e.exit("codeFencedFenceInfo"),c(C)):H(C)?(e.exit("chunkString"),e.exit("codeFencedFenceInfo"),q(e,f,"whitespace")(C)):C===96&&C===o?n(C):(e.consume(C),p)}function f(C){return C===null||O(C)?c(C):(e.enter("codeFencedFenceMeta"),e.enter("chunkString",{contentType:"string"}),x(C))}function x(C){return C===null||O(C)?(e.exit("chunkString"),e.exit("codeFencedFenceMeta"),c(C)):C===96&&C===o?n(C):(e.consume(C),x)}function m(C){return e.attempt(i,R,S)(C)}function S(C){return e.enter("lineEnding"),e.consume(C),e.exit("lineEnding"),g}function g(C){return s>0&&H(C)?q(e,v,"linePrefix",s+1)(C):v(C)}function v(C){return C===null||O(C)?e.check($r,m,R)(C):(e.enter("codeFlowValue"),k(C))}function k(C){return C===null||O(C)?(e.exit("codeFlowValue"),v(C)):(e.consume(C),k)}function R(C){return e.exit("codeFenced"),t(C)}function A(C,P,F){let B=0;return w;function w(L){return C.enter("lineEnding"),C.consume(L),C.exit("lineEnding"),j}function j(L){return C.enter("codeFencedFence"),H(L)?q(C,_,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(L):_(L)}function _(L){return L===o?(C.enter("codeFencedFenceSequence"),W(L)):F(L)}function W(L){return L===o?(B++,C.consume(L),W):B>=a?(C.exit("codeFencedFenceSequence"),H(L)?q(C,D,"whitespace")(L):D(L)):F(L)}function D(L){return L===null||O(L)?(C.exit("codeFencedFence"),P(L)):F(L)}}}function eu(e,t,n){const r=this;return i;function i(a){return a===null?n(a):(e.enter("lineEnding"),e.consume(a),e.exit("lineEnding"),s)}function s(a){return r.parser.lazy[r.now().line]?n(a):t(a)}}const Yt={name:"codeIndented",tokenize:nu},tu={partial:!0,tokenize:ru};function nu(e,t,n){const r=this;return i;function i(u){return e.enter("codeIndented"),q(e,s,"linePrefix",5)(u)}function s(u){const h=r.events[r.events.length-1];return h&&h[1].type==="linePrefix"&&h[2].sliceSerialize(h[1],!0).length>=4?a(u):n(u)}function a(u){return u===null?l(u):O(u)?e.attempt(tu,a,l)(u):(e.enter("codeFlowValue"),o(u))}function o(u){return u===null||O(u)?(e.exit("codeFlowValue"),a(u)):(e.consume(u),o)}function l(u){return e.exit("codeIndented"),t(u)}}function ru(e,t,n){const r=this;return i;function i(a){return r.parser.lazy[r.now().line]?n(a):O(a)?(e.enter("lineEnding"),e.consume(a),e.exit("lineEnding"),i):q(e,s,"linePrefix",5)(a)}function s(a){const o=r.events[r.events.length-1];return o&&o[1].type==="linePrefix"&&o[2].sliceSerialize(o[1],!0).length>=4?t(a):O(a)?i(a):n(a)}}const iu={name:"codeText",previous:au,resolve:su,tokenize:ou};function su(e){let t=e.length-4,n=3,r,i;if((e[n][1].type==="lineEnding"||e[n][1].type==="space")&&(e[t][1].type==="lineEnding"||e[t][1].type==="space")){for(r=n;++r<t;)if(e[r][1].type==="codeTextData"){e[n][1].type="codeTextPadding",e[t][1].type="codeTextPadding",n+=2,t-=2;break}}for(r=n-1,t++;++r<=t;)i===void 0?r!==t&&e[r][1].type!=="lineEnding"&&(i=r):(r===t||e[r][1].type==="lineEnding")&&(e[i][1].type="codeTextData",r!==i+2&&(e[i][1].end=e[r-1][1].end,e.splice(i+2,r-i-2),t-=r-i-2,r=i+2),i=void 0);return e}function au(e){return e!==96||this.events[this.events.length-1][1].type==="characterEscape"}function ou(e,t,n){let r=0,i,s;return a;function a(c){return e.enter("codeText"),e.enter("codeTextSequence"),o(c)}function o(c){return c===96?(e.consume(c),r++,o):(e.exit("codeTextSequence"),l(c))}function l(c){return c===null?n(c):c===32?(e.enter("space"),e.consume(c),e.exit("space"),l):c===96?(s=e.enter("codeTextSequence"),i=0,h(c)):O(c)?(e.enter("lineEnding"),e.consume(c),e.exit("lineEnding"),l):(e.enter("codeTextData"),u(c))}function u(c){return c===null||c===32||c===96||O(c)?(e.exit("codeTextData"),l(c)):(e.consume(c),u)}function h(c){return c===96?(e.consume(c),i++,h):i===r?(e.exit("codeTextSequence"),e.exit("codeText"),t(c)):(s.type="codeTextData",u(c))}}class lu{constructor(t){this.left=t?[...t]:[],this.right=[]}get(t){if(t<0||t>=this.left.length+this.right.length)throw new RangeError("Cannot access index `"+t+"` in a splice buffer of size `"+(this.left.length+this.right.length)+"`");return t<this.left.length?this.left[t]:this.right[this.right.length-t+this.left.length-1]}get length(){return this.left.length+this.right.length}shift(){return this.setCursor(0),this.right.pop()}slice(t,n){const r=n??Number.POSITIVE_INFINITY;return r<this.left.length?this.left.slice(t,r):t>this.left.length?this.right.slice(this.right.length-r+this.left.length,this.right.length-t+this.left.length).reverse():this.left.slice(t).concat(this.right.slice(this.right.length-r+this.left.length).reverse())}splice(t,n,r){const i=n||0;this.setCursor(Math.trunc(t));const s=this.right.splice(this.right.length-i,Number.POSITIVE_INFINITY);return r&&lt(this.left,r),s.reverse()}pop(){return this.setCursor(Number.POSITIVE_INFINITY),this.left.pop()}push(t){this.setCursor(Number.POSITIVE_INFINITY),this.left.push(t)}pushMany(t){this.setCursor(Number.POSITIVE_INFINITY),lt(this.left,t)}unshift(t){this.setCursor(0),this.right.push(t)}unshiftMany(t){this.setCursor(0),lt(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);lt(this.right,n.reverse())}else{const n=this.right.splice(this.left.length+this.right.length-t,Number.POSITIVE_INFINITY);lt(this.left,n.reverse())}}}function lt(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 rs(e){const t={};let n=-1,r,i,s,a,o,l,u;const h=new lu(e);for(;++n<h.length;){for(;n in t;)n=t[n];if(r=h.get(n),n&&r[1].type==="chunkFlow"&&h.get(n-1)[1].type==="listItemPrefix"&&(l=r[1]._tokenizer.events,s=0,s<l.length&&l[s][1].type==="lineEndingBlank"&&(s+=2),s<l.length&&l[s][1].type==="content"))for(;++s<l.length&&l[s][1].type!=="content";)l[s][1].type==="chunkText"&&(l[s][1]._isInFirstContentOfListItem=!0,s++);if(r[0]==="enter")r[1].contentType&&(Object.assign(t,uu(h,n)),n=t[n],u=!0);else if(r[1]._container){for(s=n,i=void 0;s--;)if(a=h.get(s),a[1].type==="lineEnding"||a[1].type==="lineEndingBlank")a[0]==="enter"&&(i&&(h.get(i)[1].type="lineEndingBlank"),a[1].type="lineEnding",i=s);else if(!(a[1].type==="linePrefix"||a[1].type==="listItemIndent"))break;i&&(r[1].end={...h.get(i)[1].start},o=h.slice(i,n),o.unshift(r),h.splice(i,n-i+1,o))}}return xe(e,0,Number.POSITIVE_INFINITY,h.slice(0)),!u}function uu(e,t){const n=e.get(t)[1],r=e.get(t)[2];let i=t-1;const s=[];let a=n._tokenizer;a||(a=r.parser[n.contentType](n.start),n._contentTypeTextTrailing&&(a._contentTypeTextTrailing=!0));const o=a.events,l=[],u={};let h,c,p=-1,f=n,x=0,m=0;const S=[m];for(;f;){for(;e.get(++i)[1]!==f;);s.push(i),f._tokenizer||(h=r.sliceStream(f),f.next||h.push(null),c&&a.defineSkip(f.start),f._isInFirstContentOfListItem&&(a._gfmTasklistFirstContentOfListItem=!0),a.write(h),f._isInFirstContentOfListItem&&(a._gfmTasklistFirstContentOfListItem=void 0)),c=f,f=f.next}for(f=n;++p<o.length;)o[p][0]==="exit"&&o[p-1][0]==="enter"&&o[p][1].type===o[p-1][1].type&&o[p][1].start.line!==o[p][1].end.line&&(m=p+1,S.push(m),f._tokenizer=void 0,f.previous=void 0,f=f.next);for(a.events=[],f?(f._tokenizer=void 0,f.previous=void 0):S.pop(),p=S.length;p--;){const g=o.slice(S[p],S[p+1]),v=s.pop();l.push([v,v+g.length-1]),e.splice(v,2,g)}for(l.reverse(),p=-1;++p<l.length;)u[x+l[p][0]]=x+l[p][1],x+=l[p][1]-l[p][0]-1;return u}const cu={resolve:du,tokenize:fu},hu={partial:!0,tokenize:pu};function du(e){return rs(e),e}function fu(e,t){let n;return r;function r(o){return e.enter("content"),n=e.enter("chunkContent",{contentType:"content"}),i(o)}function i(o){return o===null?s(o):O(o)?e.check(hu,a,s)(o):(e.consume(o),i)}function s(o){return e.exit("chunkContent"),e.exit("content"),t(o)}function a(o){return e.consume(o),e.exit("chunkContent"),n.next=e.enter("chunkContent",{contentType:"content",previous:n}),n=n.next,i}}function pu(e,t,n){const r=this;return i;function i(a){return e.exit("chunkContent"),e.enter("lineEnding"),e.consume(a),e.exit("lineEnding"),q(e,s,"linePrefix")}function s(a){if(a===null||O(a))return n(a);const o=r.events[r.events.length-1];return!r.parser.constructs.disable.null.includes("codeIndented")&&o&&o[1].type==="linePrefix"&&o[2].sliceSerialize(o[1],!0).length>=4?t(a):e.interrupt(r.parser.constructs.flow,n,t)(a)}}function is(e,t,n,r,i,s,a,o,l){const u=l||Number.POSITIVE_INFINITY;let h=0;return c;function c(g){return g===60?(e.enter(r),e.enter(i),e.enter(s),e.consume(g),e.exit(s),p):g===null||g===32||g===41||Lt(g)?n(g):(e.enter(r),e.enter(a),e.enter(o),e.enter("chunkString",{contentType:"string"}),m(g))}function p(g){return g===62?(e.enter(s),e.consume(g),e.exit(s),e.exit(i),e.exit(r),t):(e.enter(o),e.enter("chunkString",{contentType:"string"}),f(g))}function f(g){return g===62?(e.exit("chunkString"),e.exit(o),p(g)):g===null||g===60||O(g)?n(g):(e.consume(g),g===92?x:f)}function x(g){return g===60||g===62||g===92?(e.consume(g),f):f(g)}function m(g){return!h&&(g===null||g===41||Q(g))?(e.exit("chunkString"),e.exit(o),e.exit(a),e.exit(r),t(g)):h<u&&g===40?(e.consume(g),h++,m):g===41?(e.consume(g),h--,m):g===null||g===32||g===40||Lt(g)?n(g):(e.consume(g),g===92?S:m)}function S(g){return g===40||g===41||g===92?(e.consume(g),m):m(g)}}function ss(e,t,n,r,i,s){const a=this;let o=0,l;return u;function u(f){return e.enter(r),e.enter(i),e.consume(f),e.exit(i),e.enter(s),h}function h(f){return o>999||f===null||f===91||f===93&&!l||f===94&&!o&&"_hiddenFootnoteSupport"in a.parser.constructs?n(f):f===93?(e.exit(s),e.enter(i),e.consume(f),e.exit(i),e.exit(r),t):O(f)?(e.enter("lineEnding"),e.consume(f),e.exit("lineEnding"),h):(e.enter("chunkString",{contentType:"string"}),c(f))}function c(f){return f===null||f===91||f===93||O(f)||o++>999?(e.exit("chunkString"),h(f)):(e.consume(f),l||(l=!H(f)),f===92?p:c)}function p(f){return f===91||f===92||f===93?(e.consume(f),o++,c):c(f)}}function as(e,t,n,r,i,s){let a;return o;function o(p){return p===34||p===39||p===40?(e.enter(r),e.enter(i),e.consume(p),e.exit(i),a=p===40?41:p,l):n(p)}function l(p){return p===a?(e.enter(i),e.consume(p),e.exit(i),e.exit(r),t):(e.enter(s),u(p))}function u(p){return p===a?(e.exit(s),l(a)):p===null?n(p):O(p)?(e.enter("lineEnding"),e.consume(p),e.exit("lineEnding"),q(e,u,"linePrefix")):(e.enter("chunkString",{contentType:"string"}),h(p))}function h(p){return p===a||p===null||O(p)?(e.exit("chunkString"),u(p)):(e.consume(p),p===92?c:h)}function c(p){return p===a||p===92?(e.consume(p),h):h(p)}}function dt(e,t){let n;return r;function r(i){return O(i)?(e.enter("lineEnding"),e.consume(i),e.exit("lineEnding"),n=!0,r):H(i)?q(e,r,n?"linePrefix":"lineSuffix")(i):t(i)}}const mu={name:"definition",tokenize:xu},gu={partial:!0,tokenize:yu};function xu(e,t,n){const r=this;let i;return s;function s(f){return e.enter("definition"),a(f)}function a(f){return ss.call(r,e,o,n,"definitionLabel","definitionLabelMarker","definitionLabelString")(f)}function o(f){return i=Ce(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 Q(f)?dt(e,u)(f):u(f)}function u(f){return is(e,h,n,"definitionDestination","definitionDestinationLiteral","definitionDestinationLiteralMarker","definitionDestinationRaw","definitionDestinationString")(f)}function h(f){return e.attempt(gu,c,c)(f)}function c(f){return H(f)?q(e,p,"whitespace")(f):p(f)}function p(f){return f===null||O(f)?(e.exit("definition"),r.parser.defined.push(i),t(f)):n(f)}}function yu(e,t,n){return r;function r(o){return Q(o)?dt(e,i)(o):n(o)}function i(o){return as(e,s,n,"definitionTitle","definitionTitleMarker","definitionTitleString")(o)}function s(o){return H(o)?q(e,a,"whitespace")(o):a(o)}function a(o){return o===null||O(o)?t(o):n(o)}}const bu={name:"hardBreakEscape",tokenize:Su};function Su(e,t,n){return r;function r(s){return e.enter("hardBreakEscape"),e.consume(s),i}function i(s){return O(s)?(e.exit("hardBreakEscape"),t(s)):n(s)}}const ku={name:"headingAtx",resolve:wu,tokenize:vu};function wu(e,t){let n=e.length-2,r=3,i,s;return e[r][1].type==="whitespace"&&(r+=2),n-2>r&&e[n][1].type==="whitespace"&&(n-=2),e[n][1].type==="atxHeadingSequence"&&(r===n-1||n-4>r&&e[n-2][1].type==="whitespace")&&(n-=r+1===n?2:4),n>r&&(i={type:"atxHeadingText",start:e[r][1].start,end:e[n][1].end},s={type:"chunkText",start:e[r][1].start,end:e[n][1].end,contentType:"text"},xe(e,r,n-r+1,[["enter",i,t],["enter",s,t],["exit",s,t],["exit",i,t]])),e}function vu(e,t,n){let r=0;return i;function i(h){return e.enter("atxHeading"),s(h)}function s(h){return e.enter("atxHeadingSequence"),a(h)}function a(h){return h===35&&r++<6?(e.consume(h),a):h===null||Q(h)?(e.exit("atxHeadingSequence"),o(h)):n(h)}function o(h){return h===35?(e.enter("atxHeadingSequence"),l(h)):h===null||O(h)?(e.exit("atxHeading"),t(h)):H(h)?q(e,o,"whitespace")(h):(e.enter("atxHeadingText"),u(h))}function l(h){return h===35?(e.consume(h),l):(e.exit("atxHeadingSequence"),o(h))}function u(h){return h===null||h===35||Q(h)?(e.exit("atxHeadingText"),o(h)):(e.consume(h),u)}}const Cu=["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"],Hr=["pre","script","style","textarea"],Iu={concrete:!0,name:"htmlFlow",resolveTo:Eu,tokenize:Au},Tu={partial:!0,tokenize:Nu},Ru={partial:!0,tokenize:Mu};function Eu(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 Au(e,t,n){const r=this;let i,s,a,o,l;return u;function u(b){return h(b)}function h(b){return e.enter("htmlFlow"),e.enter("htmlFlowData"),e.consume(b),c}function c(b){return b===33?(e.consume(b),p):b===47?(e.consume(b),s=!0,m):b===63?(e.consume(b),i=3,r.interrupt?t:y):ce(b)?(e.consume(b),a=String.fromCharCode(b),S):n(b)}function p(b){return b===45?(e.consume(b),i=2,f):b===91?(e.consume(b),i=5,o=0,x):ce(b)?(e.consume(b),i=4,r.interrupt?t:y):n(b)}function f(b){return b===45?(e.consume(b),r.interrupt?t:y):n(b)}function x(b){const de="CDATA[";return b===de.charCodeAt(o++)?(e.consume(b),o===de.length?r.interrupt?t:_:x):n(b)}function m(b){return ce(b)?(e.consume(b),a=String.fromCharCode(b),S):n(b)}function S(b){if(b===null||b===47||b===62||Q(b)){const de=b===47,Ie=a.toLowerCase();return!de&&!s&&Hr.includes(Ie)?(i=1,r.interrupt?t(b):_(b)):Cu.includes(a.toLowerCase())?(i=6,de?(e.consume(b),g):r.interrupt?t(b):_(b)):(i=7,r.interrupt&&!r.parser.lazy[r.now().line]?n(b):s?v(b):k(b))}return b===45||ae(b)?(e.consume(b),a+=String.fromCharCode(b),S):n(b)}function g(b){return b===62?(e.consume(b),r.interrupt?t:_):n(b)}function v(b){return H(b)?(e.consume(b),v):w(b)}function k(b){return b===47?(e.consume(b),w):b===58||b===95||ce(b)?(e.consume(b),R):H(b)?(e.consume(b),k):w(b)}function R(b){return b===45||b===46||b===58||b===95||ae(b)?(e.consume(b),R):A(b)}function A(b){return b===61?(e.consume(b),C):H(b)?(e.consume(b),A):k(b)}function C(b){return b===null||b===60||b===61||b===62||b===96?n(b):b===34||b===39?(e.consume(b),l=b,P):H(b)?(e.consume(b),C):F(b)}function P(b){return b===l?(e.consume(b),l=null,B):b===null||O(b)?n(b):(e.consume(b),P)}function F(b){return b===null||b===34||b===39||b===47||b===60||b===61||b===62||b===96||Q(b)?A(b):(e.consume(b),F)}function B(b){return b===47||b===62||H(b)?k(b):n(b)}function w(b){return b===62?(e.consume(b),j):n(b)}function j(b){return b===null||O(b)?_(b):H(b)?(e.consume(b),j):n(b)}function _(b){return b===45&&i===2?(e.consume(b),G):b===60&&i===1?(e.consume(b),Y):b===62&&i===4?(e.consume(b),he):b===63&&i===3?(e.consume(b),y):b===93&&i===5?(e.consume(b),ye):O(b)&&(i===6||i===7)?(e.exit("htmlFlowData"),e.check(Tu,ue,W)(b)):b===null||O(b)?(e.exit("htmlFlowData"),W(b)):(e.consume(b),_)}function W(b){return e.check(Ru,D,ue)(b)}function D(b){return e.enter("lineEnding"),e.consume(b),e.exit("lineEnding"),L}function L(b){return b===null||O(b)?W(b):(e.enter("htmlFlowData"),_(b))}function G(b){return b===45?(e.consume(b),y):_(b)}function Y(b){return b===47?(e.consume(b),a="",le):_(b)}function le(b){if(b===62){const de=a.toLowerCase();return Hr.includes(de)?(e.consume(b),he):_(b)}return ce(b)&&a.length<8?(e.consume(b),a+=String.fromCharCode(b),le):_(b)}function ye(b){return b===93?(e.consume(b),y):_(b)}function y(b){return b===62?(e.consume(b),he):b===45&&i===2?(e.consume(b),y):_(b)}function he(b){return b===null||O(b)?(e.exit("htmlFlowData"),ue(b)):(e.consume(b),he)}function ue(b){return e.exit("htmlFlow"),t(b)}}function Mu(e,t,n){const r=this;return i;function i(a){return O(a)?(e.enter("lineEnding"),e.consume(a),e.exit("lineEnding"),s):n(a)}function s(a){return r.parser.lazy[r.now().line]?n(a):t(a)}}function Nu(e,t,n){return r;function r(i){return e.enter("lineEnding"),e.consume(i),e.exit("lineEnding"),e.attempt(yt,t,n)}}const Lu={name:"htmlText",tokenize:ju};function ju(e,t,n){const r=this;let i,s,a;return o;function o(y){return e.enter("htmlText"),e.enter("htmlTextData"),e.consume(y),l}function l(y){return y===33?(e.consume(y),u):y===47?(e.consume(y),A):y===63?(e.consume(y),k):ce(y)?(e.consume(y),F):n(y)}function u(y){return y===45?(e.consume(y),h):y===91?(e.consume(y),s=0,x):ce(y)?(e.consume(y),v):n(y)}function h(y){return y===45?(e.consume(y),f):n(y)}function c(y){return y===null?n(y):y===45?(e.consume(y),p):O(y)?(a=c,Y(y)):(e.consume(y),c)}function p(y){return y===45?(e.consume(y),f):c(y)}function f(y){return y===62?G(y):y===45?p(y):c(y)}function x(y){const he="CDATA[";return y===he.charCodeAt(s++)?(e.consume(y),s===he.length?m:x):n(y)}function m(y){return y===null?n(y):y===93?(e.consume(y),S):O(y)?(a=m,Y(y)):(e.consume(y),m)}function S(y){return y===93?(e.consume(y),g):m(y)}function g(y){return y===62?G(y):y===93?(e.consume(y),g):m(y)}function v(y){return y===null||y===62?G(y):O(y)?(a=v,Y(y)):(e.consume(y),v)}function k(y){return y===null?n(y):y===63?(e.consume(y),R):O(y)?(a=k,Y(y)):(e.consume(y),k)}function R(y){return y===62?G(y):k(y)}function A(y){return ce(y)?(e.consume(y),C):n(y)}function C(y){return y===45||ae(y)?(e.consume(y),C):P(y)}function P(y){return O(y)?(a=P,Y(y)):H(y)?(e.consume(y),P):G(y)}function F(y){return y===45||ae(y)?(e.consume(y),F):y===47||y===62||Q(y)?B(y):n(y)}function B(y){return y===47?(e.consume(y),G):y===58||y===95||ce(y)?(e.consume(y),w):O(y)?(a=B,Y(y)):H(y)?(e.consume(y),B):G(y)}function w(y){return y===45||y===46||y===58||y===95||ae(y)?(e.consume(y),w):j(y)}function j(y){return y===61?(e.consume(y),_):O(y)?(a=j,Y(y)):H(y)?(e.consume(y),j):B(y)}function _(y){return y===null||y===60||y===61||y===62||y===96?n(y):y===34||y===39?(e.consume(y),i=y,W):O(y)?(a=_,Y(y)):H(y)?(e.consume(y),_):(e.consume(y),D)}function W(y){return y===i?(e.consume(y),i=void 0,L):y===null?n(y):O(y)?(a=W,Y(y)):(e.consume(y),W)}function D(y){return y===null||y===34||y===39||y===60||y===61||y===96?n(y):y===47||y===62||Q(y)?B(y):(e.consume(y),D)}function L(y){return y===47||y===62||Q(y)?B(y):n(y)}function G(y){return y===62?(e.consume(y),e.exit("htmlTextData"),e.exit("htmlText"),t):n(y)}function Y(y){return e.exit("htmlTextData"),e.enter("lineEnding"),e.consume(y),e.exit("lineEnding"),le}function le(y){return H(y)?q(e,ye,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(y):ye(y)}function ye(y){return e.enter("htmlTextData"),a(y)}}const Zn={name:"labelEnd",resolveAll:Ou,resolveTo:zu,tokenize:Fu},Pu={tokenize:Bu},_u={tokenize:$u},Du={tokenize:Uu};function Ou(e){let t=-1;const n=[];for(;++t<e.length;){const r=e[t][1];if(n.push(e[t]),r.type==="labelImage"||r.type==="labelLink"||r.type==="labelEnd"){const i=r.type==="labelImage"?4:2;r.type="data",t+=i}}return e.length!==n.length&&xe(e,0,e.length,n),e}function zu(e,t){let n=e.length,r=0,i,s,a,o;for(;n--;)if(i=e[n][1],s){if(i.type==="link"||i.type==="labelLink"&&i._inactive)break;e[n][0]==="enter"&&i.type==="labelLink"&&(i._inactive=!0)}else if(a){if(e[n][0]==="enter"&&(i.type==="labelImage"||i.type==="labelLink")&&!i._balanced&&(s=n,i.type!=="labelLink")){r=2;break}}else i.type==="labelEnd"&&(a=n);const l={type:e[s][1].type==="labelLink"?"link":"image",start:{...e[s][1].start},end:{...e[e.length-1][1].end}},u={type:"label",start:{...e[s][1].start},end:{...e[a][1].end}},h={type:"labelText",start:{...e[s+r+2][1].end},end:{...e[a-2][1].start}};return o=[["enter",l,t],["enter",u,t]],o=Se(o,e.slice(s+1,s+r+3)),o=Se(o,[["enter",h,t]]),o=Se(o,Ut(t.parser.constructs.insideSpan.null,e.slice(s+r+4,a-3),t)),o=Se(o,[["exit",h,t],e[a-2],e[a-1],["exit",u,t]]),o=Se(o,e.slice(a+1)),o=Se(o,[["exit",l,t]]),xe(e,s,e.length,o),e}function Fu(e,t,n){const r=this;let i=r.events.length,s,a;for(;i--;)if((r.events[i][1].type==="labelImage"||r.events[i][1].type==="labelLink")&&!r.events[i][1]._balanced){s=r.events[i][1];break}return o;function o(p){return s?s._inactive?c(p):(a=r.parser.defined.includes(Ce(r.sliceSerialize({start:s.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(Pu,h,a?h:c)(p):p===91?e.attempt(_u,h,a?u:c)(p):a?h(p):c(p)}function u(p){return e.attempt(Du,h,c)(p)}function h(p){return t(p)}function c(p){return s._balanced=!0,n(p)}}function Bu(e,t,n){return r;function r(c){return e.enter("resource"),e.enter("resourceMarker"),e.consume(c),e.exit("resourceMarker"),i}function i(c){return Q(c)?dt(e,s)(c):s(c)}function s(c){return c===41?h(c):is(e,a,o,"resourceDestination","resourceDestinationLiteral","resourceDestinationLiteralMarker","resourceDestinationRaw","resourceDestinationString",32)(c)}function a(c){return Q(c)?dt(e,l)(c):h(c)}function o(c){return n(c)}function l(c){return c===34||c===39||c===40?as(e,u,n,"resourceTitle","resourceTitleMarker","resourceTitleString")(c):h(c)}function u(c){return Q(c)?dt(e,h)(c):h(c)}function h(c){return c===41?(e.enter("resourceMarker"),e.consume(c),e.exit("resourceMarker"),e.exit("resource"),t):n(c)}}function $u(e,t,n){const r=this;return i;function i(o){return ss.call(r,e,s,a,"reference","referenceMarker","referenceString")(o)}function s(o){return r.parser.defined.includes(Ce(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)))?t(o):n(o)}function a(o){return n(o)}}function Uu(e,t,n){return r;function r(s){return e.enter("reference"),e.enter("referenceMarker"),e.consume(s),e.exit("referenceMarker"),i}function i(s){return s===93?(e.enter("referenceMarker"),e.consume(s),e.exit("referenceMarker"),e.exit("reference"),t):n(s)}}const Hu={name:"labelStartImage",resolveAll:Zn.resolveAll,tokenize:Ku};function Ku(e,t,n){const r=this;return i;function i(o){return e.enter("labelImage"),e.enter("labelImageMarker"),e.consume(o),e.exit("labelImageMarker"),s}function s(o){return o===91?(e.enter("labelMarker"),e.consume(o),e.exit("labelMarker"),e.exit("labelImage"),a):n(o)}function a(o){return o===94&&"_hiddenFootnoteSupport"in r.parser.constructs?n(o):t(o)}}const Vu={name:"labelStartLink",resolveAll:Zn.resolveAll,tokenize:qu};function qu(e,t,n){const r=this;return i;function i(a){return e.enter("labelLink"),e.enter("labelMarker"),e.consume(a),e.exit("labelMarker"),e.exit("labelLink"),s}function s(a){return a===94&&"_hiddenFootnoteSupport"in r.parser.constructs?n(a):t(a)}}const Jt={name:"lineEnding",tokenize:Wu};function Wu(e,t){return n;function n(r){return e.enter("lineEnding"),e.consume(r),e.exit("lineEnding"),q(e,t,"linePrefix")}}const Mt={name:"thematicBreak",tokenize:Gu};function Gu(e,t,n){let r=0,i;return s;function s(u){return e.enter("thematicBreak"),a(u)}function a(u){return i=u,o(u)}function o(u){return u===i?(e.enter("thematicBreakSequence"),l(u)):r>=3&&(u===null||O(u))?(e.exit("thematicBreak"),t(u)):n(u)}function l(u){return u===i?(e.consume(u),r++,l):(e.exit("thematicBreakSequence"),H(u)?q(e,o,"whitespace")(u):o(u))}}const fe={continuation:{tokenize:Ju},exit:ec,name:"list",tokenize:Yu},Xu={partial:!0,tokenize:tc},Qu={partial:!0,tokenize:Zu};function Yu(e,t,n){const r=this,i=r.events[r.events.length-1];let s=i&&i[1].type==="linePrefix"?i[2].sliceSerialize(i[1],!0).length:0,a=0;return o;function o(f){const x=r.containerState.type||(f===42||f===43||f===45?"listUnordered":"listOrdered");if(x==="listUnordered"?!r.containerState.marker||f===r.containerState.marker:En(f)){if(r.containerState.type||(r.containerState.type=x,e.enter(x,{_container:!0})),x==="listUnordered")return e.enter("listItemPrefix"),f===42||f===45?e.check(Mt,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 En(f)&&++a<10?(e.consume(f),l):(!r.interrupt||a<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(yt,r.interrupt?n:h,e.attempt(Xu,p,c))}function h(f){return r.containerState.initialBlankLine=!0,s++,p(f)}function c(f){return H(f)?(e.enter("listItemPrefixWhitespace"),e.consume(f),e.exit("listItemPrefixWhitespace"),p):n(f)}function p(f){return r.containerState.size=s+r.sliceSerialize(e.exit("listItemPrefix"),!0).length,t(f)}}function Ju(e,t,n){const r=this;return r.containerState._closeFlow=void 0,e.check(yt,i,s);function i(o){return r.containerState.furtherBlankLines=r.containerState.furtherBlankLines||r.containerState.initialBlankLine,q(e,t,"listItemIndent",r.containerState.size+1)(o)}function s(o){return r.containerState.furtherBlankLines||!H(o)?(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,a(o)):(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,e.attempt(Qu,t,a)(o))}function a(o){return r.containerState._closeFlow=!0,r.interrupt=void 0,q(e,e.attempt(fe,t,n),"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(o)}}function Zu(e,t,n){const r=this;return q(e,i,"listItemIndent",r.containerState.size+1);function i(s){const a=r.events[r.events.length-1];return a&&a[1].type==="listItemIndent"&&a[2].sliceSerialize(a[1],!0).length===r.containerState.size?t(s):n(s)}}function ec(e){e.exit(this.containerState.type)}function tc(e,t,n){const r=this;return q(e,i,"listItemPrefixWhitespace",r.parser.constructs.disable.null.includes("codeIndented")?void 0:5);function i(s){const a=r.events[r.events.length-1];return!H(s)&&a&&a[1].type==="listItemPrefixWhitespace"?t(s):n(s)}}const Kr={name:"setextUnderline",resolveTo:nc,tokenize:rc};function nc(e,t){let n=e.length,r,i,s;for(;n--;)if(e[n][0]==="enter"){if(e[n][1].type==="content"){r=n;break}e[n][1].type==="paragraph"&&(i=n)}else e[n][1].type==="content"&&e.splice(n,1),!s&&e[n][1].type==="definition"&&(s=n);const a={type:"setextHeading",start:{...e[r][1].start},end:{...e[e.length-1][1].end}};return e[i][1].type="setextHeadingText",s?(e.splice(i,0,["enter",a,t]),e.splice(s+1,0,["exit",e[r][1],t]),e[r][1].end={...e[s][1].end}):e[r][1]=a,e.push(["exit",a,t]),e}function rc(e,t,n){const r=this;let i;return s;function s(u){let h=r.events.length,c;for(;h--;)if(r.events[h][1].type!=="lineEnding"&&r.events[h][1].type!=="linePrefix"&&r.events[h][1].type!=="content"){c=r.events[h][1].type==="paragraph";break}return!r.parser.lazy[r.now().line]&&(r.interrupt||c)?(e.enter("setextHeadingLine"),i=u,a(u)):n(u)}function a(u){return e.enter("setextHeadingLineSequence"),o(u)}function o(u){return u===i?(e.consume(u),o):(e.exit("setextHeadingLineSequence"),H(u)?q(e,l,"lineSuffix")(u):l(u))}function l(u){return u===null||O(u)?(e.exit("setextHeadingLine"),t(u)):n(u)}}const ic={tokenize:sc};function sc(e){const t=this,n=e.attempt(yt,r,e.attempt(this.parser.constructs.flowInitial,i,q(e,e.attempt(this.parser.constructs.flow,i,e.attempt(cu,i)),"linePrefix")));return n;function r(s){if(s===null){e.consume(s);return}return e.enter("lineEndingBlank"),e.consume(s),e.exit("lineEndingBlank"),t.currentConstruct=void 0,n}function i(s){if(s===null){e.consume(s);return}return e.enter("lineEnding"),e.consume(s),e.exit("lineEnding"),t.currentConstruct=void 0,n}}const ac={resolveAll:ls()},oc=os("string"),lc=os("text");function os(e){return{resolveAll:ls(e==="text"?uc:void 0),tokenize:t};function t(n){const r=this,i=this.parser.constructs[e],s=n.attempt(i,a,o);return a;function a(h){return u(h)?s(h):o(h)}function o(h){if(h===null){n.consume(h);return}return n.enter("data"),n.consume(h),l}function l(h){return u(h)?(n.exit("data"),s(h)):(n.consume(h),l)}function u(h){if(h===null)return!0;const c=i[h];let p=-1;if(c)for(;++p<c.length;){const f=c[p];if(!f.previous||f.previous.call(r,r.previous))return!0}return!1}}}function ls(e){return t;function t(n,r){let i=-1,s;for(;++i<=n.length;)s===void 0?n[i]&&n[i][1].type==="data"&&(s=i,i++):(!n[i]||n[i][1].type!=="data")&&(i!==s+2&&(n[s][1].end=n[i-1][1].end,n.splice(s+2,i-s-2),i=s+2),s=void 0);return e?e(n,r):n}}function uc(e,t){let n=0;for(;++n<=e.length;)if((n===e.length||e[n][1].type==="lineEnding")&&e[n-1][1].type==="data"){const r=e[n-1][1],i=t.sliceStream(r);let s=i.length,a=-1,o=0,l;for(;s--;){const u=i[s];if(typeof u=="string"){for(a=u.length;u.charCodeAt(a-1)===32;)o++,a--;if(a)break;a=-1}else if(u===-2)l=!0,o++;else if(u!==-1){s++;break}}if(t._contentTypeTextTrailing&&n===e.length&&(o=0),o){const u={type:n===e.length||l||o<2?"lineSuffix":"hardBreakTrailing",start:{_bufferIndex:s?a:r.start._bufferIndex+a,_index:r.start._index+s,line:r.end.line,column:r.end.column-o,offset:r.end.offset-o},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 cc={42:fe,43:fe,45:fe,48:fe,49:fe,50:fe,51:fe,52:fe,53:fe,54:fe,55:fe,56:fe,57:fe,62:es},hc={91:mu},dc={[-2]:Yt,[-1]:Yt,32:Yt},fc={35:ku,42:Mt,45:[Kr,Mt],60:Iu,61:Kr,95:Mt,96:Ur,126:Ur},pc={38:ns,92:ts},mc={[-5]:Jt,[-4]:Jt,[-3]:Jt,33:Hu,38:ns,42:An,60:[Vl,Lu],91:Vu,92:[bu,ts],93:Zn,95:An,96:iu},gc={null:[An,ac]},xc={null:[42,95]},yc={null:[]},bc=Object.freeze(Object.defineProperty({__proto__:null,attentionMarkers:xc,contentInitial:hc,disable:yc,document:cc,flow:fc,flowInitial:dc,insideSpan:gc,string:pc,text:mc},Symbol.toStringTag,{value:"Module"}));function Sc(e,t,n){let r={_bufferIndex:-1,_index:0,line:n&&n.line||1,column:n&&n.column||1,offset:n&&n.offset||0};const i={},s=[];let a=[],o=[];const l={attempt:P(A),check:P(C),consume:v,enter:k,exit:R,interrupt:P(C,{interrupt:!0})},u={code:null,containerState:{},defineSkip:m,events:[],now:x,parser:e,previous:null,sliceSerialize:p,sliceStream:f,write:c};let h=t.tokenize.call(u,l);return t.resolveAll&&s.push(t),u;function c(j){return a=Se(a,j),S(),a[a.length-1]!==null?[]:(F(t,0),u.events=Ut(s,u.events,u),u.events)}function p(j,_){return wc(f(j),_)}function f(j){return kc(a,j)}function x(){const{_bufferIndex:j,_index:_,line:W,column:D,offset:L}=r;return{_bufferIndex:j,_index:_,line:W,column:D,offset:L}}function m(j){i[j.line]=j.column,w()}function S(){let j;for(;r._index<a.length;){const _=a[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){h=h(j)}function v(j){O(j)?(r.line++,r.column=1,r.offset+=j===-3?2:1,w()):j!==-1&&(r.column++,r.offset++),r._bufferIndex<0?r._index++:(r._bufferIndex++,r._bufferIndex===a[r._index].length&&(r._bufferIndex=-1,r._index++)),u.previous=j}function k(j,_){const W=_||{};return W.type=j,W.start=x(),u.events.push(["enter",W,u]),o.push(W),W}function R(j){const _=o.pop();return _.end=x(),u.events.push(["exit",_,u]),_}function A(j,_){F(j,_.from)}function C(j,_){_.restore()}function P(j,_){return W;function W(D,L,G){let Y,le,ye,y;return Array.isArray(D)?ue(D):"tokenize"in D?ue([D]):he(D);function he(ee){return De;function De(ke){const Ee=ke!==null&&ee[ke],Ae=ke!==null&&ee.null,Be=[...Array.isArray(Ee)?Ee:Ee?[Ee]:[],...Array.isArray(Ae)?Ae:Ae?[Ae]:[]];return ue(Be)(ke)}}function ue(ee){return Y=ee,le=0,ee.length===0?G:b(ee[le])}function b(ee){return De;function De(ke){return y=B(),ye=ee,ee.partial||(u.currentConstruct=ee),ee.name&&u.parser.constructs.disable.null.includes(ee.name)?Ie():ee.tokenize.call(_?Object.assign(Object.create(u),_):u,l,de,Ie)(ke)}}function de(ee){return j(ye,y),L}function Ie(ee){return y.restore(),++le<Y.length?b(Y[le]):G}}}function F(j,_){j.resolveAll&&!s.includes(j)&&s.push(j),j.resolve&&xe(u.events,_,u.events.length-_,j.resolve(u.events.slice(_),u)),j.resolveTo&&(u.events=j.resolveTo(u.events,u))}function B(){const j=x(),_=u.previous,W=u.currentConstruct,D=u.events.length,L=Array.from(o);return{from:D,restore:G};function G(){r=j,u.previous=_,u.currentConstruct=W,u.events.length=D,o=L,w()}}function w(){r.line in i&&r.column<2&&(r.column=i[r.line],r.offset+=i[r.line]-1)}}function kc(e,t){const n=t.start._index,r=t.start._bufferIndex,i=t.end._index,s=t.end._bufferIndex;let a;if(n===i)a=[e[n].slice(r,s)];else{if(a=e.slice(n,i),r>-1){const o=a[0];typeof o=="string"?a[0]=o.slice(r):a.shift()}s>0&&a.push(e[i].slice(0,s))}return a}function wc(e,t){let n=-1;const r=[];let i;for(;++n<e.length;){const s=e[n];let a;if(typeof s=="string")a=s;else switch(s){case-5:{a="\r";break}case-4:{a=`
5
- `;break}case-3:{a=`\r
6
- `;break}case-2:{a=t?" ":" ";break}case-1:{if(!t&&i)continue;a=" ";break}default:a=String.fromCharCode(s)}i=s===-2,r.push(a)}return r.join("")}function vc(e){const r={constructs:Ji([bc,...(e||{}).extensions||[]]),content:i(zl),defined:[],document:i(Bl),flow:i(ic),lazy:{},string:i(oc),text:i(lc)};return r;function i(s){return a;function a(o){return Sc(r,s,o)}}}function Cc(e){for(;!rs(e););return e}const Vr=/[\0\t\n\r]/g;function Ic(){let e=1,t="",n=!0,r;return i;function i(s,a,o){const l=[];let u,h,c,p,f;for(s=t+(typeof s=="string"?s.toString():new TextDecoder(a||void 0).decode(s)),c=0,t="",n&&(s.charCodeAt(0)===65279&&c++,n=void 0);c<s.length;){if(Vr.lastIndex=c,u=Vr.exec(s),p=u&&u.index!==void 0?u.index:s.length,f=s.charCodeAt(p),!u){t=s.slice(c);break}if(f===10&&c===p&&r)l.push(-3),r=void 0;else switch(r&&(l.push(-5),r=void 0),c<p&&(l.push(s.slice(c,p)),e+=p-c),f){case 0:{l.push(65533),e++;break}case 9:{for(h=Math.ceil(e/4)*4,l.push(-2);e++<h;)l.push(-1);break}case 10:{l.push(-4),e=1;break}default:r=!0,e=1}c=p+1}return o&&(r&&l.push(-5),t&&l.push(t),l.push(null)),l}}const Tc=/\\([!-/:-@[-`{-~])|&(#(?:\d{1,7}|x[\da-f]{1,6})|[\da-z]{1,31});/gi;function Rc(e){return e.replace(Tc,Ec)}function Ec(e,t,n){if(t)return t;if(n.charCodeAt(0)===35){const i=n.charCodeAt(1),s=i===120||i===88;return Zi(n.slice(s?2:1),s?16:10)}return Jn(n)||e}const us={}.hasOwnProperty;function Ac(e,t,n){return t&&typeof t=="object"&&(n=t,t=void 0),Mc(n)(Cc(vc(n).document().write(Ic()(e,t,!0))))}function Mc(e){const t={transforms:[],canContainEols:["emphasis","fragment","heading","paragraph","strong"],enter:{autolink:s(dr),autolinkProtocol:B,autolinkEmail:B,atxHeading:s(ur),blockQuote:s(Ae),characterEscape:B,characterReference:B,codeFenced:s(Be),codeFencedFenceInfo:a,codeFencedFenceMeta:a,codeIndented:s(Be,a),codeText:s(be,a),codeTextData:B,data:B,codeFlowValue:B,definition:s(St),definitionDestinationString:a,definitionLabelString:a,definitionTitleString:a,emphasis:s(kt),hardBreakEscape:s(cr),hardBreakTrailing:s(cr),htmlFlow:s(hr,a),htmlFlowData:B,htmlText:s(hr,a),htmlTextData:B,image:s(Ks),label:a,link:s(dr),listItem:s(Vs),listItemValue:p,listOrdered:s(fr,c),listUnordered:s(fr),paragraph:s(qs),reference:b,referenceString:a,resourceDestinationString:a,resourceTitleString:a,setextHeading:s(ur),strong:s(Ws),thematicBreak:s(Xs)},exit:{atxHeading:l(),atxHeadingSequence:A,autolink:l(),autolinkEmail:Ee,autolinkProtocol:ke,blockQuote:l(),characterEscapeValue:w,characterReferenceMarkerHexadecimal:Ie,characterReferenceMarkerNumeric:Ie,characterReferenceValue:ee,characterReference:De,codeFenced:l(S),codeFencedFence:m,codeFencedFenceInfo:f,codeFencedFenceMeta:x,codeFlowValue:w,codeIndented:l(g),codeText:l(L),codeTextData:w,data:w,definition:l(),definitionDestinationString:R,definitionLabelString:v,definitionTitleString:k,emphasis:l(),hardBreakEscape:l(_),hardBreakTrailing:l(_),htmlFlow:l(W),htmlFlowData:w,htmlText:l(D),htmlTextData:w,image:l(Y),label:ye,labelText:le,lineEnding:j,link:l(G),listItem:l(),listOrdered:l(),listUnordered:l(),paragraph:l(),referenceString:de,resourceDestinationString:y,resourceTitleString:he,resource:ue,setextHeading:l(F),setextHeadingLineSequence:P,setextHeadingText:C,strong:l(),thematicBreak:l()}};cs(t,(e||{}).mdastExtensions||[]);const n={};return r;function r(I){let N={type:"root",children:[]};const $={stack:[N],tokenStack:[],config:t,enter:o,exit:u,buffer:a,resume:h,data:n},V=[];let X=-1;for(;++X<I.length;)if(I[X][1].type==="listOrdered"||I[X][1].type==="listUnordered")if(I[X][0]==="enter")V.push(X);else{const we=V.pop();X=i(I,we,X)}for(X=-1;++X<I.length;){const we=t[I[X][0]];us.call(we,I[X][1].type)&&we[I[X][1].type].call(Object.assign({sliceSerialize:I[X][2].sliceSerialize},$),I[X][1])}if($.tokenStack.length>0){const we=$.tokenStack[$.tokenStack.length-1];(we[1]||qr).call($,void 0,we[0])}for(N.position={start:Oe(I.length>0?I[0][1].start:{line:1,column:1,offset:0}),end:Oe(I.length>0?I[I.length-2][1].end:{line:1,column:1,offset:0})},X=-1;++X<t.transforms.length;)N=t.transforms[X](N)||N;return N}function i(I,N,$){let V=N-1,X=-1,we=!1,$e,Me,it,st;for(;++V<=$;){const me=I[V];switch(me[1].type){case"listUnordered":case"listOrdered":case"blockQuote":{me[0]==="enter"?X++:X--,st=void 0;break}case"lineEndingBlank":{me[0]==="enter"&&($e&&!st&&!X&&!it&&(it=V),st=void 0);break}case"linePrefix":case"listItemValue":case"listItemMarker":case"listItemPrefix":case"listItemPrefixWhitespace":break;default:st=void 0}if(!X&&me[0]==="enter"&&me[1].type==="listItemPrefix"||X===-1&&me[0]==="exit"&&(me[1].type==="listUnordered"||me[1].type==="listOrdered")){if($e){let qe=V;for(Me=void 0;qe--;){const Ne=I[qe];if(Ne[1].type==="lineEnding"||Ne[1].type==="lineEndingBlank"){if(Ne[0]==="exit")continue;Me&&(I[Me][1].type="lineEndingBlank",we=!0),Ne[1].type="lineEnding",Me=qe}else if(!(Ne[1].type==="linePrefix"||Ne[1].type==="blockQuotePrefix"||Ne[1].type==="blockQuotePrefixWhitespace"||Ne[1].type==="blockQuoteMarker"||Ne[1].type==="listItemIndent"))break}it&&(!Me||it<Me)&&($e._spread=!0),$e.end=Object.assign({},Me?I[Me][1].start:me[1].end),I.splice(Me||V,0,["exit",$e,me[2]]),V++,$++}if(me[1].type==="listItemPrefix"){const qe={type:"listItem",_spread:!1,start:Object.assign({},me[1].start),end:void 0};$e=qe,I.splice(V,0,["enter",qe,me[2]]),V++,$++,it=void 0,st=!0}}}return I[N][1]._spread=we,$}function s(I,N){return $;function $(V){o.call(this,I(V),V),N&&N.call(this,V)}}function a(){this.stack.push({type:"fragment",children:[]})}function o(I,N,$){this.stack[this.stack.length-1].children.push(I),this.stack.push(I),this.tokenStack.push([N,$||void 0]),I.position={start:Oe(N.start),end:void 0}}function l(I){return N;function N($){I&&I.call(this,$),u.call(this,$)}}function u(I,N){const $=this.stack.pop(),V=this.tokenStack.pop();if(V)V[0].type!==I.type&&(N?N.call(this,I,V[0]):(V[1]||qr).call(this,I,V[0]));else throw new Error("Cannot close `"+I.type+"` ("+ht({start:I.start,end:I.end})+"): it’s not open");$.position.end=Oe(I.end)}function h(){return Yn(this.stack.pop())}function c(){this.data.expectingFirstListItemValue=!0}function p(I){if(this.data.expectingFirstListItemValue){const N=this.stack[this.stack.length-2];N.start=Number.parseInt(this.sliceSerialize(I),10),this.data.expectingFirstListItemValue=void 0}}function f(){const I=this.resume(),N=this.stack[this.stack.length-1];N.lang=I}function x(){const I=this.resume(),N=this.stack[this.stack.length-1];N.meta=I}function m(){this.data.flowCodeInside||(this.buffer(),this.data.flowCodeInside=!0)}function S(){const I=this.resume(),N=this.stack[this.stack.length-1];N.value=I.replace(/^(\r?\n|\r)|(\r?\n|\r)$/g,""),this.data.flowCodeInside=void 0}function g(){const I=this.resume(),N=this.stack[this.stack.length-1];N.value=I.replace(/(\r?\n|\r)$/g,"")}function v(I){const N=this.resume(),$=this.stack[this.stack.length-1];$.label=N,$.identifier=Ce(this.sliceSerialize(I)).toLowerCase()}function k(){const I=this.resume(),N=this.stack[this.stack.length-1];N.title=I}function R(){const I=this.resume(),N=this.stack[this.stack.length-1];N.url=I}function A(I){const N=this.stack[this.stack.length-1];if(!N.depth){const $=this.sliceSerialize(I).length;N.depth=$}}function C(){this.data.setextHeadingSlurpLineEnding=!0}function P(I){const N=this.stack[this.stack.length-1];N.depth=this.sliceSerialize(I).codePointAt(0)===61?1:2}function F(){this.data.setextHeadingSlurpLineEnding=void 0}function B(I){const $=this.stack[this.stack.length-1].children;let V=$[$.length-1];(!V||V.type!=="text")&&(V=Gs(),V.position={start:Oe(I.start),end:void 0},$.push(V)),this.stack.push(V)}function w(I){const N=this.stack.pop();N.value+=this.sliceSerialize(I),N.position.end=Oe(I.end)}function j(I){const N=this.stack[this.stack.length-1];if(this.data.atHardBreak){const $=N.children[N.children.length-1];$.position.end=Oe(I.end),this.data.atHardBreak=void 0;return}!this.data.setextHeadingSlurpLineEnding&&t.canContainEols.includes(N.type)&&(B.call(this,I),w.call(this,I))}function _(){this.data.atHardBreak=!0}function W(){const I=this.resume(),N=this.stack[this.stack.length-1];N.value=I}function D(){const I=this.resume(),N=this.stack[this.stack.length-1];N.value=I}function L(){const I=this.resume(),N=this.stack[this.stack.length-1];N.value=I}function G(){const I=this.stack[this.stack.length-1];if(this.data.inReference){const N=this.data.referenceType||"shortcut";I.type+="Reference",I.referenceType=N,delete I.url,delete I.title}else delete I.identifier,delete I.label;this.data.referenceType=void 0}function Y(){const I=this.stack[this.stack.length-1];if(this.data.inReference){const N=this.data.referenceType||"shortcut";I.type+="Reference",I.referenceType=N,delete I.url,delete I.title}else delete I.identifier,delete I.label;this.data.referenceType=void 0}function le(I){const N=this.sliceSerialize(I),$=this.stack[this.stack.length-2];$.label=Rc(N),$.identifier=Ce(N).toLowerCase()}function ye(){const I=this.stack[this.stack.length-1],N=this.resume(),$=this.stack[this.stack.length-1];if(this.data.inReference=!0,$.type==="link"){const V=I.children;$.children=V}else $.alt=N}function y(){const I=this.resume(),N=this.stack[this.stack.length-1];N.url=I}function he(){const I=this.resume(),N=this.stack[this.stack.length-1];N.title=I}function ue(){this.data.inReference=void 0}function b(){this.data.referenceType="collapsed"}function de(I){const N=this.resume(),$=this.stack[this.stack.length-1];$.label=N,$.identifier=Ce(this.sliceSerialize(I)).toLowerCase(),this.data.referenceType="full"}function Ie(I){this.data.characterReferenceType=I.type}function ee(I){const N=this.sliceSerialize(I),$=this.data.characterReferenceType;let V;$?(V=Zi(N,$==="characterReferenceMarkerNumeric"?10:16),this.data.characterReferenceType=void 0):V=Jn(N);const X=this.stack[this.stack.length-1];X.value+=V}function De(I){const N=this.stack.pop();N.position.end=Oe(I.end)}function ke(I){w.call(this,I);const N=this.stack[this.stack.length-1];N.url=this.sliceSerialize(I)}function Ee(I){w.call(this,I);const N=this.stack[this.stack.length-1];N.url="mailto:"+this.sliceSerialize(I)}function Ae(){return{type:"blockquote",children:[]}}function Be(){return{type:"code",lang:null,meta:null,value:""}}function be(){return{type:"inlineCode",value:""}}function St(){return{type:"definition",identifier:"",label:null,title:null,url:""}}function kt(){return{type:"emphasis",children:[]}}function ur(){return{type:"heading",depth:0,children:[]}}function cr(){return{type:"break"}}function hr(){return{type:"html",value:""}}function Ks(){return{type:"image",title:null,url:"",alt:null}}function dr(){return{type:"link",title:null,url:"",children:[]}}function fr(I){return{type:"list",ordered:I.type==="listOrdered",start:null,spread:I._spread,children:[]}}function Vs(I){return{type:"listItem",spread:I._spread,checked:null,children:[]}}function qs(){return{type:"paragraph",children:[]}}function Ws(){return{type:"strong",children:[]}}function Gs(){return{type:"text",value:""}}function Xs(){return{type:"thematicBreak"}}}function Oe(e){return{line:e.line,column:e.column,offset:e.offset}}function cs(e,t){let n=-1;for(;++n<t.length;){const r=t[n];Array.isArray(r)?cs(e,r):Nc(e,r)}}function Nc(e,t){let n;for(n in t)if(us.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 qr(e,t){throw e?new Error("Cannot close `"+e.type+"` ("+ht({start:e.start,end:e.end})+"): a different token (`"+t.type+"`, "+ht({start:t.start,end:t.end})+") is open"):new Error("Cannot close document, a token (`"+t.type+"`, "+ht({start:t.start,end:t.end})+") is still open")}function Lc(e){const t=this;t.parser=n;function n(r){return Ac(r,{...t.data("settings"),...e,extensions:t.data("micromarkExtensions")||[],mdastExtensions:t.data("fromMarkdownExtensions")||[]})}}function jc(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 Pc(e,t){const n={type:"element",tagName:"br",properties:{},children:[]};return e.patch(t,n),[e.applyData(t,n),{type:"text",value:`
7
- `}]}function _c(e,t){const n=t.value?t.value+`
8
- `:"",r={},i=t.lang?t.lang.split(/\s+/):[];i.length>0&&(r.className=["language-"+i[0]]);let s={type:"element",tagName:"code",properties:r,children:[{type:"text",value:n}]};return t.meta&&(s.data={meta:t.meta}),e.patch(t,s),s=e.applyData(t,s),s={type:"element",tagName:"pre",properties:{},children:[s]},e.patch(t,s),s}function Dc(e,t){const n={type:"element",tagName:"del",properties:{},children:e.all(t)};return e.patch(t,n),e.applyData(t,n)}function Oc(e,t){const n={type:"element",tagName:"em",properties:{},children:e.all(t)};return e.patch(t,n),e.applyData(t,n)}function zc(e,t){const n=typeof e.options.clobberPrefix=="string"?e.options.clobberPrefix:"user-content-",r=String(t.identifier).toUpperCase(),i=rt(r.toLowerCase()),s=e.footnoteOrder.indexOf(r);let a,o=e.footnoteCounts.get(r);o===void 0?(o=0,e.footnoteOrder.push(r),a=e.footnoteOrder.length):a=s+1,o+=1,e.footnoteCounts.set(r,o);const l={type:"element",tagName:"a",properties:{href:"#"+n+"fn-"+i,id:n+"fnref-"+i+(o>1?"-"+o:""),dataFootnoteRef:!0,ariaDescribedBy:["footnote-label"]},children:[{type:"text",value:String(a)}]};e.patch(t,l);const u={type:"element",tagName:"sup",properties:{},children:[l]};return e.patch(t,u),e.applyData(t,u)}function Fc(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 Bc(e,t){if(e.options.allowDangerousHtml){const n={type:"raw",value:t.value};return e.patch(t,n),e.applyData(t,n)}}function hs(e,t){const n=t.referenceType;let r="]";if(n==="collapsed"?r+="[]":n==="full"&&(r+="["+(t.label||t.identifier)+"]"),t.type==="imageReference")return[{type:"text",value:"!["+t.alt+r}];const i=e.all(t),s=i[0];s&&s.type==="text"?s.value="["+s.value:i.unshift({type:"text",value:"["});const a=i[i.length-1];return a&&a.type==="text"?a.value+=r:i.push({type:"text",value:r}),i}function $c(e,t){const n=String(t.identifier).toUpperCase(),r=e.definitionById.get(n);if(!r)return hs(e,t);const i={src:rt(r.url||""),alt:t.alt};r.title!==null&&r.title!==void 0&&(i.title=r.title);const s={type:"element",tagName:"img",properties:i,children:[]};return e.patch(t,s),e.applyData(t,s)}function Uc(e,t){const n={src:rt(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 Hc(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 Kc(e,t){const n=String(t.identifier).toUpperCase(),r=e.definitionById.get(n);if(!r)return hs(e,t);const i={href:rt(r.url||"")};r.title!==null&&r.title!==void 0&&(i.title=r.title);const s={type:"element",tagName:"a",properties:i,children:e.all(t)};return e.patch(t,s),e.applyData(t,s)}function Vc(e,t){const n={href:rt(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 qc(e,t,n){const r=e.all(t),i=n?Wc(n):ds(t),s={},a=[];if(typeof t.checked=="boolean"){const h=r[0];let c;h&&h.type==="element"&&h.tagName==="p"?c=h:(c={type:"element",tagName:"p",properties:{},children:[]},r.unshift(c)),c.children.length>0&&c.children.unshift({type:"text",value:" "}),c.children.unshift({type:"element",tagName:"input",properties:{type:"checkbox",checked:t.checked,disabled:!0},children:[]}),s.className=["task-list-item"]}let o=-1;for(;++o<r.length;){const h=r[o];(i||o!==0||h.type!=="element"||h.tagName!=="p")&&a.push({type:"text",value:`
9
- `}),h.type==="element"&&h.tagName==="p"&&!i?a.push(...h.children):a.push(h)}const l=r[r.length-1];l&&(i||l.type!=="element"||l.tagName!=="p")&&a.push({type:"text",value:`
10
- `});const u={type:"element",tagName:"li",properties:s,children:a};return e.patch(t,u),e.applyData(t,u)}function Wc(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=ds(n[r])}return t}function ds(e){const t=e.spread;return t??e.children.length>1}function Gc(e,t){const n={},r=e.all(t);let i=-1;for(typeof t.start=="number"&&t.start!==1&&(n.start=t.start);++i<r.length;){const a=r[i];if(a.type==="element"&&a.tagName==="li"&&a.properties&&Array.isArray(a.properties.className)&&a.properties.className.includes("task-list-item")){n.className=["contains-task-list"];break}}const s={type:"element",tagName:t.ordered?"ol":"ul",properties:n,children:e.wrap(r,!0)};return e.patch(t,s),e.applyData(t,s)}function Xc(e,t){const n={type:"element",tagName:"p",properties:{},children:e.all(t)};return e.patch(t,n),e.applyData(t,n)}function Qc(e,t){const n={type:"root",children:e.wrap(e.all(t))};return e.patch(t,n),e.applyData(t,n)}function Yc(e,t){const n={type:"element",tagName:"strong",properties:{},children:e.all(t)};return e.patch(t,n),e.applyData(t,n)}function Jc(e,t){const n=e.all(t),r=n.shift(),i=[];if(r){const a={type:"element",tagName:"thead",properties:{},children:e.wrap([r],!0)};e.patch(t.children[0],a),i.push(a)}if(n.length>0){const a={type:"element",tagName:"tbody",properties:{},children:e.wrap(n,!0)},o=Wn(t.children[1]),l=Vi(t.children[t.children.length-1]);o&&l&&(a.position={start:o,end:l}),i.push(a)}const s={type:"element",tagName:"table",properties:{},children:e.wrap(i,!0)};return e.patch(t,s),e.applyData(t,s)}function Zc(e,t,n){const r=n?n.children:void 0,s=(r?r.indexOf(t):1)===0?"th":"td",a=n&&n.type==="table"?n.align:void 0,o=a?a.length:t.children.length;let l=-1;const u=[];for(;++l<o;){const c=t.children[l],p={},f=a?a[l]:void 0;f&&(p.align=f);let x={type:"element",tagName:s,properties:p,children:[]};c&&(x.children=e.all(c),e.patch(c,x),x=e.applyData(c,x)),u.push(x)}const h={type:"element",tagName:"tr",properties:{},children:e.wrap(u,!0)};return e.patch(t,h),e.applyData(t,h)}function eh(e,t){const n={type:"element",tagName:"td",properties:{},children:e.all(t)};return e.patch(t,n),e.applyData(t,n)}const Wr=9,Gr=32;function th(e){const t=String(e),n=/\r?\n|\r/g;let r=n.exec(t),i=0;const s=[];for(;r;)s.push(Xr(t.slice(i,r.index),i>0,!0),r[0]),i=r.index+r[0].length,r=n.exec(t);return s.push(Xr(t.slice(i),i>0,!1)),s.join("")}function Xr(e,t,n){let r=0,i=e.length;if(t){let s=e.codePointAt(r);for(;s===Wr||s===Gr;)r++,s=e.codePointAt(r)}if(n){let s=e.codePointAt(i-1);for(;s===Wr||s===Gr;)i--,s=e.codePointAt(i-1)}return i>r?e.slice(r,i):""}function nh(e,t){const n={type:"text",value:th(String(t.value))};return e.patch(t,n),e.applyData(t,n)}function rh(e,t){const n={type:"element",tagName:"hr",properties:{},children:[]};return e.patch(t,n),e.applyData(t,n)}const ih={blockquote:jc,break:Pc,code:_c,delete:Dc,emphasis:Oc,footnoteReference:zc,heading:Fc,html:Bc,imageReference:$c,image:Uc,inlineCode:Hc,linkReference:Kc,link:Vc,listItem:qc,list:Gc,paragraph:Xc,root:Qc,strong:Yc,table:Jc,tableCell:eh,tableRow:Zc,text:nh,thematicBreak:rh,toml:vt,yaml:vt,definition:vt,footnoteDefinition:vt};function vt(){}const fs=-1,Ht=0,ft=1,jt=2,er=3,tr=4,nr=5,rr=6,ps=7,ms=8,Qr=typeof self=="object"?self:globalThis,sh=(e,t)=>{const n=(i,s)=>(e.set(s,i),i),r=i=>{if(e.has(i))return e.get(i);const[s,a]=t[i];switch(s){case Ht:case fs:return n(a,i);case ft:{const o=n([],i);for(const l of a)o.push(r(l));return o}case jt:{const o=n({},i);for(const[l,u]of a)o[r(l)]=r(u);return o}case er:return n(new Date(a),i);case tr:{const{source:o,flags:l}=a;return n(new RegExp(o,l),i)}case nr:{const o=n(new Map,i);for(const[l,u]of a)o.set(r(l),r(u));return o}case rr:{const o=n(new Set,i);for(const l of a)o.add(r(l));return o}case ps:{const{name:o,message:l}=a;return n(new Qr[o](l),i)}case ms:return n(BigInt(a),i);case"BigInt":return n(Object(BigInt(a)),i);case"ArrayBuffer":return n(new Uint8Array(a).buffer,a);case"DataView":{const{buffer:o}=new Uint8Array(a);return n(new DataView(o),a)}}return n(new Qr[s](a),i)};return r},Yr=e=>sh(new Map,e)(0),Xe="",{toString:ah}={},{keys:oh}=Object,ut=e=>{const t=typeof e;if(t!=="object"||!e)return[Ht,t];const n=ah.call(e).slice(8,-1);switch(n){case"Array":return[ft,Xe];case"Object":return[jt,Xe];case"Date":return[er,Xe];case"RegExp":return[tr,Xe];case"Map":return[nr,Xe];case"Set":return[rr,Xe];case"DataView":return[ft,n]}return n.includes("Array")?[ft,n]:n.includes("Error")?[ps,n]:[jt,n]},Ct=([e,t])=>e===Ht&&(t==="function"||t==="symbol"),lh=(e,t,n,r)=>{const i=(a,o)=>{const l=r.push(a)-1;return n.set(o,l),l},s=a=>{if(n.has(a))return n.get(a);let[o,l]=ut(a);switch(o){case Ht:{let h=a;switch(l){case"bigint":o=ms,h=a.toString();break;case"function":case"symbol":if(e)throw new TypeError("unable to serialize "+l);h=null;break;case"undefined":return i([fs],a)}return i([o,h],a)}case ft:{if(l){let p=a;return l==="DataView"?p=new Uint8Array(a.buffer):l==="ArrayBuffer"&&(p=new Uint8Array(a)),i([l,[...p]],a)}const h=[],c=i([o,h],a);for(const p of a)h.push(s(p));return c}case jt:{if(l)switch(l){case"BigInt":return i([l,a.toString()],a);case"Boolean":case"Number":case"String":return i([l,a.valueOf()],a)}if(t&&"toJSON"in a)return s(a.toJSON());const h=[],c=i([o,h],a);for(const p of oh(a))(e||!Ct(ut(a[p])))&&h.push([s(p),s(a[p])]);return c}case er:return i([o,a.toISOString()],a);case tr:{const{source:h,flags:c}=a;return i([o,{source:h,flags:c}],a)}case nr:{const h=[],c=i([o,h],a);for(const[p,f]of a)(e||!(Ct(ut(p))||Ct(ut(f))))&&h.push([s(p),s(f)]);return c}case rr:{const h=[],c=i([o,h],a);for(const p of a)(e||!Ct(ut(p)))&&h.push(s(p));return c}}const{message:u}=a;return i([o,{name:l,message:u}],a)};return s},Jr=(e,{json:t,lossy:n}={})=>{const r=[];return lh(!(t||n),!!t,new Map,r)(e),r},Pt=typeof structuredClone=="function"?(e,t)=>t&&("json"in t||"lossy"in t)?Yr(Jr(e,t)):structuredClone(e):(e,t)=>Yr(Jr(e,t));function uh(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 ch(e,t){return"Back to reference "+(e+1)+(t>1?"-"+t:"")}function hh(e){const t=typeof e.options.clobberPrefix=="string"?e.options.clobberPrefix:"user-content-",n=e.options.footnoteBackContent||uh,r=e.options.footnoteBackLabel||ch,i=e.options.footnoteLabel||"Footnotes",s=e.options.footnoteLabelTagName||"h2",a=e.options.footnoteLabelProperties||{className:["sr-only"]},o=[];let l=-1;for(;++l<e.footnoteOrder.length;){const u=e.footnoteById.get(e.footnoteOrder[l]);if(!u)continue;const h=e.all(u),c=String(u.identifier).toUpperCase(),p=rt(c.toLowerCase());let f=0;const x=[],m=e.footnoteCounts.get(c);for(;m!==void 0&&++f<=m;){x.length>0&&x.push({type:"text",value:" "});let v=typeof n=="string"?n:n(l,f);typeof v=="string"&&(v={type:"text",value:v}),x.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 S=h[h.length-1];if(S&&S.type==="element"&&S.tagName==="p"){const v=S.children[S.children.length-1];v&&v.type==="text"?v.value+=" ":S.children.push({type:"text",value:" "}),S.children.push(...x)}else h.push(...x);const g={type:"element",tagName:"li",properties:{id:t+"fn-"+p},children:e.wrap(h,!0)};e.patch(u,g),o.push(g)}if(o.length!==0)return{type:"element",tagName:"section",properties:{dataFootnotes:!0,className:["footnotes"]},children:[{type:"element",tagName:s,properties:{...Pt(a),id:"footnote-label"},children:[{type:"text",value:i}]},{type:"text",value:`
11
- `},{type:"element",tagName:"ol",properties:{},children:e.wrap(o,!0)},{type:"text",value:`
12
- `}]}}const Kt=(function(e){if(e==null)return mh;if(typeof e=="function")return Vt(e);if(typeof e=="object")return Array.isArray(e)?dh(e):fh(e);if(typeof e=="string")return ph(e);throw new Error("Expected function, string, or object as test")});function dh(e){const t=[];let n=-1;for(;++n<e.length;)t[n]=Kt(e[n]);return Vt(r);function r(...i){let s=-1;for(;++s<t.length;)if(t[s].apply(this,i))return!0;return!1}}function fh(e){const t=e;return Vt(n);function n(r){const i=r;let s;for(s in e)if(i[s]!==t[s])return!1;return!0}}function ph(e){return Vt(t);function t(n){return n&&n.type===e}}function Vt(e){return t;function t(n,r,i){return!!(gh(n)&&e.call(this,n,typeof r=="number"?r:void 0,i||void 0))}}function mh(){return!0}function gh(e){return e!==null&&typeof e=="object"&&"type"in e}const gs=[],xh=!0,Mn=!1,yh="skip";function xs(e,t,n,r){let i;typeof t=="function"&&typeof n!="function"?(r=n,n=t):i=t;const s=Kt(i),a=r?-1:1;o(e,void 0,[])();function o(l,u,h){const c=l&&typeof l=="object"?l:{};if(typeof c.type=="string"){const f=typeof c.tagName=="string"?c.tagName:typeof c.name=="string"?c.name:void 0;Object.defineProperty(p,"name",{value:"node ("+(l.type+(f?"<"+f+">":""))+")"})}return p;function p(){let f=gs,x,m,S;if((!t||s(l,u,h[h.length-1]||void 0))&&(f=bh(n(l,h)),f[0]===Mn))return f;if("children"in l&&l.children){const g=l;if(g.children&&f[0]!==yh)for(m=(r?g.children.length:-1)+a,S=h.concat(g);m>-1&&m<g.children.length;){const v=g.children[m];if(x=o(v,m,S)(),x[0]===Mn)return x;m=typeof x[1]=="number"?x[1]:m+a}}return f}}}function bh(e){return Array.isArray(e)?e:typeof e=="number"?[xh,e]:e==null?gs:[e]}function ir(e,t,n,r){let i,s,a;typeof t=="function"&&typeof n!="function"?(s=void 0,a=t,i=n):(s=t,a=n,i=r),xs(e,s,o,i);function o(l,u){const h=u[u.length-1],c=h?h.children.indexOf(l):void 0;return a(l,c,h)}}const Nn={}.hasOwnProperty,Sh={};function kh(e,t){const n=t||Sh,r=new Map,i=new Map,s=new Map,a={...ih,...n.handlers},o={all:u,applyData:vh,definitionById:r,footnoteById:i,footnoteCounts:s,footnoteOrder:[],handlers:a,one:l,options:n,patch:wh,wrap:Ih};return ir(e,function(h){if(h.type==="definition"||h.type==="footnoteDefinition"){const c=h.type==="definition"?r:i,p=String(h.identifier).toUpperCase();c.has(p)||c.set(p,h)}}),o;function l(h,c){const p=h.type,f=o.handlers[p];if(Nn.call(o.handlers,p)&&f)return f(o,h,c);if(o.options.passThrough&&o.options.passThrough.includes(p)){if("children"in h){const{children:m,...S}=h,g=Pt(S);return g.children=o.all(h),g}return Pt(h)}return(o.options.unknownHandler||Ch)(o,h,c)}function u(h){const c=[];if("children"in h){const p=h.children;let f=-1;for(;++f<p.length;){const x=o.one(p[f],h);if(x){if(f&&p[f-1].type==="break"&&(!Array.isArray(x)&&x.type==="text"&&(x.value=Zr(x.value)),!Array.isArray(x)&&x.type==="element")){const m=x.children[0];m&&m.type==="text"&&(m.value=Zr(m.value))}Array.isArray(x)?c.push(...x):c.push(x)}}}return c}}function wh(e,t){e.position&&(t.position=cl(e))}function vh(e,t){let n=t;if(e&&e.data){const r=e.data.hName,i=e.data.hChildren,s=e.data.hProperties;if(typeof r=="string")if(n.type==="element")n.tagName=r;else{const a="children"in n?n.children:[n];n={type:"element",tagName:r,properties:{},children:a}}n.type==="element"&&s&&Object.assign(n.properties,Pt(s)),"children"in n&&n.children&&i!==null&&i!==void 0&&(n.children=i)}return n}function Ch(e,t){const n=t.data||{},r="value"in t&&!(Nn.call(n,"hProperties")||Nn.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 Ih(e,t){const n=[];let r=-1;for(t&&n.push({type:"text",value:`
13
- `});++r<e.length;)r&&n.push({type:"text",value:`
14
- `}),n.push(e[r]);return t&&e.length>0&&n.push({type:"text",value:`
15
- `}),n}function Zr(e){let t=0,n=e.charCodeAt(t);for(;n===9||n===32;)t++,n=e.charCodeAt(t);return e.slice(t)}function ei(e,t){const n=kh(e,t),r=n.one(e,void 0),i=hh(n),s=Array.isArray(r)?{type:"root",children:r}:r||{type:"root",children:[]};return i&&s.children.push({type:"text",value:`
16
- `},i),s}function Th(e,t){return e&&"run"in e?async function(n,r){const i=ei(n,{file:r,...t});await e.run(i,r)}:function(n,r){return ei(n,{file:r,...e||t})}}function ti(e){if(e)throw e}var Zt,ni;function Rh(){if(ni)return Zt;ni=1;var e=Object.prototype.hasOwnProperty,t=Object.prototype.toString,n=Object.defineProperty,r=Object.getOwnPropertyDescriptor,i=function(u){return typeof Array.isArray=="function"?Array.isArray(u):t.call(u)==="[object Array]"},s=function(u){if(!u||t.call(u)!=="[object Object]")return!1;var h=e.call(u,"constructor"),c=u.constructor&&u.constructor.prototype&&e.call(u.constructor.prototype,"isPrototypeOf");if(u.constructor&&!h&&!c)return!1;var p;for(p in u);return typeof p>"u"||e.call(u,p)},a=function(u,h){n&&h.name==="__proto__"?n(u,h.name,{enumerable:!0,configurable:!0,value:h.newValue,writable:!0}):u[h.name]=h.newValue},o=function(u,h){if(h==="__proto__")if(e.call(u,h)){if(r)return r(u,h).value}else return;return u[h]};return Zt=function l(){var u,h,c,p,f,x,m=arguments[0],S=1,g=arguments.length,v=!1;for(typeof m=="boolean"&&(v=m,m=arguments[1]||{},S=2),(m==null||typeof m!="object"&&typeof m!="function")&&(m={});S<g;++S)if(u=arguments[S],u!=null)for(h in u)c=o(m,h),p=o(u,h),m!==p&&(v&&p&&(s(p)||(f=i(p)))?(f?(f=!1,x=c&&i(c)?c:[]):x=c&&s(c)?c:{},a(m,{name:h,newValue:l(v,x,p)})):typeof p<"u"&&a(m,{name:h,newValue:p}));return m},Zt}var Eh=Rh();const en=Ci(Eh);function Ln(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 Ah(){const e=[],t={run:n,use:r};return t;function n(...i){let s=-1;const a=i.pop();if(typeof a!="function")throw new TypeError("Expected function as last argument, not "+a);o(null,...i);function o(l,...u){const h=e[++s];let c=-1;if(l){a(l);return}for(;++c<i.length;)(u[c]===null||u[c]===void 0)&&(u[c]=i[c]);i=u,h?Mh(h,o)(...u):a(null,...u)}}function r(i){if(typeof i!="function")throw new TypeError("Expected `middelware` to be a function, not "+i);return e.push(i),t}}function Mh(e,t){let n;return r;function r(...a){const o=e.length>a.length;let l;o&&a.push(i);try{l=e.apply(this,a)}catch(u){const h=u;if(o&&n)throw h;return i(h)}o||(l&&l.then&&typeof l.then=="function"?l.then(s,i):l instanceof Error?i(l):s(l))}function i(a,...o){n||(n=!0,t(a,...o))}function s(a){i(null,a)}}const Te={basename:Nh,dirname:Lh,extname:jh,join:Ph,sep:"/"};function Nh(e,t){if(t!==void 0&&typeof t!="string")throw new TypeError('"ext" argument must be a string');bt(e);let n=0,r=-1,i=e.length,s;if(t===void 0||t.length===0||t.length>e.length){for(;i--;)if(e.codePointAt(i)===47){if(s){n=i+1;break}}else r<0&&(s=!0,r=i+1);return r<0?"":e.slice(n,r)}if(t===e)return"";let a=-1,o=t.length-1;for(;i--;)if(e.codePointAt(i)===47){if(s){n=i+1;break}}else a<0&&(s=!0,a=i+1),o>-1&&(e.codePointAt(i)===t.codePointAt(o--)?o<0&&(r=i):(o=-1,r=a));return n===r?r=a:r<0&&(r=e.length),e.slice(n,r)}function Lh(e){if(bt(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 jh(e){bt(e);let t=e.length,n=-1,r=0,i=-1,s=0,a;for(;t--;){const o=e.codePointAt(t);if(o===47){if(a){r=t+1;break}continue}n<0&&(a=!0,n=t+1),o===46?i<0?i=t:s!==1&&(s=1):i>-1&&(s=-1)}return i<0||n<0||s===0||s===1&&i===n-1&&i===r+1?"":e.slice(i,n)}function Ph(...e){let t=-1,n;for(;++t<e.length;)bt(e[t]),e[t]&&(n=n===void 0?e[t]:n+"/"+e[t]);return n===void 0?".":_h(n)}function _h(e){bt(e);const t=e.codePointAt(0)===47;let n=Dh(e,!t);return n.length===0&&!t&&(n="."),n.length>0&&e.codePointAt(e.length-1)===47&&(n+="/"),t?"/"+n:n}function Dh(e,t){let n="",r=0,i=-1,s=0,a=-1,o,l;for(;++a<=e.length;){if(a<e.length)o=e.codePointAt(a);else{if(o===47)break;o=47}if(o===47){if(!(i===a-1||s===1))if(i!==a-1&&s===2){if(n.length<2||r!==2||n.codePointAt(n.length-1)!==46||n.codePointAt(n.length-2)!==46){if(n.length>2){if(l=n.lastIndexOf("/"),l!==n.length-1){l<0?(n="",r=0):(n=n.slice(0,l),r=n.length-1-n.lastIndexOf("/")),i=a,s=0;continue}}else if(n.length>0){n="",r=0,i=a,s=0;continue}}t&&(n=n.length>0?n+"/..":"..",r=2)}else n.length>0?n+="/"+e.slice(i+1,a):n=e.slice(i+1,a),r=a-i-1;i=a,s=0}else o===46&&s>-1?s++:s=-1}return n}function bt(e){if(typeof e!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(e))}const Oh={cwd:zh};function zh(){return"/"}function jn(e){return!!(e!==null&&typeof e=="object"&&"href"in e&&e.href&&"protocol"in e&&e.protocol&&e.auth===void 0)}function Fh(e){if(typeof e=="string")e=new URL(e);else if(!jn(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 Bh(e)}function Bh(e){if(e.hostname!==""){const r=new TypeError('File URL host must be "localhost" or empty on darwin');throw r.code="ERR_INVALID_FILE_URL_HOST",r}const t=e.pathname;let n=-1;for(;++n<t.length;)if(t.codePointAt(n)===37&&t.codePointAt(n+1)===50){const r=t.codePointAt(n+2);if(r===70||r===102){const i=new TypeError("File URL path must not include encoded / characters");throw i.code="ERR_INVALID_FILE_URL_PATH",i}}return decodeURIComponent(t)}const tn=["history","path","basename","stem","extname","dirname"];class ys{constructor(t){let n;t?jn(t)?n={path:t}:typeof t=="string"||$h(t)?n={value:t}:n=t:n={},this.cwd="cwd"in n?"":Oh.cwd(),this.data={},this.history=[],this.messages=[],this.value,this.map,this.result,this.stored;let r=-1;for(;++r<tn.length;){const s=tn[r];s in n&&n[s]!==void 0&&n[s]!==null&&(this[s]=s==="history"?[...n[s]]:n[s])}let i;for(i in n)tn.includes(i)||(this[i]=n[i])}get basename(){return typeof this.path=="string"?Te.basename(this.path):void 0}set basename(t){rn(t,"basename"),nn(t,"basename"),this.path=Te.join(this.dirname||"",t)}get dirname(){return typeof this.path=="string"?Te.dirname(this.path):void 0}set dirname(t){ri(this.basename,"dirname"),this.path=Te.join(t||"",this.basename)}get extname(){return typeof this.path=="string"?Te.extname(this.path):void 0}set extname(t){if(nn(t,"extname"),ri(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=Te.join(this.dirname,this.stem+(t||""))}get path(){return this.history[this.history.length-1]}set path(t){jn(t)&&(t=Fh(t)),rn(t,"path"),this.path!==t&&this.history.push(t)}get stem(){return typeof this.path=="string"?Te.basename(this.path,this.extname):void 0}set stem(t){rn(t,"stem"),nn(t,"stem"),this.path=Te.join(this.dirname||"",t+(this.extname||""))}fail(t,n,r){const i=this.message(t,n,r);throw i.fatal=!0,i}info(t,n,r){const i=this.message(t,n,r);return i.fatal=void 0,i}message(t,n,r){const i=new oe(t,n,r);return this.path&&(i.name=this.path+":"+i.name,i.file=this.path),i.fatal=!1,this.messages.push(i),i}toString(t){return this.value===void 0?"":typeof this.value=="string"?this.value:new TextDecoder(t||void 0).decode(this.value)}}function nn(e,t){if(e&&e.includes(Te.sep))throw new Error("`"+t+"` cannot be a path: did not expect `"+Te.sep+"`")}function rn(e,t){if(!e)throw new Error("`"+t+"` cannot be empty")}function ri(e,t){if(!e)throw new Error("Setting `"+t+"` requires `path` to be set too")}function $h(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}const Uh=(function(e){const r=this.constructor.prototype,i=r[e],s=function(){return i.apply(s,arguments)};return Object.setPrototypeOf(s,r),s}),Hh={}.hasOwnProperty;class sr extends Uh{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=Ah()}copy(){const t=new sr;let n=-1;for(;++n<this.attachers.length;){const r=this.attachers[n];t.use(...r)}return t.data(en(!0,{},this.namespace)),t}data(t,n){return typeof t=="string"?arguments.length===2?(on("data",this.frozen),this.namespace[t]=n,this):Hh.call(this.namespace,t)&&this.namespace[t]||void 0:t?(on("data",this.frozen),this.namespace=t,this):this.namespace}freeze(){if(this.frozen)return this;const t=this;for(;++this.freezeIndex<this.attachers.length;){const[n,...r]=this.attachers[this.freezeIndex];if(r[0]===!1)continue;r[0]===!0&&(r[0]=void 0);const i=n.call(t,...r);typeof i=="function"&&this.transformers.use(i)}return this.frozen=!0,this.freezeIndex=Number.POSITIVE_INFINITY,this}parse(t){this.freeze();const n=It(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),an("process",this.compiler||this.Compiler),n?i(void 0,n):new Promise(i);function i(s,a){const o=It(t),l=r.parse(o);r.run(l,o,function(h,c,p){if(h||!c||!p)return u(h);const f=c,x=r.stringify(f,p);qh(x)?p.value=x:p.result=x,u(h,p)});function u(h,c){h||!c?a(h):s?s(c):n(void 0,c)}}}processSync(t){let n=!1,r;return this.freeze(),sn("processSync",this.parser||this.Parser),an("processSync",this.compiler||this.Compiler),this.process(t,i),si("processSync","process",n),r;function i(s,a){n=!0,ti(s),r=a}}run(t,n,r){ii(t),this.freeze();const i=this.transformers;return!r&&typeof n=="function"&&(r=n,n=void 0),r?s(void 0,r):new Promise(s);function s(a,o){const l=It(n);i.run(t,l,u);function u(h,c,p){const f=c||t;h?o(h):a?a(f):r(void 0,f,p)}}}runSync(t,n){let r=!1,i;return this.run(t,n,s),si("runSync","run",r),i;function s(a,o){ti(a),i=o,r=!0}}stringify(t,n){this.freeze();const r=It(n),i=this.compiler||this.Compiler;return an("stringify",i),ii(t),i(t,r)}use(t,...n){const r=this.attachers,i=this.namespace;if(on("use",this.frozen),t!=null)if(typeof t=="function")l(t,n);else if(typeof t=="object")Array.isArray(t)?o(t):a(t);else throw new TypeError("Expected usable value, not `"+t+"`");return this;function s(u){if(typeof u=="function")l(u,[]);else if(typeof u=="object")if(Array.isArray(u)){const[h,...c]=u;l(h,c)}else a(u);else throw new TypeError("Expected usable value, not `"+u+"`")}function a(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");o(u.plugins),u.settings&&(i.settings=en(!0,i.settings,u.settings))}function o(u){let h=-1;if(u!=null)if(Array.isArray(u))for(;++h<u.length;){const c=u[h];s(c)}else throw new TypeError("Expected a list of plugins, not `"+u+"`")}function l(u,h){let c=-1,p=-1;for(;++c<r.length;)if(r[c][0]===u){p=c;break}if(p===-1)r.push([u,...h]);else if(h.length>0){let[f,...x]=h;const m=r[p][1];Ln(m)&&Ln(f)&&(f=en(!0,m,f)),r[p]=[u,f,...x]}}}}const Kh=new sr().freeze();function sn(e,t){if(typeof t!="function")throw new TypeError("Cannot `"+e+"` without `parser`")}function an(e,t){if(typeof t!="function")throw new TypeError("Cannot `"+e+"` without `compiler`")}function on(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 ii(e){if(!Ln(e)||typeof e.type!="string")throw new TypeError("Expected node, got `"+e+"`")}function si(e,t,n){if(!n)throw new Error("`"+e+"` finished async. Use `"+t+"` instead")}function It(e){return Vh(e)?e:new ys(e)}function Vh(e){return!!(e&&typeof e=="object"&&"message"in e&&"messages"in e)}function qh(e){return typeof e=="string"||Wh(e)}function Wh(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}const Gh="https://github.com/remarkjs/react-markdown/blob/main/changelog.md",ai=[],oi={allowDangerousHtml:!0},Xh=/^(https?|ircs?|mailto|xmpp)$/i,Qh=[{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 Yh(e){const t=Jh(e),n=Zh(e);return ed(t.runSync(t.parse(n),n),e)}function Jh(e){const t=e.rehypePlugins||ai,n=e.remarkPlugins||ai,r=e.remarkRehypeOptions?{...e.remarkRehypeOptions,...oi}:oi;return Kh().use(Lc).use(n).use(Th,r).use(t)}function Zh(e){const t=e.children||"",n=new ys;return typeof t=="string"&&(n.value=t),n}function ed(e,t){const n=t.allowedElements,r=t.allowElement,i=t.components,s=t.disallowedElements,a=t.skipHtml,o=t.unwrapDisallowed,l=t.urlTransform||td;for(const h of Qh)Object.hasOwn(t,h.from)&&(""+h.from+(h.to?"use `"+h.to+"` instead":"remove it")+Gh+h.id,void 0);return ir(e,u),ml(e,{Fragment:d.Fragment,components:i,ignoreInvalidStyle:!0,jsx:d.jsx,jsxs:d.jsxs,passKeys:!0,passNode:!0});function u(h,c,p){if(h.type==="raw"&&p&&typeof c=="number")return a?p.children.splice(c,1):p.children[c]={type:"text",value:h.value},c;if(h.type==="element"){let f;for(f in Qt)if(Object.hasOwn(Qt,f)&&Object.hasOwn(h.properties,f)){const x=h.properties[f],m=Qt[f];(m===null||m.includes(h.tagName))&&(h.properties[f]=l(String(x||""),f,h))}}if(h.type==="element"){let f=n?!n.includes(h.tagName):s?s.includes(h.tagName):!1;if(!f&&r&&typeof c=="number"&&(f=!r(h,c,p)),f&&p&&typeof c=="number")return o&&h.children?p.children.splice(c,1,...h.children):p.children.splice(c,1),c}}}function td(e){const t=e.indexOf(":"),n=e.indexOf("?"),r=e.indexOf("#"),i=e.indexOf("/");return t===-1||i!==-1&&t>i||n!==-1&&t>n||r!==-1&&t>r||Xh.test(e.slice(0,t))?e:""}function li(e,t){const n=String(e);if(typeof t!="string")throw new TypeError("Expected character");let r=0,i=n.indexOf(t);for(;i!==-1;)r++,i=n.indexOf(t,i+t.length);return r}function nd(e){if(typeof e!="string")throw new TypeError("Expected a string");return e.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}function rd(e,t,n){const i=Kt((n||{}).ignore||[]),s=id(t);let a=-1;for(;++a<s.length;)xs(e,"text",o);function o(u,h){let c=-1,p;for(;++c<h.length;){const f=h[c],x=p?p.children:void 0;if(i(f,x?x.indexOf(f):void 0,p))return;p=f}if(p)return l(u,h)}function l(u,h){const c=h[h.length-1],p=s[a][0],f=s[a][1];let x=0;const S=c.children.indexOf(u);let g=!1,v=[];p.lastIndex=0;let k=p.exec(u.value);for(;k;){const R=k.index,A={index:k.index,input:k.input,stack:[...h,u]};let C=f(...k,A);if(typeof C=="string"&&(C=C.length>0?{type:"text",value:C}:void 0),C===!1?p.lastIndex=R+1:(x!==R&&v.push({type:"text",value:u.value.slice(x,R)}),Array.isArray(C)?v.push(...C):C&&v.push(C),x=R+k[0].length,g=!0),!p.global)break;k=p.exec(u.value)}return g?(x<u.value.length&&v.push({type:"text",value:u.value.slice(x)}),c.children.splice(S,1,...v)):v=[u],S+v.length}}function id(e){const t=[];if(!Array.isArray(e))throw new TypeError("Expected find and replace tuple or list of tuples");const n=!e[0]||Array.isArray(e[0])?e:[e];let r=-1;for(;++r<n.length;){const i=n[r];t.push([sd(i[0]),ad(i[1])])}return t}function sd(e){return typeof e=="string"?new RegExp(nd(e),"g"):e}function ad(e){return typeof e=="function"?e:function(){return e}}const ln="phrasing",un=["autolink","link","image","label"];function od(){return{transforms:[pd],enter:{literalAutolink:ud,literalAutolinkEmail:cn,literalAutolinkHttp:cn,literalAutolinkWww:cn},exit:{literalAutolink:fd,literalAutolinkEmail:dd,literalAutolinkHttp:cd,literalAutolinkWww:hd}}}function ld(){return{unsafe:[{character:"@",before:"[+\\-.\\w]",after:"[\\-.\\w]",inConstruct:ln,notInConstruct:un},{character:".",before:"[Ww]",after:"[\\-.\\w]",inConstruct:ln,notInConstruct:un},{character:":",before:"[ps]",after:"\\/",inConstruct:ln,notInConstruct:un}]}}function ud(e){this.enter({type:"link",title:null,url:"",children:[]},e)}function cn(e){this.config.enter.autolinkProtocol.call(this,e)}function cd(e){this.config.exit.autolinkProtocol.call(this,e)}function hd(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 dd(e){this.config.exit.autolinkEmail.call(this,e)}function fd(e){this.exit(e)}function pd(e){rd(e,[[/(https?:\/\/|www(?=\.))([-.\w]+)([^ \t\r\n]*)/gi,md],[new RegExp("(?<=^|\\s|\\p{P}|\\p{S})([-.\\w+]+)@([-\\w]+(?:\\.[-\\w]+)+)","gu"),gd]],{ignore:["link","linkReference"]})}function md(e,t,n,r,i){let s="";if(!bs(i)||(/^w/i.test(t)&&(n=t+n,t="",s="http://"),!xd(n)))return!1;const a=yd(n+r);if(!a[0])return!1;const o={type:"link",title:null,url:s+t+a[0],children:[{type:"text",value:t+a[0]}]};return a[1]?[o,{type:"text",value:a[1]}]:o}function gd(e,t,n,r){return!bs(r,!0)||/[-\d_]$/.test(n)?!1:{type:"link",title:null,url:"mailto:"+t+"@"+n,children:[{type:"text",value:t+"@"+n}]}}function xd(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 yd(e){const t=/[!"&'),.:;<>?\]}]+$/.exec(e);if(!t)return[e,void 0];e=e.slice(0,t.index);let n=t[0],r=n.indexOf(")");const i=li(e,"(");let s=li(e,")");for(;r!==-1&&i>s;)e+=n.slice(0,r+1),n=n.slice(r+1),r=n.indexOf(")"),s++;return[e,n]}function bs(e,t){const n=e.input.charCodeAt(e.index-1);return(e.index===0||Ke(n)||$t(n))&&(!t||n!==47)}Ss.peek=Rd;function bd(){this.buffer()}function Sd(e){this.enter({type:"footnoteReference",identifier:"",label:""},e)}function kd(){this.buffer()}function wd(e){this.enter({type:"footnoteDefinition",identifier:"",label:"",children:[]},e)}function vd(e){const t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=Ce(this.sliceSerialize(e)).toLowerCase(),n.label=t}function Cd(e){this.exit(e)}function Id(e){const t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=Ce(this.sliceSerialize(e)).toLowerCase(),n.label=t}function Td(e){this.exit(e)}function Rd(){return"["}function Ss(e,t,n,r){const i=n.createTracker(r);let s=i.move("[^");const a=n.enter("footnoteReference"),o=n.enter("reference");return s+=i.move(n.safe(n.associationId(e),{after:"]",before:s})),o(),a(),s+=i.move("]"),s}function Ed(){return{enter:{gfmFootnoteCallString:bd,gfmFootnoteCall:Sd,gfmFootnoteDefinitionLabelString:kd,gfmFootnoteDefinition:wd},exit:{gfmFootnoteCallString:vd,gfmFootnoteCall:Cd,gfmFootnoteDefinitionLabelString:Id,gfmFootnoteDefinition:Td}}}function Ad(e){let t=!1;return e&&e.firstLineBlank&&(t=!0),{handlers:{footnoteDefinition:n,footnoteReference:Ss},unsafe:[{character:"[",inConstruct:["label","phrasing","reference"]}]};function n(r,i,s,a){const o=s.createTracker(a);let l=o.move("[^");const u=s.enter("footnoteDefinition"),h=s.enter("label");return l+=o.move(s.safe(s.associationId(r),{before:l,after:"]"})),h(),l+=o.move("]:"),r.children&&r.children.length>0&&(o.shift(4),l+=o.move((t?`
17
- `:" ")+s.indentLines(s.containerFlow(r,o.current()),t?ks:Md))),u(),l}}function Md(e,t,n){return t===0?e:ks(e,t,n)}function ks(e,t,n){return(n?"":" ")+e}const Nd=["autolink","destinationLiteral","destinationRaw","reference","titleQuote","titleApostrophe"];ws.peek=Dd;function Ld(){return{canContainEols:["delete"],enter:{strikethrough:Pd},exit:{strikethrough:_d}}}function jd(){return{unsafe:[{character:"~",inConstruct:"phrasing",notInConstruct:Nd}],handlers:{delete:ws}}}function Pd(e){this.enter({type:"delete",children:[]},e)}function _d(e){this.exit(e)}function ws(e,t,n,r){const i=n.createTracker(r),s=n.enter("strikethrough");let a=i.move("~~");return a+=n.containerPhrasing(e,{...i.current(),before:a,after:"~"}),a+=i.move("~~"),s(),a}function Dd(){return"~"}function Od(e){return e.length}function zd(e,t){const n=t||{},r=(n.align||[]).concat(),i=n.stringLength||Od,s=[],a=[],o=[],l=[];let u=0,h=-1;for(;++h<e.length;){const m=[],S=[];let g=-1;for(e[h].length>u&&(u=e[h].length);++g<e[h].length;){const v=Fd(e[h][g]);if(n.alignDelimiters!==!1){const k=i(v);S[g]=k,(l[g]===void 0||k>l[g])&&(l[g]=k)}m.push(v)}a[h]=m,o[h]=S}let c=-1;if(typeof r=="object"&&"length"in r)for(;++c<u;)s[c]=ui(r[c]);else{const m=ui(r);for(;++c<u;)s[c]=m}c=-1;const p=[],f=[];for(;++c<u;){const m=s[c];let S="",g="";m===99?(S=":",g=":"):m===108?S=":":m===114&&(g=":");let v=n.alignDelimiters===!1?1:Math.max(1,l[c]-S.length-g.length);const k=S+"-".repeat(v)+g;n.alignDelimiters!==!1&&(v=S.length+v+g.length,v>l[c]&&(l[c]=v),f[c]=v),p[c]=k}a.splice(1,0,p),o.splice(1,0,f),h=-1;const x=[];for(;++h<a.length;){const m=a[h],S=o[h];c=-1;const g=[];for(;++c<u;){const v=m[c]||"";let k="",R="";if(n.alignDelimiters!==!1){const A=l[c]-(S[c]||0),C=s[c];C===114?k=" ".repeat(A):C===99?A%2?(k=" ".repeat(A/2+.5),R=" ".repeat(A/2-.5)):(k=" ".repeat(A/2),R=k):R=" ".repeat(A)}n.delimiterStart!==!1&&!c&&g.push("|"),n.padding!==!1&&!(n.alignDelimiters===!1&&v==="")&&(n.delimiterStart!==!1||c)&&g.push(" "),n.alignDelimiters!==!1&&g.push(k),g.push(v),n.alignDelimiters!==!1&&g.push(R),n.padding!==!1&&g.push(" "),(n.delimiterEnd!==!1||c!==u-1)&&g.push("|")}x.push(n.delimiterEnd===!1?g.join("").replace(/ +$/,""):g.join(""))}return x.join(`
18
- `)}function Fd(e){return e==null?"":String(e)}function ui(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 Bd(e,t,n,r){const i=n.enter("blockquote"),s=n.createTracker(r);s.move("> "),s.shift(2);const a=n.indentLines(n.containerFlow(e,s.current()),$d);return i(),a}function $d(e,t,n){return">"+(n?"":" ")+e}function Ud(e,t){return ci(e,t.inConstruct,!0)&&!ci(e,t.notInConstruct,!1)}function ci(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 hi(e,t,n,r){let i=-1;for(;++i<n.unsafe.length;)if(n.unsafe[i].character===`
19
- `&&Ud(n.stack,n.unsafe[i]))return/[ \t]/.test(r.before)?"":" ";return`\\
20
- `}function Hd(e,t){const n=String(e);let r=n.indexOf(t),i=r,s=0,a=0;if(typeof t!="string")throw new TypeError("Expected substring");for(;r!==-1;)r===i?++s>a&&(a=s):s=1,i=r+t.length,r=n.indexOf(t,i);return a}function Kd(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 Vd(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 qd(e,t,n,r){const i=Vd(n),s=e.value||"",a=i==="`"?"GraveAccent":"Tilde";if(Kd(e,n)){const c=n.enter("codeIndented"),p=n.indentLines(s,Wd);return c(),p}const o=n.createTracker(r),l=i.repeat(Math.max(Hd(s,i)+1,3)),u=n.enter("codeFenced");let h=o.move(l);if(e.lang){const c=n.enter(`codeFencedLang${a}`);h+=o.move(n.safe(e.lang,{before:h,after:" ",encode:["`"],...o.current()})),c()}if(e.lang&&e.meta){const c=n.enter(`codeFencedMeta${a}`);h+=o.move(" "),h+=o.move(n.safe(e.meta,{before:h,after:`
21
- `,encode:["`"],...o.current()})),c()}return h+=o.move(`
22
- `),s&&(h+=o.move(s+`
23
- `)),h+=o.move(l),u(),h}function Wd(e,t,n){return(n?"":" ")+e}function ar(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 Gd(e,t,n,r){const i=ar(n),s=i==='"'?"Quote":"Apostrophe",a=n.enter("definition");let o=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("]: "),o(),!e.url||/[\0- \u007F]/.test(e.url)?(o=n.enter("destinationLiteral"),u+=l.move("<"),u+=l.move(n.safe(e.url,{before:u,after:">",...l.current()})),u+=l.move(">")):(o=n.enter("destinationRaw"),u+=l.move(n.safe(e.url,{before:u,after:e.title?" ":`
24
- `,...l.current()}))),o(),e.title&&(o=n.enter(`title${s}`),u+=l.move(" "+i),u+=l.move(n.safe(e.title,{before:u,after:i,...l.current()})),u+=l.move(i),o()),a(),u}function Xd(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 _t(e,t,n){const r=tt(e),i=tt(t);return r===void 0?i===void 0?n==="_"?{inside:!0,outside:!0}:{inside:!1,outside:!1}:i===1?{inside:!0,outside:!0}:{inside:!1,outside:!0}:r===1?i===void 0?{inside:!1,outside:!1}:i===1?{inside:!0,outside:!0}:{inside:!1,outside:!1}:i===void 0?{inside:!1,outside:!1}:i===1?{inside:!0,outside:!1}:{inside:!1,outside:!1}}vs.peek=Qd;function vs(e,t,n,r){const i=Xd(n),s=n.enter("emphasis"),a=n.createTracker(r),o=a.move(i);let l=a.move(n.containerPhrasing(e,{after:i,before:o,...a.current()}));const u=l.charCodeAt(0),h=_t(r.before.charCodeAt(r.before.length-1),u,i);h.inside&&(l=mt(u)+l.slice(1));const c=l.charCodeAt(l.length-1),p=_t(r.after.charCodeAt(0),c,i);p.inside&&(l=l.slice(0,-1)+mt(c));const f=a.move(i);return s(),n.attentionEncodeSurroundingInfo={after:p.outside,before:h.outside},o+l+f}function Qd(e,t,n){return n.options.emphasis||"*"}function Yd(e,t){let n=!1;return ir(e,function(r){if("value"in r&&/\r?\n|\r/.test(r.value)||r.type==="break")return n=!0,Mn}),!!((!e.depth||e.depth<3)&&Yn(e)&&(t.options.setext||n))}function Jd(e,t,n,r){const i=Math.max(Math.min(6,e.depth||1),1),s=n.createTracker(r);if(Yd(e,n)){const h=n.enter("headingSetext"),c=n.enter("phrasing"),p=n.containerPhrasing(e,{...s.current(),before:`
25
- `,after:`
26
- `});return c(),h(),p+`
27
- `+(i===1?"=":"-").repeat(p.length-(Math.max(p.lastIndexOf("\r"),p.lastIndexOf(`
28
- `))+1))}const a="#".repeat(i),o=n.enter("headingAtx"),l=n.enter("phrasing");s.move(a+" ");let u=n.containerPhrasing(e,{before:"# ",after:`
29
- `,...s.current()});return/^[\t ]/.test(u)&&(u=mt(u.charCodeAt(0))+u.slice(1)),u=u?a+" "+u:a,n.options.closeAtx&&(u+=" "+a),l(),o(),u}Cs.peek=Zd;function Cs(e){return e.value||""}function Zd(){return"<"}Is.peek=ef;function Is(e,t,n,r){const i=ar(n),s=i==='"'?"Quote":"Apostrophe",a=n.enter("image");let o=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("]("),o(),!e.url&&e.title||/[\0- \u007F]/.test(e.url)?(o=n.enter("destinationLiteral"),u+=l.move("<"),u+=l.move(n.safe(e.url,{before:u,after:">",...l.current()})),u+=l.move(">")):(o=n.enter("destinationRaw"),u+=l.move(n.safe(e.url,{before:u,after:e.title?" ":")",...l.current()}))),o(),e.title&&(o=n.enter(`title${s}`),u+=l.move(" "+i),u+=l.move(n.safe(e.title,{before:u,after:i,...l.current()})),u+=l.move(i),o()),u+=l.move(")"),a(),u}function ef(){return"!"}Ts.peek=tf;function Ts(e,t,n,r){const i=e.referenceType,s=n.enter("imageReference");let a=n.enter("label");const o=n.createTracker(r);let l=o.move("![");const u=n.safe(e.alt,{before:l,after:"]",...o.current()});l+=o.move(u+"]["),a();const h=n.stack;n.stack=[],a=n.enter("reference");const c=n.safe(n.associationId(e),{before:l,after:"]",...o.current()});return a(),n.stack=h,s(),i==="full"||!u||u!==c?l+=o.move(c+"]"):i==="shortcut"?l=l.slice(0,-1):l+=o.move("]"),l}function tf(){return"!"}Rs.peek=nf;function Rs(e,t,n){let r=e.value||"",i="`",s=-1;for(;new RegExp("(^|[^`])"+i+"([^`]|$)").test(r);)i+="`";for(/[^ \r\n]/.test(r)&&(/^[ \r\n]/.test(r)&&/[ \r\n]$/.test(r)||/^`|`$/.test(r))&&(r=" "+r+" ");++s<n.unsafe.length;){const a=n.unsafe[s],o=n.compilePattern(a);let l;if(a.atBreak)for(;l=o.exec(r);){let u=l.index;r.charCodeAt(u)===10&&r.charCodeAt(u-1)===13&&u--,r=r.slice(0,u)+" "+r.slice(l.index+1)}}return i+r+i}function nf(){return"`"}function Es(e,t){const n=Yn(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))}As.peek=rf;function As(e,t,n,r){const i=ar(n),s=i==='"'?"Quote":"Apostrophe",a=n.createTracker(r);let o,l;if(Es(e,n)){const h=n.stack;n.stack=[],o=n.enter("autolink");let c=a.move("<");return c+=a.move(n.containerPhrasing(e,{before:c,after:">",...a.current()})),c+=a.move(">"),o(),n.stack=h,c}o=n.enter("link"),l=n.enter("label");let u=a.move("[");return u+=a.move(n.containerPhrasing(e,{before:u,after:"](",...a.current()})),u+=a.move("]("),l(),!e.url&&e.title||/[\0- \u007F]/.test(e.url)?(l=n.enter("destinationLiteral"),u+=a.move("<"),u+=a.move(n.safe(e.url,{before:u,after:">",...a.current()})),u+=a.move(">")):(l=n.enter("destinationRaw"),u+=a.move(n.safe(e.url,{before:u,after:e.title?" ":")",...a.current()}))),l(),e.title&&(l=n.enter(`title${s}`),u+=a.move(" "+i),u+=a.move(n.safe(e.title,{before:u,after:i,...a.current()})),u+=a.move(i),l()),u+=a.move(")"),o(),u}function rf(e,t,n){return Es(e,n)?"<":"["}Ms.peek=sf;function Ms(e,t,n,r){const i=e.referenceType,s=n.enter("linkReference");let a=n.enter("label");const o=n.createTracker(r);let l=o.move("[");const u=n.containerPhrasing(e,{before:l,after:"]",...o.current()});l+=o.move(u+"]["),a();const h=n.stack;n.stack=[],a=n.enter("reference");const c=n.safe(n.associationId(e),{before:l,after:"]",...o.current()});return a(),n.stack=h,s(),i==="full"||!u||u!==c?l+=o.move(c+"]"):i==="shortcut"?l=l.slice(0,-1):l+=o.move("]"),l}function sf(){return"["}function or(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 af(e){const t=or(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 of(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 Ns(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 lf(e,t,n,r){const i=n.enter("list"),s=n.bulletCurrent;let a=e.ordered?of(n):or(n);const o=e.ordered?a==="."?")":".":af(n);let l=t&&n.bulletLastUsed?a===n.bulletLastUsed:!1;if(!e.ordered){const h=e.children?e.children[0]:void 0;if((a==="*"||a==="-")&&h&&(!h.children||!h.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),Ns(n)===a&&h){let c=-1;for(;++c<e.children.length;){const p=e.children[c];if(p&&p.type==="listItem"&&p.children&&p.children[0]&&p.children[0].type==="thematicBreak"){l=!0;break}}}}l&&(a=o),n.bulletCurrent=a;const u=n.containerFlow(e,r);return n.bulletLastUsed=a,n.bulletCurrent=s,i(),u}function uf(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 cf(e,t,n,r){const i=uf(n);let s=n.bulletCurrent||or(n);t&&t.type==="list"&&t.ordered&&(s=(typeof t.start=="number"&&t.start>-1?t.start:1)+(n.options.incrementListMarker===!1?0:t.children.indexOf(e))+s);let a=s.length+1;(i==="tab"||i==="mixed"&&(t&&t.type==="list"&&t.spread||e.spread))&&(a=Math.ceil(a/4)*4);const o=n.createTracker(r);o.move(s+" ".repeat(a-s.length)),o.shift(a);const l=n.enter("listItem"),u=n.indentLines(n.containerFlow(e,o.current()),h);return l(),u;function h(c,p,f){return p?(f?"":" ".repeat(a))+c:(f?s:s+" ".repeat(a-s.length))+c}}function hf(e,t,n,r){const i=n.enter("paragraph"),s=n.enter("phrasing"),a=n.containerPhrasing(e,r);return s(),i(),a}const df=Kt(["break","delete","emphasis","footnote","footnoteReference","image","imageReference","inlineCode","inlineMath","link","linkReference","mdxJsxTextElement","mdxTextExpression","strong","text","textDirective"]);function ff(e,t,n,r){return(e.children.some(function(a){return df(a)})?n.containerPhrasing:n.containerFlow).call(n,e,r)}function pf(e){const t=e.options.strong||"*";if(t!=="*"&&t!=="_")throw new Error("Cannot serialize strong with `"+t+"` for `options.strong`, expected `*`, or `_`");return t}Ls.peek=mf;function Ls(e,t,n,r){const i=pf(n),s=n.enter("strong"),a=n.createTracker(r),o=a.move(i+i);let l=a.move(n.containerPhrasing(e,{after:i,before:o,...a.current()}));const u=l.charCodeAt(0),h=_t(r.before.charCodeAt(r.before.length-1),u,i);h.inside&&(l=mt(u)+l.slice(1));const c=l.charCodeAt(l.length-1),p=_t(r.after.charCodeAt(0),c,i);p.inside&&(l=l.slice(0,-1)+mt(c));const f=a.move(i+i);return s(),n.attentionEncodeSurroundingInfo={after:p.outside,before:h.outside},o+l+f}function mf(e,t,n){return n.options.strong||"*"}function gf(e,t,n,r){return n.safe(e.value,r)}function xf(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 yf(e,t,n){const r=(Ns(n)+(n.options.ruleSpaces?" ":"")).repeat(xf(n));return n.options.ruleSpaces?r.slice(0,-1):r}const js={blockquote:Bd,break:hi,code:qd,definition:Gd,emphasis:vs,hardBreak:hi,heading:Jd,html:Cs,image:Is,imageReference:Ts,inlineCode:Rs,link:As,linkReference:Ms,list:lf,listItem:cf,paragraph:hf,root:ff,strong:Ls,text:gf,thematicBreak:yf};function bf(){return{enter:{table:Sf,tableData:di,tableHeader:di,tableRow:wf},exit:{codeText:vf,table:kf,tableData:hn,tableHeader:hn,tableRow:hn}}}function Sf(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 kf(e){this.exit(e),this.data.inTable=void 0}function wf(e){this.enter({type:"tableRow",children:[]},e)}function hn(e){this.exit(e)}function di(e){this.enter({type:"tableCell",children:[]},e)}function vf(e){let t=this.resume();this.data.inTable&&(t=t.replace(/\\([\\|])/g,Cf));const n=this.stack[this.stack.length-1];n.type,n.value=t,this.exit(e)}function Cf(e,t){return t==="|"?t:e}function If(e){const t=e||{},n=t.tableCellPadding,r=t.tablePipeAlign,i=t.stringLength,s=n?" ":"|";return{unsafe:[{character:"\r",inConstruct:"tableCell"},{character:`
30
- `,inConstruct:"tableCell"},{atBreak:!0,character:"|",after:"[ :-]"},{character:"|",inConstruct:"tableCell"},{atBreak:!0,character:":",after:"-"},{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{inlineCode:p,table:a,tableCell:l,tableRow:o}};function a(f,x,m,S){return u(h(f,m,S),f.align)}function o(f,x,m,S){const g=c(f,m,S),v=u([g]);return v.slice(0,v.indexOf(`
31
- `))}function l(f,x,m,S){const g=m.enter("tableCell"),v=m.enter("phrasing"),k=m.containerPhrasing(f,{...S,before:s,after:s});return v(),g(),k}function u(f,x){return zd(f,{align:x,alignDelimiters:r,padding:n,stringLength:i})}function h(f,x,m){const S=f.children;let g=-1;const v=[],k=x.enter("table");for(;++g<S.length;)v[g]=c(S[g],x,m);return k(),v}function c(f,x,m){const S=f.children;let g=-1;const v=[],k=x.enter("tableRow");for(;++g<S.length;)v[g]=l(S[g],f,x,m);return k(),v}function p(f,x,m){let S=js.inlineCode(f,x,m);return m.stack.includes("tableCell")&&(S=S.replace(/\|/g,"\\$&")),S}}function Tf(){return{exit:{taskListCheckValueChecked:fi,taskListCheckValueUnchecked:fi,paragraph:Ef}}}function Rf(){return{unsafe:[{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{listItem:Af}}}function fi(e){const t=this.stack[this.stack.length-2];t.type,t.checked=e.type==="taskListCheckValueChecked"}function Ef(e){const t=this.stack[this.stack.length-2];if(t&&t.type==="listItem"&&typeof t.checked=="boolean"){const n=this.stack[this.stack.length-1];n.type;const r=n.children[0];if(r&&r.type==="text"){const i=t.children;let s=-1,a;for(;++s<i.length;){const o=i[s];if(o.type==="paragraph"){a=o;break}}a===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 Af(e,t,n,r){const i=e.children[0],s=typeof e.checked=="boolean"&&i&&i.type==="paragraph",a="["+(e.checked?"x":" ")+"] ",o=n.createTracker(r);s&&o.move(a);let l=js.listItem(e,t,n,{...r,...o.current()});return s&&(l=l.replace(/^(?:[*+-]|\d+\.)([\r\n]| {1,3})/,u)),l;function u(h){return h+a}}function Mf(){return[od(),Ed(),Ld(),bf(),Tf()]}function Nf(e){return{extensions:[ld(),Ad(e),jd(),If(e),Rf()]}}const Lf={tokenize:zf,partial:!0},Ps={tokenize:Ff,partial:!0},_s={tokenize:Bf,partial:!0},Ds={tokenize:$f,partial:!0},jf={tokenize:Uf,partial:!0},Os={name:"wwwAutolink",tokenize:Df,previous:Fs},zs={name:"protocolAutolink",tokenize:Of,previous:Bs},_e={name:"emailAutolink",tokenize:_f,previous:$s},Re={};function Pf(){return{text:Re}}let Ue=48;for(;Ue<123;)Re[Ue]=_e,Ue++,Ue===58?Ue=65:Ue===91&&(Ue=97);Re[43]=_e;Re[45]=_e;Re[46]=_e;Re[95]=_e;Re[72]=[_e,zs];Re[104]=[_e,zs];Re[87]=[_e,Os];Re[119]=[_e,Os];function _f(e,t,n){const r=this;let i,s;return a;function a(c){return!Pn(c)||!$s.call(r,r.previous)||lr(r.events)?n(c):(e.enter("literalAutolink"),e.enter("literalAutolinkEmail"),o(c))}function o(c){return Pn(c)?(e.consume(c),o):c===64?(e.consume(c),l):n(c)}function l(c){return c===46?e.check(jf,h,u)(c):c===45||c===95||ae(c)?(s=!0,e.consume(c),l):h(c)}function u(c){return e.consume(c),i=!0,l}function h(c){return s&&i&&ce(r.previous)?(e.exit("literalAutolinkEmail"),e.exit("literalAutolink"),t(c)):n(c)}}function Df(e,t,n){const r=this;return i;function i(a){return a!==87&&a!==119||!Fs.call(r,r.previous)||lr(r.events)?n(a):(e.enter("literalAutolink"),e.enter("literalAutolinkWww"),e.check(Lf,e.attempt(Ps,e.attempt(_s,s),n),n)(a))}function s(a){return e.exit("literalAutolinkWww"),e.exit("literalAutolink"),t(a)}}function Of(e,t,n){const r=this;let i="",s=!1;return a;function a(c){return(c===72||c===104)&&Bs.call(r,r.previous)&&!lr(r.events)?(e.enter("literalAutolink"),e.enter("literalAutolinkHttp"),i+=String.fromCodePoint(c),e.consume(c),o):n(c)}function o(c){if(ce(c)&&i.length<5)return i+=String.fromCodePoint(c),e.consume(c),o;if(c===58){const p=i.toLowerCase();if(p==="http"||p==="https")return e.consume(c),l}return n(c)}function l(c){return c===47?(e.consume(c),s?u:(s=!0,l)):n(c)}function u(c){return c===null||Lt(c)||Q(c)||Ke(c)||$t(c)?n(c):e.attempt(Ps,e.attempt(_s,h),n)(c)}function h(c){return e.exit("literalAutolinkHttp"),e.exit("literalAutolink"),t(c)}}function zf(e,t,n){let r=0;return i;function i(a){return(a===87||a===119)&&r<3?(r++,e.consume(a),i):a===46&&r===3?(e.consume(a),s):n(a)}function s(a){return a===null?n(a):t(a)}}function Ff(e,t,n){let r,i,s;return a;function a(u){return u===46||u===95?e.check(Ds,l,o)(u):u===null||Q(u)||Ke(u)||u!==45&&$t(u)?l(u):(s=!0,e.consume(u),a)}function o(u){return u===95?r=!0:(i=r,r=void 0),e.consume(u),a}function l(u){return i||r||!s?n(u):t(u)}}function Bf(e,t){let n=0,r=0;return i;function i(a){return a===40?(n++,e.consume(a),i):a===41&&r<n?s(a):a===33||a===34||a===38||a===39||a===41||a===42||a===44||a===46||a===58||a===59||a===60||a===63||a===93||a===95||a===126?e.check(Ds,t,s)(a):a===null||Q(a)||Ke(a)?t(a):(e.consume(a),i)}function s(a){return a===41&&r++,e.consume(a),i}}function $f(e,t,n){return r;function r(o){return o===33||o===34||o===39||o===41||o===42||o===44||o===46||o===58||o===59||o===63||o===95||o===126?(e.consume(o),r):o===38?(e.consume(o),s):o===93?(e.consume(o),i):o===60||o===null||Q(o)||Ke(o)?t(o):n(o)}function i(o){return o===null||o===40||o===91||Q(o)||Ke(o)?t(o):r(o)}function s(o){return ce(o)?a(o):n(o)}function a(o){return o===59?(e.consume(o),r):ce(o)?(e.consume(o),a):n(o)}}function Uf(e,t,n){return r;function r(s){return e.consume(s),i}function i(s){return ae(s)?n(s):t(s)}}function Fs(e){return e===null||e===40||e===42||e===95||e===91||e===93||e===126||Q(e)}function Bs(e){return!ce(e)}function $s(e){return!(e===47||Pn(e))}function Pn(e){return e===43||e===45||e===46||e===95||ae(e)}function lr(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 Hf={tokenize:Yf,partial:!0};function Kf(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:Gf,continuation:{tokenize:Xf},exit:Qf}},text:{91:{name:"gfmFootnoteCall",tokenize:Wf},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:Vf,resolveTo:qf}}}}function Vf(e,t,n){const r=this;let i=r.events.length;const s=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let a;for(;i--;){const l=r.events[i][1];if(l.type==="labelImage"){a=l;break}if(l.type==="gfmFootnoteCall"||l.type==="labelLink"||l.type==="label"||l.type==="image"||l.type==="link")break}return o;function o(l){if(!a||!a._balanced)return n(l);const u=Ce(r.sliceSerialize({start:a.end,end:r.now()}));return u.codePointAt(0)!==94||!s.includes(u.slice(1))?n(l):(e.enter("gfmFootnoteCallLabelMarker"),e.consume(l),e.exit("gfmFootnoteCallLabelMarker"),t(l))}}function qf(e,t){let n=e.length;for(;n--;)if(e[n][1].type==="labelImage"&&e[n][0]==="enter"){e[n][1];break}e[n+1][1].type="data",e[n+3][1].type="gfmFootnoteCallLabelMarker";const r={type:"gfmFootnoteCall",start:Object.assign({},e[n+3][1].start),end:Object.assign({},e[e.length-1][1].end)},i={type:"gfmFootnoteCallMarker",start:Object.assign({},e[n+3][1].end),end:Object.assign({},e[n+3][1].end)};i.end.column++,i.end.offset++,i.end._bufferIndex++;const s={type:"gfmFootnoteCallString",start:Object.assign({},i.end),end:Object.assign({},e[e.length-1][1].start)},a={type:"chunkString",contentType:"string",start:Object.assign({},s.start),end:Object.assign({},s.end)},o=[e[n+1],e[n+2],["enter",r,t],e[n+3],e[n+4],["enter",i,t],["exit",i,t],["enter",s,t],["enter",a,t],["exit",a,t],["exit",s,t],e[e.length-2],e[e.length-1],["exit",r,t]];return e.splice(n,e.length-n+1,...o),e}function Wf(e,t,n){const r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let s=0,a;return o;function o(c){return e.enter("gfmFootnoteCall"),e.enter("gfmFootnoteCallLabelMarker"),e.consume(c),e.exit("gfmFootnoteCallLabelMarker"),l}function l(c){return c!==94?n(c):(e.enter("gfmFootnoteCallMarker"),e.consume(c),e.exit("gfmFootnoteCallMarker"),e.enter("gfmFootnoteCallString"),e.enter("chunkString").contentType="string",u)}function u(c){if(s>999||c===93&&!a||c===null||c===91||Q(c))return n(c);if(c===93){e.exit("chunkString");const p=e.exit("gfmFootnoteCallString");return i.includes(Ce(r.sliceSerialize(p)))?(e.enter("gfmFootnoteCallLabelMarker"),e.consume(c),e.exit("gfmFootnoteCallLabelMarker"),e.exit("gfmFootnoteCall"),t):n(c)}return Q(c)||(a=!0),s++,e.consume(c),c===92?h:u}function h(c){return c===91||c===92||c===93?(e.consume(c),s++,u):u(c)}}function Gf(e,t,n){const r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let s,a=0,o;return l;function l(x){return e.enter("gfmFootnoteDefinition")._container=!0,e.enter("gfmFootnoteDefinitionLabel"),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(x),e.exit("gfmFootnoteDefinitionLabelMarker"),u}function u(x){return x===94?(e.enter("gfmFootnoteDefinitionMarker"),e.consume(x),e.exit("gfmFootnoteDefinitionMarker"),e.enter("gfmFootnoteDefinitionLabelString"),e.enter("chunkString").contentType="string",h):n(x)}function h(x){if(a>999||x===93&&!o||x===null||x===91||Q(x))return n(x);if(x===93){e.exit("chunkString");const m=e.exit("gfmFootnoteDefinitionLabelString");return s=Ce(r.sliceSerialize(m)),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(x),e.exit("gfmFootnoteDefinitionLabelMarker"),e.exit("gfmFootnoteDefinitionLabel"),p}return Q(x)||(o=!0),a++,e.consume(x),x===92?c:h}function c(x){return x===91||x===92||x===93?(e.consume(x),a++,h):h(x)}function p(x){return x===58?(e.enter("definitionMarker"),e.consume(x),e.exit("definitionMarker"),i.includes(s)||i.push(s),q(e,f,"gfmFootnoteDefinitionWhitespace")):n(x)}function f(x){return t(x)}}function Xf(e,t,n){return e.check(yt,t,e.attempt(Hf,t,n))}function Qf(e){e.exit("gfmFootnoteDefinition")}function Yf(e,t,n){const r=this;return q(e,i,"gfmFootnoteDefinitionIndent",5);function i(s){const a=r.events[r.events.length-1];return a&&a[1].type==="gfmFootnoteDefinitionIndent"&&a[2].sliceSerialize(a[1],!0).length===4?t(s):n(s)}}function Jf(e){let n=(e||{}).singleTilde;const r={name:"strikethrough",tokenize:s,resolveAll:i};return n==null&&(n=!0),{text:{126:r},insideSpan:{null:[r]},attentionMarkers:{null:[126]}};function i(a,o){let l=-1;for(;++l<a.length;)if(a[l][0]==="enter"&&a[l][1].type==="strikethroughSequenceTemporary"&&a[l][1]._close){let u=l;for(;u--;)if(a[u][0]==="exit"&&a[u][1].type==="strikethroughSequenceTemporary"&&a[u][1]._open&&a[l][1].end.offset-a[l][1].start.offset===a[u][1].end.offset-a[u][1].start.offset){a[l][1].type="strikethroughSequence",a[u][1].type="strikethroughSequence";const h={type:"strikethrough",start:Object.assign({},a[u][1].start),end:Object.assign({},a[l][1].end)},c={type:"strikethroughText",start:Object.assign({},a[u][1].end),end:Object.assign({},a[l][1].start)},p=[["enter",h,o],["enter",a[u][1],o],["exit",a[u][1],o],["enter",c,o]],f=o.parser.constructs.insideSpan.null;f&&xe(p,p.length,0,Ut(f,a.slice(u+1,l),o)),xe(p,p.length,0,[["exit",c,o],["enter",a[l][1],o],["exit",a[l][1],o],["exit",h,o]]),xe(a,u-1,l-u+3,p),l=u+p.length-2;break}}for(l=-1;++l<a.length;)a[l][1].type==="strikethroughSequenceTemporary"&&(a[l][1].type="data");return a}function s(a,o,l){const u=this.previous,h=this.events;let c=0;return p;function p(x){return u===126&&h[h.length-1][1].type!=="characterEscape"?l(x):(a.enter("strikethroughSequenceTemporary"),f(x))}function f(x){const m=tt(u);if(x===126)return c>1?l(x):(a.consume(x),c++,f);if(c<2&&!n)return l(x);const S=a.exit("strikethroughSequenceTemporary"),g=tt(x);return S._open=!g||g===2&&!!m,S._close=!m||m===2&&!!g,o(x)}}}class Zf{constructor(){this.map=[]}add(t,n,r){ep(this,t,n,r)}consume(t){if(this.map.sort(function(s,a){return s[0]-a[0]}),this.map.length===0)return;let n=this.map.length;const r=[];for(;n>0;)n-=1,r.push(t.slice(this.map[n][0]+this.map[n][1]),this.map[n][2]),t.length=this.map[n][0];r.push(t.slice()),t.length=0;let i=r.pop();for(;i;){for(const s of i)t.push(s);i=r.pop()}this.map.length=0}}function ep(e,t,n,r){let i=0;if(!(n===0&&r.length===0)){for(;i<e.map.length;){if(e.map[i][0]===t){e.map[i][1]+=n,e.map[i][2].push(...r);return}i+=1}e.map.push([t,n,r])}}function tp(e,t){let n=!1;const r=[];for(;t<e.length;){const i=e[t];if(n){if(i[0]==="enter")i[1].type==="tableContent"&&r.push(e[t+1][1].type==="tableDelimiterMarker"?"left":"none");else if(i[1].type==="tableContent"){if(e[t-1][1].type==="tableDelimiterMarker"){const s=r.length-1;r[s]=r[s]==="left"?"center":"right"}}else if(i[1].type==="tableDelimiterRow")break}else i[0]==="enter"&&i[1].type==="tableDelimiterRow"&&(n=!0);t+=1}return r}function np(){return{flow:{null:{name:"table",tokenize:rp,resolveAll:ip}}}}function rp(e,t,n){const r=this;let i=0,s=0,a;return o;function o(w){let j=r.events.length-1;for(;j>-1;){const D=r.events[j][1].type;if(D==="lineEnding"||D==="linePrefix")j--;else break}const _=j>-1?r.events[j][1].type:null,W=_==="tableHead"||_==="tableRow"?C:l;return W===C&&r.parser.lazy[r.now().line]?n(w):W(w)}function l(w){return e.enter("tableHead"),e.enter("tableRow"),u(w)}function u(w){return w===124||(a=!0,s+=1),h(w)}function h(w){return w===null?n(w):O(w)?s>1?(s=0,r.interrupt=!0,e.exit("tableRow"),e.enter("lineEnding"),e.consume(w),e.exit("lineEnding"),f):n(w):H(w)?q(e,h,"whitespace")(w):(s+=1,a&&(a=!1,i+=1),w===124?(e.enter("tableCellDivider"),e.consume(w),e.exit("tableCellDivider"),a=!0,h):(e.enter("data"),c(w)))}function c(w){return w===null||w===124||Q(w)?(e.exit("data"),h(w)):(e.consume(w),w===92?p:c)}function p(w){return w===92||w===124?(e.consume(w),c):c(w)}function f(w){return r.interrupt=!1,r.parser.lazy[r.now().line]?n(w):(e.enter("tableDelimiterRow"),a=!1,H(w)?q(e,x,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(w):x(w))}function x(w){return w===45||w===58?S(w):w===124?(a=!0,e.enter("tableCellDivider"),e.consume(w),e.exit("tableCellDivider"),m):A(w)}function m(w){return H(w)?q(e,S,"whitespace")(w):S(w)}function S(w){return w===58?(s+=1,a=!0,e.enter("tableDelimiterMarker"),e.consume(w),e.exit("tableDelimiterMarker"),g):w===45?(s+=1,g(w)):w===null||O(w)?R(w):A(w)}function g(w){return w===45?(e.enter("tableDelimiterFiller"),v(w)):A(w)}function v(w){return w===45?(e.consume(w),v):w===58?(a=!0,e.exit("tableDelimiterFiller"),e.enter("tableDelimiterMarker"),e.consume(w),e.exit("tableDelimiterMarker"),k):(e.exit("tableDelimiterFiller"),k(w))}function k(w){return H(w)?q(e,R,"whitespace")(w):R(w)}function R(w){return w===124?x(w):w===null||O(w)?!a||i!==s?A(w):(e.exit("tableDelimiterRow"),e.exit("tableHead"),t(w)):A(w)}function A(w){return n(w)}function C(w){return e.enter("tableRow"),P(w)}function P(w){return w===124?(e.enter("tableCellDivider"),e.consume(w),e.exit("tableCellDivider"),P):w===null||O(w)?(e.exit("tableRow"),t(w)):H(w)?q(e,P,"whitespace")(w):(e.enter("data"),F(w))}function F(w){return w===null||w===124||Q(w)?(e.exit("data"),P(w)):(e.consume(w),w===92?B:F)}function B(w){return w===92||w===124?(e.consume(w),F):F(w)}}function ip(e,t){let n=-1,r=!0,i=0,s=[0,0,0,0],a=[0,0,0,0],o=!1,l=0,u,h,c;const p=new Zf;for(;++n<e.length;){const f=e[n],x=f[1];f[0]==="enter"?x.type==="tableHead"?(o=!1,l!==0&&(pi(p,t,l,u,h),h=void 0,l=0),u={type:"table",start:Object.assign({},x.start),end:Object.assign({},x.end)},p.add(n,0,[["enter",u,t]])):x.type==="tableRow"||x.type==="tableDelimiterRow"?(r=!0,c=void 0,s=[0,0,0,0],a=[0,n+1,0,0],o&&(o=!1,h={type:"tableBody",start:Object.assign({},x.start),end:Object.assign({},x.end)},p.add(n,0,[["enter",h,t]])),i=x.type==="tableDelimiterRow"?2:h?3:1):i&&(x.type==="data"||x.type==="tableDelimiterMarker"||x.type==="tableDelimiterFiller")?(r=!1,a[2]===0&&(s[1]!==0&&(a[0]=a[1],c=Tt(p,t,s,i,void 0,c),s=[0,0,0,0]),a[2]=n)):x.type==="tableCellDivider"&&(r?r=!1:(s[1]!==0&&(a[0]=a[1],c=Tt(p,t,s,i,void 0,c)),s=a,a=[s[1],n,0,0])):x.type==="tableHead"?(o=!0,l=n):x.type==="tableRow"||x.type==="tableDelimiterRow"?(l=n,s[1]!==0?(a[0]=a[1],c=Tt(p,t,s,i,n,c)):a[1]!==0&&(c=Tt(p,t,a,i,n,c)),i=0):i&&(x.type==="data"||x.type==="tableDelimiterMarker"||x.type==="tableDelimiterFiller")&&(a[3]=n)}for(l!==0&&pi(p,t,l,u,h),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=tp(t.events,n))}return e}function Tt(e,t,n,r,i,s){const a=r===1?"tableHeader":r===2?"tableDelimiter":"tableData",o="tableContent";n[0]!==0&&(s.end=Object.assign({},Qe(t.events,n[0])),e.add(n[0],0,[["exit",s,t]]));const l=Qe(t.events,n[1]);if(s={type:a,start:Object.assign({},l),end:Object.assign({},l)},e.add(n[1],0,[["enter",s,t]]),n[2]!==0){const u=Qe(t.events,n[2]),h=Qe(t.events,n[3]),c={type:o,start:Object.assign({},u),end:Object.assign({},h)};if(e.add(n[2],0,[["enter",c,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 x=n[2]+1,m=n[3]-n[2]-1;e.add(x,m,[])}}e.add(n[3]+1,0,[["exit",c,t]])}return i!==void 0&&(s.end=Object.assign({},Qe(t.events,i)),e.add(i,0,[["exit",s,t]]),s=void 0),s}function pi(e,t,n,r,i){const s=[],a=Qe(t.events,n);i&&(i.end=Object.assign({},a),s.push(["exit",i,t])),r.end=Object.assign({},a),s.push(["exit",r,t]),e.add(n+1,0,s)}function Qe(e,t){const n=e[t],r=n[0]==="enter"?"start":"end";return n[1][r]}const sp={name:"tasklistCheck",tokenize:op};function ap(){return{text:{91:sp}}}function op(e,t,n){const r=this;return i;function i(l){return r.previous!==null||!r._gfmTasklistFirstContentOfListItem?n(l):(e.enter("taskListCheck"),e.enter("taskListCheckMarker"),e.consume(l),e.exit("taskListCheckMarker"),s)}function s(l){return Q(l)?(e.enter("taskListCheckValueUnchecked"),e.consume(l),e.exit("taskListCheckValueUnchecked"),a):l===88||l===120?(e.enter("taskListCheckValueChecked"),e.consume(l),e.exit("taskListCheckValueChecked"),a):n(l)}function a(l){return l===93?(e.enter("taskListCheckMarker"),e.consume(l),e.exit("taskListCheckMarker"),e.exit("taskListCheck"),o):n(l)}function o(l){return O(l)?t(l):H(l)?e.check({tokenize:lp},t,n)(l):n(l)}}function lp(e,t,n){return q(e,r,"whitespace");function r(i){return i===null?n(i):t(i)}}function up(e){return Ji([Pf(),Kf(),Jf(e),np(),ap()])}const cp={};function hp(e){const t=this,n=e||cp,r=t.data(),i=r.micromarkExtensions||(r.micromarkExtensions=[]),s=r.fromMarkdownExtensions||(r.fromMarkdownExtensions=[]),a=r.toMarkdownExtensions||(r.toMarkdownExtensions=[]);i.push(up(n)),s.push(Mf()),a.push(Nf(n))}const mi=14e4,gi=220,dp=/language-([a-z0-9-]+)/i,fp=new Set(["http:","https:","mailto:","tel:"]);function pp(e){return e.length<=mi?e:`${e.slice(0,mi)}
32
-
33
- …`}function Us(e){return typeof e=="string"||typeof e=="number"?String(e):Array.isArray(e)?e.map(Us).join(""):""}function mp(e){const t=Us(e);return t.endsWith(`
34
- `)?t.slice(0,-1):t}function gp(e){var n;const t=e?dp.exec(e):null;return((n=t==null?void 0:t[1])==null?void 0:n.toLowerCase())||"text"}function xi(e){if(!e)return null;if(e.startsWith("#")||e.startsWith("/")||e.startsWith("./")||e.startsWith("../"))return e;try{const t=new URL(e);return fp.has(t.protocol)?e:null}catch{return null}}function xp(e){return/^https?:\/\//i.test(e)}function yp({className:e,children:t}){const[n,r]=E.useState(!1),i=E.useMemo(()=>gp(e),[e]),s=E.useMemo(()=>mp(t),[t]),a=E.useCallback(async()=>{var o;if(!(!s||typeof navigator>"u"||!((o=navigator.clipboard)!=null&&o.writeText)))try{await navigator.clipboard.writeText(s),r(!0)}catch{r(!1)}},[s]);return E.useEffect(()=>{if(!n||typeof window>"u")return;const o=window.setTimeout(()=>r(!1),1300);return()=>window.clearTimeout(o)},[n]),d.jsxs("div",{className:"chat-codeblock",children:[d.jsxs("div",{className:"chat-codeblock-toolbar",children:[d.jsx("span",{className:"chat-codeblock-language",children:i}),d.jsxs("button",{type:"button",className:"chat-codeblock-copy",onClick:a,"aria-label":n?T("chatCodeCopied"):T("chatCodeCopy"),children:[n?d.jsx(Ri,{className:"h-3.5 w-3.5"}):d.jsx(aa,{className:"h-3.5 w-3.5"}),d.jsx("span",{children:n?T("chatCodeCopied"):T("chatCodeCopy")})]})]}),d.jsx("pre",{children:d.jsx("code",{className:e,children:s})})]})}function bp(e){return e==="user"?T("chatRoleUser"):e==="assistant"?T("chatRoleAssistant"):e==="tool"?T("chatRoleTool"):e==="system"?T("chatRoleSystem"):T("chatRoleMessage")}function Sp(e){const t=e.toLowerCase();return t.includes("exec")||t.includes("shell")||t.includes("command")?d.jsx(oa,{className:"h-3.5 w-3.5"}):t.includes("search")?d.jsx(Dn,{className:"h-3.5 w-3.5"}):t.includes("fetch")||t.includes("http")||t.includes("web")?d.jsx(la,{className:"h-3.5 w-3.5"}):t.includes("read")||t.includes("file")?d.jsx(ua,{className:"h-3.5 w-3.5"}):t.includes("message")||t.includes("send")?d.jsx(ca,{className:"h-3.5 w-3.5"}):t.includes("cron")||t.includes("schedule")?d.jsx(ha,{className:"h-3.5 w-3.5"}):d.jsx(Ti,{className:"h-3.5 w-3.5"})}function dn({role:e}){return e==="user"?d.jsx("div",{className:"h-8 w-8 rounded-full bg-primary text-white flex items-center justify-center shadow-sm",children:d.jsx(sa,{className:"h-4 w-4"})}):e==="assistant"?d.jsx("div",{className:"h-8 w-8 rounded-full bg-slate-900 text-white flex items-center justify-center shadow-sm",children:d.jsx(Ii,{className:"h-4 w-4"})}):d.jsx("div",{className:"h-8 w-8 rounded-full bg-amber-100 text-amber-700 flex items-center justify-center shadow-sm",children:d.jsx(Ti,{className:"h-4 w-4"})})}function kp({text:e,role:t}){const n=t==="user",r=E.useMemo(()=>({a:({href:i,children:s,...a})=>{const o=xi(i);if(!o)return d.jsx("span",{className:"chat-link-invalid",children:s});const l=xp(o);return d.jsx("a",{...a,href:o,target:l?"_blank":void 0,rel:l?"noreferrer noopener":void 0,children:s})},table:({children:i,...s})=>d.jsx("div",{className:"chat-table-wrap",children:d.jsx("table",{...s,children:i})}),input:({type:i,checked:s,...a})=>i!=="checkbox"?d.jsx("input",{...a,type:i}):d.jsx("input",{...a,type:"checkbox",checked:s,readOnly:!0,disabled:!0,className:"chat-task-checkbox"}),img:({src:i,alt:s,...a})=>{const o=xi(i);return o?d.jsx("img",{...a,src:o,alt:s||"",loading:"lazy",decoding:"async"}):null},code:({className:i,children:s,...a})=>{const o=String(s??"");return!i&&!o.includes(`
35
- `)?d.jsx("code",{...a,className:ne("chat-inline-code",i),children:s}):d.jsx(yp,{className:i,children:s})}}),[]);return d.jsx("div",{className:ne("chat-markdown",n?"chat-markdown-user":"chat-markdown-assistant"),children:d.jsx(Yh,{skipHtml:!0,remarkPlugins:[hp],components:r,children:pp(e)})})}function wp({card:e}){var a;const t=e.kind==="call"?T("chatToolCall"):T("chatToolResult"),n=((a=e.text)==null?void 0:a.trim())??"",r=n.length>gi||n.includes(`
36
- `),i=r?`${n.slice(0,gi)}…`:n,s=e.kind==="result"||e.hasResult;return d.jsxs("div",{className:"rounded-xl border border-amber-200/80 bg-amber-50/60 px-3 py-2.5",children:[d.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-xs text-amber-800 font-semibold",children:[Sp(e.name),d.jsx("span",{children:t}),d.jsx("span",{className:"font-mono text-[11px] text-amber-900/80",children:e.name})]}),e.detail&&d.jsx("div",{className:"mt-1 text-[11px] text-amber-800/90 font-mono break-words",children:e.detail}),s&&d.jsx("div",{className:"mt-2",children:n?r?d.jsxs("details",{className:"group",children:[d.jsx("summary",{className:"cursor-pointer text-[11px] text-amber-700",children:T("chatToolOutput")}),d.jsx("pre",{className:"mt-2 rounded-lg border border-amber-200 bg-amber-100/40 p-2 text-[11px] whitespace-pre-wrap break-words text-amber-900",children:n})]}):d.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:i}):d.jsx("div",{className:"text-[11px] text-amber-700/80",children:T("chatToolNoOutput")})})]})}function vp({reasoning:e,isUser:t}){return d.jsxs("details",{className:"mt-3",children:[d.jsx("summary",{className:ne("cursor-pointer text-xs",t?"text-primary-100":"text-gray-500"),children:T("chatReasoning")}),d.jsx("pre",{className:ne("mt-2 text-[11px] whitespace-pre-wrap break-words rounded-lg p-2",t?"bg-primary-700/60":"bg-gray-100"),children:e})]})}function Cp(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 Ip({message:e}){const t=e.role,n=t==="user",r=e.parts.map((i,s)=>{if(i.type==="text"){const a=i.text.trim();return a?d.jsx(kp,{text:a,role:t},`text-${s}`):null}if(i.type==="reasoning"){const a=i.reasoning.trim();return a?d.jsx(vp,{reasoning:a,isUser:n},`reasoning-${s}`):null}if(i.type==="tool-invocation"){const a=i.toolInvocation,o=Ja(a.parsedArgs??a.args),l=typeof a.error=="string"&&a.error.trim()?a.error.trim():a.result!=null?Za(a.result).trim():"",u=a.status==="result"||a.status==="error"||a.status==="cancelled",h={kind:a.status==="result"&&!a.args?"result":"call",name:a.toolName,detail:o,text:l||void 0,callId:a.toolCallId||void 0,hasResult:u};return d.jsx("div",{className:"mt-0.5",children:d.jsx(wp,{card:h})},`tool-${a.toolCallId||s}`)}return null}).filter(i=>i!==null);return d.jsx("div",{className:ne("inline-block w-fit max-w-full rounded-2xl border px-4 py-3 shadow-sm",n?"bg-primary text-white border-primary":t==="assistant"?"bg-white text-gray-900 border-gray-200":"bg-orange-50/70 text-gray-900 border-orange-200/80"),children:d.jsx("div",{className:"space-y-2",children:r})})}function Tp({uiMessages:e,isSending:t,className:n}){const r=e.some(i=>{var s;return((s=i.meta)==null?void 0:s.status)==="streaming"});return d.jsxs("div",{className:ne("space-y-5",n),children:[e.map(i=>{const{role:s}=i,a=s==="user",o=Cp(i);return d.jsxs("div",{className:ne("flex gap-3",a?"justify-end":"justify-start"),children:[!a&&d.jsx(dn,{role:s}),d.jsxs("div",{className:ne("max-w-[92%] w-fit space-y-2",a&&"flex flex-col items-end"),children:[d.jsx(Ip,{message:i}),d.jsxs("div",{className:ne("text-[11px] px-1",a?"text-primary-300":"text-gray-400"),children:[bp(s)," · ",zt(o)]})]}),a&&d.jsx(dn,{role:s})]},i.id)}),t&&!r&&d.jsxs("div",{className:"flex gap-3 justify-start",children:[d.jsx(dn,{role:"assistant"}),d.jsx("div",{className:"rounded-2xl border border-gray-200 bg-white px-4 py-3 text-sm text-gray-500 shadow-sm",children:T("chatTyping")})]})]})}const Rp=[{icon:da,titleKey:"chatWelcomeCapability1Title",descKey:"chatWelcomeCapability1Desc"},{icon:zn,titleKey:"chatWelcomeCapability2Title",descKey:"chatWelcomeCapability2Desc"},{icon:On,titleKey:"chatWelcomeCapability3Title",descKey:"chatWelcomeCapability3Desc"}];function Ep({onCreateSession:e}){return d.jsx("div",{className:"h-full flex items-center justify-center p-8",children:d.jsxs("div",{className:"max-w-lg w-full text-center",children:[d.jsx("div",{className:"mx-auto mb-6 h-16 w-16 rounded-2xl bg-primary/10 flex items-center justify-center",children:d.jsx(Ii,{className:"h-8 w-8 text-primary"})}),d.jsx("h2",{className:"text-xl font-semibold text-gray-900 mb-2",children:T("chatWelcomeTitle")}),d.jsx("p",{className:"text-sm text-gray-500 mb-8",children:T("chatWelcomeSubtitle")}),d.jsx("div",{className:"grid grid-cols-3 gap-3",children:Rp.map(t=>{const n=t.icon;return d.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:[d.jsx("div",{className:"h-9 w-9 rounded-xl bg-primary/8 flex items-center justify-center mb-3",children:d.jsx(n,{className:"h-4.5 w-4.5 text-primary"})}),d.jsx("div",{className:"text-sm font-semibold text-gray-900 mb-1",children:T(t.titleKey)}),d.jsx("div",{className:"text-[11px] text-gray-500 leading-relaxed",children:T(t.descKey)})]},t.titleKey)})})]})})}const Ap=680,Mp=.82,Np=560;function Lp(e){const t=/^\/([^\s]*)$/.exec(e);return t?(t[1]??"").trim().toLowerCase():null}function Rt(e){return(e??"").trim().toLowerCase()}function yi(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 jp(e,t){const n=Rt(t);if(!n)return 1;const r=Rt(e.spec),i=Rt(e.label||e.spec),s=Rt(`${e.descriptionZh??""} ${e.description??""}`),a=i.split(/[\s/_-]+/).filter(Boolean);return r===n?1200:i===n?1150:r.startsWith(n)?1e3:i.startsWith(n)?950:a.some(o=>o.startsWith(n))?900:r.includes(n)?800:i.includes(n)?760:s.includes(n)?500:yi(n,i)||yi(n,r)?300:0}function Pp(e,t){const n=new Intl.Collator(void 0,{sensitivity:"base",numeric:!0});return e.map((i,s)=>({record:i,score:jp(i,t),order:s})).filter(i=>i.score>0).sort((i,s)=>{if(s.score!==i.score)return s.score-i.score;const a=(i.record.label||i.record.spec).trim(),o=(s.record.label||s.record.spec).trim(),l=n.compare(a,o);return l!==0?l:i.order-s.order}).map(i=>i.record).map(i=>({kind:"skill",key:`skill:${i.spec}`,title:i.label||i.spec,subtitle:T("chatSlashTypeSkill"),description:(i.descriptionZh??i.description??"").trim()||T("chatSkillsPickerNoDescription"),detailLines:[`${T("chatSlashSkillSpec")}: ${i.spec}`],skillSpec:i.spec}))}function _p(e){const[t,n]=E.useState(0),[r,i]=E.useState(!1),[s,a]=E.useState(null),o=E.useRef(null),l=E.useRef(null),u=E.useMemo(()=>Lp(e.draft),[e.draft]),h=e.draft.startsWith("/"),c=u??"",p=E.useMemo(()=>Pp(e.skillRecords,c),[c,e.skillRecords]),f=E.useMemo(()=>[...p],[p]),x=u!==null&&!r,m=f[t]??null,S=e.isSkillsLoading,g=s?Math.min(s>Np?s*Mp:s,Ap):void 0;E.useEffect(()=>{const R=o.current;if(!R||typeof ResizeObserver>"u")return;const A=()=>{a(R.getBoundingClientRect().width)};A();const C=new ResizeObserver(()=>A());return C.observe(R),()=>C.disconnect()},[]),E.useEffect(()=>{if(!x||f.length===0){n(0);return}n(R=>R<0?0:R>=f.length?f.length-1:R)},[x,f.length]),E.useEffect(()=>{!h&&r&&i(!1)},[r,h]),E.useEffect(()=>{if(!x||S||f.length===0)return;const R=l.current;if(!R)return;const A=R.querySelector(`[data-slash-index="${t}"]`);A==null||A.scrollIntoView({block:"nearest",inline:"nearest"})},[t,S,x,f.length]);const v=E.useCallback(R=>{R.kind==="skill"&&R.skillSpec&&(e.selectedSkills.includes(R.skillSpec)||e.onSelectedSkillsChange([...e.selectedSkills,R.skillSpec]),e.onDraftChange(""),i(!1))},[e]),k=E.useCallback(R=>{if(x&&!R.nativeEvent.isComposing&&(R.key===" "||R.code==="Space")&&i(!0),x&&f.length>0){if(R.key==="ArrowDown"){R.preventDefault(),n(A=>(A+1)%f.length);return}if(R.key==="ArrowUp"){R.preventDefault(),n(A=>(A-1+f.length)%f.length);return}if(R.key==="Enter"&&!R.shiftKey||R.key==="Tab"){R.preventDefault();const A=f[t];A&&v(A);return}}if(R.key==="Escape"){if(x){R.preventDefault(),i(!0);return}if(e.isSending&&e.canStopGeneration){R.preventDefault(),e.onStop();return}}R.key==="Enter"&&!R.shiftKey&&(R.preventDefault(),e.onSend())},[t,v,x,e,f]);return{slashAnchorRef:o,slashListRef:l,isSlashPanelOpen:x,isSlashPanelLoading:S,resolvedSlashPanelWidth:g,skillSlashItems:p,activeSlashIndex:t,activeSlashItem:m,onSelectSlashItem:v,onSlashPanelOpenChange:R=>{R||i(!0)},onSetActiveSlashIndex:n,onTextareaKeyDown:k}}function Dp(e){const t=e.selectedSkills.map(r=>{const i=e.skillRecords.find(s=>s.spec===r);return{spec:r,label:(i==null?void 0:i.label)||r}}),n=_p({draft:e.draft,onDraftChange:e.onDraftChange,onSend:e.onSend,onStop:e.onStop,isSending:e.isSending,canStopGeneration:e.canStopGeneration,isSkillsLoading:e.isSkillsLoading,selectedSkills:e.selectedSkills,onSelectedSkillsChange:e.onSelectedSkillsChange,skillRecords:e.skillRecords});return{selectedSkillRecords:t,...n}}function Op({records:e,isLoading:t=!1,selectedSkills:n,onSelectedSkillsChange:r}){const{language:i}=Mi(),[s,a]=E.useState(""),o=E.useMemo(()=>new Set(n),[n]),l=n.length,u=E.useMemo(()=>{const c=s.trim().toLowerCase();return c?e.filter(p=>[p.label,p.spec,p.description,p.descriptionZh].filter(x=>typeof x=="string"&&x.trim().length>0).join(" ").toLowerCase().includes(c)):e},[s,e]),h=c=>{var f;const p=(f=c.spec)==null?void 0:f.trim();if(p){if(o.has(p)){r(n.filter(x=>x!==p));return}r([...n,p])}};return d.jsxs(Ni,{children:[d.jsx(no,{asChild:!0,children:d.jsxs("button",{type:"button",className:"inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-medium text-gray-600 hover:bg-gray-100 hover:text-gray-900 transition-colors",children:[d.jsx(zn,{className:"h-4 w-4"}),d.jsx("span",{children:T("chatSkillsPickerTitle")}),l>0&&d.jsx("span",{className:"ml-0.5 min-w-[18px] h-[18px] flex items-center justify-center rounded-full bg-primary/10 text-primary text-[10px] font-semibold",children:l})]})}),d.jsxs(Li,{side:"top",align:"start",className:"w-[360px] p-0",children:[d.jsxs("div",{className:"space-y-2 border-b border-gray-100 px-4 py-3",children:[d.jsx("div",{className:"text-sm font-semibold text-gray-900",children:T("chatSkillsPickerTitle")}),d.jsxs("div",{className:"relative",children:[d.jsx(Dn,{className:"pointer-events-none absolute left-3 top-2.5 h-3.5 w-3.5 text-gray-400"}),d.jsx(Kn,{value:s,onChange:c=>a(c.target.value),placeholder:T("chatSkillsPickerSearchPlaceholder"),className:"h-8 rounded-lg pl-8 text-xs"})]})]}),d.jsx("div",{className:"max-h-[320px] overflow-y-auto custom-scrollbar",children:t?d.jsx("div",{className:"p-4 text-xs text-gray-500",children:T("sessionsLoading")}):u.length===0?d.jsx("div",{className:"p-4 text-xs text-gray-500 text-center",children:T("chatSkillsPickerEmpty")}):d.jsx("div",{className:"py-1",children:u.map(c=>{var p,f;return d.jsxs("button",{type:"button",onClick:()=>h(c),className:"flex w-full items-center gap-3 px-4 py-2.5 text-left transition-colors hover:bg-gray-50",children:[d.jsx("div",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-gray-100 text-gray-500",children:d.jsx(fa,{className:"h-4 w-4"})}),d.jsxs("div",{className:"min-w-0 flex-1",children:[d.jsxs("div",{className:"flex items-center gap-1.5",children:[d.jsx("span",{className:"truncate text-sm text-gray-900",children:c.label||c.spec}),c.origin==="builtin"&&d.jsx("span",{className:"shrink-0 text-[10px] bg-primary/10 text-primary px-1.5 py-0.5 rounded-full font-medium",children:T("chatSkillsPickerOfficial")})]}),d.jsx("div",{className:"mt-0.5 truncate text-xs text-gray-500",children:((p=i==="zh"?c.descriptionZh:c.description)==null?void 0:p.trim())||((f=c.description)==null?void 0:f.trim())||T("chatSkillsPickerNoDescription")})]}),d.jsx("div",{className:"ml-3 shrink-0",children:d.jsx("span",{className:o.has(c.spec)?"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:o.has(c.spec)&&d.jsx(Ri,{className:"h-3 w-3"})})})]},c.spec)})})}),d.jsx("div",{className:"px-4 py-2.5 border-t border-gray-100",children:d.jsxs(mn,{to:"/marketplace/skills",className:"inline-flex items-center gap-1.5 text-xs font-medium text-primary hover:text-primary/80 transition-colors",children:[T("chatSkillsPickerManage"),d.jsx(pa,{className:"h-3 w-3"})]})})]})]})}const zp={isProviderStateResolved:!1,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:[]},Z=Ot(e=>({snapshot:zp,setSnapshot:t=>e(n=>({snapshot:{...n.snapshot,...t}}))}));function Fp(){return d.jsx(Bn,{children:d.jsxs($n,{children:[d.jsx(Un,{asChild:!0,children:d.jsx("button",{type:"button",disabled:!0,className:"inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-medium text-gray-400 cursor-not-allowed",children:d.jsx(ma,{className:"h-4 w-4"})})}),d.jsx(Hn,{side:"top",children:d.jsx("p",{className:"text-xs",children:T("chatInputAttachComingSoon")})})]})})}function Bp(e){return d.jsxs(Je,{value:e.hasModelOptions?e.selectedModel:void 0,onValueChange:e.onSelectedModelChange,disabled:!e.hasModelOptions,children:[d.jsx(Ze,{className:"h-8 w-auto min-w-[220px] rounded-lg border-0 bg-transparent shadow-none text-xs font-medium text-gray-600 hover:bg-gray-100 focus:ring-0 px-3",children:e.selectedModelOption?d.jsxs("div",{className:"flex min-w-0 items-center gap-2 text-left",children:[d.jsx(ga,{className:"h-3.5 w-3.5 shrink-0 text-primary"}),d.jsxs("span",{className:"truncate text-xs font-semibold text-gray-700",children:[e.selectedModelOption.providerLabel,"/",e.selectedModelOption.modelLabel]})]}):e.isModelOptionsLoading?d.jsx("div",{className:"h-3 w-24 animate-pulse rounded bg-gray-200"}):d.jsx(Fn,{placeholder:T("chatSelectModel")})}),d.jsxs(et,{className:"w-[320px]",children:[e.modelOptions.length===0&&(e.isModelOptionsLoading?d.jsxs("div",{className:"space-y-2 px-3 py-2",children:[d.jsx("div",{className:"h-3 w-36 animate-pulse rounded bg-gray-200"}),d.jsx("div",{className:"h-3 w-28 animate-pulse rounded bg-gray-200"}),d.jsx("div",{className:"h-3 w-32 animate-pulse rounded bg-gray-200"})]}):d.jsx("div",{className:"px-3 py-2 text-xs text-gray-500",children:T("chatModelNoOptions")})),e.modelOptions.map(t=>d.jsx(ze,{value:t.value,className:"py-2",children:d.jsxs("div",{className:"flex min-w-0 flex-col gap-0.5",children:[d.jsx("span",{className:"truncate text-xs font-semibold text-gray-800",children:t.modelLabel}),d.jsx("span",{className:"truncate text-[11px] text-gray-500",children:t.providerLabel})]})},t.value))]})]})}function $p(e){var t;return d.jsxs("div",{className:"flex flex-col items-end gap-1",children:[((t=e.sendError)==null?void 0:t.trim())&&d.jsx("div",{className:"max-w-[420px] text-right text-[11px] text-red-600",children:e.sendError}),d.jsx("div",{className:"flex items-center gap-2",children:e.isSending?e.canStopGeneration?d.jsx(je,{size:"icon",variant:"outline",className:"h-8 w-8 rounded-full",onClick:()=>void e.onStop(),children:d.jsx(pr,{className:"h-3 w-3 fill-current"})}):d.jsx(Bn,{children:d.jsxs($n,{children:[d.jsx(Un,{asChild:!0,children:d.jsx("span",{children:d.jsx(je,{size:"icon",variant:"outline",className:"h-8 w-8 rounded-full",disabled:!0,children:d.jsx(pr,{className:"h-3 w-3 fill-current"})})})}),d.jsx(Hn,{side:"top",children:d.jsx("p",{className:"text-xs",children:e.resolvedStopHint})})]})}):d.jsx(je,{size:"icon",className:"h-8 w-8 rounded-full",onClick:()=>void e.onSend(),disabled:e.draft.trim().length===0||!e.hasModelOptions||e.sessionTypeUnavailable,children:d.jsx(xa,{className:"h-5 w-5"})})})]})}function Up(e){return e.shouldShowSessionTypeSelector?d.jsxs(Je,{value:e.selectedSessionType,onValueChange:e.onSelectedSessionTypeChange,disabled:!e.canEditSessionType,children:[d.jsx(Ze,{className:"h-8 w-auto min-w-[140px] rounded-lg border-0 bg-transparent shadow-none text-xs font-medium text-gray-600 hover:bg-gray-100 focus:ring-0 px-3",children:e.selectedSessionTypeOption?d.jsx("span",{className:"truncate text-xs font-semibold text-gray-700",children:e.selectedSessionTypeOption.label}):d.jsx(Fn,{placeholder:T("chatSessionTypeLabel")})}),d.jsx(et,{className:"w-[220px]",children:e.sessionTypeOptions.map(t=>d.jsx(ze,{value:t.value,className:"py-2",children:d.jsx("span",{className:"truncate text-xs font-semibold text-gray-800",children:t.label})},t.value))})]}):null}function bi(e){return e==="off"?T("chatThinkingLevelOff"):e==="minimal"?T("chatThinkingLevelMinimal"):e==="low"?T("chatThinkingLevelLow"):e==="medium"?T("chatThinkingLevelMedium"):e==="high"?T("chatThinkingLevelHigh"):e==="adaptive"?T("chatThinkingLevelAdaptive"):T("chatThinkingLevelXhigh")}function Hp(e){const t=[];for(const n of["off",...e])t.includes(n)||t.push(n);return t}function Kp(e){if(e.supportedLevels.length===0)return null;const t=Hp(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 d.jsxs(Je,{value:r,onValueChange:i=>e.onSelectedThinkingLevelChange(i),children:[d.jsx(Ze,{className:"h-8 w-auto min-w-[150px] rounded-lg border-0 bg-transparent px-3 text-xs font-medium text-gray-600 shadow-none hover:bg-gray-100 focus:ring-0",children:d.jsxs("div",{className:"flex min-w-0 items-center gap-2 text-left",children:[d.jsx(ya,{className:"h-3.5 w-3.5 shrink-0 text-gray-500"}),d.jsx("span",{className:"truncate text-xs font-semibold text-gray-700",children:bi(r)})]})}),d.jsx(et,{className:"w-[180px]",children:t.map(i=>d.jsx(ze,{value:i,children:bi(i)},i))})]})}function Vp(){var c;const e=Ft(),t=Z(p=>p.snapshot),n=t.modelOptions.length>0,r=!t.isProviderStateResolved&&!n,i=t.modelOptions.find(p=>p.value===t.selectedModel),s=t.canEditSessionType&&(t.sessionTypeOptions.length>1||!!(t.selectedSessionType&&t.selectedSessionType!=="native")),a=t.sessionTypeOptions.find(p=>p.value===t.selectedSessionType)??(t.selectedSessionType?{value:t.selectedSessionType,label:t.selectedSessionType}:null),o=t.stopDisabledReason==="__preparing__"?T("chatStopPreparing"):((c=t.stopDisabledReason)==null?void 0:c.trim())||T("chatStopUnavailable"),l=i==null?void 0:i.thinkingCapability,u=(l==null?void 0:l.supported)??[],h=u.length>0;return d.jsxs("div",{className:"flex items-center justify-between px-3 pb-3",children:[d.jsxs("div",{className:"flex items-center gap-1",children:[d.jsx(Op,{records:t.skillRecords,isLoading:t.isSkillsLoading,selectedSkills:t.selectedSkills,onSelectedSkillsChange:e.chatInputManager.selectSkills}),d.jsx(Up,{shouldShowSessionTypeSelector:s,selectedSessionType:t.selectedSessionType,selectedSessionTypeOption:a,sessionTypeOptions:t.sessionTypeOptions,onSelectedSessionTypeChange:e.chatInputManager.selectSessionType,canEditSessionType:t.canEditSessionType}),d.jsx(Bp,{modelOptions:t.modelOptions,selectedModel:t.selectedModel,selectedModelOption:i,onSelectedModelChange:e.chatInputManager.selectModel,isModelOptionsLoading:r,hasModelOptions:n}),h?d.jsx(Kp,{supportedLevels:u,selectedThinkingLevel:t.selectedThinkingLevel,defaultThinkingLevel:(l==null?void 0:l.default)??null,onSelectedThinkingLevelChange:e.chatInputManager.selectThinkingLevel}):null,d.jsx(Fp,{})]}),d.jsx($p,{sendError:t.sendError,draft:t.draft,hasModelOptions:n,sessionTypeUnavailable:t.sessionTypeUnavailable,isSending:t.isSending,canStopGeneration:t.canStopGeneration,resolvedStopHint:o,onSend:e.chatInputManager.send,onStop:e.chatInputManager.stop})]})}function qp(e){return!e.isModelOptionsLoading&&!e.isModelOptionsEmpty?null:e.isModelOptionsLoading?d.jsx("div",{className:"px-4 pb-2",children:d.jsxs("div",{className:"inline-flex items-center gap-2 rounded-lg border border-gray-200 bg-gray-50 px-3 py-2",children:[d.jsx("span",{className:"h-3 w-28 animate-pulse rounded bg-gray-200"}),d.jsx("span",{className:"h-3 w-16 animate-pulse rounded bg-gray-200"})]})}):d.jsx("div",{className:"px-4 pb-2",children:d.jsxs("div",{className:"inline-flex items-center gap-2 rounded-lg border border-amber-200 bg-amber-50 px-3 py-1.5 text-xs text-amber-800",children:[d.jsx("span",{children:T("chatModelNoOptions")}),d.jsx("button",{type:"button",onClick:e.onGoToProviders,className:"font-semibold text-amber-900 underline-offset-2 hover:underline",children:T("chatGoConfigureProvider")})]})})}function Wp(e){return e.records.length===0?null:d.jsx("div",{className:"px-4 pb-2",children:d.jsx("div",{className:"flex flex-wrap items-center gap-2",children:e.records.map(t=>d.jsxs("button",{type:"button",onClick:()=>e.onSelectedSkillsChange(e.selectedSkills.filter(n=>n!==t.spec)),className:"inline-flex max-w-[200px] items-center gap-1.5 rounded-full bg-primary/10 px-2.5 py-1 text-xs font-medium text-primary",children:[d.jsx("span",{className:"truncate",children:t.label}),d.jsx(ba,{className:"h-3 w-3 shrink-0"})]},t.spec))})})}function Gp({slashAnchorRef:e,slashListRef:t,isSlashPanelOpen:n,isSlashPanelLoading:r,resolvedSlashPanelWidth:i,skillSlashItems:s,activeSlashIndex:a,activeSlashItem:o,onSelectSlashItem:l,onSlashPanelOpenChange:u,onSetActiveSlashIndex:h}){return d.jsxs(Ni,{open:n,onOpenChange:u,children:[d.jsx(ro,{asChild:!0,children:d.jsx("div",{ref:e,className:"pointer-events-none absolute left-3 right-3 bottom-full h-0"})}),d.jsx(Li,{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:c=>c.preventDefault(),style:i?{width:`${i}px`}:void 0,children:d.jsxs("div",{className:"grid min-h-[240px] grid-cols-[minmax(220px,300px)_minmax(0,1fr)]",children:[d.jsx("div",{ref:t,className:"max-h-[320px] overflow-y-auto border-r border-gray-200 p-2.5 custom-scrollbar",children:r?d.jsx("div",{className:"p-2 text-xs text-gray-500",children:T("chatSlashLoading")}):d.jsxs(d.Fragment,{children:[d.jsx("div",{className:"mb-2 px-2 text-[11px] font-semibold uppercase tracking-wide text-gray-500",children:T("chatSlashSectionSkills")}),s.length===0?d.jsx("div",{className:"px-2 text-xs text-gray-400",children:T("chatSlashNoResult")}):d.jsx("div",{className:"space-y-1",children:s.map((c,p)=>{const f=p===a;return d.jsxs("button",{type:"button","data-slash-index":p,onMouseEnter:()=>h(p),onClick:()=>l(c),className:`flex w-full items-start gap-2 rounded-lg px-2 py-1.5 text-left transition ${f?"bg-gray-100 text-gray-900":"text-gray-700 hover:bg-gray-50"}`,children:[d.jsx("span",{className:"truncate text-xs font-semibold",children:c.title}),d.jsx("span",{className:"truncate text-xs text-gray-500",children:c.subtitle})]},c.key)})})]})}),d.jsx("div",{className:"max-w-[320px] p-3.5",children:o?d.jsxs("div",{className:"space-y-3",children:[d.jsxs("div",{className:"flex items-center gap-2",children:[d.jsx("span",{className:"inline-flex rounded-full bg-primary/10 px-2 py-0.5 text-[11px] font-semibold text-primary",children:o.subtitle}),d.jsx("span",{className:"text-sm font-semibold text-gray-900",children:o.title})]}),d.jsx("p",{className:"text-xs leading-5 text-gray-600",children:o.description}),d.jsx("div",{className:"space-y-1",children:o.detailLines.map(c=>d.jsx("div",{className:"rounded-md bg-gray-50 px-2 py-1 text-[11px] text-gray-600",children:c},c))}),d.jsx("div",{className:"pt-1 text-[11px] text-gray-500",children:T("chatSlashSkillHint")})]}):d.jsx("div",{className:"text-xs text-gray-500",children:T("chatSlashHint")})})]})})]})}function Xp(){const e=Ft(),t=Z(l=>l.snapshot),n=t.modelOptions.length>0,r=!t.isProviderStateResolved&&!n,i=t.isProviderStateResolved&&!n,s=(r||i)&&!t.isSending||t.sessionTypeUnavailable,a=r?"":n?T("chatInputPlaceholder"):T("chatModelNoOptions"),o=Dp({draft:t.draft,onDraftChange:e.chatInputManager.setDraft,onSend:e.chatInputManager.send,onStop:e.chatInputManager.stop,canStopGeneration:t.canStopGeneration,isSending:t.isSending,skillRecords:t.skillRecords,isSkillsLoading:t.isSkillsLoading,selectedSkills:t.selectedSkills,onSelectedSkillsChange:e.chatInputManager.selectSkills});return d.jsx("div",{className:"border-t border-gray-200/80 bg-white p-4",children:d.jsx("div",{className:"mx-auto w-full max-w-[min(1120px,100%)]",children:d.jsxs("div",{className:"rounded-2xl border border-gray-200 bg-white shadow-card overflow-hidden",children:[d.jsxs("div",{className:"relative",children:[d.jsx("textarea",{value:t.draft,onChange:l=>e.chatInputManager.setDraft(l.target.value),disabled:s,onKeyDown:o.onTextareaKeyDown,placeholder:a,className:"w-full min-h-[68px] max-h-[220px] resize-y bg-transparent outline-none text-sm px-4 py-3 text-gray-800 placeholder:text-gray-400"}),d.jsx(Gp,{slashAnchorRef:o.slashAnchorRef,slashListRef:o.slashListRef,isSlashPanelOpen:o.isSlashPanelOpen,isSlashPanelLoading:o.isSlashPanelLoading,resolvedSlashPanelWidth:o.resolvedSlashPanelWidth,skillSlashItems:o.skillSlashItems,activeSlashIndex:o.activeSlashIndex,activeSlashItem:o.activeSlashItem,onSelectSlashItem:o.onSelectSlashItem,onSlashPanelOpenChange:o.onSlashPanelOpenChange,onSetActiveSlashIndex:o.onSetActiveSlashIndex})]}),d.jsx(qp,{isModelOptionsLoading:r,isModelOptionsEmpty:i,onGoToProviders:e.chatInputManager.goToProviders}),d.jsx(Wp,{records:o.selectedSkillRecords,selectedSkills:t.selectedSkills,onSelectedSkillsChange:e.chatInputManager.selectSkills}),d.jsx(Vp,{})]})})})}const Qp={isProviderStateResolved:!1,modelOptions:[],sessionTypeUnavailable:!1,sessionTypeUnavailableMessage:null,selectedSessionKey:null,sessionDisplayName:void 0,canDeleteSession:!1,isDeletePending:!1,threadRef:null,isHistoryLoading:!1,uiMessages:[],isSending:!1,isAwaitingAssistantOutput:!1},ct=Ot(e=>({snapshot:Qp,setSnapshot:t=>e(n=>({snapshot:{...n.snapshot,...t}}))})),Yp=10;function Jp(){return d.jsxs("section",{className:"flex-1 min-h-0 flex flex-col overflow-hidden bg-gradient-to-b from-gray-50/60 to-white",children:[d.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto custom-scrollbar",children:d.jsx("div",{className:"mx-auto w-full max-w-[min(1120px,100%)] px-6 py-5",children:d.jsxs("div",{className:"space-y-4",children:[d.jsx("div",{className:"h-6 w-48 animate-pulse rounded bg-gray-200"}),d.jsx("div",{className:"h-24 w-[78%] animate-pulse rounded-2xl bg-gray-200/80"}),d.jsx("div",{className:"h-20 w-[62%] animate-pulse rounded-2xl bg-gray-200/80"}),d.jsx("div",{className:"h-28 w-[84%] animate-pulse rounded-2xl bg-gray-200/80"})]})})}),d.jsx("div",{className:"border-t border-gray-200/80 bg-white p-4",children:d.jsx("div",{className:"mx-auto w-full max-w-[min(1120px,100%)]",children:d.jsxs("div",{className:"rounded-2xl border border-gray-200 bg-white shadow-card p-4",children:[d.jsx("div",{className:"h-16 w-full animate-pulse rounded-xl bg-gray-200/80"}),d.jsxs("div",{className:"mt-3 flex items-center justify-between",children:[d.jsx("div",{className:"h-8 w-36 animate-pulse rounded-lg bg-gray-200/80"}),d.jsx("div",{className:"h-8 w-20 animate-pulse rounded-lg bg-gray-200/80"})]})]})})})]})}function Zp(){var x;const e=Ft(),t=ct(m=>m.snapshot),n=E.useRef(null),r=t.threadRef??n,i=E.useRef(!0),s=E.useRef(!1),a=E.useRef(null),o=E.useRef(!1),l=!t.selectedSessionKey&&t.uiMessages.length===0&&!t.isSending,u=t.modelOptions.length>0,h=t.isProviderStateResolved&&!u,c=t.isHistoryLoading&&t.uiMessages.length===0&&!t.isSending&&!t.isAwaitingAssistantOutput,p=E.useCallback(()=>{const m=r.current;m&&(s.current=!0,m.scrollTop=m.scrollHeight)},[r]),f=E.useCallback(()=>{if(s.current){s.current=!1;return}const m=r.current;if(!m)return;const S=m.scrollHeight-m.scrollTop-m.clientHeight;i.current=S<=Yp},[r]);return E.useEffect(()=>{a.current!==t.selectedSessionKey&&(a.current=t.selectedSessionKey,i.current=!0,o.current=!0)},[t.selectedSessionKey]),E.useLayoutEffect(()=>{o.current&&(t.isHistoryLoading||t.uiMessages.length===0||(o.current=!1,p()))},[p,t.isHistoryLoading,t.uiMessages]),E.useLayoutEffect(()=>{i.current&&t.uiMessages.length!==0&&p()},[p,t.uiMessages]),t.isProviderStateResolved?d.jsxs("section",{className:"flex-1 min-h-0 flex flex-col overflow-hidden bg-gradient-to-b from-gray-50/60 to-white",children:[d.jsxs("div",{className:ne("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",t.selectedSessionKey?"py-3 opacity-100":"h-0 py-0 opacity-0 border-b-0"),children:[d.jsx("div",{className:"min-w-0 flex-1",children:d.jsx("span",{className:"text-sm font-medium text-gray-700 truncate",children:t.sessionDisplayName||t.selectedSessionKey})}),d.jsx(je,{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:d.jsx(Ei,{className:"h-4 w-4"})})]}),h&&d.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:[d.jsx("span",{className:"text-xs text-amber-800",children:T("chatModelNoOptions")}),d.jsx("button",{type:"button",onClick:e.chatThreadManager.goToProviders,className:"text-xs font-semibold text-amber-900 underline-offset-2 hover:underline",children:T("chatGoConfigureProvider")})]}),t.sessionTypeUnavailable&&((x=t.sessionTypeUnavailableMessage)==null?void 0:x.trim())&&d.jsx("div",{className:"px-5 py-2.5 border-b border-amber-200/70 bg-amber-50/70 shrink-0",children:d.jsx("span",{className:"text-xs text-amber-800",children:t.sessionTypeUnavailableMessage})}),d.jsx("div",{ref:r,onScroll:f,className:"flex-1 min-h-0 overflow-y-auto custom-scrollbar",children:l?d.jsx(Ep,{onCreateSession:e.chatThreadManager.createSession}):c?d.jsx("div",{className:"h-full"}):t.uiMessages.length===0?d.jsx("div",{className:"px-5 py-5 text-sm text-gray-500",children:T("chatNoMessages")}):d.jsx("div",{className:"mx-auto w-full max-w-[min(1120px,100%)] px-6 py-5",children:d.jsx(Tp,{uiMessages:t.uiMessages,isSending:t.isSending&&t.isAwaitingAssistantOutput})})}),d.jsx(Xp,{})]}):d.jsx(Jp,{})}function Si(e){return zt(e??void 0)}function em(e){return typeof e!="number"||!Number.isFinite(e)?"-":zt(new Date(e))}function tm(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 nm(e){const t=e.schedule;return t.kind==="cron"?t.expr?`cron ${t.expr}`:"cron":t.kind==="every"?`every ${tm(t.everyMs)}`:t.kind==="at"?`at ${em(t.atMs)}`:"-"}function rm(e){if(!e.payload.deliver)return"-";const t=e.payload.channel??"-",n=e.payload.to??"-";return`${t}:${n}`}function im(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 sm(e,t){return t==="all"?!0:t==="enabled"?e.enabled:!e.enabled}function am(){var x;const[e,t]=E.useState(""),[n,r]=E.useState("all"),i=La({all:!0}),s=ja(),a=Pa(),o=_a(),{confirm:l,ConfirmDialog:u}=Ai(),h=E.useMemo(()=>{var S;return(((S=i.data)==null?void 0:S.jobs)??[]).filter(g=>im(g,e)).filter(g=>sm(g,n))},[i.data,e,n]),c=async m=>{await l({title:`${T("cronDeleteConfirm")}?`,description:m.name?`${m.name} (${m.id})`:m.id,variant:"destructive",confirmLabel:T("delete")})&&s.mutate({id:m.id})},p=async m=>{const S=!m.enabled;await l({title:S?`${T("cronEnableConfirm")}?`:`${T("cronDisableConfirm")}?`,description:m.name?`${m.name} (${m.id})`:m.id,variant:S?"default":"destructive",confirmLabel:S?T("cronEnable"):T("cronDisable")})&&a.mutate({id:m.id,enabled:S})},f=async m=>{const S=!m.enabled;await l({title:S?`${T("cronRunForceConfirm")}?`:`${T("cronRunConfirm")}?`,description:m.name?`${m.name} (${m.id})`:m.id,confirmLabel:T("cronRunNow")})&&o.mutate({id:m.id,force:S})};return d.jsxs(Ta,{fullHeight:!0,children:[d.jsx(Ra,{title:T("cronPageTitle"),description:T("cronPageDescription"),actions:d.jsx(je,{variant:"ghost",size:"icon",className:"h-9 w-9 rounded-lg text-gray-400 hover:text-gray-700 hover:bg-gray-100",onClick:()=>i.refetch(),children:d.jsx(Sa,{className:ne("h-4 w-4",i.isFetching&&"animate-spin")})})}),d.jsx("div",{className:"mb-6",children:d.jsxs("div",{className:"flex flex-wrap gap-3 items-center",children:[d.jsxs("div",{className:"relative flex-1 min-w-[240px]",children:[d.jsx(Kn,{value:e,onChange:m=>t(m.target.value),placeholder:T("cronSearchPlaceholder"),className:"pl-9"}),d.jsx(On,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-gray-400"})]}),d.jsx("div",{className:"min-w-[180px]",children:d.jsxs(Je,{value:n,onValueChange:m=>r(m),children:[d.jsx(Ze,{className:"w-full",children:d.jsx(Fn,{placeholder:T("cronStatusLabel")})}),d.jsxs(et,{children:[d.jsx(ze,{value:"all",children:T("cronStatusAll")}),d.jsx(ze,{value:"enabled",children:T("cronStatusEnabled")}),d.jsx(ze,{value:"disabled",children:T("cronStatusDisabled")})]})]})}),d.jsxs("div",{className:"text-xs text-gray-500 ml-auto",children:[T("cronTotalLabel"),": ",((x=i.data)==null?void 0:x.total)??0," / ",h.length]})]})}),d.jsx("div",{className:"flex-1 overflow-auto custom-scrollbar",children:i.isLoading?d.jsx("div",{className:"text-sm text-gray-400 p-4 text-center",children:T("cronLoading")}):h.length===0?d.jsx("div",{className:"text-sm text-gray-400 p-4 text-center",children:T("cronEmpty")}):d.jsx("div",{className:"space-y-4",children:h.map(m=>d.jsx(io,{className:"border border-gray-200",children:d.jsx(so,{className:"pt-5 pb-5",children:d.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-4",children:[d.jsxs("div",{className:"min-w-[220px] flex-1",children:[d.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[d.jsx("span",{className:"text-sm font-semibold text-gray-900",children:m.name||m.id}),d.jsx("span",{className:"text-[10px] font-semibold px-2 py-0.5 rounded-full bg-gray-100 text-gray-500",children:m.id}),d.jsx("span",{className:ne("text-[10px] font-semibold px-2 py-0.5 rounded-full",m.enabled?"bg-emerald-50 text-emerald-700":"bg-gray-100 text-gray-500"),children:m.enabled?T("enabled"):T("disabled")}),m.deleteAfterRun&&d.jsx("span",{className:"text-[10px] font-semibold px-2 py-0.5 rounded-full bg-amber-50 text-amber-700",children:T("cronOneShot")})]}),d.jsxs("div",{className:"mt-2 text-xs text-gray-500",children:[T("cronScheduleLabel"),": ",nm(m)]}),d.jsx("div",{className:"mt-2 text-sm text-gray-700 whitespace-pre-wrap break-words",children:m.payload.message}),d.jsxs("div",{className:"mt-2 text-xs text-gray-500",children:[T("cronDeliverTo"),": ",rm(m)]})]}),d.jsxs("div",{className:"min-w-[220px] text-xs text-gray-500 space-y-2",children:[d.jsxs("div",{children:[d.jsxs("span",{className:"font-medium text-gray-700",children:[T("cronNextRun"),":"]})," ",Si(m.state.nextRunAt)]}),d.jsxs("div",{children:[d.jsxs("span",{className:"font-medium text-gray-700",children:[T("cronLastRun"),":"]})," ",Si(m.state.lastRunAt)]}),d.jsxs("div",{children:[d.jsxs("span",{className:"font-medium text-gray-700",children:[T("cronLastStatus"),":"]})," ",m.state.lastStatus??"-"]}),m.state.lastError&&d.jsx("div",{className:"text-[11px] text-red-500 break-words",children:m.state.lastError})]}),d.jsxs("div",{className:"flex items-start gap-2 flex-wrap justify-end",children:[d.jsxs(je,{variant:"subtle",size:"sm",onClick:()=>f(m),className:"gap-1",children:[d.jsx(ka,{className:"h-3.5 w-3.5"}),T("cronRunNow")]}),d.jsxs(je,{variant:m.enabled?"outline":"primary",size:"sm",onClick:()=>p(m),className:"gap-1",children:[d.jsx(wa,{className:"h-3.5 w-3.5"}),m.enabled?T("cronDisable"):T("cronEnable")]}),d.jsxs(je,{variant:"destructive",size:"sm",onClick:()=>c(m),className:"gap-1",children:[d.jsx(Ei,{className:"h-3.5 w-3.5"}),T("delete")]})]})]})})},m.id))})}),d.jsx(u,{})]})}function om(e){const{modelOptions:t,selectedSessionPreferredModel:n,defaultModel:r,setSelectedModel:i}=e;E.useEffect(()=>{if(t.length===0){i("");return}i(s=>{var l;if(t.some(u=>u.value===s))return s;const a=n==null?void 0:n.trim();if(a&&t.some(u=>u.value===a))return a;const o=r==null?void 0:r.trim();return o&&t.some(u=>u.value===o)?o:((l=t[0])==null?void 0:l.value)??""})},[r,t,n,i])}function lm(e){var v;const{view:t,selectedSessionKey:n,activeBackendRunId:r,isLocallyRunning:i,resumeRun:s}=e,[a,o]=E.useState(null),l=E.useRef(!1),u=E.useRef(new Map),h=E.useRef(new Map),c=E.useRef(new Map),p=E.useRef(r),f=E.useRef(new Set);E.useEffect(()=>{n&&f.current.add(n)},[n]),E.useEffect(()=>{n&&i&&f.current.delete(n)},[i,n]);const x=Da(t==="chat"?{states:["queued","running"],limit:200,syncActiveStates:!0,isLocallyRunning:i}:void 0),m=E.useMemo(()=>{var k;return eo(((k=x.data)==null?void 0:k.runs)??[])},[(v=x.data)==null?void 0:v.runs]),S=E.useMemo(()=>{const k=to(m);if(a){const R=m.get(a.sessionKey)??null;R&&(!a.runId||R.runId===a.runId)&&k.delete(a.sessionKey)}return k},[m,a]),g=E.useMemo(()=>{if(!n)return null;const k=m.get(n)??null;return(!k||!a||a.sessionKey!==n?!1:!a.runId||k.runId===a.runId)?null:k},[m,n,a]);return E.useEffect(()=>{r&&(p.current=r)},[r]),E.useEffect(()=>{if(t!=="chat"||!n||!g||!f.current.has(n)||i||r===g.runId||u.current.get(n)===g.runId)return;const R=h.current.get(n);if(R&&R===g.runId)return;const A=c.current.get(n);if(typeof A=="number"){const C=Date.parse(g.requestedAt??"");if(Number.isFinite(C)){if(C<=A+2e3)return}else if(Date.now()-A<=8e3)return}u.current.set(n,g.runId),f.current.delete(n),s(g)},[r,g,i,s,n,t]),E.useEffect(()=>{if(!n){u.current.clear(),h.current.clear(),c.current.clear(),f.current.clear();return}m.has(n)||(u.current.delete(n),h.current.delete(n),c.current.delete(n))},[m,n]),E.useEffect(()=>{var R,A,C;const k=l.current;if(l.current=i,!i&&k&&n){const P=((R=p.current)==null?void 0:R.trim())||((C=(A=m.get(n))==null?void 0:A.runId)==null?void 0:C.trim());P&&h.current.set(n,P),c.current.set(n,Date.now()),o({sessionKey:n,...P?{runId:P}:{}}),x.refetch()}},[m,i,n,x]),E.useEffect(()=>{if(!a)return;const k=m.get(a.sessionKey)??null;if(!k){o(null);return}a.runId&&k.runId!==a.runId&&o(null)},[m,a]),E.useEffect(()=>{i&&(a==null?void 0:a.sessionKey)===n&&o(null)},[i,n,a]),{sessionRunStatusByKey:S}}const um={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 cm(e,t){return{driver:"nextbot-stream",mode:"send",payload:e,requestedSkills:t}}function hm(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 dm(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 fm(e){var m;const t=new Set(["tool","tool_result","toolresult","function"]),n=[];let r=0,i=0,s=null;const a=(S,g)=>(r+=1,`history-${S}-${g||"unknown"}-${r}`),o=S=>{const g=typeof S=="string"?S:JSON.stringify(S??{});try{return{args:g,parsedArgs:JSON.parse(g)}}catch{return{args:g}}},l=(S,g)=>{for(let v=S.length-1;v>=0;v-=1){const k=S[v];if(k.type==="tool-invocation"&&k.toolInvocation.toolCallId===g)return v}return-1},u=S=>s?(s={...s,meta:{...s.meta,timestamp:S}},s):(i+=1,s={id:`history-assistant-${i}-${S||"unknown"}`,role:"assistant",parts:[],meta:{source:"history",status:"final",timestamp:S}},s),h=()=>{s&&(s.parts.length>0&&n.push(s),s=null)},c=(S,g)=>{if(!g)return;const v=u(S);v.parts=[...v.parts,{type:"text",text:g}]},p=(S,g)=>{if(!g)return;const v=u(S);v.parts=[...v.parts,{type:"reasoning",reasoning:g,details:[]}]},f=S=>{const g=u(S.timestamp),v=l(g.parts,S.toolCallId),k={type:"tool-invocation",toolInvocation:{status:ie.CALL,toolCallId:S.toolCallId,toolName:S.toolName,args:S.args,parsedArgs:S.parsedArgs}};if(v>=0){g.parts=[...g.parts.slice(0,v),k,...g.parts.slice(v+1)];return}g.parts=[...g.parts,k]},x=S=>{if(!S.toolCallId)return;const g=u(S.timestamp),v=l(g.parts,S.toolCallId);if(v<0){g.parts=[...g.parts,{type:"tool-invocation",toolInvocation:{status:ie.RESULT,toolCallId:S.toolCallId,toolName:S.toolName,args:"{}",parsedArgs:void 0,result:S.result}}];return}const k=g.parts[v];k.type==="tool-invocation"&&(g.parts=[...g.parts.slice(0,v),{...k,toolInvocation:{...k.toolInvocation,status:ie.RESULT,result:S.result}},...g.parts.slice(v+1)])};for(const S of e){const g=(m=S.role)==null?void 0:m.toLowerCase().trim();if(!g)continue;const v=S.timestamp;if(g==="user"||g==="system"||g==="data"){h();const k=xr(S.content).trim();if(!k)continue;n.push({id:a(g,v),role:g,parts:[{type:"text",text:k}],meta:{source:"history",status:"final",timestamp:v}});continue}if(g==="assistant"){const k=xr(S.content).trim();if(k&&c(v,k),typeof S.reasoning_content=="string"&&S.reasoning_content.trim()&&p(v,S.reasoning_content.trim()),Array.isArray(S.tool_calls))for(const R of S.tool_calls){if(!R||typeof R!="object")continue;const A=R,C=A.function,P=typeof C=="object"&&C?C:null,F=typeof A.id=="string"?A.id.trim():"";if(!F)continue;const B=typeof(P==null?void 0:P.name)=="string"?P.name:typeof A.name=="string"?A.name:"tool",w=o((P==null?void 0:P.arguments)??A.arguments??"");f({timestamp:v,toolCallId:F,toolName:B,args:w.args,parsedArgs:w.parsedArgs})}continue}if(t.has(g)){const k=typeof S.tool_call_id=="string"?S.tool_call_id.trim():"",R=typeof S.name=="string"&&S.name.trim()?S.name.trim():"tool";x({timestamp:v,toolCallId:k,toolName:R,result:S.content})}}return h(),n}function Et(e){const[t,n]=E.useState(e.getValue());return E.useEffect(()=>{const r=e.subscribe(n);return()=>r.unsubscribe()},[e]),t}function pm(e,t){const[n,r]=E.useState(t);return E.useEffect(()=>{const i=e.subscribe(r);return()=>i.unsubscribe()},[e]),n}function mm(e,t){const n=E.useRef(e);E.useEffect(()=>{n.current=e});const r=E.useRef(null);E.useEffect(()=>{t.setCallbacks({onRunSettled:async({sourceSessionId:g,resultSessionId:v})=>{const k=n.current;await k.refetchSessions();const R=k.selectedSessionKeyRef.current;(!R||R===g||v&&R===v)&&await k.refetchHistory()},onRunError:({sourceMessage:g,restoreDraft:v})=>{v&&n.current.setDraft(k=>k.trim().length===0&&g?g:k)},onSessionChanged:g=>{n.current.setSelectedSessionKey(v=>v===g?v:g)}})},[t]);const i=pm(t.messages$,t.getMessages()),s=Et(t.isAgentResponding$),a=Et(t.isAwaitingResponse$),o=Et(t.activeRun$),l=Et(t.lastError$),u=(o==null?void 0:o.remoteRunId)??null,h=_o(o),c=!!(o&&(h===null||o.remoteStopCapable&&!u)),p=E.useCallback(async g=>{const v=dm(g.requestedSkills),k=cm(g,v);await t.send({message:g.message,sessionId:g.sessionKey,agentId:g.agentId,metadata:k,restoreDraftOnError:g.restoreDraftOnError,stopCapable:g.stopSupported,stopReason:g.stopReason})},[t]),f=E.useCallback(async g=>{var A,C;const v=(A=g.runId)==null?void 0:A.trim(),k=(C=g.sessionKey)==null?void 0:C.trim();if(!v||!k)return;const R=hm(g);await t.resume({remoteRunId:v,sessionId:k,agentId:g.agentId,metadata:R,stopCapable:g.stopSupported,stopReason:g.stopReason})},[t]),x=E.useCallback(async()=>{await t.stop()},[t]),m=E.useCallback(()=>{r.current=null,t.reset()},[t]),S=E.useCallback((g,v)=>{if(!!(t.activeRun$.getValue()||t.isAgentResponding$.getValue()))return;const R=n.current.selectedSessionKeyRef.current;if(R!==r.current&&(r.current=R,t.getMessages().length>0&&t.setMessages([])),!R){t.getMessages().length>0&&t.setMessages([]);return}v!=null&&v.isLoading&&g.length===0||t.setMessages(fm(g))},[t]);return{uiMessages:i,isSending:s,isAwaitingAssistantOutput:a,canStopCurrentRun:c,stopDisabledReason:h,lastSendError:l,activeBackendRunId:u,sendMessage:p,stopCurrentRun:x,resumeRun:f,resetStreamState:m,applyHistoryMessages:S}}const _n="sid_";function gm(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 xm(e){const t=Math.random().toString(36).slice(2,8);return`agent:${e}:ui:direct:web-${Date.now().toString(36)}${t}`}function ym(e){const t=new TextEncoder().encode(e);let n="";for(const i of t)n+=String.fromCharCode(i);const r=btoa(n).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/g,"");return`${_n}${r}`}function bm(e){if(!e.startsWith(_n))return null;const t=e.slice(_n.length).replace(/-/g,"+").replace(/_/g,"/"),n=t.length%4===0?"":"=".repeat(4-t.length%4);try{const r=atob(t+n),i=Uint8Array.from(r,s=>s.charCodeAt(0));return new TextDecoder().decode(i)}catch{return null}}function Sm(e){if(!e)return null;const t=bm(e);if(t)return t;try{return decodeURIComponent(e)}catch{return e}}function km(e){return`/chat/${ym(e)}`}const ve="native";function He(e){return typeof e!="string"?ve:e.trim().toLowerCase()||ve}function Dt(e,t){return e==="native"?T("chatSessionTypeNative"):e==="codex-sdk"?T("chatSessionTypeCodex"):e==="claude-agent-sdk"?T("chatSessionTypeClaude"):(t==null?void 0:t.trim())||e}function wm(e){var n;const t=new Map;for(const r of e){const i=He(r.value);t.set(i,{value:i,label:((n=r.label)==null?void 0:n.trim())||Dt(i)})}return t.has(ve)||t.set(ve,{value:ve,label:Dt(ve)}),Array.from(t.values()).sort((r,i)=>r.value===ve?-1:i.value===ve?1:r.value.localeCompare(i.value))}function vm(e){const{selectedSession:t,selectedSessionKey:n,pendingSessionType:r,setPendingSessionType:i,sessionTypesData:s}=e,a=E.useMemo(()=>wm((s==null?void 0:s.options)??[]),[s==null?void 0:s.options]),o=E.useMemo(()=>{const x=[...a],m=He(t==null?void 0:t.sessionType);return x.some(S=>S.value===m)||x.push({value:m,label:Dt(m)}),x.sort((S,g)=>S.value===ve?-1:g.value===ve?1:S.value.localeCompare(g.value))},[a,t==null?void 0:t.sessionType]),l=E.useMemo(()=>He((s==null?void 0:s.defaultType)??ve),[s==null?void 0:s.defaultType]),u=E.useMemo(()=>He((t==null?void 0:t.sessionType)??r??l),[l,r,t==null?void 0:t.sessionType]);E.useEffect(()=>{n||i(l)},[l,n,i]);const h=!n||!!(t!=null&&t.sessionTypeMutable),c=E.useMemo(()=>new Set(a.map(x=>x.value)),[a]),p=!!(t&&!c.has(He(t.sessionType))),f=p?`${Dt(u)} ${T("chatSessionTypeUnavailableSuffix")}`:null;return{sessionTypeOptions:o,defaultSessionType:l,selectedSessionType:u,canEditSessionType:h,sessionTypeUnavailable:p,sessionTypeUnavailableMessage:f}}const Cm=new Set(["off","minimal","low","medium","high","adaptive","xhigh"]);function Im(e){if(typeof e!="string")return null;const t=e.trim().toLowerCase();return t&&Cm.has(t)?t:null}function Tm(e){var S,g,v,k,R;const t=Oa(),n=za(),r=Fa({q:e.query.trim()||void 0,limit:120,activeMinutes:0}),i=Xa("skill"),s=Ba({sessionKey:e.selectedSessionKey,agentId:e.selectedAgentId}),a=$a(e.selectedSessionKey,300),o=Ua(),l=(t.isFetched||t.isSuccess)&&(n.isFetched||n.isSuccess),u=E.useMemo(()=>{const A=ao({meta:n.data,config:t.data,onlyConfigured:!0}),C=new Set,P=[];for(const F of A)for(const B of F.models){const w=oo(F.prefix,B);!w||C.has(w)||(C.add(w),P.push({value:w,modelLabel:B,providerLabel:F.displayName,thinkingCapability:lo(F.modelThinking,B,F.aliases)}))}return P.sort((F,B)=>{const w=F.providerLabel.localeCompare(B.providerLabel);return w!==0?w:F.modelLabel.localeCompare(B.modelLabel)})},[n.data,t.data]),h=E.useMemo(()=>{var A;return((A=r.data)==null?void 0:A.sessions)??[]},[(S=r.data)==null?void 0:S.sessions]),c=E.useMemo(()=>{var A;return((A=i.data)==null?void 0:A.records)??[]},[(g=i.data)==null?void 0:g.records]),p=E.useMemo(()=>h.find(A=>A.key===e.selectedSessionKey)??null,[e.selectedSessionKey,h]),f=vm({selectedSession:p,selectedSessionKey:e.selectedSessionKey,pendingSessionType:e.pendingSessionType,setPendingSessionType:e.setPendingSessionType,sessionTypesData:o.data});om({modelOptions:u,selectedSessionPreferredModel:p==null?void 0:p.preferredModel,defaultModel:(v=t.data)==null?void 0:v.agents.defaults.model,setSelectedModel:e.setSelectedModel});const x=E.useMemo(()=>{var A;return((A=a.data)==null?void 0:A.messages)??[]},[(k=a.data)==null?void 0:k.messages]),m=E.useMemo(()=>{var P;if(!e.selectedSessionKey)return null;const A=(P=a.data)==null?void 0:P.metadata;if(!A||typeof A!="object")return null;const C=[A.preferred_thinking,A.thinking,A.thinking_level,A.thinkingLevel];for(const F of C){const B=Im(F);if(B)return B}return null},[(R=a.data)==null?void 0:R.metadata,e.selectedSessionKey]);return{configQuery:t,configMetaQuery:n,sessionsQuery:r,installedSkillsQuery:i,chatCapabilitiesQuery:s,historyQuery:a,sessionTypesQuery:o,isProviderStateResolved:l,modelOptions:u,sessions:h,skillRecords:c,selectedSession:p,historyMessages:x,selectedSessionThinkingLevel:m,...f}}function Rm(e){if(e.label&&e.label.trim())return e.label.trim();const t=e.key.split(":");return t[t.length-1]||e.key}class Em{constructor(t,n){this.uiManager=t,this.streamActionsManager=n,this.hasSnapshotChanges=r=>{const i=Z.getState().snapshot;for(const[s,a]of Object.entries(r))if(!Object.is(i[s],a))return!0;return!1},this.resolveUpdateValue=(r,i)=>typeof i=="function"?i(r):i,this.syncSnapshot=r=>{if(this.hasSnapshotChanges(r)&&(Z.getState().setSnapshot(r),Object.prototype.hasOwnProperty.call(r,"modelOptions")||Object.prototype.hasOwnProperty.call(r,"selectedModel")||Object.prototype.hasOwnProperty.call(r,"selectedThinkingLevel"))){const i=Z.getState().snapshot;this.reconcileThinkingForModel(i.selectedModel)}},this.setDraft=r=>{const i=Z.getState().snapshot.draft,s=this.resolveUpdateValue(i,r);s!==i&&Z.getState().setSnapshot({draft:s})},this.setPendingSessionType=r=>{const i=Z.getState().snapshot.pendingSessionType,s=this.resolveUpdateValue(i,r);s!==i&&Z.getState().setSnapshot({pendingSessionType:s})},this.send=async()=>{const r=Z.getState().snapshot,i=se.getState().snapshot,s=r.draft.trim();if(!s)return;const a=r.selectedSkills,o=!!i.selectedSessionKey,l=i.selectedSessionKey??xm(i.selectedAgentId);o||this.uiManager.goToSession(l,{replace:!0}),this.setDraft(""),this.setSelectedSkills([]),await this.streamActionsManager.sendMessage({message:s,sessionKey:l,agentId:i.selectedAgentId,sessionType:r.selectedSessionType,model:r.selectedModel||void 0,thinkingLevel:r.selectedThinkingLevel??void 0,stopSupported:r.stopSupported,stopReason:r.stopReason,requestedSkills:a,restoreDraftOnError:!0})},this.stop=async()=>{await this.streamActionsManager.stopCurrentRun()},this.goToProviders=()=>{this.uiManager.goToProviders()},this.setSelectedModel=r=>{const i=Z.getState().snapshot.selectedModel,s=this.resolveUpdateValue(i,r);s!==i&&(Z.getState().setSnapshot({selectedModel:s}),this.reconcileThinkingForModel(s))},this.setSelectedThinkingLevel=r=>{const i=Z.getState().snapshot.selectedThinkingLevel,s=this.resolveUpdateValue(i,r);s!==i&&Z.getState().setSnapshot({selectedThinkingLevel:s})},this.selectSessionType=r=>{const i=He(r);Z.getState().setSnapshot({selectedSessionType:i,pendingSessionType:i}),this.syncRemoteSessionType(i)},this.setSelectedSkills=r=>{const i=Z.getState().snapshot.selectedSkills,s=this.resolveUpdateValue(i,r);Object.is(s,i)||Z.getState().setSnapshot({selectedSkills:s})},this.selectModel=r=>{this.setSelectedModel(r)},this.selectThinkingLevel=r=>{this.setSelectedThinkingLevel(r)},this.selectSkills=r=>{this.setSelectedSkills(r)},this.syncRemoteSessionType=async r=>{const i=se.getState().snapshot,s=i.selectedSessionKey;if(!s)return;const a=i.sessions.find(o=>o.key===s);a!=null&&a.sessionTypeMutable&&He(a.sessionType)!==r&&await Ha(s,{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=Z.getState().snapshot,r=n.modelOptions.find(s=>s.value===t),i=this.resolveThinkingForModel(r,n.selectedThinkingLevel);i!==n.selectedThinkingLevel&&Z.getState().setSnapshot({selectedThinkingLevel:i})}}function Am(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 Mm{constructor(){this.syncSnapshot=t=>{const n=bn.getState().snapshot,r=t.sessionRunStatusByKey;(!r||Am(n.sessionRunStatusByKey,r))&&(t.isLocallyRunning===void 0||Object.is(n.isLocallyRunning,t.isLocallyRunning))&&(t.activeBackendRunId===void 0||Object.is(n.activeBackendRunId,t.activeBackendRunId))||bn.getState().setSnapshot(t)}}}class Nm{constructor(t,n){this.uiManager=t,this.streamActionsManager=n,this.hasSnapshotChanges=r=>{const i=se.getState().snapshot;for(const[s,a]of Object.entries(r))if(!Object.is(i[s],a))return!0;return!1},this.resolveUpdateValue=(r,i)=>typeof i=="function"?i(r):i,this.syncSnapshot=r=>{this.hasSnapshotChanges(r)&&se.getState().setSnapshot(r)},this.setSelectedAgentId=r=>{const i=se.getState().snapshot.selectedAgentId,s=this.resolveUpdateValue(i,r);s!==i&&se.getState().setSnapshot({selectedAgentId:s})},this.setSelectedSessionKey=r=>{const i=se.getState().snapshot.selectedSessionKey,s=this.resolveUpdateValue(i,r);s!==i&&se.getState().setSnapshot({selectedSessionKey:s})},this.createSession=()=>{const r=Z.getState().snapshot.defaultSessionType||"native";this.streamActionsManager.resetStreamState(),this.setSelectedSessionKey(null),Z.getState().setSnapshot({pendingSessionType:r}),this.uiManager.goToChatRoot()},this.selectSession=r=>{this.setSelectedSessionKey(r),this.uiManager.goToSession(r)},this.setQuery=r=>{const i=se.getState().snapshot.query,s=this.resolveUpdateValue(i,r);s!==i&&se.getState().setSnapshot({query:s})}}}const fn=async()=>{},ki=()=>{};class Lm{constructor(){this.actions={sendMessage:fn,stopCurrentRun:fn,resumeRun:fn,resetStreamState:ki,applyHistoryMessages:ki},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 jm=async()=>{};class Pm{constructor(t,n,r){this.uiManager=t,this.sessionListManager=n,this.streamActionsManager=r,this.actions={refetchSessions:jm},this.bindActions=i=>{this.actions={...this.actions,...i}},this.hasSnapshotChanges=i=>{const s=ct.getState().snapshot;for(const[a,o]of Object.entries(i))if(!Object.is(s[a],o))return!0;return!1},this.syncSnapshot=i=>{this.hasSnapshotChanges(i)&&ct.getState().setSnapshot(i)},this.deleteSession=()=>{this.deleteCurrentSession()},this.createSession=()=>{this.sessionListManager.createSession()},this.goToProviders=()=>{this.uiManager.goToProviders()},this.deleteCurrentSession=async()=>{const i=se.getState().snapshot.selectedSessionKey;if(!(!i||!await this.uiManager.confirm({title:T("chatDeleteSessionConfirm"),variant:"destructive",confirmLabel:T("delete")}))){ct.getState().setSnapshot({isDeletePending:!0});try{await Ka(i),this.streamActionsManager.resetStreamState(),se.getState().setSnapshot({selectedSessionKey:null}),this.uiManager.goToChatRoot({replace:!0}),await this.actions.refetchSessions()}finally{ct.getState().setSnapshot({isDeletePending:!1})}}}}}const _m=async e=>!1;class Dm{constructor(){this.state={pathname:""},this.actions={navigate:null,confirm:_m},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(km(t),n)}}}function Om(e){return e.delta?e.started?[{type:K.TEXT_DELTA,messageId:e.messageId,delta:e.delta}]:[{type:K.TEXT_START,messageId:e.messageId},{type:K.TEXT_DELTA,messageId:e.messageId,delta:e.delta}]:[]}function zm(e){return!1}function Fm(e){var n,r;return((r=(n=e.message)==null?void 0:n.role)==null?void 0:r.toLowerCase().trim())==="assistant"}function Bm(e){var a;const{event:t,messageId:n}=e,r=t.message;if(!r)return[];const i=(a=r.role)==null?void 0:a.toLowerCase().trim();if(!i)return[];const s=[];if(typeof r.reasoning_content=="string"&&r.reasoning_content.trim()&&(s.push({type:K.REASONING_START,messageId:n}),s.push({type:K.REASONING_DELTA,messageId:n,delta:r.reasoning_content.trim()}),s.push({type:K.REASONING_END,messageId:n})),Array.isArray(r.tool_calls))for(let o=0;o<r.tool_calls.length;o+=1){const l=r.tool_calls[o];if(!l||typeof l!="object")continue;const u=l,h=u.function,c=typeof h=="object"&&h?h:null,p=typeof t.seq=="number"?String(t.seq):"unknown",f=typeof u.id=="string"?u.id:`tool-${p}-${o}`,x=typeof(c==null?void 0:c.name)=="string"?c.name:typeof u.name=="string"?u.name:"tool",m=(c==null?void 0:c.arguments)??u.arguments??"",S=typeof m=="string"?m:JSON.stringify(m??{});s.push({type:K.TOOL_CALL_START,messageId:n,toolCallId:f,toolName:x}),s.push({type:K.TOOL_CALL_ARGS,toolCallId:f,args:S}),s.push({type:K.TOOL_CALL_END,toolCallId:f})}if(i==="tool"||i==="tool_result"||i==="toolresult"||i==="function"){const o=typeof r.tool_call_id=="string"?r.tool_call_id.trim():"";o&&s.push({type:K.TOOL_CALL_RESULT,toolCallId:o,content:r.content})}return s}function Hs(){return`stream-${Date.now()}-${Math.random().toString(36).slice(2,8)}`}function $m(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 Um(e){return Va($m(e.item,e.requestedSkills),{signal:e.signal,onReady:e.onReady,onDelta:e.onDelta,onSessionEvent:e.onSessionEvent})}async function Hm(e){return qa({runId:e.runId,...typeof e.fromEventIndex=="number"?{fromEventIndex:e.fromEventIndex}:{}},{signal:e.signal,onReady:e.onReady,onDelta:e.onDelta,onSessionEvent:e.onSessionEvent})}async function Km(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 pn(r)))return;const i=await Vm(e);for(const s of i){if(n.has(s))continue;if(n.add(s),await pn(s))return}if(r&&await pn(r))return}catch{}}async function pn(e){const t=e.trim();if(!t)return!1;try{return(await Wa({runId:t})).stopped===!0}catch{return!1}}async function Vm(e){var i;const t=(i=e.sessionKey)==null?void 0:i.trim();if(!t)return[];const n=8,r=120;for(let s=0;s<n;s+=1){const a=await qm(e,t);if(a.length>0)return a;s<n-1&&await Wm(r)}return[]}async function qm(e,t){try{const n=await Ga({sessionKey:t,states:["queued","running"],limit:50}),r=n.runs.filter(i=>{var s;return((s=i.runId)==null?void 0:s.trim())&&i.sessionKey===t&&i.agentId===e.agentId}).map(i=>i.runId.trim());return r.length>0?r:n.runs.filter(i=>{var s;return((s=i.runId)==null?void 0:s.trim())&&i.sessionKey===t}).map(i=>i.runId.trim())}catch{return[]}}function Wm(e){return new Promise(t=>{window.setTimeout(t,e)})}function Gm(){const e=Date.now().toString(36),t=Math.random().toString(36).slice(2,10);return`run-${e}-${t}`}function Xm(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 i=n.payload;if(!i||typeof i!="object"||Array.isArray(i))return null;const s=Array.isArray(n.requestedSkills)?n.requestedSkills.filter(a=>typeof a=="string"):[];return{driver:"nextbot-stream",mode:"send",payload:i,requestedSkills:s}}if(r==="resume"){const i=typeof n.runId=="string"?n.runId.trim():"";if(!i)return null;const s=typeof n.fromEventIndex=="number"&&Number.isFinite(n.fromEventIndex)?Math.max(0,Math.trunc(n.fromEventIndex)):void 0,a=typeof n.sessionKey=="string"?n.sessionKey.trim():"",o=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:i,...typeof s=="number"?{fromEventIndex:s}:{},...a?{sessionKey:a}:{},...o?{agentId:o}:{},...typeof l=="boolean"?{stopSupported:l}:{},...u?{stopReason:u}:{}}}return null}function Qm(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 Ym(e){var n;return e.mode!=="send"||((n=e.payload.runId)==null?void 0:n.trim())?e:{...e,payload:{...e.payload,runId:Gm()}}}function Jm(e,t){var n,r,i;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()),(i=t.sessionKey)!=null&&i.trim()&&(e.sessionKey=t.sessionKey.trim())}function Zm(){return{deltaMessageId:Hs(),deltaStarted:!1,deltaClosed:!1,hasAssistantSessionEvent:!1,hasAssistantOutput:!1}}function eg(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 tg(e,t){return{driver:"nextbot-stream",kind:"final",sessionKey:e.sessionKey,reply:e.reply,hasAssistantSessionEvent:t}}function wi(e,t,n){e({type:K.RUN_METADATA,runId:t,metadata:n})}function vi(e,t){!e.deltaStarted||e.deltaClosed||(t({type:K.TEXT_END,messageId:e.deltaMessageId}),e.deltaClosed=!0)}function ng(e,t,n){const r=Om({messageId:e.deltaMessageId,delta:n.delta,started:e.deltaStarted});r.length>0&&(e.deltaStarted=!0,e.deltaClosed=!1,e.hasAssistantOutput=!0);for(const i of r)t(i)}function rg(e,t,n){zm(n.data),Fm(n.data)&&(e.hasAssistantSessionEvent=!0);for(const r of Bm({event:n.data,messageId:e.deltaMessageId}))t(r)}function ig(e,t,n){const r=n.trim();if(e.hasAssistantOutput||!r)return;const i=Hs();t({type:K.TEXT_START,messageId:i}),t({type:K.TEXT_DELTA,messageId:i,delta:r}),t({type:K.TEXT_END,messageId:i})}class sg{constructor(){this.activeAbortController=null,this.activeRunState=null,this.buildMissingMetadataObservable=t=>new Nt(n=>{n.next({type:K.RUN_ERROR,runId:t,error:"nextbot runtime metadata is required"}),n.complete()}),this.openRunStream=t=>{const{metadata:n,signal:r,onReady:i,onDelta:s,onSessionEvent:a}=t;return n.mode==="send"?Um({item:n.payload,requestedSkills:n.requestedSkills,signal:r,onReady:i,onDelta:s,onSessionEvent:a}):Hm({runId:n.runId,fromEventIndex:n.fromEventIndex,signal:r,onReady:i,onDelta:s,onSessionEvent:a})},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:i})=>new Nt(s=>{const a=Zm();let o=!1;const l=h=>{o||s.next(h)};return l({type:K.RUN_STARTED,runId:n}),this.openRunStream({metadata:t,signal:r.signal,onReady:h=>{this.activeRunState&&Jm(this.activeRunState,h),wi(l,n,eg(h))},onDelta:h=>{ng(a,l,h)},onSessionEvent:h=>{rg(a,l,h)}}).then(h=>{vi(a,l),ig(a,l,h.reply),wi(l,n,tg(h,a.hasAssistantSessionEvent)),l({type:K.RUN_FINISHED,runId:n}),s.complete()}).catch(h=>{vi(a,l),vn(h)||l({type:K.RUN_ERROR,runId:n,error:h instanceof Error?h.message:String(h)}),s.complete()}).finally(()=>{this.finalizeRunState(r,i)}),()=>{o=!0,r.abort(),this.activeAbortController===r&&(this.activeAbortController=null)}}),this.abortRun=()=>{var n;const t=this.activeRunState;t!=null&&t.backendStopSupported&&Km(t),(n=this.activeAbortController)==null||n.abort(),this.activeAbortController=null,this.activeRunState=null},this.run=t=>{const n=Xm(t),r=typeof t.runId=="string"&&t.runId.trim()?t.runId:`run-${Date.now()}`;if(!n)return this.buildMissingMetadataObservable(r);const i=Ym(n);this.abortRun();const s=new AbortController;this.activeAbortController=s;const a=Qm(i);return this.activeRunState=a,this.createRunObservable({metadata:i,clientRunId:r,abortController:s,runState:a})}}}class ag{constructor(){this.chatUiManager=new Dm,this.runtimeAgent=new sg,this.chatController=new Bo({agent:this.runtimeAgent,getToolDefs:()=>[],getContexts:()=>[],getToolExecutor:()=>{}},{metadataParsers:um}),this.chatStreamActionsManager=new Lm,this.chatInputManager=new Em(this.chatUiManager,this.chatStreamActionsManager),this.chatSessionListManager=new Nm(this.chatUiManager,this.chatStreamActionsManager),this.chatRunStatusManager=new Mm,this.chatThreadManager=new Pm(this.chatUiManager,this.chatSessionListManager,this.chatStreamActionsManager)}}function og(e){const{view:t,routeSessionKey:n,selectedSessionKey:r,selectedAgentId:i,setSelectedSessionKey:s,setSelectedAgentId:a,selectedSessionKeyRef:o,resetStreamState:l}=e;E.useEffect(()=>{if(t==="chat"){if(n){r!==n&&s(n);return}r!==null&&(s(null),l())}},[l,n,r,s,t]),E.useEffect(()=>{const u=r?gm(r):null;u&&i!==u&&a(u)},[i,r,a]),E.useEffect(()=>{o.current=r},[r,o])}function lg({view:e,confirmDialog:t}){return d.jsxs("div",{className:"h-full flex",children:[d.jsx(yo,{}),e==="chat"?d.jsx(Zp,{}):d.jsx("section",{className:"flex-1 min-h-0 overflow-hidden bg-gradient-to-b from-gray-50/60 to-white",children:e==="cron"?d.jsx("div",{className:"h-full overflow-auto custom-scrollbar",children:d.jsx("div",{className:"mx-auto w-full max-w-[min(1120px,100%)] px-6 py-5",children:d.jsx(am,{})})}):d.jsx("div",{className:"h-full overflow-hidden",children:d.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:d.jsx(Qa,{forcedType:"skills"})})})}),t]})}function wg({view:e}){var Ae,Be;const[t]=E.useState(()=>new ag),n=se(be=>be.snapshot.query),r=se(be=>be.snapshot.selectedSessionKey),i=se(be=>be.snapshot.selectedAgentId),s=Z(be=>be.snapshot.pendingSessionType),{confirm:a,ConfirmDialog:o}=Ai(),l=va(),u=Ca(),{sessionId:h}=Ia(),c=E.useRef(null),p=E.useRef(r),f=E.useRef(null),x=E.useMemo(()=>Sm(h),[h]),{sessionsQuery:m,installedSkillsQuery:S,chatCapabilitiesQuery:g,historyQuery:v,isProviderStateResolved:k,modelOptions:R,sessions:A,skillRecords:C,selectedSession:P,historyMessages:F,selectedSessionThinkingLevel:B,sessionTypeOptions:w,defaultSessionType:j,selectedSessionType:_,canEditSessionType:W,sessionTypeUnavailable:D,sessionTypeUnavailableMessage:L}=Tm({query:n,selectedSessionKey:r,selectedAgentId:i,pendingSessionType:s,setPendingSessionType:t.chatInputManager.setPendingSessionType,setSelectedModel:t.chatInputManager.setSelectedModel}),{uiMessages:G,isSending:Y,isAwaitingAssistantOutput:le,canStopCurrentRun:ye,stopDisabledReason:y,lastSendError:he,activeBackendRunId:ue,sendMessage:b,stopCurrentRun:de,resumeRun:Ie,resetStreamState:ee,applyHistoryMessages:De}=mm({selectedSessionKeyRef:p,setSelectedSessionKey:t.chatSessionListManager.setSelectedSessionKey,setDraft:t.chatInputManager.setDraft,refetchSessions:m.refetch,refetchHistory:v.refetch},t.chatController);console.log("[ChatPage] uiMessages",{uiMessages:G,historyMessages:F}),E.useEffect(()=>{t.chatStreamActionsManager.bind({sendMessage:b,stopCurrentRun:de,resumeRun:Ie,resetStreamState:ee,applyHistoryMessages:De})},[De,t,ee,Ie,b,de]);const{sessionRunStatusByKey:ke}=lm({view:e,selectedSessionKey:r,activeBackendRunId:ue,isLocallyRunning:Y||!!ue,resumeRun:t.chatStreamActionsManager.resumeRun});og({view:e,routeSessionKey:x,selectedSessionKey:r,selectedAgentId:i,setSelectedSessionKey:t.chatSessionListManager.setSelectedSessionKey,setSelectedAgentId:t.chatSessionListManager.setSelectedAgentId,selectedSessionKeyRef:p,resetStreamState:t.chatStreamActionsManager.resetStreamState}),E.useEffect(()=>{t.chatStreamActionsManager.applyHistoryMessages(F,{isLoading:v.isLoading})},[F,v.isLoading,t]),E.useEffect(()=>{t.chatUiManager.syncState({pathname:l.pathname}),t.chatUiManager.bindActions({navigate:u,confirm:a})},[a,l.pathname,u,t]);const Ee=P?Rm(P):void 0;return E.useEffect(()=>{t.chatThreadManager.bindActions({refetchSessions:m.refetch})},[t,m.refetch]),E.useEffect(()=>{var St,kt;const be=!Y&&!le&&!v.isLoading&&r!==f.current;t.chatInputManager.syncSnapshot({isProviderStateResolved:k,defaultSessionType:j,canStopGeneration:ye,stopDisabledReason:y,stopSupported:((St=g.data)==null?void 0:St.stopSupported)??!1,stopReason:(kt=g.data)==null?void 0:kt.stopReason,sendError:he,isSending:Y,modelOptions:R,sessionTypeOptions:w,selectedSessionType:_,...be?{selectedThinkingLevel:B}:{},canEditSessionType:W,sessionTypeUnavailable:D,skillRecords:C,isSkillsLoading:S.isLoading}),be&&(f.current=r),r||(f.current=null),t.chatSessionListManager.syncSnapshot({sessions:A,query:n,isLoading:m.isLoading}),t.chatRunStatusManager.syncSnapshot({sessionRunStatusByKey:ke,isLocallyRunning:Y||!!ue,activeBackendRunId:ue}),t.chatThreadManager.syncSnapshot({isProviderStateResolved:k,modelOptions:R,sessionTypeUnavailable:D,sessionTypeUnavailableMessage:L,selectedSessionKey:r,sessionDisplayName:Ee,canDeleteSession:!!P,threadRef:c,isHistoryLoading:v.isLoading,uiMessages:G,isSending:Y,isAwaitingAssistantOutput:le})},[ue,W,ye,Ee,(Ae=g.data)==null?void 0:Ae.stopReason,(Be=g.data)==null?void 0:Be.stopSupported,j,v.isLoading,S.isLoading,le,k,Y,he,G,R,t,n,P,B,r,i,_,ke,w,D,L,A,m.isLoading,y,c,C]),d.jsx(ho,{presenter:t,children:d.jsx(lg,{view:e,confirmDialog:d.jsx(o,{})})})}export{wg as ChatPage};